Mercurial > projects > ddmd
annotate dmd/ScopeDsymbol.d @ 79:43073c7c7769
updated to 2.035
also implemented a few missing functions
still crashes in Import.importAll though
author | Trass3r |
---|---|
date | Mon, 30 Aug 2010 03:57:51 +0200 |
parents | ad4792a1cfd6 |
children | e28b18c23469 |
rev | line source |
---|---|
0 | 1 module dmd.ScopeDsymbol; |
2 | |
3 import dmd.Dsymbol; | |
4 import dmd.Declaration; | |
5 import dmd.Array; | |
6 import dmd.OverloadSet; | |
7 import dmd.Import; | |
8 import dmd.DsymbolTable; | |
9 import dmd.Identifier; | |
10 import dmd.Loc; | |
11 import dmd.PROT; | |
12 import dmd.FuncDeclaration; | |
13 import dmd.Scope; | |
14 import dmd.Util; | |
15 import dmd.Id; | |
16 import dmd.expression.Util; | |
17 | |
79 | 18 import std.stdio : writef; |
19 //core.stdc.stdlib; | |
4 | 20 import core.memory; |
0 | 21 |
22 class ScopeDsymbol : Dsymbol | |
23 { | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
24 Dsymbols members; // all Dsymbol's in this scope |
0 | 25 DsymbolTable symtab; // members[] sorted into table |
26 | |
27 Array imports; // imported ScopeDsymbol's | |
28 PROT* prots; // array of PROT, one for each import | |
29 | |
30 this() | |
31 { | |
32 // do nothing | |
33 } | |
34 | |
35 this(Identifier id) | |
36 { | |
37 super(id); | |
38 } | |
39 | |
72 | 40 override Dsymbol syntaxCopy(Dsymbol s) |
0 | 41 { |
20
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
4
diff
changeset
|
42 //printf("ScopeDsymbol.syntaxCopy('%s')\n", toChars()); |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
4
diff
changeset
|
43 |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
4
diff
changeset
|
44 ScopeDsymbol sd; |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
4
diff
changeset
|
45 if (s) |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
4
diff
changeset
|
46 sd = cast(ScopeDsymbol)s; |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
4
diff
changeset
|
47 else |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
4
diff
changeset
|
48 sd = new ScopeDsymbol(ident); |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
4
diff
changeset
|
49 sd.members = arraySyntaxCopy(members); |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
4
diff
changeset
|
50 return sd; |
0 | 51 } |
52 | |
72 | 53 override Dsymbol search(Loc loc, Identifier ident, int flags) |
0 | 54 { |
55 //printf("%s.ScopeDsymbol.search(ident='%s', flags=x%x)\n", toChars(), ident.toChars(), flags); | |
56 //if (strcmp(ident.toChars(),"c") == 0) *(char*)0=0; | |
57 | |
58 // Look in symbols declared in this module | |
59 Dsymbol s = symtab ? symtab.lookup(ident) : null; | |
79 | 60 // writef("\ts = %p, imports = %p, %d\n", s, imports, imports ? imports->dim : 0); |
0 | 61 if (s) |
62 { | |
63 //printf("\ts = '%s.%s'\n",toChars(),s.toChars()); | |
64 } | |
65 else if (imports) | |
66 { | |
67 OverloadSet a = null; | |
68 | |
69 // Look in imported modules | |
70 for (int i = 0; i < imports.dim; i++) | |
71 { | |
72 ScopeDsymbol ss = cast(ScopeDsymbol)imports.data[i]; | |
73 Dsymbol s2; | |
74 | |
75 // If private import, don't search it | |
76 if (flags & 1 && prots[i] == PROT.PROTprivate) | |
77 continue; | |
78 | |
79 //printf("\tscanning import '%s', prots = %d, isModule = %p, isImport = %p\n", ss.toChars(), prots[i], ss.isModule(), ss.isImport()); | |
80 /* Don't find private members if ss is a module | |
81 */ | |
82 s2 = ss.search(loc, ident, ss.isModule() ? 1 : 0); | |
83 if (!s) | |
84 s = s2; | |
85 else if (s2 && s != s2) | |
86 { | |
87 if (s.toAlias() == s2.toAlias()) | |
88 { | |
89 /* After following aliases, we found the same symbol, | |
90 * so it's not an ambiguity. | |
91 * But if one alias is deprecated, prefer the other. | |
92 */ | |
93 if (s.isDeprecated()) | |
94 s = s2; | |
95 } | |
96 else | |
97 { | |
98 /* Two imports of the same module should be regarded as | |
99 * the same. | |
100 */ | |
101 Import i1 = s.isImport(); | |
102 Import i2 = s2.isImport(); | |
103 if (!(i1 && i2 && | |
104 (i1.mod == i2.mod || | |
105 (!i1.parent.isImport() && !i2.parent.isImport() && | |
106 i1.ident.equals(i2.ident)) | |
107 ) | |
108 ) | |
109 ) | |
110 { | |
111 /* If both s2 and s are overloadable (though we only | |
112 * need to check s once) | |
113 */ | |
114 if (s2.isOverloadable() && (a || s.isOverloadable())) | |
115 { if (!a) | |
116 a = new OverloadSet(); | |
117 /* Don't add to a[] if s2 is alias of previous sym | |
118 */ | |
77
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
74
diff
changeset
|
119 foreach (size_t j, Dsymbol s3; a.a) |
0 | 120 { |
121 if (s2.toAlias() == s3.toAlias()) | |
122 { | |
123 if (s3.isDeprecated()) | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
124 a.a[j] = s2; |
0 | 125 goto Lcontinue; |
126 } | |
127 } | |
128 a.push(s2); | |
129 Lcontinue: | |
130 continue; | |
131 } | |
132 if (flags & 4) // if return null on ambiguity | |
133 return null; | |
134 if (!(flags & 2)) | |
135 ss.multiplyDefined(loc, s, s2); | |
136 break; | |
137 } | |
138 } | |
139 } | |
140 } | |
141 | |
142 /* Build special symbol if we had multiple finds | |
143 */ | |
144 if (a) | |
145 { | |
146 assert(s); | |
147 a.push(s); | |
148 s = a; | |
149 } | |
150 | |
151 if (s) | |
152 { | |
153 Declaration d = s.isDeclaration(); | |
154 if (d && d.protection == PROT.PROTprivate && !d.parent.isTemplateMixin() && !(flags & 2)) | |
155 error("%s is private", d.toPrettyChars()); | |
156 } | |
157 } | |
158 return s; | |
159 } | |
160 | |
161 void importScope(ScopeDsymbol s, PROT protection) | |
162 { | |
79 | 163 //writef("%s.ScopeDsymbol.importScope(%s, %d)\n", toChars(), s.toChars(), protection); |
0 | 164 |
165 // No circular or redundant import's | |
79 | 166 if (s !is this) |
0 | 167 { |
168 if (!imports) | |
169 imports = new Array(); | |
170 else | |
171 { | |
172 for (int i = 0; i < imports.dim; i++) | |
173 { | |
174 ScopeDsymbol ss = cast(ScopeDsymbol)imports.data[i]; | |
175 if (ss is s) // if already imported | |
176 { | |
177 if (protection > prots[i]) | |
178 prots[i] = protection; // upgrade access | |
179 return; | |
180 } | |
181 } | |
182 } | |
183 imports.push(cast(void*)s); | |
2 | 184 prots = cast(PROT*)GC.realloc(prots, imports.dim * prots[0].sizeof); |
0 | 185 prots[imports.dim - 1] = protection; |
186 } | |
187 } | |
188 | |
72 | 189 override int isforwardRef() |
0 | 190 { |
79 | 191 return (members is null); |
0 | 192 } |
193 | |
72 | 194 override void defineRef(Dsymbol s) |
0 | 195 { |
79 | 196 ScopeDsymbol ss = s.isScopeDsymbol(); |
197 members = ss.members; | |
198 ss.members = null; | |
0 | 199 } |
200 | |
201 static void multiplyDefined(Loc loc, Dsymbol s1, Dsymbol s2) | |
202 { | |
203 static if (false) { | |
204 printf("ScopeDsymbol::multiplyDefined()\n"); | |
205 printf("s1 = %p, '%s' kind = '%s', parent = %s\n", s1, s1.toChars(), s1.kind(), s1.parent ? s1.parent.toChars() : ""); | |
206 printf("s2 = %p, '%s' kind = '%s', parent = %s\n", s2, s2.toChars(), s2.kind(), s2.parent ? s2.parent.toChars() : ""); | |
207 } | |
208 if (loc.filename) | |
209 { | |
210 .error(loc, "%s at %s conflicts with %s at %s", | |
211 s1.toPrettyChars(), | |
212 s1.locToChars(), | |
213 s2.toPrettyChars(), | |
214 s2.locToChars()); | |
215 } | |
216 else | |
217 { | |
218 s1.error(loc, "conflicts with %s %s at %s", s2.kind(), s2.toPrettyChars(), s2.locToChars()); | |
219 } | |
220 } | |
221 | |
222 Dsymbol nameCollision(Dsymbol s) | |
223 { | |
224 assert(false); | |
225 } | |
226 | |
72 | 227 override string kind() |
0 | 228 { |
229 assert(false); | |
230 } | |
231 | |
79 | 232 version(DMDV2) |
233 { | |
0 | 234 /******************************************* |
235 * Look for member of the form: | |
236 * const(MemberInfo)[] getMembers(string); | |
237 * Returns NULL if not found | |
238 */ | |
239 FuncDeclaration findGetMembers() | |
240 { | |
241 Dsymbol s = search_function(this, Id.getmembers); | |
242 FuncDeclaration fdx = s ? s.isFuncDeclaration() : null; | |
243 | |
244 static if (false) { // Finish | |
245 static __gshared TypeFunction tfgetmembers; | |
246 | |
247 if (!tfgetmembers) | |
248 { | |
249 Scope sc; | |
250 Arguments arguments = new Arguments(); | |
251 Arguments arg = new Argument(STCin, Type.tchar.constOf().arrayOf(), null, null); | |
252 arguments.push(arg); | |
253 | |
254 Type tret = null; | |
255 tfgetmembers = new TypeFunction(arguments, tret, 0, LINK.LINKd); | |
256 tfgetmembers = cast(TypeFunction)tfgetmembers.semantic(0, &sc); | |
257 } | |
258 if (fdx) | |
259 fdx = fdx.overloadExactMatch(tfgetmembers); | |
260 } | |
261 if (fdx && fdx.isVirtual()) { | |
262 fdx = null; | |
263 } | |
264 | |
265 return fdx; | |
266 } | |
79 | 267 } |
268 | |
269 Dsymbol symtabInsert(Dsymbol s) | |
270 { | |
271 return symtab.insert(s); | |
272 } | |
0 | 273 |
274 void emitMemberComments(Scope sc) | |
275 { | |
276 assert(false); | |
277 } | |
278 | |
79 | 279 version(DMDV2) |
280 { | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
281 static size_t dim(Dsymbols members) |
0 | 282 { |
283 assert(false); | |
284 } | |
79 | 285 |
286 | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
287 static Dsymbol getNth(Dsymbols members, size_t nth, size_t* pn = null) |
0 | 288 { |
289 assert(false); | |
290 } | |
79 | 291 } |
72 | 292 override ScopeDsymbol isScopeDsymbol() { return this; } |
20
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
4
diff
changeset
|
293 } |