[0dd3a2f] | 1 | // |
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo |
---|
| 3 | // |
---|
| 4 | // The contents of this file are covered under the licence agreement in the |
---|
| 5 | // file "LICENCE" distributed with Cforall. |
---|
| 6 | // |
---|
[974906e2] | 7 | // Initializer.cc -- |
---|
[0dd3a2f] | 8 | // |
---|
| 9 | // Author : Richard C. Bilson |
---|
| 10 | // Created On : Mon May 18 07:44:20 2015 |
---|
[d58ebf3] | 11 | // Last Modified By : Rob Schluntz |
---|
[668edd6b] | 12 | // Last Modified On : Tue Apr 26 12:57:34 2016 |
---|
[71f4e4f] | 13 | // Update Count : 28 |
---|
[0dd3a2f] | 14 | // |
---|
| 15 | |
---|
[51b7345] | 16 | #include "Initializer.h" |
---|
| 17 | #include "Expression.h" |
---|
[5b2f5bb] | 18 | #include "Statement.h" |
---|
[d3b7937] | 19 | #include "Common/utility.h" |
---|
[51b7345] | 20 | |
---|
[974906e2] | 21 | Initializer::Initializer( bool maybeConstructed ) : maybeConstructed( maybeConstructed ) {} |
---|
[51b7345] | 22 | |
---|
[d9a0e76] | 23 | Initializer::~Initializer() {} |
---|
[51b7345] | 24 | |
---|
| 25 | std::string Initializer::designator_name( Expression *des ) { |
---|
[0dd3a2f] | 26 | if ( NameExpr *n = dynamic_cast<NameExpr *>(des) ) |
---|
| 27 | return n->get_name(); |
---|
| 28 | else |
---|
| 29 | throw 0; |
---|
[51b7345] | 30 | } |
---|
| 31 | |
---|
[d9a0e76] | 32 | void Initializer::print( std::ostream &os, int indent ) {} |
---|
[51b7345] | 33 | |
---|
[620cb95] | 34 | SingleInit::SingleInit( Expression *v, const std::list< Expression *> &_designators, bool maybeConstructed ) : Initializer( maybeConstructed ), value ( v ), designators( _designators ) { |
---|
[51b7345] | 35 | } |
---|
| 36 | |
---|
[a5a71d0] | 37 | SingleInit::SingleInit( const SingleInit &other ) : Initializer(other), value ( maybeClone( other.value ) ) { |
---|
[0dd3a2f] | 38 | cloneAll(other.designators, designators ); |
---|
[51b7345] | 39 | } |
---|
| 40 | |
---|
[d9a0e76] | 41 | SingleInit::~SingleInit() {} |
---|
[51b7345] | 42 | |
---|
| 43 | SingleInit *SingleInit::clone() const { return new SingleInit( *this); } |
---|
| 44 | |
---|
[d9a0e76] | 45 | void SingleInit::print( std::ostream &os, int indent ) { |
---|
[d58ebf3] | 46 | os << std::endl << std::string(indent, ' ' ) << "Simple Initializer: " << std::endl; |
---|
| 47 | value->print( os, indent+4 ); |
---|
[0dd3a2f] | 48 | |
---|
| 49 | if ( ! designators.empty() ) { |
---|
[d58ebf3] | 50 | os << std::endl << std::string(indent + 2, ' ' ) << "designated by: " << std::endl; |
---|
| 51 | for ( std::list < Expression * >::iterator i = designators.begin(); i != designators.end(); i++ ) { |
---|
[0dd3a2f] | 52 | ( *i )->print(os, indent + 4 ); |
---|
[d58ebf3] | 53 | } |
---|
[0dd3a2f] | 54 | } // if |
---|
[51b7345] | 55 | } |
---|
| 56 | |
---|
[5b40f30] | 57 | ListInit::ListInit( const std::list<Initializer*> &_initializers, const std::list<Expression *> &_designators, bool maybeConstructed ) |
---|
[974906e2] | 58 | : Initializer( maybeConstructed), initializers( _initializers ), designators( _designators ) { |
---|
[51b7345] | 59 | } |
---|
| 60 | |
---|
[d9a0e76] | 61 | ListInit::~ListInit() {} |
---|
[51b7345] | 62 | |
---|
[d9a0e76] | 63 | ListInit *ListInit::clone() const { |
---|
[0dd3a2f] | 64 | return new ListInit( *this ); |
---|
[51b7345] | 65 | } |
---|
| 66 | |
---|
[d9a0e76] | 67 | void ListInit::print( std::ostream &os, int indent ) { |
---|
[974906e2] | 68 | os << std::endl << std::string(indent, ' ') << "Compound initializer: "; |
---|
[0dd3a2f] | 69 | if ( ! designators.empty() ) { |
---|
| 70 | os << std::string(indent + 2, ' ' ) << "designated by: ["; |
---|
| 71 | for ( std::list < Expression * >::iterator i = designators.begin(); |
---|
| 72 | i != designators.end(); i++ ) { |
---|
[974906e2] | 73 | ( *i )->print(os, indent + 4 ); |
---|
[0dd3a2f] | 74 | } // for |
---|
[974906e2] | 75 | |
---|
[0dd3a2f] | 76 | os << std::string(indent + 2, ' ' ) << "]"; |
---|
| 77 | } // if |
---|
[51b7345] | 78 | |
---|
[974906e2] | 79 | for ( std::list<Initializer *>::iterator i = initializers.begin(); i != initializers.end(); i++ ) |
---|
[0dd3a2f] | 80 | (*i)->print( os, indent + 2 ); |
---|
[51b7345] | 81 | } |
---|
[71f4e4f] | 82 | |
---|
| 83 | |
---|
[5b2f5bb] | 84 | ConstructorInit::ConstructorInit( Statement * ctor, Statement * dtor, Initializer * init ) : Initializer( true ), ctor( ctor ), dtor( dtor ), init( init ) {} |
---|
[71f4e4f] | 85 | ConstructorInit::~ConstructorInit() { |
---|
| 86 | delete ctor; |
---|
| 87 | delete init; |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | ConstructorInit *ConstructorInit::clone() const { |
---|
| 91 | return new ConstructorInit( *this ); |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | void ConstructorInit::print( std::ostream &os, int indent ) { |
---|
| 95 | os << std::endl << std::string(indent, ' ') << "Constructor initializer: "; |
---|
| 96 | if ( ctor ) { |
---|
| 97 | os << " initially constructed with "; |
---|
| 98 | ctor->print( os, indent+2 ); |
---|
| 99 | } // if |
---|
| 100 | |
---|
[5b2f5bb] | 101 | if ( dtor ) { |
---|
| 102 | os << " destructed with "; |
---|
| 103 | dtor->print( os, indent+2 ); |
---|
| 104 | } |
---|
| 105 | |
---|
[71f4e4f] | 106 | if ( init ) { |
---|
| 107 | os << " with fallback C-style initializer: "; |
---|
| 108 | init->print( os, indent+2 ); |
---|
| 109 | } |
---|
| 110 | } |
---|
| 111 | |
---|
[7a69460] | 112 | std::ostream & operator<<( std::ostream & out, Initializer * init ) { |
---|
| 113 | init->print( out ); |
---|
| 114 | return out; |
---|
| 115 | } |
---|
[71f4e4f] | 116 | |
---|
[0dd3a2f] | 117 | // Local Variables: // |
---|
| 118 | // tab-width: 4 // |
---|
| 119 | // mode: c++ // |
---|
| 120 | // compile-command: "make install" // |
---|
| 121 | // End: // |
---|