[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
|
---|
[71f4e4f] | 12 | // Last Modified On : Wed Jan 13 15:31:45 2016
|
---|
| 13 | // Update Count : 28
|
---|
[0dd3a2f] | 14 | //
|
---|
| 15 |
|
---|
[51b73452] | 16 | #include "Initializer.h"
|
---|
| 17 | #include "Expression.h"
|
---|
| 18 | #include "utility.h"
|
---|
| 19 |
|
---|
[974906e2] | 20 | Initializer::Initializer( bool maybeConstructed ) : maybeConstructed( maybeConstructed ) {}
|
---|
[51b73452] | 21 |
|
---|
[d9a0e76] | 22 | Initializer::~Initializer() {}
|
---|
[51b73452] | 23 |
|
---|
| 24 | std::string Initializer::designator_name( Expression *des ) {
|
---|
[0dd3a2f] | 25 | if ( NameExpr *n = dynamic_cast<NameExpr *>(des) )
|
---|
| 26 | return n->get_name();
|
---|
| 27 | else
|
---|
| 28 | throw 0;
|
---|
[51b73452] | 29 | }
|
---|
| 30 |
|
---|
[d9a0e76] | 31 | void Initializer::print( std::ostream &os, int indent ) {}
|
---|
[51b73452] | 32 |
|
---|
[974906e2] | 33 | SingleInit::SingleInit( Expression *v, std::list< Expression *> &_designators, bool maybeConstructed ) : Initializer( maybeConstructed ), value ( v ), designators( _designators ) {
|
---|
[51b73452] | 34 | }
|
---|
| 35 |
|
---|
[974906e2] | 36 | SingleInit::SingleInit( const SingleInit &other ) : Initializer(other), value ( other.value ) {
|
---|
[0dd3a2f] | 37 | cloneAll(other.designators, designators );
|
---|
[51b73452] | 38 | }
|
---|
| 39 |
|
---|
[d9a0e76] | 40 | SingleInit::~SingleInit() {}
|
---|
[51b73452] | 41 |
|
---|
| 42 | SingleInit *SingleInit::clone() const { return new SingleInit( *this); }
|
---|
| 43 |
|
---|
[d9a0e76] | 44 | void SingleInit::print( std::ostream &os, int indent ) {
|
---|
[d58ebf3] | 45 | os << std::endl << std::string(indent, ' ' ) << "Simple Initializer: " << std::endl;
|
---|
| 46 | value->print( os, indent+4 );
|
---|
[0dd3a2f] | 47 |
|
---|
| 48 | if ( ! designators.empty() ) {
|
---|
[d58ebf3] | 49 | os << std::endl << std::string(indent + 2, ' ' ) << "designated by: " << std::endl;
|
---|
| 50 | for ( std::list < Expression * >::iterator i = designators.begin(); i != designators.end(); i++ ) {
|
---|
[0dd3a2f] | 51 | ( *i )->print(os, indent + 4 );
|
---|
[d58ebf3] | 52 | }
|
---|
[0dd3a2f] | 53 | } // if
|
---|
[51b73452] | 54 | }
|
---|
| 55 |
|
---|
[974906e2] | 56 | ListInit::ListInit( std::list<Initializer*> &_initializers, std::list<Expression *> &_designators, bool maybeConstructed )
|
---|
| 57 | : Initializer( maybeConstructed), initializers( _initializers ), designators( _designators ) {
|
---|
[51b73452] | 58 | }
|
---|
| 59 |
|
---|
[d9a0e76] | 60 | ListInit::~ListInit() {}
|
---|
[51b73452] | 61 |
|
---|
[d9a0e76] | 62 | ListInit *ListInit::clone() const {
|
---|
[0dd3a2f] | 63 | return new ListInit( *this );
|
---|
[51b73452] | 64 | }
|
---|
| 65 |
|
---|
[d9a0e76] | 66 | void ListInit::print( std::ostream &os, int indent ) {
|
---|
[974906e2] | 67 | os << std::endl << std::string(indent, ' ') << "Compound initializer: ";
|
---|
[0dd3a2f] | 68 | if ( ! designators.empty() ) {
|
---|
| 69 | os << std::string(indent + 2, ' ' ) << "designated by: [";
|
---|
| 70 | for ( std::list < Expression * >::iterator i = designators.begin();
|
---|
| 71 | i != designators.end(); i++ ) {
|
---|
[974906e2] | 72 | ( *i )->print(os, indent + 4 );
|
---|
[0dd3a2f] | 73 | } // for
|
---|
[974906e2] | 74 |
|
---|
[0dd3a2f] | 75 | os << std::string(indent + 2, ' ' ) << "]";
|
---|
| 76 | } // if
|
---|
[51b73452] | 77 |
|
---|
[974906e2] | 78 | for ( std::list<Initializer *>::iterator i = initializers.begin(); i != initializers.end(); i++ )
|
---|
[0dd3a2f] | 79 | (*i)->print( os, indent + 2 );
|
---|
[51b73452] | 80 | }
|
---|
[71f4e4f] | 81 |
|
---|
| 82 |
|
---|
| 83 | ConstructorInit::ConstructorInit( Expression * ctor, Initializer * init ) : Initializer( true ), ctor( ctor ), init( init ) {}
|
---|
| 84 | ConstructorInit::~ConstructorInit() {
|
---|
| 85 | delete ctor;
|
---|
| 86 | delete init;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | ConstructorInit *ConstructorInit::clone() const {
|
---|
| 90 | return new ConstructorInit( *this );
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | void ConstructorInit::print( std::ostream &os, int indent ) {
|
---|
| 94 | os << std::endl << std::string(indent, ' ') << "Constructor initializer: ";
|
---|
| 95 | if ( ctor ) {
|
---|
| 96 | os << " initially constructed with ";
|
---|
| 97 | ctor->print( os, indent+2 );
|
---|
| 98 | } // if
|
---|
| 99 |
|
---|
| 100 | if ( init ) {
|
---|
| 101 | os << " with fallback C-style initializer: ";
|
---|
| 102 | init->print( os, indent+2 );
|
---|
| 103 | }
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 |
|
---|
[0dd3a2f] | 107 | // Local Variables: //
|
---|
| 108 | // tab-width: 4 //
|
---|
| 109 | // mode: c++ //
|
---|
| 110 | // compile-command: "make install" //
|
---|
| 111 | // End: //
|
---|