Changeset e67991f


Ignore:
Timestamp:
Jul 16, 2019, 10:38:32 AM (2 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
arm-eh, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr
Children:
6f15121
Parents:
7dc2e57b
Message:

WithStmt? is now a Declaration

Location:
src
Files:
23 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r7dc2e57b re67991f  
    518518        }
    519519
    520         const ast::Stmt * visit( const ast::WithStmt * node ) override final {
     520        const ast::Decl * visit( const ast::WithStmt * node ) override final {
    521521                if ( inCache( node ) ) return nullptr;
    522522                auto stmt = new WithStmt(
     
    524524                        get<Statement>().accept1( node->stmt )
    525525                );
    526                 return stmtPostamble( stmt, node );
     526                declPostamble( stmt, node );
     527                return nullptr;
    527528        }
    528529
     
    10391040                                get<Expression>().accept1(node->expr),
    10401041                                inCache(node->deleteStmt) ?
    1041                                         this->node :
    1042                                         get<BaseSyntaxNode>().accept1(node->deleteStmt)
     1042                                        strict_dynamic_cast<Declaration*>(this->node) :
     1043                                        get<Declaration>().accept1(node->deleteStmt)
    10431044                        )
    10441045                );
     
    19081909                        old->location,
    19091910                        GET_ACCEPT_V(exprs, Expr),
    1910                         GET_ACCEPT_1(stmt, Stmt),
    1911                         GET_LABELS_V(old->labels)
     1911                        GET_ACCEPT_1(stmt, Stmt)
    19121912                );
    19131913                cache.emplace( old, this->node );
     
    23972397                                GET_ACCEPT_1(expr, Expr),
    23982398                                inCache(old->deleteStmt) ?
    2399                                         this->node :
    2400                                         GET_ACCEPT_1(deleteStmt, Node)
     2399                                        strict_dynamic_cast<ast::Decl*>(this->node) :
     2400                                        GET_ACCEPT_1(deleteStmt, Decl)
    24012401                        )
    24022402                );
  • src/AST/Decl.hpp

    r7dc2e57b re67991f  
    102102        ptr<Expr> bitfieldWidth;
    103103
    104         ObjectDecl( const CodeLocation & loc, const std::string & name, const Type * type, 
    105                 const Init * init = nullptr, Storage::Classes storage = {}, 
    106                 Linkage::Spec linkage = Linkage::C, const Expr * bitWd = nullptr, 
     104        ObjectDecl( const CodeLocation & loc, const std::string & name, const Type * type,
     105                const Init * init = nullptr, Storage::Classes storage = {},
     106                Linkage::Spec linkage = Linkage::C, const Expr * bitWd = nullptr,
    107107                std::vector< ptr<Attribute> > && attrs = {}, Function::Specs fs = {} )
    108108        : DeclWithType( loc, name, storage, linkage, std::move(attrs), fs ), type( type ),
     
    321321};
    322322
     323/// With statement `with (...) ...`
     324class WithStmt final : public Decl {
     325public:
     326        std::vector<ptr<Expr>> exprs;
     327        ptr<Stmt> stmt;
     328
     329        WithStmt( const CodeLocation & loc, std::vector<ptr<Expr>> && exprs, const Stmt * stmt )
     330        : Decl(loc, "", Storage::Auto, Linkage::Cforall), exprs(std::move(exprs)), stmt(stmt) {}
     331
     332        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
     333private:
     334        WithStmt * clone() const override { return new WithStmt{ *this }; }
     335        MUTATE_FRIEND
     336};
     337
    323338class AsmDecl : public Decl {
    324339public:
  • src/AST/Expr.hpp

    r7dc2e57b re67991f  
    769769public:
    770770        ptr<Expr> expr;
    771         readonly<Node> deleteStmt;
    772 
    773         DeletedExpr( const CodeLocation & loc, const Expr * e, const Node * del )
     771        readonly<Decl> deleteStmt;
     772
     773        DeletedExpr( const CodeLocation & loc, const Expr * e, const Decl * del )
    774774        : Expr( loc, e->result ), expr( e ), deleteStmt( del ) { assert( expr->result ); }
    775775
  • src/AST/Pass.hpp

    r7dc2e57b re67991f  
    112112        const ast::Stmt *             visit( const ast::FinallyStmt          * ) override final;
    113113        const ast::Stmt *             visit( const ast::WaitForStmt          * ) override final;
    114         const ast::Stmt *             visit( const ast::WithStmt             * ) override final;
     114        const ast::Decl *             visit( const ast::WithStmt             * ) override final;
    115115        const ast::NullStmt *         visit( const ast::NullStmt             * ) override final;
    116116        const ast::Stmt *             visit( const ast::DeclStmt             * ) override final;
  • src/AST/Pass.impl.hpp

    r7dc2e57b re67991f  
    894894// WithStmt
    895895template< typename pass_t >
    896 const ast::Stmt * ast::Pass< pass_t >::visit( const ast::WithStmt * node ) {
     896const ast::Decl * ast::Pass< pass_t >::visit( const ast::WithStmt * node ) {
    897897        VISIT_START( node );
    898898
  • src/AST/Print.cpp

    r7dc2e57b re67991f  
    3737}
    3838
    39 class Printer : public Visitor {
     39class Printer final : public Visitor {
    4040public:
    4141        ostream & os;
     
    272272
    273273public:
    274         virtual const ast::DeclWithType * visit( const ast::ObjectDecl * node ) {
     274        virtual const ast::DeclWithType * visit( const ast::ObjectDecl * node ) override final {
    275275                if ( ! node->name.empty() ) os << node->name << ": ";
    276276
     
    314314        }
    315315
    316         virtual const ast::DeclWithType * visit( const ast::FunctionDecl * node ) {
     316        virtual const ast::DeclWithType * visit( const ast::FunctionDecl * node ) override final {
    317317                if ( !node->name.empty() ) os << node->name << ": ";
    318318
     
    342342        }
    343343
    344         virtual const ast::Decl * visit( const ast::StructDecl * node ) {
     344        virtual const ast::Decl * visit( const ast::StructDecl * node ) override final {
    345345                print(node);
    346346                return node;
    347347        }
    348348
    349         virtual const ast::Decl * visit( const ast::UnionDecl * node ) {
     349        virtual const ast::Decl * visit( const ast::UnionDecl * node ) override final {
    350350                print(node);
    351351                return node;
    352352        }
    353353
    354         virtual const ast::Decl * visit( const ast::EnumDecl * node ) {
     354        virtual const ast::Decl * visit( const ast::EnumDecl * node ) override final {
    355355                print(node);
    356356                return node;
    357357        }
    358358
    359         virtual const ast::Decl * visit( const ast::TraitDecl * node ) {
     359        virtual const ast::Decl * visit( const ast::TraitDecl * node ) override final {
    360360                print(node);
    361361                return node;
    362362        }
    363363
    364         virtual const ast::Decl * visit( const ast::TypeDecl * node ) {
     364        virtual const ast::Decl * visit( const ast::TypeDecl * node ) override final {
    365365                preprint( node );
    366366                if ( ! short_mode && node->init ) {
     
    374374        }
    375375
    376         virtual const ast::Decl * visit( const ast::TypedefDecl * node ) {
    377                 preprint( node );
    378                 return node;
    379         }
    380 
    381         virtual const ast::AsmDecl * visit( const ast::AsmDecl * node ) {
     376        virtual const ast::Decl * visit( const ast::TypedefDecl * node ) override final {
     377                preprint( node );
     378                return node;
     379        }
     380
     381        virtual const ast::AsmDecl * visit( const ast::AsmDecl * node ) override final {
    382382                safe_print( node->stmt );
    383383                return node;
    384384        }
    385385
    386         virtual const ast::StaticAssertDecl * visit( const ast::StaticAssertDecl * node ) {
     386        virtual const ast::StaticAssertDecl * visit( const ast::StaticAssertDecl * node ) override final {
    387387                os << "Static Assert with condition: ";
    388388                ++indent;
     
    396396        }
    397397
    398         virtual const ast::CompoundStmt * visit( const ast::CompoundStmt * node ) {
     398        virtual const ast::CompoundStmt * visit( const ast::CompoundStmt * node ) override final {
    399399                os << "Compound Statement:" << endl;
    400400                ++indent;
     
    404404        }
    405405
    406         virtual const ast::Stmt * visit( const ast::ExprStmt * node ) {
     406        virtual const ast::Stmt * visit( const ast::ExprStmt * node ) override final {
    407407                ++indent;
    408408                os << "Expression Statement:" << endl << indent;
     
    412412        }
    413413
    414         virtual const ast::Stmt * visit( const ast::AsmStmt * node ) {
     414        virtual const ast::Stmt * visit( const ast::AsmStmt * node ) override final {
    415415                os << "Assembler Statement:" << endl;
    416416                ++indent;
     
    433433        }
    434434
    435         virtual const ast::Stmt * visit( const ast::DirectiveStmt * node ) {
     435        virtual const ast::Stmt * visit( const ast::DirectiveStmt * node ) override final {
    436436                os << "GCC Directive: " << node->directive << endl;
    437437                return node;
    438438        }
    439439
    440         virtual const ast::Stmt * visit( const ast::IfStmt * node ) {
     440        virtual const ast::Stmt * visit( const ast::IfStmt * node ) override final {
    441441                os << "If on condition:" << endl;
    442442                ++indent;
     
    473473        }
    474474
    475         virtual const ast::Stmt * visit( const ast::WhileStmt * node ) {
     475        virtual const ast::Stmt * visit( const ast::WhileStmt * node ) override final {
    476476                if ( node->isDoWhile ) { os << "Do-"; }
    477477                os << "While on condition:" << endl;
     
    490490        }
    491491
    492         virtual const ast::Stmt * visit( const ast::ForStmt * node ) {
     492        virtual const ast::Stmt * visit( const ast::ForStmt * node ) override final {
    493493                os << "For Statement" << endl;
    494494
     
    532532        }
    533533
    534         virtual const ast::Stmt * visit( const ast::SwitchStmt * node ) {
     534        virtual const ast::Stmt * visit( const ast::SwitchStmt * node ) override final {
    535535                os << "Switch on condition: ";
    536536                safe_print( node->cond );
     
    546546        }
    547547
    548         virtual const ast::Stmt * visit( const ast::CaseStmt * node ) {
     548        virtual const ast::Stmt * visit( const ast::CaseStmt * node ) override final {
    549549                if ( node->isDefault() ) {
    550550                        os << indent << "Default ";
     
    565565        }
    566566
    567         virtual const ast::Stmt * visit( const ast::BranchStmt * node ) {
     567        virtual const ast::Stmt * visit( const ast::BranchStmt * node ) override final {
    568568                os << "Branch (" << node->kindName() << ")" << endl;
    569569                ++indent;
     
    586586        }
    587587
    588         virtual const ast::Stmt * visit( const ast::ReturnStmt * node ) {
     588        virtual const ast::Stmt * visit( const ast::ReturnStmt * node ) override final {
    589589                os << "Return Statement, returning";
    590590                if ( node->expr ) {
     
    601601        }
    602602
    603         virtual const ast::Stmt * visit( const ast::ThrowStmt * node ) {
     603        virtual const ast::Stmt * visit( const ast::ThrowStmt * node ) override final {
    604604                if ( node->target ) os << "Non-Local ";
    605605
     
    621621        }
    622622
    623         virtual const ast::Stmt * visit( const ast::TryStmt * node ) {
     623        virtual const ast::Stmt * visit( const ast::TryStmt * node ) override final {
    624624                ++indent;
    625625                os << "Try Statement" << endl << indent-1
     
    642642        }
    643643
    644         virtual const ast::Stmt * visit( const ast::CatchStmt * node ) {
     644        virtual const ast::Stmt * visit( const ast::CatchStmt * node ) override final {
    645645                os << "Catch ";
    646646                switch ( node->kind ) {
     
    667667        }
    668668
    669         virtual const ast::Stmt * visit( const ast::FinallyStmt * node ) {
     669        virtual const ast::Stmt * visit( const ast::FinallyStmt * node ) override final {
    670670                os << "Finally Statement" << endl;
    671671                os << indent << "... with block:" << endl;
     
    678678        }
    679679
    680         virtual const ast::Stmt * visit( const ast::WaitForStmt * node ) {
     680        virtual const ast::Stmt * visit( const ast::WaitForStmt * node ) override final {
    681681                os << "Waitfor Statement" << endl;
    682682                indent += 2;
     
    732732        }
    733733
    734         virtual const ast::Stmt * visit( const ast::WithStmt * node ) {
     734        virtual const ast::Decl * visit( const ast::WithStmt * node ) override final {
    735735                os << "With statement" << endl;
    736736                os << indent << "... with expressions:" << endl;
     
    744744        }
    745745
    746         virtual const ast::NullStmt * visit( const ast::NullStmt * node ) {
     746        virtual const ast::NullStmt * visit( const ast::NullStmt * node ) override final {
    747747                os << "Null Statement" << endl;
    748748                print( node->labels );
     
    751751        }
    752752
    753         virtual const ast::Stmt * visit( const ast::DeclStmt * node ) {
     753        virtual const ast::Stmt * visit( const ast::DeclStmt * node ) override final {
    754754                os << "Declaration of ";
    755755                safe_print( node->decl );
     
    758758        }
    759759
    760         virtual const ast::Stmt * visit( const ast::ImplicitCtorDtorStmt * node ) {
     760        virtual const ast::Stmt * visit( const ast::ImplicitCtorDtorStmt * node ) override final {
    761761                os << "Implicit Ctor Dtor Statement" << endl;
    762762                os << indent << "... with Ctor/Dtor: ";
     
    769769        }
    770770
    771         virtual const ast::Expr * visit( const ast::ApplicationExpr * node ) {
     771        virtual const ast::Expr * visit( const ast::ApplicationExpr * node ) override final {
    772772                ++indent;
    773773                os << "Application of" << endl << indent;
     
    784784        }
    785785
    786         virtual const ast::Expr * visit( const ast::UntypedExpr * node ) {
     786        virtual const ast::Expr * visit( const ast::UntypedExpr * node ) override final {
    787787                ++indent;
    788788                os << "Applying untyped:" << endl;
     
    797797        }
    798798
    799         virtual const ast::Expr * visit( const ast::NameExpr * node ) {
     799        virtual const ast::Expr * visit( const ast::NameExpr * node ) override final {
    800800                os << "Name: " << node->name;
    801801                postprint( node );
     
    804804        }
    805805
    806         virtual const ast::Expr * visit( const ast::AddressExpr * node ) {
     806        virtual const ast::Expr * visit( const ast::AddressExpr * node ) override final {
    807807                os << "Address of:" << endl;
    808808                ++indent;
     
    815815        }
    816816
    817         virtual const ast::Expr * visit( const ast::LabelAddressExpr * node ) {
     817        virtual const ast::Expr * visit( const ast::LabelAddressExpr * node ) override final {
    818818                os << "Address of label:" << node->arg;
    819819
     
    821821        }
    822822
    823         virtual const ast::Expr * visit( const ast::CastExpr * node ) {
     823        virtual const ast::Expr * visit( const ast::CastExpr * node ) override final {
    824824                ++indent;
    825825                os << (node->isGenerated ? "Generated" : "Explicit") << " cast of:" << endl << indent;
     
    841841        }
    842842
    843         virtual const ast::Expr * visit( const ast::KeywordCastExpr * node ) {
     843        virtual const ast::Expr * visit( const ast::KeywordCastExpr * node ) override final {
    844844                ++indent;
    845845                os << "Keyword Cast of:" << endl << indent;
     
    852852        }
    853853
    854         virtual const ast::Expr * visit( const ast::VirtualCastExpr * node ) {
     854        virtual const ast::Expr * visit( const ast::VirtualCastExpr * node ) override final {
    855855                ++indent;
    856856                os << "Virtual Cast of:" << endl << indent;
     
    869869        }
    870870
    871         virtual const ast::Expr * visit( const ast::UntypedMemberExpr * node ) {
     871        virtual const ast::Expr * visit( const ast::UntypedMemberExpr * node ) override final {
    872872                ++indent;
    873873                os << "Untyped Member Expression, with field: " << endl << indent;
     
    881881        }
    882882
    883         virtual const ast::Expr * visit( const ast::MemberExpr * node ) {
     883        virtual const ast::Expr * visit( const ast::MemberExpr * node ) override final {
    884884                ++indent;
    885885                os << "Member Expression, with field:" << endl << indent;
     
    893893        }
    894894
    895         virtual const ast::Expr * visit( const ast::VariableExpr * node ) {
     895        virtual const ast::Expr * visit( const ast::VariableExpr * node ) override final {
    896896                os << "Variable Expression: ";
    897897                short_print( node->var );
     
    901901        }
    902902
    903         virtual const ast::Expr * visit( const ast::ConstantExpr * node ) {
     903        virtual const ast::Expr * visit( const ast::ConstantExpr * node ) override final {
    904904                os << "Constant Expression (" << node->rep;
    905905                if ( node->result ) {
     
    913913        }
    914914
    915         virtual const ast::Expr * visit( const ast::SizeofExpr * node ) {
     915        virtual const ast::Expr * visit( const ast::SizeofExpr * node ) override final {
    916916                os << "Sizeof Expression on: ";
    917917                ++indent;
     
    924924        }
    925925
    926         virtual const ast::Expr * visit( const ast::AlignofExpr * node ) {
     926        virtual const ast::Expr * visit( const ast::AlignofExpr * node ) override final {
    927927                os << "Alignof Expression on: ";
    928928                ++indent;
     
    935935        }
    936936
    937         virtual const ast::Expr * visit( const ast::UntypedOffsetofExpr * node ) {
     937        virtual const ast::Expr * visit( const ast::UntypedOffsetofExpr * node ) override final {
    938938                os << "Untyped Offsetof Expression on member " << node->member << " of ";
    939939                ++indent;
     
    945945        }
    946946
    947         virtual const ast::Expr * visit( const ast::OffsetofExpr * node ) {
     947        virtual const ast::Expr * visit( const ast::OffsetofExpr * node ) override final {
    948948                os << "Offsetof Expression on member " << node->member->name << " of ";
    949949                ++indent;
     
    955955        }
    956956
    957         virtual const ast::Expr * visit( const ast::OffsetPackExpr * node ) {
     957        virtual const ast::Expr * visit( const ast::OffsetPackExpr * node ) override final {
    958958                os << "Offset Pack Expression on: ";
    959959                ++indent;
     
    965965        }
    966966
    967         virtual const ast::Expr * visit( const ast::LogicalExpr * node ) {
     967        virtual const ast::Expr * visit( const ast::LogicalExpr * node ) override final {
    968968                os << "Short-circuited operation (" << (node->isAnd ? "and" : "or") << ") on: ";
    969969                safe_print( node->arg1 );
     
    975975        }
    976976
    977         virtual const ast::Expr * visit( const ast::ConditionalExpr * node ) {
     977        virtual const ast::Expr * visit( const ast::ConditionalExpr * node ) override final {
    978978                ++indent;
    979979                os << "Conditional expression on:" << endl << indent;
     
    989989        }
    990990
    991         virtual const ast::Expr * visit( const ast::CommaExpr * node ) {
     991        virtual const ast::Expr * visit( const ast::CommaExpr * node ) override final {
    992992                ++indent;
    993993                os << "Comma Expression:" << endl << indent;
     
    10011001        }
    10021002
    1003         virtual const ast::Expr * visit( const ast::TypeExpr * node ) {
     1003        virtual const ast::Expr * visit( const ast::TypeExpr * node ) override final {
    10041004                safe_print( node->type );
    10051005                postprint( node );
     
    10081008        }
    10091009
    1010         virtual const ast::Expr * visit( const ast::AsmExpr * node ) {
     1010        virtual const ast::Expr * visit( const ast::AsmExpr * node ) override final {
    10111011                os << "Asm Expression:" << endl;
    10121012                ++indent;
     
    10191019        }
    10201020
    1021         virtual const ast::Expr * visit( const ast::ImplicitCopyCtorExpr * node ) {
     1021        virtual const ast::Expr * visit( const ast::ImplicitCopyCtorExpr * node ) override final {
    10221022                ++indent;
    10231023                os << "Implicit Copy Constructor Expression:" << endl << indent;
     
    10291029        }
    10301030
    1031         virtual const ast::Expr * visit( const ast::ConstructorExpr * node ) {
     1031        virtual const ast::Expr * visit( const ast::ConstructorExpr * node ) override final {
    10321032                os <<  "Constructor Expression:" << endl << indent+1;
    10331033                indent += 2;
     
    10391039        }
    10401040
    1041         virtual const ast::Expr * visit( const ast::CompoundLiteralExpr * node ) {
     1041        virtual const ast::Expr * visit( const ast::CompoundLiteralExpr * node ) override final {
    10421042                ++indent;
    10431043                os << "Compound Literal Expression: " << endl << indent;
     
    10511051        }
    10521052
    1053         virtual const ast::Expr * visit( const ast::RangeExpr * node ) {
     1053        virtual const ast::Expr * visit( const ast::RangeExpr * node ) override final {
    10541054                os << "Range Expression: ";
    10551055                safe_print( node->low );
     
    10611061        }
    10621062
    1063         virtual const ast::Expr * visit( const ast::UntypedTupleExpr * node ) {
     1063        virtual const ast::Expr * visit( const ast::UntypedTupleExpr * node ) override final {
    10641064                os << "Untyped Tuple:" << endl;
    10651065                ++indent;
     
    10711071        }
    10721072
    1073         virtual const ast::Expr * visit( const ast::TupleExpr * node ) {
     1073        virtual const ast::Expr * visit( const ast::TupleExpr * node ) override final {
    10741074                os << "Tuple:" << endl;
    10751075                ++indent;
     
    10811081        }
    10821082
    1083         virtual const ast::Expr * visit( const ast::TupleIndexExpr * node ) {
     1083        virtual const ast::Expr * visit( const ast::TupleIndexExpr * node ) override final {
    10841084                os << "Tuple Index Expression, with tuple:" << endl;
    10851085                ++indent;
     
    10931093        }
    10941094
    1095         virtual const ast::Expr * visit( const ast::TupleAssignExpr * node ) {
     1095        virtual const ast::Expr * visit( const ast::TupleAssignExpr * node ) override final {
    10961096                os << "Tuple Assignment Expression, with stmt expr:" << endl;
    10971097                ++indent;
     
    11041104        }
    11051105
    1106         virtual const ast::Expr * visit( const ast::StmtExpr * node ) {
     1106        virtual const ast::Expr * visit( const ast::StmtExpr * node ) override final {
    11071107                ++indent;
    11081108                os << "Statement Expression:" << endl << indent;
     
    11221122        }
    11231123
    1124         virtual const ast::Expr * visit( const ast::UniqueExpr * node ) {
     1124        virtual const ast::Expr * visit( const ast::UniqueExpr * node ) override final {
    11251125                ++indent;
    11261126                os << "Unique Expression with id: " << node->id << endl << indent;
     
    11361136        }
    11371137
    1138         virtual const ast::Expr * visit( const ast::UntypedInitExpr * node ) {
     1138        virtual const ast::Expr * visit( const ast::UntypedInitExpr * node ) override final {
    11391139                ++indent;
    11401140                os << "Untyped Init Expression" << endl << indent;
     
    11521152        }
    11531153
    1154         virtual const ast::Expr * visit( const ast::InitExpr * node ) {
     1154        virtual const ast::Expr * visit( const ast::InitExpr * node ) override final {
    11551155                ++indent;
    11561156                os << "Init Expression" << endl << indent;
     
    11631163        }
    11641164
    1165         virtual const ast::Expr * visit( const ast::DeletedExpr * node ) {
     1165        virtual const ast::Expr * visit( const ast::DeletedExpr * node ) override final {
    11661166                ++indent;
    11671167                os << "Deleted Expression" << endl << indent;
     
    11741174        }
    11751175
    1176         virtual const ast::Expr * visit( const ast::DefaultArgExpr * node ) {
     1176        virtual const ast::Expr * visit( const ast::DefaultArgExpr * node ) override final {
    11771177                ++indent;
    11781178                os << "Default Argument Expression" << endl << indent;
     
    11831183        }
    11841184
    1185         virtual const ast::Expr * visit( const ast::GenericExpr * node ) {
     1185        virtual const ast::Expr * visit( const ast::GenericExpr * node ) override final {
    11861186                ++indent;
    11871187                os << "C11 _Generic Expression" << endl << indent;
     
    12061206        }
    12071207
    1208         virtual const ast::Type * visit( const ast::VoidType * node ) {
     1208        virtual const ast::Type * visit( const ast::VoidType * node ) override final {
    12091209                preprint( node );
    12101210                os << "void";
     
    12121212        }
    12131213
    1214         virtual const ast::Type * visit( const ast::BasicType * node ) {
     1214        virtual const ast::Type * visit( const ast::BasicType * node ) override final {
    12151215                preprint( node );
    12161216                os << ast::BasicType::typeNames[ node->kind ];
     
    12181218        }
    12191219
    1220         virtual const ast::Type * visit( const ast::PointerType * node ) {
     1220        virtual const ast::Type * visit( const ast::PointerType * node ) override final {
    12211221                preprint( node );
    12221222                if ( ! node->isArray() ) {
     
    12411241        }
    12421242
    1243         virtual const ast::Type * visit( const ast::ArrayType * node ) {
     1243        virtual const ast::Type * visit( const ast::ArrayType * node ) override final {
    12441244                preprint( node );
    12451245                if ( node->isStatic ) {
     
    12651265        }
    12661266
    1267         virtual const ast::Type * visit( const ast::ReferenceType * node ) {
     1267        virtual const ast::Type * visit( const ast::ReferenceType * node ) override final {
    12681268                preprint( node );
    12691269                os << "reference to ";
     
    12731273        }
    12741274
    1275         virtual const ast::Type * visit( const ast::QualifiedType * node ) {
     1275        virtual const ast::Type * visit( const ast::QualifiedType * node ) override final {
    12761276                preprint( node );
    12771277                ++indent;
     
    12861286        }
    12871287
    1288         virtual const ast::Type * visit( const ast::FunctionType * node ) {
     1288        virtual const ast::Type * visit( const ast::FunctionType * node ) override final {
    12891289                preprint( node );
    12901290
     
    13151315        }
    13161316
    1317         virtual const ast::Type * visit( const ast::StructInstType * node ) {
     1317        virtual const ast::Type * visit( const ast::StructInstType * node ) override final {
    13181318                preprint( node );
    13191319                os << "instance of struct " << node->name;
     
    13261326        }
    13271327
    1328         virtual const ast::Type * visit( const ast::UnionInstType * node ) {
     1328        virtual const ast::Type * visit( const ast::UnionInstType * node ) override final {
    13291329                preprint( node );
    13301330                os << "instance of union " << node->name;
     
    13371337        }
    13381338
    1339         virtual const ast::Type * visit( const ast::EnumInstType * node ) {
     1339        virtual const ast::Type * visit( const ast::EnumInstType * node ) override final {
    13401340                preprint( node );
    13411341                os << "instance of enum " << node->name;
     
    13481348        }
    13491349
    1350         virtual const ast::Type * visit( const ast::TraitInstType * node ) {
     1350        virtual const ast::Type * visit( const ast::TraitInstType * node ) override final {
    13511351                preprint( node );
    13521352                os << "instance of trait " << node->name;
     
    13561356        }
    13571357
    1358         virtual const ast::Type * visit( const ast::TypeInstType * node ) {
     1358        virtual const ast::Type * visit( const ast::TypeInstType * node ) override final {
    13591359                preprint( node );
    13601360                os << "instance of type " << node->name
     
    13651365        }
    13661366
    1367         virtual const ast::Type * visit( const ast::TupleType * node ) {
     1367        virtual const ast::Type * visit( const ast::TupleType * node ) override final {
    13681368                preprint( node );
    13691369                os << "tuple of types" << endl;
     
    13751375        }
    13761376
    1377         virtual const ast::Type * visit( const ast::TypeofType * node ) {
     1377        virtual const ast::Type * visit( const ast::TypeofType * node ) override final {
    13781378                preprint( node );
    13791379                if ( node->kind == ast::TypeofType::Basetypeof ) { os << "base-"; }
     
    13841384        }
    13851385
    1386         virtual const ast::Type * visit( const ast::VarArgsType * node ) {
     1386        virtual const ast::Type * visit( const ast::VarArgsType * node ) override final {
    13871387                preprint( node );
    13881388                os << "builtin var args pack";
     
    13901390        }
    13911391
    1392         virtual const ast::Type * visit( const ast::ZeroType * node ) {
     1392        virtual const ast::Type * visit( const ast::ZeroType * node ) override final {
    13931393                preprint( node );
    13941394                os << "zero_t";
     
    13961396        }
    13971397
    1398         virtual const ast::Type * visit( const ast::OneType * node ) {
     1398        virtual const ast::Type * visit( const ast::OneType * node ) override final {
    13991399                preprint( node );
    14001400                os << "one_t";
     
    14021402        }
    14031403
    1404         virtual const ast::Type * visit( const ast::GlobalScopeType * node ) {
     1404        virtual const ast::Type * visit( const ast::GlobalScopeType * node ) override final {
    14051405                preprint( node );
    14061406                os << "Global Scope Type";
     
    14081408        }
    14091409
    1410         virtual const ast::Designation * visit( const ast::Designation * node ) {
     1410        virtual const ast::Designation * visit( const ast::Designation * node ) override final {
    14111411                if ( node->designators.empty() ) return node;
    14121412                os << "... designated by: " << endl;
     
    14211421        }
    14221422
    1423         virtual const ast::Init * visit( const ast::SingleInit * node ) {
     1423        virtual const ast::Init * visit( const ast::SingleInit * node ) override final {
    14241424                os << "Simple Initializer: ";
    14251425                safe_print( node->value );
     
    14271427        }
    14281428
    1429         virtual const ast::Init * visit( const ast::ListInit * node ) {
     1429        virtual const ast::Init * visit( const ast::ListInit * node ) override final {
    14301430                os << "Compound initializer: " << endl;
    14311431                ++indent;
     
    14451445        }
    14461446
    1447         virtual const ast::Init * visit( const ast::ConstructorInit * node ) {
     1447        virtual const ast::Init * visit( const ast::ConstructorInit * node ) override final {
    14481448                os << "Constructor initializer: " << endl;
    14491449                if ( node->ctor ) {
     
    14701470        }
    14711471
    1472         virtual const ast::Attribute * visit( const ast::Attribute * node ) {
     1472        virtual const ast::Attribute * visit( const ast::Attribute * node ) override final {
    14731473                if ( node->empty() ) return node;
    14741474                os << "Attribute with name: " << node->name;
     
    14811481        }
    14821482
    1483         virtual const ast::TypeSubstitution * visit( const ast::TypeSubstitution * node ) {
     1483        virtual const ast::TypeSubstitution * visit( const ast::TypeSubstitution * node ) override final {
    14841484                os << indent << "Types:" << endl;
    14851485                for ( const auto& i : *node ) {
  • src/AST/Stmt.hpp

    r7dc2e57b re67991f  
    380380};
    381381
    382 /// With statement `with (...) ...`
    383 class WithStmt final : public Stmt {
    384 public:
    385         std::vector<ptr<Expr>> exprs;
    386         ptr<Stmt> stmt;
    387 
    388         WithStmt( const CodeLocation & loc, std::vector<ptr<Expr>> && exprs, const Stmt * stmt,
    389                 std::vector<Label> && labels = {} )
    390         : Stmt(loc, std::move(labels)), exprs(std::move(exprs)), stmt(stmt) {}
    391 
    392         const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
    393 private:
    394         WithStmt * clone() const override { return new WithStmt{ *this }; }
    395         MUTATE_FRIEND
    396 };
    397 
    398382/// Any declaration in a (compound) statement.
    399383class DeclStmt final : public Stmt {
  • src/AST/SymbolTable.cpp

    r7dc2e57b re67991f  
    7373
    7474SymbolTable::SymbolTable()
    75 : idTable(), typeTable(), structTable(), enumTable(), unionTable(), traitTable(), 
     75: idTable(), typeTable(), structTable(), enumTable(), unionTable(), traitTable(),
    7676  prevScope(), scope( 0 ), repScope( 0 ) { ++*stats().count; }
    7777
     
    171171}
    172172
    173 void SymbolTable::addDeletedId( const DeclWithType * decl, const Node * deleter ) {
     173void SymbolTable::addDeletedId( const DeclWithType * decl, const Decl * deleter ) {
    174174        // default handling of conflicts is to raise an error
    175175        addId( decl, OnConflict::error(), nullptr, deleter );
     
    189189                        }
    190190                }
    191                 // does not need to be added to the table if both existing and added have a base that are 
     191                // does not need to be added to the table if both existing and added have a base that are
    192192                // the same
    193193                return true;
     
    209209        const std::string &id = decl->name;
    210210
    211         if ( ! typeTable ) { 
     211        if ( ! typeTable ) {
    212212                typeTable = TypeTable::new_ptr();
    213213        } else {
    214214                ++*stats().map_lookups;
    215215                auto existing = typeTable->find( id );
    216                 if ( existing != typeTable->end() 
    217                         && existing->second.scope == scope 
     216                if ( existing != typeTable->end()
     217                        && existing->second.scope == scope
    218218                        && addedTypeConflicts( existing->second.decl, decl ) ) return;
    219219        }
    220        
     220
    221221        lazyInitScope();
    222222        ++*stats().map_mutations;
     
    237237                ++*stats().map_lookups;
    238238                auto existing = structTable->find( id );
    239                 if ( existing != structTable->end() 
    240                         && existing->second.scope == scope 
     239                if ( existing != structTable->end()
     240                        && existing->second.scope == scope
    241241                        && addedDeclConflicts( existing->second.decl, decl ) ) return;
    242242        }
     
    256256                ++*stats().map_lookups;
    257257                auto existing = enumTable->find( id );
    258                 if ( existing != enumTable->end() 
    259                         && existing->second.scope == scope 
     258                if ( existing != enumTable->end()
     259                        && existing->second.scope == scope
    260260                        && addedDeclConflicts( existing->second.decl, decl ) ) return;
    261261        }
    262        
     262
    263263        lazyInitScope();
    264264        ++*stats().map_mutations;
     
    279279                ++*stats().map_lookups;
    280280                auto existing = unionTable->find( id );
    281                 if ( existing != unionTable->end() 
    282                         && existing->second.scope == scope 
     281                if ( existing != unionTable->end()
     282                        && existing->second.scope == scope
    283283                        && addedDeclConflicts( existing->second.decl, decl ) ) return;
    284284        }
     
    298298                ++*stats().map_lookups;
    299299                auto existing = traitTable->find( id );
    300                 if ( existing != traitTable->end() 
    301                         && existing->second.scope == scope 
     300                if ( existing != traitTable->end()
     301                        && existing->second.scope == scope
    302302                        && addedDeclConflicts( existing->second.decl, decl ) ) return;
    303303        }
     
    309309
    310310
    311 void SymbolTable::addWith( const std::vector< ptr<Expr> > & withExprs, const Node * withStmt ) {
     311void SymbolTable::addWith( const std::vector< ptr<Expr> > & withExprs, const Decl * withStmt ) {
    312312        for ( const Expr * expr : withExprs ) {
    313313                if ( ! expr->result ) continue;
    314314                const Type * resTy = expr->result->stripReferences();
    315315                auto aggrType = dynamic_cast< const ReferenceToType * >( resTy );
    316                 assertf( aggrType, "WithStmt expr has non-aggregate type: %s", 
     316                assertf( aggrType, "WithStmt expr has non-aggregate type: %s",
    317317                        toString( expr->result ).c_str() );
    318318                const AggregateDecl * aggr = aggrType->aggr();
    319                 assertf( aggr, "WithStmt has null aggregate from type: %s", 
     319                assertf( aggr, "WithStmt has null aggregate from type: %s",
    320320                        toString( expr->result ).c_str() );
    321                
     321
    322322                addMembers( aggr, expr, OnConflict::deleteWith( withStmt ) );
    323323        }
     
    373373        }
    374374
    375         /// gets the declaration for the function acting on a type specified by otype key, 
     375        /// gets the declaration for the function acting on a type specified by otype key,
    376376        /// nullptr if none such
    377         const FunctionDecl * getFunctionForOtype( 
     377        const FunctionDecl * getFunctionForOtype(
    378378                        const DeclWithType * decl, const std::string & otypeKey ) {
    379379                auto func = dynamic_cast< const FunctionDecl * >( decl );
     
    383383}
    384384
    385 bool SymbolTable::removeSpecialOverrides( 
     385bool SymbolTable::removeSpecialOverrides(
    386386                SymbolTable::IdData & data, SymbolTable::MangleTable::Ptr & mangleTable ) {
    387         // if a type contains user defined ctor/dtor/assign, then special rules trigger, which 
    388         // determine the set of ctor/dtor/assign that can be used  by the requester. In particular, 
    389         // if the user defines a default ctor, then the generated default ctor is unavailable, 
    390         // likewise for copy ctor and dtor. If the user defines any ctor/dtor, then no generated 
    391         // field ctors are available. If the user defines any ctor then the generated default ctor 
    392         // is unavailable (intrinsic default ctor must be overridden exactly). If the user defines 
    393         // anything that looks like a copy constructor, then the generated copy constructor is 
     387        // if a type contains user defined ctor/dtor/assign, then special rules trigger, which
     388        // determine the set of ctor/dtor/assign that can be used  by the requester. In particular,
     389        // if the user defines a default ctor, then the generated default ctor is unavailable,
     390        // likewise for copy ctor and dtor. If the user defines any ctor/dtor, then no generated
     391        // field ctors are available. If the user defines any ctor then the generated default ctor
     392        // is unavailable (intrinsic default ctor must be overridden exactly). If the user defines
     393        // anything that looks like a copy constructor, then the generated copy constructor is
    394394        // unavailable, and likewise for the assignment operator.
    395395
     
    450450                // if this is the first user-defined function, delete non-user-defined overloads
    451451                std::vector< MangleTable::value_type > deleted;
    452                
     452
    453453                for ( const auto& entry : *mangleTable ) {
    454454                        // skip decls that aren't functions or are for the wrong type
     
    489489                        if ( dataIsCopyFunc ) {
    490490                                // remove current function if exists a user-defined copy function
    491                                 // since the signatures for copy functions don't need to match exactly, using 
     491                                // since the signatures for copy functions don't need to match exactly, using
    492492                                // a delete statement is the wrong approach
    493493                                if ( InitTweak::isCopyFunction( decl ) ) return false;
     
    499499                }
    500500        }
    501        
     501
    502502        // nothing (more) to fix, return true
    503503        return true;
     
    525525
    526526bool SymbolTable::addedIdConflicts(
    527                 const SymbolTable::IdData & existing, const DeclWithType * added, 
    528                 SymbolTable::OnConflict handleConflicts, const Node * deleter ) {
    529         // if we're giving the same name mangling to things of different types then there is something 
     527                const SymbolTable::IdData & existing, const DeclWithType * added,
     528                SymbolTable::OnConflict handleConflicts, const Decl * deleter ) {
     529        // if we're giving the same name mangling to things of different types then there is something
    530530        // wrong
    531531        assert( (isObject( added ) && isObject( existing.id ) )
    532532                || ( isFunction( added ) && isFunction( existing.id ) ) );
    533        
     533
    534534        if ( existing.id->linkage.is_overrideable ) {
    535535                // new definition shadows the autogenerated one, even at the same scope
    536536                return false;
    537         } else if ( existing.id->linkage.is_mangled 
    538                         || ResolvExpr::typesCompatible( 
     537        } else if ( existing.id->linkage.is_mangled
     538                        || ResolvExpr::typesCompatible(
    539539                                added->get_type(), existing.id->get_type(), SymbolTable{} ) ) {
    540                
     540
    541541                // it is a conflict if one declaration is deleted and the other is not
    542542                if ( deleter && ! existing.deleter ) {
     
    555555                if ( isDefinition( added ) && isDefinition( existing.id ) ) {
    556556                        if ( handleConflicts.mode == OnConflict::Error ) {
    557                                 SemanticError( added, 
    558                                         isFunction( added ) ? 
    559                                                 "duplicate function definition for " : 
     557                                SemanticError( added,
     558                                        isFunction( added ) ?
     559                                                "duplicate function definition for " :
    560560                                                "duplicate object definition for " );
    561561                        }
     
    572572}
    573573
    574 void SymbolTable::addId( 
    575                 const DeclWithType * decl, SymbolTable::OnConflict handleConflicts, const Expr * baseExpr, 
    576                 const Node * deleter ) {
     574void SymbolTable::addId(
     575                const DeclWithType * decl, SymbolTable::OnConflict handleConflicts, const Expr * baseExpr,
     576                const Decl * deleter ) {
    577577        ++*stats().add_calls;
    578578        const std::string &name = decl->name;
     
    581581        std::string mangleName;
    582582        if ( decl->linkage.is_overrideable ) {
    583                 // mangle the name without including the appropriate suffix, so overridable routines 
     583                // mangle the name without including the appropriate suffix, so overridable routines
    584584                // are placed into the same "bucket" as their user defined versions.
    585585                mangleName = Mangle::mangle( decl, Mangle::Mode{ Mangle::NoOverrideable } );
     
    588588        }
    589589
    590         // this ensures that no two declarations with the same unmangled name at the same scope 
     590        // this ensures that no two declarations with the same unmangled name at the same scope
    591591        // both have C linkage
    592592        if ( decl->linkage.is_mangled ) {
     
    596596                }
    597597        } else {
    598                 // NOTE: only correct if name mangling is completely isomorphic to C 
     598                // NOTE: only correct if name mangling is completely isomorphic to C
    599599                // type-compatibility, which it may not be.
    600600                if ( hasIncompatibleCDecl( name, mangleName ) ) {
     
    628628                                                idTable = idTable->set(
    629629                                                        name,
    630                                                         mangleTable->set( 
    631                                                                 mangleName, 
     630                                                        mangleTable->set(
     631                                                                mangleName,
    632632                                                                IdData{ existing->second, handleConflicts.deleter } ) );
    633633                                        }
     
    647647}
    648648
    649 void SymbolTable::addMembers( 
     649void SymbolTable::addMembers(
    650650                const AggregateDecl * aggr, const Expr * expr, SymbolTable::OnConflict handleConflicts ) {
    651651        for ( const Decl * decl : aggr->members ) {
     
    655655                                const Type * t = dwt->get_type()->stripReferences();
    656656                                if ( auto rty = dynamic_cast<const ReferenceToType *>( t ) ) {
    657                                         if ( ! dynamic_cast<const StructInstType *>(rty) 
     657                                        if ( ! dynamic_cast<const StructInstType *>(rty)
    658658                                                && ! dynamic_cast<const UnionInstType *>(rty) ) continue;
    659659                                        ResolvExpr::Cost cost = ResolvExpr::Cost::zero;
    660660                                        const Expr * base = ResolvExpr::referenceToRvalueConversion( expr, cost );
    661                                         addMembers( 
     661                                        addMembers(
    662662                                                rty->aggr(), new MemberExpr{ base->location, dwt, base }, handleConflicts );
    663663                                }
     
    680680                if ( ! decl.second.id->linkage.is_mangled && decl.first == mangleName ) return true;
    681681        }
    682        
     682
    683683        return false;
    684684}
  • src/AST/SymbolTable.hpp

    r7dc2e57b re67991f  
    3737                readonly<DeclWithType> id = nullptr;  ///< Identifier of declaration
    3838                readonly<Expr> baseExpr = nullptr;    ///< Implied containing aggregate (from WithExpr)
    39                 readonly<Node> deleter = nullptr;     ///< Node deleting this declaration (if non-null)
     39                readonly<Decl> deleter = nullptr;     ///< Node deleting this declaration (if non-null)
    4040                unsigned long scope = 0;              ///< Scope of identifier
    4141
    4242                IdData() = default;
    43                 IdData( const DeclWithType * i, const Expr * base, const Node * del, unsigned long s )
     43                IdData( const DeclWithType * i, const Expr * base, const Decl * del, unsigned long s )
    4444                : id( i ), baseExpr( base ), deleter( del ), scope( s ) {}
    45                
     45
    4646                /// Modify an existing node with a new deleter
    47                 IdData( const IdData & o, const Node * del )
     47                IdData( const IdData & o, const Decl * del )
    4848                : id( o.id ), baseExpr( o.baseExpr ), deleter( del ), scope( o.scope ) {}
    4949
     
    5858        struct scoped {
    5959                readonly<D> decl;     ///< wrapped declaration
    60                 unsigned long scope;  ///< scope of this declaration 
     60                unsigned long scope;  ///< scope of this declaration
    6161
    6262                scoped(const D * d, unsigned long s) : decl(d), scope(s) {}
     
    8888        ~SymbolTable();
    8989
    90         // when using an indexer manually (e.g., within a mutator traversal), it is necessary to 
     90        // when using an indexer manually (e.g., within a mutator traversal), it is necessary to
    9191        // tell the indexer explicitly when scopes begin and end
    9292        void enterScope();
     
    118118        void addId( const DeclWithType * decl, const Expr * baseExpr = nullptr );
    119119        /// Adds a deleted identifier declaration to the symbol table
    120         void addDeletedId( const DeclWithType * decl, const Node * deleter );
     120        void addDeletedId( const DeclWithType * decl, const Decl * deleter );
    121121
    122122        /// Adds a type to the symbol table
     
    136136
    137137        /// adds all of the IDs from WithStmt exprs
    138         void addWith( const std::vector< ptr<Expr> > & withExprs, const Node * withStmt );
     138        void addWith( const std::vector< ptr<Expr> > & withExprs, const Decl * withStmt );
    139139
    140140        /// convenience function for adding a list of Ids to the indexer
     
    154154        const SymbolTable * atScope( unsigned long i ) const;
    155155
    156         /// Removes matching autogenerated constructors and destructors so that they will not be 
     156        /// Removes matching autogenerated constructors and destructors so that they will not be
    157157        /// selected. If returns false, passed decl should not be added.
    158158        bool removeSpecialOverrides( IdData & decl, MangleTable::Ptr & mangleTable );
     
    164164                        Delete  ///< Delete the earlier version with the delete statement
    165165                } mode;
    166                 const Node * deleter;  ///< Statement that deletes this expression
     166                const Decl * deleter;  ///< Statement that deletes this expression
    167167
    168168        private:
    169169                OnConflict() : mode(Error), deleter(nullptr) {}
    170                 OnConflict( const Node * d ) : mode(Delete), deleter(d) {}
     170                OnConflict( const Decl * d ) : mode(Delete), deleter(d) {}
    171171        public:
    172172                OnConflict( const OnConflict& ) = default;
    173173
    174174                static OnConflict error() { return {}; }
    175                 static OnConflict deleteWith( const Node * d ) { return { d }; }
     175                static OnConflict deleteWith( const Decl * d ) { return { d }; }
    176176        };
    177177
    178178        /// true if the existing identifier conflicts with the added identifier
    179179        bool addedIdConflicts(
    180                 const IdData & existing, const DeclWithType * added, OnConflict handleConflicts, 
    181                 const Node * deleter );
     180                const IdData & existing, const DeclWithType * added, OnConflict handleConflicts,
     181                const Decl * deleter );
    182182
    183183        /// common code for addId, addDeletedId, etc.
    184         void addId( 
    185                 const DeclWithType * decl, OnConflict handleConflicts, const Expr * baseExpr = nullptr, 
    186                 const Node * deleter = nullptr );
     184        void addId(
     185                const DeclWithType * decl, OnConflict handleConflicts, const Expr * baseExpr = nullptr,
     186                const Decl * deleter = nullptr );
    187187
    188188        /// adds all of the members of the Aggregate (addWith helper)
  • src/AST/Visitor.hpp

    r7dc2e57b re67991f  
    4848    virtual const ast::Stmt *             visit( const ast::FinallyStmt          * ) = 0;
    4949    virtual const ast::Stmt *             visit( const ast::WaitForStmt          * ) = 0;
    50     virtual const ast::Stmt *             visit( const ast::WithStmt             * ) = 0;
     50    virtual const ast::Decl *             visit( const ast::WithStmt             * ) = 0;
    5151    virtual const ast::NullStmt *         visit( const ast::NullStmt             * ) = 0;
    5252    virtual const ast::Stmt *             visit( const ast::DeclStmt             * ) = 0;
  • src/Common/PassVisitor.h

    r7dc2e57b re67991f  
    279279        virtual Statement * mutate( FinallyStmt * finallyStmt ) override final;
    280280        virtual Statement * mutate( WaitForStmt * waitforStmt ) override final;
    281         virtual Statement * mutate( WithStmt * withStmt ) override final;
     281        virtual Declaration * mutate( WithStmt * withStmt ) override final;
    282282        virtual NullStmt * mutate( NullStmt * nullStmt ) override final;
    283283        virtual Statement * mutate( DeclStmt * declStmt ) override final;
     
    420420        void indexerAddUnionFwd ( const UnionDecl           * node  ) { indexer_impl_addUnionFwd ( pass, 0, node ); }
    421421        void indexerAddTrait    ( const TraitDecl           * node  ) { indexer_impl_addTrait    ( pass, 0, node ); }
    422         void indexerAddWith     ( const std::list< Expression * > & exprs, const BaseSyntaxNode * withStmt ) { indexer_impl_addWith( pass, 0, exprs, withStmt ); }
     422        void indexerAddWith     ( const std::list< Expression * > & exprs, const Declaration * withStmt ) { indexer_impl_addWith( pass, 0, exprs, withStmt ); }
    423423
    424424
  • src/Common/PassVisitor.impl.h

    r7dc2e57b re67991f  
    16171617
    16181618template< typename pass_type >
    1619 Statement * PassVisitor< pass_type >::mutate( WithStmt * node ) {
     1619Declaration * PassVisitor< pass_type >::mutate( WithStmt * node ) {
    16201620        MUTATE_START( node );
    16211621        maybeMutate_impl( node->exprs, *this );
     
    16261626                maybeMutate_impl( node->stmt, *this );
    16271627        }
    1628         MUTATE_END( Statement, node );
     1628        MUTATE_END( Declaration, node );
    16291629}
    16301630
  • src/Common/PassVisitor.proto.h

    r7dc2e57b re67991f  
    235235INDEXER_FUNC1( addUnion  , const UnionDecl *                 );
    236236INDEXER_FUNC1( addTrait  , const TraitDecl *                 );
    237 INDEXER_FUNC2( addWith   , const std::list< Expression * > &, const BaseSyntaxNode * );
     237INDEXER_FUNC2( addWith   , const std::list< Expression * > &, const Declaration * );
    238238
    239239#undef INDEXER_FUNC1
  • src/Parser/ParseNode.h

    r7dc2e57b re67991f  
    437437WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when );
    438438WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when, StatementNode * else_stmt, ExpressionNode * else_when );
    439 WithStmt * build_with( ExpressionNode * exprs, StatementNode * stmt );
     439Statement * build_with( ExpressionNode * exprs, StatementNode * stmt );
    440440
    441441//##############################################################################
  • src/Parser/StatementNode.cc

    r7dc2e57b re67991f  
    317317} // build_waitfor_timeout
    318318
    319 WithStmt * build_with( ExpressionNode * exprs, StatementNode * stmt ) {
     319Statement * build_with( ExpressionNode * exprs, StatementNode * stmt ) {
    320320        std::list< Expression * > e;
    321321        buildMoveList( exprs, e );
    322322        Statement * s = maybeMoveBuild<Statement>( stmt );
    323         return new WithStmt( e, s );
     323        return new DeclStmt( new WithStmt( e, s ) );
    324324} // build_with
    325325
  • src/SymTab/Indexer.cc

    r7dc2e57b re67991f  
    210210        bool Indexer::addedIdConflicts(
    211211                        const Indexer::IdData & existing, const DeclarationWithType * added,
    212                         Indexer::OnConflict handleConflicts, const BaseSyntaxNode * deleteStmt ) {
     212                        Indexer::OnConflict handleConflicts, const Declaration * deleteStmt ) {
    213213                // if we're giving the same name mangling to things of different types then there is
    214214                // something wrong
     
    432432
    433433        void Indexer::addId(const DeclarationWithType * decl, OnConflict handleConflicts, const Expression * baseExpr,
    434                         const BaseSyntaxNode * deleteStmt ) {
     434                        const Declaration * deleteStmt ) {
    435435                ++* stats().add_calls;
    436436                const std::string &name = decl->name;
     
    510510        }
    511511
    512         void Indexer::addDeletedId( const DeclarationWithType * decl, const BaseSyntaxNode * deleteStmt ) {
     512        void Indexer::addDeletedId( const DeclarationWithType * decl, const Declaration * deleteStmt ) {
    513513                // default handling of conflicts is to raise an error
    514514                addId( decl, OnConflict::error(), nullptr, deleteStmt );
     
    661661        }
    662662
    663         void Indexer::addWith( const std::list< Expression * > & withExprs, const BaseSyntaxNode * withStmt ) {
     663        void Indexer::addWith( const std::list< Expression * > & withExprs, const Declaration * withStmt ) {
    664664                for ( const Expression * expr : withExprs ) {
    665665                        if ( expr->result ) {
     
    704704                        ret = new VariableExpr( const_cast<DeclarationWithType *>(id) );
    705705                }
    706                 if ( deleteStmt ) ret = new DeletedExpr( ret, const_cast<BaseSyntaxNode *>(deleteStmt) );
     706                if ( deleteStmt ) ret = new DeletedExpr( ret, const_cast<Declaration *>(deleteStmt) );
    707707                return ret;
    708708        }
  • src/SymTab/Indexer.h

    r7dc2e57b re67991f  
    4444
    4545                        /// non-null if this declaration is deleted
    46                         const BaseSyntaxNode * deleteStmt = nullptr;
     46                        const Declaration * deleteStmt = nullptr;
    4747                        /// scope of identifier
    4848                        unsigned long scope = 0;
     
    5151                        IdData() = default;
    5252                        IdData(
    53                                 const DeclarationWithType * id, const Expression * baseExpr, const BaseSyntaxNode * deleteStmt,
     53                                const DeclarationWithType * id, const Expression * baseExpr, const Declaration * deleteStmt,
    5454                                unsigned long scope )
    5555                                : id( id ), baseExpr( baseExpr ), deleteStmt( deleteStmt ), scope( scope ) {}
    56                         IdData( const IdData& o, const BaseSyntaxNode * deleteStmt )
     56                        IdData( const IdData& o, const Declaration * deleteStmt )
    5757                                : id( o.id ), baseExpr( o.baseExpr ), deleteStmt( deleteStmt ), scope( o.scope ) {}
    5858
     
    8383
    8484                void addId( const DeclarationWithType * decl, const Expression * baseExpr = nullptr );
    85                 void addDeletedId( const DeclarationWithType * decl, const BaseSyntaxNode * deleteStmt );
     85                void addDeletedId( const DeclarationWithType * decl, const Declaration * deleteStmt );
    8686
    8787                void addType( const NamedTypeDecl * decl );
     
    9494
    9595                /// adds all of the IDs from WithStmt exprs
    96                 void addWith( const std::list< Expression * > & withExprs, const BaseSyntaxNode * withStmt );
     96                void addWith( const std::list< Expression * > & withExprs, const Declaration * withStmt );
    9797
    9898                /// convenience function for adding a list of Ids to the indexer
     
    152152                                Delete  ///< Delete the earlier version with the delete statement
    153153                        } mode;
    154                         const BaseSyntaxNode * deleteStmt;  ///< Statement that deletes this expression
     154                        const Declaration * deleteStmt;  ///< Statement that deletes this expression
    155155
    156156                private:
    157157                        OnConflict() : mode(Error), deleteStmt(nullptr) {}
    158                         OnConflict( const BaseSyntaxNode * d ) : mode(Delete), deleteStmt(d) {}
     158                        OnConflict( const Declaration * d ) : mode(Delete), deleteStmt(d) {}
    159159                public:
    160160                        OnConflict( const OnConflict& ) = default;
    161161
    162162                        static OnConflict error() { return {}; }
    163                         static OnConflict deleteWith( const BaseSyntaxNode * d ) { return { d }; }
     163                        static OnConflict deleteWith( const Declaration * d ) { return { d }; }
    164164                };
    165165
     
    167167                bool addedIdConflicts(
    168168                        const IdData & existing, const DeclarationWithType * added, OnConflict handleConflicts,
    169                         const BaseSyntaxNode * deleteStmt );
     169                        const Declaration * deleteStmt );
    170170
    171171                /// common code for addId, addDeletedId, etc.
    172172                void addId(const DeclarationWithType * decl, OnConflict handleConflicts,
    173                         const Expression * baseExpr = nullptr, const BaseSyntaxNode * deleteStmt = nullptr );
     173                        const Expression * baseExpr = nullptr, const Declaration * deleteStmt = nullptr );
    174174
    175175                /// adds all of the members of the Aggregate (addWith helper)
  • src/SynTree/Declaration.h

    r7dc2e57b re67991f  
    360360};
    361361
     362class WithStmt : public Declaration {
     363public:
     364        std::list< Expression * > exprs;
     365        Statement * stmt;
     366
     367        WithStmt( const std::list< Expression * > & exprs, Statement * stmt );
     368        WithStmt( const WithStmt & other );
     369        virtual ~WithStmt();
     370
     371        virtual WithStmt * clone() const override { return new WithStmt( *this ); }
     372        virtual void accept( Visitor & v ) override { v.visit( this ); }
     373        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     374        virtual Declaration * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     375        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     376        virtual void printShort( std::ostream & os, Indenter indent = {} ) const override { print(os, indent); }
     377};
     378
    362379class AsmDecl : public Declaration {
    363380  public:
  • src/SynTree/Expression.cc

    r7dc2e57b re67991f  
    724724}
    725725
    726 DeletedExpr::DeletedExpr( Expression * expr, BaseSyntaxNode * deleteStmt ) : expr( expr ), deleteStmt( deleteStmt ) {
     726DeletedExpr::DeletedExpr( Expression * expr, Declaration * deleteStmt ) : expr( expr ), deleteStmt( deleteStmt ) {
    727727        assert( expr->result );
    728728        result = expr->result->clone();
  • src/SynTree/Expression.h

    r7dc2e57b re67991f  
    888888public:
    889889        Expression * expr;
    890         BaseSyntaxNode * deleteStmt;
    891 
    892         DeletedExpr( Expression * expr, BaseSyntaxNode * deleteStmt );
     890        Declaration * deleteStmt;
     891
     892        DeletedExpr( Expression * expr, Declaration * deleteStmt );
    893893        DeletedExpr( const DeletedExpr & other );
    894894        ~DeletedExpr();
  • src/SynTree/Mutator.h

    r7dc2e57b re67991f  
    5252        virtual Statement * mutate( FinallyStmt * catchStmt ) = 0;
    5353        virtual Statement * mutate( WaitForStmt * waitforStmt ) = 0;
    54         virtual Statement * mutate( WithStmt * withStmt ) = 0;
     54        virtual Declaration * mutate( WithStmt * withStmt ) = 0;
    5555        virtual NullStmt * mutate( NullStmt * nullStmt ) = 0;
    5656        virtual Statement * mutate( DeclStmt * declStmt ) = 0;
  • src/SynTree/Statement.cc

    r7dc2e57b re67991f  
    493493
    494494
    495 WithStmt::WithStmt( const std::list< Expression * > & exprs, Statement * stmt ) : Statement(), exprs( exprs ), stmt( stmt ) {}
    496 WithStmt::WithStmt( const WithStmt & other ) : Statement( other ), stmt( maybeClone( other.stmt ) ) {
     495WithStmt::WithStmt( const std::list< Expression * > & exprs, Statement * stmt ) : Declaration("", noStorageClasses, LinkageSpec::Cforall), exprs( exprs ), stmt( stmt ) {}
     496WithStmt::WithStmt( const WithStmt & other ) : Declaration( other ), stmt( maybeClone( other.stmt ) ) {
    497497        cloneAll( other.exprs, exprs );
    498498}
  • src/SynTree/Statement.h

    r7dc2e57b re67991f  
    461461};
    462462
    463 class WithStmt : public Statement {
    464 public:
    465         std::list< Expression * > exprs;
    466         Statement * stmt;
    467 
    468         WithStmt( const std::list< Expression * > & exprs, Statement * stmt );
    469         WithStmt( const WithStmt & other );
    470         virtual ~WithStmt();
    471 
    472         virtual WithStmt * clone() const override { return new WithStmt( *this ); }
    473         virtual void accept( Visitor & v ) override { v.visit( this ); }
    474         virtual void accept( Visitor & v ) const override { v.visit( this ); }
    475         virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
    476         virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    477 };
     463// class WithStmt : public Statement {
     464// public:
     465//      std::list< Expression * > exprs;
     466//      Statement * stmt;
     467
     468//      WithStmt( const std::list< Expression * > & exprs, Statement * stmt );
     469//      WithStmt( const WithStmt & other );
     470//      virtual ~WithStmt();
     471
     472//      virtual WithStmt * clone() const override { return new WithStmt( *this ); }
     473//      virtual void accept( Visitor & v ) override { v.visit( this ); }
     474//      virtual void accept( Visitor & v ) const override { v.visit( this ); }
     475//      virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     476//      virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     477// };
    478478
    479479
Note: See TracChangeset for help on using the changeset viewer.