Changeset add7117 for src/SynTree
- Timestamp:
- Sep 10, 2016, 11:08:47 AM (9 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:
- 5af62f1
- Parents:
- f5e81d1 (diff), 03e3117 (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. - Location:
- src/SynTree
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/Expression.cc
rf5e81d1 radd7117 28 28 #include "TypeSubstitution.h" 29 29 #include "Common/utility.h" 30 #include "InitTweak/InitTweak.h" 30 31 31 32 … … 496 497 497 498 void ImplicitCopyCtorExpr::print( std::ostream &os, int indent ) const { 498 os << std::string( indent, ' ' ) <<"Implicit Copy Constructor Expression: " << std::endl;499 os << "Implicit Copy Constructor Expression: " << std::endl; 499 500 assert( callExpr ); 500 501 callExpr->print( os, indent + 2 ); … … 506 507 } 507 508 509 510 ConstructorExpr::ConstructorExpr( Expression * callExpr ) : callExpr( callExpr ) { 511 // allow resolver to type a constructor used as an expression as if it has the same type as its first argument 512 assert( callExpr ); 513 Expression * arg = InitTweak::getCallArg( callExpr, 0 ); 514 assert( arg ); 515 cloneAll( arg->get_results(), results ); 516 } 517 518 ConstructorExpr::ConstructorExpr( const ConstructorExpr & other ) : Expression( other ), callExpr( maybeClone( other.callExpr ) ) { 519 } 520 521 ConstructorExpr::~ConstructorExpr() { 522 delete callExpr; 523 } 524 525 void ConstructorExpr::print( std::ostream &os, int indent ) const { 526 os << "Constructor Expression: " << std::endl; 527 assert( callExpr ); 528 os << std::string( indent+2, ' ' ); 529 callExpr->print( os, indent + 2 ); 530 Expression::print( os, indent ); 531 } 532 533 534 CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : type( type ), initializer( initializer ) { 535 add_result( type->clone() ); 536 } 537 538 CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), type( maybeClone( other.type ) ), initializer( maybeClone( other.initializer ) ) {} 539 540 CompoundLiteralExpr::~CompoundLiteralExpr() { 541 delete initializer; 542 delete type; 543 } 544 545 void CompoundLiteralExpr::print( std::ostream &os, int indent ) const { 546 os << "Compound Literal Expression: " << std::endl; 547 if ( type ) type->print( os, indent + 2 ); 548 if ( initializer ) initializer->print( os, indent + 2 ); 549 } 550 508 551 UntypedValofExpr::UntypedValofExpr( const UntypedValofExpr & other ) : Expression( other ), body ( maybeClone( other.body ) ) {} 509 552 … … 514 557 if ( get_body() != 0 ) 515 558 get_body()->print( os, indent + 2 ); 516 }517 518 519 CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : type( type ), initializer( initializer ) {520 add_result( type->clone() );521 }522 523 CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), type( maybeClone( other.type ) ), initializer( maybeClone( other.initializer ) ) {}524 525 CompoundLiteralExpr::~CompoundLiteralExpr() {526 delete initializer;527 delete type;528 }529 530 void CompoundLiteralExpr::print( std::ostream &os, int indent ) const {531 os << "Compound Literal Expression: " << std::endl;532 if ( type ) type->print( os, indent + 2 );533 if ( initializer ) initializer->print( os, indent + 2 );534 559 } 535 560 -
src/SynTree/Expression.h
rf5e81d1 radd7117 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 virtual ~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 virtual ~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
rf5e81d1 radd7117 340 340 } 341 341 342 Expression *Mutator::mutate( UntypedValofExpr *valofExpr ) { 343 mutateAll( valofExpr->get_results(), *this ); 344 return valofExpr; 342 Expression* Mutator::mutate( ConstructorExpr *ctorExpr ) { 343 mutateAll( ctorExpr->get_results(), *this ); 344 ctorExpr->set_callExpr( maybeMutate( ctorExpr->get_callExpr(), *this ) ); 345 return ctorExpr; 345 346 } 346 347 … … 350 351 compLitExpr->set_initializer( maybeMutate( compLitExpr->get_initializer(), *this ) ); 351 352 return compLitExpr; 353 } 354 355 Expression *Mutator::mutate( UntypedValofExpr *valofExpr ) { 356 mutateAll( valofExpr->get_results(), *this ); 357 return valofExpr; 352 358 } 353 359 -
src/SynTree/Mutator.h
rf5e81d1 radd7117 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 virtual Expression* mutate( TupleIndexExpr *tupleExpr ); -
src/SynTree/SynTree.h
rf5e81d1 radd7117 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 class TupleIndexExpr; -
src/SynTree/Visitor.cc
rf5e81d1 radd7117 288 288 } 289 289 290 void Visitor::visit( UntypedValofExpr *valofExpr ) {291 acceptAll( valofExpr->get_results(), *this );292 maybeAccept( valofExpr->get_body(), *this );290 void Visitor::visit( ConstructorExpr * ctorExpr ) { 291 acceptAll( ctorExpr->get_results(), *this ); 292 maybeAccept( ctorExpr->get_callExpr(), *this ); 293 293 } 294 294 … … 297 297 maybeAccept( compLitExpr->get_type(), *this ); 298 298 maybeAccept( compLitExpr->get_initializer(), *this ); 299 } 300 301 void Visitor::visit( UntypedValofExpr *valofExpr ) { 302 acceptAll( valofExpr->get_results(), *this ); 303 maybeAccept( valofExpr->get_body(), *this ); 299 304 } 300 305 -
src/SynTree/Visitor.h
rf5e81d1 radd7117 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 virtual void visit( TupleIndexExpr *tupleExpr );
Note:
See TracChangeset
for help on using the changeset viewer.