Mercurial > projects > ddmd
comparison dmd/ScopeExp.d @ 0:10317f0c89a5
Initial commit
author | korDen |
---|---|
date | Sat, 24 Oct 2009 08:42:06 +0400 |
parents | |
children | 2e2a5c3f943a |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:10317f0c89a5 |
---|---|
1 module dmd.ScopeExp; | |
2 | |
3 import dmd.Expression; | |
4 import dmd.backend.elem; | |
5 import dmd.ScopeDsymbol; | |
6 import dmd.OutBuffer; | |
7 import dmd.TemplateInstance; | |
8 import dmd.Loc; | |
9 import dmd.TOK; | |
10 import dmd.Scope; | |
11 import dmd.IRState; | |
12 import dmd.HdrGenState; | |
13 import dmd.Global; | |
14 import dmd.Dsymbol; | |
15 import dmd.VarExp; | |
16 import dmd.DotVarExp; | |
17 import dmd.DsymbolExp; | |
18 import dmd.Type; | |
19 | |
20 class ScopeExp : Expression | |
21 { | |
22 ScopeDsymbol sds; | |
23 | |
24 this(Loc loc, ScopeDsymbol pkg) | |
25 { | |
26 super(loc, TOK.TOKimport, ScopeExp.sizeof); | |
27 //printf("ScopeExp.ScopeExp(pkg = '%s')\n", pkg.toChars()); | |
28 //static int count; if (++count == 38) *(char*)0=0; | |
29 this.sds = pkg; | |
30 } | |
31 | |
32 Expression syntaxCopy() | |
33 { | |
34 ScopeExp se = new ScopeExp(loc, cast(ScopeDsymbol)sds.syntaxCopy(null)); | |
35 return se; | |
36 } | |
37 | |
38 Expression semantic(Scope sc) | |
39 { | |
40 TemplateInstance ti; | |
41 ScopeDsymbol sds2; | |
42 | |
43 version (LOGSEMANTIC) { | |
44 printf("+ScopeExp.semantic('%s')\n", toChars()); | |
45 } | |
46 Lagain: | |
47 ti = sds.isTemplateInstance(); | |
48 if (ti && !global.errors) | |
49 { | |
50 Dsymbol s; | |
51 if (!ti.semanticRun) | |
52 ti.semantic(sc); | |
53 s = ti.inst.toAlias(); | |
54 sds2 = s.isScopeDsymbol(); | |
55 if (!sds2) | |
56 { | |
57 Expression e; | |
58 | |
59 //printf("s = %s, '%s'\n", s.kind(), s.toChars()); | |
60 if (ti.withsym) | |
61 { | |
62 // Same as wthis.s | |
63 e = new VarExp(loc, ti.withsym.withstate.wthis); | |
64 e = new DotVarExp(loc, e, s.isDeclaration()); | |
65 } | |
66 else | |
67 e = new DsymbolExp(loc, s); | |
68 | |
69 e = e.semantic(sc); | |
70 //printf("-1ScopeExp.semantic()\n"); | |
71 return e; | |
72 } | |
73 if (sds2 != sds) | |
74 { | |
75 sds = sds2; | |
76 goto Lagain; | |
77 } | |
78 //printf("sds = %s, '%s'\n", sds.kind(), sds.toChars()); | |
79 } | |
80 else | |
81 { | |
82 //printf("sds = %s, '%s'\n", sds.kind(), sds.toChars()); | |
83 //printf("\tparent = '%s'\n", sds.parent.toChars()); | |
84 sds.semantic(sc); | |
85 } | |
86 type = Type.tvoid; | |
87 //printf("-2ScopeExp.semantic() %s\n", toChars()); | |
88 return this; | |
89 } | |
90 | |
91 elem* toElem(IRState* irs) | |
92 { | |
93 assert(false); | |
94 } | |
95 | |
96 void toCBuffer(OutBuffer buf, HdrGenState* hgs) | |
97 { | |
98 if (sds.isTemplateInstance()) | |
99 { | |
100 sds.toCBuffer(buf, hgs); | |
101 } | |
102 else | |
103 { | |
104 buf.writestring(sds.kind()); | |
105 buf.writestring(" "); | |
106 buf.writestring(sds.toChars()); | |
107 } | |
108 } | |
109 } | |
110 |