source: src/SynTree/Expression.h @ 97f65d5

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 97f65d5 was 294647b, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Filename and linenumber handling for parsing errors

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