Changeset 74dbbf6


Ignore:
Timestamp:
May 17, 2019, 12:15:44 PM (5 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
172d9342, 675d816
Parents:
896737b
Message:

ConverterNewToOld? boiler-plate code.

Location:
src/AST
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r896737b r74dbbf6  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Convert.cpp --
     7// Convert.cpp -- Convert between the new and old syntax trees.
    88//
    99// Author           : Thierry Delisle
    1010// Created On       : Thu May 09 15::37::05 2019
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Fri May 17 11:14:00 2019
    13 // Update Count     : 2
     12// Last Modified On : Fri May 17 12:13:00 2019
     13// Update Count     : 3
    1414//
    1515
     
    4141
    4242//================================================================================================
    43 class ConverterNewToOld {
     43class ConverterNewToOld : public ast::Visitor {
    4444public:
    45         std::list< Declaration * > translationUnit;
     45        template<typename T>
     46        T * get() {
     47                T * ret = strict_dynamic_cast< T * >( node );
     48                node = nullptr;
     49                return ret;
     50        }
     51
     52private:
     53        BaseSyntaxNode * node = nullptr;
     54
     55        // All the visit functions:
     56
     57        const ast::DeclWithType * visit( const ast::ObjectDecl * node ) override final {
     58                (void)node;
     59                return nullptr;
     60        }
     61
     62        const ast::DeclWithType * visit( const ast::FunctionDecl * node ) override final {
     63                (void)node;
     64                return nullptr;
     65        }
     66
     67        const ast::Decl * visit( const ast::StructDecl * node ) override final {
     68                (void)node;
     69                return nullptr;
     70        }
     71
     72        const ast::Decl * visit( const ast::UnionDecl * node ) override final {
     73                (void)node;
     74                return nullptr;
     75        }
     76
     77        const ast::Decl * visit( const ast::EnumDecl * node ) override final {
     78                (void)node;
     79                return nullptr;
     80        }
     81
     82        const ast::Decl * visit( const ast::TraitDecl * node ) override final {
     83                (void)node;
     84                return nullptr;
     85        }
     86
     87        const ast::Decl * visit( const ast::TypeDecl * node ) override final {
     88                (void)node;
     89                return nullptr;
     90        }
     91
     92        const ast::Decl * visit( const ast::TypedefDecl * node ) override final {
     93                (void)node;
     94                return nullptr;
     95        }
     96
     97        const ast::AsmDecl * visit( const ast::AsmDecl * node ) override final {
     98                (void)node;
     99                return nullptr;
     100        }
     101
     102        const ast::StaticAssertDecl * visit( const ast::StaticAssertDecl * node ) override final {
     103                (void)node;
     104                return nullptr;
     105        }
     106
     107        const ast::CompoundStmt * visit( const ast::CompoundStmt * node ) override final {
     108                (void)node;
     109                return nullptr;
     110        }
     111
     112        const ast::Stmt * visit( const ast::ExprStmt * node ) override final {
     113                (void)node;
     114                return nullptr;
     115        }
     116
     117        const ast::Stmt * visit( const ast::AsmStmt * node ) override final {
     118                (void)node;
     119                return nullptr;
     120        }
     121
     122        const ast::Stmt * visit( const ast::DirectiveStmt * node ) override final {
     123                (void)node;
     124                return nullptr;
     125        }
     126
     127        const ast::Stmt * visit( const ast::IfStmt * node ) override final {
     128                (void)node;
     129                return nullptr;
     130        }
     131
     132        const ast::Stmt * visit( const ast::WhileStmt * node ) override final {
     133                (void)node;
     134                return nullptr;
     135        }
     136
     137        const ast::Stmt * visit( const ast::ForStmt * node ) override final {
     138                (void)node;
     139                return nullptr;
     140        }
     141
     142        const ast::Stmt * visit( const ast::SwitchStmt * node ) override final {
     143                (void)node;
     144                return nullptr;
     145        }
     146
     147        const ast::Stmt * visit( const ast::CaseStmt * node ) override final {
     148                (void)node;
     149                return nullptr;
     150        }
     151
     152        const ast::Stmt * visit( const ast::BranchStmt * node ) override final {
     153                (void)node;
     154                return nullptr;
     155        }
     156
     157        const ast::Stmt * visit( const ast::ReturnStmt * node ) override final {
     158                (void)node;
     159                return nullptr;
     160        }
     161
     162        const ast::Stmt * visit( const ast::ThrowStmt * node ) override final {
     163                (void)node;
     164                return nullptr;
     165        }
     166
     167        const ast::Stmt * visit( const ast::TryStmt * node ) override final {
     168                (void)node;
     169                return nullptr;
     170        }
     171
     172        const ast::Stmt * visit( const ast::CatchStmt * node ) override final {
     173                (void)node;
     174                return nullptr;
     175        }
     176
     177        const ast::Stmt * visit( const ast::FinallyStmt * node ) override final {
     178                (void)node;
     179                return nullptr;
     180        }
     181
     182        const ast::Stmt * visit( const ast::WaitForStmt * node ) override final {
     183                (void)node;
     184                return nullptr;
     185        }
     186
     187        const ast::Stmt * visit( const ast::WithStmt * node ) override final {
     188                (void)node;
     189                return nullptr;
     190        }
     191
     192        const ast::NullStmt * visit( const ast::NullStmt * node ) override final {
     193                (void)node;
     194                return nullptr;
     195        }
     196
     197        const ast::Stmt * visit( const ast::DeclStmt * node ) override final {
     198                (void)node;
     199                return nullptr;
     200        }
     201
     202        const ast::Stmt * visit( const ast::ImplicitCtorDtorStmt * node ) override final {
     203                (void)node;
     204                return nullptr;
     205        }
     206
     207        const ast::Expr * visit( const ast::ApplicationExpr * node ) override final {
     208                (void)node;
     209                return nullptr;
     210        }
     211
     212        const ast::Expr * visit( const ast::UntypedExpr * node ) override final {
     213                (void)node;
     214                return nullptr;
     215        }
     216
     217        const ast::Expr * visit( const ast::NameExpr * node ) override final {
     218                (void)node;
     219                return nullptr;
     220        }
     221
     222        const ast::Expr * visit( const ast::AddressExpr * node ) override final {
     223                (void)node;
     224                return nullptr;
     225        }
     226
     227        const ast::Expr * visit( const ast::LabelAddressExpr * node ) override final {
     228                (void)node;
     229                return nullptr;
     230        }
     231
     232        const ast::Expr * visit( const ast::CastExpr * node ) override final {
     233                (void)node;
     234                return nullptr;
     235        }
     236
     237        const ast::Expr * visit( const ast::KeywordCastExpr * node ) override final {
     238                (void)node;
     239                return nullptr;
     240        }
     241
     242        const ast::Expr * visit( const ast::VirtualCastExpr * node ) override final {
     243                (void)node;
     244                return nullptr;
     245        }
     246
     247        const ast::Expr * visit( const ast::UntypedMemberExpr * node ) override final {
     248                (void)node;
     249                return nullptr;
     250        }
     251
     252        const ast::Expr * visit( const ast::MemberExpr * node ) override final {
     253                (void)node;
     254                return nullptr;
     255        }
     256
     257        const ast::Expr * visit( const ast::VariableExpr * node ) override final {
     258                (void)node;
     259                return nullptr;
     260        }
     261
     262        const ast::Expr * visit( const ast::ConstantExpr * node ) override final {
     263                (void)node;
     264                return nullptr;
     265        }
     266
     267        const ast::Expr * visit( const ast::SizeofExpr * node ) override final {
     268                (void)node;
     269                return nullptr;
     270        }
     271
     272        const ast::Expr * visit( const ast::AlignofExpr * node ) override final {
     273                (void)node;
     274                return nullptr;
     275        }
     276
     277        const ast::Expr * visit( const ast::UntypedOffsetofExpr * node ) override final {
     278                (void)node;
     279                return nullptr;
     280        }
     281
     282        const ast::Expr * visit( const ast::OffsetofExpr * node ) override final {
     283                (void)node;
     284                return nullptr;
     285        }
     286
     287        const ast::Expr * visit( const ast::OffsetPackExpr * node ) override final {
     288                (void)node;
     289                return nullptr;
     290        }
     291
     292        const ast::Expr * visit( const ast::LogicalExpr * node ) override final {
     293                (void)node;
     294                return nullptr;
     295        }
     296
     297        const ast::Expr * visit( const ast::ConditionalExpr * node ) override final {
     298                (void)node;
     299                return nullptr;
     300        }
     301
     302        const ast::Expr * visit( const ast::CommaExpr * node ) override final {
     303                (void)node;
     304                return nullptr;
     305        }
     306
     307        const ast::Expr * visit( const ast::TypeExpr * node ) override final {
     308                (void)node;
     309                return nullptr;
     310        }
     311
     312        const ast::Expr * visit( const ast::AsmExpr * node ) override final {
     313                (void)node;
     314                return nullptr;
     315        }
     316
     317        const ast::Expr * visit( const ast::ImplicitCopyCtorExpr * node ) override final {
     318                (void)node;
     319                return nullptr;
     320        }
     321
     322        const ast::Expr * visit( const ast::ConstructorExpr * node ) override final {
     323                (void)node;
     324                return nullptr;
     325        }
     326
     327        const ast::Expr * visit( const ast::CompoundLiteralExpr * node ) override final {
     328                (void)node;
     329                return nullptr;
     330        }
     331
     332        const ast::Expr * visit( const ast::RangeExpr * node ) override final {
     333                (void)node;
     334                return nullptr;
     335        }
     336
     337        const ast::Expr * visit( const ast::UntypedTupleExpr * node ) override final {
     338                (void)node;
     339                return nullptr;
     340        }
     341
     342        const ast::Expr * visit( const ast::TupleExpr * node ) override final {
     343                (void)node;
     344                return nullptr;
     345        }
     346
     347        const ast::Expr * visit( const ast::TupleIndexExpr * node ) override final {
     348                (void)node;
     349                return nullptr;
     350        }
     351
     352        const ast::Expr * visit( const ast::TupleAssignExpr * node ) override final {
     353                (void)node;
     354                return nullptr;
     355        }
     356
     357        const ast::Expr * visit( const ast::StmtExpr * node ) override final {
     358                (void)node;
     359                return nullptr;
     360        }
     361
     362        const ast::Expr * visit( const ast::UniqueExpr * node ) override final {
     363                (void)node;
     364                return nullptr;
     365        }
     366
     367        const ast::Expr * visit( const ast::UntypedInitExpr * node ) override final {
     368                (void)node;
     369                return nullptr;
     370        }
     371
     372        const ast::Expr * visit( const ast::InitExpr * node ) override final {
     373                (void)node;
     374                return nullptr;
     375        }
     376
     377        const ast::Expr * visit( const ast::DeletedExpr * node ) override final {
     378                (void)node;
     379                return nullptr;
     380        }
     381
     382        const ast::Expr * visit( const ast::DefaultArgExpr * node ) override final {
     383                (void)node;
     384                return nullptr;
     385        }
     386
     387        const ast::Expr * visit( const ast::GenericExpr * node ) override final {
     388                (void)node;
     389                return nullptr;
     390        }
     391
     392        const ast::Type * visit( const ast::VoidType * node ) override final {
     393                (void)node;
     394                return nullptr;
     395        }
     396
     397        const ast::Type * visit( const ast::BasicType * node ) override final {
     398                (void)node;
     399                return nullptr;
     400        }
     401
     402        const ast::Type * visit( const ast::PointerType * node ) override final {
     403                (void)node;
     404                return nullptr;
     405        }
     406
     407        const ast::Type * visit( const ast::ArrayType * node ) override final {
     408                (void)node;
     409                return nullptr;
     410        }
     411
     412        const ast::Type * visit( const ast::ReferenceType * node ) override final {
     413                (void)node;
     414                return nullptr;
     415        }
     416
     417        const ast::Type * visit( const ast::QualifiedType * node ) override final {
     418                (void)node;
     419                return nullptr;
     420        }
     421
     422        const ast::Type * visit( const ast::FunctionType * node ) override final {
     423                (void)node;
     424                return nullptr;
     425        }
     426
     427        const ast::Type * visit( const ast::StructInstType * node ) override final {
     428                (void)node;
     429                return nullptr;
     430        }
     431
     432        const ast::Type * visit( const ast::UnionInstType * node ) override final {
     433                (void)node;
     434                return nullptr;
     435        }
     436
     437        const ast::Type * visit( const ast::EnumInstType * node ) override final {
     438                (void)node;
     439                return nullptr;
     440        }
     441
     442        const ast::Type * visit( const ast::TraitInstType * node ) override final {
     443                (void)node;
     444                return nullptr;
     445        }
     446
     447        const ast::Type * visit( const ast::TypeInstType * node ) override final {
     448                (void)node;
     449                return nullptr;
     450        }
     451
     452        const ast::Type * visit( const ast::TupleType * node ) override final {
     453                (void)node;
     454                return nullptr;
     455        }
     456
     457        const ast::Type * visit( const ast::TypeofType * node ) override final {
     458                (void)node;
     459                return nullptr;
     460        }
     461
     462        const ast::Type * visit( const ast::VarArgsType * node ) override final {
     463                (void)node;
     464                return nullptr;
     465        }
     466
     467        const ast::Type * visit( const ast::ZeroType * node ) override final {
     468                (void)node;
     469                return nullptr;
     470        }
     471
     472        const ast::Type * visit( const ast::OneType * node ) override final {
     473                (void)node;
     474                return nullptr;
     475        }
     476
     477        const ast::Type * visit( const ast::GlobalScopeType * node ) override final {
     478                (void)node;
     479                return nullptr;
     480        }
     481
     482        const ast::Designation * visit( const ast::Designation * node ) override final {
     483                (void)node;
     484                return nullptr;
     485        }
     486
     487        const ast::Init * visit( const ast::SingleInit * node ) override final {
     488                (void)node;
     489                return nullptr;
     490        }
     491
     492        const ast::Init * visit( const ast::ListInit * node ) override final {
     493                (void)node;
     494                return nullptr;
     495        }
     496
     497        const ast::Init * visit( const ast::ConstructorInit * node ) override final {
     498                (void)node;
     499                return nullptr;
     500        }
     501
     502        const ast::Constant * visit( const ast::Constant * node ) override final {
     503                (void)node;
     504                return nullptr;
     505        }
     506
     507        const ast::Attribute * visit( const ast::Attribute * node ) override final {
     508                (void)node;
     509                return nullptr;
     510        }
     511
     512        const ast::TypeSubstitution * visit( const ast::TypeSubstitution * node ) override final {
     513                (void)node;
     514                return nullptr;
     515        }
    46516};
    47517
    48 std::list< Declaration * > convert( std::list< ast::ptr< ast::Decl > > & translationUnit ) {
    49         ast::Pass<ConverterNewToOld> converter;
    50         ast::accept_all(translationUnit, converter);
    51         return converter.pass.translationUnit;
     518std::list< Declaration * > convert( std::list< ast::ptr< ast::Decl > > && translationUnit ) {
     519        ConverterNewToOld c;
     520        std::list< Declaration * > decls;
     521        for(auto d : translationUnit) {
     522                d->accept( c );
     523                decls.emplace_back( c.get<Declaration>() );
     524                delete d;
     525        }
     526        return decls;
    52527}
    53528
     
    7531228#undef GET_ACCEPT_1
    7541229
    755 std::list< ast::ptr< ast::Decl > > convert( const std::list< Declaration * > & translationUnit ) {
     1230std::list< ast::ptr< ast::Decl > > convert( const std::list< Declaration * > && translationUnit ) {
    7561231        ConverterOldToNew c;
    7571232        std::list< ast::ptr< ast::Decl > > decls;
  • src/AST/Convert.hpp

    r896737b r74dbbf6  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Convert.hpp --
     7// Convert.hpp -- Convert between the new and old syntax trees.
    88//
    99// Author           : Thierry Delisle
    1010// Created On       : Thu May 09 15::37::05 2019
    11 // Last Modified By :
    12 // Last Modified On :
    13 // Update Count     :
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Fri May 17 11:25:00 2019
     13// Update Count     : 1
    1414//
    1515
     
    2525};
    2626
    27 std::list< Declaration * > convert( const std::list< ast::ptr< ast::Decl > > & translationUnit );
    28 std::list< ast::ptr< ast::Decl > > convert( const std::list< Declaration * > & translationUnit );
     27std::list< Declaration * > convert( const std::list< ast::ptr< ast::Decl > > && translationUnit );
     28std::list< ast::ptr< ast::Decl > > convert( const std::list< Declaration * > && translationUnit );
Note: See TracChangeset for help on using the changeset viewer.