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