def members(self): """Members of the composite type (list of :class:`.Variable`). The returned list can be indexed by either positions (0, 1, ...) or names. For example, consider the following structure: .. code-block:: c struct { int a; int b; }; We may index the list as follows: .. code-block:: python type.members[0] # Returns 'a'. type.members['b'] # Returns the member named 'b'. When there is no such member, it raises ``IndexError``. """ members = NamedObjectList() for node in self._type.get_declaration().get_children(): members.append(Variable(node)) return members
def vtables(self): """Virtual tables (list of :class:`Vtable`). The returned list can be indexed by either positions (0, 1, ...) or vtable names. Example: .. code-block:: python module.vtables[0] # Returns the first vtable. module.vtables['vt1'] # Returns the vtable named 'vt1'. """ vtables = NamedObjectList() for vt in self.json.get('vtables', []): vtables.append(Vtable(vt)) return vtables
def classes(self): """C++ classes (list of :class:`Class`). The returned list can be indexed by either positions (0, 1, ...) or classes' names. Example: .. code-block:: python module.classes[0] # Returns the first class. module.classes['class1'] # Returns the class named 'class1'. """ classes = NamedObjectList() for c in self.json.get('classes', []): classes.append(Class(c)) return classes
def params(self): """Function parameters (list of :class:`.Variable`). The returned list can be indexed by either positions (0, 1, ...) or names. Example: .. code-block:: python func.params[0] # Returns the first parameter. func.params['p'] # Returns the parameter named 'p'. When there is no such parameter, it raises ``IndexError``. """ params = NamedObjectList() for node in self._node.get_arguments(): params.append(Variable(node)) return params
def named_enums(self): """Named enums (list of :class:`.EnumType`). The returned list can be indexed by either positions (0, 1, ...) or enum names. Example: .. code-block:: python module.named_enums[0] # Returns the first enum. module.named_enums['node'] # Returns the enum named 'node'. When there is no such enum, it raises ``IndexError``. """ return NamedObjectList([x for x in self.enums if x.has_name()])
def named_unions(self): """Named unions (list of :class:`.UnionType`). The returned list can be indexed by either positions (0, 1, ...) or union names. Example: .. code-block:: python module.named_unions[0] # Returns the first union. module.named_unions['node'] # Returns the union named 'node'. When there is no such union, it raises ``IndexError``. """ return NamedObjectList([x for x in self.unions if x.has_name()])
def named_structs(self): """Named structures (list of :class:`.StructType`). The returned list can be indexed by either positions (0, 1, ...) or structure names. Example: .. code-block:: python module.named_structs[0] # Returns the first structure. module.named_structs['node'] # Returns the structure named 'node'. When there is no such structure, it raises ``IndexError``. """ return NamedObjectList([x for x in self.structs if x.has_name()])
def global_vars(self): """Global variables (list of :class:`.Variable`). The returned list can be indexed by either positions (0, 1, ...) or names. Example: .. code-block:: python module.global_vars[0] # Returns the first global variable. module.global_vars['g'] # Returns the global variable named 'g'. When there is no such global variable, it raises ``IndexError``. """ var_nodes = filter(self._is_global_var, self._tu.cursor.get_children()) return NamedObjectList(map(Variable, var_nodes))
def funcs(self): """Functions (list of :class:`.Function`). The returned list can be indexed by either positions (0, 1, ...) or function names. Example: .. code-block:: python module.funcs[0] # Returns the first function. module.funcs['main'] # Returns the function named 'main'. When there is no such function, it raises ``IndexError``. """ func_nodes = filter(self._is_func, self._tu.cursor.get_children()) return NamedObjectList(map(Function, func_nodes))
def setUp(self): self.vars = NamedObjectList([])