Ignore:
Timestamp:
Jun 20, 2017, 1:19:53 PM (4 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
579263a
Parents:
c6d2e93
git-author:
Rob Schluntz <rschlunt@…> (06/20/17 13:16:13)
git-committer:
Rob Schluntz <rschlunt@…> (06/20/17 13:19:53)
Message:

major effort on designations, works in many cases

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Initializer.h

    rc6d2e93 re4d829b  
    2525#include "Visitor.h"
    2626
    27 const std::list<Expression*> noDesignators;
     27// Designation: list of designator (NameExpr, VariableExpr, and ConstantExpr) expressions that specify an object being initialized.
     28class Designation : public BaseSyntaxNode {
     29public:
     30        Designation( const std::list< Expression * > & designators );
     31        Designation( const Designation & other );
     32        virtual ~Designation();
     33
     34        std::list< Expression * > & get_designators() { return designators; }
     35
     36        virtual Designation * clone() const { return new Designation( *this ); };
     37        virtual void accept( Visitor &v ) { v.visit( this ); }
     38        virtual Designation * acceptMutator( Mutator &m ) { return m.mutate( this ); }
     39        virtual void print( std::ostream &os, int indent = 0 ) const;
     40private:
     41        std::list< Expression * > designators;
     42};
     43
     44const std::list<Designation *> noDesignators;
    2845
    2946// Initializer: base class for object initializers (provide default values)
    3047class Initializer : public BaseSyntaxNode {
    3148  public:
    32         //      Initializer( std::string _name = std::string(""), int _pos = 0 );
    3349        Initializer( bool maybeConstructed );
    3450        Initializer( const Initializer & other );
    3551        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         }
    4952
    5053        bool get_maybeConstructed() { return maybeConstructed; }
     
    5356        virtual void accept( Visitor &v ) = 0;
    5457        virtual Initializer *acceptMutator( Mutator &m ) = 0;
    55         virtual void print( std::ostream &os, int indent = 0 );
     58        virtual void print( std::ostream &os, int indent = 0 ) const = 0;
    5659  private:
    57         //      std::string name;
    58         //      int pos;
    5960        bool maybeConstructed;
    6061};
     
    6364class SingleInit : public Initializer {
    6465  public:
    65         SingleInit( Expression *value, const std::list< Expression *> &designators = std::list< Expression * >(), bool maybeConstructed = false );
     66        SingleInit( Expression *value, bool maybeConstructed = false );
    6667        SingleInit( const SingleInit &other );
    6768        virtual ~SingleInit();
     
    7071        void set_value( Expression *newValue ) { value = newValue; }
    7172
    72         std::list<Expression *> &get_designators() { return designators; }
    73         void set_designators( std::list<Expression *> &newValue ) { designators = newValue; }
    74 
    7573        virtual SingleInit *clone() const { return new SingleInit( *this); }
    7674        virtual void accept( Visitor &v ) { v.visit( this ); }
    7775        virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    78         virtual void print( std::ostream &os, int indent = 0 );
     76        virtual void print( std::ostream &os, int indent = 0 ) const;
    7977  private:
    8078        //Constant *value;
    8179        Expression *value;      // has to be a compile-time constant
    82         std::list< Expression * > designators;
    8380};
    8481
     
    8885  public:
    8986        ListInit( const std::list<Initializer*> &initializers,
    90                           const std::list<Expression *> &designators = std::list< Expression * >(), bool maybeConstructed = false );
     87                          const std::list<Designation *> &designators = {}, bool maybeConstructed = false );
    9188        ListInit( const ListInit & other );
    9289        virtual ~ListInit();
    9390
    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; }
     91        std::list<Designation *> & get_designations() { return designations; }
     92        std::list<Initializer *> & get_initializers() { return initializers; }
    9893
    9994        typedef std::list<Initializer*>::iterator iterator;
     95        typedef std::list<Initializer*>::const_iterator const_iterator;
    10096        iterator begin() { return initializers.begin(); }
    10197        iterator end() { return initializers.end(); }
     98        const_iterator begin() const { return initializers.begin(); }
     99        const_iterator end() const { return initializers.end(); }
    102100
    103101        virtual ListInit *clone() const { return new ListInit( *this ); }
    104102        virtual void accept( Visitor &v ) { v.visit( this ); }
    105103        virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    106         virtual void print( std::ostream &os, int indent = 0 );
     104        virtual void print( std::ostream &os, int indent = 0 ) const;
    107105  private:
    108         std::list<Initializer*> initializers;  // order *is* important
    109         std::list<Expression *> designators;
     106        std::list<Initializer *> initializers;  // order *is* important
     107        std::list<Designation *> designations;  // order/length is consistent with initializers
    110108};
    111109
     
    130128        virtual void accept( Visitor &v ) { v.visit( this ); }
    131129        virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    132         virtual void print( std::ostream &os, int indent = 0 );
     130        virtual void print( std::ostream &os, int indent = 0 ) const;
    133131
    134132  private:
     
    140138};
    141139
    142 std::ostream & operator<<( std::ostream & out, Initializer * init );
     140std::ostream & operator<<( std::ostream & out, const Initializer * init );
     141std::ostream & operator<<( std::ostream & out, const Designation * des );
    143142
    144143#endif // INITIALIZER_H
Note: See TracChangeset for help on using the changeset viewer.