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