source: src/SynTree/Initializer.h @ 28f3a19

new-envwith_gc
Last change on this file since 28f3a19 was 68f9c43, checked in by Aaron Moss <a3moss@…>, 6 years ago

First pass at delete removal

  • Property mode set to 100644
File size: 5.5 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
36        std::list< Expression * > & get_designators() { return designators; }
37
[fa16264]38        virtual Designation * clone() const override { return new Designation( *this ); };
[e149f77]39        virtual void accept( Visitor &v ) override { v.visit( this ); }
[fa16264]40        virtual Designation * acceptMutator( Mutator &m ) override { return m.mutate( this ); }
[50377a4]41        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
[e4d829b]42};
43
44const std::list<Designation *> noDesignators;
[f0121d7]45
[51b7345]46// Initializer: base class for object initializers (provide default values)
[294647b]47class Initializer : public BaseSyntaxNode {
[d9a0e76]48  public:
[974906e2]49        Initializer( bool maybeConstructed );
[70f89d00]50        Initializer( const Initializer & other );
[0dd3a2f]51
[974906e2]52        bool get_maybeConstructed() { return maybeConstructed; }
53
[fa16264]54        virtual Initializer *clone() const override = 0;
[e149f77]55        virtual void accept( Visitor &v ) override = 0;
[fa16264]56        virtual Initializer *acceptMutator( Mutator &m ) override = 0;
[50377a4]57        virtual void print( std::ostream &os, Indenter indent = {} ) const override = 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:
[65cdc1e]65        //Constant *value;
66        Expression *value;      // has to be a compile-time constant
67
[e4d829b]68        SingleInit( Expression *value, bool maybeConstructed = false );
[0dd3a2f]69        SingleInit( const SingleInit &other );
[974906e2]70
[0dd3a2f]71        Expression *get_value() { return value; }
72        void set_value( Expression *newValue ) { value = newValue; }
73
[e149f77]74        virtual SingleInit *clone() const override { return new SingleInit( *this); }
75        virtual void accept( Visitor &v ) override { v.visit( this ); }
76        virtual Initializer *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
[50377a4]77        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
[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:
[65cdc1e]84        std::list<Initializer *> initializers;  // order *is* important
85        std::list<Designation *> designations;  // order/length is consistent with initializers
86
[5b40f30]87        ListInit( const std::list<Initializer*> &initializers,
[e4d829b]88                          const std::list<Designation *> &designators = {}, bool maybeConstructed = false );
[fc638d2]89        ListInit( const ListInit & other );
[0dd3a2f]90
[e4d829b]91        std::list<Designation *> & get_designations() { return designations; }
92        std::list<Initializer *> & get_initializers() { return initializers; }
[0dd3a2f]93
[4d2434a]94        typedef std::list<Initializer*>::iterator iterator;
[e4d829b]95        typedef std::list<Initializer*>::const_iterator const_iterator;
[4d2434a]96        iterator begin() { return initializers.begin(); }
97        iterator end() { return initializers.end(); }
[e4d829b]98        const_iterator begin() const { return initializers.begin(); }
99        const_iterator end() const { return initializers.end(); }
[0dd3a2f]100
[e149f77]101        virtual ListInit *clone() const override { return new ListInit( *this ); }
102        virtual void accept( Visitor &v ) override { v.visit( this ); }
103        virtual Initializer *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
[50377a4]104        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
[51b7345]105};
106
[71f4e4f]107// ConstructorInit represents an initializer that is either a constructor expression or
108// a C-style initializer.
[64ac636]109// It should not be necessary to create ConstructorInit nodes manually. Instead, set maybeConstructed
110// to true on SingleInit or ListInit constructors if object should be constructed.
[71f4e4f]111class ConstructorInit : public Initializer {
112  public:
[65cdc1e]113        Statement * ctor;
114        Statement * dtor;
[1189946]115        // C-style initializer made up of SingleInit and ListInit nodes to use as a fallback
116        // if an appropriate constructor definition is not found by the resolver
117        Initializer * init;
[65cdc1e]118
[f1b1e4c]119        ConstructorInit( Statement * ctor, Statement * dtor, Initializer * init );
[70f89d00]120        ConstructorInit( const ConstructorInit &other );
[71f4e4f]121
[5b2f5bb]122        void set_ctor( Statement * newValue ) { ctor = newValue; }
123        Statement * get_ctor() const { return ctor; }
124        void set_dtor( Statement * newValue ) { dtor = newValue; }
125        Statement * get_dtor() const { return dtor; }
[71f4e4f]126        void set_init( Initializer * newValue ) { init = newValue; }
127        Initializer * get_init() const { return init; }
128
[e149f77]129        ConstructorInit *clone() const override { return new ConstructorInit( *this ); }
130        virtual void accept( Visitor &v ) override { v.visit( this ); }
131        virtual Initializer *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
[50377a4]132        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
[71f4e4f]133
134  private:
135};
136
[0dd3a2f]137// Local Variables: //
138// tab-width: 4 //
139// mode: c++ //
140// compile-command: "make install" //
141// End: //
Note: See TracBrowser for help on using the repository browser.