示例#1
0
 internal ILTypeCast(ILCodeGenerator generator, TypeCast node)
 {
     this.generator = generator;
     this.node      = node;
     arg            = generator.ExprEvaluator.Create(node.InnerExpression);
     type           = new TypeEntity(node.CastingTypeNode);
 }
示例#2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:ILUnaryOperation"/> class.
 /// </summary>
 /// <param name="generator">The IL generator.</param>
 /// <param name="node">The node with this unary operation.</param>
 internal ILUnaryOperation(ILCodeGenerator generator, UnaryOperation node)
 {
     this.generator = generator;
     this.node      = node;
     arg            = generator.ExprEvaluator.Create(node.Arg);
     CheckType();
 }
示例#3
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;
        }
示例#4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:ILBinaryOperation"/> class.
 /// </summary>
 /// <param name="generator">The IL generator.</param>
 /// <param name="node">The node with this binary operation.</param>
 internal ILBinaryOperation(ILCodeGenerator generator, BinaryOperation node)
 {
     this.generator = generator;
     this.node      = node;
     arg0           = generator.ExprEvaluator.Create(node.Arg0);
     arg1           = generator.ExprEvaluator.Create(node.Arg1);
     CheckType();
 }
示例#5
0
        void IExpressionVisitor.Visit(Variable This)
        {
            string name = This.Name;

            result = GetNamedObject(This.Name);
            if (result == null || (!(result is ILGlobal || result is ILLocal || result is ILArgument)))
            {
                throw new AnalizeException("The variable " + name + " does not exist in the current context", This);
            }
        }
示例#6
0
        /// <summary>
        /// Generates the code for evaluate results of expression, and delete this result from the stack
        /// </summary>
        /// <param name="expression">The expression.</param>
        public void GenerateCodeWithoutResult(Expression expression)
        {
            if (expression == null)
            {
                return;
            }
            ILCodeObject expObj = Create(expression);

            expObj.GenerateCode();
            if (expObj.Type != TypeEntity.Void)
            {
                generator.CurrentIL.Emit(OpCodes.Pop);
            }
        }
示例#7
0
        void IExpressionVisitor.Visit(FunctionCall This)
        {
            string        name = This.Name;
            ILFunctionRef call = GetNamedObject(name) as ILFunctionRef;

            if (call == null)
            {
                call = ILFunctionRef.LookForDotNetMethod(generator, This);
            }
            if (call == null)
            {
                throw new AnalizeException("The function " + name + " does not exist in the current context (or have wrong signature)", This);
            }
            call.SetCallNode(This);
            result = call;
        }
示例#8
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);
 }
示例#9
0
 void IExpressionVisitor.Visit(TypeCast This)
 {
     result = new ILTypeCast(generator, This);
 }
示例#10
0
 void IExpressionVisitor.Visit(Const This)
 {
     result = new ILConst(generator, This);
 }
示例#11
0
 void IExpressionVisitor.Visit(UnaryOperation This)
 {
     result = new ILUnaryOperation(generator, This);
 }
示例#12
0
 /// <summary>
 /// Creates the specified expression (unary operation, binary operation, var & etc)
 /// by its node
 /// </summary>
 /// <param name="expression">The node of expression.</param>
 /// <returns>Codeobject for this expression</returns>
 public ILCodeObject Create(Expression expression)
 {
     result = null;
     expression.AcceptVisitor(this);
     return(result);
 }