Changes in / [896737b:10a1225]


Ignore:
Location:
src/AST
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r896737b r10a1225  
    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 : Thu May 16 17:21:00 2019
     13// Update Count     : 1
    1414//
    1515
     
    5454//================================================================================================
    5555
     56#define ACCEPT_1(name, child, type) \
     57        old->child->accept(*this); \
     58        auto name = strict_dynamic_cast< ast::type * >( node );
     59
     60#define ACCEPT_N(name, child, type) \
     61        std::vector< ast::ptr<ast::type> > name; \
     62        name.reserve( old->child.size() ); \
     63        for( auto a : old->child ) { \
     64                a->accept( *this ); \
     65                name.emplace_back( strict_dynamic_cast< ast::type * >(node) ); \
     66        }
     67
    5668class ConverterOldToNew : public Visitor {
    5769public:
     
    110122
    111123        virtual void visit( ObjectDecl * old ) override final {
     124                ACCEPT_1(type, type, Type)
     125                ACCEPT_1(init, init, Init)
     126                ACCEPT_1(bitWd, bitfieldWidth, Expr)
     127                ACCEPT_N(attr, attributes, Attribute)
     128
    112129                auto decl = new ast::ObjectDecl(
    113130                        old->location,
    114131                        old->name,
    115                         GET_ACCEPT_1(type, Type),
    116                         GET_ACCEPT_1(init, Init),
     132                        type,
     133                        init,
    117134                        { old->get_storageClasses().val },
    118135                        { old->linkage.val },
    119                         GET_ACCEPT_1(bitfieldWidth, Expr),
    120                         GET_ACCEPT_V(attributes, Attribute),
     136                        bitWd,
     137                        std::move( attr ),
    121138                        { old->get_funcSpec().val }
    122139                );
     
    135152
    136153        virtual void visit( StructDecl * old ) override final {
     154                ACCEPT_N(members, members, Decl)
     155                ACCEPT_N(params, parameters, TypeDecl)
     156                ACCEPT_1(parent, parent, AggregateDecl)
     157                ACCEPT_N(attr, attributes, Attribute)
     158
    137159                auto decl = new ast::StructDecl(
    138160                        old->location,
    139161                        old->name,
    140162                        old->kind,
    141                         GET_ACCEPT_V(attributes, Attribute),
     163                        std::move( attr ),
    142164                        { old->linkage.val }
    143165                );
    144                 decl->parent = GET_ACCEPT_1(parent, AggregateDecl);
     166                decl->parent = parent;
    145167                decl->body   = old->body;
    146                 decl->params = GET_ACCEPT_V(parameters, TypeDecl);
    147                 decl->members    = GET_ACCEPT_V(members, Decl);
     168                decl->params = params;
     169                decl->members    = members;
    148170                decl->extension  = old->extension;
    149171                decl->uniqueId   = old->uniqueId;
     
    154176
    155177        virtual void visit( UnionDecl * old ) override final {
     178                ACCEPT_N(members, members, Decl)
     179                ACCEPT_N(params, parameters, TypeDecl)
     180                ACCEPT_1(parent, parent, AggregateDecl)
     181                ACCEPT_N(attr, attributes, Attribute)
     182
    156183                auto decl = new ast::UnionDecl(
    157184                        old->location,
    158185                        old->name,
    159                         GET_ACCEPT_V(attributes, Attribute),
     186                        std::move( attr ),
    160187                        { old->linkage.val }
    161188                );
    162                 decl->parent = GET_ACCEPT_1(parent, AggregateDecl);
     189                decl->parent = parent;
    163190                decl->body   = old->body;
    164                 decl->params = GET_ACCEPT_V(parameters, TypeDecl);
    165                 decl->members    = GET_ACCEPT_V(members, Decl);
     191                decl->params = params;
     192                decl->members    = members;
    166193                decl->extension  = old->extension;
    167194                decl->uniqueId   = old->uniqueId;
     
    172199
    173200        virtual void visit( EnumDecl * old ) override final {
     201                ACCEPT_N(members, members, Decl)
     202                ACCEPT_N(params, parameters, TypeDecl)
     203                ACCEPT_1(parent, parent, AggregateDecl)
     204                ACCEPT_N(attr, attributes, Attribute)
     205
    174206                auto decl = new ast::UnionDecl(
    175207                        old->location,
    176208                        old->name,
    177                         GET_ACCEPT_V(attributes, Attribute),
     209                        std::move( attr ),
    178210                        { old->linkage.val }
    179211                );
    180                 decl->parent = GET_ACCEPT_1(parent, AggregateDecl);
     212                decl->parent = parent;
    181213                decl->body   = old->body;
    182                 decl->params = GET_ACCEPT_V(parameters, TypeDecl);
    183                 decl->members    = GET_ACCEPT_V(members, Decl);
     214                decl->params = params;
     215                decl->members    = members;
    184216                decl->extension  = old->extension;
    185217                decl->uniqueId   = old->uniqueId;
     
    190222
    191223        virtual void visit( TraitDecl * old ) override final {
     224                ACCEPT_N(members, members, Decl)
     225                ACCEPT_N(params, parameters, TypeDecl)
     226                ACCEPT_1(parent, parent, AggregateDecl)
     227                ACCEPT_N(attr, attributes, Attribute)
     228
    192229                auto decl = new ast::UnionDecl(
    193230                        old->location,
    194231                        old->name,
    195                         GET_ACCEPT_V(attributes, Attribute),
     232                        std::move( attr ),
    196233                        { old->linkage.val }
    197234                );
    198                 decl->parent = GET_ACCEPT_1(parent, AggregateDecl);
     235                decl->parent = parent;
    199236                decl->body   = old->body;
    200                 decl->params = GET_ACCEPT_V(parameters, TypeDecl);
    201                 decl->members    = GET_ACCEPT_V(members, Decl);
     237                decl->params = params;
     238                decl->members    = members;
    202239                decl->extension  = old->extension;
    203240                decl->uniqueId   = old->uniqueId;
     
    212249
    213250        virtual void visit( TypedefDecl * old ) override final {
     251                ACCEPT_1(type, base, Type)
     252                ACCEPT_N(params, parameters, TypeDecl)
     253                ACCEPT_N(asserts, assertions, DeclWithType)
    214254                auto decl = new ast::TypedefDecl(
    215255                        old->location,
    216256                        old->name,
    217257                        { old->storageClasses.val },
    218                         GET_ACCEPT_1(base, Type),
     258                        type,
    219259                        { old->linkage.val }
    220260                );
    221                 decl->assertions = GET_ACCEPT_V(assertions, DeclWithType);
    222                 decl->params     = GET_ACCEPT_V(parameters, TypeDecl);
     261
     262                decl->assertions = asserts;
     263                decl->params     = params;
    223264                decl->extension  = old->extension;
    224265                decl->uniqueId   = old->uniqueId;
     
    237278
    238279        virtual void visit( CompoundStmt * old ) override final {
     280                ACCEPT_N(kids, kids, Stmt)
    239281                auto stmt = new ast::CompoundStmt(
    240282                        old->location,
    241                         to<std::list>::from( GET_ACCEPT_V(kids, Stmt) ),
    242                         GET_LABELS_V(old->labels)
    243                 );
     283                        to<std::list>::from( std::move(kids) )
     284                );
     285                stmt->labels = to<std::vector>::from( make_labels( std::move( old->labels ) ) );
    244286
    245287                this->node = stmt;
     
    346388                        CASE(FallThroughDefault);
    347389                        #undef CASE
    348                         default:
    349                                 assertf(false, "Invalid BranchStmt::Type %d\n", old->type);
    350390                        }
    351391
     
    379419                        kind = ast::ThrowStmt::Resume;
    380420                        break;
    381                 default:
    382                         assertf(false, "Invalid ThrowStmt::Kind %d\n", old->kind);
    383421                }
    384422
     
    411449                        kind = ast::CatchStmt::Resume;
    412450                        break;
    413                 default:
    414                         assertf(false, "Invalid CatchStmt::Kind %d\n", old->kind);
    415451                }
    416452
     
    753789#undef GET_ACCEPT_1
    754790
     791#undef ACCEPT_N
     792#undef ACCEPT_1
     793
    755794std::list< ast::ptr< ast::Decl > > convert( const std::list< Declaration * > & translationUnit ) {
    756795        ConverterOldToNew c;
  • src/AST/Stmt.hpp

    r896737b r10a1225  
    1010// Created On       : Wed May  8 13:00:00 2019
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Fri May 17 10:03:00 2019
    13 // Update Count     : 4
     12// Last Modified On : Wed May 16 12:20:00 2019
     13// Update Count     : 3
    1414//
    1515
     
    5454        std::list<ptr<Stmt>> kids;
    5555
    56         CompoundStmt(const CodeLocation & loc, std::list<ptr<Stmt>> && ks = {},
    57                 std::vector<Label>&& labels = {} )
    58         : Stmt(loc, std::move(labels)), kids(std::move(ks)) {}
     56        CompoundStmt(const CodeLocation & loc, std::list<ptr<Stmt>> && ks = {} )
     57        : Stmt(loc), kids(std::move(ks)) {}
    5958
    6059        CompoundStmt( const CompoundStmt& o );
Note: See TracChangeset for help on using the changeset viewer.