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