1 module dsymbol.builtin.symbols;
2 
3 import dsymbol.symbol;
4 import dsymbol.builtin.names;
5 import dsymbol.string_interning;
6 import containers.ttree;
7 import stdx.allocator;
8 import stdx.allocator.mallocator;
9 import dparse.lexer;
10 
11 /**
12  * Symbols for the built in types
13  */
14 TTree!(DSymbol*, Mallocator, true, "a < b", false) builtinSymbols;
15 
16 /**
17  * Array properties
18  */
19 TTree!(DSymbol*, Mallocator, true, "a < b", false) arraySymbols;
20 
21 /**
22  * Associative array properties
23  */
24 TTree!(DSymbol*, Mallocator, true, "a < b", false) assocArraySymbols;
25 
26 /**
27  * Struct, enum, union, class, and interface properties
28  */
29 TTree!(DSymbol*, Mallocator, true, "a < b", false) aggregateSymbols;
30 
31 /**
32  * Class properties
33  */
34 TTree!(DSymbol*, Mallocator, true, "a < b", false) classSymbols;
35 
36 /**
37  * Enum properties
38  */
39 TTree!(DSymbol*, Mallocator, true, "a < b", false) enumSymbols;
40 
41 static this()
42 {
43 	auto bool_ = make!DSymbol(Mallocator.instance, builtinTypeNames[13], CompletionKind.keyword);
44 	auto int_ = make!DSymbol(Mallocator.instance, builtinTypeNames[0], CompletionKind.keyword);
45 	auto long_ = make!DSymbol(Mallocator.instance, builtinTypeNames[8], CompletionKind.keyword);
46 	auto byte_ = make!DSymbol(Mallocator.instance, builtinTypeNames[19], CompletionKind.keyword);
47 	auto char_ = make!DSymbol(Mallocator.instance, builtinTypeNames[10], CompletionKind.keyword);
48 	auto dchar_ = make!DSymbol(Mallocator.instance, builtinTypeNames[12], CompletionKind.keyword);
49 	auto short_ = make!DSymbol(Mallocator.instance, builtinTypeNames[6], CompletionKind.keyword);
50 	auto ubyte_ = make!DSymbol(Mallocator.instance, builtinTypeNames[20], CompletionKind.keyword);
51 	auto uint_ = make!DSymbol(Mallocator.instance, builtinTypeNames[1], CompletionKind.keyword);
52 	auto ulong_ = make!DSymbol(Mallocator.instance, builtinTypeNames[9], CompletionKind.keyword);
53 	auto ushort_ = make!DSymbol(Mallocator.instance, builtinTypeNames[7], CompletionKind.keyword);
54 	auto wchar_ = make!DSymbol(Mallocator.instance, builtinTypeNames[11], CompletionKind.keyword);
55 
56 	auto alignof_ = make!DSymbol(Mallocator.instance, internString("alignof"), CompletionKind.keyword);
57 	auto mangleof_ = make!DSymbol(Mallocator.instance, internString("mangleof"), CompletionKind.keyword);
58 	auto sizeof_ = make!DSymbol(Mallocator.instance, internString("sizeof"), CompletionKind.keyword);
59 	auto stringof_ = make!DSymbol(Mallocator.instance, internString("stringof"), CompletionKind.keyword);
60 	auto init = make!DSymbol(Mallocator.instance, internString("init"), CompletionKind.keyword);
61 	auto min = make!DSymbol(Mallocator.instance, internString("min"), CompletionKind.keyword);
62 	auto max = make!DSymbol(Mallocator.instance, internString("max"), CompletionKind.keyword);
63 	auto dup = make!DSymbol(Mallocator.instance, internString("dup"), CompletionKind.keyword);
64 	auto length = make!DSymbol(Mallocator.instance, internString("length"), CompletionKind.keyword, ulong_);
65 	auto tupleof = make!DSymbol(Mallocator.instance, internString("tupleof"), CompletionKind.keyword);
66 
67 	arraySymbols.insert(alignof_);
68 	arraySymbols.insert(dup);
69 	arraySymbols.insert(make!DSymbol(Mallocator.instance, internString("idup"), CompletionKind.keyword));
70 	arraySymbols.insert(init);
71 	arraySymbols.insert(length);
72 	arraySymbols.insert(mangleof_);
73 	arraySymbols.insert(make!DSymbol(Mallocator.instance, internString("ptr"), CompletionKind.keyword));
74 	arraySymbols.insert(sizeof_);
75 	arraySymbols.insert(stringof_);
76 
77 	assocArraySymbols.insert(alignof_);
78 	assocArraySymbols.insert(make!DSymbol(Mallocator.instance, internString("byKey"), CompletionKind.keyword));
79 	assocArraySymbols.insert(make!DSymbol(Mallocator.instance, internString("byValue"), CompletionKind.keyword));
80 	assocArraySymbols.insert(make!DSymbol(Mallocator.instance, internString("clear"), CompletionKind.keyword));
81 	assocArraySymbols.insert(dup);
82 	assocArraySymbols.insert(make!DSymbol(Mallocator.instance, internString("get"), CompletionKind.keyword));
83 	assocArraySymbols.insert(make!DSymbol(Mallocator.instance, internString("init"), CompletionKind.keyword));
84 	assocArraySymbols.insert(make!DSymbol(Mallocator.instance, internString("keys"), CompletionKind.keyword));
85 	assocArraySymbols.insert(length);
86 	assocArraySymbols.insert(mangleof_);
87 	assocArraySymbols.insert(make!DSymbol(Mallocator.instance, internString("rehash"), CompletionKind.keyword));
88 	assocArraySymbols.insert(sizeof_);
89 	assocArraySymbols.insert(stringof_);
90 	assocArraySymbols.insert(init);
91 	assocArraySymbols.insert(make!DSymbol(Mallocator.instance, internString("values"), CompletionKind.keyword));
92 
93 	DSymbol*[11] integralTypeArray;
94 	integralTypeArray[0] = bool_;
95 	integralTypeArray[1] = int_;
96 	integralTypeArray[2] = long_;
97 	integralTypeArray[3] = byte_;
98 	integralTypeArray[4] = char_;
99 	integralTypeArray[4] = dchar_;
100 	integralTypeArray[5] = short_;
101 	integralTypeArray[6] = ubyte_;
102 	integralTypeArray[7] = uint_;
103 	integralTypeArray[8] = ulong_;
104 	integralTypeArray[9] = ushort_;
105 	integralTypeArray[10] = wchar_;
106 
107 	foreach (s; integralTypeArray)
108 	{
109 		s.addChild(make!DSymbol(Mallocator.instance, internString("init"), CompletionKind.keyword, s), true);
110 		s.addChild(make!DSymbol(Mallocator.instance, internString("min"), CompletionKind.keyword, s), true);
111 		s.addChild(make!DSymbol(Mallocator.instance, internString("max"), CompletionKind.keyword, s), true);
112 		s.addChild(alignof_, false);
113 		s.addChild(sizeof_, false);
114 		s.addChild(stringof_, false);
115 		s.addChild(mangleof_, false);
116 	}
117 
118 	auto cdouble_ = make!DSymbol(Mallocator.instance, builtinTypeNames[21], CompletionKind.keyword);
119 	auto cent_ = make!DSymbol(Mallocator.instance, builtinTypeNames[15], CompletionKind.keyword);
120 	auto cfloat_ = make!DSymbol(Mallocator.instance, builtinTypeNames[22], CompletionKind.keyword);
121 	auto creal_ = make!DSymbol(Mallocator.instance, builtinTypeNames[23], CompletionKind.keyword);
122 	auto double_ = make!DSymbol(Mallocator.instance, builtinTypeNames[2], CompletionKind.keyword);
123 	auto float_ = make!DSymbol(Mallocator.instance, builtinTypeNames[4], CompletionKind.keyword);
124 	auto idouble_ = make!DSymbol(Mallocator.instance, builtinTypeNames[3], CompletionKind.keyword);
125 	auto ifloat_ = make!DSymbol(Mallocator.instance, builtinTypeNames[5], CompletionKind.keyword);
126 	auto ireal_ = make!DSymbol(Mallocator.instance, builtinTypeNames[18], CompletionKind.keyword);
127 	auto real_ = make!DSymbol(Mallocator.instance, builtinTypeNames[17], CompletionKind.keyword);
128 	auto ucent_ = make!DSymbol(Mallocator.instance, builtinTypeNames[16], CompletionKind.keyword);
129 
130 	DSymbol*[11] floatTypeArray;
131 	floatTypeArray[0] = cdouble_;
132 	floatTypeArray[1] = cent_;
133 	floatTypeArray[2] = cfloat_;
134 	floatTypeArray[3] = creal_;
135 	floatTypeArray[4] = double_;
136 	floatTypeArray[5] = float_;
137 	floatTypeArray[6] = idouble_;
138 	floatTypeArray[7] = ifloat_;
139 	floatTypeArray[8] = ireal_;
140 	floatTypeArray[9] = real_;
141 	floatTypeArray[10] = ucent_;
142 
143 	foreach (s; floatTypeArray)
144 	{
145 		s.addChild(alignof_, false);
146 		s.addChild(make!DSymbol(Mallocator.instance, internString("dig"), CompletionKind.keyword, s), true);
147 		s.addChild(make!DSymbol(Mallocator.instance, internString("epsilon"), CompletionKind.keyword, s), true);
148 		s.addChild(make!DSymbol(Mallocator.instance, internString("infinity"), CompletionKind.keyword, s), true);
149 		s.addChild(make!DSymbol(Mallocator.instance, internString("init"), CompletionKind.keyword, s), true);
150 		s.addChild(mangleof_, false);
151 		s.addChild(make!DSymbol(Mallocator.instance, internString("mant_dig"), CompletionKind.keyword, int_), true);
152 		s.addChild(make!DSymbol(Mallocator.instance, internString("max"), CompletionKind.keyword, s), true);
153 		s.addChild(make!DSymbol(Mallocator.instance, internString("max_10_exp"), CompletionKind.keyword, int_), true);
154 		s.addChild(make!DSymbol(Mallocator.instance, internString("max_exp"), CompletionKind.keyword, int_), true);
155 		s.addChild(make!DSymbol(Mallocator.instance, internString("min_exp"), CompletionKind.keyword, int_), true);
156 		s.addChild(make!DSymbol(Mallocator.instance, internString("min_10_exp"), CompletionKind.keyword, int_), true);
157 		s.addChild(make!DSymbol(Mallocator.instance, internString("min_normal"), CompletionKind.keyword, s), true);
158 		s.addChild(make!DSymbol(Mallocator.instance, internString("nan"), CompletionKind.keyword, s), true);
159 		s.addChild(sizeof_, false);
160 		s.addChild(stringof_, false);
161 	}
162 
163 	aggregateSymbols.insert(tupleof);
164 	aggregateSymbols.insert(mangleof_);
165 	aggregateSymbols.insert(alignof_);
166 	aggregateSymbols.insert(sizeof_);
167 	aggregateSymbols.insert(stringof_);
168 	aggregateSymbols.insert(init);
169 
170 	classSymbols.insert(make!DSymbol(Mallocator.instance, internString("classinfo"), CompletionKind.variableName));
171 	classSymbols.insert(tupleof);
172 	classSymbols.insert(make!DSymbol(Mallocator.instance, internString("__vptr"), CompletionKind.variableName));
173 	classSymbols.insert(make!DSymbol(Mallocator.instance, internString("__monitor"), CompletionKind.variableName));
174 	classSymbols.insert(mangleof_);
175 	classSymbols.insert(alignof_);
176 	classSymbols.insert(sizeof_);
177 	classSymbols.insert(stringof_);
178 	classSymbols.insert(init);
179 
180 	enumSymbols.insert(init);
181 	enumSymbols.insert(sizeof_);
182 	enumSymbols.insert(alignof_);
183 	enumSymbols.insert(mangleof_);
184 	enumSymbols.insert(stringof_);
185 	enumSymbols.insert(min);
186 	enumSymbols.insert(max);
187 
188 
189 	ireal_.addChild(make!DSymbol(Mallocator.instance, internString("im"), CompletionKind.keyword, real_), true);
190 	ifloat_.addChild(make!DSymbol(Mallocator.instance, internString("im"), CompletionKind.keyword, float_), true);
191 	idouble_.addChild(make!DSymbol(Mallocator.instance, internString("im"), CompletionKind.keyword, double_), true);
192 	ireal_.addChild(make!DSymbol(Mallocator.instance, internString("re"), CompletionKind.keyword, real_), true);
193 	ifloat_.addChild(make!DSymbol(Mallocator.instance, internString("re"), CompletionKind.keyword, float_), true);
194 	idouble_.addChild(make!DSymbol(Mallocator.instance, internString("re"), CompletionKind.keyword, double_), true);
195 
196 	auto void_ = make!DSymbol(Mallocator.instance, builtinTypeNames[14], CompletionKind.keyword);
197 
198 	builtinSymbols.insert(bool_);
199 	bool_.type = bool_;
200 	builtinSymbols.insert(int_);
201 	int_.type = int_;
202 	builtinSymbols.insert(long_);
203 	long_.type = long_;
204 	builtinSymbols.insert(byte_);
205 	byte_.type = byte_;
206 	builtinSymbols.insert(char_);
207 	char_.type = char_;
208 	builtinSymbols.insert(dchar_);
209 	dchar_.type = dchar_;
210 	builtinSymbols.insert(short_);
211 	short_.type = short_;
212 	builtinSymbols.insert(ubyte_);
213 	ubyte_.type = ubyte_;
214 	builtinSymbols.insert(uint_);
215 	uint_.type = uint_;
216 	builtinSymbols.insert(ulong_);
217 	ulong_.type = ulong_;
218 	builtinSymbols.insert(ushort_);
219 	ushort_.type = ushort_;
220 	builtinSymbols.insert(wchar_);
221 	wchar_.type = wchar_;
222 	builtinSymbols.insert(cdouble_);
223 	cdouble_.type = cdouble_;
224 	builtinSymbols.insert(cent_);
225 	cent_.type = cent_;
226 	builtinSymbols.insert(cfloat_);
227 	cfloat_.type = cfloat_;
228 	builtinSymbols.insert(creal_);
229 	creal_.type = creal_;
230 	builtinSymbols.insert(double_);
231 	double_.type = double_;
232 	builtinSymbols.insert(float_);
233 	float_.type = float_;
234 	builtinSymbols.insert(idouble_);
235 	idouble_.type = idouble_;
236 	builtinSymbols.insert(ifloat_);
237 	ifloat_.type = ifloat_;
238 	builtinSymbols.insert(ireal_);
239 	ireal_.type = ireal_;
240 	builtinSymbols.insert(real_);
241 	real_.type = real_;
242 	builtinSymbols.insert(ucent_);
243 	ucent_.type = ucent_;
244 	builtinSymbols.insert(void_);
245 	void_.type = void_;
246 
247 
248 	foreach (s; ["__DATE__", "__EOF__", "__TIME__", "__TIMESTAMP__", "__VENDOR__",
249 			"__VERSION__", "__FUNCTION__", "__PRETTY_FUNCTION__", "__MODULE__",
250 			"__FILE__", "__LINE__", "__FILE_FULL_PATH__"])
251 		builtinSymbols.insert(make!DSymbol(Mallocator.instance, internString(s), CompletionKind.keyword));
252 }