20 using System.Collections.Generic;
23 using CodeGeneration.Operations;
24 using TypeSystem.Operations;
26 namespace CodeGeneration {
34 abstract class VisitorILCodeGeneration<T> : VisitorCodeGeneration<T> where T :
ILCodeGenerator {
40 private List<FieldDefinition>[] fields;
57 private static String GetAuxFielVar()
59 return auxFieldVar + (auxFieldVarNumber++) +
"_";
65 private const string auxFieldVar =
"v_local_field_temp_";
70 private static int auxFieldVarNumber = 0;
75 private const string auxSwitchCond =
"v_local_condition_temp_";
79 private int namespaceDepth = 0;
91 this.codeGenerator.WriteHeader(moduleName);
94 auxFieldVarNumber = 0;
105 this.codeGenerator.Close();
110 #region AddExceptionCode()
116 this.codeGenerator.WriteCodeOfExceptions();
123 #region Visit(SourceFile node, Object obj)
126 this.codeGenerator.InitialComment();
128 foreach (
string key
in node.Namespacekeys) {
129 int count = node.GetNamespaceDefinitionCount(key);
130 for (
int i = 0; i < count; i++)
131 node.GetNamespaceDeclarationElement(key, i).Accept(
this, obj);
133 for (
int i = 0; i < node.DeclarationCount; i++)
134 node.GetDeclarationElement(i).Accept(
this, obj);
141 #region Visit(Namespace node, Object obj)
144 this.namespaceDepth++;
145 this.codeGenerator.WriteNamespaceHeader(this.indent++, node.Identifier.Identifier);
146 for (
int i = 0; i < node.NamespaceMembersCount; i++)
149 this.codeGenerator.WriteEndOfBlock(--this.indent);
150 this.namespaceDepth--;
156 #region Visit(ClassDefinition node, Object obj)
159 this.constantsTable.Set();
162 node.TypeExpr.AcceptOperation(
new CGClassDefinitionStartOperation<T>(this.codeGenerator, this.indent, node), null);
165 for (
int i = 0; i < node.MemberCount; i++)
168 if (this.fields[0].Count != 0)
171 if (this.fields[1].Count != 0)
174 this.codeGenerator.WriteEndOfClass(--this.indent, node.FullName);
175 this.constantsTable.Reset();
181 #region Visit(InterfaceDefinition node, Object obj)
184 node.TypeExpr.AcceptOperation(
new CGInterfaceDefinitionStartOperation<T>(this.codeGenerator, this.indent, node), null);
187 for (
int i = 0; i < node.MemberCount; i++)
190 this.codeGenerator.WriteEndOfInterface(--this.indent, node.FullName);
197 #region Visit(FieldDeclaration node, Object obj)
200 return node.TypeExpr.AcceptOperation(
new CGProcessFieldOperation<T>(this.codeGenerator, this.indent, node,
false, obj), null);
205 #region Visit(FieldDefinition node, Object obj)
208 return node.TypeExpr.AcceptOperation(
new CGProcessFieldOperation<T>(this.codeGenerator, this.indent, node,
false, obj), null);
213 #region Visit(ConstantFieldDefinition node, Object obj)
216 node.TypeExpr.AcceptOperation(
new CGProcessFieldOperation<T>(this.codeGenerator, this.indent, node,
true, obj), null);
217 node.Init.ILTypeExpression.AcceptOperation(
new CGConstantFieldDefinitionInitializationOperation<T>(this.codeGenerator, node, obj), null);
218 this.constantsTable.Insert(node.Identifier, node.Init);
225 #region Visit(MethodDeclaration node, Object obj)
228 node.TypeExpr.AcceptOperation(
new CGProcessMethodOperation<T>(this.codeGenerator, this.indent, node, obj), null);
230 this.codeGenerator.WriteStartBlock(this.indent);
231 this.codeGenerator.WriteEndOfBlock(this.indent);
237 #region Visit(MethodDefinition node, Object obj)
242 node.TypeExpr.AcceptOperation(
new CGProcessMethodOperation<T>(this.codeGenerator, this.indent, node, obj), null);
243 this.codeGenerator.WriteStartBlock(this.indent++);
244 this.codeGenerator.WriteEndOfMethod(--this.indent, ((
MethodType)node.TypeExpr).MemberInfo.MemberIdentifier);
248 this.constantsTable.Set();
249 auxFieldVarNumber = 0;
251 node.TypeExpr.AcceptOperation(
new CGProcessMethodOperation<T>(this.codeGenerator, this.indent, node, obj), null);
252 this.codeGenerator.WriteStartBlock(this.indent++);
253 if (node.IsEntryPoint)
254 this.codeGenerator.WriteEntryPoint(this.indent);
258 this.ProcessLocalVars(decls);
259 this.codeGenerator.WriteLocalVariable(this.indent);
266 this.codeGenerator.ret(this.indent--);
267 this.codeGenerator.WriteEndOfMethod(this.indent, ((
MethodType)node.TypeExpr).MemberInfo.MemberIdentifier);
268 this.constantsTable.Reset();
275 #region Visit(ConstructorDefinition node, Object obj)
278 this.constantsTable.Set();
279 auxFieldVarNumber = 0;
281 node.TypeExpr.AcceptOperation(
new CGProcessMethodOperation<T>(this.codeGenerator, this.indent, node, obj), null);
282 this.codeGenerator.WriteStartBlock(this.indent++);
286 this.WriteInitStaticFields(
new InheritedAttributes(node,
false, null,
false, null,
false));
289 this.codeGenerator.ldarg(this.indent, 0);
290 if (node.Initialization != null)
291 node.Initialization.Accept(
this,
new InheritedAttributes(node,
false, null,
false, null,
false));
294 this.codeGenerator.constructorCall(this.indent, ((
ClassType)((
MethodType)node.TypeExpr).MemberInfo.Class).BaseClass,
".ctor");
299 this.ProcessLocalVars(decls);
300 this.codeGenerator.WriteLocalVariable(this.indent);
304 this.codeGenerator.ret(this.indent--);
305 this.codeGenerator.WriteEndOfMethod(this.indent, ((
MethodType)node.TypeExpr).MemberInfo.MemberIdentifier);
307 this.constantsTable.Reset();
314 #region WriteInitFields()
316 private void WriteInitFields(Object obj) {
318 for (
int i = 0; i < this.fields[0].Count; i++) {
320 if (o is List<IdDeclaration>)
321 this.ProcessLocalVars((List<IdDeclaration>)o);
324 this.codeGenerator.WriteLocalVariable(this.indent);
326 for (
int i = 0; i < this.fields[0].Count; i++) {
327 this.codeGenerator.ldarg(this.indent, 0);
328 this.fields[0][i].Init.Accept(
this, obj);
329 this.codeGenerator.stfld(this.indent, this.fields[0][i].TypeExpr, ((
FieldType)this.fields[0][i].TypeExpr).MemberInfo.Class.FullName, this.fields[0][i].Identifier);
331 this.fields[0].Clear();
336 #region WriteInitStaticFields()
338 private void WriteInitStaticFields(Object obj) {
340 for (
int i = 0; i < this.fields[1].Count; i++) {
341 o = this.fields[1][i].Init.Accept(
new VisitorCodeGeneration2(), null);
342 if (o is List<IdDeclaration>)
343 this.ProcessLocalVars((List<IdDeclaration>)o);
346 this.codeGenerator.WriteLocalVariable(this.indent);
348 for (
int i = 0; i < this.fields[1].Count; i++) {
349 this.fields[1][i].Init.Accept(
this, obj);
350 this.codeGenerator.Promotion(this.indent, this.fields[1][i].Init.ExpressionType, this.fields[1][i].Init.ILTypeExpression, this.fields[1][i].TypeExpr, this.fields[1][i].TypeExpr,
false,
false);
351 this.codeGenerator.stsfld(this.indent, this.fields[1][i].TypeExpr, ((
FieldType)this.fields[1][i].TypeExpr).MemberInfo.Class.FullName, this.fields[1][i].Identifier);
353 this.fields[1].Clear();
358 #region AddConstructor()
360 private void AddConstructor(
ClassType classType, Object obj) {
361 this.codeGenerator.WriteConstructorHeader(this.indent);
362 this.codeGenerator.WriteStartBlock(this.indent++);
363 this.WriteInitFields(obj);
364 this.codeGenerator.ldarg(this.indent, 0);
365 this.codeGenerator.constructorCall(this.indent, classType.BaseClass,
".ctor");
366 this.codeGenerator.ret(this.indent--);
368 this.codeGenerator.WriteEndOfMethod(this.indent, classType.Name);
373 #region AddStaticConstructor()
375 private void AddStaticConstructor(
ClassType classType, Object obj) {
376 this.codeGenerator.WriteStaticConstructorHeader(this.indent);
377 this.codeGenerator.WriteStartBlock(this.indent++);
378 this.WriteInitStaticFields(obj);
379 this.codeGenerator.ret(this.indent--);
380 this.codeGenerator.WriteEndOfMethod(this.indent, classType.Name);
401 #region CheckMakeAnUnbox()
403 internal bool CheckMakeAnUnbox(
Expression exp) {
405 exp = ((ArgumentExpression)exp).Argument;
406 return (
bool)exp.AcceptOperation(
new AST.Operations.CheckMakeAnUnboxOperation(), null);
411 #region Visit(Definition node, Object obj)
431 return node.AcceptOperation(
new CGVisitDefinitionNodeOperation<T>(
this, node, this.codeGenerator, this.indent, obj), null);
437 #region Visit(ConstantDefinition node, Object obj)
440 return this.constantsTable.Insert(node.Identifier, node.Init);
445 #region ProcessLocalVars()
447 private void ProcessLocalVars(List<IdDeclaration> decls) {
449 for (
int i = 0; i < decls.Count; i++)
450 this.codeGenerator.AddLocalVariable(decls[i].ILName, decls[i].ILTypeExpression);
468 #region Visit(ArithmeticExpression node, Object obj)
473 t1.AcceptOperation(
new NewOperations.CGArithmeticOperation<T>(
this, obj, this.indent, node), null);
479 #region Visit(BitwiseExpression node, Object obj)
483 t1.AcceptOperation(
new NewOperations.CGBitwiseOperation<T>(
this, obj, this.indent, node), null);
489 #region Visit(LogicalExpression node, Object obj)
492 string label0 = this.codeGenerator.NewLabel;
493 string label1 = this.codeGenerator.NewLabel;
495 node.FirstOperand.Accept(
this, obj);
497 this.codeGenerator.Promotion(this.indent, node.FirstOperand.ExpressionType, node.FirstOperand.ILTypeExpression, node.ExpressionType, node.ExpressionType,
true, CheckMakeAnUnbox(node.
FirstOperand));
500 case LogicalOperator.Or:
501 this.codeGenerator.brtrue(this.indent, label0);
503 case LogicalOperator.And:
504 this.codeGenerator.brfalse(this.indent, label0);
510 node.SecondOperand.Accept(
this, obj);
512 this.codeGenerator.Promotion(this.indent, node.SecondOperand.ExpressionType, node.SecondOperand.ILTypeExpression, node.ExpressionType, node.ExpressionType,
true, CheckMakeAnUnbox(node.
SecondOperand));
514 this.codeGenerator.br(this.indent, label1);
515 this.codeGenerator.WriteLabel(this.indent, label0);
518 case LogicalOperator.Or:
519 this.codeGenerator.ldci4(this.indent, 1);
521 case LogicalOperator.And:
522 this.codeGenerator.ldci4(this.indent, 0);
528 this.codeGenerator.WriteLabel(this.indent, label1);
534 #region Visit(RelationalExpression node, Object obj)
538 t1.AcceptOperation(
new NewOperations.CGRelationalOperation<T>(
this, obj, this.indent, node), null);
544 #region Visit(TernaryExpression node, Object obj)
566 string label0 = this.codeGenerator.NewLabel;
567 string label1 = this.codeGenerator.NewLabel;
569 node.FirstOperand.Accept(
this, obj);
570 this.codeGenerator.Promotion(this.indent, node.FirstOperand.ExpressionType, node.FirstOperand.ILTypeExpression, BoolType.Instance, BoolType.Instance,
true, CheckMakeAnUnbox(node.
FirstOperand));
572 this.codeGenerator.brtrue(this.indent, label0);
574 node.ThirdOperand.Accept(
this, obj);
575 this.codeGenerator.Promotion(this.indent, node.ThirdOperand.ExpressionType, node.ThirdOperand.ILTypeExpression, node.ExpressionType, node.ExpressionType,
true, CheckMakeAnUnbox(node.
ThirdOperand));
576 this.codeGenerator.br(this.indent, label1);
578 this.codeGenerator.WriteLabel(this.indent, label0);
579 node.SecondOperand.Accept(
this, obj);
580 this.codeGenerator.Promotion(this.indent, node.SecondOperand.ExpressionType, node.SecondOperand.ILTypeExpression, node.ExpressionType, node.ExpressionType,
true, CheckMakeAnUnbox(node.
SecondOperand));
582 this.codeGenerator.WriteLabel(this.indent, label1);
589 #region Visit(UnaryExpression node, Object obj)
592 return node.Operand.ILTypeExpression.AcceptOperation(
new NewOperations.CGUnaryOperation<T>(
this, obj, this.indent, node), null);
597 #region Visit(AssignmentExpression node, Object obj)
603 node.SecondOperand.Accept(
this, obj);
606 TypeExpression certainType1 = node.SecondOperand.ILTypeExpression;
611 typeExp2 = TypeVariable.NewTypeVariable;
612 certainType2 = TypeVariable.NewTypeVariable;
616 typeExp1 = TypeVariable.NewTypeVariable;
617 certainType1 = TypeVariable.NewTypeVariable;
619 this.codeGenerator.Promotion(this.indent, typeExp1, certainType1, typeExp2, certainType2,
true, CheckMakeAnUnbox(node.
SecondOperand));
623 this.codeGenerator.dup(this.indent);
624 bool introspectiveAssignation =
false;
627 FieldAccessExpression fieldAccessExpression = (FieldAccessExpression) node.
FirstOperand;
631 introspectiveAssignation = case1 || case2 || case3;
632 if (introspectiveAssignation)
635 if(!introspectiveAssignation)
636 this.WriteStoreInstruction(sa, ia.CurrentMethod);
640 node.MoveStat.Accept(
this, obj);
647 #region WriteStoreInstruction()
661 t = idToStore.IdSymbol.SymbolType;
665 this.codeGenerator.stsfld(this.indent, fieldType.FieldTypeExpression, fieldType.MemberInfo.Class.FullName, idToStore.Identifier);
667 string id = GetAuxFielVar() + idToStore.Identifier;
671 this.codeGenerator.WriteAuxiliarLocalVariable(
this.indent,
id,
"object");
673 this.codeGenerator.WriteAuxiliarLocalVariable(this.indent, id, ((ClassTypeProxy)fieldType.
FieldTypeExpression).RealType.ILType());
675 this.codeGenerator.WriteAuxiliarLocalVariable(this.indent, id, fieldType.FieldTypeExpression.ILType());
676 this.codeGenerator.stloc(this.indent, id);
678 this.codeGenerator.stfld(this.indent, fieldType.FieldTypeExpression, fieldType.MemberInfo.Class.FullName, idToStore.Identifier);
680 this.codeGenerator.ldloc(this.indent, id);
685 string id = GetAuxFielVar() + idToStore.Identifier;
688 this.codeGenerator.WriteAuxiliarLocalVariable(this.indent, id, idToStore.ILTypeExpression.ILType());
689 this.codeGenerator.stloc(this.indent, id);
692 this.codeGenerator.CallVirt(this.indent, (PropertyType)idToStore.
ILTypeExpression, ((PropertyType)idToStore.ILTypeExpression).MemberInfo.Class, idToStore.
Identifier,
true);
695 this.codeGenerator.ldloc(this.indent, id);
697 this.codeGenerator.Call(this.indent, (PropertyType)idToStore.
ILTypeExpression, ((PropertyType)idToStore.ILTypeExpression).MemberInfo.Class, idToStore.
Identifier,
true);
700 this.codeGenerator.starg(this.indent, idToStore.ILName);
703 this.codeGenerator.stloc(this.indent, idToStore.ILName);
708 string id = GetAuxFielVar();
712 this.codeGenerator.stloc(this.indent, id);
715 codeGenerator.Box(this.indent, sa.Identifier.ExpressionType);
718 if (sa.CreateAuxiliarVar)
719 this.codeGenerator.ldloc(this.indent,
id);
725 #region writeStoreArrayElement()
729 reference = ((FieldType)reference).FieldTypeExpression;
731 type.
AcceptOperation(
new CGStoreArrayElementOperation<T>(
this.codeGenerator,
this.indent), null);
735 UnionType unionType = (UnionType)reference;
736 foreach (var singleType
in unionType.
TypeSet)
738 if (singleType.IsValueType())
740 type.AcceptOperation(
new CGStoreArrayElementOperation<T>(this.codeGenerator, this.indent), null);
744 if (singleType is FieldType)
746 writeStoreArrayElement(singleType, type);
752 TypeVariable.NewTypeVariable.AcceptOperation(
new CGStoreArrayElementOperation<T>(this.codeGenerator, this.indent), null);
755 type.AcceptOperation(
new CGStoreArrayElementOperation<T>(this.codeGenerator, this.indent), null);
758 IndexerCall(reference,
"set_Item");
763 #region writeLoadArrayElement()
768 reference = ((FieldType)reference).FieldTypeExpression;
770 type.
AcceptOperation(
new CGLoadArrayElementOperation<T>(
this.codeGenerator,
this.indent), null);
771 else if(reference is UnionType)
774 UnionType unionType = (UnionType) reference;
775 foreach (var singleType
in unionType.
TypeSet)
777 if (singleType.IsValueType())
779 type.AcceptOperation(
new CGLoadArrayElementOperation<T>(this.codeGenerator, this.indent), null);
783 if (singleType is FieldType)
785 writeLoadArrayElement(singleType, type);
791 TypeVariable.NewTypeVariable.AcceptOperation(
new CGLoadArrayElementOperation<T>(this.codeGenerator, this.indent), null);
794 type.AcceptOperation(
new CGLoadArrayElementOperation<T>(this.codeGenerator, this.indent), null);
796 type.AcceptOperation(
new CGLoadArrayElementOperation<T>(this.codeGenerator, this.indent), null);
799 IndexerCall(reference,
"get_Item");
806 private void IndexerCall(
TypeExpression reference,
string memberId) {
808 if (bclClass != null)
809 if (bclClass.
Methods.ContainsKey(memberId)) {
811 string[] args =
new string[method.ParameterListCount];
812 for (
int i = 0; i < method.ParameterListCount; i++)
815 this.codeGenerator.CallVirt(this.indent,
"instance ", method.Return.ILType(), reference.
ILType(), memberId, args);
821 #region Visit(CastExpression node, Object obj)
824 node.Expression.Accept(
this, obj);
833 if (node.
CastType.
IsValueType() && NewOperations.CGCastOperation<T>.IsInternallyAnObject(node.Expression.ExpressionType))
834 node.Expression.ExpressionType.AcceptOperation(
new NewOperations.CGCastOperation<T>(this.codeGenerator, this.indent), node.
CastType);
836 this.codeGenerator.UnboxAny(indent, node.CastType);
838 node.CastType.AcceptOperation(
new NewOperations.CGCastOperation<T>(this.codeGenerator, this.indent), node.
CastType);
841 this.codeGenerator.Box(indent, node.
CastType);
847 #region Visit(IsExpression node, Object obj)
850 node.Expression.Accept(
this, obj);
851 this.codeGenerator.isinst(this.indent, node.TypeExpr);
857 #region Visit(NewExpression node, Object obj)
860 Object objArgs = obj;
864 if (actualMethodCalled != null)
867 node.Arguments.Accept(
this, objArgs);
868 this.codeGenerator.newobj(this.indent, actualMethodCalled, node.NewType,
".ctor");
874 this.codeGenerator.WriteThrowMissingMethodException(this.indent, method);
877 #region Visit(NewArrayExpression node, Object obj)
883 node.Size.Accept(
this, iA);
887 this.codeGenerator.Promotion(this.indent, node.Size.ExpressionType, node.Size.ILTypeExpression, IntType.Instance, IntType.Instance,
true, CheckMakeAnUnbox(node.
Size));
891 this.codeGenerator.stloc(this.indent, node.Identifier);
893 if (node.
Init != null)
894 for (
int i = 0; i < node.Init.ExpressionCount; i++) {
896 this.codeGenerator.ldloc(this.indent, node.Identifier);
897 this.codeGenerator.ldci4(this.indent, i);
898 node.Init.GetExpressionElement(i).Accept(
this, obj);
904 this.codeGenerator.ldloc(this.indent, node.Identifier);
918 #region Visit(ArrayAccessExpression node, Object obj)
924 node.FirstOperand.Accept(
this, o);
925 node.SecondOperand.Accept(
this, o);
926 TypeExpression indexTypeExpression = node.SecondOperand.ExpressionType;
928 codeGenerator.UnboxAny(this.indent,IntType.Instance);
929 else if (indexTypeExpression is UnionType)
930 codeGenerator.UnboxAny(this.indent, IntType.Instance);
936 reference = ((FieldType)reference).FieldTypeExpression;
939 if (bclClass.Methods.ContainsKey(
"get_Item")) {
942 this.codeGenerator.Promotion(this.indent, node.SecondOperand.ExpressionType, node.SecondOperand.ILTypeExpression, method.GetParameter(0), method.
GetParameter(0),
true, CheckMakeAnUnbox(node.
SecondOperand));
947 this.codeGenerator.Promotion(this.indent, node.SecondOperand.ExpressionType, node.SecondOperand.ILTypeExpression, IntType.Instance, IntType.Instance,
true, CheckMakeAnUnbox(node.
SecondOperand));
959 #region Visit(FieldAccessExpression node, Object obj)
963 foreach (var typeExpression
in ut.TypeSet)
964 if (!(typeExpression is PropertyType))
971 foreach (var typeExpression
in ut.TypeSet)
975 if ((typeExpression as TypeVariable).Substitution != null)
981 private bool UnionTypeContainsField(UnionType unionType)
983 foreach (var typeExpression
in unionType.
TypeSet)
985 if (typeExpression is FieldType)
995 Object o = node.Expression.Accept(
this, objLeft);
1004 this.CallProperty(propertyType, propertyType.MemberInfo.Class, ia, o);
1008 UnionType unionType = node.ILTypeExpression as UnionType;
1009 node.FieldName.Accept(
this, objRight);
1010 string endLabel = this.codeGenerator.NewLabel;
1013 for (
int i = 0; i < unionType.Count; i++) {
1014 PropertyType propertyType = TypeExpression.As<PropertyType>(unionType.TypeSet[i]);
1016 if (actualClass != null) {
1017 string nextPropertyLabel = this.codeGenerator.NewLabel;
1021 this.codeGenerator.dup(this.indent);
1022 this.codeGenerator.isinst(this.indent, actualClass);
1023 this.codeGenerator.brfalse(this.indent, nextPropertyLabel);
1025 if (actualClass.IsValueType())
1026 this.codeGenerator.Unbox(
this.indent, actualClass);
1028 this.CallProperty(propertyType, actualClass, ia, o);
1029 this.codeGenerator.br(this.indent, endLabel);
1031 this.codeGenerator.WriteLabel(this.indent, nextPropertyLabel);
1035 this.ThrowMissingMethodException(node.ILTypeExpression.ILType());
1037 this.codeGenerator.WriteLabel(this.indent, endLabel);
1043 node.FieldName.Accept(
this, objRight);
1050 this.InstrospectiveFieldInvocation(node.Expression, node.FieldName.Identifier, objLeft);
1052 this.InstrospectiveFieldInvocation(node.Expression, node.FieldName.Identifier, objLeft);
1054 this.InstrospectiveFieldInvocation(node.Expression, node.FieldName.Identifier, objLeft);
1059 String finalLabel = this.codeGenerator.NewLabel;
1060 String nextLabel =
"";
1061 UnionType unionType = node.FieldName.ExpressionType as UnionType;
1062 for (
int i = 0; i < unionType.TypeSet.Count; i++)
1064 if (i != unionType.
TypeSet.Count - 1 && unionType.
TypeSet[i] is FieldType)
1066 if (!String.IsNullOrEmpty(nextLabel))
1067 this.codeGenerator.WriteLabel(indent, nextLabel);
1068 nextLabel = this.codeGenerator.NewLabel;
1069 this.codeGenerator.dup(indent);
1070 this.codeGenerator.isinst(indent, ((FieldType)unionType.
TypeSet[i]).MemberInfo.Class);
1071 this.codeGenerator.brfalse(indent, nextLabel);
1073 this.codeGenerator.br(indent, finalLabel);
1075 else if (i == unionType.
TypeSet.Count - 1)
1077 if (!String.IsNullOrEmpty(nextLabel))
1078 this.codeGenerator.WriteLabel(indent, nextLabel);
1079 this.InstrospectiveFieldInvocation(node.Expression, node.FieldName.Identifier, objLeft);
1080 this.codeGenerator.WriteLabel(indent, finalLabel);
1086 node.FieldName.Accept(
this, objRight);
1096 Object oAux = node.FieldName.Accept(
this, objRight);
1101 SynthesizedAttributes sa =
new SynthesizedAttributes(((SynthesizedAttributes) oAux).Identifier);
1102 sa.IdentifierExpressionMode = ((SynthesizedAttributes) o).IdentifierExpressionMode;
1126 private void CallProperty(PropertyType propertyType,
TypeExpression klass, InheritedAttributes ia, Object o) {
1127 if (o is SynthesizedAttributes && ((SynthesizedAttributes)o).IdentifierExpressionMode ==
IdentifierMode.Instance)
1128 this.codeGenerator.CallVirt(this.indent, propertyType, klass, propertyType.MemberInfo.MemberIdentifier, ia.Assignment);
1130 this.codeGenerator.Call(this.indent, propertyType, klass, propertyType.MemberInfo.MemberIdentifier, ia.Assignment);
1132 if (ia.MessagePassed && propertyType.PropertyTypeExpression.IsValueType())
1133 this.LoadAuxiliarVariable(propertyType.PropertyTypeExpression.ILType());
1138 #region InstrospectiveFieldInvocation()
1146 private void InstrospectiveFieldInvocation(
Expression node,
string memberName, Object obj) {
1147 this.codeGenerator.CallVirt(this.indent,
"instance class",
"[mscorlib]System.Type",
"[mscorlib]System.Object",
"GetType", null);
1148 this.codeGenerator.ldstr(this.indent, memberName);
1149 this.codeGenerator.CallVirt(this.indent,
"instance class",
"[mscorlib]System.Reflection.FieldInfo",
"[mscorlib]System.Type",
"GetField",
new string[] {
"string" });
1150 String
property = this.codeGenerator.NewLabel;
1151 String fin = this.codeGenerator.NewLabel;
1152 this.codeGenerator.dup(this.indent);
1153 this.codeGenerator.brfalse(this.indent, property);
1154 node.Accept(
this, obj);
1155 this.codeGenerator.CallVirt(this.indent,
"instance",
"object",
"[mscorlib]System.Reflection.FieldInfo",
"GetValue",
new string[] {
"object" });
1156 this.codeGenerator.br(this.indent,fin);
1157 this.codeGenerator.WriteLabel(this.indent,property);
1158 this.codeGenerator.pop(this.indent);
1159 node.Accept(
this, obj);
1160 this.codeGenerator.CallVirt(this.indent,
"instance class",
"[mscorlib]System.Type",
"[mscorlib]System.Object",
"GetType", null);
1161 this.codeGenerator.ldstr(this.indent, memberName);
1162 this.codeGenerator.CallVirt(this.indent,
"instance class",
"[mscorlib]System.Reflection.PropertyInfo",
"[mscorlib]System.Type",
"GetProperty",
new string[] {
"string" });
1163 this.codeGenerator.CallVirt(this.indent,
"instance class",
"[mscorlib]System.Reflection.MethodInfo",
"[mscorlib]System.Reflection.PropertyInfo",
"GetGetMethod",
new string[] {});
1164 node.Accept(
this, obj);
1165 this.codeGenerator.ldnull(this.indent);
1166 this.codeGenerator.CallVirt(this.indent,
"instance",
"object",
"[mscorlib]System.Reflection.MethodBase",
"Invoke",
new string[] {
"object",
"object[]" });
1167 this.codeGenerator.WriteLabel(this.indent, fin);
1171 #region InstrospectiveFieldInvocation()
1173 private void InstrospectiveFieldAssignation(
Expression node,
string memberName, Object obj)
1175 string id = GetAuxFielVar() + memberName;
1176 this.codeGenerator.WriteAuxiliarLocalVariable(this.indent, id,
"object");
1177 this.codeGenerator.stloc(this.indent, id);
1178 this.codeGenerator.pop(this.indent);
1179 node.Accept(
this, obj);
1180 this.codeGenerator.CallVirt(this.indent,
"instance class",
"[mscorlib]System.Type",
"[mscorlib]System.Object",
"GetType", null);
1181 this.codeGenerator.ldstr(this.indent, memberName);
1182 this.codeGenerator.CallVirt(this.indent,
"instance class",
"[mscorlib]System.Reflection.FieldInfo",
"[mscorlib]System.Type",
"GetField",
new string[] {
"string" });
1183 String
property = this.codeGenerator.NewLabel;
1184 String fin = this.codeGenerator.NewLabel;
1185 this.codeGenerator.dup(this.indent);
1186 this.codeGenerator.brfalse(this.indent, property);
1187 node.Accept(
this, obj);
1188 this.codeGenerator.ldloc(this.indent, id);
1189 this.codeGenerator.CallVirt(this.indent,
"instance",
"void",
"[mscorlib]System.Reflection.FieldInfo",
"SetValue",
new string[] {
"object",
"object" });
1190 this.codeGenerator.br(this.indent, fin);
1191 this.codeGenerator.WriteLabel(this.indent, property);
1192 this.codeGenerator.pop(this.indent);
1193 node.Accept(
this, obj);
1194 this.codeGenerator.CallVirt(this.indent,
"instance class",
"[mscorlib]System.Type",
"[mscorlib]System.Object",
"GetType", null);
1195 this.codeGenerator.ldstr(this.indent, memberName);
1196 this.codeGenerator.CallVirt(this.indent,
"instance class",
"[mscorlib]System.Reflection.PropertyInfo",
"[mscorlib]System.Type",
"GetProperty",
new string[] {
"string" });
1197 this.codeGenerator.CallVirt(this.indent,
"instance class",
"[mscorlib]System.Reflection.MethodInfo",
"[mscorlib]System.Reflection.PropertyInfo",
"GetSetMethod",
new string[] { });
1198 node.Accept(
this, obj);
1199 this.codeGenerator.ldci4(this.indent,1);
1200 this.codeGenerator.newarr(this.indent,
"object");
1201 this.codeGenerator.dup(this.indent);
1202 this.codeGenerator.ldci4(this.indent,0);
1203 this.codeGenerator.ldloc(this.indent, id);
1204 this.codeGenerator.stelemRef(this.indent);
1205 this.codeGenerator.CallVirt(this.indent,
"instance",
"object",
"[mscorlib]System.Reflection.MethodBase",
"Invoke",
new string[] {
"object",
"object[]" });
1206 this.codeGenerator.pop(this.indent);
1207 this.codeGenerator.WriteLabel(this.indent, fin);
1211 #region Visit(CompoundExpression node, Object obj)
1216 for (
int i = 0; i < node.ExpressionCount; i++) {
1217 node.GetExpressionElement(i).Accept(
this, obj);
1228 #region Visit(BaseExpression node, Object obj)
1231 this.codeGenerator.ldarg(this.indent, 0);
1237 #region Visit(BoolLiteralExpression node, Object obj)
1240 this.codeGenerator.ldc(this.indent, node.BoolValue);
1246 #region Visit(CharLiteralExpression node, Object obj)
1249 this.codeGenerator.ldci4(this.indent, Convert.ToUInt16(node.CharValue));
1255 #region Visit(DoubleLiteralExpression node, Object obj)
1258 this.codeGenerator.ldcr8(this.indent, node.ILValue);
1264 #region Visit(IntLiteralExpression node, Object obj)
1267 this.codeGenerator.ldci4(this.indent, node.IntValue);
1273 #region Visit(StringLiteralExpression node, Object obj)
1276 this.codeGenerator.ldstr(this.indent, node.StringValue);
1282 #region Visit(NullExpression node, Object obj)
1285 this.codeGenerator.ldnull(this.indent);
1293 #region Visit(SingleIdentifierExpression node, Object obj)
1294 public override Object
Visit(SingleIdentifierExpression node, Object obj) {
1297 Expression exp = this.constantsTable.Search(node.Identifier, out scope);
1299 if (exp == null || node.
IdSymbol != null && scope +
this.namespaceDepth < node.
IdSymbol.Scope)
1306 t = node.IdSymbol.SymbolType;
1308 field = node.ExpressionType as FieldType;
1310 field = t as FieldType;
1313 this.codeGenerator.ldarg(
this.indent, 0);
1318 WriteLoadField(field, node.
Identifier, helper);
1321 this.WriteLoadArg(node.
ILName, helper);
1324 this.WriteLoadLocalVar(node.ILName, helper, node.ExpressionType);
1331 this.codeGenerator.ldloc(this.indent, node.ILName);
1332 if (node.
ILTypeExpression is FieldType && ((FieldType)node.ILTypeExpression).FieldTypeExpression is ArrayType)
1339 node.FrozenTypeExpression = node.ExpressionType;
1345 exp.Accept(
this, obj);
1352 #region WriteLoadField()
1357 baseClass = helper.ActualMethodCalled.MemberInfo.Class as
BCLClassType;
1363 this.codeGenerator.ldsfld(this.indent, type, type.MemberInfo.Class.ILType(),
id);
1365 if ((baseClass != null) && (baseClass.
IsValueType()))
1366 this.codeGenerator.ldflda(this.indent, type, type.MemberInfo.Class.ILType(),
id);
1368 this.codeGenerator.ldfld(this.indent, type, type.MemberInfo.Class.ILType(),
id);
1373 #region WriteLoadLocalVar()
1375 private void WriteLoadLocalVar(
string id, InheritedAttributes helper,
TypeExpression type) {
1377 BCLClassType baseClass = null;
1378 if (helper.ActualMethodCalled != null)
1380 baseClass = helper.ActualMethodCalled.MemberInfo.Class as BCLClassType;
1384 if (fieldAccess != null) {
1385 PropertyType fieldType = fieldAccess.ExpressionType as PropertyType;
1386 if (fieldType != null)
1387 baseClass = fieldType.MemberInfo.Class as BCLClassType;
1391 if (baseClass != null && baseClass.
IsValueType()) {
1392 if (!type.
ILType().Equals(
"object"))
1394 if (helper.ParentNode is FieldAccessExpression)
1395 this.codeGenerator.ldloca(this.indent, id);
1398 this.codeGenerator.ldloc(this.indent, id);
1400 this.codeGenerator.ldloc(this.indent, id);
1401 this.codeGenerator.Unbox(this.indent, baseClass);
1404 this.codeGenerator.ldloc(this.indent, id);
1409 #region WriteLoadArg()
1411 private void WriteLoadArg(
string id, InheritedAttributes helper) {
1412 BCLClassType baseClass = null;
1413 if (helper.ActualMethodCalled != null)
1414 baseClass = helper.ActualMethodCalled.MemberInfo.Class as BCLClassType;
1416 if (baseClass != null && baseClass.
IsValueType() && helper.ParentNode is FieldAccessExpression)
1417 this.codeGenerator.ldarga(
this.indent,
id);
1419 this.codeGenerator.ldarg(this.indent, id);
1424 #region Visit(ThisExpression node, Object obj)
1427 this.codeGenerator.ldarg(this.indent, 0);
1435 #region Visit(ReturnStatement node, Object obj)
1438 node.Assigns.Accept(
this, obj);
1440 node.ReturnExpression.Accept(
this, obj);
1442 this.codeGenerator.Promotion(this.indent, node.ReturnExpression.ExpressionType, node.ReturnExpression.ILTypeExpression, TypeVariable.NewTypeVariable, TypeVariable.NewTypeVariable,
true, CheckMakeAnUnbox(node.
ReturnExpression));
1444 this.codeGenerator.Promotion(this.indent, node.ReturnExpression.ExpressionType, node.ReturnExpression.ILTypeExpression, node.CurrentMethodType.Return, node.CurrentMethodType.Return,
true, CheckMakeAnUnbox(node.
ReturnExpression));
1446 this.codeGenerator.ret(this.indent);
1452 #region Visit(Block node, Object obj)
1455 for (
int i = 0; i < node.StatementCount; i++) {
1456 node.GetStatementElement(i).Accept(
this, obj);
1464 #region RemovesTopElement()
1465 private void RemovesTopElement(
Statement stat) {
1478 if (invocation != null)
1482 this.codeGenerator.pop(this.indent);
1487 #region Visit(MoveStatement node, Object obj)
1492 node.RightExp.Accept(
this, obj);
1493 sa.CreateAuxiliarVar =
false;
1494 this.codeGenerator.Promotion(this.indent, node.RightExp.ExpressionType, node.RightExp.ILTypeExpression, node.LeftExp.ExpressionType, node.LeftExp.ILTypeExpression,
true, CheckMakeAnUnbox(node.
RightExp));
1497 node.MoveStat.Accept(
this, obj);
1503 #region Visit(IfElseStatement node, Object obj)
1506 string labelElse = this.codeGenerator.NewLabel;
1507 string labelEnd = this.codeGenerator.NewLabel;
1509 node.Condition.Accept(
this, obj);
1510 for (
int i = 0; i < node.AfterCondition.Count; i++)
1513 this.codeGenerator.brfalse(this.indent, labelElse);
1514 this.constantsTable.Set();
1515 node.TrueBranch.Accept(
this, obj);
1516 this.RemovesTopElement(node.TrueBranch);
1517 this.codeGenerator.br(this.indent, labelEnd);
1518 this.constantsTable.Reset();
1520 this.constantsTable.Set();
1521 this.codeGenerator.WriteLabel(this.indent, labelElse);
1522 node.FalseBranch.Accept(
this, obj);
1523 this.RemovesTopElement(node.FalseBranch);
1524 this.constantsTable.Reset();
1526 this.codeGenerator.WriteLabel(this.indent, labelEnd);
1535 #region Visit(DoStatement node, Object obj)
1538 string label = this.codeGenerator.NewLabel;
1540 for (
int i = 0; i < node.InitDo.Count; i++)
1541 node.
InitDo[i].Accept(
this, obj);
1546 this.constantsTable.Set();
1547 this.codeGenerator.WriteLabel(this.indent, label);
1548 node.Statements.Accept(
this, obj);
1549 this.RemovesTopElement(node.Statements);
1550 this.constantsTable.Reset();
1552 node.Condition.Accept(
this, obj);
1553 this.codeGenerator.brtrue(this.indent, label);
1559 #region Visit(ForStatement node, Object obj)
1562 string labelCondition = this.codeGenerator.NewLabel;
1563 string labelBody = this.codeGenerator.NewLabel;
1565 this.constantsTable.Set();
1566 for (
int i = 0; i < node.InitializerCount; i++) {
1567 node.GetInitializerElement(i).Accept(
this, obj);
1568 this.RemovesTopElement(node.GetInitializerElement(i));
1570 for (
int i = 0; i < node.AfterInit.Count; i++) {
1571 node.AfterInit[i].Accept(
this, obj);
1573 this.codeGenerator.br(this.indent, labelCondition);
1575 this.codeGenerator.WriteLabel(this.indent, labelBody);
1576 node.Statements.Accept(
this, obj);
1577 this.RemovesTopElement(node.Statements);
1579 for (
int i = 0; i < node.IteratorCount; i++) {
1580 node.GetIteratorElement(i).Accept(
this, obj);
1581 this.RemovesTopElement(node.GetIteratorElement(i));
1584 this.codeGenerator.WriteLabel(this.indent, labelCondition);
1589 node.Condition.Accept(
this, obj);
1590 for (
int i = 0; i < node.AfterCondition.Count; i++) {
1591 node.AfterCondition[i].Accept(
this, obj);
1593 this.codeGenerator.brtrue(this.indent, labelBody);
1595 this.constantsTable.Reset();
1601 #region Visit(WhileStatement node, Object obj)
1604 string labelCondition = this.codeGenerator.NewLabel;
1605 string labelBody = this.codeGenerator.NewLabel;
1607 for (
int i = 0; i < node.InitWhile.Count; i++)
1610 this.codeGenerator.br(this.indent, labelCondition);
1612 this.constantsTable.Set();
1613 this.codeGenerator.WriteLabel(this.indent, labelBody);
1614 node.Statements.Accept(
this, obj);
1615 this.RemovesTopElement(node.Statements);
1616 this.constantsTable.Reset();
1621 this.codeGenerator.WriteLabel(this.indent, labelCondition);
1622 node.Condition.Accept(
this, obj);
1623 for (
int i = 0; i < node.AfterCondition.Count; i++)
1625 this.codeGenerator.brtrue(this.indent, labelBody);
1631 #region Visit(SwitchStatement node, Object obj)
1634 List<string> labels =
new List<string>();
1636 for (
int i = 0; i < node.LabelCount(); i++)
1637 labels.Add(
this.codeGenerator.NewLabel);
1639 string endLabel = this.codeGenerator.NewLabel;
1641 string defaultLabel =
"";
1642 string idSwitchCond = auxSwitchCond + (auxFieldVarNumber++);
1644 this.codeGenerator.WriteAuxiliarLocalVariable(this.indent, idSwitchCond, node.Condition.ILTypeExpression.ILType());
1645 node.Condition.Accept(
this, obj);
1646 this.codeGenerator.stloc(this.indent, idSwitchCond);
1648 for (
int i = 0; i < node.AfterCondition.Count; i++)
1651 for (
int i = 0; i < node.SwitchBlockCount; i++) {
1652 this.constantsTable.Set();
1655 for (
int j = 0; j < node.GetSwitchSectionElement(i).LabelSection.Count; j++) {
1656 SwitchLabel n = node.GetSwitchSectionElement(i).LabelSection[j];
1658 this.codeGenerator.ldloc(this.indent, idSwitchCond);
1659 n.Condition.Accept(
this, obj);
1660 this.codeGenerator.beq(this.indent, labels[index]);
1662 defaultLabel = labels[index];
1668 this.codeGenerator.br(this.indent, defaultLabel != String.Empty ? defaultLabel : endLabel);
1671 for (
int i = 0; i < node.SwitchBlockCount; i++) {
1673 for (
int j = 0; j < node.GetSwitchSectionElement(i).LabelSection.Count; j++)
1674 this.codeGenerator.WriteLabel(this.indent, labels[index++]);
1676 node.GetSwitchSectionElement(i).SwitchBlock.
Accept(
this, obj);
1677 this.RemovesTopElement(node.GetSwitchSectionElement(i).SwitchBlock);
1678 this.codeGenerator.br(this.indent, endLabel);
1679 this.constantsTable.Reset();
1685 this.codeGenerator.WriteLabel(this.indent, endLabel);
1691 #region Visit(SwitchLabel node, Object obj)
1695 node.Condition.Accept(
this, obj);
1701 #region Visit(BreakStatement node, Object obj) // Nothing to do ¿?
1708 #region Visit(ExceptionManagementStatement node, Object obj)
1711 this.codeGenerator.WriteTryDirective(this.indent);
1712 this.codeGenerator.WriteOpenBraceTry(this.indent++);
1715 this.codeGenerator.WriteTryDirective(this.indent);
1716 this.codeGenerator.WriteOpenBraceTry(this.indent++);
1718 string firstLeaveJump = this.codeGenerator.NewLabel;
1719 string secondLeaveJump = this.codeGenerator.NewLabel;
1721 node.TryBlock.Accept(
this, obj);
1722 this.codeGenerator.WriteLeave(this.indent, firstLeaveJump);
1723 this.codeGenerator.WriteCloseBraceTry(--this.indent);
1727 for (
int i = 0; i < node.CatchCount; i++) {
1728 node.GetCatchElement(i).Accept(
this, obj);
1729 this.codeGenerator.WriteLeave(this.indent--, firstLeaveJump);
1730 this.codeGenerator.WriteCloseBraceCatch(this.indent);
1733 this.codeGenerator.WriteLabel(this.indent, firstLeaveJump);
1734 this.codeGenerator.nop(this.indent);
1737 this.codeGenerator.WriteLeave(this.indent, secondLeaveJump);
1738 this.codeGenerator.WriteCloseBraceTry(--this.indent);
1743 this.codeGenerator.WriteFinally(this.indent);
1744 this.codeGenerator.WriteOpenBraceFinally(this.indent++);
1745 node.FinallyBlock.Accept(
this, obj);
1746 this.codeGenerator.WriteLine(this.indent--,
"endfinally");
1747 this.codeGenerator.WriteCloseBraceFinally(this.indent);
1748 this.codeGenerator.WriteLabel(this.indent, node.CatchCount == 0 ? firstLeaveJump : secondLeaveJump);
1749 this.codeGenerator.nop(this.indent);
1757 #region CatchStatement // very important the brace is not closed.
1759 this.codeGenerator.WriteCatch(this.indent, node.Exception.TypeExpr.ILType(), node.
Exception.
TypeExpr.
ILType());
1760 this.codeGenerator.WriteOpenBraceCatch(this.indent++);
1761 this.codeGenerator.stloc(this.indent, node.Exception.ILName);
1762 node.Statements.Accept(
this, obj);
1771 this.codeGenerator.WriteRethrow(this.indent);
1773 node.ThrowExpression.Accept(
this, obj);
1774 codeGenerator.WriteThrow(this.indent);
1780 #region LoadAuxiliarVariable
1784 string id = tmpVars.SearchId(type);
1786 this.codeGenerator.stloc_s(this.indent, id);
1787 this.codeGenerator.ldloca_s(this.indent, id);
1794 #region RuntimeCheckArguments()
1795 internal abstract void RuntimeCheckArguments(InvocationExpression node, Object objArgs,
MethodType actualMethodCalled, List<string> nextMethod);
1807 #region Commented Code
1867 #region Nothing to do...
Encapsulates a Return statement of our programming languages.
Encapsulates a 'base' expression.
Encapsulates a definition of a concrete method.
override Object Visit(CatchStatement node, Object obj)
Encapsulates a Break statement of our programming languages.
override Object Visit(UnaryExpression node, Object obj)
override Object Visit(TernaryExpression node, Object obj)
MethodType CurrentMethodType
The method where the return statement appears
Abstract class encapsulate a programming language expression.
override Object Visit(IfElseStatement node, Object obj)
bool IsParentNodeAnInvocation
Gets or sets true if the parent node is an InvocationExpression. Otherwise, false.
override Object Visit(AssignmentExpression node, Object obj)
Encapsulates a Do statement of our programming language.
Expression FirstOperand
Gets the first operand of the ternary expression
Encapsulates a string literal expression.
Encapsulates the expression to access a field.
override Object Visit(MoveStatement node, Object obj)
Encapsulates a block of statements.
override Object Visit(StringLiteralExpression node, Object obj)
VisitorILCodeGeneration(string moduleName, T codeGenerator)
Constructor of VisitorCodeGeneration
Encapsulates a namespace definition.
List< MoveStatement > InitDo
Gets or sets the statements to use at the init of the do loop.
Representa an array type.
override Object Visit(FieldAccessExpression node, Object obj)
override bool IsValueType()
True if type expression is a ValueType. Otherwise, false.
override Object Visit(MethodDeclaration node, Object obj)
override Object Visit(BreakStatement node, Object obj)
Encapsulates a Catch statement of our programming languages.
override Object Visit(ConstructorDefinition node, Object obj)
Encapsulates a logical binary expression.
override Object Visit(RelationalExpression node, Object obj)
Encapsulates a invocation expression.
Encapsulates a boolean literal expression.
Encapsulates a cast expression.
Encapsulates a definition of a concrete field.
TypeExpression ExpressionType
Gets or sets the type of the expression.
SectionType SwitchSectionType
Gets the type of the Case statement (case or default)
Modifier ModifierMask
Gets the modifier information
Abstract class represents a programming language statement.
override Object Visit(SourceFile node, Object obj)
MethodType ActualMethodCalled
Gets or sets the type expression of the current invocation expression. If not exists, their value is null.
IdDeclaration Exception
Gets the exception to catch
override Object Visit(ForStatement node, Object obj)
override void AddExceptionCode()
Adds the intermediate code for exception to include in the file.
Dictionary< string, AccessModifier > Methods
Gets the method list
List< MoveStatement > AfterCondition
Gets or sets the statements after condition.
MoveStatement MoveStat
Gets or sets a move statement associated to the assignment expression.
Encapsulates a constant field definition.
Encapsulates a definition.
Encapsulates arithmetic binary expressions.
SingleIdentifierExpression RightExp
Gets the right expression
Abstract class that represents all different types.
Represents a generic type expression
Represents a proxy of a class type. It implements the unfold operatations of theoretical type systes...
Encapsulates a For statement of our programming languages.
Encapsulates a While statement of our programming languages.
bool ArrayAccessFound
Gets or sets true if array access expression found. Otherwise, gets or sets false.
MethodDefinition CurrentMethod
Gets or sets the current method definition node.
override Object Visit(CharLiteralExpression node, Object obj)
Encapsulates a null expression.
int ParameterListCount
Gets the number of parameters
Encapsulates a Is expression.
Expression SecondOperand
Gets the second operand of the binary expression
TypeExpression Return
Gets type expression method return
bool CreateAuxiliarVar
Gets or sets true if it is necessary to create an auxiliar variable. Otherwise, false.
override Object Visit(ReturnStatement node, Object obj)
Encapsulates a definition of a concrete interface.
bool IsUnionOfProperties(UnionType ut)
AccessModifier MemberInfo
Gets or sets the attribute information of method type
override Object Visit(SwitchStatement node, Object obj)
Encapsulates a switch label (Case + condition or Default section).
Represent a integer type.
Encapsulates a identifier expression of our programming language.
Expression Reference
Gets or sets the reference of a concrete identifier.
override void Close()
Closes the code generator.
bool IsUnionOfTypeVariablesWithoutSustitution(UnionType ut)
override Object Visit(BaseExpression node, Object obj)
override Object Visit(BitwiseExpression node, Object obj)
Encapsulates a declaration of a concrete method.
IdentifierMode
Represents how to use the identifier
Implementation of a table of variables. thist tables search for an id according to its string type re...
This class walks the AST to obtain the field and localinit directives.
override Object Visit(ConstantDefinition node, Object obj)
Encapsulates a set of expressions.
override Object Visit(ExceptionManagementStatement node, Object obj)
Expression ThrowExpression
Gets the throw expression.
abstract bool IsValueType()
True if type expression is a ValueType. Otherwise, false.
Type TypeInfo
Returns the real introspective type
Implementation of a table of constants.
Encapsulates a relational binary expression.
Encapsulates a bitwise binary expression.
override Object Visit(Namespace node, Object obj)
Encapsulates assignment binary expressions.
CompoundExpression Init
Gets or sets the array initialization
override Object Visit(DoubleLiteralExpression node, Object obj)
Encapsulates a ternary expression of our programming language.
override Object Visit(ClassDefinition node, Object obj)
Encapsulates a If-Else statement of our programming language.
override Object Accept(Visitor v, Object o)
Accept method of a concrete visitor.
IdentifierMode IdentifierExpressionMode
Gets or sets the identifier mode (Instance, UserType, Namespace)
virtual string ILType()
Gets the type name to use in IL code.
Encapsulates a new array expression.
Encapsulates a definition of a concrete constructor.
Declaration GetMemberElement(int index)
Gets the element stored in the specified index.
virtual void ThrowMissingMethodException(string method)
MoveStatement MoveStat
Gets or sets a move statement associated to the current move statement.
TypeExpression FieldTypeExpression
Gets the field type.
Encapsulates the source code.
int CatchCount
Gets the number of catch blocks.
Declaration GetDeclarationElement(int index)
Gets the element stored in the specified index.
Expression GetExpressionElement(int index)
Gets the element stored in the specified index.
override Object Visit(ThisExpression node, Object obj)
Encapsulates a Try-Catch-finally statement of our programming languages. As C# states catch blcok and...
abstract Object Accept(Visitor v, Object o)
Accept method of a concrete visitor.
override Object Visit(IsExpression node, Object obj)
override Object Visit(NewExpression node, Object obj)
Encapsulates a string literal expression.
override Object Visit(MethodDefinition node, Object obj)
override Object Visit(CompoundExpression node, Object obj)
SingleIdentifierExpression LeftExp
Gets the left expression
override Object Visit(LogicalExpression node, Object obj)
override Object Visit(ConstantFieldDefinition node, Object obj)
Object LoadAuxiliarVariable(string type)
override Object Visit(FieldDeclaration node, Object obj)
This class encapsulates several inherited attributes used in code generation process.
Encapsulates a argument expression of our programming language.
List< MoveStatement > AfterCondition
Gets or sets the statements after condition.
int IndexOfSSA
Gets or sets the index associated with SSA algorithm
override Object Visit(IntLiteralExpression node, Object obj)
Encapsulates a 'this' expression.
List< MoveStatement > InitWhile
Gets or sets the statements to use at the init of the while loop.
string ILName
Gets the IL name associated to the declaration identifier.
Encapsulates a unary expression of our programming language.
Modifier
Indicates differents modifiers to use in class (only public, internal or static), fields or methods...
int indent
Represents the indentation to write in the code file.
override Object Visit(ThrowStatement node, Object obj)
Expression Identifier
Gets or sets the current expression to use in store instruction in assignment node.
Expression Size
Gets or sets the array size
LogicalOperator Operator
Gets the operator of the binary expression
override bool IsValueType()
True if type expression is a ValueType. Otherwise, false.
Expression ReturnExpression
Gets the return expression.
bool Assignment
Gets or sets true if assignment expression found. Otherwise, gets or sets false.
SectionType
Indicates if it is a case statement or a default case.
Representa a property type.
UserType Class
Gets or sets the class type reference
override Object Visit(NullExpression node, Object obj)
Representa a method type.
Encapsulates a integer literal expression.
Encapsulates a declaration of a concrete field.
Encapsulates a constant definition.
Encapsulates the array expression to access the concrete position.
Symbol IdSymbol
Gets or sets the symbol of the identifier.
bool IsIntrospectiveInvocation
Gets or sets true the node is an Introspective Invocation. Otherwise, gets or sets false...
override Object Visit(Block node, Object obj)
override Object Visit(SwitchLabel node, Object obj)
override Object Accept(Visitor v, Object o)
Accept method of a concrete visitor.
static IntType Instance
Gets the unique instance of IntType
Block FinallyBlock
Gets the statements executed in Finally block. if there is no finally statementes can be null ...
Expression ThirdOperand
Gets the third operand of the ternary expression
TypeExpression CastType
Gets or sets the type to convert the expression
Encapsulates a Move instruction to use in SSA algorithm
IList< TypeExpression > TypeSet
Gets the list of type expressions
Expression SecondOperand
Gets the second operand of the ternary expression
This class encapsulates several inherited attributes used in code generation process.
TypeExpression Substitution
Gets the substitution; null if it does not exist
override Object Visit(SingleIdentifierExpression node, Object obj)
AccessModifier MemberInfo
Gets or sets the attribute information of method type
IdentifierMode IdMode
Gets the mode to use de identifier.
override Object Visit(NewArrayExpression node, Object obj)
Expression FirstOperand
Gets the first operand of the binary expression
override Object Visit(CastExpression node, Object obj)
override Object Visit(ArrayAccessExpression node, Object obj)
string Identifier
Gets the name name.
bool SearchParam(string param)
Searches the specified param in the method parameter list.
override Object Visit(FieldDefinition node, Object obj)
Encapsulates a Throw statement of our programming languages.
override Object Visit(ArithmeticExpression node, Object obj)
SingleIdentifierExpression FieldName
Gets the name to the field.
virtual TypeExpression ILTypeExpression
Gets the type expression to use in code generation.
List< Modifier > ModifiersInfo
Gets the modifiers information used to obtain its type
override Object Visit(WhileStatement node, Object obj)
override Object Visit(Definition node, Object obj)
TypeExpression GetParameter(int index)
Gets the type expression of the specific parameter
Expression Expression
Gets the expression to access a field.
Statement GetStatementElement(int index)
Gets the element stored in the specified index.
List< MoveStatement > AfterCondition
Encapsulates a new expression.
virtual object AcceptOperation(TypeSystemOperation op, object arg)
Encapsulates a definition of a concrete class.
Expression Expression
Gets the expression to convert.
override Object Visit(DoStatement node, Object obj)
TypeExpression TypeExpr
Gets or sets the type of the declaration
Encapsulates a Switch statement of our programming languages.
static TemporalVariablesTable Instance
Gets the unique instance of TemporalVariablesTable
override Object Visit(BoolLiteralExpression node, Object obj)
override Object Visit(InterfaceDefinition node, Object obj)
override Object Accept(Visitor v, Object o)
Accept method of a concrete visitor.