Changeset b067d9b for src/SynTree


Ignore:
Timestamp:
Oct 29, 2019, 4:01:24 PM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum, stuck-waitfor-destruct
Children:
773db65, 9421f3d8
Parents:
7951100 (diff), 8364209 (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' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src/SynTree
Files:
35 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/AddressExpr.cc

    r7951100 rb067d9b  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 23:54:44 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Tue Apr 26 12:35:13 2016
    13 // Update Count     : 6
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Thu Feb 28 13:13:38 2019
     13// Update Count     : 10
    1414//
    1515
     
    4242AddressExpr::AddressExpr( Expression *arg ) : Expression(), arg( arg ) {
    4343        if ( arg->result ) {
    44                 if ( arg->result->get_lvalue() ) {
     44                if ( arg->get_lvalue() ) {
    4545                        // lvalue, retains all layers of reference and gains a pointer inside the references
    4646                        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->result );
    50                         set_result( addrType( refType->base ) );
     49                        if ( ReferenceType * refType = dynamic_cast< ReferenceType * >( arg->result ) ) {
     50                                set_result( addrType( refType->base ) );
     51                        } else {
     52                                SemanticError( arg->result, "Attempt to take address of non-lvalue expression: " );
     53                        } // if
    5154                }
    52                 // result of & is never an lvalue
    53                 get_result()->set_lvalue( false );
    5455        }
    5556}
  • src/SynTree/AggregateDecl.cc

    r7951100 rb067d9b  
    8686std::string TraitDecl::typeString() const { return "trait"; }
    8787
    88 namespace {
    89         long long int getConstValue( Expression * expr ) {
    90                 if ( CastExpr * castExpr = dynamic_cast< CastExpr * > ( expr ) ) {
    91                         return getConstValue( castExpr->arg );
    92                 } else if ( ConstantExpr * constExpr = dynamic_cast< ConstantExpr * >( expr ) ) {
    93                         return constExpr->intValue();
    94                 // can be -1, +1, etc.
    95                 // } else if ( UntypedExpr * untypedExpr = dynamic_cast< UntypedExpr * >( expr ) ) {
    96                 //      if ( untypedExpr-> )
    97                 } else {
    98                         assertf( false, "Unhandled expression type in getConstValue for enumerators: %s", toString( expr ).c_str() );
    99                 }
    100         }
    101 }
    102 
    10388bool EnumDecl::valueOf( Declaration * enumerator, long long int & value ) {
    10489        if ( enumValues.empty() ) {
     
    10893                        if ( field->init ) {
    10994                                SingleInit * init = strict_dynamic_cast< SingleInit * >( field->init );
    110                                 currentValue = getConstValue( init->value );
     95                                auto result = eval( init->value );
     96                                if ( ! result.second ) SemanticError( init->location, toString( "Non-constexpr in initialization of enumerator: ", field ) );
     97                                currentValue = result.first;
    11198                        }
    11299                        assertf( enumValues.count( field->name ) == 0, "Enum %s has multiple members with the name %s", name.c_str(), field->name.c_str() );
  • src/SynTree/ApplicationExpr.cc

    r7951100 rb067d9b  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Tue Apr 26 12:41:06 2016
    13 // Update Count     : 4
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Mon Aug 12 14:28:00 2019
     13// Update Count     : 5
    1414//
    1515
     
    2525#include "Declaration.h"         // for Declaration
    2626#include "Expression.h"          // for ParamEntry, ApplicationExpr, Expression
     27#include "InitTweak/InitTweak.h" // for getFunction
    2728#include "ResolvExpr/typeops.h"  // for extractResultType
    2829#include "Type.h"                // for Type, PointerType, FunctionType
    2930
     31ParamEntry::ParamEntry( UniqueId decl, Declaration * declptr, Type * actualType, Type * formalType, Expression* expr )
     32                : decl( decl ), declptr( declptr ), actualType( actualType ), formalType( formalType ), expr( expr ) {
     33        }
     34
    3035ParamEntry::ParamEntry( const ParamEntry &other ) :
    31                 decl( other.decl ), actualType( maybeClone( other.actualType ) ), formalType( maybeClone( other.formalType ) ), expr( maybeClone( other.expr ) ), inferParams( new InferredParams( *other.inferParams ) ) {
    32 }
    33 
    34 ParamEntry &ParamEntry::operator=( const ParamEntry &other ) {
    35         if ( &other == this ) return *this;
    36         decl = other.decl;
    37         // xxx - this looks like a memory leak
    38         actualType = maybeClone( other.actualType );
    39         formalType = maybeClone( other.formalType );
    40         expr = maybeClone( other.expr );
    41         *inferParams = *other.inferParams;
    42         return *this;
     36                decl( other.decl ), declptr( maybeClone( other.declptr ) ), actualType( maybeClone( other.actualType ) ), formalType( maybeClone( other.formalType ) ), expr( maybeClone( other.expr ) ) {
    4337}
    4438
    4539ParamEntry::~ParamEntry() {
     40        delete declptr;
    4641        delete actualType;
    4742        delete formalType;
     
    5045
    5146ParamEntry::ParamEntry( ParamEntry && other ) :
    52                 decl( other.decl ), actualType( other.actualType ), formalType( other.formalType ), expr( other.expr ), inferParams( std::move( other.inferParams ) ) {
    53         other.actualType = nullptr;
    54         other.formalType = nullptr;
    55         other.expr = nullptr;
     47                decl( other.decl ), declptr( other.declptr ), actualType( other.actualType ), formalType( other.formalType ), expr( other.expr ) {
     48        new (&other) ParamEntry();
    5649}
    5750
    5851ParamEntry & ParamEntry::operator=( ParamEntry && other ) {
    5952        if ( &other == this ) return *this;
    60         delete actualType;
    61         delete formalType;
    62         delete expr;
    63         decl = other.decl;
    64         actualType = other.actualType;
    65         formalType = other.formalType;
    66         expr = other.expr;
    67         other.actualType = nullptr;
    68         other.formalType = nullptr;
    69         other.expr = nullptr;
    70         inferParams = std::move( other.inferParams );
     53        this->~ParamEntry();
     54        new (this) ParamEntry(other.decl, other.declptr, other.actualType, other.formalType, other.expr);
     55        new (&other) ParamEntry();
     56
    7157        return *this;
    7258}
     
    9177}
    9278
     79bool ApplicationExpr::get_lvalue() const {
     80        // from src/GenPoly/Lvalue.cc: isIntrinsicReference
     81        static std::set<std::string> lvalueFunctions = { "*?", "?[?]" };
     82        if ( const DeclarationWithType * func = InitTweak::getFunction( this ) ) {
     83                return func->linkage == LinkageSpec::Intrinsic && lvalueFunctions.count(func->name);
     84        }
     85        return false;
     86}
     87
    9388void ApplicationExpr::print( std::ostream &os, Indenter indent ) const {
    9489        os << "Application of" << std::endl << indent+1;
  • src/SynTree/ArrayType.cc

    r7951100 rb067d9b  
    2626ArrayType::ArrayType( const Type::Qualifiers &tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic, const std::list< Attribute * > & attributes )
    2727        : Type( tq, attributes ), base( base ), dimension( dimension ), isVarLen( isVarLen ), isStatic( isStatic ) {
    28         base->set_lvalue( false );
    2928}
    3029
  • src/SynTree/Attribute.cc

    r7951100 rb067d9b  
    2121#include "Expression.h"      // for Expression
    2222
    23 Attribute::Attribute( const Attribute &other ) : name( other.name ) {
     23Attribute::Attribute( const Attribute &other ) : BaseSyntaxNode( other ), name( other.name ) {
    2424        cloneAll( other.parameters, parameters );
    2525}
  • src/SynTree/Attribute.h

    r7951100 rb067d9b  
    5050        Attribute * clone() const override { return new Attribute( *this ); }
    5151        virtual void accept( Visitor & v ) override { v.visit( this ); }
     52        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    5253        virtual Attribute * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    5354        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
  • src/SynTree/BaseSyntaxNode.h

    r7951100 rb067d9b  
    99// Author           : Thierry Delisle
    1010// Created On       : Tue Feb 14 07:44:20 2017
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Aug 17 13:44:00
    13 // Update Count     : 1
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Jul 10 16:13:49 2019
     13// Update Count     : 4
    1414//
    1515
     
    1818#include "Common/CodeLocation.h"
    1919#include "Common/Indenter.h"
     20#include "Common/Stats.h"
     21
    2022class Visitor;
    2123class Mutator;
     
    2325class BaseSyntaxNode {
    2426  public:
     27        static Stats::Counters::SimpleCounter* new_nodes;
     28
    2529        CodeLocation location;
     30
     31        BaseSyntaxNode() { ++*new_nodes; }
     32        BaseSyntaxNode( const BaseSyntaxNode & o ) : location(o.location) { ++*new_nodes; }
     33        BaseSyntaxNode & operator=( const BaseSyntaxNode & ) = default;
    2634
    2735        virtual ~BaseSyntaxNode() {}
     
    2937        virtual BaseSyntaxNode * clone() const = 0;
    3038        virtual void accept( Visitor & v ) = 0;
     39        virtual void accept( Visitor & v ) const = 0;
    3140        virtual BaseSyntaxNode * acceptMutator( Mutator & m ) = 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.
     41        /// Notes:
     42        /// * each node is responsible for indenting its children.
     43        /// * Expressions should not finish with a newline, since the expression's parent has better information.
    3544        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   }
    3945};
    4046
  • src/SynTree/BasicType.cc

    r7951100 rb067d9b  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Sep 25 14:14:03 2017
    13 // Update Count     : 11
     12// Last Modified On : Sun Aug  4 21:07:44 2019
     13// Update Count     : 13
    1414//
    1515
     
    3030
    3131bool BasicType::isInteger() const {
    32         switch ( kind ) {
    33           case Bool:
    34           case Char:
    35           case SignedChar:
    36           case UnsignedChar:
    37           case ShortSignedInt:
    38           case ShortUnsignedInt:
    39           case SignedInt:
    40           case UnsignedInt:
    41           case LongSignedInt:
    42           case LongUnsignedInt:
    43           case LongLongSignedInt:
    44           case LongLongUnsignedInt:
    45           case SignedInt128:
    46           case UnsignedInt128:
    47                 return true;
    48           case Float:
    49           case Double:
    50           case LongDouble:
    51           case FloatComplex:
    52           case DoubleComplex:
    53           case LongDoubleComplex:
    54           case FloatImaginary:
    55           case DoubleImaginary:
    56           case LongDoubleImaginary:
    57           case Float80:
    58           case Float128:
    59                 return false;
    60           case NUMBER_OF_BASIC_TYPES:
    61                 assert( false );
    62         } // switch
    63         assert( false );
    64         return false;
     32        return kind <= UnsignedInt128;
    6533}
    6634
  • src/SynTree/CommaExpr.cc

    r7951100 rb067d9b  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Mon May 02 15:19:44 2016
    13 // Update Count     : 1
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Mon Arg 12 16:11:00 2016
     13// Update Count     : 2
    1414//
    1515
     
    2323CommaExpr::CommaExpr( Expression *arg1, Expression *arg2 )
    2424                : Expression(), arg1( arg1 ), arg2( arg2 ) {
    25         // xxx - result of a comma expression is never an lvalue, so should set lvalue
    26         // to false on all result types. Actually doing this causes some strange things
    27         // to happen in later passes (particularly, Specialize, Lvalue, and Box). This needs to be looked into.
    2825        set_result( maybeClone( arg2->get_result() ) );
    29         // get_type->set_isLvalue( false );
    3026}
    3127
     
    3733        delete arg1;
    3834        delete arg2;
     35}
     36
     37bool CommaExpr::get_lvalue() const {
     38        // This is wrong by C, but the current implementation uses it.
     39        // (ex: Specialize, Lvalue and Box)
     40        return arg2->get_lvalue();
    3941}
    4042
  • src/SynTree/Constant.cc

    r7951100 rb067d9b  
    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 : Fri Jul 14 14:50:00 2017
    13 // Update Count     : 29
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Feb 13 18:11:22 2019
     13// Update Count     : 32
    1414//
    1515
     
    1919
    2020#include "Constant.h"
     21#include "Expression.h" // for ConstantExpr
    2122#include "Type.h"    // for BasicType, Type, Type::Qualifiers, PointerType
    2223
    23 Constant::Constant( Type * type, std::string rep, unsigned long long val ) : type( type ), rep( rep ), val( val ) {}
    24 Constant::Constant( Type * type, std::string rep, double val ) : type( type ), rep( rep ), val( val ) {}
     24Constant::Constant( Type * type, std::string rep, std::optional<unsigned long long> ival ) : type( type ), rep( rep ), ival( ival ) {}
    2525
    26 Constant::Constant( const Constant &other ) : rep( other.rep ), val( other.val ) {
     26Constant::Constant( const Constant &other ) : BaseSyntaxNode( other ), rep( other.rep ), ival( other.ival ) {
    2727        type = other.type->clone();
    2828}
     
    3434}
    3535
    36 Constant Constant::from_char( char c ) {
    37         return Constant( new BasicType( Type::Qualifiers(), BasicType::Char ), std::to_string( c ), (unsigned long long int)c );
    38 }
    39 
    4036Constant Constant::from_int( int i ) {
    4137        return Constant( new BasicType( Type::Qualifiers(), BasicType::SignedInt ), std::to_string( i ), (unsigned long long int)i );
     
    4440Constant Constant::from_ulong( unsigned long i ) {
    4541        return Constant( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), std::to_string( i ), (unsigned long long int)i );
    46 }
    47 
    48 Constant Constant::from_double( double d ) {
    49         return Constant( new BasicType( Type::Qualifiers(), BasicType::Double ), std::to_string( d ), d );
    5042}
    5143
     
    6355unsigned long long Constant::get_ival() const {
    6456        assertf( strict_dynamic_cast<BasicType*>(type)->isInteger(), "Attempt to retrieve ival from non-integer constant." );
    65         return val.ival;
    66 }
    67 
    68 double Constant::get_dval() const {
    69         assertf( ! strict_dynamic_cast<BasicType*>(type)->isInteger(), "Attempt to retrieve dval from integer constant." );
    70         return val.dval;
     57        return ival.value();
    7158}
    7259
    7360void Constant::print( std::ostream &os, Indenter ) const {
    74         os << "(" << rep << " " << val.ival;
     61        os << "(" << rep << " " << (ival ? toString(ival.value()) : "") ;
    7562        if ( type ) {
    7663                os << ": ";
  • src/SynTree/Constant.h

    r7951100 rb067d9b  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:54:46 2017
    13 // Update Count     : 17
     12// Last Modified On : Wed Jul 10 15:57:38 2019
     13// Update Count     : 19
    1414//
    1515
     
    1818#include <iosfwd>     // for ostream
    1919#include <string>     // for string
     20#include <optional>   // for optional
    2021
    2122#include "BaseSyntaxNode.h"
     
    2728class Constant : public BaseSyntaxNode {
    2829  public:
    29         Constant( Type * type, std::string rep, unsigned long long val );
    30         Constant( Type * type, std::string rep, double val );
     30        Constant( Type * type, std::string rep, std::optional<unsigned long long> i );
    3131        Constant( const Constant & other );
     32        Constant & operator=( const Constant & ) = default;
    3233        virtual ~Constant();
    3334
    34         virtual Constant * clone() const { return new Constant( *this ); }
     35        virtual Constant * clone() const override { return new Constant( *this ); }
    3536
    3637        Type * get_type() { return type; }
     
    3940        void set_value( std::string newValue ) { rep = newValue; }
    4041        unsigned long long get_ival() const;
    41         double get_dval() const;
    4242
    4343        /// generates a boolean constant of the given bool
    4444        static Constant from_bool( bool b );
    45         /// generates a char constant of the given char
    46         static Constant from_char( char c );
    4745        /// generates an integer constant of the given int
    4846        static Constant from_int( int i );
    4947        /// generates an integer constant of the given unsigned long int
    5048        static Constant from_ulong( unsigned long i );
    51         /// generates a floating point constant of the given double
    52         static Constant from_double( double d );
    5349
    5450        /// generates a null pointer value for the given type. void * if omitted.
    5551        static Constant null( Type * ptrtype = nullptr );
    5652
    57         virtual void accept( Visitor & v ) { v.visit( this ); }
    58         virtual Constant * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    59         virtual void print( std::ostream & os, Indenter indent = 0 ) const;
    60   private:
     53        virtual void accept( Visitor & v ) override { v.visit( this ); }
     54        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     55        virtual Constant * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     56        virtual void print( std::ostream & os, Indenter indent = 0 ) const override;
     57
    6158        Type * type;
    6259        std::string rep;
    63         union Val {
    64                 unsigned long long ival;
    65                 double dval;
    66                 Val( unsigned long long ival ) : ival( ival ) {}
    67                 Val( double dval ) : dval( dval ) {}
    68         } val;
     60        std::optional<unsigned long long> ival;
    6961};
    7062
  • src/SynTree/DeclReplacer.cc

    r7951100 rb067d9b  
    3030                        bool debug;
    3131                public:
     32                        size_t replaced;
     33
     34                public:
    3235                        DeclReplacer( const DeclMap & declMap, const TypeMap & typeMap, bool debug = false );
    3336
     
    3841                        void previsit( TypeInstType * inst );
    3942                };
     43
     44                /// Mutator that replaces uses of declarations with arbitrary expressions, according to the supplied mapping
     45                struct ExprDeclReplacer {
     46                private:
     47                        const ExprMap & exprMap;
     48                        bool debug;
     49                public:
     50                        size_t replaced;
     51
     52                public:
     53                        ExprDeclReplacer( const ExprMap & exprMap, bool debug = false );
     54
     55                        // replace variable with new node from expr map
     56                        Expression * postmutate( VariableExpr * varExpr );
     57                };
    4058        }
    4159
    42         void replace( BaseSyntaxNode * node, const DeclMap & declMap, const TypeMap & typeMap, bool debug ) {
     60        size_t replace( BaseSyntaxNode * node, const DeclMap & declMap, const TypeMap & typeMap, bool debug ) {
    4361                PassVisitor<DeclReplacer> replacer( declMap, typeMap, debug );
    4462                maybeAccept( node, replacer );
     63                return replacer.pass.replaced;
    4564        }
    4665
    47         void replace( BaseSyntaxNode * node, const DeclMap & declMap, bool debug ) {
     66        size_t replace( BaseSyntaxNode * node, const DeclMap & declMap, bool debug ) {
    4867                TypeMap typeMap;
    49                 replace( node, declMap, typeMap, debug );
     68                return replace( node, declMap, typeMap, debug );
    5069        }
    5170
    52         void replace( BaseSyntaxNode * node, const TypeMap & typeMap, bool debug ) {
     71        size_t replace( BaseSyntaxNode * node, const TypeMap & typeMap, bool debug ) {
    5372                DeclMap declMap;
    54                 replace( node, declMap, typeMap, debug );
     73                return replace( node, declMap, typeMap, debug );
     74        }
     75
     76        size_t replace( BaseSyntaxNode *& node, const ExprMap & exprMap, bool debug ) {
     77                PassVisitor<ExprDeclReplacer> replacer( exprMap, debug );
     78                node = maybeMutate( node, replacer );
     79                return replacer.pass.replaced;
    5580        }
    5681
    5782        namespace {
    58                 DeclReplacer::DeclReplacer( const DeclMap & declMap, const TypeMap & typeMap, bool debug ) : declMap( declMap ), typeMap( typeMap ) , debug( debug ) {}
     83                DeclReplacer::DeclReplacer( const DeclMap & declMap, const TypeMap & typeMap, bool debug ) : declMap( declMap ), typeMap( typeMap ) , debug( debug ), replaced( 0 ) {}
    5984
    6085                // replace variable with new node from decl map
     
    6287                        // xxx - assertions and parameters aren't accounted for in this... (i.e. they aren't inserted into the map when it's made, only DeclStmts are)
    6388                        if ( declMap.count( varExpr->var ) ) {
     89                                replaced++;
    6490                                auto replacement = declMap.at( varExpr->var );
    6591                                if ( debug ) {
     
    7298                void DeclReplacer::previsit( TypeInstType * inst ) {
    7399                        if ( typeMap.count( inst->baseType ) ) {
     100                                replaced++;
    74101                                auto replacement = typeMap.at( inst->baseType );
    75102                                if ( debug ) {
     
    79106                        }
    80107                }
     108
     109                ExprDeclReplacer::ExprDeclReplacer( const ExprMap & exprMap, bool debug ) : exprMap( exprMap ), debug( debug ), replaced( 0 ) {}
     110
     111                Expression * ExprDeclReplacer::postmutate( VariableExpr * varExpr ) {
     112                        if ( exprMap.count( varExpr->var ) ) {
     113                                replaced++;
     114                                Expression * replacement = exprMap.at( varExpr->var )->clone();
     115                                if ( debug ) {
     116                                        std::cerr << "replacing variable reference: " << (void*)varExpr->var << " " << varExpr->var << " with " << (void*)replacement << " " << replacement << std::endl;
     117                                }
     118                                std::swap( varExpr->env, replacement->env );
     119                                delete varExpr;
     120                                return replacement;
     121                        }
     122                        return varExpr;
     123                }
    81124        }
    82125} // namespace VarExprReplacer
  • src/SynTree/DeclReplacer.h

    r7951100 rb067d9b  
    2626        typedef std::map< DeclarationWithType *, DeclarationWithType * > DeclMap;
    2727        typedef std::map< TypeDecl *, TypeDecl * > TypeMap;
     28        typedef std::map< DeclarationWithType *, Expression * > ExprMap;
    2829
    29         void replace( BaseSyntaxNode * node, const DeclMap & declMap, bool debug = false );
    30         void replace( BaseSyntaxNode * node, const TypeMap & typeMap, bool debug = false );
    31         void replace( BaseSyntaxNode * node, const DeclMap & declMap, const TypeMap & typeMap, bool debug = false );
     30        size_t replace( BaseSyntaxNode * node, const DeclMap & declMap, bool debug = false );
     31        size_t replace( BaseSyntaxNode * node, const TypeMap & typeMap, bool debug = false );
     32        size_t replace( BaseSyntaxNode * node, const DeclMap & declMap, const TypeMap & typeMap, bool debug = false );
     33
     34        size_t replace( BaseSyntaxNode *& node, const ExprMap & exprMap, bool debug = false);
     35
     36        template<typename T>
     37        size_t replace( T *& node, const ExprMap & exprMap, bool debug = false ) {
     38                if ( ! node ) return 0ul;
     39                BaseSyntaxNode * arg = node;
     40                size_t replaced = replace( arg, exprMap, debug );
     41                node = dynamic_cast<T *>( arg );
     42                assertf( node, "DeclReplacer fundamentally changed the type of its argument." );
     43                return replaced;
     44        }
    3245}
    3346
  • src/SynTree/Declaration.cc

    r7951100 rb067d9b  
    2727
    2828static UniqueId lastUniqueId = 0;
    29 typedef std::map< UniqueId, Declaration* > IdMapType;
    30 static IdMapType idMap;
    3129
    3230Declaration::Declaration( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage )
    33                 : name( name ), linkage( linkage ), storageClasses( scs ), uniqueId( 0 ) {
     31                : name( name ), linkage( linkage ), uniqueId( 0 ), storageClasses( scs ) {
    3432}
    3533
    3634Declaration::Declaration( const Declaration &other )
    37         : BaseSyntaxNode( other ), name( other.name ), linkage( other.linkage ), extension( other.extension ), storageClasses( other.storageClasses ), uniqueId( other.uniqueId ) {
     35        : BaseSyntaxNode( other ), name( other.name ), linkage( other.linkage ), extension( other.extension ), uniqueId( other.uniqueId ), storageClasses( other.storageClasses ) {
    3836}
    3937
     
    4543        if ( uniqueId ) return;
    4644        uniqueId = ++lastUniqueId;
    47         idMap[ uniqueId ] = this;
    4845}
    49 
    50 Declaration *Declaration::declFromId( UniqueId id ) {
    51         IdMapType::const_iterator i = idMap.find( id );
    52         return i != idMap.end() ? i->second : 0;
    53 }
    54 
    55 void Declaration::dumpIds( std::ostream &os ) {
    56         for ( IdMapType::const_iterator i = idMap.begin(); i != idMap.end(); ++i ) {
    57                 os << i->first << " -> ";
    58                 i->second->printShort( os );
    59                 os << std::endl;
    60         } // for
    61 }
    62 
    6346
    6447AsmDecl::AsmDecl( AsmStmt *stmt ) : Declaration( "", Type::StorageClasses(), LinkageSpec::C ), stmt( stmt ) {
  • src/SynTree/Declaration.h

    r7951100 rb067d9b  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Sep  3 19:24:06 2017
    13 // Update Count     : 131
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thr May  2 10:47:00 2019
     13// Update Count     : 135
    1414//
    1515
     
    1919#include <iosfwd>                // for ostream
    2020#include <list>                  // for list
     21#include <unordered_map>         // for unordered_map
    2122#include <string>                // for string, operator+, allocator, to_string
    2223
     
    6263        void fixUniqueId( void );
    6364        virtual Declaration *clone() const override = 0;
    64         virtual void accept( Visitor &v ) override = 0;
     65        virtual void accept( Visitor & v ) override = 0;
     66        virtual void accept( Visitor & v ) const override = 0;
    6567        virtual Declaration *acceptMutator( Mutator &m ) override = 0;
    6668        virtual void print( std::ostream &os, Indenter indent = {} ) const override = 0;
    6769        virtual void printShort( std::ostream &os, Indenter indent = {} ) const = 0;
    6870
    69         static void dumpIds( std::ostream &os );
    70         static Declaration *declFromId( UniqueId id );
    71 
    72   private:
     71        UniqueId uniqueId;
    7372        Type::StorageClasses storageClasses;
    74         UniqueId uniqueId;
     73  private:
    7574};
    7675
     
    141140
    142141        virtual ObjectDecl *clone() const override { return new ObjectDecl( *this ); }
    143         virtual void accept( Visitor &v ) override { v.visit( this ); }
     142        virtual void accept( Visitor & v ) override { v.visit( this ); }
     143        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    144144        virtual DeclarationWithType *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    145145        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
     
    166166        CompoundStmt *get_statements() const { return statements; }
    167167        void set_statements( CompoundStmt *newValue ) { statements = newValue; }
     168        bool has_body() const { return NULL != statements; }
    168169
    169170        static FunctionDecl * newFunction( const std::string & name, FunctionType * type, CompoundStmt * statements );
    170171
    171172        virtual FunctionDecl *clone() const override { return new FunctionDecl( *this ); }
    172         virtual void accept( Visitor &v ) override { v.visit( this ); }
     173        virtual void accept( Visitor & v ) override { v.visit( this ); }
     174        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    173175        virtual DeclarationWithType *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    174176        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
     
    202204        typedef NamedTypeDecl Parent;
    203205  public:
    204         enum Kind { Dtype, Ftype, Ttype };
     206        enum Kind { Dtype, Ftype, Ttype, NUMBER_OF_KINDS };
    205207
    206208        Type * init;
     
    211213                TypeDecl::Kind kind;
    212214                bool isComplete;
     215
    213216                Data() : kind( (TypeDecl::Kind)-1 ), isComplete( false ) {}
    214217                Data( TypeDecl * typeDecl ) : Data( typeDecl->get_kind(), typeDecl->isComplete() ) {}
    215218                Data( Kind kind, bool isComplete ) : kind( kind ), isComplete( isComplete ) {}
     219                Data( const Data& d1, const Data& d2 )
     220                : kind( d1.kind ), isComplete ( d1.isComplete || d2.isComplete ) {}
     221
    216222                bool operator==(const Data & other) const { return kind == other.kind && isComplete == other.isComplete; }
    217223                bool operator!=(const Data & other) const { return !(*this == other);}
     
    235241
    236242        virtual TypeDecl *clone() const override { return new TypeDecl( *this ); }
    237         virtual void accept( Visitor &v ) override { v.visit( this ); }
    238         virtual Declaration *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    239         virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    240 
    241   private:
     243        virtual void accept( Visitor & v ) override { v.visit( this ); }
     244        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     245        virtual Declaration *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
     246        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
     247
    242248        Kind kind;
    243249};
     
    254260
    255261        virtual TypedefDecl *clone() const override { return new TypedefDecl( *this ); }
    256         virtual void accept( Visitor &v ) override { v.visit( this ); }
     262        virtual void accept( Visitor & v ) override { v.visit( this ); }
     263        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    257264        virtual Declaration *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    258265  private:
     
    266273        bool body;
    267274        std::list< Attribute * > attributes;
     275        AggregateDecl * parent = nullptr;
    268276
    269277        AggregateDecl( const std::string &name, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall );
     
    280288        AggregateDecl * set_body( bool body ) { AggregateDecl::body = body; return this; }
    281289
    282         virtual void print( std::ostream &os, Indenter indent = {} ) const override;
     290        virtual void print( std::ostream &os, Indenter indent = {} ) const override final;
    283291        virtual void printShort( std::ostream &os, Indenter indent = {} ) const override;
    284292  protected:
     
    297305
    298306        virtual StructDecl *clone() const override { return new StructDecl( *this ); }
    299         virtual void accept( Visitor &v ) override { v.visit( this ); }
    300         virtual Declaration *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    301   private:
     307        virtual void accept( Visitor & v ) override { v.visit( this ); }
     308        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     309        virtual Declaration *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    302310        DeclarationNode::Aggregate kind;
     311  private:
    303312        virtual std::string typeString() const override;
    304313};
     
    311320
    312321        virtual UnionDecl *clone() const override { return new UnionDecl( *this ); }
    313         virtual void accept( Visitor &v ) override { v.visit( this ); }
     322        virtual void accept( Visitor & v ) override { v.visit( this ); }
     323        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    314324        virtual Declaration *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    315325  private:
     
    326336
    327337        virtual EnumDecl *clone() const override { return new EnumDecl( *this ); }
    328         virtual void accept( Visitor &v ) override { v.visit( this ); }
    329         virtual Declaration *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    330   private:
    331         std::map< std::string, long long int > enumValues;
     338        virtual void accept( Visitor & v ) override { v.visit( this ); }
     339        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     340        virtual Declaration *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
     341  private:
     342        std::unordered_map< std::string, long long int > enumValues;
    332343        virtual std::string typeString() const override;
    333344};
     
    342353
    343354        virtual TraitDecl *clone() const override { return new TraitDecl( *this ); }
    344         virtual void accept( Visitor &v ) override { v.visit( this ); }
    345         virtual Declaration *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    346   private:
    347         virtual std::string typeString() const override;
     355        virtual void accept( Visitor & v ) override { v.visit( this ); }
     356        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     357        virtual Declaration *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
     358  private:
     359        virtual std::string typeString() const override;
     360};
     361
     362class WithStmt : public Declaration {
     363public:
     364        std::list< Expression * > exprs;
     365        Statement * stmt;
     366
     367        WithStmt( const std::list< Expression * > & exprs, Statement * stmt );
     368        WithStmt( const WithStmt & other );
     369        virtual ~WithStmt();
     370
     371        virtual WithStmt * clone() const override { return new WithStmt( *this ); }
     372        virtual void accept( Visitor & v ) override { v.visit( this ); }
     373        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     374        virtual Declaration * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     375        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     376        virtual void printShort( std::ostream & os, Indenter indent = {} ) const override { print(os, indent); }
    348377};
    349378
     
    360389
    361390        virtual AsmDecl *clone() const override { return new AsmDecl( *this ); }
    362         virtual void accept( Visitor &v ) override { v.visit( this ); }
     391        virtual void accept( Visitor & v ) override { v.visit( this ); }
     392        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    363393        virtual AsmDecl *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    364394        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
     
    376406
    377407        virtual StaticAssertDecl * clone() const override { return new StaticAssertDecl( *this ); }
    378         virtual void accept( Visitor &v ) override { v.visit( this ); }
     408        virtual void accept( Visitor & v ) override { v.visit( this ); }
     409        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    379410        virtual StaticAssertDecl * acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    380411        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
  • src/SynTree/Expression.cc

    r7951100 rb067d9b  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jul 25 14:15:47 2017
    13 // Update Count     : 54
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thr Aug 15 13:43:00 2019
     13// Update Count     : 64
    1414//
    1515
     
    1919#include <iostream>                  // for ostream, operator<<, basic_ostream
    2020#include <list>                      // for list, _List_iterator, list<>::co...
     21#include <set>                       // for set
    2122
    2223#include "Common/utility.h"          // for maybeClone, cloneAll, deleteAll
     
    3334#include "GenPoly/Lvalue.h"
    3435
    35 void printInferParams( const InferredParams & inferParams, std::ostream &os, Indenter indent, int level ) {
     36void printInferParams( const InferredParams & inferParams, std::ostream & os, Indenter indent, int level ) {
    3637        if ( ! inferParams.empty() ) {
    3738                os << indent << "with inferred parameters " << level << ":" << std::endl;
    3839                for ( InferredParams::const_iterator i = inferParams.begin(); i != inferParams.end(); ++i ) {
    3940                        os << indent+1;
    40                         Declaration::declFromId( i->second.decl )->printShort( os, indent+1 );
     41                        assert(i->second.declptr);
     42                        i->second.declptr->printShort( os, indent+1 );
    4143                        os << std::endl;
    42                         printInferParams( *i->second.inferParams, os, indent+1, level+1 );
     44                        printInferParams( i->second.expr->inferParams, os, indent+1, level+1 );
    4345                } // for
    4446        } // if
     
    4749Expression::Expression() : result( 0 ), env( 0 ) {}
    4850
    49 Expression::Expression( const Expression &other ) : BaseSyntaxNode( other ), result( maybeClone( other.result ) ), env( maybeClone( other.env ) ), extension( other.extension ), inferParams( other.inferParams ) {
    50 }
     51Expression::Expression( const Expression & other ) : BaseSyntaxNode( other ), result( maybeClone( other.result ) ), env( maybeClone( other.env ) ), extension( other.extension ), inferParams( other.inferParams ), resnSlots( other.resnSlots ) {}
    5152
    5253void Expression::spliceInferParams( Expression * other ) {
     
    5556                inferParams[p.first] = std::move( p.second );
    5657        }
     58        resnSlots.insert( resnSlots.end(), other->resnSlots.begin(), other->resnSlots.end() );
    5759}
    5860
     
    6264}
    6365
    64 void Expression::print( std::ostream &os, Indenter indent ) const {
     66bool Expression::get_lvalue() const {
     67        return false;
     68}
     69
     70void Expression::print( std::ostream & os, Indenter indent ) const {
    6571        printInferParams( inferParams, os, indent+1, 0 );
    6672
     
    7985}
    8086
    81 ConstantExpr::ConstantExpr( const ConstantExpr &other) : Expression( other ), constant( other.constant ) {
     87ConstantExpr::ConstantExpr( const ConstantExpr & other) : Expression( other ), constant( other.constant ) {
    8288}
    8389
    8490ConstantExpr::~ConstantExpr() {}
    8591
    86 void ConstantExpr::print( std::ostream &os, Indenter indent ) const {
     92void ConstantExpr::print( std::ostream & os, Indenter indent ) const {
    8793        os << "constant expression " ;
    8894        constant.print( os );
     
    103109}
    104110
     111VariableExpr::VariableExpr() : Expression(), var( nullptr ) {}
     112
    105113VariableExpr::VariableExpr( DeclarationWithType *_var ) : Expression(), var( _var ) {
    106114        assert( var );
    107115        assert( var->get_type() );
    108116        Type * type = var->get_type()->clone();
    109         type->set_lvalue( true );
    110117
    111118        // xxx - doesn't quite work yet - get different alternatives with the same cost
     
    117124        //      long long int value;
    118125        //      if ( decl->valueOf( var, value ) ) {
    119         //              type->set_lvalue( false );
     126        //              type->set_lvalue( false ); // Would have to move to get_lvalue.
    120127        //      }
    121128        // }
     
    124131}
    125132
    126 VariableExpr::VariableExpr( const VariableExpr &other ) : Expression( other ), var( other.var ) {
     133VariableExpr::VariableExpr( const VariableExpr & other ) : Expression( other ), var( other.var ) {
    127134}
    128135
    129136VariableExpr::~VariableExpr() {
    130137        // don't delete the declaration, since it points somewhere else in the tree
     138}
     139
     140bool VariableExpr::get_lvalue() const {
     141        // It isn't always an lvalue, but it is never an rvalue.
     142        return true;
    131143}
    132144
     
    137149}
    138150
    139 void VariableExpr::print( std::ostream &os, Indenter indent ) const {
     151void VariableExpr::print( std::ostream & os, Indenter indent ) const {
    140152        os << "Variable Expression: ";
    141153        var->printShort(os, indent);
     
    143155}
    144156
    145 SizeofExpr::SizeofExpr( Expression *expr_ ) :
     157SizeofExpr::SizeofExpr( Expression * expr_ ) :
    146158                Expression(), expr(expr_), type(0), isType(false) {
    147159        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
    148160}
    149161
    150 SizeofExpr::SizeofExpr( Type *type_ ) :
     162SizeofExpr::SizeofExpr( Type * type_ ) :
    151163                Expression(), expr(0), type(type_), isType(true) {
    152164        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
    153165}
    154166
    155 SizeofExpr::SizeofExpr( const SizeofExpr &other ) :
     167SizeofExpr::SizeofExpr( const SizeofExpr & other ) :
    156168        Expression( other ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) {
    157169}
     
    162174}
    163175
    164 void SizeofExpr::print( std::ostream &os, Indenter indent) const {
     176void SizeofExpr::print( std::ostream & os, Indenter indent) const {
    165177        os << "Sizeof Expression on: ";
    166178        if (isType) type->print(os, indent+1);
     
    169181}
    170182
    171 AlignofExpr::AlignofExpr( Expression *expr_ ) :
     183AlignofExpr::AlignofExpr( Expression * expr_ ) :
    172184                Expression(), expr(expr_), type(0), isType(false) {
    173185        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
    174186}
    175187
    176 AlignofExpr::AlignofExpr( Type *type_ ) :
     188AlignofExpr::AlignofExpr( Type * type_ ) :
    177189                Expression(), expr(0), type(type_), isType(true) {
    178190        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
    179191}
    180192
    181 AlignofExpr::AlignofExpr( const AlignofExpr &other ) :
     193AlignofExpr::AlignofExpr( const AlignofExpr & other ) :
    182194        Expression( other ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) {
    183195}
     
    188200}
    189201
    190 void AlignofExpr::print( std::ostream &os, Indenter indent) const {
     202void AlignofExpr::print( std::ostream & os, Indenter indent) const {
    191203        os << "Alignof Expression on: ";
    192204        if (isType) type->print(os, indent+1);
     
    195207}
    196208
    197 UntypedOffsetofExpr::UntypedOffsetofExpr( Type *type, const std::string &member ) :
     209UntypedOffsetofExpr::UntypedOffsetofExpr( Type * type, const std::string & member ) :
    198210                Expression(), type(type), member(member) {
    199211        assert( type );
     
    201213}
    202214
    203 UntypedOffsetofExpr::UntypedOffsetofExpr( const UntypedOffsetofExpr &other ) :
     215UntypedOffsetofExpr::UntypedOffsetofExpr( const UntypedOffsetofExpr & other ) :
    204216        Expression( other ), type( maybeClone( other.type ) ), member( other.member ) {}
    205217
     
    208220}
    209221
    210 void UntypedOffsetofExpr::print( std::ostream &os, Indenter indent) const {
     222void UntypedOffsetofExpr::print( std::ostream & os, Indenter indent) const {
    211223        os << "Untyped Offsetof Expression on member " << member << " of ";
    212224        type->print(os, indent+1);
     
    214226}
    215227
    216 OffsetofExpr::OffsetofExpr( Type *type, DeclarationWithType *member ) :
     228OffsetofExpr::OffsetofExpr( Type * type, DeclarationWithType * member ) :
    217229                Expression(), type(type), member(member) {
    218230        assert( member );
     
    221233}
    222234
    223 OffsetofExpr::OffsetofExpr( const OffsetofExpr &other ) :
     235OffsetofExpr::OffsetofExpr( const OffsetofExpr & other ) :
    224236        Expression( other ), type( maybeClone( other.type ) ), member( other.member ) {}
    225237
     
    228240}
    229241
    230 void OffsetofExpr::print( std::ostream &os, Indenter indent) const {
     242void OffsetofExpr::print( std::ostream & os, Indenter indent) const {
    231243        os << "Offsetof Expression on member " << member->name << " of ";
    232244        type->print(os, indent+1);
     
    234246}
    235247
    236 OffsetPackExpr::OffsetPackExpr( StructInstType *type ) : Expression(), type( type ) {
     248OffsetPackExpr::OffsetPackExpr( StructInstType * type ) : Expression(), type( type ) {
    237249        assert( type );
    238250        set_result( new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, false, false ) );
    239251}
    240252
    241 OffsetPackExpr::OffsetPackExpr( const OffsetPackExpr &other ) : Expression( other ), type( maybeClone( other.type ) ) {}
     253OffsetPackExpr::OffsetPackExpr( const OffsetPackExpr & other ) : Expression( other ), type( maybeClone( other.type ) ) {}
    242254
    243255OffsetPackExpr::~OffsetPackExpr() { delete type; }
    244256
    245 void OffsetPackExpr::print( std::ostream &os, Indenter indent ) const {
     257void OffsetPackExpr::print( std::ostream & os, Indenter indent ) const {
    246258        os << "Offset pack expression on ";
    247259        type->print(os, indent+1);
     
    249261}
    250262
    251 AttrExpr::AttrExpr( Expression *attr, Expression *expr_ ) :
    252                 Expression(), attr( attr ), expr(expr_), type(0), isType(false) {
    253 }
    254 
    255 AttrExpr::AttrExpr( Expression *attr, Type *type_ ) :
    256                 Expression(), attr( attr ), expr(0), type(type_), isType(true) {
    257 }
    258 
    259 AttrExpr::AttrExpr( const AttrExpr &other ) :
    260                 Expression( other ), attr( maybeClone( other.attr ) ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) {
    261 }
    262 
    263 AttrExpr::~AttrExpr() {
    264         delete attr;
    265         delete expr;
    266         delete type;
    267 }
    268 
    269 void AttrExpr::print( std::ostream &os, Indenter indent) const {
    270         os << "Attr ";
    271         attr->print( os, indent+1);
    272         if ( isType || expr ) {
    273                 os << "applied to: ";
    274                 if (isType) type->print(os, indent+1);
    275                 else expr->print(os, indent+1);
    276         } // if
    277         Expression::print( os, indent );
    278 }
    279 
    280 CastExpr::CastExpr( Expression *arg, Type *toType, bool isGenerated ) : Expression(), arg(arg), isGenerated( isGenerated ) {
     263CastExpr::CastExpr( Expression * arg, Type * toType, bool isGenerated ) : arg(arg), isGenerated( isGenerated ) {
    281264        set_result(toType);
    282265}
    283266
    284 CastExpr::CastExpr( Expression *arg, bool isGenerated ) : Expression(), arg(arg), isGenerated( isGenerated ) {
     267CastExpr::CastExpr( Expression * arg, bool isGenerated ) : arg(arg), isGenerated( isGenerated ) {
    285268        set_result( new VoidType( Type::Qualifiers() ) );
    286269}
    287270
    288 CastExpr::CastExpr( const CastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ), isGenerated( other.isGenerated ) {
     271CastExpr::CastExpr( const CastExpr & other ) : Expression( other ), arg( maybeClone( other.arg ) ), isGenerated( other.isGenerated ) {
    289272}
    290273
     
    293276}
    294277
    295 void CastExpr::print( std::ostream &os, Indenter indent ) const {
    296         os << "Cast of:" << std::endl << indent+1;
     278bool CastExpr::get_lvalue() const {
     279        // This is actually wrong by C, but it works with our current set-up.
     280        return arg->get_lvalue();
     281}
     282
     283void CastExpr::print( std::ostream & os, Indenter indent ) const {
     284        os << (isGenerated ? "Generated " : "Explicit ") << "Cast of:" << std::endl << indent+1;
    297285        arg->print(os, indent+1);
    298286        os << std::endl << indent << "... to:";
     
    306294}
    307295
    308 KeywordCastExpr::KeywordCastExpr( Expression *arg, Target target ) : Expression(), arg(arg), target( target ) {
    309 }
    310 
    311 KeywordCastExpr::KeywordCastExpr( const KeywordCastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ), target( other.target ) {
     296KeywordCastExpr::KeywordCastExpr( Expression * arg, Target target ) : Expression(), arg(arg), target( target ) {
     297}
     298
     299KeywordCastExpr::KeywordCastExpr( const KeywordCastExpr & other ) : Expression( other ), arg( maybeClone( other.arg ) ), target( other.target ) {
    312300}
    313301
     
    327315}
    328316
    329 void KeywordCastExpr::print( std::ostream &os, Indenter indent ) const {
     317void KeywordCastExpr::print( std::ostream & os, Indenter indent ) const {
    330318        os << "Keyword Cast of:" << std::endl << indent+1;
    331319        arg->print(os, indent+1);
     
    335323}
    336324
    337 VirtualCastExpr::VirtualCastExpr( Expression *arg_, Type *toType ) : Expression(), arg(arg_) {
     325VirtualCastExpr::VirtualCastExpr( Expression * arg_, Type * toType ) : Expression(), arg(arg_) {
    338326        set_result(toType);
    339327}
    340328
    341 VirtualCastExpr::VirtualCastExpr( const VirtualCastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ) {
     329VirtualCastExpr::VirtualCastExpr( const VirtualCastExpr & other ) : Expression( other ), arg( maybeClone( other.arg ) ) {
    342330}
    343331
     
    346334}
    347335
    348 void VirtualCastExpr::print( std::ostream &os, Indenter indent ) const {
     336void VirtualCastExpr::print( std::ostream & os, Indenter indent ) const {
    349337        os << "Virtual Cast of:" << std::endl << indent+1;
    350338        arg->print(os, indent+1);
     
    359347}
    360348
    361 UntypedMemberExpr::UntypedMemberExpr( Expression * member, Expression *aggregate ) :
     349UntypedMemberExpr::UntypedMemberExpr( Expression * member, Expression * aggregate ) :
    362350                Expression(), member(member), aggregate(aggregate) {
    363351        assert( aggregate );
    364352}
    365353
    366 UntypedMemberExpr::UntypedMemberExpr( const UntypedMemberExpr &other ) :
     354UntypedMemberExpr::UntypedMemberExpr( const UntypedMemberExpr & other ) :
    367355                Expression( other ), member( maybeClone( other.member ) ), aggregate( maybeClone( other.aggregate ) ) {
    368356}
     
    373361}
    374362
    375 void UntypedMemberExpr::print( std::ostream &os, Indenter indent ) const {
     363bool UntypedMemberExpr::get_lvalue() const {
     364        return aggregate->get_lvalue();
     365}
     366
     367void UntypedMemberExpr::print( std::ostream & os, Indenter indent ) const {
    376368        os << "Untyped Member Expression, with field: " << std::endl << indent+1;
    377369        member->print(os, indent+1 );
    378         os << indent << "... from aggregate: " << std::endl << indent+1;
     370        os << indent << "... from aggregate:" << std::endl << indent+1;
    379371        aggregate->print(os, indent+1);
    380372        Expression::print( os, indent );
    381373}
    382374
    383 MemberExpr::MemberExpr( DeclarationWithType *member, Expression *aggregate ) :
     375MemberExpr::MemberExpr( DeclarationWithType * member, Expression * aggregate ) :
    384376                Expression(), member(member), aggregate(aggregate) {
    385377        assert( member );
     
    391383        sub.apply( res );
    392384        result = res;
    393         result->set_lvalue( true );
    394385        result->get_qualifiers() |= aggregate->result->get_qualifiers();
    395386}
    396387
    397 MemberExpr::MemberExpr( const MemberExpr &other ) :
     388MemberExpr::MemberExpr( const MemberExpr & other ) :
    398389                Expression( other ), member( other.member ), aggregate( maybeClone( other.aggregate ) ) {
    399390}
     
    404395}
    405396
    406 void MemberExpr::print( std::ostream &os, Indenter indent ) const {
    407         os << "Member Expression, with field: " << std::endl;
     397bool MemberExpr::get_lvalue() const {
     398        // This is actually wrong by C, but it works with our current set-up.
     399        return true;
     400}
     401
     402void MemberExpr::print( std::ostream & os, Indenter indent ) const {
     403        os << "Member Expression, with field:" << std::endl;
    408404        os << indent+1;
    409405        member->print( os, indent+1 );
    410         os << std::endl << indent << "... from aggregate: " << std::endl << indent+1;
     406        os << std::endl << indent << "... from aggregate:" << std::endl << indent+1;
    411407        aggregate->print(os, indent + 1);
    412408        Expression::print( os, indent );
    413409}
    414410
    415 UntypedExpr::UntypedExpr( Expression *function, const std::list<Expression *> &args ) :
     411UntypedExpr::UntypedExpr( Expression * function, const std::list<Expression *> & args ) :
    416412                Expression(), function(function), args(args) {}
    417413
    418 UntypedExpr::UntypedExpr( const UntypedExpr &other ) :
     414UntypedExpr::UntypedExpr( const UntypedExpr & other ) :
    419415                Expression( other ), function( maybeClone( other.function ) ) {
    420416        cloneAll( other.args, args );
     
    435431                        // if references are still allowed in the AST, dereference returns a reference
    436432                        ret->set_result( new ReferenceType( Type::Qualifiers(), ret->get_result() ) );
    437                 } else {
    438                         // references have been removed, in which case dereference returns an lvalue of the base type.
    439                         ret->result->set_lvalue( true );
    440433                }
    441434        }
     
    454447}
    455448
    456 
    457 void UntypedExpr::print( std::ostream &os, Indenter indent ) const {
    458         os << "Applying untyped: " << std::endl;
     449bool UntypedExpr::get_lvalue() const {
     450        // from src/GenPoly/Lvalue.cc: isIntrinsicReference
     451        static std::set<std::string> lvalueFunctions = { "*?", "?[?]" };
     452        std::string fname = InitTweak::getFunctionName( const_cast< UntypedExpr * >( this ) );
     453        return lvalueFunctions.count(fname);
     454}
     455
     456void UntypedExpr::print( std::ostream & os, Indenter indent ) const {
     457        os << "Applying untyped:" << std::endl;
    459458        os << indent+1;
    460459        function->print(os, indent+1);
    461         os << std::endl << indent << "...to: " << std::endl;
     460        os << std::endl << indent << "...to:" << std::endl;
    462461        printAll(args, os, indent+1);
    463462        Expression::print( os, indent );
     
    469468}
    470469
    471 NameExpr::NameExpr( const NameExpr &other ) : Expression( other ), name( other.name ) {
     470NameExpr::NameExpr( const NameExpr & other ) : Expression( other ), name( other.name ) {
    472471}
    473472
    474473NameExpr::~NameExpr() {}
    475474
    476 void NameExpr::print( std::ostream &os, Indenter indent ) const {
     475void NameExpr::print( std::ostream & os, Indenter indent ) const {
    477476        os << "Name: " << get_name();
    478477        Expression::print( os, indent );
    479478}
    480479
    481 LogicalExpr::LogicalExpr( Expression *arg1_, Expression *arg2_, bool andp ) :
     480LogicalExpr::LogicalExpr( Expression * arg1_, Expression * arg2_, bool andp ) :
    482481                Expression(), arg1(arg1_), arg2(arg2_), isAnd(andp) {
    483482        set_result( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) );
    484483}
    485484
    486 LogicalExpr::LogicalExpr( const LogicalExpr &other ) :
     485LogicalExpr::LogicalExpr( const LogicalExpr & other ) :
    487486                Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), isAnd( other.isAnd ) {
    488487}
     
    493492}
    494493
    495 void LogicalExpr::print( std::ostream &os, Indenter indent )const {
     494void LogicalExpr::print( std::ostream & os, Indenter indent )const {
    496495        os << "Short-circuited operation (" << (isAnd ? "and" : "or") << ") on: ";
    497496        arg1->print(os);
     
    504503                Expression(), arg1(arg1), arg2(arg2), arg3(arg3) {}
    505504
    506 ConditionalExpr::ConditionalExpr( const ConditionalExpr &other ) :
     505ConditionalExpr::ConditionalExpr( const ConditionalExpr & other ) :
    507506                Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), arg3( maybeClone( other.arg3 ) ) {
    508507}
     
    514513}
    515514
    516 void ConditionalExpr::print( std::ostream &os, Indenter indent ) const {
     515bool ConditionalExpr::get_lvalue() const {
     516        return false;
     517}
     518
     519void ConditionalExpr::print( std::ostream & os, Indenter indent ) const {
    517520        os << "Conditional expression on: " << std::endl << indent+1;
    518521        arg1->print( os, indent+1 );
     
    527530
    528531
    529 void AsmExpr::print( std::ostream &os, Indenter indent ) const {
     532void AsmExpr::print( std::ostream & os, Indenter indent ) const {
    530533        os << "Asm Expression: " << std::endl;
    531534        if ( inout ) inout->print( os, indent+1 );
     
    538541        assert( callExpr );
    539542        assert( callExpr->result );
    540         set_result( callExpr->get_result()->clone() );
     543        set_result( callExpr->result->clone() );
    541544}
    542545
    543546ImplicitCopyCtorExpr::ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other ) : Expression( other ), callExpr( maybeClone( other.callExpr ) ) {
    544         cloneAll( other.tempDecls, tempDecls );
    545         cloneAll( other.returnDecls, returnDecls );
    546         cloneAll( other.dtors, dtors );
    547547}
    548548
     
    550550        set_env( nullptr ); // ImplicitCopyCtorExpr does not take ownership of an environment
    551551        delete callExpr;
    552         deleteAll( tempDecls );
    553         deleteAll( returnDecls );
    554         deleteAll( dtors );
    555 }
    556 
    557 void ImplicitCopyCtorExpr::print( std::ostream &os, Indenter indent ) const {
     552}
     553
     554void ImplicitCopyCtorExpr::print( std::ostream & os, Indenter indent ) const {
    558555        os <<  "Implicit Copy Constructor Expression: " << std::endl << indent+1;
    559556        callExpr->print( os, indent+1 );
    560         os << std::endl << indent << "... with temporaries:" << std::endl;
    561         printAll( tempDecls, os, indent+1 );
    562         os << std::endl << indent << "... with return temporaries:" << std::endl;
    563         printAll( returnDecls, os, indent+1 );
    564         Expression::print( os, indent );
    565557}
    566558
     
    581573}
    582574
    583 void ConstructorExpr::print( std::ostream &os, Indenter indent ) const {
     575bool ConstructorExpr::get_lvalue() const {
     576        return false;
     577}
     578
     579void ConstructorExpr::print( std::ostream & os, Indenter indent ) const {
    584580        os <<  "Constructor Expression: " << std::endl << indent+1;
    585581        callExpr->print( os, indent + 2 );
     
    590586CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : initializer( initializer ) {
    591587        assert( type && initializer );
    592         type->set_lvalue( true );
    593588        set_result( type );
    594589}
    595590
    596 CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), initializer( other.initializer->clone() ) {}
     591CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr & other ) : Expression( other ), initializer( other.initializer->clone() ) {}
    597592
    598593CompoundLiteralExpr::~CompoundLiteralExpr() {
     
    600595}
    601596
    602 void CompoundLiteralExpr::print( std::ostream &os, Indenter indent ) const {
     597bool CompoundLiteralExpr::get_lvalue() const {
     598        return true;
     599}
     600
     601void CompoundLiteralExpr::print( std::ostream & os, Indenter indent ) const {
    603602        os << "Compound Literal Expression: " << std::endl << indent+1;
    604603        result->print( os, indent+1 );
     
    608607}
    609608
    610 RangeExpr::RangeExpr( Expression *low, Expression *high ) : low( low ), high( high ) {}
    611 RangeExpr::RangeExpr( const RangeExpr &other ) : Expression( other ), low( other.low->clone() ), high( other.high->clone() ) {}
    612 void RangeExpr::print( std::ostream &os, Indenter indent ) const {
     609RangeExpr::RangeExpr( Expression * low, Expression * high ) : low( low ), high( high ) {}
     610RangeExpr::RangeExpr( const RangeExpr & other ) : Expression( other ), low( other.low->clone() ), high( other.high->clone() ) {}
     611void RangeExpr::print( std::ostream & os, Indenter indent ) const {
    613612        os << "Range Expression: ";
    614613        low->print( os, indent );
     
    618617}
    619618
    620 StmtExpr::StmtExpr( CompoundStmt *statements ) : statements( statements ) {
     619StmtExpr::StmtExpr( CompoundStmt * statements ) : statements( statements ) {
    621620        computeResult();
    622621}
    623 StmtExpr::StmtExpr( const StmtExpr &other ) : Expression( other ), statements( other.statements->clone() ) {
     622StmtExpr::StmtExpr( const StmtExpr & other ) : Expression( other ), statements( other.statements->clone() ), resultExpr( other.resultExpr ) {
    624623        cloneAll( other.returnDecls, returnDecls );
    625624        cloneAll( other.dtors, dtors );
     
    650649        }
    651650}
    652 void StmtExpr::print( std::ostream &os, Indenter indent ) const {
     651bool StmtExpr::get_lvalue() const {
     652        return false;
     653}
     654void StmtExpr::print( std::ostream & os, Indenter indent ) const {
    653655        os << "Statement Expression: " << std::endl << indent+1;
    654656        statements->print( os, indent+1 );
     
    666668
    667669long long UniqueExpr::count = 0;
    668 UniqueExpr::UniqueExpr( Expression *expr, long long idVal ) : expr( expr ), object( nullptr ), var( nullptr ), id( idVal ) {
     670UniqueExpr::UniqueExpr( Expression * expr, long long idVal ) : expr( expr ), object( nullptr ), var( nullptr ), id( idVal ) {
    669671        assert( expr );
    670672        assert( count != -1 );
     
    674676        }
    675677}
    676 UniqueExpr::UniqueExpr( const UniqueExpr &other ) : Expression( other ), expr( maybeClone( other.expr ) ), object( maybeClone( other.object ) ), var( maybeClone( other.var ) ), id( other.id ) {
     678UniqueExpr::UniqueExpr( const UniqueExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), object( maybeClone( other.object ) ), var( maybeClone( other.var ) ), id( other.id ) {
    677679}
    678680UniqueExpr::~UniqueExpr() {
     
    681683        delete var;
    682684}
    683 void UniqueExpr::print( std::ostream &os, Indenter indent ) const {
     685void UniqueExpr::print( std::ostream & os, Indenter indent ) const {
    684686        os << "Unique Expression with id:" << id << std::endl << indent+1;
    685687        expr->print( os, indent+1 );
     
    732734}
    733735
    734 DeletedExpr::DeletedExpr( Expression * expr, BaseSyntaxNode * deleteStmt ) : expr( expr ), deleteStmt( deleteStmt ) {
     736DeletedExpr::DeletedExpr( Expression * expr, Declaration * deleteStmt ) : expr( expr ), deleteStmt( deleteStmt ) {
    735737        assert( expr->result );
    736738        result = expr->result->clone();
     
    746748        os << std::endl << indent+1 << "... deleted by: ";
    747749        deleteStmt->print( os, indent+1 );
     750}
     751
     752
     753DefaultArgExpr::DefaultArgExpr( Expression * expr ) : expr( expr ) {
     754        assert( expr->result );
     755        result = expr->result->clone();
     756}
     757DefaultArgExpr::DefaultArgExpr( const DefaultArgExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ) {}
     758DefaultArgExpr::~DefaultArgExpr() {
     759        delete expr;
     760}
     761
     762void DefaultArgExpr::print( std::ostream & os, Indenter indent ) const {
     763        os << "Default Argument Expression" << std::endl << indent+1;
     764        expr->print( os, indent+1 );
    748765}
    749766
  • src/SynTree/Expression.h

    r7951100 rb067d9b  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Sep  3 19:23:46 2017
    13 // Update Count     : 48
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thr Aug 15 13:46:00 2019
     13// Update Count     : 54
    1414//
    1515
     
    2121#include <memory>                 // for allocator, unique_ptr
    2222#include <string>                 // for string
     23#include <vector>                 // for vector
    2324
    2425#include "BaseSyntaxNode.h"       // for BaseSyntaxNode
     
    3839/// but subject to decay-to-pointer and type parameter renaming
    3940struct ParamEntry {
    40         ParamEntry(): decl( 0 ), actualType( 0 ), formalType( 0 ), expr( 0 ), inferParams( new InferredParams ) {}
    41         ParamEntry( UniqueId decl, Type * actualType, Type * formalType, Expression* expr ): decl( decl ), actualType( actualType ), formalType( formalType ), expr( expr ), inferParams( new InferredParams ) {}
     41        ParamEntry(): decl( 0 ), declptr( nullptr ), actualType( nullptr ), formalType( nullptr ), expr( nullptr ) {}
     42        ParamEntry( UniqueId decl, Declaration * declptr, Type * actualType, Type * formalType, Expression* expr );
    4243        ParamEntry( const ParamEntry & other );
    4344        ParamEntry( ParamEntry && other );
    4445        ~ParamEntry();
    45         ParamEntry & operator=( const ParamEntry & other );
    4646        ParamEntry & operator=( ParamEntry && other );
    4747
    48         UniqueId decl;
    49         Type * actualType;
    50         Type * formalType;
     48        UniqueId const decl;
     49        Declaration * const declptr;
     50        Type * const actualType;
     51        Type * const formalType;
    5152        Expression * expr;
    52         std::unique_ptr< InferredParams > inferParams;
    5353};
    5454
     
    5959        TypeSubstitution * env;
    6060        bool extension = false;
    61         InferredParams inferParams;
     61        InferredParams inferParams;       ///< Post-resolution inferred parameter slots
     62        std::vector<UniqueId> resnSlots;  ///< Pre-resolution inferred parameter slots
     63
     64        // xxx - should turn inferParams+resnSlots into a union to save some memory
    6265
    6366        Expression();
     
    6871        const Type * get_result() const { return result; }
    6972        void set_result( Type * newValue ) { result = newValue; }
     73        virtual bool get_lvalue() const;
    7074
    7175        TypeSubstitution * get_env() const { return env; }
     
    7478        Expression * set_extension( bool exten ) { extension = exten; return this; }
    7579
    76         InferredParams & get_inferParams() { return inferParams; }
    77 
    7880        // move other's inferParams to this
    7981        void spliceInferParams( Expression * other );
     
    8183        virtual Expression * clone() const override = 0;
    8284        virtual void accept( Visitor & v ) override = 0;
     85        virtual void accept( Visitor & v ) const override = 0;
    8386        virtual Expression * acceptMutator( Mutator & m ) override = 0;
    8487        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    9699        virtual ~ApplicationExpr();
    97100
     101        bool get_lvalue() const final;
     102
    98103        Expression * get_function() const { return function; }
    99104        void set_function( Expression * newValue ) { function = newValue; }
    100105        std::list<Expression *>& get_args() { return args; }
    101106
    102         virtual ApplicationExpr * clone() const { return new ApplicationExpr( * this ); }
    103         virtual void accept( Visitor & v ) { v.visit( this ); }
    104         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    105         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     107        virtual ApplicationExpr * clone() const override { return new ApplicationExpr( * this ); }
     108        virtual void accept( Visitor & v ) override { v.visit( this ); }
     109        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     110        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     111        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    106112};
    107113
     
    118124        virtual ~UntypedExpr();
    119125
     126        bool get_lvalue() const final;
     127
    120128        Expression * get_function() const { return function; }
    121129        void set_function( Expression * newValue ) { function = newValue; }
     
    128136        static UntypedExpr * createAssign( Expression * arg1, Expression * arg2 );
    129137
    130         virtual UntypedExpr * clone() const { return new UntypedExpr( * this ); }
    131         virtual void accept( Visitor & v ) { v.visit( this ); }
    132         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    133         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     138        virtual UntypedExpr * clone() const override { return new UntypedExpr( * this ); }
     139        virtual void accept( Visitor & v ) override { v.visit( this ); }
     140        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     141        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     142        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    134143};
    135144
     
    146155        void set_name( std::string newValue ) { name = newValue; }
    147156
    148         virtual NameExpr * clone() const { return new NameExpr( * this ); }
    149         virtual void accept( Visitor & v ) { v.visit( this ); }
    150         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    151         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     157        virtual NameExpr * clone() const override { return new NameExpr( * this ); }
     158        virtual void accept( Visitor & v ) override { v.visit( this ); }
     159        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     160        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     161        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    152162};
    153163
     
    167177        void set_arg(Expression * newValue ) { arg = newValue; }
    168178
    169         virtual AddressExpr * clone() const { return new AddressExpr( * this ); }
    170         virtual void accept( Visitor & v ) { v.visit( this ); }
    171         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    172         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     179        virtual AddressExpr * clone() const override { return new AddressExpr( * this ); }
     180        virtual void accept( Visitor & v ) override { v.visit( this ); }
     181        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     182        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     183        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    173184};
    174185
     
    183194        virtual ~LabelAddressExpr();
    184195
    185         virtual LabelAddressExpr * clone() const { return new LabelAddressExpr( * this ); }
    186         virtual void accept( Visitor & v ) { v.visit( this ); }
    187         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    188         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     196        virtual LabelAddressExpr * clone() const override { return new LabelAddressExpr( * this ); }
     197        virtual void accept( Visitor & v ) override { v.visit( this ); }
     198        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     199        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     200        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    189201};
    190202
     
    193205  public:
    194206        Expression * arg;
    195         bool isGenerated = true; // whether this cast appeared in the source program
     207        bool isGenerated = true; // cast generated implicitly by code generation or explicit in program
    196208
    197209        CastExpr( Expression * arg, bool isGenerated = true );
     
    201213        virtual ~CastExpr();
    202214
     215        bool get_lvalue() const final;
     216
    203217        Expression * get_arg() const { return arg; }
    204218        void set_arg( Expression * newValue ) { arg = newValue; }
    205219
    206         virtual CastExpr * clone() const { return new CastExpr( * this ); }
    207         virtual void accept( Visitor & v ) { v.visit( this ); }
    208         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    209         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     220        virtual CastExpr * clone() const override { return new CastExpr( * this ); }
     221        virtual void accept( Visitor & v ) override { v.visit( this ); }
     222        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     223        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     224        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    210225};
    211226
     
    224239        const std::string & targetString() const;
    225240
    226         virtual KeywordCastExpr * clone() const { return new KeywordCastExpr( * this ); }
    227         virtual void accept( Visitor & v ) { v.visit( this ); }
    228         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    229         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     241        virtual KeywordCastExpr * clone() const override { return new KeywordCastExpr( * this ); }
     242        virtual void accept( Visitor & v ) override { v.visit( this ); }
     243        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     244        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     245        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    230246};
    231247
     
    242258        void set_arg( Expression * newValue ) { arg = newValue; }
    243259
    244         virtual VirtualCastExpr * clone() const { return new VirtualCastExpr( * this ); }
    245         virtual void accept( Visitor & v ) { v.visit( this ); }
    246         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    247         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     260        virtual VirtualCastExpr * clone() const override { return new VirtualCastExpr( * this ); }
     261        virtual void accept( Visitor & v ) override { v.visit( this ); }
     262        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     263        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     264        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    248265};
    249266
     
    257274        UntypedMemberExpr( const UntypedMemberExpr & other );
    258275        virtual ~UntypedMemberExpr();
     276
     277        bool get_lvalue() const final;
    259278
    260279        Expression * get_member() const { return member; }
     
    263282        void set_aggregate( Expression * newValue ) { aggregate = newValue; }
    264283
    265         virtual UntypedMemberExpr * clone() const { return new UntypedMemberExpr( * this ); }
    266         virtual void accept( Visitor & v ) { v.visit( this ); }
    267         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    268         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     284        virtual UntypedMemberExpr * clone() const override { return new UntypedMemberExpr( * this ); }
     285        virtual void accept( Visitor & v ) override { v.visit( this ); }
     286        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     287        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     288        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    269289};
    270290
     
    279299        MemberExpr( const MemberExpr & other );
    280300        virtual ~MemberExpr();
     301
     302        bool get_lvalue() const final;
    281303
    282304        DeclarationWithType * get_member() const { return member; }
     
    285307        void set_aggregate( Expression * newValue ) { aggregate = newValue; }
    286308
    287         virtual MemberExpr * clone() const { return new MemberExpr( * this ); }
    288         virtual void accept( Visitor & v ) { v.visit( this ); }
    289         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    290         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     309        virtual MemberExpr * clone() const override { return new MemberExpr( * this ); }
     310        virtual void accept( Visitor & v ) override { v.visit( this ); }
     311        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     312        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     313        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    291314};
    292315
     
    297320        DeclarationWithType * var;
    298321
     322        VariableExpr();
    299323        VariableExpr( DeclarationWithType * var );
    300324        VariableExpr( const VariableExpr & other );
    301325        virtual ~VariableExpr();
    302326
     327        bool get_lvalue() const final;
     328
    303329        DeclarationWithType * get_var() const { return var; }
    304330        void set_var( DeclarationWithType * newValue ) { var = newValue; }
     
    306332        static VariableExpr * functionPointer( FunctionDecl * decl );
    307333
    308         virtual VariableExpr * clone() const { return new VariableExpr( * this ); }
    309         virtual void accept( Visitor & v ) { v.visit( this ); }
    310         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    311         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     334        virtual VariableExpr * clone() const override { return new VariableExpr( * this ); }
     335        virtual void accept( Visitor & v ) override { v.visit( this ); }
     336        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     337        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     338        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    312339};
    313340
     
    327354        long long int intValue() const;
    328355
    329         virtual ConstantExpr * clone() const { return new ConstantExpr( * this ); }
    330         virtual void accept( Visitor & v ) { v.visit( this ); }
    331         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    332         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     356        virtual ConstantExpr * clone() const override { return new ConstantExpr( * this ); }
     357        virtual void accept( Visitor & v ) override { v.visit( this ); }
     358        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     359        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     360        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    333361};
    334362
     
    352380        void set_isType( bool newValue ) { isType = newValue; }
    353381
    354         virtual SizeofExpr * clone() const { return new SizeofExpr( * this ); }
    355         virtual void accept( Visitor & v ) { v.visit( this ); }
    356         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    357         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     382        virtual SizeofExpr * clone() const override { return new SizeofExpr( * this ); }
     383        virtual void accept( Visitor & v ) override { v.visit( this ); }
     384        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     385        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     386        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    358387};
    359388
     
    377406        void set_isType( bool newValue ) { isType = newValue; }
    378407
    379         virtual AlignofExpr * clone() const { return new AlignofExpr( * this ); }
    380         virtual void accept( Visitor & v ) { v.visit( this ); }
    381         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    382         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     408        virtual AlignofExpr * clone() const override { return new AlignofExpr( * this ); }
     409        virtual void accept( Visitor & v ) override { v.visit( this ); }
     410        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     411        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     412        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    383413};
    384414
     
    398428        void set_type( Type * newValue ) { type = newValue; }
    399429
    400         virtual UntypedOffsetofExpr * clone() const { return new UntypedOffsetofExpr( * this ); }
    401         virtual void accept( Visitor & v ) { v.visit( this ); }
    402         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    403         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     430        virtual UntypedOffsetofExpr * clone() const override { return new UntypedOffsetofExpr( * this ); }
     431        virtual void accept( Visitor & v ) override { v.visit( this ); }
     432        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     433        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     434        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    404435};
    405436
     
    419450        void set_member( DeclarationWithType * newValue ) { member = newValue; }
    420451
    421         virtual OffsetofExpr * clone() const { return new OffsetofExpr( * this ); }
    422         virtual void accept( Visitor & v ) { v.visit( this ); }
    423         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    424         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     452        virtual OffsetofExpr * clone() const override { return new OffsetofExpr( * this ); }
     453        virtual void accept( Visitor & v ) override { v.visit( this ); }
     454        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     455        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     456        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    425457};
    426458
     
    437469        void set_type( StructInstType * newValue ) { type = newValue; }
    438470
    439         virtual OffsetPackExpr * clone() const { return new OffsetPackExpr( * this ); }
    440         virtual void accept( Visitor & v ) { v.visit( this ); }
    441         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    442         virtual void print( std::ostream & os, Indenter indent = {} ) const;
    443 };
    444 
    445 /// AttrExpr represents an @attribute expression (like sizeof, but user-defined)
    446 class AttrExpr : public Expression {
    447   public:
    448         Expression * attr;
    449         Expression * expr;
    450         Type * type;
    451         bool isType;
    452 
    453         AttrExpr(Expression * attr, Expression * expr );
    454         AttrExpr( const AttrExpr & other );
    455         AttrExpr( Expression * attr, Type * type );
    456         virtual ~AttrExpr();
    457 
    458         Expression * get_attr() const { return attr; }
    459         void set_attr( Expression * newValue ) { attr = newValue; }
    460         Expression * get_expr() const { return expr; }
    461         void set_expr( Expression * newValue ) { expr = newValue; }
    462         Type * get_type() const { return type; }
    463         void set_type( Type * newValue ) { type = newValue; }
    464         bool get_isType() const { return isType; }
    465         void set_isType( bool newValue ) { isType = newValue; }
    466 
    467         virtual AttrExpr * clone() const { return new AttrExpr( * this ); }
    468         virtual void accept( Visitor & v ) { v.visit( this ); }
    469         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    470         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     471        virtual OffsetPackExpr * clone() const override { return new OffsetPackExpr( * this ); }
     472        virtual void accept( Visitor & v ) override { v.visit( this ); }
     473        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     474        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     475        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    471476};
    472477
     
    487492        void set_arg2( Expression * newValue ) { arg2 = newValue; }
    488493
    489         virtual LogicalExpr * clone() const { return new LogicalExpr( * this ); }
    490         virtual void accept( Visitor & v ) { v.visit( this ); }
    491         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    492         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     494        virtual LogicalExpr * clone() const override { return new LogicalExpr( * this ); }
     495        virtual void accept( Visitor & v ) override { v.visit( this ); }
     496        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     497        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     498        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    493499
    494500  private:
     
    506512        ConditionalExpr( const ConditionalExpr & other );
    507513        virtual ~ConditionalExpr();
     514
     515        bool get_lvalue() const final;
    508516
    509517        Expression * get_arg1() const { return arg1; }
     
    514522        void set_arg3( Expression * newValue ) { arg3 = newValue; }
    515523
    516         virtual ConditionalExpr * clone() const { return new ConditionalExpr( * this ); }
    517         virtual void accept( Visitor & v ) { v.visit( this ); }
    518         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    519         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     524        virtual ConditionalExpr * clone() const override { return new ConditionalExpr( * this ); }
     525        virtual void accept( Visitor & v ) override { v.visit( this ); }
     526        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     527        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     528        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    520529};
    521530
     
    529538        CommaExpr( const CommaExpr & other );
    530539        virtual ~CommaExpr();
     540
     541        bool get_lvalue() const final;
    531542
    532543        Expression * get_arg1() const { return arg1; }
     
    535546        void set_arg2( Expression * newValue ) { arg2 = newValue; }
    536547
    537         virtual CommaExpr * clone() const { return new CommaExpr( * this ); }
    538         virtual void accept( Visitor & v ) { v.visit( this ); }
    539         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    540         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     548        virtual CommaExpr * clone() const override { return new CommaExpr( * this ); }
     549        virtual void accept( Visitor & v ) override { v.visit( this ); }
     550        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     551        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     552        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    541553};
    542554
     
    553565        void set_type( Type * newValue ) { type = newValue; }
    554566
    555         virtual TypeExpr * clone() const { return new TypeExpr( * this ); }
    556         virtual void accept( Visitor & v ) { v.visit( this ); }
    557         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    558         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     567        virtual TypeExpr * clone() const override { return new TypeExpr( * this ); }
     568        virtual void accept( Visitor & v ) override { v.visit( this ); }
     569        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     570        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     571        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    559572};
    560573
     
    579592        void set_operand( Expression * newValue ) { operand = newValue; }
    580593
    581         virtual AsmExpr * clone() const { return new AsmExpr( * this ); }
    582         virtual void accept( Visitor & v ) { v.visit( this ); }
    583         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    584         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     594        virtual AsmExpr * clone() const override { return new AsmExpr( * this ); }
     595        virtual void accept( Visitor & v ) override { v.visit( this ); }
     596        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     597        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     598        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    585599
    586600        // https://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Machine-Constraints.html#Machine-Constraints
     
    591605class ImplicitCopyCtorExpr : public Expression {
    592606public:
    593         ApplicationExpr * callExpr;
    594         std::list< ObjectDecl * > tempDecls;
    595         std::list< ObjectDecl * > returnDecls;
    596         std::list< Expression * > dtors;
     607        ApplicationExpr * callExpr = nullptr;
    597608
    598609        ImplicitCopyCtorExpr( ApplicationExpr * callExpr );
     
    600611        virtual ~ImplicitCopyCtorExpr();
    601612
    602         ApplicationExpr * get_callExpr() const { return callExpr; }
    603         void set_callExpr( ApplicationExpr * newValue ) { callExpr = newValue; }
    604 
    605         std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; }
    606         std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; }
    607         std::list< Expression * > & get_dtors() { return dtors; }
    608 
    609         virtual ImplicitCopyCtorExpr * clone() const { return new ImplicitCopyCtorExpr( * this ); }
    610         virtual void accept( Visitor & v ) { v.visit( this ); }
    611         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    612         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     613        virtual ImplicitCopyCtorExpr * clone() const override { return new ImplicitCopyCtorExpr( * this ); }
     614        virtual void accept( Visitor & v ) override { v.visit( this ); }
     615        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     616        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     617        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    613618};
    614619
     
    622627        ~ConstructorExpr();
    623628
     629        bool get_lvalue() const final;
     630
    624631        Expression * get_callExpr() const { return callExpr; }
    625632        void set_callExpr( Expression * newValue ) { callExpr = newValue; }
    626633
    627         virtual ConstructorExpr * clone() const { return new ConstructorExpr( * this ); }
    628         virtual void accept( Visitor & v ) { v.visit( this ); }
    629         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    630         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     634        virtual ConstructorExpr * clone() const override { return new ConstructorExpr( * this ); }
     635        virtual void accept( Visitor & v ) override { v.visit( this ); }
     636        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     637        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     638        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    631639};
    632640
     
    640648        virtual ~CompoundLiteralExpr();
    641649
     650        bool get_lvalue() const final;
     651
    642652        Initializer * get_initializer() const { return initializer; }
    643653        void set_initializer( Initializer * i ) { initializer = i; }
    644654
    645         virtual CompoundLiteralExpr * clone() const { return new CompoundLiteralExpr( * this ); }
    646         virtual void accept( Visitor & v ) { v.visit( this ); }
    647         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    648         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     655        virtual CompoundLiteralExpr * clone() const override { return new CompoundLiteralExpr( * this ); }
     656        virtual void accept( Visitor & v ) override { v.visit( this ); }
     657        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     658        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     659        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    649660};
    650661
     
    662673        RangeExpr * set_high( Expression * high ) { RangeExpr::high = high; return this; }
    663674
    664         virtual RangeExpr * clone() const { return new RangeExpr( * this ); }
    665         virtual void accept( Visitor & v ) { v.visit( this ); }
    666         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    667         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     675        virtual RangeExpr * clone() const override { return new RangeExpr( * this ); }
     676        virtual void accept( Visitor & v ) override { v.visit( this ); }
     677        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     678        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     679        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    668680};
    669681
     
    679691        std::list<Expression*>& get_exprs() { return exprs; }
    680692
    681         virtual UntypedTupleExpr * clone() const { return new UntypedTupleExpr( * this ); }
    682         virtual void accept( Visitor & v ) { v.visit( this ); }
    683         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    684         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     693        virtual UntypedTupleExpr * clone() const override { return new UntypedTupleExpr( * this ); }
     694        virtual void accept( Visitor & v ) override { v.visit( this ); }
     695        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     696        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     697        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    685698};
    686699
     
    694707        virtual ~TupleExpr();
    695708
     709        bool get_lvalue() const final;
     710
    696711        std::list<Expression*>& get_exprs() { return exprs; }
    697712
    698         virtual TupleExpr * clone() const { return new TupleExpr( * this ); }
    699         virtual void accept( Visitor & v ) { v.visit( this ); }
    700         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    701         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     713        virtual TupleExpr * clone() const override { return new TupleExpr( * this ); }
     714        virtual void accept( Visitor & v ) override { v.visit( this ); }
     715        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     716        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     717        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    702718};
    703719
     
    711727        TupleIndexExpr( const TupleIndexExpr & other );
    712728        virtual ~TupleIndexExpr();
     729
     730        bool get_lvalue() const final;
    713731
    714732        Expression * get_tuple() const { return tuple; }
     
    717735        TupleIndexExpr * set_index( unsigned int newValue ) { index = newValue; return this; }
    718736
    719         virtual TupleIndexExpr * clone() const { return new TupleIndexExpr( * this ); }
    720         virtual void accept( Visitor & v ) { v.visit( this ); }
    721         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    722         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     737        virtual TupleIndexExpr * clone() const override { return new TupleIndexExpr( * this ); }
     738        virtual void accept( Visitor & v ) override { v.visit( this ); }
     739        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     740        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     741        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    723742};
    724743
     
    735754        StmtExpr * get_stmtExpr() const { return stmtExpr; }
    736755
    737         virtual TupleAssignExpr * clone() const { return new TupleAssignExpr( * this ); }
    738         virtual void accept( Visitor & v ) { v.visit( this ); }
    739         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    740         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     756        virtual TupleAssignExpr * clone() const override { return new TupleAssignExpr( * this ); }
     757        virtual void accept( Visitor & v ) override { v.visit( this ); }
     758        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     759        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     760        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     761
     762        friend class ConverterNewToOld;
     763  private:
     764    TupleAssignExpr( StmtExpr * stmts );
    741765};
    742766
     
    748772        std::list< Expression * > dtors; // destructor(s) for return variable(s)
    749773
     774        // readonly
     775        ExprStmt * resultExpr = nullptr;
     776
    750777        StmtExpr( CompoundStmt * statements );
    751778        StmtExpr( const StmtExpr & other );
    752779        virtual ~StmtExpr();
    753780
     781        bool get_lvalue() const final;
     782
    754783        CompoundStmt * get_statements() const { return statements; }
    755784        StmtExpr * set_statements( CompoundStmt * newValue ) { statements = newValue; return this; }
     
    761790        std::list< Expression * > & get_dtors() { return dtors; }
    762791
    763         virtual StmtExpr * clone() const { return new StmtExpr( * this ); }
    764         virtual void accept( Visitor & v ) { v.visit( this ); }
    765         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    766         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     792        virtual StmtExpr * clone() const override { return new StmtExpr( * this ); }
     793        virtual void accept( Visitor & v ) override { v.visit( this ); }
     794        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     795        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     796        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    767797};
    768798
     
    788818        int get_id() const { return id; }
    789819
    790         virtual UniqueExpr * clone() const { return new UniqueExpr( * this ); }
    791         virtual void accept( Visitor & v ) { v.visit( this ); }
    792         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    793         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     820        virtual UniqueExpr * clone() const override { return new UniqueExpr( * this ); }
     821        virtual void accept( Visitor & v ) override { v.visit( this ); }
     822        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     823        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     824        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    794825
    795826private:
     
    822853        std::list<InitAlternative> & get_initAlts() { return initAlts; }
    823854
    824         virtual UntypedInitExpr * clone() const { return new UntypedInitExpr( * this ); }
    825         virtual void accept( Visitor & v ) { v.visit( this ); }
    826         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    827         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     855        virtual UntypedInitExpr * clone() const override { return new UntypedInitExpr( * this ); }
     856        virtual void accept( Visitor & v ) override { v.visit( this ); }
     857        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     858        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     859        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    828860};
    829861
     
    843875        InitExpr * set_designation( Designation * newValue ) { designation = newValue; return this; }
    844876
    845         virtual InitExpr * clone() const { return new InitExpr( * this ); }
    846         virtual void accept( Visitor & v ) { v.visit( this ); }
    847         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    848         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     877        virtual InitExpr * clone() const override { return new InitExpr( * this ); }
     878        virtual void accept( Visitor & v ) override { v.visit( this ); }
     879        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     880        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     881        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    849882};
    850883
     
    853886public:
    854887        Expression * expr;
    855         BaseSyntaxNode * deleteStmt;
    856 
    857         DeletedExpr( Expression * expr, BaseSyntaxNode * deleteStmt );
     888        Declaration * deleteStmt;
     889
     890        DeletedExpr( Expression * expr, Declaration * deleteStmt );
    858891        DeletedExpr( const DeletedExpr & other );
    859892        ~DeletedExpr();
    860893
    861         virtual DeletedExpr * clone() const { return new DeletedExpr( * this ); }
    862         virtual void accept( Visitor & v ) { v.visit( this ); }
    863         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    864         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     894        virtual DeletedExpr * clone() const override { return new DeletedExpr( * this ); }
     895        virtual void accept( Visitor & v ) override { v.visit( this ); }
     896        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     897        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     898        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     899};
     900
     901/// expression wrapping the use of a default argument - should never make it past the resolver.
     902class DefaultArgExpr : public Expression {
     903public:
     904        Expression * expr;
     905
     906        DefaultArgExpr( Expression * expr );
     907        DefaultArgExpr( const DefaultArgExpr & other );
     908        ~DefaultArgExpr();
     909
     910        virtual DefaultArgExpr * clone() const override { return new DefaultArgExpr( * this ); }
     911        virtual void accept( Visitor & v ) override { v.visit( this ); }
     912        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     913        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     914        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    865915};
    866916
     
    887937        virtual ~GenericExpr();
    888938
    889         virtual GenericExpr * clone() const { return new GenericExpr( * this ); }
    890         virtual void accept( Visitor & v ) { v.visit( this ); }
    891         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    892         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     939        virtual GenericExpr * clone() const override { return new GenericExpr( * this ); }
     940        virtual void accept( Visitor & v ) override { v.visit( this ); }
     941        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     942        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     943        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    893944};
    894945
  • src/SynTree/FunctionDecl.cc

    r7951100 rb067d9b  
    8787
    8888        if ( statements ) {
    89                 os << indent << "... with body " << endl << indent+1;
     89                os << indent << "... with body" << endl << indent+1;
    9090                statements->print( os, indent+1 );
    9191        } // if
  • src/SynTree/FunctionType.cc

    r7951100 rb067d9b  
    6666                os << indent+1 << "accepting unspecified arguments" << endl;
    6767        } // if
    68         os << indent << "... returning ";
     68        os << indent << "... returning";
    6969        if ( returnVals.empty() ) {
    70                 os << "nothing " << endl;
     70                os << " nothing" << endl;
    7171        } else {
    7272                os << endl;
  • src/SynTree/Initializer.h

    r7951100 rb067d9b  
    3838
    3939        virtual Designation * clone() const override { return new Designation( *this ); };
    40         virtual void accept( Visitor &v ) override { v.visit( this ); }
     40        virtual void accept( Visitor & v ) override { v.visit( this ); }
     41        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    4142        virtual Designation * acceptMutator( Mutator &m ) override { return m.mutate( this ); }
    4243        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
     
    5253        virtual ~Initializer();
    5354
    54         bool get_maybeConstructed() { return maybeConstructed; }
     55        bool get_maybeConstructed() const { return maybeConstructed; }
    5556
    5657        virtual Initializer *clone() const override = 0;
    57         virtual void accept( Visitor &v ) override = 0;
     58        virtual void accept( Visitor & v ) override = 0;
     59        virtual void accept( Visitor & v ) const override = 0;
    5860        virtual Initializer *acceptMutator( Mutator &m ) override = 0;
    5961        virtual void print( std::ostream &os, Indenter indent = {} ) const override = 0;
     
    7678
    7779        virtual SingleInit *clone() const override { return new SingleInit( *this); }
    78         virtual void accept( Visitor &v ) override { v.visit( this ); }
     80        virtual void accept( Visitor & v ) override { v.visit( this ); }
     81        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    7982        virtual Initializer *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    8083        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
     
    104107
    105108        virtual ListInit *clone() const override { return new ListInit( *this ); }
    106         virtual void accept( Visitor &v ) override { v.visit( this ); }
     109        virtual void accept( Visitor & v ) override { v.visit( this ); }
     110        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    107111        virtual Initializer *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    108112        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
     
    133137
    134138        ConstructorInit *clone() const override { return new ConstructorInit( *this ); }
    135         virtual void accept( Visitor &v ) override { v.visit( this ); }
     139        virtual void accept( Visitor & v ) override { v.visit( this ); }
     140        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    136141        virtual Initializer *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    137142        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
  • src/SynTree/Label.h

    r7951100 rb067d9b  
    3535        operator std::string() const { return name; }
    3636        bool empty() { return name.empty(); }
    37   private:
     37
    3838        std::string name;
    3939        Statement * labelled;
  • src/SynTree/Mutator.h

    r7951100 rb067d9b  
    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 : Mon Jul 24 16:31:00 2017
    13 // Update Count     : 16
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Thu Jul 25 22:37:46 2019
     13// Update Count     : 17
    1414//
    1515#pragma once
     
    5252        virtual Statement * mutate( FinallyStmt * catchStmt ) = 0;
    5353        virtual Statement * mutate( WaitForStmt * waitforStmt ) = 0;
    54         virtual Statement * mutate( WithStmt * withStmt ) = 0;
     54        virtual Declaration * mutate( WithStmt * withStmt ) = 0;
    5555        virtual NullStmt * mutate( NullStmt * nullStmt ) = 0;
    5656        virtual Statement * mutate( DeclStmt * declStmt ) = 0;
     
    7474        virtual Expression * mutate( OffsetofExpr * offsetofExpr ) = 0;
    7575        virtual Expression * mutate( OffsetPackExpr * offsetPackExpr ) = 0;
    76         virtual Expression * mutate( AttrExpr * attrExpr ) = 0;
    7776        virtual Expression * mutate( LogicalExpr * logicalExpr ) = 0;
    7877        virtual Expression * mutate( ConditionalExpr * conditionalExpr ) = 0;
     
    9392        virtual Expression * mutate( InitExpr  * initExpr ) = 0;
    9493        virtual Expression * mutate( DeletedExpr * delExpr ) = 0;
     94        virtual Expression * mutate( DefaultArgExpr * argExpr ) = 0;
    9595        virtual Expression * mutate( GenericExpr * genExpr ) = 0;
    9696
     
    100100        virtual Type * mutate( ArrayType * arrayType ) = 0;
    101101        virtual Type * mutate( ReferenceType * refType ) = 0;
     102        virtual Type * mutate( QualifiedType * qualType ) = 0;
    102103        virtual Type * mutate( FunctionType * functionType ) = 0;
    103104        virtual Type * mutate( StructInstType * aggregateUseType ) = 0;
     
    112113        virtual Type * mutate( ZeroType * zeroType ) = 0;
    113114        virtual Type * mutate( OneType * oneType ) = 0;
     115        virtual Type * mutate( GlobalScopeType * globalType ) = 0;
    114116
    115117        virtual Designation * mutate( Designation * designation ) = 0 ;
     
    117119        virtual Initializer * mutate( ListInit * listInit ) = 0 ;
    118120        virtual Initializer * mutate( ConstructorInit * ctorInit ) = 0 ;
    119 
    120         virtual Subrange * mutate( Subrange * subrange ) = 0;
    121121
    122122        virtual Constant * mutate( Constant * constant ) = 0;
  • src/SynTree/ObjectDecl.cc

    r7951100 rb067d9b  
    6666
    6767        if ( ! attributes.empty() ) {
    68                 os << std::endl << indent << "... with attributes: " << std::endl;
     68                os << std::endl << indent << "... with attributes:" << std::endl;
    6969                printAll( attributes, os, indent+1 );
    7070        }
  • src/SynTree/ReferenceToType.cc

    r7951100 rb067d9b  
    7676bool StructInstType::isComplete() const { return baseStruct ? baseStruct->has_body() : false; }
    7777
    78 AggregateDecl * StructInstType::getAggr() { return baseStruct; }
     78AggregateDecl * StructInstType::getAggr() const { return baseStruct; }
    7979
    8080TypeSubstitution StructInstType::genericSubstitution() const {
     
    9393        else {
    9494                Type::print( os, indent );
    95                 os << "instance of " << typeString() << " " << name << " with body " << baseStruct->has_body() << " ";
     95                os << "instance of " << typeString() << " " << name << " with body " << baseStruct->has_body();
    9696                if ( ! parameters.empty() ) {
    9797                        os << endl << indent << "... with parameters" << endl;
     
    119119bool UnionInstType::isComplete() const { return baseUnion ? baseUnion->has_body() : false; }
    120120
    121 AggregateDecl * UnionInstType::getAggr() { return baseUnion; }
     121AggregateDecl * UnionInstType::getAggr() const { return baseUnion; }
    122122
    123123TypeSubstitution UnionInstType::genericSubstitution() const {
     
    136136        else {
    137137                Type::print( os, indent );
    138                 os << "instance of " << typeString() << " " << name << " with body " << baseUnion->has_body() << " ";
     138                os << "instance of " << typeString() << " " << name << " with body " << baseUnion->has_body();
    139139                if ( ! parameters.empty() ) {
    140140                        os << endl << indent << "... with parameters" << endl;
     
    152152bool EnumInstType::isComplete() const { return baseEnum ? baseEnum->has_body() : false; }
    153153
     154AggregateDecl * EnumInstType::getAggr() const { return baseEnum; }
     155
    154156void EnumInstType::print( std::ostream &os, Indenter indent ) const {
    155157        using std::endl;
     
    158160        else {
    159161                Type::print( os, indent );
    160                 os << "instance of " << typeString() << " " << name << " with body " << baseEnum->has_body() << " ";
     162                os << "instance of " << typeString() << " " << name << " with body " << baseEnum->has_body();
    161163        } // if
    162164}
     
    203205
    204206        Type::print( os, indent );
    205         os << "instance of " << typeString() << " " << get_name() << " (" << ( isFtype ? "" : "not" ) << " function type) ";
     207        os << "instance of " << typeString() << " " << get_name() << " (" << ( isFtype ? "" : "not" ) << " function type)";
    206208        if ( ! parameters.empty() ) {
    207209                os << endl << indent << "... with parameters" << endl;
  • src/SynTree/Statement.cc

    r7951100 rb067d9b  
    493493
    494494
    495 WithStmt::WithStmt( const std::list< Expression * > & exprs, Statement * stmt ) : Statement(), exprs( exprs ), stmt( stmt ) {}
    496 WithStmt::WithStmt( const WithStmt & other ) : Statement( other ), stmt( maybeClone( other.stmt ) ) {
     495WithStmt::WithStmt( const std::list< Expression * > & exprs, Statement * stmt ) : Declaration("", noStorageClasses, LinkageSpec::Cforall), exprs( exprs ), stmt( stmt ) {}
     496WithStmt::WithStmt( const WithStmt & other ) : Declaration( other ), stmt( maybeClone( other.stmt ) ) {
    497497        cloneAll( other.exprs, exprs );
    498498}
  • src/SynTree/Statement.h

    r7951100 rb067d9b  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar  8 14:53:02 2018
    13 // Update Count     : 78
     12// Last Modified On : Tue Mar 12 09:01:53 2019
     13// Update Count     : 83
    1414//
    1515
     
    1919#include <list>                    // for list
    2020#include <memory>                  // for allocator
    21 #include <vector>                        // for vector
     21#include <vector>                                  // for vector
    2222
    2323#include "BaseSyntaxNode.h"        // for BaseSyntaxNode
     
    4343        const std::list<Label> & get_labels() const { return labels; }
    4444
    45         virtual Statement *clone() const override = 0;
    46         virtual void accept( Visitor &v ) override = 0;
    47         virtual Statement *acceptMutator( Mutator &m ) override = 0;
    48         virtual void print( std::ostream &os, Indenter indent = {} ) const override;
     45        virtual Statement * clone() const override = 0;
     46        virtual void accept( Visitor & v ) override = 0;
     47        virtual void accept( Visitor & v ) const override = 0;
     48        virtual Statement * acceptMutator( Mutator & m ) override = 0;
     49        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    4950};
    5051
     
    5556        CompoundStmt();
    5657        CompoundStmt( std::list<Statement *> stmts );
    57         CompoundStmt( const CompoundStmt &other );
     58        CompoundStmt( const CompoundStmt & other );
    5859        virtual ~CompoundStmt();
    5960
     
    6263        void push_front( Statement * stmt ) { kids.push_front( stmt ); }
    6364
    64         virtual CompoundStmt *clone() const override { return new CompoundStmt( *this ); }
    65         virtual void accept( Visitor &v ) override { v.visit( this ); }
    66         virtual CompoundStmt *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    67         virtual void print( std::ostream &os, Indenter indent = {} ) const override;
     65        virtual CompoundStmt * clone() const override { return new CompoundStmt( *this ); }
     66        virtual void accept( Visitor & v ) override { v.visit( this ); }
     67        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     68        virtual CompoundStmt * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     69        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    6870};
    6971
     
    7274        NullStmt( const std::list<Label> & labels = {} );
    7375
    74         virtual NullStmt *clone() const override { return new NullStmt( *this ); }
    75         virtual void accept( Visitor &v ) override { v.visit( this ); }
    76         virtual NullStmt *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    77         virtual void print( std::ostream &os, Indenter indent = {} ) const override;
     76        virtual NullStmt * clone() const override { return new NullStmt( *this ); }
     77        virtual void accept( Visitor & v ) override { v.visit( this ); }
     78        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     79        virtual NullStmt * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     80        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    7881};
    7982
    8083class ExprStmt : public Statement {
    8184  public:
    82         Expression *expr;
    83 
    84         ExprStmt( Expression *expr );
    85         ExprStmt( const ExprStmt &other );
     85        Expression * expr;
     86
     87        ExprStmt( Expression * expr );
     88        ExprStmt( const ExprStmt & other );
    8689        virtual ~ExprStmt();
    8790
    88         Expression *get_expr() { return expr; }
    89         void set_expr( Expression *newValue ) { expr = newValue; }
    90 
    91         virtual ExprStmt *clone() const override { return new ExprStmt( *this ); }
    92         virtual void accept( Visitor &v ) override { v.visit( this ); }
    93         virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    94         virtual void print( std::ostream &os, Indenter indent = {} ) const override;
     91        Expression * get_expr() { return expr; }
     92        void set_expr( Expression * newValue ) { expr = newValue; }
     93
     94        virtual ExprStmt * clone() const override { return new ExprStmt( *this ); }
     95        virtual void accept( Visitor & v ) override { v.visit( this ); }
     96        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     97        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     98        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    9599};
    96100
     
    98102  public:
    99103        bool voltile;
    100         Expression *instruction;
     104        Expression * instruction;
    101105        std::list<Expression *> output, input;
    102106        std::list<ConstantExpr *> clobber;
    103107        std::list<Label> gotolabels;
    104108
    105         AsmStmt( bool voltile, Expression *instruction, std::list<Expression *> output, std::list<Expression *> input, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels );
    106         AsmStmt( const AsmStmt &other );
     109        AsmStmt( bool voltile, Expression * instruction, std::list<Expression *> output, std::list<Expression *> input, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels );
     110        AsmStmt( const AsmStmt & other );
    107111        virtual ~AsmStmt();
    108112
     
    114118        void set_output( const std::list<Expression *> & newValue ) { output = newValue; }
    115119        std::list<Expression *> & get_input() { return input; }
    116         void set_input( const std::list<Expression *> &newValue ) { input = newValue; }
     120        void set_input( const std::list<Expression *> & newValue ) { input = newValue; }
    117121        std::list<ConstantExpr *> & get_clobber() { return clobber; }
    118         void set_clobber( const std::list<ConstantExpr *> &newValue ) { clobber = newValue; }
     122        void set_clobber( const std::list<ConstantExpr *> & newValue ) { clobber = newValue; }
    119123        std::list<Label> & get_gotolabels() { return gotolabels; }
    120         void set_gotolabels( const std::list<Label> &newValue ) { gotolabels = newValue; }
    121 
    122         virtual AsmStmt * clone() const { return new AsmStmt( *this ); }
    123         virtual void accept( Visitor & v ) { v.visit( this ); }
    124         virtual Statement * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    125         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     124        void set_gotolabels( const std::list<Label> & newValue ) { gotolabels = newValue; }
     125
     126        virtual AsmStmt * clone() const override { return new AsmStmt( *this ); }
     127        virtual void accept( Visitor & v ) override { v.visit( this ); }
     128        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     129        virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     130        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    126131};
    127132
     
    133138        virtual ~DirectiveStmt(){}
    134139
    135         virtual DirectiveStmt * clone() const { return new DirectiveStmt( *this ); }
    136         virtual void accept( Visitor & v ) { v.visit( this ); }
    137         virtual Statement * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    138         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     140        virtual DirectiveStmt * clone() const override { return new DirectiveStmt( *this ); }
     141        virtual void accept( Visitor & v ) override { v.visit( this ); }
     142        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     143        virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     144        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    139145};
    140146
    141147class IfStmt : public Statement {
    142148  public:
    143         Expression *condition;
    144         Statement *thenPart;
    145         Statement *elsePart;
     149        Expression * condition;
     150        Statement * thenPart;
     151        Statement * elsePart;
    146152        std::list<Statement *> initialization;
    147153
    148         IfStmt( Expression *condition, Statement *thenPart, Statement *elsePart,
     154        IfStmt( Expression * condition, Statement * thenPart, Statement * elsePart,
    149155                        std::list<Statement *> initialization = std::list<Statement *>() );
    150         IfStmt( const IfStmt &other );
     156        IfStmt( const IfStmt & other );
    151157        virtual ~IfStmt();
    152158
    153         std::list<Statement *> &get_initialization() { return initialization; }
    154         Expression *get_condition() { return condition; }
    155         void set_condition( Expression *newValue ) { condition = newValue; }
    156         Statement *get_thenPart() { return thenPart; }
    157         void set_thenPart( Statement *newValue ) { thenPart = newValue; }
    158         Statement *get_elsePart() { return elsePart; }
    159         void set_elsePart( Statement *newValue ) { elsePart = newValue; }
    160 
    161         virtual IfStmt *clone() const override { return new IfStmt( *this ); }
    162         virtual void accept( Visitor &v ) override { v.visit( this ); }
    163         virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    164         virtual void print( std::ostream &os, Indenter indent = {} ) const override;
     159        std::list<Statement *> & get_initialization() { return initialization; }
     160        Expression * get_condition() { return condition; }
     161        void set_condition( Expression * newValue ) { condition = newValue; }
     162        Statement * get_thenPart() { return thenPart; }
     163        void set_thenPart( Statement * newValue ) { thenPart = newValue; }
     164        Statement * get_elsePart() { return elsePart; }
     165        void set_elsePart( Statement * newValue ) { elsePart = newValue; }
     166
     167        virtual IfStmt * clone() const override { return new IfStmt( *this ); }
     168        virtual void accept( Visitor & v ) override { v.visit( this ); }
     169        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     170        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     171        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    165172};
    166173
     
    170177        std::list<Statement *> statements;
    171178
    172         SwitchStmt( Expression *condition, const std::list<Statement *> &statements );
    173         SwitchStmt( const SwitchStmt &other );
     179        SwitchStmt( Expression * condition, const std::list<Statement *> & statements );
     180        SwitchStmt( const SwitchStmt & other );
    174181        virtual ~SwitchStmt();
    175182
    176         Expression *get_condition() { return condition; }
    177         void set_condition( Expression *newValue ) { condition = newValue; }
     183        Expression * get_condition() { return condition; }
     184        void set_condition( Expression * newValue ) { condition = newValue; }
    178185
    179186        std::list<Statement *> & get_statements() { return statements; }
    180187
    181         virtual void accept( Visitor &v ) override { v.visit( this ); }
    182         virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    183 
    184         virtual SwitchStmt *clone() const override { return new SwitchStmt( *this ); }
    185         virtual void print( std::ostream &os, Indenter indent = {} ) const override;
     188        virtual void accept( Visitor & v ) override { v.visit( this ); }
     189        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     190        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     191
     192        virtual SwitchStmt * clone() const override { return new SwitchStmt( *this ); }
     193        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    186194
    187195};
     
    192200        std::list<Statement *> stmts;
    193201
    194         CaseStmt( Expression *conditions, const std::list<Statement *> &stmts, bool isdef = false ) throw (SemanticErrorException);
    195         CaseStmt( const CaseStmt &other );
     202        CaseStmt( Expression * conditions, const std::list<Statement *> & stmts, bool isdef = false ) throw (SemanticErrorException);
     203        CaseStmt( const CaseStmt & other );
    196204        virtual ~CaseStmt();
    197205
     
    201209        void set_default(bool b) { _isDefault = b; }
    202210
    203         Expression * &get_condition() { return condition; }
    204         void set_condition( Expression *newValue ) { condition = newValue; }
    205 
    206         std::list<Statement *> &get_statements() { return stmts; }
    207         void set_statements( std::list<Statement *> &newValue ) { stmts = newValue; }
    208 
    209         virtual void accept( Visitor &v ) override { v.visit( this ); }
    210         virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    211 
    212         virtual CaseStmt *clone() const override { return new CaseStmt( *this ); }
    213         virtual void print( std::ostream &os, Indenter indent = {} ) const override;
     211        Expression * & get_condition() { return condition; }
     212        void set_condition( Expression * newValue ) { condition = newValue; }
     213
     214        std::list<Statement *> & get_statements() { return stmts; }
     215        void set_statements( std::list<Statement *> & newValue ) { stmts = newValue; }
     216
     217        virtual void accept( Visitor & v ) override { v.visit( this ); }
     218        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     219        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     220
     221        virtual CaseStmt * clone() const override { return new CaseStmt( *this ); }
     222        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    214223  private:
    215224        bool _isDefault;
     
    218227class WhileStmt : public Statement {
    219228  public:
    220         Expression *condition;
    221         Statement *body;
     229        Expression * condition;
     230        Statement * body;
    222231        std::list<Statement *> initialization;
    223232        bool isDoWhile;
    224233
    225         WhileStmt( Expression *condition,
    226                Statement *body, std::list<Statement *> & initialization, bool isDoWhile = false );
    227         WhileStmt( const WhileStmt &other );
     234        WhileStmt( Expression * condition, Statement * body, std::list<Statement *> & initialization, bool isDoWhile = false );
     235        WhileStmt( const WhileStmt & other );
    228236        virtual ~WhileStmt();
    229237
    230         Expression *get_condition() { return condition; }
    231         void set_condition( Expression *newValue ) { condition = newValue; }
    232         Statement *get_body() { return body; }
    233         void set_body( Statement *newValue ) { body = newValue; }
     238        Expression * get_condition() { return condition; }
     239        void set_condition( Expression * newValue ) { condition = newValue; }
     240        Statement * get_body() { return body; }
     241        void set_body( Statement * newValue ) { body = newValue; }
    234242        bool get_isDoWhile() { return isDoWhile; }
    235243        void set_isDoWhile( bool newValue ) { isDoWhile = newValue; }
    236244
    237         virtual WhileStmt *clone() const override { return new WhileStmt( *this ); }
    238         virtual void accept( Visitor &v ) override { v.visit( this ); }
    239         virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    240         virtual void print( std::ostream &os, Indenter indent = {} ) const override;
     245        virtual WhileStmt * clone() const override { return new WhileStmt( *this ); }
     246        virtual void accept( Visitor & v ) override { v.visit( this ); }
     247        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     248        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     249        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    241250};
    242251
     
    244253  public:
    245254        std::list<Statement *> initialization;
    246         Expression *condition;
    247         Expression *increment;
    248         Statement *body;
    249 
    250         ForStmt( std::list<Statement *> initialization,
    251              Expression *condition = 0, Expression *increment = 0, Statement *body = 0 );
    252         ForStmt( const ForStmt &other );
     255        Expression * condition;
     256        Expression * increment;
     257        Statement * body;
     258
     259        ForStmt( std::list<Statement *> initialization, Expression * condition = 0, Expression * increment = 0, Statement * body = 0 );
     260        ForStmt( const ForStmt & other );
    253261        virtual ~ForStmt();
    254262
    255         std::list<Statement *> &get_initialization() { return initialization; }
    256         Expression *get_condition() { return condition; }
    257         void set_condition( Expression *newValue ) { condition = newValue; }
    258         Expression *get_increment() { return increment; }
    259         void set_increment( Expression *newValue ) { increment = newValue; }
    260         Statement *get_body() { return body; }
    261         void set_body( Statement *newValue ) { body = newValue; }
    262 
    263         virtual ForStmt *clone() const override { return new ForStmt( *this ); }
    264         virtual void accept( Visitor &v ) override { v.visit( this ); }
    265         virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    266         virtual void print( std::ostream &os, Indenter indent = {} ) const override;
     263        std::list<Statement *> & get_initialization() { return initialization; }
     264        Expression * get_condition() { return condition; }
     265        void set_condition( Expression * newValue ) { condition = newValue; }
     266        Expression * get_increment() { return increment; }
     267        void set_increment( Expression * newValue ) { increment = newValue; }
     268        Statement * get_body() { return body; }
     269        void set_body( Statement * newValue ) { body = newValue; }
     270
     271        virtual ForStmt * clone() const override { return new ForStmt( *this ); }
     272        virtual void accept( Visitor & v ) override { v.visit( this ); }
     273        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     274        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     275        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    267276};
    268277
     
    274283        const Label originalTarget;
    275284        Label target;
    276         Expression *computedTarget;
     285        Expression * computedTarget;
    277286        Type type;
    278287
    279288        BranchStmt( Label target, Type ) throw (SemanticErrorException);
    280         BranchStmt( Expression *computedTarget, Type ) throw (SemanticErrorException);
     289        BranchStmt( Expression * computedTarget, Type ) throw (SemanticErrorException);
    281290
    282291        Label get_originalTarget() { return originalTarget; }
     
    284293        void set_target( Label newValue ) { target = newValue; }
    285294
    286         Expression *get_computedTarget() { return computedTarget; }
     295        Expression * get_computedTarget() { return computedTarget; }
    287296        void set_target( Expression * newValue ) { computedTarget = newValue; }
    288297
    289298        Type get_type() { return type; }
    290         const char *get_typename() { return brType[ type ]; }
    291 
    292         virtual BranchStmt *clone() const override { return new BranchStmt( *this ); }
    293         virtual void accept( Visitor &v ) override { v.visit( this ); }
    294         virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    295         virtual void print( std::ostream &os, Indenter indent = {} ) const override;
     299        const char * get_typename() { return brType[ type ]; }
     300
     301        virtual BranchStmt * clone() const override { return new BranchStmt( *this ); }
     302        virtual void accept( Visitor & v ) override { v.visit( this ); }
     303        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     304        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     305        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    296306  private:
    297         static const char *brType[];
     307        static const char * brType[];
    298308};
    299309
    300310class ReturnStmt : public Statement {
    301311  public:
    302         Expression *expr;
    303 
    304         ReturnStmt( Expression *expr );
    305         ReturnStmt( const ReturnStmt &other );
     312        Expression * expr;
     313
     314        ReturnStmt( Expression * expr );
     315        ReturnStmt( const ReturnStmt & other );
    306316        virtual ~ReturnStmt();
    307317
    308         Expression *get_expr() { return expr; }
    309         void set_expr( Expression *newValue ) { expr = newValue; }
    310 
    311         virtual ReturnStmt *clone() const override { return new ReturnStmt( *this ); }
    312         virtual void accept( Visitor &v ) override { v.visit( this ); }
    313         virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    314         virtual void print( std::ostream &os, Indenter indent = {} ) const override;
     318        Expression * get_expr() { return expr; }
     319        void set_expr( Expression * newValue ) { expr = newValue; }
     320
     321        virtual ReturnStmt * clone() const override { return new ReturnStmt( *this ); }
     322        virtual void accept( Visitor & v ) override { v.visit( this ); }
     323        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     324        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     325        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    315326};
    316327
     
    324335
    325336        ThrowStmt( Kind kind, Expression * expr, Expression * target = nullptr );
    326         ThrowStmt( const ThrowStmt &other );
     337        ThrowStmt( const ThrowStmt & other );
    327338        virtual ~ThrowStmt();
    328339
     
    333344        void set_target( Expression * newTarget ) { target = newTarget; }
    334345
    335         virtual ThrowStmt *clone() const override { return new ThrowStmt( *this ); }
    336         virtual void accept( Visitor &v ) override { v.visit( this ); }
    337         virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    338         virtual void print( std::ostream &os, Indenter indent = {} ) const override;
     346        virtual ThrowStmt * clone() const override { return new ThrowStmt( *this ); }
     347        virtual void accept( Visitor & v ) override { v.visit( this ); }
     348        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     349        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     350        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    339351};
    340352
     
    345357        FinallyStmt * finallyBlock;
    346358
    347         TryStmt( CompoundStmt *tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock = 0 );
    348         TryStmt( const TryStmt &other );
     359        TryStmt( CompoundStmt * tryBlock, std::list<CatchStmt *> & handlers, FinallyStmt * finallyBlock = 0 );
     360        TryStmt( const TryStmt & other );
    349361        virtual ~TryStmt();
    350362
    351         CompoundStmt *get_block() const { return block; }
    352         void set_block( CompoundStmt *newValue ) { block = newValue; }
     363        CompoundStmt * get_block() const { return block; }
     364        void set_block( CompoundStmt * newValue ) { block = newValue; }
    353365        std::list<CatchStmt *>& get_catchers() { return handlers; }
    354366
    355         FinallyStmt *get_finally() const { return finallyBlock; }
    356         void set_finally( FinallyStmt *newValue ) { finallyBlock = newValue; }
    357 
    358         virtual TryStmt *clone() const override { return new TryStmt( *this ); }
    359         virtual void accept( Visitor &v ) override { v.visit( this ); }
    360         virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    361         virtual void print( std::ostream &os, Indenter indent = {} ) const override;
     367        FinallyStmt * get_finally() const { return finallyBlock; }
     368        void set_finally( FinallyStmt * newValue ) { finallyBlock = newValue; }
     369
     370        virtual TryStmt * clone() const override { return new TryStmt( *this ); }
     371        virtual void accept( Visitor & v ) override { v.visit( this ); }
     372        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     373        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     374        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    362375};
    363376
     
    367380
    368381        const Kind kind;
    369         Declaration *decl;
    370         Expression *cond;
    371         Statement *body;
    372 
    373         CatchStmt( Kind kind, Declaration *decl,
    374                    Expression *cond, Statement *body );
    375         CatchStmt( const CatchStmt &other );
     382        Declaration * decl;
     383        Expression * cond;
     384        Statement * body;
     385
     386        CatchStmt( Kind kind, Declaration * decl,
     387                   Expression * cond, Statement * body );
     388        CatchStmt( const CatchStmt & other );
    376389        virtual ~CatchStmt();
    377390
    378391        Kind get_kind() { return kind; }
    379         Declaration *get_decl() { return decl; }
    380         void set_decl( Declaration *newValue ) { decl = newValue; }
    381         Expression *get_cond() { return cond; }
    382         void set_cond( Expression *newCond ) { cond = newCond; }
    383         Statement *get_body() { return body; }
    384         void set_body( Statement *newValue ) { body = newValue; }
    385 
    386         virtual CatchStmt *clone() const override { return new CatchStmt( *this ); }
    387         virtual void accept( Visitor &v ) override { v.visit( this ); }
    388         virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    389         virtual void print( std::ostream &os, Indenter indent = {} ) const override;
     392        Declaration * get_decl() { return decl; }
     393        void set_decl( Declaration * newValue ) { decl = newValue; }
     394        Expression * get_cond() { return cond; }
     395        void set_cond( Expression * newCond ) { cond = newCond; }
     396        Statement * get_body() { return body; }
     397        void set_body( Statement * newValue ) { body = newValue; }
     398
     399        virtual CatchStmt * clone() const override { return new CatchStmt( *this ); }
     400        virtual void accept( Visitor & v ) override { v.visit( this ); }
     401        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     402        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     403        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    390404};
    391405
    392406class FinallyStmt : public Statement {
    393407  public:
    394         CompoundStmt *block;
    395 
    396         FinallyStmt( CompoundStmt *block );
    397         FinallyStmt( const FinallyStmt &other );
     408        CompoundStmt * block;
     409
     410        FinallyStmt( CompoundStmt * block );
     411        FinallyStmt( const FinallyStmt & other );
    398412        virtual ~FinallyStmt();
    399413
    400         CompoundStmt *get_block() const { return block; }
    401         void set_block( CompoundStmt *newValue ) { block = newValue; }
    402 
    403         virtual FinallyStmt *clone() const override { return new FinallyStmt( *this ); }
    404         virtual void accept( Visitor &v ) override { v.visit( this ); }
    405         virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    406         virtual void print( std::ostream &os, Indenter indent = {} ) const override;
     414        CompoundStmt * get_block() const { return block; }
     415        void set_block( CompoundStmt * newValue ) { block = newValue; }
     416
     417        virtual FinallyStmt * clone() const override { return new FinallyStmt( *this ); }
     418        virtual void accept( Visitor & v ) override { v.visit( this ); }
     419        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     420        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     421        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    407422};
    408423
     
    438453        } orelse;
    439454
    440         virtual WaitForStmt *clone() const override { return new WaitForStmt( *this ); }
    441         virtual void accept( Visitor &v ) override { v.visit( this ); }
    442         virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    443         virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    444 
    445 };
    446 
    447 class WithStmt : public Statement {
    448 public:
    449         std::list< Expression * > exprs;
    450         Statement * stmt;
    451 
    452         WithStmt( const std::list< Expression * > & exprs, Statement * stmt );
    453         WithStmt( const WithStmt & other );
    454         virtual ~WithStmt();
    455 
    456         virtual WithStmt * clone() const override { return new WithStmt( *this ); }
    457         virtual void accept( Visitor & v ) override { v.visit( this ); }
    458         virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
    459         virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    460 };
     455        virtual WaitForStmt * clone() const override { return new WaitForStmt( *this ); }
     456        virtual void accept( Visitor & v ) override { v.visit( this ); }
     457        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     458        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     459        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     460
     461};
     462
     463// class WithStmt : public Statement {
     464// public:
     465//      std::list< Expression * > exprs;
     466//      Statement * stmt;
     467
     468//      WithStmt( const std::list< Expression * > & exprs, Statement * stmt );
     469//      WithStmt( const WithStmt & other );
     470//      virtual ~WithStmt();
     471
     472//      virtual WithStmt * clone() const override { return new WithStmt( *this ); }
     473//      virtual void accept( Visitor & v ) override { v.visit( this ); }
     474//      virtual void accept( Visitor & v ) const override { v.visit( this ); }
     475//      virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     476//      virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     477// };
    461478
    462479
     
    464481class DeclStmt : public Statement {
    465482  public:
    466         Declaration *decl;
    467 
    468         DeclStmt( Declaration *decl );
    469         DeclStmt( const DeclStmt &other );
     483        Declaration * decl;
     484
     485        DeclStmt( Declaration * decl );
     486        DeclStmt( const DeclStmt & other );
    470487        virtual ~DeclStmt();
    471488
    472         Declaration *get_decl() const { return decl; }
    473         void set_decl( Declaration *newValue ) { decl = newValue; }
    474 
    475         virtual DeclStmt *clone() const override { return new DeclStmt( *this ); }
    476         virtual void accept( Visitor &v ) override { v.visit( this ); }
    477         virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    478         virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    479 };
    480 
    481 
    482 /// represents an implicit application of a constructor or destructor. Qualifiers are replaced
    483 /// immediately before and after the call so that qualified objects can be constructed
    484 /// with the same functions as unqualified objects.
     489        Declaration * get_decl() const { return decl; }
     490        void set_decl( Declaration * newValue ) { decl = newValue; }
     491
     492        virtual DeclStmt * clone() const override { return new DeclStmt( *this ); }
     493        virtual void accept( Visitor & v ) override { v.visit( this ); }
     494        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     495        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     496        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     497};
     498
     499
     500/// represents an implicit application of a constructor or destructor. Qualifiers are replaced immediately before and
     501/// after the call so that qualified objects can be constructed with the same functions as unqualified objects.
    485502class ImplicitCtorDtorStmt : public Statement {
    486503  public:
     
    492509        virtual ~ImplicitCtorDtorStmt();
    493510
    494         Statement *get_callStmt() const { return callStmt; }
     511        Statement * get_callStmt() const { return callStmt; }
    495512        void set_callStmt( Statement * newValue ) { callStmt = newValue; }
    496513
    497         virtual ImplicitCtorDtorStmt *clone() const override { return new ImplicitCtorDtorStmt( *this ); }
    498         virtual void accept( Visitor &v ) override { v.visit( this ); }
    499         virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    500         virtual void print( std::ostream &os, Indenter indent = {} ) const override;
     514        virtual ImplicitCtorDtorStmt * clone() const override { return new ImplicitCtorDtorStmt( *this ); }
     515        virtual void accept( Visitor & v ) override { v.visit( this ); }
     516        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     517        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     518        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    501519};
    502520
  • src/SynTree/SynTree.h

    r7951100 rb067d9b  
    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 : Mon Jul 24 16:54:00 2017
    13 // Update Count     : 11
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Thu Jul 25 22:37:45 2019
     13// Update Count     : 12
    1414//
    1515
     
    3434class NamedTypeDecl;
    3535class TypeDecl;
    36 class FtypeDecl;
    37 class DtypeDecl;
    3836class TypedefDecl;
    3937class AsmDecl;
     
    8179class OffsetofExpr;
    8280class OffsetPackExpr;
    83 class AttrExpr;
    8481class LogicalExpr;
    8582class ConditionalExpr;
     
    9087class ConstructorExpr;
    9188class CompoundLiteralExpr;
    92 class UntypedValofExpr;
    9389class RangeExpr;
    9490class UntypedTupleExpr;
     
    10197class InitExpr;
    10298class DeletedExpr;
     99class DefaultArgExpr;
    103100class GenericExpr;
    104101
     
    109106class ArrayType;
    110107class ReferenceType;
     108class QualifiedType;
    111109class FunctionType;
    112110class ReferenceToType;
     
    122120class ZeroType;
    123121class OneType;
     122class GlobalScopeType;
    124123
    125124class Designation;
     
    128127class ListInit;
    129128class ConstructorInit;
    130 
    131 class Subrange;
    132129
    133130//template <class T>    // emulate a union with templates?
  • src/SynTree/TupleExpr.cc

    r7951100 rb067d9b  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Mar 17 09:42:29 2017
    13 // Update Count     : 3
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed Aug 14 14:34:00 2019
     13// Update Count     : 5
    1414//
    1515
     
    5757}
    5858
     59bool TupleExpr::get_lvalue() const {
     60        return false;
     61}
     62
    5963void TupleExpr::print( std::ostream &os, Indenter indent ) const {
    6064        os << "Tuple:" << std::endl;
     
    6771        assertf( type->size() > index, "TupleIndexExpr index out of bounds: tuple size %d, requested index %d in expr %s", type->size(), index, toString( tuple ).c_str() );
    6872        set_result( (*std::next( type->get_types().begin(), index ))->clone() );
    69         // like MemberExpr, TupleIndexExpr is always an lvalue
    70         get_result()->set_lvalue( true );
    7173}
    7274
     
    7678TupleIndexExpr::~TupleIndexExpr() {
    7779        delete tuple;
     80}
     81
     82bool TupleIndexExpr::get_lvalue() const {
     83        return tuple->get_lvalue();
    7884}
    7985
     
    105111}
    106112
     113TupleAssignExpr::TupleAssignExpr(
     114        StmtExpr * s )
     115: Expression(), stmtExpr(s) {
     116}
     117
     118
    107119TupleAssignExpr::~TupleAssignExpr() {
    108120        delete stmtExpr;
  • src/SynTree/Type.cc

    r7951100 rb067d9b  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Sep 25 15:16:32 2017
    13 // Update Count     : 38
     12// Last Modified On : Sun Aug  4 21:05:07 2019
     13// Update Count     : 45
    1414//
    1515#include "Type.h"
     
    2424using namespace std;
    2525
    26 const char *BasicType::typeNames[] = {
     26const char * BasicType::typeNames[] = {
    2727        "_Bool",
    2828        "char",
     
    3737        "signed long long int",
    3838        "unsigned long long int",
    39         "float",
    40         "double",
    41         "long double",
    42         "float _Complex",
    43         "double _Complex",
    44         "long double _Complex",
    45         "float _Imaginary",
    46         "double _Imaginary",
    47         "long double _Imaginary",
    4839        "__int128",
    4940        "unsigned __int128",
     41        "_Float16",
     42        "_Float16 _Complex",
     43        "_Float32",
     44        "_Float32 _Complex",
     45        "float",
     46        "float _Complex",
     47        //"float _Imaginary",
     48        "_Float32x",
     49        "_Float32x _Complex",
     50        "_Float64",
     51        "_Float64 _Complex",
     52        "double",
     53        "double _Complex",
     54        //"double _Imaginary",
     55        "_Float64x",
     56        "_Float64x _Complex",
    5057        "__float80",
    51         "__float128"
     58        "_Float128",
     59        "_Float128 _Complex",
     60        "__float128",
     61        "long double",
     62        "long double _Complex",
     63        //"long double _Imaginary",
     64        "_Float128x",
     65        "_Float128x _Complex",
    5266};
    5367static_assert(
    54         sizeof(BasicType::typeNames)/sizeof(BasicType::typeNames[0]) == BasicType::NUMBER_OF_BASIC_TYPES,
     68        sizeof(BasicType::typeNames) / sizeof(BasicType::typeNames[0]) == BasicType::NUMBER_OF_BASIC_TYPES,
    5569        "Each basic type name should have a corresponding kind enum value"
    5670);
     
    6983
    7084// These must remain in the same order as the corresponding bit fields.
    71 const char * Type::FuncSpecifiersNames[] = { "inline", "fortran", "_Noreturn" };
     85const char * Type::FuncSpecifiersNames[] = { "inline", "_Noreturn", "fortran" };
    7286const char * Type::StorageClassesNames[] = { "extern", "static", "auto", "register", "_Thread_local" };
    73 const char * Type::QualifiersNames[] = { "const", "restrict", "volatile", "lvalue", "mutex", "_Atomic" };
     87const char * Type::QualifiersNames[] = { "const", "restrict", "volatile", "mutex", "_Atomic" };
    7488
    7589Type * Type::stripDeclarator() {
     
    86100}
    87101
     102const Type * Type::stripReferences() const {
     103        const Type * type;
     104        const ReferenceType * ref;
     105        for ( type = this; (ref = dynamic_cast<const ReferenceType *>( type )); type = ref->base );
     106        return type;
     107}
     108
    88109int Type::referenceDepth() const { return 0; }
    89110
    90111TypeSubstitution Type::genericSubstitution() const { assertf( false, "Non-aggregate type: %s", toCString( this ) ); }
    91112
    92 void Type::print( std::ostream &os, Indenter indent ) const {
     113void Type::print( std::ostream & os, Indenter indent ) const {
    93114        if ( ! forall.empty() ) {
    94115                os << "forall" << std::endl;
     
    105126}
    106127
     128
     129QualifiedType::QualifiedType( const Type::Qualifiers & tq, Type * parent, Type * child ) : Type( tq, {} ), parent( parent ), child( child ) {
     130}
     131
     132QualifiedType::QualifiedType( const QualifiedType & other ) : Type( other ), parent( maybeClone( other.parent ) ), child( maybeClone( other.child ) ) {
     133}
     134
     135QualifiedType::~QualifiedType() {
     136        delete parent;
     137        delete child;
     138}
     139
     140void QualifiedType::print( std::ostream & os, Indenter indent ) const {
     141        os << "Qualified Type:" << endl;
     142        os << indent+1;
     143        parent->print( os, indent+1 );
     144        os << endl << indent+1;
     145        child->print( os, indent+1 );
     146        os << endl;
     147        Type::print( os, indent+1 );
     148}
     149
     150GlobalScopeType::GlobalScopeType() : Type( Type::Qualifiers(), {} ) {}
     151
     152void GlobalScopeType::print( std::ostream & os, Indenter ) const {
     153        os << "Global Scope Type" << endl;
     154}
     155
     156
    107157// Empty Variable declarations:
    108158const Type::FuncSpecifiers noFuncSpecifiers;
  • src/SynTree/Type.h

    r7951100 rb067d9b  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Sep 25 14:14:01 2017
    13 // Update Count     : 154
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed Sep  4 09:58:00 2019
     13// Update Count     : 170
    1414//
    1515
     
    102102        }; // StorageClasses
    103103
    104         enum { Const = 1 << 0, Restrict = 1 << 1, Volatile = 1 << 2, Lvalue = 1 << 3, Mutex = 1 << 4, Atomic = 1 << 5, NumTypeQualifier = 6 };
     104        enum { Const = 1 << 0, Restrict = 1 << 1, Volatile = 1 << 2, Mutex = 1 << 3, Atomic = 1 << 4, NumTypeQualifier = 5 };
    105105        static const char * QualifiersNames[];
    106106        union Qualifiers {
    107                 enum { Mask = ~(Restrict | Lvalue) };
     107                enum { Mask = ~Restrict };
    108108                unsigned int val;
    109109                struct {
     
    111111                        bool is_restrict : 1;
    112112                        bool is_volatile : 1;
    113                         bool is_lvalue : 1;
    114113                        bool is_mutex : 1;
    115114                        bool is_atomic : 1;
     
    131130                bool operator>( Qualifiers other ) const { return *this != other && *this >= other; }
    132131                BFCommon( Qualifiers, NumTypeQualifier )
     132
     133                Qualifiers unify( Qualifiers const & other ) const {
     134                        int or_flags = Mask & (val | other.val);
     135                        int and_flags = val & other.val;
     136                        return Qualifiers( or_flags | and_flags );
     137                }
    133138        }; // Qualifiers
    134139
     
    144149
    145150        Qualifiers & get_qualifiers() { return tq; }
    146         bool get_const() { return tq.is_const; }
    147         bool get_volatile() { return tq.is_volatile; }
    148         bool get_restrict() { return tq.is_restrict; }
    149         bool get_lvalue() { return tq.is_lvalue; }
    150         bool get_mutex() { return tq.is_mutex; }
    151         bool get_atomic() { return tq.is_atomic; }
     151        bool get_const() const { return tq.is_const; }
     152        bool get_volatile() const { return tq.is_volatile; }
     153        bool get_restrict() const { return tq.is_restrict; }
     154        bool get_mutex() const { return tq.is_mutex; }
     155        bool get_atomic() const { return tq.is_atomic; }
    152156        void set_const( bool newValue ) { tq.is_const = newValue; }
    153157        void set_volatile( bool newValue ) { tq.is_volatile = newValue; }
    154158        void set_restrict( bool newValue ) { tq.is_restrict = newValue; }
    155         void set_lvalue( bool newValue ) { tq.is_lvalue = newValue; }
    156159        void set_mutex( bool newValue ) { tq.is_mutex = newValue; }
    157160        void set_atomic( bool newValue ) { tq.is_atomic = newValue; }
     
    172175        /// return type without outer references
    173176        Type * stripReferences();
     177        const Type * stripReferences() const;
    174178
    175179        /// return the number of references occuring consecutively on the outermost layer of this type (i.e. do not count references nested within other types)
     
    178182        virtual bool isComplete() const { return true; }
    179183
    180         virtual AggregateDecl * getAggr() { assertf( false, "Non-aggregate type: %s", toCString( this ) ); }
     184        virtual AggregateDecl * getAggr() const { assertf( false, "Non-aggregate type: %s", toCString( this ) ); }
    181185
    182186        virtual TypeSubstitution genericSubstitution() const;
     
    184188        virtual Type *clone() const = 0;
    185189        virtual void accept( Visitor & v ) = 0;
     190        virtual void accept( Visitor & v ) const = 0;
    186191        virtual Type *acceptMutator( Mutator & m ) = 0;
    187192        virtual void print( std::ostream & os, Indenter indent = {} ) const;
     
    201206        virtual VoidType *clone() const override { return new VoidType( *this ); }
    202207        virtual void accept( Visitor & v ) override { v.visit( this ); }
     208        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    203209        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    204210        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    207213class BasicType : public Type {
    208214  public:
     215        // GENERATED START, DO NOT EDIT
     216        // GENERATED BY BasicTypes-gen.cc
    209217        enum Kind {
    210218                Bool,
     
    220228                LongLongSignedInt,
    221229                LongLongUnsignedInt,
    222                 Float,
    223                 Double,
    224                 LongDouble,
    225                 FloatComplex,
    226                 DoubleComplex,
    227                 LongDoubleComplex,
    228                 FloatImaginary,
    229                 DoubleImaginary,
    230                 LongDoubleImaginary,
    231230                SignedInt128,
    232231                UnsignedInt128,
    233                 Float80,
    234                 Float128,
     232                uFloat16,
     233                uFloat16Complex,
     234                uFloat32,
     235                uFloat32Complex,
     236                Float,
     237                FloatComplex,
     238                uFloat32x,
     239                uFloat32xComplex,
     240                uFloat64,
     241                uFloat64Complex,
     242                Double,
     243                DoubleComplex,
     244                uFloat64x,
     245                uFloat64xComplex,
     246                uuFloat80,
     247                uFloat128,
     248                uFloat128Complex,
     249                uuFloat128,
     250                LongDouble,
     251                LongDoubleComplex,
     252                uFloat128x,
     253                uFloat128xComplex,
    235254                NUMBER_OF_BASIC_TYPES
    236255        } kind;
     256        // GENERATED END
    237257
    238258        static const char *typeNames[];                                         // string names for basic types, MUST MATCH with Kind
     
    240260        BasicType( const Type::Qualifiers & tq, Kind bt, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
    241261
    242         Kind get_kind() { return kind; }
     262        Kind get_kind() const { return kind; }
    243263        void set_kind( Kind newValue ) { kind = newValue; }
    244264
    245265        virtual BasicType *clone() const override { return new BasicType( *this ); }
    246266        virtual void accept( Visitor & v ) override { v.visit( this ); }
     267        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    247268        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    248269        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    280301        virtual PointerType *clone() const override { return new PointerType( *this ); }
    281302        virtual void accept( Visitor & v ) override { v.visit( this ); }
     303        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    282304        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    283305        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    311333        virtual ArrayType *clone() const override { return new ArrayType( *this ); }
    312334        virtual void accept( Visitor & v ) override { v.visit( this ); }
     335        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     336        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     337        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     338};
     339
     340class QualifiedType : public Type {
     341public:
     342        Type * parent;
     343        Type * child;
     344
     345        QualifiedType( const Type::Qualifiers & tq, Type * parent, Type * child );
     346        QualifiedType( const QualifiedType & tq );
     347        virtual ~QualifiedType();
     348
     349        virtual QualifiedType *clone() const override { return new QualifiedType( *this ); }
     350        virtual void accept( Visitor & v ) override { v.visit( this ); }
     351        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    313352        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    314353        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    337376        virtual ReferenceType *clone() const override { return new ReferenceType( *this ); }
    338377        virtual void accept( Visitor & v ) override { v.visit( this ); }
     378        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    339379        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    340380        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    366406        virtual FunctionType *clone() const override { return new FunctionType( *this ); }
    367407        virtual void accept( Visitor & v ) override { v.visit( this ); }
     408        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    368409        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    369410        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    416457        virtual bool isComplete() const override;
    417458
    418         virtual AggregateDecl * getAggr() override;
     459        virtual AggregateDecl * getAggr() const override;
    419460
    420461        virtual TypeSubstitution genericSubstitution() const override;
     
    426467        virtual StructInstType *clone() const override { return new StructInstType( *this ); }
    427468        virtual void accept( Visitor & v ) override { v.visit( this ); }
     469        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    428470        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    429471
     
    453495        virtual bool isComplete() const override;
    454496
    455         virtual AggregateDecl * getAggr() override;
     497        virtual AggregateDecl * getAggr() const override;
    456498
    457499        virtual TypeSubstitution genericSubstitution() const override;
     
    463505        virtual UnionInstType *clone() const override { return new UnionInstType( *this ); }
    464506        virtual void accept( Visitor & v ) override { v.visit( this ); }
     507        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    465508        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    466509
     
    486529        virtual bool isComplete() const override;
    487530
     531        virtual AggregateDecl * getAggr() const override;
     532
    488533        virtual EnumInstType *clone() const override { return new EnumInstType( *this ); }
    489534        virtual void accept( Visitor & v ) override { v.visit( this ); }
     535        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    490536        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    491537
     
    511557        virtual TraitInstType *clone() const override { return new TraitInstType( *this ); }
    512558        virtual void accept( Visitor & v ) override { v.visit( this ); }
     559        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    513560        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    514561  private:
     
    538585        virtual TypeInstType *clone() const override { return new TypeInstType( *this ); }
    539586        virtual void accept( Visitor & v ) override { v.visit( this ); }
     587        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    540588        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    541589        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    575623        virtual TupleType *clone() const override { return new TupleType( *this ); }
    576624        virtual void accept( Visitor & v ) override { v.visit( this ); }
     625        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    577626        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    578627        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    581630class TypeofType : public Type {
    582631  public:
    583         Expression *expr;
    584 
    585         TypeofType( const Type::Qualifiers & tq, Expression *expr, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
     632        Expression *expr;    ///< expression to take the type of
     633        bool is_basetypeof;  ///< true iff is basetypeof type
     634
     635        TypeofType( const Type::Qualifiers & tq, Expression *expr, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
     636        TypeofType( const Type::Qualifiers & tq, Expression *expr, bool is_basetypeof,
     637                const std::list< Attribute * > & attributes = std::list< Attribute * >() );
    586638        TypeofType( const TypeofType& );
    587639        virtual ~TypeofType();
     
    594646        virtual TypeofType *clone() const override { return new TypeofType( *this ); }
    595647        virtual void accept( Visitor & v ) override { v.visit( this ); }
     648        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    596649        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    597650        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    623676        virtual AttrType *clone() const override { return new AttrType( *this ); }
    624677        virtual void accept( Visitor & v ) override { v.visit( this ); }
     678        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    625679        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    626680        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    637691        virtual VarArgsType *clone() const override { return new VarArgsType( *this ); }
    638692        virtual void accept( Visitor & v ) override { v.visit( this ); }
     693        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    639694        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    640695        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    649704        virtual ZeroType *clone() const override { return new ZeroType( *this ); }
    650705        virtual void accept( Visitor & v ) override { v.visit( this ); }
     706        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    651707        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    652708        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    661717        virtual OneType *clone() const override { return new OneType( *this ); }
    662718        virtual void accept( Visitor & v ) override { v.visit( this ); }
     719        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     720        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     721        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     722};
     723
     724class GlobalScopeType : public Type {
     725  public:
     726        GlobalScopeType();
     727
     728        virtual GlobalScopeType *clone() const override { return new GlobalScopeType( *this ); }
     729        virtual void accept( Visitor & v ) override { v.visit( this ); }
     730        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    663731        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    664732        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
  • src/SynTree/TypeSubstitution.cc

    r7951100 rb067d9b  
    6464}
    6565
     66void TypeSubstitution::addVar( std::string formalExpr, Expression *actualExpr ) {
     67        varEnv[ formalExpr ] = actualExpr;
     68}
     69
    6670void TypeSubstitution::remove( std::string formalType ) {
    6771        TypeEnvType::iterator i = typeEnv.find( formalType );
     
    108112namespace {
    109113        struct EnvTrimmer {
    110                 TypeSubstitution * env, * newEnv;
    111                 EnvTrimmer( TypeSubstitution * env, TypeSubstitution * newEnv ) : env( env ), newEnv( newEnv ){}
     114                const TypeSubstitution * env;
     115                TypeSubstitution * newEnv;
     116                EnvTrimmer( const TypeSubstitution * env, TypeSubstitution * newEnv ) : env( env ), newEnv( newEnv ){}
    112117                void previsit( TypeDecl * tyDecl ) {
    113118                        // transfer known bindings for seen type variables
     
    120125
    121126/// reduce environment to just the parts that are referenced in a given expression
    122 TypeSubstitution * TypeSubstitution::newFromExpr( Expression * expr, TypeSubstitution * env ) {
     127TypeSubstitution * TypeSubstitution::newFromExpr( Expression * expr, const TypeSubstitution * env ) {
    123128        if ( env ) {
    124129                TypeSubstitution * newEnv = new TypeSubstitution();
  • src/SynTree/TypeSubstitution.h

    r7951100 rb067d9b  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:52:24 2017
    13 // Update Count     : 3
     12// Last Modified On : Tue Apr 30 22:52:47 2019
     13// Update Count     : 9
    1414//
    1515
     
    1919#include <iosfwd>                  // for ostream
    2020#include <list>                    // for list<>::iterator, _List_iterator
    21 #include <map>                     // for _Rb_tree_iterator, map, map<>::val...
    22 #include <set>                     // for set
     21#include <unordered_map>
     22#include <unordered_set>
    2323#include <string>                  // for string, operator!=
    2424#include <utility>                 // for pair
     
    3939        TypeSubstitution &operator=( const TypeSubstitution &other );
    4040
    41         template< typename SynTreeClass > int apply( SynTreeClass *&input );
    42         template< typename SynTreeClass > int applyFree( SynTreeClass *&input );
     41        template< typename SynTreeClass > int apply( SynTreeClass *&input ) const;
     42        template< typename SynTreeClass > int applyFree( SynTreeClass *&input ) const;
    4343
    4444        void add( std::string formalType, Type *actualType );
     
    4848        bool empty() const;
    4949
     50        void addVar( std::string formalExpr, Expression *actualExpr );
     51
    5052        template< typename FormalIterator, typename ActualIterator >
    5153        void add( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin );
     
    5658
    5759        /// create a new TypeSubstitution using bindings from env containing all of the type variables in expr
    58         static TypeSubstitution * newFromExpr( Expression * expr, TypeSubstitution * env );
     60        static TypeSubstitution * newFromExpr( Expression * expr, const TypeSubstitution * env );
    5961
    6062        void normalize();
     
    7880        friend class PassVisitor;
    7981
    80         typedef std::map< std::string, Type* > TypeEnvType;
    81         typedef std::map< std::string, Expression* > VarEnvType;
     82        typedef std::unordered_map< std::string, Type * > TypeEnvType;
     83        typedef std::unordered_map< std::string, Expression * > VarEnvType;
    8284        TypeEnvType typeEnv;
    8385        VarEnvType varEnv;
     
    8991        auto begin() const -> decltype( typeEnv.begin() ) { return typeEnv.begin(); }
    9092        auto   end() const -> decltype( typeEnv.  end() ) { return typeEnv.  end(); }
     93
     94        auto beginVar()       -> decltype( varEnv.begin() ) { return varEnv.begin(); }
     95        auto   endVar()       -> decltype( varEnv.  end() ) { return varEnv.  end(); }
     96        auto beginVar() const -> decltype( varEnv.begin() ) { return varEnv.begin(); }
     97        auto   endVar() const -> decltype( varEnv.  end() ) { return varEnv.  end(); }
    9198};
    9299
     
    98105        ActualIterator actualIt = actualBegin;
    99106        for ( ; formalIt != formalEnd; ++formalIt, ++actualIt ) {
    100                 if ( TypeDecl *formal = dynamic_cast< TypeDecl* >( *formalIt ) ) {
    101                         if ( TypeExpr *actual = dynamic_cast< TypeExpr* >( *actualIt ) ) {
     107                if ( TypeDecl *formal = dynamic_cast< TypeDecl * >( *formalIt ) ) {
     108                        if ( TypeExpr *actual = dynamic_cast< TypeExpr * >( *actualIt ) ) {
    102109                                if ( formal->get_name() != "" ) {
    103110                                        TypeEnvType::iterator i = typeEnv.find( formal->get_name() );
     
    130137// definitition must happen after PassVisitor is included so that WithGuards can be used
    131138struct TypeSubstitution::Substituter : public WithGuards, public WithVisitorRef<Substituter> {
    132                 Substituter( TypeSubstitution & sub, bool freeOnly ) : sub( sub ), freeOnly( freeOnly ) {}
     139                Substituter( const TypeSubstitution & sub, bool freeOnly ) : sub( sub ), freeOnly( freeOnly ) {}
    133140
    134141                Type * postmutate( TypeInstType * aggregateUseType );
     
    143150                void premutate( UnionInstType * aggregateUseType );
    144151
    145                 TypeSubstitution & sub;
     152                const TypeSubstitution & sub;
    146153                int subCount = 0;
    147154                bool freeOnly;
    148                 typedef std::set< std::string > BoundVarsType;
     155                typedef std::unordered_set< std::string > BoundVarsType;
    149156                BoundVarsType boundVars;
    150157};
    151158
    152159template< typename SynTreeClass >
    153 int TypeSubstitution::apply( SynTreeClass *&input ) {
     160int TypeSubstitution::apply( SynTreeClass *&input ) const {
    154161        assert( input );
    155162        PassVisitor<Substituter> sub( *this, false );
     
    163170
    164171template< typename SynTreeClass >
    165 int TypeSubstitution::applyFree( SynTreeClass *&input ) {
     172int TypeSubstitution::applyFree( SynTreeClass *&input ) const {
    166173        assert( input );
    167174        PassVisitor<Substituter> sub( *this, true );
  • src/SynTree/TypeofType.cc

    r7951100 rb067d9b  
    2323class Attribute;
    2424
    25 TypeofType::TypeofType( const Type::Qualifiers &tq, Expression *expr, const std::list< Attribute * > & attributes ) : Type( tq, attributes ), expr( expr ) {
    26 }
     25TypeofType::TypeofType( const Type::Qualifiers &tq, Expression *expr,
     26        const std::list< Attribute * > & attributes )
     27: Type( tq, attributes ), expr( expr ), is_basetypeof(false) {}
    2728
    28 TypeofType::TypeofType( const TypeofType &other ) : Type( other ), expr( maybeClone( other.expr ) ) {
    29 }
     29TypeofType::TypeofType( const Type::Qualifiers &tq, Expression *expr, bool is_basetypeof,
     30        const std::list< Attribute * > & attributes )
     31: Type( tq, attributes ), expr( expr ), is_basetypeof( is_basetypeof ) {}
     32
     33TypeofType::TypeofType( const TypeofType &other )
     34: Type( other ), expr( maybeClone( other.expr ) ), is_basetypeof( other.is_basetypeof ) {}
    3035
    3136TypeofType::~TypeofType() {
     
    3540void TypeofType::print( std::ostream &os, Indenter indent ) const {
    3641        Type::print( os, indent );
     42        if ( is_basetypeof ) { os << "base-"; }
    3743        os << "type-of expression ";
    3844        if ( expr ) {
  • src/SynTree/Visitor.h

    r7951100 rb067d9b  
    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 : Mon Jul 24 16:28:00 2017
    13 // Update Count     : 13
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Thu Jul 25 22:21:49 2019
     13// Update Count     : 14
    1414//
    1515
     
    2727        // of the given syntax node, but performs no other action.
    2828
    29         virtual void visit( ObjectDecl * objectDecl ) = 0;
    30         virtual void visit( FunctionDecl * functionDecl ) = 0;
    31         virtual void visit( StructDecl * aggregateDecl ) = 0;
    32         virtual void visit( UnionDecl * aggregateDecl ) = 0;
    33         virtual void visit( EnumDecl * aggregateDecl ) = 0;
    34         virtual void visit( TraitDecl * aggregateDecl ) = 0;
    35         virtual void visit( TypeDecl * typeDecl ) = 0;
    36         virtual void visit( TypedefDecl * typeDecl ) = 0;
    37         virtual void visit( AsmDecl * asmDecl ) = 0;
    38         virtual void visit( StaticAssertDecl * assertDecl ) = 0;
    39 
    40         virtual void visit( CompoundStmt * compoundStmt ) = 0;
    41         virtual void visit( ExprStmt * exprStmt ) = 0;
    42         virtual void visit( AsmStmt * asmStmt ) = 0;
    43         virtual void visit( DirectiveStmt * directiveStmt ) = 0;
    44         virtual void visit( IfStmt * ifStmt ) = 0;
    45         virtual void visit( WhileStmt * whileStmt ) = 0;
    46         virtual void visit( ForStmt * forStmt ) = 0;
    47         virtual void visit( SwitchStmt * switchStmt ) = 0;
    48         virtual void visit( CaseStmt * caseStmt ) = 0;
    49         virtual void visit( BranchStmt * branchStmt ) = 0;
    50         virtual void visit( ReturnStmt * returnStmt ) = 0;
    51         virtual void visit( ThrowStmt * throwStmt ) = 0;
    52         virtual void visit( TryStmt * tryStmt ) = 0;
    53         virtual void visit( CatchStmt * catchStmt ) = 0;
    54         virtual void visit( FinallyStmt * finallyStmt ) = 0;
    55         virtual void visit( WaitForStmt * waitforStmt ) = 0;
    56         virtual void visit( WithStmt * withStmt ) = 0;
    57         virtual void visit( NullStmt * nullStmt ) = 0;
    58         virtual void visit( DeclStmt * declStmt ) = 0;
    59         virtual void visit( ImplicitCtorDtorStmt * impCtorDtorStmt ) = 0;
    60 
    61         virtual void visit( ApplicationExpr * applicationExpr ) = 0;
    62         virtual void visit( UntypedExpr * untypedExpr ) = 0;
    63         virtual void visit( NameExpr * nameExpr ) = 0;
    64         virtual void visit( CastExpr * castExpr ) = 0;
    65         virtual void visit( KeywordCastExpr * castExpr ) = 0;
    66         virtual void visit( VirtualCastExpr * castExpr ) = 0;
    67         virtual void visit( AddressExpr * addressExpr ) = 0;
    68         virtual void visit( LabelAddressExpr * labAddressExpr ) = 0;
    69         virtual void visit( UntypedMemberExpr * memberExpr ) = 0;
    70         virtual void visit( MemberExpr * memberExpr ) = 0;
    71         virtual void visit( VariableExpr * variableExpr ) = 0;
    72         virtual void visit( ConstantExpr * constantExpr ) = 0;
    73         virtual void visit( SizeofExpr * sizeofExpr ) = 0;
    74         virtual void visit( AlignofExpr * alignofExpr ) = 0;
    75         virtual void visit( UntypedOffsetofExpr * offsetofExpr ) = 0;
    76         virtual void visit( OffsetofExpr * offsetofExpr ) = 0;
    77         virtual void visit( OffsetPackExpr * offsetPackExpr ) = 0;
    78         virtual void visit( AttrExpr * attrExpr ) = 0;
    79         virtual void visit( LogicalExpr * logicalExpr ) = 0;
    80         virtual void visit( ConditionalExpr * conditionalExpr ) = 0;
    81         virtual void visit( CommaExpr * commaExpr ) = 0;
    82         virtual void visit( TypeExpr * typeExpr ) = 0;
    83         virtual void visit( AsmExpr * asmExpr ) = 0;
    84         virtual void visit( ImplicitCopyCtorExpr * impCpCtorExpr ) = 0;
    85         virtual void visit( ConstructorExpr *  ctorExpr ) = 0;
    86         virtual void visit( CompoundLiteralExpr * compLitExpr ) = 0;
    87         virtual void visit( RangeExpr * rangeExpr ) = 0;
    88         virtual void visit( UntypedTupleExpr * tupleExpr ) = 0;
    89         virtual void visit( TupleExpr * tupleExpr ) = 0;
    90         virtual void visit( TupleIndexExpr * tupleExpr ) = 0;
    91         virtual void visit( TupleAssignExpr * assignExpr ) = 0;
    92         virtual void visit( StmtExpr *  stmtExpr ) = 0;
    93         virtual void visit( UniqueExpr *  uniqueExpr ) = 0;
    94         virtual void visit( UntypedInitExpr *  initExpr ) = 0;
    95         virtual void visit( InitExpr *  initExpr ) = 0;
    96         virtual void visit( DeletedExpr * delExpr ) = 0;
    97         virtual void visit( GenericExpr * genExpr ) = 0;
    98 
    99         virtual void visit( VoidType * basicType ) = 0;
    100         virtual void visit( BasicType * basicType ) = 0;
    101         virtual void visit( PointerType * pointerType ) = 0;
    102         virtual void visit( ArrayType * arrayType ) = 0;
    103         virtual void visit( ReferenceType * refType ) = 0;
    104         virtual void visit( FunctionType * functionType ) = 0;
    105         virtual void visit( StructInstType * aggregateUseType ) = 0;
    106         virtual void visit( UnionInstType * aggregateUseType ) = 0;
    107         virtual void visit( EnumInstType * aggregateUseType ) = 0;
    108         virtual void visit( TraitInstType * aggregateUseType ) = 0;
    109         virtual void visit( TypeInstType * aggregateUseType ) = 0;
    110         virtual void visit( TupleType * tupleType ) = 0;
    111         virtual void visit( TypeofType * typeofType ) = 0;
    112         virtual void visit( AttrType * attrType ) = 0;
    113         virtual void visit( VarArgsType * varArgsType ) = 0;
    114         virtual void visit( ZeroType * zeroType ) = 0;
    115         virtual void visit( OneType * oneType ) = 0;
    116 
    117         virtual void visit( Designation * designation ) = 0;
    118         virtual void visit( SingleInit * singleInit ) = 0;
    119         virtual void visit( ListInit * listInit ) = 0;
    120         virtual void visit( ConstructorInit * ctorInit ) = 0;
    121 
    122         virtual void visit( Subrange * subrange ) = 0;
    123 
    124         virtual void visit( Constant * constant ) = 0;
    125 
    126         virtual void visit( Attribute * attribute ) = 0;
     29        virtual void visit( ObjectDecl * node ) { visit( const_cast<const ObjectDecl *>(node) ); }
     30        virtual void visit( const ObjectDecl * objectDecl ) = 0;
     31        virtual void visit( FunctionDecl * node ) { visit( const_cast<const FunctionDecl *>(node) ); }
     32        virtual void visit( const FunctionDecl * functionDecl ) = 0;
     33        virtual void visit( StructDecl * node ) { visit( const_cast<const StructDecl *>(node) ); }
     34        virtual void visit( const StructDecl * aggregateDecl ) = 0;
     35        virtual void visit( UnionDecl * node ) { visit( const_cast<const UnionDecl *>(node) ); }
     36        virtual void visit( const UnionDecl * aggregateDecl ) = 0;
     37        virtual void visit( EnumDecl * node ) { visit( const_cast<const EnumDecl *>(node) ); }
     38        virtual void visit( const EnumDecl * aggregateDecl ) = 0;
     39        virtual void visit( TraitDecl * node ) { visit( const_cast<const TraitDecl *>(node) ); }
     40        virtual void visit( const TraitDecl * aggregateDecl ) = 0;
     41        virtual void visit( TypeDecl * node ) { visit( const_cast<const TypeDecl *>(node) ); }
     42        virtual void visit( const TypeDecl * typeDecl ) = 0;
     43        virtual void visit( TypedefDecl * node ) { visit( const_cast<const TypedefDecl *>(node) ); }
     44        virtual void visit( const TypedefDecl * typeDecl ) = 0;
     45        virtual void visit( AsmDecl * node ) { visit( const_cast<const AsmDecl *>(node) ); }
     46        virtual void visit( const AsmDecl * asmDecl ) = 0;
     47        virtual void visit( StaticAssertDecl * node ) { visit( const_cast<const StaticAssertDecl *>(node) ); }
     48        virtual void visit( const StaticAssertDecl * assertDecl ) = 0;
     49
     50        virtual void visit( CompoundStmt * node ) { visit( const_cast<const CompoundStmt *>(node) ); }
     51        virtual void visit( const CompoundStmt * compoundStmt ) = 0;
     52        virtual void visit( ExprStmt * node ) { visit( const_cast<const ExprStmt *>(node) ); }
     53        virtual void visit( const ExprStmt * exprStmt ) = 0;
     54        virtual void visit( AsmStmt * node ) { visit( const_cast<const AsmStmt *>(node) ); }
     55        virtual void visit( const AsmStmt * asmStmt ) = 0;
     56        virtual void visit( DirectiveStmt * node ) { visit( const_cast<const DirectiveStmt *>(node) ); }
     57        virtual void visit( const DirectiveStmt * directiveStmt ) = 0;
     58        virtual void visit( IfStmt * node ) { visit( const_cast<const IfStmt *>(node) ); }
     59        virtual void visit( const IfStmt * ifStmt ) = 0;
     60        virtual void visit( WhileStmt * node ) { visit( const_cast<const WhileStmt *>(node) ); }
     61        virtual void visit( const WhileStmt * whileStmt ) = 0;
     62        virtual void visit( ForStmt * node ) { visit( const_cast<const ForStmt *>(node) ); }
     63        virtual void visit( const ForStmt * forStmt ) = 0;
     64        virtual void visit( SwitchStmt * node ) { visit( const_cast<const SwitchStmt *>(node) ); }
     65        virtual void visit( const SwitchStmt * switchStmt ) = 0;
     66        virtual void visit( CaseStmt * node ) { visit( const_cast<const CaseStmt *>(node) ); }
     67        virtual void visit( const CaseStmt * caseStmt ) = 0;
     68        virtual void visit( BranchStmt * node ) { visit( const_cast<const BranchStmt *>(node) ); }
     69        virtual void visit( const BranchStmt * branchStmt ) = 0;
     70        virtual void visit( ReturnStmt * node ) { visit( const_cast<const ReturnStmt *>(node) ); }
     71        virtual void visit( const ReturnStmt * returnStmt ) = 0;
     72        virtual void visit( ThrowStmt * node ) { visit( const_cast<const ThrowStmt *>(node) ); }
     73        virtual void visit( const ThrowStmt * throwStmt ) = 0;
     74        virtual void visit( TryStmt * node ) { visit( const_cast<const TryStmt *>(node) ); }
     75        virtual void visit( const TryStmt * tryStmt ) = 0;
     76        virtual void visit( CatchStmt * node ) { visit( const_cast<const CatchStmt *>(node) ); }
     77        virtual void visit( const CatchStmt * catchStmt ) = 0;
     78        virtual void visit( FinallyStmt * node ) { visit( const_cast<const FinallyStmt *>(node) ); }
     79        virtual void visit( const FinallyStmt * finallyStmt ) = 0;
     80        virtual void visit( WaitForStmt * node ) { visit( const_cast<const WaitForStmt *>(node) ); }
     81        virtual void visit( const WaitForStmt * waitforStmt ) = 0;
     82        virtual void visit( WithStmt * node ) { visit( const_cast<const WithStmt *>(node) ); }
     83        virtual void visit( const WithStmt * withStmt ) = 0;
     84        virtual void visit( NullStmt * node ) { visit( const_cast<const NullStmt *>(node) ); }
     85        virtual void visit( const NullStmt * nullStmt ) = 0;
     86        virtual void visit( DeclStmt * node ) { visit( const_cast<const DeclStmt *>(node) ); }
     87        virtual void visit( const DeclStmt * declStmt ) = 0;
     88        virtual void visit( ImplicitCtorDtorStmt * node ) { visit( const_cast<const ImplicitCtorDtorStmt *>(node) ); }
     89        virtual void visit( const ImplicitCtorDtorStmt * impCtorDtorStmt ) = 0;
     90
     91        virtual void visit( ApplicationExpr * node ) { visit( const_cast<const ApplicationExpr *>(node) ); }
     92        virtual void visit( const ApplicationExpr * applicationExpr ) = 0;
     93        virtual void visit( UntypedExpr * node ) { visit( const_cast<const UntypedExpr *>(node) ); }
     94        virtual void visit( const UntypedExpr * untypedExpr ) = 0;
     95        virtual void visit( NameExpr * node ) { visit( const_cast<const NameExpr *>(node) ); }
     96        virtual void visit( const NameExpr * nameExpr ) = 0;
     97        virtual void visit( CastExpr * node ) { visit( const_cast<const CastExpr *>(node) ); }
     98        virtual void visit( const CastExpr * castExpr ) = 0;
     99        virtual void visit( KeywordCastExpr * node ) { visit( const_cast<const KeywordCastExpr *>(node) ); }
     100        virtual void visit( const KeywordCastExpr * castExpr ) = 0;
     101        virtual void visit( VirtualCastExpr * node ) { visit( const_cast<const VirtualCastExpr *>(node) ); }
     102        virtual void visit( const VirtualCastExpr * castExpr ) = 0;
     103        virtual void visit( AddressExpr * node ) { visit( const_cast<const AddressExpr *>(node) ); }
     104        virtual void visit( const AddressExpr * addressExpr ) = 0;
     105        virtual void visit( LabelAddressExpr * node ) { visit( const_cast<const LabelAddressExpr *>(node) ); }
     106        virtual void visit( const LabelAddressExpr * labAddressExpr ) = 0;
     107        virtual void visit( UntypedMemberExpr * node ) { visit( const_cast<const UntypedMemberExpr *>(node) ); }
     108        virtual void visit( const UntypedMemberExpr * memberExpr ) = 0;
     109        virtual void visit( MemberExpr * node ) { visit( const_cast<const MemberExpr *>(node) ); }
     110        virtual void visit( const MemberExpr * memberExpr ) = 0;
     111        virtual void visit( VariableExpr * node ) { visit( const_cast<const VariableExpr *>(node) ); }
     112        virtual void visit( const VariableExpr * variableExpr ) = 0;
     113        virtual void visit( ConstantExpr * node ) { visit( const_cast<const ConstantExpr *>(node) ); }
     114        virtual void visit( const ConstantExpr * constantExpr ) = 0;
     115        virtual void visit( SizeofExpr * node ) { visit( const_cast<const SizeofExpr *>(node) ); }
     116        virtual void visit( const SizeofExpr * sizeofExpr ) = 0;
     117        virtual void visit( AlignofExpr * node ) { visit( const_cast<const AlignofExpr *>(node) ); }
     118        virtual void visit( const AlignofExpr * alignofExpr ) = 0;
     119        virtual void visit( UntypedOffsetofExpr * node ) { visit( const_cast<const UntypedOffsetofExpr *>(node) ); }
     120        virtual void visit( const UntypedOffsetofExpr * offsetofExpr ) = 0;
     121        virtual void visit( OffsetofExpr * node ) { visit( const_cast<const OffsetofExpr *>(node) ); }
     122        virtual void visit( const OffsetofExpr * offsetofExpr ) = 0;
     123        virtual void visit( OffsetPackExpr * node ) { visit( const_cast<const OffsetPackExpr *>(node) ); }
     124        virtual void visit( const OffsetPackExpr * offsetPackExpr ) = 0;
     125        virtual void visit( LogicalExpr * node ) { visit( const_cast<const LogicalExpr *>(node) ); }
     126        virtual void visit( const LogicalExpr * logicalExpr ) = 0;
     127        virtual void visit( ConditionalExpr * node ) { visit( const_cast<const ConditionalExpr *>(node) ); }
     128        virtual void visit( const ConditionalExpr * conditionalExpr ) = 0;
     129        virtual void visit( CommaExpr * node ) { visit( const_cast<const CommaExpr *>(node) ); }
     130        virtual void visit( const CommaExpr * commaExpr ) = 0;
     131        virtual void visit( TypeExpr * node ) { visit( const_cast<const TypeExpr *>(node) ); }
     132        virtual void visit( const TypeExpr * typeExpr ) = 0;
     133        virtual void visit( AsmExpr * node ) { visit( const_cast<const AsmExpr *>(node) ); }
     134        virtual void visit( const AsmExpr * asmExpr ) = 0;
     135        virtual void visit( ImplicitCopyCtorExpr * node ) { visit( const_cast<const ImplicitCopyCtorExpr *>(node) ); }
     136        virtual void visit( const ImplicitCopyCtorExpr * impCpCtorExpr ) = 0;
     137        virtual void visit( ConstructorExpr * node ) { visit( const_cast<const ConstructorExpr *>(node) ); }
     138        virtual void visit( const ConstructorExpr *  ctorExpr ) = 0;
     139        virtual void visit( CompoundLiteralExpr * node ) { visit( const_cast<const CompoundLiteralExpr *>(node) ); }
     140        virtual void visit( const CompoundLiteralExpr * compLitExpr ) = 0;
     141        virtual void visit( RangeExpr * node ) { visit( const_cast<const RangeExpr *>(node) ); }
     142        virtual void visit( const RangeExpr * rangeExpr ) = 0;
     143        virtual void visit( UntypedTupleExpr * node ) { visit( const_cast<const UntypedTupleExpr *>(node) ); }
     144        virtual void visit( const UntypedTupleExpr * tupleExpr ) = 0;
     145        virtual void visit( TupleExpr * node ) { visit( const_cast<const TupleExpr *>(node) ); }
     146        virtual void visit( const TupleExpr * tupleExpr ) = 0;
     147        virtual void visit( TupleIndexExpr * node ) { visit( const_cast<const TupleIndexExpr *>(node) ); }
     148        virtual void visit( const TupleIndexExpr * tupleExpr ) = 0;
     149        virtual void visit( TupleAssignExpr * node ) { visit( const_cast<const TupleAssignExpr *>(node) ); }
     150        virtual void visit( const TupleAssignExpr * assignExpr ) = 0;
     151        virtual void visit( StmtExpr * node ) { visit( const_cast<const StmtExpr *>(node) ); }
     152        virtual void visit( const StmtExpr *  stmtExpr ) = 0;
     153        virtual void visit( UniqueExpr * node ) { visit( const_cast<const UniqueExpr *>(node) ); }
     154        virtual void visit( const UniqueExpr *  uniqueExpr ) = 0;
     155        virtual void visit( UntypedInitExpr * node ) { visit( const_cast<const UntypedInitExpr *>(node) ); }
     156        virtual void visit( const UntypedInitExpr *  initExpr ) = 0;
     157        virtual void visit( InitExpr * node ) { visit( const_cast<const InitExpr *>(node) ); }
     158        virtual void visit( const InitExpr *  initExpr ) = 0;
     159        virtual void visit( DeletedExpr * node ) { visit( const_cast<const DeletedExpr *>(node) ); }
     160        virtual void visit( const DeletedExpr * delExpr ) = 0;
     161        virtual void visit( DefaultArgExpr * node ) { visit( const_cast<const DefaultArgExpr *>(node) ); }
     162        virtual void visit( const DefaultArgExpr * argExpr ) = 0;
     163        virtual void visit( GenericExpr * node ) { visit( const_cast<const GenericExpr *>(node) ); }
     164        virtual void visit( const GenericExpr * genExpr ) = 0;
     165
     166        virtual void visit( VoidType * node ) { visit( const_cast<const VoidType *>(node) ); }
     167        virtual void visit( const VoidType * basicType ) = 0;
     168        virtual void visit( BasicType * node ) { visit( const_cast<const BasicType *>(node) ); }
     169        virtual void visit( const BasicType * basicType ) = 0;
     170        virtual void visit( PointerType * node ) { visit( const_cast<const PointerType *>(node) ); }
     171        virtual void visit( const PointerType * pointerType ) = 0;
     172        virtual void visit( ArrayType * node ) { visit( const_cast<const ArrayType *>(node) ); }
     173        virtual void visit( const ArrayType * arrayType ) = 0;
     174        virtual void visit( ReferenceType * node ) { visit( const_cast<const ReferenceType *>(node) ); }
     175        virtual void visit( const ReferenceType * refType ) = 0;
     176        virtual void visit( QualifiedType * node ) { visit( const_cast<const QualifiedType *>(node) ); }
     177        virtual void visit( const QualifiedType * qualType ) = 0;
     178        virtual void visit( FunctionType * node ) { visit( const_cast<const FunctionType *>(node) ); }
     179        virtual void visit( const FunctionType * functionType ) = 0;
     180        virtual void visit( StructInstType * node ) { visit( const_cast<const StructInstType *>(node) ); }
     181        virtual void visit( const StructInstType * aggregateUseType ) = 0;
     182        virtual void visit( UnionInstType * node ) { visit( const_cast<const UnionInstType *>(node) ); }
     183        virtual void visit( const UnionInstType * aggregateUseType ) = 0;
     184        virtual void visit( EnumInstType * node ) { visit( const_cast<const EnumInstType *>(node) ); }
     185        virtual void visit( const EnumInstType * aggregateUseType ) = 0;
     186        virtual void visit( TraitInstType * node ) { visit( const_cast<const TraitInstType *>(node) ); }
     187        virtual void visit( const TraitInstType * aggregateUseType ) = 0;
     188        virtual void visit( TypeInstType * node ) { visit( const_cast<const TypeInstType *>(node) ); }
     189        virtual void visit( const TypeInstType * aggregateUseType ) = 0;
     190        virtual void visit( TupleType * node ) { visit( const_cast<const TupleType *>(node) ); }
     191        virtual void visit( const TupleType * tupleType ) = 0;
     192        virtual void visit( TypeofType * node ) { visit( const_cast<const TypeofType *>(node) ); }
     193        virtual void visit( const TypeofType * typeofType ) = 0;
     194        virtual void visit( AttrType * node ) { visit( const_cast<const AttrType *>(node) ); }
     195        virtual void visit( const AttrType * attrType ) = 0;
     196        virtual void visit( VarArgsType * node ) { visit( const_cast<const VarArgsType *>(node) ); }
     197        virtual void visit( const VarArgsType * varArgsType ) = 0;
     198        virtual void visit( ZeroType * node ) { visit( const_cast<const ZeroType *>(node) ); }
     199        virtual void visit( const ZeroType * zeroType ) = 0;
     200        virtual void visit( OneType * node ) { visit( const_cast<const OneType *>(node) ); }
     201        virtual void visit( const OneType * oneType ) = 0;
     202        virtual void visit( GlobalScopeType * node ) { visit( const_cast<const GlobalScopeType *>(node) ); }
     203        virtual void visit( const GlobalScopeType * globalType ) = 0;
     204
     205        virtual void visit( Designation * node ) { visit( const_cast<const Designation *>(node) ); }
     206        virtual void visit( const Designation * designation ) = 0;
     207        virtual void visit( SingleInit * node ) { visit( const_cast<const SingleInit *>(node) ); }
     208        virtual void visit( const SingleInit * singleInit ) = 0;
     209        virtual void visit( ListInit * node ) { visit( const_cast<const ListInit *>(node) ); }
     210        virtual void visit( const ListInit * listInit ) = 0;
     211        virtual void visit( ConstructorInit * node ) { visit( const_cast<const ConstructorInit *>(node) ); }
     212        virtual void visit( const ConstructorInit * ctorInit ) = 0;
     213
     214        virtual void visit( Constant * node ) { visit( const_cast<const Constant *>(node) ); }
     215        virtual void visit( const Constant * constant ) = 0;
     216
     217        virtual void visit( Attribute * node ) { visit( const_cast<const Attribute *>(node) ); }
     218        virtual void visit( const Attribute * attribute ) = 0;
    127219};
    128220
    129221template< typename TreeType, typename VisitorType >
    130 inline void maybeAccept( TreeType *tree, VisitorType &visitor ) {
     222inline void maybeAccept( TreeType * tree, VisitorType & visitor ) {
    131223        if ( tree ) {
    132224                tree->accept( visitor );
     
    134226}
    135227
     228template< typename TreeType, typename VisitorType >
     229inline void maybeAccept( const TreeType * tree, VisitorType & visitor ) {
     230        if ( tree ) {
     231                tree->accept( visitor );
     232        }
     233}
     234
    136235template< typename Container, typename VisitorType >
    137 inline void acceptAll( Container &container, VisitorType &visitor ) {
     236inline void acceptAll( Container & container, VisitorType & visitor ) {
    138237        SemanticErrorException errors;
    139         for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {
     238        for ( auto * i : container ) {
    140239                try {
    141                         if ( *i ) {
    142                                 (*i)->accept( visitor );
     240                        if ( i ) {
     241                                i->accept( visitor );
     242                        }
     243                } catch( SemanticErrorException & e ) {
     244                        errors.append( e );
     245                }
     246        }
     247        if ( ! errors.isEmpty() ) {
     248                throw errors;
     249        }
     250}
     251
     252template< typename Container, typename VisitorType >
     253inline void acceptAll( const Container & container, VisitorType & visitor ) {
     254        SemanticErrorException errors;
     255        for ( const auto * i : container ) {
     256                try {
     257                        if ( i ) {
     258                                i->accept( visitor );
    143259                        }
    144260                } catch( SemanticErrorException &e ) {
  • src/SynTree/module.mk

    r7951100 rb067d9b  
    1515###############################################################################
    1616
    17 SRC += SynTree/Type.cc \
    18        SynTree/VoidType.cc \
    19        SynTree/BasicType.cc \
    20        SynTree/PointerType.cc \
    21        SynTree/ArrayType.cc \
    22        SynTree/ReferenceType.cc \
    23        SynTree/FunctionType.cc \
    24        SynTree/ReferenceToType.cc \
    25        SynTree/TupleType.cc \
    26        SynTree/TypeofType.cc \
    27        SynTree/AttrType.cc \
    28        SynTree/VarArgsType.cc \
    29        SynTree/ZeroOneType.cc \
    30        SynTree/Constant.cc \
    31        SynTree/Expression.cc \
    32        SynTree/TupleExpr.cc \
    33        SynTree/CommaExpr.cc \
    34        SynTree/TypeExpr.cc \
    35        SynTree/ApplicationExpr.cc \
    36        SynTree/AddressExpr.cc \
    37        SynTree/Statement.cc \
    38        SynTree/CompoundStmt.cc \
    39        SynTree/DeclStmt.cc \
    40        SynTree/Declaration.cc \
    41        SynTree/DeclarationWithType.cc \
    42        SynTree/ObjectDecl.cc \
    43        SynTree/FunctionDecl.cc \
    44        SynTree/AggregateDecl.cc \
    45        SynTree/NamedTypeDecl.cc \
    46        SynTree/TypeDecl.cc \
    47        SynTree/Initializer.cc \
    48        SynTree/TypeSubstitution.cc \
    49        SynTree/Attribute.cc \
    50        SynTree/DeclReplacer.cc
     17SRC_SYNTREE = \
     18      SynTree/Type.cc \
     19      SynTree/VoidType.cc \
     20      SynTree/BasicType.cc \
     21      SynTree/PointerType.cc \
     22      SynTree/ArrayType.cc \
     23      SynTree/ReferenceType.cc \
     24      SynTree/FunctionType.cc \
     25      SynTree/ReferenceToType.cc \
     26      SynTree/TupleType.cc \
     27      SynTree/TypeofType.cc \
     28      SynTree/AttrType.cc \
     29      SynTree/VarArgsType.cc \
     30      SynTree/ZeroOneType.cc \
     31      SynTree/Constant.cc \
     32      SynTree/Expression.cc \
     33      SynTree/TupleExpr.cc \
     34      SynTree/CommaExpr.cc \
     35      SynTree/TypeExpr.cc \
     36      SynTree/ApplicationExpr.cc \
     37      SynTree/AddressExpr.cc \
     38      SynTree/Statement.cc \
     39      SynTree/CompoundStmt.cc \
     40      SynTree/DeclStmt.cc \
     41      SynTree/Declaration.cc \
     42      SynTree/DeclarationWithType.cc \
     43      SynTree/ObjectDecl.cc \
     44      SynTree/FunctionDecl.cc \
     45      SynTree/AggregateDecl.cc \
     46      SynTree/NamedTypeDecl.cc \
     47      SynTree/TypeDecl.cc \
     48      SynTree/Initializer.cc \
     49      SynTree/TypeSubstitution.cc \
     50      SynTree/Attribute.cc \
     51      SynTree/DeclReplacer.cc
    5152
     53SRC += $(SRC_SYNTREE)
     54SRCDEMANGLE += $(SRC_SYNTREE)
Note: See TracChangeset for help on using the changeset viewer.