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