source: src/SynTree/Initializer.h @ 64cb860

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 64cb860 was 294647b, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

Filename and linenumber handling for parsing errors

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