source: src/SynTree/Initializer.cc @ 89ce869

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 89ce869 was d668182, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

Merge branch 'fix-tree-printing' into ctor

Conflicts:

src/SynTree/Expression.cc
src/SynTree/Initializer.cc
src/SynTree/ObjectDecl.cc

  • Property mode set to 100644
File size: 3.7 KB
RevLine 
[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
[d668182]12// Last Modified On : Fri May 13 13:23:03 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]21Initializer::Initializer( bool maybeConstructed ) : maybeConstructed( maybeConstructed ) {}
[51b7345]22
[d9a0e76]23Initializer::~Initializer() {}
[51b7345]24
25std::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]32void Initializer::print( std::ostream &os, int indent ) {}
[51b7345]33
[620cb95]34SingleInit::SingleInit( Expression *v, const std::list< Expression *> &_designators, bool maybeConstructed ) : Initializer( maybeConstructed ), value ( v ), designators( _designators ) {
[51b7345]35}
36
[a5a71d0]37SingleInit::SingleInit( const SingleInit &other ) : Initializer(other), value ( maybeClone( other.value ) ) {
[0dd3a2f]38        cloneAll(other.designators, designators );
[51b7345]39}
40
[d9a0e76]41SingleInit::~SingleInit() {}
[51b7345]42
43SingleInit *SingleInit::clone() const { return new SingleInit( *this); }
44
[d9a0e76]45void SingleInit::print( std::ostream &os, int indent ) {
[d58ebf3]46        os << std::endl << std::string(indent, ' ' ) << "Simple Initializer: " << std::endl;
[60089f4]47        os << std::string(indent+4, ' ' );
[d58ebf3]48        value->print( os, indent+4 );
[0dd3a2f]49
50        if ( ! designators.empty() ) {
[bb8ea30]51                os << std::endl << std::string(indent + 2, ' ' ) << "designated by: " << std::endl;
[d58ebf3]52                for ( std::list < Expression * >::iterator i = designators.begin(); i != designators.end(); i++ ) {
[bb8ea30]53                        os << std::string(indent + 4, ' ' );
[0dd3a2f]54                        ( *i )->print(os, indent + 4 );
[d58ebf3]55                }
[0dd3a2f]56        } // if
[51b7345]57}
58
[5b40f30]59ListInit::ListInit( const std::list<Initializer*> &_initializers, const std::list<Expression *> &_designators, bool maybeConstructed )
[974906e2]60        : Initializer( maybeConstructed), initializers( _initializers ), designators( _designators ) {
[51b7345]61}
62
[d9a0e76]63ListInit::~ListInit() {}
[51b7345]64
[d9a0e76]65ListInit *ListInit::clone() const {
[0dd3a2f]66        return new ListInit( *this );
[51b7345]67}
68
[d9a0e76]69void ListInit::print( std::ostream &os, int indent ) {
[974906e2]70        os << std::endl << std::string(indent, ' ') << "Compound initializer:  ";
[0dd3a2f]71        if ( ! designators.empty() ) {
72                os << std::string(indent + 2, ' ' ) << "designated by: [";
73                for ( std::list < Expression * >::iterator i = designators.begin();
74                          i != designators.end(); i++ ) {
[974906e2]75                        ( *i )->print(os, indent + 4 );
[0dd3a2f]76                } // for
[974906e2]77
[0dd3a2f]78                os << std::string(indent + 2, ' ' ) << "]";
79        } // if
[51b7345]80
[974906e2]81        for ( std::list<Initializer *>::iterator i = initializers.begin(); i != initializers.end(); i++ )
[0dd3a2f]82                (*i)->print( os, indent + 2 );
[51b7345]83}
[71f4e4f]84
85
[5b2f5bb]86ConstructorInit::ConstructorInit( Statement * ctor, Statement * dtor, Initializer * init ) : Initializer( true ), ctor( ctor ), dtor( dtor ), init( init ) {}
[71f4e4f]87ConstructorInit::~ConstructorInit() {
88        delete ctor;
89        delete init;
90}
91
92ConstructorInit *ConstructorInit::clone() const {
93        return new ConstructorInit( *this );
94}
95
96void ConstructorInit::print( std::ostream &os, int indent ) {
[84bb4d9]97        os << std::endl << std::string(indent, ' ') << "Constructor initializer: " << std::endl;
[71f4e4f]98        if ( ctor ) {
[84bb4d9]99                os << std::string(indent+2, ' ');
100                os << "initially constructed with ";
101                ctor->print( os, indent+4 );
[71f4e4f]102        } // if
103
[5b2f5bb]104        if ( dtor ) {
[84bb4d9]105                os << std::string(indent+2, ' ');
106                os << "destructed with ";
107                dtor->print( os, indent+4 );
[5b2f5bb]108        }
109
[71f4e4f]110        if ( init ) {
[84bb4d9]111                os << std::string(indent+2, ' ');
112                os << "with fallback C-style initializer: ";
113                init->print( os, indent+4 );
[71f4e4f]114        }
115}
116
[7a69460]117std::ostream & operator<<( std::ostream & out, Initializer * init ) {
118        init->print( out );
119        return out;
120}
[71f4e4f]121
[0dd3a2f]122// Local Variables: //
123// tab-width: 4 //
124// mode: c++ //
125// compile-command: "make install" //
126// End: //
Note: See TracBrowser for help on using the repository browser.