Mercurial > projects > dil
comparison src/dil/ast/Types.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/Types.d@9e6c6bb73e5f |
children | 451ede0105e0 |
comparison
equal
deleted
inserted
replaced
805:a3fab8b74a7d | 806:bcb74c9b895c |
---|---|
1 /++ | |
2 Author: Aziz Köksal | |
3 License: GPL3 | |
4 +/ | |
5 module dil.ast.Types; | |
6 | |
7 public import dil.ast.Type; | |
8 import dil.ast.Node; | |
9 import dil.ast.Expression; | |
10 import dil.ast.Parameters; | |
11 import dil.ast.NodeCopier; | |
12 import dil.lexer.Identifier; | |
13 import dil.semantic.Types; | |
14 import dil.Enums; | |
15 | |
16 /// Syntax error. | |
17 class IllegalType : TypeNode | |
18 { | |
19 this() | |
20 { | |
21 mixin(set_kind); | |
22 } | |
23 mixin(copyMethod); | |
24 } | |
25 | |
26 /// char, int, float etc. | |
27 class IntegralType : TypeNode | |
28 { | |
29 TOK tok; | |
30 this(TOK tok) | |
31 { | |
32 mixin(set_kind); | |
33 this.tok = tok; | |
34 } | |
35 mixin(copyMethod); | |
36 } | |
37 | |
38 /// Identifier | |
39 class IdentifierType : TypeNode | |
40 { | |
41 Identifier* ident; | |
42 this(Identifier* ident) | |
43 { | |
44 mixin(set_kind); | |
45 this.ident = ident; | |
46 } | |
47 mixin(copyMethod); | |
48 } | |
49 | |
50 /// Type "." Type | |
51 class QualifiedType : TypeNode | |
52 { | |
53 alias next lhs; /// Left-hand side type. | |
54 TypeNode rhs; /// Right-hand side type. | |
55 this(TypeNode lhs, TypeNode rhs) | |
56 { | |
57 super(lhs); | |
58 mixin(set_kind); | |
59 addChild(rhs); | |
60 this.rhs = rhs; | |
61 } | |
62 mixin(copyMethod); | |
63 } | |
64 | |
65 /// "." Type | |
66 class ModuleScopeType : TypeNode | |
67 { | |
68 this() | |
69 { | |
70 mixin(set_kind); | |
71 } | |
72 mixin(copyMethod); | |
73 } | |
74 | |
75 /// "typeof" "(" Expression ")" or$(BR) | |
76 /// "typeof" "(" "return" ")" (D2.0) | |
77 class TypeofType : TypeNode | |
78 { | |
79 Expression e; | |
80 this(Expression e) | |
81 { | |
82 this(); | |
83 addChild(e); | |
84 this.e = e; | |
85 } | |
86 | |
87 // For D2.0: "typeof" "(" "return" ")" | |
88 this() | |
89 { | |
90 mixin(set_kind); | |
91 } | |
92 | |
93 bool isTypeofReturn() | |
94 { | |
95 return e is null; | |
96 } | |
97 | |
98 mixin(copyMethod); | |
99 } | |
100 | |
101 /// Identifier "!" "(" TemplateParameters? ")" | |
102 class TemplateInstanceType : TypeNode | |
103 { | |
104 Identifier* ident; | |
105 TemplateArguments targs; | |
106 this(Identifier* ident, TemplateArguments targs) | |
107 { | |
108 mixin(set_kind); | |
109 addOptChild(targs); | |
110 this.ident = ident; | |
111 this.targs = targs; | |
112 } | |
113 mixin(copyMethod); | |
114 } | |
115 | |
116 /// Type * | |
117 class PointerType : TypeNode | |
118 { | |
119 this(TypeNode next) | |
120 { | |
121 super(next); | |
122 mixin(set_kind); | |
123 } | |
124 mixin(copyMethod); | |
125 } | |
126 | |
127 /// Dynamic array: T[] or$(BR) | |
128 /// Static array: T[E] or$(BR) | |
129 /// Slice array (for tuples): T[E..E] or$(BR) | |
130 /// Associative array: T[T] | |
131 class ArrayType : TypeNode | |
132 { | |
133 Expression e1, e2; | |
134 TypeNode assocType; | |
135 | |
136 this(TypeNode t) | |
137 { | |
138 super(t); | |
139 mixin(set_kind); | |
140 } | |
141 | |
142 this(TypeNode t, Expression e1, Expression e2) | |
143 { | |
144 this(t); | |
145 addChild(e1); | |
146 addOptChild(e2); | |
147 this.e1 = e1; | |
148 this.e2 = e2; | |
149 } | |
150 | |
151 this(TypeNode t, TypeNode assocType) | |
152 { | |
153 this(t); | |
154 addChild(assocType); | |
155 this.assocType = assocType; | |
156 } | |
157 | |
158 bool isDynamic() | |
159 { | |
160 return !assocType && !e1; | |
161 } | |
162 | |
163 bool isStatic() | |
164 { | |
165 return e1 && !e2; | |
166 } | |
167 | |
168 bool isSlice() | |
169 { | |
170 return e1 && e2; | |
171 } | |
172 | |
173 bool isAssociative() | |
174 { | |
175 return assocType !is null; | |
176 } | |
177 | |
178 mixin(copyMethod); | |
179 } | |
180 | |
181 /// ReturnType "function" "(" Parameters? ")" | |
182 class FunctionType : TypeNode | |
183 { | |
184 alias next returnType; | |
185 Parameters params; | |
186 this(TypeNode returnType, Parameters params) | |
187 { | |
188 super(returnType); | |
189 mixin(set_kind); | |
190 addChild(params); | |
191 this.params = params; | |
192 } | |
193 mixin(copyMethod); | |
194 } | |
195 | |
196 /// ReturnType "delegate" "(" Parameters? ")" | |
197 class DelegateType : TypeNode | |
198 { | |
199 alias next returnType; | |
200 Parameters params; | |
201 this(TypeNode returnType, Parameters params) | |
202 { | |
203 super(returnType); | |
204 mixin(set_kind); | |
205 addChild(params); | |
206 this.params = params; | |
207 } | |
208 mixin(copyMethod); | |
209 } | |
210 | |
211 /// Type "(" BasicType2 Identifier ")" "(" Parameters? ")" | |
212 class CFuncPointerType : TypeNode | |
213 { | |
214 Parameters params; | |
215 this(TypeNode type, Parameters params) | |
216 { | |
217 super(type); | |
218 mixin(set_kind); | |
219 addOptChild(params); | |
220 } | |
221 mixin(copyMethod); | |
222 } | |
223 | |
224 /// "class" Identifier : BaseClasses | |
225 class BaseClassType : TypeNode | |
226 { | |
227 Protection prot; | |
228 this(Protection prot, TypeNode type) | |
229 { | |
230 super(type); | |
231 mixin(set_kind); | |
232 this.prot = prot; | |
233 } | |
234 mixin(copyMethod); | |
235 } | |
236 | |
237 // version(D2) | |
238 // { | |
239 /// "const" "(" Type ")" | |
240 class ConstType : TypeNode | |
241 { | |
242 this(TypeNode next) | |
243 { | |
244 // If t is null: cast(const) | |
245 super(next); | |
246 mixin(set_kind); | |
247 } | |
248 mixin(copyMethod); | |
249 } | |
250 | |
251 /// "invariant" "(" Type ")" | |
252 class InvariantType : TypeNode | |
253 { | |
254 this(TypeNode next) | |
255 { | |
256 // If t is null: cast(invariant) | |
257 super(next); | |
258 mixin(set_kind); | |
259 } | |
260 mixin(copyMethod); | |
261 } | |
262 // } // version(D2) |