Ejemplo n.º 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;
            }))));
        }
 public virtual T VisitStaticMethodCall(ASTStaticMethodCallNode MethodCall)
 {
     foreach (var item in MethodCall.Arguments)
     {
         item.Accept(this);
     }
     return(default(T));
 }
Ejemplo n.º 3
0
        public override SemanticCheckResult VisitStaticMethodCall(ASTStaticMethodCallNode MethodCall)
        {
            var onResult = MethodCall.InvokeOnExpresion.Accept(this);

            MethodCall.SemanticCheckResult.Ensure(!Types.IsSelfType(MethodCall.TypeName),
                                                  new Lazy <Error>(() => new Error($"Not Allowed {MethodCall.TypeName}", ErrorKind.SemanticError, MethodCall.Type.Line, MethodCall.Type.Column)));
            var isStaticDef = CompilationUnit.TypeEnvironment.GetTypeDefinition(MethodCall.TypeName, MethodCall.SymbolTable, out var staticType);

            MethodCall.SemanticCheckResult.Ensure(isStaticDef,
                                                  new Lazy <Error>(() => new Error($"Missing declaration for type {MethodCall.TypeName}.", ErrorKind.TypeError, MethodCall.Type.Line, MethodCall.Type.Column)));
            if (isStaticDef)
            {
                MethodCall.SemanticCheckResult.Ensure(onResult, onResult.Type.IsIt(staticType),
                                                      new Lazy <Error>(() => new Error($"Type {onResult.Type} does not inherot from type {staticType}.", ErrorKind.TypeError, MethodCall.Type.Line, MethodCall.Type.Line)));
            }

            var isMetDef = CompilationUnit.MethodEnvironment.GetMethodIfDef(staticType, MethodCall.MethodName, out var method);

            MethodCall.SemanticCheckResult.Ensure(isMetDef,
                                                  new Lazy <Error>(() => new Error($"Missing declaration of method {MethodCall.MethodName} on type {MethodCall.TypeName}.", ErrorKind.MethodError, MethodCall.Method.Line, MethodCall.Method.Column)));
            if (isMetDef)
            {
                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.SemanticError, 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.MethodError, MethodCall.Method.Line, MethodCall.Method.Column)));
                }

                var returntype = (method.ReturnType is SelfType) ?onResult.Type: method.ReturnType;
                MethodCall.SemanticCheckResult.EnsureReturnType(returntype);
            }
            return(MethodCall.SemanticCheckResult);
        }