1 module dsymbol.builtin.names;
2 
3 import dparse.lexer;
4 import dsymbol.string_interning;
5 
6 package istring[24] builtinTypeNames;
7 
8 /// Constants for buit-in or dummy symbol names
9 istring FUNCTION_SYMBOL_NAME;
10 /// ditto
11 istring IMPORT_SYMBOL_NAME;
12 /// ditto
13 istring ARRAY_SYMBOL_NAME;
14 /// ditto
15 istring ASSOC_ARRAY_SYMBOL_NAME;
16 /// ditto
17 istring POINTER_SYMBOL_NAME;
18 /// ditto
19 istring PARAMETERS_SYMBOL_NAME;
20 /// ditto
21 istring WITH_SYMBOL_NAME;
22 /// ditto
23 istring CONSTRUCTOR_SYMBOL_NAME;
24 /// ditto
25 istring DESTRUCTOR_SYMBOL_NAME;
26 /// ditto
27 istring ARGPTR_SYMBOL_NAME;
28 /// ditto
29 istring ARGUMENTS_SYMBOL_NAME;
30 /// ditto
31 istring THIS_SYMBOL_NAME;
32 /// ditto
33 istring SUPER_SYMBOL_NAME;
34 /// ditto
35 istring UNITTEST_SYMBOL_NAME;
36 /// ditto
37 istring DOUBLE_LITERAL_SYMBOL_NAME;
38 /// ditto
39 istring FLOAT_LITERAL_SYMBOL_NAME;
40 /// ditto
41 istring IDOUBLE_LITERAL_SYMBOL_NAME;
42 /// ditto
43 istring IFLOAT_LITERAL_SYMBOL_NAME;
44 /// ditto
45 istring INT_LITERAL_SYMBOL_NAME;
46 /// ditto
47 istring LONG_LITERAL_SYMBOL_NAME;
48 /// ditto
49 istring REAL_LITERAL_SYMBOL_NAME;
50 /// ditto
51 istring IREAL_LITERAL_SYMBOL_NAME;
52 /// ditto
53 istring UINT_LITERAL_SYMBOL_NAME;
54 /// ditto
55 istring ULONG_LITERAL_SYMBOL_NAME;
56 /// ditto
57 istring CHAR_LITERAL_SYMBOL_NAME;
58 /// ditto
59 istring DSTRING_LITERAL_SYMBOL_NAME;
60 /// ditto
61 istring STRING_LITERAL_SYMBOL_NAME;
62 /// ditto
63 istring WSTRING_LITERAL_SYMBOL_NAME;
64 /// ditto
65 istring BOOL_VALUE_SYMBOL_NAME;
66 
67 /**
68  * Translates the IDs for built-in types into an interned string.
69  */
70 istring getBuiltinTypeName(IdType id) nothrow @nogc @safe
71 {
72 	switch (id)
73 	{
74 	case tok!"int": return builtinTypeNames[0];
75 	case tok!"uint": return builtinTypeNames[1];
76 	case tok!"double": return builtinTypeNames[2];
77 	case tok!"idouble": return builtinTypeNames[3];
78 	case tok!"float": return builtinTypeNames[4];
79 	case tok!"ifloat": return builtinTypeNames[5];
80 	case tok!"short": return builtinTypeNames[6];
81 	case tok!"ushort": return builtinTypeNames[7];
82 	case tok!"long": return builtinTypeNames[8];
83 	case tok!"ulong": return builtinTypeNames[9];
84 	case tok!"char": return builtinTypeNames[10];
85 	case tok!"wchar": return builtinTypeNames[11];
86 	case tok!"dchar": return builtinTypeNames[12];
87 	case tok!"bool": return builtinTypeNames[13];
88 	case tok!"void": return builtinTypeNames[14];
89 	case tok!"cent": return builtinTypeNames[15];
90 	case tok!"ucent": return builtinTypeNames[16];
91 	case tok!"real": return builtinTypeNames[17];
92 	case tok!"ireal": return builtinTypeNames[18];
93 	case tok!"byte": return builtinTypeNames[19];
94 	case tok!"ubyte": return builtinTypeNames[20];
95 	case tok!"cdouble": return builtinTypeNames[21];
96 	case tok!"cfloat": return builtinTypeNames[22];
97 	case tok!"creal": return builtinTypeNames[23];
98 	default: assert (false);
99 	}
100 }
101 
102 
103 /**
104  * Initializes builtin types and the various properties of builtin types
105  */
106 static this()
107 {
108 	builtinTypeNames[0] = internString("int");
109 	builtinTypeNames[1] = internString("uint");
110 	builtinTypeNames[2] = internString("double");
111 	builtinTypeNames[3] = internString("idouble");
112 	builtinTypeNames[4] = internString("float");
113 	builtinTypeNames[5] = internString("ifloat");
114 	builtinTypeNames[6] = internString("short");
115 	builtinTypeNames[7] = internString("ushort");
116 	builtinTypeNames[8] = internString("long");
117 	builtinTypeNames[9] = internString("ulong");
118 	builtinTypeNames[10] = internString("char");
119 	builtinTypeNames[11] = internString("wchar");
120 	builtinTypeNames[12] = internString("dchar");
121 	builtinTypeNames[13] = internString("bool");
122 	builtinTypeNames[14] = internString("void");
123 	builtinTypeNames[15] = internString("cent");
124 	builtinTypeNames[16] = internString("ucent");
125 	builtinTypeNames[17] = internString("real");
126 	builtinTypeNames[18] = internString("ireal");
127 	builtinTypeNames[19] = internString("byte");
128 	builtinTypeNames[20] = internString("ubyte");
129 	builtinTypeNames[21] = internString("cdouble");
130 	builtinTypeNames[22] = internString("cfloat");
131 	builtinTypeNames[23] = internString("creal");
132 
133 	FUNCTION_SYMBOL_NAME = internString("function");
134 	IMPORT_SYMBOL_NAME = internString("import");
135 	ARRAY_SYMBOL_NAME = internString("*arr*");
136 	ASSOC_ARRAY_SYMBOL_NAME = internString("*aa*");
137 	POINTER_SYMBOL_NAME = internString("*");
138 	PARAMETERS_SYMBOL_NAME = internString("*parameters*");
139 	WITH_SYMBOL_NAME = internString("with");
140 	CONSTRUCTOR_SYMBOL_NAME = internString("*constructor*");
141 	DESTRUCTOR_SYMBOL_NAME = internString("~this");
142 	ARGPTR_SYMBOL_NAME = internString("_argptr");
143 	ARGUMENTS_SYMBOL_NAME = internString("_arguments");
144 	THIS_SYMBOL_NAME = internString("this");
145 	SUPER_SYMBOL_NAME = internString("super");
146 	UNITTEST_SYMBOL_NAME = internString("*unittest*");
147 	DOUBLE_LITERAL_SYMBOL_NAME = internString("*double");
148 	FLOAT_LITERAL_SYMBOL_NAME = internString("*float");
149 	IDOUBLE_LITERAL_SYMBOL_NAME = internString("*idouble");
150 	IFLOAT_LITERAL_SYMBOL_NAME = internString("*ifloat");
151 	INT_LITERAL_SYMBOL_NAME = internString("*int");
152 	LONG_LITERAL_SYMBOL_NAME = internString("*long");
153 	REAL_LITERAL_SYMBOL_NAME = internString("*real");
154 	IREAL_LITERAL_SYMBOL_NAME = internString("*ireal");
155 	UINT_LITERAL_SYMBOL_NAME = internString("*uint");
156 	ULONG_LITERAL_SYMBOL_NAME = internString("*ulong");
157 	CHAR_LITERAL_SYMBOL_NAME = internString("*char");
158 	DSTRING_LITERAL_SYMBOL_NAME = internString("*dstring");
159 	STRING_LITERAL_SYMBOL_NAME = internString("*string");
160 	WSTRING_LITERAL_SYMBOL_NAME = internString("*wstring");
161 	BOOL_VALUE_SYMBOL_NAME = internString("*bool");
162 }
163 
164 istring symbolNameToTypeName(istring name)
165 {
166 	if (name.ptr == DOUBLE_LITERAL_SYMBOL_NAME.ptr)
167 		return builtinTypeNames[2];
168 	if (name.ptr == FLOAT_LITERAL_SYMBOL_NAME.ptr)
169 		return builtinTypeNames[4];
170 	if (name.ptr == IDOUBLE_LITERAL_SYMBOL_NAME.ptr)
171 		return builtinTypeNames[3];
172 	if (name.ptr == IFLOAT_LITERAL_SYMBOL_NAME.ptr)
173 		return builtinTypeNames[5];
174 	if (name.ptr == INT_LITERAL_SYMBOL_NAME.ptr)
175 		return builtinTypeNames[0];
176 	if (name.ptr == LONG_LITERAL_SYMBOL_NAME.ptr)
177 		return builtinTypeNames[8];
178 	if (name.ptr == REAL_LITERAL_SYMBOL_NAME.ptr)
179 		return builtinTypeNames[17];
180 	if (name.ptr == IREAL_LITERAL_SYMBOL_NAME.ptr)
181 		return builtinTypeNames[18];
182 	if (name.ptr == UINT_LITERAL_SYMBOL_NAME.ptr)
183 		return builtinTypeNames[1];
184 	if (name.ptr == ULONG_LITERAL_SYMBOL_NAME.ptr)
185 		return builtinTypeNames[9];
186 	if (name.ptr == CHAR_LITERAL_SYMBOL_NAME.ptr)
187 		return builtinTypeNames[10];
188 	if (name.ptr == DSTRING_LITERAL_SYMBOL_NAME.ptr)
189 		return internString("dstring");
190 	if (name.ptr == STRING_LITERAL_SYMBOL_NAME.ptr)
191 		return internString("string");
192 	if (name.ptr == WSTRING_LITERAL_SYMBOL_NAME.ptr)
193 		return internString("wstring");
194 	if (name.ptr == BOOL_VALUE_SYMBOL_NAME.ptr)
195 		return internString("bool");
196 	return name;
197 }