コード例 #1
0
ファイル: ir_visitor.py プロジェクト: LarsenRidder/BioScript
    def visitMethodInvocation(self, ctx: BSParser.MethodInvocationContext):
        deff = self.visitVariableDefinition(ctx.variableDefinition())
        deff['var'] = self.symbol_table.get_local(deff['name'],
                                                  self.scope_stack[-1])
        if deff['var'].value.size <= 1 and deff['index'] == -1:
            offset = 0
        else:
            offset = deff['index']
        method_name, args = self.visitMethodCall(ctx.methodCall())
        self.current_block.add(
            Call({
                'name': deff['name'],
                'offset': offset
            }, self.symbol_table.functions[method_name], args))

        # Create the jump to the function.
        jump_location = self.get_entry_block(method_name)
        # Build the graph edge.
        add_cycle(self.graph, [self.current_block.nid, jump_location['nid']])
        #self.graph.add_cycle([self.current_block.nid, jump_location['nid']])
        # self.current_block.add(Jump(jump_location['label']))
        # Sve the block.
        self.functions[self.scope_stack[-1]]['blocks'][
            self.current_block.nid] = self.current_block
        # Save this for the return call.
        previous_nid = self.current_block.nid
        # We must create a new block.
        self.current_block = BasicBlock()
        # This is the return call from the return call.
        self.current_block.add(
            Label('{}_return_{}'.format(method_name, previous_nid)))
コード例 #2
0
    def visitMethodInvocation(self, ctx: BSParser.MethodInvocationContext):
        deff = self.visitVariableDefinition(ctx.variableDefinition())
        # Get the symbol.
        symbol = self.symbol_table.get_local(deff['name'],
                                             self.scope_stack[-1])
        # Grab the function.
        function = self.visitMethodCall(ctx.methodCall())
        # Update the types of the symbol.
        symbol.types.update(function['types'])
        if ChemTypeResolver.is_only_numeric(symbol.types):
            symbol.value = Number(symbol.name, deff['index'])
        else:
            symbol.value = Movable(symbol.name, deff['index'])

        # Save the symbol.
        self.symbol_table.update_symbol(symbol)
コード例 #3
0
ファイル: symbol_visitor.py プロジェクト: lilott8/BioScript
    def visitMethodInvocation(self, ctx: BSParser.MethodInvocationContext):
        deff = self.visitVariableDefinition(ctx.variableDefinition())

        method_name, args = self.visitMethodCall(ctx.methodCall())

        if len(args) != len(self.symbol_table.functions[method_name].args):
            raise UnsupportedOperation(
                "Function {} takes {} arguments; {} arguments provided.".
                format(method_name,
                       len(self.symbol_table.functions[method_name].args),
                       len(args)))

        symbol = Symbol(deff['name'], self.scope_stack[-1],
                        self.symbol_table.functions[method_name].types)

        self.symbol_table.add_local(symbol)

        return None