Skip to content

Commit

Permalink
Feat: add disgonostic printing for codegen (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanglei1949 authored Jun 14, 2024
1 parent b13b0ab commit bc07e09
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions codegen/actor_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ def process_actor_groups(process_args):
p.close()
p.join()

def check_diagnostics_and_print(unit):
if unit.diagnostics:
parse_success = False
for diag in unit.diagnostics:
if diag.severity > clang.cindex.Diagnostic.Warning:
print(f"Error: {diag.spelling}")
print(f" File: {diag.location.file.name}")
print(f" Line: {diag.location.line}")
print(f" Column: {diag.location.column}")
print(f" Severity: {diag.severity}")
else:
parse_success = True
return parse_success

def process_one_actor_group(arg: ActorGroupProcessArgument):
include_path = os.path.relpath(arg.filepath, arg.source_dir)
Expand All @@ -42,6 +55,9 @@ def process_one_actor_group(arg: ActorGroupProcessArgument):
index = clang.cindex.Index.create()
unit = index.parse(arg.filepath, ['-nostdinc++', '-x', 'c++', '-std=gnu++17'] + arg.include_list)

if not check_diagnostics_and_print(unit):
raise Exception("Failed to parse %s" % arg.filepath)

actg_list = []
ns_list = []
traverse_actor_group_types(unit.cursor, arg.filepath, actg_list, ns_list)
Expand Down Expand Up @@ -81,6 +97,9 @@ def process_one_actor(arg: ActorProcessArgument):
index = clang.cindex.Index.create()
unit = index.parse(arg.filepath, ['-nostdinc++', '-x', 'c++', '-std=gnu++17'] + arg.include_list)

if not check_diagnostics_and_print(unit):
raise Exception("Failed to parse %s" % arg.filepath)

act_list = []
ns_list = []
traverse_actor_types(unit.cursor, arg.filepath, act_list, ns_list)
Expand Down

0 comments on commit bc07e09

Please sign in to comment.