Changeset 3f7e12cb for src/SynTree/Expression.h
- Timestamp:
- Nov 8, 2017, 5:43:33 PM (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:
- 954908d
- Parents:
- 78315272 (diff), e35f30a (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
r78315272 r3f7e12cb 31 31 32 32 33 /// Expression is the root type for all expressions34 class Expression : public BaseSyntaxNode{35 public:36 Type * result;37 TypeSubstitution * env;38 Expression * argName; // if expression is used as an argument, it can be "designated" by this name39 bool extension = false;40 41 Expression( Expression * _aname = nullptr );42 Expression( const Expression & other );43 virtual ~Expression();44 45 Type *& get_result() { return result; }46 const Type * get_result() const { return result; }47 void set_result( Type * newValue ) { result = newValue; }48 bool has_result() const { return result != nullptr; }49 50 TypeSubstitution * get_env() const { return env; }51 void set_env( TypeSubstitution * newValue ) { env = newValue; }52 Expression * get_argName() const { return argName; }53 void set_argName( Expression * name ) { argName = name; }54 bool get_extension() const { return extension; }55 Expression * set_extension( bool exten ) { extension = exten; return this; }56 57 virtual Expression * clone() const = 0;58 virtual void accept( Visitor & v ) = 0;59 virtual Expression * acceptMutator( Mutator & m ) = 0;60 virtual void print( std::ostream & os, int indent = 0 ) const;61 };62 63 33 struct ParamEntry; 64 34 … … 77 47 Type * actualType; 78 48 Type * formalType; 79 Expression * expr;49 Expression * expr; 80 50 std::unique_ptr< InferredParams > inferParams; 51 }; 52 53 /// Expression is the root type for all expressions 54 class Expression : public BaseSyntaxNode { 55 public: 56 Type * result; 57 TypeSubstitution * env; 58 bool extension = false; 59 InferredParams inferParams; 60 61 Expression(); 62 Expression( const Expression & other ); 63 virtual ~Expression(); 64 65 Type *& get_result() { return result; } 66 const Type * get_result() const { return result; } 67 void set_result( Type * newValue ) { result = newValue; } 68 69 TypeSubstitution * get_env() const { return env; } 70 void set_env( TypeSubstitution * newValue ) { env = newValue; } 71 bool get_extension() const { return extension; } 72 Expression * set_extension( bool exten ) { extension = exten; return this; } 73 74 InferredParams & get_inferParams() { return inferParams; } 75 76 virtual Expression * clone() const override = 0; 77 virtual void accept( Visitor & v ) override = 0; 78 virtual Expression * acceptMutator( Mutator & m ) override = 0; 79 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 81 80 }; 82 81 … … 87 86 Expression * function; 88 87 std::list<Expression *> args; 89 InferredParams inferParams;90 88 91 89 ApplicationExpr( Expression * function, const std::list<Expression *> & args = std::list< Expression * >() ); … … 96 94 void set_function( Expression * newValue ) { function = newValue; } 97 95 std::list<Expression *>& get_args() { return args; } 98 InferredParams & get_inferParams() { return inferParams; }99 96 100 97 virtual ApplicationExpr * clone() const { return new ApplicationExpr( * this ); } 101 98 virtual void accept( Visitor & v ) { v.visit( this ); } 102 99 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 103 virtual void print( std::ostream & os, int indent = 0) const;100 virtual void print( std::ostream & os, Indenter indent = {} ) const; 104 101 }; 105 102 … … 112 109 std::list<Expression*> args; 113 110 114 UntypedExpr( Expression * function, const std::list<Expression *> & args = std::list< Expression * >() , Expression *_aname = nullptr);111 UntypedExpr( Expression * function, const std::list<Expression *> & args = std::list< Expression * >() ); 115 112 UntypedExpr( const UntypedExpr & other ); 116 113 virtual ~UntypedExpr(); … … 119 116 void set_function( Expression * newValue ) { function = newValue; } 120 117 121 void set_args( std::list<Expression *> & listArgs ) { args = listArgs; }122 118 std::list<Expression*>::iterator begin_args() { return args.begin(); } 123 119 std::list<Expression*>::iterator end_args() { return args.end(); } … … 130 126 virtual void accept( Visitor & v ) { v.visit( this ); } 131 127 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 132 virtual void print( std::ostream & os, int indent = 0 ) const; 133 virtual void printArgs(std::ostream & os, int indent = 0) const; 128 virtual void print( std::ostream & os, Indenter indent = {} ) const; 134 129 }; 135 130 … … 139 134 std::string name; 140 135 141 NameExpr( std::string name , Expression *_aname = nullptr);136 NameExpr( std::string name ); 142 137 NameExpr( const NameExpr & other ); 143 138 virtual ~NameExpr(); … … 149 144 virtual void accept( Visitor & v ) { v.visit( this ); } 150 145 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 151 virtual void print( std::ostream & os, int indent = 0) const;146 virtual void print( std::ostream & os, Indenter indent = {} ) const; 152 147 }; 153 148 … … 160 155 Expression * arg; 161 156 162 AddressExpr( Expression * arg , Expression *_aname = nullptr);157 AddressExpr( Expression * arg ); 163 158 AddressExpr( const AddressExpr & other ); 164 159 virtual ~AddressExpr(); … … 170 165 virtual void accept( Visitor & v ) { v.visit( this ); } 171 166 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 172 virtual void print( std::ostream & os, int indent = 0) const;167 virtual void print( std::ostream & os, Indenter indent = {} ) const; 173 168 }; 174 169 … … 186 181 virtual void accept( Visitor & v ) { v.visit( this ); } 187 182 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 188 virtual void print( std::ostream & os, int indent = 0) const;183 virtual void print( std::ostream & os, Indenter indent = {} ) const; 189 184 }; 190 185 … … 194 189 Expression * arg; 195 190 196 CastExpr( Expression * arg , Expression *_aname = nullptr);197 CastExpr( Expression * arg, Type * toType , Expression *_aname = nullptr);191 CastExpr( Expression * arg ); 192 CastExpr( Expression * arg, Type * toType ); 198 193 CastExpr( const CastExpr & other ); 199 194 virtual ~CastExpr(); … … 205 200 virtual void accept( Visitor & v ) { v.visit( this ); } 206 201 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 207 virtual void print( std::ostream & os, int indent = 0) const;202 virtual void print( std::ostream & os, Indenter indent = {} ) const; 208 203 }; 209 204 … … 223 218 virtual void accept( Visitor & v ) { v.visit( this ); } 224 219 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 225 virtual void print( std::ostream & os, int indent = 0) const;220 virtual void print( std::ostream & os, Indenter indent = {} ) const; 226 221 }; 227 222 … … 232 227 Expression * aggregate; 233 228 234 UntypedMemberExpr( Expression * member, Expression * aggregate , Expression *_aname = nullptr);229 UntypedMemberExpr( Expression * member, Expression * aggregate ); 235 230 UntypedMemberExpr( const UntypedMemberExpr & other ); 236 231 virtual ~UntypedMemberExpr(); … … 244 239 virtual void accept( Visitor & v ) { v.visit( this ); } 245 240 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 246 virtual void print( std::ostream & os, int indent = 0) const;241 virtual void print( std::ostream & os, Indenter indent = {} ) const; 247 242 }; 248 243 … … 254 249 Expression * aggregate; 255 250 256 MemberExpr( DeclarationWithType * member, Expression * aggregate , Expression *_aname = nullptr);251 MemberExpr( DeclarationWithType * member, Expression * aggregate ); 257 252 MemberExpr( const MemberExpr & other ); 258 253 virtual ~MemberExpr(); … … 266 261 virtual void accept( Visitor & v ) { v.visit( this ); } 267 262 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 268 virtual void print( std::ostream & os, int indent = 0) const;263 virtual void print( std::ostream & os, Indenter indent = {} ) const; 269 264 }; 270 265 … … 275 270 DeclarationWithType * var; 276 271 277 VariableExpr( DeclarationWithType * var , Expression *_aname = nullptr);272 VariableExpr( DeclarationWithType * var ); 278 273 VariableExpr( const VariableExpr & other ); 279 274 virtual ~VariableExpr(); … … 287 282 virtual void accept( Visitor & v ) { v.visit( this ); } 288 283 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 289 virtual void print( std::ostream & os, int indent = 0) const;284 virtual void print( std::ostream & os, Indenter indent = {} ) const; 290 285 }; 291 286 … … 295 290 Constant constant; 296 291 297 ConstantExpr( Constant constant , Expression *_aname = nullptr);292 ConstantExpr( Constant constant ); 298 293 ConstantExpr( const ConstantExpr & other ); 299 294 virtual ~ConstantExpr(); … … 305 300 virtual void accept( Visitor & v ) { v.visit( this ); } 306 301 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 307 virtual void print( std::ostream & os, int indent = 0) const;302 virtual void print( std::ostream & os, Indenter indent = {} ) const; 308 303 }; 309 304 … … 315 310 bool isType; 316 311 317 SizeofExpr( Expression * expr , Expression *_aname = nullptr);312 SizeofExpr( Expression * expr ); 318 313 SizeofExpr( const SizeofExpr & other ); 319 SizeofExpr( Type * type , Expression *_aname = nullptr);314 SizeofExpr( Type * type ); 320 315 virtual ~SizeofExpr(); 321 316 … … 330 325 virtual void accept( Visitor & v ) { v.visit( this ); } 331 326 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 332 virtual void print( std::ostream & os, int indent = 0) const;327 virtual void print( std::ostream & os, Indenter indent = {} ) const; 333 328 }; 334 329 … … 340 335 bool isType; 341 336 342 AlignofExpr( Expression * expr , Expression *_aname = nullptr);337 AlignofExpr( Expression * expr ); 343 338 AlignofExpr( const AlignofExpr & other ); 344 AlignofExpr( Type * type , Expression *_aname = nullptr);339 AlignofExpr( Type * type ); 345 340 virtual ~AlignofExpr(); 346 341 … … 355 350 virtual void accept( Visitor & v ) { v.visit( this ); } 356 351 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 357 virtual void print( std::ostream & os, int indent = 0) const;352 virtual void print( std::ostream & os, Indenter indent = {} ) const; 358 353 }; 359 354 … … 364 359 std::string member; 365 360 366 UntypedOffsetofExpr( Type * type, const std::string & member , Expression *_aname = nullptr);361 UntypedOffsetofExpr( Type * type, const std::string & member ); 367 362 UntypedOffsetofExpr( const UntypedOffsetofExpr & other ); 368 363 virtual ~UntypedOffsetofExpr(); … … 376 371 virtual void accept( Visitor & v ) { v.visit( this ); } 377 372 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 378 virtual void print( std::ostream & os, int indent = 0) const;373 virtual void print( std::ostream & os, Indenter indent = {} ) const; 379 374 }; 380 375 … … 385 380 DeclarationWithType * member; 386 381 387 OffsetofExpr( Type * type, DeclarationWithType * member , Expression *_aname = nullptr);382 OffsetofExpr( Type * type, DeclarationWithType * member ); 388 383 OffsetofExpr( const OffsetofExpr & other ); 389 384 virtual ~OffsetofExpr(); … … 397 392 virtual void accept( Visitor & v ) { v.visit( this ); } 398 393 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 399 virtual void print( std::ostream & os, int indent = 0) const;394 virtual void print( std::ostream & os, Indenter indent = {} ) const; 400 395 }; 401 396 … … 405 400 StructInstType * type; 406 401 407 OffsetPackExpr( StructInstType * type _, Expression * aname_ = 0);402 OffsetPackExpr( StructInstType * type ); 408 403 OffsetPackExpr( const OffsetPackExpr & other ); 409 404 virtual ~OffsetPackExpr(); … … 415 410 virtual void accept( Visitor & v ) { v.visit( this ); } 416 411 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 417 virtual void print( std::ostream & os, int indent = 0) const;412 virtual void print( std::ostream & os, Indenter indent = {} ) const; 418 413 }; 419 414 … … 426 421 bool isType; 427 422 428 AttrExpr(Expression * attr, Expression * expr , Expression *_aname = nullptr);423 AttrExpr(Expression * attr, Expression * expr ); 429 424 AttrExpr( const AttrExpr & other ); 430 AttrExpr( Expression * attr, Type * type , Expression *_aname = nullptr);425 AttrExpr( Expression * attr, Type * type ); 431 426 virtual ~AttrExpr(); 432 427 … … 443 438 virtual void accept( Visitor & v ) { v.visit( this ); } 444 439 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 445 virtual void print( std::ostream & os, int indent = 0) const;440 virtual void print( std::ostream & os, Indenter indent = {} ) const; 446 441 }; 447 442 … … 452 447 Expression * arg2; 453 448 454 LogicalExpr( Expression * arg1, Expression * arg2, bool andp = true , Expression *_aname = nullptr);449 LogicalExpr( Expression * arg1, Expression * arg2, bool andp = true ); 455 450 LogicalExpr( const LogicalExpr & other ); 456 451 virtual ~LogicalExpr(); … … 465 460 virtual void accept( Visitor & v ) { v.visit( this ); } 466 461 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 467 virtual void print( std::ostream & os, int indent = 0) const;462 virtual void print( std::ostream & os, Indenter indent = {} ) const; 468 463 469 464 private: … … 478 473 Expression * arg3; 479 474 480 ConditionalExpr( Expression * arg1, Expression * arg2, Expression * arg3 , Expression *_aname = nullptr);475 ConditionalExpr( Expression * arg1, Expression * arg2, Expression * arg3 ); 481 476 ConditionalExpr( const ConditionalExpr & other ); 482 477 virtual ~ConditionalExpr(); … … 492 487 virtual void accept( Visitor & v ) { v.visit( this ); } 493 488 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 494 virtual void print( std::ostream & os, int indent = 0) const;489 virtual void print( std::ostream & os, Indenter indent = {} ) const; 495 490 }; 496 491 … … 501 496 Expression * arg2; 502 497 503 CommaExpr( Expression * arg1, Expression * arg2 , Expression *_aname = nullptr);498 CommaExpr( Expression * arg1, Expression * arg2 ); 504 499 CommaExpr( const CommaExpr & other ); 505 500 virtual ~CommaExpr(); … … 513 508 virtual void accept( Visitor & v ) { v.visit( this ); } 514 509 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 515 virtual void print( std::ostream & os, int indent = 0) const;510 virtual void print( std::ostream & os, Indenter indent = {} ) const; 516 511 }; 517 512 … … 531 526 virtual void accept( Visitor & v ) { v.visit( this ); } 532 527 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 533 virtual void print( std::ostream & os, int indent = 0) const;528 virtual void print( std::ostream & os, Indenter indent = {} ) const; 534 529 }; 535 530 … … 557 552 virtual void accept( Visitor & v ) { v.visit( this ); } 558 553 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 559 virtual void print( std::ostream & os, int indent = 0) const;554 virtual void print( std::ostream & os, Indenter indent = {} ) const; 560 555 561 556 // https://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Machine-Constraints.html#Machine-Constraints … … 585 580 virtual void accept( Visitor & v ) { v.visit( this ); } 586 581 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 587 virtual void print( std::ostream & os, int indent = 0) const;582 virtual void print( std::ostream & os, Indenter indent = {} ) const; 588 583 }; 589 584 … … 603 598 virtual void accept( Visitor & v ) { v.visit( this ); } 604 599 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 605 virtual void print( std::ostream & os, int indent = 0) const;600 virtual void print( std::ostream & os, Indenter indent = {} ) const; 606 601 }; 607 602 … … 621 616 virtual void accept( Visitor & v ) { v.visit( this ); } 622 617 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 623 virtual void print( std::ostream & os, int indent = 0) const;618 virtual void print( std::ostream & os, Indenter indent = {} ) const; 624 619 }; 625 620 … … 640 635 virtual void accept( Visitor & v ) { v.visit( this ); } 641 636 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 642 virtual void print( std::ostream & os, int indent = 0) const;637 virtual void print( std::ostream & os, Indenter indent = {} ) const; 643 638 }; 644 639 … … 648 643 std::list<Expression*> exprs; 649 644 650 UntypedTupleExpr( const std::list< Expression * > & exprs , Expression *_aname = nullptr);645 UntypedTupleExpr( const std::list< Expression * > & exprs ); 651 646 UntypedTupleExpr( const UntypedTupleExpr & other ); 652 647 virtual ~UntypedTupleExpr(); … … 657 652 virtual void accept( Visitor & v ) { v.visit( this ); } 658 653 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 659 virtual void print( std::ostream & os, int indent = 0) const;654 virtual void print( std::ostream & os, Indenter indent = {} ) const; 660 655 }; 661 656 … … 665 660 std::list<Expression*> exprs; 666 661 667 TupleExpr( const std::list< Expression * > & exprs , Expression *_aname = nullptr);662 TupleExpr( const std::list< Expression * > & exprs ); 668 663 TupleExpr( const TupleExpr & other ); 669 664 virtual ~TupleExpr(); … … 674 669 virtual void accept( Visitor & v ) { v.visit( this ); } 675 670 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 676 virtual void print( std::ostream & os, int indent = 0) const;671 virtual void print( std::ostream & os, Indenter indent = {} ) const; 677 672 }; 678 673 … … 695 690 virtual void accept( Visitor & v ) { v.visit( this ); } 696 691 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 697 virtual void print( std::ostream & os, int indent = 0) const;692 virtual void print( std::ostream & os, Indenter indent = {} ) const; 698 693 }; 699 694 … … 703 698 StmtExpr * stmtExpr = nullptr; 704 699 705 TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls , Expression * _aname = nullptr);700 TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls ); 706 701 TupleAssignExpr( const TupleAssignExpr & other ); 707 702 virtual ~TupleAssignExpr(); … … 713 708 virtual void accept( Visitor & v ) { v.visit( this ); } 714 709 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 715 virtual void print( std::ostream & os, int indent = 0) const;710 virtual void print( std::ostream & os, Indenter indent = {} ) const; 716 711 }; 717 712 … … 736 731 virtual void accept( Visitor & v ) { v.visit( this ); } 737 732 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 738 virtual void print( std::ostream & os, int indent = 0) const;733 virtual void print( std::ostream & os, Indenter indent = {} ) const; 739 734 }; 740 735 … … 763 758 virtual void accept( Visitor & v ) { v.visit( this ); } 764 759 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 765 virtual void print( std::ostream & os, int indent = 0) const;760 virtual void print( std::ostream & os, Indenter indent = {} ) const; 766 761 767 762 private: … … 797 792 virtual void accept( Visitor & v ) { v.visit( this ); } 798 793 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 799 virtual void print( std::ostream & os, int indent = 0) const;794 virtual void print( std::ostream & os, Indenter indent = {} ) const; 800 795 }; 801 796 … … 818 813 virtual void accept( Visitor & v ) { v.visit( this ); } 819 814 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 820 virtual void print( std::ostream & os, int indent = 0 ) const; 821 }; 822 823 824 std::ostream & operator<<( std::ostream & out, const Expression * expr ); 815 virtual void print( std::ostream & os, Indenter indent = {} ) const; 816 }; 825 817 826 818 // Local Variables: //
Note:
See TracChangeset
for help on using the changeset viewer.