def start_func_scope_var_declaration(self, return_t, scope):
        self.current_scope = scope
        self.param_table[scope] = TuplaDirectorioFunciones(
            name=scope,
            return_type=return_t,
            param_table=[],
            param_pointers=[],
            address_size=[0, 0, 0, 0],
            start_pointer=self.quad_list.pointer + 1)
        self.current_local_var_table = dict()

        if (return_t != 'void'):
            var_func = "var_func_" + scope
            addr = self.get_addr(VarType(return_t), scope='global')
            self.global_var_table[var_func] = TuplaTablaVariables(
                name=var_func, type=VarType(return_t), addr=addr)
    def add_params_to_current_scope(self, params):
        params.reverse()

        for (name, tipo) in params:
            var_type = VarType(tipo)
            addr = self.get_addr(var_type, scope=self.current_scope)
            self.param_table[self.current_scope].param_table.append(
                var_type.value)
            self.param_table[self.current_scope].param_pointers.append(addr)
            self.add_size_to_addr_size(var_type=var_type)
            self.current_local_var_table[name] = TuplaTablaVariables(
                name=name, type=var_type, addr=addr)
    def validate_operation_and_get_result_type(self, op, a, b):
        primitive_a = self.resolve_primitive_type(a)
        primitive_b = self.resolve_primitive_type(b)

        result_type = self.cubo_seman.typematch(primitive_a, op, primitive_b)

        if (result_type == "error"):
            raise Exception(
                'TYPE MISMATCH. {}({}) and {}({}) should be compatible through {} operation'
                .format(str(a), primitive_a, str(b), primitive_b, str(op)))

        return VarType(result_type)
    def get_or_create_constant_addr(self, c):
        try:
            addr = self.constant_map.get(str(c))
            if addr != None: return addr[1]

            if type(c) == str and c[0] == '@':
                var_type = VarType.CHAR
                value = c[2:-1]
            else:
                var_type = VarType(type(c).__name__)
                value = c

            addr = self.virtual_memory_manager.const_addr.next(var_type)
            self.constant_map[str(c)] = (value, addr, var_type.name)
            return addr
        except:
            return None
    def add_variable_to_current_scope(self, tipo, vars):
        var_type = VarType(tipo)

        for var in vars:
            (var_name, dim1, dim2) = var
            addr = None
            if dim1 != None and dim2 != None:
                size = dim1 * dim2
                addr = self.allocate_block(type=var_type,
                                           scope=self.current_scope,
                                           size=size)
            elif dim1 != None:
                size = dim1
                addr = self.allocate_block(type=var_type,
                                           scope=self.current_scope,
                                           size=size)
            else:
                size = 1
                addr = self.get_addr(type=var_type, scope=self.current_scope)

            self.add_size_to_addr_size(var_type=var_type, size=size)

            self.current_local_var_table[var_name] = TuplaTablaVariables(
                name=var_name, type=var_type, addr=addr, dims=(dim1, dim2))
Beispiel #6
0
 def declaracion(self, p):
     self.action_handler.add_variable_to_current_scope(tipo=VarType(p.tipo),
                                                       vars=p.lista_id_aux)
Beispiel #7
0
 def paramsaux(self, p):
     p.paramsaux.append((p.ID, VarType(p.tipo)))
     return p.paramsaux
Beispiel #8
0
 def params(self, p):
     p.paramsaux.append((p.ID, VarType(p.tipo)))
     return self.action_handler.add_params_to_current_scope(
         params=p.paramsaux)