File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2222 from libdestruct .common .obj import obj
2323
2424
25- PARSED_STRUCT = {}
25+ PARSED_STRUCTS = {}
2626"""A cache for parsed struct definitions, indexed by name."""
2727
2828TYPEDEFS = {}
@@ -53,12 +53,16 @@ def definition_to_type(definition: str) -> type[obj]:
5353 struct_node = decl .type
5454
5555 if struct_node .name :
56- PARSED_STRUCT [struct_node .name ] = struct_to_type (struct_node )
56+ PARSED_STRUCTS [struct_node .name ] = struct_to_type (struct_node )
5757 elif isinstance (decl , c_ast .Typedef ):
5858 name , definition = typedef_to_pair (decl )
5959 TYPEDEFS [name ] = definition
6060
61- return struct_to_type (root )
61+ result = struct_to_type (root )
62+
63+ PARSED_STRUCTS [root .name ] = result
64+
65+ return result
6266
6367
6468def struct_to_type (struct_node : c_ast .Struct ) -> type [struct ]:
@@ -68,9 +72,9 @@ def struct_to_type(struct_node: c_ast.Struct) -> type[struct]:
6872
6973 fields = {}
7074
71- if not struct_node .decls and struct_node .name in PARSED_STRUCT :
75+ if not struct_node .decls and struct_node .name in PARSED_STRUCTS :
7276 # We can check if the struct is already parsed.
73- return PARSED_STRUCT [struct_node .name ]
77+ return PARSED_STRUCTS [struct_node .name ]
7478 elif not struct_node .decls :
7579 raise ValueError ("Struct must have fields." )
7680
You can’t perform that action at this time.
0 commit comments