Exemplo n.º 1
0
 def visit_FunctionDef(self, node):
     self.aliases = dict()
     self.aliases.update((k, {k})
         for k, v in builtin_constants.iteritems())
     self.aliases.update((k, {v})
         for k, v in builtin_constructors.iteritems())
     for module in modules:
         self.aliases.update((v, {v})
             for k, v in modules[module].iteritems())
     self.aliases.update((f.name, {f})
         for f in self.global_declarations.itervalues())
     self.aliases.update((arg.id, {arg})
             for arg in node.args.args)
     self.generic_visit(node)
Exemplo n.º 2
0
    def visit_FunctionDef(self, node):
        self.current = node
        self.typedefs = list()
        self.name_to_nodes = {arg.id: {arg} for arg in node.args.args}
        self.yield_points = self.passmanager.gather(YieldPoints, node)

        for k, v in builtin_constants.iteritems():
            fake_node = ast.Name(k, ast.Load())
            self.name_to_nodes.update({k: {fake_node}})
            self.result[fake_node] = NamedType(v)

        self.generic_visit(node)

        # propagate type information through all aliases
        for name, nodes in self.name_to_nodes.iteritems():
            final_node = ast.Name("__fake__" + name, ast.Load())
            for n in nodes:
                self.combine(final_node, n)
            for n in nodes:
                self.result[n] = self.result[final_node]
        self.current_global_declarations[node.name] = node
        self.result[node] = (Assignable(self.result[node]), self.typedefs)
Exemplo n.º 3
0
    def visit_FunctionDef(self, node):
        self.current = node
        self.typedefs = list()
        self.name_to_nodes = {arg.id: {arg} for arg in node.args.args}
        self.yield_points = self.passmanager.gather(YieldPoints, node)

        for k, v in builtin_constants.iteritems():
            fake_node = ast.Name(k, ast.Load())
            self.name_to_nodes.update({k: {fake_node}})
            self.result[fake_node] = NamedType(v)

        # two stages, one for inter procedural propagation
        self.stage = 0
        self.generic_visit(node)

        # and one for backward propagation
        # but this step is generally costly
        if cfg.getboolean('typing', 'enable_two_steps_typing'):
            self.stage = 1
            self.generic_visit(node)

        # propagate type information through all aliases
        for name, nodes in self.name_to_nodes.iteritems():
            final_node = ast.Name("__fake__" + name, ast.Load())
            for n in nodes:
                self.combine(final_node, n)
            for n in nodes:
                self.result[n] = self.result[final_node]
        self.current_global_declarations[node.name] = node
        self.result[node] = (Assignable(self.result[node]), self.typedefs)
        for k in self.passmanager.gather(LocalDeclarations, node):
            lazy_res = self.lazyness_analysis[k.id]
            if lazy_res <= self.max_recompute:
                self.result[k] = Lazy(self.result[k])
            else:
                self.result[k] = Assignable(self.result[k])