Mercurial > projects > ddmd
annotate dmd/TypeIdentifier.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 | e3afd1303184 |
children |
rev | line source |
---|---|
0 | 1 module dmd.TypeIdentifier; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.TypeQualified; |
5 import dmd.MOD; | |
6 import dmd.Identifier; | |
7 import dmd.IdentifierExp; | |
8 import dmd.DotIdExp; | |
9 import dmd.TypeTypedef; | |
10 import dmd.Loc; | |
11 import dmd.OutBuffer; | |
12 import dmd.HdrGenState; | |
13 import dmd.Expression; | |
14 import dmd.Scope; | |
15 import dmd.Type; | |
16 import dmd.Dsymbol; | |
17 import dmd.MATCH; | |
18 import dmd.ArrayTypes; | |
19 import dmd.TY; | |
20 import dmd.Util; | |
21 | |
22 debug import dmd.Global; | |
23 | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
24 import dmd.DDMDExtensions; |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
25 |
0 | 26 class TypeIdentifier : TypeQualified |
27 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
28 mixin insertMemberExtension!(typeof(this)); |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
29 |
0 | 30 Identifier ident; |
31 | |
32 this(Loc loc, Identifier ident) | |
33 { | |
178 | 34 register(); |
0 | 35 super(TY.Tident, loc); |
36 this.ident = ident; | |
37 } | |
38 | |
72 | 39 override Type syntaxCopy() |
0 | 40 { |
41 TypeIdentifier t = new TypeIdentifier(loc, ident); | |
42 t.syntaxCopyHelper(this); | |
43 t.mod = mod; | |
44 | |
45 return t; | |
46 } | |
47 | |
48 //char *toChars(); | |
49 | |
72 | 50 override void toDecoBuffer(OutBuffer buf, int flag) |
0 | 51 { |
52 Type.toDecoBuffer(buf, flag); | |
53 string name = ident.toChars(); | |
54 buf.printf("%d%s", name.length, name); | |
55 } | |
56 | |
72 | 57 override void toCBuffer2(OutBuffer buf, HdrGenState* hgs, MOD mod) |
0 | 58 { |
59 if (mod != this.mod) | |
60 { | |
61 toCBuffer3(buf, hgs, mod); | |
62 return; | |
63 } | |
64 buf.writestring(this.ident.toChars()); | |
65 toCBuffer2Helper(buf, hgs); | |
66 } | |
67 | |
68 /************************************* | |
69 * Takes an array of Identifiers and figures out if | |
70 * it represents a Type or an Expression. | |
71 * Output: | |
72 * if expression, *pe is set | |
73 * if type, *pt is set | |
74 */ | |
72 | 75 override void resolve(Loc loc, Scope sc, Expression* pe, Type* pt, Dsymbol* ps) |
0 | 76 { |
77 Dsymbol scopesym; | |
78 | |
79 //printf("TypeIdentifier::resolve(sc = %p, idents = '%s')\n", sc, toChars()); | |
80 Dsymbol s = sc.search(loc, ident, &scopesym); | |
81 resolveHelper(loc, sc, s, scopesym, pe, pt, ps); | |
82 if (*pt) | |
83 (*pt) = (*pt).addMod(mod); | |
84 } | |
85 | |
86 /***************************************** | |
87 * See if type resolves to a symbol, if so, | |
88 * return that symbol. | |
89 */ | |
72 | 90 override Dsymbol toDsymbol(Scope sc) |
0 | 91 { |
92 //printf("TypeIdentifier::toDsymbol('%s')\n", toChars()); | |
93 if (!sc) | |
94 return null; | |
95 //printf("ident = '%s'\n", ident.toChars()); | |
96 | |
97 Dsymbol scopesym; | |
98 Dsymbol s = sc.search(loc, ident, &scopesym); | |
99 if (s) | |
100 { | |
101 for (int i = 0; i < idents.dim; i++) | |
102 { | |
103 Identifier id = cast(Identifier)idents.data[i]; | |
104 s = s.searchX(loc, sc, id); | |
105 if (!s) // failed to find a symbol | |
106 { | |
107 //printf("\tdidn't find a symbol\n"); | |
108 break; | |
109 } | |
110 } | |
111 } | |
112 | |
113 return s; | |
114 } | |
115 | |
72 | 116 override Type semantic(Loc loc, Scope sc) |
0 | 117 { |
118 Type t; | |
119 Expression e; | |
120 Dsymbol s; | |
121 | |
122 //printf("TypeIdentifier::semantic(%s)\n", toChars()); | |
123 resolve(loc, sc, &e, &t, &s); | |
124 if (t) | |
125 { | |
126 //printf("\tit's a type %d, %s, %s\n", t.ty, t.toChars(), t.deco); | |
127 | |
128 if (t.ty == TY.Ttypedef) | |
129 { | |
130 TypeTypedef tt = cast(TypeTypedef)t; | |
131 | |
132 if (tt.sym.sem == 1) | |
133 error(loc, "circular reference of typedef %s", tt.toChars()); | |
134 } | |
135 t = t.addMod(mod); | |
136 } | |
137 else | |
138 { | |
139 debug { | |
140 if (!global.gag) { | |
141 writef("1: "); | |
142 } | |
143 } | |
144 if (s) | |
145 { | |
146 s.error(loc, "is used as a type"); | |
147 //halt(); | |
148 } | |
149 else { | |
150 error(loc, "%s is used as a type", toChars()); | |
151 } | |
152 t = tvoid; | |
153 } | |
154 //t.print(); | |
155 return t; | |
156 } | |
157 | |
72 | 158 override MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes) |
0 | 159 { |
51 | 160 // Extra check |
161 if (tparam && tparam.ty == Tident) | |
162 { | |
163 TypeIdentifier tp = cast(TypeIdentifier)tparam; | |
164 | |
165 for (int i = 0; i < idents.dim; i++) | |
166 { | |
167 Identifier id1 = cast(Identifier)idents.data[i]; | |
168 Identifier id2 = cast(Identifier)tp.idents.data[i]; | |
169 | |
170 if (!id1.equals(id2)) | |
171 return MATCHnomatch; | |
172 } | |
173 } | |
174 return Type.deduceType(sc, tparam, parameters, dedtypes); | |
0 | 175 } |
176 | |
72 | 177 override Type reliesOnTident() |
0 | 178 { |
179 return this; | |
180 } | |
181 | |
72 | 182 override Expression toExpression() |
0 | 183 { |
184 Expression e = new IdentifierExp(loc, ident); | |
185 for (int i = 0; i < idents.dim; i++) | |
186 { | |
187 Identifier id = cast(Identifier)idents.data[i]; | |
188 e = new DotIdExp(loc, e, id); | |
189 } | |
190 | |
191 return e; | |
192 } | |
72 | 193 } |