Changeset ca8704f


Ignore:
Timestamp:
May 21, 2019, 3:56:33 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
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:
461046f, a83044fb
Parents:
733074e (diff), 112fe04 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src/AST
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r733074e rca8704f  
    1010// Created On       : Thu May 09 15::37::05 2019
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Fri May 17 16:01:00 2019
    13 // Update Count     : 4
     12// Last Modified On : Tue May 21 15:30:00 2019
     13// Update Count     : 5
    1414//
    1515
     
    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
    95117        const ast::DeclWithType * visit( const ast::ObjectDecl * node ) override final {
    96                 (void)node;
    97                 return nullptr;
     118                auto decl = new ObjectDecl(
     119                        node->name,
     120                        Type::StorageClasses( node->storage.val ),
     121                        LinkageSpec::Spec( node->linkage.val ),
     122                        get<Expression>().accept1( node->bitfieldWidth ),
     123                        get<Type>().accept1( node->type ),
     124                        get<Initializer>().accept1( node->init ),
     125                        get<Attribute>().acceptL( node->attributes ),
     126                        Type::FuncSpecifiers( node->funcSpec.val )
     127                );
     128                return declWithTypePostamble( decl, node );
    98129        }
    99130
    100131        const ast::DeclWithType * visit( const ast::FunctionDecl * node ) override final {
    101                 (void)node;
     132                auto decl = new FunctionDecl(
     133                        node->name,
     134                        Type::StorageClasses( node->storage.val ),
     135                        LinkageSpec::Spec( node->linkage.val ),
     136                        get<FunctionType>().accept1( node->type ),
     137                        get<CompoundStmt>().accept1( node->stmts ),
     138                        get<Attribute>().acceptL( node->attributes ),
     139                        Type::FuncSpecifiers( node->funcSpec.val )
     140                );
     141                decl->withExprs = get<Expression>().acceptL( node->withExprs );
     142                return declWithTypePostamble( decl, node );
     143        }
     144
     145        // NamedTypeDecl
     146        const ast::Decl * namedTypePostamble( NamedTypeDecl * decl, const ast::NamedTypeDecl * node ) {
     147                declPostamble( decl, node );
     148                // base comes from constructor
     149                decl->parameters = get<TypeDecl>().acceptL( node->params );
     150                decl->assertions = get<DeclarationWithType>().acceptL( node->assertions );
     151                return nullptr;
     152        }
     153
     154        const ast::Decl * visit( const ast::TypeDecl * node ) override final {
     155                TypeDecl::Kind kind;
     156                switch (node->kind) {
     157                case ast::TypeVar::Dtype:
     158                        kind = TypeDecl::Dtype;
     159                        break;
     160                case ast::TypeVar::Ftype:
     161                        kind = TypeDecl::Ftype;
     162                        break;
     163                case ast::TypeVar::Ttype:
     164                        kind = TypeDecl::Ttype;
     165                        break;
     166                default:
     167                        assertf(false, "Invalid ast::TypeVar::Kind: %d\n", node->kind);
     168                };
     169                auto decl = new TypeDecl(
     170                        node->name,
     171                        Type::StorageClasses( node->storage.val ),
     172                        get<Type>().accept1( node->base ),
     173                        kind,
     174                        node->sized,
     175                        get<Type>().accept1( node->init )
     176                );
     177                return namedTypePostamble( decl, node );
     178        }
     179
     180        const ast::Decl * visit( const ast::TypedefDecl * node ) override final {
     181                auto decl = new TypedefDecl(
     182                        node->name,
     183                        node->location,
     184                        Type::StorageClasses( node->storage.val ),
     185            get<Type>().accept1( node->base ),
     186                        LinkageSpec::Spec( node->linkage.val )
     187                );
     188                return namedTypePostamble( decl, node );
     189        }
     190
     191        const ast::Decl * aggregatePostamble( AggregateDecl * decl, const ast::AggregateDecl * node ) {
     192                decl->members = get<Declaration>().acceptL( node->members );
     193                decl->parameters = get<TypeDecl>().acceptL( node->params );
     194                decl->body = node->body;
     195                // attributes come from constructor
     196                // TODO: Need caching for: decl->parent = node->parent;
    102197                return nullptr;
    103198        }
    104199
    105200        const ast::Decl * visit( const ast::StructDecl * node ) override final {
    106                 (void)node;
    107                 return nullptr;
     201                auto decl = new StructDecl(
     202                        node->name,
     203                        node->kind,
     204                        get<Attribute>().acceptL( node->attributes ),
     205                        LinkageSpec::Spec( node->linkage.val )
     206                );
     207                return aggregatePostamble( decl, node );
    108208        }
    109209
    110210        const ast::Decl * visit( const ast::UnionDecl * node ) override final {
    111                 (void)node;
    112                 return nullptr;
     211                auto decl = new UnionDecl(
     212                        node->name,
     213                        get<Attribute>().acceptL( node->attributes ),
     214                        LinkageSpec::Spec( node->linkage.val )
     215                );
     216                return aggregatePostamble( decl, node );
    113217        }
    114218
    115219        const ast::Decl * visit( const ast::EnumDecl * node ) override final {
    116                 (void)node;
    117                 return nullptr;
     220                auto decl = new EnumDecl(
     221                        node->name,
     222                        get<Attribute>().acceptL( node->attributes ),
     223                        LinkageSpec::Spec( node->linkage.val )
     224                );
     225                return aggregatePostamble( decl, node );
    118226        }
    119227
    120228        const ast::Decl * visit( const ast::TraitDecl * node ) override final {
    121                 (void)node;
    122                 return nullptr;
    123         }
    124 
    125         const ast::Decl * visit( const ast::TypeDecl * node ) override final {
    126                 (void)node;
    127                 return nullptr;
    128         }
    129 
    130         const ast::Decl * visit( const ast::TypedefDecl * node ) override final {
    131                 (void)node;
    132                 return nullptr;
     229                auto decl = new TraitDecl(
     230                        node->name,
     231                        {},
     232                        LinkageSpec::Spec( node->linkage.val )
     233                );
     234                return aggregatePostamble( decl, node );
    133235        }
    134236
    135237        const ast::AsmDecl * visit( const ast::AsmDecl * node ) override final {
    136                 (void)node;
     238                auto decl = new AsmDecl( get<AsmStmt>().accept1( node->stmt ) );
     239                declPostamble( decl, node );
    137240                return nullptr;
    138241        }
    139242
    140243        const ast::StaticAssertDecl * visit( const ast::StaticAssertDecl * node ) override final {
    141                 (void)node;
    142                 return nullptr;
    143         }
    144 
    145         const ast::CompoundStmt * visit( const ast::CompoundStmt * node ) override final {
    146                 auto stmt = new CompoundStmt( get<Statement>().acceptL( node->kids ) );
     244                auto decl = new StaticAssertDecl(
     245                        get<Expression>().accept1( node->cond ),
     246                        get<ConstantExpr>().accept1( node->msg )
     247                );
     248                declPostamble( decl, node );
     249                return nullptr;
     250        }
     251
     252        const ast::Stmt * stmtPostamble( Statement * stmt, const ast::Stmt * node ) {
    147253                stmt->location = node->location;
    148254                stmt->labels = makeLabelL( stmt, node->labels );
     
    151257        }
    152258
     259        const ast::CompoundStmt * visit( const ast::CompoundStmt * node ) override final {
     260                auto stmt = new CompoundStmt( get<Statement>().acceptL( node->kids ) );
     261                stmtPostamble( stmt, node );
     262                return nullptr;
     263        }
     264
    153265        const ast::Stmt * visit( const ast::ExprStmt * node ) override final {
    154266                auto stmt = new ExprStmt( get<Expression>().accept1( node->expr ) );
    155                 stmt->location = node->location;
    156                 stmt->labels = makeLabelL( stmt, node->labels );
    157                 this->node = stmt;
    158                 return nullptr;
     267                return stmtPostamble( stmt, node );
    159268        }
    160269
     
    168277                        makeLabelL( nullptr, node->gotoLabels ) // What are these labelling?
    169278                );
    170                 stmt->location = node->location;
    171                 stmt->labels = makeLabelL( stmt, node->labels );
    172                 this->node = stmt;
    173                 return nullptr;
     279                return stmtPostamble( stmt, node );
    174280        }
    175281
    176282        const ast::Stmt * visit( const ast::DirectiveStmt * node ) override final {
    177283                auto stmt = new DirectiveStmt( node->directive );
    178                 stmt->location = node->location;
    179                 stmt->labels = makeLabelL( stmt, node->labels );
    180                 this->node = stmt;
    181                 return nullptr;
     284                return stmtPostamble( stmt, node );
    182285        }
    183286
     
    189292                        get<Statement>().acceptL( node->inits )
    190293                );
    191                 stmt->location = node->location;
    192                 stmt->labels = makeLabelL( stmt, node->labels );
    193                 this->node = stmt;
    194                 return nullptr;
     294                return stmtPostamble( stmt, node );
    195295        }
    196296
     
    200300                        get<Statement>().acceptL( node->stmts )
    201301                );
    202                 stmt->location = node->location;
    203                 stmt->labels = makeLabelL( stmt, node->labels );
    204                 this->node = stmt;
    205                 return nullptr;
     302                return stmtPostamble( stmt, node );
    206303        }
    207304
     
    212309                        node->isDefault()
    213310                );
    214                 stmt->location = node->location;
    215                 stmt->labels = makeLabelL( stmt, node->labels );
    216                 this->node = stmt;
    217                 return nullptr;
     311                return stmtPostamble( stmt, node );
    218312        }
    219313
     
    226320                        node->isDoWhile
    227321                );
    228                 stmt->location = node->location;
    229                 stmt->labels = makeLabelL( stmt, node->labels );
    230                 this->node = stmt;
    231                 return nullptr;
     322                return stmtPostamble( stmt, node );
    232323        }
    233324
     
    239330                        get<Statement>().accept1( node->body )
    240331                );
    241                 stmt->location = node->location;
    242                 stmt->labels = makeLabelL( stmt, node->labels );
    243                 this->node = stmt;
    244                 return nullptr;
     332                return stmtPostamble( stmt, node );
    245333        }
    246334
     
    271359                        stmt->target = makeLabel( stmt, node->target );
    272360                }
    273                 stmt->location = node->location;
    274                 stmt->labels = makeLabelL( stmt, node->labels );
    275                 this->node = stmt;
    276                 return nullptr;
     361                return stmtPostamble( stmt, node );
    277362        }
    278363
    279364        const ast::Stmt * visit( const ast::ReturnStmt * node ) override final {
    280365                auto stmt = new ReturnStmt( get<Expression>().accept1( node->expr ) );
    281                 stmt->location = node->location;
    282                 stmt->labels = makeLabelL( stmt, node->labels );
    283                 this->node = stmt;
    284                 return nullptr;
     366                return stmtPostamble( stmt, node );
    285367        }
    286368
     
    302384                        get<Expression>().accept1( node->target )
    303385                );
    304                 stmt->location = node->location;
    305                 stmt->labels = makeLabelL( stmt, node->labels );
    306                 this->node = stmt;
    307                 return nullptr;
     386                return stmtPostamble( stmt, node );
    308387        }
    309388
     
    315394                        get<FinallyStmt>().accept1( node->finally )
    316395                );
    317                 stmt->location = node->location;
    318                 stmt->labels = makeLabelL( stmt, node->labels );
    319                 this->node = stmt;
    320                 return nullptr;
     396                return stmtPostamble( stmt, node );
    321397        }
    322398
     
    339415                        get<Statement>().accept1( node->body )
    340416                );
    341                 stmt->location = node->location;
    342                 stmt->labels = makeLabelL( stmt, node->labels );
    343                 this->node = stmt;
    344                 return nullptr;
     417                return stmtPostamble( stmt, node );
    345418        }
    346419
    347420        const ast::Stmt * visit( const ast::FinallyStmt * node ) override final {
    348421                auto stmt = new FinallyStmt( get<CompoundStmt>().accept1( node->body ) );
    349                 stmt->location = node->location;
    350                 stmt->labels = makeLabelL( stmt, node->labels );
    351                 this->node = stmt;
    352                 return nullptr;
     422                return stmtPostamble( stmt, node );
    353423        }
    354424
     
    374444                        get<Expression>().accept1( node->orElse.cond ),
    375445                };
    376                 stmt->location = node->location;
    377                 stmt->labels = makeLabelL( stmt, node->labels );
    378                 this->node = stmt;
    379                 return nullptr;
     446                return stmtPostamble( stmt, node );
    380447        }
    381448
     
    385452                        get<Statement>().accept1( node->stmt )
    386453                );
    387                 stmt->location = node->location;
    388                 stmt->labels = makeLabelL( stmt, node->labels );
    389                 this->node = stmt;
    390                 return nullptr;
     454                return stmtPostamble( stmt, node );
    391455        }
    392456
    393457        const ast::NullStmt * visit( const ast::NullStmt * node ) override final {
    394458                auto stmt = new NullStmt();
    395                 stmt->location = node->location;
    396                 stmt->labels = makeLabelL( stmt, node->labels );
    397                 this->node = stmt;
     459                stmtPostamble( stmt, node );
    398460                return nullptr;
    399461        }
     
    401463        const ast::Stmt * visit( const ast::DeclStmt * node ) override final {
    402464                auto stmt = new DeclStmt( get<Declaration>().accept1( node->decl ) );
    403                 stmt->location = node->location;
    404                 stmt->labels = makeLabelL( stmt, node->labels );
    405                 this->node = stmt;
    406                 return nullptr;
     465                return stmtPostamble( stmt, node );
    407466        }
    408467
  • src/AST/Decl.hpp

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

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