17 using System.Collections.Generic;
20 using ErrorManagement;
42 private Dictionary<string, TypeExpression> table;
47 private Dictionary<string, System.Type> map;
58 get {
return instance; }
70 this.table =
new Dictionary<string, TypeExpression>();
85 this.table.Add(
"object",
new BCLClassType(
"System.Object", Type.GetType(
"System.Object")));
88 this.map =
new Dictionary<string, Type>(5);
89 this.map.Add(IntType.Instance.ToString(), Type.GetType(
"System.Int32"));
90 this.map.Add(DoubleType.Instance.ToString(), Type.GetType(
"System.Double"));
91 this.map.Add(CharType.Instance.ToString(), Type.GetType(
"System.Char"));
92 this.map.Add(StringType.Instance.ToString(), Type.GetType(
"System.String"));
93 this.map.Add(BoolType.Instance.ToString(), Type.GetType(
"System.Boolean"));
94 this.map.Add(VoidType.Instance.ToString(), Type.GetType(
"System.Void"));
103 instance =
new TypeTable();
123 if (this.table.ContainsKey(name))
124 return this.table[name];
127 Type type = Type.GetType(name,
false);
129 TypeExpression te = Introspection.createBCLUserType(name, type, location);
139 #region TypeExpressionToType()
148 Type[] aux =
new Type[typ.GetLength(0)];
150 for (
int i = 0; i < typ.GetLength(0); i++)
152 if (this.map.ContainsKey(typ[i].
FullName))
153 aux[i] = this.map[typ[i].FullName];
157 aux[i] = ((IBCLUserType)typ[i]).TypeInfo;
159 ErrorManager.Instance.NotifyError(
new UnknownTypeError(typ[i].FullName, location));
167 #region ContainsType()
176 return this.table.ContainsKey(key);
193 if (!this.table.ContainsKey(name))
194 this.table.Add(name, type);
205 if (!this.table.ContainsKey(type.
FullName))
206 this.table.Add(type.
FullName, type);
211 #region ObtainNewType()
215 if (type.StartsWith(
"Var("))
217 string aux = Convert.ToString(TypeSystem.TypeVariable.NewTypeVariable);
218 int index = type.IndexOf(
')', 3) + 1;
219 type = type.Substring(index, type.Length - index);
237 Dictionary<string, TypeExpression>.KeyCollection keys = this.table.Keys;
238 foreach (
string key
in keys)
240 aux.AppendFormat(
"{0}\t\t\t{1}", key, this.table[key].ToString());
243 return aux.ToString();
static StringType Instance
Gets the unique instance of StringType
static CharType Instance
Gets the unique instance of CharType
override string FullName
The full name in type variables is calculated just in time
static DoubleType Instance
Gets the unique instance of DoubleType
static TypeTable Instance
Gets the unique instance of TypeTable
static string ObtainNewType(string type)
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.
Represent a character type.
Abstract class that represents all different types.
Represents a error produced when the defined type already exists.
Represents a generic type expression
TypeExpression GetType(string name, Location location)
Gets the type associated to the name specified in the argument.
System.Text.StringBuilder StringBuilder
virtual string FullName
Gets the full name of the type Note: WriteType expression is the longest recursive representation of ...
Represent a integer type.
Type[] TypeExpressionToType(TypeExpression[] typ, Location location)
Gets the type of the type expression.
Represents a double type.
bool ContainsType(string key)
Returns if the type table contains the specified tmpName.
Implementation of a table of types.
void AddType(string name, TypeExpression type, Location location)
Adds a new type into the type table
static VoidType Instance
Gets the unique instance of VoidType
static IntType Instance
Gets the unique instance of IntType
static BoolType Instance
Gets the unique instance of BoolType
void AddVarType(TypeVariable type)
Adds a new variable type
override string ToString()
Dumps the information stores in the table of types.
void Clear()
Clears the type table (debug purposes)