Exemplo n.º 1
0
    def visitProgram(self, ctx: BSParser.ProgramContext):
        # Visit the functions, for the 3rd time.
        if ctx.functions():
            self.visitFunctions(ctx.functions())

        self.scope_stack.append("main")
        self.symbol_table.current_scope = self.symbol_table.scope_map[
            self.scope_stack[-1]]
        # While this visits *all* the statements,
        # it only looks at the methodInvocation
        # statements.
        for statement in ctx.statements():
            self.visitStatements(statement)
        self.scope_stack.pop()

        # The last attempt to find the types of a method chain.
        # Because we know the chain, we can simply crawl the chain
        # and the first thing to give us typing information,
        # because it is called from a function, we grab it,
        # and assign it to the unknown function.
        for name, objekt in self.symbol_table.functions.items():
            if not objekt.types:
                types = set()
                find = name
                while not types and find in self.call_chain.keys():
                    types = self.symbol_table.functions[find].types
                    find = self.call_chain[find]
                objekt.types = types
Exemplo n.º 2
0
    def visitProgram(self, ctx: BSParser.ProgramContext):
        self.scope_stack.append("main")
        self.symbol_table.current_scope = self.symbol_table.scope_map['main']

        for header in ctx.globalDeclarations():
            self.visitGlobalDeclarations(header)

        if ctx.functions():
            self.visitFunctions(ctx.functions())

        # Set the current block to a new block *after* the functions.
        self.current_block = BasicBlock()
        self.labels['main'] = self.current_block.nid
        self.current_block.label = Label("main")
        self.graph.add_node(self.current_block.nid, function=self.scope_stack[-1], label=self.current_block.label.label)
        # Build the main function.
        self.functions['main'] = {'blocks': dict(), 'entry': self.current_block.nid, 'graph': self.graph}

        # Add all the subsequent instructions to the B.B.
        for statement in ctx.statements():
            self.visitStatements(statement)

        self.current_block.add(NOP())
        self.functions[self.scope_stack[-1]]['blocks'][self.current_block.nid] = self.current_block

        # Add the graph edges for function calls.
        for key, val in self.calls.items():
            for v in val:
                self.graph.add_cycle([key, self.functions[v]['entry']])
Exemplo n.º 3
0
    def visitProgram(self, ctx: BSParser.ProgramContext):
        # Visiting globals is done in global_visitor.
        # Add main first, it is the root.
        self.symbol_table.new_scope("main")
        self.scope_stack.append('main')

        # We set current_scope equal to main for because the statements
        # hereafter are main's statements.
        self.symbol_table.current_scope = self.symbol_table.scope_map['main']
        for statement in ctx.statements():
            self.visitStatements(statement)

        self.scope_stack.pop()

        if ctx.functions():
            self.visitFunctions(ctx.functions())
Exemplo n.º 4
0
    def visitProgram(self, ctx: BSParser.ProgramContext):
        self.scope_stack.append("main")

        for header in ctx.globalDeclarations():
            self.visitGlobalDeclarations(header)

        smt = ""

        if ctx.functions():
            smt += self.visitFunctions(ctx.functions())

        for statement in ctx.statements():
            smt += self.visitStatements(statement)

        smt += f"{self.nl}(check-sat)"
        self.add_smt(smt)
Exemplo n.º 5
0
 def visitProgram(self, ctx: BSParser.ProgramContext):
     for header in ctx.globalDeclarations():
         self.visitGlobalDeclarations(header)
     if ctx.functions():
         self.visitFunctions(ctx.functions())