annotate dmd/ScopeExp.d @ 0:10317f0c89a5

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