Mercurial > projects > ddmd
annotate dmd/TemplateTupleParameter.d @ 192:eb38fdcb3e62 default tip
updated to compile with dmd2.062
author | korDen |
---|---|
date | Sat, 02 Mar 2013 01:25:52 -0800 |
parents | b0d41ff5e0df |
children |
rev | line source |
---|---|
0 | 1 module dmd.TemplateTupleParameter; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.TemplateParameter; |
5 import dmd.Loc; | |
6 import dmd.Identifier; | |
7 import dmd.TypeIdentifier; | |
8 import dmd.AliasDeclaration; | |
9 import dmd.Scope; | |
10 import dmd.ArrayTypes; | |
11 import dmd.MATCH; | |
12 import dmd.Declaration; | |
13 import dmd.OutBuffer; | |
14 import dmd.HdrGenState; | |
15 import dmd.Util; | |
16 import dmd.Tuple; | |
17 import dmd.Dsymbol; | |
18 import dmd.TemplateInstance; | |
19 import dmd.Type; | |
20 import dmd.Expression; | |
21 import dmd.TupleDeclaration; | |
22 | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
23 import dmd.DDMDExtensions; |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
24 |
0 | 25 class TemplateTupleParameter : TemplateParameter |
26 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
27 mixin insertMemberExtension!(typeof(this)); |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
28 |
0 | 29 /* Syntax: |
30 * ident ... | |
31 */ | |
32 | |
33 this(Loc loc, Identifier ident) | |
34 { | |
178 | 35 register(); |
0 | 36 super(loc, ident); |
37 this.ident = ident; | |
38 } | |
39 | |
72 | 40 override TemplateTupleParameter isTemplateTupleParameter() |
0 | 41 { |
42 return this; | |
43 } | |
44 | |
72 | 45 override TemplateParameter syntaxCopy() |
0 | 46 { |
47 TemplateTupleParameter tp = new TemplateTupleParameter(loc, ident); | |
48 return tp; | |
49 } | |
50 | |
72 | 51 override void declareParameter(Scope sc) |
0 | 52 { |
53 TypeIdentifier ti = new TypeIdentifier(loc, ident); | |
54 sparam = new AliasDeclaration(loc, ident, ti); | |
55 if (!sc.insert(sparam)) | |
56 error(loc, "parameter '%s' multiply defined", ident.toChars()); | |
57 } | |
58 | |
72 | 59 override void semantic(Scope) |
0 | 60 { |
61 } | |
62 | |
72 | 63 override void print(Object oarg, Object oded) |
0 | 64 { |
65 writef(" %s... [", ident.toChars()); | |
66 Tuple v = isTuple(oded); | |
67 assert(v); | |
68 | |
69 //printf("|%d| ", v.objects.dim); | |
70 for (int i = 0; i < v.objects.dim; i++) | |
71 { | |
72 if (i) | |
73 writef(", "); | |
74 | |
113
3482c73a991b
More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
94
diff
changeset
|
75 Object o = v.objects[i]; |
0 | 76 |
77 Dsymbol sa = isDsymbol(o); | |
78 if (sa) | |
79 writef("alias: %s", sa.toChars()); | |
80 | |
81 Type ta = isType(o); | |
82 if (ta) | |
83 writef("type: %s", ta.toChars()); | |
84 | |
85 Expression ea = isExpression(o); | |
86 if (ea) | |
87 writef("exp: %s", ea.toChars()); | |
88 | |
89 assert(!isTuple(o)); // no nested Tuple arguments | |
90 } | |
91 | |
92 writef("]\n"); | |
93 } | |
94 | |
72 | 95 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 96 { |
97 buf.writestring(ident.toChars()); | |
98 buf.writestring("..."); | |
99 } | |
100 | |
72 | 101 override Object specialization() |
0 | 102 { |
103 return null; | |
104 } | |
105 | |
72 | 106 override Object defaultArg(Loc loc, Scope sc) |
0 | 107 { |
108 return null; | |
109 } | |
110 | |
72 | 111 override bool overloadMatch(TemplateParameter tp) |
0 | 112 { |
113 TemplateTupleParameter tvp = tp.isTemplateTupleParameter(); | |
114 if (tvp) { | |
115 return true; // match | |
116 } | |
117 | |
118 Lnomatch: | |
119 return false; | |
120 } | |
121 | |
72 | 122 override MATCH matchArg(Scope sc, Objects tiargs, int i, TemplateParameters parameters, Objects dedtypes, Declaration* psparam, int flags) |
0 | 123 { |
124 //printf("TemplateTupleParameter.matchArg()\n"); | |
125 | |
126 /* The rest of the actual arguments (tiargs[]) form the match | |
127 * for the variadic parameter. | |
128 */ | |
129 assert(i + 1 == dedtypes.dim); // must be the last one | |
130 Tuple ovar; | |
113
3482c73a991b
More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
94
diff
changeset
|
131 if (i + 1 == tiargs.dim && isTuple(tiargs[i])) |
3482c73a991b
More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
94
diff
changeset
|
132 ovar = isTuple(tiargs[i]); |
0 | 133 else |
134 { | |
135 ovar = new Tuple(); | |
136 //printf("ovar = %p\n", ovar); | |
137 if (i < tiargs.dim) | |
138 { | |
139 //printf("i = %d, tiargs.dim = %d\n", i, tiargs.dim); | |
140 ovar.objects.setDim(tiargs.dim - i); | |
141 for (size_t j = 0; j < ovar.objects.dim; j++) | |
113
3482c73a991b
More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
94
diff
changeset
|
142 ovar.objects[j] = tiargs[i + j]; |
0 | 143 } |
144 } | |
145 *psparam = new TupleDeclaration(loc, ident, ovar.objects); | |
94
3a0b150c9841
Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
146 dedtypes[i] = ovar; |
0 | 147 |
148 return MATCH.MATCHexact; | |
149 } | |
150 | |
94
3a0b150c9841
Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
151 override Object dummyArg() |
0 | 152 { |
153 return null; | |
154 } | |
72 | 155 } |