source: translator/SynTree/Initializer.h @ 51b7345

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

initial commit

  • Property mode set to 100644
File size: 4.9 KB
Line 
1/*
2 * This file is part of the Cforall project
3 *
4 * $Id: Initializer.h,v 1.14 2005/08/29 20:59:25 rcbilson Exp $
5 *
6 */
7
8#ifndef INITIALIZER_H
9#define INITIALIZER_H
10
11#include "SynTree.h"
12#include "Visitor.h"
13#include "Mutator.h"
14
15#include <cassert>
16
17
18// Initializer: base class for object initializers (provide default values)
19class Initializer
20{
21public:
22    //  Initializer( std::string _name = std::string(""), int _pos = 0 );
23    Initializer( );
24    virtual ~Initializer();
25
26    static std::string designator_name( Expression *designator );
27
28    //  void set_name( std::string newValue ) { name = newValue; }
29    //  std::string get_name() const { return name; }
30
31    //  void set_pos( int newValue ) { pos = newValue; }
32    //  int get_pos() const { return pos; }
33    virtual void set_designators( std::list<Expression *> & ) { assert(false); }
34    virtual std::list<Expression *> &get_designators() {
35        assert(false);
36        std::list<Expression *> *ret = 0; return *ret;  // never reached
37    }
38
39    virtual Initializer *clone() const = 0;
40    virtual void accept( Visitor &v ) = 0;
41    virtual Initializer *acceptMutator( Mutator &m ) = 0;
42    virtual void print( std::ostream &os, int indent = 0 );
43   
44private:
45    //  std::string name;
46    //  int pos;
47};
48
49// SingleInit represents an initializer for a common object (e.g., int x = 4)
50class SingleInit : public Initializer
51{
52public:
53    SingleInit( Expression *value, std::list< Expression *> &designators );
54    SingleInit( const SingleInit &other );
55    virtual ~SingleInit();
56   
57    Expression *get_value() { return value; }
58    void set_value( Expression *newValue ) { value = newValue; }
59
60    void set_designators( std::list<Expression *> &newValue ) { designators = newValue; }
61    std::list<Expression *> &get_designators() { return designators; }
62
63    virtual SingleInit *clone() const;
64    virtual void accept( Visitor &v ) { v.visit( this ); }
65    virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); }
66    virtual void print( std::ostream &os, int indent = 0 );
67   
68private:
69    //Constant *value;
70    Expression *value;  // has to be a compile-time constant
71    std::list< Expression * > designators;
72};
73
74// MemberInit represents an initializer for a member of an aggregate object
75// (e.g., struct q { int a } x = { a: 4 } )
76class MemberInit : public Initializer
77{
78public:
79    MemberInit( Expression *value, std::string member = std::string("") );
80    virtual ~MemberInit();
81   
82    std::string get_member() { return member; }
83    void set_member( std::string newValue ) { member = newValue; }
84    Expression *get_value() { return value; }
85    void set_value( Expression *newValue ) { value = newValue; }
86
87    virtual MemberInit *clone() const;
88    virtual void accept( Visitor &v ) { v.visit( this ); }
89    virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); }
90    virtual void print( std::ostream &os, int indent = 0 );
91   
92private:
93    std::string member;
94    Expression *value;
95};
96
97// ElementInit represents an initializer of an element of an array
98// (e.g., [10] int x = { [7]: 4 }
99class ElementInit : public Initializer
100{
101public:
102    ElementInit( Expression *value );
103    virtual ~ElementInit();
104   
105    int get_index() { return index; }
106    void set_index( int newValue ) { index = newValue; }
107    Expression *get_value() { return value; }
108    void set_value( Expression *newValue ) { value = newValue; }
109
110    virtual ElementInit *clone() const;
111    virtual void accept( Visitor &v ) { v.visit( this ); }
112    virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); }
113    virtual void print( std::ostream &os, int indent = 0 );
114   
115private:
116    int index;
117    Expression *value;
118};
119
120// ListInit represents an initializer that is composed recursively of a list of initializers; this
121// is used to initialize an array or aggregate
122class ListInit : public Initializer
123{
124public:
125    ListInit( std::list<Initializer*> &, 
126            std::list<Expression *> &designators = *(new std::list<Expression *>()) );
127    virtual ~ListInit();
128
129    void set_designators( std::list<Expression *> &newValue ) { designators = newValue; }
130    std::list<Expression *> &get_designators() { return designators; }
131    void set_initializers( std::list<Initializer*> &newValue ) { initializers = newValue; }
132    std::list<Initializer*> &get_initializers() { return initializers; }
133
134    std::list<Initializer*>::iterator begin_initializers() { return initializers.begin(); }
135    std::list<Initializer*>::iterator end_initializers() { return initializers.end(); }
136
137    virtual ListInit *clone() const;
138    virtual void accept( Visitor &v ) { v.visit( this ); }
139    virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); }
140    virtual void print( std::ostream &os, int indent = 0 );
141   
142private:
143    std::list<Initializer*> initializers;  // order *is* important
144    std::list<Expression *> designators;
145};
146
147
148#endif /* #ifndef INITIALIZER_H */
149
150/*
151    Local Variables:
152    mode: c++
153    End:
154*/
Note: See TracBrowser for help on using the repository browser.