annotate dmd/TypeIdentifier.d @ 178:e3afd1303184

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