Ejemplo n.º 1
0
 def visit_var_item(self, node, type):
     name = node.first_child
     if len(node.children) == 1:
         # name, is_array, size, context
         return AST.VarDecl(type, False, 0, name.value, name.context)
     else:
         # visit_subscript2
         size = self.visit(node.children[1])
         return AST.VarDecl(type, True, size, name.value, name.context)
Ejemplo n.º 2
0
    def visit_decl_trailer(self, node, type_name, name):
        # generator: need to be list()
        first = node.first_child
        type = self.visit(type_name)
        if first.value == ';':  # a single non-array var_decl
            yield AST.VarDecl(type, False, 0, name.value, type_name.context)
        elif first.type in (sym.paralist, sym.compound_stmt):
            yield self.visit_funcdef(type, name.value, node.children, type_name.context)
        else:  # complex var_decl
            if first.type == sym.subscript2:  # first item is an array
                # strip subscript2 and semicolon
                var_items = node.children[1:-1]
                # visit_subscript2
                yield AST.VarDecl(type, True, self.visit(first), name.value, node.context)
            else:  # first item is a basic_type
                var_items = node.children[:-1]  # strip semicolon
                yield AST.VarDecl(type, False, 0, name.value, node.context)

            # handle (',', var_items)*
            for child in var_items[1::2]:
                # visit_var_item
                yield self.visit(child, type)