// // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo // // The contents of this file are covered under the licence agreement in the // file "LICENCE" distributed with Cforall. // // Initializer.h -- // // Author : Richard C. Bilson // Created On : Mon May 18 07:44:20 2015 // Last Modified By : Peter A. Buhr // Last Modified On : Mon May 18 09:03:48 2015 // Update Count : 1 // #ifndef INITIALIZER_H #define INITIALIZER_H #include "SynTree.h" #include "Visitor.h" #include "Mutator.h" #include // Initializer: base class for object initializers (provide default values) class Initializer { public: // Initializer( std::string _name = std::string(""), int _pos = 0 ); Initializer( ); virtual ~Initializer(); static std::string designator_name( Expression *designator ); // void set_name( std::string newValue ) { name = newValue; } // std::string get_name() const { return name; } // void set_pos( int newValue ) { pos = newValue; } // int get_pos() const { return pos; } virtual void set_designators( std::list & ) { assert(false); } virtual std::list &get_designators() { assert(false); std::list *ret = 0; return *ret; // never reached } virtual Initializer *clone() const = 0; virtual void accept( Visitor &v ) = 0; virtual Initializer *acceptMutator( Mutator &m ) = 0; virtual void print( std::ostream &os, int indent = 0 ); private: // std::string name; // int pos; }; // SingleInit represents an initializer for a common object (e.g., int x = 4) class SingleInit : public Initializer { public: SingleInit( Expression *value, std::list< Expression *> &designators ); SingleInit( const SingleInit &other ); virtual ~SingleInit(); Expression *get_value() { return value; } void set_value( Expression *newValue ) { value = newValue; } void set_designators( std::list &newValue ) { designators = newValue; } std::list &get_designators() { return designators; } virtual SingleInit *clone() const; virtual void accept( Visitor &v ) { v.visit( this ); } virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); } virtual void print( std::ostream &os, int indent = 0 ); private: //Constant *value; Expression *value; // has to be a compile-time constant std::list< Expression * > designators; }; // ListInit represents an initializer that is composed recursively of a list of initializers; this is used to initialize // an array or aggregate class ListInit : public Initializer { public: ListInit( std::list &, std::list &designators = *(new std::list()) ); virtual ~ListInit(); void set_designators( std::list &newValue ) { designators = newValue; } std::list &get_designators() { return designators; } void set_initializers( std::list &newValue ) { initializers = newValue; } std::list &get_initializers() { return initializers; } std::list::iterator begin_initializers() { return initializers.begin(); } std::list::iterator end_initializers() { return initializers.end(); } virtual ListInit *clone() const; virtual void accept( Visitor &v ) { v.visit( this ); } virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); } virtual void print( std::ostream &os, int indent = 0 ); private: std::list initializers; // order *is* important std::list designators; }; #endif // INITIALIZER_H // Local Variables: // // tab-width: 4 // // mode: c++ // // compile-command: "make install" // // End: //