Mercurial > projects > ddmd
annotate dmd/IdentifierExp.d @ 187:b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
author | Abscissa |
---|---|
date | Tue, 07 Jun 2011 23:37:34 -0400 |
parents | cd48cb899aee |
children | 52188e7e3fb5 |
rev | line source |
---|---|
72 | 1 module dmd.IdentifierExp; |
2 | |
114 | 3 import dmd.common; |
72 | 4 import dmd.Expression; |
5 import dmd.Declaration; | |
6 import dmd.TY; | |
7 import dmd.TypePointer; | |
8 import dmd.FuncDeclaration; | |
9 import dmd.TemplateInstance; | |
179 | 10 import dmd.Id; |
11 import dmd.VarDeclaration; | |
72 | 12 import dmd.TemplateDeclaration; |
13 import dmd.TemplateExp; | |
14 import dmd.DsymbolExp; | |
15 import dmd.Identifier; | |
16 import dmd.OutBuffer; | |
17 import dmd.Loc; | |
18 import dmd.Scope; | |
19 import dmd.Dsymbol; | |
20 import dmd.WithScopeSymbol; | |
21 import dmd.VarExp; | |
22 import dmd.DotIdExp; | |
23 import dmd.Type; | |
24 import dmd.HdrGenState; | |
25 import dmd.TOK; | |
26 | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
179
diff
changeset
|
27 import dmd.DDMDExtensions; |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
179
diff
changeset
|
28 |
0 | 29 class IdentifierExp : Expression |
30 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
179
diff
changeset
|
31 mixin insertMemberExtension!(typeof(this)); |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
179
diff
changeset
|
32 |
0 | 33 Identifier ident; |
34 | |
35 Declaration var; | |
36 | |
37 this(Loc loc, Identifier ident) | |
38 { | |
178 | 39 register(); |
72 | 40 super(loc, TOK.TOKidentifier, IdentifierExp.sizeof); |
0 | 41 this.ident = ident; |
42 } | |
43 | |
44 this(Loc loc, Declaration var) | |
45 { | |
178 | 46 register(); |
72 | 47 assert(false); |
0 | 48 super(loc, TOK.init, 0); |
49 } | |
50 | |
72 | 51 override Expression semantic(Scope sc) |
0 | 52 { |
72 | 53 Dsymbol s; |
54 Dsymbol scopesym; | |
55 | |
56 version (LOGSEMANTIC) { | |
57 printf("IdentifierExp.semantic('%s')\n", ident.toChars()); | |
58 } | |
59 s = sc.search(loc, ident, &scopesym); | |
60 if (s) | |
61 { | |
62 Expression e; | |
63 WithScopeSymbol withsym; | |
64 | |
65 /* See if the symbol was a member of an enclosing 'with' | |
66 */ | |
67 withsym = scopesym.isWithScopeSymbol(); | |
68 if (withsym) | |
69 { | |
70 version (DMDV2) { | |
71 /* Disallow shadowing | |
72 */ | |
73 // First find the scope of the with | |
74 Scope scwith = sc; | |
75 while (scwith.scopesym !is scopesym) | |
76 { | |
77 scwith = scwith.enclosing; | |
78 assert(scwith); | |
79 } | |
80 | |
81 // Look at enclosing scopes for symbols with the same name, | |
82 // in the same function | |
83 for (Scope scx = scwith; scx && scx.func == scwith.func; scx = scx.enclosing) | |
84 { | |
85 Dsymbol s2; | |
86 | |
87 if (scx.scopesym && scx.scopesym.symtab && (s2 = scx.scopesym.symtab.lookup(s.ident)) !is null && s !is s2) | |
88 { | |
89 error("with symbol %s is shadowing local symbol %s", s.toPrettyChars(), s2.toPrettyChars()); | |
90 } | |
91 } | |
92 } | |
93 s = s.toAlias(); | |
94 | |
95 // Same as wthis.ident | |
96 if (s.needThis() || s.isTemplateDeclaration()) | |
97 { | |
98 e = new VarExp(loc, withsym.withstate.wthis); | |
99 e = new DotIdExp(loc, e, ident); | |
100 } | |
101 else | |
102 { | |
103 Type t = withsym.withstate.wthis.type; | |
104 if (t.ty == TY.Tpointer) | |
105 t = (cast(TypePointer)t).next; | |
106 e = typeDotIdExp(loc, t, ident); | |
107 } | |
108 } | |
109 else | |
110 { | |
111 /* If f is really a function template, | |
112 * then replace f with the function template declaration. | |
113 */ | |
114 FuncDeclaration f = s.isFuncDeclaration(); | |
115 if (f && f.parent) | |
116 { | |
117 TemplateInstance ti = f.parent.isTemplateInstance(); | |
118 | |
119 if (ti && !ti.isTemplateMixin() && | |
120 (ti.name == f.ident || ti.toAlias().ident == f.ident) && | |
121 ti.tempdecl && ti.tempdecl.onemember) | |
122 { | |
123 TemplateDeclaration tempdecl = ti.tempdecl; | |
124 | |
125 if (tempdecl.overroot) // if not start of overloaded list of TemplateDeclaration's | |
126 tempdecl = tempdecl.overroot; // then get the start | |
127 | |
128 e = new TemplateExp(loc, tempdecl); | |
129 e = e.semantic(sc); | |
130 | |
131 return e; | |
132 } | |
133 } | |
134 | |
135 // Haven't done overload resolution yet, so pass 1 | |
136 e = new DsymbolExp(loc, s, 1); | |
137 } | |
138 | |
139 return e.semantic(sc); | |
140 } | |
179 | 141 |
142 if (ident == Id.ctfe) | |
143 { | |
144 // Create the magic __ctfe bool variable | |
145 VarDeclaration vd = new VarDeclaration(loc, Type.tbool, Id.ctfe, null); | |
146 Expression e = new VarExp(loc, vd); | |
147 e = e.semantic(sc); | |
148 return e; | |
149 } | |
72 | 150 |
151 error("undefined identifier %s", ident.toChars()); | |
152 type = Type.terror; | |
0 | 153 return this; |
154 } | |
155 | |
72 | 156 override string toChars() |
0 | 157 { |
158 return ident.toChars(); | |
159 } | |
160 | |
72 | 161 override void dump(int indent) |
0 | 162 { |
163 assert(false); | |
164 } | |
165 | |
72 | 166 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 167 { |
72 | 168 if (hgs.hdrgen) |
169 buf.writestring(ident.toHChars2()); | |
170 else | |
0 | 171 buf.writestring(ident.toChars()); |
172 } | |
173 | |
72 | 174 override int isLvalue() |
0 | 175 { |
68
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
0
diff
changeset
|
176 return 1; |
0 | 177 } |
178 | |
72 | 179 override Expression toLvalue(Scope sc, Expression e) |
0 | 180 { |
72 | 181 static if (false) { |
182 tym = tybasic(e1.ET.Tty); | |
183 if (!(tyscalar(tym) || tym == TYM.TYstruct || tym == TYM.TYarray && e.Eoper == TOK.TOKaddr)) | |
184 synerr(EM_lvalue); // lvalue expected | |
185 } | |
0 | 186 return this; |
187 } | |
188 } | |
189 |