예제 #1
0
        public override SemanticCheckResult VisitOwnMethodCall(ASTOwnMethodCallNode OwnMethodCall)
        {
            var selfcooltype = CompilationUnit.TypeEnvironment.GetContextType(OwnMethodCall.SymbolTable);
            var isdef        = CompilationUnit.MethodEnvironment.GetMethodIfDef(selfcooltype, OwnMethodCall.MethodName, out var method);

            OwnMethodCall.SemanticCheckResult.Ensure(isdef,
                                                     new Lazy <Error>(() => new Error($"Missing declaration for method {OwnMethodCall.MethodName} on type {CompilationUnit.TypeEnvironment.GetContextType(OwnMethodCall.SymbolTable)}.",
                                                                                      ErrorKind.MethodError, OwnMethodCall.Method.Line, OwnMethodCall.Method.Column)));
            if (isdef)
            {
                OwnMethodCall.SemanticCheckResult.Ensure(method.EnsureParametersCount(OwnMethodCall.Arguments.Length),
                                                         new Lazy <Error>(() => new Error($"Mismatch parameters and argument count. Expected {method.CountParams} and provided {OwnMethodCall.Arguments.Length}",
                                                                                          ErrorKind.MethodError, OwnMethodCall.Method.Line, OwnMethodCall.Method.Column)));

                for (int i = 0; i < OwnMethodCall.Arguments.Length; i++)
                {
                    var r = OwnMethodCall.Arguments[i].Accept(this);
                    OwnMethodCall.SemanticCheckResult.Ensure(r, r.Type.IsIt(method.GetParam(i)),
                                                             new Lazy <Error>(() => new Error($"Paremeter {i} type mismatch. Type {r.Type} does not inherit from type {method.GetParam(i)}.",
                                                                                              ErrorKind.MethodError, OwnMethodCall.Method.Line, OwnMethodCall.Method.Column)));
                }
                var returntype = (method.ReturnType is SelfType) ? CompilationUnit.TypeEnvironment.SelfType(OwnMethodCall.SymbolTable) : method.ReturnType;
                OwnMethodCall.SemanticCheckResult.EnsureReturnType(returntype);
            }
            return(OwnMethodCall.SemanticCheckResult);
        }
 public virtual T VisitOwnMethodCall(ASTOwnMethodCallNode OwnMethodCall)
 {
     foreach (var item in OwnMethodCall.Arguments)
     {
         item.Accept(this);
     }
     return(default(T));
 }
예제 #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;
            }))));
        }