Changes in src/SynTree/Initializer.cc [62423350:d7dc824]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/Initializer.cc
r62423350 rd7dc824 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 } // if43 }44 45 21 Initializer::Initializer( bool maybeConstructed ) : maybeConstructed( maybeConstructed ) {} 46 22 Initializer::Initializer( const Initializer & other ) : BaseSyntaxNode( other ), maybeConstructed( other.maybeConstructed ) { 47 23 } 24 25 48 26 Initializer::~Initializer() {} 49 27 50 SingleInit::SingleInit( Expression *v, bool maybeConstructed ) : Initializer( maybeConstructed ), value ( v ) { 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( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent ) {} 36 37 SingleInit::SingleInit( Expression *v, const std::list< Expression *> &_designators, bool maybeConstructed ) : Initializer( maybeConstructed ), value ( v ), designators( _designators ) { 51 38 } 52 39 53 40 SingleInit::SingleInit( const SingleInit &other ) : Initializer(other), value ( maybeClone( other.value ) ) { 41 cloneAll(other.designators, designators ); 54 42 } 55 43 56 44 SingleInit::~SingleInit() { 57 45 delete value; 46 deleteAll(designators); 58 47 } 59 48 60 void SingleInit::print( std::ostream &os, int indent ) const{61 os << std:: string(indent, ' ' ) << "Simple Initializer: " << std::endl;49 void SingleInit::print( std::ostream &os, int indent ) { 50 os << std::endl << std::string(indent, ' ' ) << "Simple Initializer: " << std::endl; 62 51 os << std::string(indent+4, ' ' ); 63 52 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 } // if 64 61 } 65 62 66 67 ListInit::ListInit( const std::list<Initializer*> &inits, const std::list<Designation *> &des, bool maybeConstructed ) 68 : Initializer( maybeConstructed ), initializers( inits ), designations( des ) { 69 // handle the common case where a ListInit is created without designations by making a list of empty designations with the same length as the initializer 70 if ( designations.empty() ) { 71 for ( auto & i : initializers ) { 72 (void)i; 73 designations.push_back( new Designation( {} ) ); 74 } 75 } 76 assertf( initializers.size() == designations.size(), "Created ListInit with mismatching initializers (%d) and designations (%d)", initializers.size(), designations.size() ); 63 ListInit::ListInit( const std::list<Initializer*> &_initializers, const std::list<Expression *> &_designators, bool maybeConstructed ) 64 : Initializer( maybeConstructed ), initializers( _initializers ), designators( _designators ) { 77 65 } 78 66 79 67 ListInit::ListInit( const ListInit & other ) : Initializer( other ) { 80 68 cloneAll( other.initializers, initializers ); 81 cloneAll( other.designat ions, designations );69 cloneAll( other.designators, designators ); 82 70 } 71 83 72 84 73 ListInit::~ListInit() { 85 74 deleteAll( initializers ); 86 deleteAll( designat ions );75 deleteAll( designators ); 87 76 } 88 77 89 void ListInit::print( std::ostream &os, int indent ) const { 90 os << std::string(indent, ' ') << "Compound initializer: " << std::endl; 91 for ( Designation * d : designations ) { 92 d->print( os, indent + 2 ); 93 } 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 94 86 95 for ( const Initializer * init : initializers ) { 96 init->print( os, indent + 2 ); 97 os << std::endl; 98 } 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 ); 99 92 } 100 93 … … 110 103 } 111 104 112 void ConstructorInit::print( std::ostream &os, int indent ) const{105 void ConstructorInit::print( std::ostream &os, int indent ) { 113 106 os << std::endl << std::string(indent, ' ') << "Constructor initializer: " << std::endl; 114 107 if ( ctor ) { … … 131 124 } 132 125 133 std::ostream & operator<<( std::ostream & out, const Initializer * init ) { 134 if ( init ) { 135 init->print( out ); 136 } else { 137 out << "nullptr"; 138 } 139 return out; 140 } 141 142 std::ostream & operator<<( std::ostream & out, const Designation * des ) { 143 if ( des ) { 144 des->print( out ); 145 } else { 146 out << "nullptr"; 147 } 126 std::ostream & operator<<( std::ostream & out, Initializer * init ) { 127 init->print( out ); 148 128 return out; 149 129 }
Note:
See TracChangeset
for help on using the changeset viewer.