source: src/SynTree/Expression.h @ f006f01

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since f006f01 was 6eb8948, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

make TupleAssignment? generate temporaries, add StmtExpr? for GCC statement expressions, expand tuple assignment expressions, collapse SolvedTupleExpr?, MassAssignExpr?, and MultipleAssignExpr? into TupleAssignExpr?

  • Property mode set to 100644
File size: 28.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        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
57struct 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
70typedef 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.
74class 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.
98class UntypedExpr : public Expression {
99  public:
100        UntypedExpr( Expression *function, const std::list<Expression *> &args = std::list< Expression * >(), Expression *_aname = nullptr );
101        UntypedExpr( const UntypedExpr &other );
102        virtual ~UntypedExpr();
103
104        Expression *get_function() const { return function; }
105        void set_function( Expression *newValue ) { function = newValue; }
106
107        void set_args( std::list<Expression *> &listArgs ) { args = listArgs; }
108        std::list<Expression*>::iterator begin_args() { return args.begin(); }
109        std::list<Expression*>::iterator end_args() { return args.end(); }
110        std::list<Expression*>& get_args() { return args; }
111
112        virtual UntypedExpr *clone() const { return new UntypedExpr( *this ); }
113        virtual void accept( Visitor &v ) { v.visit( this ); }
114        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
115        virtual void print( std::ostream &os, int indent = 0 ) const;
116        virtual void printArgs(std::ostream &os, int indent = 0) const;
117  private:
118        Expression *function;
119        std::list<Expression*> args;
120};
121
122/// NameExpr contains a name whose meaning is still not determined
123class NameExpr : public Expression {
124  public:
125        NameExpr( std::string name, Expression *_aname = nullptr );
126        NameExpr( const NameExpr &other );
127        virtual ~NameExpr();
128
129        const std::string &get_name() const { return name; }
130        void set_name( std::string newValue ) { name = newValue; }
131
132        virtual NameExpr *clone() const { return new NameExpr( *this ); }
133        virtual void accept( Visitor &v ) { v.visit( this ); }
134        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
135        virtual void print( std::ostream &os, int indent = 0 ) const;
136  private:
137        std::string name;
138};
139
140// The following classes are used to represent expression types that cannot be converted into
141// function-call format.
142
143/// AddressExpr represents a address-of expression, e.g. &e
144class AddressExpr : public Expression {
145  public:
146        AddressExpr( Expression *arg, Expression *_aname = nullptr );
147        AddressExpr( const AddressExpr &other );
148        virtual ~AddressExpr();
149
150        Expression *get_arg() const { return arg; }
151        void set_arg(Expression *newValue ) { arg = newValue; }
152
153        virtual AddressExpr *clone() const { return new AddressExpr( *this ); }
154        virtual void accept( Visitor &v ) { v.visit( this ); }
155        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
156        virtual void print( std::ostream &os, int indent = 0 ) const;
157  private:
158        Expression *arg;
159};
160
161// xxx - this doesn't appear to actually be hooked in anywhere. We should use this instead of the "&&"" UntypedExpr hack
162class LabelAddressExpr : public Expression {
163  public:
164        LabelAddressExpr( Expression *arg );
165        LabelAddressExpr( const LabelAddressExpr &other );
166        virtual ~LabelAddressExpr();
167
168        Expression *get_arg() const { return arg; }
169        void set_arg(Expression *newValue ) { arg = newValue; }
170
171        virtual LabelAddressExpr *clone() const { return new LabelAddressExpr( *this ); }
172        virtual void accept( Visitor &v ) { v.visit( this ); }
173        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
174        virtual void print( std::ostream &os, int indent = 0 ) const;
175  private:
176        Expression *arg;
177};
178
179/// CastExpr represents a type cast expression, e.g. (int)e
180class CastExpr : public Expression {
181  public:
182        CastExpr( Expression *arg, Expression *_aname = nullptr );
183        CastExpr( Expression *arg, Type *toType, Expression *_aname = nullptr );
184        CastExpr( const CastExpr &other );
185        virtual ~CastExpr();
186
187        Expression *get_arg() const { return arg; }
188        void set_arg(Expression *newValue ) { arg = newValue; }
189
190        virtual CastExpr *clone() const { return new CastExpr( *this ); }
191        virtual void accept( Visitor &v ) { v.visit( this ); }
192        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
193        virtual void print( std::ostream &os, int indent = 0 ) const;
194  private:
195        Expression *arg;
196};
197
198/// UntypedMemberExpr represents a member selection operation, e.g. q.p before processing by the expression analyzer
199class UntypedMemberExpr : public Expression {
200  public:
201        UntypedMemberExpr( Expression *member, Expression *aggregate, Expression *_aname = nullptr );
202        UntypedMemberExpr( const UntypedMemberExpr &other );
203        virtual ~UntypedMemberExpr();
204
205        Expression * get_member() const { return member; }
206        void set_member( Expression * newValue ) { member = newValue; }
207        Expression *get_aggregate() const { return aggregate; }
208        void set_aggregate( Expression *newValue ) { aggregate = newValue; }
209
210        virtual UntypedMemberExpr *clone() const { return new UntypedMemberExpr( *this ); }
211        virtual void accept( Visitor &v ) { v.visit( this ); }
212        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
213        virtual void print( std::ostream &os, int indent = 0 ) const;
214  private:
215        Expression *member;
216        Expression *aggregate;
217};
218
219/// MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer
220class MemberExpr : public Expression {
221  public:
222        MemberExpr( DeclarationWithType *member, Expression *aggregate, Expression *_aname = nullptr );
223        MemberExpr( const MemberExpr &other );
224        virtual ~MemberExpr();
225
226        DeclarationWithType *get_member() const { return member; }
227        void set_member( DeclarationWithType *newValue ) { member = newValue; }
228        Expression *get_aggregate() const { return aggregate; }
229        void set_aggregate( Expression *newValue ) { aggregate = newValue; }
230
231        virtual MemberExpr *clone() const { return new MemberExpr( *this ); }
232        virtual void accept( Visitor &v ) { v.visit( this ); }
233        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
234        virtual void print( std::ostream &os, int indent = 0 ) const;
235  private:
236        DeclarationWithType *member;
237        Expression *aggregate;
238};
239
240/// VariableExpr represents an expression that simply refers to the value of a named variable
241class VariableExpr : public Expression {
242  public:
243        VariableExpr( DeclarationWithType *var, Expression *_aname = nullptr );
244        VariableExpr( const VariableExpr &other );
245        virtual ~VariableExpr();
246
247        DeclarationWithType *get_var() const { return var; }
248        void set_var( DeclarationWithType *newValue ) { var = newValue; }
249
250        virtual VariableExpr *clone() const { return new VariableExpr( *this ); }
251        virtual void accept( Visitor &v ) { v.visit( this ); }
252        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
253        virtual void print( std::ostream &os, int indent = 0 ) const;
254  private:
255        DeclarationWithType *var;
256};
257
258/// ConstantExpr represents an expression that simply refers to the value of a constant
259class ConstantExpr : public Expression {
260  public:
261        ConstantExpr( Constant constant, Expression *_aname = nullptr );
262        ConstantExpr( const ConstantExpr &other );
263        virtual ~ConstantExpr();
264
265        Constant *get_constant() { return &constant; }
266        void set_constant( const Constant &newValue ) { constant = newValue; }
267
268        virtual ConstantExpr *clone() const { return new ConstantExpr( *this ); }
269        virtual void accept( Visitor &v ) { v.visit( this ); }
270        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
271        virtual void print( std::ostream &os, int indent = 0 ) const;
272  private:
273        Constant constant;
274};
275
276/// SizeofExpr represents a sizeof expression (could be sizeof(int) or sizeof 3+4)
277class SizeofExpr : public Expression {
278  public:
279        SizeofExpr( Expression *expr, Expression *_aname = nullptr );
280        SizeofExpr( const SizeofExpr &other );
281        SizeofExpr( Type *type, Expression *_aname = nullptr );
282        virtual ~SizeofExpr();
283
284        Expression *get_expr() const { return expr; }
285        void set_expr( Expression *newValue ) { expr = newValue; }
286        Type *get_type() const { return type; }
287        void set_type( Type *newValue ) { type = newValue; }
288        bool get_isType() const { return isType; }
289        void set_isType( bool newValue ) { isType = newValue; }
290
291        virtual SizeofExpr *clone() const { return new SizeofExpr( *this ); }
292        virtual void accept( Visitor &v ) { v.visit( this ); }
293        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
294        virtual void print( std::ostream &os, int indent = 0 ) const;
295  private:
296        Expression *expr;
297        Type *type;
298        bool isType;
299};
300
301/// AlignofExpr represents an alignof expression
302class AlignofExpr : public Expression {
303  public:
304        AlignofExpr( Expression *expr, Expression *_aname = nullptr );
305        AlignofExpr( const AlignofExpr &other );
306        AlignofExpr( Type *type, Expression *_aname = nullptr );
307        virtual ~AlignofExpr();
308
309        Expression *get_expr() const { return expr; }
310        void set_expr( Expression *newValue ) { expr = newValue; }
311        Type *get_type() const { return type; }
312        void set_type( Type *newValue ) { type = newValue; }
313        bool get_isType() const { return isType; }
314        void set_isType( bool newValue ) { isType = newValue; }
315
316        virtual AlignofExpr *clone() const { return new AlignofExpr( *this ); }
317        virtual void accept( Visitor &v ) { v.visit( this ); }
318        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
319        virtual void print( std::ostream &os, int indent = 0 ) const;
320  private:
321        Expression *expr;
322        Type *type;
323        bool isType;
324};
325
326/// UntypedOffsetofExpr represents an offsetof expression before resolution
327class UntypedOffsetofExpr : public Expression {
328  public:
329        UntypedOffsetofExpr( Type *type, const std::string &member, Expression *_aname = nullptr );
330        UntypedOffsetofExpr( const UntypedOffsetofExpr &other );
331        virtual ~UntypedOffsetofExpr();
332
333        std::string get_member() const { return member; }
334        void set_member( const std::string &newValue ) { member = newValue; }
335        Type *get_type() const { return type; }
336        void set_type( Type *newValue ) { type = newValue; }
337
338        virtual UntypedOffsetofExpr *clone() const { return new UntypedOffsetofExpr( *this ); }
339        virtual void accept( Visitor &v ) { v.visit( this ); }
340        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
341        virtual void print( std::ostream &os, int indent = 0 ) const;
342  private:
343        Type *type;
344        std::string member;
345};
346
347/// OffsetofExpr represents an offsetof expression
348class OffsetofExpr : public Expression {
349  public:
350        OffsetofExpr( Type *type, DeclarationWithType *member, Expression *_aname = nullptr );
351        OffsetofExpr( const OffsetofExpr &other );
352        virtual ~OffsetofExpr();
353
354        Type *get_type() const { return type; }
355        void set_type( Type *newValue ) { type = newValue; }
356        DeclarationWithType *get_member() const { return member; }
357        void set_member( DeclarationWithType *newValue ) { member = newValue; }
358
359        virtual OffsetofExpr *clone() const { return new OffsetofExpr( *this ); }
360        virtual void accept( Visitor &v ) { v.visit( this ); }
361        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
362        virtual void print( std::ostream &os, int indent = 0 ) const;
363  private:
364        Type *type;
365        DeclarationWithType *member;
366};
367
368/// Expression representing a pack of field-offsets for a generic type
369class OffsetPackExpr : public Expression {
370public:
371        OffsetPackExpr( StructInstType *type_, Expression *aname_ = 0 );
372        OffsetPackExpr( const OffsetPackExpr &other );
373        virtual ~OffsetPackExpr();
374
375        StructInstType *get_type() const { return type; }
376        void set_type( StructInstType *newValue ) { type = newValue; }
377
378        virtual OffsetPackExpr *clone() const { return new OffsetPackExpr( *this ); }
379        virtual void accept( Visitor &v ) { v.visit( this ); }
380        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
381
382        virtual void print( std::ostream &os, int indent = 0 ) const;
383
384private:
385        StructInstType *type;
386};
387
388/// AttrExpr represents an @attribute expression (like sizeof, but user-defined)
389class AttrExpr : public Expression {
390  public:
391        AttrExpr(Expression *attr, Expression *expr, Expression *_aname = nullptr );
392        AttrExpr( const AttrExpr &other );
393        AttrExpr( Expression *attr, Type *type, Expression *_aname = nullptr );
394        virtual ~AttrExpr();
395
396        Expression *get_attr() const { return attr; }
397        void set_attr( Expression *newValue ) { attr = newValue; }
398        Expression *get_expr() const { return expr; }
399        void set_expr( Expression *newValue ) { expr = newValue; }
400        Type *get_type() const { return type; }
401        void set_type( Type *newValue ) { type = newValue; }
402        bool get_isType() const { return isType; }
403        void set_isType( bool newValue ) { isType = newValue; }
404
405        virtual AttrExpr *clone() const { return new AttrExpr( *this ); }
406        virtual void accept( Visitor &v ) { v.visit( this ); }
407        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
408        virtual void print( std::ostream &os, int indent = 0 ) const;
409  private:
410        Expression *attr;
411        Expression *expr;
412        Type *type;
413        bool isType;
414};
415
416/// LogicalExpr represents a short-circuit boolean expression (&& or ||)
417class LogicalExpr : public Expression {
418  public:
419        LogicalExpr( Expression *arg1, Expression *arg2, bool andp = true, Expression *_aname = nullptr );
420        LogicalExpr( const LogicalExpr &other );
421        virtual ~LogicalExpr();
422
423        bool get_isAnd() const { return isAnd; }
424        Expression *get_arg1() { return arg1; }
425        void set_arg1( Expression *newValue ) { arg1 = newValue; }
426        Expression *get_arg2() const { return arg2; }
427        void set_arg2( Expression *newValue ) { arg2 = newValue; }
428
429        virtual LogicalExpr *clone() const { return new LogicalExpr( *this ); }
430        virtual void accept( Visitor &v ) { v.visit( this ); }
431        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
432        virtual void print( std::ostream &os, int indent = 0 ) const;
433  private:
434        Expression *arg1;
435        Expression *arg2;
436        bool isAnd;
437};
438
439/// ConditionalExpr represents the three-argument conditional ( p ? a : b )
440class ConditionalExpr : public Expression {
441  public:
442        ConditionalExpr( Expression *arg1, Expression *arg2, Expression *arg3, Expression *_aname = nullptr );
443        ConditionalExpr( const ConditionalExpr &other );
444        virtual ~ConditionalExpr();
445
446        Expression *get_arg1() const { return arg1; }
447        void set_arg1( Expression *newValue ) { arg1 = newValue; }
448        Expression *get_arg2() const { return arg2; }
449        void set_arg2( Expression *newValue ) { arg2 = newValue; }
450        Expression *get_arg3() const { return arg3; }
451        void set_arg3( Expression *newValue ) { arg3 = newValue; }
452
453        virtual ConditionalExpr *clone() const { return new ConditionalExpr( *this ); }
454        virtual void accept( Visitor &v ) { v.visit( this ); }
455        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
456        virtual void print( std::ostream &os, int indent = 0 ) const;
457  private:
458        Expression *arg1;
459        Expression *arg2;
460        Expression *arg3;
461};
462
463/// CommaExpr represents the sequence operator ( a, b )
464class CommaExpr : public Expression {
465  public:
466        CommaExpr( Expression *arg1, Expression *arg2, Expression *_aname = nullptr );
467        CommaExpr( const CommaExpr &other );
468        virtual ~CommaExpr();
469
470        Expression *get_arg1() const { return arg1; }
471        void set_arg1( Expression *newValue ) { arg1 = newValue; }
472        Expression *get_arg2() const { return arg2; }
473        void set_arg2( Expression *newValue ) { arg2 = newValue; }
474
475        virtual CommaExpr *clone() const { return new CommaExpr( *this ); }
476        virtual void accept( Visitor &v ) { v.visit( this ); }
477        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
478        virtual void print( std::ostream &os, int indent = 0 ) const;
479  private:
480        Expression *arg1;
481        Expression *arg2;
482};
483
484/// TypeExpr represents a type used in an expression (e.g. as a type generator parameter)
485class TypeExpr : public Expression {
486  public:
487        TypeExpr( Type *type );
488        TypeExpr( const TypeExpr &other );
489        virtual ~TypeExpr();
490
491        Type *get_type() const { return type; }
492        void set_type( Type *newValue ) { type = newValue; }
493
494        virtual TypeExpr *clone() const { return new TypeExpr( *this ); }
495        virtual void accept( Visitor &v ) { v.visit( this ); }
496        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
497        virtual void print( std::ostream &os, int indent = 0 ) const;
498  private:
499        Type *type;
500};
501
502/// AsmExpr represents a GCC 'asm constraint operand' used in an asm statement: [output] "=f" (result)
503class AsmExpr : public Expression {
504  public:
505        AsmExpr( Expression *inout, ConstantExpr *constraint, Expression *operand ) : inout( inout ), constraint( constraint ), operand( operand ) {}
506        AsmExpr( const AsmExpr & other );
507        virtual ~AsmExpr() { delete inout; delete constraint; delete operand; };
508
509        Expression *get_inout() const { return inout; }
510        void set_inout( Expression *newValue ) { inout = newValue; }
511
512        ConstantExpr *get_constraint() const { return constraint; }
513        void set_constraint( ConstantExpr *newValue ) { constraint = newValue; }
514
515        Expression *get_operand() const { return operand; }
516        void set_operand( Expression *newValue ) { operand = newValue; }
517
518        virtual AsmExpr *clone() const { return new AsmExpr( *this ); }
519        virtual void accept( Visitor &v ) { v.visit( this ); }
520        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
521        virtual void print( std::ostream &os, int indent = 0 ) const;
522  private:
523        // https://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Machine-Constraints.html#Machine-Constraints
524        Expression *inout;
525        ConstantExpr *constraint;
526        Expression *operand;
527};
528
529/// ImplicitCopyCtorExpr represents the application of a function to a set of parameters,
530/// along with a set of copy constructor calls, one for each argument.
531class ImplicitCopyCtorExpr : public Expression {
532public:
533        ImplicitCopyCtorExpr( ApplicationExpr * callExpr );
534        ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other );
535        virtual ~ImplicitCopyCtorExpr();
536
537        ApplicationExpr *get_callExpr() const { return callExpr; }
538        void set_callExpr( ApplicationExpr *newValue ) { callExpr = newValue; }
539
540        std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; }
541        void set_tempDecls( std::list< ObjectDecl * > newValue ) { tempDecls = newValue; }
542
543        std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; }
544        void set_returnDecls( std::list< ObjectDecl * > newValue ) { returnDecls = newValue; }
545
546        std::list< Expression * > & get_dtors() { return dtors; }
547        void set_dtors( std::list< Expression * > newValue ) { dtors = newValue; }
548
549        virtual ImplicitCopyCtorExpr *clone() const { return new ImplicitCopyCtorExpr( *this ); }
550        virtual void accept( Visitor &v ) { v.visit( this ); }
551        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
552        virtual void print( std::ostream &os, int indent = 0 ) const;
553  private:
554        ApplicationExpr * callExpr;
555        std::list< ObjectDecl * > tempDecls;
556        std::list< ObjectDecl * > returnDecls;
557        std::list< Expression * > dtors;
558};
559
560/// ConstructorExpr represents the use of a constructor in an expression context, e.g. int * x = malloc() { 5 };
561class ConstructorExpr : public Expression {
562public:
563        ConstructorExpr( Expression * callExpr );
564        ConstructorExpr( const ConstructorExpr & other );
565        ~ConstructorExpr();
566
567        Expression *get_callExpr() const { return callExpr; }
568        void set_callExpr( Expression *newValue ) { callExpr = newValue; }
569
570        virtual ConstructorExpr *clone() const { return new ConstructorExpr( *this ); }
571        virtual void accept( Visitor &v ) { v.visit( this ); }
572        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
573        virtual void print( std::ostream &os, int indent = 0 ) const;
574private:
575        Expression * callExpr;
576};
577
578/// CompoundLiteralExpr represents a C99 'compound literal'
579class CompoundLiteralExpr : public Expression {
580  public:
581        CompoundLiteralExpr( Type * type, Initializer * initializer );
582        CompoundLiteralExpr( const CompoundLiteralExpr &other );
583        virtual ~CompoundLiteralExpr();
584
585        Type * get_type() const { return type; }
586        void set_type( Type * t ) { type = t; }
587
588        Initializer * get_initializer() const { return initializer; }
589        void set_initializer( Initializer * i ) { initializer = i; }
590
591        virtual CompoundLiteralExpr *clone() const { return new CompoundLiteralExpr( *this ); }
592        virtual void accept( Visitor &v ) { v.visit( this ); }
593        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
594        virtual void print( std::ostream &os, int indent = 0 ) const;
595  private:
596        Type * type;
597        Initializer * initializer;
598};
599
600/// ValofExpr represents a GCC 'lambda expression'
601class UntypedValofExpr : public Expression {
602  public:
603        UntypedValofExpr( Statement *_body, Expression *_aname = nullptr ) : Expression( _aname ), body ( _body ) {}
604        UntypedValofExpr( const UntypedValofExpr & other );
605        virtual ~UntypedValofExpr();
606
607        Expression *get_value();
608        Statement *get_body() const { return body; }
609
610        virtual UntypedValofExpr *clone() const { return new UntypedValofExpr( *this ); }
611        virtual void accept( Visitor &v ) { v.visit( this ); }
612        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
613        virtual void print( std::ostream &os, int indent = 0 ) const;
614  private:
615        Statement *body;
616};
617
618/// RangeExpr represents a range e.g. '3 ... 5' or '1~10'
619class RangeExpr : public Expression {
620  public:
621        RangeExpr( Expression *low, Expression *high );
622        RangeExpr( const RangeExpr &other );
623
624        Expression * get_low() const { return low; }
625        Expression * get_high() const { return high; }
626        RangeExpr * set_low( Expression *low ) { RangeExpr::low = low; return this; }
627        RangeExpr * set_high( Expression *high ) { RangeExpr::high = high; return this; }
628
629        virtual RangeExpr *clone() const { return new RangeExpr( *this ); }
630        virtual void accept( Visitor &v ) { v.visit( this ); }
631        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
632        virtual void print( std::ostream &os, int indent = 0 ) const;
633  private:
634        Expression *low, *high;
635};
636
637/// TupleExpr represents a tuple expression ( [a, b, c] )
638class TupleExpr : public Expression {
639  public:
640        TupleExpr( Expression *_aname = nullptr );
641        TupleExpr( const TupleExpr &other );
642        virtual ~TupleExpr();
643
644        void set_exprs( std::list<Expression*> newValue ) { exprs = newValue; }
645        std::list<Expression*>& get_exprs() { return exprs; }
646
647        virtual TupleExpr *clone() const { return new TupleExpr( *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        std::list<Expression*> exprs;
653};
654
655/// TupleIndexExpr represents an element selection operation on a tuple value, e.g. t.3 after processing by the expression analyzer
656class TupleIndexExpr : public Expression {
657  public:
658        TupleIndexExpr( Expression * tuple, unsigned int index );
659        TupleIndexExpr( const TupleIndexExpr &other );
660        virtual ~TupleIndexExpr();
661
662        Expression * get_tuple() const { return tuple; }
663        int get_index() const { return index; }
664        TupleIndexExpr * set_tuple( Expression *newValue ) { tuple = newValue; return this; }
665        TupleIndexExpr * set_index( unsigned int newValue ) { index = newValue; return this; }
666
667        virtual TupleIndexExpr *clone() const { return new TupleIndexExpr( *this ); }
668        virtual void accept( Visitor &v ) { v.visit( this ); }
669        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
670        virtual void print( std::ostream &os, int indent = 0 ) const;
671  private:
672        Expression * tuple;
673        unsigned int index;
674};
675
676/// MemberTupleExpr represents a tuple member selection operation on a struct type, e.g. s.[a, b, c] after processing by the expression analyzer
677class MemberTupleExpr : public Expression {
678  public:
679        MemberTupleExpr( Expression * member, Expression * aggregate, Expression * _aname = nullptr );
680        MemberTupleExpr( const MemberTupleExpr &other );
681        virtual ~MemberTupleExpr();
682
683        Expression * get_member() const { return member; }
684        Expression * get_aggregate() const { return aggregate; }
685        MemberTupleExpr * set_member( Expression *newValue ) { member = newValue; return this; }
686        MemberTupleExpr * set_aggregate( Expression *newValue ) { aggregate = newValue; return this; }
687
688        virtual MemberTupleExpr *clone() const { return new MemberTupleExpr( *this ); }
689        virtual void accept( Visitor &v ) { v.visit( this ); }
690        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
691        virtual void print( std::ostream &os, int indent = 0 ) const;
692  private:
693        Expression * member;
694        Expression * aggregate;
695};
696
697/// TupleAssignExpr represents a multiple assignment operation, where both sides of the assignment have tuple type, e.g. [a, b, c] = [d, e, f];, or 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;
698class TupleAssignExpr : public Expression {
699  public:
700        TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls, Expression * _aname = nullptr );
701        TupleAssignExpr( const TupleAssignExpr &other );
702        virtual ~TupleAssignExpr();
703
704        std::list< Expression * > & get_assigns() { return assigns; }
705        std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; }
706
707        virtual TupleAssignExpr *clone() const { return new TupleAssignExpr( *this ); }
708        virtual void accept( Visitor &v ) { v.visit( this ); }
709        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
710        virtual void print( std::ostream &os, int indent = 0 ) const;
711  private:
712        std::list< Expression * > assigns; // assignment expressions that use tempDecls
713        std::list< ObjectDecl * > tempDecls; // temporaries for address of lhs exprs
714};
715
716/// StmtExpr represents a GCC 'statement expression', e.g. ({ int x = 5; x; })
717class StmtExpr : public Expression {
718public:
719        StmtExpr( CompoundStmt *statements );
720        StmtExpr( const StmtExpr & other );
721        virtual ~StmtExpr();
722
723        CompoundStmt * get_statements() const { return statements; }
724        StmtExpr * set_statements( CompoundStmt * newValue ) { statements = newValue; return this; }
725
726        virtual StmtExpr *clone() const { return new StmtExpr( *this ); }
727        virtual void accept( Visitor &v ) { v.visit( this ); }
728        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
729        virtual void print( std::ostream &os, int indent = 0 ) const;
730private:
731        CompoundStmt * statements;
732};
733
734std::ostream & operator<<( std::ostream & out, const Expression * expr );
735
736#endif // EXPRESSION_H
737
738// Local Variables: //
739// tab-width: 4 //
740// mode: c++ //
741// compile-command: "make install" //
742// End: //
Note: See TracBrowser for help on using the repository browser.