comparison src/dil/ast/Parameters.d @ 806:bcb74c9b895c

Moved out files in the trunk folder to the root.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Sun, 09 Mar 2008 00:12:19 +0100
parents trunk/src/dil/ast/Parameters.d@5fe89bb8cbdd
children 09a64d96967a
comparison
equal deleted inserted replaced
805:a3fab8b74a7d 806:bcb74c9b895c
1 /++
2 Author: Aziz Köksal
3 License: GPL3
4 +/
5 module dil.ast.Parameters;
6
7 import dil.ast.Node;
8 import dil.ast.Type;
9 import dil.ast.Expression;
10 import dil.ast.NodeCopier;
11 import dil.lexer.Identifier;
12 import dil.Enums;
13
14 /// A function or foreach parameter.
15 class Parameter : Node
16 {
17 StorageClass stc; /// The storage classes of the parameter.
18 TypeNode type; /// The parameter's type.
19 Identifier* name; /// The name of the parameter.
20 Expression defValue; /// The default initialization value.
21
22 this(StorageClass stc, TypeNode type, Identifier* name, Expression defValue)
23 {
24 super(NodeCategory.Other);
25 mixin(set_kind);
26 // type can be null when param in foreach statement
27 addOptChild(type);
28 addOptChild(defValue);
29
30 this.stc = stc;
31 this.type = type;
32 this.name = name;
33 this.defValue = defValue;
34 }
35
36 /// Returns true if this is a D-style variadic parameter.
37 /// E.g.: func(int[] values ...)
38 bool isDVariadic()
39 {
40 return isVariadic && !isCVariadic;
41 }
42
43 /// Returns true if this is a C-style variadic parameter.
44 /// E.g.: func(...)
45 bool isCVariadic()
46 {
47 return stc == StorageClass.Variadic &&
48 type is null && name is null;
49 }
50
51 /// Returns true if this is a D- or C-style variadic parameter.
52 bool isVariadic()
53 {
54 return !!(stc & StorageClass.Variadic);
55 }
56
57 mixin(copyMethod);
58 }
59
60 /// Array of parameters.
61 class Parameters : Node
62 {
63 this()
64 {
65 super(NodeCategory.Other);
66 mixin(set_kind);
67 }
68
69 bool hasVariadic()
70 {
71 if (children.length != 0)
72 return items[$-1].isVariadic();
73 return false;
74 }
75
76 void opCatAssign(Parameter param)
77 { addChild(param); }
78
79 Parameter[] items()
80 { return cast(Parameter[])children; }
81
82 size_t length()
83 { return children.length; }
84
85 mixin(copyMethod);
86 }
87
88 /*~~~~~~~~~~~~~~~~~~~~~~
89 ~ Template parameters: ~
90 ~~~~~~~~~~~~~~~~~~~~~~*/
91
92 /// Abstract base class for all template parameters.
93 abstract class TemplateParameter : Node
94 {
95 Identifier* ident;
96 this(Identifier* ident)
97 {
98 super(NodeCategory.Other);
99 this.ident = ident;
100 }
101 override abstract TemplateParameter copy();
102 }
103
104 /// E.g.: (alias T)
105 class TemplateAliasParameter : TemplateParameter
106 {
107 TypeNode specType, defType;
108 this(Identifier* ident, TypeNode specType, TypeNode defType)
109 {
110 super(ident);
111 mixin(set_kind);
112 addOptChild(specType);
113 addOptChild(defType);
114 this.ident = ident;
115 this.specType = specType;
116 this.defType = defType;
117 }
118 mixin(copyMethod);
119 }
120
121 /// E.g.: (T t)
122 class TemplateTypeParameter : TemplateParameter
123 {
124 TypeNode specType, defType;
125 this(Identifier* ident, TypeNode specType, TypeNode defType)
126 {
127 super(ident);
128 mixin(set_kind);
129 addOptChild(specType);
130 addOptChild(defType);
131 this.ident = ident;
132 this.specType = specType;
133 this.defType = defType;
134 }
135 mixin(copyMethod);
136 }
137
138 // version(D2)
139 // {
140 /// E.g.: (this T)
141 class TemplateThisParameter : TemplateParameter
142 {
143 TypeNode specType, defType;
144 this(Identifier* ident, TypeNode specType, TypeNode defType)
145 {
146 super(ident);
147 mixin(set_kind);
148 addOptChild(specType);
149 addOptChild(defType);
150 this.ident = ident;
151 this.specType = specType;
152 this.defType = defType;
153 }
154 mixin(copyMethod);
155 }
156 // }
157
158 /// E.g.: (T)
159 class TemplateValueParameter : TemplateParameter
160 {
161 TypeNode valueType;
162 Expression specValue, defValue;
163 this(TypeNode valueType, Identifier* ident, Expression specValue, Expression defValue)
164 {
165 super(ident);
166 mixin(set_kind);
167 addChild(valueType);
168 addOptChild(specValue);
169 addOptChild(defValue);
170 this.valueType = valueType;
171 this.ident = ident;
172 this.specValue = specValue;
173 this.defValue = defValue;
174 }
175 mixin(copyMethod);
176 }
177
178 /// E.g.: (T...)
179 class TemplateTupleParameter : TemplateParameter
180 {
181 this(Identifier* ident)
182 {
183 super(ident);
184 mixin(set_kind);
185 this.ident = ident;
186 }
187 mixin(copyMethod);
188 }
189
190 /// Array of template parameters.
191 class TemplateParameters : Node
192 {
193 this()
194 {
195 super(NodeCategory.Other);
196 mixin(set_kind);
197 }
198
199 void opCatAssign(TemplateParameter parameter)
200 {
201 addChild(parameter);
202 }
203
204 TemplateParameter[] items()
205 {
206 return cast(TemplateParameter[])children;
207 }
208
209 mixin(copyMethod);
210 }
211
212 /// Array of template arguments.
213 class TemplateArguments : Node
214 {
215 this()
216 {
217 super(NodeCategory.Other);
218 mixin(set_kind);
219 }
220
221 void opCatAssign(Node argument)
222 {
223 addChild(argument);
224 }
225
226 mixin(copyMethod);
227 }