source: translator/SynTree/Initializer.cc @ 9df2dd5

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 9df2dd5 was d9a0e76, checked in by Peter A. Buhr <pabuhr@…>, 10 years ago

remove Parser.old, add -XCFA to driver, copy ptrdiff_t from stddef.h in preclude, remove casts from initialization constants, adjust formatting

  • Property mode set to 100644
File size: 2.3 KB
RevLine 
[51b7345]1#include "Initializer.h"
2#include "Expression.h"
3#include "utility.h"
4
5
[d9a0e76]6Initializer::Initializer() {}
[51b7345]7
[d9a0e76]8Initializer::~Initializer() {}
[51b7345]9
10std::string Initializer::designator_name( Expression *des ) {
[d9a0e76]11    if ( NameExpr *n = dynamic_cast<NameExpr *>(des) )
[51b7345]12        return n->get_name();
13    else
14        throw 0;
15}
16
[d9a0e76]17void Initializer::print( std::ostream &os, int indent ) {}
[51b7345]18
[d9a0e76]19SingleInit::SingleInit( Expression *v, std::list< Expression *> &_designators ) : value ( v ), designators( _designators ) { 
[51b7345]20}
21
[d9a0e76]22SingleInit::SingleInit( const SingleInit &other ) : value ( other.value ) {
[51b7345]23    cloneAll(other.designators, designators );
24}
25
[d9a0e76]26SingleInit::~SingleInit() {}
[51b7345]27
28SingleInit *SingleInit::clone() const { return new SingleInit( *this); }
29
[d9a0e76]30void SingleInit::print( std::ostream &os, int indent ) {
[51b7345]31    os << std::endl << std::string(indent, ' ' ) << "Simple Initializer: ";
32    value->print( os, indent+2 );
33
[d9a0e76]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    }
[51b7345]39}
40
[d9a0e76]41MemberInit::MemberInit( Expression *_value, std::string _member ) : member ( _member ), value ( _value ) {}
[51b7345]42
[d9a0e76]43MemberInit::~MemberInit() {}
[51b7345]44
[d9a0e76]45MemberInit * MemberInit::clone() const {
[51b7345]46    return new MemberInit( *this );
47}
48
[d9a0e76]49void MemberInit::print( std::ostream &os, int indent ) {
[51b7345]50    os << "Member Initializer";
51    value->print( os, indent+2 );
52}
53
54ListInit::ListInit( std::list<Initializer*> &_initializers, std::list<Expression *> &_designators )
[d9a0e76]55    : initializers( _initializers ), designators( _designators ) {
[51b7345]56}
57
[d9a0e76]58ListInit::~ListInit() {}
[51b7345]59
[d9a0e76]60ListInit *ListInit::clone() const {
[51b7345]61    return new ListInit( *this );
62}
63
[d9a0e76]64void ListInit::print( std::ostream &os, int indent ) {
[51b7345]65    os << std::endl << std::string(indent, ' ') << "Compound initializer:  "; 
[d9a0e76]66    if ( ! designators.empty() ) {
[51b7345]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}
Note: See TracBrowser for help on using the repository browser.