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 | Initializer::Initializer( bool maybeConstructed ) : maybeConstructed( maybeConstructed ) {} |
---|
46 | Initializer::Initializer( const Initializer & other ) : BaseSyntaxNode( other ), maybeConstructed( other.maybeConstructed ) { |
---|
47 | } |
---|
48 | Initializer::~Initializer() {} |
---|
49 | |
---|
50 | SingleInit::SingleInit( Expression *v, bool maybeConstructed ) : Initializer( maybeConstructed ), value ( v ) { |
---|
51 | } |
---|
52 | |
---|
53 | SingleInit::SingleInit( const SingleInit &other ) : Initializer(other), value ( maybeClone( other.value ) ) { |
---|
54 | } |
---|
55 | |
---|
56 | SingleInit::~SingleInit() { |
---|
57 | delete value; |
---|
58 | } |
---|
59 | |
---|
60 | void 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 | |
---|
67 | ListInit::ListInit( const std::list<Initializer*> &initializers, const std::list<Designation *> &designations, bool maybeConstructed ) |
---|
68 | : Initializer( maybeConstructed ), initializers( initializers ), designations( designations ) { |
---|
69 | } |
---|
70 | |
---|
71 | ListInit::ListInit( const ListInit & other ) : Initializer( other ) { |
---|
72 | cloneAll( other.initializers, initializers ); |
---|
73 | cloneAll( other.designations, designations ); |
---|
74 | } |
---|
75 | |
---|
76 | ListInit::~ListInit() { |
---|
77 | deleteAll( initializers ); |
---|
78 | deleteAll( designations ); |
---|
79 | } |
---|
80 | |
---|
81 | void 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 | |
---|
94 | ConstructorInit::ConstructorInit( Statement * ctor, Statement * dtor, Initializer * init ) : Initializer( true ), ctor( ctor ), dtor( dtor ), init( init ) {} |
---|
95 | ConstructorInit::ConstructorInit( const ConstructorInit &other ) : Initializer( other ), ctor( maybeClone( other.ctor ) ), dtor( maybeClone( other.dtor ) ), init( maybeClone( other.init ) ) { |
---|
96 | } |
---|
97 | |
---|
98 | ConstructorInit::~ConstructorInit() { |
---|
99 | delete ctor; |
---|
100 | delete dtor; |
---|
101 | delete init; |
---|
102 | } |
---|
103 | |
---|
104 | void 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 | |
---|
125 | std::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 | |
---|
134 | std::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: // |
---|