Example #1
0
 /// <summary>
 /// Evaluates the values of  argumants.
 /// </summary>
 private void GenerateArgs()
 {
     arg0.GenerateCode();
     ILTypeTranslator.GenerateImplicitCast(IL, arg0.Type, Type);
     arg1.GenerateCode();
     ILTypeTranslator.GenerateImplicitCast(IL, arg1.Type, Type);
 }
Example #2
0
        //

        /// <summary>
        /// Generates the code for function calling, before call this function must be called SetCallNode()
        /// </summary>
        public override void GenerateCode()
        {
            if (call == null)
            {
                throw new ArgumentException("You should before call SetCallNode() method");
            }

            int index = 0;

            foreach (Expression arg in call)
            {
                ILCodeObject argObject = generator.ExprEvaluator.Create(arg);
                argObject.GenerateCode();
                if (!system)
                {
                    try
                    {
                        ILTypeTranslator.GenerateImplicitCast(IL, argObject.Type, new TypeEntity(node.Args[index].Type));
                    }
                    catch (AnalizeException)
                    {
                        string message = string.Format("Function {0}, missing parameters type. Has \"{1}\" instead of \"{2}\"", node.Name, argObject.Type, new TypeEntity(node.Args[index].Type));
                        throw new AnalizeException(message, call);
                    }
                }
            }
            IL.Emit(OpCodes.Call, self);
            if (type == TypeEntity.Object && self.ReturnType.IsValueType) //post boxing
            {
                IL.Emit(OpCodes.Box, self.ReturnType);
            }
            call = null;
        }
Example #3
0
 /// <summary>
 /// Generates the IL code for <c>return</c> construction
 /// </summary>
 /// <param name="This">The [return] node.</param>
 void IStatementVisitor.Visit(ReturnStatement This)
 {
     if (This.Result == null)
     {
         if (generator.CurrentFunction.Type != TypeEntity.Void)
         {
             throw new AnalizeException("This function must return a value", This);
         }
     }
     else
     {
         try
         {
             ILCodeObject result = generator.ExprEvaluator.Create(This.Result);
             result.GenerateCode();
             ILTypeTranslator.GenerateImplicitCast(IL, result.Type, generator.CurrentFunction.Type);
         }
         catch (AnalizeException e)
         {
             throw new AnalizeException(e.Message, This);
         }
     }
     IL.Emit(OpCodes.Ret);
 }
Example #4
0
 public override void GenerateStore(CodeObject value)
 {
     value.GenerateCode();
     ILTypeTranslator.GenerateImplicitCast(IL, value.Type, Type);
     GenerateStore();
 }