The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
TypeMapping.cs
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
3 // Project rROTOR
4 // --------------------------------------------------------------------------
5 // File: TypeMapping.cs
6 // Author: Francisco Ortin - francisco.ortin@gmail.com
7 // Description:
8 // Offers the mappings between different representations of types in IL.
9 // Implements Singleton [Singleton].
10 // --------------------------------------------------------------------------
11 // Create date: 21-08-2007
12 // Modification date: 21-08-2007
14 
15 using System;
16 using System.Collections.Generic;
17 
18 
19 namespace CodeGeneration {
23  class TypeMapping {
24 
25  #region SingletonDesingPattern
26  private static TypeMapping instance = new TypeMapping();
27 
28  public static TypeMapping Instance {
29  get { return instance; }
30  }
31 
32  private TypeMapping() {
33  // * Types that require boxing
34  this.requireBoxing = new List<string>();
35  this.requireBoxing.Add("bool");
36  this.requireBoxing.Add("char");
37  this.requireBoxing.Add("int32");
38  this.requireBoxing.Add("float64");
39  // * Mapping of types
40  this.mappings = new Dictionary<string, string>();
41  this.mappings["bool"] = "System.Boolean";
42  this.mappings["char"] = "System.Char";
43  this.mappings["int32"] = "System.Int32";
44  this.mappings["float64"] = "System.Double";
45  this.mappings["string"] = "System.String";
46  this.mappings["object"] = "System.Object";
47  }
48  #endregion
49 
50  #region Fields
51  private IList<string> requireBoxing;
56 
61  private IDictionary<string, string> mappings;
62  #endregion
63 
64 
65  #region RequiresBoxing
66  public bool RequireBoxing(string ilType) {
72  return this.requireBoxing.Contains(ilType);
73  }
74  #endregion
75 
76 
83  public string GetBCLName(string ilType, bool includeLibrary) {
84  if (this.mappings.ContainsKey(ilType))
85  // * It is a built-in type
86  return includeLibrary ? "[mscorlib]"+this.mappings[ilType] : this.mappings[ilType];
87  if (this.mappings.Values.Contains(ilType))
88  // * It is a BCL type
89  return includeLibrary ? "[mscorlib]" + ilType : ilType;
90  // * Another type
91  return ilType;
92  }
93 
94  }
95 }
bool RequireBoxing(string ilType)
Tells if an IL type requires boxing to convert into an object
Definition: TypeMapping.cs:71
static TypeMapping Instance
Definition: TypeMapping.cs:28
Offers the mappings between different representations of types in IL.
Definition: TypeMapping.cs:23
string GetBCLName(string ilType, bool includeLibrary)
Obtains the BCL representation of an IL type
Definition: TypeMapping.cs:83