source: src/SynTree/Initializer.h @ 8f60f0b

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

fixed StmtExpr? code in PolyMutator?, added missing copy constructor, misc documentation

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