Changeset 6840e7c for src/SynTree


Ignore:
Timestamp:
Oct 19, 2017, 12:01:04 PM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
837ce06
Parents:
b96ec83 (diff), a15b72c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into cleanup-dtors

Location:
src/SynTree
Files:
43 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/AddressExpr.cc

    rb96ec83 r6840e7c  
    3333        Type * addrType( Type * type ) {
    3434                if ( ReferenceType * refType = dynamic_cast< ReferenceType * >( type ) ) {
    35                         return new ReferenceType( refType->get_qualifiers(), addrType( refType->get_base() ) );
     35                        return new ReferenceType( refType->get_qualifiers(), addrType( refType->base ) );
    3636                } else {
    3737                        return new PointerType( Type::Qualifiers(), type->clone() );
     
    4040}
    4141
    42 AddressExpr::AddressExpr( Expression *arg, Expression *_aname ) : Expression( _aname ), arg( arg ) {
    43         if ( arg->has_result() ) {
    44                 if ( arg->get_result()->get_lvalue() ) {
     42AddressExpr::AddressExpr( Expression *arg ) : Expression(), arg( arg ) {
     43        if ( arg->result ) {
     44                if ( arg->result->get_lvalue() ) {
    4545                        // lvalue, retains all layers of reference and gains a pointer inside the references
    46                         set_result( addrType( arg->get_result() ) );
     46                        set_result( addrType( arg->result ) );
    4747                } else {
    4848                        // taking address of non-lvalue -- must be a reference, loses one layer of reference
    49                         ReferenceType * refType = strict_dynamic_cast< ReferenceType * >( arg->get_result() );
    50                         set_result( addrType( refType->get_base() ) );
     49                        ReferenceType * refType = strict_dynamic_cast< ReferenceType * >( arg->result );
     50                        set_result( addrType( refType->base ) );
    5151                }
    5252                // result of & is never an lvalue
     
    6262}
    6363
    64 void AddressExpr::print( std::ostream &os, int indent ) const {
     64void AddressExpr::print( std::ostream &os, Indenter indent ) const {
    6565        os << "Address of:" << std::endl;
    6666        if ( arg ) {
    67                 os << std::string( indent+2, ' ' );
    68                 arg->print( os, indent+2 );
     67                os << indent+1;
     68                arg->print( os, indent+1 );
    6969        } // if
    7070}
     
    7777LabelAddressExpr::~LabelAddressExpr() {}
    7878
    79 void LabelAddressExpr::print( std::ostream & os, int indent ) const {
    80         os << "Address of label:" << std::endl << std::string( indent+2, ' ' ) << arg;
     79void LabelAddressExpr::print( std::ostream & os, Indenter ) const {
     80        os << "Address of label:" << arg;
    8181}
    8282
  • src/SynTree/AggregateDecl.cc

    rb96ec83 r6840e7c  
    4141}
    4242
    43 void AggregateDecl::print( std::ostream &os, int indent ) const {
     43void AggregateDecl::print( std::ostream &os, Indenter indent ) const {
    4444        using std::string;
    4545        using std::endl;
    4646
    47         os << typeString() << " " << get_name() << ":";
     47        os << typeString() << " " << name << ":";
    4848        if ( get_linkage() != LinkageSpec::Cforall ) {
    49                 os << " " << LinkageSpec::linkageName( get_linkage() );
     49                os << " " << LinkageSpec::linkageName( linkage );
    5050        } // if
    51         os << " with body " << has_body() << endl;
     51        os << " with body " << has_body();
    5252
    5353        if ( ! parameters.empty() ) {
    54                 os << endl << string( indent+2, ' ' ) << "with parameters" << endl;
    55                 printAll( parameters, os, indent+4 );
     54                os << endl << indent << "... with parameters" << endl;
     55                printAll( parameters, os, indent+1 );
    5656        } // if
    5757        if ( ! members.empty() ) {
    58                 os << endl << string( indent+2, ' ' ) << "with members" << endl;
    59                 printAll( members, os, indent+4 );
     58                os << endl << indent << "... with members" << endl;
     59                printAll( members, os, indent+1 );
    6060        } // if
    6161        if ( ! attributes.empty() ) {
    62                 os << endl << string( indent+2, ' ' ) << "with attributes" << endl;
    63                 printAll( attributes, os, indent+4 );
     62                os << endl << indent << "... with attributes" << endl;
     63                printAll( attributes, os, indent+1 );
    6464        } // if
     65        os << endl;
    6566}
    6667
    67 void AggregateDecl::printShort( std::ostream &os, int indent ) const {
     68void AggregateDecl::printShort( std::ostream &os, Indenter indent ) const {
    6869        using std::string;
    6970        using std::endl;
    7071
    71         os << typeString() << " " << get_name();
    72         os << string( indent+2, ' ' ) << "with body " << has_body() << endl;
     72        os << typeString() << " " << name << " with body " << has_body() << endl;
    7373
    7474        if ( ! parameters.empty() ) {
    75                 os << endl << string( indent+2, ' ' ) << "with parameters" << endl;
    76                 printAll( parameters, os, indent+4 );
     75                os << indent << "... with parameters" << endl;
     76                printAll( parameters, os, indent+1 );
    7777        } // if
    7878}
  • src/SynTree/ApplicationExpr.cc

    rb96ec83 r6840e7c  
    5555        set_result( ResolvExpr::extractResultType( function ) );
    5656
    57         assert( has_result() );
     57        assert( result );
    5858}
    5959
     
    6868}
    6969
    70 void printInferParams( const InferredParams & inferParams, std::ostream &os, int indent, int level ) {
     70void printInferParams( const InferredParams & inferParams, std::ostream &os, Indenter indent, int level ) {
    7171        if ( ! inferParams.empty() ) {
    72                 os << std::string(indent, ' ') << "with inferred parameters " << level << ":" << std::endl;
     72                os << indent << "with inferred parameters " << level << ":" << std::endl;
    7373                for ( InferredParams::const_iterator i = inferParams.begin(); i != inferParams.end(); ++i ) {
    74                         os << std::string(indent+2, ' ');
    75                         Declaration::declFromId( i->second.decl )->printShort( os, indent+2 );
     74                        os << indent+1;
     75                        Declaration::declFromId( i->second.decl )->printShort( os, indent+1 );
    7676                        os << std::endl;
    77                         printInferParams( *i->second.inferParams, os, indent+2, level+1 );
     77                        printInferParams( *i->second.inferParams, os, indent+1, level+1 );
    7878                } // for
    7979        } // if
    8080}
    8181
    82 void ApplicationExpr::print( std::ostream &os, int indent ) const {
    83         os << "Application of" << std::endl << std::string(indent+2, ' ');
    84         function->print( os, indent+2 );
     82void ApplicationExpr::print( std::ostream &os, Indenter indent ) const {
     83        os << "Application of" << std::endl << indent+1;
     84        function->print( os, indent+1 );
     85        os << std::endl;
    8586        if ( ! args.empty() ) {
    86                 os << std::string( indent, ' ' ) << "to arguments" << std::endl;
    87                 printAll( args, os, indent+2 );
     87                os << indent << "... to arguments" << std::endl;
     88                printAll( args, os, indent+1 );
    8889        } // if
    89         printInferParams( inferParams, os, indent+2, 0 );
     90        printInferParams( inferParams, os, indent+1, 0 );
    9091        Expression::print( os, indent );
    9192}
  • src/SynTree/ArrayType.cc

    rb96ec83 r6840e7c  
    3939}
    4040
    41 void ArrayType::print( std::ostream &os, int indent ) const {
     41void ArrayType::print( std::ostream &os, Indenter indent ) const {
    4242        Type::print( os, indent );
    4343        if ( isStatic ) {
  • src/SynTree/AttrType.cc

    rb96ec83 r6840e7c  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // AttrType.cc.cc -- 
     7// AttrType.cc.cc --
    88//
    99// Author           : Richard C. Bilson
     
    4242}
    4343
    44 void AttrType::print( std::ostream &os, int indent ) const {
     44void AttrType::print( std::ostream &os, Indenter indent ) const {
    4545        Type::print( os, indent );
    4646        os << "attribute " << name << " applied to ";
  • src/SynTree/Attribute.cc

    rb96ec83 r6840e7c  
    2828}
    2929
    30 void Attribute::print( std::ostream &os, int indent ) const {
     30void Attribute::print( std::ostream &os, Indenter indent ) const {
    3131  using std::endl;
    3232  using std::string;
     
    3636    if ( ! parameters.empty() ) {
    3737      os << " with parameters: " << endl;
    38       printAll( parameters, os, indent );
     38      printAll( parameters, os, indent+1 );
    3939    }
    4040  }
  • src/SynTree/Attribute.h

    rb96ec83 r6840e7c  
    4343        bool empty() const { return name == ""; }
    4444
    45         Attribute * clone() const { return new Attribute( *this ); }
    46         virtual void accept( Visitor & v ) { v.visit( this ); }
    47         virtual Attribute * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    48         virtual void print( std::ostream & os, int indent = 0 ) const;
     45        Attribute * clone() const override { return new Attribute( *this ); }
     46        virtual void accept( Visitor & v ) override { v.visit( this ); }
     47        virtual Attribute * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     48        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    4949};
    5050
  • src/SynTree/BaseSyntaxNode.h

    rb96ec83 r6840e7c  
    1717
    1818#include "Common/CodeLocation.h"
     19#include "Common/Indenter.h"
    1920class Visitor;
    2021class Mutator;
     
    2930        virtual void accept( Visitor & v ) = 0;
    3031        virtual BaseSyntaxNode * acceptMutator( Mutator & m ) = 0;
    31         virtual void print( std::ostream & os, int indent = 0 ) const = 0;
     32  /// Notes:
     33  /// * each node is responsible for indenting its children.
     34  /// * Expressions should not finish with a newline, since the expression's parent has better information.
     35        virtual void print( std::ostream & os, Indenter indent = {} ) const = 0;
     36  void print( std::ostream & os, unsigned int indent ) {
     37    print( os, Indenter{ Indenter::tabsize, indent });
     38  }
    3239};
    3340
  • src/SynTree/BasicType.cc

    rb96ec83 r6840e7c  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // BasicType.cc -- 
     7// BasicType.cc --
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Sep 11 12:52:05 2017
    13 // Update Count     : 9
     12// Last Modified On : Mon Sep 25 14:14:03 2017
     13// Update Count     : 11
    1414//
    1515
     
    2424BasicType::BasicType( const Type::Qualifiers &tq, Kind bt, const std::list< Attribute * > & attributes ) : Type( tq, attributes ), kind( bt ) {}
    2525
    26 void BasicType::print( std::ostream &os, int indent ) const {
     26void BasicType::print( std::ostream &os, Indenter indent ) const {
    2727        Type::print( os, indent );
    2828        os << BasicType::typeNames[ kind ];
     
    4343          case LongLongSignedInt:
    4444          case LongLongUnsignedInt:
     45          case SignedInt128:
     46          case UnsignedInt128:
    4547                return true;
    4648          case Float:
  • src/SynTree/CommaExpr.cc

    rb96ec83 r6840e7c  
    2121#include "Type.h"            // for Type
    2222
    23 CommaExpr::CommaExpr( Expression *arg1, Expression *arg2, Expression *_aname )
    24                 : Expression( _aname ), arg1( arg1 ), arg2( arg2 ) {
     23CommaExpr::CommaExpr( Expression *arg1, Expression *arg2 )
     24                : Expression(), arg1( arg1 ), arg2( arg2 ) {
    2525        // xxx - result of a comma expression is never an lvalue, so should set lvalue
    2626        // to false on all result types. Actually doing this causes some strange things
     
    3939}
    4040
    41 void CommaExpr::print( std::ostream &os, int indent ) const {
     41void CommaExpr::print( std::ostream &os, Indenter indent ) const {
    4242        os << "Comma Expression:" << std::endl;
    43         os << std::string( indent+2, ' ' );
    44         arg1->print( os, indent+2 );
     43        os << (indent+1);
     44        arg1->print( os, indent+1 );
    4545        os << std::endl;
    46         os << std::string( indent+2, ' ' );
    47         arg2->print( os, indent+2 );
     46        os << (indent+1);
     47        arg2->print( os, indent+1 );
    4848        Expression::print( os, indent );
    4949}
  • src/SynTree/CompoundStmt.cc

    rb96ec83 r6840e7c  
    7373}
    7474
    75 void CompoundStmt::print( std::ostream &os, int indent ) const {
    76         os << "CompoundStmt" << endl ;
    77         printAll( kids, os, indent + 2 );
     75void CompoundStmt::print( std::ostream &os, Indenter indent ) const {
     76        os << "CompoundStmt" << endl;
     77        printAll( kids, os, indent+1 );
    7878}
    7979
  • src/SynTree/Constant.cc

    rb96ec83 r6840e7c  
    7171}
    7272
    73 void Constant::print( std::ostream &os ) const {
     73void Constant::print( std::ostream &os, Indenter ) const {
    7474        os << "(" << rep << " " << val.ival;
    7575        if ( type ) {
  • src/SynTree/Constant.h

    rb96ec83 r6840e7c  
    1919#include <string>     // for string
    2020
     21#include "BaseSyntaxNode.h"
    2122#include "Mutator.h"  // for Mutator
    2223#include "Visitor.h"  // for Visitor
     
    2425class Type;
    2526
    26 class Constant {
     27class Constant : public BaseSyntaxNode {
    2728  public:
    2829        Constant( Type * type, std::string rep, unsigned long long val );
     
    3031        Constant( const Constant & other );
    3132        virtual ~Constant();
     33
     34        virtual Constant * clone() const { return new Constant( *this ); }
    3235
    3336        Type * get_type() { return type; }
     
    5457        virtual void accept( Visitor & v ) { v.visit( this ); }
    5558        virtual Constant * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    56         virtual void print( std::ostream & os ) const;
     59        virtual void print( std::ostream & os, Indenter indent = 0 ) const;
    5760  private:
    5861        Type * type;
  • src/SynTree/DeclStmt.cc

    rb96ec83 r6840e7c  
    3333}
    3434
    35 void DeclStmt::print( std::ostream &os, int indent ) const {
     35void DeclStmt::print( std::ostream &os, Indenter indent ) const {
    3636        assert( decl != 0 );
    3737        os << "Declaration of ";
  • src/SynTree/Declaration.cc

    rb96ec83 r6840e7c  
    4242
    4343void Declaration::fixUniqueId() {
     44        // don't need to set unique ID twice
     45        if ( uniqueId ) return;
    4446        uniqueId = ++lastUniqueId;
    4547        idMap[ uniqueId ] = this;
     
    7072}
    7173
    72 void AsmDecl::print( std::ostream &os, int indent ) const {
     74void AsmDecl::print( std::ostream &os, Indenter indent ) const {
    7375        stmt->print( os, indent );
    7476}
    7577
    76 void AsmDecl::printShort( std::ostream &os, int indent ) const {
     78void AsmDecl::printShort( std::ostream &os, Indenter indent ) const {
    7779        stmt->print( os, indent );
    7880}
  • src/SynTree/Declaration.h

    rb96ec83 r6840e7c  
    6161
    6262        void fixUniqueId( void );
    63         virtual Declaration *clone() const = 0;
     63        virtual Declaration *clone() const override = 0;
    6464        virtual void accept( Visitor &v ) override = 0;
    65         virtual Declaration *acceptMutator( Mutator &m ) = 0;
    66         virtual void print( std::ostream &os, int indent = 0 ) const override = 0;
    67         virtual void printShort( std::ostream &os, int indent = 0 ) const = 0;
     65        virtual Declaration *acceptMutator( Mutator &m ) override = 0;
     66        virtual void print( std::ostream &os, Indenter indent = {} ) const override = 0;
     67        virtual void printShort( std::ostream &os, Indenter indent = {} ) const = 0;
    6868
    6969        static void dumpIds( std::ostream &os );
     
    142142        virtual void accept( Visitor &v ) override { v.visit( this ); }
    143143        virtual DeclarationWithType *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    144         virtual void print( std::ostream &os, int indent = 0 ) const override;
    145         virtual void printShort( std::ostream &os, int indent = 0 ) const override;
     144        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
     145        virtual void printShort( std::ostream &os, Indenter indent = {} ) const override;
    146146};
    147147
     
    170170        virtual void accept( Visitor &v ) override { v.visit( this ); }
    171171        virtual DeclarationWithType *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    172         virtual void print( std::ostream &os, int indent = 0 ) const override;
    173         virtual void printShort( std::ostream &os, int indent = 0 ) const override;
     172        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
     173        virtual void printShort( std::ostream &os, Indenter indent = {} ) const override;
    174174};
    175175
     
    193193
    194194        virtual NamedTypeDecl *clone() const override = 0;
    195         virtual void print( std::ostream &os, int indent = 0 ) const override;
    196         virtual void printShort( std::ostream &os, int indent = 0 ) const override;
     195        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
     196        virtual void printShort( std::ostream &os, Indenter indent = {} ) const override;
    197197};
    198198
     
    235235        virtual void accept( Visitor &v ) override { v.visit( this ); }
    236236        virtual Declaration *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    237         virtual void print( std::ostream &os, int indent = 0 ) const override;
     237        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    238238
    239239  private:
     
    276276        AggregateDecl * set_body( bool body ) { AggregateDecl::body = body; return this; }
    277277
    278         virtual void print( std::ostream &os, int indent = 0 ) const override;
    279         virtual void printShort( std::ostream &os, int indent = 0 ) const override;
     278        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
     279        virtual void printShort( std::ostream &os, Indenter indent = {} ) const override;
    280280  protected:
    281281        virtual std::string typeString() const = 0;
     
    355355        virtual void accept( Visitor &v ) override { v.visit( this ); }
    356356        virtual AsmDecl *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    357         virtual void print( std::ostream &os, int indent = 0 ) const override;
    358         virtual void printShort( std::ostream &os, int indent = 0 ) const override;
     357        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
     358        virtual void printShort( std::ostream &os, Indenter indent = {} ) const override;
    359359};
    360360
  • src/SynTree/Expression.cc

    rb96ec83 r6840e7c  
    3333#include "GenPoly/Lvalue.h"
    3434
    35 Expression::Expression( Expression *_aname ) : result( 0 ), env( 0 ), argName( _aname ) {}
    36 
    37 Expression::Expression( const Expression &other ) : BaseSyntaxNode( other ), result( maybeClone( other.result ) ), env( maybeClone( other.env ) ), argName( maybeClone( other.get_argName() ) ), extension( other.extension ) {
     35Expression::Expression() : result( 0 ), env( 0 ) {}
     36
     37Expression::Expression( const Expression &other ) : BaseSyntaxNode( other ), result( maybeClone( other.result ) ), env( maybeClone( other.env ) ), extension( other.extension ) {
    3838}
    3939
    4040Expression::~Expression() {
    4141        delete env;
    42         delete argName; // xxx -- there's a problem in cloning ConstantExpr I still don't know how to fix
    4342        delete result;
    4443}
    4544
    46 void Expression::print( std::ostream &os, int indent ) const {
     45void Expression::print( std::ostream &os, Indenter indent ) const {
    4746        if ( env ) {
    48                 os << std::string( indent, ' ' ) << "with environment:" << std::endl;
    49                 env->print( os, indent+2 );
     47                os << std::endl << indent << "... with environment:" << std::endl;
     48                env->print( os, indent+1 );
    5049        } // if
    5150
    52         if ( argName ) {
    53                 os << std::string( indent, ' ' ) << "with designator:";
    54                 argName->print( os, indent+2 );
     51        if ( extension ) {
     52                os << std::endl << indent << "... with extension:";
    5553        } // if
    56 
    57         if ( extension ) {
    58                 os << std::string( indent, ' ' ) << "with extension:";
    59         } // if
    60 }
    61 
    62 ConstantExpr::ConstantExpr( Constant _c, Expression *_aname ) : Expression( _aname ), constant( _c ) {
     54}
     55
     56ConstantExpr::ConstantExpr( Constant _c ) : Expression(), constant( _c ) {
    6357        set_result( constant.get_type()->clone() );
    6458}
     
    6963ConstantExpr::~ConstantExpr() {}
    7064
    71 void ConstantExpr::print( std::ostream &os, int indent ) const {
     65void ConstantExpr::print( std::ostream &os, Indenter indent ) const {
    7266        os << "constant expression " ;
    7367        constant.print( os );
     
    7569}
    7670
    77 VariableExpr::VariableExpr( DeclarationWithType *_var, Expression *_aname ) : Expression( _aname ), var( _var ) {
     71VariableExpr::VariableExpr( DeclarationWithType *_var ) : Expression(), var( _var ) {
    7872        assert( var );
    7973        assert( var->get_type() );
     
    9690}
    9791
    98 void VariableExpr::print( std::ostream &os, int indent ) const {
     92void VariableExpr::print( std::ostream &os, Indenter indent ) const {
    9993        os << "Variable Expression: ";
    100 
    101         Declaration *decl = get_var();
    102         if ( decl != 0) decl->printShort(os, indent + 2);
    103         os << std::endl;
    104         Expression::print( os, indent );
    105 }
    106 
    107 SizeofExpr::SizeofExpr( Expression *expr_, Expression *_aname ) :
    108                 Expression( _aname ), expr(expr_), type(0), isType(false) {
     94        var->printShort(os, indent);
     95        Expression::print( os, indent );
     96}
     97
     98SizeofExpr::SizeofExpr( Expression *expr_ ) :
     99                Expression(), expr(expr_), type(0), isType(false) {
    109100        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
    110101}
    111102
    112 SizeofExpr::SizeofExpr( Type *type_, Expression *_aname ) :
    113                 Expression( _aname ), expr(0), type(type_), isType(true) {
     103SizeofExpr::SizeofExpr( Type *type_ ) :
     104                Expression(), expr(0), type(type_), isType(true) {
    114105        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
    115106}
     
    124115}
    125116
    126 void SizeofExpr::print( std::ostream &os, int indent) const {
     117void SizeofExpr::print( std::ostream &os, Indenter indent) const {
    127118        os << "Sizeof Expression on: ";
    128 
    129         if (isType)
    130                 type->print(os, indent + 2);
    131         else
    132                 expr->print(os, indent + 2);
    133 
    134         os << std::endl;
    135         Expression::print( os, indent );
    136 }
    137 
    138 AlignofExpr::AlignofExpr( Expression *expr_, Expression *_aname ) :
    139                 Expression( _aname ), expr(expr_), type(0), isType(false) {
     119        if (isType) type->print(os, indent+1);
     120        else expr->print(os, indent+1);
     121        Expression::print( os, indent );
     122}
     123
     124AlignofExpr::AlignofExpr( Expression *expr_ ) :
     125                Expression(), expr(expr_), type(0), isType(false) {
    140126        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
    141127}
    142128
    143 AlignofExpr::AlignofExpr( Type *type_, Expression *_aname ) :
    144                 Expression( _aname ), expr(0), type(type_), isType(true) {
     129AlignofExpr::AlignofExpr( Type *type_ ) :
     130                Expression(), expr(0), type(type_), isType(true) {
    145131        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
    146132}
     
    155141}
    156142
    157 void AlignofExpr::print( std::ostream &os, int indent) const {
     143void AlignofExpr::print( std::ostream &os, Indenter indent) const {
    158144        os << "Alignof Expression on: ";
    159 
    160         if (isType)
    161                 type->print(os, indent + 2);
    162         else
    163                 expr->print(os, indent + 2);
    164 
    165         os << std::endl;
    166         Expression::print( os, indent );
    167 }
    168 
    169 UntypedOffsetofExpr::UntypedOffsetofExpr( Type *type_, const std::string &member_, Expression *_aname ) :
    170                 Expression( _aname ), type(type_), member(member_) {
     145        if (isType) type->print(os, indent+1);
     146        else expr->print(os, indent+1);
     147        Expression::print( os, indent );
     148}
     149
     150UntypedOffsetofExpr::UntypedOffsetofExpr( Type *type, const std::string &member ) :
     151                Expression(), type(type), member(member) {
     152        assert( type );
    171153        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
    172154}
     
    179161}
    180162
    181 void UntypedOffsetofExpr::print( std::ostream &os, int indent) const {
    182         os << std::string( indent, ' ' ) << "Untyped Offsetof Expression on member " << member << " of ";
    183 
    184         if ( type ) {
    185                 type->print(os, indent + 2);
    186         } else {
    187                 os << "<NULL>";
    188         }
    189 
    190         os << std::endl;
    191         Expression::print( os, indent );
    192 }
    193 
    194 OffsetofExpr::OffsetofExpr( Type *type_, DeclarationWithType *member_, Expression *_aname ) :
    195                 Expression( _aname ), type(type_), member(member_) {
     163void UntypedOffsetofExpr::print( std::ostream &os, Indenter indent) const {
     164        os << "Untyped Offsetof Expression on member " << member << " of ";
     165        type->print(os, indent+1);
     166        Expression::print( os, indent );
     167}
     168
     169OffsetofExpr::OffsetofExpr( Type *type, DeclarationWithType *member ) :
     170                Expression(), type(type), member(member) {
     171        assert( member );
     172        assert( type );
    196173        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
    197174}
     
    204181}
    205182
    206 void OffsetofExpr::print( std::ostream &os, int indent) const {
    207         os << std::string( indent, ' ' ) << "Offsetof Expression on member ";
    208 
    209         if ( member ) {
    210                 os << member->get_name();
    211         } else {
    212                 os << "<NULL>";
    213         }
    214 
    215         os << " of ";
    216 
    217         if ( type ) {
    218                 type->print(os, indent + 2);
    219         } else {
    220                 os << "<NULL>";
    221         }
    222 
    223         os << std::endl;
    224         Expression::print( os, indent );
    225 }
    226 
    227 OffsetPackExpr::OffsetPackExpr( StructInstType *type_, Expression *aname_ ) : Expression( aname_ ), type( type_ ) {
     183void OffsetofExpr::print( std::ostream &os, Indenter indent) const {
     184        os << "Offsetof Expression on member " << member->name << " of ";
     185        type->print(os, indent+1);
     186        Expression::print( os, indent );
     187}
     188
     189OffsetPackExpr::OffsetPackExpr( StructInstType *type ) : Expression(), type( type ) {
     190        assert( type );
    228191        set_result( new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, false, false ) );
    229192}
     
    233196OffsetPackExpr::~OffsetPackExpr() { delete type; }
    234197
    235 void OffsetPackExpr::print( std::ostream &os, int indent ) const {
    236         os << std::string( indent, ' ' ) << "Offset pack expression on ";
    237 
    238         if ( type ) {
    239                 type->print(os, indent + 2);
    240         } else {
    241                 os << "<NULL>";
    242         }
    243 
    244         os << std::endl;
    245         Expression::print( os, indent );
    246 }
    247 
    248 AttrExpr::AttrExpr( Expression *attr, Expression *expr_, Expression *_aname ) :
    249                 Expression( _aname ), attr( attr ), expr(expr_), type(0), isType(false) {
    250 }
    251 
    252 AttrExpr::AttrExpr( Expression *attr, Type *type_, Expression *_aname ) :
    253                 Expression( _aname ), attr( attr ), expr(0), type(type_), isType(true) {
     198void OffsetPackExpr::print( std::ostream &os, Indenter indent ) const {
     199        os << "Offset pack expression on ";
     200        type->print(os, indent+1);
     201        Expression::print( os, indent );
     202}
     203
     204AttrExpr::AttrExpr( Expression *attr, Expression *expr_ ) :
     205                Expression(), attr( attr ), expr(expr_), type(0), isType(false) {
     206}
     207
     208AttrExpr::AttrExpr( Expression *attr, Type *type_ ) :
     209                Expression(), attr( attr ), expr(0), type(type_), isType(true) {
    254210}
    255211
     
    264220}
    265221
    266 void AttrExpr::print( std::ostream &os, int indent) const {
     222void AttrExpr::print( std::ostream &os, Indenter indent) const {
    267223        os << "Attr ";
    268         attr->print( os, indent + 2 );
     224        attr->print( os, indent+1);
    269225        if ( isType || expr ) {
    270226                os << "applied to: ";
    271 
    272                 if (isType)
    273                         type->print(os, indent + 2);
    274                 else
    275                         expr->print(os, indent + 2);
     227                if (isType) type->print(os, indent+1);
     228                else expr->print(os, indent+1);
    276229        } // if
    277 
    278         os << std::endl;
    279         Expression::print( os, indent );
    280 }
    281 
    282 CastExpr::CastExpr( Expression *arg_, Type *toType, Expression *_aname ) : Expression( _aname ), arg(arg_) {
     230        Expression::print( os, indent );
     231}
     232
     233CastExpr::CastExpr( Expression *arg_, Type *toType ) : Expression(), arg(arg_) {
    283234        set_result(toType);
    284235}
    285236
    286 CastExpr::CastExpr( Expression *arg_, Expression *_aname ) : Expression( _aname ), arg(arg_) {
     237CastExpr::CastExpr( Expression *arg_ ) : Expression(), arg(arg_) {
    287238        set_result( new VoidType( Type::Qualifiers() ) );
    288239}
     
    295246}
    296247
    297 void CastExpr::print( std::ostream &os, int indent ) const {
    298         os << "Cast of:" << std::endl << std::string( indent+2, ' ' );
    299         arg->print(os, indent+2);
    300         os << std::endl << std::string( indent, ' ' ) << "to:" << std::endl;
    301         os << std::string( indent+2, ' ' );
     248void CastExpr::print( std::ostream &os, Indenter indent ) const {
     249        os << "Cast of:" << std::endl << indent+1;
     250        arg->print(os, indent+1);
     251        os << std::endl << indent << "... to:";
    302252        if ( result->isVoid() ) {
    303                 os << "nothing";
     253                os << " nothing";
    304254        } else {
    305                 result->print( os, indent+2 );
     255                os << std::endl << indent+1;
     256                result->print( os, indent+1 );
    306257        } // if
    307         os << std::endl;
    308258        Expression::print( os, indent );
    309259}
     
    320270}
    321271
    322 void VirtualCastExpr::print( std::ostream &os, int indent ) const {
    323         os << "Virtual Cast of:" << std::endl << std::string( indent+2, ' ' );
    324         arg->print(os, indent+2);
    325         os << std::endl << std::string( indent, ' ' ) << "to:" << std::endl;
    326         os << std::string( indent+2, ' ' );
     272void VirtualCastExpr::print( std::ostream &os, Indenter indent ) const {
     273        os << "Virtual Cast of:" << std::endl << indent+1;
     274        arg->print(os, indent+1);
     275        os << std::endl << indent << "... to:";
    327276        if ( ! result ) {
    328                 os << "unknown";
     277                os << " unknown";
    329278        } else {
    330                 result->print( os, indent+2 );
     279                os << std::endl << indent+1;
     280                result->print( os, indent+1 );
    331281        } // if
    332         os << std::endl;
    333         Expression::print( os, indent );
    334 }
    335 
    336 UntypedMemberExpr::UntypedMemberExpr( Expression * _member, Expression *_aggregate, Expression *_aname ) :
    337                 Expression( _aname ), member(_member), aggregate(_aggregate) {}
     282        Expression::print( os, indent );
     283}
     284
     285UntypedMemberExpr::UntypedMemberExpr( Expression * member, Expression *aggregate ) :
     286                Expression(), member(member), aggregate(aggregate) {
     287        assert( aggregate );
     288}
    338289
    339290UntypedMemberExpr::UntypedMemberExpr( const UntypedMemberExpr &other ) :
     
    346297}
    347298
    348 void UntypedMemberExpr::print( std::ostream &os, int indent ) const {
    349         os << "Untyped Member Expression, with field: " << std::endl;
    350         os << std::string( indent+2, ' ' );
    351         get_member()->print(os, indent+4);
    352         os << std::string( indent+2, ' ' );
    353 
    354         Expression *agg = get_aggregate();
    355         os << "from aggregate: " << std::endl;
    356         if (agg != 0) {
    357                 os << std::string( indent + 4, ' ' );
    358                 agg->print(os, indent + 4);
    359         }
    360         os << std::string( indent+2, ' ' );
     299void UntypedMemberExpr::print( std::ostream &os, Indenter indent ) const {
     300        os << "Untyped Member Expression, with field: " << std::endl << indent+1;
     301        member->print(os, indent+1 );
     302        os << indent << "... from aggregate: " << std::endl << indent+1;
     303        aggregate->print(os, indent+1);
    361304        Expression::print( os, indent );
    362305}
     
    377320
    378321
    379 MemberExpr::MemberExpr( DeclarationWithType *_member, Expression *_aggregate, Expression *_aname ) :
    380                 Expression( _aname ), member(_member), aggregate(_aggregate) {
     322MemberExpr::MemberExpr( DeclarationWithType *member, Expression *aggregate ) :
     323                Expression(), member(member), aggregate(aggregate) {
     324        assert( member );
     325        assert( aggregate );
    381326
    382327        TypeSubstitution sub( makeSub( aggregate->get_result() ) );
     
    396341}
    397342
    398 void MemberExpr::print( std::ostream &os, int indent ) const {
     343void MemberExpr::print( std::ostream &os, Indenter indent ) const {
    399344        os << "Member Expression, with field: " << std::endl;
    400 
    401         assert( member );
    402         os << std::string( indent + 2, ' ' );
    403         member->print( os, indent + 2 );
    404         os << std::endl;
    405 
    406         Expression *agg = get_aggregate();
    407         os << std::string( indent, ' ' ) << "from aggregate: " << std::endl;
    408         if (agg != 0) {
    409                 os << std::string( indent + 2, ' ' );
    410                 agg->print(os, indent + 2);
    411         }
    412         os << std::string( indent+2, ' ' );
    413         Expression::print( os, indent );
    414 }
    415 
    416 UntypedExpr::UntypedExpr( Expression *_function, const std::list<Expression *> &_args, Expression *_aname ) :
    417                 Expression( _aname ), function(_function), args(_args) {}
     345        os << indent+1;
     346        member->print( os, indent+1 );
     347        os << std::endl << indent << "... from aggregate: " << std::endl << indent+1;
     348        aggregate->print(os, indent + 1);
     349        Expression::print( os, indent );
     350}
     351
     352UntypedExpr::UntypedExpr( Expression *function, const std::list<Expression *> &args ) :
     353                Expression(), function(function), args(args) {}
    418354
    419355UntypedExpr::UntypedExpr( const UntypedExpr &other ) :
     
    456392
    457393
    458 void UntypedExpr::print( std::ostream &os, int indent ) const {
     394void UntypedExpr::print( std::ostream &os, Indenter indent ) const {
    459395        os << "Applying untyped: " << std::endl;
    460         os << std::string( indent+2, ' ' );
    461         function->print(os, indent + 2);
    462         os << std::string( indent, ' ' ) << "...to: " << std::endl;
    463         printAll(args, os, indent + 2);
    464         Expression::print( os, indent );
    465 }
    466 
    467 void UntypedExpr::printArgs( std::ostream &os, int indent ) const {
    468         std::list<Expression *>::const_iterator i;
    469         for (i = args.begin(); i != args.end(); i++) {
    470                 os << std::string(indent, ' ' );
    471                 (*i)->print(os, indent);
    472         }
    473 }
    474 
    475 NameExpr::NameExpr( std::string _name, Expression *_aname ) : Expression( _aname ), name(_name) {
    476         assertf(_name != "0", "Zero is not a valid name\n");
    477         assertf(_name != "1", "One is not a valid name\n");
     396        os << indent+1;
     397        function->print(os, indent+1);
     398        os << std::endl << indent << "...to: " << std::endl;
     399        printAll(args, os, indent+1);
     400        Expression::print( os, indent );
     401}
     402
     403NameExpr::NameExpr( std::string name ) : Expression(), name(name) {
     404        assertf(name != "0", "Zero is not a valid name");
     405        assertf(name != "1", "One is not a valid name");
    478406}
    479407
     
    483411NameExpr::~NameExpr() {}
    484412
    485 void NameExpr::print( std::ostream &os, int indent ) const {
    486         os << "Name: " << get_name() << std::endl;
    487         Expression::print( os, indent );
    488 }
    489 
    490 LogicalExpr::LogicalExpr( Expression *arg1_, Expression *arg2_, bool andp, Expression *_aname ) :
    491                 Expression( _aname ), arg1(arg1_), arg2(arg2_), isAnd(andp) {
     413void NameExpr::print( std::ostream &os, Indenter indent ) const {
     414        os << "Name: " << get_name();
     415        Expression::print( os, indent );
     416}
     417
     418LogicalExpr::LogicalExpr( Expression *arg1_, Expression *arg2_, bool andp ) :
     419                Expression(), arg1(arg1_), arg2(arg2_), isAnd(andp) {
    492420        set_result( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) );
    493421}
     
    502430}
    503431
    504 void LogicalExpr::print( std::ostream &os, int indent )const {
    505         os << "Short-circuited operation (" << (isAnd?"and":"or") << ") on: ";
     432void LogicalExpr::print( std::ostream &os, Indenter indent )const {
     433        os << "Short-circuited operation (" << (isAnd ? "and" : "or") << ") on: ";
    506434        arg1->print(os);
    507435        os << " and ";
    508436        arg2->print(os);
    509         os << std::endl;
    510         Expression::print( os, indent );
    511 }
    512 
    513 ConditionalExpr::ConditionalExpr( Expression *arg1_, Expression *arg2_, Expression *arg3_, Expression *_aname ) :
    514                 Expression( _aname ), arg1(arg1_), arg2(arg2_), arg3(arg3_) {}
     437        Expression::print( os, indent );
     438}
     439
     440ConditionalExpr::ConditionalExpr( Expression * arg1, Expression * arg2, Expression * arg3 ) :
     441                Expression(), arg1(arg1), arg2(arg2), arg3(arg3) {}
    515442
    516443ConditionalExpr::ConditionalExpr( const ConditionalExpr &other ) :
     
    524451}
    525452
    526 void ConditionalExpr::print( std::ostream &os, int indent ) const {
    527         os << "Conditional expression on: " << std::endl;
    528         os << std::string( indent+2, ' ' );
    529         arg1->print( os, indent+2 );
    530         os << std::string( indent, ' ' ) << "First alternative:" << std::endl;
    531         os << std::string( indent+2, ' ' );
    532         arg2->print( os, indent+2 );
    533         os << std::string( indent, ' ' ) << "Second alternative:" << std::endl;
    534         os << std::string( indent+2, ' ' );
    535         arg3->print( os, indent+2 );
    536         os << std::endl;
     453void ConditionalExpr::print( std::ostream &os, Indenter indent ) const {
     454        os << "Conditional expression on: " << std::endl << indent+1;
     455        arg1->print( os, indent+1 );
     456        os << indent << "First alternative:" << std::endl << indent+1;
     457        arg2->print( os, indent+1 );
     458        os << indent << "Second alternative:" << std::endl << indent+1;
     459        arg3->print( os, indent+1 );
    537460        Expression::print( os, indent );
    538461}
     
    541464
    542465
    543 void AsmExpr::print( std::ostream &os, int indent ) const {
     466void AsmExpr::print( std::ostream &os, Indenter indent ) const {
    544467        os << "Asm Expression: " << std::endl;
    545         if ( inout ) inout->print( os, indent + 2 );
    546         if ( constraint ) constraint->print( os, indent + 2 );
    547         if ( operand ) operand->print( os, indent + 2 );
     468        if ( inout ) inout->print( os, indent+1 );
     469        if ( constraint ) constraint->print( os, indent+1 );
     470        if ( operand ) operand->print( os, indent+1 );
    548471}
    549472
     
    551474ImplicitCopyCtorExpr::ImplicitCopyCtorExpr( ApplicationExpr * callExpr ) : callExpr( callExpr ) {
    552475        assert( callExpr );
    553         assert( callExpr->has_result() );
     476        assert( callExpr->result );
    554477        set_result( callExpr->get_result()->clone() );
    555478}
     
    569492}
    570493
    571 void ImplicitCopyCtorExpr::print( std::ostream &os, int indent ) const {
    572         os <<  "Implicit Copy Constructor Expression: " << std::endl;
    573         assert( callExpr );
    574         os << std::string( indent+2, ' ' );
    575         callExpr->print( os, indent + 2 );
    576         os << std::endl << std::string( indent, ' ' ) << "with temporaries:" << std::endl;
    577         printAll(tempDecls, os, indent+2);
    578         os << std::endl << std::string( indent, ' ' ) << "with return temporaries:" << std::endl;
    579         printAll(returnDecls, os, indent+2);
     494void ImplicitCopyCtorExpr::print( std::ostream &os, Indenter indent ) const {
     495        os <<  "Implicit Copy Constructor Expression: " << std::endl << indent+1;
     496        callExpr->print( os, indent+1 );
     497        os << std::endl << indent << "... with temporaries:" << std::endl;
     498        printAll( tempDecls, os, indent+1 );
     499        os << std::endl << indent << "... with return temporaries:" << std::endl;
     500        printAll( returnDecls, os, indent+1 );
    580501        Expression::print( os, indent );
    581502}
     
    587508        Expression * arg = InitTweak::getCallArg( callExpr, 0 );
    588509        assert( arg );
    589         set_result( maybeClone( arg->get_result() ) );
     510        set_result( maybeClone( arg->result ) );
    590511}
    591512
     
    597518}
    598519
    599 void ConstructorExpr::print( std::ostream &os, int indent ) const {
    600         os <<  "Constructor Expression: " << std::endl;
    601         assert( callExpr );
    602         os << std::string( indent+2, ' ' );
     520void ConstructorExpr::print( std::ostream &os, Indenter indent ) const {
     521        os <<  "Constructor Expression: " << std::endl << indent+1;
    603522        callExpr->print( os, indent + 2 );
    604523        Expression::print( os, indent );
     
    618537}
    619538
    620 void CompoundLiteralExpr::print( std::ostream &os, int indent ) const {
    621         os << "Compound Literal Expression: " << std::endl;
    622         os << std::string( indent+2, ' ' );
    623         get_result()->print( os, indent + 2 );
    624         os << std::string( indent+2, ' ' );
    625         initializer->print( os, indent + 2 );
     539void CompoundLiteralExpr::print( std::ostream &os, Indenter indent ) const {
     540        os << "Compound Literal Expression: " << std::endl << indent+1;
     541        result->print( os, indent+1 );
     542        os << indent+1;
     543        initializer->print( os, indent+1 );
    626544        Expression::print( os, indent );
    627545}
     
    629547RangeExpr::RangeExpr( Expression *low, Expression *high ) : low( low ), high( high ) {}
    630548RangeExpr::RangeExpr( const RangeExpr &other ) : Expression( other ), low( other.low->clone() ), high( other.high->clone() ) {}
    631 void RangeExpr::print( std::ostream &os, int indent ) const {
     549void RangeExpr::print( std::ostream &os, Indenter indent ) const {
    632550        os << "Range Expression: ";
    633551        low->print( os, indent );
     
    659577        deleteAll( returnDecls );
    660578}
    661 void StmtExpr::print( std::ostream &os, int indent ) const {
    662         os << "Statement Expression: " << std::endl << std::string( indent, ' ' );
    663         statements->print( os, indent+2 );
     579void StmtExpr::print( std::ostream &os, Indenter indent ) const {
     580        os << "Statement Expression: " << std::endl << indent+1;
     581        statements->print( os, indent+1 );
    664582        if ( ! returnDecls.empty() ) {
    665                 os << std::string( indent+2, ' ' ) << "with returnDecls: ";
    666                 printAll( returnDecls, os, indent+2 );
     583                os << indent+1 << "... with returnDecls: ";
     584                printAll( returnDecls, os, indent+1 );
    667585        }
    668586        if ( ! dtors.empty() ) {
    669                 os << std::string( indent+2, ' ' ) << "with dtors: ";
    670                 printAll( dtors, os, indent+2 );
     587                os << indent+1 << "... with dtors: ";
     588                printAll( dtors, os, indent+1 );
    671589        }
    672590        Expression::print( os, indent );
     
    690608        delete var;
    691609}
    692 void UniqueExpr::print( std::ostream &os, int indent ) const {
    693         os << "Unique Expression with id:" << id << std::endl << std::string( indent+2, ' ' );
    694         get_expr()->print( os, indent+2 );
    695         if ( get_object() ) {
    696                 os << std::string( indent+2, ' ' ) << "with decl: ";
    697                 get_object()->printShort( os, indent+2 );
     610void UniqueExpr::print( std::ostream &os, Indenter indent ) const {
     611        os << "Unique Expression with id:" << id << std::endl << indent+1;
     612        expr->print( os, indent+1 );
     613        if ( object ) {
     614                os << indent << "... with decl: ";
     615                get_object()->printShort( os, indent+1 );
    698616        }
    699617        Expression::print( os, indent );
     
    713631}
    714632
    715 void UntypedInitExpr::print( std::ostream & os, int indent ) const {
    716         os << "Untyped Init Expression" << std::endl << std::string( indent+2, ' ' );
    717         expr->print( os, indent+2 );
     633void UntypedInitExpr::print( std::ostream & os, Indenter indent ) const {
     634        os << "Untyped Init Expression" << std::endl << indent+1;
     635        expr->print( os, indent+1 );
    718636        if ( ! initAlts.empty() ) {
    719637                for ( const InitAlternative & alt : initAlts ) {
    720                         os << std::string( indent+2, ' ' ) <<  "InitAlternative: ";
    721                         alt.type->print( os, indent+2 );
    722                         alt.designation->print( os, indent+2 );
     638                        os << indent+1 <<  "InitAlternative: ";
     639                        alt.type->print( os, indent+1 );
     640                        alt.designation->print( os, indent+1 );
    723641                }
    724642        }
     
    734652}
    735653
    736 void InitExpr::print( std::ostream & os, int indent ) const {
    737         os << "Init Expression" << std::endl << std::string( indent+2, ' ' );
    738         expr->print( os, indent+2 );
    739         os << std::string( indent+2, ' ' ) << "with designation: ";
    740         designation->print( os, indent+2 );
     654void InitExpr::print( std::ostream & os, Indenter indent ) const {
     655        os << "Init Expression" << std::endl << indent+1;
     656        expr->print( os, indent+1 );
     657        os << indent+1 << "... with designation: ";
     658        designation->print( os, indent+1 );
    741659}
    742660
  • src/SynTree/Expression.h

    rb96ec83 r6840e7c  
    3636        Type * result;
    3737        TypeSubstitution * env;
    38         Expression * argName; // if expression is used as an argument, it can be "designated" by this name
    3938        bool extension = false;
    4039
    41         Expression( Expression * _aname = nullptr );
     40        Expression();
    4241        Expression( const Expression & other );
    4342        virtual ~Expression();
     
    4645        const Type * get_result() const { return result; }
    4746        void set_result( Type * newValue ) { result = newValue; }
    48         bool has_result() const { return result != nullptr; }
    4947
    5048        TypeSubstitution * get_env() const { return env; }
    5149        void set_env( TypeSubstitution * newValue ) { env = newValue; }
    52         Expression * get_argName() const { return argName; }
    53         void set_argName( Expression * name ) { argName = name; }
    5450        bool get_extension() const { return extension; }
    5551        Expression * set_extension( bool exten ) { extension = exten; return this; }
    5652
    57         virtual Expression * clone() const = 0;
    58         virtual void accept( Visitor & v ) = 0;
    59         virtual Expression * acceptMutator( Mutator & m ) = 0;
    60         virtual void print( std::ostream & os, int indent = 0 ) const;
     53        virtual Expression * clone() const override = 0;
     54        virtual void accept( Visitor & v ) override = 0;
     55        virtual Expression * acceptMutator( Mutator & m ) override = 0;
     56        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    6157};
    6258
     
    10197        virtual void accept( Visitor & v ) { v.visit( this ); }
    10298        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    103         virtual void print( std::ostream & os, int indent = 0 ) const;
     99        virtual void print( std::ostream & os, Indenter indent = {} ) const;
    104100};
    105101
     
    112108        std::list<Expression*> args;
    113109
    114         UntypedExpr( Expression * function, const std::list<Expression *> & args = std::list< Expression * >(), Expression *_aname = nullptr );
     110        UntypedExpr( Expression * function, const std::list<Expression *> & args = std::list< Expression * >() );
    115111        UntypedExpr( const UntypedExpr & other );
    116112        virtual ~UntypedExpr();
     
    119115        void set_function( Expression * newValue ) { function = newValue; }
    120116
    121         void set_args( std::list<Expression *> & listArgs ) { args = listArgs; }
    122117        std::list<Expression*>::iterator begin_args() { return args.begin(); }
    123118        std::list<Expression*>::iterator end_args() { return args.end(); }
     
    130125        virtual void accept( Visitor & v ) { v.visit( this ); }
    131126        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    132         virtual void print( std::ostream & os, int indent = 0 ) const;
    133         virtual void printArgs(std::ostream & os, int indent = 0) const;
     127        virtual void print( std::ostream & os, Indenter indent = {} ) const;
    134128};
    135129
     
    139133        std::string name;
    140134
    141         NameExpr( std::string name, Expression *_aname = nullptr );
     135        NameExpr( std::string name );
    142136        NameExpr( const NameExpr & other );
    143137        virtual ~NameExpr();
     
    149143        virtual void accept( Visitor & v ) { v.visit( this ); }
    150144        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    151         virtual void print( std::ostream & os, int indent = 0 ) const;
     145        virtual void print( std::ostream & os, Indenter indent = {} ) const;
    152146};
    153147
     
    160154        Expression * arg;
    161155
    162         AddressExpr( Expression * arg, Expression *_aname = nullptr );
     156        AddressExpr( Expression * arg );
    163157        AddressExpr( const AddressExpr & other );
    164158        virtual ~AddressExpr();
     
    170164        virtual void accept( Visitor & v ) { v.visit( this ); }
    171165        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    172         virtual void print( std::ostream & os, int indent = 0 ) const;
     166        virtual void print( std::ostream & os, Indenter indent = {} ) const;
    173167};
    174168
     
    186180        virtual void accept( Visitor & v ) { v.visit( this ); }
    187181        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    188         virtual void print( std::ostream & os, int indent = 0 ) const;
     182        virtual void print( std::ostream & os, Indenter indent = {} ) const;
    189183};
    190184
     
    194188        Expression * arg;
    195189
    196         CastExpr( Expression * arg, Expression *_aname = nullptr );
    197         CastExpr( Expression * arg, Type * toType, Expression *_aname = nullptr );
     190        CastExpr( Expression * arg );
     191        CastExpr( Expression * arg, Type * toType );
    198192        CastExpr( const CastExpr & other );
    199193        virtual ~CastExpr();
     
    205199        virtual void accept( Visitor & v ) { v.visit( this ); }
    206200        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    207         virtual void print( std::ostream & os, int indent = 0 ) const;
     201        virtual void print( std::ostream & os, Indenter indent = {} ) const;
    208202};
    209203
     
    223217        virtual void accept( Visitor & v ) { v.visit( this ); }
    224218        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    225         virtual void print( std::ostream & os, int indent = 0 ) const;
     219        virtual void print( std::ostream & os, Indenter indent = {} ) const;
    226220};
    227221
     
    232226        Expression * aggregate;
    233227
    234         UntypedMemberExpr( Expression * member, Expression * aggregate, Expression *_aname = nullptr );
     228        UntypedMemberExpr( Expression * member, Expression * aggregate );
    235229        UntypedMemberExpr( const UntypedMemberExpr & other );
    236230        virtual ~UntypedMemberExpr();
     
    244238        virtual void accept( Visitor & v ) { v.visit( this ); }
    245239        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    246         virtual void print( std::ostream & os, int indent = 0 ) const;
     240        virtual void print( std::ostream & os, Indenter indent = {} ) const;
    247241};
    248242
     
    254248        Expression * aggregate;
    255249
    256         MemberExpr( DeclarationWithType * member, Expression * aggregate, Expression *_aname = nullptr );
     250        MemberExpr( DeclarationWithType * member, Expression * aggregate );
    257251        MemberExpr( const MemberExpr & other );
    258252        virtual ~MemberExpr();
     
    266260        virtual void accept( Visitor & v ) { v.visit( this ); }
    267261        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    268         virtual void print( std::ostream & os, int indent = 0 ) const;
     262        virtual void print( std::ostream & os, Indenter indent = {} ) const;
    269263};
    270264
     
    275269        DeclarationWithType * var;
    276270
    277         VariableExpr( DeclarationWithType * var, Expression *_aname = nullptr );
     271        VariableExpr( DeclarationWithType * var );
    278272        VariableExpr( const VariableExpr & other );
    279273        virtual ~VariableExpr();
     
    287281        virtual void accept( Visitor & v ) { v.visit( this ); }
    288282        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    289         virtual void print( std::ostream & os, int indent = 0 ) const;
     283        virtual void print( std::ostream & os, Indenter indent = {} ) const;
    290284};
    291285
     
    295289        Constant constant;
    296290
    297         ConstantExpr( Constant constant, Expression *_aname = nullptr );
     291        ConstantExpr( Constant constant );
    298292        ConstantExpr( const ConstantExpr & other );
    299293        virtual ~ConstantExpr();
     
    305299        virtual void accept( Visitor & v ) { v.visit( this ); }
    306300        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    307         virtual void print( std::ostream & os, int indent = 0 ) const;
     301        virtual void print( std::ostream & os, Indenter indent = {} ) const;
    308302};
    309303
     
    315309        bool isType;
    316310
    317         SizeofExpr( Expression * expr, Expression *_aname = nullptr );
     311        SizeofExpr( Expression * expr );
    318312        SizeofExpr( const SizeofExpr & other );
    319         SizeofExpr( Type * type, Expression *_aname = nullptr );
     313        SizeofExpr( Type * type );
    320314        virtual ~SizeofExpr();
    321315
     
    330324        virtual void accept( Visitor & v ) { v.visit( this ); }
    331325        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    332         virtual void print( std::ostream & os, int indent = 0 ) const;
     326        virtual void print( std::ostream & os, Indenter indent = {} ) const;
    333327};
    334328
     
    340334        bool isType;
    341335
    342         AlignofExpr( Expression * expr, Expression *_aname = nullptr );
     336        AlignofExpr( Expression * expr );
    343337        AlignofExpr( const AlignofExpr & other );
    344         AlignofExpr( Type * type, Expression *_aname = nullptr );
     338        AlignofExpr( Type * type );
    345339        virtual ~AlignofExpr();
    346340
     
    355349        virtual void accept( Visitor & v ) { v.visit( this ); }
    356350        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    357         virtual void print( std::ostream & os, int indent = 0 ) const;
     351        virtual void print( std::ostream & os, Indenter indent = {} ) const;
    358352};
    359353
     
    364358        std::string member;
    365359
    366         UntypedOffsetofExpr( Type * type, const std::string & member, Expression *_aname = nullptr );
     360        UntypedOffsetofExpr( Type * type, const std::string & member );
    367361        UntypedOffsetofExpr( const UntypedOffsetofExpr & other );
    368362        virtual ~UntypedOffsetofExpr();
     
    376370        virtual void accept( Visitor & v ) { v.visit( this ); }
    377371        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    378         virtual void print( std::ostream & os, int indent = 0 ) const;
     372        virtual void print( std::ostream & os, Indenter indent = {} ) const;
    379373};
    380374
     
    385379        DeclarationWithType * member;
    386380
    387         OffsetofExpr( Type * type, DeclarationWithType * member, Expression *_aname = nullptr );
     381        OffsetofExpr( Type * type, DeclarationWithType * member );
    388382        OffsetofExpr( const OffsetofExpr & other );
    389383        virtual ~OffsetofExpr();
     
    397391        virtual void accept( Visitor & v ) { v.visit( this ); }
    398392        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    399         virtual void print( std::ostream & os, int indent = 0 ) const;
     393        virtual void print( std::ostream & os, Indenter indent = {} ) const;
    400394};
    401395
     
    405399        StructInstType * type;
    406400
    407         OffsetPackExpr( StructInstType * type_, Expression * aname_ = 0 );
     401        OffsetPackExpr( StructInstType * type );
    408402        OffsetPackExpr( const OffsetPackExpr & other );
    409403        virtual ~OffsetPackExpr();
     
    415409        virtual void accept( Visitor & v ) { v.visit( this ); }
    416410        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    417         virtual void print( std::ostream & os, int indent = 0 ) const;
     411        virtual void print( std::ostream & os, Indenter indent = {} ) const;
    418412};
    419413
     
    426420        bool isType;
    427421
    428         AttrExpr(Expression * attr, Expression * expr, Expression *_aname = nullptr );
     422        AttrExpr(Expression * attr, Expression * expr );
    429423        AttrExpr( const AttrExpr & other );
    430         AttrExpr( Expression * attr, Type * type, Expression *_aname = nullptr );
     424        AttrExpr( Expression * attr, Type * type );
    431425        virtual ~AttrExpr();
    432426
     
    443437        virtual void accept( Visitor & v ) { v.visit( this ); }
    444438        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    445         virtual void print( std::ostream & os, int indent = 0 ) const;
     439        virtual void print( std::ostream & os, Indenter indent = {} ) const;
    446440};
    447441
     
    452446        Expression * arg2;
    453447
    454         LogicalExpr( Expression * arg1, Expression * arg2, bool andp = true, Expression *_aname = nullptr );
     448        LogicalExpr( Expression * arg1, Expression * arg2, bool andp = true );
    455449        LogicalExpr( const LogicalExpr & other );
    456450        virtual ~LogicalExpr();
     
    465459        virtual void accept( Visitor & v ) { v.visit( this ); }
    466460        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    467         virtual void print( std::ostream & os, int indent = 0 ) const;
     461        virtual void print( std::ostream & os, Indenter indent = {} ) const;
    468462
    469463  private:
     
    478472        Expression * arg3;
    479473
    480         ConditionalExpr( Expression * arg1, Expression * arg2, Expression * arg3, Expression *_aname = nullptr );
     474        ConditionalExpr( Expression * arg1, Expression * arg2, Expression * arg3 );
    481475        ConditionalExpr( const ConditionalExpr & other );
    482476        virtual ~ConditionalExpr();
     
    492486        virtual void accept( Visitor & v ) { v.visit( this ); }
    493487        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    494         virtual void print( std::ostream & os, int indent = 0 ) const;
     488        virtual void print( std::ostream & os, Indenter indent = {} ) const;
    495489};
    496490
     
    501495        Expression * arg2;
    502496
    503         CommaExpr( Expression * arg1, Expression * arg2, Expression *_aname = nullptr );
     497        CommaExpr( Expression * arg1, Expression * arg2 );
    504498        CommaExpr( const CommaExpr & other );
    505499        virtual ~CommaExpr();
     
    513507        virtual void accept( Visitor & v ) { v.visit( this ); }
    514508        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    515         virtual void print( std::ostream & os, int indent = 0 ) const;
     509        virtual void print( std::ostream & os, Indenter indent = {} ) const;
    516510};
    517511
     
    531525        virtual void accept( Visitor & v ) { v.visit( this ); }
    532526        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    533         virtual void print( std::ostream & os, int indent = 0 ) const;
     527        virtual void print( std::ostream & os, Indenter indent = {} ) const;
    534528};
    535529
     
    557551        virtual void accept( Visitor & v ) { v.visit( this ); }
    558552        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    559         virtual void print( std::ostream & os, int indent = 0 ) const;
     553        virtual void print( std::ostream & os, Indenter indent = {} ) const;
    560554
    561555        // https://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Machine-Constraints.html#Machine-Constraints
     
    585579        virtual void accept( Visitor & v ) { v.visit( this ); }
    586580        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    587         virtual void print( std::ostream & os, int indent = 0 ) const;
     581        virtual void print( std::ostream & os, Indenter indent = {} ) const;
    588582};
    589583
     
    603597        virtual void accept( Visitor & v ) { v.visit( this ); }
    604598        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    605         virtual void print( std::ostream & os, int indent = 0 ) const;
     599        virtual void print( std::ostream & os, Indenter indent = {} ) const;
    606600};
    607601
     
    621615        virtual void accept( Visitor & v ) { v.visit( this ); }
    622616        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    623         virtual void print( std::ostream & os, int indent = 0 ) const;
     617        virtual void print( std::ostream & os, Indenter indent = {} ) const;
    624618};
    625619
     
    640634        virtual void accept( Visitor & v ) { v.visit( this ); }
    641635        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    642         virtual void print( std::ostream & os, int indent = 0 ) const;
     636        virtual void print( std::ostream & os, Indenter indent = {} ) const;
    643637};
    644638
     
    648642        std::list<Expression*> exprs;
    649643
    650         UntypedTupleExpr( const std::list< Expression * > & exprs, Expression *_aname = nullptr );
     644        UntypedTupleExpr( const std::list< Expression * > & exprs );
    651645        UntypedTupleExpr( const UntypedTupleExpr & other );
    652646        virtual ~UntypedTupleExpr();
     
    657651        virtual void accept( Visitor & v ) { v.visit( this ); }
    658652        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    659         virtual void print( std::ostream & os, int indent = 0 ) const;
     653        virtual void print( std::ostream & os, Indenter indent = {} ) const;
    660654};
    661655
     
    665659        std::list<Expression*> exprs;
    666660
    667         TupleExpr( const std::list< Expression * > & exprs, Expression *_aname = nullptr );
     661        TupleExpr( const std::list< Expression * > & exprs );
    668662        TupleExpr( const TupleExpr & other );
    669663        virtual ~TupleExpr();
     
    674668        virtual void accept( Visitor & v ) { v.visit( this ); }
    675669        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    676         virtual void print( std::ostream & os, int indent = 0 ) const;
     670        virtual void print( std::ostream & os, Indenter indent = {} ) const;
    677671};
    678672
     
    695689        virtual void accept( Visitor & v ) { v.visit( this ); }
    696690        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    697         virtual void print( std::ostream & os, int indent = 0 ) const;
     691        virtual void print( std::ostream & os, Indenter indent = {} ) const;
    698692};
    699693
     
    703697        StmtExpr * stmtExpr = nullptr;
    704698
    705         TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls, Expression * _aname = nullptr );
     699        TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls );
    706700        TupleAssignExpr( const TupleAssignExpr & other );
    707701        virtual ~TupleAssignExpr();
     
    713707        virtual void accept( Visitor & v ) { v.visit( this ); }
    714708        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    715         virtual void print( std::ostream & os, int indent = 0 ) const;
     709        virtual void print( std::ostream & os, Indenter indent = {} ) const;
    716710};
    717711
     
    736730        virtual void accept( Visitor & v ) { v.visit( this ); }
    737731        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    738         virtual void print( std::ostream & os, int indent = 0 ) const;
     732        virtual void print( std::ostream & os, Indenter indent = {} ) const;
    739733};
    740734
     
    763757        virtual void accept( Visitor & v ) { v.visit( this ); }
    764758        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    765         virtual void print( std::ostream & os, int indent = 0 ) const;
     759        virtual void print( std::ostream & os, Indenter indent = {} ) const;
    766760
    767761private:
     
    797791        virtual void accept( Visitor & v ) { v.visit( this ); }
    798792        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    799         virtual void print( std::ostream & os, int indent = 0 ) const;
     793        virtual void print( std::ostream & os, Indenter indent = {} ) const;
    800794};
    801795
     
    818812        virtual void accept( Visitor & v ) { v.visit( this ); }
    819813        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    820         virtual void print( std::ostream & os, int indent = 0 ) const;
     814        virtual void print( std::ostream & os, Indenter indent = {} ) const;
    821815};
    822816
  • src/SynTree/FunctionDecl.cc

    rb96ec83 r6840e7c  
    6363}
    6464
    65 void FunctionDecl::print( std::ostream &os, int indent ) const {
     65void FunctionDecl::print( std::ostream &os, Indenter indent ) const {
    6666        using std::endl;
    6767        using std::string;
    6868
    69         if ( get_name() != "" ) {
    70                 os << get_name() << ": ";
     69        if ( name != "" ) {
     70                os << name << ": ";
    7171        } // if
    72         if ( get_linkage() != LinkageSpec::Cforall ) {
    73                 os << LinkageSpec::linkageName( get_linkage() ) << " ";
     72        if ( linkage != LinkageSpec::Cforall ) {
     73                os << LinkageSpec::linkageName( linkage ) << " ";
    7474        } // if
    7575
    76         printAll( get_attributes(), os, indent );
     76        printAll( attributes, os, indent );
    7777
    7878        get_storageClasses().print( os );
    7979        get_funcSpec().print( os );
    8080
    81         if ( get_type() ) {
    82                 get_type()->print( os, indent );
     81        if ( type ) {
     82                type->print( os, indent );
    8383        } else {
    8484                os << "untyped entity ";
     
    8686
    8787        if ( statements ) {
    88                 os << string( indent + 2, ' ' ) << "with body " << endl;
    89                 os << string( indent + 4, ' ' );
    90                 statements->print( os, indent + 4 );
     88                os << indent << "... with body " << endl << indent+1;
     89                statements->print( os, indent+1 );
    9190        } // if
    9291}
    9392
    94 void FunctionDecl::printShort( std::ostream &os, int indent ) const {
     93void FunctionDecl::printShort( std::ostream &os, Indenter indent ) const {
    9594        using std::endl;
    9695        using std::string;
    9796
    98         if ( get_name() != "" ) {
    99                 os << get_name() << ": ";
     97        if ( name != "" ) {
     98                os << name << ": ";
    10099        } // if
    101 
    102         // xxx - should printShort print attributes?
    103100
    104101        get_storageClasses().print( os );
    105102        get_funcSpec().print( os );
    106103
    107         if ( get_type() ) {
    108                 get_type()->print( os, indent );
     104        if ( type ) {
     105                type->print( os, indent );
    109106        } else {
    110107                os << "untyped entity ";
  • src/SynTree/FunctionType.cc

    rb96ec83 r6840e7c  
    5151}
    5252
    53 void FunctionType::print( std::ostream &os, int indent ) const {
     53void FunctionType::print( std::ostream &os, Indenter indent ) const {
    5454        using std::string;
    5555        using std::endl;
     
    5858        os << "function" << endl;
    5959        if ( ! parameters.empty() ) {
    60                 os << string( indent + 2, ' ' ) << "with parameters" << endl;
    61                 printAll( parameters, os, indent + 4 );
     60                os << indent << "... with parameters" << endl;
     61                printAll( parameters, os, indent+1 );
    6262                if ( isVarArgs ) {
    63                         os << string( indent + 4, ' ' ) << "and a variable number of other arguments" << endl;
     63                        os << indent+1 << "and a variable number of other arguments" << endl;
    6464                } // if
    6565        } else if ( isVarArgs ) {
    66                 os << string( indent + 4, ' ' ) << "accepting unspecified arguments" << endl;
     66                os << indent+1 << "accepting unspecified arguments" << endl;
    6767        } // if
    68         os << string( indent + 2, ' ' ) << "returning ";
     68        os << indent << "... returning ";
    6969        if ( returnVals.empty() ) {
    70                 os << endl << string( indent + 4, ' ' ) << "nothing " << endl;
     70                os << "nothing " << endl;
    7171        } else {
    7272                os << endl;
    73                 printAll( returnVals, os, indent + 4 );
     73                printAll( returnVals, os, indent+1 );
    7474        } // if
    7575}
  • src/SynTree/Initializer.cc

    rb96ec83 r6840e7c  
    3838}
    3939
    40 void Designation::print( std::ostream &os, int indent ) const {
     40void Designation::print( std::ostream &os, Indenter indent ) const {
    4141        if ( ! designators.empty() ) {
    42                 os << std::string(indent + 2, ' ' ) << "designated by: " << std::endl;
    43                 for ( std::list < Expression * >::const_iterator i = designators.begin(); i != designators.end(); i++ ) {
    44                         os << std::string(indent + 4, ' ' );
    45                         ( *i )->print(os, indent + 4 );
     42                os << "... designated by: " << std::endl;
     43                for ( const Expression * d : designators ) {
     44                        os << indent+1;
     45                        d->print(os, indent+1 );
     46                        os << std::endl;
    4647                }
    47                 os << std::endl;
    4848        } // if
    4949}
     
    6464}
    6565
    66 void SingleInit::print( std::ostream &os, int indent ) const {
    67         os << std::string(indent, ' ' ) << "Simple Initializer: " << std::endl;
    68         os << std::string(indent+4, ' ' );
    69         value->print( os, indent+4 );
     66void SingleInit::print( std::ostream &os, Indenter indent ) const {
     67        os << "Simple Initializer: ";
     68        value->print( os, indent );
    7069}
    7170
     
    9392}
    9493
    95 void ListInit::print( std::ostream &os, int indent ) const {
    96         os << std::string(indent, ' ') << "Compound initializer:  " << std::endl;
    97         for ( Designation * d : designations ) {
    98                 d->print( os, indent + 2 );
    99         }
    100 
    101         for ( const Initializer * init : initializers ) {
    102                 init->print( os, indent + 2 );
     94void ListInit::print( std::ostream &os, Indenter indent ) const {
     95        os << "Compound initializer: " << std::endl;
     96        for ( auto p : group_iterate( designations, initializers ) ) {
     97                const Designation * d = std::get<0>(p);
     98                const Initializer * init = std::get<1>(p);
     99                os << indent+1;
     100                init->print( os, indent+1 );
    103101                os << std::endl;
     102                if ( ! d->designators.empty() ) {
     103                        os << indent+1;
     104                        d->print( os, indent+1 );
     105                }
    104106        }
    105107}
     
    116118}
    117119
    118 void ConstructorInit::print( std::ostream &os, int indent ) const {
    119         os << std::endl << std::string(indent, ' ') << "Constructor initializer: " << std::endl;
     120void ConstructorInit::print( std::ostream &os, Indenter indent ) const {
     121        os << "Constructor initializer: " << std::endl;
    120122        if ( ctor ) {
    121                 os << std::string(indent+2, ' ');
    122                 os << "initially constructed with ";
    123                 ctor->print( os, indent+4 );
     123                os << indent << "... initially constructed with ";
     124                ctor->print( os, indent+1 );
    124125        } // if
    125126
    126127        if ( dtor ) {
    127                 os << std::string(indent+2, ' ');
    128                 os << "destructed with ";
    129                 dtor->print( os, indent+4 );
     128                os << indent << "... destructed with ";
     129                dtor->print( os, indent+1 );
    130130        }
    131131
    132132        if ( init ) {
    133                 os << std::string(indent+2, ' ');
    134                 os << "with fallback C-style initializer: ";
    135                 init->print( os, indent+4 );
     133                os << indent << "... with fallback C-style initializer: ";
     134                init->print( os, indent+1 );
    136135        }
    137136}
  • src/SynTree/Initializer.h

    rb96ec83 r6840e7c  
    3737        std::list< Expression * > & get_designators() { return designators; }
    3838
    39         virtual Designation * clone() const { return new Designation( *this ); };
     39        virtual Designation * clone() const override { return new Designation( *this ); };
    4040        virtual void accept( Visitor &v ) override { v.visit( this ); }
    41         virtual Designation * acceptMutator( Mutator &m ) { return m.mutate( this ); }
    42         virtual void print( std::ostream &os, int indent = 0 ) const override;
     41        virtual Designation * acceptMutator( Mutator &m ) override { return m.mutate( this ); }
     42        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    4343};
    4444
     
    5454        bool get_maybeConstructed() { return maybeConstructed; }
    5555
    56         virtual Initializer *clone() const = 0;
     56        virtual Initializer *clone() const override = 0;
    5757        virtual void accept( Visitor &v ) override = 0;
    58         virtual Initializer *acceptMutator( Mutator &m ) = 0;
    59         virtual void print( std::ostream &os, int indent = 0 ) const override = 0;
     58        virtual Initializer *acceptMutator( Mutator &m ) override = 0;
     59        virtual void print( std::ostream &os, Indenter indent = {} ) const override = 0;
    6060  private:
    6161        bool maybeConstructed;
     
    7878        virtual void accept( Visitor &v ) override { v.visit( this ); }
    7979        virtual Initializer *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    80         virtual void print( std::ostream &os, int indent = 0 ) const override;
     80        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    8181};
    8282
     
    106106        virtual void accept( Visitor &v ) override { v.visit( this ); }
    107107        virtual Initializer *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    108         virtual void print( std::ostream &os, int indent = 0 ) const override;
     108        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    109109};
    110110
     
    135135        virtual void accept( Visitor &v ) override { v.visit( this ); }
    136136        virtual Initializer *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    137         virtual void print( std::ostream &os, int indent = 0 ) const override;
     137        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    138138
    139139  private:
  • src/SynTree/Mutator.cc

    rb96ec83 r6840e7c  
    626626}
    627627
     628TypeSubstitution * Mutator::mutate( TypeSubstitution * sub ) {
     629        for ( auto & p : sub->typeEnv ) {
     630                p.second = maybeMutate( p.second, *this );
     631        }
     632        for ( auto & p : sub->varEnv ) {
     633                p.second = maybeMutate( p.second, *this );
     634        }
     635        return sub;
     636}
     637
    628638// Local Variables: //
    629639// tab-width: 4 //
  • src/SynTree/Mutator.h

    rb96ec83 r6840e7c  
    117117
    118118        virtual Attribute * mutate( Attribute * attribute );
     119
     120        virtual TypeSubstitution * mutate( TypeSubstitution * sub );
     121
    119122  private:
    120123        virtual Declaration * handleAggregateDecl(AggregateDecl * aggregateDecl );
  • src/SynTree/NamedTypeDecl.cc

    rb96ec83 r6840e7c  
    3838}
    3939
    40 void NamedTypeDecl::print( std::ostream &os, int indent ) const {
     40void NamedTypeDecl::print( std::ostream &os, Indenter indent ) const {
    4141        using namespace std;
    4242
    43         if ( get_name() != "" ) {
    44                 os << get_name() << ": ";
    45         } // if
    46         if ( get_linkage() != LinkageSpec::Cforall ) {
    47                 os << LinkageSpec::linkageName( get_linkage() ) << " ";
     43        if ( name != "" ) os << name << ": ";
     44
     45        if ( linkage != LinkageSpec::Cforall ) {
     46                os << LinkageSpec::linkageName( linkage ) << " ";
    4847        } // if
    4948        get_storageClasses().print( os );
     
    5150        if ( base ) {
    5251                os << " for ";
    53                 base->print( os, indent );
     52                base->print( os, indent+1 );
    5453        } // if
    5554        if ( ! parameters.empty() ) {
    56                 os << endl << string( indent, ' ' ) << "with parameters" << endl;
    57                 printAll( parameters, os, indent+2 );
     55                os << endl << indent << "... with parameters" << endl;
     56                printAll( parameters, os, indent+1 );
    5857        } // if
    5958        if ( ! assertions.empty() ) {
    60                 os << endl << string( indent, ' ' ) << "with assertions" << endl;
    61                 printAll( assertions, os, indent+2 );
     59                os << endl << indent << "... with assertions" << endl;
     60                printAll( assertions, os, indent+1 );
    6261        } // if
    6362}
    6463
    65 void NamedTypeDecl::printShort( std::ostream &os, int indent ) const {
     64void NamedTypeDecl::printShort( std::ostream &os, Indenter indent ) const {
    6665        using namespace std;
    6766
    68         if ( get_name() != "" ) {
    69                 os << get_name() << ": ";
    70         } // if
     67        if ( name != "" ) os << name << ": ";
    7168        get_storageClasses().print( os );
    7269        os << typeString();
    7370        if ( base ) {
    7471                os << " for ";
    75                 base->print( os, indent );
     72                base->print( os, indent+1 );
    7673        } // if
    7774        if ( ! parameters.empty() ) {
    78                 os << endl << string( indent, ' ' ) << "with parameters" << endl;
    79                 printAll( parameters, os, indent+2 );
     75                os << endl << indent << "... with parameters" << endl;
     76                printAll( parameters, os, indent+1 );
    8077        } // if
    8178}
  • src/SynTree/ObjectDecl.cc

    rb96ec83 r6840e7c  
    4444}
    4545
    46 void ObjectDecl::print( std::ostream &os, int indent ) const {
    47         if ( get_name() != "" ) {
    48                 os << get_name() << ": ";
     46void ObjectDecl::print( std::ostream &os, Indenter indent ) const {
     47        if ( name != "" ) os << name << ": ";
     48
     49        if ( linkage != LinkageSpec::Cforall ) {
     50                os << LinkageSpec::linkageName( linkage ) << " ";
    4951        } // if
    50 
    51         if ( get_linkage() != LinkageSpec::Cforall ) {
    52                 os << LinkageSpec::linkageName( get_linkage() ) << " ";
    53         } // if
    54 
    55         printAll( get_attributes(), os, indent );
    5652
    5753        get_storageClasses().print( os );
    5854
    59         if ( get_type() ) {
    60                 get_type()->print( os, indent );
     55        if ( type ) {
     56                type->print( os, indent );
    6157        } else {
    6258                os << " untyped entity ";
     
    6460
    6561        if ( init ) {
    66                 os << " with initializer " << std::endl;
    67                 init->print( os, indent+2 );
    68                 os << std::endl << std::string(indent+2, ' ');
    69                 os << "maybeConstructed? " << init->get_maybeConstructed();
     62                os << " with initializer (" << (init->get_maybeConstructed() ? "maybe constructed" : "not constructed") << ")" << std::endl << indent+1;
     63                init->print( os, indent+1 );
     64                os << std::endl;
    7065        } // if
    7166
     67        if ( ! attributes.empty() ) {
     68                os << std::endl << indent << "... with attributes: " << std::endl;
     69                printAll( attributes, os, indent+1 );
     70        }
     71
    7272        if ( bitfieldWidth ) {
    73                 os << std::string(indent, ' ');
    74                 os << " with bitfield width ";
     73                os << indent << " with bitfield width ";
    7574                bitfieldWidth->print( os );
    7675        } // if
    7776}
    7877
    79 void ObjectDecl::printShort( std::ostream &os, int indent ) const {
     78void ObjectDecl::printShort( std::ostream &os, Indenter indent ) const {
    8079#if 0
    8180        if ( get_mangleName() != "") {
     
    8382        } else
    8483#endif
    85         if ( get_name() != "" ) {
    86                 os << get_name() << ": ";
    87         } // if
    88 
    89         // xxx - should printShort print attributes?
     84        if ( name != "" ) os << name << ": ";
    9085
    9186        get_storageClasses().print( os );
    9287
    93         if ( get_type() ) {
    94                 get_type()->print( os, indent );
     88        if ( type ) {
     89                type->print( os, indent );
    9590        } else {
    9691                os << "untyped entity ";
  • src/SynTree/PointerType.cc

    rb96ec83 r6840e7c  
    4141}
    4242
    43 void PointerType::print( std::ostream &os, int indent ) const {
     43void PointerType::print( std::ostream &os, Indenter indent ) const {
    4444        Type::print( os, indent );
    4545        if ( ! is_array() ) {
  • src/SynTree/ReferenceToType.cc

    rb96ec83 r6840e7c  
    1414//
    1515
    16 #include <stddef.h>          // for NULL
    1716#include <cassert>           // for assert
    1817#include <list>              // for list, _List_const_iterator, list<>::cons...
     
    3837}
    3938
    40 void ReferenceToType::print( std::ostream &os, int indent ) const {
     39void ReferenceToType::print( std::ostream &os, Indenter indent ) const {
    4140        using std::endl;
    4241
     
    4443        os << "instance of " << typeString() << " " << name << " ";
    4544        if ( ! parameters.empty() ) {
    46                 os << endl << std::string( indent, ' ' ) << "with parameters" << endl;
    47                 printAll( parameters, os, indent+2 );
     45                os << endl << indent << "... with parameters" << endl;
     46                printAll( parameters, os, indent+1 );
    4847        } // if
    4948}
     
    6564
    6665std::list<TypeDecl*>* StructInstType::get_baseParameters() {
    67         if ( ! baseStruct ) return NULL;
     66        if ( ! baseStruct ) return nullptr;
    6867        return &baseStruct->get_parameters();
    6968}
     
    7675}
    7776
    78 void StructInstType::print( std::ostream &os, int indent ) const {
     77void StructInstType::print( std::ostream &os, Indenter indent ) const {
    7978        using std::endl;
    8079
    81         if ( baseStruct == NULL ) ReferenceToType::print( os, indent );
     80        if ( baseStruct == nullptr ) ReferenceToType::print( os, indent );
    8281        else {
    8382                Type::print( os, indent );
    8483                os << "instance of " << typeString() << " " << name << " with body " << baseStruct->has_body() << " ";
    8584                if ( ! parameters.empty() ) {
    86                         os << endl << std::string( indent, ' ' ) << "with parameters" << endl;
    87                         printAll( parameters, os, indent+2 );
     85                        os << endl << indent << "... with parameters" << endl;
     86                        printAll( parameters, os, indent+1 );
    8887                } // if
    8988        } // if
     
    9796
    9897std::list< TypeDecl * > * UnionInstType::get_baseParameters() {
    99         if ( ! baseUnion ) return NULL;
     98        if ( ! baseUnion ) return nullptr;
    10099        return &baseUnion->get_parameters();
    101100}
     
    108107}
    109108
    110 void UnionInstType::print( std::ostream &os, int indent ) const {
     109void UnionInstType::print( std::ostream &os, Indenter indent ) const {
    111110        using std::endl;
    112111
    113         if ( baseUnion == NULL ) ReferenceToType::print( os, indent );
     112        if ( baseUnion == nullptr ) ReferenceToType::print( os, indent );
    114113        else {
    115114                Type::print( os, indent );
    116115                os << "instance of " << typeString() << " " << name << " with body " << baseUnion->has_body() << " ";
    117116                if ( ! parameters.empty() ) {
    118                         os << endl << std::string( indent, ' ' ) << "with parameters" << endl;
    119                         printAll( parameters, os, indent+2 );
     117                        os << endl << indent << "... with parameters" << endl;
     118                        printAll( parameters, os, indent+1 );
    120119                } // if
    121120        } // if
     
    129128
    130129bool EnumInstType::isComplete() const { return baseEnum ? baseEnum->has_body() : false; }
     130
     131void EnumInstType::print( std::ostream &os, Indenter indent ) const {
     132        using std::endl;
     133
     134        if ( baseEnum == nullptr ) ReferenceToType::print( os, indent );
     135        else {
     136                Type::print( os, indent );
     137                os << "instance of " << typeString() << " " << name << " with body " << baseEnum->has_body() << " ";
     138        } // if
     139}
     140
    131141
    132142std::string TraitInstType::typeString() const { return "trait"; }
     
    166176bool TypeInstType::isComplete() const { return baseType->isComplete(); }
    167177
    168 void TypeInstType::print( std::ostream &os, int indent ) const {
     178void TypeInstType::print( std::ostream &os, Indenter indent ) const {
    169179        using std::endl;
    170180
     
    172182        os << "instance of " << typeString() << " " << get_name() << " (" << ( isFtype ? "" : "not" ) << " function type) ";
    173183        if ( ! parameters.empty() ) {
    174                 os << endl << std::string( indent, ' ' ) << "with parameters" << endl;
    175                 printAll( parameters, os, indent+2 );
     184                os << endl << indent << "... with parameters" << endl;
     185                printAll( parameters, os, indent+1 );
    176186        } // if
    177187}
  • src/SynTree/ReferenceType.cc

    rb96ec83 r6840e7c  
    3535}
    3636
    37 void ReferenceType::print( std::ostream &os, int indent ) const {
     37void ReferenceType::print( std::ostream &os, Indenter indent ) const {
    3838        Type::print( os, indent );
    3939        os << "reference to ";
  • src/SynTree/Statement.cc

    rb96ec83 r6840e7c  
    3434Statement::Statement( std::list<Label> labels ) : labels( labels ) {}
    3535
    36 void Statement::print( __attribute__((unused)) std::ostream &, __attribute__((unused)) int indent ) const {}
     36void Statement::print( std::ostream & os, Indenter ) const {
     37        if ( ! labels.empty() ) {
     38                os << "Labels: {";
     39                for ( const Label & l : labels ) {
     40                        os << l << ",";
     41                }
     42                os << "}" << endl;
     43        }
     44}
    3745
    3846Statement::~Statement() {}
     
    4654}
    4755
    48 void ExprStmt::print( std::ostream &os, int indent ) const {
    49         os << "Expression Statement:" << endl << std::string( indent + 2, ' ' );
    50         expr->print( os, indent + 2 );
     56void ExprStmt::print( std::ostream &os, Indenter indent ) const {
     57        os << "Expression Statement:" << endl << indent+1;
     58        expr->print( os, indent+1 );
    5159}
    5260
     
    6775}
    6876
    69 void AsmStmt::print( std::ostream &os, int indent ) const {
     77void AsmStmt::print( std::ostream &os, Indenter indent ) const {
    7078        os << "Assembler Statement:" << endl;
    71         os << std::string( indent, ' ' ) << "instruction: " << endl << std::string( indent, ' ' );
    72         instruction->print( os, indent + 2 );
     79        os << indent+1 << "instruction: " << endl << indent;
     80        instruction->print( os, indent+1 );
    7381        if ( ! output.empty() ) {
    74                 os << endl << std::string( indent, ' ' ) << "output: " << endl;
    75                 printAll( output, os, indent + 2 );
     82                os << endl << indent+1 << "output: " << endl;
     83                printAll( output, os, indent+1 );
    7684        } // if
    7785        if ( ! input.empty() ) {
    78                 os << std::string( indent, ' ' ) << "input: " << endl << std::string( indent, ' ' );
    79                 printAll( input, os, indent + 2 );
     86                os << indent+1 << "input: " << endl;
     87                printAll( input, os, indent+1 );
    8088        } // if
    8189        if ( ! clobber.empty() ) {
    82                 os << std::string( indent, ' ' ) << "clobber: " << endl;
    83                 printAll( clobber, os, indent + 2 );
     90                os << indent+1 << "clobber: " << endl;
     91                printAll( clobber, os, indent+1 );
    8492        } // if
    8593}
     
    103111}
    104112
    105 void BranchStmt::print( std::ostream &os, int indent ) const {
    106         os << string( indent, ' ' ) << "Branch (" << brType[type] << ")" << endl ;
    107         if ( target != "" ) os << string( indent+2, ' ' ) << "with target: " << target << endl;
    108         if ( originalTarget != "" ) os << string( indent+2, ' ' ) << "with original target: " << originalTarget << endl;
    109         if ( computedTarget != nullptr ) os << string( indent+2, ' ' ) << "with computed target: " << computedTarget << endl;
     113void BranchStmt::print( std::ostream &os, Indenter indent ) const {
     114        os << "Branch (" << brType[type] << ")" << endl ;
     115        if ( target != "" ) os << indent+1 << "with target: " << target << endl;
     116        if ( originalTarget != "" ) os << indent+1 << "with original target: " << originalTarget << endl;
     117        if ( computedTarget != nullptr ) os << indent+1 << "with computed target: " << computedTarget << endl;
    110118}
    111119
     
    118126}
    119127
    120 void ReturnStmt::print( std::ostream &os, int indent ) const {
    121         os <<  "Return Statement, returning: ";
    122         if ( expr != 0 ) {
    123                 os << endl << string( indent+2, ' ' );
    124                 expr->print( os, indent + 2 );
     128void ReturnStmt::print( std::ostream &os, Indenter indent ) const {
     129        os << "Return Statement, returning: ";
     130        if ( expr != nullptr ) {
     131                os << endl << indent+1;
     132                expr->print( os, indent+1 );
    125133        }
    126134        os << endl;
     
    142150}
    143151
    144 void IfStmt::print( std::ostream &os, int indent ) const {
    145         os << "If on condition: " << endl ;
    146         os << string( indent+4, ' ' );
    147         condition->print( os, indent + 4 );
     152void IfStmt::print( std::ostream &os, Indenter indent ) const {
     153        os << "If on condition: " << endl;
     154        os << indent+1;
     155        condition->print( os, indent+1 );
    148156
    149157        if ( !initialization.empty() ) {
    150                 os << string( indent + 2, ' ' ) << "initialization: \n";
    151                 for ( std::list<Statement *>::const_iterator it = initialization.begin(); it != initialization.end(); ++it ) {
    152                         os << string( indent + 4, ' ' );
    153                         (*it)->print( os, indent + 4 );
     158                os << indent << "... with initialization: \n";
     159                for ( const Statement * stmt : initialization ) {
     160                        os << indent+1;
     161                        stmt->print( os, indent+1 );
    154162                }
    155163                os << endl;
    156164        }
    157165
    158         os << string( indent+2, ' ' ) << "... then: " << endl;
    159 
    160         os << string( indent+4, ' ' );
    161         thenPart->print( os, indent + 4 );
     166        os << indent << "... then: " << endl;
     167
     168        os << indent+1;
     169        thenPart->print( os, indent+1 );
    162170
    163171        if ( elsePart != 0 ) {
    164                 os << string( indent+2, ' ' ) << "... else: " << endl;
    165                 os << string( indent+4, ' ' );
    166                 elsePart->print( os, indent + 4 );
     172                os << indent << "... else: " << endl;
     173                os << indent+1;
     174                elsePart->print( os, indent+1 );
    167175        } // if
    168176}
     
    183191}
    184192
    185 void SwitchStmt::print( std::ostream &os, int indent ) const {
     193void SwitchStmt::print( std::ostream &os, Indenter indent ) const {
    186194        os << "Switch on condition: ";
    187195        condition->print( os );
    188196        os << endl;
    189197
    190         // statements
    191         std::list<Statement *>::const_iterator i;
    192         for ( i = statements.begin(); i != statements.end(); i++)
    193                 (*i)->print( os, indent + 4 );
    194 
    195         //for_each( statements.begin(), statements.end(), mem_fun( bind1st(&Statement::print ), os ));
     198        for ( const Statement * stmt : statements ) {
     199                stmt->print( os, indent+1 );
     200        }
    196201}
    197202
    198203CaseStmt::CaseStmt( std::list<Label> labels, Expression *condition, const std::list<Statement *> &statements, bool deflt ) throw ( SemanticError ) :
    199204        Statement( labels ), condition( condition ), stmts( statements ), _isDefault( deflt ) {
    200         if ( isDefault() && condition != 0 )
    201                 throw SemanticError("default with conditions");
     205        if ( isDefault() && condition != 0 ) throw SemanticError("default case with condition: ", condition);
    202206}
    203207
     
    216220}
    217221
    218 void CaseStmt::print( std::ostream &os, int indent ) const {
    219         os << string( indent, ' ' );
    220 
    221         if ( isDefault() )
    222                 os << "Default ";
     222void CaseStmt::print( std::ostream &os, Indenter indent ) const {
     223        if ( isDefault() ) os << "Default ";
    223224        else {
    224225                os << "Case ";
    225                 condition->print( os );
    226         } // if
    227 
    228         os << endl;
    229 
    230         std::list<Statement *>::const_iterator i;
    231         for ( i = stmts.begin(); i != stmts.end(); i++)
    232                 (*i )->print( os, indent + 4 );
     226                condition->print( os, indent );
     227        } // if
     228        os << endl;
     229
     230        for ( Statement * stmt : stmts ) {
     231                stmt->print( os, indent+1 );
     232        }
    233233}
    234234
     
    246246}
    247247
    248 void WhileStmt::print( std::ostream &os, int indent ) const {
     248void WhileStmt::print( std::ostream &os, Indenter indent ) const {
    249249        os << "While on condition: " << endl ;
    250         condition->print( os, indent + 4 );
    251 
    252         os << string( indent, ' ' ) << ".... with body: " << endl;
    253 
    254         if ( body != 0 ) body->print( os, indent + 4 );
     250        condition->print( os, indent+1 );
     251
     252        os << indent << "... with body: " << endl;
     253
     254        if ( body != 0 ) body->print( os, indent+1 );
    255255}
    256256
     
    272272}
    273273
    274 void ForStmt::print( std::ostream &os, int indent ) const {
    275         os << "Labels: {";
    276         for ( std::list<Label>::const_iterator it = get_labels().begin(); it != get_labels().end(); ++it) {
    277                 os << *it << ",";
    278         }
    279         os << "}" << endl;
    280 
    281         os << string( indent, ' ' ) << "For Statement" << endl ;
    282 
    283         os << string( indent + 2, ' ' ) << "initialization: \n";
    284         for ( std::list<Statement *>::const_iterator it = initialization.begin(); it != initialization.end(); ++it ) {
    285                 os << string( indent + 4, ' ' );
    286                 (*it)->print( os, indent + 4 );
    287         }
    288 
    289         os << "\n" << string( indent + 2, ' ' ) << "condition: \n";
    290         if ( condition != 0 ) {
    291                 os << string( indent + 4, ' ' );
    292                 condition->print( os, indent + 4 );
    293         }
    294 
    295         os << "\n" << string( indent + 2, ' ' ) << "increment: \n";
    296         if ( increment != 0 ) {
    297                 os << string( indent + 4, ' ' );
    298                 increment->print( os, indent + 4 );
    299         }
    300 
    301         os << "\n" << string( indent + 2, ' ' ) << "statement block: \n";
     274void ForStmt::print( std::ostream &os, Indenter indent ) const {
     275        Statement::print( os, indent ); // print labels
     276
     277        os << "For Statement" << endl;
     278
     279        if ( ! initialization.empty() ) {
     280                os << indent << "... initialization: \n";
     281                for ( Statement * stmt : initialization ) {
     282                        os << indent+1;
     283                        stmt->print( os, indent+1 );
     284                }
     285        }
     286
     287        if ( condition != nullptr ) {
     288                os << indent << "... condition: \n" << indent+1;
     289                condition->print( os, indent+1 );
     290        }
     291
     292        if ( increment != nullptr ) {
     293                os << "\n" << indent << "... increment: \n" << indent+1;
     294                increment->print( os, indent+1 );
     295        }
     296
    302297        if ( body != 0 ) {
    303                 os << string( indent + 4, ' ' );
    304                 body->print( os, indent + 4 );
    305         }
    306 
     298                os << "\n" << indent << "... with body: \n" << indent+1;
     299                body->print( os, indent+1 );
     300        }
    307301        os << endl;
    308302}
     
    322316}
    323317
    324 void ThrowStmt::print( std::ostream &os, int indent) const {
     318void ThrowStmt::print( std::ostream &os, Indenter indent) const {
     319        if ( target ) os << "Non-Local ";
     320        os << "Throw Statement, raising: ";
     321        expr->print(os, indent+1);
    325322        if ( target ) {
    326                 os << "Non-Local ";
    327         }
    328         os << "Throw Statement, raising: ";
    329         expr->print(os, indent + 4);
    330         if ( target ) {
    331                 os << "At: ";
    332                 target->print(os, indent + 4);
     323                os << "... at: ";
     324                target->print(os, indent+1);
    333325        }
    334326}
     
    348340}
    349341
    350 void TryStmt::print( std::ostream &os, int indent ) const {
     342void TryStmt::print( std::ostream &os, Indenter indent ) const {
    351343        os << "Try Statement" << endl;
    352         os << string( indent + 2, ' ' ) << "with block:" << endl;
    353         os << string( indent + 4, ' ' );
    354         block->print( os, indent + 4 );
     344        os << indent << "... with block:" << endl << indent+1;
     345        block->print( os, indent+1 );
    355346
    356347        // handlers
    357         os << string( indent + 2, ' ' ) << "and handlers:" << endl;
    358         for ( std::list<CatchStmt *>::const_iterator i = handlers.begin(); i != handlers.end(); i++) {
    359                 os << string( indent + 4, ' ' );
    360                 (*i )->print( os, indent + 4 );
     348        os << indent << "... and handlers:" << endl;
     349        for ( const CatchStmt * stmt : handlers ) {
     350                os << indent+1;
     351                stmt->print( os, indent+1 );
    361352        }
    362353
    363354        // finally block
    364355        if ( finallyBlock != 0 ) {
    365                 os << string( indent + 2, ' ' ) << "and finally:" << endl;
    366                 finallyBlock->print( os, indent + 4 );
     356                os << indent << "... and finally:" << endl << indent+1;
     357                finallyBlock->print( os, indent+1 );
    367358        } // if
    368359}
     
    370361CatchStmt::CatchStmt( std::list<Label> labels, Kind kind, Declaration *decl, Expression *cond, Statement *body ) :
    371362        Statement( labels ), kind ( kind ), decl ( decl ), cond ( cond ), body( body ) {
     363                assertf( decl, "Catch clause must have a declaration." );
    372364}
    373365
     
    381373}
    382374
    383 void CatchStmt::print( std::ostream &os, int indent ) const {
     375void CatchStmt::print( std::ostream &os, Indenter indent ) const {
    384376        os << "Catch " << ((Terminate == kind) ? "Terminate" : "Resume") << " Statement" << endl;
    385377
    386         os << string( indent + 2, ' ' ) << "... catching: ";
    387         if ( decl ) {
    388                 decl->printShort( os, indent + 4 );
    389                 os << endl;
    390         }
    391         else
    392                 os << string( indent + 4 , ' ' ) << ">>> Error:  this catch clause must have a declaration <<<" << endl;
     378        os << indent << "... catching: ";
     379        decl->printShort( os, indent+1 );
     380        os << endl;
    393381
    394382        if ( cond ) {
    395                 os << string( indent + 2, ' ' ) << "with conditional:" << endl;
    396                 os << string( indent + 4, ' ' );
    397                 cond->print( os, indent + 4 );
    398         }
    399         else
    400                 os << string( indent + 2, ' ' ) << "with no conditional" << endl;
    401 
    402         os << string( indent + 2, ' ' ) << "with block:" << endl;
    403         os << string( indent + 4, ' ' );
    404         body->print( os, indent + 4 );
     383                os << indent << "... with conditional:" << endl << indent+1;
     384                cond->print( os, indent+1 );
     385        }
     386
     387        os << indent << "... with block:" << endl;
     388        os << indent+1;
     389        body->print( os, indent+1 );
    405390}
    406391
     
    417402}
    418403
    419 void FinallyStmt::print( std::ostream &os, int indent ) const {
     404void FinallyStmt::print( std::ostream &os, Indenter indent ) const {
    420405        os << "Finally Statement" << endl;
    421         os << string( indent + 2, ' ' ) << "with block:" << endl;
    422         os << string( indent + 4, ' ' );
    423         block->print( os, indent + 4 );
     406        os << indent << "... with block:" << endl << indent+1;
     407        block->print( os, indent+1 );
    424408}
    425409
     
    465449}
    466450
    467 void WaitForStmt::print( std::ostream &os, int indent ) const {
     451void WaitForStmt::print( std::ostream &os, Indenter indent ) const {
    468452        os << "Waitfor Statement" << endl;
    469         os << string( indent + 2, ' ' ) << "with block:" << endl;
    470         os << string( indent + 4, ' ' );
     453        os << indent << "... with block:" << endl << indent+1;
    471454        // block->print( os, indent + 4 );
    472455}
     
    475458NullStmt::NullStmt() : Statement( std::list<Label>() ) {}
    476459
    477 void NullStmt::print( std::ostream &os, __attribute__((unused)) int indent ) const {
    478         os << "Null Statement" << endl ;
     460void NullStmt::print( std::ostream &os, Indenter ) const {
     461        os << "Null Statement" << endl;
    479462}
    480463
     
    490473}
    491474
    492 void ImplicitCtorDtorStmt::print( std::ostream &os, int indent ) const {
     475void ImplicitCtorDtorStmt::print( std::ostream &os, Indenter indent ) const {
    493476        os << "Implicit Ctor Dtor Statement" << endl;
    494         os << string( indent + 2, ' ' ) << "with Ctor/Dtor: ";
    495         callStmt->print( os, indent + 2);
     477        os << indent << "... with Ctor/Dtor: ";
     478        callStmt->print( os, indent+1);
    496479        os << endl;
    497480}
  • src/SynTree/Statement.h

    rb96ec83 r6840e7c  
    4343        const std::list<Label> & get_labels() const { return labels; }
    4444
    45         virtual Statement *clone() const = 0;
     45        virtual Statement *clone() const override = 0;
    4646        virtual void accept( Visitor &v ) override = 0;
    47         virtual Statement *acceptMutator( Mutator &m ) = 0;
    48         virtual void print( std::ostream &os, int indent = 0 ) const override;
     47        virtual Statement *acceptMutator( Mutator &m ) override = 0;
     48        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    4949};
    5050
     
    6565        virtual void accept( Visitor &v ) override { v.visit( this ); }
    6666        virtual CompoundStmt *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    67         virtual void print( std::ostream &os, int indent = 0 ) const override;
     67        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    6868};
    6969
     
    7676        virtual void accept( Visitor &v ) override { v.visit( this ); }
    7777        virtual NullStmt *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    78         virtual void print( std::ostream &os, int indent = 0 ) const override;
     78        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    7979};
    8080
     
    9393        virtual void accept( Visitor &v ) override { v.visit( this ); }
    9494        virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    95         virtual void print( std::ostream &os, int indent = 0 ) const override;
     95        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    9696};
    9797
     
    124124        virtual void accept( Visitor & v ) { v.visit( this ); }
    125125        virtual Statement * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    126         virtual void print( std::ostream & os, int indent = 0 ) const;
     126        virtual void print( std::ostream & os, Indenter indent = {} ) const;
    127127};
    128128
     
    150150        virtual void accept( Visitor &v ) override { v.visit( this ); }
    151151        virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    152         virtual void print( std::ostream &os, int indent = 0 ) const override;
     152        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    153153};
    154154
     
    171171
    172172        virtual SwitchStmt *clone() const override { return new SwitchStmt( *this ); }
    173         virtual void print( std::ostream &os, int indent = 0 ) const override;
     173        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    174174
    175175};
     
    199199
    200200        virtual CaseStmt *clone() const override { return new CaseStmt( *this ); }
    201         virtual void print( std::ostream &os, int indent = 0 ) const override;
     201        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    202202  private:
    203203        bool _isDefault;
     
    225225        virtual void accept( Visitor &v ) override { v.visit( this ); }
    226226        virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    227         virtual void print( std::ostream &os, int indent = 0 ) const override;
     227        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    228228};
    229229
     
    251251        virtual void accept( Visitor &v ) override { v.visit( this ); }
    252252        virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    253         virtual void print( std::ostream &os, int indent = 0 ) const override;
     253        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    254254};
    255255
     
    280280        virtual void accept( Visitor &v ) override { v.visit( this ); }
    281281        virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    282         virtual void print( std::ostream &os, int indent = 0 ) const override;
     282        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    283283  private:
    284284        static const char *brType[];
     
    299299        virtual void accept( Visitor &v ) override { v.visit( this ); }
    300300        virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    301         virtual void print( std::ostream &os, int indent = 0 ) const override;
     301        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    302302};
    303303
     
    323323        virtual void accept( Visitor &v ) override { v.visit( this ); }
    324324        virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    325         virtual void print( std::ostream &os, int indent = 0 ) const override;
     325        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    326326};
    327327
     
    346346        virtual void accept( Visitor &v ) override { v.visit( this ); }
    347347        virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    348         virtual void print( std::ostream &os, int indent = 0 ) const override;
     348        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    349349};
    350350
     
    374374        virtual void accept( Visitor &v ) override { v.visit( this ); }
    375375        virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    376         virtual void print( std::ostream &os, int indent = 0 ) const override;
     376        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    377377};
    378378
     
    391391        virtual void accept( Visitor &v ) override { v.visit( this ); }
    392392        virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    393         virtual void print( std::ostream &os, int indent = 0 ) const override;
     393        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    394394};
    395395
     
    428428        virtual void accept( Visitor &v ) override { v.visit( this ); }
    429429        virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    430         virtual void print( std::ostream &os, int indent = 0 ) const override;
     430        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    431431
    432432};
     
    448448        virtual void accept( Visitor &v ) override { v.visit( this ); }
    449449        virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    450         virtual void print( std::ostream &os, int indent = 0 ) const override;
     450        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    451451};
    452452
     
    470470        virtual void accept( Visitor &v ) override { v.visit( this ); }
    471471        virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    472         virtual void print( std::ostream &os, int indent = 0 ) const override;
     472        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    473473};
    474474
  • src/SynTree/TupleExpr.cc

    rb96ec83 r6840e7c  
    2828#include "Type.h"               // for TupleType, Type
    2929
    30 UntypedTupleExpr::UntypedTupleExpr( const std::list< Expression * > & exprs, Expression *_aname ) : Expression( _aname ), exprs( exprs ) {
     30UntypedTupleExpr::UntypedTupleExpr( const std::list< Expression * > & exprs ) : Expression(), exprs( exprs ) {
    3131}
    3232
     
    3939}
    4040
    41 void UntypedTupleExpr::print( std::ostream &os, int indent ) const {
     41void UntypedTupleExpr::print( std::ostream &os, Indenter indent ) const {
    4242        os << "Untyped Tuple:" << std::endl;
    43         printAll( exprs, os, indent+2 );
     43        printAll( exprs, os, indent+1 );
    4444        Expression::print( os, indent );
    4545}
    4646
    47 TupleExpr::TupleExpr( const std::list< Expression * > & exprs, Expression *_aname ) : Expression( _aname ), exprs( exprs ) {
     47TupleExpr::TupleExpr( const std::list< Expression * > & exprs ) : Expression(), exprs( exprs ) {
    4848        set_result( Tuples::makeTupleType( exprs ) );
    4949}
     
    5757}
    5858
    59 void TupleExpr::print( std::ostream &os, int indent ) const {
     59void TupleExpr::print( std::ostream &os, Indenter indent ) const {
    6060        os << "Tuple:" << std::endl;
    61         printAll( exprs, os, indent+2 );
     61        printAll( exprs, os, indent+1 );
    6262        Expression::print( os, indent );
    6363}
     
    7878}
    7979
    80 void TupleIndexExpr::print( std::ostream &os, int indent ) const {
     80void TupleIndexExpr::print( std::ostream &os, Indenter indent ) const {
    8181        os << "Tuple Index Expression, with tuple:" << std::endl;
    82         os << std::string( indent+2, ' ' );
    83         tuple->print( os, indent+2 );
    84         os << std::string( indent+2, ' ' ) << "with index: " << index << std::endl;
     82        os << indent+1;
     83        tuple->print( os, indent+1 );
     84        os << indent+1 << "with index: " << index << std::endl;
    8585        Expression::print( os, indent );
    8686}
    8787
    88 TupleAssignExpr::TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls, Expression * _aname ) : Expression( _aname ) {
     88TupleAssignExpr::TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls ) : Expression() {
    8989        // convert internally into a StmtExpr which contains the declarations and produces the tuple of the assignments
    9090        set_result( Tuples::makeTupleType( assigns ) );
     
    109109}
    110110
    111 void TupleAssignExpr::print( std::ostream &os, int indent ) const {
     111void TupleAssignExpr::print( std::ostream &os, Indenter indent ) const {
    112112        os << "Tuple Assignment Expression, with stmt expr:" << std::endl;
    113         os << std::string( indent+2, ' ' );
    114         stmtExpr->print( os, indent+4 );
     113        os << indent+1;
     114        stmtExpr->print( os, indent+1 );
    115115        Expression::print( os, indent );
    116116}
  • src/SynTree/TupleType.cc

    rb96ec83 r6840e7c  
    4848}
    4949
    50 void TupleType::print( std::ostream &os, int indent ) const {
     50void TupleType::print( std::ostream &os, Indenter indent ) const {
    5151        Type::print( os, indent );
    5252        os << "tuple of types" << std::endl;
    53         printAll( types, os, indent+2 );
     53        printAll( types, os, indent+1 );
    5454}
    5555
  • src/SynTree/Type.cc

    rb96ec83 r6840e7c  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Sep 11 13:21:25 2017
    13 // Update Count     : 37
     12// Last Modified On : Mon Sep 25 15:16:32 2017
     13// Update Count     : 38
    1414//
    1515#include "Type.h"
     
    4545        "double _Imaginary",
    4646        "long double _Imaginary",
     47        "__int128",
     48        "unsigned __int128",
    4749};
    4850
     
    7375        Type * type;
    7476        ReferenceType * ref;
    75         for ( type = this; (ref = dynamic_cast<ReferenceType *>( type )); type = ref->get_base() );
     77        for ( type = this; (ref = dynamic_cast<ReferenceType *>( type )); type = ref->base );
    7678        return type;
    7779}
     
    7981int Type::referenceDepth() const { return 0; }
    8082
    81 void Type::print( std::ostream &os, int indent ) const {
     83void Type::print( std::ostream &os, Indenter indent ) const {
    8284        if ( ! forall.empty() ) {
    8385                os << "forall" << std::endl;
    84                 printAll( forall, os, indent + 4 );
    85                 os << std::string( indent+2, ' ' );
     86                printAll( forall, os, indent+1 );
     87                os << ++indent;
    8688        } // if
    8789
    8890        if ( ! attributes.empty() ) {
    89                 os << endl << string( indent+2, ' ' ) << "with attributes" << endl;
    90                 printAll( attributes, os, indent+4 );
     91                os << "with attributes" << endl;
     92                printAll( attributes, os, indent+1 );
    9193        } // if
    9294
  • src/SynTree/Type.h

    rb96ec83 r6840e7c  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Aug  9 14:25:00 2017
    13 // Update Count     : 152
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon Sep 25 14:14:01 2017
     13// Update Count     : 154
    1414//
    1515
     
    181181        virtual void accept( Visitor & v ) = 0;
    182182        virtual Type *acceptMutator( Mutator & m ) = 0;
    183         virtual void print( std::ostream & os, int indent = 0 ) const;
     183        virtual void print( std::ostream & os, Indenter indent = {} ) const;
    184184};
    185185
     
    198198        virtual void accept( Visitor & v ) override { v.visit( this ); }
    199199        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    200         virtual void print( std::ostream & os, int indent = 0 ) const override;
     200        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    201201};
    202202
     
    225225                DoubleImaginary,
    226226                LongDoubleImaginary,
     227                SignedInt128,
     228                UnsignedInt128,
    227229                NUMBER_OF_BASIC_TYPES
    228230        } kind;
     
    238240        virtual void accept( Visitor & v ) override { v.visit( this ); }
    239241        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    240         virtual void print( std::ostream & os, int indent = 0 ) const override;
     242        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    241243
    242244        bool isInteger() const;
     
    273275        virtual void accept( Visitor & v ) override { v.visit( this ); }
    274276        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    275         virtual void print( std::ostream & os, int indent = 0 ) const override;
     277        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    276278};
    277279
     
    301303        virtual void accept( Visitor & v ) override { v.visit( this ); }
    302304        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    303         virtual void print( std::ostream & os, int indent = 0 ) const override;
     305        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    304306};
    305307
     
    325327        virtual void accept( Visitor & v ) override { v.visit( this ); }
    326328        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    327         virtual void print( std::ostream & os, int indent = 0 ) const override;
     329        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    328330};
    329331
     
    352354        virtual void accept( Visitor & v ) override { v.visit( this ); }
    353355        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    354         virtual void print( std::ostream & os, int indent = 0 ) const override;
     356        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    355357};
    356358
     
    374376        virtual void accept( Visitor & v ) override = 0;
    375377        virtual Type *acceptMutator( Mutator & m ) override = 0;
    376         virtual void print( std::ostream & os, int indent = 0 ) const override;
     378        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    377379
    378380        virtual void lookup( __attribute__((unused)) const std::string & name, __attribute__((unused)) std::list< Declaration* > & foundDecls ) const {}
     
    408410        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    409411
    410         virtual void print( std::ostream & os, int indent = 0 ) const override;
     412        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    411413  private:
    412414        virtual std::string typeString() const override;
     
    440442        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    441443
    442         virtual void print( std::ostream & os, int indent = 0 ) const override;
     444        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    443445  private:
    444446        virtual std::string typeString() const override;
     
    464466        virtual void accept( Visitor & v ) override { v.visit( this ); }
    465467        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     468
     469        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    466470  private:
    467471        virtual std::string typeString() const override;
     
    512516        virtual void accept( Visitor & v ) override { v.visit( this ); }
    513517        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    514         virtual void print( std::ostream & os, int indent = 0 ) const override;
     518        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    515519  private:
    516520        virtual std::string typeString() const override;
     
    549553        virtual void accept( Visitor & v ) override { v.visit( this ); }
    550554        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    551         virtual void print( std::ostream & os, int indent = 0 ) const override;
     555        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    552556};
    553557
     
    568572        virtual void accept( Visitor & v ) override { v.visit( this ); }
    569573        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    570         virtual void print( std::ostream & os, int indent = 0 ) const override;
     574        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    571575};
    572576
     
    597601        virtual void accept( Visitor & v ) override { v.visit( this ); }
    598602        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    599         virtual void print( std::ostream & os, int indent = 0 ) const override;
     603        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    600604};
    601605
     
    611615        virtual void accept( Visitor & v ) override { v.visit( this ); }
    612616        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    613         virtual void print( std::ostream & os, int indent = 0 ) const override;
     617        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    614618};
    615619
     
    623627        virtual void accept( Visitor & v ) override { v.visit( this ); }
    624628        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    625         virtual void print( std::ostream & os, int indent = 0 ) const override;
     629        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    626630};
    627631
     
    635639        virtual void accept( Visitor & v ) override { v.visit( this ); }
    636640        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    637         virtual void print( std::ostream & os, int indent = 0 ) const override;
     641        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    638642};
    639643
  • src/SynTree/TypeDecl.cc

    rb96ec83 r6840e7c  
    4141}
    4242
    43 void TypeDecl::print( std::ostream &os, int indent ) const {
     43void TypeDecl::print( std::ostream &os, Indenter indent ) const {
    4444  NamedTypeDecl::print( os, indent );
    4545  if ( init ) {
    46     os << std::endl << std::string( indent, ' ' ) << "with type initializer: ";
    47     init->print( os, indent + 2 );
     46    os << std::endl << indent << "with type initializer: ";
     47    init->print( os, indent + 1 );
    4848  }
    4949}
  • src/SynTree/TypeExpr.cc

    rb96ec83 r6840e7c  
    3030}
    3131
    32 void TypeExpr::print( std::ostream &os, int indent ) const {
     32void TypeExpr::print( std::ostream &os, Indenter indent ) const {
    3333        if ( type ) type->print( os, indent );
    3434        Expression::print( os, indent );
  • src/SynTree/TypeSubstitution.cc

    rb96ec83 r6840e7c  
    148148template< typename TypeClass >
    149149Type *TypeSubstitution::handleType( TypeClass *type ) {
    150         BoundVarsType oldBoundVars( boundVars );
     150        ValueGuard<BoundVarsType> oldBoundVars( boundVars );
    151151        // bind type variables from forall-qualifiers
    152152        if ( freeOnly ) {
     
    156156        } // if
    157157        Type *ret = Mutator::mutate( type );
    158         boundVars = oldBoundVars;
    159158        return ret;
    160159}
     
    162161template< typename TypeClass >
    163162Type *TypeSubstitution::handleAggregateType( TypeClass *type ) {
    164         BoundVarsType oldBoundVars( boundVars );
     163        ValueGuard<BoundVarsType> oldBoundVars( boundVars );
    165164        // bind type variables from forall-qualifiers
    166165        if ( freeOnly ) {
     
    177176        } // if
    178177        Type *ret = Mutator::mutate( type );
    179         boundVars = oldBoundVars;
    180178        return ret;
    181179}
     
    233231}
    234232
    235 TypeSubstitution * TypeSubstitution::acceptMutator( Mutator & mutator ) {
    236         for ( auto & p : typeEnv ) {
    237                 p.second = maybeMutate( p.second, mutator );
    238         }
    239         for ( auto & p : varEnv ) {
    240                 p.second = maybeMutate( p.second, mutator );
    241         }
    242         return this;
    243 }
    244 
    245 void TypeSubstitution::print( std::ostream &os, int indent ) const {
    246         os << std::string( indent, ' ' ) << "Types:" << std::endl;
     233void TypeSubstitution::print( std::ostream &os, Indenter indent ) const {
     234        os << indent << "Types:" << std::endl;
    247235        for ( TypeEnvType::const_iterator i = typeEnv.begin(); i != typeEnv.end(); ++i ) {
    248                 os << std::string( indent+2, ' ' ) << i->first << " -> ";
    249                 i->second->print( os, indent+4 );
     236                os << indent+1 << i->first << " -> ";
     237                i->second->print( os, indent+2 );
    250238                os << std::endl;
    251239        } // for
    252         os << std::string( indent, ' ' ) << "Non-types:" << std::endl;
     240        os << indent << "Non-types:" << std::endl;
    253241        for ( VarEnvType::const_iterator i = varEnv.begin(); i != varEnv.end(); ++i ) {
    254                 os << std::string( indent+2, ' ' ) << i->first << " -> ";
    255                 i->second->print( os, indent+4 );
     242                os << indent+1 << i->first << " -> ";
     243                i->second->print( os, indent+2 );
    256244                os << std::endl;
    257245        } // for
  • src/SynTree/TypeSubstitution.h

    rb96ec83 r6840e7c  
    5959        void normalize();
    6060
    61         TypeSubstitution * acceptMutator( Mutator & mutator );
     61        TypeSubstitution * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    6262
    63         void print( std::ostream &os, int indent = 0 ) const;
     63        void print( std::ostream &os, Indenter indent = {} ) const;
    6464        TypeSubstitution *clone() const { return new TypeSubstitution( *this ); }
    6565  private:
     
    8989
    9090        void initialize( const TypeSubstitution &src, TypeSubstitution &dest );
     91
     92        friend class Mutator;
     93
     94        template<typename pass_type>
     95        friend class PassVisitor;
    9196
    9297        typedef std::map< std::string, Type* > TypeEnvType;
  • src/SynTree/TypeofType.cc

    rb96ec83 r6840e7c  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // TypeofType.cc -- 
     7// TypeofType.cc --
    88//
    99// Author           : Richard C. Bilson
     
    3333}
    3434
    35 void TypeofType::print( std::ostream &os, int indent ) const {
     35void TypeofType::print( std::ostream &os, Indenter indent ) const {
    3636        Type::print( os, indent );
    3737        os << "type-of expression ";
  • src/SynTree/VarArgsType.cc

    rb96ec83 r6840e7c  
    2525VarArgsType::VarArgsType( Type::Qualifiers tq, const std::list< Attribute * > & attributes ) : Type( tq, attributes ) {}
    2626
    27 void VarArgsType::print( std::ostream &os, int indent ) const {
     27void VarArgsType::print( std::ostream &os, Indenter indent ) const {
    2828        Type::print( os, indent );
    2929        os << "builtin var args pack";
  • src/SynTree/VoidType.cc

    rb96ec83 r6840e7c  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // VoidType.cc -- 
     7// VoidType.cc --
    88//
    99// Author           : Richard C. Bilson
     
    2424}
    2525
    26 void VoidType::print( std::ostream &os, int indent ) const {
     26void VoidType::print( std::ostream &os, Indenter indent ) const {
    2727        Type::print( os, indent );
    2828        os << "void ";
  • src/SynTree/ZeroOneType.cc

    rb96ec83 r6840e7c  
    2525ZeroType::ZeroType( Type::Qualifiers tq, const std::list< Attribute * > & attributes ) : Type( tq, attributes ) {}
    2626
    27 void ZeroType::print( std::ostream &os, __attribute__((unused)) int indent ) const {
     27void ZeroType::print( std::ostream &os, Indenter ) const {
    2828        os << "zero_t";
    2929}
     
    3333OneType::OneType( Type::Qualifiers tq, const std::list< Attribute * > & attributes ) : Type( tq, attributes ) {}
    3434
    35 void OneType::print( std::ostream &os, __attribute__((unused)) int indent ) const {
     35void OneType::print( std::ostream &os, Indenter ) const {
    3636        os << "one_t";
    3737}
Note: See TracChangeset for help on using the changeset viewer.