source: translator/SynTree/Initializer.cc @ a0d9f94

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since a0d9f94 was 51b7345, checked in by Peter A. Buhr <pabuhr@…>, 10 years ago

initial commit

  • Property mode set to 100644
File size: 2.4 KB
Line 
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
13Initializer::Initializer( )
14{
15}
16
17Initializer::~Initializer( )
18{
19}
20
21std::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
28void 
29Initializer::print( std::ostream &os, int indent )
30{
31}
32
33SingleInit::SingleInit ( Expression *v, std::list< Expression *> &_designators )
34    : value ( v ), designators( _designators )
35{ 
36}
37
38SingleInit::SingleInit ( const SingleInit &other )
39    : value ( other.value )
40{
41    cloneAll(other.designators, designators );
42}
43
44SingleInit::~SingleInit()
45{
46}
47
48SingleInit *SingleInit::clone() const { return new SingleInit( *this); }
49
50void 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
63MemberInit::MemberInit( Expression *_value, std::string _member )
64    : member ( _member ), value ( _value )
65{
66}
67
68MemberInit::~MemberInit()
69{
70}
71
72MemberInit * MemberInit::clone() const
73{
74    return new MemberInit( *this );
75}
76
77void MemberInit::print( std::ostream &os, int indent )
78{
79    os << "Member Initializer";
80    value->print( os, indent+2 );
81}
82
83ListInit::ListInit( std::list<Initializer*> &_initializers, std::list<Expression *> &_designators )
84    : initializers( _initializers ), designators( _designators )
85{
86}
87
88ListInit::~ListInit()
89{
90}
91
92ListInit *ListInit::clone() const
93{
94    return new ListInit( *this );
95}
96
97void 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
Note: See TracBrowser for help on using the repository browser.