annotate dmd/TypeIdentifier.d @ 72:2e2a5c3f943a

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