source: src/SynTree/Initializer.cc @ 83de11e

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 83de11e 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
Line 
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//
7// Initializer.cc --
8//
9// Author           : Richard C. Bilson
10// Created On       : Mon May 18 07:44:20 2015
11// Last Modified By : Rob Schluntz
12// Last Modified On : Fri May 13 13:23:03 2016
13// Update Count     : 28
14//
15
16#include "Initializer.h"
17#include "Expression.h"
18#include "Statement.h"
19#include "Common/utility.h"
20
21Initializer::Initializer( bool maybeConstructed ) : maybeConstructed( maybeConstructed ) {}
22
23Initializer::~Initializer() {}
24
25std::string Initializer::designator_name( Expression *des ) {
26        if ( NameExpr *n = dynamic_cast<NameExpr *>(des) )
27                return n->get_name();
28        else
29                throw 0;
30}
31
32void Initializer::print( std::ostream &os, int indent ) {}
33
34SingleInit::SingleInit( Expression *v, const std::list< Expression *> &_designators, bool maybeConstructed ) : Initializer( maybeConstructed ), value ( v ), designators( _designators ) {
35}
36
37SingleInit::SingleInit( const SingleInit &other ) : Initializer(other), value ( maybeClone( other.value ) ) {
38        cloneAll(other.designators, designators );
39}
40
41SingleInit::~SingleInit() {}
42
43SingleInit *SingleInit::clone() const { return new SingleInit( *this); }
44
45void SingleInit::print( std::ostream &os, int indent ) {
46        os << std::endl << std::string(indent, ' ' ) << "Simple Initializer: " << std::endl;
47        os << std::string(indent+4, ' ' );
48        value->print( os, indent+4 );
49
50        if ( ! designators.empty() ) {
51                os << std::endl << std::string(indent + 2, ' ' ) << "designated by: " << std::endl;
52                for ( std::list < Expression * >::iterator i = designators.begin(); i != designators.end(); i++ ) {
53                        os << std::string(indent + 4, ' ' );
54                        ( *i )->print(os, indent + 4 );
55                }
56        } // if
57}
58
59ListInit::ListInit( const std::list<Initializer*> &_initializers, const std::list<Expression *> &_designators, bool maybeConstructed )
60        : Initializer( maybeConstructed), initializers( _initializers ), designators( _designators ) {
61}
62
63ListInit::~ListInit() {}
64
65ListInit *ListInit::clone() const {
66        return new ListInit( *this );
67}
68
69void ListInit::print( std::ostream &os, int indent ) {
70        os << std::endl << std::string(indent, ' ') << "Compound initializer:  ";
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++ ) {
75                        ( *i )->print(os, indent + 4 );
76                } // for
77
78                os << std::string(indent + 2, ' ' ) << "]";
79        } // if
80
81        for ( std::list<Initializer *>::iterator i = initializers.begin(); i != initializers.end(); i++ )
82                (*i)->print( os, indent + 2 );
83}
84
85
86ConstructorInit::ConstructorInit( Statement * ctor, Statement * dtor, Initializer * init ) : Initializer( true ), ctor( ctor ), dtor( dtor ), init( init ) {}
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 ) {
97        os << std::endl << std::string(indent, ' ') << "Constructor initializer: " << std::endl;
98        if ( ctor ) {
99                os << std::string(indent+2, ' ');
100                os << "initially constructed with ";
101                ctor->print( os, indent+4 );
102        } // if
103
104        if ( dtor ) {
105                os << std::string(indent+2, ' ');
106                os << "destructed with ";
107                dtor->print( os, indent+4 );
108        }
109
110        if ( init ) {
111                os << std::string(indent+2, ' ');
112                os << "with fallback C-style initializer: ";
113                init->print( os, indent+4 );
114        }
115}
116
117std::ostream & operator<<( std::ostream & out, Initializer * init ) {
118        init->print( out );
119        return out;
120}
121
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.