Changeset 89c2f7c9


Ignore:
Timestamp:
May 15, 2019, 4:13:44 PM (2 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
arm-eh, cleanup-dtors, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr
Children:
54e41b3, 8a5530c, e0d19f8
Parents:
3648d98 (diff), 1e97287 (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

Files:
11 edited

Legend:

Unmodified
Added
Removed
  • benchmark/tls-fetch_add.c

    r3648d98 r89c2f7c9  
    66#define thread_local _Thread_local
    77
    8 volatile thread_local bool value;
     8thread_local volatile bool value;
    99
    1010void __attribute__((noinline)) do_call() {
  • src/AST/Decl.hpp

    r3648d98 r89c2f7c9  
    5757        static readonly<Decl> fromId( UniqueId id );
    5858
    59         virtual const Decl * accept( Visitor & v ) const override = 0;
    60 private:
    61         virtual Decl * clone() const override = 0;
     59        const Decl * accept( Visitor & v ) const override = 0;
     60private:
     61        Decl * clone() const override = 0;
    6262};
    6363
     
    8787        virtual const Type * get_type() const = 0;
    8888        /// Set type of this declaration. May be verified by subclass
    89         virtual void set_type(Type*) = 0;
    90 
    91         virtual const DeclWithType * accept( Visitor & v ) const override = 0;
    92 private:
    93         virtual DeclWithType * clone() const override = 0;
     89        virtual void set_type(Type *) = 0;
     90
     91        const DeclWithType * accept( Visitor & v ) const override = 0;
     92private:
     93        DeclWithType * clone() const override = 0;
    9494};
    9595
     
    108108
    109109        const Type* get_type() const override { return type; }
    110         void set_type( Type* ty ) override { type = ty; }
    111 
    112         virtual const DeclWithType * accept( Visitor& v ) const override { return v.visit( this ); }
    113 private:
    114         virtual ObjectDecl * clone() const override { return new ObjectDecl{ *this }; }
     110        void set_type( Type * ty ) override { type = ty; }
     111
     112        const DeclWithType * accept( Visitor& v ) const override { return v.visit( this ); }
     113private:
     114        ObjectDecl * clone() const override { return new ObjectDecl{ *this }; }
     115
     116        /// Must be copied in ALL derived classes
     117        template<typename node_t>
     118        friend auto mutate(const node_t * node);
     119};
     120
     121class FunctionDecl : public DeclWithType {
     122public:
     123        ptr<FunctionType> type;
     124        ptr<CompoundStmt> stmts;
     125        std::list< ptr<Expr> > withExprs;
     126
     127        FunctionDecl( const CodeLocation & loc, const std::string &name, FunctionType * type,
     128                CompoundStmt * stmts, Storage::Classes storage = {}, Linkage::Spec linkage = Linkage::C,
     129                std::vector<ptr<Attribute>>&& attrs = {}, Function::Specs fs = {})
     130        : DeclWithType( loc, name, storage, linkage, std::move(attrs), fs ), type( type ),
     131          stmts( stmts ) {}
     132
     133        const Type * get_type() const override { return type.get(); }
     134        void set_type(Type * t) override { type = strict_dynamic_cast< FunctionType* >( t ); }
     135
     136        bool has_body() const { return stmts; }
     137
     138        const DeclWithType * accept( Visitor &v ) const override { return v.visit( this ); }
     139private:
     140        FunctionDecl * clone() const override { return new FunctionDecl( *this ); }
    115141
    116142        /// Must be copied in ALL derived classes
     
    173199        bool isComplete() { return sized; }
    174200
    175         virtual const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
    176 private:
    177         virtual TypeDecl * clone() const override { return new TypeDecl{ *this }; }
     201        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
     202private:
     203        TypeDecl * clone() const override { return new TypeDecl{ *this }; }
     204
     205        /// Must be copied in ALL derived classes
     206        template<typename node_t>
     207        friend auto mutate(const node_t * node);
    178208};
    179209
     
    187217        std::string typeString() const override { return "typedef"; }
    188218
    189         virtual const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
    190 private:
    191         virtual TypedefDecl * clone() const override { return new TypedefDecl{ *this }; }
     219        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
     220private:
     221        TypedefDecl * clone() const override { return new TypedefDecl{ *this }; }
     222
     223        /// Must be copied in ALL derived classes
     224        template<typename node_t>
     225        friend auto mutate(const node_t * node);
    192226};
    193227
     
    227261        bool is_thread() { return kind == DeclarationNode::Thread; }
    228262
    229         virtual const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
    230 private:
    231         virtual StructDecl * clone() const override { return new StructDecl{ *this }; }
     263        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
     264private:
     265        StructDecl * clone() const override { return new StructDecl{ *this }; }
     266
     267        /// Must be copied in ALL derived classes
     268        template<typename node_t>
     269        friend auto mutate(const node_t * node);
    232270
    233271        std::string typeString() const override { return "struct"; }
     
    241279        : AggregateDecl( loc, name, std::move(attrs), linkage ) {}
    242280
    243         virtual const Decl * accept( Visitor& v ) const override { return v.visit( this ); }
    244 private:
    245         virtual UnionDecl * clone() const override { return new UnionDecl{ *this }; }
     281        const Decl * accept( Visitor& v ) const override { return v.visit( this ); }
     282private:
     283        UnionDecl * clone() const override { return new UnionDecl{ *this }; }
     284
     285        /// Must be copied in ALL derived classes
     286        template<typename node_t>
     287        friend auto mutate(const node_t * node);
    246288
    247289        std::string typeString() const override { return "union"; }
     
    258300        bool valueOf( Decl* enumerator, long long& value ) const;
    259301
    260         virtual const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
    261 private:
    262         virtual EnumDecl * clone() const override { return new EnumDecl{ *this }; }
     302        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
     303private:
     304        EnumDecl * clone() const override { return new EnumDecl{ *this }; }
     305
     306        /// Must be copied in ALL derived classes
     307        template<typename node_t>
     308        friend auto mutate(const node_t * node);
    263309
    264310        std::string typeString() const override { return "enum"; }
     
    275321        : AggregateDecl( loc, name, std::move(attrs), linkage ) {}
    276322
    277         virtual const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
    278 private:
    279         virtual TraitDecl * clone() const override { return new TraitDecl{ *this }; }
     323        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
     324private:
     325        TraitDecl * clone() const override { return new TraitDecl{ *this }; }
     326
     327        /// Must be copied in ALL derived classes
     328        template<typename node_t>
     329        friend auto mutate(const node_t * node);
    280330
    281331        std::string typeString() const override { return "trait"; }
    282332};
    283333
     334class AsmDecl : public Decl {
     335public:
     336        ptr<AsmStmt> stmt;
     337
     338        AsmDecl( const CodeLocation & loc, AsmStmt *stmt )
     339        : Decl( loc, "", {}, {} ), stmt(stmt) {}
     340
     341        const AsmDecl * accept( Visitor &v ) const override { return v.visit( this ); }
     342private:
     343        AsmDecl *clone() const override { return new AsmDecl( *this ); }
     344
     345        /// Must be copied in ALL derived classes
     346        template<typename node_t>
     347        friend auto mutate(const node_t * node);
     348};
     349
     350class StaticAssertDecl : public Decl {
     351public:
     352        ptr<Expr> condition;
     353        ptr<ConstantExpr> msg;   // string literal
     354
     355        StaticAssertDecl( const CodeLocation & loc, const Expr * condition, const ConstantExpr * msg )
     356        : Decl( loc, "", {}, {} ), condition( condition ), msg( msg ) {}
     357
     358        const StaticAssertDecl * accept( Visitor &v ) const override { return v.visit( this ); }
     359private:
     360        StaticAssertDecl * clone() const override { return new StaticAssertDecl( *this ); }
     361
     362        /// Must be copied in ALL derived classes
     363        template<typename node_t>
     364        friend auto mutate(const node_t * node);
     365};
    284366
    285367//=================================================================================================
     
    294376inline void increment( const class ObjectDecl * node, Node::ref_type ref ) { node->increment(ref); }
    295377inline void decrement( const class ObjectDecl * node, Node::ref_type ref ) { node->decrement(ref); }
    296 // inline void increment( const class FunctionDecl * node, Node::ref_type ref ) { node->increment(ref); }
    297 // inline void decrement( const class FunctionDecl * node, Node::ref_type ref ) { node->decrement(ref); }
     378inline void increment( const class FunctionDecl * node, Node::ref_type ref ) { node->increment(ref); }
     379inline void decrement( const class FunctionDecl * node, Node::ref_type ref ) { node->decrement(ref); }
    298380inline void increment( const class AggregateDecl * node, Node::ref_type ref ) { node->increment(ref); }
    299381inline void decrement( const class AggregateDecl * node, Node::ref_type ref ) { node->decrement(ref); }
     
    310392inline void increment( const class TypeDecl * node, Node::ref_type ref ) { node->increment(ref); }
    311393inline void decrement( const class TypeDecl * node, Node::ref_type ref ) { node->decrement(ref); }
    312 // inline void increment( const class FtypeDecl * node, Node::ref_type ref ) { node->increment(ref); }
    313 // inline void decrement( const class FtypeDecl * node, Node::ref_type ref ) { node->decrement(ref); }
    314 // inline void increment( const class DtypeDecl * node, Node::ref_type ref ) { node->increment(ref); }
    315 // inline void decrement( const class DtypeDecl * node, Node::ref_type ref ) { node->decrement(ref); }
    316394inline void increment( const class TypedefDecl * node, Node::ref_type ref ) { node->increment(ref); }
    317395inline void decrement( const class TypedefDecl * node, Node::ref_type ref ) { node->decrement(ref); }
    318 // inline void increment( const class AsmDecl * node, Node::ref_type ref ) { node->increment(ref); }
    319 // inline void decrement( const class AsmDecl * node, Node::ref_type ref ) { node->decrement(ref); }
    320 // inline void increment( const class StaticAssertDecl * node, Node::ref_type ref ) { node->increment(ref); }
    321 // inline void decrement( const class StaticAssertDecl * node, Node::ref_type ref ) { node->decrement(ref); }
     396inline void increment( const class AsmDecl * node, Node::ref_type ref ) { node->increment(ref); }
     397inline void decrement( const class AsmDecl * node, Node::ref_type ref ) { node->decrement(ref); }
     398inline void increment( const class StaticAssertDecl * node, Node::ref_type ref ) { node->increment(ref); }
     399inline void decrement( const class StaticAssertDecl * node, Node::ref_type ref ) { node->decrement(ref); }
    322400
    323401}
  • src/AST/Expr.hpp

    r3648d98 r89c2f7c9  
    123123        virtual const Expr * accept( Visitor & v ) const override = 0;
    124124private:
    125         virtual Expr * clone() const override = 0;
     125        Expr * clone() const override = 0;
    126126};
    127127
  • src/AST/Fwd.hpp

    r3648d98 r89c2f7c9  
    3333class NamedTypeDecl;
    3434class TypeDecl;
    35 class FtypeDecl;
    36 class DtypeDecl;
    3735class TypedefDecl;
    3836class AsmDecl;
     
    170168inline void increment( const class TypeDecl *, Node::ref_type );
    171169inline void decrement( const class TypeDecl *, Node::ref_type );
    172 inline void increment( const class FtypeDecl *, Node::ref_type );
    173 inline void decrement( const class FtypeDecl *, Node::ref_type );
    174 inline void increment( const class DtypeDecl *, Node::ref_type );
    175 inline void decrement( const class DtypeDecl *, Node::ref_type );
    176170inline void increment( const class TypedefDecl *, Node::ref_type );
    177171inline void decrement( const class TypedefDecl *, Node::ref_type );
  • src/AST/Init.hpp

    r3648d98 r89c2f7c9  
    3737        : ParseNode( loc ), designators( std::move(ds) ) {}
    3838
    39         virtual const Designation* accept( Visitor& v ) const override { return v.visit( this ); }
     39        const Designation* accept( Visitor& v ) const override { return v.visit( this ); }
    4040private:
    41         virtual Designation* clone() const override { return new Designation{ *this }; }
     41        Designation* clone() const override { return new Designation{ *this }; }
    4242};
    4343
     
    5252        Init( const CodeLocation& loc, ConstructFlag mc ) : ParseNode( loc ), maybeConstructed( mc ) {}
    5353
    54         virtual const Init * accept( Visitor& v ) const override = 0;
     54        const Init * accept( Visitor& v ) const override = 0;
    5555private:
    56         virtual const Init * clone() const override = 0;
     56        const Init * clone() const override = 0;
    5757};
    5858
     
    6666        : Init( loc, mc ), value( val ) {}
    6767
    68         virtual const Init * accept( Visitor & v ) const override { return v.visit( this ); }
     68        const Init * accept( Visitor & v ) const override { return v.visit( this ); }
    6969private:
    70         virtual SingleInit * clone() const override { return new SingleInit{ *this }; }
     70        SingleInit * clone() const override { return new SingleInit{ *this }; }
    7171
    7272        /// Must be copied in ALL derived classes
     
    9494        const_iterator end() const { return initializers.end(); }
    9595
    96         virtual const Init * accept( Visitor & v ) const override { return v.visit( this ); }
     96        const Init * accept( Visitor & v ) const override { return v.visit( this ); }
    9797private:
    98         virtual ListInit * clone() const override { return new ListInit{ *this }; }
     98        ListInit * clone() const override { return new ListInit{ *this }; }
    9999
    100100        /// Must be copied in ALL derived classes
     
    117117        : Init( loc, DoConstruct ), ctor( ctor ), dtor( dtor ), init( init ) {}
    118118
    119         virtual const Init * accept( Visitor & v ) const override { return v.visit( this ); }
     119        const Init * accept( Visitor & v ) const override { return v.visit( this ); }
    120120private:
    121         virtual ConstructorInit * clone() const override { return new ConstructorInit{ *this }; }
     121        ConstructorInit * clone() const override { return new ConstructorInit{ *this }; }
    122122
    123123        /// Must be copied in ALL derived classes
  • src/AST/Node.hpp

    r3648d98 r89c2f7c9  
    99// Author           : Thierry Delisle
    1010// Created On       : Wed May 8 10:27:04 2019
    11 // Last Modified By : Aaron B. Moss
    12 // Last Modified On : Wed May 8 11:00:00 2019
    13 // Update Count     : 2
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed May 15 16:02:00 2019
     13// Update Count     : 3
    1414//
    1515
  • src/AST/Pass.hpp

    r3648d98 r89c2f7c9  
    8585
    8686        /// Visit function declarations
    87         virtual const ast::DeclWithType *     visit( const ast::ObjectDecl           * ) override final;
    88         virtual const ast::DeclWithType *     visit( const ast::FunctionDecl         * ) override final;
    89         virtual const ast::Decl *             visit( const ast::StructDecl           * ) override final;
    90         virtual const ast::Decl *             visit( const ast::UnionDecl            * ) override final;
    91         virtual const ast::Decl *             visit( const ast::EnumDecl             * ) override final;
    92         virtual const ast::Decl *             visit( const ast::TraitDecl            * ) override final;
    93         virtual const ast::Decl *             visit( const ast::TypeDecl             * ) override final;
    94         virtual const ast::Decl *             visit( const ast::TypedefDecl          * ) override final;
    95         virtual const ast::AsmDecl *          visit( const ast::AsmDecl              * ) override final;
    96         virtual const ast::StaticAssertDecl * visit( const ast::StaticAssertDecl     * ) override final;
    97         virtual const ast::CompoundStmt *     visit( const ast::CompoundStmt         * ) override final;
    98         virtual const ast::Stmt *             visit( const ast::ExprStmt             * ) override final;
    99         virtual const ast::Stmt *             visit( const ast::AsmStmt              * ) override final;
    100         virtual const ast::Stmt *             visit( const ast::DirectiveStmt        * ) override final;
    101         virtual const ast::Stmt *             visit( const ast::IfStmt               * ) override final;
    102         virtual const ast::Stmt *             visit( const ast::WhileStmt            * ) override final;
    103         virtual const ast::Stmt *             visit( const ast::ForStmt              * ) override final;
    104         virtual const ast::Stmt *             visit( const ast::SwitchStmt           * ) override final;
    105         virtual const ast::Stmt *             visit( const ast::CaseStmt             * ) override final;
    106         virtual const ast::Stmt *             visit( const ast::BranchStmt           * ) override final;
    107         virtual const ast::Stmt *             visit( const ast::ReturnStmt           * ) override final;
    108         virtual const ast::Stmt *             visit( const ast::ThrowStmt            * ) override final;
    109         virtual const ast::Stmt *             visit( const ast::TryStmt              * ) override final;
    110         virtual const ast::Stmt *             visit( const ast::CatchStmt            * ) override final;
    111         virtual const ast::Stmt *             visit( const ast::FinallyStmt          * ) override final;
    112         virtual const ast::Stmt *             visit( const ast::WaitForStmt          * ) override final;
    113         virtual const ast::Stmt *             visit( const ast::WithStmt             * ) override final;
    114         virtual const ast::NullStmt *         visit( const ast::NullStmt             * ) override final;
    115         virtual const ast::Stmt *             visit( const ast::DeclStmt             * ) override final;
    116         virtual const ast::Stmt *             visit( const ast::ImplicitCtorDtorStmt * ) override final;
    117         virtual const ast::Expr *             visit( const ast::ApplicationExpr      * ) override final;
    118         virtual const ast::Expr *             visit( const ast::UntypedExpr          * ) override final;
    119         virtual const ast::Expr *             visit( const ast::NameExpr             * ) override final;
    120         virtual const ast::Expr *             visit( const ast::AddressExpr          * ) override final;
    121         virtual const ast::Expr *             visit( const ast::LabelAddressExpr     * ) override final;
    122         virtual const ast::Expr *             visit( const ast::CastExpr             * ) override final;
    123         virtual const ast::Expr *             visit( const ast::KeywordCastExpr      * ) override final;
    124         virtual const ast::Expr *             visit( const ast::VirtualCastExpr      * ) override final;
    125         virtual const ast::Expr *             visit( const ast::UntypedMemberExpr    * ) override final;
    126         virtual const ast::Expr *             visit( const ast::MemberExpr           * ) override final;
    127         virtual const ast::Expr *             visit( const ast::VariableExpr         * ) override final;
    128         virtual const ast::Expr *             visit( const ast::ConstantExpr         * ) override final;
    129         virtual const ast::Expr *             visit( const ast::SizeofExpr           * ) override final;
    130         virtual const ast::Expr *             visit( const ast::AlignofExpr          * ) override final;
    131         virtual const ast::Expr *             visit( const ast::UntypedOffsetofExpr  * ) override final;
    132         virtual const ast::Expr *             visit( const ast::OffsetofExpr         * ) override final;
    133         virtual const ast::Expr *             visit( const ast::OffsetPackExpr       * ) override final;
    134         virtual const ast::Expr *             visit( const ast::AttrExpr             * ) override final;
    135         virtual const ast::Expr *             visit( const ast::LogicalExpr          * ) override final;
    136         virtual const ast::Expr *             visit( const ast::ConditionalExpr      * ) override final;
    137         virtual const ast::Expr *             visit( const ast::CommaExpr            * ) override final;
    138         virtual const ast::Expr *             visit( const ast::TypeExpr             * ) override final;
    139         virtual const ast::Expr *             visit( const ast::AsmExpr              * ) override final;
    140         virtual const ast::Expr *             visit( const ast::ImplicitCopyCtorExpr * ) override final;
    141         virtual const ast::Expr *             visit( const ast::ConstructorExpr      * ) override final;
    142         virtual const ast::Expr *             visit( const ast::CompoundLiteralExpr  * ) override final;
    143         virtual const ast::Expr *             visit( const ast::RangeExpr            * ) override final;
    144         virtual const ast::Expr *             visit( const ast::UntypedTupleExpr     * ) override final;
    145         virtual const ast::Expr *             visit( const ast::TupleExpr            * ) override final;
    146         virtual const ast::Expr *             visit( const ast::TupleIndexExpr       * ) override final;
    147         virtual const ast::Expr *             visit( const ast::TupleAssignExpr      * ) override final;
    148         virtual const ast::Expr *             visit( const ast::StmtExpr             * ) override final;
    149         virtual const ast::Expr *             visit( const ast::UniqueExpr           * ) override final;
    150         virtual const ast::Expr *             visit( const ast::UntypedInitExpr      * ) override final;
    151         virtual const ast::Expr *             visit( const ast::InitExpr             * ) override final;
    152         virtual const ast::Expr *             visit( const ast::DeletedExpr          * ) override final;
    153         virtual const ast::Expr *             visit( const ast::DefaultArgExpr       * ) override final;
    154         virtual const ast::Expr *             visit( const ast::GenericExpr          * ) override final;
    155         virtual const ast::Type *             visit( const ast::VoidType             * ) override final;
    156         virtual const ast::Type *             visit( const ast::BasicType            * ) override final;
    157         virtual const ast::Type *             visit( const ast::PointerType          * ) override final;
    158         virtual const ast::Type *             visit( const ast::ArrayType            * ) override final;
    159         virtual const ast::Type *             visit( const ast::ReferenceType        * ) override final;
    160         virtual const ast::Type *             visit( const ast::QualifiedType        * ) override final;
    161         virtual const ast::Type *             visit( const ast::FunctionType         * ) override final;
    162         virtual const ast::Type *             visit( const ast::StructInstType       * ) override final;
    163         virtual const ast::Type *             visit( const ast::UnionInstType        * ) override final;
    164         virtual const ast::Type *             visit( const ast::EnumInstType         * ) override final;
    165         virtual const ast::Type *             visit( const ast::TraitInstType        * ) override final;
    166         virtual const ast::Type *             visit( const ast::TypeInstType         * ) override final;
    167         virtual const ast::Type *             visit( const ast::TupleType            * ) override final;
    168         virtual const ast::Type *             visit( const ast::TypeofType           * ) override final;
    169         virtual const ast::Type *             visit( const ast::VarArgsType          * ) override final;
    170         virtual const ast::Type *             visit( const ast::ZeroType             * ) override final;
    171         virtual const ast::Type *             visit( const ast::OneType              * ) override final;
    172         virtual const ast::Type *             visit( const ast::GlobalScopeType      * ) override final;
    173         virtual const ast::Designation *      visit( const ast::Designation          * ) override final;
    174         virtual const ast::Init *             visit( const ast::SingleInit           * ) override final;
    175         virtual const ast::Init *             visit( const ast::ListInit             * ) override final;
    176         virtual const ast::Init *             visit( const ast::ConstructorInit      * ) override final;
    177         virtual const ast::Constant *         visit( const ast::Constant             * ) override final;
    178         virtual const ast::Attribute *        visit( const ast::Attribute            * ) override final;
    179         virtual const ast::TypeSubstitution * visit( const ast::TypeSubstitution     * ) override final;
     87        const ast::DeclWithType *     visit( const ast::ObjectDecl           * ) override final;
     88        const ast::DeclWithType *     visit( const ast::FunctionDecl         * ) override final;
     89        const ast::Decl *             visit( const ast::StructDecl           * ) override final;
     90        const ast::Decl *             visit( const ast::UnionDecl            * ) override final;
     91        const ast::Decl *             visit( const ast::EnumDecl             * ) override final;
     92        const ast::Decl *             visit( const ast::TraitDecl            * ) override final;
     93        const ast::Decl *             visit( const ast::TypeDecl             * ) override final;
     94        const ast::Decl *             visit( const ast::TypedefDecl          * ) override final;
     95        const ast::AsmDecl *          visit( const ast::AsmDecl              * ) override final;
     96        const ast::StaticAssertDecl * visit( const ast::StaticAssertDecl     * ) override final;
     97        const ast::CompoundStmt *     visit( const ast::CompoundStmt         * ) override final;
     98        const ast::Stmt *             visit( const ast::ExprStmt             * ) override final;
     99        const ast::Stmt *             visit( const ast::AsmStmt              * ) override final;
     100        const ast::Stmt *             visit( const ast::DirectiveStmt        * ) override final;
     101        const ast::Stmt *             visit( const ast::IfStmt               * ) override final;
     102        const ast::Stmt *             visit( const ast::WhileStmt            * ) override final;
     103        const ast::Stmt *             visit( const ast::ForStmt              * ) override final;
     104        const ast::Stmt *             visit( const ast::SwitchStmt           * ) override final;
     105        const ast::Stmt *             visit( const ast::CaseStmt             * ) override final;
     106        const ast::Stmt *             visit( const ast::BranchStmt           * ) override final;
     107        const ast::Stmt *             visit( const ast::ReturnStmt           * ) override final;
     108        const ast::Stmt *             visit( const ast::ThrowStmt            * ) override final;
     109        const ast::Stmt *             visit( const ast::TryStmt              * ) override final;
     110        const ast::Stmt *             visit( const ast::CatchStmt            * ) override final;
     111        const ast::Stmt *             visit( const ast::FinallyStmt          * ) override final;
     112        const ast::Stmt *             visit( const ast::WaitForStmt          * ) override final;
     113        const ast::Stmt *             visit( const ast::WithStmt             * ) override final;
     114        const ast::NullStmt *         visit( const ast::NullStmt             * ) override final;
     115        const ast::Stmt *             visit( const ast::DeclStmt             * ) override final;
     116        const ast::Stmt *             visit( const ast::ImplicitCtorDtorStmt * ) override final;
     117        const ast::Expr *             visit( const ast::ApplicationExpr      * ) override final;
     118        const ast::Expr *             visit( const ast::UntypedExpr          * ) override final;
     119        const ast::Expr *             visit( const ast::NameExpr             * ) override final;
     120        const ast::Expr *             visit( const ast::AddressExpr          * ) override final;
     121        const ast::Expr *             visit( const ast::LabelAddressExpr     * ) override final;
     122        const ast::Expr *             visit( const ast::CastExpr             * ) override final;
     123        const ast::Expr *             visit( const ast::KeywordCastExpr      * ) override final;
     124        const ast::Expr *             visit( const ast::VirtualCastExpr      * ) override final;
     125        const ast::Expr *             visit( const ast::UntypedMemberExpr    * ) override final;
     126        const ast::Expr *             visit( const ast::MemberExpr           * ) override final;
     127        const ast::Expr *             visit( const ast::VariableExpr         * ) override final;
     128        const ast::Expr *             visit( const ast::ConstantExpr         * ) override final;
     129        const ast::Expr *             visit( const ast::SizeofExpr           * ) override final;
     130        const ast::Expr *             visit( const ast::AlignofExpr          * ) override final;
     131        const ast::Expr *             visit( const ast::UntypedOffsetofExpr  * ) override final;
     132        const ast::Expr *             visit( const ast::OffsetofExpr         * ) override final;
     133        const ast::Expr *             visit( const ast::OffsetPackExpr       * ) override final;
     134        const ast::Expr *             visit( const ast::AttrExpr             * ) override final;
     135        const ast::Expr *             visit( const ast::LogicalExpr          * ) override final;
     136        const ast::Expr *             visit( const ast::ConditionalExpr      * ) override final;
     137        const ast::Expr *             visit( const ast::CommaExpr            * ) override final;
     138        const ast::Expr *             visit( const ast::TypeExpr             * ) override final;
     139        const ast::Expr *             visit( const ast::AsmExpr              * ) override final;
     140        const ast::Expr *             visit( const ast::ImplicitCopyCtorExpr * ) override final;
     141        const ast::Expr *             visit( const ast::ConstructorExpr      * ) override final;
     142        const ast::Expr *             visit( const ast::CompoundLiteralExpr  * ) override final;
     143        const ast::Expr *             visit( const ast::RangeExpr            * ) override final;
     144        const ast::Expr *             visit( const ast::UntypedTupleExpr     * ) override final;
     145        const ast::Expr *             visit( const ast::TupleExpr            * ) override final;
     146        const ast::Expr *             visit( const ast::TupleIndexExpr       * ) override final;
     147        const ast::Expr *             visit( const ast::TupleAssignExpr      * ) override final;
     148        const ast::Expr *             visit( const ast::StmtExpr             * ) override final;
     149        const ast::Expr *             visit( const ast::UniqueExpr           * ) override final;
     150        const ast::Expr *             visit( const ast::UntypedInitExpr      * ) override final;
     151        const ast::Expr *             visit( const ast::InitExpr             * ) override final;
     152        const ast::Expr *             visit( const ast::DeletedExpr          * ) override final;
     153        const ast::Expr *             visit( const ast::DefaultArgExpr       * ) override final;
     154        const ast::Expr *             visit( const ast::GenericExpr          * ) override final;
     155        const ast::Type *             visit( const ast::VoidType             * ) override final;
     156        const ast::Type *             visit( const ast::BasicType            * ) override final;
     157        const ast::Type *             visit( const ast::PointerType          * ) override final;
     158        const ast::Type *             visit( const ast::ArrayType            * ) override final;
     159        const ast::Type *             visit( const ast::ReferenceType        * ) override final;
     160        const ast::Type *             visit( const ast::QualifiedType        * ) override final;
     161        const ast::Type *             visit( const ast::FunctionType         * ) override final;
     162        const ast::Type *             visit( const ast::StructInstType       * ) override final;
     163        const ast::Type *             visit( const ast::UnionInstType        * ) override final;
     164        const ast::Type *             visit( const ast::EnumInstType         * ) override final;
     165        const ast::Type *             visit( const ast::TraitInstType        * ) override final;
     166        const ast::Type *             visit( const ast::TypeInstType         * ) override final;
     167        const ast::Type *             visit( const ast::TupleType            * ) override final;
     168        const ast::Type *             visit( const ast::TypeofType           * ) override final;
     169        const ast::Type *             visit( const ast::VarArgsType          * ) override final;
     170        const ast::Type *             visit( const ast::ZeroType             * ) override final;
     171        const ast::Type *             visit( const ast::OneType              * ) override final;
     172        const ast::Type *             visit( const ast::GlobalScopeType      * ) override final;
     173        const ast::Designation *      visit( const ast::Designation          * ) override final;
     174        const ast::Init *             visit( const ast::SingleInit           * ) override final;
     175        const ast::Init *             visit( const ast::ListInit             * ) override final;
     176        const ast::Init *             visit( const ast::ConstructorInit      * ) override final;
     177        const ast::Constant *         visit( const ast::Constant             * ) override final;
     178        const ast::Attribute *        visit( const ast::Attribute            * ) override final;
     179        const ast::TypeSubstitution * visit( const ast::TypeSubstitution     * ) override final;
    180180
    181181        friend void acceptAll( std::list< ptr<Decl> > & decls, Pass<pass_t>& visitor );
     
    215215                Pass<pass_t> & pass;
    216216        };
     217
     218private:
     219        bool inFunction = false;
    217220};
    218221
  • src/AST/Pass.impl.hpp

    r3648d98 r89c2f7c9  
    158158                // These may be modified by subnode but most be restored once we exit this statemnet.
    159159                ValueGuardPtr< const ast::TypeSubstitution * > __old_env         ( __pass::env( pass, 0) );
    160                 ValueGuardPtr< typename std::remove_pointer< decltype(stmts_before) > > __old_decls_before( stmts_before );
    161                 ValueGuardPtr< typename std::remove_pointer< decltype(stmts_after ) > > __old_decls_after ( stmts_after  );
    162                 ValueGuardPtr< typename std::remove_pointer< decltype(decls_before) > > __old_stmts_before( decls_before );
    163                 ValueGuardPtr< typename std::remove_pointer< decltype(decls_after ) > > __old_stmts_after ( decls_after  );
     160                ValueGuardPtr< typename std::remove_pointer< decltype(stmts_before) >::type > __old_decls_before( stmts_before );
     161                ValueGuardPtr< typename std::remove_pointer< decltype(stmts_after ) >::type > __old_decls_after ( stmts_after  );
     162                ValueGuardPtr< typename std::remove_pointer< decltype(decls_before) >::type > __old_stmts_before( decls_before );
     163                ValueGuardPtr< typename std::remove_pointer< decltype(decls_after ) >::type > __old_stmts_after ( decls_after  );
    164164
    165165                // Now is the time to actually visit the node
     
    212212
    213213                // These may be modified by subnode but most be restored once we exit this statemnet.
    214                 ValueGuardPtr< typename std::remove_pointer< decltype(stmts_before) > > __old_decls_before( stmts_before );
    215                 ValueGuardPtr< typename std::remove_pointer< decltype(stmts_after ) > > __old_decls_after ( stmts_after  );
    216                 ValueGuardPtr< typename std::remove_pointer< decltype(decls_before) > > __old_stmts_before( decls_before );
    217                 ValueGuardPtr< typename std::remove_pointer< decltype(decls_after ) > > __old_stmts_after ( decls_after  );
     214                ValueGuardPtr< typename std::remove_pointer< decltype(stmts_before) >::type > __old_decls_before( stmts_before );
     215                ValueGuardPtr< typename std::remove_pointer< decltype(stmts_after ) >::type > __old_decls_after ( stmts_after  );
     216                ValueGuardPtr< typename std::remove_pointer< decltype(decls_before) >::type > __old_stmts_before( decls_before );
     217                ValueGuardPtr< typename std::remove_pointer< decltype(decls_after ) >::type > __old_stmts_after ( decls_after  );
    218218
    219219                // update pass statitistics
     
    390390                {
    391391                        guard_indexer guard { *this };
    392                         maybe_accept( node, &ast::ObjectDecl::type );
    393                 }
    394                 maybe_accept( node, &ast::ObjectDecl::init          );
    395                 maybe_accept( node, &ast::ObjectDecl::bitfieldWidth );
    396                 maybe_accept( node, &ast::ObjectDecl::attributes    );
     392                        maybe_accept( node, &ObjectDecl::type );
     393                }
     394                maybe_accept( node, &ObjectDecl::init          );
     395                maybe_accept( node, &ObjectDecl::bitfieldWidth );
     396                maybe_accept( node, &ObjectDecl::attributes    );
    397397        )
    398398
     
    401401        VISIT_END( DeclWithType, node );
    402402}
     403
     404//--------------------------------------------------------------------------
     405// FunctionDecl
     406template< typename pass_t >
     407const ast::DeclWithType * ast::Pass< pass_t >::visit( const ast::FunctionDecl * node ) {
     408        VISIT_START( node );
     409
     410        __pass::indexer::addId( pass, 0, node );
     411
     412        VISIT(maybe_accept( node, &FunctionDecl::withExprs );)
     413        {
     414                // with clause introduces a level of scope (for the with expression members).
     415                // with clause exprs are added to the indexer before parameters so that parameters
     416                // shadow with exprs and not the other way around.
     417                guard_indexer guard { *this };
     418                __pass::indexer::addWith( pass, 0, node->withExprs, node );
     419                {
     420                        guard_indexer guard { *this };
     421                        // implicit add __func__ identifier as specified in the C manual 6.4.2.2
     422                        static ast::ObjectDecl func(
     423                                node->location, "__func__",
     424                                new ast::ArrayType(
     425                                        new ast::BasicType( ast::BasicType::Char, ast::CV::Qualifiers( ast::CV::Const ) ),
     426                                        nullptr, true, false
     427                                )
     428                        );
     429                        __pass::indexer::addId( pass, 0, &func );
     430                        VISIT(
     431                                maybe_accept( node, &FunctionDecl::type );
     432                                // function body needs to have the same scope as parameters - CompoundStmt will not enter
     433                                // a new scope if inFunction is true
     434                                ValueGuard< bool > oldInFunction( inFunction );
     435                                inFunction = true;
     436                                maybe_accept( node, &FunctionDecl::statements );
     437                                maybe_accept( node, &FunctionDecl::attributes );
     438                        )
     439                }
     440        }
     441
     442        VISIT_END( DeclWithType, node );
     443}
     444
     445//--------------------------------------------------------------------------
     446// StructDecl
     447template< typename pass_t >
     448const ast::Decl * ast::Pass< pass_t >::visit( const ast::StructDecl * node ) {
     449        VISIT_START( node );
     450
     451        // make up a forward declaration and add it before processing the members
     452        // needs to be on the heap because addStruct saves the pointer
     453        __pass::indexer::addStructFwd( pass, 0, node );
     454
     455        VISIT({
     456                guard_indexer guard { * this };
     457                maybe_accept( node, &StructDecl::parameters );
     458                maybe_accept( node, &StructDecl::members    );
     459        })
     460
     461        // this addition replaces the forward declaration
     462        __pass::indexer::addStruct( pass, 0, node );
     463
     464        VISIT_END( Decl, node );
     465}
     466
     467//--------------------------------------------------------------------------
     468// UnionDecl
     469template< typename pass_t >
     470const ast::Decl * ast::Pass< pass_t >::visit( const ast::UnionDecl * node ) {
     471        VISIT_START( node );
     472
     473        // make up a forward declaration and add it before processing the members
     474        __pass::indexer::addUnionFwd( pass, 0, node );
     475
     476        VISIT({
     477                guard_indexer guard { * this };
     478                maybe_accept( node, &UnionDecl::parameters );
     479                maybe_accept( node, &UnionDecl::members    );
     480        })
     481
     482        __pass::indexer::addUnion( pass, 0, node );
     483
     484        VISIT_END( Decl, node );
     485}
     486
     487//--------------------------------------------------------------------------
     488// EnumDecl
     489template< typename pass_t >
     490const ast::Decl * ast::Pass< pass_t >::visit( const ast::EnumDecl * node ) {
     491        VISIT_START( node );
     492
     493        __pass::indexer::addEnum( pass, 0, node );
     494
     495        VISIT(
     496                // unlike structs, traits, and unions, enums inject their members into the global scope
     497                maybe_accept( node, &EnumDecl::parameters );
     498                maybe_accept( node, &EnumDecl::members    );
     499        )
     500
     501        VISIT_END( Decl, node );
     502}
     503
     504//--------------------------------------------------------------------------
     505// TraitDecl
     506template< typename pass_t >
     507const ast::Decl * ast::Pass< pass_t >::visit( const ast::TraitDecl * node ) {
     508        VISIT_START( node );
     509
     510        VISIT({
     511                guard_indexer guard { *this };
     512                maybe_accept( node, &TraitDecl::parameters );
     513                maybe_accept( node, &TraitDecl::members    );
     514        })
     515
     516        __pass::indexer::addTrait( pass, 0, node );
     517
     518        VISIT_END( Decl, node );
     519}
     520
     521//--------------------------------------------------------------------------
     522// TypeDecl
     523template< typename pass_t >
     524const ast::Decl * ast::Pass< pass_t >::visit( const ast::TypeDecl * node ) {
     525        VISIT_START( node );
     526
     527        VISIT({
     528                guard_indexer guard { *this };
     529                maybe_accept( node, &TypeDecl::parameters );
     530                maybe_accept( node, &TypeDecl::base       );
     531        })
     532
     533        // see A NOTE ON THE ORDER OF TRAVERSAL, above
     534        // note that assertions come after the type is added to the symtab, since they are not part of the type proper
     535        // and may depend on the type itself
     536        __pass::indexer::addType( pass, 0, node );
     537
     538        VISIT(
     539                maybe_accept( node, &TypeDecl::assertions, *this );
     540
     541                {
     542                        guard_indexer guard { *this };
     543                        maybe_accept( node, &TypeDecl::init );
     544                }
     545        )
     546
     547        VISIT_END( Decl, node );
     548}
     549
     550//--------------------------------------------------------------------------
     551// TypedefDecl
     552template< typename pass_t >
     553const ast::Decl * ast::Pass< pass_t >::visit( const ast::TypedefDecl * node ) {
     554        VISIT_START( node );
     555
     556        VISIT({
     557                guard_indexer guard { *this };
     558                maybe_accept( node, &TypedefDecl::parameters );
     559                maybe_accept( node, &TypedefDecl::base       );
     560        })
     561
     562        __pass::indexer::addType( pass, 0, node );
     563
     564        maybe_accept( node, &TypedefDecl::assertions );
     565
     566        VISIT_END( Decl, node );
     567}
     568
     569//--------------------------------------------------------------------------
     570// AsmDecl
     571template< typename pass_t >
     572const ast::AsmDecl * ast::Pass< pass_t >::visit( const ast::AsmDecl * node ) {
     573        VISIT_START( node );
     574
     575        VISIT(
     576                maybe_accept( node, &AsmDecl::stmt );
     577        )
     578
     579        VISIT_END( AsmDecl, node );
     580}
     581
     582//--------------------------------------------------------------------------
     583// StaticAssertDecl
     584template< typename pass_t >
     585const ast::StaticAssertDecl * ast::Pass< pass_t >::visit( const ast::StaticAssertDecl * node ) {
     586        VISIT_START( node );
     587
     588        VISIT(
     589                maybe_accept( node, &StaticAssertDecl::condition );
     590                maybe_accept( node, &StaticAssertDecl::msg       );
     591        )
     592
     593        VISIT_END( StaticAssertDecl, node );
     594}
     595
     596//--------------------------------------------------------------------------
     597// CompoundStmt
     598template< typename pass_t >
     599const ast::CompoundStmt * ast::Pass< pass_t >::visit( const ast::CompoundStmt * node ) {
     600        VISIT_START( node );
     601        VISIT({
     602                // do not enter a new scope if inFunction is true - needs to check old state before the assignment
     603                auto guard1 = makeFuncGuard( [this, inFunction = this->inFunction]() {
     604                        if ( ! inFunction ) __pass::indexer::enter(pass, 0);
     605                }, [this, inFunction = this->inFunction]() {
     606                        if ( ! inFunction ) __pass::indexer::leave(pass, 0);
     607                });
     608                ValueGuard< bool > guard2( inFunction );
     609                guard_scope guard3 { *this };
     610                inFunction = false;
     611                maybe_accept( node, &CompoundStmt::kids );
     612        })
     613        VISIT_END( CompoundStmt, node );
     614}
     615
    403616
    404617//--------------------------------------------------------------------------
  • src/AST/Stmt.cpp

    r3648d98 r89c2f7c9  
    88//
    99// Author           : Aaron B. Moss
    10 // Created On       : Wed May 8 13:00:00 2019
    11 // Last Modified By : Aaron B. Moss
    12 // Last Modified On : Wed May 8 13:00:00 2019
    13 // Update Count     : 1
     10// Created On       : Wed May  8 13:00:00 2019
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed May 15 15:53:00 2019
     13// Update Count     : 2
    1414//
    1515
     
    1818#include "DeclReplacer.hpp"
    1919
     20namespace ast {
     21
    2022// --- CompoundStmt
     23CompoundStmt::CompoundStmt( const CompoundStmt& o ) : Stmt(o), kids(o.kids) {
     24        assert(!"implemented");
     25}
    2126
    22 namespace ast {
    23         CompoundStmt::CompoundStmt( const CompoundStmt& o ) : Stmt(o), kids(o.kids) {
    24                 assert(!"implemented");
    25         }
     27// --- BranchStmt
     28BranchStmt( const CodeLocation& loc, Kind kind, Label target, std::vector<Label>&& labels )
     29: Stmt(loc, std::move(labels)), originalTarget(target), target(target), kind(kind) {
     30        // Make sure a syntax error hasn't slipped through.
     31        assert( Goto != kind || !target.empty() );
     32}
     33
     34const char * BranchStmt::kindNames[] = {
     35    "Goto", "Break", "Continue", "FallThrough", "FallThroughDefault"
     36}
     37
    2638}
    2739
  • src/AST/Stmt.hpp

    r3648d98 r89c2f7c9  
    88//
    99// Author           : Aaron B. Moss
    10 // Created On       : Wed May 8 13:00:00 2019
    11 // Last Modified By : Aaron B. Moss
    12 // Last Modified On : Wed May 8 13:00:00 2019
    13 // Update Count     : 1
     10// Created On       : Wed May  8 13:00:00 2019
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed May 15 16:01:00 2019
     13// Update Count     : 2
    1414//
    1515
     
    4040        Stmt(const Stmt& o) : ParseNode(o), labels(o.labels) {}
    4141
    42         virtual const Stmt* accept( Visitor& v ) const override = 0;
    43 private:
    44         virtual Stmt* clone() const override = 0;
     42        const Stmt* accept( Visitor& v ) const override = 0;
     43private:
     44        Stmt* clone() const override = 0;
    4545};
    4646
     
    5959        void push_front( Stmt* s ) { kids.emplace_front( s ); }
    6060
    61         virtual const CompoundStmt* accept( Visitor& v ) const override { return v.visit( this ); }
    62 private:
    63         virtual CompoundStmt* clone() const override { return new CompoundStmt{ *this }; }
     61        const CompoundStmt* accept( Visitor& v ) const override { return v.visit( this ); }
     62private:
     63        CompoundStmt* clone() const override { return new CompoundStmt{ *this }; }
    6464};
    6565
     
    7070        : Stmt(loc, std::move(labels)) {}
    7171
    72         virtual const NullStmt * accept( Visitor& v ) const override { return v.visit( this ); }
    73 private:
    74         virtual NullStmt * clone() const override { return new NullStmt{ *this }; }
     72        const NullStmt* accept( Visitor& v ) const override { return v.visit( this ); }
     73private:
     74        NullStmt* clone() const override { return new NullStmt{ *this }; }
    7575};
    7676
     
    8080        ptr<Expr> expr;
    8181
    82         ExprStmt( const CodeLocation& loc, Expr* e ) : Stmt(loc), expr(e) {}
    83 
    84         virtual const Stmt * accept( Visitor& v ) const override { return v.visit( this ); }
    85 private:
    86         virtual ExprStmt * clone() const override { return new ExprStmt{ *this }; }
    87 };
    88 
    89 
     82        ExprStmt( const CodeLocation& loc, const Expr* e ) : Stmt(loc), expr(e) {}
     83
     84        const Stmt * accept( Visitor& v ) const override { return v.visit( this ); }
     85private:
     86        ExprStmt * clone() const override { return new ExprStmt{ *this }; }
     87};
     88
     89class AsmStmt final : public Stmt {
     90public:
     91        bool isVolatile;
     92        ptr<Expr> instruction;
     93        std::vector<ptr<Expr>> output, input;
     94        std::vector<ptr<ConstantExpr>> clobber;
     95        std::vector<Label> gotoLabels;
     96
     97        AsmStmt( const CodeLocation& loc, bool isVolatile, const Expr * instruction,
     98                std::vector<ptr<Expr>>&& output, std::vector<ptr<Expr>>&& input,
     99                std::vector<ptr<ConstantExpr>>&& clobber, std::vector<Label>&& gotoLabels,
     100                std::vector<Label>&& labels = {})
     101        : Stmt(loc, std::move(labels)), isVolatile(isVolatile), instruction(instruction),
     102          output(std::move(output)), input(std::move(input)), clobber(std::move(clobber)),
     103          gotoLabels(std::move(gotoLabels)) {}
     104
     105        const Stmt* accept( Visitor& v ) const override { return v.visit( this ); }
     106private:
     107        AsmStmt* clone() const override { return new AsmStmt{ *this }; }
     108};
     109
     110class DirectiveStmt final : public Stmt {
     111public:
     112        std::string directive;
     113
     114        DirectiveStmt( const CodeLocation& loc, const std::string & directive,
     115                std::vector<Label>&& labels = {} )
     116        : Stmt(loc, std::move(labels)), directive(directive) {}
     117
     118        const Stmt* accept( Visitor& v ) const override { return v.visit( this ); }
     119private:
     120        DirectiveStmt* clone() const override { return new DirectiveStmt{ *this }; }
     121};
     122
     123class IfStmt final : public Stmt {
     124public:
     125        ptr<Expr> cond;
     126        ptr<Stmt> thenPart;
     127        ptr<Stmt> elsePart;
     128        std::vector<ptr<Stmt>> inits;
     129
     130        IfStmt( const CodeLocation& loc, const Expr* cond, const Stmt* thenPart,
     131                Stmt * const elsePart, std::vector<ptr<Stmt>>&& inits,
     132                std::vector<Label>&& labels = {} )
     133        : Stmt(loc, std::move(labels)), cond(cond), thenPart(thenPart), elsePart(elsePart),
     134          inits(std::move(inits)) {}
     135
     136        const Stmt* accept( Visitor& v ) const override { return v.visit( this ); }
     137private:
     138        IfStmt* clone() const override { return new IfStmt{ *this }; }
     139};
     140
     141class SwitchStmt final : public Stmt {
     142public:
     143        ptr<Expr> cond;
     144        std::vector<ptr<Stmt>> stmts;
     145
     146        SwitchStmt( const CodeLocation& loc, const Expr* cond, std::vector<ptr<Stmt>>&& stmts,
     147                std::vector<Label>&& labels = {} )
     148        : Stmt(loc, std::move(labels)), cond(cond), stmts(std::move(stmts)) {}
     149
     150        const Stmt* accept( Visitor& v ) const override { return v.visit( this ); }
     151private:
     152        SwitchStmt* clone() const override { return new SwitchStmt{ *this }; }
     153};
     154
     155class CaseStmt final : public Stmt {
     156public:
     157        ptr<Expr> cond;
     158        std::vector<ptr<Stmt>> stmts;
     159
     160    CaseStmt( const CodeLocation& loc, const Expr* cond, std::vector<ptr<Stmt>>&& stmts,
     161        std::vector<Label>&& labels = {} )
     162    : Stmt(loc, std::move(labels)), cond(cond), stmts(std::move(stmts)) {}
     163
     164        bool isDefault() { return !cond; }
     165
     166        const Stmt* accept( Visitor& v ) const override { return v.visit( this ); }
     167private:
     168        CaseStmt* clone() const override { return new CaseStmt{ *this }; }
     169};
     170
     171class WhileStmt final : public Stmt {
     172public:
     173        ptr<Expr> cond;
     174        ptr<Stmt> body;
     175        std::vector<ptr<Stmt>> inits;
     176        bool isDoWhile;
     177
     178        WhileStmt( const CodeLocation& loc, const Expr* cond, const Stmt* body,
     179                std::vector<ptr<Stmt>>&& inits, bool isDoWhile = false, std::vector<Label>&& labels = {} )
     180        : Stmt(loc, std::move(labels)), cond(cond), body(body), inits(std::move(inits)),
     181          isDoWhile(isDoWhile) {}
     182
     183        const Stmt* accept( Visitor& v ) const override { return v.visit( this ); }
     184private:
     185        WhileStmt* clone() const override { return new WhileStmt{ *this }; }
     186};
     187
     188class ForStmt final : public Stmt {
     189public:
     190        std::vector<ptr<Stmt>> inits;
     191        ptr<Expr> cond;
     192        ptr<Expr> increment;
     193        ptr<Stmt> body;
     194
     195        ForStmt( const CodeLocation& loc, std::vector<ptr<Stmt>>&& inits, const Expr* cond,
     196                const Expr* increment, const Stmt* body, std::vector<Label>&& labels = {} )
     197        : Stmt(loc, std::move(labels)), inits(std::move(inits)), cond(cond), increment(increment),
     198          body(body) {}
     199
     200        const Stmt* accept( Visitor& v ) const override { return v.visit( this ); }
     201private:
     202        ForStmt* clone() const override { return new ForStmt{ *this }; }
     203};
     204
     205class BranchStmt final : public Stmt {
     206public:
     207        enum Kind { Goto, Break, Continue, FallThrough, FallThroughDefault };
     208        static constexpr size_t kindEnd = 1 + (size_t)FallThroughDefault;
     209
     210        const Label originalTarget;
     211        Label target;
     212        ptr<Expr> computedTarget;
     213        Kind kind;
     214
     215        BranchStmt( const CodeLocation& loc, Kind kind, Label target,
     216                std::vector<Label>&& labels = {} );
     217        BranchStmt( const CodeLocation& loc, const Expr* computedTarget,
     218                std::vector<Label>&& labels = {} )
     219        : Stmt(loc, std::move(labels)), originalTarget(loc), target(loc),
     220          computedTarget(computedTarget), kind(Goto) {}
     221
     222        const char * kindName() { return kindNames[kind]; }
     223
     224        const Stmt* accept( Visitor& v ) const override { return v.visit( this ); }
     225private:
     226        BranchStmt* clone() const override { return new BranchStmt{ *this }; }
     227        static const char * kindNames[kindEnd];
     228};
     229
     230class ReturnStmt final : public Stmt {
     231public:
     232        ptr<Expr> expr;
     233
     234        ReturnStmt( const CodeLocation& loc, const Expr* expr, std::vector<Label>&& labels = {} )
     235        : Stmt(loc, std::move(labels)), expr(expr) {}
     236
     237        const Stmt* accept( Visitor& v ) const override { return v.visit( this ); }
     238private:
     239        ReturnStmt* clone() const override { return new ReturnStmt{ *this }; }
     240};
     241
     242class ThrowStmt final : public Stmt {
     243public:
     244        enum Kind { Terminate, Resume };
     245
     246        ptr<Expr> expr;
     247        ptr<Expr> target;
     248        Kind kind;
     249
     250        ThrowStmt( const CodeLocation& loc, Kind kind, const Expr* expr, const Expr* target,
     251                std::vector<Label>&& labels = {} )
     252        : Stmt(loc, std::move(labels)), expr(expr), target(target), kind(kind) {}
     253
     254        const Stmt* accept( Visitor& v ) const override { return v.visit( this ); }
     255private:
     256        ThrowStmt* clone() const override { return new ThrowStmt{ *this }; }
     257};
     258
     259class TryStmt final : public Stmt {
     260public:
     261        ptr<CompoundStmt> body;
     262        std::vector<ptr<CatchStmt>> handlers;
     263        ptr<FinallyStmt> finally;
     264
     265        TryStmt( const CodeLocation& loc, const CompoundStmt* body,
     266                std::vector<ptr<CatchStmt>>&& handlers, const FinallyStmt* finally,
     267                std::vector<Label>&& labels = {} )
     268        : Stmt(loc, std::move(labels)), body(body), handlers(std::move(handlers)), finally(finally) {}
     269
     270        const Stmt* accept( Visitor& v ) const override { return v.visit( this ); }
     271private:
     272        TryStmt* clone() const override { return new TryStmt{ *this }; }
     273};
     274
     275class CatchStmt final : public Stmt {
     276public:
     277        enum Kind { Terminate, Resume };
     278
     279        ptr<Decl> decl;
     280        ptr<Expr> cond;
     281        ptr<Stmt> body;
     282        Kind kind;
     283
     284        CatchStmt( const CodeLocation& loc, Kind kind, const Decl* decl, const Expr* cond,
     285                const Stmt* body, std::vector<Label>&& labels = {} )
     286        : Stmt(loc, std::move(labels)), decl(decl), cond(cond), body(body), kind(kind) {}
     287
     288        const Stmt* accept( Visitor& v ) const override { return v.visit( this ); }
     289private:
     290        CatchStmt* clone() const override { return new CatchStmt{ *this }; }
     291};
     292
     293class FinallyStmt final : public Stmt {
     294public:
     295        ptr<CompoundStmt> body;
     296
     297        FinallyStmt( const CodeLocation& loc, const CompoundStmt* body,
     298                std::vector<Label>&& labels = {} )
     299        : Stmt(loc, std::move(labels)), body(body) {}
     300
     301        const Stmt* accept( Visitor& v ) const override { return v.visit( this ); }
     302private:
     303        FinallyStmt* clone() const override { return new FinallyStmt{ *this }; }
     304};
     305
     306class WaitForStmt final : public Stmt {
     307public:
     308        struct Target {
     309                ptr<Expr> function;
     310                std::vector<ptr<Expr>> arguments;
     311        };
     312
     313        struct Clause {
     314                Target target;
     315                ptr<Stmt> stmt;
     316                ptr<Expr> cond;
     317        };
     318
     319        struct Timeout {
     320                ptr<Expr> time;
     321                ptr<Stmt> stmt;
     322                ptr<Expr> cond;
     323        };
     324
     325        struct OrElse {
     326                ptr<Stmt> stmt;
     327                ptr<Expr> cond;
     328        };
     329
     330        std::vector<Clause> clauses;
     331        Timeout timeout;
     332        OrElse orElse;
     333
     334        WaitForStmt( const CodeLocation& loc, std::vector<Label>&& labels = {} )
     335        : Stmt(loc, std::move(labels)) {}
     336
     337        const Stmt* accept( Visitor& v ) const override { return v.visit( this ); }
     338private:
     339        WaitForStmt* clone() const override { return new WaitForStmt{ *this }; }
     340};
     341
     342class WithStmt final : public Stmt {
     343public:
     344        std::vector<ptr<Expr>> exprs;
     345        ptr<Stmt> stmt;
     346
     347        WithStmt( const CodeLocation& loc, std::vector<ptr<Expr>>&& exprs, const Stmt* stmt,
     348                std::vector<Label>&& labels = {} )
     349        : Stmt(loc, std::move(labels)), exprs(std::move(exprs)), stmt(stmt) {}
     350
     351        const Stmt* accept( Visitor& v ) const override { return v.visit( this ); }
     352private:
     353        WithStmt* clone() const override { return new WithStmt{ *this }; }
     354};
     355
     356class DeclStmt final : public Stmt {
     357public:
     358        ptr<Decl> decl;
     359
     360        DeclStmt( const CodeLocation& loc, const Decl* decl, std::vector<Label>&& labels = {} )
     361        : Stmt(loc, std::move(labels)), decl(decl) {}
     362
     363        const Stmt* accept( Visitor& v ) const override { return v.visit( this ); }
     364private:
     365        DeclStmt* clone() const override { return new DeclStmt{ *this }; }
     366};
     367
     368class ImplicitCtorDtorStmt final : public Stmt {
     369public:
     370        readonly<Stmt> callStmt;
     371
     372        ImplicitCtorDtorStmt( const CodeLocation& loc, const Stmt* callStmt,
     373                std::vector<Label>&& labels = {} )
     374        : Stmt(loc, std::move(labels)), callStmt(callStmt) {}
     375
     376        const Stmt* accept( Visitor& v ) const override { return v.visit( this ); }
     377private:
     378        ImplicitCtorDtorStmt* clone() const override { return new ImplicitCtorDtorStmt{ *this }; }
     379};
    90380
    91381//=================================================================================================
  • src/AST/porting.md

    r3648d98 r89c2f7c9  
    122122* `get_statement()` exclusively used for code location, replaced with `CodeLocation` field
    123123
     124`CaseStmt`
     125* `_isDefault` has been removed
     126  * `isDefault` calculates value from `cond`
     127  * default may not have a condition. I believe case (!default) requires a condition.
     128
     129`BranchStmt`
     130* `Type` -> `Kind` and `type` -> `kind`
     131* Constructors no longer throw SemanticErrorException:
     132  * `label` constructor claims it is now considered a syntax error, replaced with assert.
     133  * `computedTarget` constructor assumes `Goto`, other check would have SegFaulted.
     134
     135`TryStmt`
     136* `block` -> `body` and `finallyBlock` -> `finally`
     137
     138`FinallyStmt`
     139* `block` -> `body`
     140
    124141`CompoundStmt`
    125142* **TODO** port copy operator
Note: See TracChangeset for help on using the changeset viewer.