Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r112fe04 rd148778  
    1010// Created On       : Thu May 09 15::37::05 2019
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tue May 21 15:30:00 2019
    13 // Update Count     : 5
     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>
    1719
    1820#include "AST/Attribute.hpp"
     
    4244class ConverterNewToOld : public ast::Visitor {
    4345        BaseSyntaxNode * node = nullptr;
     46        std::unordered_map< ast::Node *, BaseSyntaxNode * > cache;
    4447
    4548        template<typename T>
     
    4952                template<typename U>
    5053                T * accept1( const ast::ptr<U> & ptr ) {
     54                        if ( ! ptr ) return nullptr;
    5155                        ptr->accept( visitor );
    5256                        T * ret = strict_dynamic_cast< T * >( visitor.node );
     
    8791        }
    8892
     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
    89104public:
    90105        Declaration * decl( const ast::Decl * declNode ) {
     
    93108
    94109private:
    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 
    117110        const ast::DeclWithType * visit( const ast::ObjectDecl * node ) override final {
    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 );
     111                (void)node;
     112                return nullptr;
    129113        }
    130114
    131115        const ast::DeclWithType * visit( const ast::FunctionDecl * node ) override final {
    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 );
     116                (void)node;
     117                return nullptr;
     118        }
     119
     120        const ast::Decl * visit( const ast::StructDecl * node ) override final {
     121                (void)node;
     122                return nullptr;
     123        }
     124
     125        const ast::Decl * visit( const ast::UnionDecl * node ) override final {
     126                (void)node;
     127                return nullptr;
     128        }
     129
     130        const ast::Decl * visit( const ast::EnumDecl * node ) override final {
     131                (void)node;
     132                return nullptr;
     133        }
     134
     135        const ast::Decl * visit( const ast::TraitDecl * node ) override final {
     136                (void)node;
    151137                return nullptr;
    152138        }
    153139
    154140        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 );
     141                (void)node;
     142                return nullptr;
    178143        }
    179144
    180145        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;
    197                 return nullptr;
    198         }
    199 
    200         const ast::Decl * visit( const ast::StructDecl * node ) override final {
    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 );
    208         }
    209 
    210         const ast::Decl * visit( const ast::UnionDecl * node ) override final {
    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 );
    217         }
    218 
    219         const ast::Decl * visit( const ast::EnumDecl * node ) override final {
    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 );
    226         }
    227 
    228         const ast::Decl * visit( const ast::TraitDecl * node ) override final {
    229                 auto decl = new TraitDecl(
    230                         node->name,
    231                         {},
    232                         LinkageSpec::Spec( node->linkage.val )
    233                 );
    234                 return aggregatePostamble( decl, node );
     146                (void)node;
     147                return nullptr;
    235148        }
    236149
    237150        const ast::AsmDecl * visit( const ast::AsmDecl * node ) override final {
    238                 auto decl = new AsmDecl( get<AsmStmt>().accept1( node->stmt ) );
    239                 declPostamble( decl, node );
     151                (void)node;
    240152                return nullptr;
    241153        }
    242154
    243155        const ast::StaticAssertDecl * visit( const ast::StaticAssertDecl * node ) override final {
    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 ) {
    253                 stmt->location = node->location;
    254                 stmt->labels = makeLabelL( stmt, node->labels );
    255                 this->node = stmt;
     156                (void)node;
    256157                return nullptr;
    257158        }
     
    259160        const ast::CompoundStmt * visit( const ast::CompoundStmt * node ) override final {
    260161                auto stmt = new CompoundStmt( get<Statement>().acceptL( node->kids ) );
    261                 stmtPostamble( stmt, node );
     162                stmt->location = node->location;
     163                stmt->labels = makeLabelL( stmt, node->labels );
     164                this->node = stmt;
    262165                return nullptr;
    263166        }
     
    265168        const ast::Stmt * visit( const ast::ExprStmt * node ) override final {
    266169                auto stmt = new ExprStmt( get<Expression>().accept1( node->expr ) );
    267                 return stmtPostamble( stmt, node );
     170                stmt->location = node->location;
     171                stmt->labels = makeLabelL( stmt, node->labels );
     172                this->node = stmt;
     173                return nullptr;
    268174        }
    269175
     
    277183                        makeLabelL( nullptr, node->gotoLabels ) // What are these labelling?
    278184                );
    279                 return stmtPostamble( stmt, node );
     185                stmt->location = node->location;
     186                stmt->labels = makeLabelL( stmt, node->labels );
     187                this->node = stmt;
     188                return nullptr;
    280189        }
    281190
    282191        const ast::Stmt * visit( const ast::DirectiveStmt * node ) override final {
    283192                auto stmt = new DirectiveStmt( node->directive );
    284                 return stmtPostamble( stmt, node );
     193                stmt->location = node->location;
     194                stmt->labels = makeLabelL( stmt, node->labels );
     195                this->node = stmt;
     196                return nullptr;
    285197        }
    286198
     
    292204                        get<Statement>().acceptL( node->inits )
    293205                );
    294                 return stmtPostamble( stmt, node );
     206                stmt->location = node->location;
     207                stmt->labels = makeLabelL( stmt, node->labels );
     208                this->node = stmt;
     209                return nullptr;
    295210        }
    296211
     
    300215                        get<Statement>().acceptL( node->stmts )
    301216                );
    302                 return stmtPostamble( stmt, node );
     217                stmt->location = node->location;
     218                stmt->labels = makeLabelL( stmt, node->labels );
     219                this->node = stmt;
     220                return nullptr;
    303221        }
    304222
     
    309227                        node->isDefault()
    310228                );
    311                 return stmtPostamble( stmt, node );
     229                stmt->location = node->location;
     230                stmt->labels = makeLabelL( stmt, node->labels );
     231                this->node = stmt;
     232                return nullptr;
    312233        }
    313234
     
    320241                        node->isDoWhile
    321242                );
    322                 return stmtPostamble( stmt, node );
     243                stmt->location = node->location;
     244                stmt->labels = makeLabelL( stmt, node->labels );
     245                this->node = stmt;
     246                return nullptr;
    323247        }
    324248
     
    330254                        get<Statement>().accept1( node->body )
    331255                );
    332                 return stmtPostamble( stmt, node );
     256                stmt->location = node->location;
     257                stmt->labels = makeLabelL( stmt, node->labels );
     258                this->node = stmt;
     259                return nullptr;
    333260        }
    334261
     
    359286                        stmt->target = makeLabel( stmt, node->target );
    360287                }
    361                 return stmtPostamble( stmt, node );
     288                stmt->location = node->location;
     289                stmt->labels = makeLabelL( stmt, node->labels );
     290                this->node = stmt;
     291                return nullptr;
    362292        }
    363293
    364294        const ast::Stmt * visit( const ast::ReturnStmt * node ) override final {
    365295                auto stmt = new ReturnStmt( get<Expression>().accept1( node->expr ) );
    366                 return stmtPostamble( stmt, node );
     296                stmt->location = node->location;
     297                stmt->labels = makeLabelL( stmt, node->labels );
     298                this->node = stmt;
     299                return nullptr;
    367300        }
    368301
     
    384317                        get<Expression>().accept1( node->target )
    385318                );
    386                 return stmtPostamble( stmt, node );
     319                stmt->location = node->location;
     320                stmt->labels = makeLabelL( stmt, node->labels );
     321                this->node = stmt;
     322                return nullptr;
    387323        }
    388324
     
    394330                        get<FinallyStmt>().accept1( node->finally )
    395331                );
    396                 return stmtPostamble( stmt, node );
     332                stmt->location = node->location;
     333                stmt->labels = makeLabelL( stmt, node->labels );
     334                this->node = stmt;
     335                return nullptr;
    397336        }
    398337
     
    415354                        get<Statement>().accept1( node->body )
    416355                );
    417                 return stmtPostamble( stmt, node );
     356                stmt->location = node->location;
     357                stmt->labels = makeLabelL( stmt, node->labels );
     358                this->node = stmt;
     359                return nullptr;
    418360        }
    419361
    420362        const ast::Stmt * visit( const ast::FinallyStmt * node ) override final {
    421363                auto stmt = new FinallyStmt( get<CompoundStmt>().accept1( node->body ) );
    422                 return stmtPostamble( stmt, node );
     364                stmt->location = node->location;
     365                stmt->labels = makeLabelL( stmt, node->labels );
     366                this->node = stmt;
     367                return nullptr;
    423368        }
    424369
     
    428373                for ( auto clause : node->clauses ) {
    429374                        stmt->clauses.push_back({{
    430                                         get<Expression>().accept1( clause.target.func ),
    431                                         get<Expression>().acceptL( clause.target.args ),
     375                                        get<Expression>().accept1( clause.target.function ),
     376                                        get<Expression>().acceptL( clause.target.arguments ),
    432377                                },
    433378                                get<Statement>().accept1( clause.stmt ),
     
    444389                        get<Expression>().accept1( node->orElse.cond ),
    445390                };
    446                 return stmtPostamble( stmt, node );
     391                stmt->location = node->location;
     392                stmt->labels = makeLabelL( stmt, node->labels );
     393                this->node = stmt;
     394                return nullptr;
    447395        }
    448396
     
    452400                        get<Statement>().accept1( node->stmt )
    453401                );
    454                 return stmtPostamble( stmt, node );
     402                stmt->location = node->location;
     403                stmt->labels = makeLabelL( stmt, node->labels );
     404                this->node = stmt;
     405                return nullptr;
    455406        }
    456407
    457408        const ast::NullStmt * visit( const ast::NullStmt * node ) override final {
    458409                auto stmt = new NullStmt();
    459                 stmtPostamble( stmt, node );
     410                stmt->location = node->location;
     411                stmt->labels = makeLabelL( stmt, node->labels );
     412                this->node = stmt;
    460413                return nullptr;
    461414        }
     
    463416        const ast::Stmt * visit( const ast::DeclStmt * node ) override final {
    464417                auto stmt = new DeclStmt( get<Declaration>().accept1( node->decl ) );
    465                 return stmtPostamble( stmt, node );
     418                stmt->location = node->location;
     419                stmt->labels = makeLabelL( stmt, node->labels );
     420                this->node = stmt;
     421                return nullptr;
    466422        }
    467423
     
    471427        }
    472428
    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 
    528429        const ast::Expr * visit( const ast::ApplicationExpr * node ) override final {
    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;
     430                (void)node;
    536431                return nullptr;
    537432        }
    538433
    539434        const ast::Expr * visit( const ast::UntypedExpr * node ) override final {
    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;
     435                (void)node;
    547436                return nullptr;
    548437        }
    549438
    550439        const ast::Expr * visit( const ast::NameExpr * node ) override final {
    551                 auto expr = visitBaseExpr( node,
    552                         new NameExpr(
    553                                 node->name
    554                         )
    555                 );
    556                 this->node = expr;
     440                (void)node;
    557441                return nullptr;
    558442        }
     
    729613
    730614        const ast::Type * visit( const ast::VoidType * node ) override final {
    731                 (void)node;
     615                this->node = new VoidType{ cv( node ) };
    732616                return nullptr;
    733617        }
    734618
    735619        const ast::Type * visit( const ast::BasicType * node ) override final {
    736                 (void)node;
     620                this->node = new BasicType{ cv( node ), (BasicType::Kind)(unsigned)node->kind };
    737621                return nullptr;
    738622        }
    739623
    740624        const ast::Type * visit( const ast::PointerType * node ) override final {
    741                 (void)node;
     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                };
    742632                return nullptr;
    743633        }
    744634
    745635        const ast::Type * visit( const ast::ArrayType * node ) override final {
    746                 (void)node;
     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                };
    747643                return nullptr;
    748644        }
    749645
    750646        const ast::Type * visit( const ast::ReferenceType * node ) override final {
    751                 (void)node;
     647                this->node = new ReferenceType{
     648                        cv( node ),
     649                        get<Type>().accept1( node->base )
     650                };
    752651                return nullptr;
    753652        }
    754653
    755654        const ast::Type * visit( const ast::QualifiedType * node ) override final {
    756                 (void)node;
     655                this->node = new QualifiedType{
     656                        cv( node ),
     657                        get<Type>().accept1( node->parent ),
     658                        get<Type>().accept1( node->child )
     659                };
    757660                return nullptr;
    758661        }
    759662
    760663        const ast::Type * visit( const ast::FunctionType * node ) override final {
    761                 (void)node;
     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;
    762669                return nullptr;
    763670        }
     
    867774        }
    868775private:
     776        /// conversion output
    869777        ast::Node * node;
     778        /// cache of nodes that might be referenced by readonly<> for de-duplication
     779        std::unordered_map< BaseSyntaxNode *, ast::Node * > cache;
    870780
    871781        // Local Utilities:
     
    873783        template<typename NewT, typename OldT>
    874784        NewT * getAccept1( OldT old ) {
     785                if ( ! old ) return nullptr;
    875786                old->accept(*this);
    876787                return strict_dynamic_cast< NewT * >( node );
     
    913824#       define GET_LABELS_V(labels) \
    914825                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        }
    915836
    916837        // Now all the visit functions:
     
    13151236                                      getAccept1<ast::Expr>(old_i->second) );
    13161237                }
    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                 }
     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
    13441247        }
    13451248
     
    13551258        }
    13561259
    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                 );
     1260        virtual void visit( ApplicationExpr * ) override final {
     1261                // TODO
     1262        }
     1263
     1264        virtual void visit( UntypedExpr * ) override final {
     1265                // TODO
    13751266        }
    13761267
     
    13841275        }
    13851276
    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                 );
     1277        virtual void visit( CastExpr * ) override final {
     1278                // TODO ... (rest)
    13941279        }
    13951280
     
    15261411        }
    15271412
    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 
     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;
    15741521        }
    15751522
Note: See TracChangeset for help on using the changeset viewer.