source: src/SynTree/Initializer.h @ 7870799

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 7870799 was 7870799, checked in by Thierry Delisle <tdelisle@…>, 5 years ago

Cast cost and conversion cost now take constant parameters.
This required supporting visiting const node.
The PassVisitor? can now visit const nodes but not when using the Indexer

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