Changes in src/SynTree/Expression.h [7f5566b:8688ce1]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/Expression.h
r7f5566b r8688ce1 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Expression.h -- 7 // Expression.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 24 13:49:28 201513 // Update Count : 1812 // Last Modified On : Wed Aug 3 17:08:44 2016 13 // Update Count : 27 14 14 // 15 15 … … 18 18 19 19 #include <map> 20 #include <memory> 20 21 #include "SynTree.h" 21 22 #include "Visitor.h" 22 23 #include "Mutator.h" 23 24 #include "Constant.h" 24 25 #include "Common/UniqueName.h" 26 27 /// Expression is the root type for all expressions 25 28 class Expression { 26 29 public: … … 36 39 Expression *get_argName() const { return argName; } 37 40 void set_argName( Expression *name ) { argName = name; } 41 bool get_extension() const { return extension; } 42 Expression * set_extension( bool exten ) { extension = exten; return this; } 38 43 39 44 virtual Expression *clone() const = 0; … … 45 50 TypeSubstitution *env; 46 51 Expression* argName; // if expression is used as an argument, it can be "designated" by this name 47 };48 49 // ParamEntry contains the i.d. of a declaration and a type that is derived from that declaration, 50 // but subject to decay-to-pointer and type parameter renaming51 52 bool extension = false; 53 }; 54 55 /// ParamEntry contains the i.d. of a declaration and a type that is derived from that declaration, 56 /// but subject to decay-to-pointer and type parameter renaming 52 57 struct ParamEntry { 53 58 ParamEntry(): decl( 0 ), actualType( 0 ), formalType( 0 ), expr( 0 ) {} … … 65 70 typedef std::map< UniqueId, ParamEntry > InferredParams; 66 71 67 // ApplicationExpr represents the application of a function to a set of parameters. This is the 68 // result of running an UntypedExpr through the expression analyzer. 69 72 /// ApplicationExpr represents the application of a function to a set of parameters. This is the 73 /// result of running an UntypedExpr through the expression analyzer. 70 74 class ApplicationExpr : public Expression { 71 75 public: … … 89 93 }; 90 94 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. 94 95 /// UntypedExpr represents the application of a function to a set of parameters, but where the 96 /// particular overload for the function name has not yet been determined. Most operators are 97 /// converted into functional form automatically, to permit operator overloading. 95 98 class UntypedExpr : public Expression { 96 99 public: … … 118 121 }; 119 122 120 // this classcontains a name whose meaning is still not determined123 /// NameExpr contains a name whose meaning is still not determined 121 124 class NameExpr : public Expression { 122 125 public: … … 139 142 // function-call format. 140 143 141 // AddressExpr represents a address-of expression, e.g. &e144 /// AddressExpr represents a address-of expression, e.g. &e 142 145 class AddressExpr : public Expression { 143 146 public: … … 157 160 }; 158 161 162 // xxx - this doesn't appear to actually be hooked in anywhere. We should use this instead of the "&&"" UntypedExpr hack 159 163 class LabelAddressExpr : public Expression { 160 164 public: 161 165 LabelAddressExpr( Expression *arg ); 162 LabelAddressExpr( const AddressExpr &other );166 LabelAddressExpr( const LabelAddressExpr &other ); 163 167 virtual ~LabelAddressExpr(); 164 168 … … 174 178 }; 175 179 176 // CastExpr represents a type cast expression, e.g. (int)e180 /// CastExpr represents a type cast expression, e.g. (int)e 177 181 class CastExpr : public Expression { 178 182 public: … … 193 197 }; 194 198 195 // UntypedMemberExpr represents a member selection operation, e.g. q.p before processing by the expression analyzer199 /// UntypedMemberExpr represents a member selection operation, e.g. q.p before processing by the expression analyzer 196 200 class UntypedMemberExpr : public Expression { 197 201 public: … … 214 218 }; 215 219 216 // MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer220 /// MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer 217 221 class MemberExpr : public Expression { 218 222 public: … … 235 239 }; 236 240 237 // VariableExpr represents an expression that simply refers to the value of a named variable241 /// VariableExpr represents an expression that simply refers to the value of a named variable 238 242 class VariableExpr : public Expression { 239 243 public: … … 253 257 }; 254 258 255 // ConstantExpr represents an expression that simply refers to the value of a constant259 /// ConstantExpr represents an expression that simply refers to the value of a constant 256 260 class ConstantExpr : public Expression { 257 261 public: … … 271 275 }; 272 276 273 // SizeofExpr represents a sizeof expression (could be sizeof(int) or sizeof 3+4)277 /// SizeofExpr represents a sizeof expression (could be sizeof(int) or sizeof 3+4) 274 278 class SizeofExpr : public Expression { 275 279 public: … … 296 300 }; 297 301 298 // AttrExpr represents an @attribute expression (like sizeof, but user-defined) 302 /// AlignofExpr represents an alignof expression 303 class AlignofExpr : public Expression { 304 public: 305 AlignofExpr( Expression *expr, Expression *_aname = 0 ); 306 AlignofExpr( const AlignofExpr &other ); 307 AlignofExpr( Type *type, Expression *_aname = 0 ); 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 327 /// UntypedOffsetofExpr represents an offsetof expression before resolution 328 class UntypedOffsetofExpr : public Expression { 329 public: 330 UntypedOffsetofExpr( Type *type, const std::string &member, Expression *_aname = 0 ); 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 348 /// OffsetofExpr represents an offsetof expression 349 class OffsetofExpr : public Expression { 350 public: 351 OffsetofExpr( Type *type, DeclarationWithType *member, Expression *_aname = 0 ); 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 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 389 /// AttrExpr represents an @attribute expression (like sizeof, but user-defined) 299 390 class AttrExpr : public Expression { 300 391 public: … … 324 415 }; 325 416 326 // LogicalExpr represents a short-circuit boolean expression (&& or ||)417 /// LogicalExpr represents a short-circuit boolean expression (&& or ||) 327 418 class LogicalExpr : public Expression { 328 419 public: … … 347 438 }; 348 439 349 // ConditionalExpr represents the three-argument conditional ( p ? a : b )440 /// ConditionalExpr represents the three-argument conditional ( p ? a : b ) 350 441 class ConditionalExpr : public Expression { 351 442 public: … … 371 462 }; 372 463 373 // CommaExpr represents the sequence operator ( a, b )464 /// CommaExpr represents the sequence operator ( a, b ) 374 465 class CommaExpr : public Expression { 375 466 public: … … 392 483 }; 393 484 394 // TupleExpr represents a tuple expression ( [a, b, c] )485 /// TupleExpr represents a tuple expression ( [a, b, c] ) 395 486 class TupleExpr : public Expression { 396 487 public: … … 410 501 }; 411 502 412 // SolvedTupleExpr represents a TupleExpr whose components have been type-resolved. It is effectively a shell for the code generator to work on503 /// SolvedTupleExpr represents a TupleExpr whose components have been type-resolved. It is effectively a shell for the code generator to work on 413 504 class SolvedTupleExpr : public Expression { 414 505 public: … … 428 519 }; 429 520 430 // TypeExpr represents a type used in an expression (e.g. as a type generator parameter)521 /// TypeExpr represents a type used in an expression (e.g. as a type generator parameter) 431 522 class TypeExpr : public Expression { 432 523 public: … … 446 537 }; 447 538 448 // AsmExpr represents a GCC 'asm constraint operand' used in an asm statement: [output] "=f" (result)539 /// AsmExpr represents a GCC 'asm constraint operand' used in an asm statement: [output] "=f" (result) 449 540 class AsmExpr : public Expression { 450 541 public: 451 542 AsmExpr( Expression *inout, ConstantExpr *constraint, Expression *operand ) : inout( inout ), constraint( constraint ), operand( operand ) {} 543 AsmExpr( const AsmExpr & other ); 452 544 virtual ~AsmExpr() { delete inout; delete constraint; delete operand; }; 453 545 … … 472 564 }; 473 565 474 // ValofExpr represents a GCC 'lambda expression' 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 597 /// ValofExpr represents a GCC 'lambda expression' 475 598 class UntypedValofExpr : public Expression { 476 599 public: 477 600 UntypedValofExpr( Statement *_body, Expression *_aname = 0 ) : Expression( _aname ), body ( _body ) {} 478 virtual ~UntypedValofExpr() {} 601 UntypedValofExpr( const UntypedValofExpr & other ); 602 virtual ~UntypedValofExpr(); 479 603 480 604 Expression *get_value(); … … 488 612 Statement *body; 489 613 }; 614 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 637 class RangeExpr : public Expression { 638 public: 639 RangeExpr( ConstantExpr *low, ConstantExpr *high ); 640 RangeExpr( const RangeExpr &other ); 641 642 ConstantExpr * get_low() const { return low.get(); } 643 ConstantExpr * get_high() const { return high.get(); } 644 RangeExpr * set_low( ConstantExpr *low ) { RangeExpr::low.reset( low ); return this; } 645 RangeExpr * set_high( ConstantExpr *high ) { RangeExpr::high.reset( high ); return this; } 646 647 virtual RangeExpr *clone() const { return new RangeExpr( *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::unique_ptr<ConstantExpr> low, high; 653 }; 654 655 std::ostream & operator<<( std::ostream & out, Expression * expr ); 490 656 491 657 #endif // EXPRESSION_H
Note:
See TracChangeset
for help on using the changeset viewer.