1 | /* |
---|
2 | * This file is part of the Cforall project |
---|
3 | * |
---|
4 | * $Id: Initializer.cc,v 1.10 2005/08/29 20:59:25 rcbilson Exp $ |
---|
5 | * |
---|
6 | */ |
---|
7 | |
---|
8 | #include "Initializer.h" |
---|
9 | #include "Expression.h" |
---|
10 | #include "utility.h" |
---|
11 | |
---|
12 | |
---|
13 | Initializer::Initializer( ) |
---|
14 | { |
---|
15 | } |
---|
16 | |
---|
17 | Initializer::~Initializer( ) |
---|
18 | { |
---|
19 | } |
---|
20 | |
---|
21 | std::string Initializer::designator_name( Expression *des ) { |
---|
22 | if( NameExpr *n = dynamic_cast<NameExpr *>(des) ) |
---|
23 | return n->get_name(); |
---|
24 | else |
---|
25 | throw 0; |
---|
26 | } |
---|
27 | |
---|
28 | void |
---|
29 | Initializer::print( std::ostream &os, int indent ) |
---|
30 | { |
---|
31 | } |
---|
32 | |
---|
33 | SingleInit::SingleInit ( Expression *v, std::list< Expression *> &_designators ) |
---|
34 | : value ( v ), designators( _designators ) |
---|
35 | { |
---|
36 | } |
---|
37 | |
---|
38 | SingleInit::SingleInit ( const SingleInit &other ) |
---|
39 | : value ( other.value ) |
---|
40 | { |
---|
41 | cloneAll(other.designators, designators ); |
---|
42 | } |
---|
43 | |
---|
44 | SingleInit::~SingleInit() |
---|
45 | { |
---|
46 | } |
---|
47 | |
---|
48 | SingleInit *SingleInit::clone() const { return new SingleInit( *this); } |
---|
49 | |
---|
50 | void SingleInit::print( std::ostream &os, int indent ) |
---|
51 | { |
---|
52 | os << std::endl << std::string(indent, ' ' ) << "Simple Initializer: "; |
---|
53 | value->print( os, indent+2 ); |
---|
54 | |
---|
55 | if ( ! designators.empty() ) |
---|
56 | { |
---|
57 | os << std::endl << std::string(indent + 2, ' ' ) << "designated by: " ; |
---|
58 | for ( std::list < Expression * >::iterator i = designators.begin(); i != designators.end(); i++ ) |
---|
59 | ( *i )->print(os, indent + 4 ); |
---|
60 | } |
---|
61 | } |
---|
62 | |
---|
63 | MemberInit::MemberInit( Expression *_value, std::string _member ) |
---|
64 | : member ( _member ), value ( _value ) |
---|
65 | { |
---|
66 | } |
---|
67 | |
---|
68 | MemberInit::~MemberInit() |
---|
69 | { |
---|
70 | } |
---|
71 | |
---|
72 | MemberInit * MemberInit::clone() const |
---|
73 | { |
---|
74 | return new MemberInit( *this ); |
---|
75 | } |
---|
76 | |
---|
77 | void MemberInit::print( std::ostream &os, int indent ) |
---|
78 | { |
---|
79 | os << "Member Initializer"; |
---|
80 | value->print( os, indent+2 ); |
---|
81 | } |
---|
82 | |
---|
83 | ListInit::ListInit( std::list<Initializer*> &_initializers, std::list<Expression *> &_designators ) |
---|
84 | : initializers( _initializers ), designators( _designators ) |
---|
85 | { |
---|
86 | } |
---|
87 | |
---|
88 | ListInit::~ListInit() |
---|
89 | { |
---|
90 | } |
---|
91 | |
---|
92 | ListInit *ListInit::clone() const |
---|
93 | { |
---|
94 | return new ListInit( *this ); |
---|
95 | } |
---|
96 | |
---|
97 | void ListInit::print( std::ostream &os, int indent ) |
---|
98 | { |
---|
99 | os << std::endl << std::string(indent, ' ') << "Compound initializer: "; |
---|
100 | if( ! designators.empty() ) { |
---|
101 | os << std::string(indent + 2, ' ' ) << "designated by: ["; |
---|
102 | for ( std::list < Expression * >::iterator i = designators.begin(); |
---|
103 | i != designators.end(); i++ ) { |
---|
104 | ( *i )->print(os, indent + 4 ); |
---|
105 | } |
---|
106 | |
---|
107 | os << std::string(indent + 2, ' ' ) << "]"; |
---|
108 | } |
---|
109 | |
---|
110 | for( std::list<Initializer *>::iterator i = initializers.begin(); i != initializers.end(); i++ ) |
---|
111 | (*i)->print( os, indent + 2 ); |
---|
112 | } |
---|
113 | |
---|