Changes in / [d908563:933f32f]


Ignore:
Files:
5 deleted
40 edited

Legend:

Unmodified
Added
Removed
  • doc/proposals/vtable.md

    rd908563 r933f32f  
    220220    trait iterator(otype T, otype Item) {
    221221        bool has_next(T const &);
    222         Item get_next(T &);
     222        Item get_next(T const *);
    223223    }
    224224
  • libcfa/src/iostream.cfa

    rd908563 r933f32f  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue May 21 13:01:26 2019
    13 // Update Count     : 674
     12// Last Modified On : Sun May 19 10:48:27 2019
     13// Update Count     : 654
    1414//
    1515
     
    154154        } // ?|?
    155155
    156         #define PrintWithDP( os, format, val, ... ) \
    157                 { \
    158                         enum { size = 48 }; \
    159                         char buf[size]; \
    160                         int len = snprintf( buf, size, format, ##__VA_ARGS__, val ); \
    161                         fmt( os, "%s", buf ); \
    162                         if ( isfinite( val ) ) {                                        /* if number, always print decimal point */ \
    163                                 for ( int i = 0;; i += 1 ) { \
    164                                         if ( i == len ) { fmt( os, "." ); break; } \
    165                                         if ( buf[i] == '.' ) break; \
    166                                 } /* for */ \
    167                         } /* if */ \
    168                 }
     156        static void checkDecPt( ostype & os, const char * buf, int len ) {
     157                for ( int i = 0;; i += 1 ) {
     158                        if ( i == len ) { fmt( os, "." ); break; }
     159                        if ( buf[i] == '.' ) break;
     160                } // for
     161        } // checkDecPt
    169162
    170163        ostype & ?|?( ostype & os, float f ) {
    171164                if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
    172                 PrintWithDP( os, "%g", f );
     165                char buf[48];
     166                int len = snprintf( buf, 48, "%g", f );
     167                fmt( os, "%s", buf );
     168                if ( isfinite( f ) ) checkDecPt( os, buf, len ); // always print decimal point
    173169                return os;
    174170        } // ?|?
     
    179175        ostype & ?|?( ostype & os, double d ) {
    180176                if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
    181                 PrintWithDP( os, "%.*lg", d, DBL_DIG );
     177                char buf[48];
     178                int len = snprintf( buf, 48, "%.*lg", DBL_DIG, d );
     179                fmt( os, "%s", buf );
     180                if ( isfinite( d ) ) checkDecPt( os, buf, len ); // always print decimal point
    182181                return os;
    183182        } // ?|?
     
    188187        ostype & ?|?( ostype & os, long double ld ) {
    189188                if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
    190                 PrintWithDP( os, "%.*Lg", ld, LDBL_DIG );
     189                char buf[48];
     190                int len = snprintf( buf, 48, "%.*Lg", LDBL_DIG, ld );
     191                fmt( os, "%s", buf );
     192                if ( isfinite( ld ) ) checkDecPt( os, buf, len ); // always print decimal point
    191193                return os;
    192194        } // ?|?
     
    199201//              os | crealf( fc ) | nonl;
    200202                float f = crealf( fc );
    201                 PrintWithDP( os, "%g", f );
     203                char buf[48];
     204                int len = snprintf( buf, 48, "%g", f );
     205                fmt( os, "%s", buf );
     206                if ( isfinite( f ) ) checkDecPt( os, buf, len ); // always print decimal point
    202207                f = cimagf( fc );
    203                 PrintWithDP( os, "%+g", f );
     208                len = snprintf( buf, 48, "%+g", f );
     209                fmt( os, "%s", buf );
     210                if ( isfinite( f ) ) checkDecPt( os, buf, len ); // always print decimal point
    204211                fmt( os, "i" );
    205212                return os;
     
    213220//              os | creal( dc ) | nonl;
    214221                double d = creal( dc );
    215                 PrintWithDP( os, "%.*lg", d, DBL_DIG );
     222                char buf[48];
     223                int len = snprintf( buf, 48, "%.*lg", DBL_DIG, d );
     224                fmt( os, "%s", buf );
     225                if ( isfinite( d ) ) checkDecPt( os, buf, len ); // always print decimal point
    216226                d = cimag( dc );
    217                 PrintWithDP( os, "%+.*lg", d, DBL_DIG );
     227                len = snprintf( buf, 48, "%+.*lg", DBL_DIG, d );
     228                fmt( os, "%s", buf );
     229                if ( isfinite( d ) ) checkDecPt( os, buf, len ); // always print decimal point
    218230                fmt( os, "i" );
    219231                return os;
     
    227239//              os | creall( ldc ) || nonl;
    228240                long double ld = creall( ldc );
    229                 PrintWithDP( os, "%.*Lg", ld, LDBL_DIG );
     241                char buf[48];
     242                int len = snprintf( buf, 48, "%.*Lg", LDBL_DIG, ld );
     243                fmt( os, "%s", buf );
     244                if ( isfinite( ld ) ) checkDecPt( os, buf, len ); // always print decimal point
    230245                ld = cimagl( ldc );
    231                 PrintWithDP( os, "%+.*Lg", ld, LDBL_DIG );
     246                len = snprintf( buf, 48, "%+.*Lg", LDBL_DIG, ld );
     247                fmt( os, "%s", buf );
     248                if ( isfinite( ld ) ) checkDecPt( os, buf, len ); // always print decimal point
    232249                fmt( os, "i" );
    233250                return os;
  • src/AST/Attribute.cpp

    rd908563 r933f32f  
    2828        auto end = name.find_last_not_of('_');
    2929        if ( begin == std::string::npos || end == std::string::npos ) return "";
    30 
     30       
    3131        // convert to lowercase
    3232        std::string ret;
  • src/AST/Attribute.hpp

    rd908563 r933f32f  
    3030public:
    3131        std::string name;
    32         std::vector<ptr<Expr>> params;
     32        std::vector<ptr<Expr>> parameters;
    3333
    3434        Attribute( const std::string & name = "", std::vector<ptr<Expr>> && params = {})
    35         : name( name ), params( params ) {}
     35        : name( name ), parameters( params ) {}
    3636        virtual ~Attribute() = default;
    3737
  • src/AST/Bitfield.hpp

    rd908563 r933f32f  
    5757};
    5858
    59 template<typename T>
    60 inline bool operator== ( const bitfield<T> & a, const bitfield<T> & b ) {
    61         return a.val == b.val;
    62 }
    63 
    64 template<typename T>
    65 inline bool operator!= ( const bitfield<T> & a, const bitfield<T> & b ) {
    66         return !(a == b);
    67 }
     59/// Adds default printing operator to a bitfield type.
     60/// Include in definition to add print function, requires other bitfield operators.
     61/// @param N  Number of bits in bitfield
     62#define MakeBitfieldPrint( N ) \
     63        static const char* Names[]; \
     64 \
     65        void print( std::ostream & os ) const { \
     66                if ( (*this).any() ) { \
     67                        for ( unsigned int i = 0; i < N; i += 1 ) { \
     68                                if ( (*this)[i] ) { \
     69                                        os << Names[i] << ' '; \
     70                                } \
     71                        } \
     72                } \
     73        }
    6874
    6975// Local Variables: //
  • src/AST/Convert.cpp

    rd908563 r933f32f  
    1010// Created On       : Thu May 09 15::37::05 2019
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thu May 23 16:59:00 2019
    13 // Update Count     : 6
     12// Last Modified On : Fri May 17 16:01:00 2019
     13// Update Count     : 4
    1414//
    1515
    1616#include "Convert.hpp"
    17 
    18 #include <unordered_map>
    1917
    2018#include "AST/Attribute.hpp"
     
    4442class ConverterNewToOld : public ast::Visitor {
    4543        BaseSyntaxNode * node = nullptr;
    46         using Cache = std::unordered_map< const ast::Node *, BaseSyntaxNode * >;
    47         Cache cache;
    4844
    4945        template<typename T>
     
    5147                ConverterNewToOld & visitor;
    5248
    53                 template<typename U, enum ast::Node::ref_type R>
    54                 T * accept1( const ast::ptr_base<U, R> & ptr ) {
    55                         if ( ! ptr ) return nullptr;
     49                template<typename U>
     50                T * accept1( const ast::ptr<U> & ptr ) {
    5651                        ptr->accept( visitor );
    5752                        T * ret = strict_dynamic_cast< T * >( visitor.node );
     
    9287        }
    9388
    94         /// get new qualifiers from old type
    95         Type::Qualifiers cv( const ast::Type * ty ) { return { ty->qualifiers.val }; }
    96 
    97         /// returns true and sets `node` if in cache
    98         bool inCache( const ast::Node * node ) {
    99                 auto it = cache.find( node );
    100                 if ( it == cache.end() ) return false;
    101                 this->node = it->second;
    102                 return true;
    103         }
    104 
    10589public:
    10690        Declaration * decl( const ast::Decl * declNode ) {
     
    10993
    11094private:
    111         void declPostamble( Declaration * decl, const ast::Decl * node ) {
    112                 decl->location = node->location;
    113                 // name comes from constructor
    114                 // linkage comes from constructor
    115                 decl->extension = node->extension;
    116                 decl->uniqueId = node->uniqueId;
    117                 // storageClasses comes from constructor
    118                 this->node = decl;
    119         }
    120 
    121         const ast::DeclWithType * declWithTypePostamble (
    122                         DeclarationWithType * decl, const ast::DeclWithType * node ) {
    123                 cache.emplace( node, decl );
    124                 decl->mangleName = node->mangleName;
    125                 decl->scopeLevel = node->scopeLevel;
    126                 decl->asmName = get<Expression>().accept1( node->asmName );
    127                 // attributes comes from constructor
    128                 decl->isDeleted = node->isDeleted;
    129                 // fs comes from constructor
    130                 declPostamble( decl, node );
    131                 return nullptr;
    132         }
    133 
    13495        const ast::DeclWithType * visit( const ast::ObjectDecl * node ) override final {
    135                 if ( inCache( node ) ) return nullptr;
    136                 auto decl = new ObjectDecl(
    137                         node->name,
    138                         Type::StorageClasses( node->storage.val ),
    139                         LinkageSpec::Spec( node->linkage.val ),
    140                         get<Expression>().accept1( node->bitfieldWidth ),
    141                         get<Type>().accept1( node->type ),
    142                         get<Initializer>().accept1( node->init ),
    143                         get<Attribute>().acceptL( node->attributes ),
    144                         Type::FuncSpecifiers( node->funcSpec.val )
    145                 );
    146                 return declWithTypePostamble( decl, node );
     96                (void)node;
     97                return nullptr;
    14798        }
    14899
    149100        const ast::DeclWithType * visit( const ast::FunctionDecl * node ) override final {
    150                 if ( inCache( node ) ) return nullptr;
    151                 auto decl = new FunctionDecl(
    152                         node->name,
    153                         Type::StorageClasses( node->storage.val ),
    154                         LinkageSpec::Spec( node->linkage.val ),
    155                         get<FunctionType>().accept1( node->type ),
    156                         get<CompoundStmt>().accept1( node->stmts ),
    157                         get<Attribute>().acceptL( node->attributes ),
    158                         Type::FuncSpecifiers( node->funcSpec.val )
    159                 );
    160                 decl->withExprs = get<Expression>().acceptL( node->withExprs );
    161                 return declWithTypePostamble( decl, node );
    162         }
    163 
    164         const ast::Decl * namedTypePostamble( NamedTypeDecl * decl, const ast::NamedTypeDecl * node ) {
    165                 // base comes from constructor
    166                 decl->parameters = get<TypeDecl>().acceptL( node->params );
    167                 decl->assertions = get<DeclarationWithType>().acceptL( node->assertions );
    168                 declPostamble( decl, node );
     101                (void)node;
     102                return nullptr;
     103        }
     104
     105        const ast::Decl * visit( const ast::StructDecl * node ) override final {
     106                (void)node;
     107                return nullptr;
     108        }
     109
     110        const ast::Decl * visit( const ast::UnionDecl * node ) override final {
     111                (void)node;
     112                return nullptr;
     113        }
     114
     115        const ast::Decl * visit( const ast::EnumDecl * node ) override final {
     116                (void)node;
     117                return nullptr;
     118        }
     119
     120        const ast::Decl * visit( const ast::TraitDecl * node ) override final {
     121                (void)node;
    169122                return nullptr;
    170123        }
    171124
    172125        const ast::Decl * visit( const ast::TypeDecl * node ) override final {
    173                 if ( inCache( node ) ) return nullptr;
    174                 auto decl = new TypeDecl(
    175                         node->name,
    176                         Type::StorageClasses( node->storage.val ),
    177                         get<Type>().accept1( node->base ),
    178                         (TypeDecl::Kind)(unsigned)node->kind,
    179                         node->sized,
    180                         get<Type>().accept1( node->init )
    181                 );
    182                 cache.emplace( node, decl );
    183                 return namedTypePostamble( decl, node );
     126                (void)node;
     127                return nullptr;
    184128        }
    185129
    186130        const ast::Decl * visit( const ast::TypedefDecl * node ) override final {
    187                 auto decl = new TypedefDecl(
    188                         node->name,
    189                         node->location,
    190                         Type::StorageClasses( node->storage.val ),
    191             get<Type>().accept1( node->base ),
    192                         LinkageSpec::Spec( node->linkage.val )
    193                 );
    194                 return namedTypePostamble( decl, node );
    195         }
    196 
    197         const ast::Decl * aggregatePostamble( AggregateDecl * decl, const ast::AggregateDecl * node ) {
    198                 cache.emplace( node, decl );
    199                 decl->members = get<Declaration>().acceptL( node->members );
    200                 decl->parameters = get<TypeDecl>().acceptL( node->params );
    201                 decl->body = node->body;
    202                 // attributes come from constructor
    203                 decl->parent = get<AggregateDecl>().accept1( node->parent );
    204                 declPostamble( decl, node );
    205                 return nullptr;
    206         }
    207 
    208         const ast::Decl * visit( const ast::StructDecl * node ) override final {
    209                 if ( inCache( node ) ) return nullptr;
    210                 auto decl = new StructDecl(
    211                         node->name,
    212                         node->kind,
    213                         get<Attribute>().acceptL( node->attributes ),
    214                         LinkageSpec::Spec( node->linkage.val )
    215                 );
    216                 return aggregatePostamble( decl, node );
    217         }
    218 
    219         const ast::Decl * visit( const ast::UnionDecl * node ) override final {
    220                 if ( inCache( node ) ) return nullptr;
    221                 auto decl = new UnionDecl(
    222                         node->name,
    223                         get<Attribute>().acceptL( node->attributes ),
    224                         LinkageSpec::Spec( node->linkage.val )
    225                 );
    226                 return aggregatePostamble( decl, node );
    227         }
    228 
    229         const ast::Decl * visit( const ast::EnumDecl * node ) override final {
    230                 if ( inCache( node ) ) return nullptr;
    231                 auto decl = new EnumDecl(
    232                         node->name,
    233                         get<Attribute>().acceptL( node->attributes ),
    234                         LinkageSpec::Spec( node->linkage.val )
    235                 );
    236                 return aggregatePostamble( decl, node );
    237         }
    238 
    239         const ast::Decl * visit( const ast::TraitDecl * node ) override final {
    240                 if ( inCache( node ) ) return nullptr;
    241                 auto decl = new TraitDecl(
    242                         node->name,
    243                         {},
    244                         LinkageSpec::Spec( node->linkage.val )
    245                 );
    246                 return aggregatePostamble( decl, node );
     131                (void)node;
     132                return nullptr;
    247133        }
    248134
    249135        const ast::AsmDecl * visit( const ast::AsmDecl * node ) override final {
    250                 auto decl = new AsmDecl( get<AsmStmt>().accept1( node->stmt ) );
    251                 declPostamble( decl, node );
     136                (void)node;
    252137                return nullptr;
    253138        }
    254139
    255140        const ast::StaticAssertDecl * visit( const ast::StaticAssertDecl * node ) override final {
    256                 auto decl = new StaticAssertDecl(
    257                         get<Expression>().accept1( node->cond ),
    258                         get<ConstantExpr>().accept1( node->msg )
    259                 );
    260                 declPostamble( decl, node );
    261                 return nullptr;
    262         }
    263 
    264         const ast::Stmt * stmtPostamble( Statement * stmt, const ast::Stmt * node ) {
    265                 cache.emplace( node, stmt );
    266                 stmt->location = node->location;
    267                 stmt->labels = makeLabelL( stmt, node->labels );
    268                 this->node = stmt;
     141                (void)node;
    269142                return nullptr;
    270143        }
    271144
    272145        const ast::CompoundStmt * visit( const ast::CompoundStmt * node ) override final {
    273                 if ( inCache( node ) ) return nullptr;
    274146                auto stmt = new CompoundStmt( get<Statement>().acceptL( node->kids ) );
    275                 stmtPostamble( stmt, node );
     147                stmt->location = node->location;
     148                stmt->labels = makeLabelL( stmt, node->labels );
     149                this->node = stmt;
    276150                return nullptr;
    277151        }
    278152
    279153        const ast::Stmt * visit( const ast::ExprStmt * node ) override final {
    280                 if ( inCache( node ) ) return nullptr;
    281                 auto stmt = new ExprStmt( nullptr );
    282                 cache.emplace( node, stmt );
    283                 stmt->expr = get<Expression>().accept1( node->expr );
    284                 return stmtPostamble( stmt, node );
     154                auto stmt = new ExprStmt( get<Expression>().accept1( node->expr ) );
     155                stmt->location = node->location;
     156                stmt->labels = makeLabelL( stmt, node->labels );
     157                this->node = stmt;
     158                return nullptr;
    285159        }
    286160
    287161        const ast::Stmt * visit( const ast::AsmStmt * node ) override final {
    288                 if ( inCache( node ) ) return nullptr;
    289162                auto stmt = new AsmStmt(
    290163                        node->isVolatile,
     
    295168                        makeLabelL( nullptr, node->gotoLabels ) // What are these labelling?
    296169                );
    297                 return stmtPostamble( stmt, node );
     170                stmt->location = node->location;
     171                stmt->labels = makeLabelL( stmt, node->labels );
     172                this->node = stmt;
     173                return nullptr;
    298174        }
    299175
    300176        const ast::Stmt * visit( const ast::DirectiveStmt * node ) override final {
    301                 if ( inCache( node ) ) return nullptr;
    302177                auto stmt = new DirectiveStmt( node->directive );
    303                 return stmtPostamble( stmt, node );
     178                stmt->location = node->location;
     179                stmt->labels = makeLabelL( stmt, node->labels );
     180                this->node = stmt;
     181                return nullptr;
    304182        }
    305183
    306184        const ast::Stmt * visit( const ast::IfStmt * node ) override final {
    307                 if ( inCache( node ) ) return nullptr;
    308185                auto stmt = new IfStmt(
    309186                        get<Expression>().accept1( node->cond ),
     
    312189                        get<Statement>().acceptL( node->inits )
    313190                );
    314                 return stmtPostamble( stmt, node );
     191                stmt->location = node->location;
     192                stmt->labels = makeLabelL( stmt, node->labels );
     193                this->node = stmt;
     194                return nullptr;
    315195        }
    316196
    317197        const ast::Stmt * visit( const ast::SwitchStmt * node ) override final {
    318                 if ( inCache( node ) ) return nullptr;
    319198                auto stmt = new SwitchStmt(
    320199                        get<Expression>().accept1( node->cond ),
    321200                        get<Statement>().acceptL( node->stmts )
    322201                );
    323                 return stmtPostamble( stmt, node );
     202                stmt->location = node->location;
     203                stmt->labels = makeLabelL( stmt, node->labels );
     204                this->node = stmt;
     205                return nullptr;
    324206        }
    325207
    326208        const ast::Stmt * visit( const ast::CaseStmt * node ) override final {
    327                 if ( inCache( node ) ) return nullptr;
    328209                auto stmt = new CaseStmt(
    329210                        get<Expression>().accept1( node->cond ),
     
    331212                        node->isDefault()
    332213                );
    333                 return stmtPostamble( stmt, node );
     214                stmt->location = node->location;
     215                stmt->labels = makeLabelL( stmt, node->labels );
     216                this->node = stmt;
     217                return nullptr;
    334218        }
    335219
    336220        const ast::Stmt * visit( const ast::WhileStmt * node ) override final {
    337                 if ( inCache( node ) ) return nullptr;
    338221                auto inits = get<Statement>().acceptL( node->inits );
    339222                auto stmt = new WhileStmt(
     
    343226                        node->isDoWhile
    344227                );
    345                 return stmtPostamble( stmt, node );
     228                stmt->location = node->location;
     229                stmt->labels = makeLabelL( stmt, node->labels );
     230                this->node = stmt;
     231                return nullptr;
    346232        }
    347233
    348234        const ast::Stmt * visit( const ast::ForStmt * node ) override final {
    349                 if ( inCache( node ) ) return nullptr;
    350235                auto stmt = new ForStmt(
    351236                        get<Statement>().acceptL( node->inits ),
     
    354239                        get<Statement>().accept1( node->body )
    355240                );
    356                 return stmtPostamble( stmt, node );
     241                stmt->location = node->location;
     242                stmt->labels = makeLabelL( stmt, node->labels );
     243                this->node = stmt;
     244                return nullptr;
    357245        }
    358246
    359247        const ast::Stmt * visit( const ast::BranchStmt * node ) override final {
    360                 if ( inCache( node ) ) return nullptr;
    361248                BranchStmt * stmt;
    362249                if (node->computedTarget) {
     
    384271                        stmt->target = makeLabel( stmt, node->target );
    385272                }
    386                 return stmtPostamble( stmt, node );
     273                stmt->location = node->location;
     274                stmt->labels = makeLabelL( stmt, node->labels );
     275                this->node = stmt;
     276                return nullptr;
    387277        }
    388278
    389279        const ast::Stmt * visit( const ast::ReturnStmt * node ) override final {
    390                 if ( inCache( node ) ) return nullptr;
    391280                auto stmt = new ReturnStmt( get<Expression>().accept1( node->expr ) );
    392                 return stmtPostamble( stmt, node );
     281                stmt->location = node->location;
     282                stmt->labels = makeLabelL( stmt, node->labels );
     283                this->node = stmt;
     284                return nullptr;
    393285        }
    394286
    395287        const ast::Stmt * visit( const ast::ThrowStmt * node ) override final {
    396                 if ( inCache( node ) ) return nullptr;
    397288                ThrowStmt::Kind kind;
    398289                switch (node->kind) {
     
    411302                        get<Expression>().accept1( node->target )
    412303                );
    413                 return stmtPostamble( stmt, node );
     304                stmt->location = node->location;
     305                stmt->labels = makeLabelL( stmt, node->labels );
     306                this->node = stmt;
     307                return nullptr;
    414308        }
    415309
    416310        const ast::Stmt * visit( const ast::TryStmt * node ) override final {
    417                 if ( inCache( node ) ) return nullptr;
    418311                auto handlers = get<CatchStmt>().acceptL( node->handlers );
    419312                auto stmt = new TryStmt(
     
    422315                        get<FinallyStmt>().accept1( node->finally )
    423316                );
    424                 return stmtPostamble( stmt, node );
     317                stmt->location = node->location;
     318                stmt->labels = makeLabelL( stmt, node->labels );
     319                this->node = stmt;
     320                return nullptr;
    425321        }
    426322
    427323        const ast::Stmt * visit( const ast::CatchStmt * node ) override final {
    428                 if ( inCache( node ) ) return nullptr;
    429324                CatchStmt::Kind kind;
    430325                switch (node->kind) {
     
    444339                        get<Statement>().accept1( node->body )
    445340                );
    446                 return stmtPostamble( stmt, node );
     341                stmt->location = node->location;
     342                stmt->labels = makeLabelL( stmt, node->labels );
     343                this->node = stmt;
     344                return nullptr;
    447345        }
    448346
    449347        const ast::Stmt * visit( const ast::FinallyStmt * node ) override final {
    450                 if ( inCache( node ) ) return nullptr;
    451348                auto stmt = new FinallyStmt( get<CompoundStmt>().accept1( node->body ) );
    452                 return stmtPostamble( stmt, node );
     349                stmt->location = node->location;
     350                stmt->labels = makeLabelL( stmt, node->labels );
     351                this->node = stmt;
     352                return nullptr;
    453353        }
    454354
    455355        const ast::Stmt * visit( const ast::WaitForStmt * node ) override final {
    456                 if ( inCache( node ) ) return nullptr;
    457356                auto stmt = new WaitForStmt;
    458357                stmt->clauses.reserve( node->clauses.size() );
    459358                for ( auto clause : node->clauses ) {
    460359                        stmt->clauses.push_back({{
    461                                         get<Expression>().accept1( clause.target.func ),
    462                                         get<Expression>().acceptL( clause.target.args ),
     360                                        get<Expression>().accept1( clause.target.function ),
     361                                        get<Expression>().acceptL( clause.target.arguments ),
    463362                                },
    464363                                get<Statement>().accept1( clause.stmt ),
     
    475374                        get<Expression>().accept1( node->orElse.cond ),
    476375                };
    477                 return stmtPostamble( stmt, node );
     376                stmt->location = node->location;
     377                stmt->labels = makeLabelL( stmt, node->labels );
     378                this->node = stmt;
     379                return nullptr;
    478380        }
    479381
    480382        const ast::Stmt * visit( const ast::WithStmt * node ) override final {
    481                 if ( inCache( node ) ) return nullptr;
    482383                auto stmt = new WithStmt(
    483384                        get<Expression>().acceptL( node->exprs ),
    484385                        get<Statement>().accept1( node->stmt )
    485386                );
    486                 return stmtPostamble( stmt, node );
     387                stmt->location = node->location;
     388                stmt->labels = makeLabelL( stmt, node->labels );
     389                this->node = stmt;
     390                return nullptr;
    487391        }
    488392
    489393        const ast::NullStmt * visit( const ast::NullStmt * node ) override final {
    490                 if ( inCache( node ) ) return nullptr;
    491394                auto stmt = new NullStmt();
    492                 stmtPostamble( stmt, node );
     395                stmt->location = node->location;
     396                stmt->labels = makeLabelL( stmt, node->labels );
     397                this->node = stmt;
    493398                return nullptr;
    494399        }
    495400
    496401        const ast::Stmt * visit( const ast::DeclStmt * node ) override final {
    497                 if ( inCache( node ) ) return nullptr;
    498402                auto stmt = new DeclStmt( get<Declaration>().accept1( node->decl ) );
    499                 return stmtPostamble( stmt, node );
     403                stmt->location = node->location;
     404                stmt->labels = makeLabelL( stmt, node->labels );
     405                this->node = stmt;
     406                return nullptr;
    500407        }
    501408
    502409        const ast::Stmt * visit( const ast::ImplicitCtorDtorStmt * node ) override final {
    503                 if ( inCache( node ) ) return nullptr;
    504                 auto stmt = new ImplicitCtorDtorStmt{
    505                         get<Statement>().accept1( node->callStmt )
    506                 };
    507                 return stmtPostamble( stmt, node );
    508         }
    509 
    510         TypeSubstitution * convertTypeSubstitution(const ast::TypeSubstitution * src) {
    511 
    512                 if (!src) return nullptr;
    513 
    514                 TypeSubstitution *rslt = new TypeSubstitution();
    515 
    516                 for (decltype(src->begin()) src_i = src->begin(); src_i != src->end(); src_i++) {
    517                         rslt->add( src_i->first,
    518                                    get<Type>().accept1(src_i->second) );
    519                 }
    520 
    521                 for (decltype(src->beginVar()) src_i = src->beginVar(); src_i != src->endVar(); src_i++) {
    522                         rslt->addVar( src_i->first,
    523                                       get<Expression>().accept1(src_i->second) );
    524                 }
    525 
    526                 return rslt;
    527         }
    528 
    529         void convertInferUnion(std::map<UniqueId,ParamEntry> &tgtInferParams,
    530                                                    std::vector<UniqueId>         &tgtResnSlots,
    531                                                    const ast::Expr::InferUnion   &srcInferred ) {
    532 
    533                 assert( tgtInferParams.empty() );
    534                 assert( tgtResnSlots.empty() );
    535 
    536                 if ( srcInferred.mode == ast::Expr::InferUnion::Params ) {
    537                         const ast::InferredParams &srcParams = srcInferred.inferParamsConst();
    538                         for (auto srcParam : srcParams) {
    539                                 tgtInferParams[srcParam.first] = ParamEntry(
    540                                         srcParam.second.decl,
    541                                         get<Type>().accept1(srcParam.second.actualType),
    542                                         get<Type>().accept1(srcParam.second.formalType),
    543                                         get<Expression>().accept1(srcParam.second.expr)
    544                                 );
    545                         }
    546                 } else if ( srcInferred.mode == ast::Expr::InferUnion::Slots  ) {
    547                         const ast::ResnSlots &srcSlots = srcInferred.resnSlotsConst();
    548                         for (auto srcSlot : srcSlots) {
    549                                 tgtResnSlots.push_back(srcSlot);
    550                         }
    551                 }
    552         }
    553 
    554         Expression * visitBaseExpr_skipResultType(const ast::Expr * src, Expression * tgt) {
    555 
    556                 tgt->location  = src->location;
    557                 tgt->env       = convertTypeSubstitution(src->env);
    558                 tgt->extension = src->extension;
    559 
    560                 convertInferUnion(tgt->inferParams, tgt->resnSlots, src->inferred);
    561                 return tgt;
    562         }
    563 
    564         Expression * visitBaseExpr(const ast::Expr * src, Expression * tgt) {
    565 
    566                 tgt->result = get<Type>().accept1(src->result);
    567                 return visitBaseExpr_skipResultType(src, tgt);
     410                (void)node;
     411                return nullptr;
    568412        }
    569413
    570414        const ast::Expr * visit( const ast::ApplicationExpr * node ) override final {
    571                 auto expr = visitBaseExpr( node,
    572                         new ApplicationExpr(
    573                                 get<Expression>().accept1(node->func),
    574                                 get<Expression>().acceptL(node->args)
    575                         )
    576                 );
    577                 this->node = expr;
     415                (void)node;
    578416                return nullptr;
    579417        }
    580418
    581419        const ast::Expr * visit( const ast::UntypedExpr * node ) override final {
    582                 auto expr = visitBaseExpr( node,
    583                         new UntypedExpr(
    584                                 get<Expression>().accept1(node->func),
    585                                 get<Expression>().acceptL(node->args)
    586                         )
    587                 );
    588                 this->node = expr;
     420                (void)node;
    589421                return nullptr;
    590422        }
    591423
    592424        const ast::Expr * visit( const ast::NameExpr * node ) override final {
    593                 auto expr = visitBaseExpr( node,
    594                         new NameExpr(
    595                                 node->name
    596                         )
    597                 );
    598                 this->node = expr;
     425                (void)node;
    599426                return nullptr;
    600427        }
    601428
    602429        const ast::Expr * visit( const ast::AddressExpr * node ) override final {
    603                 auto expr = visitBaseExpr( node,
    604                         new AddressExpr(
    605                                 get<Expression>().accept1(node->arg)
    606                         )
    607                 );
    608                 this->node = expr;
     430                (void)node;
    609431                return nullptr;
    610432        }
    611433
    612434        const ast::Expr * visit( const ast::LabelAddressExpr * node ) override final {
    613                 auto expr = visitBaseExpr( node,
    614                         new LabelAddressExpr(
    615                                 makeLabel(nullptr, node->arg)
    616                         )
    617                 );
    618                 this->node = expr;
     435                (void)node;
    619436                return nullptr;
    620437        }
    621438
    622439        const ast::Expr * visit( const ast::CastExpr * node ) override final {
    623                 auto expr = visitBaseExpr( node,
    624                         new CastExpr(
    625                                 get<Expression>().accept1(node->arg),
    626                                 (node->isGenerated == ast::GeneratedCast)
    627                         )
    628                 );
    629                 this->node = expr;
     440                (void)node;
    630441                return nullptr;
    631442        }
    632443
    633444        const ast::Expr * visit( const ast::KeywordCastExpr * node ) override final {
    634                 KeywordCastExpr::Target castTarget = KeywordCastExpr::NUMBER_OF_TARGETS;
    635                 switch (node->target) {
    636                         case ast::KeywordCastExpr::Coroutine:
    637                                 castTarget = KeywordCastExpr::Coroutine;
    638                                 break;
    639                         case ast::KeywordCastExpr::Thread:
    640                                 castTarget = KeywordCastExpr::Thread;
    641                                 break;
    642                         case ast::KeywordCastExpr::Monitor:
    643                                 castTarget = KeywordCastExpr::Monitor;
    644                                 break;
    645                         default:
    646                                 break;
    647                 }
    648                 assert ( castTarget < KeywordCastExpr::NUMBER_OF_TARGETS );
    649                 auto expr = visitBaseExpr( node,
    650                         new KeywordCastExpr(
    651                                 get<Expression>().accept1(node->arg),
    652                                 castTarget
    653                         )
    654                 );
    655                 this->node = expr;
     445                (void)node;
    656446                return nullptr;
    657447        }
    658448
    659449        const ast::Expr * visit( const ast::VirtualCastExpr * node ) override final {
    660                 auto expr = visitBaseExpr_skipResultType( node,
    661                         new VirtualCastExpr(
    662                                 get<Expression>().accept1(node->arg),
    663                                 get<Type>().accept1(node->result)
    664                         )
    665                 );
    666                 this->node = expr;
     450                (void)node;
    667451                return nullptr;
    668452        }
    669453
    670454        const ast::Expr * visit( const ast::UntypedMemberExpr * node ) override final {
    671                 auto expr = visitBaseExpr( node,
    672                         new UntypedMemberExpr(
    673                                 get<Expression>().accept1(node->member),
    674                                 get<Expression>().accept1(node->aggregate)
    675                         )
    676                 );
    677                 this->node = expr;
     455                (void)node;
    678456                return nullptr;
    679457        }
    680458
    681459        const ast::Expr * visit( const ast::MemberExpr * node ) override final {
    682                 auto expr = visitBaseExpr( node,
    683                         new MemberExpr(
    684                                 inCache(node->member) ?
    685                                         dynamic_cast<DeclarationWithType *>(this->node) :
    686                                         get<DeclarationWithType>().accept1(node->member),
    687                                 get<Expression>().accept1(node->aggregate)
    688                         )
    689                 );
    690                 this->node = expr;
     460                (void)node;
    691461                return nullptr;
    692462        }
    693463
    694464        const ast::Expr * visit( const ast::VariableExpr * node ) override final {
    695                 auto expr = visitBaseExpr( node,
    696                         new VariableExpr(
    697                                 inCache(node->var) ?
    698                                         dynamic_cast<DeclarationWithType *>(this->node) :
    699                                         get<DeclarationWithType>().accept1(node->var)
    700                         )
    701                 );
    702                 this->node = expr;
     465                (void)node;
    703466                return nullptr;
    704467        }
    705468
    706469        const ast::Expr * visit( const ast::ConstantExpr * node ) override final {
    707                 ConstantExpr *rslt = nullptr;
    708                 switch ( node->kind ) {
    709                 case ast::ConstantExpr::Integer:
    710                         rslt = new ConstantExpr{Constant{
    711                                 get<Type>().accept1( node->result ),
    712                                 node->rep,
    713                                 (unsigned long long) node->intValue()
    714                         }};
    715                         break;
    716                 case ast::ConstantExpr::FloatingPoint:
    717                         rslt = new ConstantExpr{Constant{
    718                                 get<Type>().accept1(node->result),
    719                                 node->rep,
    720                                 (double) node->floatValue()
    721                         }};
    722                         break;
    723                 case ast::ConstantExpr::String:
    724                         rslt = new ConstantExpr{Constant::from_string( node->rep )};
    725                         break;
    726                 }
    727                 assert(rslt);
    728                 auto expr = visitBaseExpr( node, rslt );
    729                 this->node = expr;
     470                (void)node;
    730471                return nullptr;
    731472        }
    732473
    733474        const ast::Expr * visit( const ast::SizeofExpr * node ) override final {
    734                 assert (node->expr || node->type);
    735                 assert (! (node->expr && node->type));
    736                 SizeofExpr *rslt;
    737                 if (node->expr) {
    738                         rslt = new SizeofExpr(
    739                                 get<Expression>().accept1(node->expr)
    740                         );
    741                         assert (!rslt->isType);
    742                 }
    743                 if (node->type) {
    744                         rslt = new SizeofExpr(
    745                                 get<Type>().accept1(node->type)
    746                         );
    747                         assert (rslt->isType);
    748                 }
    749                 auto expr = visitBaseExpr( node, rslt );
    750                 this->node = expr;
     475                (void)node;
    751476                return nullptr;
    752477        }
    753478
    754479        const ast::Expr * visit( const ast::AlignofExpr * node ) override final {
    755                 assert (node->expr || node->type);
    756                 assert (! (node->expr && node->type));
    757                 AlignofExpr *rslt;
    758                 if (node->expr) {
    759                         rslt = new AlignofExpr(
    760                                 get<Expression>().accept1(node->expr)
    761                         );
    762                         assert (!rslt->isType);
    763                 }
    764                 if (node->type) {
    765                         rslt = new AlignofExpr(
    766                                 get<Type>().accept1(node->type)
    767                         );
    768                         assert (rslt->isType);
    769                 }
    770                 auto expr = visitBaseExpr( node, rslt );
    771                 this->node = expr;
     480                (void)node;
    772481                return nullptr;
    773482        }
    774483
    775484        const ast::Expr * visit( const ast::UntypedOffsetofExpr * node ) override final {
    776                 auto expr = visitBaseExpr( node,
    777                         new UntypedOffsetofExpr(
    778                                 get<Type>().accept1(node->type),
    779                                 node->member
    780                         )
    781                 );
    782                 this->node = expr;
     485                (void)node;
    783486                return nullptr;
    784487        }
    785488
    786489        const ast::Expr * visit( const ast::OffsetofExpr * node ) override final {
    787                 auto expr = visitBaseExpr( node,
    788                         new OffsetofExpr(
    789                                 get<Type>().accept1(node->type),
    790                                 inCache(node->member) ?
    791                                         dynamic_cast<DeclarationWithType *>(this->node) :
    792                                         get<DeclarationWithType>().accept1(node->member)
    793                         )
    794                 );
    795                 this->node = expr;
     490                (void)node;
    796491                return nullptr;
    797492        }
    798493
    799494        const ast::Expr * visit( const ast::OffsetPackExpr * node ) override final {
    800                 auto expr = visitBaseExpr( node,
    801                         new OffsetPackExpr(
    802                                 get<StructInstType>().accept1(node->type)
    803                         )
    804                 );
    805                 this->node = expr;
     495                (void)node;
    806496                return nullptr;
    807497        }
    808498
    809499        const ast::Expr * visit( const ast::LogicalExpr * node ) override final {
    810                 assert (node->isAnd == ast::LogicalFlag::AndExpr ||
    811                                 node->isAnd == ast::LogicalFlag::OrExpr );
    812                 auto expr = visitBaseExpr( node,
    813                         new LogicalExpr(
    814                                 get<Expression>().accept1(node->arg1),
    815                                 get<Expression>().accept1(node->arg2),
    816                                 (node->isAnd == ast::LogicalFlag::AndExpr)
    817                         )
    818                 );
    819                 this->node = expr;
     500                (void)node;
    820501                return nullptr;
    821502        }
    822503
    823504        const ast::Expr * visit( const ast::ConditionalExpr * node ) override final {
    824                 auto expr = visitBaseExpr( node,
    825                         new ConditionalExpr(
    826                                 get<Expression>().accept1(node->arg1),
    827                                 get<Expression>().accept1(node->arg2),
    828                                 get<Expression>().accept1(node->arg3)
    829                         )
    830                 );
    831                 this->node = expr;
     505                (void)node;
    832506                return nullptr;
    833507        }
    834508
    835509        const ast::Expr * visit( const ast::CommaExpr * node ) override final {
    836                 auto expr = visitBaseExpr( node,
    837                         new CommaExpr(
    838                                 get<Expression>().accept1(node->arg1),
    839                                 get<Expression>().accept1(node->arg2)
    840                         )
    841                 );
    842                 this->node = expr;
     510                (void)node;
    843511                return nullptr;
    844512        }
    845513
    846514        const ast::Expr * visit( const ast::TypeExpr * node ) override final {
    847                 auto expr = visitBaseExpr( node,
    848                         new TypeExpr(
    849                                 get<Type>().accept1(node->type)
    850                         )
    851                 );
    852                 this->node = expr;
     515                (void)node;
    853516                return nullptr;
    854517        }
    855518
    856519        const ast::Expr * visit( const ast::AsmExpr * node ) override final {
    857                 auto expr = visitBaseExpr( node,
    858                         new AsmExpr(
    859                                 get<Expression>().accept1(node->inout),
    860                                 get<Expression>().accept1(node->constraint),
    861                                 get<Expression>().accept1(node->operand)
    862                         )
    863                 );
    864                 this->node = expr;
     520                (void)node;
    865521                return nullptr;
    866522        }
    867523
    868524        const ast::Expr * visit( const ast::ImplicitCopyCtorExpr * node ) override final {
    869                 auto rslt = new ImplicitCopyCtorExpr(
    870                         get<ApplicationExpr>().accept1(node->callExpr)
    871                 );
    872 
    873                 auto expr = visitBaseExpr( node, rslt );
    874                 this->node = expr;
     525                (void)node;
    875526                return nullptr;
    876527        }
    877528
    878529        const ast::Expr * visit( const ast::ConstructorExpr * node ) override final {
    879                 auto expr = visitBaseExpr( node,
    880                         new ConstructorExpr(
    881                                 get<Expression>().accept1(node->callExpr)
    882                         )
    883                 );
    884                 this->node = expr;
     530                (void)node;
    885531                return nullptr;
    886532        }
    887533
    888534        const ast::Expr * visit( const ast::CompoundLiteralExpr * node ) override final {
    889                 auto expr = visitBaseExpr_skipResultType( node,
    890                         new CompoundLiteralExpr(
    891                                 get<Type>().accept1(node->result),
    892                                 get<Initializer>().accept1(node->init)
    893                         )
    894                 );
    895                 this->node = expr;
     535                (void)node;
    896536                return nullptr;
    897537        }
    898538
    899539        const ast::Expr * visit( const ast::RangeExpr * node ) override final {
    900                 auto expr = visitBaseExpr( node,
    901                         new RangeExpr(
    902                                 get<Expression>().accept1(node->low),
    903                                 get<Expression>().accept1(node->high)
    904                         )
    905                 );
    906                 this->node = expr;
     540                (void)node;
    907541                return nullptr;
    908542        }
    909543
    910544        const ast::Expr * visit( const ast::UntypedTupleExpr * node ) override final {
    911                 auto expr = visitBaseExpr( node,
    912                         new UntypedTupleExpr(
    913                                 get<Expression>().acceptL(node->exprs)
    914                         )
    915                 );
    916                 this->node = expr;
     545                (void)node;
    917546                return nullptr;
    918547        }
    919548
    920549        const ast::Expr * visit( const ast::TupleExpr * node ) override final {
    921                 auto expr = visitBaseExpr( node,
    922                         new UntypedTupleExpr(
    923                                 get<Expression>().acceptL(node->exprs)
    924                         )
    925                 );
    926                 this->node = expr;
     550                (void)node;
    927551                return nullptr;
    928552        }
    929553
    930554        const ast::Expr * visit( const ast::TupleIndexExpr * node ) override final {
    931                 auto expr = visitBaseExpr( node,
    932                         new TupleIndexExpr(
    933                                 get<Expression>().accept1(node->tuple),
    934                                 node->index
    935                         )
    936                 );
    937                 this->node = expr;
     555                (void)node;
    938556                return nullptr;
    939557        }
    940558
    941559        const ast::Expr * visit( const ast::TupleAssignExpr * node ) override final {
    942                 auto expr = visitBaseExpr( node,
    943                         new TupleAssignExpr(
    944                                 get<StmtExpr>().accept1(node->stmtExpr)
    945                         )
    946                 );
    947                 this->node = expr;
     560                (void)node;
    948561                return nullptr;
    949562        }
    950563
    951564        const ast::Expr * visit( const ast::StmtExpr * node ) override final {
    952                 auto rslt = new StmtExpr(
    953                         get<CompoundStmt>().accept1(node->stmts)
    954                 );
    955 
    956                 rslt->returnDecls = get<ObjectDecl>().acceptL(node->returnDecls);
    957                 rslt->dtors       = get<Expression>().acceptL(node->dtors);
    958 
    959                 auto expr = visitBaseExpr( node, rslt );
    960                 this->node = expr;
     565                (void)node;
    961566                return nullptr;
    962567        }
    963568
    964569        const ast::Expr * visit( const ast::UniqueExpr * node ) override final {
    965                 auto rslt = new UniqueExpr(
    966                         get<Expression>().accept1(node->expr)
    967                 );
    968 
    969                 rslt->object = get<ObjectDecl>  ().accept1(node->object);
    970                 rslt->var    = get<VariableExpr>().accept1(node->var);
    971 
    972                 auto expr = visitBaseExpr( node, rslt );
    973                 this->node = expr;
     570                (void)node;
    974571                return nullptr;
    975572        }
    976573
    977574        const ast::Expr * visit( const ast::UntypedInitExpr * node ) override final {
    978                 std::list<InitAlternative> initAlts;
    979                 for (auto ia : node->initAlts) {
    980                         initAlts.push_back(InitAlternative(
    981                                 get<Type>       ().accept1(ia.type),
    982                                 get<Designation>().accept1(ia.designation)
    983                         ));
    984                 }
    985                 auto expr = visitBaseExpr( node,
    986                         new UntypedInitExpr(
    987                                 get<Expression>().accept1(node->expr),
    988                                 initAlts
    989                         )
    990                 );
    991                 this->node = expr;
     575                (void)node;
    992576                return nullptr;
    993577        }
    994578
    995579        const ast::Expr * visit( const ast::InitExpr * node ) override final {
    996                 auto expr = visitBaseExpr( node,
    997                         new InitExpr(
    998                                 get<Expression>().accept1(node->expr),
    999                                 get<Designation>().accept1(node->designation)
    1000                         )
    1001                 );
    1002                 this->node = expr;
     580                (void)node;
    1003581                return nullptr;
    1004582        }
    1005583
    1006584        const ast::Expr * visit( const ast::DeletedExpr * node ) override final {
    1007                 auto expr = visitBaseExpr( node,
    1008                         new DeletedExpr(
    1009                                 get<Expression>().accept1(node->expr),
    1010                                 inCache(node->deleteStmt) ?
    1011                                         this->node :
    1012                                         get<BaseSyntaxNode>().accept1(node->deleteStmt)
    1013                         )
    1014                 );
    1015                 this->node = expr;
     585                (void)node;
    1016586                return nullptr;
    1017587        }
    1018588
    1019589        const ast::Expr * visit( const ast::DefaultArgExpr * node ) override final {
    1020                 auto expr = visitBaseExpr( node,
    1021                         new DefaultArgExpr(
    1022                                 get<Expression>().accept1(node->expr)
    1023                         )
    1024                 );
    1025                 this->node = expr;
     590                (void)node;
    1026591                return nullptr;
    1027592        }
    1028593
    1029594        const ast::Expr * visit( const ast::GenericExpr * node ) override final {
    1030                 std::list<GenericExpr::Association> associations;
    1031                 for (auto association : node->associations) {
    1032                         associations.push_back(GenericExpr::Association(
    1033                                 get<Type>      ().accept1(association.type),
    1034                                 get<Expression>().accept1(association.expr)
    1035                         ));
    1036                 }
    1037                 auto expr = visitBaseExpr( node,
    1038                         new GenericExpr(
    1039                                 get<Expression>().accept1(node->control),
    1040                                 associations
    1041                         )
    1042                 );
    1043                 this->node = expr;
     595                (void)node;
    1044596                return nullptr;
    1045597        }
    1046598
    1047599        const ast::Type * visit( const ast::VoidType * node ) override final {
    1048                 this->node = new VoidType{ cv( node ) };
     600                (void)node;
    1049601                return nullptr;
    1050602        }
    1051603
    1052604        const ast::Type * visit( const ast::BasicType * node ) override final {
    1053                 this->node = new BasicType{ cv( node ), (BasicType::Kind)(unsigned)node->kind };
     605                (void)node;
    1054606                return nullptr;
    1055607        }
    1056608
    1057609        const ast::Type * visit( const ast::PointerType * node ) override final {
    1058                 this->node = new PointerType{
    1059                         cv( node ),
    1060                         get<Type>().accept1( node->base ),
    1061                         get<Expression>().accept1( node->dimension ),
    1062                         (bool)node->isVarLen,
    1063                         (bool)node->isStatic
    1064                 };
     610                (void)node;
    1065611                return nullptr;
    1066612        }
    1067613
    1068614        const ast::Type * visit( const ast::ArrayType * node ) override final {
    1069                 this->node = new ArrayType{
    1070                         cv( node ),
    1071                         get<Type>().accept1( node->base ),
    1072                         get<Expression>().accept1( node->dimension ),
    1073                         (bool)node->isVarLen,
    1074                         (bool)node->isStatic
    1075                 };
     615                (void)node;
    1076616                return nullptr;
    1077617        }
    1078618
    1079619        const ast::Type * visit( const ast::ReferenceType * node ) override final {
    1080                 this->node = new ReferenceType{
    1081                         cv( node ),
    1082                         get<Type>().accept1( node->base )
    1083                 };
     620                (void)node;
    1084621                return nullptr;
    1085622        }
    1086623
    1087624        const ast::Type * visit( const ast::QualifiedType * node ) override final {
    1088                 this->node = new QualifiedType{
    1089                         cv( node ),
    1090                         get<Type>().accept1( node->parent ),
    1091                         get<Type>().accept1( node->child )
    1092                 };
     625                (void)node;
    1093626                return nullptr;
    1094627        }
    1095628
    1096629        const ast::Type * visit( const ast::FunctionType * node ) override final {
    1097                 auto ty = new FunctionType {
    1098                         cv( node ),
    1099                         (bool)node->isVarArgs
    1100                 };
    1101                 ty->returnVals = get<DeclarationWithType>().acceptL( node->returns );
    1102                 ty->parameters = get<DeclarationWithType>().acceptL( node->params );
    1103                 ty->forall = get<TypeDecl>().acceptL( node->forall );
    1104                 this->node = ty;
    1105                 return nullptr;
    1106         }
    1107 
    1108         void postvisit( const ast::ReferenceToType * old, ReferenceToType * ty ) {
    1109                 ty->forall = get<TypeDecl>().acceptL( old->forall );
    1110                 ty->parameters = get<Expression>().acceptL( old->params );
    1111                 ty->hoistType = old->hoistType;
     630                (void)node;
     631                return nullptr;
    1112632        }
    1113633
    1114634        const ast::Type * visit( const ast::StructInstType * node ) override final {
    1115                 StructInstType * ty;
    1116                 if ( node->base ) {
    1117                         ty = new StructInstType{
    1118                                 cv( node ),
    1119                                 get<StructDecl>().accept1( node->base ),
    1120                                 get<Attribute>().acceptL( node->attributes )
    1121                         };
    1122                 } else {
    1123                         ty = new StructInstType{
    1124                                 cv( node ),
    1125                                 node->name,
    1126                                 get<Attribute>().acceptL( node->attributes )
    1127                         };
    1128                 }
    1129                 postvisit( node, ty );
    1130                 this->node = ty;
     635                (void)node;
    1131636                return nullptr;
    1132637        }
    1133638
    1134639        const ast::Type * visit( const ast::UnionInstType * node ) override final {
    1135                 UnionInstType * ty;
    1136                 if ( node->base ) {
    1137                         ty = new UnionInstType{
    1138                                 cv( node ),
    1139                                 get<UnionDecl>().accept1( node->base ),
    1140                                 get<Attribute>().acceptL( node->attributes )
    1141                         };
    1142                 } else {
    1143                         ty = new UnionInstType{
    1144                                 cv( node ),
    1145                                 node->name,
    1146                                 get<Attribute>().acceptL( node->attributes )
    1147                         };
    1148                 }
    1149                 postvisit( node, ty );
    1150                 this->node = ty;
     640                (void)node;
    1151641                return nullptr;
    1152642        }
    1153643
    1154644        const ast::Type * visit( const ast::EnumInstType * node ) override final {
    1155                 EnumInstType * ty;
    1156                 if ( node->base ) {
    1157                         ty = new EnumInstType{
    1158                                 cv( node ),
    1159                                 get<EnumDecl>().accept1( node->base ),
    1160                                 get<Attribute>().acceptL( node->attributes )
    1161                         };
    1162                 } else {
    1163                         ty = new EnumInstType{
    1164                                 cv( node ),
    1165                                 node->name,
    1166                                 get<Attribute>().acceptL( node->attributes )
    1167                         };
    1168                 }
    1169                 postvisit( node, ty );
    1170                 this->node = ty;
     645                (void)node;
    1171646                return nullptr;
    1172647        }
    1173648
    1174649        const ast::Type * visit( const ast::TraitInstType * node ) override final {
    1175                 TraitInstType * ty;
    1176                 if ( node->base ) {
    1177                         ty = new TraitInstType{
    1178                                 cv( node ),
    1179                                 get<TraitDecl>().accept1( node->base ),
    1180                                 get<Attribute>().acceptL( node->attributes )
    1181                         };
    1182                 } else {
    1183                         ty = new TraitInstType{
    1184                                 cv( node ),
    1185                                 node->name,
    1186                                 get<Attribute>().acceptL( node->attributes )
    1187                         };
    1188                 }
    1189                 postvisit( node, ty );
    1190                 this->node = ty;
     650                (void)node;
    1191651                return nullptr;
    1192652        }
    1193653
    1194654        const ast::Type * visit( const ast::TypeInstType * node ) override final {
    1195                 TypeInstType * ty;
    1196                 if ( node->base ) {
    1197                         ty = new TypeInstType{
    1198                                 cv( node ),
    1199                                 node->name,
    1200                                 get<TypeDecl>().accept1( node->base ),
    1201                                 get<Attribute>().acceptL( node->attributes )
    1202                         };
    1203                 } else {
    1204                         ty = new TypeInstType{
    1205                                 cv( node ),
    1206                                 node->name,
    1207                                 node->kind == ast::TypeVar::Ftype,
    1208                                 get<Attribute>().acceptL( node->attributes )
    1209                         };
    1210                 }
    1211                 postvisit( node, ty );
    1212                 this->node = ty;
     655                (void)node;
    1213656                return nullptr;
    1214657        }
    1215658
    1216659        const ast::Type * visit( const ast::TupleType * node ) override final {
    1217                 this->node = new TupleType{
    1218                         cv( node ),
    1219                         get<Type>().acceptL( node->types )
    1220                         // members generated by TupleType c'tor
    1221                 };
     660                (void)node;
    1222661                return nullptr;
    1223662        }
    1224663
    1225664        const ast::Type * visit( const ast::TypeofType * node ) override final {
    1226                 this->node = new TypeofType{
    1227                         cv( node ),
    1228                         get<Expression>().accept1( node->expr ),
    1229                         (bool)node->kind
    1230                 };
     665                (void)node;
    1231666                return nullptr;
    1232667        }
    1233668
    1234669        const ast::Type * visit( const ast::VarArgsType * node ) override final {
    1235                 this->node = new VarArgsType{ cv( node ) };
     670                (void)node;
    1236671                return nullptr;
    1237672        }
    1238673
    1239674        const ast::Type * visit( const ast::ZeroType * node ) override final {
    1240                 this->node = new ZeroType{ cv( node ) };
     675                (void)node;
    1241676                return nullptr;
    1242677        }
    1243678
    1244679        const ast::Type * visit( const ast::OneType * node ) override final {
    1245                 this->node = new OneType{ cv( node ) };
    1246                 return nullptr;
    1247         }
    1248 
    1249         const ast::Type * visit( const ast::GlobalScopeType * ) override final {
    1250                 this->node = new GlobalScopeType{};
     680                (void)node;
     681                return nullptr;
     682        }
     683
     684        const ast::Type * visit( const ast::GlobalScopeType * node ) override final {
     685                (void)node;
    1251686                return nullptr;
    1252687        }
    1253688
    1254689        const ast::Designation * visit( const ast::Designation * node ) override final {
    1255                 auto designation = new Designation( get<Expression>().acceptL( node->designators ) );
    1256                 designation->location = node->location;
    1257                 this->node = designation;
     690                (void)node;
    1258691                return nullptr;
    1259692        }
    1260693
    1261694        const ast::Init * visit( const ast::SingleInit * node ) override final {
    1262                 auto init = new SingleInit(
    1263                         get<Expression>().accept1( node->value ),
    1264                         ast::MaybeConstruct == node->maybeConstructed
    1265                 );
    1266                 init->location = node->location;
    1267                 this->node = init;
     695                (void)node;
    1268696                return nullptr;
    1269697        }
    1270698
    1271699        const ast::Init * visit( const ast::ListInit * node ) override final {
    1272                 auto init = new ListInit(
    1273                         get<Initializer>().acceptL( node->initializers ),
    1274                         get<Designation>().acceptL( node->designations ),
    1275                         ast::MaybeConstruct == node->maybeConstructed
    1276                 );
    1277                 init->location = node->location;
    1278                 this->node = init;
     700                (void)node;
    1279701                return nullptr;
    1280702        }
    1281703
    1282704        const ast::Init * visit( const ast::ConstructorInit * node ) override final {
    1283                 auto init = new ConstructorInit(
    1284                         get<Statement>().accept1( node->ctor ),
    1285                         get<Statement>().accept1( node->dtor ),
    1286                         get<Initializer>().accept1( node->init )
    1287                 );
    1288                 init->location = node->location;
    1289                 this->node = init;
     705                (void)node;
    1290706                return nullptr;
    1291707        }
    1292708
    1293709        const ast::Attribute * visit( const ast::Attribute * node ) override final {
    1294                 auto attr = new Attribute(
    1295                         node->name,
    1296                         get<Expression>().acceptL(node->params)
    1297                 );
    1298                 this->node = attr;
     710                (void)node;
    1299711                return nullptr;
    1300712        }
    1301713
    1302714        const ast::TypeSubstitution * visit( const ast::TypeSubstitution * node ) override final {
    1303                 // Handled by convertTypeSubstitution helper instead.
    1304                 // TypeSubstitution is not a node in the old model, so the conversion result wouldn't fit in this->node.
    1305                 assert( 0 );
    1306715                (void)node;
    1307716                return nullptr;
     
    1309718};
    1310719
    1311 std::list< Declaration * > convert( const std::list< ast::ptr< ast::Decl > > && translationUnit ) {
     720std::list< Declaration * > convert( std::list< ast::ptr< ast::Decl > > && translationUnit ) {
    1312721        ConverterNewToOld c;
    1313722        std::list< Declaration * > decls;
    1314723        for(auto d : translationUnit) {
    1315724                decls.emplace_back( c.decl( d ) );
     725                delete d;
    1316726        }
    1317727        return decls;
     
    1326736        }
    1327737private:
    1328         /// conversion output
    1329738        ast::Node * node;
    1330         /// cache of nodes that might be referenced by readonly<> for de-duplication
    1331         std::unordered_map< BaseSyntaxNode *, ast::Node * > cache;
    1332739
    1333740        // Local Utilities:
     
    1335742        template<typename NewT, typename OldT>
    1336743        NewT * getAccept1( OldT old ) {
    1337                 if ( ! old ) return nullptr;
    1338744                old->accept(*this);
    1339745                return strict_dynamic_cast< NewT * >( node );
     
    1377783                to<std::vector>::from( make_labels( std::move( labels ) ) )
    1378784
    1379         static ast::CV::Qualifiers cv( Type * ty ) { return { ty->get_qualifiers().val }; }
    1380 
    1381         /// returns true and sets `node` if in cache
    1382         bool inCache( BaseSyntaxNode * old ) {
    1383                 auto it = cache.find( old );
    1384                 if ( it == cache.end() ) return false;
    1385                 node = it->second;
    1386                 return true;
    1387         }
    1388 
    1389785        // Now all the visit functions:
    1390786
    1391787        virtual void visit( ObjectDecl * old ) override final {
    1392                 if ( inCache( old ) ) return;
    1393788                auto decl = new ast::ObjectDecl(
    1394789                        old->location,
     
    1402797                        { old->get_funcSpec().val }
    1403798                );
    1404                 cache.emplace( old, decl );
    1405799                decl->scopeLevel = old->scopeLevel;
    1406800                decl->mangleName = old->mangleName;
     
    1412806        }
    1413807
    1414         virtual void visit( FunctionDecl * old ) override final {
    1415                 if ( inCache( old ) ) return;
    1416                 auto decl = new ast::FunctionDecl{
    1417                         old->location,
    1418                         old->name,
    1419                         GET_ACCEPT_1(type, FunctionType),
    1420                         GET_ACCEPT_1(statements, CompoundStmt),
    1421                         { old->storageClasses.val },
    1422                         { old->linkage.val },
    1423                         GET_ACCEPT_V(attributes, Attribute),
    1424                         { old->get_funcSpec().val }
    1425                 };
    1426                 cache.emplace( old, decl );
    1427                 decl->scopeLevel = old->scopeLevel;
    1428                 decl->mangleName = old->mangleName;
    1429                 decl->isDeleted  = old->isDeleted;
    1430                 decl->uniqueId   = old->uniqueId;
    1431                 decl->extension  = old->extension;
    1432 
    1433                 this->node = decl;
     808        virtual void visit( FunctionDecl * ) override final {
     809
    1434810        }
    1435811
    1436812        virtual void visit( StructDecl * old ) override final {
    1437                 if ( inCache( old ) ) return;
    1438813                auto decl = new ast::StructDecl(
    1439814                        old->location,
     
    1443818                        { old->linkage.val }
    1444819                );
    1445                 cache.emplace( old, decl );
    1446820                decl->parent = GET_ACCEPT_1(parent, AggregateDecl);
    1447821                decl->body   = old->body;
     
    1456830
    1457831        virtual void visit( UnionDecl * old ) override final {
    1458                 if ( inCache( old ) ) return;
    1459832                auto decl = new ast::UnionDecl(
    1460833                        old->location,
     
    1463836                        { old->linkage.val }
    1464837                );
    1465                 cache.emplace( old, decl );
    1466838                decl->parent = GET_ACCEPT_1(parent, AggregateDecl);
    1467839                decl->body   = old->body;
     
    1476848
    1477849        virtual void visit( EnumDecl * old ) override final {
    1478                 if ( inCache( old ) ) return;
    1479850                auto decl = new ast::UnionDecl(
    1480851                        old->location,
     
    1483854                        { old->linkage.val }
    1484855                );
    1485                 cache.emplace( old, decl );
    1486856                decl->parent = GET_ACCEPT_1(parent, AggregateDecl);
    1487857                decl->body   = old->body;
     
    1496866
    1497867        virtual void visit( TraitDecl * old ) override final {
    1498                 if ( inCache( old ) ) return;
    1499868                auto decl = new ast::UnionDecl(
    1500869                        old->location,
     
    1503872                        { old->linkage.val }
    1504873                );
    1505                 cache.emplace( old, decl );
    1506874                decl->parent = GET_ACCEPT_1(parent, AggregateDecl);
    1507875                decl->body   = old->body;
     
    1515883        }
    1516884
    1517         virtual void visit( TypeDecl * old ) override final {
    1518                 if ( inCache( old ) ) return;
    1519                 auto decl = new ast::TypeDecl{
    1520                         old->location,
    1521                         old->name,
    1522                         { old->storageClasses.val },
    1523                         GET_ACCEPT_1(base, Type),
    1524                         (ast::TypeVar::Kind)(unsigned)old->kind,
    1525                         old->sized,
    1526                         GET_ACCEPT_1(init, Type)
    1527                 };
    1528                 cache.emplace( old, decl );
    1529                 decl->assertions = GET_ACCEPT_V(assertions, DeclWithType);
    1530                 decl->params     = GET_ACCEPT_V(parameters, TypeDecl);
    1531                 decl->extension  = old->extension;
    1532                 decl->uniqueId   = old->uniqueId;
    1533 
    1534                 this->node = decl;
     885        virtual void visit( TypeDecl * ) override final {
     886
    1535887        }
    1536888
     
    1552904        }
    1553905
    1554         virtual void visit( AsmDecl * old ) override final {
    1555                 auto decl = new ast::AsmDecl{
    1556                         old->location,
    1557                         GET_ACCEPT_1(stmt, AsmStmt)
    1558                 };
    1559                 decl->extension  = old->extension;
    1560                 decl->uniqueId   = old->uniqueId;
    1561                 decl->storage    = { old->storageClasses.val };
    1562 
    1563                 this->node = decl;
    1564         }
    1565 
    1566         virtual void visit( StaticAssertDecl * old ) override final {
    1567                 auto decl = new ast::StaticAssertDecl{
    1568                         old->location,
    1569                         GET_ACCEPT_1(condition, Expr),
    1570                         GET_ACCEPT_1(message, ConstantExpr)
    1571                 };
    1572                 decl->extension  = old->extension;
    1573                 decl->uniqueId   = old->uniqueId;
    1574                 decl->storage    = { old->storageClasses.val };
    1575 
    1576                 this->node = decl;
     906        virtual void visit( AsmDecl * ) override final {
     907
     908        }
     909
     910        virtual void visit( StaticAssertDecl * ) override final {
     911
    1577912        }
    1578913
    1579914        virtual void visit( CompoundStmt * old ) override final {
    1580                 if ( inCache( old ) ) return;
    1581915                auto stmt = new ast::CompoundStmt(
    1582916                        old->location,
     
    1586920
    1587921                this->node = stmt;
    1588                 cache.emplace( old, this->node );
    1589922        }
    1590923
    1591924        virtual void visit( ExprStmt * old ) override final {
    1592                 if ( inCache( old ) ) return;
    1593925                this->node = new ast::ExprStmt(
    1594926                        old->location,
     
    1596928                        GET_LABELS_V(old->labels)
    1597929                );
    1598                 cache.emplace( old, this->node );
    1599930        }
    1600931
    1601932        virtual void visit( AsmStmt * old ) override final {
    1602                 if ( inCache( old ) ) return;
    1603933                this->node = new ast::AsmStmt(
    1604934                        old->location,
     
    1611941                        GET_LABELS_V(old->labels)
    1612942                );
    1613                 cache.emplace( old, this->node );
    1614943        }
    1615944
    1616945        virtual void visit( DirectiveStmt * old ) override final {
    1617                 if ( inCache( old ) ) return;
    1618946                this->node = new ast::DirectiveStmt(
    1619947                        old->location,
     
    1621949                        GET_LABELS_V(old->labels)
    1622950                );
    1623                 cache.emplace( old, this->node );
    1624951        }
    1625952
    1626953        virtual void visit( IfStmt * old ) override final {
    1627                 if ( inCache( old ) ) return;
    1628954                this->node = new ast::IfStmt(
    1629955                        old->location,
     
    1634960                        GET_LABELS_V(old->labels)
    1635961                );
    1636                 cache.emplace( old, this->node );
    1637962        }
    1638963
    1639964        virtual void visit( SwitchStmt * old ) override final {
    1640                 if ( inCache( old ) ) return;
    1641965                this->node = new ast::SwitchStmt(
    1642966                        old->location,
     
    1645969                        GET_LABELS_V(old->labels)
    1646970                );
    1647                 cache.emplace( old, this->node );
    1648971        }
    1649972
    1650973        virtual void visit( CaseStmt * old ) override final {
    1651                 if ( inCache( old ) ) return;
    1652974                this->node = new ast::CaseStmt(
    1653975                        old->location,
     
    1656978                        GET_LABELS_V(old->labels)
    1657979                );
    1658                 cache.emplace( old, this->node );
    1659980        }
    1660981
    1661982        virtual void visit( WhileStmt * old ) override final {
    1662                 if ( inCache( old ) ) return;
    1663983                this->node = new ast::WhileStmt(
    1664984                        old->location,
     
    1669989                        GET_LABELS_V(old->labels)
    1670990                );
    1671                 cache.emplace( old, this->node );
    1672991        }
    1673992
    1674993        virtual void visit( ForStmt * old ) override final {
    1675                 if ( inCache( old ) ) return;
    1676994                this->node = new ast::ForStmt(
    1677995                        old->location,
     
    16821000                        GET_LABELS_V(old->labels)
    16831001                );
    1684                 cache.emplace( old, this->node );
    16851002        }
    16861003
    16871004        virtual void visit( BranchStmt * old ) override final {
    1688                 if ( inCache( old ) ) return;
    16891005                if (old->computedTarget) {
    16901006                        this->node = new ast::BranchStmt(
     
    17201036                        this->node = stmt;
    17211037                }
    1722                 cache.emplace( old, this->node );
    17231038        }
    17241039
    17251040        virtual void visit( ReturnStmt * old ) override final {
    1726                 if ( inCache( old ) ) return;
    17271041                this->node = new ast::ReturnStmt(
    17281042                        old->location,
     
    17301044                        GET_LABELS_V(old->labels)
    17311045                );
    1732                 cache.emplace( old, this->node );
    17331046        }
    17341047
    17351048        virtual void visit( ThrowStmt * old ) override final {
    1736                 if ( inCache( old ) ) return;
    17371049                ast::ThrowStmt::Kind kind;
    17381050                switch (old->kind) {
     
    17541066                        GET_LABELS_V(old->labels)
    17551067                );
    1756                 cache.emplace( old, this->node );
    17571068        }
    17581069
    17591070        virtual void visit( TryStmt * old ) override final {
    1760                 if ( inCache( old ) ) return;
    17611071                this->node = new ast::TryStmt(
    17621072                        old->location,
     
    17661076                        GET_LABELS_V(old->labels)
    17671077                );
    1768                 cache.emplace( old, this->node );
    17691078        }
    17701079
    17711080        virtual void visit( CatchStmt * old ) override final {
    1772                 if ( inCache( old ) ) return;
    17731081                ast::CatchStmt::Kind kind;
    17741082                switch (old->kind) {
     
    17911099                        GET_LABELS_V(old->labels)
    17921100                );
    1793                 cache.emplace( old, this->node );
    17941101        }
    17951102
    17961103        virtual void visit( FinallyStmt * old ) override final {
    1797                 if ( inCache( old ) ) return;
    17981104                this->node = new ast::FinallyStmt(
    17991105                        old->location,
     
    18011107                        GET_LABELS_V(old->labels)
    18021108                );
    1803                 cache.emplace( old, this->node );
    18041109        }
    18051110
    18061111        virtual void visit( WaitForStmt * old ) override final {
    1807                 if ( inCache( old ) ) return;
    18081112                ast::WaitForStmt * stmt = new ast::WaitForStmt(
    18091113                        old->location,
     
    18331137
    18341138                this->node = stmt;
    1835                 cache.emplace( old, this->node );
    18361139        }
    18371140
    18381141        virtual void visit( WithStmt * old ) override final {
    1839                 if ( inCache( old ) ) return;
    18401142                this->node = new ast::WithStmt(
    18411143                        old->location,
     
    18441146                        GET_LABELS_V(old->labels)
    18451147                );
    1846                 cache.emplace( old, this->node );
    18471148        }
    18481149
    18491150        virtual void visit( NullStmt * old ) override final {
    1850                 if ( inCache( old ) ) return;
    18511151                this->node = new ast::NullStmt(
    18521152                        old->location,
    18531153                        GET_LABELS_V(old->labels)
    18541154                );
    1855                 cache.emplace( old, this->node );
    18561155        }
    18571156
    18581157        virtual void visit( DeclStmt * old ) override final {
    1859                 if ( inCache( old ) ) return;
    18601158                this->node = new ast::DeclStmt(
    18611159                        old->location,
     
    18631161                        GET_LABELS_V(old->labels)
    18641162                );
    1865                 cache.emplace( old, this->node );
    18661163        }
    18671164
    18681165        virtual void visit( ImplicitCtorDtorStmt * old ) override final {
    1869                 if ( inCache( old ) ) return;
    1870                 auto stmt = new ast::ImplicitCtorDtorStmt(
    1871                         old->location,
    1872                         nullptr,
    1873                         GET_LABELS_V(old->labels)
    1874                 );
    1875                 this->node = stmt;
    1876                 cache.emplace( old, this->node );
    1877                 stmt->callStmt = GET_ACCEPT_1(callStmt, Stmt);
     1166                this->node = new ast::ImplicitCtorDtorStmt(
     1167                        old->location,
     1168                        GET_ACCEPT_1(callStmt, Stmt),
     1169                        GET_LABELS_V(old->labels)
     1170                );
    18781171        }
    18791172
    18801173        ast::TypeSubstitution * convertTypeSubstitution(const TypeSubstitution * old) {
    1881 
    1882                 if (!old) return nullptr;
    18831174
    18841175                ast::TypeSubstitution *rslt = new ast::TypeSubstitution();
     
    18931184                                      getAccept1<ast::Expr>(old_i->second) );
    18941185                }
    1895 
    1896                 return rslt;
    1897         }
    1898 
    1899         void convertInferUnion(ast::Expr::InferUnion               &newInferred,
    1900                                                    const std::map<UniqueId,ParamEntry> &oldInferParams,
    1901                                                    const std::vector<UniqueId>         &oldResnSlots) {
    1902 
    1903                 assert( oldInferParams.empty() || oldResnSlots.empty() );
    1904                 assert( newInferred.mode == ast::Expr::InferUnion::Empty );
    1905 
    1906                 if ( !oldInferParams.empty() ) {
    1907                         ast::InferredParams &tgt = newInferred.inferParams();
    1908                         for (auto old : oldInferParams) {
    1909                                 tgt[old.first] = ast::ParamEntry(
    1910                                         old.second.decl,
    1911                                         getAccept1<ast::Type>(old.second.actualType),
    1912                                         getAccept1<ast::Type>(old.second.formalType),
    1913                                         getAccept1<ast::Expr>(old.second.expr)
    1914                                 );
    1915                         }
    1916                 } else if ( !oldResnSlots.empty() ) {
    1917                         ast::ResnSlots &tgt = newInferred.resnSlots();
    1918                         for (auto old : oldResnSlots) {
    1919                                 tgt.push_back(old);
    1920                         }
    1921                 }
    1922         }
    1923 
    1924         ast::Expr * visitBaseExpr_SkipResultType(Expression * old, ast::Expr * nw) {
    1925 
     1186        }
     1187
     1188        void convertInferUnion(ast::Expr::InferUnion &nwInferred, InferredParams oldInferParams, const std::vector<UniqueId> &oldResnSlots) {
     1189               
     1190                (void) nwInferred;
     1191                (void) oldInferParams;
     1192                (void) oldResnSlots;
     1193               
     1194                // TODO
     1195        }
     1196
     1197        ast::Expr * visitBaseExpr(Expression * old, ast::Expr * nw) {
     1198
     1199                nw->result = GET_ACCEPT_1(result, Type);
    19261200                nw->env    = convertTypeSubstitution(old->env);
    19271201
     
    19321206        }
    19331207
    1934         ast::Expr * visitBaseExpr(Expression * old, ast::Expr * nw) {
    1935 
    1936                 nw->result = GET_ACCEPT_1(result, Type);
    1937                 return visitBaseExpr_SkipResultType(old, nw);;
    1938         }
    1939 
    1940         virtual void visit( ApplicationExpr * old ) override final {
    1941                 this->node = visitBaseExpr( old,
    1942                         new ast::ApplicationExpr(
    1943                                 old->location,
    1944                                 GET_ACCEPT_1(function, Expr),
    1945                                 GET_ACCEPT_V(args, Expr)
    1946                         )
    1947                 );
    1948         }
    1949 
    1950         virtual void visit( UntypedExpr * old ) override final {
    1951                 this->node = visitBaseExpr( old,
    1952                         new ast::UntypedExpr(
    1953                                 old->location,
    1954                                 GET_ACCEPT_1(function, Expr),
    1955                                 GET_ACCEPT_V(args, Expr)
    1956                         )
    1957                 );
     1208        virtual void visit( ApplicationExpr * ) override final {
     1209                // TODO
     1210        }
     1211
     1212        virtual void visit( UntypedExpr * ) override final {
     1213                // TODO
    19581214        }
    19591215
     
    19671223        }
    19681224
    1969         virtual void visit( CastExpr * old ) override final {
    1970                 this->node = visitBaseExpr( old,
    1971                         new ast::CastExpr(
    1972                                 old->location,
    1973                                 GET_ACCEPT_1(arg, Expr),
    1974                                 old->isGenerated ? ast::GeneratedCast : ast::ExplicitCast
    1975                         )
    1976                 );
    1977         }
    1978 
    1979         virtual void visit( KeywordCastExpr * old) override final {
    1980                 ast::KeywordCastExpr::Target castTarget = ast::KeywordCastExpr::NUMBER_OF_TARGETS;
    1981                 switch (old->target) {
    1982                         case KeywordCastExpr::Coroutine:
    1983                                 castTarget = ast::KeywordCastExpr::Coroutine;
    1984                                 break;
    1985                         case KeywordCastExpr::Thread:
    1986                                 castTarget = ast::KeywordCastExpr::Thread;
    1987                                 break;
    1988                         case KeywordCastExpr::Monitor:
    1989                                 castTarget = ast::KeywordCastExpr::Monitor;
    1990                                 break;
    1991                         default:
    1992                                 break;
    1993                 }
    1994                 assert ( castTarget < ast::KeywordCastExpr::NUMBER_OF_TARGETS );
    1995                 this->node = visitBaseExpr( old,
    1996                         new ast::KeywordCastExpr(
    1997                                 old->location,
    1998                                 GET_ACCEPT_1(arg, Expr),
    1999                                 castTarget
    2000                         )
    2001                 );
    2002         }
    2003 
    2004         virtual void visit( VirtualCastExpr * old ) override final {
    2005                 this->node = visitBaseExpr_SkipResultType( old,
    2006                         new ast::VirtualCastExpr(
    2007                                 old->location,
    2008                                 GET_ACCEPT_1(arg, Expr),
    2009                                 GET_ACCEPT_1(result, Type)
    2010                         )
    2011                 );
    2012         }
    2013 
    2014         virtual void visit( AddressExpr * old ) override final {
    2015                 this->node = visitBaseExpr( old,
    2016                         new ast::AddressExpr(
    2017                                 old->location,
    2018                                 GET_ACCEPT_1(arg, Expr)
    2019                         )
    2020                 );
    2021         }
    2022 
    2023         virtual void visit( LabelAddressExpr * old ) override final {
    2024                 this->node = visitBaseExpr( old,
    2025                         new ast::LabelAddressExpr(
    2026                                 old->location,
    2027                                 make_label(&old->arg)
    2028                         )
    2029                 );
    2030         }
    2031 
    2032         virtual void visit( UntypedMemberExpr * old ) override final {
    2033                 this->node = visitBaseExpr( old,
    2034                         new ast::UntypedMemberExpr(
    2035                                 old->location,
    2036                                 GET_ACCEPT_1(member, Expr),
    2037                                 GET_ACCEPT_1(aggregate, Expr)
    2038                         )
    2039                 );
    2040         }
    2041 
    2042         virtual void visit( MemberExpr * old ) override final {
    2043                 this->node = visitBaseExpr( old,
    2044                         new ast::MemberExpr(
    2045                                 old->location,
    2046                                 inCache(old->member) ?
    2047                                         dynamic_cast<ast::DeclWithType *>(this->node) :
    2048                                         GET_ACCEPT_1(member, DeclWithType),
    2049                                 GET_ACCEPT_1(aggregate, Expr)
    2050                         )
    2051                 );
    2052         }
    2053 
    2054         virtual void visit( VariableExpr * old ) override final {
    2055                 this->node = visitBaseExpr( old,
    2056                         new ast::VariableExpr(
    2057                                 old->location,
    2058                                 inCache(old->var) ?
    2059                                         dynamic_cast<ast::DeclWithType *>(this->node) :
    2060                                         GET_ACCEPT_1(var, DeclWithType)
    2061                         )
    2062                 );
    2063         }
    2064 
    2065         bool isIntlikeConstantType(const Type *t) {
    2066                 if ( const BasicType * basicType = dynamic_cast< const BasicType * >( t ) ) {
    2067                         if ( basicType->isInteger() ) {
    2068                                 return true;
    2069                         }
    2070                 } else if ( dynamic_cast< const OneType * >( t ) ) {
    2071                         return true;
    2072                 } else if ( dynamic_cast< const ZeroType * >( t ) ) {
    2073                         return true;
    2074                 } else if ( dynamic_cast< const PointerType * >( t ) ) {
    2075                         // null pointer constants, with zero int-values
    2076                         return true;
    2077                 }
    2078                 return false;
    2079         }
    2080 
    2081         int isFloatlikeConstantType(const Type *t) {
    2082                 if ( const BasicType * bty = dynamic_cast< const BasicType * >( t ) ) {
    2083                         if ( ! bty->isInteger() ) {
    2084                                 return true;
    2085                         }
    2086                 }
    2087                 return false;
    2088         }
    2089 
    2090         int isStringlikeConstantType(const Type *t) {
    2091                 if ( const ArrayType * aty = dynamic_cast< const ArrayType * >( t ) ) {
    2092                         if ( const BasicType * bty = dynamic_cast< const BasicType * >( aty->base ) ) {
    2093                            if ( bty->kind == BasicType::Kind::Char ) {
    2094                                    return true;
    2095                            }
    2096                         }
    2097                 }
    2098                 return false;
    2099         }
    2100 
    2101         virtual void visit( ConstantExpr * old ) override final {
    2102                 ast::ConstantExpr *rslt = nullptr;
    2103                 if (isIntlikeConstantType(old->result)) {
    2104                         rslt = new ast::ConstantExpr(
    2105                                 old->location,
    2106                                 GET_ACCEPT_1(result, Type),
    2107                                 old->constant.get_value(),
    2108                                 (unsigned long long) old->intValue()
    2109                         );
    2110                 } else if (isFloatlikeConstantType(old->result)) {
    2111                         rslt = new ast::ConstantExpr(
    2112                                 old->location,
    2113                                 GET_ACCEPT_1(result, Type),
    2114                                 old->constant.get_value(),
    2115                                 (double) old->constant.get_dval()
    2116                         );
    2117                 } else if (isStringlikeConstantType(old->result)) {
    2118                         rslt = ast::ConstantExpr::from_string(
    2119                                 old->location,
    2120                                 old->constant.get_value()
    2121                         );
    2122                 }
    2123                 assert(rslt);
    2124                 this->node = visitBaseExpr( old, rslt );
    2125         }
    2126 
    2127         virtual void visit( SizeofExpr * old ) override final {
    2128                 assert (old->expr || old->type);
    2129                 assert (! (old->expr && old->type));
    2130                 ast::SizeofExpr *rslt;
    2131                 if (old->expr) {
    2132                         assert(!old->isType);
    2133                         rslt = new ast::SizeofExpr(
    2134                                 old->location,
    2135                                 GET_ACCEPT_1(expr, Expr)
    2136                         );
    2137                 }
    2138                 if (old->type) {
    2139                         assert(old->isType);
    2140                         rslt = new ast::SizeofExpr(
    2141                                 old->location,
    2142                                 GET_ACCEPT_1(type, Type)
    2143                         );
    2144                 }
    2145                 this->node = visitBaseExpr( old, rslt );
    2146         }
    2147 
    2148         virtual void visit( AlignofExpr * old ) override final {
    2149                 assert (old->expr || old->type);
    2150                 assert (! (old->expr && old->type));
    2151                 ast::AlignofExpr *rslt;
    2152                 if (old->expr) {
    2153                         assert(!old->isType);
    2154                         rslt = new ast::AlignofExpr(
    2155                                 old->location,
    2156                                 GET_ACCEPT_1(expr, Expr)
    2157                         );
    2158                 }
    2159                 if (old->type) {
    2160                         assert(old->isType);
    2161                         rslt = new ast::AlignofExpr(
    2162                                 old->location,
    2163                                 GET_ACCEPT_1(type, Type)
    2164                         );
    2165                 }
    2166                 this->node = visitBaseExpr( old, rslt );
    2167         }
    2168 
    2169         virtual void visit( UntypedOffsetofExpr * old ) override final {
    2170                 this->node = visitBaseExpr( old,
    2171                         new ast::UntypedOffsetofExpr(
    2172                                 old->location,
    2173                                 GET_ACCEPT_1(type, Type),
    2174                                 old->member
    2175                         )
    2176                 );
    2177         }
    2178 
    2179         virtual void visit( OffsetofExpr * old ) override final {
    2180                 this->node = visitBaseExpr( old,
    2181                         new ast::OffsetofExpr(
    2182                                 old->location,
    2183                                 GET_ACCEPT_1(type, Type),
    2184                                 inCache(old->member) ?
    2185                                         dynamic_cast<ast::DeclWithType *>(this->node) :
    2186                                         GET_ACCEPT_1(member, DeclWithType)
    2187                         )
    2188                 );
    2189         }
    2190 
    2191         virtual void visit( OffsetPackExpr * old ) override final {
    2192                 this->node = visitBaseExpr( old,
    2193                         new ast::OffsetPackExpr(
    2194                                 old->location,
    2195                                 GET_ACCEPT_1(type, StructInstType)
    2196                         )
    2197                 );
    2198         }
    2199 
    2200         virtual void visit( LogicalExpr * old ) override final {
    2201                 this->node = visitBaseExpr( old,
    2202                         new ast::LogicalExpr(
    2203                                 old->location,
    2204                                 GET_ACCEPT_1(arg1, Expr),
    2205                                 GET_ACCEPT_1(arg2, Expr),
    2206                                 old->get_isAnd() ?
    2207                                         ast::LogicalFlag::AndExpr :
    2208                                         ast::LogicalFlag::OrExpr
    2209                         )
    2210                 );
    2211         }
    2212 
    2213         virtual void visit( ConditionalExpr * old ) override final {
    2214                 this->node = visitBaseExpr( old,
    2215                         new ast::ConditionalExpr(
    2216                                 old->location,
    2217                                 GET_ACCEPT_1(arg1, Expr),
    2218                                 GET_ACCEPT_1(arg2, Expr),
    2219                                 GET_ACCEPT_1(arg3, Expr)
    2220                         )
    2221                 );
    2222         }
    2223 
    2224         virtual void visit( CommaExpr * old ) override final {
    2225                 this->node = visitBaseExpr( old,
    2226                         new ast::CommaExpr(
    2227                                 old->location,
    2228                                 GET_ACCEPT_1(arg1, Expr),
    2229                                 GET_ACCEPT_1(arg2, Expr)
    2230                         )
    2231                 );
    2232         }
    2233 
    2234         virtual void visit( TypeExpr * old ) override final {
    2235                 this->node = visitBaseExpr( old,
    2236                         new ast::TypeExpr(
    2237                                 old->location,
    2238                                 GET_ACCEPT_1(type, Type)
    2239                         )
    2240                 );
    2241         }
    2242 
    2243         virtual void visit( AsmExpr * old ) override final {
    2244                 this->node = visitBaseExpr( old,
    2245                         new ast::AsmExpr(
    2246                                 old->location,
    2247                                 GET_ACCEPT_1(inout, Expr),
    2248                                 GET_ACCEPT_1(constraint, Expr),
    2249                                 GET_ACCEPT_1(operand, Expr)
    2250                         )
    2251                 );
    2252         }
    2253 
    2254         virtual void visit( ImplicitCopyCtorExpr * old ) override final {
    2255                 auto rslt = new ast::ImplicitCopyCtorExpr(
    2256                         old->location,
    2257                         GET_ACCEPT_1(callExpr, ApplicationExpr)
    2258                 );
    2259 
    2260                 this->node = visitBaseExpr( old, rslt );
    2261         }
    2262 
    2263         virtual void visit( ConstructorExpr * old ) override final {
    2264                 this->node = visitBaseExpr( old,
    2265                         new ast::ConstructorExpr(
    2266                                 old->location,
    2267                                 GET_ACCEPT_1(callExpr, Expr)
    2268                         )
    2269                 );
    2270         }
    2271 
    2272         virtual void visit( CompoundLiteralExpr * old ) override final {
    2273                 this->node = visitBaseExpr_SkipResultType( old,
    2274                         new ast::CompoundLiteralExpr(
    2275                                 old->location,
    2276                                 GET_ACCEPT_1(result, Type),
    2277                                 GET_ACCEPT_1(initializer, Init)
    2278                         )
    2279                 );
    2280         }
    2281 
    2282         virtual void visit( RangeExpr * old ) override final {
    2283                 this->node = visitBaseExpr( old,
    2284                         new ast::RangeExpr(
    2285                                 old->location,
    2286                                 GET_ACCEPT_1(low, Expr),
    2287                                 GET_ACCEPT_1(high, Expr)
    2288                         )
    2289                 );
    2290         }
    2291 
    2292         virtual void visit( UntypedTupleExpr * old ) override final {
    2293                 this->node = visitBaseExpr( old,
    2294                         new ast::UntypedTupleExpr(
    2295                                 old->location,
    2296                                 GET_ACCEPT_V(exprs, Expr)
    2297                         )
    2298                 );
    2299         }
    2300 
    2301         virtual void visit( TupleExpr * old ) override final {
    2302                 this->node = visitBaseExpr( old,
    2303                         new ast::TupleExpr(
    2304                                 old->location,
    2305                                 GET_ACCEPT_V(exprs, Expr)
    2306                         )
    2307                 );
    2308         }
    2309 
    2310         virtual void visit( TupleIndexExpr * old ) override final {
    2311                 this->node = visitBaseExpr( old,
    2312                         new ast::TupleIndexExpr(
    2313                                 old->location,
    2314                                 GET_ACCEPT_1(tuple, Expr),
    2315                                 old->index
    2316                         )
    2317                 );
    2318         }
    2319 
    2320         virtual void visit( TupleAssignExpr * old ) override final {
    2321                 this->node = visitBaseExpr_SkipResultType( old,
    2322                         new ast::TupleAssignExpr(
    2323                                 old->location,
    2324                                 GET_ACCEPT_1(result, Type),
    2325                                 GET_ACCEPT_1(stmtExpr, StmtExpr)
    2326                         )
    2327                 );
    2328         }
    2329 
    2330         virtual void visit( StmtExpr * old ) override final {
    2331                 auto rslt = new ast::StmtExpr(
    2332                         old->location,
    2333                         GET_ACCEPT_1(statements, CompoundStmt)
    2334                 );
    2335                 rslt->returnDecls = GET_ACCEPT_V(returnDecls, ObjectDecl);
    2336                 rslt->dtors       = GET_ACCEPT_V(dtors      , Expr);
    2337 
    2338                 this->node = visitBaseExpr_SkipResultType( old, rslt );
    2339         }
    2340 
    2341         virtual void visit( UniqueExpr * old ) override final {
    2342                 auto rslt = new ast::UniqueExpr(
    2343                         old->location,
    2344                         GET_ACCEPT_1(expr, Expr)
    2345                 );
    2346                 rslt->object = GET_ACCEPT_1(object, ObjectDecl);
    2347                 rslt->var    = GET_ACCEPT_1(var   , VariableExpr);
    2348 
    2349                 this->node = visitBaseExpr( old, rslt );
    2350         }
    2351 
    2352         virtual void visit( UntypedInitExpr * old ) override final {
    2353                 std::vector<ast::InitAlternative> initAlts;
    2354                 for (auto ia : old->initAlts) {
    2355                         initAlts.push_back(ast::InitAlternative(
    2356                                 getAccept1< ast::Type, Type * >( ia.type ),
    2357                                 getAccept1< ast::Designation, Designation * >( ia.designation )
    2358                         ));
    2359                 }
    2360                 this->node = visitBaseExpr( old,
    2361                         new ast::UntypedInitExpr(
    2362                                 old->location,
    2363                                 GET_ACCEPT_1(expr, Expr),
    2364                                 std::move(initAlts)
    2365                         )
    2366                 );
    2367         }
    2368 
    2369         virtual void visit( InitExpr * old ) override final {
    2370                 this->node = visitBaseExpr( old,
    2371                         new ast::InitExpr(
    2372                                 old->location,
    2373                                 GET_ACCEPT_1(expr, Expr),
    2374                                 GET_ACCEPT_1(designation, Designation)
    2375                         )
    2376                 );
    2377         }
    2378 
    2379         virtual void visit( DeletedExpr * old ) override final {
    2380                 this->node = visitBaseExpr( old,
    2381                         new ast::DeletedExpr(
    2382                                 old->location,
    2383                                 GET_ACCEPT_1(expr, Expr),
    2384                                 inCache(old->deleteStmt) ?
    2385                                         this->node :
    2386                                         GET_ACCEPT_1(deleteStmt, Node)
    2387                         )
    2388                 );
    2389         }
    2390 
    2391         virtual void visit( DefaultArgExpr * old ) override final {
    2392                 this->node = visitBaseExpr( old,
    2393                         new ast::DefaultArgExpr(
    2394                                 old->location,
    2395                                 GET_ACCEPT_1(expr, Expr)
    2396                         )
    2397                 );
    2398         }
    2399 
    2400         virtual void visit( GenericExpr * old ) override final {
    2401                 std::vector<ast::GenericExpr::Association> associations;
    2402                 for (auto association : old->associations) {
    2403                         associations.push_back(ast::GenericExpr::Association(
    2404                                 getAccept1< ast::Type, Type * >( association.type ),
    2405                                 getAccept1< ast::Expr, Expression * >( association.expr )
    2406                         ));
    2407                 }
    2408                 this->node = visitBaseExpr( old,
    2409                         new ast::GenericExpr(
    2410                                 old->location,
    2411                                 GET_ACCEPT_1(control, Expr),
    2412                                 std::move(associations)
    2413                         )
    2414                 );
    2415         }
    2416 
    2417         virtual void visit( VoidType * old ) override final {
    2418                 this->node = new ast::VoidType{ cv( old ) };
    2419         }
    2420 
    2421         virtual void visit( BasicType * old ) override final {
    2422                 this->node = new ast::BasicType{ (ast::BasicType::Kind)(unsigned)old->kind, cv( old ) };
    2423         }
    2424 
    2425         virtual void visit( PointerType * old ) override final {
    2426                 this->node = new ast::PointerType{
    2427                         GET_ACCEPT_1( base, Type ),
    2428                         GET_ACCEPT_1( dimension, Expr ),
    2429                         (ast::LengthFlag)old->isVarLen,
    2430                         (ast::DimensionFlag)old->isStatic,
    2431                         cv( old )
    2432                 };
    2433         }
    2434 
    2435         virtual void visit( ArrayType * old ) override final {
    2436                 this->node = new ast::ArrayType{
    2437                         GET_ACCEPT_1( base, Type ),
    2438                         GET_ACCEPT_1( dimension, Expr ),
    2439                         (ast::LengthFlag)old->isVarLen,
    2440                         (ast::DimensionFlag)old->isStatic,
    2441                         cv( old )
    2442                 };
    2443         }
    2444 
    2445         virtual void visit( ReferenceType * old ) override final {
    2446                 this->node = new ast::ReferenceType{
    2447                         GET_ACCEPT_1( base, Type ),
    2448                         cv( old )
    2449                 };
    2450         }
    2451 
    2452         virtual void visit( QualifiedType * old ) override final {
    2453                 this->node = new ast::QualifiedType{
    2454                         GET_ACCEPT_1( parent, Type ),
    2455                         GET_ACCEPT_1( child, Type ),
    2456                         cv( old )
    2457                 };
    2458         }
    2459 
    2460         virtual void visit( FunctionType * old ) override final {
    2461                 auto ty = new ast::FunctionType {
    2462                         (ast::ArgumentFlag)old->isVarArgs,
    2463                         cv( old )
    2464                 };
    2465                 ty->returns = GET_ACCEPT_V( returnVals, DeclWithType );
    2466                 ty->params = GET_ACCEPT_V( parameters, DeclWithType );
    2467                 ty->forall = GET_ACCEPT_V( forall, TypeDecl );
    2468                 this->node = ty;
    2469         }
    2470 
    2471         void postvisit( ReferenceToType * old, ast::ReferenceToType * ty ) {
    2472                 ty->forall = GET_ACCEPT_V( forall, TypeDecl );
    2473                 ty->params = GET_ACCEPT_V( parameters, Expr );
    2474                 ty->hoistType = old->hoistType;
    2475         }
    2476 
    2477         virtual void visit( StructInstType * old ) override final {
    2478                 ast::StructInstType * ty;
    2479                 if ( old->baseStruct ) {
    2480                         ty = new ast::StructInstType{
    2481                                 GET_ACCEPT_1( baseStruct, StructDecl ),
    2482                                 cv( old ),
    2483                                 GET_ACCEPT_V( attributes, Attribute )
    2484                         };
    2485                 } else {
    2486                         ty = new ast::StructInstType{
    2487                                 old->name,
    2488                                 cv( old ),
    2489                                 GET_ACCEPT_V( attributes, Attribute )
    2490                         };
    2491                 }
    2492                 postvisit( old, ty );
    2493                 this->node = ty;
    2494         }
    2495 
    2496         virtual void visit( UnionInstType * old ) override final {
    2497                 ast::UnionInstType * ty;
    2498                 if ( old->baseUnion ) {
    2499                         ty = new ast::UnionInstType{
    2500                                 GET_ACCEPT_1( baseUnion, UnionDecl ),
    2501                                 cv( old ),
    2502                                 GET_ACCEPT_V( attributes, Attribute )
    2503                         };
    2504                 } else {
    2505                         ty = new ast::UnionInstType{
    2506                                 old->name,
    2507                                 cv( old ),
    2508                                 GET_ACCEPT_V( attributes, Attribute )
    2509                         };
    2510                 }
    2511                 postvisit( old, ty );
    2512                 this->node = ty;
    2513         }
    2514 
    2515         virtual void visit( EnumInstType * old ) override final {
    2516                 ast::EnumInstType * ty;
    2517                 if ( old->baseEnum ) {
    2518                         ty = new ast::EnumInstType{
    2519                                 GET_ACCEPT_1( baseEnum, EnumDecl ),
    2520                                 cv( old ),
    2521                                 GET_ACCEPT_V( attributes, Attribute )
    2522                         };
    2523                 } else {
    2524                         ty = new ast::EnumInstType{
    2525                                 old->name,
    2526                                 cv( old ),
    2527                                 GET_ACCEPT_V( attributes, Attribute )
    2528                         };
    2529                 }
    2530                 postvisit( old, ty );
    2531                 this->node = ty;
    2532         }
    2533 
    2534         virtual void visit( TraitInstType * old ) override final {
    2535                 ast::TraitInstType * ty;
    2536                 if ( old->baseTrait ) {
    2537                         ty = new ast::TraitInstType{
    2538                                 GET_ACCEPT_1( baseTrait, TraitDecl ),
    2539                                 cv( old ),
    2540                                 GET_ACCEPT_V( attributes, Attribute )
    2541                         };
    2542                 } else {
    2543                         ty = new ast::TraitInstType{
    2544                                 old->name,
    2545                                 cv( old ),
    2546                                 GET_ACCEPT_V( attributes, Attribute )
    2547                         };
    2548                 }
    2549                 postvisit( old, ty );
    2550                 this->node = ty;
    2551         }
    2552 
    2553         virtual void visit( TypeInstType * old ) override final {
    2554                 ast::TypeInstType * ty;
    2555                 if ( old->baseType ) {
    2556                         ty = new ast::TypeInstType{
    2557                                 old->name,
    2558                                 GET_ACCEPT_1( baseType, TypeDecl ),
    2559                                 cv( old ),
    2560                                 GET_ACCEPT_V( attributes, Attribute )
    2561                         };
    2562                 } else {
    2563                         ty = new ast::TypeInstType{
    2564                                 old->name,
    2565                                 old->isFtype ? ast::TypeVar::Ftype : ast::TypeVar::Dtype,
    2566                                 cv( old ),
    2567                                 GET_ACCEPT_V( attributes, Attribute )
    2568                         };
    2569                 }
    2570                 postvisit( old, ty );
    2571                 this->node = ty;
    2572         }
    2573 
    2574         virtual void visit( TupleType * old ) override final {
    2575                 this->node = new ast::TupleType{
    2576                         GET_ACCEPT_V( types, Type ),
    2577                         // members generated by TupleType c'tor
    2578                         cv( old )
    2579                 };
    2580         }
    2581 
    2582         virtual void visit( TypeofType * old ) override final {
    2583                 this->node = new ast::TypeofType{
    2584                         GET_ACCEPT_1( expr, Expr ),
    2585                         (ast::TypeofType::Kind)old->is_basetypeof,
    2586                         cv( old )
    2587                 };
     1225        virtual void visit( CastExpr * ) override final {
     1226                // TODO ... (rest)
     1227        }
     1228
     1229        virtual void visit( KeywordCastExpr * ) override final {
     1230
     1231        }
     1232
     1233        virtual void visit( VirtualCastExpr * ) override final {
     1234
     1235        }
     1236
     1237        virtual void visit( AddressExpr * ) override final {
     1238
     1239        }
     1240
     1241        virtual void visit( LabelAddressExpr * ) override final {
     1242
     1243        }
     1244
     1245        virtual void visit( UntypedMemberExpr * ) override final {
     1246
     1247        }
     1248
     1249        virtual void visit( MemberExpr * ) override final {
     1250
     1251        }
     1252
     1253        virtual void visit( VariableExpr * ) override final {
     1254
     1255        }
     1256
     1257        virtual void visit( ConstantExpr * ) override final {
     1258
     1259        }
     1260
     1261        virtual void visit( SizeofExpr * ) override final {
     1262
     1263        }
     1264
     1265        virtual void visit( AlignofExpr * ) override final {
     1266
     1267        }
     1268
     1269        virtual void visit( UntypedOffsetofExpr * ) override final {
     1270
     1271        }
     1272
     1273        virtual void visit( OffsetofExpr * ) override final {
     1274
     1275        }
     1276
     1277        virtual void visit( OffsetPackExpr * ) override final {
     1278
     1279        }
     1280
     1281        virtual void visit( LogicalExpr * ) override final {
     1282
     1283        }
     1284
     1285        virtual void visit( ConditionalExpr * ) override final {
     1286
     1287        }
     1288
     1289        virtual void visit( CommaExpr * ) override final {
     1290
     1291        }
     1292
     1293        virtual void visit( TypeExpr * ) override final {
     1294
     1295        }
     1296
     1297        virtual void visit( AsmExpr * ) override final {
     1298
     1299        }
     1300
     1301        virtual void visit( ImplicitCopyCtorExpr * ) override final {
     1302
     1303        }
     1304
     1305        virtual void visit( ConstructorExpr *  ) override final {
     1306
     1307        }
     1308
     1309        virtual void visit( CompoundLiteralExpr * ) override final {
     1310
     1311        }
     1312
     1313        virtual void visit( RangeExpr * ) override final {
     1314
     1315        }
     1316
     1317        virtual void visit( UntypedTupleExpr * ) override final {
     1318
     1319        }
     1320
     1321        virtual void visit( TupleExpr * ) override final {
     1322
     1323        }
     1324
     1325        virtual void visit( TupleIndexExpr * ) override final {
     1326
     1327        }
     1328
     1329        virtual void visit( TupleAssignExpr * ) override final {
     1330
     1331        }
     1332
     1333        virtual void visit( StmtExpr *  ) override final {
     1334
     1335        }
     1336
     1337        virtual void visit( UniqueExpr *  ) override final {
     1338
     1339        }
     1340
     1341        virtual void visit( UntypedInitExpr *  ) override final {
     1342
     1343        }
     1344
     1345        virtual void visit( InitExpr *  ) override final {
     1346
     1347        }
     1348
     1349        virtual void visit( DeletedExpr * ) override final {
     1350
     1351        }
     1352
     1353        virtual void visit( DefaultArgExpr * ) override final {
     1354
     1355        }
     1356
     1357        virtual void visit( GenericExpr * ) override final {
     1358
     1359        }
     1360
     1361        virtual void visit( VoidType * ) override final {
     1362
     1363        }
     1364
     1365        virtual void visit( BasicType * ) override final {
     1366
     1367        }
     1368
     1369        virtual void visit( PointerType * ) override final {
     1370
     1371        }
     1372
     1373        virtual void visit( ArrayType * ) override final {
     1374
     1375        }
     1376
     1377        virtual void visit( ReferenceType * ) override final {
     1378
     1379        }
     1380
     1381        virtual void visit( QualifiedType * ) override final {
     1382
     1383        }
     1384
     1385        virtual void visit( FunctionType * ) override final {
     1386
     1387        }
     1388
     1389        virtual void visit( StructInstType * ) override final {
     1390
     1391        }
     1392
     1393        virtual void visit( UnionInstType * ) override final {
     1394
     1395        }
     1396
     1397        virtual void visit( EnumInstType * ) override final {
     1398
     1399        }
     1400
     1401        virtual void visit( TraitInstType * ) override final {
     1402
     1403        }
     1404
     1405        virtual void visit( TypeInstType * ) override final {
     1406
     1407        }
     1408
     1409        virtual void visit( TupleType * ) override final {
     1410
     1411        }
     1412
     1413        virtual void visit( TypeofType * ) override final {
     1414
    25881415        }
    25891416
    25901417        virtual void visit( AttrType * ) override final {
    2591                 assertf( false, "AttrType deprecated in new AST." );
    2592         }
    2593 
    2594         virtual void visit( VarArgsType * old ) override final {
    2595                 this->node = new ast::VarArgsType{ cv( old ) };
    2596         }
    2597 
    2598         virtual void visit( ZeroType * old ) override final {
    2599                 this->node = new ast::ZeroType{ cv( old ) };
    2600         }
    2601 
    2602         virtual void visit( OneType * old ) override final {
    2603                 this->node = new ast::OneType{ cv( old ) };
     1418
     1419        }
     1420
     1421        virtual void visit( VarArgsType * ) override final {
     1422
     1423        }
     1424
     1425        virtual void visit( ZeroType * ) override final {
     1426
     1427        }
     1428
     1429        virtual void visit( OneType * ) override final {
     1430
    26041431        }
    26051432
    26061433        virtual void visit( GlobalScopeType * ) override final {
    2607                 this->node = new ast::GlobalScopeType{};
    2608         }
    2609 
    2610         virtual void visit( Designation * old ) override final {
    2611                 this->node = new ast::Designation(
    2612                         old->location,
    2613                         GET_ACCEPT_V(designators, Expr)
    2614                 );
    2615         }
    2616 
    2617         virtual void visit( SingleInit * old ) override final {
    2618                 this->node = new ast::SingleInit(
    2619                         old->location,
    2620                         GET_ACCEPT_1(value, Expr),
    2621                         (old->get_maybeConstructed()) ? ast::MaybeConstruct : ast::DoConstruct
    2622                 );
    2623         }
    2624 
    2625         virtual void visit( ListInit * old ) override final {
    2626                 this->node = new ast::ListInit(
    2627                         old->location,
    2628                         GET_ACCEPT_V(initializers, Init),
    2629                         GET_ACCEPT_V(designations, Designation),
    2630                         (old->get_maybeConstructed()) ? ast::MaybeConstruct : ast::DoConstruct
    2631                 );
    2632         }
    2633 
    2634         virtual void visit( ConstructorInit * old ) override final {
    2635                 this->node = new ast::ConstructorInit(
    2636                         old->location,
    2637                         GET_ACCEPT_1(ctor, Stmt),
    2638                         GET_ACCEPT_1(dtor, Stmt),
    2639                         GET_ACCEPT_1(init, Init)
    2640                 );
     1434
     1435        }
     1436
     1437        virtual void visit( Designation * ) override final {
     1438
     1439        }
     1440
     1441        virtual void visit( SingleInit * ) override final {
     1442
     1443        }
     1444
     1445        virtual void visit( ListInit * ) override final {
     1446
     1447        }
     1448
     1449        virtual void visit( ConstructorInit * ) override final {
     1450
    26411451        }
    26421452
    26431453        virtual void visit( Constant * ) override final {
    2644                 // Handled in visit( ConstantEpxr * ).
    2645                 // In the new tree, Constant fields are inlined into containing ConstantExpression.
     1454
     1455        }
     1456
     1457        virtual void visit( Attribute * ) override final {
     1458
     1459        }
     1460
     1461        virtual void visit( AttrExpr * ) override final {
     1462
    26461463                assert( 0 );
    2647         }
    2648 
    2649         virtual void visit( Attribute * old ) override final {
    2650                 this->node = new ast::Attribute(
    2651                         old->name,
    2652                         GET_ACCEPT_V( parameters, Expr )
    2653                 );
    2654         }
    2655 
    2656         virtual void visit( AttrExpr * ) override final {
    2657                 assertf( false, "AttrExpr deprecated in new AST." );
    26581464        }
    26591465};
     
    26691475                d->accept( c );
    26701476                decls.emplace_back( c.decl() );
    2671         }
    2672         deleteAll(translationUnit);
     1477                delete d;
     1478        }
    26731479        return decls;
    26741480}
  • src/AST/Decl.cpp

    rd908563 r933f32f  
    7272// --- EnumDecl
    7373
    74 bool EnumDecl::valueOf( const Decl * enumerator, long long& value ) const {
     74bool EnumDecl::valueOf( Decl* enumerator, long long& value ) const {
    7575        if ( enumValues.empty() ) {
    7676                long long crntVal = 0;
    77                 for ( const Decl * member : members ) {
     77                for ( const Decl* member : members ) {
    7878                        const ObjectDecl* field = strict_dynamic_cast< const ObjectDecl* >( member );
    7979                        if ( field->init ) {
     
    8181                                auto result = eval( init->value );
    8282                                if ( ! result.second ) {
    83                                         SemanticError( init->location, ::toString( "Non-constexpr in initialization of "
     83                                        SemanticError( init->location, toString( "Non-constexpr in initialization of "
    8484                                                "enumerator: ", field ) );
    8585                                }
     
    8787                        }
    8888                        if ( enumValues.count( field->name ) != 0 ) {
    89                                 SemanticError( location, ::toString( "Enum ", name, " has multiple members with the "   "name ", field->name ) );
     89                                SemanticError( location, toString( "Enum ", name, " has multiple members with the "     "name ", field->name ) );
    9090                        }
    9191                        enumValues[ field->name ] = crntVal;
  • src/AST/Decl.hpp

    rd908563 r933f32f  
    232232        AggregateDecl* set_body( bool b ) { body = b; return this; }
    233233
     234private:
     235        AggregateDecl * clone() const override = 0;
     236        MUTATE_FRIEND
     237
     238protected:
    234239        /// Produces a name for the kind of aggregate
    235240        virtual std::string typeString() const = 0;
    236 
    237 private:
    238         AggregateDecl * clone() const override = 0;
    239         MUTATE_FRIEND
    240241};
    241242
     
    255256
    256257        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
     258private:
     259        StructDecl * clone() const override { return new StructDecl{ *this }; }
     260        MUTATE_FRIEND
    257261
    258262        std::string typeString() const override { return "struct"; }
    259 
    260 private:
    261         StructDecl * clone() const override { return new StructDecl{ *this }; }
    262         MUTATE_FRIEND
    263263};
    264264
     
    271271
    272272        const Decl * accept( Visitor& v ) const override { return v.visit( this ); }
     273private:
     274        UnionDecl * clone() const override { return new UnionDecl{ *this }; }
     275        MUTATE_FRIEND
    273276
    274277        std::string typeString() const override { return "union"; }
    275 
    276 private:
    277         UnionDecl * clone() const override { return new UnionDecl{ *this }; }
    278         MUTATE_FRIEND
    279278};
    280279
     
    287286
    288287        /// gets the integer value for this enumerator, returning true iff value found
    289         bool valueOf( const Decl * enumerator, long long& value ) const;
    290 
    291         const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
     288        bool valueOf( Decl* enumerator, long long& value ) const;
     289
     290        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
     291private:
     292        EnumDecl * clone() const override { return new EnumDecl{ *this }; }
     293        MUTATE_FRIEND
    292294
    293295        std::string typeString() const override { return "enum"; }
    294 
    295 private:
    296         EnumDecl * clone() const override { return new EnumDecl{ *this }; }
    297         MUTATE_FRIEND
    298296
    299297        /// Map from names to enumerator values; kept private for lazy initialization
     
    309307
    310308        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
     309private:
     310        TraitDecl * clone() const override { return new TraitDecl{ *this }; }
     311        MUTATE_FRIEND
    311312
    312313        std::string typeString() const override { return "trait"; }
    313 
    314 private:
    315         TraitDecl * clone() const override { return new TraitDecl{ *this }; }
    316         MUTATE_FRIEND
    317314};
    318315
     
    332329class StaticAssertDecl : public Decl {
    333330public:
    334         ptr<Expr> cond;
     331        ptr<Expr> condition;
    335332        ptr<ConstantExpr> msg;   // string literal
    336333
    337334        StaticAssertDecl( const CodeLocation & loc, const Expr * condition, const ConstantExpr * msg )
    338         : Decl( loc, "", {}, {} ), cond( condition ), msg( msg ) {}
     335        : Decl( loc, "", {}, {} ), condition( condition ), msg( msg ) {}
    339336
    340337        const StaticAssertDecl * accept( Visitor &v ) const override { return v.visit( this ); }
  • src/AST/DeclReplacer.cpp

    rd908563 r933f32f  
    1414//
    1515
    16 #include "DeclReplacer.hpp"
    17 #include "Expr.hpp"
    18 #include "Type.hpp"
    19 
    20 #include "Pass.hpp"
    21 
    22 namespace ast {
    23 
    24 namespace DeclReplacer {
    25         namespace {
    26                 struct DeclReplacer {
    27                 private:
    28                         const DeclMap & declMap;
    29                         const TypeMap & typeMap;
    30                         bool debug;
    31 
    32                 public:
    33                         DeclReplacer(const DeclMap & declMap, const TypeMap & typeMap, bool debug)
    34                                 : declMap( declMap ), typeMap( typeMap ), debug( debug )
    35                         {}
    36 
    37                         const ast::VariableExpr * previsit( const ast::VariableExpr * );
    38                         const ast::TypeInstType * previsit( const ast::TypeInstType * );
    39                 };
    40         }
    41 
    42         const ast::Node * replace( const ast::Node * node, const DeclMap & declMap, const TypeMap & typeMap, bool debug ) {
    43                 if(!node) return nullptr;
    44                 Pass<DeclReplacer> replacer = { declMap, typeMap, debug };
    45                 return node->accept( replacer );
    46         }
    47 
    48         const ast::Node * replace( const ast::Node * node, const DeclMap & declMap, bool debug ) {
    49                 TypeMap typeMap;
    50                 return replace( node, declMap, typeMap, debug );
    51         }
    52 
    53         const ast::Node * replace( const ast::Node * node, const TypeMap & typeMap, bool debug ) {
    54                 DeclMap declMap;
    55                 return replace( node, declMap, typeMap, debug );
    56         }
    57 
    58         namespace {
    59                 // replace variable with new node from decl map
    60                 const ast::VariableExpr * DeclReplacer::previsit( const VariableExpr * varExpr ) {
    61                         // 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)
    62                         if ( !declMap.count( varExpr->var ) ) return varExpr;
    63 
    64                         auto replacement = declMap.at( varExpr->var );
    65                         if ( debug ) {
    66                                 std::cerr << "replacing variable reference: "
    67                                         << (void*)varExpr->var.get() << " " << varExpr->var
    68                                         << " with " << (void*)replacement << " " << replacement
    69                                         << std::endl;
    70                         }
    71                         auto nexpr = mutate(varExpr);
    72                         nexpr->var = replacement;
    73                         return nexpr;
    74                 }
    75 
    76                 const TypeInstType * DeclReplacer::previsit( const TypeInstType * inst ) {
    77                         if ( !typeMap.count( inst->base ) ) return inst;
    78 
    79                         auto replacement = typeMap.at( inst->base );
    80                         if ( debug ) {
    81                                 std::cerr << "replacing type reference: "
    82                                         << (void*)inst->base.get() << " " << inst->base
    83                                         << " with " << (void*)replacement << " " << replacement
    84                                         << std::endl;
    85                         }
    86                         auto ninst = mutate(inst);
    87                         ninst->base = replacement;
    88                         return ninst;
    89                 }
    90         }
    91 }
    92 
    93 }
     16#warning unimplemented
    9417
    9518// Local Variables: //
  • src/AST/DeclReplacer.hpp

    rd908563 r933f32f  
    2525
    2626        namespace DeclReplacer {
    27                 using DeclMap = std::unordered_map< const DeclWithType *, const DeclWithType * >;
    28                 using TypeMap = std::unordered_map< const TypeDecl *, const TypeDecl * >;
     27                using DeclMap = std::unordered_map< DeclWithType*, DeclWithType* >;
     28                using TypeMap = std::unordered_map< TypeDecl*, TypeDecl* >;
    2929
    30                 const Node * replace( const Node * node, const DeclMap & declMap, bool debug = false );
    31                 const Node * replace( const Node * node, const TypeMap & typeMap, bool debug = false );
    32                 const Node * replace( const Node * node, const DeclMap & declMap, const TypeMap & typeMap, bool debug = false );
     30                void replace( Node* node, const DeclMap& declMap );
     31                void replace( Node* node, const TypeMap& typeMap );
     32                void replace( Node* node, const DeclMap& declMap, const TypeMap& typeMap );
    3333        }
    3434}
  • src/AST/Expr.cpp

    rd908563 r933f32f  
    2020#include <vector>
    2121
    22 #include "GenericSubstitution.hpp"
    2322#include "Stmt.hpp"
    2423#include "Type.hpp"
    25 #include "TypeSubstitution.hpp"
    26 #include "Common/utility.h"
    2724#include "Common/SemanticError.h"
    2825#include "GenPoly/Lvalue.h"        // for referencesPermissable
     
    159156        assert( aggregate->result );
    160157
    161         // take ownership of member type
    162         result = mem->get_type();
    163         // substitute aggregate generic parameters into member type
    164         genericSubsitution( aggregate->result ).apply( result );
    165         // ensure lvalue and appropriate restrictions from aggregate type
    166         result.get_and_mutate()->qualifiers |= aggregate->result->qualifiers | CV::Lvalue;
     158        assert(!"unimplemented; need TypeSubstitution, genericSubstitution");
    167159}
    168160
     
    241233                        FixedLen, DynamicDim },
    242234                std::string{"\""} + s + "\"",
    243                 (unsigned long long)0,
    244                 ConstantExpr::String };
     235                (unsigned long long)0 };
    245236}
    246237
     
    341332        stmts.emplace_back( new ExprStmt{ loc, tupleExpr } );
    342333        stmtExpr = new StmtExpr{ loc, new CompoundStmt{ loc, std::move(stmts) } };
    343 }
    344 
    345 TupleAssignExpr::TupleAssignExpr(
    346         const CodeLocation & loc, const Type * result, const StmtExpr * s )
    347 : Expr( loc, result ), stmtExpr() {
    348         stmtExpr = s;
    349334}
    350335
  • src/AST/Expr.hpp

    rd908563 r933f32f  
    3030#define MUTATE_FRIEND template<typename node_t> friend node_t * mutate(const node_t * node);
    3131
    32 class ConverterOldToNew;
    33 
    3432namespace ast {
    3533
     
    108106                        case Params: assert(!"Cannot return to resnSlots from Params");
    109107                        }
    110                         return *((ResnSlots*)nullptr);
    111                 }
    112 
    113                 const ResnSlots& resnSlotsConst() const {
    114                         if (mode == Slots) {
    115                                 return data.resnSlots;
    116                         }
    117                         assert(!"Mode was not already resnSlots");
    118                         return *((ResnSlots*)nullptr);
    119108                }
    120109
     
    125114                        case Params: return data.inferParams;
    126115                        }
    127                         return *((InferredParams*)nullptr);
    128                 }
    129 
    130                 const InferredParams& inferParamsConst() const {
    131                         if (mode == Params) {
    132                                 return data.inferParams;
    133                         }
    134                         assert(!"Mode was not already Params");
    135                         return *((InferredParams*)nullptr);
    136116                }
    137117        };
     
    337317public:
    338318        std::string rep;
    339         enum Kind { Integer, FloatingPoint, String } kind;
    340319
    341320        ConstantExpr(
    342                 const CodeLocation & loc, const Type * ty, const std::string & r, unsigned long long v,
    343                 Kind k = Integer )
    344         : Expr( loc, ty ), val( v ), rep( r ), kind( k ) {}
     321                const CodeLocation & loc, const Type * ty, const std::string & r, unsigned long long v )
     322        : Expr( loc, ty ), val( v ), rep( r ) {}
    345323        ConstantExpr( const CodeLocation & loc, const Type * ty, const std::string & r, double v )
    346         : Expr( loc, ty ), val( v ), rep( r ), kind( FloatingPoint ) {}
     324        : Expr( loc, ty ), val( v ), rep( r ) {}
    347325
    348326        /// Gets the value of this constant as an integer
     
    525503};
    526504
    527 /// The application of a function to a set of parameters, along with a set of copy constructor
     505/// The application of a function to a set of parameters, along with a set of copy constructor 
    528506/// calls, one for each argument
    529507class ImplicitCopyCtorExpr final : public Expr {
    530508public:
    531509        ptr<ApplicationExpr> callExpr;
     510        std::vector<ptr<ObjectDecl>> tempDecls;
     511        std::vector<ptr<ObjectDecl>> returnDecls;
     512        std::vector<ptr<ObjectDecl>> dtors;
    532513
    533514        ImplicitCopyCtorExpr( const CodeLocation& loc, const ApplicationExpr * call )
    534         : Expr( loc, call->result ) { assert( call ); }
     515        : Expr( loc, call->result ), tempDecls(), returnDecls(), dtors() { assert( call ); }
    535516
    536517        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
     
    622603};
    623604
    624 /// A multiple- or mass-assignment operation, or a tuple ctor/dtor expression.
    625 /// multiple-assignment: both sides of the assignment have tuple type,
     605/// A multiple- or mass-assignment operation, or a tuple ctor/dtor expression. 
     606/// multiple-assignment: both sides of the assignment have tuple type, 
    626607///     e.g. `[a, b, c] = [d, e, f];`
    627608/// mass-assignment: left-hand side has tuple type and right-hand side does not:
     
    631612        ptr<StmtExpr> stmtExpr;
    632613
    633         TupleAssignExpr(
    634                 const CodeLocation & loc, std::vector<ptr<Expr>> && assigns,
     614        TupleAssignExpr( 
     615                const CodeLocation & loc, std::vector<ptr<Expr>> && assigns, 
    635616                std::vector<ptr<ObjectDecl>> && tempDecls );
    636 
    637         const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
    638 
    639         friend class ::ConverterOldToNew;
    640 
     617       
     618        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
    641619private:
    642620        TupleAssignExpr * clone() const override { return new TupleAssignExpr{ *this }; }
    643     TupleAssignExpr( const CodeLocation & loc, const Type * result, const StmtExpr * s );
    644 
    645621        MUTATE_FRIEND
    646622};
  • src/AST/Fwd.hpp

    rd908563 r933f32f  
    131131class TypeSubstitution;
    132132
     133std::string toString( const Node * );
     134
     135template < typename ... Params >
     136std::string toString( const Params & ... params );
     137
    133138typedef unsigned int UniqueId;
    134139
  • src/AST/Label.hpp

    rd908563 r933f32f  
    3939
    4040        operator std::string () const { return name; }
    41         bool empty() const { return name.empty(); }
     41        bool empty() { return name.empty(); }
    4242};
    4343
  • src/AST/Node.cpp

    rd908563 r933f32f  
    1616#include "Node.hpp"
    1717#include "Fwd.hpp"
    18 
    19 #include <iostream>
    2018
    2119#include "Attribute.hpp"
     
    2725#include "TypeSubstitution.hpp"
    2826
    29 #include "Print.hpp"
    30 
    3127template< typename node_t, enum ast::Node::ref_type ref_t >
    3228void ast::ptr_base<node_t, ref_t>::_inc( const node_t * node ) { node->increment(ref_t); }
     
    3531void ast::ptr_base<node_t, ref_t>::_dec( const node_t * node ) { node->decrement(ref_t); }
    3632
     33/// Sets this pointer to a mutated version of a pointer (possibly) owned elsehere.
     34/// Returns a mutable version of the pointer in this node.
    3735template< typename node_t, enum ast::Node::ref_type ref_t >
    38 node_t * ast::ptr_base<node_t, ref_t>::get_and_mutate() {
     36node_t * ast::ptr_base<node_t, ref_t>::set_and_mutate( const node_t * n ) {
     37        // ensure ownership of `n` by this node to avoid spurious single-owner mutates
     38        assign( n );
    3939        // get mutable version of `n`
    4040        auto r = mutate( node );
     
    4242        assign( r );
    4343        return r;
    44 }
    45 
    46 template< typename node_t, enum ast::Node::ref_type ref_t >
    47 node_t * ast::ptr_base<node_t, ref_t>::set_and_mutate( const node_t * n ) {
    48         // ensure ownership of `n` by this node to avoid spurious single-owner mutates
    49         assign( n );
    50         // return mutable version
    51         return get_and_mutate();
    52 }
    53 
    54 std::ostream & ast::operator<< ( std::ostream & out, const ast::Node * node ) {
    55         print(out, node);
    56         return out;
    5744}
    5845
  • src/AST/Node.hpp

    rd908563 r933f32f  
    1010// Created On       : Wed May 8 10:27:04 2019
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thu May 23 16:00:00 2019
    13 // Update Count     : 4
     12// Last Modified On : Wed May 15 16:02:00 2019
     13// Update Count     : 3
    1414//
    1515
     
    9494std::ostream& operator<< ( std::ostream& out, const Node * node );
    9595
    96 /// Call a visitor on a possibly-null node
    97 template<typename node_t>
    98 auto maybe_accept( const node_t * n, Visitor & v ) -> decltype( n->accept(v) ) {
    99         return n ? n->accept( v ) : nullptr;
    100 }
    101 
    10296/// Base class for the smart pointer types
    10397/// should never really be used.
     
    108102        ptr_base( const node_t * n ) : node(n) { if( node ) _inc(node); }
    109103        ~ptr_base() { if( node ) _dec(node); }
    110 
    111         ptr_base( const ptr_base & o ) : node(o.node) {
    112                 if( node ) _inc(node);
    113         }
    114 
    115         ptr_base( ptr_base && o ) : node(o.node) {
    116                 if( node ) _inc(node);
    117         }
    118104
    119105        template< enum Node::ref_type o_ref_t >
     
    129115        template<typename o_node_t>
    130116        ptr_base & operator=( const o_node_t * node ) {
    131                 assign( node ? strict_dynamic_cast<const node_t *>(node) : nullptr );
    132                 return *this;
    133         }
    134 
    135         ptr_base & operator=( const ptr_base & o ) {
    136                 assign(o.node);
    137                 return *this;
    138         }
    139 
    140         ptr_base & operator=( ptr_base && o ) {
    141                 assign(o.node);
     117                assign(strict_dynamic_cast<const node_t *>(node));
    142118                return *this;
    143119        }
     
    164140        template<typename o_node_t>
    165141        const o_node_t * as() const { return dynamic_cast<const o_node_t *>(node); }
    166 
    167         /// Returns a mutable version of the pointer in this node.
    168         node_t * get_and_mutate();
    169142
    170143        /// Sets this pointer to a mutated version of a pointer (possibly) owned elsehere.
  • src/AST/Pass.hpp

    rd908563 r933f32f  
    178178        const ast::TypeSubstitution * visit( const ast::TypeSubstitution     * ) override final;
    179179
    180         template<typename pass_type>
    181         friend void acceptAll( std::list< ptr<Decl> > & decls, Pass<pass_type>& visitor );
     180        friend void acceptAll( std::list< ptr<Decl> > & decls, Pass<pass_t>& visitor );
    182181private:
    183182
     
    224223};
    225224
    226 /// Apply a pass to an entire translation unit
    227225template<typename pass_t>
    228226void accept_all( std::list< ast::ptr<ast::Decl> > &, ast::Pass<pass_t> & visitor );
  • src/AST/Pass.impl.hpp

    rd908563 r933f32f  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // ast::Pass.impl.hpp --
     7// Pass.impl.hpp --
    88//
    99// Author           : Thierry Delisle
     
    121121        template< typename pass_t >
    122122        template< typename node_t >
    123         auto ast::Pass< pass_t >::call_accept( const node_t * node )
     123        auto Pass< pass_t >::call_accept( const node_t * node )
    124124                -> typename std::enable_if<
    125125                                !std::is_base_of<ast::Expr, node_t>::value &&
     
    139139
    140140        template< typename pass_t >
    141         const ast::Expr * ast::Pass< pass_t >::call_accept( const ast::Expr * expr ) {
     141        const ast::Expr * Pass< pass_t >::call_accept( const ast::Expr * expr ) {
    142142                __pedantic_pass_assert( __visit_children() );
    143143                __pedantic_pass_assert( expr );
     
    152152
    153153        template< typename pass_t >
    154         const ast::Stmt * ast::Pass< pass_t >::call_accept( const ast::Stmt * stmt ) {
     154        const ast::Stmt * Pass< pass_t >::call_accept( const ast::Stmt * stmt ) {
    155155                __pedantic_pass_assert( __visit_children() );
    156156                __pedantic_pass_assert( stmt );
     
    204204        template< typename pass_t >
    205205        template< template <class...> class container_t >
    206         container_t< ptr<Stmt> > ast::Pass< pass_t >::call_accept( const container_t< ptr<Stmt> > & statements ) {
     206        container_t< ptr<Stmt> > Pass< pass_t >::call_accept( const container_t< ptr<Stmt> > & statements ) {
    207207                __pedantic_pass_assert( __visit_children() );
    208208                if( statements.empty() ) return {};
     
    270270        template< typename pass_t >
    271271        template< template <class...> class container_t, typename node_t >
    272         container_t< ast::ptr<node_t> > ast::Pass< pass_t >::call_accept( const container_t< ast::ptr<node_t> > & container ) {
     272        container_t< ast::ptr<node_t> > Pass< pass_t >::call_accept( const container_t< ast::ptr<node_t> > & container ) {
    273273                __pedantic_pass_assert( __visit_children() );
    274274                if( container.empty() ) return {};
     
    301301        template< typename pass_t >
    302302        template<typename node_t, typename parent_t, typename child_t>
    303         void ast::Pass< pass_t >::maybe_accept(
     303        void Pass< pass_t >::maybe_accept(
    304304                const node_t * & parent,
    305305                child_t parent_t::*child
     
    571571        __pass::indexer::addType( pass, 0, node );
    572572
    573         VISIT( maybe_accept( node, &TypedefDecl::assertions ); )
     573        maybe_accept( node, &TypedefDecl::assertions );
    574574
    575575        VISIT_END( Decl, node );
     
    596596
    597597        VISIT(
    598                 maybe_accept( node, &StaticAssertDecl::cond );
    599                 maybe_accept( node, &StaticAssertDecl::msg  );
     598                maybe_accept( node, &StaticAssertDecl::condition );
     599                maybe_accept( node, &StaticAssertDecl::msg       );
    600600        )
    601601
     
    626626// ExprStmt
    627627template< typename pass_t >
    628 const ast::Stmt * ast::Pass< pass_t >::visit( const ast::ExprStmt * node ) {
     628const ast::Stmt * ast::Pass< pass_t >::visit( const ExprStmt * node ) {
    629629        VISIT_START( node );
    630630
     
    666666const ast::Stmt * ast::Pass< pass_t >::visit( const ast::IfStmt * node ) {
    667667        VISIT_START( node );
    668 
    669668        VISIT({
    670669                // if statements introduce a level of scope (for the initialization)
     
    675674                maybe_accept( node, &IfStmt::elsePart );
    676675        })
    677 
    678676        VISIT_END( Stmt, node );
    679677}
     
    682680// WhileStmt
    683681template< typename pass_t >
    684 const ast::Stmt * ast::Pass< pass_t >::visit( const ast::WhileStmt * node ) {
     682const ast::Stmt * ast::Pass< pass_t >::visit( const WhileStmt * node ) {
    685683        VISIT_START( node );
    686684
     
    835833                // }
    836834
    837         VISIT({
    838                 std::vector<WaitForStmt::Clause> new_clauses;
    839                 new_clauses.reserve( node->clauses.size() );
    840                 bool mutated = false;
    841                 for( const auto & clause : node->clauses ) {
    842 
    843                         const Expr * func = clause.target.func ? clause.target.func->accept(*this) : nullptr;
    844                         if(func != clause.target.func) mutated = true;
    845 
    846                         std::vector<ptr<Expr>> new_args;
    847                         new_args.reserve(clause.target.args.size());
    848                         for( const auto & arg : clause.target.args ) {
    849                                 auto a = arg->accept(*this);
    850                                 new_args.push_back( a );
    851                                 if( a != arg ) mutated = true;
    852                         }
    853 
    854                         const Stmt * stmt = clause.stmt ? clause.stmt->accept(*this) : nullptr;
    855                         if(stmt != clause.stmt) mutated = true;
    856 
    857                         const Expr * cond = clause.cond ? clause.cond->accept(*this) : nullptr;
    858                         if(cond != clause.cond) mutated = true;
    859 
    860                         new_clauses.push_back( WaitForStmt::Clause{ {func, std::move(new_args) }, stmt, cond } );
    861                 }
    862 
    863                 if(mutated) {
    864                         auto n = mutate(node);
    865                         n->clauses = std::move( new_clauses );
    866                         node = n;
    867                 }
    868         })
    869 
    870835        #define maybe_accept(field) \
    871836                if(node->field) { \
     
    945910}
    946911
    947 //--------------------------------------------------------------------------
    948 // ApplicationExpr
    949 template< typename pass_t >
    950 const ast::Expr * ast::Pass< pass_t >::visit( const ast::ApplicationExpr * node ) {
    951         VISIT_START( node );
    952 
    953         VISIT(
    954                 {
    955                         guard_indexer guard { *this };
    956                         maybe_accept( node, &ApplicationExpr::result );
    957                 }
    958                 maybe_accept( node, &ApplicationExpr::func );
    959                 maybe_accept( node, &ApplicationExpr::args );
    960         )
    961 
    962         VISIT_END( Expr, node );
    963 }
    964 
    965 //--------------------------------------------------------------------------
    966 // UntypedExpr
    967 template< typename pass_t >
    968 const ast::Expr * ast::Pass< pass_t >::visit( const ast::UntypedExpr * node ) {
    969         VISIT_START( node );
    970 
    971         VISIT(
    972                 {
    973                         guard_indexer guard { *this };
    974                         maybe_accept( node, &UntypedExpr::result );
    975                 }
    976 
    977                 maybe_accept( node, &UntypedExpr::args );
    978         )
    979 
    980         VISIT_END( Expr, node );
    981 }
    982 
    983 //--------------------------------------------------------------------------
    984 // NameExpr
    985 template< typename pass_t >
    986 const ast::Expr * ast::Pass< pass_t >::visit( const ast::NameExpr * node ) {
    987         VISIT_START( node );
    988 
    989         VISIT({
    990                 guard_indexer guard { *this };
    991                 maybe_accept( node, &NameExpr::result );
    992         })
    993 
    994         VISIT_END( Expr, node );
    995 }
    996 
    997 //--------------------------------------------------------------------------
    998 // CastExpr
    999 template< typename pass_t >
    1000 const ast::Expr * ast::Pass< pass_t >::visit( const ast::CastExpr * node ) {
    1001         VISIT_START( node );
    1002 
    1003         VISIT({
    1004                         guard_indexer guard { *this };
    1005                         maybe_accept( node, &CastExpr::result );
    1006                 }
    1007                 maybe_accept( node, &CastExpr::arg );
    1008         )
    1009 
    1010         VISIT_END( Expr, node );
    1011 }
    1012 
    1013 //--------------------------------------------------------------------------
    1014 // KeywordCastExpr
    1015 template< typename pass_t >
    1016 const ast::Expr * ast::Pass< pass_t >::visit( const ast::KeywordCastExpr * node ) {
    1017         VISIT_START( node );
    1018 
    1019         VISIT({
    1020                         guard_indexer guard { *this };
    1021                         maybe_accept( node, &KeywordCastExpr::result );
    1022                 }
    1023                 maybe_accept( node, &KeywordCastExpr::arg );
    1024         )
    1025 
    1026         VISIT_END( Expr, node );
    1027 }
    1028 
    1029 //--------------------------------------------------------------------------
    1030 // VirtualCastExpr
    1031 template< typename pass_t >
    1032 const ast::Expr * ast::Pass< pass_t >::visit( const ast::VirtualCastExpr * node ) {
    1033         VISIT_START( node );
    1034 
    1035         VISIT({
    1036                         guard_indexer guard { *this };
    1037                         maybe_accept( node, &VirtualCastExpr::result );
    1038                 }
    1039                 maybe_accept( node, &VirtualCastExpr::arg );
    1040         )
    1041 
    1042         VISIT_END( Expr, node );
    1043 }
    1044 
    1045 //--------------------------------------------------------------------------
    1046 // AddressExpr
    1047 template< typename pass_t >
    1048 const ast::Expr * ast::Pass< pass_t >::visit( const ast::AddressExpr * node ) {
    1049         VISIT_START( node );
    1050 
    1051         VISIT({
    1052                         guard_indexer guard { *this };
    1053                         maybe_accept( node, &AddressExpr::result );
    1054                 }
    1055                 maybe_accept( node, &AddressExpr::arg );
    1056         )
    1057 
    1058         VISIT_END( Expr, node );
    1059 }
    1060 
    1061 //--------------------------------------------------------------------------
    1062 // LabelAddressExpr
    1063 template< typename pass_t >
    1064 const ast::Expr * ast::Pass< pass_t >::visit( const ast::LabelAddressExpr * node ) {
    1065         VISIT_START( node );
    1066 
    1067         VISIT({
    1068                 guard_indexer guard { *this };
    1069                 maybe_accept( node, &LabelAddressExpr::result );
    1070         })
    1071 
    1072         VISIT_END( Expr, node );
    1073 }
    1074 
    1075 //--------------------------------------------------------------------------
    1076 // UntypedMemberExpr
    1077 template< typename pass_t >
    1078 const ast::Expr * ast::Pass< pass_t >::visit( const ast::UntypedMemberExpr * node ) {
    1079         VISIT_START( node );
    1080 
    1081         VISIT({
    1082                         guard_indexer guard { *this };
    1083                         maybe_accept( node, &UntypedMemberExpr::result );
    1084                 }
    1085                 maybe_accept( node, &UntypedMemberExpr::aggregate );
    1086                 maybe_accept( node, &UntypedMemberExpr::member    );
    1087         )
    1088 
    1089         VISIT_END( Expr, node );
    1090 }
    1091 
    1092 //--------------------------------------------------------------------------
    1093 // MemberExpr
    1094 template< typename pass_t >
    1095 const ast::Expr * ast::Pass< pass_t >::visit( const ast::MemberExpr * node ) {
    1096         VISIT_START( node );
    1097 
    1098         VISIT({
    1099                         guard_indexer guard { *this };
    1100                         maybe_accept( node, &MemberExpr::result );
    1101                 }
    1102                 maybe_accept( node, &MemberExpr::aggregate );
    1103         )
    1104 
    1105         VISIT_END( Expr, node );
    1106 }
    1107 
    1108 //--------------------------------------------------------------------------
    1109 // VariableExpr
    1110 template< typename pass_t >
    1111 const ast::Expr * ast::Pass< pass_t >::visit( const ast::VariableExpr * node ) {
    1112         VISIT_START( node );
    1113 
    1114         VISIT({
    1115                 guard_indexer guard { *this };
    1116                 maybe_accept( node, &VariableExpr::result );
    1117         })
    1118 
    1119         VISIT_END( Expr, node );
    1120 }
    1121 
    1122 //--------------------------------------------------------------------------
    1123 // ConstantExpr
    1124 template< typename pass_t >
    1125 const ast::Expr * ast::Pass< pass_t >::visit( const ast::ConstantExpr * node ) {
    1126         VISIT_START( node );
    1127 
    1128         VISIT({
    1129                 guard_indexer guard { *this };
    1130                 maybe_accept( node, &ConstantExpr::result );
    1131         })
    1132 
    1133         VISIT_END( Expr, node );
    1134 }
    1135 
    1136 //--------------------------------------------------------------------------
    1137 // SizeofExpr
    1138 template< typename pass_t >
    1139 const ast::Expr * ast::Pass< pass_t >::visit( const ast::SizeofExpr * node ) {
    1140         VISIT_START( node );
    1141 
    1142         VISIT({
    1143                         guard_indexer guard { *this };
    1144                         maybe_accept( node, &SizeofExpr::result );
    1145                 }
    1146                 if ( node->type ) {
    1147                         maybe_accept( node, &SizeofExpr::type );
    1148                 } else {
    1149                         maybe_accept( node, &SizeofExpr::expr );
    1150                 }
    1151         )
    1152 
    1153         VISIT_END( Expr, node );
    1154 }
    1155 
    1156 //--------------------------------------------------------------------------
    1157 // AlignofExpr
    1158 template< typename pass_t >
    1159 const ast::Expr * ast::Pass< pass_t >::visit( const ast::AlignofExpr * node ) {
    1160         VISIT_START( node );
    1161 
    1162         VISIT({
    1163                         guard_indexer guard { *this };
    1164                         maybe_accept( node, &AlignofExpr::result );
    1165                 }
    1166                 if ( node->type ) {
    1167                         maybe_accept( node, &AlignofExpr::type );
    1168                 } else {
    1169                         maybe_accept( node, &AlignofExpr::expr );
    1170                 }
    1171         )
    1172 
    1173         VISIT_END( Expr, node );
    1174 }
    1175 
    1176 //--------------------------------------------------------------------------
    1177 // UntypedOffsetofExpr
    1178 template< typename pass_t >
    1179 const ast::Expr * ast::Pass< pass_t >::visit( const ast::UntypedOffsetofExpr * node ) {
    1180         VISIT_START( node );
    1181 
    1182         VISIT({
    1183                         guard_indexer guard { *this };
    1184                         maybe_accept( node, &UntypedOffsetofExpr::result );
    1185                 }
    1186                 maybe_accept( node, &UntypedOffsetofExpr::type   );
    1187         )
    1188 
    1189         VISIT_END( Expr, node );
    1190 }
    1191 
    1192 //--------------------------------------------------------------------------
    1193 // OffsetofExpr
    1194 template< typename pass_t >
    1195 const ast::Expr * ast::Pass< pass_t >::visit( const ast::OffsetofExpr * node ) {
    1196         VISIT_START( node );
    1197 
    1198         VISIT({
    1199                         guard_indexer guard { *this };
    1200                         maybe_accept( node, &OffsetofExpr::result );
    1201                 }
    1202                 maybe_accept( node, &OffsetofExpr::type   );
    1203         )
    1204 
    1205         VISIT_END( Expr, node );
    1206 }
    1207 
    1208 //--------------------------------------------------------------------------
    1209 // OffsetPackExpr
    1210 template< typename pass_t >
    1211 const ast::Expr * ast::Pass< pass_t >::visit( const ast::OffsetPackExpr * node ) {
    1212         VISIT_START( node );
    1213 
    1214         VISIT({
    1215                         guard_indexer guard { *this };
    1216                         maybe_accept( node, &OffsetPackExpr::result );
    1217                 }
    1218                 maybe_accept( node, &OffsetPackExpr::type   );
    1219         )
    1220 
    1221         VISIT_END( Expr, node );
    1222 }
    1223 
    1224 //--------------------------------------------------------------------------
    1225 // LogicalExpr
    1226 template< typename pass_t >
    1227 const ast::Expr * ast::Pass< pass_t >::visit( const ast::LogicalExpr * node ) {
    1228         VISIT_START( node );
    1229 
    1230         VISIT({
    1231                         guard_indexer guard { *this };
    1232                         maybe_accept( node, &LogicalExpr::result );
    1233                 }
    1234                 maybe_accept( node, &LogicalExpr::arg1 );
    1235                 maybe_accept( node, &LogicalExpr::arg2 );
    1236         )
    1237 
    1238         VISIT_END( Expr, node );
    1239 }
    1240 
    1241 //--------------------------------------------------------------------------
    1242 // ConditionalExpr
    1243 template< typename pass_t >
    1244 const ast::Expr * ast::Pass< pass_t >::visit( const ast::ConditionalExpr * node ) {
    1245         VISIT_START( node );
    1246 
    1247         VISIT({
    1248                         guard_indexer guard { *this };
    1249                         maybe_accept( node, &ConditionalExpr::result );
    1250                 }
    1251                 maybe_accept( node, &ConditionalExpr::arg1 );
    1252                 maybe_accept( node, &ConditionalExpr::arg2 );
    1253                 maybe_accept( node, &ConditionalExpr::arg3 );
    1254         )
    1255 
    1256         VISIT_END( Expr, node );
    1257 }
    1258 
    1259 //--------------------------------------------------------------------------
    1260 // CommaExpr
    1261 template< typename pass_t >
    1262 const ast::Expr * ast::Pass< pass_t >::visit( const ast::CommaExpr * node ) {
    1263         VISIT_START( node );
    1264 
    1265         VISIT({
    1266                         guard_indexer guard { *this };
    1267                         maybe_accept( node, &CommaExpr::result );
    1268                 }
    1269                 maybe_accept( node, &CommaExpr::arg1 );
    1270                 maybe_accept( node, &CommaExpr::arg2 );
    1271         )
    1272 
    1273         VISIT_END( Expr, node );
    1274 }
    1275 
    1276 //--------------------------------------------------------------------------
    1277 // TypeExpr
    1278 template< typename pass_t >
    1279 const ast::Expr * ast::Pass< pass_t >::visit( const ast::TypeExpr * node ) {
    1280         VISIT_START( node );
    1281 
    1282         VISIT({
    1283                         guard_indexer guard { *this };
    1284                         maybe_accept( node, &TypeExpr::result );
    1285                 }
    1286                 maybe_accept( node, &TypeExpr::type );
    1287         )
    1288 
    1289         VISIT_END( Expr, node );
    1290 }
    1291 
    1292 //--------------------------------------------------------------------------
    1293 // AsmExpr
    1294 template< typename pass_t >
    1295 const ast::Expr * ast::Pass< pass_t >::visit( const ast::AsmExpr * node ) {
    1296         VISIT_START( node );
    1297 
    1298         VISIT({
    1299                         guard_indexer guard { *this };
    1300                         maybe_accept( node, &AsmExpr::result );
    1301                 }
    1302                 maybe_accept( node, &AsmExpr::inout      );
    1303                 maybe_accept( node, &AsmExpr::constraint );
    1304                 maybe_accept( node, &AsmExpr::operand    );
    1305         )
    1306 
    1307         VISIT_END( Expr, node );
    1308 }
    1309 
    1310 //--------------------------------------------------------------------------
    1311 // ImplicitCopyCtorExpr
    1312 template< typename pass_t >
    1313 const ast::Expr * ast::Pass< pass_t >::visit( const ast::ImplicitCopyCtorExpr * node ) {
    1314         VISIT_START( node );
    1315 
    1316         VISIT({
    1317                         guard_indexer guard { *this };
    1318                         maybe_accept( node, &ImplicitCopyCtorExpr::result );
    1319                 }
    1320                 maybe_accept( node, &ImplicitCopyCtorExpr::callExpr    );
    1321         )
    1322 
    1323         VISIT_END( Expr, node );
    1324 }
    1325 
    1326 //--------------------------------------------------------------------------
    1327 // ConstructorExpr
    1328 template< typename pass_t >
    1329 const ast::Expr * ast::Pass< pass_t >::visit( const ast::ConstructorExpr * node ) {
    1330         VISIT_START( node );
    1331 
    1332         VISIT({
    1333                         guard_indexer guard { *this };
    1334                         maybe_accept( node, &ConstructorExpr::result );
    1335                 }
    1336                 maybe_accept( node, &ConstructorExpr::callExpr );
    1337         )
    1338 
    1339         VISIT_END( Expr, node );
    1340 }
    1341 
    1342 //--------------------------------------------------------------------------
    1343 // CompoundLiteralExpr
    1344 template< typename pass_t >
    1345 const ast::Expr * ast::Pass< pass_t >::visit( const ast::CompoundLiteralExpr * node ) {
    1346         VISIT_START( node );
    1347 
    1348         VISIT({
    1349                         guard_indexer guard { *this };
    1350                         maybe_accept( node, &CompoundLiteralExpr::result );
    1351                 }
    1352                 maybe_accept( node, &CompoundLiteralExpr::init );
    1353         )
    1354 
    1355         VISIT_END( Expr, node );
    1356 }
    1357 
    1358 //--------------------------------------------------------------------------
    1359 // RangeExpr
    1360 template< typename pass_t >
    1361 const ast::Expr * ast::Pass< pass_t >::visit( const ast::RangeExpr * node ) {
    1362         VISIT_START( node );
    1363 
    1364         VISIT({
    1365                         guard_indexer guard { *this };
    1366                         maybe_accept( node, &RangeExpr::result );
    1367                 }
    1368                 maybe_accept( node, &RangeExpr::low    );
    1369                 maybe_accept( node, &RangeExpr::high   );
    1370         )
    1371 
    1372         VISIT_END( Expr, node );
    1373 }
    1374 
    1375 //--------------------------------------------------------------------------
    1376 // UntypedTupleExpr
    1377 template< typename pass_t >
    1378 const ast::Expr * ast::Pass< pass_t >::visit( const ast::UntypedTupleExpr * node ) {
    1379         VISIT_START( node );
    1380 
    1381         VISIT({
    1382                         guard_indexer guard { *this };
    1383                         maybe_accept( node, &UntypedTupleExpr::result );
    1384                 }
    1385                 maybe_accept( node, &UntypedTupleExpr::exprs  );
    1386         )
    1387 
    1388         VISIT_END( Expr, node );
    1389 }
    1390 
    1391 //--------------------------------------------------------------------------
    1392 // TupleExpr
    1393 template< typename pass_t >
    1394 const ast::Expr * ast::Pass< pass_t >::visit( const ast::TupleExpr * node ) {
    1395         VISIT_START( node );
    1396 
    1397         VISIT({
    1398                         guard_indexer guard { *this };
    1399                         maybe_accept( node, &TupleExpr::result );
    1400                 }
    1401                 maybe_accept( node, &TupleExpr::exprs  );
    1402         )
    1403 
    1404         VISIT_END( Expr, node );
    1405 }
    1406 
    1407 //--------------------------------------------------------------------------
    1408 // TupleIndexExpr
    1409 template< typename pass_t >
    1410 const ast::Expr * ast::Pass< pass_t >::visit( const ast::TupleIndexExpr * node ) {
    1411         VISIT_START( node );
    1412 
    1413         VISIT({
    1414                         guard_indexer guard { *this };
    1415                         maybe_accept( node, &TupleIndexExpr::result );
    1416                 }
    1417                 maybe_accept( node, &TupleIndexExpr::tuple  );
    1418         )
    1419 
    1420         VISIT_END( Expr, node );
    1421 }
    1422 
    1423 //--------------------------------------------------------------------------
    1424 // TupleAssignExpr
    1425 template< typename pass_t >
    1426 const ast::Expr * ast::Pass< pass_t >::visit( const ast::TupleAssignExpr * node ) {
    1427         VISIT_START( node );
    1428 
    1429         VISIT({
    1430                         guard_indexer guard { *this };
    1431                         maybe_accept( node, &TupleAssignExpr::result );
    1432                 }
    1433                 maybe_accept( node, &TupleAssignExpr::stmtExpr );
    1434         )
    1435 
    1436         VISIT_END( Expr, node );
    1437 }
    1438 
    1439 //--------------------------------------------------------------------------
    1440 // StmtExpr
    1441 template< typename pass_t >
    1442 const ast::Expr * ast::Pass< pass_t >::visit( const ast::StmtExpr * node ) {
    1443         VISIT_START( node );
    1444 
    1445         VISIT(// don't want statements from outer CompoundStmts to be added to this StmtExpr
    1446                 // get the stmts that will need to be spliced in
    1447                 auto stmts_before = __pass::stmtsToAddBefore( pass, 0);
    1448                 auto stmts_after  = __pass::stmtsToAddAfter ( pass, 0);
    1449 
    1450                 // These may be modified by subnode but most be restored once we exit this statemnet.
    1451                 ValueGuardPtr< const ast::TypeSubstitution * > __old_env( __pass::env( pass, 0) );
    1452                 ValueGuardPtr< typename std::remove_pointer< decltype(stmts_before) >::type > __old_decls_before( stmts_before );
    1453                 ValueGuardPtr< typename std::remove_pointer< decltype(stmts_after ) >::type > __old_decls_after ( stmts_after  );
    1454 
    1455                 {
    1456                         guard_indexer guard { *this };
    1457                         maybe_accept( node, &StmtExpr::result );
    1458                 }
    1459                 maybe_accept( node, &StmtExpr::stmts       );
    1460                 maybe_accept( node, &StmtExpr::returnDecls );
    1461                 maybe_accept( node, &StmtExpr::dtors       );
    1462         )
    1463 
    1464         VISIT_END( Expr, node );
    1465 }
    1466 
    1467 //--------------------------------------------------------------------------
    1468 // UniqueExpr
    1469 template< typename pass_t >
    1470 const ast::Expr * ast::Pass< pass_t >::visit( const ast::UniqueExpr * node ) {
    1471         VISIT_START( node );
    1472 
    1473         VISIT({
    1474                         guard_indexer guard { *this };
    1475                         maybe_accept( node, &UniqueExpr::result );
    1476                 }
    1477                 maybe_accept( node, &UniqueExpr::expr   );
    1478         )
    1479 
    1480         VISIT_END( Expr, node );
    1481 }
    1482 
    1483 //--------------------------------------------------------------------------
    1484 // UntypedInitExpr
    1485 template< typename pass_t >
    1486 const ast::Expr * ast::Pass< pass_t >::visit( const ast::UntypedInitExpr * node ) {
    1487         VISIT_START( node );
    1488 
    1489         VISIT({
    1490                         guard_indexer guard { *this };
    1491                         maybe_accept( node, &UntypedInitExpr::result );
    1492                 }
    1493                 maybe_accept( node, &UntypedInitExpr::expr   );
    1494                 // not currently visiting initAlts, but this doesn't matter since this node is only used in the resolver.
    1495         )
    1496 
    1497         VISIT_END( Expr, node );
    1498 }
    1499 
    1500 //--------------------------------------------------------------------------
    1501 // InitExpr
    1502 template< typename pass_t >
    1503 const ast::Expr * ast::Pass< pass_t >::visit( const ast::InitExpr * node ) {
    1504         VISIT_START( node );
    1505 
    1506         VISIT({
    1507                         guard_indexer guard { *this };
    1508                         maybe_accept( node, &InitExpr::result );
    1509                 }
    1510                 maybe_accept( node, &InitExpr::expr   );
    1511                 maybe_accept( node, &InitExpr::designation );
    1512         )
    1513 
    1514         VISIT_END( Expr, node );
    1515 }
    1516 
    1517 //--------------------------------------------------------------------------
    1518 // DeletedExpr
    1519 template< typename pass_t >
    1520 const ast::Expr * ast::Pass< pass_t >::visit( const ast::DeletedExpr * node ) {
    1521         VISIT_START( node );
    1522 
    1523         VISIT({
    1524                         guard_indexer guard { *this };
    1525                         maybe_accept( node, &DeletedExpr::result );
    1526                 }
    1527                 maybe_accept( node, &DeletedExpr::expr );
    1528                 // don't visit deleteStmt, because it is a pointer to somewhere else in the tree.
    1529         )
    1530 
    1531         VISIT_END( Expr, node );
    1532 }
    1533 
    1534 //--------------------------------------------------------------------------
    1535 // DefaultArgExpr
    1536 template< typename pass_t >
    1537 const ast::Expr * ast::Pass< pass_t >::visit( const ast::DefaultArgExpr * node ) {
    1538         VISIT_START( node );
    1539 
    1540         VISIT({
    1541                         guard_indexer guard { *this };
    1542                         maybe_accept( node, &DefaultArgExpr::result );
    1543                 }
    1544                 maybe_accept( node, &DefaultArgExpr::expr );
    1545         )
    1546 
    1547         VISIT_END( Expr, node );
    1548 }
    1549 
    1550 //--------------------------------------------------------------------------
    1551 // GenericExpr
    1552 template< typename pass_t >
    1553 const ast::Expr * ast::Pass< pass_t >::visit( const ast::GenericExpr * node ) {
    1554         VISIT_START( node );
    1555 
    1556         VISIT({
    1557                         guard_indexer guard { *this };
    1558                         maybe_accept( node, &GenericExpr::result );
    1559                 }
    1560                 maybe_accept( node, &GenericExpr::control );
    1561 
    1562                 std::vector<GenericExpr::Association> new_kids;
    1563                 new_kids.reserve(node->associations.size());
    1564                 bool mutated = false;
    1565                 for( const auto & assoc : node->associations ) {
    1566                         const Type * type = nullptr;
    1567                         if( assoc.type ) {
    1568                                 guard_indexer guard { *this };
    1569                                 type = assoc.type->accept( *this );
    1570                                 if( type != assoc.type ) mutated = true;
    1571                         }
    1572                         const Expr * expr = nullptr;
    1573                         if( assoc.expr ) {
    1574                                 expr = assoc.expr->accept( *this );
    1575                                 if( expr != assoc.expr ) mutated = true;
    1576                         }
    1577                         new_kids.emplace_back( type, expr );
    1578                 }
    1579 
    1580                 if(mutated) {
    1581                         auto n = mutate(node);
    1582                         n->associations = std::move( new_kids );
    1583                         node = n;
    1584                 }
    1585         )
    1586 
    1587         VISIT_END( Expr, node );
    1588 }
    1589 
    1590 //--------------------------------------------------------------------------
    1591 // VoidType
    1592 template< typename pass_t >
    1593 const ast::Type * ast::Pass< pass_t >::visit( const ast::VoidType * node ) {
    1594         VISIT_START( node );
    1595 
    1596         VISIT_END( Type, node );
    1597 }
    1598 
    1599 //--------------------------------------------------------------------------
    1600 // BasicType
    1601 template< typename pass_t >
    1602 const ast::Type * ast::Pass< pass_t >::visit( const ast::BasicType * node ) {
    1603         VISIT_START( node );
    1604 
    1605         VISIT_END( Type, node );
    1606 }
    1607 
    1608 //--------------------------------------------------------------------------
    1609 // PointerType
    1610 template< typename pass_t >
    1611 const ast::Type * ast::Pass< pass_t >::visit( const ast::PointerType * node ) {
    1612         VISIT_START( node );
    1613 
    1614         VISIT(
    1615                 // xxx - should PointerType visit/mutate dimension?
    1616                 maybe_accept( node, &PointerType::base );
    1617         )
    1618 
    1619         VISIT_END( Type, node );
    1620 }
    1621 
    1622 //--------------------------------------------------------------------------
    1623 // ArrayType
    1624 template< typename pass_t >
    1625 const ast::Type * ast::Pass< pass_t >::visit( const ast::ArrayType * node ) {
    1626         VISIT_START( node );
    1627 
    1628         VISIT(
    1629                 maybe_accept( node, &ArrayType::dimension );
    1630                 maybe_accept( node, &ArrayType::base );
    1631         )
    1632 
    1633         VISIT_END( Type, node );
    1634 }
    1635 
    1636 //--------------------------------------------------------------------------
    1637 // ReferenceType
    1638 template< typename pass_t >
    1639 const ast::Type * ast::Pass< pass_t >::visit( const ast::ReferenceType * node ) {
    1640         VISIT_START( node );
    1641 
    1642         VISIT(
    1643                 maybe_accept( node, &ReferenceType::base );
    1644         )
    1645 
    1646         VISIT_END( Type, node );
    1647 }
    1648 
    1649 //--------------------------------------------------------------------------
    1650 // QualifiedType
    1651 template< typename pass_t >
    1652 const ast::Type * ast::Pass< pass_t >::visit( const ast::QualifiedType * node ) {
    1653         VISIT_START( node );
    1654 
    1655         VISIT(
    1656                 maybe_accept( node, &QualifiedType::parent );
    1657                 maybe_accept( node, &QualifiedType::child );
    1658         )
    1659 
    1660         VISIT_END( Type, node );
    1661 }
    1662 
    1663 //--------------------------------------------------------------------------
    1664 // FunctionType
    1665 template< typename pass_t >
    1666 const ast::Type * ast::Pass< pass_t >::visit( const ast::FunctionType * node ) {
    1667         VISIT_START( node );
    1668 
    1669         VISIT(
    1670                 maybe_accept( node, &FunctionType::forall  );
    1671                 maybe_accept( node, &FunctionType::returns );
    1672                 maybe_accept( node, &FunctionType::params  );
    1673         )
    1674 
    1675         VISIT_END( Type, node );
    1676 }
    1677 
    1678 //--------------------------------------------------------------------------
    1679 // StructInstType
    1680 template< typename pass_t >
    1681 const ast::Type * ast::Pass< pass_t >::visit( const ast::StructInstType * node ) {
    1682         VISIT_START( node );
    1683 
    1684         __pass::indexer::addStruct( pass, 0, node->name );
    1685 
    1686         VISIT({
    1687                 guard_indexer guard { *this };
    1688                 maybe_accept( node, &StructInstType::forall );
    1689                 maybe_accept( node, &StructInstType::params );
    1690         })
    1691 
    1692         VISIT_END( Type, node );
    1693 }
    1694 
    1695 //--------------------------------------------------------------------------
    1696 // UnionInstType
    1697 template< typename pass_t >
    1698 const ast::Type * ast::Pass< pass_t >::visit( const ast::UnionInstType * node ) {
    1699         VISIT_START( node );
    1700 
    1701         __pass::indexer::addStruct( pass, 0, node->name );
    1702 
    1703         {
    1704                 guard_indexer guard { *this };
    1705                 maybe_accept( node, &UnionInstType::forall );
    1706                 maybe_accept( node, &UnionInstType::params );
    1707         }
    1708 
    1709         VISIT_END( Type, node );
    1710 }
    1711 
    1712 //--------------------------------------------------------------------------
    1713 // EnumInstType
    1714 template< typename pass_t >
    1715 const ast::Type * ast::Pass< pass_t >::visit( const ast::EnumInstType * node ) {
    1716         VISIT_START( node );
    1717 
    1718         VISIT(
    1719                 maybe_accept( node, &EnumInstType::forall );
    1720                 maybe_accept( node, &EnumInstType::params );
    1721         )
    1722 
    1723         VISIT_END( Type, node );
    1724 }
    1725 
    1726 //--------------------------------------------------------------------------
    1727 // TraitInstType
    1728 template< typename pass_t >
    1729 const ast::Type * ast::Pass< pass_t >::visit( const ast::TraitInstType * node ) {
    1730         VISIT_START( node );
    1731 
    1732         VISIT(
    1733                 maybe_accept( node, &TraitInstType::forall );
    1734                 maybe_accept( node, &TraitInstType::params );
    1735         )
    1736 
    1737         VISIT_END( Type, node );
    1738 }
    1739 
    1740 //--------------------------------------------------------------------------
    1741 // TypeInstType
    1742 template< typename pass_t >
    1743 const ast::Type * ast::Pass< pass_t >::visit( const ast::TypeInstType * node ) {
    1744         VISIT_START( node );
    1745 
    1746         VISIT(
    1747                 maybe_accept( node, &TypeInstType::forall );
    1748                 maybe_accept( node, &TypeInstType::params );
    1749         )
    1750 
    1751         VISIT_END( Type, node );
    1752 }
    1753 
    1754 //--------------------------------------------------------------------------
    1755 // TupleType
    1756 template< typename pass_t >
    1757 const ast::Type * ast::Pass< pass_t >::visit( const ast::TupleType * node ) {
    1758         VISIT_START( node );
    1759 
    1760         VISIT(
    1761                 maybe_accept( node, &TupleType::types );
    1762                 maybe_accept( node, &TupleType::members );
    1763         )
    1764 
    1765         VISIT_END( Type, node );
    1766 }
    1767 
    1768 //--------------------------------------------------------------------------
    1769 // TypeofType
    1770 template< typename pass_t >
    1771 const ast::Type * ast::Pass< pass_t >::visit( const ast::TypeofType * node ) {
    1772         VISIT_START( node );
    1773 
    1774         VISIT(
    1775                 maybe_accept( node, &TypeofType::expr );
    1776         )
    1777 
    1778         VISIT_END( Type, node );
    1779 }
    1780 
    1781 //--------------------------------------------------------------------------
    1782 // VarArgsType
    1783 template< typename pass_t >
    1784 const ast::Type * ast::Pass< pass_t >::visit( const ast::VarArgsType * node ) {
    1785         VISIT_START( node );
    1786 
    1787         VISIT_END( Type, node );
    1788 }
    1789 
    1790 //--------------------------------------------------------------------------
    1791 // ZeroType
    1792 template< typename pass_t >
    1793 const ast::Type * ast::Pass< pass_t >::visit( const ast::ZeroType * node ) {
    1794         VISIT_START( node );
    1795 
    1796         VISIT_END( Type, node );
    1797 }
    1798 
    1799 //--------------------------------------------------------------------------
    1800 // OneType
    1801 template< typename pass_t >
    1802 const ast::Type * ast::Pass< pass_t >::visit( const ast::OneType * node ) {
    1803         VISIT_START( node );
    1804 
    1805         VISIT_END( Type, node );
    1806 }
    1807 
    1808 //--------------------------------------------------------------------------
    1809 // GlobalScopeType
    1810 template< typename pass_t >
    1811 const ast::Type * ast::Pass< pass_t >::visit( const ast::GlobalScopeType * node ) {
    1812         VISIT_START( node );
    1813 
    1814         VISIT_END( Type, node );
    1815 }
    1816 
    1817 
    1818 //--------------------------------------------------------------------------
    1819 // Designation
    1820 template< typename pass_t >
    1821 const ast::Designation * ast::Pass< pass_t >::visit( const ast::Designation * node ) {
    1822         VISIT_START( node );
    1823 
    1824         VISIT( maybe_accept( node, &Designation::designators ); )
    1825 
    1826         VISIT_END( Designation, node );
    1827 }
     912
     913
     914
     915
    1828916
    1829917//--------------------------------------------------------------------------
     
    1876964
    1877965        VISIT(
    1878                 maybe_accept( node, &Attribute::params );
     966                maybe_accept( node, &Attribute::parameters );
    1879967        )
    1880968
  • src/AST/Pass.proto.hpp

    rd908563 r933f32f  
    107107                bool     * m_prev;
    108108                bool_ref * m_ref;
    109         };
    110 
    111         /// "Short hand" to check if this is a valid previsit function
    112         /// Mostly used to make the static_assert look (and print) prettier
    113         template<typename pass_t, typename node_t>
    114         struct is_valid_previsit {
    115                 using ret_t = decltype( ((pass_t*)nullptr)->previsit( (const node_t *)nullptr ) );
    116 
    117                 static constexpr bool value = std::is_void< ret_t >::value ||
    118                         std::is_base_of<const node_t, typename std::remove_pointer<ret_t>::type >::value;
    119         };
    120 
    121         /// Used by previsit implementation
    122         /// We need to reassign the result to 'node', unless the function
    123         /// returns void, then we just leave 'node' unchanged
    124         template<bool is_void>
    125         struct __assign;
    126 
    127         template<>
    128         struct __assign<true> {
    129                 template<typename pass_t, typename node_t>
    130                 static inline void result( pass_t & pass, const node_t * & node ) {
    131                         pass.previsit( node );
    132                 }
    133         };
    134 
    135         template<>
    136         struct __assign<false> {
    137                 template<typename pass_t, typename node_t>
    138                 static inline void result( pass_t & pass, const node_t * & node ) {
    139                         node = pass.previsit( node );
    140                         assertf(node, "Previsit must not return NULL");
    141                 }
    142         };
    143 
    144         /// Used by postvisit implementation
    145         /// We need to return the result unless the function
    146         /// returns void, then we just return the original node
    147         template<bool is_void>
    148         struct __return;
    149 
    150         template<>
    151         struct __return<true> {
    152                 template<typename pass_t, typename node_t>
    153                 static inline const node_t * result( pass_t & pass, const node_t * & node ) {
    154                         pass.postvisit( node );
    155                         return node;
    156                 }
    157         };
    158 
    159         template<>
    160         struct __return<false> {
    161                 template<typename pass_t, typename node_t>
    162                 static inline auto result( pass_t & pass, const node_t * & node ) {
    163                         return pass.postvisit( node );
    164                 }
    165109        };
    166110
     
    182126        template<typename pass_t, typename node_t>
    183127        static inline auto previsit( pass_t & pass, const node_t * & node, int ) -> decltype( pass.previsit( node ), void() ) {
    184                 static_assert(
    185                         is_valid_previsit<pass_t, node_t>::value,
    186                         "Previsit may not change the type of the node. It must return its paremeter or void."
    187                 );
    188 
    189                 __assign<
    190                         std::is_void<
    191                                 decltype( pass.previsit( node ) )
    192                         >::value
    193                 >::result( pass, node );
     128                node = pass.previsit( node );
     129                assert(node);
    194130        }
    195131
     
    199135        // PostVisit : never mutates the passed pointer but may return a different node
    200136        template<typename pass_t, typename node_t>
    201         static inline auto postvisit( pass_t & pass, const node_t * node, int ) ->
    202                 decltype( pass.postvisit( node ), node->accept( *(Visitor*)nullptr ) )
    203         {
    204                 return __return<
    205                         std::is_void<
    206                                 decltype( pass.postvisit( node ) )
    207                         >::value
    208                 >::result( pass, node );
     137        static inline auto postvisit( pass_t & pass, const node_t * node, int ) -> decltype( pass.postvisit( node ), (const node_t *)nullptr ) {
     138                return pass.postvisit( node );
    209139        }
    210140
  • src/AST/Stmt.cpp

    rd908563 r933f32f  
    1616#include "Stmt.hpp"
    1717
    18 
    1918#include "DeclReplacer.hpp"
    20 #include "Type.hpp"
    2119
    2220namespace ast {
    2321
    2422// --- CompoundStmt
    25 CompoundStmt::CompoundStmt( const CompoundStmt& other ) : Stmt(other), kids(other.kids) {
    26         // when cloning a compound statement, we may end up cloning declarations which
    27         // are referred to by VariableExprs throughout the block. Cloning a VariableExpr
    28         // does a shallow copy, so the VariableExpr will end up pointing to the original
    29         // declaration. If the original declaration is deleted, e.g. because the original
    30         // CompoundStmt is deleted, then we have a dangling pointer. To avoid this case,
    31         // find all DeclarationWithType nodes (since a VariableExpr must point to a
    32         // DeclarationWithType) in the original CompoundStmt and map them to the cloned
    33         // node in the new CompoundStmt ('this'), then replace the Declarations referred to
    34         // by each VariableExpr according to the constructed map. Note that only the declarations
    35         // in the current level are collected into the map, because child CompoundStmts will
    36         // recursively execute this routine. There may be more efficient ways of doing
    37         // this.
    38         DeclReplacer::DeclMap declMap;
    39         auto origit = other.kids.begin();
    40         for ( const Stmt * s : kids ) {
    41                 assert( origit != other.kids.end() );
    42                 const Stmt * origStmt = *origit++;
    43                 if ( const DeclStmt * declStmt = dynamic_cast< const DeclStmt * >( s ) ) {
    44                         const DeclStmt * origDeclStmt = strict_dynamic_cast< const DeclStmt * >( origStmt );
    45                         if ( const DeclWithType * dwt = dynamic_cast< const DeclWithType * > ( declStmt->decl.get() ) ) {
    46                                 const DeclWithType * origdwt = strict_dynamic_cast< const DeclWithType * > ( origDeclStmt->decl.get() );
    47                                 assert( dwt->name == origdwt->name );
    48                                 declMap[ origdwt ] = dwt;
    49                         } else assert( ! dynamic_cast< const DeclWithType * > ( origDeclStmt->decl.get() ) );
    50                 } else assert( ! dynamic_cast< const DeclStmt * > ( s ) );
    51         }
    52         if ( ! declMap.empty() ) {
    53                 DeclReplacer::replace( this, declMap );
    54         }
     23CompoundStmt::CompoundStmt( const CompoundStmt& o ) : Stmt(o), kids(o.kids) {
     24        assert(!"implemented");
    5525}
    5626
  • src/AST/Stmt.hpp

    rd908563 r933f32f  
    9696};
    9797
    98 /// Assembly statement `asm ... ( "..." : ... )`
    9998class AsmStmt final : public Stmt {
    10099public:
     
    119118};
    120119
    121 /// C-preprocessor directive `#...`
    122120class DirectiveStmt final : public Stmt {
    123121public:
     
    134132};
    135133
    136 /// If conditional statement `if (...) ... else ...`
    137134class IfStmt final : public Stmt {
    138135public:
     
    154151};
    155152
    156 /// Switch or choose conditional statement `switch (...) { ... }`
    157153class SwitchStmt final : public Stmt {
    158154public:
     
    170166};
    171167
    172 /// Case label `case ...:` `default:`
    173168class CaseStmt final : public Stmt {
    174169public:
     
    188183};
    189184
    190 /// While loop `while (...) ...` `do ... while (...);
    191185class WhileStmt final : public Stmt {
    192186public:
     
    207201};
    208202
    209 /// For loop `for (... ; ... ; ...) ...`
    210203class ForStmt final : public Stmt {
    211204public:
     
    226219};
    227220
    228 /// Branch control flow statement `goto ...` `break` `continue` `fallthru`
    229221class BranchStmt final : public Stmt {
    230222public:
     
    244236          computedTarget(computedTarget), kind(Goto) {}
    245237
    246         const char * kindName() const { return kindNames[kind]; }
     238        const char * kindName() { return kindNames[kind]; }
    247239
    248240        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     
    254246};
    255247
    256 /// Return statement `return ...`
    257248class ReturnStmt final : public Stmt {
    258249public:
     
    268259};
    269260
    270 /// Throw statement `throw ...`
    271261class ThrowStmt final : public Stmt {
    272262public:
     
    287277};
    288278
    289 /// Try statement `try { ... } ...`
    290279class TryStmt final : public Stmt {
    291280public:
     
    305294};
    306295
    307 /// Catch clause of try statement
    308296class CatchStmt final : public Stmt {
    309297public:
     
    325313};
    326314
    327 /// Finally clause of try statement
    328315class FinallyStmt final : public Stmt {
    329316public:
     
    340327};
    341328
    342 /// Wait for concurrency statement `when (...) waitfor (... , ...) ... timeout(...) ... else ...`
    343329class WaitForStmt final : public Stmt {
    344330public:
    345331        struct Target {
    346                 ptr<Expr> func;
    347                 std::vector<ptr<Expr>> args;
     332                ptr<Expr> function;
     333                std::vector<ptr<Expr>> arguments;
    348334        };
    349335
     
    378364};
    379365
    380 /// With statement `with (...) ...`
    381366class WithStmt final : public Stmt {
    382367public:
     
    394379};
    395380
    396 /// Any declaration in a (compound) statement.
    397381class DeclStmt final : public Stmt {
    398382public:
     
    408392};
    409393
    410 /// Represents an implicit application of a constructor or destructor.
    411394class ImplicitCtorDtorStmt final : public Stmt {
    412395public:
  • src/AST/Type.cpp

    rd908563 r933f32f  
    141141bool EnumInstType::isComplete() const { return base ? base->body : false; }
    142142
    143 // --- TraitInstType
    144 
    145 TraitInstType::TraitInstType( const TraitDecl * b, CV::Qualifiers q,
    146         std::vector<ptr<Attribute>>&& as )
    147 : ReferenceToType( b->name, q, std::move(as) ), base( b ) {}
    148 
    149143// --- TypeInstType
    150144
  • src/AST/Type.hpp

    rd908563 r933f32f  
    4747        bool is_atomic() const { return qualifiers.is_atomic; }
    4848
    49         Type * set_const( bool v ) { qualifiers.is_const = v; return this; }
    50         Type * set_restrict( bool v ) { qualifiers.is_restrict = v; return this; }
    51         Type * set_lvalue( bool v ) { qualifiers.is_lvalue = v; return this; }
    52         Type * set_mutex( bool v ) { qualifiers.is_mutex = v; return this; }
    53         Type * set_atomic( bool v ) { qualifiers.is_atomic = v; return this; }
     49        void set_const( bool v ) { qualifiers.is_const = v; }
     50        void set_restrict( bool v ) { qualifiers.is_restrict = v; }
     51        void set_lvalue( bool v ) { qualifiers.is_lvalue = v; }
     52        void set_mutex( bool v ) { qualifiers.is_mutex = v; }
     53        void set_atomic( bool v ) { qualifiers.is_atomic = v; }
    5454
    5555        /// How many elemental types are represented by this type
     
    308308        virtual ReferenceToType * clone() const override = 0;
    309309        MUTATE_FRIEND
     310
     311protected:
     312        /// Name for the kind of type this is
     313        virtual std::string typeString() const = 0;
    310314};
    311315
     
    329333        StructInstType * clone() const override { return new StructInstType{ *this }; }
    330334        MUTATE_FRIEND
     335
     336        std::string typeString() const override { return "struct"; }
    331337};
    332338
     
    350356        UnionInstType * clone() const override { return new UnionInstType{ *this }; }
    351357        MUTATE_FRIEND
     358
     359        std::string typeString() const override { return "union"; }
    352360};
    353361
     
    371379        EnumInstType * clone() const override { return new EnumInstType{ *this }; }
    372380        MUTATE_FRIEND
     381
     382        std::string typeString() const override { return "enum"; }
    373383};
    374384
     
    393403        TraitInstType * clone() const override { return new TraitInstType{ *this }; }
    394404        MUTATE_FRIEND
     405
     406        std::string typeString() const override { return "trait"; }
    395407};
    396408
     
    420432        TypeInstType * clone() const override { return new TypeInstType{ *this }; }
    421433        MUTATE_FRIEND
     434
     435        std::string typeString() const override { return "type"; }
    422436};
    423437
     
    500514class GlobalScopeType final : public Type {
    501515public:
    502         GlobalScopeType() : Type() {}
     516        GlobalScopeType( CV::Qualifiers q = {} ) : Type( q ) {}
    503517
    504518        const Type * accept( Visitor & v ) const override { return v.visit( this ); }
  • src/AST/TypeSubstitution.hpp

    rd908563 r933f32f  
    2525#include "Fwd.hpp"        // for UniqueId
    2626#include "ParseNode.hpp"
    27 #include "Type.hpp"
     27#include "Type.hpp"       // for ptr<Type>
    2828#include "Common/SemanticError.h"  // for SemanticError
    2929#include "Visitor.hpp"
    3030#include "Decl.hpp"
    3131#include "Expr.hpp"
    32 #include "Node.hpp"
    3332
    3433namespace ast {
     
    4443        TypeSubstitution &operator=( const TypeSubstitution &other );
    4544
    46         template< typename SynTreeClass > int apply( const SynTreeClass *& input ) const;
    47         template< typename SynTreeClass > int applyFree( const SynTreeClass *& input ) const;
    48 
    49         template< typename node_t, enum Node::ref_type ref_t >
    50         int apply( ptr_base< node_t, ref_t > & input ) const {
    51                 const node_t * p = input.get();
    52                 int ret = apply(p);
    53                 input = p;
    54                 return ret;
    55         }
    56 
    57         template< typename node_t, enum Node::ref_type ref_t >
    58         int applyFree( ptr_base< node_t, ref_t > & input ) const {
    59                 const node_t * p = input.get();
    60                 int ret = applyFree(p);
    61                 input = p;
    62                 return ret;
    63         }
     45        template< typename SynTreeClass > int apply( SynTreeClass *&input ) const;
     46        template< typename SynTreeClass > int applyFree( SynTreeClass *&input ) const;
    6447
    6548        void add( std::string formalType, const Type *actualType );
     
    179162
    180163template< typename SynTreeClass >
    181 int TypeSubstitution::apply( const SynTreeClass *& input ) const {
     164int TypeSubstitution::apply( SynTreeClass *&input ) const {
    182165        assert( input );
    183166        Pass<Substituter> sub( *this, false );
    184         input = strict_dynamic_cast< const SynTreeClass * >( input->accept( sub ) );
     167        input = dynamic_cast< SynTreeClass * >( input->acceptMutator( sub ) );
     168        assert( input );
    185169///     std::cerr << "substitution result is: ";
    186170///     newType->print( std::cerr );
     
    190174
    191175template< typename SynTreeClass >
    192 int TypeSubstitution::applyFree( const SynTreeClass *& input ) const {
     176int TypeSubstitution::applyFree( SynTreeClass *&input ) const {
    193177        assert( input );
    194178        Pass<Substituter> sub( *this, true );
    195         input = strict_dynamic_cast< const SynTreeClass * >( input->accept( sub ) );
     179        input = dynamic_cast< SynTreeClass * >( input->acceptMutator( sub ) );
     180        assert( input );
    196181///     std::cerr << "substitution result is: ";
    197182///     newType->print( std::cerr );
  • src/AST/module.mk

    rd908563 r933f32f  
    1 ######################### -*- Mode: Makefile-Gmake -*- ########################
     1######################### -*- Mode: Makefile-Gmake -*-
     2########################
    23##
    34## Cforall Version 1.0.0 Copyright (C) 2019 University of Waterloo
     
    1617
    1718SRC_AST = \
    18         AST/Attribute.cpp \
    19         AST/Convert.cpp \
    20         AST/Decl.cpp \
    21         AST/DeclReplacer.cpp \
    22         AST/Expr.cpp \
    23         AST/GenericSubstitution.cpp \
    24         AST/Init.cpp \
    25         AST/LinkageSpec.cpp \
    26         AST/Node.cpp \
    27         AST/Pass.cpp \
    28         AST/Print.cpp \
    29         AST/Stmt.cpp \
    30         AST/Type.cpp \
    31         AST/TypeSubstitution.cpp
     19     AST/Convert.cpp \
     20     AST/Node.cpp \
     21     AST/TypeSubstitution.cpp
    3222
    3323
     
    3525SRC += $(SRC_AST)
    3626SRCDEMANGLE += $(SRC_AST)
     27
  • src/AST/porting.md

    rd908563 r933f32f  
    3838
    3939`N->print(std::ostream&)` is a visitor now, port these methods to `ast::Print` class
    40 * **TODO** `Declaration::printShort` should also be integrated
     40* **TODO** write this visitor
     41* **TODO** write `std::ostream& operator<< ( std::ostream& out, const Node* node )` in `Node.hpp` in terms of `ast::Print`
     42* `Declaration::printShort` should also be integrated
    4143
    4244`clone` is private to `Node` now
     
    110112
    111113## Specific Nodes ##
    112 `Attribute`
    113 * `parameters` => `params`
    114 
    115114`Decl`
    116115* `storageClasses` => `storage`
     
    209208
    210209`CompoundStmt`
     210* **TODO** port copy operator
     211  * Needs to be an almost-shallow clone, where the declarations are cloned only if needed
     212  * **TODO** port `DeclReplacer`
    211213* Still a `std::list` for children, rather than `std::vector`
    212214  * allows more-efficient splicing for purposes of later code generation
     
    227229  * `getAggr()` => `aggr()`
    228230    * also now returns `const AggregateDecl *`
    229 * `genericSubstitution()` moved to own visitor in `AST/GenericSubstitution.hpp`
     231* `genericSubstitution()` moved to own visitor in `AST/GenericSubstitution.hpp` **TODO** write
    230232
    231233`BasicType`
  • src/Common/Eval.cc

    rd908563 r933f32f  
    1717
    1818#include "Common/PassVisitor.h"
    19 #include "AST/Pass.hpp"
    2019#include "InitTweak/InitTweak.h"
    2120#include "SynTree/Expression.h"
    2221
    23 //-------------------------------------------------------------
    24 // Old AST
    25 struct EvalOld : public WithShortCircuiting {
     22struct Eval : public WithShortCircuiting {
    2623        long long int value = 0;
    2724        bool valid = true;
     
    8380};
    8481
    85 //-------------------------------------------------------------
    86 // New AST
    87 struct EvalNew : public ast::WithShortCircuiting {
    88         long long int value = 0;
    89         bool valid = true;
    90 
    91         void previsit( const ast::Node * ) { visit_children = false; }
    92         void postvisit( const ast::Node * ) { valid = false; }
    93 
    94         void postvisit( const ast::ConstantExpr * expr ) {
    95                 value = expr->intValue();
    96         }
    97 
    98         void postvisit( const ast::CastExpr * expr ) {
    99                 auto arg = eval(expr->arg);
    100                 valid = arg.second;
    101                 value = arg.first;
    102                 // TODO: perform type conversion on value if valid
    103         }
    104 
    105         void postvisit( const ast::VariableExpr * expr ) {
    106                 if ( const ast::EnumInstType * inst = dynamic_cast<const ast::EnumInstType *>(expr->result.get()) ) {
    107                         if ( const ast::EnumDecl * decl = inst->base ) {
    108                                 if ( decl->valueOf( expr->var, value ) ) { // value filled by valueOf
    109                                         return;
    110                                 }
    111                         }
    112                 }
    113                 valid = false;
    114         }
    115 
    116         void postvisit( const ast::ApplicationExpr * expr ) {
    117                 const ast::DeclWithType * function = InitTweak::getFunction(expr);
    118                 if ( ! function || function->linkage != ast::Linkage::Intrinsic ) { valid = false; return; }
    119                 const std::string & fname = function->name;
    120                 assertf( expr->args.size() == 1 || expr->args.size() == 2, "Intrinsic function with %zd arguments: %s", expr->args.size(), fname.c_str() );
    121                 std::pair<long long int, bool> arg1, arg2;
    122                 arg1 = eval(expr->args.front());
    123                 valid = valid && arg1.second;
    124                 if ( ! valid ) return;
    125                 if ( expr->args.size() == 2 ) {
    126                         arg2 = eval(expr->args.back());
    127                         valid = valid && arg2.second;
    128                         if ( ! valid ) return;
    129                 }
    130                 if (fname == "?+?") {
    131                         value = arg1.first + arg2.first;
    132                 } else if (fname == "?-?") {
    133                         value = arg1.first - arg2.first;
    134                 } else if (fname == "?*?") {
    135                         value = arg1.first * arg2.first;
    136                 } else if (fname == "?/?") {
    137                         value = arg1.first / arg2.first;
    138                 } else if (fname == "?%?") {
    139                         value = arg1.first % arg2.first;
    140                 } else {
    141                         valid = false;
    142                 }
    143                 // TODO: implement other intrinsic functions
    144         }
    145 };
    146 
    14782std::pair<long long int, bool> eval(Expression * expr) {
    148         PassVisitor<EvalOld> ev;
    149         if (expr) {
    150                 expr->accept(ev);
    151                 return std::make_pair(ev.pass.value, ev.pass.valid);
    152         } else {
    153                 return std::make_pair(0, false);
    154         }
    155 }
    156 
    157 std::pair<long long int, bool> eval(const ast::Expr * expr) {
    158         ast::Pass<EvalNew> ev;
     83        PassVisitor<Eval> ev;
    15984        if (expr) {
    16085                expr->accept(ev);
  • src/Common/PassVisitor.impl.h

    rd908563 r933f32f  
    2323        assert( __return ); \
    2424        return __return;
     25
     26
     27#define VISIT_BODY( node )          \
     28        VISIT_START( node );          \
     29        if( children_guard ) {        \
     30                Visitor::visit( node ); \
     31        }                             \
     32        VISIT_END( node );            \
     33
     34
     35#define MUTATE_BODY( type, node )    \
     36        MUTATE_START( node );          \
     37        if( children_guard ) {         \
     38                Mutator::mutate( node ); \
     39        }                              \
     40        MUTATE_END( type, node );      \
     41
    2542
    2643
     
    27392756        MUTATE_END( TypeSubstitution, node );
    27402757}
    2741 
    2742 #undef VISIT_START
    2743 #undef VISIT_END
    2744 
    2745 #undef MUTATE_START
    2746 #undef MUTATE_END
  • src/Common/utility.h

    rd908563 r933f32f  
    7474
    7575template< typename Container >
    76 void deleteAll( const Container &container ) {
    77         for ( const auto &i : container ) {
    78                 delete i;
     76void deleteAll( Container &container ) {
     77        for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {
     78                delete *i;
    7979        } // for
    8080}
  • src/InitTweak/InitTweak.cc

    rd908563 r933f32f  
    346346        namespace {
    347347                DeclarationWithType * getCalledFunction( Expression * expr );
    348                 const ast::DeclWithType * getCalledFunction( const ast::Expr * expr );
    349348
    350349                template<typename CallExpr>
     
    356355                        return getCalledFunction( expr->get_args().front() );
    357356                }
    358 
    359                 template<typename CallExpr>
    360                 const ast::DeclWithType * handleDerefCalledFunction( const CallExpr * expr ) {
    361                         // (*f)(x) => should get "f"
    362                         std::string name = getFunctionName( expr );
    363                         assertf( name == "*?", "Unexpected untyped expression: %s", name.c_str() );
    364                         assertf( ! expr->args.empty(), "Cannot get called function from dereference with no arguments" );
    365                         return getCalledFunction( expr->args.front() );
    366                 }
    367 
    368357
    369358                DeclarationWithType * getCalledFunction( Expression * expr ) {
     
    386375                        return nullptr;
    387376                }
    388 
    389                 const ast::DeclWithType * getCalledFunction( const ast::Expr * expr ) {
    390                         assert( expr );
    391                         if ( const ast::VariableExpr * varExpr = dynamic_cast< const ast::VariableExpr * >( expr ) ) {
    392                                 return varExpr->var;
    393                         } else if ( const ast::MemberExpr * memberExpr = dynamic_cast< const ast::MemberExpr * >( expr ) ) {
    394                                 return memberExpr->member;
    395                         } else if ( const ast::CastExpr * castExpr = dynamic_cast< const ast::CastExpr * >( expr ) ) {
    396                                 return getCalledFunction( castExpr->arg );
    397                         } else if ( const ast::UntypedExpr * untypedExpr = dynamic_cast< const ast::UntypedExpr * >( expr ) ) {
    398                                 return handleDerefCalledFunction( untypedExpr );
    399                         } else if ( const ast::ApplicationExpr * appExpr = dynamic_cast< const ast::ApplicationExpr * > ( expr ) ) {
    400                                 return handleDerefCalledFunction( appExpr );
    401                         } else if ( const ast::AddressExpr * addrExpr = dynamic_cast< const ast::AddressExpr * >( expr ) ) {
    402                                 return getCalledFunction( addrExpr->arg );
    403                         } else if ( const ast::CommaExpr * commaExpr = dynamic_cast< const ast::CommaExpr * >( expr ) ) {
    404                                 return getCalledFunction( commaExpr->arg2 );
    405                         }
    406                         return nullptr;
    407                 }
    408377        }
    409378
     
    413382                } else if ( UntypedExpr * untyped = dynamic_cast< UntypedExpr * > ( expr ) ) {
    414383                        return getCalledFunction( untyped->get_function() );
    415                 }
    416                 assertf( false, "getFunction received unknown expression: %s", toString( expr ).c_str() );
    417         }
    418 
    419         const ast::DeclWithType * getFunction( const ast::Expr * expr ) {
    420                 if ( const ast::ApplicationExpr * appExpr = dynamic_cast< const ast::ApplicationExpr * >( expr ) ) {
    421                         return getCalledFunction( appExpr->func );
    422                 } else if ( const ast::UntypedExpr * untyped = dynamic_cast< const ast::UntypedExpr * > ( expr ) ) {
    423                         return getCalledFunction( untyped->func );
    424384                }
    425385                assertf( false, "getFunction received unknown expression: %s", toString( expr ).c_str() );
     
    474434                }
    475435
    476                 template<typename CallExpr>
    477                 const ast::Expr * callArg( const CallExpr * call, unsigned int pos ) {
    478                         if( pos >= call->args.size() ) {
    479                                 assertf( false, "getCallArg for argument that doesn't exist: (%u); %s.",
    480                                         pos, toString( call ).c_str() );
    481                         }
    482                         for ( const ast::Expr * arg : call->args ) {
    483                                 if ( pos == 0 ) return arg;
    484                                 --pos;
    485                         }
    486                         assert( false );
    487                 }
     436                // template<typename CallExpr>
     437                // const ast::Expr * callArg( const CallExpr * call, unsigned int pos ) {
     438                //      if( pos >= call->args.size() ) {
     439                //              assertf( false, "getCallArg for argument that doesn't exist: (%u); %s.",
     440                //                      pos, toString( call ).c_str() );
     441                //      }
     442                //      for ( const ast::Expr * arg : call->args ) {
     443                //              if ( pos == 0 ) return arg;
     444                //              --pos;
     445                //      }
     446                //      assert( false );
     447                // }
    488448        }
    489449
     
    506466                }
    507467        }
    508 
    509468        const ast::Expr * getCallArg( const ast::Expr * call, unsigned pos ) {
    510                 if ( auto app = dynamic_cast< const ast::ApplicationExpr * >( call ) ) {
    511                         return callArg( app, pos );
    512                 } else if ( auto untyped = dynamic_cast< const ast::UntypedExpr * >( call ) ) {
    513                         return callArg( untyped, pos );
    514                 } else if ( auto tupleAssn = dynamic_cast< const ast::TupleAssignExpr * >( call ) ) {
    515                         const std::list<ast::ptr<ast::Stmt>>& stmts = tupleAssn->stmtExpr->stmts->kids;
    516                         assertf( ! stmts.empty(), "TupleAssignExpr missing statements." );
    517                         auto stmt  = strict_dynamic_cast< const ast::ExprStmt * >( stmts.back().get() );
    518                         auto tuple = strict_dynamic_cast< const ast::TupleExpr * >( stmt->expr.get() );
    519                         assertf( ! tuple->exprs.empty(), "TupleAssignExpr has empty tuple expr.");
    520                         return getCallArg( tuple->exprs.front(), pos );
    521                 } else if ( auto ctor = dynamic_cast< const ast::ImplicitCopyCtorExpr * >( call ) ) {
    522                         return getCallArg( ctor->callExpr, pos );
    523                 } else {
    524                         assertf( false, "Unexpected expression type passed to getCallArg: %s",
    525                                 toString( call ).c_str() );
    526                 }
     469                (void)call;
     470                (void)pos;
     471                #warning unimplemented; needs to build AST/Expr.cpp
     472                assertf(false, "unimplemented; needs to build AST/Expr.cpp");
     473                // if ( auto app = dynamic_cast< const ast::ApplicationExpr * >( call ) ) {
     474                //      return callArg( app, pos );
     475                // } else if ( auto untyped = dynamic_cast< const ast::UntypedExpr * >( call ) ) {
     476                //      return callArg( untyped, pos );
     477                // } else if ( auto tupleAssn = dynamic_cast< const ast::TupleAssignExpr * >( call ) ) {
     478                //      const std::list<ast::ptr<ast::Stmt>>& stmts = tupleAssn->stmtExpr->stmts->kids;
     479                //      assertf( ! stmts.empty(), "TupleAssignExpr missing statements." );
     480                //      const ExprStmt * stmt = strict_dynamic_cast< const ast::ExprStmt * >( stmts.back() );
     481                //      const TupleExpr * tuple = strict_dynamic_cast< const ast::TupleExpr * >( stmt->expr );
     482                //      assertf( ! tuple->exprs.empty(), "TupleAssignExpr has empty tuple expr.");
     483                //      return getCallArg( tuple->exprs.front(), pos );
     484                // } else if ( auto ctor = dynamic_cast< const ast::ImplicitCopyCtorExpr * >( call ) ) {
     485                //      return getCallArg( ctor->callExpr, pos );
     486                // } else {
     487                //      assertf( false, "Unexpected expression type passed to getCallArg: %s",
     488                //              toString( call ).c_str() );
     489                // }
    527490        }
    528491
    529492        namespace {
    530493                std::string funcName( Expression * func );
    531                 std::string funcName( const ast::Expr * func );
    532494
    533495                template<typename CallExpr>
     
    538500                        assertf( ! expr->get_args().empty(), "Cannot get function name from dereference with no arguments" );
    539501                        return funcName( expr->get_args().front() );
    540                 }
    541 
    542                 template<typename CallExpr>
    543                 std::string handleDerefName( const CallExpr * expr ) {
    544                         // (*f)(x) => should get name "f"
    545                         std::string name = getFunctionName( expr );
    546                         assertf( name == "*?", "Unexpected untyped expression: %s", name.c_str() );
    547                         assertf( ! expr->args.empty(), "Cannot get function name from dereference with no arguments" );
    548                         return funcName( expr->args.front() );
    549502                }
    550503
     
    570523                        }
    571524                }
    572 
    573                 std::string funcName( const ast::Expr * func ) {
    574                         if ( const ast::NameExpr * nameExpr = dynamic_cast< const ast::NameExpr * >( func ) ) {
    575                                 return nameExpr->name;
    576                         } else if ( const ast::VariableExpr * varExpr = dynamic_cast< const ast::VariableExpr * >( func ) ) {
    577                                 return varExpr->var->name;
    578                         }       else if ( const ast::CastExpr * castExpr = dynamic_cast< const ast::CastExpr * >( func ) ) {
    579                                 return funcName( castExpr->arg );
    580                         } else if ( const ast::MemberExpr * memberExpr = dynamic_cast< const ast::MemberExpr * >( func ) ) {
    581                                 return memberExpr->member->name;
    582                         } else if ( const ast::UntypedMemberExpr * memberExpr = dynamic_cast< const ast::UntypedMemberExpr * > ( func ) ) {
    583                                 return funcName( memberExpr->member );
    584                         } else if ( const ast::UntypedExpr * untypedExpr = dynamic_cast< const ast::UntypedExpr * >( func ) ) {
    585                                 return handleDerefName( untypedExpr );
    586                         } else if ( const ast::ApplicationExpr * appExpr = dynamic_cast< const ast::ApplicationExpr * >( func ) ) {
    587                                 return handleDerefName( appExpr );
    588                         } else if ( const ast::ConstructorExpr * ctorExpr = dynamic_cast< const ast::ConstructorExpr * >( func ) ) {
    589                                 return funcName( getCallArg( ctorExpr->callExpr, 0 ) );
    590                         } else {
    591                                 assertf( false, "Unexpected expression type being called as a function in call expression: %s", toString( func ).c_str() );
    592                         }
    593                 }
    594525        }
    595526
     
    608539        }
    609540
    610         std::string getFunctionName( const ast::Expr * expr ) {
    611                 // there's some unforunate overlap here with getCalledFunction. Ideally this would be able to use getCalledFunction and
    612                 // return the name of the DeclarationWithType, but this needs to work for NameExpr and UntypedMemberExpr, where getCalledFunction
    613                 // can't possibly do anything reasonable.
    614                 if ( const ast::ApplicationExpr * appExpr = dynamic_cast< const ast::ApplicationExpr * >( expr ) ) {
    615                         return funcName( appExpr->func );
    616                 } else if ( const ast::UntypedExpr * untypedExpr = dynamic_cast< const ast::UntypedExpr * > ( expr ) ) {
    617                         return funcName( untypedExpr->func );
    618                 } else {
    619                         std::cerr << expr << std::endl;
    620                         assertf( false, "Unexpected expression type passed to getFunctionName" );
    621                 }
    622         }
    623 
    624541        Type * getPointerBase( Type * type ) {
    625542                if ( PointerType * ptrType = dynamic_cast< PointerType * >( type ) ) {
     
    634551        }
    635552        const ast::Type* getPointerBase( const ast::Type* t ) {
    636                 if ( const auto * p = dynamic_cast< const ast::PointerType * >( t ) ) {
    637                         return p->base;
    638                 } else if ( const auto * a = dynamic_cast< const ast::ArrayType * >( t ) ) {
    639                         return a->base;
    640                 } else if ( const auto * r = dynamic_cast< const ast::ReferenceType * >( t ) ) {
    641                         return r->base;
    642                 } else return nullptr;
     553                (void)t;
     554                #warning needs to build Type.cpp before inclusion
     555                assertf(false, "needs to build Type.cpp before inclusion");
     556                // if ( const auto * p = dynamic_cast< const ast::PointerType * >( t ) ) {
     557                //      return p->base;
     558                // } else if ( const auto * a = dynamic_cast< const ast::ArrayType * >( t ) ) {
     559                //      return a->base;
     560                // } else if ( const auto * r = dynamic_cast< const ast::ReferenceType * >( t ) ) {
     561                //      return r->base;
     562                // } else return nullptr;
    643563        }
    644564
  • src/InitTweak/InitTweak.h

    rd908563 r933f32f  
    5858        /// returns the declaration of the function called by the expr (must be ApplicationExpr or UntypedExpr)
    5959        DeclarationWithType * getFunction( Expression * expr );
    60         const ast::DeclWithType * getFunction( const ast::Expr * expr );
    6160
    6261        /// Non-Null if expr is a call expression whose target function is intrinsic
     
    7978        /// returns the name of the function being called
    8079        std::string getFunctionName( Expression * expr );
    81         std::string getFunctionName( const ast::Expr * expr );
    8280
    8381        /// returns the argument to a call expression in position N indexed from 0
  • src/Makefile.am

    rd908563 r933f32f  
    3737endif
    3838
    39 include AST/module.mk
    4039include CodeGen/module.mk
    4140include CodeTools/module.mk
  • src/Makefile.in

    rd908563 r933f32f  
    1616
    1717######################## -*- Mode: Makefile-Automake -*- ######################
    18 ###############################################################################
    19 
    20 ######################### -*- Mode: Makefile-Gmake -*- ########################
    2118###############################################################################
    2219
     
    165162libdemangle_a_LIBADD =
    166163am__dirstamp = $(am__leading_dot)dirstamp
    167 am__objects_1 = AST/Attribute.$(OBJEXT) AST/Convert.$(OBJEXT) \
    168         AST/Decl.$(OBJEXT) AST/DeclReplacer.$(OBJEXT) \
    169         AST/Expr.$(OBJEXT) AST/GenericSubstitution.$(OBJEXT) \
    170         AST/Init.$(OBJEXT) AST/LinkageSpec.$(OBJEXT) \
    171         AST/Node.$(OBJEXT) AST/Pass.$(OBJEXT) AST/Print.$(OBJEXT) \
    172         AST/Stmt.$(OBJEXT) AST/Type.$(OBJEXT) \
    173         AST/TypeSubstitution.$(OBJEXT)
    174 am__objects_2 = CodeGen/CodeGenerator.$(OBJEXT) \
     164am__objects_1 = CodeGen/CodeGenerator.$(OBJEXT) \
    175165        CodeGen/FixMain.$(OBJEXT) CodeGen/GenType.$(OBJEXT) \
    176166        CodeGen/OperatorTable.$(OBJEXT)
    177 am__objects_3 = Common/Assert.$(OBJEXT) Common/Eval.$(OBJEXT) \
     167am__objects_2 = Common/Assert.$(OBJEXT) Common/Eval.$(OBJEXT) \
    178168        Common/PassVisitor.$(OBJEXT) Common/SemanticError.$(OBJEXT) \
    179169        Common/Stats/Counter.$(OBJEXT) Common/Stats/Heap.$(OBJEXT) \
    180170        Common/Stats/Stats.$(OBJEXT) Common/Stats/Time.$(OBJEXT) \
    181171        Common/UniqueName.$(OBJEXT)
    182 am__objects_4 = ControlStruct/ForExprMutator.$(OBJEXT) \
     172am__objects_3 = ControlStruct/ForExprMutator.$(OBJEXT) \
    183173        ControlStruct/LabelFixer.$(OBJEXT) \
    184174        ControlStruct/LabelGenerator.$(OBJEXT) \
    185175        ControlStruct/MLEMutator.$(OBJEXT) \
    186176        ControlStruct/Mutate.$(OBJEXT)
    187 am__objects_5 = ResolvExpr/AdjustExprType.$(OBJEXT) \
     177am__objects_4 = ResolvExpr/AdjustExprType.$(OBJEXT) \
    188178        ResolvExpr/Alternative.$(OBJEXT) \
    189179        ResolvExpr/AlternativeFinder.$(OBJEXT) \
     
    203193        ResolvExpr/TypeEnvironment.$(OBJEXT) \
    204194        ResolvExpr/Unify.$(OBJEXT)
    205 am__objects_6 = SymTab/Autogen.$(OBJEXT) SymTab/FixFunction.$(OBJEXT) \
     195am__objects_5 = SymTab/Autogen.$(OBJEXT) SymTab/FixFunction.$(OBJEXT) \
    206196        SymTab/Indexer.$(OBJEXT) SymTab/Mangler.$(OBJEXT) \
    207197        SymTab/ManglerCommon.$(OBJEXT) SymTab/Validate.$(OBJEXT)
    208 am__objects_7 = SynTree/Type.$(OBJEXT) SynTree/VoidType.$(OBJEXT) \
     198am__objects_6 = SynTree/Type.$(OBJEXT) SynTree/VoidType.$(OBJEXT) \
    209199        SynTree/BasicType.$(OBJEXT) SynTree/PointerType.$(OBJEXT) \
    210200        SynTree/ArrayType.$(OBJEXT) SynTree/ReferenceType.$(OBJEXT) \
     
    226216        SynTree/TypeSubstitution.$(OBJEXT) SynTree/Attribute.$(OBJEXT) \
    227217        SynTree/DeclReplacer.$(OBJEXT)
    228 am__objects_8 = CompilationState.$(OBJEXT) $(am__objects_1) \
    229         $(am__objects_2) Concurrency/Keywords.$(OBJEXT) \
    230         $(am__objects_3) $(am__objects_4) GenPoly/GenPoly.$(OBJEXT) \
     218am__objects_7 = CompilationState.$(OBJEXT) $(am__objects_1) \
     219        Concurrency/Keywords.$(OBJEXT) $(am__objects_2) \
     220        $(am__objects_3) GenPoly/GenPoly.$(OBJEXT) \
    231221        GenPoly/Lvalue.$(OBJEXT) InitTweak/GenInit.$(OBJEXT) \
    232222        InitTweak/InitTweak.$(OBJEXT) Parser/LinkageSpec.$(OBJEXT) \
    233         $(am__objects_5) $(am__objects_6) SymTab/Demangle.$(OBJEXT) \
    234         $(am__objects_7) Tuples/TupleAssignment.$(OBJEXT) \
     223        $(am__objects_4) $(am__objects_5) SymTab/Demangle.$(OBJEXT) \
     224        $(am__objects_6) Tuples/TupleAssignment.$(OBJEXT) \
    235225        Tuples/TupleExpansion.$(OBJEXT) Tuples/Explode.$(OBJEXT) \
    236226        Validate/HandleAttributes.$(OBJEXT) \
    237227        Validate/FindSpecialDecls.$(OBJEXT)
    238 am_libdemangle_a_OBJECTS = $(am__objects_8)
     228am_libdemangle_a_OBJECTS = $(am__objects_7)
    239229libdemangle_a_OBJECTS = $(am_libdemangle_a_OBJECTS)
    240230am__installdirs = "$(DESTDIR)$(cfa_cpplibdir)"
    241231PROGRAMS = $(cfa_cpplib_PROGRAMS)
    242 am__objects_9 = main.$(OBJEXT) MakeLibCfa.$(OBJEXT) \
    243         CompilationState.$(OBJEXT) $(am__objects_1) $(am__objects_2) \
     232am__objects_8 = main.$(OBJEXT) MakeLibCfa.$(OBJEXT) \
     233        CompilationState.$(OBJEXT) $(am__objects_1) \
    244234        CodeGen/Generate.$(OBJEXT) CodeGen/FixNames.$(OBJEXT) \
    245235        CodeTools/DeclStats.$(OBJEXT) \
    246236        CodeTools/ResolvProtoDump.$(OBJEXT) \
    247237        CodeTools/TrackLoc.$(OBJEXT) Concurrency/Keywords.$(OBJEXT) \
    248         Concurrency/Waitfor.$(OBJEXT) $(am__objects_3) \
    249         Common/DebugMalloc.$(OBJEXT) $(am__objects_4) \
     238        Concurrency/Waitfor.$(OBJEXT) $(am__objects_2) \
     239        Common/DebugMalloc.$(OBJEXT) $(am__objects_3) \
    250240        ControlStruct/ExceptTranslate.$(OBJEXT) GenPoly/Box.$(OBJEXT) \
    251241        GenPoly/GenPoly.$(OBJEXT) GenPoly/ScrubTyVars.$(OBJEXT) \
     
    261251        Parser/InitializerNode.$(OBJEXT) Parser/TypeData.$(OBJEXT) \
    262252        Parser/LinkageSpec.$(OBJEXT) Parser/parserutility.$(OBJEXT) \
    263         $(am__objects_5) ResolvExpr/AlternativePrinter.$(OBJEXT) \
    264         $(am__objects_6) $(am__objects_7) \
     253        $(am__objects_4) ResolvExpr/AlternativePrinter.$(OBJEXT) \
     254        $(am__objects_5) $(am__objects_6) \
    265255        Tuples/TupleAssignment.$(OBJEXT) \
    266256        Tuples/TupleExpansion.$(OBJEXT) Tuples/Explode.$(OBJEXT) \
     
    268258        Validate/FindSpecialDecls.$(OBJEXT) \
    269259        Virtual/ExpandCasts.$(OBJEXT)
    270 am____driver_cfa_cpp_OBJECTS = $(am__objects_9)
     260am____driver_cfa_cpp_OBJECTS = $(am__objects_8)
    271261___driver_cfa_cpp_OBJECTS = $(am____driver_cfa_cpp_OBJECTS)
    272262am__DEPENDENCIES_1 =
     
    378368ETAGS = etags
    379369CTAGS = ctags
    380 am__DIST_COMMON = $(srcdir)/AST/module.mk $(srcdir)/CodeGen/module.mk \
     370am__DIST_COMMON = $(srcdir)/CodeGen/module.mk \
    381371        $(srcdir)/CodeTools/module.mk $(srcdir)/Common/module.mk \
    382372        $(srcdir)/Concurrency/module.mk \
     
    538528AUTOMAKE_OPTIONS = foreign subdir-objects
    539529ACLOCAL_AMFLAGS = -I automake
    540 SRC = main.cc MakeLibCfa.cc CompilationState.cc $(SRC_AST) \
    541         $(SRC_CODEGEN) CodeGen/Generate.cc CodeGen/FixNames.cc \
    542         CodeTools/DeclStats.cc CodeTools/ResolvProtoDump.cc \
    543         CodeTools/TrackLoc.cc Concurrency/Keywords.cc \
    544         Concurrency/Waitfor.cc $(SRC_COMMON) Common/DebugMalloc.cc \
    545         $(SRC_CONTROLSTRUCT) ControlStruct/ExceptTranslate.cc \
    546         GenPoly/Box.cc GenPoly/GenPoly.cc GenPoly/ScrubTyVars.cc \
    547         GenPoly/Lvalue.cc GenPoly/Specialize.cc \
    548         GenPoly/FindFunction.cc GenPoly/InstantiateGeneric.cc \
    549         InitTweak/GenInit.cc InitTweak/FixInit.cc \
    550         InitTweak/FixGlobalInit.cc InitTweak/InitTweak.cc \
    551         Parser/parser.yy Parser/lex.ll Parser/TypedefTable.cc \
    552         Parser/ParseNode.cc Parser/DeclarationNode.cc \
    553         Parser/ExpressionNode.cc Parser/StatementNode.cc \
    554         Parser/InitializerNode.cc Parser/TypeData.cc \
    555         Parser/LinkageSpec.cc Parser/parserutility.cc \
    556         $(SRC_RESOLVEXPR) ResolvExpr/AlternativePrinter.cc \
    557         $(SRC_SYMTAB) $(SRC_SYNTREE) Tuples/TupleAssignment.cc \
    558         Tuples/TupleExpansion.cc Tuples/Explode.cc \
    559         Validate/HandleAttributes.cc Validate/FindSpecialDecls.cc \
    560         Virtual/ExpandCasts.cc
    561 SRCDEMANGLE = CompilationState.cc $(SRC_AST) $(SRC_CODEGEN) \
     530SRC = main.cc MakeLibCfa.cc CompilationState.cc $(SRC_CODEGEN) \
     531        CodeGen/Generate.cc CodeGen/FixNames.cc CodeTools/DeclStats.cc \
     532        CodeTools/ResolvProtoDump.cc CodeTools/TrackLoc.cc \
     533        Concurrency/Keywords.cc Concurrency/Waitfor.cc $(SRC_COMMON) \
     534        Common/DebugMalloc.cc $(SRC_CONTROLSTRUCT) \
     535        ControlStruct/ExceptTranslate.cc GenPoly/Box.cc \
     536        GenPoly/GenPoly.cc GenPoly/ScrubTyVars.cc GenPoly/Lvalue.cc \
     537        GenPoly/Specialize.cc GenPoly/FindFunction.cc \
     538        GenPoly/InstantiateGeneric.cc InitTweak/GenInit.cc \
     539        InitTweak/FixInit.cc InitTweak/FixGlobalInit.cc \
     540        InitTweak/InitTweak.cc Parser/parser.yy Parser/lex.ll \
     541        Parser/TypedefTable.cc Parser/ParseNode.cc \
     542        Parser/DeclarationNode.cc Parser/ExpressionNode.cc \
     543        Parser/StatementNode.cc Parser/InitializerNode.cc \
     544        Parser/TypeData.cc Parser/LinkageSpec.cc \
     545        Parser/parserutility.cc $(SRC_RESOLVEXPR) \
     546        ResolvExpr/AlternativePrinter.cc $(SRC_SYMTAB) $(SRC_SYNTREE) \
     547        Tuples/TupleAssignment.cc Tuples/TupleExpansion.cc \
     548        Tuples/Explode.cc Validate/HandleAttributes.cc \
     549        Validate/FindSpecialDecls.cc Virtual/ExpandCasts.cc
     550SRCDEMANGLE = CompilationState.cc $(SRC_CODEGEN) \
    562551        Concurrency/Keywords.cc $(SRC_COMMON) $(SRC_CONTROLSTRUCT) \
    563552        GenPoly/GenPoly.cc GenPoly/Lvalue.cc InitTweak/GenInit.cc \
     
    573562@WITH_LIBTCMALLOC_TRUE@LIBTCMALLOC = -ltcmalloc
    574563@WITH_LIBTCMALLOC_TRUE@TCMALLOCFLAG = -DTCMALLOC
    575 SRC_AST = \
    576         AST/Attribute.cpp \
    577         AST/Convert.cpp \
    578         AST/Decl.cpp \
    579         AST/DeclReplacer.cpp \
    580         AST/Expr.cpp \
    581         AST/GenericSubstitution.cpp \
    582         AST/Init.cpp \
    583         AST/LinkageSpec.cpp \
    584         AST/Node.cpp \
    585         AST/Pass.cpp \
    586         AST/Print.cpp \
    587         AST/Stmt.cpp \
    588         AST/Type.cpp \
    589         AST/TypeSubstitution.cpp
    590 
    591564SRC_CODEGEN = \
    592565        CodeGen/CodeGenerator.cc \
     
    697670
    698671.SUFFIXES:
    699 .SUFFIXES: .cc .cpp .ll .lo .o .obj .yy
    700 $(srcdir)/Makefile.in:  $(srcdir)/Makefile.am $(srcdir)/AST/module.mk $(srcdir)/CodeGen/module.mk $(srcdir)/CodeTools/module.mk $(srcdir)/Concurrency/module.mk $(srcdir)/Common/module.mk $(srcdir)/ControlStruct/module.mk $(srcdir)/GenPoly/module.mk $(srcdir)/InitTweak/module.mk $(srcdir)/Parser/module.mk $(srcdir)/ResolvExpr/module.mk $(srcdir)/SymTab/module.mk $(srcdir)/SynTree/module.mk $(srcdir)/Tuples/module.mk $(srcdir)/Validate/module.mk $(srcdir)/Virtual/module.mk $(am__configure_deps)
     672.SUFFIXES: .cc .ll .lo .o .obj .yy
     673$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am $(srcdir)/CodeGen/module.mk $(srcdir)/CodeTools/module.mk $(srcdir)/Concurrency/module.mk $(srcdir)/Common/module.mk $(srcdir)/ControlStruct/module.mk $(srcdir)/GenPoly/module.mk $(srcdir)/InitTweak/module.mk $(srcdir)/Parser/module.mk $(srcdir)/ResolvExpr/module.mk $(srcdir)/SymTab/module.mk $(srcdir)/SynTree/module.mk $(srcdir)/Tuples/module.mk $(srcdir)/Validate/module.mk $(srcdir)/Virtual/module.mk $(am__configure_deps)
    701674        @for dep in $?; do \
    702675          case '$(am__configure_deps)' in \
     
    718691            cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
    719692        esac;
    720 $(srcdir)/AST/module.mk $(srcdir)/CodeGen/module.mk $(srcdir)/CodeTools/module.mk $(srcdir)/Concurrency/module.mk $(srcdir)/Common/module.mk $(srcdir)/ControlStruct/module.mk $(srcdir)/GenPoly/module.mk $(srcdir)/InitTweak/module.mk $(srcdir)/Parser/module.mk $(srcdir)/ResolvExpr/module.mk $(srcdir)/SymTab/module.mk $(srcdir)/SynTree/module.mk $(srcdir)/Tuples/module.mk $(srcdir)/Validate/module.mk $(srcdir)/Virtual/module.mk $(am__empty):
     693$(srcdir)/CodeGen/module.mk $(srcdir)/CodeTools/module.mk $(srcdir)/Concurrency/module.mk $(srcdir)/Common/module.mk $(srcdir)/ControlStruct/module.mk $(srcdir)/GenPoly/module.mk $(srcdir)/InitTweak/module.mk $(srcdir)/Parser/module.mk $(srcdir)/ResolvExpr/module.mk $(srcdir)/SymTab/module.mk $(srcdir)/SynTree/module.mk $(srcdir)/Tuples/module.mk $(srcdir)/Validate/module.mk $(srcdir)/Virtual/module.mk $(am__empty):
    721694
    722695$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
     
    731704clean-noinstLIBRARIES:
    732705        -test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES)
    733 AST/$(am__dirstamp):
    734         @$(MKDIR_P) AST
    735         @: > AST/$(am__dirstamp)
    736 AST/$(DEPDIR)/$(am__dirstamp):
    737         @$(MKDIR_P) AST/$(DEPDIR)
    738         @: > AST/$(DEPDIR)/$(am__dirstamp)
    739 AST/Attribute.$(OBJEXT): AST/$(am__dirstamp) \
    740         AST/$(DEPDIR)/$(am__dirstamp)
    741 AST/Convert.$(OBJEXT): AST/$(am__dirstamp) \
    742         AST/$(DEPDIR)/$(am__dirstamp)
    743 AST/Decl.$(OBJEXT): AST/$(am__dirstamp) AST/$(DEPDIR)/$(am__dirstamp)
    744 AST/DeclReplacer.$(OBJEXT): AST/$(am__dirstamp) \
    745         AST/$(DEPDIR)/$(am__dirstamp)
    746 AST/Expr.$(OBJEXT): AST/$(am__dirstamp) AST/$(DEPDIR)/$(am__dirstamp)
    747 AST/GenericSubstitution.$(OBJEXT): AST/$(am__dirstamp) \
    748         AST/$(DEPDIR)/$(am__dirstamp)
    749 AST/Init.$(OBJEXT): AST/$(am__dirstamp) AST/$(DEPDIR)/$(am__dirstamp)
    750 AST/LinkageSpec.$(OBJEXT): AST/$(am__dirstamp) \
    751         AST/$(DEPDIR)/$(am__dirstamp)
    752 AST/Node.$(OBJEXT): AST/$(am__dirstamp) AST/$(DEPDIR)/$(am__dirstamp)
    753 AST/Pass.$(OBJEXT): AST/$(am__dirstamp) AST/$(DEPDIR)/$(am__dirstamp)
    754 AST/Print.$(OBJEXT): AST/$(am__dirstamp) AST/$(DEPDIR)/$(am__dirstamp)
    755 AST/Stmt.$(OBJEXT): AST/$(am__dirstamp) AST/$(DEPDIR)/$(am__dirstamp)
    756 AST/Type.$(OBJEXT): AST/$(am__dirstamp) AST/$(DEPDIR)/$(am__dirstamp)
    757 AST/TypeSubstitution.$(OBJEXT): AST/$(am__dirstamp) \
    758         AST/$(DEPDIR)/$(am__dirstamp)
    759706CodeGen/$(am__dirstamp):
    760707        @$(MKDIR_P) CodeGen
     
    11551102mostlyclean-compile:
    11561103        -rm -f *.$(OBJEXT)
    1157         -rm -f AST/*.$(OBJEXT)
    11581104        -rm -f CodeGen/*.$(OBJEXT)
    11591105        -rm -f CodeTools/*.$(OBJEXT)
     
    11781124@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MakeLibCfa.Po@am__quote@
    11791125@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@
    1180 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/Attribute.Po@am__quote@
    1181 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/Convert.Po@am__quote@
    1182 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/Decl.Po@am__quote@
    1183 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/DeclReplacer.Po@am__quote@
    1184 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/Expr.Po@am__quote@
    1185 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/GenericSubstitution.Po@am__quote@
    1186 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/Init.Po@am__quote@
    1187 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/LinkageSpec.Po@am__quote@
    1188 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/Node.Po@am__quote@
    1189 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/Pass.Po@am__quote@
    1190 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/Print.Po@am__quote@
    1191 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/Stmt.Po@am__quote@
    1192 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/Type.Po@am__quote@
    1193 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/TypeSubstitution.Po@am__quote@
    11941126@AMDEP_TRUE@@am__include@ @am__quote@CodeGen/$(DEPDIR)/CodeGenerator.Po@am__quote@
    11951127@AMDEP_TRUE@@am__include@ @am__quote@CodeGen/$(DEPDIR)/FixMain.Po@am__quote@
     
    13351267@am__fastdepCXX_FALSE@  $(AM_V_CXX@am__nodep@)$(LTCXXCOMPILE) -c -o $@ $<
    13361268
    1337 .cpp.o:
    1338 @am__fastdepCXX_TRUE@   $(AM_V_CXX)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
    1339 @am__fastdepCXX_TRUE@   $(CXXCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\
    1340 @am__fastdepCXX_TRUE@   $(am__mv) $$depbase.Tpo $$depbase.Po
    1341 @AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(AM_V_CXX)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
    1342 @AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
    1343 @am__fastdepCXX_FALSE@  $(AM_V_CXX@am__nodep@)$(CXXCOMPILE) -c -o $@ $<
    1344 
    1345 .cpp.obj:
    1346 @am__fastdepCXX_TRUE@   $(AM_V_CXX)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'`;\
    1347 @am__fastdepCXX_TRUE@   $(CXXCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ `$(CYGPATH_W) '$<'` &&\
    1348 @am__fastdepCXX_TRUE@   $(am__mv) $$depbase.Tpo $$depbase.Po
    1349 @AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(AM_V_CXX)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
    1350 @AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
    1351 @am__fastdepCXX_FALSE@  $(AM_V_CXX@am__nodep@)$(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
    1352 
    1353 .cpp.lo:
    1354 @am__fastdepCXX_TRUE@   $(AM_V_CXX)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'`;\
    1355 @am__fastdepCXX_TRUE@   $(LTCXXCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\
    1356 @am__fastdepCXX_TRUE@   $(am__mv) $$depbase.Tpo $$depbase.Plo
    1357 @AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(AM_V_CXX)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
    1358 @AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
    1359 @am__fastdepCXX_FALSE@  $(AM_V_CXX@am__nodep@)$(LTCXXCOMPILE) -c -o $@ $<
    1360 
    13611269.ll.cc:
    13621270        $(AM_V_LEX)$(am__skiplex) $(SHELL) $(YLWRAP) $< $(LEX_OUTPUT_ROOT).c $@ -- $(LEXCOMPILE)
     
    14911399        -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
    14921400        -rm -f ../driver/$(am__dirstamp)
    1493         -rm -f AST/$(DEPDIR)/$(am__dirstamp)
    1494         -rm -f AST/$(am__dirstamp)
    14951401        -rm -f CodeGen/$(DEPDIR)/$(am__dirstamp)
    14961402        -rm -f CodeGen/$(am__dirstamp)
     
    15381444
    15391445distclean: distclean-am
    1540         -rm -rf ./$(DEPDIR) AST/$(DEPDIR) CodeGen/$(DEPDIR) CodeTools/$(DEPDIR) Common/$(DEPDIR) Common/Stats/$(DEPDIR) Concurrency/$(DEPDIR) ControlStruct/$(DEPDIR) GenPoly/$(DEPDIR) InitTweak/$(DEPDIR) Parser/$(DEPDIR) ResolvExpr/$(DEPDIR) SymTab/$(DEPDIR) SynTree/$(DEPDIR) Tuples/$(DEPDIR) Validate/$(DEPDIR) Virtual/$(DEPDIR)
     1446        -rm -rf ./$(DEPDIR) CodeGen/$(DEPDIR) CodeTools/$(DEPDIR) Common/$(DEPDIR) Common/Stats/$(DEPDIR) Concurrency/$(DEPDIR) ControlStruct/$(DEPDIR) GenPoly/$(DEPDIR) InitTweak/$(DEPDIR) Parser/$(DEPDIR) ResolvExpr/$(DEPDIR) SymTab/$(DEPDIR) SynTree/$(DEPDIR) Tuples/$(DEPDIR) Validate/$(DEPDIR) Virtual/$(DEPDIR)
    15411447        -rm -f Makefile
    15421448distclean-am: clean-am distclean-compile distclean-generic \
     
    15841490
    15851491maintainer-clean: maintainer-clean-am
    1586         -rm -rf ./$(DEPDIR) AST/$(DEPDIR) CodeGen/$(DEPDIR) CodeTools/$(DEPDIR) Common/$(DEPDIR) Common/Stats/$(DEPDIR) Concurrency/$(DEPDIR) ControlStruct/$(DEPDIR) GenPoly/$(DEPDIR) InitTweak/$(DEPDIR) Parser/$(DEPDIR) ResolvExpr/$(DEPDIR) SymTab/$(DEPDIR) SynTree/$(DEPDIR) Tuples/$(DEPDIR) Validate/$(DEPDIR) Virtual/$(DEPDIR)
     1492        -rm -rf ./$(DEPDIR) CodeGen/$(DEPDIR) CodeTools/$(DEPDIR) Common/$(DEPDIR) Common/Stats/$(DEPDIR) Concurrency/$(DEPDIR) ControlStruct/$(DEPDIR) GenPoly/$(DEPDIR) InitTweak/$(DEPDIR) Parser/$(DEPDIR) ResolvExpr/$(DEPDIR) SymTab/$(DEPDIR) SynTree/$(DEPDIR) Tuples/$(DEPDIR) Validate/$(DEPDIR) Virtual/$(DEPDIR)
    15871493        -rm -f Makefile
    15881494maintainer-clean-am: distclean-am maintainer-clean-generic
  • src/ResolvExpr/Unify.cc

    rd908563 r933f32f  
    179179                                result = false;
    180180                        } else {
    181                                 result = env.bindVarToVar(
    182                                         var1, var2, TypeDecl::Data{ entry1->second, entry2->second }, needAssertions,
     181                                result = env.bindVarToVar( 
     182                                        var1, var2, TypeDecl::Data{ entry1->second, entry2->second }, needAssertions, 
    183183                                        haveAssertions, openVars, widenMode, indexer );
    184184                        }
     
    648648
    649649        ast::ptr<ast::Type> extractResultType( const ast::FunctionType * func ) {
    650                 if ( func->returns.empty() ) return new ast::VoidType{};
    651                 if ( func->returns.size() == 1 ) return func->returns[0]->get_type();
    652 
    653                 std::vector<ast::ptr<ast::Type>> tys;
    654                 for ( const ast::DeclWithType * decl : func->returns ) {
    655                         tys.emplace_back( decl->get_type() );
    656                 }
    657                 return new ast::TupleType{ std::move(tys) };
     650                assert(!"restore after AST added to build");
     651                // if ( func->returns.empty() ) return new ast::VoidType{};
     652                // if ( func->returns.size() == 1 ) return func->returns[0]->get_type();
     653
     654                // std::vector<ast::ptr<ast::Type>> tys;
     655                // for ( const ast::DeclWithType * decl : func->returns ) {
     656                //      tys.emplace_back( decl->get_type() );
     657                // }
     658                // return new ast::TupleType{ std::move(tys) };
    658659        }
    659660} // namespace ResolvExpr
  • src/SynTree/Declaration.h

    rd908563 r933f32f  
    286286        AggregateDecl * set_body( bool body ) { AggregateDecl::body = body; return this; }
    287287
    288         virtual void print( std::ostream &os, Indenter indent = {} ) const override final;
     288        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    289289        virtual void printShort( std::ostream &os, Indenter indent = {} ) const override;
    290290  protected:
  • src/SynTree/Expression.h

    rd908563 r933f32f  
    731731        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    732732        virtual void print( std::ostream & os, Indenter indent = {} ) const;
    733 
    734         friend class ConverterNewToOld;
    735   private:
    736     TupleAssignExpr( StmtExpr * stmts );
    737733};
    738734
  • src/SynTree/TupleExpr.cc

    rd908563 r933f32f  
    105105}
    106106
    107 TupleAssignExpr::TupleAssignExpr(
    108         StmtExpr * s )
    109 : Expression(), stmtExpr(s) {
    110 }
    111 
    112 
    113107TupleAssignExpr::~TupleAssignExpr() {
    114108        delete stmtExpr;
  • src/Tuples/TupleExpansion.cc

    rd908563 r933f32f  
    320320        }
    321321        const ast::Type * makeTupleType( const std::vector<ast::ptr<ast::Expr>> & exprs ) {
    322                 // produce the TupleType which aggregates the types of the exprs
    323                 std::vector<ast::ptr<ast::Type>> types;
    324                 ast::CV::Qualifiers quals{
    325                         ast::CV::Const | ast::CV::Volatile | ast::CV::Restrict | ast::CV::Lvalue |
    326                         ast::CV::Atomic | ast::CV::Mutex };
    327 
    328                 for ( const ast::Expr * expr : exprs ) {
    329                         assert( expr->result );
    330                         // if the type of any expr is void, the type of the entire tuple is void
    331                         if ( expr->result->isVoid() ) return new ast::VoidType{};
    332 
    333                         // qualifiers on the tuple type are the qualifiers that exist on all components
    334                         quals &= expr->result->qualifiers;
    335 
    336                         types.emplace_back( expr->result );
    337                 }
    338 
    339                 if ( exprs.empty() ) { quals = ast::CV::Qualifiers{}; }
    340                 return new ast::TupleType{ std::move(types), quals };
     322                (void) exprs;
     323                #warning Not implemented; needs Type.cpp in build
     324                assertf(false, "Not implemented; needs Type.cpp in build");
     325                // // produce the TupleType which aggregates the types of the exprs
     326                // std::vector<ast::ptr<ast::Type>> types;
     327                // ast::CV::Qualifiers quals{
     328                //      ast::CV::Const | ast::CV::Volatile | ast::CV::Restrict | ast::CV::Lvalue |
     329                //      ast::CV::Atomic | ast::CV::Mutex };
     330
     331                // for ( const ast::Expr * expr : exprs ) {
     332                //      assert( expr->result );
     333                //      // if the type of any expr is void, the type of the entire tuple is void
     334                //      if ( expr->result->isVoid() ) return new ast::VoidType{};
     335
     336                //      // qualifiers on the tuple type are the qualifiers that exist on all components
     337                //      quals &= expr->result->qualifiers;
     338
     339                //      types.emplace_back( expr->result );
     340                // }
     341
     342                // if ( exprs.empty() ) { quals = ast::CV::Qualifiers{}; }
     343                // return new ast::TupleType{ std::move(types), quals };
    341344        }
    342345
     
    344347                if ( TypeInstType * inst = dynamic_cast< TypeInstType * >( type ) ) {
    345348                        if ( inst->get_baseType() && inst->get_baseType()->get_kind() == TypeDecl::Ttype ) {
    346                                 return inst;
    347                         }
    348                 }
    349                 return nullptr;
    350         }
    351 
    352         const ast::TypeInstType * isTtype( const ast::Type * type ) {
    353                 if ( const ast::TypeInstType * inst = dynamic_cast< const ast::TypeInstType * >( type ) ) {
    354                         if ( inst->base && inst->base->kind == ast::TypeVar::Ttype ) {
    355349                                return inst;
    356350                        }
  • src/include/cassert

    rd908563 r933f32f  
    99// Author           : Peter A. Buhr
    1010// Created On       : Thu Aug 18 13:19:26 2016
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Thu May 23 15:30:00 2017
    13 // Update Count     : 17
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Tue Aug  1 11:56:01 2017
     13// Update Count     : 16
    1414//
    1515
     
    1919
    2020#include_next <cassert>
    21 
    22 #include <string>
    23 
    24 template < typename ... Params >
    25 std::string toString( const Params & ... params );
    2621
    2722#ifdef NDEBUG
     
    4338#endif
    4439
    45 enum StrictAllowNull {NonNull, AllowNull};
    46 
    47 template<typename T, StrictAllowNull nullable = NonNull, typename U>
     40template<typename T, typename U>
    4841static inline T strict_dynamic_cast( const U & src ) {
    49         if (nullable == AllowNull && src == nullptr) {
    50                 return nullptr;
    51         }
    52         assert(src);
    5342        T ret = dynamic_cast<T>(src);
    5443        assertf(ret, "%s", toString(src).c_str());
  • src/main.cc

    rd908563 r933f32f  
    4040#include "Common/Stats.h"
    4141#include "Common/PassVisitor.h"
     42// #include "AST/Pass.hpp"
    4243#include "Common/SemanticError.h"           // for SemanticError
    4344#include "Common/UnimplementedError.h"      // for UnimplementedError
Note: See TracChangeset for help on using the changeset viewer.