Mercurial > projects > dang
comparison src/ast/Expr.d @ 206:d3c148ca429b
Major moving of files. all src now goes into src, all docs in docs.
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Tue, 12 Aug 2008 18:14:56 +0200 |
parents | |
children | 42e663451371 |
comparison
equal
deleted
inserted
replaced
205:8387cbaa85ab | 206:d3c148ca429b |
---|---|
1 module ast.Expr; | |
2 | |
3 /** | |
4 The base class for all Expressions. | |
5 */ | |
6 class Expr | |
7 { | |
8 /// Get the type of the Expr | |
9 Object getType() | |
10 { | |
11 assert(0, "Unimplemented"); | |
12 return null; | |
13 } | |
14 | |
15 /// Set the type of the Expr | |
16 void setType(Object type) | |
17 { | |
18 assert(0, "Unimplemented"); | |
19 } | |
20 | |
21 /// Returns true if the Expr can be compile-time evaluated. | |
22 bool isConstantExpr() { return false; } | |
23 | |
24 NumberLiteral asNumberLiteral() { return null; } | |
25 bool isNumberLiteral() { return false; } | |
26 | |
27 StringLiteral asStringLiteral() { return null; } | |
28 bool isStringLiteral() { return false; } | |
29 | |
30 ArrayLiteral asArrayLiteral() { return null; } | |
31 bool isArrayLiteral() { return false; } | |
32 | |
33 Assign asAssign() { return null; } | |
34 bool isAssign() { return false; } | |
35 | |
36 Binary asBinary() { return null; } | |
37 bool isBinary() { return false; } | |
38 | |
39 Negate asNegate() { return null; } | |
40 bool isNegate() { return false; } | |
41 | |
42 Deref asDeref() { return null; } | |
43 bool isDeref() { return false; } | |
44 | |
45 AddressOf asAddressOf() { return null; } | |
46 bool isAddressOf() { return false; } | |
47 | |
48 Index asIndex() { return null; } | |
49 bool isIndex() { return false; } | |
50 | |
51 Identifier asIdentifier() { return null; } | |
52 bool isIdentifier() { return false; } | |
53 | |
54 Member asMember() { return null; } | |
55 bool isMember() { return false; } | |
56 | |
57 private: | |
58 /// FIXME: Add DType? here | |
59 } | |
60 | |
61 /** | |
62 NumberLiteral | |
63 */ | |
64 /// FIXME: Should there be an IntegerLiteral and FloatLiteral instead? | |
65 class NumberLiteral : Expr | |
66 { | |
67 override bool isConstantExpr() { return true; } | |
68 | |
69 override NumberLiteral asNumberLiteral() { return this; } | |
70 override bool isNumberLiteral() { return true; } | |
71 } | |
72 | |
73 /** | |
74 StringLiteral | |
75 */ | |
76 class StringLiteral : Expr | |
77 { | |
78 override bool isConstantExpr() { return true; } | |
79 | |
80 override StringLiteral asStringLiteral() { return this; } | |
81 override bool isStringLiteral() { return true; } | |
82 } | |
83 | |
84 /** | |
85 ArrayLiteral | |
86 */ | |
87 class ArrayLiteral : Expr | |
88 { | |
89 /// Return the arguments for the ArrayLiteral | |
90 Expr[] getArguments() { return arguments; } | |
91 | |
92 /// Return a given argument for the ArrayLiteral | |
93 Expr getArgument(int index) { return arguments[index]; } | |
94 | |
95 /// Get the count of arguments for the ArrayLiteral | |
96 int getArgumentCount() { return arguments.length; } | |
97 | |
98 override bool isConstantExpr() | |
99 { | |
100 /** | |
101 If all the arguments to the ArrayLiteral is an constant Expr, then | |
102 this ArrayLiteral can be considered an constant Expr aswell. | |
103 */ | |
104 // FIXME: consider if it should save the result | |
105 foreach (arg; arguments) | |
106 if (!arg.isConstantExpr()) | |
107 return false; | |
108 return true; | |
109 } | |
110 | |
111 override ArrayLiteral asArrayLiteral() { return this; } | |
112 override bool isArrayLiteral() { return true; } | |
113 | |
114 private: | |
115 Expr[] arguments; | |
116 } | |
117 | |
118 /** | |
119 The Assign expression contains two expression, a left and a right side, | |
120 left being a lvalue, right being a rvalue. | |
121 | |
122 If the right side ain't the same type as the left type, the right side will | |
123 try to be promoted through an implicit cast. If this failes, an error must | |
124 be given. | |
125 */ | |
126 class Assign : Expr | |
127 { | |
128 override Assign asAssign() { return this; } | |
129 override bool isAssign() { return true; } | |
130 | |
131 private: | |
132 Expr left, right; | |
133 } | |
134 | |
135 /** | |
136 Binary | |
137 */ | |
138 class Binary : Expr | |
139 { | |
140 override Binary asBinary() { return this; } | |
141 override bool isBinary() { return true; } | |
142 | |
143 private: | |
144 Expr left, right; | |
145 } | |
146 | |
147 /** | |
148 Negate | |
149 */ | |
150 class Negate : Expr | |
151 { | |
152 override Negate asNegate() { return this; } | |
153 override bool isNegate() { return true; } | |
154 | |
155 private: | |
156 Expr expr; | |
157 } | |
158 | |
159 /** | |
160 Deref | |
161 */ | |
162 class Deref : Expr | |
163 { | |
164 override Deref asDeref() { return this; } | |
165 override bool isDeref() { return true; } | |
166 } | |
167 | |
168 /** | |
169 AddressOf | |
170 */ | |
171 class AddressOf : Expr | |
172 { | |
173 override AddressOf asAddressOf() { return this; } | |
174 override bool isAddressOf() { return true; } | |
175 } | |
176 | |
177 /** | |
178 Index | |
179 */ | |
180 class Index : Expr | |
181 { | |
182 override Index asIndex() { return this; } | |
183 override bool isIndex() { return true; } | |
184 } | |
185 | |
186 /** | |
187 Identifier | |
188 */ | |
189 class Identifier : Expr | |
190 { | |
191 override Identifier asIdentifier() { return this; } | |
192 override bool isIdentifier() { return true; } | |
193 } | |
194 | |
195 /** | |
196 Member | |
197 */ | |
198 class Member : Expr | |
199 { | |
200 override Member asMember() { return this; } | |
201 override bool isMember() { return true; } | |
202 } | |
203 |