source: src/SynTree/Initializer.cc @ bb1cd95

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since bb1cd95 was 579263a, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

Merge branch 'master' into designations

Conflicts:

src/InitTweak/FixInit.cc
src/SymTab/Autogen.h
src/SynTree/Initializer.cc
src/SynTree/Initializer.h
src/Tuples/TupleExpansion.cc

  • Property mode set to 100644
File size: 4.3 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
21Designation::Designation( const std::list< Expression * > & designators ) : designators( designators ) {}
22Designation::Designation( const Designation & other ) : BaseSyntaxNode( other ) {
23        // std::cerr << "cloning designation" << std::endl;
24        cloneAll( other.designators, designators );
25        // std::cerr << "finished cloning designation" << std::endl;
26}
27
28Designation::~Designation() {
29        // std::cerr << "destroying designation" << std::endl;
30        deleteAll( designators );
31        // std::cerr << "finished destroying designation" << std::endl;
32}
33
34void Designation::print( std::ostream &os, int indent ) const {
35        if ( ! designators.empty() ) {
36                os << std::string(indent + 2, ' ' ) << "designated by: " << std::endl;
37                for ( std::list < Expression * >::const_iterator i = designators.begin(); i != designators.end(); i++ ) {
38                        os << std::string(indent + 4, ' ' );
39                        ( *i )->print(os, indent + 4 );
40                }
41                os << std::endl;
42        } // if
43}
44
45Initializer::Initializer( bool maybeConstructed ) : maybeConstructed( maybeConstructed ) {}
46Initializer::Initializer( const Initializer & other ) : BaseSyntaxNode( other ), maybeConstructed( other.maybeConstructed ) {
47}
48Initializer::~Initializer() {}
49
50SingleInit::SingleInit( Expression *v, bool maybeConstructed ) : Initializer( maybeConstructed ), value ( v ) {
51}
52
53SingleInit::SingleInit( const SingleInit &other ) : Initializer(other), value ( maybeClone( other.value ) ) {
54}
55
56SingleInit::~SingleInit() {
57        delete value;
58}
59
60void SingleInit::print( std::ostream &os, int indent ) const {
61        os << std::string(indent, ' ' ) << "Simple Initializer: " << std::endl;
62        os << std::string(indent+4, ' ' );
63        value->print( os, indent+4 );
64}
65
66
67ListInit::ListInit( const std::list<Initializer*> &initializers, const std::list<Designation *> &designations, bool maybeConstructed )
68        : Initializer( maybeConstructed ), initializers( initializers ), designations( designations ) {
69}
70
71ListInit::ListInit( const ListInit & other ) : Initializer( other ) {
72        cloneAll( other.initializers, initializers );
73        cloneAll( other.designations, designations );
74}
75
76ListInit::~ListInit() {
77        deleteAll( initializers );
78        deleteAll( designations );
79}
80
81void ListInit::print( std::ostream &os, int indent ) const {
82        os << std::string(indent, ' ') << "Compound initializer:  " << std::endl;
83        for ( Designation * d : designations ) {
84                d->print( os, indent + 2 );
85        }
86
87        for ( const Initializer * init : initializers ) {
88                init->print( os, indent + 2 );
89                os << std::endl;
90        }
91}
92
93
94ConstructorInit::ConstructorInit( Statement * ctor, Statement * dtor, Initializer * init ) : Initializer( true ), ctor( ctor ), dtor( dtor ), init( init ) {}
95ConstructorInit::ConstructorInit( const ConstructorInit &other ) : Initializer( other ), ctor( maybeClone( other.ctor ) ), dtor( maybeClone( other.dtor ) ), init( maybeClone( other.init ) ) {
96}
97
98ConstructorInit::~ConstructorInit() {
99        delete ctor;
100        delete dtor;
101        delete init;
102}
103
104void ConstructorInit::print( std::ostream &os, int indent ) const {
105        os << std::endl << std::string(indent, ' ') << "Constructor initializer: " << std::endl;
106        if ( ctor ) {
107                os << std::string(indent+2, ' ');
108                os << "initially constructed with ";
109                ctor->print( os, indent+4 );
110        } // if
111
112        if ( dtor ) {
113                os << std::string(indent+2, ' ');
114                os << "destructed with ";
115                dtor->print( os, indent+4 );
116        }
117
118        if ( init ) {
119                os << std::string(indent+2, ' ');
120                os << "with fallback C-style initializer: ";
121                init->print( os, indent+4 );
122        }
123}
124
125std::ostream & operator<<( std::ostream & out, const Initializer * init ) {
126        if ( init ) {
127                init->print( out );
128        } else {
129                out << "nullptr";
130        }
131        return out;
132}
133
134std::ostream & operator<<( std::ostream & out, const Designation * des ) {
135        if ( des ) {
136                des->print( out );
137        } else {
138                out << "nullptr";
139        }
140        return out;
141}
142
143// Local Variables: //
144// tab-width: 4 //
145// mode: c++ //
146// compile-command: "make install" //
147// End: //
Note: See TracBrowser for help on using the repository browser.