The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
CodeGeneration.CodeGenerator Class Referenceabstract

This class encapsulates the instruction used to generate the code. More...

Inheritance diagram for CodeGeneration.CodeGenerator:
CodeGeneration.ILCodeGenerator CodeGeneration.CLRCodeGenerator CodeGeneration.RrotorCodeGenerator

Public Member Functions

 CodeGenerator (TextWriter writer)
 Constructor of CodeGenerator. More...
 
abstract void InitialComment ()
 
abstract void Comment (string msg)
 Writes the specified message stored in msg in a comment wrapped in the proper format of the target langage. More...
 
abstract void Comment (int indent, string msg)
 Writes the specified message stored in msg in a comment wrapped in the proper format of the target langage. More...
 
abstract void WriteLabel (int indent, string label)
 Writes the specified label. More...
 
abstract void WriteType (TypeExpression type)
 Writes the current type information More...
 
abstract void WriteHeader (string fileName)
 Writes the header of the object code file. More...
 
abstract void WriteNamespaceHeader (int indent, string name)
 Writes the namespace header. More...
 
abstract void WriteLNClassHeader (int indent, string name, ClassType type)
 Writes the class header. More...
 
abstract void WriteEndOfClass (int indent, string name)
 Writes the class termination More...
 
abstract void WriteInterfaceHeader (int indent, string name, InterfaceType type)
 Writes the interface header More...
 
abstract void WriteEndOfInterface (int indent, string name)
 Writes the interface termination More...
 
abstract void WriteLNMethodHeader (int indent, string name, MethodType type)
 Writes the method header. More...
 
abstract void WriteEndOfMethod (int indent, string name)
 Writes the method termination More...
 
abstract void WriteParams (MethodType memberType, AST.CompoundExpression arguments)
 Writes the parameters of a method More...
 
abstract void WriteField (int indent, string name, FieldType type, bool constantField)
 Writes the field header. More...
 
abstract void WriteLNFieldInitialization (TypeExpression type)
 Writes the field inicialization. More...
 
virtual void WriteLNFieldInitialization (string init)
 Writes the field inicialization expression. More...
 
abstract void WriteEndOfField ()
 Writes the field termination More...
 
abstract void WriteStartBlock (int indent)
 Writes the class inicialization More...
 
abstract void WriteEndOfBlock (int indent)
 Writes the termination token More...
 
abstract void AddLocalVariable (string name, TypeExpression type)
 
abstract void WriteLocalVariable (int indent)
 Writes the information of local variables. More...
 
abstract void WriteAuxiliarLocalVariable (int indent, string id, string type)
 Writes the information of local variables. More...
 
virtual void WriteCodeOfExceptions ()
 Implements Template Method Pattern Writes the intermediate code for each exceptions to include More...
 
abstract void WriteEntryPoint (int indent)
 Writes the entrypoint directive. More...
 
virtual void WriteEntryPoint ()
 
abstract void WriteTryDirective (int indent)
 
abstract void WriteOpenBraceTry (int indent)
 
abstract void WriteCloseBraceTry (int indent)
 
abstract void WriteCatch (int indent, String type, String var)
 
abstract void WriteOpenBraceCatch (int indent)
 
abstract void WriteCloseBraceCatch (int indent)
 
abstract void WriteFinally (int indent)
 
abstract void WriteOpenBraceFinally (int indent)
 
abstract void WriteCloseBraceFinally (int indent)
 
abstract void WriteThrowException (int indent, DynamicExceptionManager dynException)
 Checks if the type variable on the stack is a specified type or can be to promotion.

Parameters
indentIndentation level
typeExpressionThe type expression to promote to
More...
 
abstract void WriteThrowException (int indent, string ex, string[] msg)
 
abstract void Box (int indent, TypeExpression type)
 Writes the Box instruction More...
 
abstract void BoxIfNeeded (int indent, TypeExpression type)
 Makes sure to convert a type to an object More...
 
abstract void UnboxAny (int indent, TypeExpression type)
 Writes the Unbox instruction More...
 
