source: src/SynTree/Initializer.h @ cbce272

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 cbce272 was 6b0b624, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

change #ifndef to #pragma once

  • Property mode set to 100644
File size: 5.4 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
[6013bd7]11// Last Modified By : Peter A. Buhr
[6b0b624]12// Last Modified On : Sat Jul 22 09:52:02 2017
13// Update Count     : 21
[0dd3a2f]14//
15
[6b0b624]16#pragma once
[51b7345]17
[294647b]18#include <cassert>
19
20#include "BaseSyntaxNode.h"
[51b7345]21#include "Mutator.h"
[294647b]22#include "SynTree.h"
[70f89d00]23#include "Type.h"
[294647b]24#include "Visitor.h"
[51b7345]25
[e4d829b]26// Designation: list of designator (NameExpr, VariableExpr, and ConstantExpr) expressions that specify an object being initialized.
27class Designation : public BaseSyntaxNode {
28public:
29        Designation( const std::list< Expression * > & designators );
30        Designation( const Designation & other );
31        virtual ~Designation();
32
33        std::list< Expression * > & get_designators() { return designators; }
34
35        virtual Designation * clone() const { return new Designation( *this ); };
36        virtual void accept( Visitor &v ) { v.visit( this ); }
37        virtual Designation * acceptMutator( Mutator &m ) { return m.mutate( this ); }
38        virtual void print( std::ostream &os, int indent = 0 ) const;
39private:
40        std::list< Expression * > designators;
41};
42
43const std::list<Designation *> noDesignators;
[f0121d7]44
[51b7345]45// Initializer: base class for object initializers (provide default values)
[294647b]46class Initializer : public BaseSyntaxNode {
[d9a0e76]47  public:
[974906e2]48        Initializer( bool maybeConstructed );
[70f89d00]49        Initializer( const Initializer & other );
[0dd3a2f]50        virtual ~Initializer();
51
[974906e2]52        bool get_maybeConstructed() { return maybeConstructed; }
53
[0dd3a2f]54        virtual Initializer *clone() const = 0;
55        virtual void accept( Visitor &v ) = 0;
56        virtual Initializer *acceptMutator( Mutator &m ) = 0;
[e4d829b]57        virtual void print( std::ostream &os, int indent = 0 ) const = 0;
[d9a0e76]58  private:
[974906e2]59        bool maybeConstructed;
[51b7345]60};
61
62// SingleInit represents an initializer for a common object (e.g., int x = 4)
[d9a0e76]63class SingleInit : public Initializer {
64  public:
[e4d829b]65        SingleInit( Expression *value, bool maybeConstructed = false );
[0dd3a2f]66        SingleInit( const SingleInit &other );
67        virtual ~SingleInit();
[974906e2]68
[0dd3a2f]69        Expression *get_value() { return value; }
70        void set_value( Expression *newValue ) { value = newValue; }
71
[70f89d00]72        virtual SingleInit *clone() const { return new SingleInit( *this); }
[0dd3a2f]73        virtual void accept( Visitor &v ) { v.visit( this ); }
74        virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[e4d829b]75        virtual void print( std::ostream &os, int indent = 0 ) const;
[d9a0e76]76  private:
[0dd3a2f]77        //Constant *value;
78        Expression *value;      // has to be a compile-time constant
[51b7345]79};
80
[d9a0e76]81// ListInit represents an initializer that is composed recursively of a list of initializers; this is used to initialize
82// an array or aggregate
83class ListInit : public Initializer {
84  public:
[5b40f30]85        ListInit( const std::list<Initializer*> &initializers,
[e4d829b]86                          const std::list<Designation *> &designators = {}, bool maybeConstructed = false );
[fc638d2]87        ListInit( const ListInit & other );
[0dd3a2f]88        virtual ~ListInit();
89
[e4d829b]90        std::list<Designation *> & get_designations() { return designations; }
91        std::list<Initializer *> & get_initializers() { return initializers; }
[0dd3a2f]92
[4d2434a]93        typedef std::list<Initializer*>::iterator iterator;
[e4d829b]94        typedef std::list<Initializer*>::const_iterator const_iterator;
[4d2434a]95        iterator begin() { return initializers.begin(); }
96        iterator end() { return initializers.end(); }
[e4d829b]97        const_iterator begin() const { return initializers.begin(); }
98        const_iterator end() const { return initializers.end(); }
[0dd3a2f]99
[70f89d00]100        virtual ListInit *clone() const { return new ListInit( *this ); }
[0dd3a2f]101        virtual void accept( Visitor &v ) { v.visit( this ); }
102        virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[e4d829b]103        virtual void print( std::ostream &os, int indent = 0 ) const;
[d9a0e76]104  private:
[e4d829b]105        std::list<Initializer *> initializers;  // order *is* important
106        std::list<Designation *> designations;  // order/length is consistent with initializers
[51b7345]107};
108
[71f4e4f]109// ConstructorInit represents an initializer that is either a constructor expression or
110// a C-style initializer.
[64ac636]111// It should not be necessary to create ConstructorInit nodes manually. Instead, set maybeConstructed
112// to true on SingleInit or ListInit constructors if object should be constructed.
[71f4e4f]113class ConstructorInit : public Initializer {
114  public:
[f1b1e4c]115        ConstructorInit( Statement * ctor, Statement * dtor, Initializer * init );
[70f89d00]116        ConstructorInit( const ConstructorInit &other );
[71f4e4f]117        virtual ~ConstructorInit();
118
[5b2f5bb]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; }
[71f4e4f]123        void set_init( Initializer * newValue ) { init = newValue; }
124        Initializer * get_init() const { return init; }
125
[70f89d00]126        ConstructorInit *clone() const { return new ConstructorInit( *this ); }
[71f4e4f]127        virtual void accept( Visitor &v ) { v.visit( this ); }
128        virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[e4d829b]129        virtual void print( std::ostream &os, int indent = 0 ) const;
[71f4e4f]130
131  private:
[5b2f5bb]132        Statement * ctor;
133        Statement * dtor;
[71f4e4f]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
[e4d829b]139std::ostream & operator<<( std::ostream & out, const Initializer * init );
140std::ostream & operator<<( std::ostream & out, const Designation * des );
[7a69460]141
[0dd3a2f]142// Local Variables: //
143// tab-width: 4 //
144// mode: c++ //
145// compile-command: "make install" //
146// End: //
Note: See TracBrowser for help on using the repository browser.