Changeset b6fe7e6 for src/SynTree
- Timestamp:
- Sep 9, 2016, 1:58:07 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:
- 03e3117
- Parents:
- d1969a6
- Location:
- src/SynTree
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/Expression.cc
rd1969a6 rb6fe7e6 28 28 #include "TypeSubstitution.h" 29 29 #include "Common/utility.h" 30 #include "InitTweak/InitTweak.h" 30 31 31 32 … … 493 494 494 495 void ImplicitCopyCtorExpr::print( std::ostream &os, int indent ) const { 495 os << std::string( indent, ' ' ) <<"Implicit Copy Constructor Expression: " << std::endl;496 os << "Implicit Copy Constructor Expression: " << std::endl; 496 497 assert( callExpr ); 497 498 callExpr->print( os, indent + 2 ); … … 503 504 } 504 505 506 507 ConstructorExpr::ConstructorExpr( Expression * callExpr ) : callExpr( callExpr ) { 508 // allow resolver to type a constructor used as an expression as if it has the same type as its first argument 509 assert( callExpr ); 510 Expression * arg = InitTweak::getCallArg( callExpr, 0 ); 511 assert( arg ); 512 cloneAll( arg->get_results(), results ); 513 } 514 515 ConstructorExpr::ConstructorExpr( const ConstructorExpr & other ) : Expression( other ), callExpr( maybeClone( other.callExpr ) ) { 516 } 517 518 ConstructorExpr::~ConstructorExpr() { 519 delete callExpr; 520 } 521 522 void ConstructorExpr::print( std::ostream &os, int indent ) const { 523 os << "Constructor Expression: " << std::endl; 524 assert( callExpr ); 525 os << std::string( indent+2, ' ' ); 526 callExpr->print( os, indent + 2 ); 527 Expression::print( os, indent ); 528 } 529 530 531 CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : type( type ), initializer( initializer ) { 532 add_result( type->clone() ); 533 } 534 535 CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), type( maybeClone( other.type ) ), initializer( maybeClone( other.initializer ) ) {} 536 537 CompoundLiteralExpr::~CompoundLiteralExpr() { 538 delete initializer; 539 delete type; 540 } 541 542 void CompoundLiteralExpr::print( std::ostream &os, int indent ) const { 543 os << "Compound Literal Expression: " << std::endl; 544 if ( type ) type->print( os, indent + 2 ); 545 if ( initializer ) initializer->print( os, indent + 2 ); 546 } 547 505 548 UntypedValofExpr::UntypedValofExpr( const UntypedValofExpr & other ) : Expression( other ), body ( maybeClone( other.body ) ) {} 506 549 … … 511 554 if ( get_body() != 0 ) 512 555 get_body()->print( os, indent + 2 ); 513 }514 515 516 CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : type( type ), initializer( initializer ) {517 add_result( type->clone() );518 }519 520 CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), type( maybeClone( other.type ) ), initializer( maybeClone( other.initializer ) ) {}521 522 CompoundLiteralExpr::~CompoundLiteralExpr() {523 delete initializer;524 delete type;525 }526 527 void CompoundLiteralExpr::print( std::ostream &os, int indent ) const {528 os << "Compound Literal Expression: " << std::endl;529 if ( type ) type->print( os, indent + 2 );530 if ( initializer ) initializer->print( os, indent + 2 );531 556 } 532 557 -
src/SynTree/Expression.h
rd1969a6 rb6fe7e6 595 595 }; 596 596 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(); 603 604 Expression *get_callExpr() const { return callExpr; } 605 void set_callExpr( Expression *newValue ) { callExpr = newValue; } 606 607 virtual ConstructorExpr *clone() const { return new ConstructorExpr( *this ); } 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; 611 private: 612 Expression * callExpr; 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 597 637 /// ValofExpr represents a GCC 'lambda expression' 598 638 class UntypedValofExpr : public Expression { … … 613 653 }; 614 654 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 655 /// RangeExpr represents a range e.g. '3 ... 5' or '1~10' 637 656 class RangeExpr : public Expression { 638 657 public: -
src/SynTree/Mutator.cc
rd1969a6 rb6fe7e6 339 339 } 340 340 341 Expression *Mutator::mutate( UntypedValofExpr *valofExpr ) { 342 mutateAll( valofExpr->get_results(), *this ); 343 return valofExpr; 341 Expression* Mutator::mutate( ConstructorExpr *ctorExpr ) { 342 mutateAll( ctorExpr->get_results(), *this ); 343 ctorExpr->set_callExpr( maybeMutate( ctorExpr->get_callExpr(), *this ) ); 344 return ctorExpr; 344 345 } 345 346 … … 349 350 compLitExpr->set_initializer( maybeMutate( compLitExpr->get_initializer(), *this ) ); 350 351 return compLitExpr; 352 } 353 354 Expression *Mutator::mutate( UntypedValofExpr *valofExpr ) { 355 mutateAll( valofExpr->get_results(), *this ); 356 return valofExpr; 351 357 } 352 358 -
src/SynTree/Mutator.h
rd1969a6 rb6fe7e6 76 76 virtual Expression* mutate( AsmExpr *asmExpr ); 77 77 virtual Expression* mutate( ImplicitCopyCtorExpr *impCpCtorExpr ); 78 virtual Expression* mutate( ConstructorExpr *ctorExpr ); 79 virtual Expression* mutate( CompoundLiteralExpr *compLitExpr ); 78 80 virtual Expression* mutate( UntypedValofExpr *valofExpr ); 79 virtual Expression* mutate( CompoundLiteralExpr *compLitExpr );80 81 virtual Expression* mutate( RangeExpr *rangeExpr ); 81 82 -
src/SynTree/SynTree.h
rd1969a6 rb6fe7e6 81 81 class AsmExpr; 82 82 class ImplicitCopyCtorExpr; 83 class ConstructorExpr; 84 class CompoundLiteralExpr; 83 85 class UntypedValofExpr; 84 class CompoundLiteralExpr;85 86 class RangeExpr; 86 87 -
src/SynTree/Visitor.cc
rd1969a6 rb6fe7e6 287 287 } 288 288 289 void Visitor::visit( UntypedValofExpr *valofExpr ) {290 acceptAll( valofExpr->get_results(), *this );291 maybeAccept( valofExpr->get_body(), *this );289 void Visitor::visit( ConstructorExpr * ctorExpr ) { 290 acceptAll( ctorExpr->get_results(), *this ); 291 maybeAccept( ctorExpr->get_callExpr(), *this ); 292 292 } 293 293 … … 296 296 maybeAccept( compLitExpr->get_type(), *this ); 297 297 maybeAccept( compLitExpr->get_initializer(), *this ); 298 } 299 300 void Visitor::visit( UntypedValofExpr *valofExpr ) { 301 acceptAll( valofExpr->get_results(), *this ); 302 maybeAccept( valofExpr->get_body(), *this ); 298 303 } 299 304 -
src/SynTree/Visitor.h
rd1969a6 rb6fe7e6 76 76 virtual void visit( AsmExpr *asmExpr ); 77 77 virtual void visit( ImplicitCopyCtorExpr *impCpCtorExpr ); 78 virtual void visit( ConstructorExpr * ctorExpr ); 79 virtual void visit( CompoundLiteralExpr *compLitExpr ); 78 80 virtual void visit( UntypedValofExpr *valofExpr ); 79 virtual void visit( CompoundLiteralExpr *compLitExpr );80 81 virtual void visit( RangeExpr *rangeExpr ); 81 82
Note: See TracChangeset
for help on using the changeset viewer.