source: src/SynTree/Initializer.h @ 45576af9

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 45576af9 was db4ecc5, checked in by Rob Schluntz <rschlunt@…>, 9 years ago

add ImplicitCopyCtorExpr? node, implicit copy constructors are inserted into the right places (but there is room for elision)

  • Property mode set to 100644
File size: 4.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.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
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( bool maybeConstructed );
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        bool get_maybeConstructed() { return maybeConstructed; }
46
47        virtual Initializer *clone() const = 0;
48        virtual void accept( Visitor &v ) = 0;
49        virtual Initializer *acceptMutator( Mutator &m ) = 0;
50        virtual void print( std::ostream &os, int indent = 0 );
51  private:
52        //      std::string name;
53        //      int pos;
54        bool maybeConstructed;
55};
56
57// SingleInit represents an initializer for a common object (e.g., int x = 4)
58class SingleInit : public Initializer {
59  public:
60        SingleInit( Expression *value, const std::list< Expression *> &designators = std::list< Expression * >(), bool maybeConstructed = false );
61        SingleInit( const SingleInit &other );
62        virtual ~SingleInit();
63
64        Expression *get_value() { return value; }
65        void set_value( Expression *newValue ) { value = newValue; }
66
67        void set_designators( std::list<Expression *> &newValue ) { designators = newValue; }
68        std::list<Expression *> &get_designators() { return designators; }
69
70        virtual SingleInit *clone() const;
71        virtual void accept( Visitor &v ) { v.visit( this ); }
72        virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); }
73        virtual void print( std::ostream &os, int indent = 0 );
74  private:
75        //Constant *value;
76        Expression *value;      // has to be a compile-time constant
77        std::list< Expression * > designators;
78};
79
80// ListInit represents an initializer that is composed recursively of a list of initializers; this is used to initialize
81// an array or aggregate
82class ListInit : public Initializer {
83  public:
84        ListInit( const std::list<Initializer*> &initializers,
85                          const std::list<Expression *> &designators = std::list< Expression * >(), bool maybeConstructed = false );
86        virtual ~ListInit();
87
88        void set_designators( std::list<Expression *> &newValue ) { designators = newValue; }
89        std::list<Expression *> &get_designators() { return designators; }
90        void set_initializers( std::list<Initializer*> &newValue ) { initializers = newValue; }
91        std::list<Initializer*> &get_initializers() { return initializers; }
92
93        std::list<Initializer*>::iterator begin_initializers() { return initializers.begin(); }
94        std::list<Initializer*>::iterator end_initializers() { return initializers.end(); }
95
96        virtual ListInit *clone() const;
97        virtual void accept( Visitor &v ) { v.visit( this ); }
98        virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); }
99        virtual void print( std::ostream &os, int indent = 0 );
100  private:
101        std::list<Initializer*> initializers;  // order *is* important
102        std::list<Expression *> designators;
103};
104
105// ConstructorInit represents an initializer that is either a constructor expression or
106// a C-style initializer.
107class ConstructorInit : public Initializer {
108  public:
109        ConstructorInit( Statement * ctor, Statement * dtor, Initializer * init );
110        virtual ~ConstructorInit();
111
112        void set_ctor( Statement * newValue ) { ctor = newValue; }
113        Statement * get_ctor() const { return ctor; }
114        void set_dtor( Statement * newValue ) { dtor = newValue; }
115        Statement * get_dtor() const { return dtor; }
116        void set_init( Initializer * newValue ) { init = newValue; }
117        Initializer * get_init() const { return init; }
118
119        virtual ConstructorInit *clone() const;
120        virtual void accept( Visitor &v ) { v.visit( this ); }
121        virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); }
122        virtual void print( std::ostream &os, int indent = 0 );
123
124  private:
125        Statement * ctor;
126        Statement * dtor;
127        // C-style initializer made up of SingleInit and ListInit nodes to use as a fallback
128        // if an appropriate constructor definition is not found by the resolver
129        Initializer * init;
130};
131
132std::ostream & operator<<( std::ostream & out, Initializer * init );
133
134#endif // INITIALIZER_H
135
136// Local Variables: //
137// tab-width: 4 //
138// mode: c++ //
139// compile-command: "make install" //
140// End: //
Note: See TracBrowser for help on using the repository browser.