Changes in / [ca8704f:733074e]


Ignore:
Location:
src/AST
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    rca8704f r733074e  
    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
     
    9393
    9494private:
    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 
    11795        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 );
     96                (void)node;
     97                return nullptr;
    12998        }
    13099
    131100        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 );
     101                (void)node;
     102                return nullptr;
     103        }
     104
     105        const ast::Decl * visit( const ast::StructDecl * node ) override final {
     106                (void)node;
     107                return nullptr;
     108        }
     109
     110        const ast::Decl * visit( const ast::UnionDecl * node ) override final {
     111                (void)node;
     112                return nullptr;
     113        }
     114
     115        const ast::Decl * visit( const ast::EnumDecl * node ) override final {
     116                (void)node;
     117                return nullptr;
     118        }
     119
     120        const ast::Decl * visit( const ast::TraitDecl * node ) override final {
     121                (void)node;
    151122                return nullptr;
    152123        }
    153124
    154125        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 );
     126                (void)node;
     127                return nullptr;
    178128        }
    179129
    180130        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 );
     131                (void)node;
     132                return nullptr;
    235133        }
    236134
    237135        const ast::AsmDecl * visit( const ast::AsmDecl * node ) override final {
    238                 auto decl = new AsmDecl( get<AsmStmt>().accept1( node->stmt ) );
    239                 declPostamble( decl, node );
     136                (void)node;
    240137                return nullptr;
    241138        }
    242139
    243140        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;
     141                (void)node;
    256142                return nullptr;
    257143        }
     
    259145        const ast::CompoundStmt * visit( const ast::CompoundStmt * node ) override final {
    260146                auto stmt = new CompoundStmt( get<Statement>().acceptL( node->kids ) );
    261                 stmtPostamble( stmt, node );
     147                stmt->location = node->location;
     148                stmt->labels = makeLabelL( stmt, node->labels );
     149                this->node = stmt;
    262150                return nullptr;
    263151        }
     
    265153        const ast::Stmt * visit( const ast::ExprStmt * node ) override final {
    266154                auto stmt = new ExprStmt( get<Expression>().accept1( node->expr ) );
    267                 return stmtPostamble( stmt, node );
     155                stmt->location = node->location;
     156                stmt->labels = makeLabelL( stmt, node->labels );
     157                this->node = stmt;
     158                return nullptr;
    268159        }
    269160
     
    277168                        makeLabelL( nullptr, node->gotoLabels ) // What are these labelling?
    278169                );
    279                 return stmtPostamble( stmt, node );
     170                stmt->location = node->location;
     171                stmt->labels = makeLabelL( stmt, node->labels );
     172                this->node = stmt;
     173                return nullptr;
    280174        }
    281175
    282176        const ast::Stmt * visit( const ast::DirectiveStmt * node ) override final {
    283177                auto stmt = new DirectiveStmt( node->directive );
    284                 return stmtPostamble( stmt, node );
     178                stmt->location = node->location;
     179                stmt->labels = makeLabelL( stmt, node->labels );
     180                this->node = stmt;
     181                return nullptr;
    285182        }
    286183
     
    292189                        get<Statement>().acceptL( node->inits )
    293190                );
    294                 return stmtPostamble( stmt, node );
     191                stmt->location = node->location;
     192                stmt->labels = makeLabelL( stmt, node->labels );
     193                this->node = stmt;
     194                return nullptr;
    295195        }
    296196
     
    300200                        get<Statement>().acceptL( node->stmts )
    301201                );
    302                 return stmtPostamble( stmt, node );
     202                stmt->location = node->location;
     203                stmt->labels = makeLabelL( stmt, node->labels );
     204                this->node = stmt;
     205                return nullptr;
    303206        }
    304207
     
    309212                        node->isDefault()
    310213                );
    311                 return stmtPostamble( stmt, node );
     214                stmt->location = node->location;
     215                stmt->labels = makeLabelL( stmt, node->labels );
     216                this->node = stmt;
     217                return nullptr;
    312218        }
    313219
     
    320226                        node->isDoWhile
    321227                );
    322                 return stmtPostamble( stmt, node );
     228                stmt->location = node->location;
     229                stmt->labels = makeLabelL( stmt, node->labels );
     230                this->node = stmt;
     231                return nullptr;
    323232        }
    324233
     
    330239                        get<Statement>().accept1( node->body )
    331240                );
    332                 return stmtPostamble( stmt, node );
     241                stmt->location = node->location;
     242                stmt->labels = makeLabelL( stmt, node->labels );
     243                this->node = stmt;
     244                return nullptr;
    333245        }
    334246
     
    359271                        stmt->target = makeLabel( stmt, node->target );
    360272                }
    361                 return stmtPostamble( stmt, node );
     273                stmt->location = node->location;
     274                stmt->labels = makeLabelL( stmt, node->labels );
     275                this->node = stmt;
     276                return nullptr;
    362277        }
    363278
    364279        const ast::Stmt * visit( const ast::ReturnStmt * node ) override final {
    365280                auto stmt = new ReturnStmt( get<Expression>().accept1( node->expr ) );
    366                 return stmtPostamble( stmt, node );
     281                stmt->location = node->location;
     282                stmt->labels = makeLabelL( stmt, node->labels );
     283                this->node = stmt;
     284                return nullptr;
    367285        }
    368286
     
    384302                        get<Expression>().accept1( node->target )
    385303                );
    386                 return stmtPostamble( stmt, node );
     304                stmt->location = node->location;
     305                stmt->labels = makeLabelL( stmt, node->labels );
     306                this->node = stmt;
     307                return nullptr;
    387308        }
    388309
     
    394315                        get<FinallyStmt>().accept1( node->finally )
    395316                );
    396                 return stmtPostamble( stmt, node );
     317                stmt->location = node->location;
     318                stmt->labels = makeLabelL( stmt, node->labels );
     319                this->node = stmt;
     320                return nullptr;
    397321        }
    398322
     
    415339                        get<Statement>().accept1( node->body )
    416340                );
    417                 return stmtPostamble( stmt, node );
     341                stmt->location = node->location;
     342                stmt->labels = makeLabelL( stmt, node->labels );
     343                this->node = stmt;
     344                return nullptr;
    418345        }
    419346
    420347        const ast::Stmt * visit( const ast::FinallyStmt * node ) override final {
    421348                auto stmt = new FinallyStmt( get<CompoundStmt>().accept1( node->body ) );
    422                 return stmtPostamble( stmt, node );
     349                stmt->location = node->location;
     350                stmt->labels = makeLabelL( stmt, node->labels );
     351                this->node = stmt;
     352                return nullptr;
    423353        }
    424354
     
    444374                        get<Expression>().accept1( node->orElse.cond ),
    445375                };
    446                 return stmtPostamble( stmt, node );
     376                stmt->location = node->location;
     377                stmt->labels = makeLabelL( stmt, node->labels );
     378                this->node = stmt;
     379                return nullptr;
    447380        }
    448381
     
    452385                        get<Statement>().accept1( node->stmt )
    453386                );
    454                 return stmtPostamble( stmt, node );
     387                stmt->location = node->location;
     388                stmt->labels = makeLabelL( stmt, node->labels );
     389                this->node = stmt;
     390                return nullptr;
    455391        }
    456392
    457393        const ast::NullStmt * visit( const ast::NullStmt * node ) override final {
    458394                auto stmt = new NullStmt();
    459                 stmtPostamble( stmt, node );
     395                stmt->location = node->location;
     396                stmt->labels = makeLabelL( stmt, node->labels );
     397                this->node = stmt;
    460398                return nullptr;
    461399        }
     
    463401        const ast::Stmt * visit( const ast::DeclStmt * node ) override final {
    464402                auto stmt = new DeclStmt( get<Declaration>().accept1( node->decl ) );
    465                 return stmtPostamble( stmt, node );
     403                stmt->location = node->location;
     404                stmt->labels = makeLabelL( stmt, node->labels );
     405                this->node = stmt;
     406                return nullptr;
    466407        }
    467408
  • src/AST/Decl.hpp

    rca8704f r733074e  
    329329class StaticAssertDecl : public Decl {
    330330public:
    331         ptr<Expr> cond;
     331        ptr<Expr> condition;
    332332        ptr<ConstantExpr> msg;   // string literal
    333333
    334334        StaticAssertDecl( const CodeLocation & loc, const Expr * condition, const ConstantExpr * msg )
    335         : Decl( loc, "", {}, {} ), cond( condition ), msg( msg ) {}
     335        : Decl( loc, "", {}, {} ), condition( condition ), msg( msg ) {}
    336336
    337337        const StaticAssertDecl * accept( Visitor &v ) const override { return v.visit( this ); }
  • src/AST/Pass.impl.hpp

    rca8704f r733074e  
    596596
    597597        VISIT(
    598                 maybe_accept( node, &StaticAssertDecl::cond );
    599                 maybe_accept( node, &StaticAssertDecl::msg  );
     598                maybe_accept( node, &StaticAssertDecl::condition );
     599                maybe_accept( node, &StaticAssertDecl::msg       );
    600600        )
    601601
Note: See TracChangeset for help on using the changeset viewer.