source: src/SynTree/Initializer.cc @ c2ce2350

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 c2ce2350 was 668edd6b, checked in by Rob Schluntz <rschlunt@…>, 9 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.5 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 : Tue Apr 26 12:57:34 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        value->print( os, indent+4 );
48
49        if ( ! designators.empty() ) {
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++ ) {
52                        ( *i )->print(os, indent + 4 );
53                }
54        } // if
55}
56
57ListInit::ListInit( const std::list<Initializer*> &_initializers, const std::list<Expression *> &_designators, bool maybeConstructed )
58        : Initializer( maybeConstructed), initializers( _initializers ), designators( _designators ) {
59}
60
61ListInit::~ListInit() {}
62
63ListInit *ListInit::clone() const {
64        return new ListInit( *this );
65}
66
67void ListInit::print( std::ostream &os, int indent ) {
68        os << std::endl << std::string(indent, ' ') << "Compound initializer:  ";
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++ ) {
73                        ( *i )->print(os, indent + 4 );
74                } // for
75
76                os << std::string(indent + 2, ' ' ) << "]";
77        } // if
78
79        for ( std::list<Initializer *>::iterator i = initializers.begin(); i != initializers.end(); i++ )
80                (*i)->print( os, indent + 2 );
81}
82
83
84ConstructorInit::ConstructorInit( Statement * ctor, Statement * dtor, Initializer * init ) : Initializer( true ), ctor( ctor ), dtor( dtor ), init( init ) {}
85ConstructorInit::~ConstructorInit() {
86        delete ctor;
87        delete init;
88}
89
90ConstructorInit *ConstructorInit::clone() const {
91        return new ConstructorInit( *this );
92}
93
94void 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
101        if ( dtor ) {
102                os << " destructed with ";
103                dtor->print( os, indent+2 );
104        }
105
106        if ( init ) {
107                os << " with fallback C-style initializer: ";
108                init->print( os, indent+2 );
109        }
110}
111
112std::ostream & operator<<( std::ostream & out, Initializer * init ) {
113        init->print( out );
114        return out;
115}
116
117// Local Variables: //
118// tab-width: 4 //
119// mode: c++ //
120// compile-command: "make install" //
121// End: //
Note: See TracBrowser for help on using the repository browser.