Mercurial > projects > ddmd
annotate dmd/TemplateTupleParameter.d @ 137:09c858522d55
merge
author | Trass3r |
---|---|
date | Mon, 13 Sep 2010 23:29:00 +0200 |
parents | e28b18c23469 |
children | e3afd1303184 |
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 | |
23 class TemplateTupleParameter : TemplateParameter | |
24 { | |
25 /* Syntax: | |
26 * ident ... | |
27 */ | |
28 | |
29 this(Loc loc, Identifier ident) | |
30 { | |
31 super(loc, ident); | |
32 this.ident = ident; | |
33 } | |
34 | |
72 | 35 override TemplateTupleParameter isTemplateTupleParameter() |
0 | 36 { |
37 return this; | |
38 } | |
39 | |
72 | 40 override TemplateParameter syntaxCopy() |
0 | 41 { |
42 TemplateTupleParameter tp = new TemplateTupleParameter(loc, ident); | |
43 return tp; | |
44 } | |
45 | |
72 | 46 override void declareParameter(Scope sc) |
0 | 47 { |
48 TypeIdentifier ti = new TypeIdentifier(loc, ident); | |
49 sparam = new AliasDeclaration(loc, ident, ti); | |
50 if (!sc.insert(sparam)) | |
51 error(loc, "parameter '%s' multiply defined", ident.toChars()); | |
52 } | |
53 | |
72 | 54 override void semantic(Scope) |
0 | 55 { |
56 } | |
57 | |
72 | 58 override void print(Object oarg, Object oded) |
0 | 59 { |
60 writef(" %s... [", ident.toChars()); | |
61 Tuple v = isTuple(oded); | |
62 assert(v); | |
63 | |
64 //printf("|%d| ", v.objects.dim); | |
65 for (int i = 0; i < v.objects.dim; i++) | |
66 { | |
67 if (i) | |
68 writef(", "); | |
69 | |
113
3482c73a991b
More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
94
diff
changeset
|
70 Object o = v.objects[i]; |
0 | 71 |
72 Dsymbol sa = isDsymbol(o); | |
73 if (sa) | |
74 writef("alias: %s", sa.toChars()); | |
75 | |
76 Type ta = isType(o); | |
77 if (ta) | |
78 writef("type: %s", ta.toChars()); | |
79 | |
80 Expression ea = isExpression(o); | |
81 if (ea) | |
82 writef("exp: %s", ea.toChars()); | |
83 | |
84 assert(!isTuple(o)); // no nested Tuple arguments | |
85 } | |
86 | |
87 writef("]\n"); | |
88 } | |
89 | |
72 | 90 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 91 { |
92 buf.writestring(ident.toChars()); | |
93 buf.writestring("..."); | |
94 } | |
95 | |
72 | 96 override Object specialization() |
0 | 97 { |
98 return null; | |
99 } | |
100 | |
72 | 101 override Object defaultArg(Loc loc, Scope sc) |
0 | 102 { |
103 return null; | |
104 } | |
105 | |
72 | 106 override bool overloadMatch(TemplateParameter tp) |
0 | 107 { |
108 TemplateTupleParameter tvp = tp.isTemplateTupleParameter(); | |
109 if (tvp) { | |
110 return true; // match | |
111 } | |
112 | |
113 Lnomatch: | |
114 return false; | |
115 } | |
116 | |
72 | 117 override MATCH matchArg(Scope sc, Objects tiargs, int i, TemplateParameters parameters, Objects dedtypes, Declaration* psparam, int flags) |
0 | 118 { |
119 //printf("TemplateTupleParameter.matchArg()\n"); | |
120 | |
121 /* The rest of the actual arguments (tiargs[]) form the match | |
122 * for the variadic parameter. | |
123 */ | |
124 assert(i + 1 == dedtypes.dim); // must be the last one | |
125 Tuple ovar; | |
113
3482c73a991b
More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
94
diff
changeset
|
126 if (i + 1 == tiargs.dim && isTuple(tiargs[i])) |
3482c73a991b
More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
94
diff
changeset
|
127 ovar = isTuple(tiargs[i]); |
0 | 128 else |
129 { | |
130 ovar = new Tuple(); | |
131 //printf("ovar = %p\n", ovar); | |
132 if (i < tiargs.dim) | |
133 { | |
134 //printf("i = %d, tiargs.dim = %d\n", i, tiargs.dim); | |
135 ovar.objects.setDim(tiargs.dim - i); | |
136 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
|
137 ovar.objects[j] = tiargs[i + j]; |
0 | 138 } |
139 } | |
140 *psparam = new TupleDeclaration(loc, ident, ovar.objects); | |
94
3a0b150c9841
Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
141 dedtypes[i] = ovar; |
0 | 142 |
143 return MATCH.MATCHexact; | |
144 } | |
145 | |
94
3a0b150c9841
Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
146 override Object dummyArg() |
0 | 147 { |
148 return null; | |
149 } | |
72 | 150 } |