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