0
|
1 module dmd.DotTemplateInstanceExp;
|
|
2
|
|
3 import dmd.Expression;
|
|
4 import dmd.UnaExp;
|
|
5 import dmd.OutBuffer;
|
|
6 import dmd.Loc;
|
|
7 import dmd.Scope;
|
|
8 import dmd.TemplateInstance;
|
|
9 import dmd.HdrGenState;
|
2
|
10 import dmd.TOK;
|
|
11 import dmd.PREC;
|
|
12 import dmd.Declaration;
|
|
13 import dmd.Global;
|
|
14 import dmd.TypePointer;
|
|
15 import dmd.TypeStruct;
|
|
16 import dmd.TY;
|
|
17 import dmd.ScopeExp;
|
|
18 import dmd.DotExp;
|
|
19 import dmd.Type;
|
|
20 import dmd.Identifier;
|
|
21 import dmd.ErrorExp;
|
|
22 import dmd.DotVarExp;
|
|
23 import dmd.TemplateDeclaration;
|
|
24 import dmd.Dsymbol;
|
|
25
|
|
26 import dmd.expression.Util;
|
|
27
|
|
28 /* Things like:
|
|
29 * foo.bar!(args)
|
|
30 */
|
0
|
31 class DotTemplateInstanceExp : UnaExp
|
|
32 {
|
|
33 TemplateInstance ti;
|
|
34
|
|
35 this(Loc loc, Expression e, TemplateInstance ti)
|
2
|
36 {
|
|
37 super(loc, TOK.TOKdotti, DotTemplateInstanceExp.sizeof, e);
|
|
38 //printf("DotTemplateInstanceExp()\n");
|
|
39 this.ti = ti;
|
0
|
40 }
|
|
41
|
|
42 Expression syntaxCopy()
|
|
43 {
|
2
|
44 DotTemplateInstanceExp de = new DotTemplateInstanceExp(loc, e1.syntaxCopy(), cast(TemplateInstance)ti.syntaxCopy(null));
|
|
45 return de;
|
0
|
46 }
|
|
47
|
|
48 Expression semantic(Scope sc)
|
|
49 {
|
2
|
50 Dsymbol s;
|
|
51 Dsymbol s2;
|
|
52 TemplateDeclaration td;
|
|
53 Expression e;
|
|
54 Identifier id;
|
|
55 Type t1;
|
|
56 Expression eleft = null;
|
|
57 Expression eright;
|
|
58
|
|
59 version (LOGSEMANTIC) {
|
|
60 printf("DotTemplateInstanceExp.semantic('%s')\n", toChars());
|
|
61 }
|
|
62 //e1.print();
|
|
63 //print();
|
|
64 e1 = e1.semantic(sc);
|
|
65 t1 = e1.type;
|
|
66 if (t1)
|
|
67 t1 = t1.toBasetype();
|
|
68 //t1.print();
|
|
69
|
|
70 /* Extract the following from e1:
|
|
71 * s: the symbol which ti should be a member of
|
|
72 * eleft: if not null, it is the 'this' pointer for ti
|
|
73 */
|
|
74
|
|
75 if (e1.op == TOKdotexp)
|
|
76 {
|
|
77 DotExp de = cast(DotExp)e1;
|
|
78 eleft = de.e1;
|
|
79 eright = de.e2;
|
|
80 }
|
|
81 else
|
|
82 {
|
|
83 eleft = null;
|
|
84 eright = e1;
|
|
85 }
|
|
86 if (eright.op == TOKimport)
|
|
87 {
|
|
88 s = (cast(ScopeExp)eright).sds;
|
|
89 }
|
|
90 else if (e1.op == TOKtype)
|
|
91 {
|
|
92 s = t1.isClassHandle();
|
|
93 if (!s)
|
|
94 {
|
|
95 if (t1.ty == Tstruct)
|
|
96 s = (cast(TypeStruct)t1).sym;
|
|
97 else
|
|
98 goto L1;
|
|
99 }
|
|
100 }
|
|
101 else if (t1 && (t1.ty == Tstruct || t1.ty == Tclass))
|
|
102 {
|
|
103 s = t1.toDsymbol(sc);
|
|
104 eleft = e1;
|
|
105 }
|
|
106 else if (t1 && t1.ty == Tpointer)
|
|
107 {
|
|
108 t1 = (cast(TypePointer)t1).next.toBasetype();
|
|
109 if (t1.ty != Tstruct)
|
|
110 goto L1;
|
|
111 s = t1.toDsymbol(sc);
|
|
112 eleft = e1;
|
|
113 }
|
|
114 else
|
|
115 {
|
|
116 L1:
|
|
117 error("template %s is not a member of %s", ti.toChars(), e1.toChars());
|
|
118 goto Lerr;
|
|
119 }
|
|
120
|
|
121 assert(s);
|
|
122 id = ti.name;
|
|
123 s2 = s.search(loc, id, 0);
|
|
124 if (!s2)
|
|
125 {
|
|
126 if (!s.ident)
|
|
127 error("template identifier %s is not a member of undefined %s", id.toChars(), s.kind());
|
|
128 else
|
|
129 error("template identifier %s is not a member of %s %s", id.toChars(), s.kind(), s.ident.toChars());
|
|
130 goto Lerr;
|
|
131 }
|
|
132 s = s2;
|
|
133 s.semantic(sc);
|
|
134 s = s.toAlias();
|
|
135 td = s.isTemplateDeclaration();
|
|
136 if (!td)
|
|
137 {
|
|
138 error("%s is not a template", id.toChars());
|
|
139 goto Lerr;
|
|
140 }
|
|
141 if (global.errors)
|
|
142 goto Lerr;
|
|
143
|
|
144 ti.tempdecl = td;
|
|
145
|
|
146 if (eleft)
|
|
147 {
|
|
148 Declaration v;
|
|
149
|
|
150 ti.semantic(sc);
|
|
151 s = ti.inst.toAlias();
|
|
152 v = s.isDeclaration();
|
|
153 if (v)
|
|
154 {
|
|
155 e = new DotVarExp(loc, eleft, v);
|
|
156 e = e.semantic(sc);
|
|
157 return e;
|
|
158 }
|
|
159 }
|
|
160
|
|
161 e = new ScopeExp(loc, ti);
|
|
162 if (eleft)
|
|
163 {
|
|
164 e = new DotExp(loc, eleft, e);
|
|
165 }
|
|
166 e = e.semantic(sc);
|
|
167 return e;
|
|
168
|
|
169 Lerr:
|
|
170 return new ErrorExp();
|
0
|
171 }
|
|
172
|
|
173 void toCBuffer(OutBuffer buf, HdrGenState* hgs)
|
|
174 {
|
2
|
175 expToCBuffer(buf, hgs, e1, PREC.PREC_primary);
|
|
176 buf.writeByte('.');
|
|
177 ti.toCBuffer(buf, hgs);
|
0
|
178 }
|
|
179
|
|
180 void dump(int indent)
|
|
181 {
|
|
182 assert(false);
|
|
183 }
|
|
184 }
|
|
185
|