annotate dmd/TypeIdentifier.d @ 114:e28b18c23469

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