1 | #include "Initializer.h" |
---|
2 | #include "Expression.h" |
---|
3 | #include "utility.h" |
---|
4 | |
---|
5 | |
---|
6 | Initializer::Initializer() {} |
---|
7 | |
---|
8 | Initializer::~Initializer() {} |
---|
9 | |
---|
10 | std::string Initializer::designator_name( Expression *des ) { |
---|
11 | if ( NameExpr *n = dynamic_cast<NameExpr *>(des) ) |
---|
12 | return n->get_name(); |
---|
13 | else |
---|
14 | throw 0; |
---|
15 | } |
---|
16 | |
---|
17 | void Initializer::print( std::ostream &os, int indent ) {} |
---|
18 | |
---|
19 | SingleInit::SingleInit( Expression *v, std::list< Expression *> &_designators ) : value ( v ), designators( _designators ) { |
---|
20 | } |
---|
21 | |
---|
22 | SingleInit::SingleInit( const SingleInit &other ) : value ( other.value ) { |
---|
23 | cloneAll(other.designators, designators ); |
---|
24 | } |
---|
25 | |
---|
26 | SingleInit::~SingleInit() {} |
---|
27 | |
---|
28 | SingleInit *SingleInit::clone() const { return new SingleInit( *this); } |
---|
29 | |
---|
30 | void SingleInit::print( std::ostream &os, int indent ) { |
---|
31 | os << std::endl << std::string(indent, ' ' ) << "Simple Initializer: "; |
---|
32 | value->print( os, indent+2 ); |
---|
33 | |
---|
34 | if ( ! designators.empty() ) { |
---|
35 | os << std::endl << std::string(indent + 2, ' ' ) << "designated by: " ; |
---|
36 | for ( std::list < Expression * >::iterator i = designators.begin(); i != designators.end(); i++ ) |
---|
37 | ( *i )->print(os, indent + 4 ); |
---|
38 | } |
---|
39 | } |
---|
40 | |
---|
41 | MemberInit::MemberInit( Expression *_value, std::string _member ) : member ( _member ), value ( _value ) {} |
---|
42 | |
---|
43 | MemberInit::~MemberInit() {} |
---|
44 | |
---|
45 | MemberInit * MemberInit::clone() const { |
---|
46 | return new MemberInit( *this ); |
---|
47 | } |
---|
48 | |
---|
49 | void MemberInit::print( std::ostream &os, int indent ) { |
---|
50 | os << "Member Initializer"; |
---|
51 | value->print( os, indent+2 ); |
---|
52 | } |
---|
53 | |
---|
54 | ListInit::ListInit( std::list<Initializer*> &_initializers, std::list<Expression *> &_designators ) |
---|
55 | : initializers( _initializers ), designators( _designators ) { |
---|
56 | } |
---|
57 | |
---|
58 | ListInit::~ListInit() {} |
---|
59 | |
---|
60 | ListInit *ListInit::clone() const { |
---|
61 | return new ListInit( *this ); |
---|
62 | } |
---|
63 | |
---|
64 | void ListInit::print( std::ostream &os, int indent ) { |
---|
65 | os << std::endl << std::string(indent, ' ') << "Compound initializer: "; |
---|
66 | if ( ! designators.empty() ) { |
---|
67 | os << std::string(indent + 2, ' ' ) << "designated by: ["; |
---|
68 | for ( std::list < Expression * >::iterator i = designators.begin(); |
---|
69 | i != designators.end(); i++ ) { |
---|
70 | ( *i )->print(os, indent + 4 ); |
---|
71 | } |
---|
72 | |
---|
73 | os << std::string(indent + 2, ' ' ) << "]"; |
---|
74 | } |
---|
75 | |
---|
76 | for( std::list<Initializer *>::iterator i = initializers.begin(); i != initializers.end(); i++ ) |
---|
77 | (*i)->print( os, indent + 2 ); |
---|
78 | } |
---|