source: src/SynTree/Initializer.cc @ be945ac

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since be945ac was f1b1e4c, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

can construct global const objects, except with intrinsic constructors

  • Property mode set to 100644
File size: 3.9 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// Initializer.cc --
8//
9// Author           : Richard C. Bilson
10// Created On       : Mon May 18 07:44:20 2015
11// Last Modified By : Rob Schluntz
12// Last Modified On : Fri May 13 13:23:03 2016
13// Update Count     : 28
14//
15
16#include "Initializer.h"
17#include "Expression.h"
18#include "Statement.h"
19#include "Common/utility.h"
20
21Initializer::Initializer( bool maybeConstructed ) : maybeConstructed( maybeConstructed ) {}
22Initializer::Initializer( const Initializer & other ) : maybeConstructed( other.maybeConstructed ) {
23}
24
25
26Initializer::~Initializer() {}
27
28std::string Initializer::designator_name( Expression *des ) {
29        if ( NameExpr *n = dynamic_cast<NameExpr *>(des) )
30                return n->get_name();
31        else
32                throw 0;
33}
34
35void Initializer::print( std::ostream &os, int indent ) {}
36
37SingleInit::SingleInit( Expression *v, const std::list< Expression *> &_designators, bool maybeConstructed ) : Initializer( maybeConstructed ), value ( v ), designators( _designators ) {
38}
39
40SingleInit::SingleInit( const SingleInit &other ) : Initializer(other), value ( maybeClone( other.value ) ) {
41        cloneAll(other.designators, designators );
42}
43
44SingleInit::~SingleInit() {
45        deleteAll(designators);
46}
47
48void SingleInit::print( std::ostream &os, int indent ) {
49        os << std::endl << std::string(indent, ' ' ) << "Simple Initializer: " << std::endl;
50        os << std::string(indent+4, ' ' );
51        value->print( os, indent+4 );
52
53        if ( ! designators.empty() ) {
54                os << std::endl << std::string(indent + 2, ' ' ) << "designated by: " << std::endl;
55                for ( std::list < Expression * >::iterator i = designators.begin(); i != designators.end(); i++ ) {
56                        os << std::string(indent + 4, ' ' );
57                        ( *i )->print(os, indent + 4 );
58                }
59        } // if
60}
61
62ListInit::ListInit( const std::list<Initializer*> &_initializers, const std::list<Expression *> &_designators, bool maybeConstructed )
63        : Initializer( maybeConstructed ), initializers( _initializers ), designators( _designators ) {
64}
65
66ListInit::~ListInit() {
67        deleteAll( initializers );
68        deleteAll( designators );
69}
70
71void ListInit::print( std::ostream &os, int indent ) {
72        os << std::endl << std::string(indent, ' ') << "Compound initializer:  ";
73        if ( ! designators.empty() ) {
74                os << std::string(indent + 2, ' ' ) << "designated by: [";
75                for ( std::list < Expression * >::iterator i = designators.begin();
76                          i != designators.end(); i++ ) {
77                        ( *i )->print(os, indent + 4 );
78                } // for
79
80                os << std::string(indent + 2, ' ' ) << "]";
81        } // if
82
83        for ( std::list<Initializer *>::iterator i = initializers.begin(); i != initializers.end(); i++ )
84                (*i)->print( os, indent + 2 );
85}
86
87
88ConstructorInit::ConstructorInit( Statement * ctor, Statement * dtor, Initializer * init ) : Initializer( true ), ctor( ctor ), dtor( dtor ), init( init ) {}
89ConstructorInit::ConstructorInit( const ConstructorInit &other ) : Initializer( other ), ctor( maybeClone( other.ctor ) ), dtor( maybeClone( other.dtor ) ), init( maybeClone( other.init ) ) {
90}
91
92ConstructorInit::~ConstructorInit() {
93        delete ctor;
94        delete dtor;
95        delete init;
96}
97
98void ConstructorInit::print( std::ostream &os, int indent ) {
99        os << std::endl << std::string(indent, ' ') << "Constructor initializer: " << std::endl;
100        if ( ctor ) {
101                os << std::string(indent+2, ' ');
102                os << "initially constructed with ";
103                ctor->print( os, indent+4 );
104        } // if
105
106        if ( dtor ) {
107                os << std::string(indent+2, ' ');
108                os << "destructed with ";
109                dtor->print( os, indent+4 );
110        }
111
112        if ( init ) {
113                os << std::string(indent+2, ' ');
114                os << "with fallback C-style initializer: ";
115                init->print( os, indent+4 );
116        }
117}
118
119std::ostream & operator<<( std::ostream & out, Initializer * init ) {
120        init->print( out );
121        return out;
122}
123
124// Local Variables: //
125// tab-width: 4 //
126// mode: c++ //
127// compile-command: "make install" //
128// End: //
Note: See TracBrowser for help on using the repository browser.