The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
DeclarationTable.cs
Go to the documentation of this file.
1 // -------------------------------------------------------------------------- //
3 // Project rROTOR //
4 // -------------------------------------------------------------------------- //
5 // File: DeclarationTable.cs //
6 // Author: Cristina Gonzalez Muņoz - cristi.gm@gmail.com //
7 // Description: //
8 // Implementation of a table of declarations. //
9 // -------------------------------------------------------------------------- //
10 // Create date: 31-01-2007 //
11 // Modification date: 27-02-2007 //
13 
14 using System;
15 using System.Collections.Generic;
16 using System.IO;
17 using System.Text;
18 
19 using ErrorManagement;
20 using TypeSystem.Operations;
21 namespace TypeSystem
22 {
27  {
28  #region Fields
29 
33  private Dictionary<string, TypeExpression> table;
34 
35  #endregion
36 
37  #region DEBUG
38 
39  //private StreamWriter sw;
40 
44  //public void Close()
45  //{
46  // sw.Close();
47  //}
48 
49  #endregion
50 
51  #region Constructor
52 
57  {
58  this.table = new Dictionary<string, TypeExpression>();
59  //sw = new StreamWriter("DeclarationTable"+name+".txt");
60  }
61 
62  #endregion
63 
64 
65 
66  #region Reset()
67 
71  public void Reset() //string id
72  {
73  this.table.Clear();
74  //this.sw.WriteLine("Close Scope: {0}", id);
75  }
76 
77  #endregion
78 
79  #region AddDeclaration()
80 
89  public void AddDeclaration(string name, TypeExpression type, Location location)
90  {
91  if (!this.table.ContainsKey(name))
92  {
93  this.table.Add(name, type);
94  //sw.WriteLine("\t{0}\t\t{1}:{2}", name, type.FullName, type.ToString());
95  }
96  else
97  ErrorManager.Instance.NotifyError(new DeclarationFoundError(name, location));
98  }
99 
100  #endregion
101 
102  #region SearchType()
103 
109  public TypeExpression SearchType(string name)
110  {
111  if (this.table.ContainsKey(name))
112  return this.table[name];
113  return null;
114  }
115 
116  #endregion
117  }
118 }
void AddDeclaration(string name, TypeExpression type, Location location)
Adds a new declaration into their scope.
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
Represents a error produced when the declaration already exists.
Implementation of a table of declarations.
Abstract class that represents all different types.
void Reset()
Removes the last information.
TypeExpression SearchType(string name)
Gets the type associated to the declaration name.
DeclarationTable()
Constructor of class DeclarationTable.