source: src/SynTree/Initializer.h @ bfbf97f

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 bfbf97f was 843054c2, checked in by Peter A. Buhr <pabuhr@…>, 9 years ago

licencing: seventh groups of files

  • Property mode set to 100644
File size: 3.6 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.h --
8//
9// Author           : Richard C. Bilson
10// Created On       : Mon May 18 07:44:20 2015
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Mon May 18 09:03:48 2015
13// Update Count     : 1
14//
15
16#ifndef INITIALIZER_H
17#define INITIALIZER_H
18
19#include "SynTree.h"
20#include "Visitor.h"
21#include "Mutator.h"
22
23#include <cassert>
24
25// Initializer: base class for object initializers (provide default values)
26class Initializer {
27  public:
28        //      Initializer( std::string _name = std::string(""), int _pos = 0 );
29        Initializer( );
30        virtual ~Initializer();
31
32        static std::string designator_name( Expression *designator );
33
34        //      void set_name( std::string newValue ) { name = newValue; }
35        //      std::string get_name() const { return name; }
36
37        //      void set_pos( int newValue ) { pos = newValue; }
38        //      int get_pos() const { return pos; }
39        virtual void set_designators( std::list<Expression *> & ) { assert(false); }
40        virtual std::list<Expression *> &get_designators() {
41                assert(false);
42                std::list<Expression *> *ret = 0; return *ret;  // never reached
43        }
44
45        virtual Initializer *clone() const = 0;
46        virtual void accept( Visitor &v ) = 0;
47        virtual Initializer *acceptMutator( Mutator &m ) = 0;
48        virtual void print( std::ostream &os, int indent = 0 );
49  private:
50        //      std::string name;
51        //      int pos;
52};
53
54// SingleInit represents an initializer for a common object (e.g., int x = 4)
55class SingleInit : public Initializer {
56  public:
57        SingleInit( Expression *value, std::list< Expression *> &designators );
58        SingleInit( const SingleInit &other );
59        virtual ~SingleInit();
60       
61        Expression *get_value() { return value; }
62        void set_value( Expression *newValue ) { value = newValue; }
63
64        void set_designators( std::list<Expression *> &newValue ) { designators = newValue; }
65        std::list<Expression *> &get_designators() { return designators; }
66
67        virtual SingleInit *clone() const;
68        virtual void accept( Visitor &v ) { v.visit( this ); }
69        virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); }
70        virtual void print( std::ostream &os, int indent = 0 );
71  private:
72        //Constant *value;
73        Expression *value;      // has to be a compile-time constant
74        std::list< Expression * > designators;
75};
76
77// ListInit represents an initializer that is composed recursively of a list of initializers; this is used to initialize
78// an array or aggregate
79class ListInit : public Initializer {
80  public:
81        ListInit( std::list<Initializer*> &, 
82                          std::list<Expression *> &designators = *(new std::list<Expression *>()) );
83        virtual ~ListInit();
84
85        void set_designators( std::list<Expression *> &newValue ) { designators = newValue; }
86        std::list<Expression *> &get_designators() { return designators; }
87        void set_initializers( std::list<Initializer*> &newValue ) { initializers = newValue; }
88        std::list<Initializer*> &get_initializers() { return initializers; }
89
90        std::list<Initializer*>::iterator begin_initializers() { return initializers.begin(); }
91        std::list<Initializer*>::iterator end_initializers() { return initializers.end(); }
92
93        virtual ListInit *clone() const;
94        virtual void accept( Visitor &v ) { v.visit( this ); }
95        virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); }
96        virtual void print( std::ostream &os, int indent = 0 );
97  private:
98        std::list<Initializer*> initializers;  // order *is* important
99        std::list<Expression *> designators;
100};
101
102#endif // INITIALIZER_H
103
104// Local Variables: //
105// tab-width: 4 //
106// mode: c++ //
107// compile-command: "make install" //
108// End: //
Note: See TracBrowser for help on using the repository browser.