source: translator/SynTree/Initializer.cc @ 48e99f2

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 48e99f2 was bdd516a, checked in by Peter A. Buhr <pabuhr@…>, 10 years ago

fixed sizeof type variable, find lowest cost alternative for sizeof expression, removed unused classes, added compiler flag, remove temporary file for -CFA, formatting

  • Property mode set to 100644
File size: 1.9 KB
Line 
1#include "Initializer.h"
2#include "Expression.h"
3#include "utility.h"
4
5
6Initializer::Initializer() {}
7
8Initializer::~Initializer() {}
9
10std::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
17void Initializer::print( std::ostream &os, int indent ) {}
18
19SingleInit::SingleInit( Expression *v, std::list< Expression *> &_designators ) : value ( v ), designators( _designators ) { 
20}
21
22SingleInit::SingleInit( const SingleInit &other ) : value ( other.value ) {
23    cloneAll(other.designators, designators );
24}
25
26SingleInit::~SingleInit() {}
27
28SingleInit *SingleInit::clone() const { return new SingleInit( *this); }
29
30void 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
41ListInit::ListInit( std::list<Initializer*> &_initializers, std::list<Expression *> &_designators )
42    : initializers( _initializers ), designators( _designators ) {
43}
44
45ListInit::~ListInit() {}
46
47ListInit *ListInit::clone() const {
48    return new ListInit( *this );
49}
50
51void ListInit::print( std::ostream &os, int indent ) {
52    os << std::endl << std::string(indent, ' ') << "Compound initializer:  "; 
53    if ( ! designators.empty() ) {
54        os << std::string(indent + 2, ' ' ) << "designated by: [";
55        for ( std::list < Expression * >::iterator i = designators.begin();
56                    i != designators.end(); i++ ) {
57            ( *i )->print(os, indent + 4 ); 
58        }
59       
60        os << std::string(indent + 2, ' ' ) << "]";
61    }
62
63    for( std::list<Initializer *>::iterator i = initializers.begin(); i != initializers.end(); i++ ) 
64        (*i)->print( os, indent + 2 );
65}
Note: See TracBrowser for help on using the repository browser.