abstract void Unbox (int indent, TypeExpression type)
 Writes the Unbox instruction More...
 
abstract void CallVirt (int indent, MethodType memberType, TypeExpression klass, string member, AST.CompoundExpression arguments)
 Writes the CallVirt instruction. More...
 
abstract void CallVirt (int indent, PropertyType memberType, TypeExpression obj, string member, bool setProperty)
 Writes the CallVirt instruction. More...
 
abstract void CallVirt (int indent, string methodType, string result, string klass, string memberName, string[] args)
 Writes the CallVirt instruction More...
 
abstract void Call (int indent, MethodType memberType, TypeExpression obj, string member)
 Writes the call instruction. More...
 
abstract void Call (int indent, PropertyType memberType, TypeExpression obj, string member, bool setProperty)
 
abstract void Call (int indent, string methodType, string result, string klass, string memberName, string[] args)
 Writes the call instruction More...
 
void Close ()
 Close the writer More...
 
virtual TypeExpression MakeCall (int indent, InvocationExpression node, Object o, MethodType actualMethodCalled, FieldAccessExpression fieldAccessExpression, object arg)
 

Protected Member Functions

abstract void WriteCodeOfExceptionsTemplateMethod (DynamicExceptionManager d)
 Algorithm used in WriteCodeException More...
 

Protected Attributes

TextWriter output
 Writer to write the intermediate code. More...
 
StringBuilder currentLocalVars
 Stores the current information about local variables. More...
 
int currentLabel
 Represents the value of the current label. More...
 
Dictionary< string,
DynamicExceptionManager
exceptions
 List of exceptions that is necessary to include in intermediate code file. More...
 

Properties

abstract string NewLabel [get]
 Gets the value of the current label More...
 

Detailed Description

This class encapsulates the instruction used to generate the code.

Definition at line 32 of file CodeGenerator.cs.

Constructor & Destructor Documentation

CodeGeneration.CodeGenerator.CodeGenerator ( TextWriter  writer)

Constructor of CodeGenerator.

Parameters
writerWriter to write the intermediate code.

Definition at line 76 of file CodeGenerator.cs.

Member Function Documentation

abstract void CodeGeneration.CodeGenerator.AddLocalVariable ( string  name,
TypeExpression  type 
)
pure virtual
abstract void CodeGeneration.CodeGenerator.Box ( int  indent,
TypeExpression  type 
)
pure virtual

Writes the Box instruction

Parameters
indentIndentation to use.
typeConverts to this object reference.

Implemented in CodeGeneration.ILCodeGenerator.

abstract void CodeGeneration.CodeGenerator.BoxIfNeeded ( int  indent,
TypeExpression  type 
)
pure virtual

Makes sure to convert a type to an object

Parameters
indentIndentation level
typeThe type to be promoted

Implemented in CodeGeneration.ILCodeGenerator.

abstract void CodeGeneration.CodeGenerator.Call ( int  indent,
MethodType  memberType,
TypeExpression  obj,
string  member 
)
pure virtual

Writes the call instruction.

Parameters
indentIndentation to use.
memberTypeMember type.
objObject to access to the member.
memberMember to call.

Implemented in CodeGeneration.ILCodeGenerator.

abstract void CodeGeneration.CodeGenerator.Call ( int  indent,
PropertyType  memberType,
TypeExpression  obj,
string  member,
bool  setProperty 
)
pure virtual

Writes the call instruction.

Parameters
indentIndentation to use.
memberTypeMember type.
objObject to access to the member.
memberMember to call.
setPropertyTrue if it is a set property. False if it is a get property.

Implemented in CodeGeneration.ILCodeGenerator.

abstract void CodeGeneration.CodeGenerator.Call ( int  indent,
string  methodType,
string  result,
string  klass,
string  memberName,
string[]  args 
)
pure virtual

Writes the call instruction

Parameters
indentText Indentation
methodTypeQualifiers of the method
resultReturn type
klassClass type
memberNameName of the member
argsTypes of parameters

Implemented in CodeGeneration.ILCodeGenerator.

abstract void CodeGeneration.CodeGenerator.CallVirt ( int  indent,
MethodType  memberType,
TypeExpression  klass,
string  member,
AST.CompoundExpression  arguments 
)
pure virtual

Writes the CallVirt instruction.

Parameters
indentIndentation to use.
memberTypeMember type.
klassClass to access to the member.
memberMember to call.
argumentsActual arguments

Implemented in CodeGeneration.ILCodeGenerator.

abstract void CodeGeneration.CodeGenerator.CallVirt ( int  indent,
PropertyType  memberType,
TypeExpression  obj,
string  member,
bool  setProperty 
)
pure virtual

Writes the CallVirt instruction.

Parameters
indentIndentation to use.
memberTypeMember type.
objObject to access to the member.
memberMember to call.
setPropertyTrue if it is a set property. False if it is a get property.

Implemented in CodeGeneration.ILCodeGenerator.

abstract void CodeGeneration.CodeGenerator.CallVirt ( int  indent,
string  methodType,
string  result,
string  klass,
string  memberName,
string[]  args 
)
pure virtual

Writes the CallVirt instruction

Parameters
indentText Indentation
methodTypeQualifiers of the method
resultReturn type
klassClass type
memberNameName of the member
argsTypes of parameters

Implemented in CodeGeneration.ILCodeGenerator.

void CodeGeneration.CodeGenerator.Close ( )

Close the writer

Definition at line 568 of file CodeGenerator.cs.

abstract void CodeGeneration.CodeGenerator.Comment ( string  msg)
pure virtual

Writes the specified message stored in msg in a comment wrapped in the proper format of the target langage.

Parameters
msgcomment to write.

Implemented in CodeGeneration.ILCodeGenerator.

abstract void CodeGeneration.CodeGenerator.Comment ( int  indent,
string  msg 
)
pure virtual

Writes the specified message stored in msg in a comment wrapped in the proper format of the target langage.

Parameters
msgcomment to write.
indentindentation to use

Implemented in CodeGeneration.ILCodeGenerator.

abstract void CodeGeneration.CodeGenerator.InitialComment ( )
pure virtual
virtual TypeExpression CodeGeneration.CodeGenerator.MakeCall ( int  indent,
InvocationExpression  node,
Object  o,
MethodType  actualMethodCalled,
FieldAccessExpression  fieldAccessExpression,
object  arg 
)
virtual

Definition at line 575 of file CodeGenerator.cs.

abstract void CodeGeneration.CodeGenerator.Unbox ( int  indent,
TypeExpression  type 
)
pure virtual

Writes the Unbox instruction

Parameters
indentIndentation to use.
typeValue type to revert.

Implemented in CodeGeneration.ILCodeGenerator.

abstract void CodeGeneration.CodeGenerator.UnboxAny ( int  indent,
TypeExpression  type 
)
pure virtual

Writes the Unbox instruction

Parameters
indentIndentation to use.
typeValue type to revert.

Implemented in CodeGeneration.ILCodeGenerator, CodeGeneration.CLRCodeGenerator, and CodeGeneration.RrotorCodeGenerator.

abstract void CodeGeneration.CodeGenerator.WriteAuxiliarLocalVariable ( int  indent,
string  id,
string  type 
)
pure virtual

Writes the information of local variables.

Parameters
indentCurrent indentation.
idAuxiliar local variable identifier.
typeAuxiliar local variable type expression.

Implemented in CodeGeneration.ILCodeGenerator.

abstract void CodeGeneration.CodeGenerator.WriteCatch ( int  indent,
String  type,
String  var 
)
pure virtual
abstract void CodeGeneration.CodeGenerator.WriteCloseBraceCatch ( int  indent)
pure virtual
abstract void CodeGeneration.CodeGenerator.WriteCloseBraceFinally ( int  indent)
pure virtual
abstract void CodeGeneration.CodeGenerator.WriteCloseBraceTry ( int  indent)
pure virtual
virtual void CodeGeneration.CodeGenerator.WriteCodeOfExceptions ( )
virtual

Implements Template Method Pattern Writes the intermediate code for each exceptions to include

Definition at line 340 of file CodeGenerator.cs.

abstract void CodeGeneration.CodeGenerator.WriteCodeOfExceptionsTemplateMethod ( DynamicExceptionManager  d)
protectedpure virtual

Algorithm used in WriteCodeException

Parameters
dThe exception to write in the code

Implemented in CodeGeneration.ILCodeGenerator.

abstract void CodeGeneration.CodeGenerator.WriteEndOfBlock ( int  indent)
pure virtual

Writes the termination token

Parameters
indentIndentation to use.

Implemented in CodeGeneration.ILCodeGenerator.

abstract void CodeGeneration.CodeGenerator.WriteEndOfClass ( int  indent,
string  name 
)
pure virtual

Writes the class termination

Parameters
indentIndentation to use.
nameName of the class to terminate.

Implemented in CodeGeneration.ILCodeGenerator.

abstract void CodeGeneration.CodeGenerator.WriteEndOfField ( )
pure virtual

Writes the field termination

Implemented in CodeGeneration.ILCodeGenerator.

abstract void CodeGeneration.CodeGenerator.WriteEndOfInterface ( int  indent,
string  name 
)
pure virtual

Writes the interface termination

Parameters
indentIndentation to use.
nameName of the interface to terminate.

Implemented in CodeGeneration.ILCodeGenerator.

abstract void CodeGeneration.CodeGenerator.WriteEndOfMethod ( int  indent,
string  name 
)
pure virtual

Writes the method termination

Parameters
indentIndentation to use.
nameName of the method to terminate.

Implemented in CodeGeneration.ILCodeGenerator.

abstract void CodeGeneration.CodeGenerator.WriteEntryPoint ( int  indent)
pure virtual

Writes the entrypoint directive.

Parameters
indentIndentation to use.

Implemented in CodeGeneration.ILCodeGenerator.

virtual void CodeGeneration.CodeGenerator.WriteEntryPoint ( )
virtual

Definition at line 366 of file CodeGenerator.cs.

abstract void CodeGeneration.CodeGenerator.WriteField ( int  indent,
string  name,
FieldType  type,
bool  constantField 
)
pure virtual

Writes the field header.

Parameters
indentIndentation to use.
nameField name.
typeField type expression.
constantFieldTrue if the field is a constant. Otherwise, false.

Implemented in CodeGeneration.ILCodeGenerator.

abstract void CodeGeneration.CodeGenerator.WriteFinally ( int  indent)
pure virtual
abstract void CodeGeneration.CodeGenerator.WriteHeader ( string  fileName)
pure virtual

Writes the header of the object code file.

Parameters
fileNameName of the module.

Implemented in CodeGeneration.ILCodeGenerator.

abstract void CodeGeneration.CodeGenerator.WriteInterfaceHeader ( int  indent,
string  name,
InterfaceType  type 
)
pure virtual

Writes the interface header

Parameters
indentIndentation to use.
nameInterface name.
typeInterface type expression.

Implemented in CodeGeneration.ILCodeGenerator.

abstract void CodeGeneration.CodeGenerator.WriteLabel ( int  indent,
string  label 
)
pure virtual

Writes the specified label.

Parameters
labelLabel to write.

Implemented in CodeGeneration.ILCodeGenerator.

abstract void CodeGeneration.CodeGenerator.WriteLNClassHeader ( int  indent,
string  name,
ClassType  type 
)
pure virtual

Writes the class header.

Parameters
indentIndentation to use.
nameClass name.
typeClass type expression.

Implemented in CodeGeneration.ILCodeGenerator.

abstract void CodeGeneration.CodeGenerator.WriteLNFieldInitialization ( TypeExpression  type)
pure virtual

Writes the field inicialization.

Parameters
typeWriteType Expression of the field inicialization.

Implemented in CodeGeneration.ILCodeGenerator.

virtual void CodeGeneration.CodeGenerator.WriteLNFieldInitialization ( string  init)
virtual

Writes the field inicialization expression.

