MCPcopy Create free account
hub / github.com/ddnet/ddnet / process_source_file

Function process_source_file

scripts/extract_identifiers.py:101–152  ·  view source on GitHub ↗
(out, file, extra_args, break_on)

Source from the content-addressed store, hash-verified

99
100
101def process_source_file(out, file, extra_args, break_on):
102 args = extra_args + ["-Isrc"]
103 if file.endswith(".c"):
104 header = f"{file[:-2]}.h"
105 elif file.endswith(".cpp"):
106 header = f"{file[:-4]}.h"
107 else:
108 raise ValueError(f"unrecognized source file: {file}")
109
110 index = clang.cindex.Index.create()
111 unit = index.parse(file, args=args)
112 errors = list(unit.diagnostics)
113 if errors:
114 for error in errors:
115 print(f"{file}: {error.format()}", file=sys.stderr)
116 print(args, file=sys.stderr)
117 raise ParseError(f"failed parsing {file}")
118
119 filter_files = frozenset([file, header])
120
121 for namespace, node in traverse_namespaced(unit.cursor, filter_files=filter_files):
122 cur_file = None
123 if node.location.file is not None:
124 cur_file = node.location.file.name
125 if cur_file is None or cur_file not in (file, header):
126 continue
127 if node.kind in INTERESTING_NODE_KINDS and node.spelling:
128 typ = get_complex_type(node.type)
129 qualifiers = ""
130 if INTERESTING_NODE_KINDS[node.kind] in {"variable", "function"}:
131 is_member = node.semantic_parent.kind in {CursorKind.CLASS_DECL, CursorKind.CLASS_TEMPLATE, CursorKind.STRUCT_DECL, CursorKind.UNION_DECL}
132 is_static = node.storage_class == StorageClass.STATIC or is_static_member_definition_hack(node)
133 if is_static:
134 qualifiers = "s" + qualifiers
135 if is_member:
136 qualifiers = "m" + qualifiers
137 if is_static and not is_member and is_const(node.type):
138 qualifiers = "c" + qualifiers
139 if node.linkage == LinkageKind.EXTERNAL and not is_member:
140 qualifiers = "g" + qualifiers
141 out.writerow({
142 "file": cur_file,
143 "line": node.location.line,
144 "column": node.location.column,
145 "kind": INTERESTING_NODE_KINDS[node.kind],
146 "path": "::".join(namespace),
147 "qualifiers": qualifiers,
148 "type": typ,
149 "name": node.spelling,
150 })
151 if node.spelling == break_on:
152 breakpoint()
153
154
155def main():

Callers 1

mainFunction · 0.85

Calls 6

ParseErrorClass · 0.85
traverse_namespacedFunction · 0.85
get_complex_typeFunction · 0.85
is_constFunction · 0.85
parseMethod · 0.45

Tested by

no test coverage detected