source: src/SynTree/Initializer.cc @ d7903b1

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 d7903b1 was d7903b1, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

Merge branch 'fix-tree-printing' into ctor

Conflicts:

src/SynTree/CommaExpr.cc
src/SynTree/CompoundStmt.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 : Tue Apr 26 15:51:35 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                        ( *i )->print(os, indent + 4 );
54                }
55        } // if
56}
57
58ListInit::ListInit( const std::list<Initializer*> &_initializers, const std::list<Expression *> &_designators, bool maybeConstructed )
59        : Initializer( maybeConstructed), initializers( _initializers ), designators( _designators ) {
60}
61
62ListInit::~ListInit() {}
63
64ListInit *ListInit::clone() const {
65        return new ListInit( *this );
66}
67
68void ListInit::print( std::ostream &os, int indent ) {
69        os << std::endl << std::string(indent, ' ') << "Compound initializer:  ";
70        if ( ! designators.empty() ) {
71                os << std::string(indent + 2, ' ' ) << "designated by: [";
72                for ( std::list < Expression * >::iterator i = designators.begin();
73                          i != designators.end(); i++ ) {
74                        ( *i )->print(os, indent + 4 );
75                } // for
76
77                os << std::string(indent + 2, ' ' ) << "]";
78        } // if
79
80        for ( std::list<Initializer *>::iterator i = initializers.begin(); i != initializers.end(); i++ )
81                (*i)->print( os, indent + 2 );
82}
83
84
85ConstructorInit::ConstructorInit( Statement * ctor, Statement * dtor, Initializer * init ) : Initializer( true ), ctor( ctor ), dtor( dtor ), init( init ) {}
86ConstructorInit::~ConstructorInit() {
87        delete ctor;
88        delete init;
89}
90
91ConstructorInit *ConstructorInit::clone() const {
92        return new ConstructorInit( *this );
93}
94
95void ConstructorInit::print( std::ostream &os, int indent ) {
96        os << std::endl << std::string(indent, ' ') << "Constructor initializer: " << std::endl;
97        if ( ctor ) {
98                os << std::string(indent+2, ' ');
99                os << "initially constructed with ";
100                ctor->print( os, indent+4 );
101        } // if
102
103        if ( dtor ) {
104                os << std::string(indent+2, ' ');
105                os << "destructed with ";
106                dtor->print( os, indent+4 );
107        }
108
109        if ( init ) {
110                os << std::string(indent+2, ' ');
111                os << "with fallback C-style initializer: ";
112                init->print( os, indent+4 );
113        }
114}
115
116std::ostream & operator<<( std::ostream & out, Initializer * init ) {
117        init->print( out );
118        return out;
119}
120
121// Local Variables: //
122// tab-width: 4 //
123// mode: c++ //
124// compile-command: "make install" //
125// End: //
Note: See TracBrowser for help on using the repository browser.