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