The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
SourceFile.cs
Go to the documentation of this file.
1 // -------------------------------------------------------------------------- //
3 // Project rROTOR //
4 // -------------------------------------------------------------------------- //
5 // File: SourceFile.cs //
6 // Author: Cristina Gonzalez Muņoz - cristi.gm@gmail.com //
7 // Description: //
8 // Encapsulates the source code. //
9 // Inheritance: AstNode. //
10 // Implements Composite pattern [Composite]. //
11 // Implements Visitor pattern [Concrete Element]. //
12 // -------------------------------------------------------------------------- //
13 // Create date: 07-12-2006 //
14 // Modification date: 09-02-2007 //
16 
17 using System;
18 using System.Collections.Generic;
19 using System.IO;
20 using System.Text;
21 
22 using ErrorManagement;
23 using Tools;
24 
25 namespace AST
26 {
35  public class SourceFile : AstNode
36  {
37  #region Fields
38 
42  private List<string> usings;
43 
47  private Dictionary<string, List<Namespace>> namespaceDefinitions;
48 
52  private List<Declaration> declarations;
53 
54  #endregion
55 
56  #region Properties
57 
58 
62  public List<string> Usings
63  {
64  get { return this.usings; }
65  }
66 
70  public Dictionary<string, List<Namespace>>.KeyCollection Namespacekeys
71  {
72  get { return this.namespaceDefinitions.Keys; }
73  }
74 
78  public int DeclarationCount
79  {
80  get { return this.declarations.Count; }
81  }
82 
83  #endregion
84 
85  #region Constructor
86 
93  public SourceFile(Location loc)
94  : base(loc)
95  {
96  this.usings = new List<string>();
97  this.namespaceDefinitions = new Dictionary<string, List<Namespace>>();
98  this.declarations = new List<Declaration>();
99  }
100 
101  #endregion
102 
103  #region AddUsing()
104 
110  public void AddUsing(string include)
111  {
112  this.usings.Add(include);
113  }
114 
115  #endregion
116 
117  #region AddDeclaration()
118 
123  public void AddDeclaration(Declaration declaration)
124  {
125  this.declarations.Add(declaration);
126  }
127 
128  #endregion
129 
130  #region AddNamespace()
131 
137  public void AddNamespace(IdentifierExpression name, List<Declaration> declaration)
138  {
139  if (!namespaceDefinitions.ContainsKey(name.Identifier))
140  {
141  this.namespaceDefinitions.Add(name.Identifier, new List<Namespace>());
142  }
143  this.namespaceDefinitions[name.Identifier].Add(new Namespace(name, declaration, name.Location));
144  }
145 
146  #endregion
147 
148  #region GetDeclarationElement()
149 
156  {
157  return this.declarations[index];
158  }
159 
160  #endregion
161 
162  #region GetNamespaceDefinitionCount
163 
168  public int GetNamespaceDefinitionCount(string name)
169  {
170  if (this.namespaceDefinitions.ContainsKey(name))
171  return this.namespaceDefinitions[name].Count;
172  return 0;
173  }
174 
175  #endregion
176 
177  #region GetNamespaceDeclarationElement()
178 
185  public Namespace GetNamespaceDeclarationElement(string name, int index)
186  {
187  if (this.namespaceDefinitions.ContainsKey(name))
188  return this.namespaceDefinitions[name][index];
189  return null;
190  }
191 
192  #endregion
193 
194  #region Accept()
195 
202  public override Object Accept(Visitor v, Object o)
203  {
204  return v.Visit(this, o);
205  }
206 
207  #endregion
208  }
209 }
Declaration GetDeclarationElement(int index)
Gets the element stored in the specified index.
Definition: SourceFile.cs:155
Encapsulates a name expression of our programming language.
void AddNamespace(IdentifierExpression name, List< Declaration > declaration)
Add a new namespace definition.
Definition: SourceFile.cs:137
Encapsulates a namespace definition.
Definition: Namespace.cs:35
Abstract class to define different visits over the abstract syntax tree.
Definition: Visitor.cs:29
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.
Definition: Location.cs:24
override Object Accept(Visitor v, Object o)
Accept method of a concrete visitor.
Definition: SourceFile.cs:202
Location Location
Definition: AstNode.cs:45
int DeclarationCount
Gets the number of declarations out of namespace definition.
Definition: SourceFile.cs:79
Namespace GetNamespaceDeclarationElement(string name, int index)
Gets the element stored in the specified namespace and index.
Definition: SourceFile.cs:185
Dictionary< string, List< Namespace > >.KeyCollection Namespacekeys
Gets the keys of namespace definition.
Definition: SourceFile.cs:71
SourceFile(Location loc)
Constructor of SourceFile
Definition: SourceFile.cs:93
Abstract class for all nodes that compounds the abstract syntax tree.
Definition: AstNode.cs:33
Encapsulates the source code.
Definition: SourceFile.cs:35
Encapsulates a declaration of a concrete type.
Definition: Declaration.cs:34
int GetNamespaceDefinitionCount(string name)
Gets the number of declaration into the specified namespace.
Definition: SourceFile.cs:168
void AddUsing(string include)
Add a new include file.
Definition: SourceFile.cs:110
void AddDeclaration(Declaration declaration)
Add a new declaration.
Definition: SourceFile.cs:123
string Identifier
Gets the name name.
List< string > Usings
Gets the included files.
Definition: SourceFile.cs:63