Skip to content

Commit bc07e09

Browse files
authored
Feat: add disgonostic printing for codegen (alibaba#45)
1 parent b13b0ab commit bc07e09

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

codegen/actor_codegen.py

+19
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ def process_actor_groups(process_args):
3434
p.close()
3535
p.join()
3636

37+
def check_diagnostics_and_print(unit):
38+
if unit.diagnostics:
39+
parse_success = False
40+
for diag in unit.diagnostics:
41+
if diag.severity > clang.cindex.Diagnostic.Warning:
42+
print(f"Error: {diag.spelling}")
43+
print(f" File: {diag.location.file.name}")
44+
print(f" Line: {diag.location.line}")
45+
print(f" Column: {diag.location.column}")
46+
print(f" Severity: {diag.severity}")
47+
else:
48+
parse_success = True
49+
return parse_success
3750

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

58+
if not check_diagnostics_and_print(unit):
59+
raise Exception("Failed to parse %s" % arg.filepath)
60+
4561
actg_list = []
4662
ns_list = []
4763
traverse_actor_group_types(unit.cursor, arg.filepath, actg_list, ns_list)
@@ -81,6 +97,9 @@ def process_one_actor(arg: ActorProcessArgument):
8197
index = clang.cindex.Index.create()
8298
unit = index.parse(arg.filepath, ['-nostdinc++', '-x', 'c++', '-std=gnu++17'] + arg.include_list)
8399

100+
if not check_diagnostics_and_print(unit):
101+
raise Exception("Failed to parse %s" % arg.filepath)
102+
84103
act_list = []
85104
ns_list = []
86105
traverse_actor_types(unit.cursor, arg.filepath, act_list, ns_list)

0 commit comments

Comments
 (0)