Example #1
0
        public static void TryToCastMethodParameters(MethodInvokationExpression method)
        {
            TableMethod tableMethod = GlobalTable.Table.FetchMethod(method.Name, method.GetParametersTypes());

            for (int i = 0; i < tableMethod.ArgCount; i++)
            {
                TryToCastExpression(method.Parameters[i].ParameterInstance, tableMethod.Arguments[i].Type);
            }
        }
Example #2
0
        public static void ResolveMethodInvokationStatementTypes(MethodInvokationStatement method)
        {
            TypeCaster.TryToCastMethodInvokationStatement(method);
            ReportErrors = true;
            MethodInvokationExpression methodInvokationExpression = (MethodInvokationExpression)method.Instance;

            foreach (ParameterDeclaration parameter in methodInvokationExpression.Parameters)
            {
                ResolveMethodParametersTypes(parameter);
            }
        }
Example #3
0
        public static void TryToCastMethodInvokation(MethodInvokationExpression method, InnerType toType)
        {
            SyntaxTreeNode parent = method.Parent;

            TryToCastMethodParameters(method);
            if (CanCast(method.ReturnType, toType, false))
            {
                CastCase   castCase   = DefineCastCase(method.ReturnType, toType);
                Expression castMethod = CreateCastMethod(parent, toType, new ParameterDeclaration[] { new ParameterDeclaration(method) }, castCase);
                Replace(parent, method, castMethod);
            }
        }
Example #4
0
 private static void EmitMethodInvokation(MethodInvokationExpression method, ILGenerator methodIL)
 {
     if (EmitBaseMethod(method, methodIL))
     {
         return;
     }
     if (GetCreatedExternalMethod(method.Name, CreateTypes(method.GetParametersTypes())) != null)
     {
         EmitExternalMethodInvokation(method, methodIL);
     }
     else
     {
         MethodInfo createdMethod = GetCreatedMethod(method.Name, CreateTypes(method.GetParametersTypes()));
         EmitMethodParameters(method.Parameters, methodIL);
         methodIL.EmitCall(OpCodes.Call, createdMethod, null);
     }
 }
Example #5
0
        private static bool EmitBaseMethod(MethodInvokationExpression method, ILGenerator methodIL)
        {
            switch (method.Name)
            {
            case "len":
                EmitExpression(method.Parameters[0].ParameterInstance, methodIL);
                methodIL.Emit(OpCodes.Ldlen);
                return(true);

            case "ToInt32":
            case "ToInt64":
            case "ToSingle":
                EmitExpression(method.Parameters[0].ParameterInstance, methodIL);
                methodIL.EmitCall(OpCodes.Call, typeof(Convert).GetMethod(method.Name, new Type[] { method.GetParametersTypes()[0].GetEquivalence() }), null);
                return(true);
            }
            return(false);
        }
Example #6
0
        private static Expression CreateCastMethod(SyntaxTreeNode parent, InnerType returnType, ParameterDeclaration[] parameters, CastCase castCase)
        {
            Expression castMethod;

            if (castCase != CastCase.NoNeedToCast && castCase != CastCase.Undefined)
            {
                castMethod = new MethodInvokationExpression(GetCastMethodName(castCase), parameters, parameters[0].SourceContext)
                {
                    ReturnType = returnType
                }
            }
            ;
            else
            {
                castMethod = parameters[0].ParameterInstance;
            }
            castMethod.Parent = parent;
            return(castMethod);
        }
Example #7
0
        public static void ResolveMethodsParametersTypes(MethodInvokationExpression method)
        {
            TableMethod tableMethod = GlobalTable.Table.FetchMethod(method.Name, method.GetParametersTypes());

            if (tableMethod == null)
            {
                return;
            }
            for (int i = 0; i < tableMethod.ArgCount; i++)
            {
                TableMethodArgument  tableArgument       = tableMethod.Arguments[i];
                ParameterDeclaration methodParameter     = method.Parameters[i];
                InnerType            methodParameterType = ResolveExpressionType(methodParameter.ParameterInstance);
                if (tableArgument.Type != methodParameterType)
                {
                    ReportError(new IncompatibleMethodParameterType(method.Name, tableArgument.Type, methodParameterType, methodParameter.SourceContext));
                }
            }
        }
Example #8
0
        private static void EmitExternalMethodInvokation(MethodInvokationExpression method, ILGenerator methodIL)
        {
            Type[] arguments = CreateTypes(method.GetParametersTypes());
            Type   type      = Type.GetType(GetExternalPackage(method.Name, arguments));

            EmitMethodParameters(method.Parameters, methodIL);
            if (type != null && type.GetMethod(method.Name, arguments) != null)
            {
                methodIL.EmitCall(OpCodes.Call, type.GetMethod(method.Name, arguments), null);
            }
            else
            if (type == null)
            {
                ConsoleCustomizer.ColorizedPrintln($"Error occurred when trying to find package \"{GetExternalPackage(method.Name, arguments)}\".", ConsoleColor.DarkRed);
            }
            else
            {
                ConsoleCustomizer.ColorizedPrintln($"No method [{method.Name}] with those type of arguments found in package \"{GetExternalPackage(method.Name, arguments)}\".", ConsoleColor.DarkRed);
            }
        }
Example #9
0
        public static void ResolveMethodInvokation(MethodInvokationExpression method, Table.Table table)
        {
            ResolveMethodParameters(method.Parameters, table);

            if (table.CheckMethod(method.Name, method.GetParametersTypes(), true))
            {
                TableMethod tableMethod = table.FetchMethod(method.Name, method.GetParametersTypes());
                for (int i = 0; i < method.ArgCount; i++)
                {
                    method.Parameters[i].Type = tableMethod.Arguments[i].Type;
                }
                method.ReturnType = tableMethod.ReturnType;
            }
            else
            if (table.IsMethodWithThisNameDeclared(method.Name))
            {
                ReportError(new MethodWithThoseArgumentsIsNotDeclared(method.Name, method.SourceContext));
            }
            else
            {
                ReportError(new MethodIsNotDeclared(method.Name, method.SourceContext));
            }
        }
Example #10
0
 public static InnerType ResolveMethodInvokationExpressionType(MethodInvokationExpression methodInvokation)
 {
     ResolveMethodsParametersTypes(methodInvokation);
     return(methodInvokation.ReturnType);
 }