Changes in src/SynTree/Initializer.cc [d3b7937:f1b1e4c]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/Initializer.cc
rd3b7937 rf1b1e4c 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Initializer.cc -- 7 // Initializer.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Aug 12 14:05:25 201513 // Update Count : 1412 // Last Modified On : Fri May 13 13:23:03 2016 13 // Update Count : 28 14 14 // 15 15 16 16 #include "Initializer.h" 17 17 #include "Expression.h" 18 #include "Statement.h" 18 19 #include "Common/utility.h" 19 20 20 Initializer::Initializer() {} 21 Initializer::Initializer( bool maybeConstructed ) : maybeConstructed( maybeConstructed ) {} 22 Initializer::Initializer( const Initializer & other ) : maybeConstructed( other.maybeConstructed ) { 23 } 24 21 25 22 26 Initializer::~Initializer() {} … … 31 35 void Initializer::print( std::ostream &os, int indent ) {} 32 36 33 SingleInit::SingleInit( Expression *v, std::list< Expression *> &_designators ) : value ( v ), designators( _designators ) {37 SingleInit::SingleInit( Expression *v, const std::list< Expression *> &_designators, bool maybeConstructed ) : Initializer( maybeConstructed ), value ( v ), designators( _designators ) { 34 38 } 35 39 36 SingleInit::SingleInit( const SingleInit &other ) : value ( other.value) {40 SingleInit::SingleInit( const SingleInit &other ) : Initializer(other), value ( maybeClone( other.value ) ) { 37 41 cloneAll(other.designators, designators ); 38 42 } 39 43 40 SingleInit::~SingleInit() { }41 42 SingleInit *SingleInit::clone() const { return new SingleInit( *this);}44 SingleInit::~SingleInit() { 45 deleteAll(designators); 46 } 43 47 44 48 void SingleInit::print( std::ostream &os, int indent ) { 45 49 os << std::endl << std::string(indent, ' ' ) << "Simple Initializer: " << std::endl; 50 os << std::string(indent+4, ' ' ); 46 51 value->print( os, indent+4 ); 47 52 48 53 if ( ! designators.empty() ) { 49 os << std::endl << std::string(indent + 2, ' ' ) << "designated by: " 54 os << std::endl << std::string(indent + 2, ' ' ) << "designated by: " << std::endl; 50 55 for ( std::list < Expression * >::iterator i = designators.begin(); i != designators.end(); i++ ) { 56 os << std::string(indent + 4, ' ' ); 51 57 ( *i )->print(os, indent + 4 ); 52 58 } … … 54 60 } 55 61 56 ListInit::ListInit( std::list<Initializer*> &_initializers, std::list<Expression *> &_designators)57 : initializers( _initializers ), designators( _designators ) {62 ListInit::ListInit( const std::list<Initializer*> &_initializers, const std::list<Expression *> &_designators, bool maybeConstructed ) 63 : Initializer( maybeConstructed ), initializers( _initializers ), designators( _designators ) { 58 64 } 59 65 60 ListInit::~ListInit() {} 61 62 ListInit *ListInit::clone() const { 63 return new ListInit( *this ); 66 ListInit::~ListInit() { 67 deleteAll( initializers ); 68 deleteAll( designators ); 64 69 } 65 70 66 71 void ListInit::print( std::ostream &os, int indent ) { 67 os << std::endl << std::string(indent, ' ') << "Compound initializer: "; 72 os << std::endl << std::string(indent, ' ') << "Compound initializer: "; 68 73 if ( ! designators.empty() ) { 69 74 os << std::string(indent + 2, ' ' ) << "designated by: ["; 70 75 for ( std::list < Expression * >::iterator i = designators.begin(); 71 76 i != designators.end(); i++ ) { 72 ( *i )->print(os, indent + 4 ); 77 ( *i )->print(os, indent + 4 ); 73 78 } // for 74 79 75 80 os << std::string(indent + 2, ' ' ) << "]"; 76 81 } // if 77 82 78 for ( std::list<Initializer *>::iterator i = initializers.begin(); i != initializers.end(); i++ ) 83 for ( std::list<Initializer *>::iterator i = initializers.begin(); i != initializers.end(); i++ ) 79 84 (*i)->print( os, indent + 2 ); 80 85 } 86 87 88 ConstructorInit::ConstructorInit( Statement * ctor, Statement * dtor, Initializer * init ) : Initializer( true ), ctor( ctor ), dtor( dtor ), init( init ) {} 89 ConstructorInit::ConstructorInit( const ConstructorInit &other ) : Initializer( other ), ctor( maybeClone( other.ctor ) ), dtor( maybeClone( other.dtor ) ), init( maybeClone( other.init ) ) { 90 } 91 92 ConstructorInit::~ConstructorInit() { 93 delete ctor; 94 delete dtor; 95 delete init; 96 } 97 98 void ConstructorInit::print( std::ostream &os, int indent ) { 99 os << std::endl << std::string(indent, ' ') << "Constructor initializer: " << std::endl; 100 if ( ctor ) { 101 os << std::string(indent+2, ' '); 102 os << "initially constructed with "; 103 ctor->print( os, indent+4 ); 104 } // if 105 106 if ( dtor ) { 107 os << std::string(indent+2, ' '); 108 os << "destructed with "; 109 dtor->print( os, indent+4 ); 110 } 111 112 if ( init ) { 113 os << std::string(indent+2, ' '); 114 os << "with fallback C-style initializer: "; 115 init->print( os, indent+4 ); 116 } 117 } 118 119 std::ostream & operator<<( std::ostream & out, Initializer * init ) { 120 init->print( out ); 121 return out; 122 } 123 81 124 // Local Variables: // 82 125 // tab-width: 4 //
Note:
See TracChangeset
for help on using the changeset viewer.