Exemple #1
0
        public ASTCILNode VisitStaticMethodCall(ASTStaticMethodCallNode MethodCall)
        {
            var invoke = (ASTCILExpressionNode)MethodCall.InvokeOnExpresion.Accept(this);
            ASTCILExpressionNode invokeOn = invoke;

            if (MethodCall.InvokeOnExpresion.SemanticCheckResult.Type == compilationUnit.TypeEnvironment.Int ||
                MethodCall.InvokeOnExpresion.SemanticCheckResult.Type == compilationUnit.TypeEnvironment.Bool)
            {
                invokeOn = new ASTCILBoxingNode(invoke, MethodCall.InvokeOnExpresion.SemanticCheckResult.Type);
            }

            compilationUnit.TypeEnvironment.GetTypeDefinition(MethodCall.TypeName, null, out var type);
            return(new ASTCILFuncStaticCallNode(
                       MethodCall.MethodName, type,
                       new[] { invokeOn }
                       .Concat(MethodCall.Arguments.Select((param, i) =>
            {
                var exp = (ASTCILExpressionNode)param.Accept(this);
                ASTCILExpressionNode arg = exp;
                var coolMethod = compilationUnit.MethodEnvironment.GetMethod(type, MethodCall.MethodName);
                if (coolMethod.GetParam(i) == compilationUnit.TypeEnvironment.Object && (param.SemanticCheckResult.Type == compilationUnit.TypeEnvironment.Int || param.SemanticCheckResult.Type == compilationUnit.TypeEnvironment.Bool))
                {
                    arg = new ASTCILBoxingNode(exp, param.SemanticCheckResult.Type);
                }
                return arg;
            }))));
        }
Exemple #2
0
        public ASTCILNode VisitDynamicMethodCall(ASTDynamicMethodCallNode MethodCall)
        {
            var type = MethodCall.InvokeOnExpresion.SemanticCheckResult.Type;

            if (type is SelfType self)
            {
                type = self.ContextType;
            }

            var invoke = (ASTCILExpressionNode)MethodCall.InvokeOnExpresion.Accept(this);
            ASTCILExpressionNode invokeOn = invoke;

            if (MethodCall.InvokeOnExpresion.SemanticCheckResult.Type == compilationUnit.TypeEnvironment.Int ||
                MethodCall.InvokeOnExpresion.SemanticCheckResult.Type == compilationUnit.TypeEnvironment.Bool)
            {
                invokeOn = new ASTCILBoxingNode(invoke, MethodCall.InvokeOnExpresion.SemanticCheckResult.Type);
            }

            var args = new[] { invokeOn }
            .Concat(MethodCall.Arguments.Select((param, i) =>
            {
                var exp = (ASTCILExpressionNode)param.Accept(this);
                ASTCILExpressionNode arg = exp;
                var coolMethod           = compilationUnit.MethodEnvironment.GetMethod(type, MethodCall.MethodName);
                if (coolMethod.GetParam(i) == compilationUnit.TypeEnvironment.Object && (param.SemanticCheckResult.Type == compilationUnit.TypeEnvironment.Int || param.SemanticCheckResult.Type == compilationUnit.TypeEnvironment.Bool))
                {
                    arg = new ASTCILBoxingNode(exp, param.SemanticCheckResult.Type);
                }
                return(arg);
            }));

            return(new ASTCILFuncVirtualCallNode(type, MethodCall.MethodName, args));
        }
Exemple #3
0
        public ASTCILNode VisitOwnMethodCall(ASTOwnMethodCallNode OwnMethodCall)
        {
            var self = compilationUnit.TypeEnvironment.GetContextType(OwnMethodCall.SymbolTable);

            return(new ASTCILFuncVirtualCallNode(self,
                                                 OwnMethodCall.Method.Text,
                                                 new[] { new ASTCILSelfNode() }
                                                 .Concat(OwnMethodCall.Arguments.Select((param, i) =>
            {
                var exp = (ASTCILExpressionNode)param.Accept(this);
                ASTCILExpressionNode arg = exp;
                var coolMethod = compilationUnit.MethodEnvironment.GetMethod(self, OwnMethodCall.MethodName);
                if (coolMethod.GetParam(i) == compilationUnit.TypeEnvironment.Object && (param.SemanticCheckResult.Type == compilationUnit.TypeEnvironment.Int || param.SemanticCheckResult.Type == compilationUnit.TypeEnvironment.Bool))
                {
                    arg = new ASTCILBoxingNode(exp, param.SemanticCheckResult.Type);
                }
                return arg;
            }))));
        }
 public MipsProgram VisitExpression(ASTCILExpressionNode Expression) => Expression.Accept(this);
Exemple #5
0
 public ASTCILDivideTwoVariablesNode(ASTCILExpressionNode left, ASTCILExpressionNode right) : base()
 {
     Left  = left;
     Right = right;
 }