18 using System.Collections.Generic;
23 namespace CodeGeneration {
37 private List<FieldDefinition>[] fields;
42 private List<IdDeclaration> decls;
47 private const string auxiliarVar =
"v_array_temp_";
52 private const string auxiliarValue =
"V_";
57 private static int currentAuxiliarSuffix = 0;
60 get {
return currentAuxiliarSuffix; }
61 set { currentAuxiliarSuffix = value; }
72 this.fields =
new List<FieldDefinition>[2];
73 this.fields[0] =
new List<FieldDefinition>();
74 this.fields[1] =
new List<FieldDefinition>();
75 this.decls =
new List<IdDeclaration>();
76 TemporalVariablesTable.Instance.Clear();
83 #region Visit(ClassDefinition node, Object obj)
86 for (
int i = 0; i < node.MemberCount; i++) {
87 node.GetMemberElement(i).Accept(
this, obj);
97 node.Identifier.Accept(
this, null);
101 id.TypeExpr = node.ExpressionType ?? node.ILTypeExpression;
103 TemporalVariablesTable.Instance.Insert(id.FullName, id.ILName);
107 node.Arguments.Accept(
this, obj);
110 #region Visit(CastExpression node, Object obj)
113 node.Expression.Accept(
this, obj);
118 id.TypeExpr = node.Expression.ExpressionType;
121 TemporalVariablesTable.Instance.Insert(id.FullName, id.ILName);
132 id.TypeExpr = node.Expression.ExpressionType;
135 TemporalVariablesTable.Instance.Insert(id.FullName, id.ILName);
139 node.FieldName.Accept(
this, obj);
146 node.Body.Accept(
this, obj);
151 #region Visit(ConstructorDefinition node, Object obj)
154 this.CurrentAuxiliarSuffix = 0;
155 node.Body.Accept(
this, obj);
163 #region Visit(FieldDefinition node, Object obj)
166 node.Init.Accept(
this, obj);
168 this.fields[1].Add(node);
170 this.fields[0].Add(node);
187 #region Visit(IdDeclaration node, Object obj)
190 this.decls.Add(node);
196 #region Visit(Definition node, Object obj)
199 this.decls.Add(node);
200 node.Init.Accept(
this, obj);
208 #region Visit(NewArrayExpression node, Object obj)
214 id.TypeExpr = node.ILTypeExpression;
217 TemporalVariablesTable.Instance.Insert(id.FullName, id.ILName);
219 node.Identifier = id.Identifier;
222 if (node.
Size != null)
223 node.Size.Accept(
this, obj);
224 if (node.
Init != null)
225 node.Init.Accept(
this, obj);
233 #region Visit(BoolLiteralExpression node, Object obj)
236 return Convert.ToString(node.BoolValue);
241 #region Visit(CharLiteralExpression node, Object obj)
244 return Convert.ToString(Convert.ToUInt16(node.CharValue));
249 #region Visit(DoubleLiteralExpression node, Object obj)
257 #region Visit(IntLiteralExpression node, Object obj)
265 #region Visit(StringLiteralExpression node, Object obj)
268 return node.StringValue;
275 System.Diagnostics.Debug.Assert(
false,
"no debería llegar aqú );
}
public override void Close() {
System.Diagnostics.Debug.Assert(false, "no debería llegar aqú");
}
}
}
");
278 System.Diagnostics.Debug.Assert(
false,
"no debería llegar aqú );
}
}
}
");
override Object Visit(IntLiteralExpression node, Object obj)
Encapsulates a definition of a concrete method.
override void Close()
Class used to generate de intermediate code We implement explicitly covariance in this attribute by m...
Encapsulates a string literal expression.
Encapsulates the expression to access a field.
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.
This class walks the AST to to obtain intermediate code Thisis a layer adapter class and is the base ...
override Object Visit(BoolLiteralExpression node, Object obj)
Encapsulates a definition.
override Object Visit(DoubleLiteralExpression node, Object obj)
override Object Visit(StringLiteralExpression node, Object obj)
string TypeInfo
Gets the name of the new type
string SearchId(string type)
Searches the temporal variable.whose type is represented in type
Encapsulates a identifier expression of our programming language.
override Object Visit(NewArrayExpression node, Object obj)
override Object Visit(ConstructorDefinition node, Object obj)
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.
abstract bool IsValueType()
True if type expression is a ValueType. Otherwise, false.
override Object Visit(FieldAccessExpression node, Object obj)
CompoundExpression Init
Gets or sets the array initialization
virtual string ILType()
Gets the type name to use in IL code.
Encapsulates a new array expression.
Encapsulates a definition of a concrete constructor.
override Object Visit(ClassDefinition node, Object obj)
Encapsulates a string literal expression.
override Object Visit(IdDeclaration node, Object obj)
override void AddExceptionCode()
Encapsulates a declaration.
Modifier
Indicates differents modifiers to use in class (only public, internal or static), fields or methods...
Expression Size
Gets or sets the array size
Encapsulates a integer literal expression.
override Object Visit(MethodDefinition node, Object obj)
override Object Visit(InvocationExpression node, Object obj)
override Object Visit(CharLiteralExpression node, Object obj)
VisitorCodeGeneration2()
Constructor of VisitorCodeGeneration2
override Object Visit(CastExpression node, Object obj)
override Object Visit(Definition node, Object obj)
TypeExpression FrozenTypeExpression
WriteType variable may change its type's substitution (e.g., field type variables) This attribute sav...
virtual TypeExpression ILTypeExpression
Gets the type expression to use in code generation.
Expression Expression
Gets the expression to access a field.
Encapsulates a definition of a concrete class.
Expression Expression
Gets the expression to convert.
override Object Visit(FieldDefinition node, Object obj)
TypeExpression TypeExpr
Gets or sets the type of the declaration
static TemporalVariablesTable Instance
Gets the unique instance of TemporalVariablesTable
int CurrentAuxiliarSuffix