/// <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); }
// /// <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; }
public override void GenerateCode() { arg.GenerateCode(); try { ILTypeTranslator.GenerateExplicitCast(IL, arg.Type, type); } catch (AnalizeException e) { throw new AnalizeException(e.Message, node); } }
/// <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); } }
void IUnaryOperationVisitor.Visit(opUnaryMinus This) { if (checkType) { if (!arg.Type.IsNumeric) { throw new AnalizeException("Can't apply unary minus to nonnumeric type", This); } type = arg.Type; return; } arg.GenerateCode(); IL.Emit(OpCodes.Neg); }
/// <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); }