Ejemplo n.º 1
0
def p_class_declaration_statement(p):
    '''class_declaration_statement : class_entry_type STRING extends_from implements_list LBRACE class_statement_list RBRACE
                                   | INTERFACE STRING interface_extends_list LBRACE class_statement_list RBRACE'''
    if len(p) == 8:
        p[0] = ast.Class(p[2], p[1], p[3], p[4], p[6], lineno=p.lineno(2))
    else:
        p[0] = ast.Interface(p[2], p[3], p[5], lineno=p.lineno(1))
Ejemplo n.º 2
0
                extends += [node.extends]
            if node.implements:
                extends += node.implements
            extends = extends or ['object']
            for superclass in extends:
                bases.append(py.Name(superclass, py.Load(**pos(node)), **pos(node)))
            body = map(to_stmt, flatten(map(self.from_phpast, node.nodes)))
        for stmt in body:
            if (isinstance(stmt, py.FunctionDef)
                and stmt.name in (name, '__construct')):
                stmt.name = '__init__'
        if not body: body = [py.Pass(**pos(node))]
        return py.ClassDef(name, bases, body, [], **pos(node))

        if isinstance(node, php.Interface):
            return self.from_phpast(php.Class(node.name, None, "object", [], [], lineno=node.lineno))

    if isinstance(node, (php.ClassConstants, php.ClassVariables)):
            statements = []
            for child in node.nodes:
                if isinstance(child, php.ClassConstant):
                    name = php.Constant(child.name, lineno=child.lineno)
        else:
                    name = php.Variable(child.name, lineno=child.lineno)
                initial = child.initial
        if initial is None:
                    initial = php.Constant('None', lineno=child.lineno)
                statements.append(py.Assign([store(self.from_phpast(name))],
                                            self.from_phpast(initial),
                                            **pos(child)))
            return statements