Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    rd148778 r112fe04  
    1010// Created On       : Thu May 09 15::37::05 2019
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Fri May 17 16:01:00 2019
    13 // Update Count     : 4
     12// Last Modified On : Tue May 21 15:30:00 2019
     13// Update Count     : 5
    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         std::unordered_map< ast::Node *, BaseSyntaxNode * > cache;
    4744
    4845        template<typename T>
     
    5249                template<typename U>
    5350                T * accept1( const ast::ptr<U> & ptr ) {
    54                         if ( ! ptr ) return nullptr;
    5551                        ptr->accept( visitor );
    5652                        T * ret = strict_dynamic_cast< T * >( visitor.node );
     
    9187        }
    9288
    93         /// get new qualifiers from old type
    94         Type::Qualifiers cv( const ast::Type * ty ) { return { ty->qualifiers.val }; }
    95 
    96         template<typename NewT, typename OldT>
    97         NewT * cached( OldT * old ) {
    98                 auto it = cache.find( old );
    99                 // doesn't update cache, that should be handled by the accept function
    100                 ast::Node * nw = it == cache.end() ? getAccept1< NewT >( old ) : it->second;
    101                 return strict_dynamic_cast< NewT * >( nw );
    102         }
    103 
    10489public:
    10590        Declaration * decl( const ast::Decl * declNode ) {
     
    10893
    10994private:
     95        void declPostamble( Declaration * decl, const ast::Decl * node ) {
     96                decl->location = node->location;
     97                // name comes from constructor
     98                // linkage comes from constructor
     99                decl->extension = node->extension;
     100                decl->uniqueId = node->uniqueId;
     101                // storageClasses comes from constructor
     102                this->node = decl;
     103        }
     104
     105        const ast::DeclWithType * declWithTypePostamble (
     106                        DeclarationWithType * decl, const ast::DeclWithType * node ) {
     107                declPostamble( decl, node );
     108                decl->mangleName = node->mangleName;
     109                decl->scopeLevel = node->scopeLevel;
     110                decl->asmName = get<Expression>().accept1( node->asmName );
     111                // attributes comes from constructor
     112                decl->isDeleted = node->isDeleted;
     113                // fs comes from constructor
     114                return nullptr;
     115        }
     116
    110117        const ast::DeclWithType * visit( const ast::ObjectDecl * node ) override final {
    111                 (void)node;
    112                 return nullptr;
     118                auto decl = new ObjectDecl(
     119                        node->name,
     120                        Type::StorageClasses( node->storage.val ),
     121                        LinkageSpec::Spec( node->linkage.val ),
     122                        get<Expression>().accept1( node->bitfieldWidth ),
     123                        get<Type>().accept1( node->type ),
     124                        get<Initializer>().accept1( node->init ),
     125                        get<Attribute>().acceptL( node->attributes ),
     126                        Type::FuncSpecifiers( node->funcSpec.val )
     127                );
     128                return declWithTypePostamble( decl, node );
    113129        }
    114130
    115131        const ast::DeclWithType * visit( const ast::FunctionDecl * node ) override final {
    116                 (void)node;
     132                auto decl = new FunctionDecl(
     133                        node->name,
     134                        Type::StorageClasses( node->storage.val ),
     135                        LinkageSpec::Spec( node->linkage.val ),
     136                        get<FunctionType>().accept1( node->type ),
     137                        get<CompoundStmt>().accept1( node->stmts ),
     138                        get<Attribute>().acceptL( node->attributes ),
     139                        Type::FuncSpecifiers( node->funcSpec.val )
     140                );
     141                decl->withExprs = get<Expression>().acceptL( node->withExprs );
     142                return declWithTypePostamble( decl, node );
     143        }
     144
     145        // NamedTypeDecl
     146        const ast::Decl * namedTypePostamble( NamedTypeDecl * decl, const ast::NamedTypeDecl * node ) {
     147                declPostamble( decl, node );
     148                // base comes from constructor
     149                decl->parameters = get<TypeDecl>().acceptL( node->params );
     150                decl->assertions = get<DeclarationWithType>().acceptL( node->assertions );
     151                return nullptr;
     152        }
     153
     154        const ast::Decl * visit( const ast::TypeDecl * node ) override final {
     155                TypeDecl::Kind kind;
     156                switch (node->kind) {
     157                case ast::TypeVar::Dtype:
     158                        kind = TypeDecl::Dtype;
     159                        break;
     160                case ast::TypeVar::Ftype:
     161                        kind = TypeDecl::Ftype;
     162                        break;
     163                case ast::TypeVar::Ttype:
     164                        kind = TypeDecl::Ttype;
     165                        break;
     166                default:
     167                        assertf(false, "Invalid ast::TypeVar::Kind: %d\n", node->kind);
     168                };
     169                auto decl = new TypeDecl(
     170                        node->name,
     171                        Type::StorageClasses( node->storage.val ),
     172                        get<Type>().accept1( node->base ),
     173                        kind,
     174                        node->sized,
     175                        get<Type>().accept1( node->init )
     176                );
     177                return namedTypePostamble( decl, node );
     178        }
     179
     180        const ast::Decl * visit( const ast::TypedefDecl * node ) override final {
     181                auto decl = new TypedefDecl(
     182                        node->name,
     183                        node->location,
     184                        Type::StorageClasses( node->storage.val ),
     185            get<Type>().accept1( node->base ),
     186                        LinkageSpec::Spec( node->linkage.val )
     187                );
     188                return namedTypePostamble( decl, node );
     189        }
     190
     191        const ast::Decl * aggregatePostamble( AggregateDecl * decl, const ast::AggregateDecl * node ) {
     192                decl->members = get<Declaration>().acceptL( node->members );
     193                decl->parameters = get<TypeDecl>().acceptL( node->params );
     194                decl->body = node->body;
     195                // attributes come from constructor
     196                // TODO: Need caching for: decl->parent = node->parent;
    117197                return nullptr;
    118198        }
    119199
    120200        const ast::Decl * visit( const ast::StructDecl * node ) override final {
    121                 (void)node;
    122                 return nullptr;
     201                auto decl = new StructDecl(
     202                        node->name,
     203                        node->kind,
     204                        get<Attribute>().acceptL( node->attributes ),
     205                        LinkageSpec::Spec( node->linkage.val )
     206                );
     207                return aggregatePostamble( decl, node );
    123208        }
    124209
    125210        const ast::Decl * visit( const ast::UnionDecl * node ) override final {
    126                 (void)node;
    127                 return nullptr;
     211                auto decl = new UnionDecl(
     212                        node->name,
     213                        get<Attribute>().acceptL( node->attributes ),
     214                        LinkageSpec::Spec( node->linkage.val )
     215                );
     216                return aggregatePostamble( decl, node );
    128217        }
    129218
    130219        const ast::Decl * visit( const ast::EnumDecl * node ) override final {
    131                 (void)node;
    132                 return nullptr;
     220                auto decl = new EnumDecl(
     221                        node->name,
     222                        get<Attribute>().acceptL( node->attributes ),
     223                        LinkageSpec::Spec( node->linkage.val )
     224                );
     225                return aggregatePostamble( decl, node );
    133226        }
    134227
    135228        const ast::Decl * visit( const ast::TraitDecl * node ) override final {
    136                 (void)node;
    137                 return nullptr;
    138         }
    139 
    140         const ast::Decl * visit( const ast::TypeDecl * node ) override final {
    141                 (void)node;
    142                 return nullptr;
    143         }
    144 
    145         const ast::Decl * visit( const ast::TypedefDecl * node ) override final {
    146                 (void)node;
    147                 return nullptr;
     229                auto decl = new TraitDecl(
     230                        node->name,
     231                        {},
     232                        LinkageSpec::Spec( node->linkage.val )
     233                );
     234                return aggregatePostamble( decl, node );
    148235        }
    149236
    150237        const ast::AsmDecl * visit( const ast::AsmDecl * node ) override final {
    151                 (void)node;
     238                auto decl = new AsmDecl( get<AsmStmt>().accept1( node->stmt ) );
     239                declPostamble( decl, node );
    152240                return nullptr;
    153241        }
    154242
    155243        const ast::StaticAssertDecl * visit( const ast::StaticAssertDecl * node ) override final {
    156                 (void)node;
    157                 return nullptr;
    158         }
    159 
    160         const ast::CompoundStmt * visit( const ast::CompoundStmt * node ) override final {
    161                 auto stmt = new CompoundStmt( get<Statement>().acceptL( node->kids ) );
     244                auto decl = new StaticAssertDecl(
     245                        get<Expression>().accept1( node->cond ),
     246                        get<ConstantExpr>().accept1( node->msg )
     247                );
     248                declPostamble( decl, node );
     249                return nullptr;
     250        }
     251
     252        const ast::Stmt * stmtPostamble( Statement * stmt, const ast::Stmt * node ) {
    162253                stmt->location = node->location;
    163254                stmt->labels = makeLabelL( stmt, node->labels );
     
    166257        }
    167258
     259        const ast::CompoundStmt * visit( const ast::CompoundStmt * node ) override final {
     260                auto stmt = new CompoundStmt( get<Statement>().acceptL( node->kids ) );
     261                stmtPostamble( stmt, node );
     262                return nullptr;
     263        }
     264
    168265        const ast::Stmt * visit( const ast::ExprStmt * node ) override final {
    169266                auto stmt = new ExprStmt( get<Expression>().accept1( node->expr ) );
    170                 stmt->location = node->location;
    171                 stmt->labels = makeLabelL( stmt, node->labels );
    172                 this->node = stmt;
    173                 return nullptr;
     267                return stmtPostamble( stmt, node );
    174268        }
    175269
     
    183277                        makeLabelL( nullptr, node->gotoLabels ) // What are these labelling?
    184278                );
    185                 stmt->location = node->location;
    186                 stmt->labels = makeLabelL( stmt, node->labels );
    187                 this->node = stmt;
    188                 return nullptr;
     279                return stmtPostamble( stmt, node );
    189280        }
    190281
    191282        const ast::Stmt * visit( const ast::DirectiveStmt * node ) override final {
    192283                auto stmt = new DirectiveStmt( node->directive );
    193                 stmt->location = node->location;
    194                 stmt->labels = makeLabelL( stmt, node->labels );
    195                 this->node = stmt;
    196                 return nullptr;
     284                return stmtPostamble( stmt, node );
    197285        }
    198286
     
    204292                        get<Statement>().acceptL( node->inits )
    205293                );
    206                 stmt->location = node->location;
    207                 stmt->labels = makeLabelL( stmt, node->labels );
    208                 this->node = stmt;
    209                 return nullptr;
     294                return stmtPostamble( stmt, node );
    210295        }
    211296
     
    215300                        get<Statement>().acceptL( node->stmts )
    216301                );
    217                 stmt->location = node->location;
    218                 stmt->labels = makeLabelL( stmt, node->labels );
    219                 this->node = stmt;
    220                 return nullptr;
     302                return stmtPostamble( stmt, node );
    221303        }
    222304
     
    227309                        node->isDefault()
    228310                );
    229                 stmt->location = node->location;
    230                 stmt->labels = makeLabelL( stmt, node->labels );
    231                 this->node = stmt;
    232                 return nullptr;
     311                return stmtPostamble( stmt, node );
    233312        }
    234313
     
    241320                        node->isDoWhile
    242321                );
    243                 stmt->location = node->location;
    244                 stmt->labels = makeLabelL( stmt, node->labels );
    245                 this->node = stmt;
    246                 return nullptr;
     322                return stmtPostamble( stmt, node );
    247323        }
    248324
     
    254330                        get<Statement>().accept1( node->body )
    255331                );
    256                 stmt->location = node->location;
    257                 stmt->labels = makeLabelL( stmt, node->labels );
    258                 this->node = stmt;
    259                 return nullptr;
     332                return stmtPostamble( stmt, node );
    260333        }
    261334
     
    286359                        stmt->target = makeLabel( stmt, node->target );
    287360                }
    288                 stmt->location = node->location;
    289                 stmt->labels = makeLabelL( stmt, node->labels );
    290                 this->node = stmt;
    291                 return nullptr;
     361                return stmtPostamble( stmt, node );
    292362        }
    293363
    294364        const ast::Stmt * visit( const ast::ReturnStmt * node ) override final {
    295365                auto stmt = new ReturnStmt( get<Expression>().accept1( node->expr ) );
    296                 stmt->location = node->location;
    297                 stmt->labels = makeLabelL( stmt, node->labels );
    298                 this->node = stmt;
    299                 return nullptr;
     366                return stmtPostamble( stmt, node );
    300367        }
    301368
     
    317384                        get<Expression>().accept1( node->target )
    318385                );
    319                 stmt->location = node->location;
    320                 stmt->labels = makeLabelL( stmt, node->labels );
    321                 this->node = stmt;
    322                 return nullptr;
     386                return stmtPostamble( stmt, node );
    323387        }
    324388
     
    330394                        get<FinallyStmt>().accept1( node->finally )
    331395                );
    332                 stmt->location = node->location;
    333                 stmt->labels = makeLabelL( stmt, node->labels );
    334                 this->node = stmt;
    335                 return nullptr;
     396                return stmtPostamble( stmt, node );
    336397        }
    337398
     
    354415                        get<Statement>().accept1( node->body )
    355416                );
    356                 stmt->location = node->location;
    357                 stmt->labels = makeLabelL( stmt, node->labels );
    358                 this->node = stmt;
    359                 return nullptr;
     417                return stmtPostamble( stmt, node );
    360418        }
    361419
    362420        const ast::Stmt * visit( const ast::FinallyStmt * node ) override final {
    363421                auto stmt = new FinallyStmt( get<CompoundStmt>().accept1( node->body ) );
    364                 stmt->location = node->location;
    365                 stmt->labels = makeLabelL( stmt, node->labels );
    366                 this->node = stmt;
    367                 return nullptr;
     422                return stmtPostamble( stmt, node );
    368423        }
    369424
     
    373428                for ( auto clause : node->clauses ) {
    374429                        stmt->clauses.push_back({{
    375                                         get<Expression>().accept1( clause.target.function ),
    376                                         get<Expression>().acceptL( clause.target.arguments ),
     430                                        get<Expression>().accept1( clause.target.func ),
     431                                        get<Expression>().acceptL( clause.target.args ),
    377432                                },
    378433                                get<Statement>().accept1( clause.stmt ),
     
    389444                        get<Expression>().accept1( node->orElse.cond ),
    390445                };
    391                 stmt->location = node->location;
    392                 stmt->labels = makeLabelL( stmt, node->labels );
    393                 this->node = stmt;
    394                 return nullptr;
     446                return stmtPostamble( stmt, node );
    395447        }
    396448
     
    400452                        get<Statement>().accept1( node->stmt )
    401453                );
    402                 stmt->location = node->location;
    403                 stmt->labels = makeLabelL( stmt, node->labels );
    404                 this->node = stmt;
    405                 return nullptr;
     454                return stmtPostamble( stmt, node );
    406455        }
    407456
    408457        const ast::NullStmt * visit( const ast::NullStmt * node ) override final {
    409458                auto stmt = new NullStmt();
    410                 stmt->location = node->location;
    411                 stmt->labels = makeLabelL( stmt, node->labels );
    412                 this->node = stmt;
     459                stmtPostamble( stmt, node );
    413460                return nullptr;
    414461        }
     
    416463        const ast::Stmt * visit( const ast::DeclStmt * node ) override final {
    417464                auto stmt = new DeclStmt( get<Declaration>().accept1( node->decl ) );
    418                 stmt->location = node->location;
    419                 stmt->labels = makeLabelL( stmt, node->labels );
    420                 this->node = stmt;
    421                 return nullptr;
     465                return stmtPostamble( stmt, node );
    422466        }
    423467
     
    427471        }
    428472
     473        TypeSubstitution * convertTypeSubstitution(const ast::TypeSubstitution * src) {
     474
     475                TypeSubstitution *rslt = new TypeSubstitution();
     476
     477                for (decltype(src->begin()) src_i = src->begin(); src_i != src->end(); src_i++) {
     478                        rslt->add( src_i->first,
     479                                   get<Type>().accept1(src_i->second) );
     480                }
     481
     482                for (decltype(src->beginVar()) src_i = src->beginVar(); src_i != src->endVar(); src_i++) {
     483                        rslt->addVar( src_i->first,
     484                                      get<Expression>().accept1(src_i->second) );
     485                }
     486
     487                return rslt;
     488        }
     489
     490        void convertInferUnion(std::map<UniqueId,ParamEntry> &tgtInferParams,
     491                                                   std::vector<UniqueId>         &tgtResnSlots,
     492                                                   const ast::Expr::InferUnion   &srcInferred ) {
     493
     494                assert( tgtInferParams.empty() );
     495                assert( tgtResnSlots.empty() );
     496
     497                if ( srcInferred.mode == ast::Expr::InferUnion::Params ) {
     498                        const ast::InferredParams &srcParams = srcInferred.inferParamsConst();
     499                        for (auto srcParam : srcParams) {
     500                                tgtInferParams[srcParam.first] = ParamEntry(
     501                                        srcParam.second.decl,
     502                                        get<Type>().accept1(srcParam.second.actualType),
     503                                        get<Type>().accept1(srcParam.second.formalType),
     504                                        get<Expression>().accept1(srcParam.second.expr)
     505                                );
     506                        }
     507                } else if ( srcInferred.mode == ast::Expr::InferUnion::Slots  ) {
     508                        const ast::ResnSlots &srcSlots = srcInferred.resnSlotsConst();
     509                        for (auto srcSlot : srcSlots) {
     510                                tgtResnSlots.push_back(srcSlot);
     511                        }
     512                }
     513        }
     514
     515        Expression * visitBaseExpr(const ast::Expr * src, Expression * tgt) {
     516
     517                tgt->location = src->location;
     518
     519                tgt->result = get<Type>().accept1(src->result);
     520                tgt->env    = convertTypeSubstitution(src->env);
     521
     522                tgt->extension = src->extension;
     523                convertInferUnion(tgt->inferParams, tgt->resnSlots, src->inferred);
     524
     525                return tgt;
     526        }
     527
    429528        const ast::Expr * visit( const ast::ApplicationExpr * node ) override final {
    430                 (void)node;
     529                auto expr = visitBaseExpr( node,
     530                        new ApplicationExpr(
     531                                get<Expression>().accept1(node->func),
     532                                get<Expression>().acceptL(node->args)
     533                        )
     534                );
     535                this->node = expr;
    431536                return nullptr;
    432537        }
    433538
    434539        const ast::Expr * visit( const ast::UntypedExpr * node ) override final {
    435                 (void)node;
     540                auto expr = visitBaseExpr( node,
     541                        new UntypedExpr(
     542                                get<Expression>().accept1(node->func),
     543                                get<Expression>().acceptL(node->args)
     544                        )
     545                );
     546                this->node = expr;
    436547                return nullptr;
    437548        }
    438549
    439550        const ast::Expr * visit( const ast::NameExpr * node ) override final {
    440                 (void)node;
     551                auto expr = visitBaseExpr( node,
     552                        new NameExpr(
     553                                node->name
     554                        )
     555                );
     556                this->node = expr;
    441557                return nullptr;
    442558        }
     
    613729
    614730        const ast::Type * visit( const ast::VoidType * node ) override final {
    615                 this->node = new VoidType{ cv( node ) };
     731                (void)node;
    616732                return nullptr;
    617733        }
    618734
    619735        const ast::Type * visit( const ast::BasicType * node ) override final {
    620                 this->node = new BasicType{ cv( node ), (BasicType::Kind)(unsigned)node->kind };
     736                (void)node;
    621737                return nullptr;
    622738        }
    623739
    624740        const ast::Type * visit( const ast::PointerType * node ) override final {
    625                 this->node = new PointerType{
    626                         cv( node ),
    627                         get<Type>().accept1( node->base ),
    628                         get<Expression>().accept1( node->dimension ),
    629                         node->isVarLen,
    630                         node->isStatic
    631                 };
     741                (void)node;
    632742                return nullptr;
    633743        }
    634744
    635745        const ast::Type * visit( const ast::ArrayType * node ) override final {
    636                 this->node = new ArrayType{
    637                         cv( node ),
    638                         get<Type>().accept1( node->base ),
    639                         get<Expression>().accept1( node->dimension ),
    640                         node->isVarLen,
    641                         node->isStatic
    642                 };
     746                (void)node;
    643747                return nullptr;
    644748        }
    645749
    646750        const ast::Type * visit( const ast::ReferenceType * node ) override final {
    647                 this->node = new ReferenceType{
    648                         cv( node ),
    649                         get<Type>().accept1( node->base )
    650                 };
     751                (void)node;
    651752                return nullptr;
    652753        }
    653754
    654755        const ast::Type * visit( const ast::QualifiedType * node ) override final {
    655                 this->node = new QualifiedType{
    656                         cv( node ),
    657                         get<Type>().accept1( node->parent ),
    658                         get<Type>().accept1( node->child )
    659                 };
     756                (void)node;
    660757                return nullptr;
    661758        }
    662759
    663760        const ast::Type * visit( const ast::FunctionType * node ) override final {
    664                 auto ty = new FunctionType { cv( node ), node->isVarArgs };
    665                 ty->returnVals = get<DeclarationWithType>().acceptL( node->returns );
    666                 ty->parameters = get<DeclarationWithType>().acceptL( node->params );
    667                 ty->forall = get<TypeDecl>().acceptL( node->forall );
    668                 node = ty;
     761                (void)node;
    669762                return nullptr;
    670763        }
     
    774867        }
    775868private:
    776         /// conversion output
    777869        ast::Node * node;
    778         /// cache of nodes that might be referenced by readonly<> for de-duplication
    779         std::unordered_map< BaseSyntaxNode *, ast::Node * > cache;
    780870
    781871        // Local Utilities:
     
    783873        template<typename NewT, typename OldT>
    784874        NewT * getAccept1( OldT old ) {
    785                 if ( ! old ) return nullptr;
    786875                old->accept(*this);
    787876                return strict_dynamic_cast< NewT * >( node );
     
    824913#       define GET_LABELS_V(labels) \
    825914                to<std::vector>::from( make_labels( std::move( labels ) ) )
    826        
    827         static ast::CV::Qualifiers cv( Type * ty ) { return { ty->get_qualifiers().val }; }
    828 
    829         template<typename NewT, typename OldT>
    830         NewT * cached( OldT * old ) {
    831                 auto it = cache.find( old );
    832                 // doesn't update cache, that should be handled by the accept function
    833                 ast::Node * nw = it == cache.end() ? getAccept1< NewT >( old ) : it->second;
    834                 return strict_dynamic_cast< NewT * >( nw );
    835         }
    836915
    837916        // Now all the visit functions:
     
    12361315                                      getAccept1<ast::Expr>(old_i->second) );
    12371316                }
    1238         }
    1239 
    1240         void convertInferUnion(ast::Expr::InferUnion &nwInferred, InferredParams oldInferParams, const std::vector<UniqueId> &oldResnSlots) {
    1241                
    1242                 (void) nwInferred;
    1243                 (void) oldInferParams;
    1244                 (void) oldResnSlots;
    1245                
    1246                 // TODO
     1317
     1318                return rslt;
     1319        }
     1320
     1321        void convertInferUnion(ast::Expr::InferUnion               &newInferred,
     1322                                                   const std::map<UniqueId,ParamEntry> &oldInferParams,
     1323                                                   const std::vector<UniqueId>         &oldResnSlots) {
     1324
     1325                assert( oldInferParams.empty() || oldResnSlots.empty() );
     1326                assert( newInferred.mode == ast::Expr::InferUnion::Empty );
     1327
     1328                if ( !oldInferParams.empty() ) {
     1329                        ast::InferredParams &tgt = newInferred.inferParams();
     1330                        for (auto old : oldInferParams) {
     1331                                tgt[old.first] = ast::ParamEntry(
     1332                                        old.second.decl,
     1333                                        getAccept1<ast::Type>(old.second.actualType),
     1334                                        getAccept1<ast::Type>(old.second.formalType),
     1335                                        getAccept1<ast::Expr>(old.second.expr)
     1336                                );
     1337                        }
     1338                } else if ( !oldResnSlots.empty() ) {
     1339                        ast::ResnSlots &tgt = newInferred.resnSlots();
     1340                        for (auto old : oldResnSlots) {
     1341                                tgt.push_back(old);
     1342                        }
     1343                }
    12471344        }
    12481345
     
    12581355        }
    12591356
    1260         virtual void visit( ApplicationExpr * ) override final {
    1261                 // TODO
    1262         }
    1263 
    1264         virtual void visit( UntypedExpr * ) override final {
    1265                 // TODO
     1357        virtual void visit( ApplicationExpr * old ) override final {
     1358                this->node = visitBaseExpr( old,
     1359                        new ast::ApplicationExpr(
     1360                                old->location,
     1361                                GET_ACCEPT_1(function, Expr),
     1362                                GET_ACCEPT_V(args, Expr)
     1363                        )
     1364                );
     1365        }
     1366
     1367        virtual void visit( UntypedExpr * old ) override final {
     1368                this->node = visitBaseExpr( old,
     1369                        new ast::UntypedExpr(
     1370                                old->location,
     1371                                GET_ACCEPT_1(function, Expr),
     1372                                GET_ACCEPT_V(args, Expr)
     1373                        )
     1374                );
    12661375        }
    12671376
     
    12751384        }
    12761385
    1277         virtual void visit( CastExpr * ) override final {
    1278                 // TODO ... (rest)
     1386        virtual void visit( CastExpr * old ) override final {
     1387                this->node = visitBaseExpr( old,
     1388                        new ast::CastExpr(
     1389                                old->location,
     1390                                nullptr, // cast's "to" type is expr's result type; converted in visitBaseExpr
     1391                                old->isGenerated ? ast::GeneratedCast : ast::ExplicitCast
     1392                        )
     1393                );
    12791394        }
    12801395
     
    14111526        }
    14121527
    1413         virtual void visit( VoidType * old ) override final {
    1414                 this->node = new ast::VoidType{ cv( old ) };
    1415         }
    1416 
    1417         virtual void visit( BasicType * old ) override final {
    1418                 this->node = new ast::BasicType{ (ast::BasicType::Kind)(unsigned)old->kind, cv( old ) };
    1419         }
    1420 
    1421         virtual void visit( PointerType * old ) override final {
    1422                 this->node = new ast::PointerType{
    1423                         GET_ACCEPT_1( base, Type ),
    1424                         GET_ACCEPT_1( dimension, Expr ),
    1425                         (ast::LengthFlag)old->isVarLen,
    1426                         (ast::DimensionFlag)old->isStatic,
    1427                         cv( old )
    1428                 };
    1429         }
    1430 
    1431         virtual void visit( ArrayType * old ) override final {
    1432                 this->node = new ast::ArrayType{
    1433                         GET_ACCEPT_1( base, Type ),
    1434                         GET_ACCEPT_1( dimension, Expr ),
    1435                         (ast::LengthFlag)old->isVarLen,
    1436                         (ast::DimensionFlag)old->isStatic,
    1437                         cv( old )
    1438                 };
    1439         }
    1440 
    1441         virtual void visit( ReferenceType * old ) override final {
    1442                 this->node = new ast::ReferenceType{
    1443                         GET_ACCEPT_1( base, Type ),
    1444                         cv( old )
    1445                 };
    1446         }
    1447 
    1448         virtual void visit( QualifiedType * old ) override final {
    1449                 this->node = new ast::QualifiedType{
    1450                         GET_ACCEPT_1( parent, Type ),
    1451                         GET_ACCEPT_1( child, Type ),
    1452                         cv( old )
    1453                 };
    1454         }
    1455 
    1456         virtual void visit( FunctionType * old ) override final {
    1457                 auto ty = new ast::FunctionType {
    1458                         (ast::ArgumentFlag)old->isVarArgs,
    1459                         cv( old )
    1460                 };
    1461                 ty->returns = GET_ACCEPT_V( returnVals, DeclWithType );
    1462                 ty->params = GET_ACCEPT_V( parameters, DeclWithType );
    1463                 ty->forall = GET_ACCEPT_V( forall, TypeDecl );
    1464                 this->node = ty;
    1465         }
    1466 
    1467         void postvisit( ReferenceToType * old, ast::ReferenceToType * ty ) {
    1468                 ty->forall = GET_ACCEPT_V( forall, TypeDecl );
    1469                 ty->params = GET_ACCEPT_V( parameters, Expr );
    1470                 ty->hoistType = old->hoistType;
    1471         }
    1472 
    1473         virtual void visit( StructInstType * old ) override final {
    1474                 auto ty = new ast::StructInstType{
    1475                         cached< ast::StructDecl >( old->baseStruct ),
    1476                         cv( old ),
    1477                         GET_ACCEPT_V( attributes, Attribute )
    1478                 };
    1479                 postvisit( old, ty );
    1480                 this->node = ty;
    1481         }
    1482 
    1483         virtual void visit( UnionInstType * old ) override final {
    1484                 auto ty = new ast::UnionInstType{
    1485                         cached< ast::UnionDecl >( old->baseUnion ),
    1486                         cv( old ),
    1487                         GET_ACCEPT_V( attributes, Attribute )
    1488                 };
    1489                 postvisit( old, ty );
    1490                 this->node = ty;
    1491         }
    1492 
    1493         virtual void visit( EnumInstType * old ) override final {
    1494                 auto ty = new ast::EnumInstType{
    1495                         cached< ast::EnumDecl >( old->baseEnum ),
    1496                         cv( old ),
    1497                         GET_ACCEPT_V( attributes, Attribute )
    1498                 };
    1499                 postvisit( old, ty );
    1500                 this->node = ty;
    1501         }
    1502 
    1503         virtual void visit( TraitInstType * old ) override final {
    1504                 auto ty = new ast::TraitInstType{
    1505                         cached< ast::TraitDecl >( old->baseTrait ),
    1506                         cv( old ),
    1507                         GET_ACCEPT_V( attributes, Attribute )
    1508                 };
    1509                 postvisit( old, ty );
    1510                 this->node = ty;
    1511         }
    1512 
    1513         virtual void visit( TypeInstType * old ) override final {
    1514                 auto ty = new ast::TypeInstType{
    1515                         cached< ast::TypeDecl >( old->baseStruct ),
    1516                         cv( old ),
    1517                         GET_ACCEPT_V( attributes, Attribute )
    1518                 };
    1519                 postvisit( old, ty );
    1520                 this->node = ty;
     1528        virtual void visit( VoidType * ) override final {
     1529
     1530        }
     1531
     1532        virtual void visit( BasicType * ) override final {
     1533
     1534        }
     1535
     1536        virtual void visit( PointerType * ) override final {
     1537
     1538        }
     1539
     1540        virtual void visit( ArrayType * ) override final {
     1541
     1542        }
     1543
     1544        virtual void visit( ReferenceType * ) override final {
     1545
     1546        }
     1547
     1548        virtual void visit( QualifiedType * ) override final {
     1549
     1550        }
     1551
     1552        virtual void visit( FunctionType * ) override final {
     1553
     1554        }
     1555
     1556        virtual void visit( StructInstType * ) override final {
     1557
     1558        }
     1559
     1560        virtual void visit( UnionInstType * ) override final {
     1561
     1562        }
     1563
     1564        virtual void visit( EnumInstType * ) override final {
     1565
     1566        }
     1567
     1568        virtual void visit( TraitInstType * ) override final {
     1569
     1570        }
     1571
     1572        virtual void visit( TypeInstType * ) override final {
     1573
    15211574        }
    15221575
Note: See TracChangeset for help on using the changeset viewer.