| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent fd4f9bc commit 094bf2c
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,6 +18,57 @@ namespace Python.Runtime | |||
| 18 | 18 | internal static partial class TypeOffset | |
| 19 | 19 | { | |
| 20 | 20 | // Auto-generated from PyHeapTypeObject in Python.h | |
| 21 | + public static int ob_refcnt = 0; | ||
| 22 | + public static int ob_type = 0; | ||
| 23 | + public static int ob_size = 0; | ||
| 24 | + public static int tp_name = 0; | ||
| 25 | + public static int tp_basicsize = 0; | ||
| 26 | + public static int tp_itemsize = 0; | ||
| 27 | + public static int tp_dealloc = 0; | ||
| 28 | + public static int tp_vectorcall_offset = 0; | ||
| 29 | + public static int tp_getattr = 0; | ||
| 30 | + public static int tp_setattr = 0; | ||
| 31 | + public static int tp_as_async = 0; | ||
| 32 | + public static int tp_repr = 0; | ||
| 33 | + public static int tp_as_number = 0; | ||
| 34 | + public static int tp_as_sequence = 0; | ||
| 35 | + public static int tp_as_mapping = 0; | ||
| 36 | + public static int tp_hash = 0; | ||
| 37 | + public static int tp_call = 0; | ||
| 38 | + public static int tp_str = 0; | ||
| 39 | + public static int tp_getattro = 0; | ||
| 40 | + public static int tp_setattro = 0; | ||
| 41 | + public static int tp_as_buffer = 0; | ||
| 42 | + public static int tp_flags = 0; | ||
| 43 | + public static int tp_doc = 0; | ||
| 44 | + public static int tp_traverse = 0; | ||
| 45 | + public static int tp_clear = 0; | ||
| 46 | + public static int tp_richcompare = 0; | ||
| 47 | + public static int tp_weaklistoffset = 0; | ||
| 48 | + public static int tp_iter = 0; | ||
| 49 | + public static int tp_iternext = 0; | ||
| 50 | + public static int tp_methods = 0; | ||
| 51 | + public static int tp_members = 0; | ||
| 52 | + public static int tp_getset = 0; | ||
| 53 | + public static int tp_base = 0; | ||
| 54 | + public static int tp_dict = 0; | ||
| 55 | + public static int tp_descr_get = 0; | ||
| 56 | + public static int tp_descr_set = 0; | ||
| 57 | + public static int tp_dictoffset = 0; | ||
| 58 | + public static int tp_init = 0; | ||
| 59 | + public static int tp_alloc = 0; | ||
| 60 | + public static int tp_new = 0; | ||
| 61 | + public static int tp_free = 0; | ||
| 62 | + public static int tp_is_gc = 0; | ||
| 63 | + public static int tp_bases = 0; | ||
| 64 | + public static int tp_mro = 0; | ||
| 65 | + public static int tp_cache = 0; | ||
| 66 | + public static int tp_subclasses = 0; | ||
| 67 | + public static int tp_weaklist = 0; | ||
| 68 | + public static int tp_del = 0; | ||
| 69 | + public static int tp_version_tag = 0; | ||
| 70 | + public static int tp_finalize = 0; | ||
| 71 | + public static int tp_vectorcall = 0; | ||
| 21 | 72 | public static int am_await = 0; | |
| 22 | 73 | public static int am_aiter = 0; | |
| 23 | 74 | public static int am_anext = 0; | |
@@ -174,4 +225,3 @@ internal static partial class SlotTypes | |||
| 174 | 225 | ||
| 175 | 226 | } | |
| 176 | 227 | #endif | |
| 177 | - | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -53,25 +53,25 @@ class AstParser(object): | |||
| 53 | 53 | """Walk an AST and determine the members of all structs""" | |
| 54 | 54 | ||
| 55 | 55 | def __init__(self): | |
| 56 | - self.__typedefs = {} | ||
| 57 | - self.__typedecls = {} | ||
| 58 | - self.__structs = {} | ||
| 59 | - self.__struct_stack = [] | ||
| 60 | - self.__struct_members_stack = [] | ||
| 61 | - self.__ptr_decl_depth = 0 | ||
| 62 | - self.__struct_members = {} | ||
| 63 | - self.__decl_names = {} | ||
| 56 | + self._typedefs = {} | ||
| 57 | + self._typedecls = {} | ||
| 58 | + self._structs = {} | ||
| 59 | + self._struct_stack = [] | ||
| 60 | + self._struct_members_stack = [] | ||
| 61 | + self._ptr_decl_depth = 0 | ||
| 62 | + self._struct_members = {} | ||
| 63 | + self._decl_names = {} | ||
| 64 | 64 | ||
| 65 | 65 | def get_struct_members(self, name): | |
| 66 | 66 | """return a list of (name, type) of struct members""" | |
| 67 | - defs = self.__typedefs.get(name) | ||
| 67 | + defs = self._typedefs.get(name) | ||
| 68 | 68 | if defs is None: | |
| 69 | 69 | return None | |
| 70 | - node = self.__get_leaf_node(defs) | ||
| 70 | + node = self._get_leaf_node(defs) | ||
| 71 | 71 | name = node.name | |
| 72 | 72 | if name is None: | |
| 73 | 73 | name = defs.declname | |
| 74 | - return self.__struct_members.get(name) | ||
| 74 | + return self._struct_members.get(name) | ||
| 75 | 75 | ||
| 76 | 76 | def visit(self, node): | |
| 77 | 77 | if isinstance(node, c_ast.FileAST): | |
@@ -96,27 +96,27 @@ def visit_ast(self, ast): | |||
| 96 | 96 | self.visit(node) | |
| 97 | 97 | ||
| 98 | 98 | def visit_typedef(self, typedef): | |
| 99 | - self.__typedefs[typedef.name] = typedef.type | ||
| 99 | + self._typedefs[typedef.name] = typedef.type | ||
| 100 | 100 | self.visit(typedef.type) | |
| 101 | 101 | ||
| 102 | 102 | def visit_typedecl(self, typedecl): | |
| 103 | - self.__decl_names[typedecl.type] = typedecl.declname | ||
| 103 | + self._decl_names[typedecl.type] = typedecl.declname | ||
| 104 | 104 | self.visit(typedecl.type) | |
| 105 | 105 | ||
| 106 | 106 | def visit_struct(self, struct): | |
| 107 | - self.__structs[self.__get_struct_name(struct)] = struct | ||
| 108 | 107 | if struct.decls: | |
| 108 | + self._structs[self._get_struct_name(struct)] = struct | ||
| 109 | 109 | # recurse into the struct | |
| 110 | - self.__struct_stack.insert(0, struct) | ||
| 110 | + self._struct_stack.insert(0, struct) | ||
| 111 | 111 | for decl in struct.decls: | |
| 112 | - self.__struct_members_stack.insert(0, decl.name) | ||
| 112 | + self._struct_members_stack.insert(0, decl.name) | ||
| 113 | 113 | self.visit(decl) | |
| 114 | - self.__struct_members_stack.pop(0) | ||
| 115 | - self.__struct_stack.pop(0) | ||
| 116 | - elif self.__ptr_decl_depth: | ||
| 114 | + self._struct_members_stack.pop(0) | ||
| 115 | + self._struct_stack.pop(0) | ||
| 116 | + elif self._ptr_decl_depth: | ||
| 117 | 117 | # the struct is empty, but add it as a member to the current | |
| 118 | 118 | # struct as the current member maybe a pointer to it. | |
| 119 | - self.__add_struct_member(struct.name) | ||
| 119 | + self._add_struct_member(struct.name) | ||
| 120 | 120 | ||
| 121 | 121 | def visit_decl(self, decl): | |
| 122 | 122 | self.visit(decl.type) | |
@@ -125,51 +125,57 @@ def visit_funcdecl(self, funcdecl): | |||
| 125 | 125 | self.visit(funcdecl.type) | |
| 126 | 126 | ||
| 127 | 127 | def visit_ptrdecl(self, ptrdecl): | |
| 128 | - self.__ptr_decl_depth += 1 | ||
| 128 | + self._ptr_decl_depth += 1 | ||
| 129 | 129 | self.visit(ptrdecl.type) | |
| 130 | - self.__ptr_decl_depth -= 1 | ||
| 130 | + self._ptr_decl_depth -= 1 | ||
| 131 | 131 | ||
| 132 | 132 | def visit_identifier(self, identifier): | |
| 133 | 133 | type_name = " ".join(identifier.names) | |
| 134 | - self.__add_struct_member(type_name) | ||
| 134 | + self._add_struct_member(type_name) | ||
| 135 | 135 | ||
| 136 | - def __add_struct_member(self, type_name): | ||
| 137 | - if not (self.__struct_stack and self.__struct_members_stack): | ||
| 136 | + def _add_struct_member(self, type_name): | ||
| 137 | + if not (self._struct_stack and self._struct_members_stack): | ||
| 138 | 138 | return | |
| 139 | 139 | ||
| 140 | 140 | # add member to current struct | |
| 141 | - current_struct = self.__struct_stack[0] | ||
| 142 | - member_name = self.__struct_members_stack[0] | ||
| 143 | - struct_members = self.__struct_members.setdefault( | ||
| 144 | - self.__get_struct_name(current_struct), []) | ||
| 141 | + current_struct = self._struct_stack[0] | ||
| 142 | + member_name = self._struct_members_stack[0] | ||
| 143 | + struct_members = self._struct_members.setdefault( | ||
| 144 | + self._get_struct_name(current_struct), []) | ||
| 145 | 145 | ||
| 146 | 146 | # get the node associated with this type | |
| 147 | 147 | node = None | |
| 148 | - if type_name in self.__typedefs: | ||
| 149 | - node = self.__get_leaf_node(self.__typedefs[type_name]) | ||
| 150 | - elif type_name in self.__structs: | ||
| 151 | - node = self.__structs[type_name] | ||
| 148 | + if type_name in self._typedefs: | ||
| 149 | + node = self._get_leaf_node(self._typedefs[type_name]) | ||
| 150 | + # If the struct was only declared when the typedef was created, its member | ||
| 151 | + # information will not have been recorded and we have to look it up in the | ||
| 152 | + # structs | ||
| 153 | + if isinstance(node, c_ast.Struct) and node.decls is None: | ||
| 154 | + if node.name in self._structs: | ||
| 155 | + node = self._structs[node.name] | ||
| 156 | + elif type_name in self._structs: | ||
| 157 | + node = self._structs[type_name] | ||
| 152 | 158 | ||
| 153 | 159 | # If it's a struct (and not a pointer to a struct) expand | |
| 154 | 160 | # it into the current struct definition | |
| 155 | - if not self.__ptr_decl_depth and isinstance(node, c_ast.Struct): | ||
| 161 | + if not self._ptr_decl_depth and isinstance(node, c_ast.Struct): | ||
| 156 | 162 | for decl in node.decls or []: | |
| 157 | - self.__struct_members_stack.insert(0, decl.name) | ||
| 163 | + self._struct_members_stack.insert(0, decl.name) | ||
| 158 | 164 | self.visit(decl) | |
| 159 | - self.__struct_members_stack.pop(0) | ||
| 165 | + self._struct_members_stack.pop(0) | ||
| 160 | 166 | else: | |
| 161 | 167 | # otherwise add it as a single member | |
| 162 | 168 | struct_members.append((member_name, type_name)) | |
| 163 | 169 | ||
| 164 | - def __get_leaf_node(self, node): | ||
| 170 | + def _get_leaf_node(self, node): | ||
| 165 | 171 | if isinstance(node, c_ast.Typedef): | |
| 166 | - return self.__get_leaf_node(node.type) | ||
| 172 | + return self._get_leaf_node(node.type) | ||
| 167 | 173 | if isinstance(node, c_ast.TypeDecl): | |
| 168 | - return self.__get_leaf_node(node.type) | ||
| 174 | + return self._get_leaf_node(node.type) | ||
| 169 | 175 | return node | |
| 170 | 176 | ||
| 171 | - def __get_struct_name(self, node): | ||
| 172 | - return node.name or self.__decl_names.get(node) or "_struct_%d" % id(node) | ||
| 177 | + def _get_struct_name(self, node): | ||
| 178 | + return node.name or self._decl_names.get(node) or "_struct_%d" % id(node) | ||
| 173 | 179 | ||
| 174 | 180 | ||
| 175 | 181 | class Writer(object): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments