20 using System.Collections.Generic;
25 using ErrorManagement;
29 using DynVarManagement;
53 private List<string> usings;
63 private string currentNamespace;
68 private string currentClass;
73 private string currentMethod;
88 private List<int> blockList;
93 private int indexBlockList = 0;
98 private IDictionary<string, string> directories;
111 this.usings =
new List<string>();
113 this.currentNamespace =
"";
114 this.currentClass =
"";
115 this.currentMethod =
"";
116 this.directories = directories;
126 private void loadDynVars()
128 string dynFile = Path.ChangeExtension(this.currentFile, DynVarManagement.DynVarManager.DynVarFileExt);
130 if (File.Exists(dynFile))
134 manager.Load(dynFile);
136 catch (DynVarManagement.DynVarException e)
146 #region searchDynInfo()
153 private bool searchDynInfo(
string id)
157 if (this.currentMethod.Length == 0)
158 return manager.SearchDynVar(this.currentNamespace, this.currentClass, id);
159 if ((this.blockList != null) && (this.blockList.Count != 0) && (this.indexBlockList > 0))
160 return manager.
SearchDynVar(
this.currentNamespace,
this.currentClass,
this.currentMethod,
this.blockList.GetRange(0,
this.indexBlockList), id);
161 return manager.SearchDynVar(this.currentNamespace, this.currentClass, this.currentMethod, id);
168 #region Visit(SourceFile node, Object obj)
172 this.currentFile = node.Location.FileName;
176 for (
int i = 0; i < node.Usings.Count; i++)
178 usings.Add(node.Usings[i]);
181 foreach (
string key
in node.Namespacekeys)
183 int count = node.GetNamespaceDefinitionCount(key);
184 for (
int i = 0; i < count; i++)
186 node.GetNamespaceDeclarationElement(key, i).Accept(
this, obj);
190 for (
int i = 0; i < node.DeclarationCount; i++)
192 node.GetDeclarationElement(i).Accept(
this, obj);
200 #region Visit(Namespace node, Object obj)
205 this.currentNamespace = node.Identifier.Identifier;
207 usings.Add(node.Identifier.Identifier);
209 for (
int i = 0; i < node.NamespaceMembersCount; i++)
211 node.GetDeclarationElement(i).Accept(
this, obj);
214 usings.Remove(node.Identifier.Identifier);
216 this.currentNamespace =
"";
223 #region Visit(ClassDefinition node, Object obj)
228 this.currentClass = node.Identifier;
230 this.baseType = ((
ClassType)node.TypeExpr).BaseClass;
233 for (
int i = 0; i < node.MemberCount; i++)
240 for (
int i = 0; i < node.MemberCount; i++)
242 node.GetMemberElement(i).Accept(
this, obj);
245 this.currentClass =
"";
246 this.thisType = null;
247 this.baseType = null;
254 #region Visit(IdDeclaration node, Object obj)
258 node.Symbol = declarationSymbol(node);
264 #region Visit(Definition node, Object obj)
268 node.Init.Accept(
this, obj);
269 node.Symbol = declarationSymbol(node);
275 #region Visit(ConstantDefinition node, Object obj)
279 node.Init.Accept(
this, obj);
280 node.Symbol = declarationSymbol(node);
286 #region declarationSymbol()
295 TypeExpression te = this.searchType(node.FullName, node.Location.Line, node.Location.Column);
299 string id = node.Identifier;
301 id += node.IdentifierExp.IndexOfSSA;
313 #region fieldDeclarationSymbol()
326 bool isDynamic = searchDynInfo(node.
Identifier);
332 DynVarOptions.Instance.AssignDynamism(this.thisType.Fields[node.Identifier].Type, isDynamic);
337 #region Visit(MethodDefinition node, Object obj)
341 this.blockList =
new List<int>();
342 this.indexBlockList = 0;
345 this.currentMethod = node.Identifier;
346 node.IsReturnDynamic = this.searchDynInfo(
"");
347 this.parameterSymbol(node);
348 node.Body.Accept(
this, node);
349 this.currentMethod =
"";
356 #region Visit(ConstructorDefinition node, Object obj)
360 this.blockList =
new List<int>();
361 this.indexBlockList = 0;
364 this.currentMethod = node.Identifier;
365 this.parameterSymbol(node);
368 node.Initialization.Accept(
this, obj);
370 node.Body.Accept(
this, node);
371 this.currentMethod =
"";
378 #region parameterSymbol()
384 string id = node.ParametersInfo[i].Identifier;
396 #region Visit(SingleIdentifierExpression node, Object obj)
402 sym = this.table.Search(node.Identifier + node.IndexOfSSA);
404 sym = this.table.Search(node.Identifier);
407 node.IdSymbol = (
Symbol)sym;
423 private TypeExpression searchType(
string typeIdentifier,
int line,
int column)
429 while ((typeIdentifier.Contains(
"[]")) && (!found))
431 te = TypeTable.Instance.GetType(typeIdentifier,
new Location(this.
currentFile, line, column));
434 typeIdentifier = typeIdentifier.Substring(0, typeIdentifier.Length - 2);
442 te = TypeTable.Instance.GetType(typeIdentifier,
new Location(this.
currentFile, line, column));
446 for (
int i = 0; i < usings.Count; i++)
449 str.Append(usings[i]);
451 str.Append(typeIdentifier);
453 te = TypeTable.Instance.GetType(str.ToString(),
new Location(this.
currentFile, line, column));
463 for (
int i = 0; i < rank; i++)
465 te =
new ArrayType(te);
477 #region compoundExpressionToArray()
489 for (
int i = 0; i < args.ExpressionCount; i++)
503 #region Visit(Block node, Object obj)
511 if (this.indexBlockList >= this.blockList.Count)
512 this.blockList.Add(0);
514 this.blockList[indexBlockList] = this.blockList[indexBlockList] + 1;
515 this.indexBlockList++;
518 for (
int i = 0; i < node.StatementCount; i++)
521 if (!(obj is MethodDefinition))
523 for (
int i = this.indexBlockList; i < this.blockList.Count; i++)
524 this.blockList.RemoveAt(i);
525 this.indexBlockList--;
534 #region Visit(DoStatement node, Object obj)
538 for (
int i = 0; i < node.InitDo.Count; i++)
540 node.InitDo[i].Accept(
this, obj);
543 for (
int i = 0; i < node.BeforeBody.Count; i++)
545 node.BeforeBody[i].Accept(
this, obj);
547 node.Statements.Accept(
this, obj);
549 node.Condition.Accept(
this, obj);
555 #region Visit(ForStatement node, Object obj)
560 for (
int i = 0; i < node.InitializerCount; i++)
562 node.GetInitializerElement(i).Accept(
this, obj);
564 for (
int i = 0; i < node.AfterInit.Count; i++)
566 node.AfterInit[i].Accept(
this, obj);
568 for (
int i = 0; i < node.BeforeCondition.Count; i++)
570 node.BeforeCondition[i].Accept(
this, obj);
572 node.Condition.Accept(
this, obj);
573 for (
int i = 0; i < node.AfterCondition.Count; i++)
575 node.AfterCondition[i].Accept(
this, obj);
577 node.Statements.Accept(
this, obj);
578 for (
int i = 0; i < node.IteratorCount; i++)
580 node.GetIteratorElement(i).Accept(
this, obj);
588 #region Visit(IfElseStatement node, Object obj)
592 node.Condition.Accept(
this, obj);
593 for (
int i = 0; i < node.AfterCondition.Count; i++)
595 node.AfterCondition[i].Accept(
this, obj);
598 node.TrueBranch.Accept(
this, obj);
601 node.FalseBranch.Accept(
this, obj);
603 for (
int i = 0; i < node.ThetaStatements.Count; i++)
605 node.ThetaStatements[i].Accept(
this, obj);
612 #region Visit(WhileStatement node, Object obj)
616 for (
int i = 0; i < node.InitWhile.Count; i++)
618 node.InitWhile[i].Accept(
this, obj);
620 for (
int i = 0; i < node.BeforeCondition.Count; i++)
622 node.BeforeCondition[i].Accept(
this, obj);
624 node.Condition.Accept(
this, obj);
625 for (
int i = 0; i < node.AfterCondition.Count; i++)
627 node.AfterCondition[i].Accept(
this, obj);
630 node.Statements.Accept(
this, obj);
637 #region Visit(SwitchStatement node, Object obj)
641 node.Condition.Accept(
this, obj);
642 for (
int i = 0; i < node.AfterCondition.Count; i++)
644 node.AfterCondition[i].Accept(
this, obj);
647 for (
int i = 0; i < node.SwitchBlockCount; i++)
650 node.GetSwitchSectionElement(i).Accept(
this, obj);
653 for (
int i = 0; i < node.ThetaStatements.Count; i++)
655 node.ThetaStatements[i].Accept(
this, obj);
Encapsulates a definition of a concrete method.
override Object Visit(MethodDefinition node, Object obj)
override Object Visit(Block node, Object obj)
Encapsulates a Do statement of our programming language.
Encapsulates a block of statements.
Encapsulates a namespace definition.
override Object Visit(ConstantDefinition node, Object obj)
Representa an array type.
static TypeTable Instance
Gets the unique instance of TypeTable
Represents a error produced when the used type is not defined.
This class encapsulates a location in a specific file. Implements an Inmutable pattern. So it can be used in any context, that is his internal fields never change.
override Object Visit(ConstructorDefinition node, Object obj)
override Object Visit(DoStatement node, Object obj)
override Object Visit(WhileStatement node, Object obj)
Symbol Insert(string id, TypeExpression type, bool isDynamic)
Insert a new symbol in the current scope.
VisitorSymbolIdentification(IDictionary< string, string > directories)
Constructor of VisitorSymbolIdentification A mapping between each sort file name and its full directo...
Represents a error produced when the declaration already exists.
Encapsulates a definition.
New implementation of DynVarManagement: -Ignores "block" elements: not used anymore. -Provides wider interface: -Dynamic method return (dynreturn attribute in method elements) -Interface elements Includes set of old fields, properties and methods for retro-compatibility reasons.
override Object Visit(IdDeclaration node, Object obj)
override Object Visit(SourceFile node, Object obj)
override Object Visit(IfElseStatement node, Object obj)
bool Ready
Gets true if the xml document is loaded. Otherwise false.
Abstract class that represents all different types.
Encapsulates a For statement of our programming languages.
Implementation of a symbol table.
Encapsulates a While statement of our programming languages.
System.Text.StringBuilder StringBuilder
int StatementCount
Gets the number of statements.
bool SearchDynVar(string ns, string classId, string varId)
virtual string FullName
Gets the full name of the type Note: WriteType expression is the longest recursive representation of ...
This class represents a symbol associated with its identifier.
int Column
Gets column where the item is located
Encapsulates a identifier expression of our programming language.
override Object Visit(SwitchStatement node, Object obj)
Encapsulates a set of expressions.
List< Parameter > ParametersInfo
Gets the parameters information used to obtain its type
int Line
Gets line where the item is located
bool ContainsType(string key)
Returns if the type table contains the specified tmpName.
SingleIdentifierExpression IdentifierExp
Gets the identifier expression
override Object Visit(Namespace node, Object obj)
Implementation of a table of types.
Encapsulates a If-Else statement of our programming language.
override Object Visit(Definition node, Object obj)
void AddType(string name, TypeExpression type, Location location)
Adds a new type into the type table
Encapsulates a definition of a concrete constructor.
Declaration GetMemberElement(int index)
Gets the element stored in the specified index.
Encapsulates the source code.
Expression GetExpressionElement(int index)
Gets the element stored in the specified index.
Encapsulates a declaration.
int IndexOfSSA
Gets or sets the index associated with SSA algorithm
InvocationExpression Initialization
Gets the base or this initialization of the constructor definition
Representa a method type.
Encapsulates a declaration of a concrete field.
Encapsulates a constant definition.
override Object Visit(ClassDefinition node, Object obj)
string FullName
Gets or sets the nominal type of the declaration
string Identifier
Gets the name associated to the declaration
This class visits the AST to assign symbol information to identifier expression.
override Object Visit(SingleIdentifierExpression node, Object obj)
Represents a class or interface type.
Statement GetStatementElement(int index)
Gets the element stored in the specified index.
Encapsulates a definition of a concrete class.
override Object Visit(ForStatement node, Object obj)
TypeExpression TypeExpr
Gets or sets the type of the declaration
Encapsulates a Switch statement of our programming languages.
Represents the error occurred when dynamic variable are loaded.