source: src/SynTree/Expression.h@ 3f0c6a5

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since 3f0c6a5 was 77971f6, checked in by Rob Schluntz <rschlunt@…>, 9 years ago

resolve ctor/dtors for UniqueExprs

  • Property mode set to 100644
File size: 29.8 KB
Line 
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
28class Expression {
29 public:
30 Expression( Expression *_aname = nullptr );
31 Expression( const Expression &other );
32 virtual ~Expression();
33
34 Type *& get_result() { return result; }
35 void set_result( Type *newValue ) { result = newValue; }
36 bool has_result() const { return result != nullptr; }
37
38 TypeSubstitution *get_env() const { return env; }
39 void set_env( TypeSubstitution *newValue ) { env = newValue; }
40 Expression *get_argName() const { return argName; }
41 void set_argName( Expression *name ) { argName = name; }
42 bool get_extension() const { return extension; }
43 Expression * set_extension( bool exten ) { extension = exten; return this; }
44
45 virtual Expression *clone() const = 0;
46 virtual void accept( Visitor &v ) = 0;
47 virtual Expression *acceptMutator( Mutator &m ) = 0;
48 virtual void print( std::ostream &os, int indent = 0 ) const;
49 protected:
50 Type * result;
51 TypeSubstitution *env;
52 Expression* argName; // if expression is used as an argument, it can be "designated" by this name
53 bool extension = false;
54};
55
56/// ParamEntry contains the i.d. of a declaration and a type that is derived from that declaration,
57/// but subject to decay-to-pointer and type parameter renaming
58struct ParamEntry {
59 ParamEntry(): decl( 0 ), actualType( 0 ), formalType( 0 ), expr( 0 ) {}
60 ParamEntry( UniqueId decl, Type *actualType, Type *formalType, Expression* expr ): decl( decl ), actualType( actualType ), formalType( formalType ), expr( expr ) {}
61 ParamEntry( const ParamEntry &other );
62 ~ParamEntry();
63 ParamEntry &operator=( const ParamEntry &other );
64
65 UniqueId decl;
66 Type *actualType;
67 Type *formalType;
68 Expression* expr;
69};
70
71typedef std::map< UniqueId, ParamEntry > InferredParams;
72
73/// ApplicationExpr represents the application of a function to a set of parameters. This is the result of running an
74/// UntypedExpr through the expression analyzer.
75class ApplicationExpr : public Expression {
76 public:
77 ApplicationExpr( Expression *function );
78 ApplicationExpr( const ApplicationExpr &other );
79 virtual ~ApplicationExpr();
80
81 Expression *get_function() const { return function; }
82 void set_function( Expression *newValue ) { function = newValue; }
83 std::list<Expression *>& get_args() { return args; }
84 InferredParams &get_inferParams() { return inferParams; }
85
86 virtual ApplicationExpr *clone() const { return new ApplicationExpr( *this ); }
87 virtual void accept( Visitor &v ) { v.visit( this ); }
88 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
89 virtual void print( std::ostream &os, int indent = 0 ) const;
90 private:
91 Expression *function;
92 std::list<Expression *> args;
93 InferredParams inferParams;
94};
95
96/// UntypedExpr represents the application of a function to a set of parameters, but where the particular overload for
97/// the function name has not yet been determined. Most operators are converted into functional form automatically, to
98/// permit operator overloading.
99class UntypedExpr : public Expression {
100 public:
101 UntypedExpr( Expression *function, const std::list<Expression *> &args = std::list< Expression * >(), Expression *_aname = nullptr );
102 UntypedExpr( const UntypedExpr &other );
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
124class 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
145class 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
163class 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
181class 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
200class UntypedMemberExpr : public Expression {
201 public:
202 UntypedMemberExpr( Expression *member, Expression *aggregate, Expression *_aname = nullptr );
203 UntypedMemberExpr( const UntypedMemberExpr &other );
204 virtual ~UntypedMemberExpr();
205
206 Expression * get_member() const { return member; }
207 void set_member( Expression * 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 Expression *member;
217 Expression *aggregate;
218};
219
220/// MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer
221class 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
242class 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
260class 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)
278class 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
303class 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
328class 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
349class 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
370class OffsetPackExpr : public Expression {
371public:
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
385private:
386 StructInstType *type;
387};
388
389/// AttrExpr represents an @attribute expression (like sizeof, but user-defined)
390class 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 ||)
418class 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 )
441class 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 )
465class 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/// TypeExpr represents a type used in an expression (e.g. as a type generator parameter)
486class TypeExpr : public Expression {
487 public:
488 TypeExpr( Type *type );
489 TypeExpr( const TypeExpr &other );
490 virtual ~TypeExpr();
491
492 Type *get_type() const { return type; }
493 void set_type( Type *newValue ) { type = newValue; }
494
495 virtual TypeExpr *clone() const { return new TypeExpr( *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 Type *type;
501};
502
503/// AsmExpr represents a GCC 'asm constraint operand' used in an asm statement: [output] "=f" (result)
504class AsmExpr : public Expression {
505 public:
506 AsmExpr( Expression *inout, ConstantExpr *constraint, Expression *operand ) : inout( inout ), constraint( constraint ), operand( operand ) {}
507 AsmExpr( const AsmExpr & other );
508 virtual ~AsmExpr() { delete inout; delete constraint; delete operand; };
509
510 Expression *get_inout() const { return inout; }
511 void set_inout( Expression *newValue ) { inout = newValue; }
512
513 ConstantExpr *get_constraint() const { return constraint; }
514 void set_constraint( ConstantExpr *newValue ) { constraint = newValue; }
515
516 Expression *get_operand() const { return operand; }
517 void set_operand( Expression *newValue ) { operand = newValue; }
518
519 virtual AsmExpr *clone() const { return new AsmExpr( *this ); }
520 virtual void accept( Visitor &v ) { v.visit( this ); }
521 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
522 virtual void print( std::ostream &os, int indent = 0 ) const;
523 private:
524 // https://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Machine-Constraints.html#Machine-Constraints
525 Expression *inout;
526 ConstantExpr *constraint;
527 Expression *operand;
528};
529
530/// ImplicitCopyCtorExpr represents the application of a function to a set of parameters,
531/// along with a set of copy constructor calls, one for each argument.
532class ImplicitCopyCtorExpr : public Expression {
533public:
534 ImplicitCopyCtorExpr( ApplicationExpr * callExpr );
535 ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other );
536 virtual ~ImplicitCopyCtorExpr();
537
538 ApplicationExpr *get_callExpr() const { return callExpr; }
539 void set_callExpr( ApplicationExpr *newValue ) { callExpr = newValue; }
540
541 std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; }
542 void set_tempDecls( std::list< ObjectDecl * > newValue ) { tempDecls = newValue; }
543
544 std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; }
545 void set_returnDecls( std::list< ObjectDecl * > newValue ) { returnDecls = newValue; }
546
547 std::list< Expression * > & get_dtors() { return dtors; }
548 void set_dtors( std::list< Expression * > newValue ) { dtors = newValue; }
549
550 virtual ImplicitCopyCtorExpr *clone() const { return new ImplicitCopyCtorExpr( *this ); }
551 virtual void accept( Visitor &v ) { v.visit( this ); }
552 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
553 virtual void print( std::ostream &os, int indent = 0 ) const;
554 private:
555 ApplicationExpr * callExpr;
556 std::list< ObjectDecl * > tempDecls;
557 std::list< ObjectDecl * > returnDecls;
558 std::list< Expression * > dtors;
559};
560
561/// ConstructorExpr represents the use of a constructor in an expression context, e.g. int * x = malloc() { 5 };
562class ConstructorExpr : public Expression {
563public:
564 ConstructorExpr( Expression * callExpr );
565 ConstructorExpr( const ConstructorExpr & other );
566 ~ConstructorExpr();
567
568 Expression *get_callExpr() const { return callExpr; }
569 void set_callExpr( Expression *newValue ) { callExpr = newValue; }
570
571 virtual ConstructorExpr *clone() const { return new ConstructorExpr( *this ); }
572 virtual void accept( Visitor &v ) { v.visit( this ); }
573 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
574 virtual void print( std::ostream &os, int indent = 0 ) const;
575private:
576 Expression * callExpr;
577};
578
579/// CompoundLiteralExpr represents a C99 'compound literal'
580class CompoundLiteralExpr : public Expression {
581 public:
582 CompoundLiteralExpr( Type * type, Initializer * initializer );
583 CompoundLiteralExpr( const CompoundLiteralExpr &other );
584 virtual ~CompoundLiteralExpr();
585
586 Type * get_type() const { return type; }
587 void set_type( Type * t ) { type = t; }
588
589 Initializer * get_initializer() const { return initializer; }
590 void set_initializer( Initializer * i ) { initializer = i; }
591
592 virtual CompoundLiteralExpr *clone() const { return new CompoundLiteralExpr( *this ); }
593 virtual void accept( Visitor &v ) { v.visit( this ); }
594 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
595 virtual void print( std::ostream &os, int indent = 0 ) const;
596 private:
597 Type * type;
598 Initializer * initializer;
599};
600
601/// ValofExpr represents a GCC 'lambda expression'
602class UntypedValofExpr : public Expression {
603 public:
604 UntypedValofExpr( Statement *_body, Expression *_aname = nullptr ) : Expression( _aname ), body ( _body ) {}
605 UntypedValofExpr( const UntypedValofExpr & other );
606 virtual ~UntypedValofExpr();
607
608 Expression *get_value();
609 Statement *get_body() const { return body; }
610
611 virtual UntypedValofExpr *clone() const { return new UntypedValofExpr( *this ); }
612 virtual void accept( Visitor &v ) { v.visit( this ); }
613 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
614 virtual void print( std::ostream &os, int indent = 0 ) const;
615 private:
616 Statement *body;
617};
618
619/// RangeExpr represents a range e.g. '3 ... 5' or '1~10'
620class RangeExpr : public Expression {
621 public:
622 RangeExpr( Expression *low, Expression *high );
623 RangeExpr( const RangeExpr &other );
624
625 Expression * get_low() const { return low; }
626 Expression * get_high() const { return high; }
627 RangeExpr * set_low( Expression *low ) { RangeExpr::low = low; return this; }
628 RangeExpr * set_high( Expression *high ) { RangeExpr::high = high; return this; }
629
630 virtual RangeExpr *clone() const { return new RangeExpr( *this ); }
631 virtual void accept( Visitor &v ) { v.visit( this ); }
632 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
633 virtual void print( std::ostream &os, int indent = 0 ) const;
634 private:
635 Expression *low, *high;
636};
637
638/// TupleExpr represents a tuple expression ( [a, b, c] )
639class TupleExpr : public Expression {
640 public:
641 TupleExpr( const std::list< Expression * > & exprs = std::list< Expression * >(), Expression *_aname = nullptr );
642 TupleExpr( const TupleExpr &other );
643 virtual ~TupleExpr();
644
645 void set_exprs( std::list<Expression*> newValue ) { exprs = newValue; }
646 std::list<Expression*>& get_exprs() { return exprs; }
647
648 virtual TupleExpr *clone() const { return new TupleExpr( *this ); }
649 virtual void accept( Visitor &v ) { v.visit( this ); }
650 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
651 virtual void print( std::ostream &os, int indent = 0 ) const;
652 private:
653 std::list<Expression*> exprs;
654};
655
656/// TupleIndexExpr represents an element selection operation on a tuple value, e.g. t.3 after processing by the expression analyzer
657class TupleIndexExpr : public Expression {
658 public:
659 TupleIndexExpr( Expression * tuple, unsigned int index );
660 TupleIndexExpr( const TupleIndexExpr &other );
661 virtual ~TupleIndexExpr();
662
663 Expression * get_tuple() const { return tuple; }
664 int get_index() const { return index; }
665 TupleIndexExpr * set_tuple( Expression *newValue ) { tuple = newValue; return this; }
666 TupleIndexExpr * set_index( unsigned int newValue ) { index = newValue; return this; }
667
668 virtual TupleIndexExpr *clone() const { return new TupleIndexExpr( *this ); }
669 virtual void accept( Visitor &v ) { v.visit( this ); }
670 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
671 virtual void print( std::ostream &os, int indent = 0 ) const;
672 private:
673 Expression * tuple;
674 unsigned int index;
675};
676
677/// MemberTupleExpr represents a tuple member selection operation on a struct type, e.g. s.[a, b, c] after processing by the expression analyzer
678class MemberTupleExpr : public Expression {
679 public:
680 MemberTupleExpr( Expression * member, Expression * aggregate, Expression * _aname = nullptr );
681 MemberTupleExpr( const MemberTupleExpr &other );
682 virtual ~MemberTupleExpr();
683
684 Expression * get_member() const { return member; }
685 Expression * get_aggregate() const { return aggregate; }
686 MemberTupleExpr * set_member( Expression *newValue ) { member = newValue; return this; }
687 MemberTupleExpr * set_aggregate( Expression *newValue ) { aggregate = newValue; return this; }
688
689 virtual MemberTupleExpr *clone() const { return new MemberTupleExpr( *this ); }
690 virtual void accept( Visitor &v ) { v.visit( this ); }
691 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
692 virtual void print( std::ostream &os, int indent = 0 ) const;
693 private:
694 Expression * member;
695 Expression * aggregate;
696};
697
698/// TupleAssignExpr represents a multiple assignment operation, where both sides of the assignment have tuple type, e.g. [a, b, c] = [d, e, f];, a mass assignment operation, where the left hand side has tuple type and the right hand side does not, e.g. [a, b, c] = 5.0;, or a tuple ctor/dtor expression
699class TupleAssignExpr : public Expression {
700 public:
701 TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls, Expression * _aname = nullptr );
702 TupleAssignExpr( const TupleAssignExpr &other );
703 virtual ~TupleAssignExpr();
704
705 std::list< Expression * > & get_assigns() { return assigns; }
706 std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; }
707
708 virtual TupleAssignExpr *clone() const { return new TupleAssignExpr( *this ); }
709 virtual void accept( Visitor &v ) { v.visit( this ); }
710 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
711 virtual void print( std::ostream &os, int indent = 0 ) const;
712 private:
713 std::list< Expression * > assigns; // assignment expressions that use tempDecls
714 std::list< ObjectDecl * > tempDecls; // temporaries for address of lhs exprs
715};
716
717/// StmtExpr represents a GCC 'statement expression', e.g. ({ int x = 5; x; })
718class StmtExpr : public Expression {
719public:
720 StmtExpr( CompoundStmt *statements );
721 StmtExpr( const StmtExpr & other );
722 virtual ~StmtExpr();
723
724 CompoundStmt * get_statements() const { return statements; }
725 StmtExpr * set_statements( CompoundStmt * newValue ) { statements = newValue; return this; }
726
727 virtual StmtExpr *clone() const { return new StmtExpr( *this ); }
728 virtual void accept( Visitor &v ) { v.visit( this ); }
729 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
730 virtual void print( std::ostream &os, int indent = 0 ) const;
731private:
732 CompoundStmt * statements;
733};
734
735class UniqueExpr : public Expression {
736public:
737 UniqueExpr( Expression * expr, long long idVal = -1 );
738 UniqueExpr( const UniqueExpr & other );
739 ~UniqueExpr();
740
741 Expression * get_expr() const { return *expr; }
742 UniqueExpr * set_expr( Expression * newValue ) { *expr = newValue; return this; }
743
744 ObjectDecl * get_object() const { return *object; }
745 UniqueExpr * set_object( ObjectDecl * newValue ) { *object = newValue; return this; }
746
747 int get_id() const { return id; }
748
749 virtual UniqueExpr *clone() const { return new UniqueExpr( *this ); }
750 virtual void accept( Visitor &v ) { v.visit( this ); }
751 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
752 virtual void print( std::ostream &os, int indent = 0 ) const;
753private:
754 std::shared_ptr< Expression * > expr;
755 std::shared_ptr< ObjectDecl * > object;
756 int id;
757 static long long count;
758};
759
760std::ostream & operator<<( std::ostream & out, const Expression * expr );
761
762#endif // EXPRESSION_H
763
764// Local Variables: //
765// tab-width: 4 //
766// mode: c++ //
767// compile-command: "make install" //
768// End: //
Note: See TracBrowser for help on using the repository browser.