Changeset 23f99e1


Ignore:
Timestamp:
May 15, 2019, 3:46:36 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
1e97287
Parents:
54db6ba
Message:

Finished implementing declarations

Location:
src/AST
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Decl.hpp

    r54db6ba r23f99e1  
    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
     
    170196        std::string genTypeString() const;
    171197
    172         virtual const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
    173 private:
    174         virtual TypeDecl * clone() const override { return new TypeDecl{ *this }; }
     198        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
     199private:
     200        TypeDecl * clone() const override { return new TypeDecl{ *this }; }
     201
     202        /// Must be copied in ALL derived classes
     203        template<typename node_t>
     204        friend auto mutate(const node_t * node);
    175205};
    176206
     
    184214        std::string typeString() const override { return "typedef"; }
    185215
    186         virtual const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
    187 private:
    188         virtual TypedefDecl * clone() const override { return new TypedefDecl{ *this }; }
     216        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
     217private:
     218        TypedefDecl * clone() const override { return new TypedefDecl{ *this }; }
     219
     220        /// Must be copied in ALL derived classes
     221        template<typename node_t>
     222        friend auto mutate(const node_t * node);
    189223};
    190224
     
    224258        bool is_thread() { return kind == DeclarationNode::Thread; }
    225259
    226         virtual const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
    227 private:
    228         virtual StructDecl * clone() const override { return new StructDecl{ *this }; }
     260        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
     261private:
     262        StructDecl * clone() const override { return new StructDecl{ *this }; }
     263
     264        /// Must be copied in ALL derived classes
     265        template<typename node_t>
     266        friend auto mutate(const node_t * node);
    229267
    230268        std::string typeString() const override { return "struct"; }
     
    238276        : AggregateDecl( loc, name, std::move(attrs), linkage ) {}
    239277
    240         virtual const Decl * accept( Visitor& v ) const override { return v.visit( this ); }
    241 private:
    242         virtual UnionDecl * clone() const override { return new UnionDecl{ *this }; }
     278        const Decl * accept( Visitor& v ) const override { return v.visit( this ); }
     279private:
     280        UnionDecl * clone() const override { return new UnionDecl{ *this }; }
     281
     282        /// Must be copied in ALL derived classes
     283        template<typename node_t>
     284        friend auto mutate(const node_t * node);
    243285
    244286        std::string typeString() const override { return "union"; }
     
    255297        bool valueOf( Decl* enumerator, long long& value ) const;
    256298
    257         virtual const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
    258 private:
    259         virtual EnumDecl * clone() const override { return new EnumDecl{ *this }; }
     299        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
     300private:
     301        EnumDecl * clone() const override { return new EnumDecl{ *this }; }
     302
     303        /// Must be copied in ALL derived classes
     304        template<typename node_t>
     305        friend auto mutate(const node_t * node);
    260306
    261307        std::string typeString() const override { return "enum"; }
     
    272318        : AggregateDecl( loc, name, std::move(attrs), linkage ) {}
    273319
    274         virtual const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
    275 private:
    276         virtual TraitDecl * clone() const override { return new TraitDecl{ *this }; }
     320        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
     321private:
     322        TraitDecl * clone() const override { return new TraitDecl{ *this }; }
     323
     324        /// Must be copied in ALL derived classes
     325        template<typename node_t>
     326        friend auto mutate(const node_t * node);
    277327
    278328        std::string typeString() const override { return "trait"; }
    279329};
    280330
     331class AsmDecl : public Decl {
     332public:
     333        ptr<AsmStmt> stmt;
     334
     335        AsmDecl( const CodeLocation & loc, AsmStmt *stmt )
     336        : Decl( loc, "", {}, {} ), stmt(stmt) {}
     337
     338        const AsmDecl * accept( Visitor &v ) const override { return v.visit( this ); }
     339private:
     340        AsmDecl *clone() const override { return new AsmDecl( *this ); }
     341
     342        /// Must be copied in ALL derived classes
     343        template<typename node_t>
     344        friend auto mutate(const node_t * node);
     345};
     346
     347class StaticAssertDecl : public Decl {
     348public:
     349        ptr<Expr> condition;
     350        ptr<ConstantExpr> msg;   // string literal
     351
     352        StaticAssertDecl( const CodeLocation & loc, const Expr * condition, const ConstantExpr * msg )
     353        : Decl( loc, "", {}, {} ), condition( condition ), msg( msg ) {}
     354
     355        const StaticAssertDecl * accept( Visitor &v ) const override { return v.visit( this ); }
     356private:
     357        StaticAssertDecl * clone() const override { return new StaticAssertDecl( *this ); }
     358
     359        /// Must be copied in ALL derived classes
     360        template<typename node_t>
     361        friend auto mutate(const node_t * node);
     362};
    281363
    282364//=================================================================================================
     
    291373inline void increment( const class ObjectDecl * node, Node::ref_type ref ) { node->increment(ref); }
    292374inline void decrement( const class ObjectDecl * node, Node::ref_type ref ) { node->decrement(ref); }
    293 // inline void increment( const class FunctionDecl * node, Node::ref_type ref ) { node->increment(ref); }
    294 // inline void decrement( const class FunctionDecl * node, Node::ref_type ref ) { node->decrement(ref); }
     375inline void increment( const class FunctionDecl * node, Node::ref_type ref ) { node->increment(ref); }
     376inline void decrement( const class FunctionDecl * node, Node::ref_type ref ) { node->decrement(ref); }
    295377inline void increment( const class AggregateDecl * node, Node::ref_type ref ) { node->increment(ref); }
    296378inline void decrement( const class AggregateDecl * node, Node::ref_type ref ) { node->decrement(ref); }
     
    307389inline void increment( const class TypeDecl * node, Node::ref_type ref ) { node->increment(ref); }
    308390inline void decrement( const class TypeDecl * node, Node::ref_type ref ) { node->decrement(ref); }
    309 // inline void increment( const class FtypeDecl * node, Node::ref_type ref ) { node->increment(ref); }
    310 // inline void decrement( const class FtypeDecl * node, Node::ref_type ref ) { node->decrement(ref); }
    311 // inline void increment( const class DtypeDecl * node, Node::ref_type ref ) { node->increment(ref); }
    312 // inline void decrement( const class DtypeDecl * node, Node::ref_type ref ) { node->decrement(ref); }
    313391inline void increment( const class TypedefDecl * node, Node::ref_type ref ) { node->increment(ref); }
    314392inline void decrement( const class TypedefDecl * node, Node::ref_type ref ) { node->decrement(ref); }
    315 // inline void increment( const class AsmDecl * node, Node::ref_type ref ) { node->increment(ref); }
    316 // inline void decrement( const class AsmDecl * node, Node::ref_type ref ) { node->decrement(ref); }
    317 // inline void increment( const class StaticAssertDecl * node, Node::ref_type ref ) { node->increment(ref); }
    318 // inline void decrement( const class StaticAssertDecl * node, Node::ref_type ref ) { node->decrement(ref); }
     393inline void increment( const class AsmDecl * node, Node::ref_type ref ) { node->increment(ref); }
     394inline void decrement( const class AsmDecl * node, Node::ref_type ref ) { node->decrement(ref); }
     395inline void increment( const class StaticAssertDecl * node, Node::ref_type ref ) { node->increment(ref); }
     396inline void decrement( const class StaticAssertDecl * node, Node::ref_type ref ) { node->decrement(ref); }
    319397
    320398}
  • src/AST/Expr.hpp

    r54db6ba r23f99e1  
    121121        Expr* set_extension( bool ex ) { extension = ex; return this; }
    122122
    123         virtual const Expr * accept( Visitor& v ) const override = 0;
     123        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

    r54db6ba r23f99e1  
    3333class NamedTypeDecl;
    3434class TypeDecl;
    35 class FtypeDecl;
    36 class DtypeDecl;
    3735class TypedefDecl;
    3836class AsmDecl;
     
    171169inline void increment( const class TypeDecl *, Node::ref_type );
    172170inline void decrement( const class TypeDecl *, Node::ref_type );
    173 inline void increment( const class FtypeDecl *, Node::ref_type );
    174 inline void decrement( const class FtypeDecl *, Node::ref_type );
    175 inline void increment( const class DtypeDecl *, Node::ref_type );
    176 inline void decrement( const class DtypeDecl *, Node::ref_type );
    177171inline void increment( const class TypedefDecl *, Node::ref_type );
    178172inline void decrement( const class TypedefDecl *, Node::ref_type );
  • src/AST/Init.hpp

    r54db6ba r23f99e1  
    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
     
    4949        Init( const CodeLocation& loc, bool mc ) : ParseNode( loc ), maybeConstructed( mc ) {}
    5050
    51         virtual const Init * accept( Visitor& v ) const override = 0;
     51        const Init * accept( Visitor& v ) const override = 0;
    5252private:
    53         virtual const Init * clone() const override = 0;
     53        const Init * clone() const override = 0;
    5454};
    5555
     
    6363        : Init( loc, mc ), value( val ) {}
    6464
    65         virtual const Init * accept( Visitor & v ) const override { return v.visit( this ); }
     65        const Init * accept( Visitor & v ) const override { return v.visit( this ); }
    6666private:
    67         virtual SingleInit * clone() const override { return new SingleInit{ *this }; }
     67        SingleInit * clone() const override { return new SingleInit{ *this }; }
    6868
    6969        /// Must be copied in ALL derived classes
     
    9191        const_iterator end() const { return initializers.end(); }
    9292
    93         virtual const Init * accept( Visitor & v ) const override { return v.visit( this ); }
     93        const Init * accept( Visitor & v ) const override { return v.visit( this ); }
    9494private:
    95         virtual ListInit * clone() const override { return new ListInit{ *this }; }
     95        ListInit * clone() const override { return new ListInit{ *this }; }
    9696
    9797        /// Must be copied in ALL derived classes
     
    114114        : Init( loc, true ), ctor( ctor ), dtor( dtor ), init( init ) {}
    115115
    116         virtual const Init * accept( Visitor & v ) const override { return v.visit( this ); }
     116        const Init * accept( Visitor & v ) const override { return v.visit( this ); }
    117117private:
    118         virtual ConstructorInit * clone() const override { return new ConstructorInit{ *this }; }
     118        ConstructorInit * clone() const override { return new ConstructorInit{ *this }; }
    119119
    120120        /// Must be copied in ALL derived classes
  • src/AST/Pass.hpp

    r54db6ba r23f99e1  
    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::AttrType             * ) override final;
    170         virtual const ast::Type *             visit( const ast::VarArgsType          * ) override final;
    171         virtual const ast::Type *             visit( const ast::ZeroType             * ) override final;
    172         virtual const ast::Type *             visit( const ast::OneType              * ) override final;
    173         virtual const ast::Type *             visit( const ast::GlobalScopeType      * ) override final;
    174         virtual const ast::Designation *      visit( const ast::Designation          * ) override final;
    175         virtual const ast::Init *             visit( const ast::SingleInit           * ) override final;
    176         virtual const ast::Init *             visit( const ast::ListInit             * ) override final;
    177         virtual const ast::Init *             visit( const ast::ConstructorInit      * ) override final;
    178         virtual const ast::Constant *         visit( const ast::Constant             * ) override final;
    179         virtual const ast::Attribute *        visit( const ast::Attribute            * ) override final;
    180         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::AttrType             * ) override final;
     170        const ast::Type *             visit( const ast::VarArgsType          * ) override final;
     171        const ast::Type *             visit( const ast::ZeroType             * ) override final;
     172        const ast::Type *             visit( const ast::OneType              * ) override final;
     173        const ast::Type *             visit( const ast::GlobalScopeType      * ) override final;
     174        const ast::Designation *      visit( const ast::Designation          * ) override final;
     175        const ast::Init *             visit( const ast::SingleInit           * ) override final;
     176        const ast::Init *             visit( const ast::ListInit             * ) override final;
     177        const ast::Init *             visit( const ast::ConstructorInit      * ) override final;
     178        const ast::Constant *         visit( const ast::Constant             * ) override final;
     179        const ast::Attribute *        visit( const ast::Attribute            * ) override final;
     180        const ast::TypeSubstitution * visit( const ast::TypeSubstitution     * ) override final;
    181181
    182182        friend void acceptAll( std::list< ptr<Decl> > & decls, Pass<pass_t>& visitor );
     
    216216                Pass<pass_t> & pass;
    217217        };
     218
     219private:
     220        bool inFunction = false;
    218221};
    219222
  • src/AST/Pass.impl.hpp

    r54db6ba r23f99e1  
    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.hpp

    r54db6ba r23f99e1  
    4040        Stmt(const Stmt& o) : ParseNode(o), labels(o.labels) {}
    4141
    42         virtual const Stmt* accept( Visitor& v ) const override = 0;
     42        const Stmt* accept( Visitor& v ) const override = 0;
    4343private:
    44         virtual Stmt* clone() const override = 0;
     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 ); }
     61        const CompoundStmt* accept( Visitor& v ) const override { return v.visit( this ); }
    6262private:
    63         virtual CompoundStmt* clone() const override { return new CompoundStmt{ *this }; }
     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 ); }
     72        const NullStmt * accept( Visitor& v ) const override { return v.visit( this ); }
    7373private:
    74         virtual NullStmt * clone() const override { return new NullStmt{ *this }; }
     74        NullStmt * clone() const override { return new NullStmt{ *this }; }
    7575};
    7676
     
    8282        ExprStmt( const CodeLocation& loc, Expr* e ) : Stmt(loc), expr(e) {}
    8383
    84         virtual const Stmt * accept( Visitor& v ) const override { return v.visit( this ); }
     84        const Stmt * accept( Visitor& v ) const override { return v.visit( this ); }
    8585private:
    86         virtual ExprStmt * clone() const override { return new ExprStmt{ *this }; }
     86        ExprStmt * clone() const override { return new ExprStmt{ *this }; }
    8787};
    8888
Note: See TracChangeset for help on using the changeset viewer.