source: src/SynTree/Initializer.h @ 796cea3

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 796cea3 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
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 <cassert>
20
21#include "BaseSyntaxNode.h"
22#include "Mutator.h"
23#include "SynTree.h"
24#include "Type.h"
25#include "Visitor.h"
26
27const std::list<Expression*> noDesignators;
28
29// Initializer: base class for object initializers (provide default values)
30class Initializer : public BaseSyntaxNode {
31  public:
32        //      Initializer( std::string _name = std::string(""), int _pos = 0 );
33        Initializer( bool maybeConstructed );
34        Initializer( const Initializer & other );
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
50        bool get_maybeConstructed() { return maybeConstructed; }
51
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 );
56  private:
57        //      std::string name;
58        //      int pos;
59        bool maybeConstructed;
60};
61
62// SingleInit represents an initializer for a common object (e.g., int x = 4)
63class SingleInit : public Initializer {
64  public:
65        SingleInit( Expression *value, const std::list< Expression *> &designators = std::list< Expression * >(), bool maybeConstructed = false );
66        SingleInit( const SingleInit &other );
67        virtual ~SingleInit();
68
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
75        virtual SingleInit *clone() const { return new SingleInit( *this); }
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 );
79  private:
80        //Constant *value;
81        Expression *value;      // has to be a compile-time constant
82        std::list< Expression * > designators;
83};
84
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:
89        ListInit( const std::list<Initializer*> &initializers,
90                          const std::list<Expression *> &designators = std::list< Expression * >(), bool maybeConstructed = false );
91        ListInit( const ListInit & other );
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
99        typedef std::list<Initializer*>::iterator iterator;
100        iterator begin() { return initializers.begin(); }
101        iterator end() { return initializers.end(); }
102
103        virtual ListInit *clone() const { return new ListInit( *this ); }
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 );
107  private:
108        std::list<Initializer*> initializers;  // order *is* important
109        std::list<Expression *> designators;
110};
111
112// ConstructorInit represents an initializer that is either a constructor expression or
113// a C-style initializer.
114class ConstructorInit : public Initializer {
115  public:
116        ConstructorInit( Statement * ctor, Statement * dtor, Initializer * init );
117        ConstructorInit( const ConstructorInit &other );
118        virtual ~ConstructorInit();
119
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; }
124        void set_init( Initializer * newValue ) { init = newValue; }
125        Initializer * get_init() const { return init; }
126
127        ConstructorInit *clone() const { return new ConstructorInit( *this ); }
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:
133        Statement * ctor;
134        Statement * dtor;
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
140std::ostream & operator<<( std::ostream & out, Initializer * init );
141
142#endif // INITIALIZER_H
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.