Changeset 0720e049 for src/SynTree/Expression.h
- Timestamp:
- Aug 11, 2017, 10:33:37 AM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 54cd58b0
- Parents:
- 3d4b23fa (diff), 59a75cb (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/Expression.h
r3d4b23fa r0720e049 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Thu Mar 30 16:44:00 201713 // Update Count : 4 111 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Aug 8 11:54:00 2017 13 // Update Count : 44 14 14 // 15 15 16 #ifndef EXPRESSION_H 17 #define EXPRESSION_H 16 #pragma once 18 17 19 18 #include <map> … … 30 29 class Expression : public BaseSyntaxNode{ 31 30 public: 31 Type * result; 32 TypeSubstitution * env; 33 Expression * argName; // if expression is used as an argument, it can be "designated" by this name 34 bool extension = false; 35 32 36 Expression( Expression * _aname = nullptr ); 33 37 Expression( const Expression & other ); … … 50 54 virtual Expression * acceptMutator( Mutator & m ) = 0; 51 55 virtual void print( std::ostream & os, int indent = 0 ) const; 52 protected:53 Type * result;54 TypeSubstitution * env;55 Expression * argName; // if expression is used as an argument, it can be "designated" by this name56 bool extension = false;57 56 }; 58 57 … … 80 79 class ApplicationExpr : public Expression { 81 80 public: 82 ApplicationExpr( Expression * function ); 81 Expression * function; 82 83 ApplicationExpr( Expression * function, const std::list<Expression *> & args = std::list< Expression * >() ); 83 84 ApplicationExpr( const ApplicationExpr & other ); 84 85 virtual ~ApplicationExpr(); … … 93 94 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 94 95 virtual void print( std::ostream & os, int indent = 0 ) const; 96 95 97 private: 96 Expression * function;97 98 std::list<Expression *> args; 98 99 InferredParams inferParams; … … 104 105 class UntypedExpr : public Expression { 105 106 public: 107 Expression * function; 108 std::list<Expression*> args; 109 106 110 UntypedExpr( Expression * function, const std::list<Expression *> & args = std::list< Expression * >(), Expression *_aname = nullptr ); 107 111 UntypedExpr( const UntypedExpr & other ); … … 124 128 virtual void print( std::ostream & os, int indent = 0 ) const; 125 129 virtual void printArgs(std::ostream & os, int indent = 0) const; 126 private:127 Expression * function;128 std::list<Expression*> args;129 130 }; 130 131 … … 132 133 class NameExpr : public Expression { 133 134 public: 135 std::string name; 136 134 137 NameExpr( std::string name, Expression *_aname = nullptr ); 135 138 NameExpr( const NameExpr & other ); … … 143 146 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 144 147 virtual void print( std::ostream & os, int indent = 0 ) const; 145 private:146 std::string name;147 148 }; 148 149 … … 153 154 class AddressExpr : public Expression { 154 155 public: 156 Expression * arg; 157 155 158 AddressExpr( Expression * arg, Expression *_aname = nullptr ); 156 159 AddressExpr( const AddressExpr & other ); … … 164 167 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 165 168 virtual void print( std::ostream & os, int indent = 0 ) const; 166 private:167 Expression * arg;168 169 }; 169 170 … … 171 172 class LabelAddressExpr : public Expression { 172 173 public: 174 Expression * arg; 175 173 176 LabelAddressExpr( Expression * arg ); 174 177 LabelAddressExpr( const LabelAddressExpr & other ); … … 182 185 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 183 186 virtual void print( std::ostream & os, int indent = 0 ) const; 184 private:185 Expression * arg;186 187 }; 187 188 … … 189 190 class CastExpr : public Expression { 190 191 public: 192 Expression * arg; 193 191 194 CastExpr( Expression * arg, Expression *_aname = nullptr ); 192 195 CastExpr( Expression * arg, Type * toType, Expression *_aname = nullptr ); … … 195 198 196 199 Expression * get_arg() const { return arg; } 197 void set_arg( Expression * newValue ) { arg = newValue; }200 void set_arg( Expression * newValue ) { arg = newValue; } 198 201 199 202 virtual CastExpr * clone() const { return new CastExpr( * this ); } … … 201 204 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 202 205 virtual void print( std::ostream & os, int indent = 0 ) const; 203 private: 206 }; 207 208 /// VirtualCastExpr repersents a virtual dynamic cast, e.g. (virtual exception)e 209 class VirtualCastExpr : public Expression { 210 public: 204 211 Expression * arg; 212 213 VirtualCastExpr( Expression * arg, Type * toType ); 214 VirtualCastExpr( const VirtualCastExpr & other ); 215 virtual ~VirtualCastExpr(); 216 217 Expression * get_arg() const { return arg; } 218 void set_arg( Expression * newValue ) { arg = newValue; } 219 220 virtual VirtualCastExpr * clone() const { return new VirtualCastExpr( * this ); } 221 virtual void accept( Visitor & v ) { v.visit( this ); } 222 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 223 virtual void print( std::ostream & os, int indent = 0 ) const; 205 224 }; 206 225 … … 208 227 class UntypedMemberExpr : public Expression { 209 228 public: 229 Expression * member; 230 Expression * aggregate; 231 210 232 UntypedMemberExpr( Expression * member, Expression * aggregate, Expression *_aname = nullptr ); 211 233 UntypedMemberExpr( const UntypedMemberExpr & other ); … … 221 243 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 222 244 virtual void print( std::ostream & os, int indent = 0 ) const; 223 private:224 Expression * member;225 Expression * aggregate;226 245 }; 227 246 … … 230 249 class MemberExpr : public Expression { 231 250 public: 251 DeclarationWithType * member; 252 Expression * aggregate; 253 232 254 MemberExpr( DeclarationWithType * member, Expression * aggregate, Expression *_aname = nullptr ); 233 255 MemberExpr( const MemberExpr & other ); … … 243 265 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 244 266 virtual void print( std::ostream & os, int indent = 0 ) const; 245 private:246 DeclarationWithType * member;247 Expression * aggregate;248 267 }; 249 268 … … 252 271 class VariableExpr : public Expression { 253 272 public: 273 DeclarationWithType * var; 274 254 275 VariableExpr( DeclarationWithType * var, Expression *_aname = nullptr ); 255 276 VariableExpr( const VariableExpr & other ); … … 263 284 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 264 285 virtual void print( std::ostream & os, int indent = 0 ) const; 265 private:266 DeclarationWithType * var;267 286 }; 268 287 … … 270 289 class ConstantExpr : public Expression { 271 290 public: 291 Constant constant; 292 272 293 ConstantExpr( Constant constant, Expression *_aname = nullptr ); 273 294 ConstantExpr( const ConstantExpr & other ); … … 281 302 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 282 303 virtual void print( std::ostream & os, int indent = 0 ) const; 283 private:284 Constant constant;285 304 }; 286 305 … … 288 307 class SizeofExpr : public Expression { 289 308 public: 309 Expression * expr; 310 Type * type; 311 bool isType; 312 290 313 SizeofExpr( Expression * expr, Expression *_aname = nullptr ); 291 314 SizeofExpr( const SizeofExpr & other ); … … 304 327 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 305 328 virtual void print( std::ostream & os, int indent = 0 ) const; 306 private: 329 }; 330 331 /// AlignofExpr represents an alignof expression 332 class AlignofExpr : public Expression { 333 public: 307 334 Expression * expr; 308 335 Type * type; 309 336 bool isType; 310 }; 311 312 /// AlignofExpr represents an alignof expression 313 class AlignofExpr : public Expression { 314 public: 337 315 338 AlignofExpr( Expression * expr, Expression *_aname = nullptr ); 316 339 AlignofExpr( const AlignofExpr & other ); … … 329 352 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 330 353 virtual void print( std::ostream & os, int indent = 0 ) const; 331 private:332 Expression * expr;333 Type * type;334 bool isType;335 354 }; 336 355 … … 338 357 class UntypedOffsetofExpr : public Expression { 339 358 public: 359 Type * type; 360 std::string member; 361 340 362 UntypedOffsetofExpr( Type * type, const std::string & member, Expression *_aname = nullptr ); 341 363 UntypedOffsetofExpr( const UntypedOffsetofExpr & other ); … … 351 373 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 352 374 virtual void print( std::ostream & os, int indent = 0 ) const; 353 private:354 Type * type;355 std::string member;356 375 }; 357 376 … … 359 378 class OffsetofExpr : public Expression { 360 379 public: 380 Type * type; 381 DeclarationWithType * member; 382 361 383 OffsetofExpr( Type * type, DeclarationWithType * member, Expression *_aname = nullptr ); 362 384 OffsetofExpr( const OffsetofExpr & other ); … … 372 394 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 373 395 virtual void print( std::ostream & os, int indent = 0 ) const; 374 private:375 Type * type;376 DeclarationWithType * member;377 396 }; 378 397 … … 380 399 class OffsetPackExpr : public Expression { 381 400 public: 401 StructInstType * type; 402 382 403 OffsetPackExpr( StructInstType * type_, Expression * aname_ = 0 ); 383 404 OffsetPackExpr( const OffsetPackExpr & other ); … … 390 411 virtual void accept( Visitor & v ) { v.visit( this ); } 391 412 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 392 393 virtual void print( std::ostream & os, int indent = 0 ) const; 394 395 private: 396 StructInstType * type; 413 virtual void print( std::ostream & os, int indent = 0 ) const; 397 414 }; 398 415 … … 400 417 class AttrExpr : public Expression { 401 418 public: 419 Expression * attr; 420 Expression * expr; 421 Type * type; 422 bool isType; 423 402 424 AttrExpr(Expression * attr, Expression * expr, Expression *_aname = nullptr ); 403 425 AttrExpr( const AttrExpr & other ); … … 418 440 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 419 441 virtual void print( std::ostream & os, int indent = 0 ) const; 420 private:421 Expression * attr;422 Expression * expr;423 Type * type;424 bool isType;425 442 }; 426 443 … … 428 445 class LogicalExpr : public Expression { 429 446 public: 447 Expression * arg1; 448 Expression * arg2; 449 430 450 LogicalExpr( Expression * arg1, Expression * arg2, bool andp = true, Expression *_aname = nullptr ); 431 451 LogicalExpr( const LogicalExpr & other ); … … 442 462 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 443 463 virtual void print( std::ostream & os, int indent = 0 ) const; 464 444 465 private: 466 bool isAnd; 467 }; 468 469 /// ConditionalExpr represents the three-argument conditional ( p ? a : b ) 470 class ConditionalExpr : public Expression { 471 public: 445 472 Expression * arg1; 446 473 Expression * arg2; 447 bool isAnd; 448 }; 449 450 /// ConditionalExpr represents the three-argument conditional ( p ? a : b ) 451 class ConditionalExpr : public Expression { 452 public: 474 Expression * arg3; 475 453 476 ConditionalExpr( Expression * arg1, Expression * arg2, Expression * arg3, Expression *_aname = nullptr ); 454 477 ConditionalExpr( const ConditionalExpr & other ); … … 466 489 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 467 490 virtual void print( std::ostream & os, int indent = 0 ) const; 468 private: 491 }; 492 493 /// CommaExpr represents the sequence operator ( a, b ) 494 class CommaExpr : public Expression { 495 public: 469 496 Expression * arg1; 470 497 Expression * arg2; 471 Expression * arg3; 472 }; 473 474 /// CommaExpr represents the sequence operator ( a, b ) 475 class CommaExpr : public Expression { 476 public: 498 477 499 CommaExpr( Expression * arg1, Expression * arg2, Expression *_aname = nullptr ); 478 500 CommaExpr( const CommaExpr & other ); … … 488 510 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 489 511 virtual void print( std::ostream & os, int indent = 0 ) const; 490 private:491 Expression * arg1;492 Expression * arg2;493 512 }; 494 513 … … 496 515 class TypeExpr : public Expression { 497 516 public: 517 Type * type; 518 498 519 TypeExpr( Type * type ); 499 520 TypeExpr( const TypeExpr & other ); … … 507 528 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 508 529 virtual void print( std::ostream & os, int indent = 0 ) const; 509 private:510 Type * type;511 530 }; 512 531 … … 514 533 class AsmExpr : public Expression { 515 534 public: 535 Expression * inout; 536 ConstantExpr * constraint; 537 Expression * operand; 538 516 539 AsmExpr( Expression * inout, ConstantExpr * constraint, Expression * operand ) : inout( inout ), constraint( constraint ), operand( operand ) {} 517 540 AsmExpr( const AsmExpr & other ); … … 531 554 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 532 555 virtual void print( std::ostream & os, int indent = 0 ) const; 533 private: 556 534 557 // https://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Machine-Constraints.html#Machine-Constraints 535 Expression * inout;536 ConstantExpr * constraint;537 Expression * operand;538 558 }; 539 559 … … 542 562 class ImplicitCopyCtorExpr : public Expression { 543 563 public: 544 ImplicitCopyCtorExpr( ApplicationExpr * callExpr );545 ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other );546 virtual ~ImplicitCopyCtorExpr();547 548 ApplicationExpr * get_callExpr() const { return callExpr; }549 void set_callExpr( ApplicationExpr * newValue ) { callExpr = newValue; }550 551 std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; }552 std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; }553 std::list< Expression * > & get_dtors() { return dtors; }554 555 virtual ImplicitCopyCtorExpr * clone() const { return new ImplicitCopyCtorExpr( * 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 564 ApplicationExpr * callExpr; 561 565 std::list< ObjectDecl * > tempDecls; 562 566 std::list< ObjectDecl * > returnDecls; 563 567 std::list< Expression * > dtors; 568 569 ImplicitCopyCtorExpr( ApplicationExpr * callExpr ); 570 ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other ); 571 virtual ~ImplicitCopyCtorExpr(); 572 573 ApplicationExpr * get_callExpr() const { return callExpr; } 574 void set_callExpr( ApplicationExpr * newValue ) { callExpr = newValue; } 575 576 std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; } 577 std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; } 578 std::list< Expression * > & get_dtors() { return dtors; } 579 580 virtual ImplicitCopyCtorExpr * clone() const { return new ImplicitCopyCtorExpr( * this ); } 581 virtual void accept( Visitor & v ) { v.visit( this ); } 582 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 583 virtual void print( std::ostream & os, int indent = 0 ) const; 564 584 }; 565 585 … … 567 587 class ConstructorExpr : public Expression { 568 588 public: 589 Expression * callExpr; 590 569 591 ConstructorExpr( Expression * callExpr ); 570 592 ConstructorExpr( const ConstructorExpr & other ); … … 578 600 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 579 601 virtual void print( std::ostream & os, int indent = 0 ) const; 580 private:581 Expression * callExpr;582 602 }; 583 603 … … 585 605 class CompoundLiteralExpr : public Expression { 586 606 public: 607 Initializer * initializer; 608 587 609 CompoundLiteralExpr( Type * type, Initializer * initializer ); 588 610 CompoundLiteralExpr( const CompoundLiteralExpr & other ); … … 596 618 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 597 619 virtual void print( std::ostream & os, int indent = 0 ) const; 598 private:599 Initializer * initializer;600 620 }; 601 621 … … 603 623 class RangeExpr : public Expression { 604 624 public: 625 Expression * low, * high; 626 605 627 RangeExpr( Expression * low, Expression * high ); 606 628 RangeExpr( const RangeExpr & other ); … … 615 637 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 616 638 virtual void print( std::ostream & os, int indent = 0 ) const; 617 private:618 Expression * low, * high;619 639 }; 620 640 … … 622 642 class UntypedTupleExpr : public Expression { 623 643 public: 644 std::list<Expression*> exprs; 645 624 646 UntypedTupleExpr( const std::list< Expression * > & exprs, Expression *_aname = nullptr ); 625 647 UntypedTupleExpr( const UntypedTupleExpr & other ); … … 632 654 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 633 655 virtual void print( std::ostream & os, int indent = 0 ) const; 634 private:635 std::list<Expression*> exprs;636 656 }; 637 657 … … 639 659 class TupleExpr : public Expression { 640 660 public: 661 std::list<Expression*> exprs; 662 641 663 TupleExpr( const std::list< Expression * > & exprs, Expression *_aname = nullptr ); 642 664 TupleExpr( const TupleExpr & other ); … … 649 671 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 650 672 virtual void print( std::ostream & os, int indent = 0 ) const; 651 private:652 std::list<Expression*> exprs;653 673 }; 654 674 … … 656 676 class TupleIndexExpr : public Expression { 657 677 public: 678 Expression * tuple; 679 unsigned int index; 680 658 681 TupleIndexExpr( Expression * tuple, unsigned int index ); 659 682 TupleIndexExpr( const TupleIndexExpr & other ); … … 669 692 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 670 693 virtual void print( std::ostream & os, int indent = 0 ) const; 671 private:672 Expression * tuple;673 unsigned int index;674 694 }; 675 695 … … 677 697 class TupleAssignExpr : public Expression { 678 698 public: 699 StmtExpr * stmtExpr = nullptr; 700 679 701 TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls, Expression * _aname = nullptr ); 680 702 TupleAssignExpr( const TupleAssignExpr & other ); … … 688 710 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 689 711 virtual void print( std::ostream & os, int indent = 0 ) const; 690 private:691 StmtExpr * stmtExpr = nullptr;692 712 }; 693 713 … … 695 715 class StmtExpr : public Expression { 696 716 public: 717 CompoundStmt * statements; 718 std::list< ObjectDecl * > returnDecls; // return variable(s) for stmt expression 719 std::list< Expression * > dtors; // destructor(s) for return variable(s) 720 697 721 StmtExpr( CompoundStmt * statements ); 698 722 StmtExpr( const StmtExpr & other ); … … 709 733 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 710 734 virtual void print( std::ostream & os, int indent = 0 ) const; 711 private:712 CompoundStmt * statements;713 std::list< ObjectDecl * > returnDecls; // return variable(s) for stmt expression714 std::list< Expression * > dtors; // destructor(s) for return variable(s)715 735 }; 716 736 717 737 class UniqueExpr : public Expression { 718 738 public: 739 Expression * expr; 740 ObjectDecl * object; 741 VariableExpr * var; 742 719 743 UniqueExpr( Expression * expr, long long idVal = -1 ); 720 744 UniqueExpr( const UniqueExpr & other ); … … 736 760 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 737 761 virtual void print( std::ostream & os, int indent = 0 ) const; 762 738 763 private: 739 Expression * expr;740 ObjectDecl * object;741 VariableExpr * var;742 764 int id; 743 765 static long long count; … … 756 778 class UntypedInitExpr : public Expression { 757 779 public: 780 Expression * expr; 781 std::list<InitAlternative> initAlts; 782 758 783 UntypedInitExpr( Expression * expr, const std::list<InitAlternative> & initAlts ); 759 784 UntypedInitExpr( const UntypedInitExpr & other ); … … 769 794 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 770 795 virtual void print( std::ostream & os, int indent = 0 ) const; 771 private:772 Expression * expr;773 std::list<InitAlternative> initAlts;774 796 }; 775 797 776 798 class InitExpr : public Expression { 777 799 public: 800 Expression * expr; 801 Designation * designation; 802 778 803 InitExpr( Expression * expr, Designation * designation ); 779 804 InitExpr( const InitExpr & other ); … … 790 815 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 791 816 virtual void print( std::ostream & os, int indent = 0 ) const; 792 private:793 Expression * expr;794 Designation * designation;795 817 }; 796 818 797 819 798 820 std::ostream & operator<<( std::ostream & out, const Expression * expr ); 799 800 #endif // EXPRESSION_H801 821 802 822 // Local Variables: //
Note:
See TracChangeset
for help on using the changeset viewer.