Exemplo n.º 1
0
    def make_superclass_constructor_call(self, info, callee_type):
        """Construct a statement that calls the superclass constructor.

        In particular, it passes any type variables arguments as needed.
        """
        callee = SuperExpr('__init__')
        callee.info = info
        
        # We do not handle generic constructors. Either pass runtime
        # type variables from the current scope or perhaps require
        # explicit constructor in this case.
        
        selftype = self_type(info)    
        
        # FIX overloading
        # FIX default args / varargs
        
        # Map self type to the superclass context.
        selftype = map_instance_to_supertype(selftype, info.base)
        
        super_init = info.base.get_method('__init__')
        
        # Add constructor arguments.
        args = []
        for n in range(1, callee_type.min_args):            
            args.append(NameExpr(super_init.args[n].name()))
            self.tf.set_type(args[-1], callee_type.arg_types[n])

        # Store callee type after stripping away the 'self' type.
        self.tf.set_type(callee, nodes.method_callable(callee_type))
        
        call = CallExpr(callee, args, [nodes.ARG_POS] * len(args))
        return ExpressionStmt(call)
Exemplo n.º 2
0
 def visit_super_expr(self, node: SuperExpr) -> Node:
     new = SuperExpr(node.name)
     new.info = node.info
     return new
Exemplo n.º 3
0
        """Replace bound type vars of callable with args from instance type."""
        a = <tuple<int, Type>> []
        for i in range(len(typ.args)):
            a.append((i + 1, typ.args[i]))
        return Callable(callable.arg_types, callable.arg_kinds,
                        callable.arg_names, callable.ret_type,
                        callable.is_type_obj(), callable.name,
                        callable.variables, a)
    
    ExpressionStmt make_superclass_constructor_call(self, TypeInfo info,
                                                    Callable callee_type):
        """Construct a statement that calls the superclass constructor.

        In particular, it passes any type variables arguments as needed.
        """
        callee = SuperExpr('__init__')
        callee.info = info
        
        # We do not handle generic constructors. Either pass runtime
        # type variables from the current scope or perhaps require
        # explicit constructor in this case.
        
        selftype = self_type(info)    
        
        # FIX overloading
        # FIX default args / varargs
        
        # Map self type to the superclass context.
        selftype = map_instance_to_supertype(selftype, info.base)
        
        super_init = (FuncDef)info.base.get_method('__init__')
Exemplo n.º 4
0
 def visit_super_expr(self, node: SuperExpr) -> None:
     super().visit_super_expr(node)
     if node.info is not None:
         node.info = self.fixup(node.info)
Exemplo n.º 5
0
 def visit_super_expr(self, node: SuperExpr) -> None:
     node.info = None
     super().visit_super_expr(node)
Exemplo n.º 6
0
 def visit_super_expr(self, node: SuperExpr) -> SuperExpr:
     call = self.expr(node.call)
     assert isinstance(call, CallExpr)
     new = SuperExpr(node.name, call)
     new.info = node.info
     return new
Exemplo n.º 7
0
 def visit_super_expr(self, node: SuperExpr) -> None:
     super().visit_super_expr(node)
     if node.info is not None:
         node.info = self.fixup(node.info)
Exemplo n.º 8
0
 def visit_super_expr(self, node: SuperExpr) -> SuperExpr:
     call = self.expr(node.call)
     assert isinstance(call, CallExpr)
     new = SuperExpr(node.name, call)
     new.info = node.info
     return new
Exemplo n.º 9
0
 def visit_super_expr(self, node: SuperExpr) -> None:
     node.info = None
     super().visit_super_expr(node)
Exemplo n.º 10
0
 def visit_super_expr(self, node: SuperExpr) -> SuperExpr:
     new = SuperExpr(node.name)
     new.info = node.info
     return new