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