def visit(self, node, scope, current_class):
     O = enviroment.ObjectEnviroment(current_class)
     scope.new_scope(O)
     for declaration in node.declaration_list:
         self.visit(declaration, scope, current_class)
     r_type_expr = self.visit(node.expr, scope, current_class)
     scope.end_scope()
     node.static_type = r_type_expr
     return r_type_expr
 def visit(self, node, scope, current_class):
     O = enviroment.ObjectEnviroment(current_class)
     scope.new_scope(O)
     if not scope.is_defined(node.var_id)[0]:
         scope.add(node.var_id, node.exp_type)
     else:
         # ERROR
         pass
     case_type = self.visit(node.exp, scope, current_class)
     scope.end_scope()
     return case_type
 def visit(self, node, scope, current_class):
     if node.meth_id == "main" and current_class == "Main":
         self.__main = True
     O = enviroment.ObjectEnviroment(current_class)
     for param in node.param_list:
         a, b = self.visit(param, scope, current_class)
         O.add(a, b)
     scope.new_scope(O)
     expr_type = self.visit(node.exp, scope, current_class)
     scope.end_scope()
     conform = self.context.lca.conform(expr_type, node.return_type)
     return conform
Example #4
0
    def visit(self, node, current_class, scope):
        _locals = []
        _body = []

        scope.new_scope(enviroment.ObjectEnviroment(current_class))
        for declaration in node.declaration_list:
            local, body, value = self.visit(declaration, current_class, scope)
            _locals += local
            _body += body

        local_expr, body_expr, value_expr = self.visit(node.expr,
                                                       current_class, scope)
        scope.end_scope()
        return _locals + local_expr, _body + body_expr, value_expr
Example #5
0
    def visit(self, node, value_expression, expr0_type, type_of_case,
              current_class, scope):
        scope.new_scope(enviroment.ObjectEnviroment(current_class))
        scope.add(node.var_id, node.exp_type, self.local_count)
        self.local_count += 1
        local_id = scope.get_last_O().get_local(node.var_id)

        _locals = []
        _body = []

        if node.exp_type == "Object" and expr0_type in [
                "String", "Int", "Bool"
        ]:
            l1, b1, v = self.__boxing(expr0_type, value_expression)
            value_expression = v
            _locals += l1
            _body += b1

        assign = AssignCIL(local_id, value_expression)

        l, b, v = self.visit(node.exp, current_class, scope)
        scope.end_scope()
        b = [assign] + b
        l.append(local_id)

        if type_of_case == "Object" and node.exp.static_type in [
                "String", "Int", "Bool"
        ]:
            l1, b1, value = self.__boxing(node.exp.static_type,
                                          value_expression)
            v = value
            _locals += l1
            _body += b1

        _locals += l
        _body += b

        return node.exp_type, _locals, _body, v
Example #6
0
    def visit(self, node, current_class, scope):
        new_name = "{}_{}".format(current_class, node.meth_id)
        _locals_args = []
        # if node.meth_id == "main":
        _locals_args.append(self.void)
        # save_name = self.self_instance.name
        # self.self_instance.name += "_{}".format(node.meth_id)
        param_list = [ArgCIL(self.self_instance)]
        O = enviroment.ObjectEnviroment(current_class)
        for param in node.param_list[::-1]:
            p, t = self.visit(param, current_class, node.meth_id, scope)
            # _locals_args.append(p.arg)
            O.add(p, t, self.local_count)
            self.local_count += 1
            temp_local = O.get_local(p)
            param_list.append(ArgCIL(temp_local))

        scope.new_scope(O)
        _locals, _code, _ = self.visit(node.exp, current_class, scope)
        scope.end_scope()
        f = FunctionCIL(new_name, param_list, _locals_args + _locals, _code)
        meth = MethodCIL(node.meth_id, new_name, f)
        return None, meth, [f]