2 using CodeGeneration.Operations;
6 namespace CodeGeneration.NewOperations
9 internal class CGArithmeticOperation<T> : NewOperations.CGBinaryOperation<T> where T :
ILCodeGenerator
18 protected override sealed
void LoadSecondOperand()
20 if (String.IsNullOrEmpty(label_op2))
22 this.node.SecondOperand.Accept(this.visitor, this.obj);
23 label_op2 =
"tempvar_" + this.codeGenerator.NewLabel;
25 this.codeGenerator.WriteAuxiliarLocalVariable(
this.indent, label_op2,
"object");
27 this.codeGenerator.WriteAuxiliarLocalVariable(this.indent, label_op2, this.node.SecondOperand.ILTypeExpression.ILType());
28 this.codeGenerator.stloc(this.indent, label_op2);
31 this.codeGenerator.ldloc(this.indent, label_op2);
38 label_result =
"tempvar_" + this.codeGenerator.NewLabel;
39 this.codeGenerator.WriteAuxiliarLocalVariable(this.indent, label_result, node.ExpressionType.ILType());
41 base.GenerateRightOperand(teLeft,teRight);
44 protected override UnionType GenerateAllUnionTypes()
47 unions.AddType(IntType.Instance);
48 unions.AddType(DoubleType.Instance);
49 unions.AddType(CharType.Instance);
51 unions.AddType(StringType.Instance);
63 bool isConcat =
false;
64 switch (arithmeticOperator)
66 case ArithmeticOperator.Minus:
67 this.codeGenerator.sub(this.indent);
69 case ArithmeticOperator.Plus:
73 this.codeGenerator.concat(this.indent);
76 this.codeGenerator.add(this.indent);
78 case ArithmeticOperator.Mult:
79 this.codeGenerator.mul(this.indent);
81 case ArithmeticOperator.Div:
82 this.codeGenerator.div(this.indent);
84 case ArithmeticOperator.Mod:
85 this.codeGenerator.rem(this.indent);
88 this.codeGenerator.Comment(
"ERROR");
92 this.codeGenerator.Box(indent, result);
93 if (!
string.IsNullOrEmpty(label_result))
95 this.codeGenerator.stloc(this.indent, label_result);
Encapsulates a binary expression of our programming language.
This class walks the AST to obtain the IL code.
TypeExpression ExpressionType
Gets or sets the type of the expression.
Encapsulates arithmetic binary expressions.
Abstract class that represents all different types.
Expression SecondOperand
Gets the second operand of the binary expression
ArithmeticOperator
Arithmetic binary operators