1 | //
|
---|
2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
|
---|
3 | //
|
---|
4 | // The contents of this file are covered under the licence agreement in the
|
---|
5 | // file "LICENCE" distributed with Cforall.
|
---|
6 | //
|
---|
7 | // Expression.h --
|
---|
8 | //
|
---|
9 | // Author : Richard C. Bilson
|
---|
10 | // Created On : Mon May 18 07:44:20 2015
|
---|
11 | // Last Modified By : Peter A. Buhr
|
---|
12 | // Last Modified On : Sat Aug 6 08:52:53 2016
|
---|
13 | // Update Count : 35
|
---|
14 | //
|
---|
15 |
|
---|
16 | #ifndef EXPRESSION_H
|
---|
17 | #define EXPRESSION_H
|
---|
18 |
|
---|
19 | #include <map>
|
---|
20 | #include <memory>
|
---|
21 | #include "SynTree.h"
|
---|
22 | #include "Visitor.h"
|
---|
23 | #include "Mutator.h"
|
---|
24 | #include "Constant.h"
|
---|
25 | #include "Common/UniqueName.h"
|
---|
26 |
|
---|
27 | /// Expression is the root type for all expressions
|
---|
28 | class Expression {
|
---|
29 | public:
|
---|
30 | Expression( Expression *_aname = nullptr );
|
---|
31 | Expression( const Expression &other );
|
---|
32 | virtual ~Expression();
|
---|
33 |
|
---|
34 | std::list<Type *>& get_results() { return results; }
|
---|
35 | void add_result( Type *t );
|
---|
36 |
|
---|
37 | TypeSubstitution *get_env() const { return env; }
|
---|
38 | void set_env( TypeSubstitution *newValue ) { env = newValue; }
|
---|
39 | Expression *get_argName() const { return argName; }
|
---|
40 | void set_argName( Expression *name ) { argName = name; }
|
---|
41 | bool get_extension() const { return extension; }
|
---|
42 | Expression * set_extension( bool exten ) { extension = exten; return this; }
|
---|
43 |
|
---|
44 | virtual Expression *clone() const = 0;
|
---|
45 | virtual void accept( Visitor &v ) = 0;
|
---|
46 | virtual Expression *acceptMutator( Mutator &m ) = 0;
|
---|
47 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
48 | protected:
|
---|
49 | std::list<Type *> results;
|
---|
50 | TypeSubstitution *env;
|
---|
51 | Expression* argName; // if expression is used as an argument, it can be "designated" by this name
|
---|
52 | bool extension = false;
|
---|
53 | };
|
---|
54 |
|
---|
55 | /// ParamEntry contains the i.d. of a declaration and a type that is derived from that declaration,
|
---|
56 | /// but subject to decay-to-pointer and type parameter renaming
|
---|
57 | struct ParamEntry {
|
---|
58 | ParamEntry(): decl( 0 ), actualType( 0 ), formalType( 0 ), expr( 0 ) {}
|
---|
59 | ParamEntry( UniqueId decl, Type *actualType, Type *formalType, Expression* expr ): decl( decl ), actualType( actualType ), formalType( formalType ), expr( expr ) {}
|
---|
60 | ParamEntry( const ParamEntry &other );
|
---|
61 | ~ParamEntry();
|
---|
62 | ParamEntry &operator=( const ParamEntry &other );
|
---|
63 |
|
---|
64 | UniqueId decl;
|
---|
65 | Type *actualType;
|
---|
66 | Type *formalType;
|
---|
67 | Expression* expr;
|
---|
68 | };
|
---|
69 |
|
---|
70 | typedef std::map< UniqueId, ParamEntry > InferredParams;
|
---|
71 |
|
---|
72 | /// ApplicationExpr represents the application of a function to a set of parameters. This is the result of running an
|
---|
73 | /// UntypedExpr through the expression analyzer.
|
---|
74 | class ApplicationExpr : public Expression {
|
---|
75 | public:
|
---|
76 | ApplicationExpr( Expression *function );
|
---|
77 | ApplicationExpr( const ApplicationExpr &other );
|
---|
78 | virtual ~ApplicationExpr();
|
---|
79 |
|
---|
80 | Expression *get_function() const { return function; }
|
---|
81 | void set_function( Expression *newValue ) { function = newValue; }
|
---|
82 | std::list<Expression *>& get_args() { return args; }
|
---|
83 | InferredParams &get_inferParams() { return inferParams; }
|
---|
84 |
|
---|
85 | virtual ApplicationExpr *clone() const { return new ApplicationExpr( *this ); }
|
---|
86 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
87 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
88 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
89 | private:
|
---|
90 | Expression *function;
|
---|
91 | std::list<Expression *> args;
|
---|
92 | InferredParams inferParams;
|
---|
93 | };
|
---|
94 |
|
---|
95 | /// UntypedExpr represents the application of a function to a set of parameters, but where the particular overload for
|
---|
96 | /// the function name has not yet been determined. Most operators are converted into functional form automatically, to
|
---|
97 | /// permit operator overloading.
|
---|
98 | class UntypedExpr : public Expression {
|
---|
99 | public:
|
---|
100 | UntypedExpr( Expression *function, Expression *_aname = nullptr );
|
---|
101 | UntypedExpr( const UntypedExpr &other );
|
---|
102 | UntypedExpr( Expression *function, std::list<Expression *> &args, Expression *_aname = nullptr );
|
---|
103 | virtual ~UntypedExpr();
|
---|
104 |
|
---|
105 | Expression *get_function() const { return function; }
|
---|
106 | void set_function( Expression *newValue ) { function = newValue; }
|
---|
107 |
|
---|
108 | void set_args( std::list<Expression *> &listArgs ) { args = listArgs; }
|
---|
109 | std::list<Expression*>::iterator begin_args() { return args.begin(); }
|
---|
110 | std::list<Expression*>::iterator end_args() { return args.end(); }
|
---|
111 | std::list<Expression*>& get_args() { return args; }
|
---|
112 |
|
---|
113 | virtual UntypedExpr *clone() const { return new UntypedExpr( *this ); }
|
---|
114 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
115 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
116 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
117 | virtual void printArgs(std::ostream &os, int indent = 0) const;
|
---|
118 | private:
|
---|
119 | Expression *function;
|
---|
120 | std::list<Expression*> args;
|
---|
121 | };
|
---|
122 |
|
---|
123 | /// NameExpr contains a name whose meaning is still not determined
|
---|
124 | class NameExpr : public Expression {
|
---|
125 | public:
|
---|
126 | NameExpr( std::string name, Expression *_aname = nullptr );
|
---|
127 | NameExpr( const NameExpr &other );
|
---|
128 | virtual ~NameExpr();
|
---|
129 |
|
---|
130 | const std::string &get_name() const { return name; }
|
---|
131 | void set_name( std::string newValue ) { name = newValue; }
|
---|
132 |
|
---|
133 | virtual NameExpr *clone() const { return new NameExpr( *this ); }
|
---|
134 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
135 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
136 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
137 | private:
|
---|
138 | std::string name;
|
---|
139 | };
|
---|
140 |
|
---|
141 | // The following classes are used to represent expression types that cannot be converted into
|
---|
142 | // function-call format.
|
---|
143 |
|
---|
144 | /// AddressExpr represents a address-of expression, e.g. &e
|
---|
145 | class AddressExpr : public Expression {
|
---|
146 | public:
|
---|
147 | AddressExpr( Expression *arg, Expression *_aname = nullptr );
|
---|
148 | AddressExpr( const AddressExpr &other );
|
---|
149 | virtual ~AddressExpr();
|
---|
150 |
|
---|
151 | Expression *get_arg() const { return arg; }
|
---|
152 | void set_arg(Expression *newValue ) { arg = newValue; }
|
---|
153 |
|
---|
154 | virtual AddressExpr *clone() const { return new AddressExpr( *this ); }
|
---|
155 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
156 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
157 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
158 | private:
|
---|
159 | Expression *arg;
|
---|
160 | };
|
---|
161 |
|
---|
162 | // xxx - this doesn't appear to actually be hooked in anywhere. We should use this instead of the "&&"" UntypedExpr hack
|
---|
163 | class LabelAddressExpr : public Expression {
|
---|
164 | public:
|
---|
165 | LabelAddressExpr( Expression *arg );
|
---|
166 | LabelAddressExpr( const LabelAddressExpr &other );
|
---|
167 | virtual ~LabelAddressExpr();
|
---|
168 |
|
---|
169 | Expression *get_arg() const { return arg; }
|
---|
170 | void set_arg(Expression *newValue ) { arg = newValue; }
|
---|
171 |
|
---|
172 | virtual LabelAddressExpr *clone() const { return new LabelAddressExpr( *this ); }
|
---|
173 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
174 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
175 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
176 | private:
|
---|
177 | Expression *arg;
|
---|
178 | };
|
---|
179 |
|
---|
180 | /// CastExpr represents a type cast expression, e.g. (int)e
|
---|
181 | class CastExpr : public Expression {
|
---|
182 | public:
|
---|
183 | CastExpr( Expression *arg, Expression *_aname = nullptr );
|
---|
184 | CastExpr( Expression *arg, Type *toType, Expression *_aname = nullptr );
|
---|
185 | CastExpr( const CastExpr &other );
|
---|
186 | virtual ~CastExpr();
|
---|
187 |
|
---|
188 | Expression *get_arg() const { return arg; }
|
---|
189 | void set_arg(Expression *newValue ) { arg = newValue; }
|
---|
190 |
|
---|
191 | virtual CastExpr *clone() const { return new CastExpr( *this ); }
|
---|
192 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
193 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
194 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
195 | private:
|
---|
196 | Expression *arg;
|
---|
197 | };
|
---|
198 |
|
---|
199 | /// UntypedMemberExpr represents a member selection operation, e.g. q.p before processing by the expression analyzer
|
---|
200 | class UntypedMemberExpr : public Expression {
|
---|
201 | public:
|
---|
202 | UntypedMemberExpr( std::string member, Expression *aggregate, Expression *_aname = nullptr );
|
---|
203 | UntypedMemberExpr( const UntypedMemberExpr &other );
|
---|
204 | virtual ~UntypedMemberExpr();
|
---|
205 |
|
---|
206 | std::string get_member() const { return member; }
|
---|
207 | void set_member( const std::string &newValue ) { member = newValue; }
|
---|
208 | Expression *get_aggregate() const { return aggregate; }
|
---|
209 | void set_aggregate( Expression *newValue ) { aggregate = newValue; }
|
---|
210 |
|
---|
211 | virtual UntypedMemberExpr *clone() const { return new UntypedMemberExpr( *this ); }
|
---|
212 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
213 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
214 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
215 | private:
|
---|
216 | std::string member;
|
---|
217 | Expression *aggregate;
|
---|
218 | };
|
---|
219 |
|
---|
220 | /// MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer
|
---|
221 | class MemberExpr : public Expression {
|
---|
222 | public:
|
---|
223 | MemberExpr( DeclarationWithType *member, Expression *aggregate, Expression *_aname = nullptr );
|
---|
224 | MemberExpr( const MemberExpr &other );
|
---|
225 | virtual ~MemberExpr();
|
---|
226 |
|
---|
227 | DeclarationWithType *get_member() const { return member; }
|
---|
228 | void set_member( DeclarationWithType *newValue ) { member = newValue; }
|
---|
229 | Expression *get_aggregate() const { return aggregate; }
|
---|
230 | void set_aggregate( Expression *newValue ) { aggregate = newValue; }
|
---|
231 |
|
---|
232 | virtual MemberExpr *clone() const { return new MemberExpr( *this ); }
|
---|
233 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
234 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
235 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
236 | private:
|
---|
237 | DeclarationWithType *member;
|
---|
238 | Expression *aggregate;
|
---|
239 | };
|
---|
240 |
|
---|
241 | /// VariableExpr represents an expression that simply refers to the value of a named variable
|
---|
242 | class VariableExpr : public Expression {
|
---|
243 | public:
|
---|
244 | VariableExpr( DeclarationWithType *var, Expression *_aname = nullptr );
|
---|
245 | VariableExpr( const VariableExpr &other );
|
---|
246 | virtual ~VariableExpr();
|
---|
247 |
|
---|
248 | DeclarationWithType *get_var() const { return var; }
|
---|
249 | void set_var( DeclarationWithType *newValue ) { var = newValue; }
|
---|
250 |
|
---|
251 | virtual VariableExpr *clone() const { return new VariableExpr( *this ); }
|
---|
252 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
253 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
254 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
255 | private:
|
---|
256 | DeclarationWithType *var;
|
---|
257 | };
|
---|
258 |
|
---|
259 | /// ConstantExpr represents an expression that simply refers to the value of a constant
|
---|
260 | class ConstantExpr : public Expression {
|
---|
261 | public:
|
---|
262 | ConstantExpr( Constant constant, Expression *_aname = nullptr );
|
---|
263 | ConstantExpr( const ConstantExpr &other );
|
---|
264 | virtual ~ConstantExpr();
|
---|
265 |
|
---|
266 | Constant *get_constant() { return &constant; }
|
---|
267 | void set_constant( const Constant &newValue ) { constant = newValue; }
|
---|
268 |
|
---|
269 | virtual ConstantExpr *clone() const { return new ConstantExpr( *this ); }
|
---|
270 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
271 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
272 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
273 | private:
|
---|
274 | Constant constant;
|
---|
275 | };
|
---|
276 |
|
---|
277 | /// SizeofExpr represents a sizeof expression (could be sizeof(int) or sizeof 3+4)
|
---|
278 | class SizeofExpr : public Expression {
|
---|
279 | public:
|
---|
280 | SizeofExpr( Expression *expr, Expression *_aname = nullptr );
|
---|
281 | SizeofExpr( const SizeofExpr &other );
|
---|
282 | SizeofExpr( Type *type, Expression *_aname = nullptr );
|
---|
283 | virtual ~SizeofExpr();
|
---|
284 |
|
---|
285 | Expression *get_expr() const { return expr; }
|
---|
286 | void set_expr( Expression *newValue ) { expr = newValue; }
|
---|
287 | Type *get_type() const { return type; }
|
---|
288 | void set_type( Type *newValue ) { type = newValue; }
|
---|
289 | bool get_isType() const { return isType; }
|
---|
290 | void set_isType( bool newValue ) { isType = newValue; }
|
---|
291 |
|
---|
292 | virtual SizeofExpr *clone() const { return new SizeofExpr( *this ); }
|
---|
293 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
294 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
295 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
296 | private:
|
---|
297 | Expression *expr;
|
---|
298 | Type *type;
|
---|
299 | bool isType;
|
---|
300 | };
|
---|
301 |
|
---|
302 | /// AlignofExpr represents an alignof expression
|
---|
303 | class AlignofExpr : public Expression {
|
---|
304 | public:
|
---|
305 | AlignofExpr( Expression *expr, Expression *_aname = nullptr );
|
---|
306 | AlignofExpr( const AlignofExpr &other );
|
---|
307 | AlignofExpr( Type *type, Expression *_aname = nullptr );
|
---|
308 | virtual ~AlignofExpr();
|
---|
309 |
|
---|
310 | Expression *get_expr() const { return expr; }
|
---|
311 | void set_expr( Expression *newValue ) { expr = newValue; }
|
---|
312 | Type *get_type() const { return type; }
|
---|
313 | void set_type( Type *newValue ) { type = newValue; }
|
---|
314 | bool get_isType() const { return isType; }
|
---|
315 | void set_isType( bool newValue ) { isType = newValue; }
|
---|
316 |
|
---|
317 | virtual AlignofExpr *clone() const { return new AlignofExpr( *this ); }
|
---|
318 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
319 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
320 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
321 | private:
|
---|
322 | Expression *expr;
|
---|
323 | Type *type;
|
---|
324 | bool isType;
|
---|
325 | };
|
---|
326 |
|
---|
327 | /// UntypedOffsetofExpr represents an offsetof expression before resolution
|
---|
328 | class UntypedOffsetofExpr : public Expression {
|
---|
329 | public:
|
---|
330 | UntypedOffsetofExpr( Type *type, const std::string &member, Expression *_aname = nullptr );
|
---|
331 | UntypedOffsetofExpr( const UntypedOffsetofExpr &other );
|
---|
332 | virtual ~UntypedOffsetofExpr();
|
---|
333 |
|
---|
334 | std::string get_member() const { return member; }
|
---|
335 | void set_member( const std::string &newValue ) { member = newValue; }
|
---|
336 | Type *get_type() const { return type; }
|
---|
337 | void set_type( Type *newValue ) { type = newValue; }
|
---|
338 |
|
---|
339 | virtual UntypedOffsetofExpr *clone() const { return new UntypedOffsetofExpr( *this ); }
|
---|
340 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
341 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
342 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
343 | private:
|
---|
344 | Type *type;
|
---|
345 | std::string member;
|
---|
346 | };
|
---|
347 |
|
---|
348 | /// OffsetofExpr represents an offsetof expression
|
---|
349 | class OffsetofExpr : public Expression {
|
---|
350 | public:
|
---|
351 | OffsetofExpr( Type *type, DeclarationWithType *member, Expression *_aname = nullptr );
|
---|
352 | OffsetofExpr( const OffsetofExpr &other );
|
---|
353 | virtual ~OffsetofExpr();
|
---|
354 |
|
---|
355 | Type *get_type() const { return type; }
|
---|
356 | void set_type( Type *newValue ) { type = newValue; }
|
---|
357 | DeclarationWithType *get_member() const { return member; }
|
---|
358 | void set_member( DeclarationWithType *newValue ) { member = newValue; }
|
---|
359 |
|
---|
360 | virtual OffsetofExpr *clone() const { return new OffsetofExpr( *this ); }
|
---|
361 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
362 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
363 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
364 | private:
|
---|
365 | Type *type;
|
---|
366 | DeclarationWithType *member;
|
---|
367 | };
|
---|
368 |
|
---|
369 | /// Expression representing a pack of field-offsets for a generic type
|
---|
370 | class OffsetPackExpr : public Expression {
|
---|
371 | public:
|
---|
372 | OffsetPackExpr( StructInstType *type_, Expression *aname_ = 0 );
|
---|
373 | OffsetPackExpr( const OffsetPackExpr &other );
|
---|
374 | virtual ~OffsetPackExpr();
|
---|
375 |
|
---|
376 | StructInstType *get_type() const { return type; }
|
---|
377 | void set_type( StructInstType *newValue ) { type = newValue; }
|
---|
378 |
|
---|
379 | virtual OffsetPackExpr *clone() const { return new OffsetPackExpr( *this ); }
|
---|
380 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
381 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
382 |
|
---|
383 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
384 |
|
---|
385 | private:
|
---|
386 | StructInstType *type;
|
---|
387 | };
|
---|
388 |
|
---|
389 | /// AttrExpr represents an @attribute expression (like sizeof, but user-defined)
|
---|
390 | class AttrExpr : public Expression {
|
---|
391 | public:
|
---|
392 | AttrExpr(Expression *attr, Expression *expr, Expression *_aname = nullptr );
|
---|
393 | AttrExpr( const AttrExpr &other );
|
---|
394 | AttrExpr( Expression *attr, Type *type, Expression *_aname = nullptr );
|
---|
395 | virtual ~AttrExpr();
|
---|
396 |
|
---|
397 | Expression *get_attr() const { return attr; }
|
---|
398 | void set_attr( Expression *newValue ) { attr = newValue; }
|
---|
399 | Expression *get_expr() const { return expr; }
|
---|
400 | void set_expr( Expression *newValue ) { expr = newValue; }
|
---|
401 | Type *get_type() const { return type; }
|
---|
402 | void set_type( Type *newValue ) { type = newValue; }
|
---|
403 | bool get_isType() const { return isType; }
|
---|
404 | void set_isType( bool newValue ) { isType = newValue; }
|
---|
405 |
|
---|
406 | virtual AttrExpr *clone() const { return new AttrExpr( *this ); }
|
---|
407 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
408 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
409 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
410 | private:
|
---|
411 | Expression *attr;
|
---|
412 | Expression *expr;
|
---|
413 | Type *type;
|
---|
414 | bool isType;
|
---|
415 | };
|
---|
416 |
|
---|
417 | /// LogicalExpr represents a short-circuit boolean expression (&& or ||)
|
---|
418 | class LogicalExpr : public Expression {
|
---|
419 | public:
|
---|
420 | LogicalExpr( Expression *arg1, Expression *arg2, bool andp = true, Expression *_aname = nullptr );
|
---|
421 | LogicalExpr( const LogicalExpr &other );
|
---|
422 | virtual ~LogicalExpr();
|
---|
423 |
|
---|
424 | bool get_isAnd() const { return isAnd; }
|
---|
425 | Expression *get_arg1() { return arg1; }
|
---|
426 | void set_arg1( Expression *newValue ) { arg1 = newValue; }
|
---|
427 | Expression *get_arg2() const { return arg2; }
|
---|
428 | void set_arg2( Expression *newValue ) { arg2 = newValue; }
|
---|
429 |
|
---|
430 | virtual LogicalExpr *clone() const { return new LogicalExpr( *this ); }
|
---|
431 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
432 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
433 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
434 | private:
|
---|
435 | Expression *arg1;
|
---|
436 | Expression *arg2;
|
---|
437 | bool isAnd;
|
---|
438 | };
|
---|
439 |
|
---|
440 | /// ConditionalExpr represents the three-argument conditional ( p ? a : b )
|
---|
441 | class ConditionalExpr : public Expression {
|
---|
442 | public:
|
---|
443 | ConditionalExpr( Expression *arg1, Expression *arg2, Expression *arg3, Expression *_aname = nullptr );
|
---|
444 | ConditionalExpr( const ConditionalExpr &other );
|
---|
445 | virtual ~ConditionalExpr();
|
---|
446 |
|
---|
447 | Expression *get_arg1() const { return arg1; }
|
---|
448 | void set_arg1( Expression *newValue ) { arg1 = newValue; }
|
---|
449 | Expression *get_arg2() const { return arg2; }
|
---|
450 | void set_arg2( Expression *newValue ) { arg2 = newValue; }
|
---|
451 | Expression *get_arg3() const { return arg3; }
|
---|
452 | void set_arg3( Expression *newValue ) { arg3 = newValue; }
|
---|
453 |
|
---|
454 | virtual ConditionalExpr *clone() const { return new ConditionalExpr( *this ); }
|
---|
455 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
456 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
457 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
458 | private:
|
---|
459 | Expression *arg1;
|
---|
460 | Expression *arg2;
|
---|
461 | Expression *arg3;
|
---|
462 | };
|
---|
463 |
|
---|
464 | /// CommaExpr represents the sequence operator ( a, b )
|
---|
465 | class CommaExpr : public Expression {
|
---|
466 | public:
|
---|
467 | CommaExpr( Expression *arg1, Expression *arg2, Expression *_aname = nullptr );
|
---|
468 | CommaExpr( const CommaExpr &other );
|
---|
469 | virtual ~CommaExpr();
|
---|
470 |
|
---|
471 | Expression *get_arg1() const { return arg1; }
|
---|
472 | void set_arg1( Expression *newValue ) { arg1 = newValue; }
|
---|
473 | Expression *get_arg2() const { return arg2; }
|
---|
474 | void set_arg2( Expression *newValue ) { arg2 = newValue; }
|
---|
475 |
|
---|
476 | virtual CommaExpr *clone() const { return new CommaExpr( *this ); }
|
---|
477 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
478 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
479 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
480 | private:
|
---|
481 | Expression *arg1;
|
---|
482 | Expression *arg2;
|
---|
483 | };
|
---|
484 |
|
---|
485 | /// TupleExpr represents a tuple expression ( [a, b, c] )
|
---|
486 | class TupleExpr : public Expression {
|
---|
487 | public:
|
---|
488 | TupleExpr( Expression *_aname = nullptr );
|
---|
489 | TupleExpr( const TupleExpr &other );
|
---|
490 | virtual ~TupleExpr();
|
---|
491 |
|
---|
492 | void set_exprs( std::list<Expression*> newValue ) { exprs = newValue; }
|
---|
493 | std::list<Expression*>& get_exprs() { return exprs; }
|
---|
494 |
|
---|
495 | virtual TupleExpr *clone() const { return new TupleExpr( *this ); }
|
---|
496 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
497 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
498 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
499 | private:
|
---|
500 | std::list<Expression*> exprs;
|
---|
501 | };
|
---|
502 |
|
---|
503 | /// SolvedTupleExpr represents a TupleExpr whose components have been type-resolved. It is effectively a shell for the code generator to work on
|
---|
504 | class SolvedTupleExpr : public Expression {
|
---|
505 | public:
|
---|
506 | SolvedTupleExpr( Expression *_aname = nullptr ) : Expression( _aname ) {}
|
---|
507 | SolvedTupleExpr( std::list<Expression *> &, Expression *_aname = nullptr );
|
---|
508 | SolvedTupleExpr( const SolvedTupleExpr &other );
|
---|
509 | virtual ~SolvedTupleExpr() {}
|
---|
510 |
|
---|
511 | std::list<Expression*> &get_exprs() { return exprs; }
|
---|
512 |
|
---|
513 | virtual SolvedTupleExpr *clone() const { return new SolvedTupleExpr( *this ); }
|
---|
514 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
515 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
516 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
517 | private:
|
---|
518 | std::list<Expression*> exprs;
|
---|
519 | };
|
---|
520 |
|
---|
521 | /// TypeExpr represents a type used in an expression (e.g. as a type generator parameter)
|
---|
522 | class TypeExpr : public Expression {
|
---|
523 | public:
|
---|
524 | TypeExpr( Type *type );
|
---|
525 | TypeExpr( const TypeExpr &other );
|
---|
526 | virtual ~TypeExpr();
|
---|
527 |
|
---|
528 | Type *get_type() const { return type; }
|
---|
529 | void set_type( Type *newValue ) { type = newValue; }
|
---|
530 |
|
---|
531 | virtual TypeExpr *clone() const { return new TypeExpr( *this ); }
|
---|
532 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
533 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
534 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
535 | private:
|
---|
536 | Type *type;
|
---|
537 | };
|
---|
538 |
|
---|
539 | /// AsmExpr represents a GCC 'asm constraint operand' used in an asm statement: [output] "=f" (result)
|
---|
540 | class AsmExpr : public Expression {
|
---|
541 | public:
|
---|
542 | AsmExpr( Expression *inout, ConstantExpr *constraint, Expression *operand ) : inout( inout ), constraint( constraint ), operand( operand ) {}
|
---|
543 | AsmExpr( const AsmExpr & other );
|
---|
544 | virtual ~AsmExpr() { delete inout; delete constraint; delete operand; };
|
---|
545 |
|
---|
546 | Expression *get_inout() const { return inout; }
|
---|
547 | void set_inout( Expression *newValue ) { inout = newValue; }
|
---|
548 |
|
---|
549 | ConstantExpr *get_constraint() const { return constraint; }
|
---|
550 | void set_constraint( ConstantExpr *newValue ) { constraint = newValue; }
|
---|
551 |
|
---|
552 | Expression *get_operand() const { return operand; }
|
---|
553 | void set_operand( Expression *newValue ) { operand = newValue; }
|
---|
554 |
|
---|
555 | virtual AsmExpr *clone() const { return new AsmExpr( *this ); }
|
---|
556 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
557 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
558 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
559 | private:
|
---|
560 | // https://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Machine-Constraints.html#Machine-Constraints
|
---|
561 | Expression *inout;
|
---|
562 | ConstantExpr *constraint;
|
---|
563 | Expression *operand;
|
---|
564 | };
|
---|
565 |
|
---|
566 | /// ImplicitCopyCtorExpr represents the application of a function to a set of parameters,
|
---|
567 | /// along with a set of copy constructor calls, one for each argument.
|
---|
568 | class ImplicitCopyCtorExpr : public Expression {
|
---|
569 | public:
|
---|
570 | ImplicitCopyCtorExpr( ApplicationExpr * callExpr );
|
---|
571 | ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other );
|
---|
572 | virtual ~ImplicitCopyCtorExpr();
|
---|
573 |
|
---|
574 | ApplicationExpr *get_callExpr() const { return callExpr; }
|
---|
575 | void set_callExpr( ApplicationExpr *newValue ) { callExpr = newValue; }
|
---|
576 |
|
---|
577 | std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; }
|
---|
578 | void set_tempDecls( std::list< ObjectDecl * > newValue ) { tempDecls = newValue; }
|
---|
579 |
|
---|
580 | std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; }
|
---|
581 | void set_returnDecls( std::list< ObjectDecl * > newValue ) { returnDecls = newValue; }
|
---|
582 |
|
---|
583 | std::list< Expression * > & get_dtors() { return dtors; }
|
---|
584 | void set_dtors( std::list< Expression * > newValue ) { dtors = newValue; }
|
---|
585 |
|
---|
586 | virtual ImplicitCopyCtorExpr *clone() const { return new ImplicitCopyCtorExpr( *this ); }
|
---|
587 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
588 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
589 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
590 | private:
|
---|
591 | ApplicationExpr * callExpr;
|
---|
592 | std::list< ObjectDecl * > tempDecls;
|
---|
593 | std::list< ObjectDecl * > returnDecls;
|
---|
594 | std::list< Expression * > dtors;
|
---|
595 | };
|
---|
596 |
|
---|
597 | /// ValofExpr represents a GCC 'lambda expression'
|
---|
598 | class UntypedValofExpr : public Expression {
|
---|
599 | public:
|
---|
600 | UntypedValofExpr( Statement *_body, Expression *_aname = nullptr ) : Expression( _aname ), body ( _body ) {}
|
---|
601 | UntypedValofExpr( const UntypedValofExpr & other );
|
---|
602 | virtual ~UntypedValofExpr();
|
---|
603 |
|
---|
604 | Expression *get_value();
|
---|
605 | Statement *get_body() const { return body; }
|
---|
606 |
|
---|
607 | virtual UntypedValofExpr *clone() const { return new UntypedValofExpr( *this ); }
|
---|
608 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
609 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
610 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
611 | private:
|
---|
612 | Statement *body;
|
---|
613 | };
|
---|
614 |
|
---|
615 | /// CompoundLiteralExpr represents a C99 'compound literal'
|
---|
616 | class CompoundLiteralExpr : public Expression {
|
---|
617 | public:
|
---|
618 | CompoundLiteralExpr( Type * type, Initializer * initializer );
|
---|
619 | CompoundLiteralExpr( const CompoundLiteralExpr &other );
|
---|
620 | ~CompoundLiteralExpr();
|
---|
621 |
|
---|
622 | Type * get_type() const { return type; }
|
---|
623 | void set_type( Type * t ) { type = t; }
|
---|
624 |
|
---|
625 | Initializer * get_initializer() const { return initializer; }
|
---|
626 | void set_initializer( Initializer * i ) { initializer = i; }
|
---|
627 |
|
---|
628 | virtual CompoundLiteralExpr *clone() const { return new CompoundLiteralExpr( *this ); }
|
---|
629 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
630 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
631 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
632 | private:
|
---|
633 | Type * type;
|
---|
634 | Initializer * initializer;
|
---|
635 | };
|
---|
636 |
|
---|
637 | class RangeExpr : public Expression {
|
---|
638 | public:
|
---|
639 | RangeExpr( Expression *low, Expression *high );
|
---|
640 | RangeExpr( const RangeExpr &other );
|
---|
641 |
|
---|
642 | Expression * get_low() const { return low; }
|
---|
643 | Expression * get_high() const { return high; }
|
---|
644 | RangeExpr * set_low( Expression *low ) { RangeExpr::low = low; return this; }
|
---|
645 | RangeExpr * set_high( Expression *high ) { RangeExpr::high = high; return this; }
|
---|
646 |
|
---|
647 | virtual RangeExpr *clone() const { return new RangeExpr( *this ); }
|
---|
648 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
649 | virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
650 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
651 | private:
|
---|
652 | Expression *low, *high;
|
---|
653 | };
|
---|
654 |
|
---|
655 | std::ostream & operator<<( std::ostream & out, Expression * expr );
|
---|
656 |
|
---|
657 | #endif // EXPRESSION_H
|
---|
658 |
|
---|
659 | // Local Variables: //
|
---|
660 | // tab-width: 4 //
|
---|
661 | // mode: c++ //
|
---|
662 | // compile-command: "make install" //
|
---|
663 | // End: //
|
---|