source: src/SynTree/Initializer.h @ b287f67

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 b287f67 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
RevLine 
[0dd3a2f]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//
[974906e2]7// Initializer.h --
[0dd3a2f]8//
9// Author           : Richard C. Bilson
10// Created On       : Mon May 18 07:44:20 2015
[974906e2]11// Last Modified By : Rob Schluntz
[db4ecc5]12// Last Modified On : Tue Apr 12 13:49:13 2016
[d63eeb0]13// Update Count     : 19
[0dd3a2f]14//
15
[51b7345]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)
[d9a0e76]26class Initializer {
27  public:
[0dd3a2f]28        //      Initializer( std::string _name = std::string(""), int _pos = 0 );
[974906e2]29        Initializer( bool maybeConstructed );
[0dd3a2f]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
[974906e2]45        bool get_maybeConstructed() { return maybeConstructed; }
46
[0dd3a2f]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 );
[d9a0e76]51  private:
[0dd3a2f]52        //      std::string name;
53        //      int pos;
[974906e2]54        bool maybeConstructed;
[51b7345]55};
56
57// SingleInit represents an initializer for a common object (e.g., int x = 4)
[d9a0e76]58class SingleInit : public Initializer {
59  public:
[db4ecc5]60        SingleInit( Expression *value, const std::list< Expression *> &designators = std::list< Expression * >(), bool maybeConstructed = false );
[0dd3a2f]61        SingleInit( const SingleInit &other );
62        virtual ~SingleInit();
[974906e2]63
[0dd3a2f]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 );
[d9a0e76]74  private:
[0dd3a2f]75        //Constant *value;
76        Expression *value;      // has to be a compile-time constant
77        std::list< Expression * > designators;
[51b7345]78};
79
[d9a0e76]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:
[5b40f30]84        ListInit( const std::list<Initializer*> &initializers,
[db4ecc5]85                          const std::list<Expression *> &designators = std::list< Expression * >(), bool maybeConstructed = false );
[0dd3a2f]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 );
[d9a0e76]100  private:
[0dd3a2f]101        std::list<Initializer*> initializers;  // order *is* important
102        std::list<Expression *> designators;
[51b7345]103};
104
[71f4e4f]105// ConstructorInit represents an initializer that is either a constructor expression or
106// a C-style initializer.
107class ConstructorInit : public Initializer {
108  public:
[5b2f5bb]109        ConstructorInit( Statement * ctor, Statement * dtor, Initializer * init );
[71f4e4f]110        virtual ~ConstructorInit();
111
[5b2f5bb]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; }
[71f4e4f]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:
[5b2f5bb]125        Statement * ctor;
126        Statement * dtor;
[71f4e4f]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
[7a69460]132std::ostream & operator<<( std::ostream & out, Initializer * init );
133
[d9a0e76]134#endif // INITIALIZER_H
[0dd3a2f]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.