source: src/SynTree/Initializer.h @ 4d4882a

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

major reorganization of constructor generation from initializer list so that it now works with multi-dimensional arrays

  • Property mode set to 100644
File size: 5.1 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 : Rob Schluntz
12// Last Modified On : Tue Apr 12 13:49:13 2016
13// Update Count     : 19
14//
15
16#ifndef INITIALIZER_H
17#define INITIALIZER_H
18
19#include "SynTree.h"
20#include "Visitor.h"
21#include "Mutator.h"
22#include "Type.h"
23
24#include <cassert>
25
26// Initializer: base class for object initializers (provide default values)
27class Initializer {
28  public:
29        //      Initializer( std::string _name = std::string(""), int _pos = 0 );
30        Initializer( bool maybeConstructed );
31        Initializer( const Initializer & other );
32        virtual ~Initializer();
33
34        static std::string designator_name( Expression *designator );
35
36        //      void set_name( std::string newValue ) { name = newValue; }
37        //      std::string get_name() const { return name; }
38
39        //      void set_pos( int newValue ) { pos = newValue; }
40        //      int get_pos() const { return pos; }
41        virtual void set_designators( std::list<Expression *> & ) { assert(false); }
42        virtual std::list<Expression *> &get_designators() {
43                assert(false);
44                std::list<Expression *> *ret = 0; return *ret;  // never reached
45        }
46
47        bool get_maybeConstructed() { return maybeConstructed; }
48
49        virtual Initializer *clone() const = 0;
50        virtual void accept( Visitor &v ) = 0;
51        virtual Initializer *acceptMutator( Mutator &m ) = 0;
52        virtual void print( std::ostream &os, int indent = 0 );
53  private:
54        //      std::string name;
55        //      int pos;
56        bool maybeConstructed;
57};
58
59// SingleInit represents an initializer for a common object (e.g., int x = 4)
60class SingleInit : public Initializer {
61  public:
62        SingleInit( Expression *value, const std::list< Expression *> &designators = std::list< Expression * >(), bool maybeConstructed = false );
63        SingleInit( const SingleInit &other );
64        virtual ~SingleInit();
65
66        Expression *get_value() { return value; }
67        void set_value( Expression *newValue ) { value = newValue; }
68
69        void set_designators( std::list<Expression *> &newValue ) { designators = newValue; }
70        std::list<Expression *> &get_designators() { return designators; }
71
72        virtual SingleInit *clone() const { return new SingleInit( *this); }
73        virtual void accept( Visitor &v ) { v.visit( this ); }
74        virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); }
75        virtual void print( std::ostream &os, int indent = 0 );
76  private:
77        //Constant *value;
78        Expression *value;      // has to be a compile-time constant
79        std::list< Expression * > designators;
80};
81
82// ListInit represents an initializer that is composed recursively of a list of initializers; this is used to initialize
83// an array or aggregate
84class ListInit : public Initializer {
85  public:
86        ListInit( const std::list<Initializer*> &initializers,
87                          const std::list<Expression *> &designators = std::list< Expression * >(), bool maybeConstructed = false );
88        virtual ~ListInit();
89
90        void set_designators( std::list<Expression *> &newValue ) { designators = newValue; }
91        std::list<Expression *> &get_designators() { return designators; }
92        void set_initializers( std::list<Initializer*> &newValue ) { initializers = newValue; }
93        std::list<Initializer*> &get_initializers() { return initializers; }
94
95        typedef std::list<Initializer*>::iterator iterator;
96        iterator begin() { return initializers.begin(); }
97        iterator end() { return initializers.end(); }
98
99        virtual ListInit *clone() const { return new ListInit( *this ); }
100        virtual void accept( Visitor &v ) { v.visit( this ); }
101        virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); }
102        virtual void print( std::ostream &os, int indent = 0 );
103  private:
104        std::list<Initializer*> initializers;  // order *is* important
105        std::list<Expression *> designators;
106};
107
108// ConstructorInit represents an initializer that is either a constructor expression or
109// a C-style initializer.
110class ConstructorInit : public Initializer {
111  public:
112        ConstructorInit( Statement * ctor, Statement * dtor, Initializer * init );
113        ConstructorInit( const ConstructorInit &other );
114        virtual ~ConstructorInit();
115
116        void set_ctor( Statement * newValue ) { ctor = newValue; }
117        Statement * get_ctor() const { return ctor; }
118        void set_dtor( Statement * newValue ) { dtor = newValue; }
119        Statement * get_dtor() const { return dtor; }
120        void set_init( Initializer * newValue ) { init = newValue; }
121        Initializer * get_init() const { return init; }
122
123        ConstructorInit *clone() const { return new ConstructorInit( *this ); }
124        virtual void accept( Visitor &v ) { v.visit( this ); }
125        virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); }
126        virtual void print( std::ostream &os, int indent = 0 );
127
128  private:
129        Statement * ctor;
130        Statement * dtor;
131        // C-style initializer made up of SingleInit and ListInit nodes to use as a fallback
132        // if an appropriate constructor definition is not found by the resolver
133        Initializer * init;
134};
135
136std::ostream & operator<<( std::ostream & out, Initializer * init );
137
138#endif // INITIALIZER_H
139
140// Local Variables: //
141// tab-width: 4 //
142// mode: c++ //
143// compile-command: "make install" //
144// End: //
Note: See TracBrowser for help on using the repository browser.