21 using System.Collections.Generic;
25 using CodeGeneration.ExceptionManagement;
28 namespace CodeGeneration {
55 protected Dictionary<string, DynamicExceptionManager>
exceptions;
79 this.currentLabel = 0;
80 this.exceptions =
new Dictionary<string, DynamicExceptionManager>();
87 #region WriteComment()
94 public abstract void Comment(
string msg);
101 public abstract void Comment(
int indent,
string msg);
112 public abstract void WriteLabel(
int indent,
string label);
116 internal abstract void WriteConstructorHeader(
int indent);
118 internal abstract void WriteStaticConstructorHeader(
int indent);
158 #region WriteHeader()
168 #region WriteNamespaceHeader()
178 #region WriteLNClassHeader()
189 #region WriteEndOfClass()
200 #region WriteLNInterfaceHeader()
212 #region WriteLNEndOfInterface()
222 #region WriteLNMethodHeader()
232 #region WriteEndOfMethod()
243 #region WriteParams()
261 public abstract void WriteField(
int indent,
string name,
FieldType type,
bool constantField);
274 this.output.WriteLine(init);
279 #region WriteEndOfField()
287 #region WriteStartBlock()
297 #region WriteLNEndOfBlock()
307 #region AddLocalVariable();
312 #region WriteLocalVariable()
322 #region WriteAuxiliarLocalVariable()
334 #region WriteCodeOfExceptions()
352 #region WriteEntryPoint()
364 #region WriteEntryPoint()
367 this.WriteEntryPoint();
372 #region TryDirective ()
384 public abstract void WriteCatch(
int indent, String type, String var);
410 #region RuntimeIsInstruction()
421 #region WriteThrowException
440 #region Box and Unbox
489 #region CallVirt <token>
522 public abstract void CallVirt(
int indent,
string methodType,
string result,
string klass,
string memberName,
string[] args);
559 public abstract void Call(
int indent,
string methodType,
string result,
string klass,
string memberName,
string[] args);
579 this.CallVirt(indent, actualMethodCalled, actualMethodCalled.MemberInfo.Class, fieldAccessExpression.FieldName.Identifier, node.Arguments);
580 else if (actualMethodCalled.MemberInfo.Modifiers.Contains(
Modifier.Abstract))
584 this.Call(indent, actualMethodCalled, actualMethodCalled.MemberInfo.Class, actualMethodCalled.MemberInfo.MemberIdentifier);
586 return actualMethodCalled.Return;
abstract void WriteEndOfClass(int indent, string name)
Writes the class termination
abstract void BoxIfNeeded(int indent, TypeExpression type)
Makes sure to convert a type to an object
abstract void WriteLNMethodHeader(int indent, string name, MethodType type)
Writes the method header.
abstract void WriteCodeOfExceptionsTemplateMethod(DynamicExceptionManager d)
Algorithm used in WriteCodeException
abstract void WriteLocalVariable(int indent)
Writes the information of local variables.
Encapsulates the expression to access a field.
virtual void WriteLNFieldInitialization(string init)
Writes the field inicialization expression.
abstract void WriteParams(MethodType memberType, AST.CompoundExpression arguments)
Writes the parameters of a method
abstract void Comment(string msg)
Writes the specified message stored in msg in a comment wrapped in the proper format of the target la...
abstract void WriteEndOfInterface(int indent, string name)
Writes the interface termination
void Close()
Close the writer
abstract void WriteNamespaceHeader(int indent, string name)
Writes the namespace header.
abstract void WriteOpenBraceCatch(int indent)
abstract void WriteFinally(int indent)
Encapsulates a invocation expression.
abstract void Unbox(int indent, TypeExpression type)
Writes the Unbox instruction
virtual void WriteEntryPoint()
abstract string NewLabel
Gets the value of the current label
abstract void WriteStartBlock(int indent)
Writes the class inicialization
virtual void WriteCodeOfExceptions()
Implements Template Method Pattern Writes the intermediate code for each exceptions to include ...
abstract void AddLocalVariable(string name, TypeExpression type)
This class encapsulates the IL code to generate a dynamic exception.
Represents a interface type.
abstract void InitialComment()
abstract void Box(int indent, TypeExpression type)
Writes the Box instruction
Abstract class that represents all different types.
abstract void WriteThrowException(int indent, DynamicExceptionManager dynException)
Checks if the type variable on the stack is a specified type or can be to promotion. Indentation levelThe type expression to promote to
abstract void WriteCatch(int indent, String type, String var)
abstract void WriteCloseBraceTry(int indent)
System.Text.StringBuilder StringBuilder
This class encapsulates the instruction used to generate the code.
abstract void Call(int indent, MethodType memberType, TypeExpression obj, string member)
Writes the call instruction.
virtual TypeExpression MakeCall(int indent, InvocationExpression node, Object o, MethodType actualMethodCalled, FieldAccessExpression fieldAccessExpression, object arg)
abstract void WriteInterfaceHeader(int indent, string name, InterfaceType type)
Writes the interface header
abstract void WriteOpenBraceFinally(int indent)
IdentifierMode
Represents how to use the identifier
CodeGenerator(TextWriter writer)
Constructor of CodeGenerator.
abstract void WriteHeader(string fileName)
Writes the header of the object code file.
CompoundExpression Arguments
Gets the arguments to invoke in the expression
TextWriter output
Writer to write the intermediate code.
abstract void WriteOpenBraceTry(int indent)
abstract void WriteLNClassHeader(int indent, string name, ClassType type)
Writes the class header.
abstract void WriteType(TypeExpression type)
Writes the current type information
Modifier
Indicates differents modifiers to use in class (only public, internal or static), fields or methods...
abstract void WriteEndOfField()
Writes the field termination
abstract void WriteTryDirective(int indent)
Representa a property type.
abstract void WriteAuxiliarLocalVariable(int indent, string id, string type)
Writes the information of local variables.
Representa a method type.
abstract void WriteEndOfMethod(int indent, string name)
Writes the method termination
abstract void UnboxAny(int indent, TypeExpression type)
Writes the Unbox instruction
abstract void WriteCloseBraceFinally(int indent)
Dictionary< string, DynamicExceptionManager > exceptions
List of exceptions that is necessary to include in intermediate code file.
StringBuilder currentLocalVars
Stores the current information about local variables.
This class encapsulates several inherited attributes used in code generation process.
abstract void CallVirt(int indent, MethodType memberType, TypeExpression klass, string member, AST.CompoundExpression arguments)
Writes the CallVirt instruction.
abstract void WriteEndOfBlock(int indent)
Writes the termination token
string Identifier
Gets the name name.
SingleIdentifierExpression FieldName
Gets the name to the field.
abstract void WriteField(int indent, string name, FieldType type, bool constantField)
Writes the field header.
abstract void WriteLNFieldInitialization(TypeExpression type)
Writes the field inicialization.
abstract void WriteLabel(int indent, string label)
Writes the specified label.
abstract void WriteCloseBraceCatch(int indent)
int currentLabel
Represents the value of the current label.