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