コード例 #1
0
        public override SemanticCheckResult VisitDynamicMethodCall(ASTDynamicMethodCallNode MethodCall)
        {
            var onResult = MethodCall.InvokeOnExpresion.Accept(this);

            MethodCall.SemanticCheckResult.Ensure(onResult);

            var isdef = CompilationUnit.MethodEnvironment.GetMethodIfDef(onResult.Type, MethodCall.MethodName, out var method);

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

                for (int i = 0; i < MethodCall.Arguments.Length; i++)
                {
                    var r = MethodCall.Arguments[i].Accept(this);
                    MethodCall.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.TypeError, MethodCall.Method.Line, MethodCall.Method.Column)));
                }

                var returntype = (method.ReturnType is SelfType) ? onResult.Type : method.ReturnType;
                MethodCall.SemanticCheckResult.EnsureReturnType(returntype);
            }
            return(MethodCall.SemanticCheckResult);
        }
コード例 #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));
        }
 public virtual T VisitDynamicMethodCall(ASTDynamicMethodCallNode MethodCall)
 {
     MethodCall.InvokeOnExpresion.Accept(this);
     foreach (var item in MethodCall.Arguments)
     {
         item.Accept(this);
     }
     return(default(T));
 }