Changeset 9c23f31 for src/SynTree
- Timestamp:
- Sep 24, 2016, 12:19:33 PM (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:
- 3b5e3aa
- Parents:
- 2298f728 (diff), 7ae930a (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:
-
- 1 added
- 11 edited
-
Expression.cc (modified) (4 diffs)
-
Expression.h (modified) (2 diffs)
-
Mutator.cc (modified) (3 diffs)
-
Mutator.h (modified) (2 diffs)
-
SynTree.h (modified) (2 diffs)
-
Type.h (modified) (1 diff)
-
TypeSubstitution.cc (modified) (2 diffs)
-
TypeSubstitution.h (modified) (1 diff)
-
Visitor.cc (modified) (3 diffs)
-
Visitor.h (modified) (2 diffs)
-
ZeroOneType.cc (added)
-
module.mk (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/Expression.cc
r2298f728 r9c23f31 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
r2298f728 r9c23f31 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
r2298f728 r9c23f31 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 … … 447 453 } 448 454 455 Type *Mutator::mutate( ZeroType *zeroType ) { 456 mutateAll( zeroType->get_forall(), *this ); 457 return zeroType; 458 } 459 460 Type *Mutator::mutate( OneType *oneType ) { 461 mutateAll( oneType->get_forall(), *this ); 462 return oneType; 463 } 464 449 465 Initializer *Mutator::mutate( SingleInit *singleInit ) { 450 466 singleInit->set_value( singleInit->get_value()->acceptMutator( *this ) ); -
src/SynTree/Mutator.h
r2298f728 r9c23f31 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 … … 94 95 virtual Type* mutate( AttrType *attrType ); 95 96 virtual Type* mutate( VarArgsType *varArgsType ); 97 virtual Type* mutate( ZeroType *zeroType ); 98 virtual Type* mutate( OneType *oneType ); 96 99 97 100 virtual Initializer* mutate( SingleInit *singleInit ); -
src/SynTree/SynTree.h
r2298f728 r9c23f31 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 … … 101 102 class AttrType; 102 103 class VarArgsType; 104 class ZeroType; 105 class OneType; 103 106 104 107 class Initializer; -
src/SynTree/Type.h
r2298f728 r9c23f31 418 418 }; 419 419 420 /// Represents a zero constant 421 class ZeroType : public Type { 422 public: 423 ZeroType(); 424 ZeroType( Type::Qualifiers tq ); 425 426 virtual ZeroType *clone() const { return new ZeroType( *this ); } 427 virtual void accept( Visitor &v ) { v.visit( this ); } 428 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 429 virtual void print( std::ostream &os, int indent = 0 ) const; 430 }; 431 432 /// Represents a one constant 433 class OneType : public Type { 434 public: 435 OneType(); 436 OneType( Type::Qualifiers tq ); 437 438 virtual OneType *clone() const { return new OneType( *this ); } 439 virtual void accept( Visitor &v ) { v.visit( this ); } 440 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 441 virtual void print( std::ostream &os, int indent = 0 ) const; 442 }; 443 420 444 inline Type::Qualifiers &Type::Qualifiers::operator+=( const Type::Qualifiers &other ) { 421 445 isConst |= other.isConst; -
src/SynTree/TypeSubstitution.cc
r2298f728 r9c23f31 179 179 } 180 180 181 Type * TypeSubstitution::mutate( VoidType * basicType ) {182 return handleType( basicType );181 Type * TypeSubstitution::mutate( VoidType *voidType ) { 182 return handleType( voidType ); 183 183 } 184 184 … … 221 221 Type * TypeSubstitution::mutate( VarArgsType *varArgsType ) { 222 222 return handleType( varArgsType ); 223 } 224 225 Type * TypeSubstitution::mutate( ZeroType *zeroType ) { 226 return handleType( zeroType ); 227 } 228 229 Type * TypeSubstitution::mutate( OneType *oneType ) { 230 return handleType( oneType ); 223 231 } 224 232 -
src/SynTree/TypeSubstitution.h
r2298f728 r9c23f31 76 76 virtual Type* mutate(TupleType *tupleType); 77 77 virtual Type* mutate(VarArgsType *varArgsType); 78 virtual Type* mutate(ZeroType *zeroType); 79 virtual Type* mutate(OneType *oneType); 78 80 79 81 // TODO: worry about traversing into a forall-qualified function type or type decl with assertions -
src/SynTree/Visitor.cc
r2298f728 r9c23f31 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 … … 378 383 } 379 384 385 void Visitor::visit( ZeroType *zeroType ) { 386 acceptAll( zeroType->get_forall(), *this ); 387 } 388 389 void Visitor::visit( OneType *oneType ) { 390 acceptAll( oneType->get_forall(), *this ); 391 } 392 380 393 void Visitor::visit( SingleInit *singleInit ) { 381 394 singleInit->get_value()->accept( *this ); -
src/SynTree/Visitor.h
r2298f728 r9c23f31 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 … … 94 95 virtual void visit( AttrType *attrType ); 95 96 virtual void visit( VarArgsType *varArgsType ); 97 virtual void visit( ZeroType *zeroType ); 98 virtual void visit( OneType *oneType ); 96 99 97 100 virtual void visit( SingleInit *singleInit ); -
src/SynTree/module.mk
r2298f728 r9c23f31 26 26 SynTree/AttrType.cc \ 27 27 SynTree/VarArgsType.cc \ 28 SynTree/ZeroOneType.cc \ 28 29 SynTree/Constant.cc \ 29 30 SynTree/Expression.cc \
Note:
See TracChangeset
for help on using the changeset viewer.