Parameters
typeExpression of the field inicialization.

Definition at line 273 of file CodeGenerator.cs.

abstract void CodeGeneration.CodeGenerator.WriteLNMethodHeader ( int  indent,
string  name,
MethodType  type 
)
pure virtual

Writes the method header.

Parameters
indentIndentation to use.
nameMethod name.
typeMethod type expression.

Implemented in CodeGeneration.ILCodeGenerator.

abstract void CodeGeneration.CodeGenerator.WriteLocalVariable ( int  indent)
pure virtual

Writes the information of local variables.

Parameters
indentCurrent indentation.

Implemented in CodeGeneration.ILCodeGenerator.

abstract void CodeGeneration.CodeGenerator.WriteNamespaceHeader ( int  indent,
string  name 
)
pure virtual

Writes the namespace header.

Parameters
indentIndentation to use.
nameNamespace name.

<,

Implemented in CodeGeneration.ILCodeGenerator.

abstract void CodeGeneration.CodeGenerator.WriteOpenBraceCatch ( int  indent)
pure virtual
abstract void CodeGeneration.CodeGenerator.WriteOpenBraceFinally ( int  indent)
pure virtual
abstract void CodeGeneration.CodeGenerator.WriteOpenBraceTry ( int  indent)
pure virtual
abstract void CodeGeneration.CodeGenerator.WriteParams ( MethodType  memberType,
AST.CompoundExpression  arguments 
)
pure virtual

Writes the parameters of a method

Parameters
memberTypeThe type of the method
argumentsActual arguments

Implemented in CodeGeneration.ILCodeGenerator.

abstract void CodeGeneration.CodeGenerator.WriteStartBlock ( int  indent)
pure virtual

Writes the class inicialization

Parameters
indentIndentation to use.

Implemented in CodeGeneration.ILCodeGenerator.

abstract void CodeGeneration.CodeGenerator.WriteThrowException ( int  indent,
DynamicExceptionManager  dynException 
)
pure virtual

Checks if the type variable on the stack is a specified type or can be to promotion.

Parameters
indentIndentation level
typeExpressionThe type expression to promote to

public abstract void RuntimeIsInstruction(int indent, TypeExpression typeExpression);

Writes the generation code to throw a specified exception.

Parameters
indentIdentation to use.
dynExceptionException to throw.

Implemented in CodeGeneration.ILCodeGenerator.

abstract void CodeGeneration.CodeGenerator.WriteThrowException ( int  indent,
string  ex,
string[]  msg 
)
pure virtual

Writes the code to throw an exception derived from Exception without using DynamicExceptionManager .

Parameters
indentindentation to use
exName of the exception to throw
argsarguments of the exception. If the list is empty there won't be code generation about this param

Implemented in CodeGeneration.ILCodeGenerator.

abstract void CodeGeneration.CodeGenerator.WriteTryDirective ( int  indent)
pure virtual
abstract void CodeGeneration.CodeGenerator.WriteType ( TypeExpression  type)
pure virtual

Writes the current type information

Parameters
typeWriteType expression with the type information.

Implemented in CodeGeneration.ILCodeGenerator.

Member Data Documentation

int CodeGeneration.CodeGenerator.currentLabel
protected

Represents the value of the current label.

Definition at line 50 of file CodeGenerator.cs.

StringBuilder CodeGeneration.CodeGenerator.currentLocalVars
protected

Stores the current information about local variables.

Definition at line 45 of file CodeGenerator.cs.

Dictionary<string, DynamicExceptionManager> CodeGeneration.CodeGenerator.exceptions
protected

List of exceptions that is necessary to include in intermediate code file.

Definition at line 55 of file CodeGenerator.cs.

TextWriter CodeGeneration.CodeGenerator.output
protected

Writer to write the intermediate code.

Definition at line 40 of file CodeGenerator.cs.

Property Documentation

abstract string CodeGeneration.CodeGenerator.NewLabel
get

Gets the value of the current label

Definition at line 64 of file CodeGenerator.cs.


The documentation for this class was generated from the following file: