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