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.cc

    rc6d2e93 re4d829b  
    1919#include "Common/utility.h"
    2020
     21Designation::Designation( const std::list< Expression * > & designators ) : designators( designators ) {}
     22Designation::Designation( const Designation & other ) : BaseSyntaxNode( other ) {
     23        // std::cerr << "cloning designation" << std::endl;
     24        cloneAll( other.designators, designators );
     25        // std::cerr << "finished cloning designation" << std::endl;
     26}
     27
     28Designation::~Designation() {
     29        // std::cerr << "destroying designation" << std::endl;
     30        deleteAll( designators );
     31        // std::cerr << "finished destroying designation" << std::endl;
     32}
     33
     34void Designation::print( std::ostream &os, int indent ) const {
     35        if ( ! designators.empty() ) {
     36                os << std::string(indent + 2, ' ' ) << "designated by: " << std::endl;
     37                for ( std::list < Expression * >::const_iterator i = designators.begin(); i != designators.end(); i++ ) {
     38                        os << std::string(indent + 4, ' ' );
     39                        ( *i )->print(os, indent + 4 );
     40                }
     41                os << std::endl;
     42        } // if
     43}
     44
     45
    2146Initializer::Initializer( bool maybeConstructed ) : maybeConstructed( maybeConstructed ) {}
    2247Initializer::Initializer( const Initializer & other ) : BaseSyntaxNode( other ), maybeConstructed( other.maybeConstructed ) {
    2348}
    24 
    25 
    2649Initializer::~Initializer() {}
    2750
    28 std::string Initializer::designator_name( Expression *des ) {
    29         if ( NameExpr *n = dynamic_cast<NameExpr *>(des) )
    30                 return n->get_name();
    31         else
    32                 throw 0;
    33 }
    34 
    35 void Initializer::print( std::ostream &os, int indent ) {}
    36 
    37 SingleInit::SingleInit( Expression *v, const std::list< Expression *> &_designators, bool maybeConstructed ) : Initializer( maybeConstructed ), value ( v ), designators( _designators ) {
     51SingleInit::SingleInit( Expression *v, bool maybeConstructed ) : Initializer( maybeConstructed ), value ( v ) {
    3852}
    3953
    4054SingleInit::SingleInit( const SingleInit &other ) : Initializer(other), value ( maybeClone( other.value ) ) {
    41         cloneAll(other.designators, designators );
    4255}
    4356
    4457SingleInit::~SingleInit() {
    4558        delete value;
    46         deleteAll(designators);
    4759}
    4860
    49 void SingleInit::print( std::ostream &os, int indent ) {
    50         os << std::endl << std::string(indent, ' ' ) << "Simple Initializer: " << std::endl;
     61void SingleInit::print( std::ostream &os, int indent ) const {
     62        os << std::string(indent, ' ' ) << "Simple Initializer: " << std::endl;
    5163        os << std::string(indent+4, ' ' );
    5264        value->print( os, indent+4 );
    53 
    54         if ( ! designators.empty() ) {
    55                 os << std::endl << std::string(indent + 2, ' ' ) << "designated by: " << std::endl;
    56                 for ( std::list < Expression * >::iterator i = designators.begin(); i != designators.end(); i++ ) {
    57                         os << std::string(indent + 4, ' ' );
    58                         ( *i )->print(os, indent + 4 );
    59                 }
    60         } // if
    6165}
    6266
    63 ListInit::ListInit( const std::list<Initializer*> &_initializers, const std::list<Expression *> &_designators, bool maybeConstructed )
    64         : Initializer( maybeConstructed ), initializers( _initializers ), designators( _designators ) {
     67
     68ListInit::ListInit( const std::list<Initializer*> &initializers, const std::list<Designation *> &designations, bool maybeConstructed )
     69        : Initializer( maybeConstructed ), initializers( initializers ), designations( designations ) {
    6570}
    6671
    6772ListInit::ListInit( const ListInit & other ) : Initializer( other ) {
    6873        cloneAll( other.initializers, initializers );
    69         cloneAll( other.designators, designators );
     74        cloneAll( other.designations, designations );
    7075}
    71 
    7276
    7377ListInit::~ListInit() {
    7478        deleteAll( initializers );
    75         deleteAll( designators );
     79        deleteAll( designations );
    7680}
    7781
    78 void ListInit::print( std::ostream &os, int indent ) {
    79         os << std::endl << std::string(indent, ' ') << "Compound initializer:  ";
    80         if ( ! designators.empty() ) {
    81                 os << std::string(indent + 2, ' ' ) << "designated by: [";
    82                 for ( std::list < Expression * >::iterator i = designators.begin();
    83                           i != designators.end(); i++ ) {
    84                         ( *i )->print(os, indent + 4 );
    85                 } // for
     82void ListInit::print( std::ostream &os, int indent ) const {
     83        os << std::string(indent, ' ') << "Compound initializer:  " << std::endl;
     84        for ( Designation * d : designations ) {
     85                d->print( os, indent + 2 );
     86        }
    8687
    87                 os << std::string(indent + 2, ' ' ) << "]";
    88         } // if
    89 
    90         for ( std::list<Initializer *>::iterator i = initializers.begin(); i != initializers.end(); i++ )
    91                 (*i)->print( os, indent + 2 );
     88        for ( const Initializer * init : initializers ) {
     89                init->print( os, indent + 2 );
     90                os << std::endl;
     91        }
    9292}
    9393
     
    103103}
    104104
    105 void ConstructorInit::print( std::ostream &os, int indent ) {
     105void ConstructorInit::print( std::ostream &os, int indent ) const {
    106106        os << std::endl << std::string(indent, ' ') << "Constructor initializer: " << std::endl;
    107107        if ( ctor ) {
     
    124124}
    125125
    126 std::ostream & operator<<( std::ostream & out, Initializer * init ) {
    127         init->print( out );
     126std::ostream & operator<<( std::ostream & out, const Initializer * init ) {
     127        if ( init ) {
     128                init->print( out );
     129        } else {
     130                out << "nullptr";
     131        }
     132        return out;
     133}
     134
     135std::ostream & operator<<( std::ostream & out, const Designation * des ) {
     136        if ( des ) {
     137                des->print( out );
     138        } else {
     139                out << "nullptr";
     140        }
    128141        return out;
    129142}
Note: See TracChangeset for help on using the changeset viewer.