Changeset 9236060 for src/SynTree/Expression.h
- Timestamp:
- Aug 14, 2017, 2:03:39 PM (7 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:
- 74b007ba
- Parents:
- fd344aa (diff), 54cd58b (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
rfd344aa r9236060 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, const std::list<Expression *> & args = std::list<Expression *>() ); 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 ); … … 265 286 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 266 287 virtual void print( std::ostream & os, int indent = 0 ) const; 267 private:268 DeclarationWithType * var;269 288 }; 270 289 … … 272 291 class ConstantExpr : public Expression { 273 292 public: 293 Constant constant; 294 274 295 ConstantExpr( Constant constant, Expression *_aname = nullptr ); 275 296 ConstantExpr( const ConstantExpr & other ); … … 283 304 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 284 305 virtual void print( std::ostream & os, int indent = 0 ) const; 285 private:286 Constant constant;287 306 }; 288 307 … … 290 309 class SizeofExpr : public Expression { 291 310 public: 311 Expression * expr; 312 Type * type; 313 bool isType; 314 292 315 SizeofExpr( Expression * expr, Expression *_aname = nullptr ); 293 316 SizeofExpr( const SizeofExpr & other ); … … 306 329 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 307 330 virtual void print( std::ostream & os, int indent = 0 ) const; 308 private: 331 }; 332 333 /// AlignofExpr represents an alignof expression 334 class AlignofExpr : public Expression { 335 public: 309 336 Expression * expr; 310 337 Type * type; 311 338 bool isType; 312 }; 313 314 /// AlignofExpr represents an alignof expression 315 class AlignofExpr : public Expression { 316 public: 339 317 340 AlignofExpr( Expression * expr, Expression *_aname = nullptr ); 318 341 AlignofExpr( const AlignofExpr & other ); … … 331 354 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 332 355 virtual void print( std::ostream & os, int indent = 0 ) const; 333 private:334 Expression * expr;335 Type * type;336 bool isType;337 356 }; 338 357 … … 340 359 class UntypedOffsetofExpr : public Expression { 341 360 public: 361 Type * type; 362 std::string member; 363 342 364 UntypedOffsetofExpr( Type * type, const std::string & member, Expression *_aname = nullptr ); 343 365 UntypedOffsetofExpr( const UntypedOffsetofExpr & other ); … … 353 375 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 354 376 virtual void print( std::ostream & os, int indent = 0 ) const; 355 private:356 Type * type;357 std::string member;358 377 }; 359 378 … … 361 380 class OffsetofExpr : public Expression { 362 381 public: 382 Type * type; 383 DeclarationWithType * member; 384 363 385 OffsetofExpr( Type * type, DeclarationWithType * member, Expression *_aname = nullptr ); 364 386 OffsetofExpr( const OffsetofExpr & other ); … … 374 396 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 375 397 virtual void print( std::ostream & os, int indent = 0 ) const; 376 private:377 Type * type;378 DeclarationWithType * member;379 398 }; 380 399 … … 382 401 class OffsetPackExpr : public Expression { 383 402 public: 403 StructInstType * type; 404 384 405 OffsetPackExpr( StructInstType * type_, Expression * aname_ = 0 ); 385 406 OffsetPackExpr( const OffsetPackExpr & other ); … … 392 413 virtual void accept( Visitor & v ) { v.visit( this ); } 393 414 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 394 395 virtual void print( std::ostream & os, int indent = 0 ) const; 396 397 private: 398 StructInstType * type; 415 virtual void print( std::ostream & os, int indent = 0 ) const; 399 416 }; 400 417 … … 402 419 class AttrExpr : public Expression { 403 420 public: 421 Expression * attr; 422 Expression * expr; 423 Type * type; 424 bool isType; 425 404 426 AttrExpr(Expression * attr, Expression * expr, Expression *_aname = nullptr ); 405 427 AttrExpr( const AttrExpr & other ); … … 420 442 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 421 443 virtual void print( std::ostream & os, int indent = 0 ) const; 422 private:423 Expression * attr;424 Expression * expr;425 Type * type;426 bool isType;427 444 }; 428 445 … … 430 447 class LogicalExpr : public Expression { 431 448 public: 449 Expression * arg1; 450 Expression * arg2; 451 432 452 LogicalExpr( Expression * arg1, Expression * arg2, bool andp = true, Expression *_aname = nullptr ); 433 453 LogicalExpr( const LogicalExpr & other ); … … 444 464 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 445 465 virtual void print( std::ostream & os, int indent = 0 ) const; 466 446 467 private: 468 bool isAnd; 469 }; 470 471 /// ConditionalExpr represents the three-argument conditional ( p ? a : b ) 472 class ConditionalExpr : public Expression { 473 public: 447 474 Expression * arg1; 448 475 Expression * arg2; 449 bool isAnd; 450 }; 451 452 /// ConditionalExpr represents the three-argument conditional ( p ? a : b ) 453 class ConditionalExpr : public Expression { 454 public: 476 Expression * arg3; 477 455 478 ConditionalExpr( Expression * arg1, Expression * arg2, Expression * arg3, Expression *_aname = nullptr ); 456 479 ConditionalExpr( const ConditionalExpr & other ); … … 468 491 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 469 492 virtual void print( std::ostream & os, int indent = 0 ) const; 470 private: 493 }; 494 495 /// CommaExpr represents the sequence operator ( a, b ) 496 class CommaExpr : public Expression { 497 public: 471 498 Expression * arg1; 472 499 Expression * arg2; 473 Expression * arg3; 474 }; 475 476 /// CommaExpr represents the sequence operator ( a, b ) 477 class CommaExpr : public Expression { 478 public: 500 479 501 CommaExpr( Expression * arg1, Expression * arg2, Expression *_aname = nullptr ); 480 502 CommaExpr( const CommaExpr & other ); … … 490 512 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 491 513 virtual void print( std::ostream & os, int indent = 0 ) const; 492 private:493 Expression * arg1;494 Expression * arg2;495 514 }; 496 515 … … 498 517 class TypeExpr : public Expression { 499 518 public: 519 Type * type; 520 500 521 TypeExpr( Type * type ); 501 522 TypeExpr( const TypeExpr & other ); … … 509 530 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 510 531 virtual void print( std::ostream & os, int indent = 0 ) const; 511 private:512 Type * type;513 532 }; 514 533 … … 516 535 class AsmExpr : public Expression { 517 536 public: 537 Expression * inout; 538 ConstantExpr * constraint; 539 Expression * operand; 540 518 541 AsmExpr( Expression * inout, ConstantExpr * constraint, Expression * operand ) : inout( inout ), constraint( constraint ), operand( operand ) {} 519 542 AsmExpr( const AsmExpr & other ); … … 533 556 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 534 557 virtual void print( std::ostream & os, int indent = 0 ) const; 535 private: 558 536 559 // https://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Machine-Constraints.html#Machine-Constraints 537 Expression * inout;538 ConstantExpr * constraint;539 Expression * operand;540 560 }; 541 561 … … 544 564 class ImplicitCopyCtorExpr : public Expression { 545 565 public: 546 ImplicitCopyCtorExpr( ApplicationExpr * callExpr );547 ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other );548 virtual ~ImplicitCopyCtorExpr();549 550 ApplicationExpr * get_callExpr() const { return callExpr; }551 void set_callExpr( ApplicationExpr * newValue ) { callExpr = newValue; }552 553 std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; }554 std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; }555 std::list< Expression * > & get_dtors() { return dtors; }556 557 virtual ImplicitCopyCtorExpr * clone() const { return new ImplicitCopyCtorExpr( * this ); }558 virtual void accept( Visitor & v ) { v.visit( this ); }559 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }560 virtual void print( std::ostream & os, int indent = 0 ) const;561 private:562 566 ApplicationExpr * callExpr; 563 567 std::list< ObjectDecl * > tempDecls; 564 568 std::list< ObjectDecl * > returnDecls; 565 569 std::list< Expression * > dtors; 570 571 ImplicitCopyCtorExpr( ApplicationExpr * callExpr ); 572 ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other ); 573 virtual ~ImplicitCopyCtorExpr(); 574 575 ApplicationExpr * get_callExpr() const { return callExpr; } 576 void set_callExpr( ApplicationExpr * newValue ) { callExpr = newValue; } 577 578 std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; } 579 std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; } 580 std::list< Expression * > & get_dtors() { return dtors; } 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; 566 586 }; 567 587 … … 569 589 class ConstructorExpr : public Expression { 570 590 public: 591 Expression * callExpr; 592 571 593 ConstructorExpr( Expression * callExpr ); 572 594 ConstructorExpr( const ConstructorExpr & other ); … … 580 602 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 581 603 virtual void print( std::ostream & os, int indent = 0 ) const; 582 private:583 Expression * callExpr;584 604 }; 585 605 … … 587 607 class CompoundLiteralExpr : public Expression { 588 608 public: 609 Initializer * initializer; 610 589 611 CompoundLiteralExpr( Type * type, Initializer * initializer ); 590 612 CompoundLiteralExpr( const CompoundLiteralExpr & other ); … … 598 620 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 599 621 virtual void print( std::ostream & os, int indent = 0 ) const; 600 private:601 Initializer * initializer;602 622 }; 603 623 … … 605 625 class RangeExpr : public Expression { 606 626 public: 627 Expression * low, * high; 628 607 629 RangeExpr( Expression * low, Expression * high ); 608 630 RangeExpr( const RangeExpr & other ); … … 617 639 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 618 640 virtual void print( std::ostream & os, int indent = 0 ) const; 619 private:620 Expression * low, * high;621 641 }; 622 642 … … 624 644 class UntypedTupleExpr : public Expression { 625 645 public: 646 std::list<Expression*> exprs; 647 626 648 UntypedTupleExpr( const std::list< Expression * > & exprs, Expression *_aname = nullptr ); 627 649 UntypedTupleExpr( const UntypedTupleExpr & other ); … … 634 656 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 635 657 virtual void print( std::ostream & os, int indent = 0 ) const; 636 private:637 std::list<Expression*> exprs;638 658 }; 639 659 … … 641 661 class TupleExpr : public Expression { 642 662 public: 663 std::list<Expression*> exprs; 664 643 665 TupleExpr( const std::list< Expression * > & exprs, Expression *_aname = nullptr ); 644 666 TupleExpr( const TupleExpr & other ); … … 651 673 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 652 674 virtual void print( std::ostream & os, int indent = 0 ) const; 653 private:654 std::list<Expression*> exprs;655 675 }; 656 676 … … 658 678 class TupleIndexExpr : public Expression { 659 679 public: 680 Expression * tuple; 681 unsigned int index; 682 660 683 TupleIndexExpr( Expression * tuple, unsigned int index ); 661 684 TupleIndexExpr( const TupleIndexExpr & other ); … … 671 694 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 672 695 virtual void print( std::ostream & os, int indent = 0 ) const; 673 private:674 Expression * tuple;675 unsigned int index;676 696 }; 677 697 … … 679 699 class TupleAssignExpr : public Expression { 680 700 public: 701 StmtExpr * stmtExpr = nullptr; 702 681 703 TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls, Expression * _aname = nullptr ); 682 704 TupleAssignExpr( const TupleAssignExpr & other ); … … 690 712 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 691 713 virtual void print( std::ostream & os, int indent = 0 ) const; 692 private:693 StmtExpr * stmtExpr = nullptr;694 714 }; 695 715 … … 697 717 class StmtExpr : public Expression { 698 718 public: 719 CompoundStmt * statements; 720 std::list< ObjectDecl * > returnDecls; // return variable(s) for stmt expression 721 std::list< Expression * > dtors; // destructor(s) for return variable(s) 722 699 723 StmtExpr( CompoundStmt * statements ); 700 724 StmtExpr( const StmtExpr & other ); … … 711 735 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 712 736 virtual void print( std::ostream & os, int indent = 0 ) const; 713 private:714 CompoundStmt * statements;715 std::list< ObjectDecl * > returnDecls; // return variable(s) for stmt expression716 std::list< Expression * > dtors; // destructor(s) for return variable(s)717 737 }; 718 738 719 739 class UniqueExpr : public Expression { 720 740 public: 741 Expression * expr; 742 ObjectDecl * object; 743 VariableExpr * var; 744 721 745 UniqueExpr( Expression * expr, long long idVal = -1 ); 722 746 UniqueExpr( const UniqueExpr & other ); … … 738 762 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 739 763 virtual void print( std::ostream & os, int indent = 0 ) const; 764 740 765 private: 741 Expression * expr;742 ObjectDecl * object;743 VariableExpr * var;744 766 int id; 745 767 static long long count; … … 758 780 class UntypedInitExpr : public Expression { 759 781 public: 782 Expression * expr; 783 std::list<InitAlternative> initAlts; 784 760 785 UntypedInitExpr( Expression * expr, const std::list<InitAlternative> & initAlts ); 761 786 UntypedInitExpr( const UntypedInitExpr & other ); … … 771 796 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 772 797 virtual void print( std::ostream & os, int indent = 0 ) const; 773 private:774 Expression * expr;775 std::list<InitAlternative> initAlts;776 798 }; 777 799 778 800 class InitExpr : public Expression { 779 801 public: 802 Expression * expr; 803 Designation * designation; 804 780 805 InitExpr( Expression * expr, Designation * designation ); 781 806 InitExpr( const InitExpr & other ); … … 792 817 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 793 818 virtual void print( std::ostream & os, int indent = 0 ) const; 794 private:795 Expression * expr;796 Designation * designation;797 819 }; 798 820 799 821 800 822 std::ostream & operator<<( std::ostream & out, const Expression * expr ); 801 802 #endif // EXPRESSION_H803 823 804 824 // Local Variables: //
Note: See TracChangeset
for help on using the changeset viewer.