Changeset e4d829b for src/SynTree/Initializer.cc
- Timestamp:
- Jun 20, 2017, 1:19:53 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:
- 579263a
- Parents:
- c6d2e93
- git-author:
- Rob Schluntz <rschlunt@…> (06/20/17 13:16:13)
- git-committer:
- Rob Schluntz <rschlunt@…> (06/20/17 13:19:53)
- File:
-
- 1 edited
-
src/SynTree/Initializer.cc (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/Initializer.cc
rc6d2e93 re4d829b 19 19 #include "Common/utility.h" 20 20 21 Designation::Designation( const std::list< Expression * > & designators ) : designators( designators ) {} 22 Designation::Designation( const Designation & other ) : BaseSyntaxNode( other ) { 23 // std::cerr << "cloning designation" << std::endl; 24 cloneAll( other.designators, designators ); 25 // std::cerr << "finished cloning designation" << std::endl; 26 } 27 28 Designation::~Designation() { 29 // std::cerr << "destroying designation" << std::endl; 30 deleteAll( designators ); 31 // std::cerr << "finished destroying designation" << std::endl; 32 } 33 34 void Designation::print( std::ostream &os, int indent ) const { 35 if ( ! designators.empty() ) { 36 os << std::string(indent + 2, ' ' ) << "designated by: " << std::endl; 37 for ( std::list < Expression * >::const_iterator i = designators.begin(); i != designators.end(); i++ ) { 38 os << std::string(indent + 4, ' ' ); 39 ( *i )->print(os, indent + 4 ); 40 } 41 os << std::endl; 42 } // if 43 } 44 45 21 46 Initializer::Initializer( bool maybeConstructed ) : maybeConstructed( maybeConstructed ) {} 22 47 Initializer::Initializer( const Initializer & other ) : BaseSyntaxNode( other ), maybeConstructed( other.maybeConstructed ) { 23 48 } 24 25 26 49 Initializer::~Initializer() {} 27 50 28 std::string Initializer::designator_name( Expression *des ) { 29 if ( NameExpr *n = dynamic_cast<NameExpr *>(des) ) 30 return n->get_name(); 31 else 32 throw 0; 33 } 34 35 void Initializer::print( std::ostream &os, int indent ) {} 36 37 SingleInit::SingleInit( Expression *v, const std::list< Expression *> &_designators, bool maybeConstructed ) : Initializer( maybeConstructed ), value ( v ), designators( _designators ) { 51 SingleInit::SingleInit( Expression *v, bool maybeConstructed ) : Initializer( maybeConstructed ), value ( v ) { 38 52 } 39 53 40 54 SingleInit::SingleInit( const SingleInit &other ) : Initializer(other), value ( maybeClone( other.value ) ) { 41 cloneAll(other.designators, designators );42 55 } 43 56 44 57 SingleInit::~SingleInit() { 45 58 delete value; 46 deleteAll(designators);47 59 } 48 60 49 void SingleInit::print( std::ostream &os, int indent ) {50 os << std:: endl << std::string(indent, ' ' ) << "Simple Initializer: " << std::endl;61 void SingleInit::print( std::ostream &os, int indent ) const { 62 os << std::string(indent, ' ' ) << "Simple Initializer: " << std::endl; 51 63 os << std::string(indent+4, ' ' ); 52 64 value->print( os, indent+4 ); 53 54 if ( ! designators.empty() ) {55 os << std::endl << std::string(indent + 2, ' ' ) << "designated by: " << std::endl;56 for ( std::list < Expression * >::iterator i = designators.begin(); i != designators.end(); i++ ) {57 os << std::string(indent + 4, ' ' );58 ( *i )->print(os, indent + 4 );59 }60 } // if61 65 } 62 66 63 ListInit::ListInit( const std::list<Initializer*> &_initializers, const std::list<Expression *> &_designators, bool maybeConstructed ) 64 : Initializer( maybeConstructed ), initializers( _initializers ), designators( _designators ) { 67 68 ListInit::ListInit( const std::list<Initializer*> &initializers, const std::list<Designation *> &designations, bool maybeConstructed ) 69 : Initializer( maybeConstructed ), initializers( initializers ), designations( designations ) { 65 70 } 66 71 67 72 ListInit::ListInit( const ListInit & other ) : Initializer( other ) { 68 73 cloneAll( other.initializers, initializers ); 69 cloneAll( other.designat ors, designators );74 cloneAll( other.designations, designations ); 70 75 } 71 72 76 73 77 ListInit::~ListInit() { 74 78 deleteAll( initializers ); 75 deleteAll( designat ors );79 deleteAll( designations ); 76 80 } 77 81 78 void ListInit::print( std::ostream &os, int indent ) { 79 os << std::endl << std::string(indent, ' ') << "Compound initializer: "; 80 if ( ! designators.empty() ) { 81 os << std::string(indent + 2, ' ' ) << "designated by: ["; 82 for ( std::list < Expression * >::iterator i = designators.begin(); 83 i != designators.end(); i++ ) { 84 ( *i )->print(os, indent + 4 ); 85 } // for 82 void ListInit::print( std::ostream &os, int indent ) const { 83 os << std::string(indent, ' ') << "Compound initializer: " << std::endl; 84 for ( Designation * d : designations ) { 85 d->print( os, indent + 2 ); 86 } 86 87 87 os << std::string(indent + 2, ' ' ) << "]"; 88 } // if 89 90 for ( std::list<Initializer *>::iterator i = initializers.begin(); i != initializers.end(); i++ ) 91 (*i)->print( os, indent + 2 ); 88 for ( const Initializer * init : initializers ) { 89 init->print( os, indent + 2 ); 90 os << std::endl; 91 } 92 92 } 93 93 … … 103 103 } 104 104 105 void ConstructorInit::print( std::ostream &os, int indent ) {105 void ConstructorInit::print( std::ostream &os, int indent ) const { 106 106 os << std::endl << std::string(indent, ' ') << "Constructor initializer: " << std::endl; 107 107 if ( ctor ) { … … 124 124 } 125 125 126 std::ostream & operator<<( std::ostream & out, Initializer * init ) { 127 init->print( out ); 126 std::ostream & operator<<( std::ostream & out, const Initializer * init ) { 127 if ( init ) { 128 init->print( out ); 129 } else { 130 out << "nullptr"; 131 } 132 return out; 133 } 134 135 std::ostream & operator<<( std::ostream & out, const Designation * des ) { 136 if ( des ) { 137 des->print( out ); 138 } else { 139 out << "nullptr"; 140 } 128 141 return out; 129 142 }
Note:
See TracChangeset
for help on using the changeset viewer.