Changes in / [be567e9:62315a0]


Ignore:
Location:
src
Files:
2 deleted
21 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Attribute.hpp

    rbe567e9 r62315a0  
    1919#include <vector>
    2020
    21 #include "Fwd.hpp"
    2221#include "Node.hpp"     // for ptr
    2322#include "Visitor.hpp"
     
    3231        std::vector<ptr<Expr>> parameters;
    3332
    34         Attribute( const std::string & name = "", std::vector<ptr<Expr>> && params = {})
     33        Attribute( const std::string& name = "", std::vector<ptr<Expr>>&& params = {})
    3534        : name( name ), parameters( params ) {}
    36         virtual ~Attribute() = default;
    3735
    3836        bool empty() const { return name.empty(); }
     
    4442        bool isValidOnFuncParam() const;
    4543
    46         const Attribute * accept( Visitor & v ) const override { return v.visit( this ); }
     44        Attribute* accept( Visitor& v ) override { return v.visit( this ); }
    4745private:
    48         Attribute * clone() const override { return new Attribute{ *this }; }
    49 
    50         /// Must be copied in ALL derived classes
    51         template<typename node_t>
    52         friend auto mutate(const node_t * node);
     46        Attribute* clone() const override { return new Attribute{ *this }; }
    5347};
    5448
  • src/AST/Decl.hpp

    rbe567e9 r62315a0  
    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        virtual Decl* accept( Visitor& v ) override = 0;
     60private:
     61        virtual Decl* clone() const override = 0;
    6262};
    6363
     
    8585
    8686        /// Get type of this declaration. May be generated by subclass
    87         virtual const Type * get_type() const = 0;
     87        virtual const Type* get_type() const = 0;
    8888        /// Set type of this declaration. May be verified by subclass
    8989        virtual void set_type(Type*) = 0;
    9090
    91         virtual const DeclWithType * accept( Visitor & v ) const override = 0;
    92 private:
    93         virtual DeclWithType * clone() const override = 0;
     91        virtual DeclWithType* accept( Visitor& v ) override = 0;
     92private:
     93        virtual DeclWithType* clone() const override = 0;
    9494};
    9595
     
    110110        void set_type( Type* ty ) override { type = ty; }
    111111
    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 }; }
    115 
    116         /// Must be copied in ALL derived classes
    117         template<typename node_t>
    118         friend auto mutate(const node_t * node);
     112        DeclWithType* accept( Visitor& v ) override { return v.visit( this ); }
     113private:
     114        ObjectDecl* clone() const override { return new ObjectDecl{ *this }; }
    119115};
    120116
     
    170166        std::string genTypeString() const;
    171167
    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 }; }
     168        Decl* accept( Visitor& v ) override { return v.visit( this ); }
     169private:
     170        TypeDecl* clone() const override { return new TypeDecl{ *this }; }
    175171};
    176172
     
    184180        std::string typeString() const override { return "typedef"; }
    185181
    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 }; }
     182        Decl* accept( Visitor& v ) override { return v.visit( this ); }
     183private:
     184        TypedefDecl* clone() const override { return new TypedefDecl{ *this }; }
    189185};
    190186
     
    224220        bool is_thread() { return kind == DeclarationNode::Thread; }
    225221
    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 }; }
     222        Decl* accept( Visitor& v ) override { return v.visit( this ); }
     223private:
     224        StructDecl* clone() const override { return new StructDecl{ *this }; }
    229225
    230226        std::string typeString() const override { return "struct"; }
     
    238234        : AggregateDecl( loc, name, std::move(attrs), linkage ) {}
    239235
    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 }; }
     236        Decl* accept( Visitor& v ) override { return v.visit( this ); }
     237private:
     238        UnionDecl* clone() const override { return new UnionDecl{ *this }; }
    243239
    244240        std::string typeString() const override { return "union"; }
     
    255251        bool valueOf( Decl* enumerator, long long& value ) const;
    256252
    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 }; }
     253        Decl* accept( Visitor& v ) override { return v.visit( this ); }
     254private:
     255        EnumDecl* clone() const override { return new EnumDecl{ *this }; }
    260256
    261257        std::string typeString() const override { return "enum"; }
     
    272268        : AggregateDecl( loc, name, std::move(attrs), linkage ) {}
    273269
    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 }; }
     270        Decl* accept( Visitor& v ) override { return v.visit( this ); }
     271private:
     272        TraitDecl* clone() const override { return new TraitDecl{ *this }; }
    277273
    278274        std::string typeString() const override { return "trait"; }
     
    291287inline void increment( const class ObjectDecl * node, Node::ref_type ref ) { node->increment(ref); }
    292288inline 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); }
     289inline void increment( const class FunctionDecl * node, Node::ref_type ref ) { node->increment(ref); }
     290inline void decrement( const class FunctionDecl * node, Node::ref_type ref ) { node->decrement(ref); }
    295291inline void increment( const class AggregateDecl * node, Node::ref_type ref ) { node->increment(ref); }
    296292inline void decrement( const class AggregateDecl * node, Node::ref_type ref ) { node->decrement(ref); }
     
    307303inline void increment( const class TypeDecl * node, Node::ref_type ref ) { node->increment(ref); }
    308304inline 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); }
     305inline void increment( const class FtypeDecl * node, Node::ref_type ref ) { node->increment(ref); }
     306inline void decrement( const class FtypeDecl * node, Node::ref_type ref ) { node->decrement(ref); }
     307inline void increment( const class DtypeDecl * node, Node::ref_type ref ) { node->increment(ref); }
     308inline void decrement( const class DtypeDecl * node, Node::ref_type ref ) { node->decrement(ref); }
    313309inline void increment( const class TypedefDecl * node, Node::ref_type ref ) { node->increment(ref); }
    314310inline 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); }
     311inline void increment( const class AsmDecl * node, Node::ref_type ref ) { node->increment(ref); }
     312inline void decrement( const class AsmDecl * node, Node::ref_type ref ) { node->decrement(ref); }
     313inline void increment( const class StaticAssertDecl * node, Node::ref_type ref ) { node->increment(ref); }
     314inline void decrement( const class StaticAssertDecl * node, Node::ref_type ref ) { node->decrement(ref); }
    319315
    320316}
  • src/AST/Expr.hpp

    rbe567e9 r62315a0  
    2727namespace ast {
    2828
    29 /// Contains the ID of a declaration and a type that is derived from that declaration,
     29/// Contains the ID of a declaration and a type that is derived from that declaration, 
    3030/// but subject to decay-to-pointer and type parameter renaming
    3131struct ParamEntry {
     
    7474                        case Empty:  return;
    7575                        case Slots:  new(&data.resnSlots) ResnSlots{ std::move(o.data.resnSlots) }; return;
    76                         case Params:
     76                        case Params: 
    7777                                new(&data.inferParams) InferredParams{ std::move(o.data.inferParams) }; return;
    7878                        }
     
    121121        Expr* set_extension( bool ex ) { extension = ex; return this; }
    122122
    123         virtual const Expr * accept( Visitor& v ) const override = 0;
     123        virtual Expr* accept( Visitor& v ) override = 0;
    124124private:
    125         virtual Expr * clone() const override = 0;
     125        virtual Expr* clone() const override = 0;
    126126};
    127127
    128 
    129 //=================================================================================================
    130 /// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency
    131 /// remove only if there is a better solution
    132 /// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with
    133 /// forward declarations
    134 inline void increment( const class Expr * node, Node::ref_type ref ) { node->increment(ref); }
    135 inline void decrement( const class Expr * node, Node::ref_type ref ) { node->decrement(ref); }
    136 // inline void increment( const class ApplicationExpr * node, Node::ref_type ref ) { node->increment(ref); }
    137 // inline void decrement( const class ApplicationExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    138 // inline void increment( const class UntypedExpr * node, Node::ref_type ref ) { node->increment(ref); }
    139 // inline void decrement( const class UntypedExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    140 // inline void increment( const class NameExpr * node, Node::ref_type ref ) { node->increment(ref); }
    141 // inline void decrement( const class NameExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    142 // inline void increment( const class AddressExpr * node, Node::ref_type ref ) { node->increment(ref); }
    143 // inline void decrement( const class AddressExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    144 // inline void increment( const class LabelAddressExpr * node, Node::ref_type ref ) { node->increment(ref); }
    145 // inline void decrement( const class LabelAddressExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    146 // inline void increment( const class CastExpr * node, Node::ref_type ref ) { node->increment(ref); }
    147 // inline void decrement( const class CastExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    148 // inline void increment( const class KeywordCastExpr * node, Node::ref_type ref ) { node->increment(ref); }
    149 // inline void decrement( const class KeywordCastExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    150 // inline void increment( const class VirtualCastExpr * node, Node::ref_type ref ) { node->increment(ref); }
    151 // inline void decrement( const class VirtualCastExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    152 // inline void increment( const class MemberExpr * node, Node::ref_type ref ) { node->increment(ref); }
    153 // inline void decrement( const class MemberExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    154 // inline void increment( const class UntypedMemberExpr * node, Node::ref_type ref ) { node->increment(ref); }
    155 // inline void decrement( const class UntypedMemberExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    156 // inline void increment( const class VariableExpr * node, Node::ref_type ref ) { node->increment(ref); }
    157 // inline void decrement( const class VariableExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    158 // inline void increment( const class ConstantExpr * node, Node::ref_type ref ) { node->increment(ref); }
    159 // inline void decrement( const class ConstantExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    160 // inline void increment( const class SizeofExpr * node, Node::ref_type ref ) { node->increment(ref); }
    161 // inline void decrement( const class SizeofExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    162 // inline void increment( const class AlignofExpr * node, Node::ref_type ref ) { node->increment(ref); }
    163 // inline void decrement( const class AlignofExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    164 // inline void increment( const class UntypedOffsetofExpr * node, Node::ref_type ref ) { node->increment(ref); }
    165 // inline void decrement( const class UntypedOffsetofExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    166 // inline void increment( const class OffsetofExpr * node, Node::ref_type ref ) { node->increment(ref); }
    167 // inline void decrement( const class OffsetofExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    168 // inline void increment( const class OffsetPackExpr * node, Node::ref_type ref ) { node->increment(ref); }
    169 // inline void decrement( const class OffsetPackExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    170 // inline void increment( const class AttrExpr * node, Node::ref_type ref ) { node->increment(ref); }
    171 // inline void decrement( const class AttrExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    172 // inline void increment( const class LogicalExpr * node, Node::ref_type ref ) { node->increment(ref); }
    173 // inline void decrement( const class LogicalExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    174 // inline void increment( const class ConditionalExpr * node, Node::ref_type ref ) { node->increment(ref); }
    175 // inline void decrement( const class ConditionalExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    176 // inline void increment( const class CommaExpr * node, Node::ref_type ref ) { node->increment(ref); }
    177 // inline void decrement( const class CommaExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    178 // inline void increment( const class TypeExpr * node, Node::ref_type ref ) { node->increment(ref); }
    179 // inline void decrement( const class TypeExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    180 // inline void increment( const class AsmExpr * node, Node::ref_type ref ) { node->increment(ref); }
    181 // inline void decrement( const class AsmExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    182 // inline void increment( const class ImplicitCopyCtorExpr * node, Node::ref_type ref ) { node->increment(ref); }
    183 // inline void decrement( const class ImplicitCopyCtorExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    184 // inline void increment( const class ConstructorExpr * node, Node::ref_type ref ) { node->increment(ref); }
    185 // inline void decrement( const class ConstructorExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    186 // inline void increment( const class CompoundLiteralExpr * node, Node::ref_type ref ) { node->increment(ref); }
    187 // inline void decrement( const class CompoundLiteralExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    188 // inline void increment( const class UntypedValofExpr * node, Node::ref_type ref ) { node->increment(ref); }
    189 // inline void decrement( const class UntypedValofExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    190 // inline void increment( const class RangeExpr * node, Node::ref_type ref ) { node->increment(ref); }
    191 // inline void decrement( const class RangeExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    192 // inline void increment( const class UntypedTupleExpr * node, Node::ref_type ref ) { node->increment(ref); }
    193 // inline void decrement( const class UntypedTupleExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    194 // inline void increment( const class TupleExpr * node, Node::ref_type ref ) { node->increment(ref); }
    195 // inline void decrement( const class TupleExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    196 // inline void increment( const class TupleIndexExpr * node, Node::ref_type ref ) { node->increment(ref); }
    197 // inline void decrement( const class TupleIndexExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    198 // inline void increment( const class TupleAssignExpr * node, Node::ref_type ref ) { node->increment(ref); }
    199 // inline void decrement( const class TupleAssignExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    200 // inline void increment( const class StmtExpr * node, Node::ref_type ref ) { node->increment(ref); }
    201 // inline void decrement( const class StmtExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    202 // inline void increment( const class UniqueExpr * node, Node::ref_type ref ) { node->increment(ref); }
    203 // inline void decrement( const class UniqueExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    204 // inline void increment( const class UntypedInitExpr * node, Node::ref_type ref ) { node->increment(ref); }
    205 // inline void decrement( const class UntypedInitExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    206 // inline void increment( const class InitExpr * node, Node::ref_type ref ) { node->increment(ref); }
    207 // inline void decrement( const class InitExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    208 // inline void increment( const class DeletedExpr * node, Node::ref_type ref ) { node->increment(ref); }
    209 // inline void decrement( const class DeletedExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    210 // inline void increment( const class DefaultArgExpr * node, Node::ref_type ref ) { node->increment(ref); }
    211 // inline void decrement( const class DefaultArgExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    212 // inline void increment( const class GenericExpr * node, Node::ref_type ref ) { node->increment(ref); }
    213 // inline void decrement( const class GenericExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    214128}
    215129
  • src/AST/Fwd.hpp

    rbe567e9 r62315a0  
    137137
    138138class TypeSubstitution;
    139 
    140 std::string toString( const Node * );
    141139
    142140//=================================================================================================
     
    357355inline void increment( const class Constant *, Node::ref_type );
    358356inline void decrement( const class Constant *, Node::ref_type );
     357inline void increment( const class Label *, Node::ref_type );
     358inline void decrement( const class Label *, Node::ref_type );
    359359inline void increment( const class Attribute *, Node::ref_type );
    360360inline void decrement( const class Attribute *, Node::ref_type );
  • src/AST/Init.hpp

    rbe567e9 r62315a0  
    3737        : ParseNode( loc ), designators( std::move(ds) ) {}
    3838
    39         virtual const Designation* accept( Visitor& v ) const override { return v.visit( this ); }
     39        Designation* accept( Visitor& v ) 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        virtual Init* accept( Visitor& v ) override = 0;
    5252private:
    53         virtual const Init * clone() const override = 0;
     53        virtual 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        Init* accept( Visitor& v ) override { return v.visit( this ); }
    6666private:
    67         virtual SingleInit * clone() const override { return new SingleInit{ *this }; }
    68 
    69         /// Must be copied in ALL derived classes
    70         template<typename node_t>
    71         friend auto mutate(const node_t * node);
     67        SingleInit* clone() const override { return new SingleInit{ *this }; }
    7268};
    7369
     
    9187        const_iterator end() const { return initializers.end(); }
    9288
    93         virtual const Init * accept( Visitor & v ) const override { return v.visit( this ); }
     89        Init* accept( Visitor& v ) override { return v.visit( this ); }
    9490private:
    95         virtual ListInit * clone() const override { return new ListInit{ *this }; }
    96 
    97         /// Must be copied in ALL derived classes
    98         template<typename node_t>
    99         friend auto mutate(const node_t * node);
     91        ListInit* clone() const override { return new ListInit{ *this }; }
    10092};
    10193
     
    114106        : Init( loc, true ), ctor( ctor ), dtor( dtor ), init( init ) {}
    115107
    116         virtual const Init * accept( Visitor & v ) const override { return v.visit( this ); }
     108        Init* accept( Visitor& v ) override { return v.visit( this ); }
    117109private:
    118         virtual ConstructorInit * clone() const override { return new ConstructorInit{ *this }; }
    119 
    120         /// Must be copied in ALL derived classes
    121         template<typename node_t>
    122         friend auto mutate(const node_t * node);
     110        ConstructorInit* clone() const override { return new ConstructorInit{ *this }; }
    123111};
    124112
  • src/AST/Label.hpp

    rbe567e9 r62315a0  
    3535
    3636        Label( CodeLocation loc, const std::string& name = "",
    37                 std::vector<ptr<Attribute>> && attrs = std::vector<ptr<Attribute>>{} )
     37                const std::vector<ptr<Attribute>>& attrs = std::vector<ptr<Attribute>>{} )
    3838        : location( loc ), name( name ), attributes( attrs ) {}
    3939
     
    4848inline std::ostream& operator<< ( std::ostream& out, const Label& l ) { return out << l.name; }
    4949
     50
     51//=================================================================================================
     52/// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency
     53/// remove only if there is a better solution
     54/// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with
     55/// forward declarations
     56inline void increment( const class Label * node, Node::ref_type ref ) { node->increment( ref ); }
     57inline void decrement( const class Label * node, Node::ref_type ref ) { node->decrement( ref ); }
     58
    5059}
    5160
  • src/AST/Node.hpp

    rbe567e9 r62315a0  
    3030        // change/share reference counts
    3131        Node() = default;
    32         Node(const Node&) : strong_count(0), weak_count(0) {}
    33         Node(Node&&) : strong_count(0), weak_count(0) {}
     32        Node(const Node&) : strong_ref(0), weak_ref(0) {}
     33        Node(Node&&) : strong_ref(0), weak_ref(0) {}
    3434        Node& operator= (const Node&) = delete;
    3535        Node& operator= (Node&&) = delete;
    3636        virtual ~Node() = default;
    3737
    38         virtual const Node * accept( Visitor & v ) const = 0;
     38        virtual Node* accept( Visitor& v ) = 0;
    3939
    4040        /// Types of node references
     
    4646        inline void increment(ref_type ref) const {
    4747                switch (ref) {
    48                         case ref_type::strong: strong_count++; break;
    49                         case ref_type::weak  : weak_count  ++; break;
     48                        case ref_type::strong: strong_ref++; break;
     49                        case ref_type::weak  : weak_ref  ++; break;
    5050                }
    5151        }
     
    5353        inline void decrement(ref_type ref) const {
    5454                switch (ref) {
    55                         case ref_type::strong: strong_count--; break;
    56                         case ref_type::weak  : weak_count  --; break;
     55                        case ref_type::strong: strong_ref--; break;
     56                        case ref_type::weak  : weak_ref  --; break;
    5757                }
    5858
    59                 if(!strong_count && !weak_count) {
     59                if(!strong_ref && !weak_ref) {
    6060                        delete this;
    6161                }
    6262        }
    63 private:
    64         /// Make a copy of this node; should be overridden in subclass with more precise return type
    65         virtual const Node * clone() const = 0;
    6663
    67         /// Must be copied in ALL derived classes
    6864        template<typename node_t>
    6965        friend auto mutate(const node_t * node);
    7066
    71         mutable size_t strong_count = 0;
    72         mutable size_t weak_count = 0;
     67private:
     68        /// Make a copy of this node; should be overridden in subclass with more precise return type
     69        virtual Node* clone() const = 0;
     70
     71        mutable size_t strong_ref = 0;
     72        mutable size_t weak_ref = 0;
    7373};
    7474
     
    100100public:
    101101        ptr_base() : node(nullptr) {}
    102         ptr_base( const node_t * n ) : node(n) { if( !node ) increment(node, ref_t); }
    103         ~ptr_base() { if( node ) decrement(node, ref_t); }
     102        ptr_base( node_t * n ) : node(n) { if( !node ) node->increment(ref_t); }
     103        ~ptr_base() { if( node ) node->decrement(ref_t); }
    104104
    105105        template< enum  Node::ref_type o_ref_t >
    106106        ptr_base( const ptr_base<node_t, o_ref_t> & o ) : node(o.node) {
    107107                if( !node ) return;
    108                 increment(node, ref_t);
     108                node->increment(ref_t);
    109109        }
    110110
    111111        template< enum  Node::ref_type o_ref_t >
    112112        ptr_base( ptr_base<node_t, o_ref_t> && o ) : node(o.node) {
    113                 if( node ) increment(node, ref_t);
    114         }
    115 
    116         template<typename o_node_t>
    117         ptr_base & operator=( const o_node_t * node ) {
    118                 assign(strict_dynamic_cast<const node_t *>(node));
    119                 return *this;
     113                if( node ) node->increment(ref_t);
    120114        }
    121115
     
    145139
    146140private:
    147         void assign(const node_t * other ) {
    148                 if( other ) increment(other, ref_t);
    149                 if( node  ) decrement(node , ref_t);
     141        void assign(node_t * other ) {
     142                if( other ) other->increment(ref_t);
     143                if( node  ) node ->decrement(ref_t);
    150144                node = other;
    151145        }
    152146
    153147protected:
    154         const node_t * node;
     148        node_t * node;
    155149};
    156150
  • src/AST/Pass.hpp

    rbe567e9 r62315a0  
    2323#include "AST/Fwd.hpp"
    2424#include "AST/Node.hpp"
    25 
    26 #include "AST/Attribute.hpp"
    2725#include "AST/Decl.hpp"
    28 #include "AST/Expr.hpp"
    29 #include "AST/Init.hpp"
    30 #include "AST/Stmt.hpp"
    31 
    3226#include "AST/Visitor.hpp"
    3327
     
    8579
    8680        /// 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;
     81        virtual DeclWithType *     visit( const ObjectDecl           * ) override final;
     82        virtual DeclWithType *     visit( const FunctionDecl         * ) override final;
     83        virtual Decl *             visit( const StructDecl           * ) override final;
     84        virtual Decl *             visit( const UnionDecl            * ) override final;
     85        virtual Decl *             visit( const EnumDecl             * ) override final;
     86        virtual Decl *             visit( const TraitDecl            * ) override final;
     87        virtual Decl *             visit( const TypeDecl             * ) override final;
     88        virtual Decl *             visit( const TypedefDecl          * ) override final;
     89        virtual AsmDecl *          visit( const AsmDecl              * ) override final;
     90        virtual StaticAssertDecl * visit( const StaticAssertDecl     * ) override final;
     91        virtual CompoundStmt *     visit( const CompoundStmt         * ) override final;
     92        virtual Stmt *             visit( const ExprStmt             * ) override final;
     93        virtual Stmt *             visit( const AsmStmt              * ) override final;
     94        virtual Stmt *             visit( const DirectiveStmt        * ) override final;
     95        virtual Stmt *             visit( const IfStmt               * ) override final;
     96        virtual Stmt *             visit( const WhileStmt            * ) override final;
     97        virtual Stmt *             visit( const ForStmt              * ) override final;
     98        virtual Stmt *             visit( const SwitchStmt           * ) override final;
     99        virtual Stmt *             visit( const CaseStmt             * ) override final;
     100        virtual Stmt *             visit( const BranchStmt           * ) override final;
     101        virtual Stmt *             visit( const ReturnStmt           * ) override final;
     102        virtual Stmt *             visit( const ThrowStmt            * ) override final;
     103        virtual Stmt *             visit( const TryStmt              * ) override final;
     104        virtual Stmt *             visit( const CatchStmt            * ) override final;
     105        virtual Stmt *             visit( const FinallyStmt          * ) override final;
     106        virtual Stmt *             visit( const WaitForStmt          * ) override final;
     107        virtual Stmt *             visit( const WithStmt             * ) override final;
     108        virtual NullStmt *         visit( const NullStmt             * ) override final;
     109        virtual Stmt *             visit( const DeclStmt             * ) override final;
     110        virtual Stmt *             visit( const ImplicitCtorDtorStmt * ) override final;
     111        virtual Expr *             visit( const ApplicationExpr      * ) override final;
     112        virtual Expr *             visit( const UntypedExpr          * ) override final;
     113        virtual Expr *             visit( const NameExpr             * ) override final;
     114        virtual Expr *             visit( const AddressExpr          * ) override final;
     115        virtual Expr *             visit( const LabelAddressExpr     * ) override final;
     116        virtual Expr *             visit( const CastExpr             * ) override final;
     117        virtual Expr *             visit( const KeywordCastExpr      * ) override final;
     118        virtual Expr *             visit( const VirtualCastExpr      * ) override final;
     119        virtual Expr *             visit( const UntypedMemberExpr    * ) override final;
     120        virtual Expr *             visit( const MemberExpr           * ) override final;
     121        virtual Expr *             visit( const VariableExpr         * ) override final;
     122        virtual Expr *             visit( const ConstantExpr         * ) override final;
     123        virtual Expr *             visit( const SizeofExpr           * ) override final;
     124        virtual Expr *             visit( const AlignofExpr          * ) override final;
     125        virtual Expr *             visit( const UntypedOffsetofExpr  * ) override final;
     126        virtual Expr *             visit( const OffsetofExpr         * ) override final;
     127        virtual Expr *             visit( const OffsetPackExpr       * ) override final;
     128        virtual Expr *             visit( const AttrExpr             * ) override final;
     129        virtual Expr *             visit( const LogicalExpr          * ) override final;
     130        virtual Expr *             visit( const ConditionalExpr      * ) override final;
     131        virtual Expr *             visit( const CommaExpr            * ) override final;
     132        virtual Expr *             visit( const TypeExpr             * ) override final;
     133        virtual Expr *             visit( const AsmExpr              * ) override final;
     134        virtual Expr *             visit( const ImplicitCopyCtorExpr * ) override final;
     135        virtual Expr *             visit( const ConstructorExpr      * ) override final;
     136        virtual Expr *             visit( const CompoundLiteralExpr  * ) override final;
     137        virtual Expr *             visit( const RangeExpr            * ) override final;
     138        virtual Expr *             visit( const UntypedTupleExpr     * ) override final;
     139        virtual Expr *             visit( const TupleExpr            * ) override final;
     140        virtual Expr *             visit( const TupleIndexExpr       * ) override final;
     141        virtual Expr *             visit( const TupleAssignExpr      * ) override final;
     142        virtual Expr *             visit( const StmtExpr             * ) override final;
     143        virtual Expr *             visit( const UniqueExpr           * ) override final;
     144        virtual Expr *             visit( const UntypedInitExpr      * ) override final;
     145        virtual Expr *             visit( const InitExpr             * ) override final;
     146        virtual Expr *             visit( const DeletedExpr          * ) override final;
     147        virtual Expr *             visit( const DefaultArgExpr       * ) override final;
     148        virtual Expr *             visit( const GenericExpr          * ) override final;
     149        virtual Type *             visit( const VoidType             * ) override final;
     150        virtual Type *             visit( const BasicType            * ) override final;
     151        virtual Type *             visit( const PointerType          * ) override final;
     152        virtual Type *             visit( const ArrayType            * ) override final;
     153        virtual Type *             visit( const ReferenceType        * ) override final;
     154        virtual Type *             visit( const QualifiedType        * ) override final;
     155        virtual Type *             visit( const FunctionType         * ) override final;
     156        virtual Type *             visit( const StructInstType       * ) override final;
     157        virtual Type *             visit( const UnionInstType        * ) override final;
     158        virtual Type *             visit( const EnumInstType         * ) override final;
     159        virtual Type *             visit( const TraitInstType        * ) override final;
     160        virtual Type *             visit( const TypeInstType         * ) override final;
     161        virtual Type *             visit( const TupleType            * ) override final;
     162        virtual Type *             visit( const TypeofType           * ) override final;
     163        virtual Type *             visit( const AttrType             * ) override final;
     164        virtual Type *             visit( const VarArgsType          * ) override final;
     165        virtual Type *             visit( const ZeroType             * ) override final;
     166        virtual Type *             visit( const OneType              * ) override final;
     167        virtual Type *             visit( const GlobalScopeType      * ) override final;
     168        virtual Designation *      visit( const Designation          * ) override final;
     169        virtual Init *             visit( const SingleInit           * ) override final;
     170        virtual Init *             visit( const ListInit             * ) override final;
     171        virtual Init *             visit( const ConstructorInit      * ) override final;
     172        virtual Constant *         visit( const Constant             * ) override final;
     173        virtual Attribute *        visit( const Attribute            * ) override final;
     174        virtual TypeSubstitution * visit( const TypeSubstitution     * ) override final;
    181175
    182176        friend void acceptAll( std::list< ptr<Decl> > & decls, Pass<pass_t>& visitor );
     
    186180
    187181private:
    188         const ast::Stmt * call_accept( const ast::Stmt * );
    189         const ast::Expr * call_accept( const ast::Expr * );
    190 
    191         template< typename node_t >
    192         auto call_accept( const node_t * node ) -> decltype( node->accept(*this) );
    193 
    194         template< template <class...> class container_t >
     182        /// Logic to call the accept and mutate the parent if needed, delegates call to accept
     183        template<typename parent_t, typename child_t>
     184        void maybe_accept(parent_t * & , typename parent_t::child_t *);
     185
     186        Stmt * call_accept( const Stmt * );
     187        Expr * call_accept( const Expr * );
     188
     189        template< template <class> class container_t >
    195190        container_t< ptr<Stmt> > call_accept( const container_t< ptr<Stmt> > & );
    196191
    197         template< template <class...> class container_t, typename node_t >
     192        template< template <class> class container_t, typename node_t >
    198193        container_t< ptr<node_t> > call_accept( const container_t< ptr<node_t> > & container );
    199 
    200         /// Logic to call the accept and mutate the parent if needed, delegates call to accept
    201         template<typename node_t, typename parent_t, typename child_t>
    202         void maybe_accept(const node_t * &, child_t parent_t::* child);
    203194
    204195private:
     
    219210
    220211template<typename pass_t>
    221 void accept_all( std::list< ast::ptr<ast::Decl> > &, ast::Pass<pass_t> & visitor );
     212void acceptAll( std::list< ptr<Decl> >, Pass<pass_t>& visitor );
    222213
    223214//-------------------------------------------------------------------------------------------------
    224215// PASS ACCESSORIES
    225216//-------------------------------------------------------------------------------------------------
     217
     218template<typename T>
     219using std_list = std::list<T>;
    226220
    227221/// Keep track of the polymorphic const TypeSubstitution * env for the current expression
     
    232226/// Used if visitor requires added statements before or after the current node.
    233227/// The Pass template handles what *before* and *after* means automatically
    234 template< template<class...> class container_t = std::list >
     228template< template<class> class container_t = std_list >
    235229struct WithStmtsToAdd {
    236230        container_t< ptr<Stmt> > stmtsToAddBefore;
     
    240234/// Used if visitor requires added declarations before or after the current node.
    241235/// The Pass template handles what *before* and *after* means automatically
    242 template< template<class...> class container_t = std::list >
     236template< template<class> class container_t = std_list >
    243237struct WithDeclsToAdd {
    244238        container_t< ptr<Decl> > declsToAddBefore;
     
    292286};
    293287}
    294 
    295 #include "Common/Stats.h"
    296 
    297 extern struct PassVisitorStats {
    298         size_t depth = 0;
    299         Stats::Counters::MaxCounter<double> * max = nullptr;
    300         Stats::Counters::AverageCounter<double> * avg = nullptr;
    301 } pass_visitor_stats;
    302 
    303 #include "AST/Pass.impl.hpp"
  • src/AST/Pass.impl.hpp

    rbe567e9 r62315a0  
    1616#pragma once
    1717// IWYU pragma: private, include "AST/Pass.hpp"
    18 
    19 #include <type_traits>
    20 #include <unordered_map>
    2118
    2219#define VISIT_START( node ) \
     
    2926        __pass::previsit( pass, node, 0 );
    3027
    31 #define VISIT( code... ) \
     28#define VISIT( code ) \
    3229        /* if this node should visit its children */ \
    3330        if ( __visit_children() ) { \
     
    3835#define VISIT_END( type, node ) \
    3936        /* call the implementation of the postvisit of this pass */ \
    40         auto __return = __pass::postvisit( pass, node, 0 ); \
     37        auto __return = __pass::postvisit< type * >( node ); \
    4138        assertf(__return, "post visit should never return null"); \
    4239        return __return;
    4340
    4441#ifdef PEDANTIC_PASS_ASSERT
    45 #define __pedantic_pass_assert(...) assert (__VA_ARGS__)
    46 #define __pedantic_pass_assertf(...) assertf(__VA_ARGS__)
     42#define __pedantic_pass_assert (...) assert (__VAR_ARGS__)
     43#define __pedantic_pass_assertf(...) assertf(__VAR_ARGS__)
    4744#else
    48 #define __pedantic_pass_assert(...)
     45#define __pedantic_pass_assert (...)
    4946#define __pedantic_pass_assertf(...)
    5047#endif
     
    5855                }
    5956
    60                 //------------------------------
    61                 template<typename it_t, template <class...> class container_t>
    62                 static inline void take_all( it_t it, container_t<ast::ptr<ast::Decl>> * decls, bool * mutated = nullptr ) {
     57                template<typename it_t, template <class> class container_t>
     58                static inline void take_all( it_t it, container_t<ast::ptr<ast::Declaration>> * decls, bool * mutated = nullptr ) {
    6359                        if(empty(decls)) return;
    6460
    65                         std::transform(decls->begin(), decls->end(), it, [](const ast::Decl * decl) -> auto {
     61                        std::transform(decls->begin(), decls->end(), it, [](Declaration * decl) -> auto {
    6662                                        return new DeclStmt( decl );
    6763                                });
     
    7066                }
    7167
    72                 template<typename it_t, template <class...> class container_t>
    73                 static inline void take_all( it_t it, container_t<ast::ptr<ast::Stmt>> * decls, bool * mutated = nullptr ) {
     68                template<typename it_t, template <class> class container_t>
     69                static inline void take_all( it_t it, container_t<ast::ptr<ast::Statement>> * decls, bool * mutated = nullptr ) {
    7470                        if(empty(decls)) return;
    7571
     
    7975                }
    8076
    81                 //------------------------------
    82                 /// Check if should be skipped, different for pointers and containers
    8377                template<typename node_t>
    84                 bool skip( const ast::ptr<node_t> & val) {
    85                         return !val;
    86                 }
    87 
    88                 template< template <class...> class container_t, typename node_t >
    89                 bool skip( const container_t<ast::ptr< node_t >> & val ) {
    90                         return val.empty();
    91                 }
    92 
    93                 //------------------------------
    94                 /// Get the value to visit, different for pointers and containers
    95                 template<typename node_t>
    96                 auto get( const ast::ptr<node_t> & val, int ) -> decltype(val.get()) {
    97                         return val.get();
    98                 }
    99 
    100                 template<typename node_t>
    101                 const node_t & get( const node_t & val, long) {
    102                         return val;
    103                 }
    104 
    105 
    106                 //------------------------------
    107                 /// Check if value was mutated, different for pointers and containers
    108                 template<typename lhs_t, typename rhs_t>
    109                 bool differs( const lhs_t * old_val, const rhs_t * new_val ) {
     78                bool differs( const node_t * old_val, const node_t * new_val ) {
    11079                        return old_val != new_val;
    11180                }
    11281
    113                 template< template <class...> class container_t, typename node_t >
    114                 bool differs( const container_t<ast::ptr< node_t >> &, const container_t<ast::ptr< node_t >> & new_val ) {
     82                template< template <class> class container_t >
     83                bool differs( const container_t<ast::ptr< ast::Statement >> &, const container_t<ast::ptr< ast::Statement >> & new_val ) {
    11584                        return !new_val.empty();
    11685                }
    11786        }
    11887
     88        template<typename parent_t, typename child_t>
     89        template< typename pass_t >
     90        void Pass< pass_t >::maybe_accept(
     91                const parent_t * & parent,
     92                const typename parent_t::child_t * child
     93        ) {
     94                const auto & old_val = parent->*child;
     95                if(!old_val) return;
     96
     97                auto new_val = call_accept(old_val);
     98
     99                if( __pass::differs(old_val, new_val) ) {
     100                        auto new_parent = mutate(parent);
     101                        new_parent->*child = new_val;
     102                        parent = new_parent;
     103                }
     104        }
     105
    119106        template< typename pass_t >
    120107        template< typename node_t >
    121         auto Pass< pass_t >::call_accept( const node_t * node ) -> decltype( node->accept(*this) ) {
     108        auto Pass< pass_t >::call_accept( const node_t * node ) {
    122109                __pedantic_pass_assert( __visit_children() );
    123110                __pedantic_pass_assert( expr );
    124111
    125                 static_assert( !std::is_base_of<ast::Expr, node_t>::value, "ERROR");
    126                 static_assert( !std::is_base_of<ast::Stmt, node_t>::value, "ERROR");
    127 
    128112                return node->accept( *this );
    129113        }
    130114
    131115        template< typename pass_t >
    132         const ast::Expr * Pass< pass_t >::call_accept( const ast::Expr * expr ) {
     116        ast::Expr * Pass< pass_t >::call_accept( const ast::Expr * expr ) {
    133117                __pedantic_pass_assert( __visit_children() );
    134118                __pedantic_pass_assert( expr );
     
    143127
    144128        template< typename pass_t >
    145         const ast::Stmt * Pass< pass_t >::call_accept( const ast::Stmt * stmt ) {
     129        Stmt * Pass< pass_t >::call_accept( const Stmt * stmt ) {
    146130                __pedantic_pass_assert( __visit_children() );
    147131                __pedantic_pass_assert( stmt );
     
    157141
    158142                // These may be modified by subnode but most be restored once we exit this statemnet.
    159                 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  );
     143                ValueGuardPtr< const ast::TypeSubstitution * > __old_env         ( __pass::env( pass, 0); );
     144                ValueGuardPtr< typename std::remove_pointer< decltype(stmts_before) > __old_decls_before( stmts_before );
     145                ValueGuardPtr< typename std::remove_pointer< decltype(stmts_after ) > __old_decls_after ( stmts_after  );
     146                ValueGuardPtr< typename std::remove_pointer< decltype(decls_before) > __old_stmts_before( decls_before );
     147                ValueGuardPtr< typename std::remove_pointer< decltype(decls_after ) > __old_stmts_after ( decls_after  );
    164148
    165149                // Now is the time to actually visit the node
    166                 const ast::Stmt * nstmt = stmt->accept( *this );
     150                ast::Statement * nstmt = stmt->accept( *this );
    167151
    168152                // If the pass doesn't want to add anything then we are done
     
    177161
    178162                // Create a new Compound Statement to hold the new decls/stmts
    179                 ast::CompoundStmt * compound = new ast::CompoundStmt( stmt->location );
     163                ast::CompoundStmt * compound = new ast::CompoundStmt( parent->*child.location );
    180164
    181165                // Take all the declarations that go before
     
    184168
    185169                // Insert the original declaration
    186                 compound->kids.emplace_back( nstmt );
     170                compound->kids.push_back( nstmt );
    187171
    188172                // Insert all the declarations that go before
     
    194178
    195179        template< typename pass_t >
    196         template< template <class...> class container_t >
     180        template< template <class> class container_t >
    197181        container_t< ptr<Stmt> > Pass< pass_t >::call_accept( const container_t< ptr<Stmt> > & statements ) {
    198182                __pedantic_pass_assert( __visit_children() );
     
    212196
    213197                // 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  );
     198                ValueGuardPtr< typename std::remove_pointer< decltype(stmts_before) > __old_decls_before( stmts_before );
     199                ValueGuardPtr< typename std::remove_pointer< decltype(stmts_after ) > __old_decls_after ( stmts_after  );
     200                ValueGuardPtr< typename std::remove_pointer< decltype(decls_before) > __old_stmts_before( decls_before );
     201                ValueGuardPtr< typename std::remove_pointer< decltype(decls_after ) > __old_stmts_after ( decls_after  );
    218202
    219203                // update pass statitistics
     
    227211                        try {
    228212                                __pedantic_pass_assert( stmt );
    229                                 const ast::Stmt * new_stmt = stmt->accept( *this );
     213                                const ast::Statment * new_stmt = stmt->accept( visitor );
    230214                                assert( new_stmt );
    231215                                if(new_stmt != stmt ) mutated = true;
     
    256240                if ( !errors.isEmpty() ) { throw errors; }
    257241
    258                 return mutated ? new_kids : container_t< ptr<Stmt> >();
    259         }
    260 
    261         template< typename pass_t >
    262         template< template <class...> class container_t, typename node_t >
     242                return mutated ? new_kids : {};
     243        }
     244
     245        template< typename pass_t >
     246        template< template <class> class container_t, typename node_t >
    263247        container_t< ast::ptr<node_t> > Pass< pass_t >::call_accept( const container_t< ast::ptr<node_t> > & container ) {
    264248                __pedantic_pass_assert( __visit_children() );
     
    275259                        try {
    276260                                __pedantic_pass_assert( node );
    277                                 const node_t * new_stmt = strict_dynamic_cast< const node_t * >( node->accept( *this ) );
    278                                 if(new_stmt != node ) mutated = true;
     261                                const node_t * new_node = strict_dynamic_cast< const node_t * >( node->accept( *this ) );
     262                                if(new_stmt != stmt ) mutated = true;
    279263
    280264                                new_kids.emplace_back( new_stmt );
     
    287271                if ( ! errors.isEmpty() ) { throw errors; }
    288272
    289                 return mutated ? new_kids : container_t< ast::ptr<node_t> >();
    290         }
    291 
    292         template< typename pass_t >
    293         template<typename node_t, typename parent_t, typename child_t>
    294         void Pass< pass_t >::maybe_accept(
    295                 const node_t * & parent,
    296                 child_t parent_t::*child
    297         ) {
    298                 static_assert( std::is_base_of<parent_t, node_t>::value, "Error deductiing member object" );
    299 
    300                 if(__pass::skip(parent->*child)) return;
    301                 const auto & old_val = __pass::get(parent->*child, 0);
    302 
    303                 static_assert( !std::is_same<const ast::Node * &, decltype(old_val)>::value, "ERROR");
    304 
    305                 auto new_val = call_accept( old_val );
    306 
    307                 static_assert( !std::is_same<const ast::Node *, decltype(new_val)>::value || std::is_same<int, decltype(old_val)>::value, "ERROR");
    308 
    309                 if( __pass::differs(old_val, new_val) ) {
    310                         auto new_parent = mutate(parent);
    311                         new_parent->*child = new_val;
    312                         parent = new_parent;
    313                 }
    314         }
    315 
     273                return mutated ? new_kids : {};
     274        }
    316275}
    317276
     
    325284
    326285template< typename pass_t >
    327 inline void ast::accept_all( std::list< ast::ptr<ast::Decl> > & decls, ast::Pass< pass_t > & visitor ) {
     286inline void ast::acceptAll( std::list< ast::ptr<ast::Decl> > & decls, ast::Pass< pass_t > & visitor ) {
    328287        // We are going to aggregate errors for all these statements
    329288        SemanticErrorException errors;
     
    333292
    334293        // get the stmts/decls that will need to be spliced in
    335         auto decls_before = __pass::declsToAddBefore( visitor.pass, 0);
    336         auto decls_after  = __pass::declsToAddAfter ( visitor.pass, 0);
     294        auto decls_before = __pass::declsToAddBefore( pass, 0);
     295        auto decls_after  = __pass::declsToAddAfter ( pass, 0);
    337296
    338297        // update pass statitistics
     
    384343// ObjectDecl
    385344template< typename pass_t >
    386 const ast::DeclWithType * ast::Pass< pass_t >::visit( const ast::ObjectDecl * node ) {
     345ast::DeclWithType * ast::Pass< pass_t >::visit( const ast::ObjectDecl * node ) {
    387346        VISIT_START( node );
    388347
    389348        VISIT(
    390349                {
    391                         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    );
     350                        indexer_guard guard { *this };
     351                        maybe_accept( node, ObjectDecl::type );
     352                }
     353                maybe_accept( node, ObjectDecl::init          );
     354                maybe_accept( node, ObjectDecl::bitfieldWidth );
     355                maybe_accept( node, ObjectDecl::attributes    );
    397356        )
    398357
    399         __pass::indexer::addId( pass, 0, node );
     358        __pass::indexer::AddId( pass, 0, node );
    400359
    401360        VISIT_END( DeclWithType, node );
    402 }
    403 
    404 //--------------------------------------------------------------------------
    405 // SingleInit
    406 template< typename pass_t >
    407 const ast::Init * ast::Pass< pass_t >::visit( const ast::SingleInit * node ) {
    408         VISIT_START( node );
    409 
    410         VISIT(
    411                 maybe_accept( node, &SingleInit::value );
    412         )
    413 
    414         VISIT_END( Init, node );
    415 }
    416 
    417 //--------------------------------------------------------------------------
    418 // ListInit
    419 template< typename pass_t >
    420 const ast::Init * ast::Pass< pass_t >::visit( const ast::ListInit * node ) {
    421         VISIT_START( node );
    422 
    423         VISIT(
    424                 maybe_accept( node, &ListInit::designations );
    425                 maybe_accept( node, &ListInit::initializers );
    426         )
    427 
    428         VISIT_END( Init, node );
    429 }
    430 
    431 //--------------------------------------------------------------------------
    432 // ConstructorInit
    433 template< typename pass_t >
    434 const ast::Init * ast::Pass< pass_t >::visit( const ast::ConstructorInit * node ) {
    435         VISIT_START( node );
    436 
    437         VISIT(
    438                 maybe_accept( node, &ConstructorInit::ctor );
    439                 maybe_accept( node, &ConstructorInit::dtor );
    440                 maybe_accept( node, &ConstructorInit::init );
    441         )
    442 
    443         VISIT_END( Init, node );
    444361}
    445362
    446363//--------------------------------------------------------------------------
    447364// Attribute
    448 template< typename pass_t >
    449 const ast::Attribute * ast::Pass< pass_t >::visit( const ast::Attribute * node  )  {
    450         VISIT_START( node );
     365template< typename pass_type >
     366ast::Attribute * ast::Pass< pass_type >::visit( const ast::Attribute * node  )  {
     367        VISIT_START(node);
    451368
    452369        VISIT(
    453                 maybe_accept( node, &Attribute::parameters );
     370                maybe_accept( node, ast::Attribute::parameters );
    454371        )
    455372
    456         VISIT_END( Attribute *, node );
     373        VISIT_END(ast::Attribute *, node );
    457374}
    458375
    459376//--------------------------------------------------------------------------
    460377// TypeSubstitution
    461 template< typename pass_t >
    462 const ast::TypeSubstitution * ast::Pass< pass_t >::visit( const ast::TypeSubstitution * node ) {
    463         VISIT_START( node );
    464 
    465         VISIT(
    466                 {
    467                         bool mutated = false;
    468                         std::unordered_map< std::string, ast::ptr< ast::Type > > new_map;
    469                         for ( const auto & p : node->typeEnv ) {
    470                                 guard_indexer guard { *this };
    471                                 auto new_node = p.second->accept( *this );
    472                                 if (new_node != p.second) mutated = false;
    473                                 new_map.insert({ p.first, new_node });
    474                         }
    475                         if (mutated) {
    476                                 auto new_node = mutate( node );
    477                                 new_node->typeEnv.swap( new_map );
    478                                 node = new_node;
    479                         }
    480                 }
    481 
    482                 {
    483                         bool mutated = false;
    484                         std::unordered_map< std::string, ast::ptr< ast::Expr > > new_map;
    485                         for ( const auto & p : node->varEnv ) {
    486                                 guard_indexer guard { *this };
    487                                 auto new_node = p.second->accept( *this );
    488                                 if (new_node != p.second) mutated = false;
    489                                 new_map.insert({ p.first, new_node });
    490                         }
    491                         if (mutated) {
    492                                 auto new_node = mutate( node );
    493                                 new_node->varEnv.swap( new_map );
    494                                 node = new_node;
    495                         }
    496                 }
    497         )
    498 
    499         VISIT_END( TypeSubstitution, node );
     378template< typename pass_type >
     379TypeSubstitution * PassVisitor< pass_type >::mutate( const TypeSubstitution * node ) {
     380        MUTATE_START( node );
     381
     382        #error this is broken
     383
     384        for ( auto & p : node->typeEnv ) {
     385                indexerScopedMutate( p.second, *this );
     386        }
     387        for ( auto & p : node->varEnv ) {
     388                indexerScopedMutate( p.second, *this );
     389        }
     390
     391        MUTATE_END( TypeSubstitution, node );
    500392}
    501393
  • src/AST/Pass.proto.hpp

    rbe567e9 r62315a0  
    162162
    163163        // List of fields and their expected types
    164         FIELD_PTR( env, const ast::TypeSubstitution * )
     164        FIELD_PTR( env, const ast::TypeSubstitution )
    165165        FIELD_PTR( stmtsToAddBefore, std::list< ast::ptr< ast::Stmt > > )
    166166        FIELD_PTR( stmtsToAddAfter , std::list< ast::ptr< ast::Stmt > > )
     
    235235                static inline void func( pass_t &, long, type1, type2 ) {}
    236236
    237                 INDEXER_FUNC1( addId     , const DeclWithType *  );
    238                 INDEXER_FUNC1( addType   , const NamedTypeDecl * );
    239                 INDEXER_FUNC1( addStruct , const StructDecl *    );
    240                 INDEXER_FUNC1( addEnum   , const EnumDecl *      );
    241                 INDEXER_FUNC1( addUnion  , const UnionDecl *     );
    242                 INDEXER_FUNC1( addTrait  , const TraitDecl *     );
    243                 INDEXER_FUNC2( addWith   , const std::list< Expression * > &, const Node * );
     237                INDEXER_FUNC1( addId     , DeclWithType *  );
     238                INDEXER_FUNC1( addType   , NamedTypeDecl * );
     239                INDEXER_FUNC1( addStruct , StructDecl *    );
     240                INDEXER_FUNC1( addEnum   , EnumDecl *      );
     241                INDEXER_FUNC1( addUnion  , UnionDecl *     );
     242                INDEXER_FUNC1( addTrait  , TraitDecl *     );
     243                INDEXER_FUNC2( addWith   , std::list< Expression * > &, Node * );
    244244
    245245                // A few extra functions have more complicated behaviour, they are hand written
    246                 template<typename pass_t>
    247                 static inline auto addStructFwd( pass_t & pass, int, const ast::StructDecl * decl ) -> decltype( pass.indexer.addStruct( decl ), void() ) {
    248                         ast::StructDecl * fwd = new ast::StructDecl( decl->location, decl->name );
    249                         fwd->parameters = decl->parameters;
    250                         pass.indexer.addStruct( fwd );
    251                 }
    252 
    253                 template<typename pass_t>
    254                 static inline void addStructFwd( pass_t &, long, const ast::StructDecl * ) {}
    255 
    256                 template<typename pass_t>
    257                 static inline auto addUnionFwd( pass_t & pass, int, const ast::UnionDecl * decl ) -> decltype( pass.indexer.addUnion( decl ), void() ) {
    258                         UnionDecl * fwd = new UnionDecl( decl->location, decl->name );
    259                         fwd->parameters = decl->parameters;
    260                         pass.indexer.addUnion( fwd );
    261                 }
    262 
    263                 template<typename pass_t>
    264                 static inline void addUnionFwd( pass_t &, long, const ast::UnionDecl * ) {}
    265 
    266                 template<typename pass_t>
    267                 static inline auto addStruct( pass_t & pass, int, const std::string & str ) -> decltype( pass.indexer.addStruct( str ), void() ) {
    268                         if ( ! pass.indexer.lookupStruct( str ) ) {
    269                                 pass.indexer.addStruct( str );
    270                         }
    271                 }
    272 
    273                 template<typename pass_t>
    274                 static inline void addStruct( pass_t &, long, const std::string & ) {}
    275 
    276                 template<typename pass_t>
    277                 static inline auto addUnion( pass_t & pass, int, const std::string & str ) -> decltype( pass.indexer.addUnion( str ), void() ) {
    278                         if ( ! pass.indexer.lookupUnion( str ) ) {
    279                                 pass.indexer.addUnion( str );
    280                         }
    281                 }
    282 
    283                 template<typename pass_t>
    284                 static inline void addUnion( pass_t &, long, const std::string & ) {}
     246                // template<typename pass_t>
     247                // static inline auto addStructFwd( pass_t & pass, int, ast::StructDecl * decl ) -> decltype( pass.indexer.addStruct( decl ), void() ) {
     248                //      ast::StructDecl * fwd = new ast::StructDecl( decl->location, decl->name );
     249                //      fwd->parameters = decl->parameters;
     250                //      pass.indexer.addStruct( fwd );
     251                // }
     252
     253                // template<typename pass_t>
     254                // static inline void addStructFwd( pass_t &, long, ast::StructDecl * ) {}
     255
     256                // template<typename pass_t>
     257                // static inline auto addUnionFwd( pass_t & pass, int, ast::UnionDecl * decl ) -> decltype( pass.indexer.addUnion( decl ), void() ) {
     258                //      UnionDecl * fwd = new UnionDecl( decl->name );
     259                //      fwd->parameters = decl->parameters;
     260                //      pass.indexer.addUnion( fwd );
     261                // }
     262
     263                // template<typename pass_t>
     264                // static inline void addUnionFwd( pass_t &, long, ast::UnionDecl * ) {}
     265
     266                // template<typename pass_t>
     267                // static inline auto addStruct( pass_t & pass, int, const std::string & str ) -> decltype( pass.indexer.addStruct( str ), void() ) {
     268                //      if ( ! pass.indexer.lookupStruct( str ) ) {
     269                //              pass.indexer.addStruct( str );
     270                //      }
     271                // }
     272
     273                // template<typename pass_t>
     274                // static inline void addStruct( pass_t &, long, const std::string & ) {}
     275
     276                // template<typename pass_t>
     277                // static inline auto addUnion( pass_t & pass, int, const std::string & str ) -> decltype( pass.indexer.addUnion( str ), void() ) {
     278                //      if ( ! pass.indexer.lookupUnion( str ) ) {
     279                //              pass.indexer.addUnion( str );
     280                //      }
     281                // }
     282
     283                // template<typename pass_t>
     284                // static inline void addUnion( pass_t &, long, const std::string & ) {}
    285285
    286286                #undef INDEXER_FUNC1
  • src/AST/Stmt.hpp

    rbe567e9 r62315a0  
    4040        Stmt(const Stmt& o) : ParseNode(o), labels(o.labels) {}
    4141
    42         virtual const Stmt* accept( Visitor& v ) const override = 0;
     42        virtual Stmt* accept( Visitor& v ) override = 0;
    4343private:
    4444        virtual Stmt* clone() const override = 0;
     
    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        CompoundStmt* accept( Visitor& v ) 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        NullStmt* accept( Visitor& v ) 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        Stmt* accept( Visitor& v ) 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
     
    100100inline void increment( const class ExprStmt * node, Node::ref_type ref ) { node->increment( ref ); }
    101101inline void decrement( const class ExprStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    102 // inline void increment( const class AsmStmt * node, Node::ref_type ref ) { node->increment( ref ); }
    103 // inline void decrement( const class AsmStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    104 // inline void increment( const class DirectiveStmt * node, Node::ref_type ref ) { node->increment( ref ); }
    105 // inline void decrement( const class DirectiveStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    106 // inline void increment( const class IfStmt * node, Node::ref_type ref ) { node->increment( ref ); }
    107 // inline void decrement( const class IfStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    108 // inline void increment( const class WhileStmt * node, Node::ref_type ref ) { node->increment( ref ); }
    109 // inline void decrement( const class WhileStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    110 // inline void increment( const class ForStmt * node, Node::ref_type ref ) { node->increment( ref ); }
    111 // inline void decrement( const class ForStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    112 // inline void increment( const class SwitchStmt * node, Node::ref_type ref ) { node->increment( ref ); }
    113 // inline void decrement( const class SwitchStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    114 // inline void increment( const class CaseStmt * node, Node::ref_type ref ) { node->increment( ref ); }
    115 // inline void decrement( const class CaseStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    116 // inline void increment( const class BranchStmt * node, Node::ref_type ref ) { node->increment( ref ); }
    117 // inline void decrement( const class BranchStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    118 // inline void increment( const class ReturnStmt * node, Node::ref_type ref ) { node->increment( ref ); }
    119 // inline void decrement( const class ReturnStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    120 // inline void increment( const class ThrowStmt * node, Node::ref_type ref ) { node->increment( ref ); }
    121 // inline void decrement( const class ThrowStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    122 // inline void increment( const class TryStmt * node, Node::ref_type ref ) { node->increment( ref ); }
    123 // inline void decrement( const class TryStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    124 // inline void increment( const class CatchStmt * node, Node::ref_type ref ) { node->increment( ref ); }
    125 // inline void decrement( const class CatchStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    126 // inline void increment( const class FinallyStmt * node, Node::ref_type ref ) { node->increment( ref ); }
    127 // inline void decrement( const class FinallyStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    128 // inline void increment( const class WaitForStmt * node, Node::ref_type ref ) { node->increment( ref ); }
    129 // inline void decrement( const class WaitForStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    130 // inline void increment( const class WithStmt * node, Node::ref_type ref ) { node->increment( ref ); }
    131 // inline void decrement( const class WithStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    132 // inline void increment( const class DeclStmt * node, Node::ref_type ref ) { node->increment( ref ); }
    133 // inline void decrement( const class DeclStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
     102inline void increment( const class AsmStmt * node, Node::ref_type ref ) { node->increment( ref ); }
     103inline void decrement( const class AsmStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
     104inline void increment( const class DirectiveStmt * node, Node::ref_type ref ) { node->increment( ref ); }
     105inline void decrement( const class DirectiveStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
     106inline void increment( const class IfStmt * node, Node::ref_type ref ) { node->increment( ref ); }
     107inline void decrement( const class IfStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
     108inline void increment( const class WhileStmt * node, Node::ref_type ref ) { node->increment( ref ); }
     109inline void decrement( const class WhileStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
     110inline void increment( const class ForStmt * node, Node::ref_type ref ) { node->increment( ref ); }
     111inline void decrement( const class ForStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
     112inline void increment( const class SwitchStmt * node, Node::ref_type ref ) { node->increment( ref ); }
     113inline void decrement( const class SwitchStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
     114inline void increment( const class CaseStmt * node, Node::ref_type ref ) { node->increment( ref ); }
     115inline void decrement( const class CaseStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
     116inline void increment( const class BranchStmt * node, Node::ref_type ref ) { node->increment( ref ); }
     117inline void decrement( const class BranchStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
     118inline void increment( const class ReturnStmt * node, Node::ref_type ref ) { node->increment( ref ); }
     119inline void decrement( const class ReturnStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
     120inline void increment( const class ThrowStmt * node, Node::ref_type ref ) { node->increment( ref ); }
     121inline void decrement( const class ThrowStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
     122inline void increment( const class TryStmt * node, Node::ref_type ref ) { node->increment( ref ); }
     123inline void decrement( const class TryStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
     124inline void increment( const class CatchStmt * node, Node::ref_type ref ) { node->increment( ref ); }
     125inline void decrement( const class CatchStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
     126inline void increment( const class FinallyStmt * node, Node::ref_type ref ) { node->increment( ref ); }
     127inline void decrement( const class FinallyStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
     128inline void increment( const class WaitForStmt * node, Node::ref_type ref ) { node->increment( ref ); }
     129inline void decrement( const class WaitForStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
     130inline void increment( const class WithStmt * node, Node::ref_type ref ) { node->increment( ref ); }
     131inline void decrement( const class WithStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
     132inline void increment( const class DeclStmt * node, Node::ref_type ref ) { node->increment( ref ); }
     133inline void decrement( const class DeclStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    134134inline void increment( const class NullStmt * node, Node::ref_type ref ) { node->increment( ref ); }
    135135inline void decrement( const class NullStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    136 // inline void increment( const class ImplicitCtorDtorStmt * node, Node::ref_type ref ) { node->increment( ref ); }
    137 // inline void decrement( const class ImplicitCtorDtorStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
     136inline void increment( const class ImplicitCtorDtorStmt * node, Node::ref_type ref ) { node->increment( ref ); }
     137inline void decrement( const class ImplicitCtorDtorStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    138138
    139139}
  • src/AST/Type.hpp

    rbe567e9 r62315a0  
    2121
    2222class Type : public Node {
    23 public:
    24 virtual const Type * accept( Visitor & v) const = 0;
     23
    2524};
    2625
     
    3231/// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with
    3332/// forward declarations
    34 inline void increment( const class Type * /*node*/, Node::ref_type /*ref*/ ) { /*node->increment( ref );*/ }
    35 inline void decrement( const class Type * /*node*/, Node::ref_type /*ref*/ ) { /*node->decrement( ref );*/ }
    36 // inline void increment( const class VoidType * node, Node::ref_type ref ) { node->increment( ref ); }
    37 // inline void decrement( const class VoidType * node, Node::ref_type ref ) { node->decrement( ref ); }
    38 // inline void increment( const class BasicType * node, Node::ref_type ref ) { node->increment( ref ); }
    39 // inline void decrement( const class BasicType * node, Node::ref_type ref ) { node->decrement( ref ); }
    40 // inline void increment( const class PointerType * node, Node::ref_type ref ) { node->increment( ref ); }
    41 // inline void decrement( const class PointerType * node, Node::ref_type ref ) { node->decrement( ref ); }
    42 // inline void increment( const class ArrayType * node, Node::ref_type ref ) { node->increment( ref ); }
    43 // inline void decrement( const class ArrayType * node, Node::ref_type ref ) { node->decrement( ref ); }
    44 // inline void increment( const class ReferenceType * node, Node::ref_type ref ) { node->increment( ref ); }
    45 // inline void decrement( const class ReferenceType * node, Node::ref_type ref ) { node->decrement( ref ); }
    46 // inline void increment( const class QualifiedType * node, Node::ref_type ref ) { node->increment( ref ); }
    47 // inline void decrement( const class QualifiedType * node, Node::ref_type ref ) { node->decrement( ref ); }
    48 // inline void increment( const class FunctionType * node, Node::ref_type ref ) { node->increment( ref ); }
    49 // inline void decrement( const class FunctionType * node, Node::ref_type ref ) { node->decrement( ref ); }
    50 // inline void increment( const class ReferenceToType * node, Node::ref_type ref ) { node->increment( ref ); }
    51 // inline void decrement( const class ReferenceToType * node, Node::ref_type ref ) { node->decrement( ref ); }
    52 // inline void increment( const class StructInstType * node, Node::ref_type ref ) { node->increment( ref ); }
    53 // inline void decrement( const class StructInstType * node, Node::ref_type ref ) { node->decrement( ref ); }
    54 // inline void increment( const class UnionInstType * node, Node::ref_type ref ) { node->increment( ref ); }
    55 // inline void decrement( const class UnionInstType * node, Node::ref_type ref ) { node->decrement( ref ); }
    56 // inline void increment( const class EnumInstType * node, Node::ref_type ref ) { node->increment( ref ); }
    57 // inline void decrement( const class EnumInstType * node, Node::ref_type ref ) { node->decrement( ref ); }
    58 // inline void increment( const class TraitInstType * node, Node::ref_type ref ) { node->increment( ref ); }
    59 // inline void decrement( const class TraitInstType * node, Node::ref_type ref ) { node->decrement( ref ); }
    60 // inline void increment( const class TypeInstType * node, Node::ref_type ref ) { node->increment( ref ); }
    61 // inline void decrement( const class TypeInstType * node, Node::ref_type ref ) { node->decrement( ref ); }
    62 // inline void increment( const class TupleType * node, Node::ref_type ref ) { node->increment( ref ); }
    63 // inline void decrement( const class TupleType * node, Node::ref_type ref ) { node->decrement( ref ); }
    64 // inline void increment( const class TypeofType * node, Node::ref_type ref ) { node->increment( ref ); }
    65 // inline void decrement( const class TypeofType * node, Node::ref_type ref ) { node->decrement( ref ); }
    66 // inline void increment( const class AttrType * node, Node::ref_type ref ) { node->increment( ref ); }
    67 // inline void decrement( const class AttrType * node, Node::ref_type ref ) { node->decrement( ref ); }
    68 // inline void increment( const class VarArgsType * node, Node::ref_type ref ) { node->increment( ref ); }
    69 // inline void decrement( const class VarArgsType * node, Node::ref_type ref ) { node->decrement( ref ); }
    70 // inline void increment( const class ZeroType * node, Node::ref_type ref ) { node->increment( ref ); }
    71 // inline void decrement( const class ZeroType * node, Node::ref_type ref ) { node->decrement( ref ); }
    72 // inline void increment( const class OneType * node, Node::ref_type ref ) { node->increment( ref ); }
    73 // inline void decrement( const class OneType * node, Node::ref_type ref ) { node->decrement( ref ); }
    74 // inline void increment( const class GlobalScopeType * node, Node::ref_type ref ) { node->increment( ref ); }
    75 // inline void decrement( const class GlobalScopeType * node, Node::ref_type ref ) { node->decrement( ref ); }
     33inline void increment( const class Type * node, Node::ref_type ref ) { node->increment( ref ); }
     34inline void decrement( const class Type * node, Node::ref_type ref ) { node->decrement( ref ); }
     35inline void increment( const class VoidType * node, Node::ref_type ref ) { node->increment( ref ); }
     36inline void decrement( const class VoidType * node, Node::ref_type ref ) { node->decrement( ref ); }
     37inline void increment( const class BasicType * node, Node::ref_type ref ) { node->increment( ref ); }
     38inline void decrement( const class BasicType * node, Node::ref_type ref ) { node->decrement( ref ); }
     39inline void increment( const class PointerType * node, Node::ref_type ref ) { node->increment( ref ); }
     40inline void decrement( const class PointerType * node, Node::ref_type ref ) { node->decrement( ref ); }
     41inline void increment( const class ArrayType * node, Node::ref_type ref ) { node->increment( ref ); }
     42inline void decrement( const class ArrayType * node, Node::ref_type ref ) { node->decrement( ref ); }
     43inline void increment( const class ReferenceType * node, Node::ref_type ref ) { node->increment( ref ); }
     44inline void decrement( const class ReferenceType * node, Node::ref_type ref ) { node->decrement( ref ); }
     45inline void increment( const class QualifiedType * node, Node::ref_type ref ) { node->increment( ref ); }
     46inline void decrement( const class QualifiedType * node, Node::ref_type ref ) { node->decrement( ref ); }
     47inline void increment( const class FunctionType * node, Node::ref_type ref ) { node->increment( ref ); }
     48inline void decrement( const class FunctionType * node, Node::ref_type ref ) { node->decrement( ref ); }
     49inline void increment( const class ReferenceToType * node, Node::ref_type ref ) { node->increment( ref ); }
     50inline void decrement( const class ReferenceToType * node, Node::ref_type ref ) { node->decrement( ref ); }
     51inline void increment( const class StructInstType * node, Node::ref_type ref ) { node->increment( ref ); }
     52inline void decrement( const class StructInstType * node, Node::ref_type ref ) { node->decrement( ref ); }
     53inline void increment( const class UnionInstType * node, Node::ref_type ref ) { node->increment( ref ); }
     54inline void decrement( const class UnionInstType * node, Node::ref_type ref ) { node->decrement( ref ); }
     55inline void increment( const class EnumInstType * node, Node::ref_type ref ) { node->increment( ref ); }
     56inline void decrement( const class EnumInstType * node, Node::ref_type ref ) { node->decrement( ref ); }
     57inline void increment( const class TraitInstType * node, Node::ref_type ref ) { node->increment( ref ); }
     58inline void decrement( const class TraitInstType * node, Node::ref_type ref ) { node->decrement( ref ); }
     59inline void increment( const class TypeInstType * node, Node::ref_type ref ) { node->increment( ref ); }
     60inline void decrement( const class TypeInstType * node, Node::ref_type ref ) { node->decrement( ref ); }
     61inline void increment( const class TupleType * node, Node::ref_type ref ) { node->increment( ref ); }
     62inline void decrement( const class TupleType * node, Node::ref_type ref ) { node->decrement( ref ); }
     63inline void increment( const class TypeofType * node, Node::ref_type ref ) { node->increment( ref ); }
     64inline void decrement( const class TypeofType * node, Node::ref_type ref ) { node->decrement( ref ); }
     65inline void increment( const class AttrType * node, Node::ref_type ref ) { node->increment( ref ); }
     66inline void decrement( const class AttrType * node, Node::ref_type ref ) { node->decrement( ref ); }
     67inline void increment( const class VarArgsType * node, Node::ref_type ref ) { node->increment( ref ); }
     68inline void decrement( const class VarArgsType * node, Node::ref_type ref ) { node->decrement( ref ); }
     69inline void increment( const class ZeroType * node, Node::ref_type ref ) { node->increment( ref ); }
     70inline void decrement( const class ZeroType * node, Node::ref_type ref ) { node->decrement( ref ); }
     71inline void increment( const class OneType * node, Node::ref_type ref ) { node->increment( ref ); }
     72inline void decrement( const class OneType * node, Node::ref_type ref ) { node->decrement( ref ); }
     73inline void increment( const class GlobalScopeType * node, Node::ref_type ref ) { node->increment( ref ); }
     74inline void decrement( const class GlobalScopeType * node, Node::ref_type ref ) { node->decrement( ref ); }
    7675
    7776}
  • src/AST/Visitor.hpp

    rbe567e9 r62315a0  
    2222class Visitor {
    2323public:
    24     virtual const ast::DeclWithType *     visit( const ast::ObjectDecl           * ) = 0;
    25     virtual const ast::DeclWithType *     visit( const ast::FunctionDecl         * ) = 0;
    26     virtual const ast::Decl *             visit( const ast::StructDecl           * ) = 0;
    27     virtual const ast::Decl *             visit( const ast::UnionDecl            * ) = 0;
    28     virtual const ast::Decl *             visit( const ast::EnumDecl             * ) = 0;
    29     virtual const ast::Decl *             visit( const ast::TraitDecl            * ) = 0;
    30     virtual const ast::Decl *             visit( const ast::TypeDecl             * ) = 0;
    31     virtual const ast::Decl *             visit( const ast::TypedefDecl          * ) = 0;
    32     virtual const ast::AsmDecl *          visit( const ast::AsmDecl              * ) = 0;
    33     virtual const ast::StaticAssertDecl * visit( const ast::StaticAssertDecl     * ) = 0;
    34     virtual const ast::CompoundStmt *     visit( const ast::CompoundStmt         * ) = 0;
    35     virtual const ast::Stmt *             visit( const ast::ExprStmt             * ) = 0;
    36     virtual const ast::Stmt *             visit( const ast::AsmStmt              * ) = 0;
    37     virtual const ast::Stmt *             visit( const ast::DirectiveStmt        * ) = 0;
    38     virtual const ast::Stmt *             visit( const ast::IfStmt               * ) = 0;
    39     virtual const ast::Stmt *             visit( const ast::WhileStmt            * ) = 0;
    40     virtual const ast::Stmt *             visit( const ast::ForStmt              * ) = 0;
    41     virtual const ast::Stmt *             visit( const ast::SwitchStmt           * ) = 0;
    42     virtual const ast::Stmt *             visit( const ast::CaseStmt             * ) = 0;
    43     virtual const ast::Stmt *             visit( const ast::BranchStmt           * ) = 0;
    44     virtual const ast::Stmt *             visit( const ast::ReturnStmt           * ) = 0;
    45     virtual const ast::Stmt *             visit( const ast::ThrowStmt            * ) = 0;
    46     virtual const ast::Stmt *             visit( const ast::TryStmt              * ) = 0;
    47     virtual const ast::Stmt *             visit( const ast::CatchStmt            * ) = 0;
    48     virtual const ast::Stmt *             visit( const ast::FinallyStmt          * ) = 0;
    49     virtual const ast::Stmt *             visit( const ast::WaitForStmt          * ) = 0;
    50     virtual const ast::Stmt *             visit( const ast::WithStmt             * ) = 0;
    51     virtual const ast::NullStmt *         visit( const ast::NullStmt             * ) = 0;
    52     virtual const ast::Stmt *             visit( const ast::DeclStmt             * ) = 0;
    53     virtual const ast::Stmt *             visit( const ast::ImplicitCtorDtorStmt * ) = 0;
    54     virtual const ast::Expr *             visit( const ast::ApplicationExpr      * ) = 0;
    55     virtual const ast::Expr *             visit( const ast::UntypedExpr          * ) = 0;
    56     virtual const ast::Expr *             visit( const ast::NameExpr             * ) = 0;
    57     virtual const ast::Expr *             visit( const ast::AddressExpr          * ) = 0;
    58     virtual const ast::Expr *             visit( const ast::LabelAddressExpr     * ) = 0;
    59     virtual const ast::Expr *             visit( const ast::CastExpr             * ) = 0;
    60     virtual const ast::Expr *             visit( const ast::KeywordCastExpr      * ) = 0;
    61     virtual const ast::Expr *             visit( const ast::VirtualCastExpr      * ) = 0;
    62     virtual const ast::Expr *             visit( const ast::UntypedMemberExpr    * ) = 0;
    63     virtual const ast::Expr *             visit( const ast::MemberExpr           * ) = 0;
    64     virtual const ast::Expr *             visit( const ast::VariableExpr         * ) = 0;
    65     virtual const ast::Expr *             visit( const ast::ConstantExpr         * ) = 0;
    66     virtual const ast::Expr *             visit( const ast::SizeofExpr           * ) = 0;
    67     virtual const ast::Expr *             visit( const ast::AlignofExpr          * ) = 0;
    68     virtual const ast::Expr *             visit( const ast::UntypedOffsetofExpr  * ) = 0;
    69     virtual const ast::Expr *             visit( const ast::OffsetofExpr         * ) = 0;
    70     virtual const ast::Expr *             visit( const ast::OffsetPackExpr       * ) = 0;
    71     virtual const ast::Expr *             visit( const ast::AttrExpr             * ) = 0;
    72     virtual const ast::Expr *             visit( const ast::LogicalExpr          * ) = 0;
    73     virtual const ast::Expr *             visit( const ast::ConditionalExpr      * ) = 0;
    74     virtual const ast::Expr *             visit( const ast::CommaExpr            * ) = 0;
    75     virtual const ast::Expr *             visit( const ast::TypeExpr             * ) = 0;
    76     virtual const ast::Expr *             visit( const ast::AsmExpr              * ) = 0;
    77     virtual const ast::Expr *             visit( const ast::ImplicitCopyCtorExpr * ) = 0;
    78     virtual const ast::Expr *             visit( const ast::ConstructorExpr      * ) = 0;
    79     virtual const ast::Expr *             visit( const ast::CompoundLiteralExpr  * ) = 0;
    80     virtual const ast::Expr *             visit( const ast::RangeExpr            * ) = 0;
    81     virtual const ast::Expr *             visit( const ast::UntypedTupleExpr     * ) = 0;
    82     virtual const ast::Expr *             visit( const ast::TupleExpr            * ) = 0;
    83     virtual const ast::Expr *             visit( const ast::TupleIndexExpr       * ) = 0;
    84     virtual const ast::Expr *             visit( const ast::TupleAssignExpr      * ) = 0;
    85     virtual const ast::Expr *             visit( const ast::StmtExpr             * ) = 0;
    86     virtual const ast::Expr *             visit( const ast::UniqueExpr           * ) = 0;
    87     virtual const ast::Expr *             visit( const ast::UntypedInitExpr      * ) = 0;
    88     virtual const ast::Expr *             visit( const ast::InitExpr             * ) = 0;
    89     virtual const ast::Expr *             visit( const ast::DeletedExpr          * ) = 0;
    90     virtual const ast::Expr *             visit( const ast::DefaultArgExpr       * ) = 0;
    91     virtual const ast::Expr *             visit( const ast::GenericExpr          * ) = 0;
    92     virtual const ast::Type *             visit( const ast::VoidType             * ) = 0;
    93     virtual const ast::Type *             visit( const ast::BasicType            * ) = 0;
    94     virtual const ast::Type *             visit( const ast::PointerType          * ) = 0;
    95     virtual const ast::Type *             visit( const ast::ArrayType            * ) = 0;
    96     virtual const ast::Type *             visit( const ast::ReferenceType        * ) = 0;
    97     virtual const ast::Type *             visit( const ast::QualifiedType        * ) = 0;
    98     virtual const ast::Type *             visit( const ast::FunctionType         * ) = 0;
    99     virtual const ast::Type *             visit( const ast::StructInstType       * ) = 0;
    100     virtual const ast::Type *             visit( const ast::UnionInstType        * ) = 0;
    101     virtual const ast::Type *             visit( const ast::EnumInstType         * ) = 0;
    102     virtual const ast::Type *             visit( const ast::TraitInstType        * ) = 0;
    103     virtual const ast::Type *             visit( const ast::TypeInstType         * ) = 0;
    104     virtual const ast::Type *             visit( const ast::TupleType            * ) = 0;
    105     virtual const ast::Type *             visit( const ast::TypeofType           * ) = 0;
    106     virtual const ast::Type *             visit( const ast::AttrType             * ) = 0;
    107     virtual const ast::Type *             visit( const ast::VarArgsType          * ) = 0;
    108     virtual const ast::Type *             visit( const ast::ZeroType             * ) = 0;
    109     virtual const ast::Type *             visit( const ast::OneType              * ) = 0;
    110     virtual const ast::Type *             visit( const ast::GlobalScopeType      * ) = 0;
    111     virtual const ast::Designation *      visit( const ast::Designation          * ) = 0;
    112     virtual const ast::Init *             visit( const ast::SingleInit           * ) = 0;
    113     virtual const ast::Init *             visit( const ast::ListInit             * ) = 0;
    114     virtual const ast::Init *             visit( const ast::ConstructorInit      * ) = 0;
    115     virtual const ast::Constant *         visit( const ast::Constant             * ) = 0;
    116     virtual const ast::Attribute *        visit( const ast::Attribute            * ) = 0;
    117     virtual const ast::TypeSubstitution * visit( const ast::TypeSubstitution     * ) = 0;
     24    virtual DeclWithType *     visit( const ObjectDecl           * ) = 0;
     25    virtual DeclWithType *     visit( const FunctionDecl         * ) = 0;
     26    virtual Decl *             visit( const StructDecl           * ) = 0;
     27    virtual Decl *             visit( const UnionDecl            * ) = 0;
     28    virtual Decl *             visit( const EnumDecl             * ) = 0;
     29    virtual Decl *             visit( const TraitDecl            * ) = 0;
     30    virtual Decl *             visit( const TypeDecl             * ) = 0;
     31    virtual Decl *             visit( const TypedefDecl          * ) = 0;
     32    virtual AsmDecl *          visit( const AsmDecl              * ) = 0;
     33    virtual StaticAssertDecl * visit( const StaticAssertDecl     * ) = 0;
     34    virtual CompoundStmt *     visit( const CompoundStmt         * ) = 0;
     35    virtual Stmt *             visit( const ExprStmt             * ) = 0;
     36    virtual Stmt *             visit( const AsmStmt              * ) = 0;
     37    virtual Stmt *             visit( const DirectiveStmt        * ) = 0;
     38    virtual Stmt *             visit( const IfStmt               * ) = 0;
     39    virtual Stmt *             visit( const WhileStmt            * ) = 0;
     40    virtual Stmt *             visit( const ForStmt              * ) = 0;
     41    virtual Stmt *             visit( const SwitchStmt           * ) = 0;
     42    virtual Stmt *             visit( const CaseStmt             * ) = 0;
     43    virtual Stmt *             visit( const BranchStmt           * ) = 0;
     44    virtual Stmt *             visit( const ReturnStmt           * ) = 0;
     45    virtual Stmt *             visit( const ThrowStmt            * ) = 0;
     46    virtual Stmt *             visit( const TryStmt              * ) = 0;
     47    virtual Stmt *             visit( const CatchStmt            * ) = 0;
     48    virtual Stmt *             visit( const FinallyStmt          * ) = 0;
     49    virtual Stmt *             visit( const WaitForStmt          * ) = 0;
     50    virtual Stmt *             visit( const WithStmt             * ) = 0;
     51    virtual NullStmt *         visit( const NullStmt             * ) = 0;
     52    virtual Stmt *             visit( const DeclStmt             * ) = 0;
     53    virtual Stmt *             visit( const ImplicitCtorDtorStmt * ) = 0;
     54    virtual Expr *             visit( const ApplicationExpr      * ) = 0;
     55    virtual Expr *             visit( const UntypedExpr          * ) = 0;
     56    virtual Expr *             visit( const NameExpr             * ) = 0;
     57    virtual Expr *             visit( const AddressExpr          * ) = 0;
     58    virtual Expr *             visit( const LabelAddressExpr     * ) = 0;
     59    virtual Expr *             visit( const CastExpr             * ) = 0;
     60    virtual Expr *             visit( const KeywordCastExpr      * ) = 0;
     61    virtual Expr *             visit( const VirtualCastExpr      * ) = 0;
     62    virtual Expr *             visit( const UntypedMemberExpr    * ) = 0;
     63    virtual Expr *             visit( const MemberExpr           * ) = 0;
     64    virtual Expr *             visit( const VariableExpr         * ) = 0;
     65    virtual Expr *             visit( const ConstantExpr         * ) = 0;
     66    virtual Expr *             visit( const SizeofExpr           * ) = 0;
     67    virtual Expr *             visit( const AlignofExpr          * ) = 0;
     68    virtual Expr *             visit( const UntypedOffsetofExpr  * ) = 0;
     69    virtual Expr *             visit( const OffsetofExpr         * ) = 0;
     70    virtual Expr *             visit( const OffsetPackExpr       * ) = 0;
     71    virtual Expr *             visit( const AttrExpr             * ) = 0;
     72    virtual Expr *             visit( const LogicalExpr          * ) = 0;
     73    virtual Expr *             visit( const ConditionalExpr      * ) = 0;
     74    virtual Expr *             visit( const CommaExpr            * ) = 0;
     75    virtual Expr *             visit( const TypeExpr             * ) = 0;
     76    virtual Expr *             visit( const AsmExpr              * ) = 0;
     77    virtual Expr *             visit( const ImplicitCopyCtorExpr * ) = 0;
     78    virtual Expr *             visit( const ConstructorExpr      * ) = 0;
     79    virtual Expr *             visit( const CompoundLiteralExpr  * ) = 0;
     80    virtual Expr *             visit( const RangeExpr            * ) = 0;
     81    virtual Expr *             visit( const UntypedTupleExpr     * ) = 0;
     82    virtual Expr *             visit( const TupleExpr            * ) = 0;
     83    virtual Expr *             visit( const TupleIndexExpr       * ) = 0;
     84    virtual Expr *             visit( const TupleAssignExpr      * ) = 0;
     85    virtual Expr *             visit( const StmtExpr             * ) = 0;
     86    virtual Expr *             visit( const UniqueExpr           * ) = 0;
     87    virtual Expr *             visit( const UntypedInitExpr      * ) = 0;
     88    virtual Expr *             visit( const InitExpr             * ) = 0;
     89    virtual Expr *             visit( const DeletedExpr          * ) = 0;
     90    virtual Expr *             visit( const DefaultArgExpr       * ) = 0;
     91    virtual Expr *             visit( const GenericExpr          * ) = 0;
     92    virtual Type *             visit( const VoidType             * ) = 0;
     93    virtual Type *             visit( const BasicType            * ) = 0;
     94    virtual Type *             visit( const PointerType          * ) = 0;
     95    virtual Type *             visit( const ArrayType            * ) = 0;
     96    virtual Type *             visit( const ReferenceType        * ) = 0;
     97    virtual Type *             visit( const QualifiedType        * ) = 0;
     98    virtual Type *             visit( const FunctionType         * ) = 0;
     99    virtual Type *             visit( const StructInstType       * ) = 0;
     100    virtual Type *             visit( const UnionInstType        * ) = 0;
     101    virtual Type *             visit( const EnumInstType         * ) = 0;
     102    virtual Type *             visit( const TraitInstType        * ) = 0;
     103    virtual Type *             visit( const TypeInstType         * ) = 0;
     104    virtual Type *             visit( const TupleType            * ) = 0;
     105    virtual Type *             visit( const TypeofType           * ) = 0;
     106    virtual Type *             visit( const AttrType             * ) = 0;
     107    virtual Type *             visit( const VarArgsType          * ) = 0;
     108    virtual Type *             visit( const ZeroType             * ) = 0;
     109    virtual Type *             visit( const OneType              * ) = 0;
     110    virtual Type *             visit( const GlobalScopeType      * ) = 0;
     111    virtual Designation *      visit( const Designation          * ) = 0;
     112    virtual Init *             visit( const SingleInit           * ) = 0;
     113    virtual Init *             visit( const ListInit             * ) = 0;
     114    virtual Init *             visit( const ConstructorInit      * ) = 0;
     115    virtual Constant *         visit( const Constant             * ) = 0;
     116    virtual Attribute *        visit( const Attribute            * ) = 0;
     117    virtual TypeSubstitution * visit( const TypeSubstitution     * ) = 0;
    118118};
    119119
  • src/AST/porting.md

    rbe567e9 r62315a0  
    1010## Visitors ##
    1111* `Visitor` and `Mutator` are combined into a single `ast::Visitor` class
    12   * Base nodes now override `const Node * accept( Visitor & v ) const = 0` with, e.g. `const Stmt * accept( Visitor & v ) const override = 0`
     12  * Base nodes now override `Node* accept( Visitor& v ) = 0` with, e.g. `Stmt* accept( Visitor& v ) override = 0`
    1313* `PassVisitor` is replaced with `ast::Pass`
    1414
     
    2626`clone` is private to `Node` now
    2727* still needs to be overriden to return appropriate type
    28   * e.g. `private: virtual Stmt * clone() const override = 0;`
    29   * because friendship is not inherited, all implementations of clone need
    30       /// Must be copied in ALL derived classes
    31       template<typename node_t>
    32       friend auto mutate(const node_t * node);
     28  * e.g. `private: virtual Stmt* clone() const override = 0;`
    3329
    3430All leaves of the `Node` inheritance tree are now declared `final`
  • src/Common/PassVisitor.h

    rbe567e9 r62315a0  
    155155        virtual void visit( ConstructorInit * ctorInit ) override final;
    156156
     157        virtual void visit( Subrange * subrange ) override final;
     158
    157159        virtual void visit( Constant * constant ) override final;
    158160
     
    255257        virtual Initializer * mutate( ConstructorInit * ctorInit ) override final;
    256258
     259        virtual Subrange * mutate( Subrange * subrange ) override final;
     260
    257261        virtual Constant * mutate( Constant * constant ) override final;
    258262
  • src/Common/PassVisitor.impl.h

    rbe567e9 r62315a0  
    27122712
    27132713//--------------------------------------------------------------------------
     2714// Subrange
     2715template< typename pass_type >
     2716void PassVisitor< pass_type >::visit( Subrange * node ) {
     2717        VISIT_START( node );
     2718
     2719        VISIT_END( node );
     2720}
     2721
     2722template< typename pass_type >
     2723Subrange * PassVisitor< pass_type >::mutate( Subrange * node  )  {
     2724        MUTATE_START( node );
     2725
     2726        MUTATE_END( Subrange, node );
     2727}
     2728
     2729//--------------------------------------------------------------------------
    27142730// Attribute
    27152731template< typename pass_type >
  • src/SynTree/Declaration.h

    rbe567e9 r62315a0  
    245245        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    246246
     247  private:
    247248        Kind kind;
    248249};
     
    305306        virtual void accept( Visitor &v ) override { v.visit( this ); }
    306307        virtual Declaration *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
     308  private:
    307309        DeclarationNode::Aggregate kind;
    308   private:
    309310        virtual std::string typeString() const override;
    310311};
  • src/SynTree/Label.h

    rbe567e9 r62315a0  
    3535        operator std::string() const { return name; }
    3636        bool empty() { return name.empty(); }
    37 
     37  private:
    3838        std::string name;
    3939        Statement * labelled;
  • src/SynTree/Mutator.h

    rbe567e9 r62315a0  
    121121        virtual Initializer * mutate( ConstructorInit * ctorInit ) = 0 ;
    122122
     123        virtual Subrange * mutate( Subrange * subrange ) = 0;
     124
    123125        virtual Constant * mutate( Constant * constant ) = 0;
    124126
  • src/SynTree/SynTree.h

    rbe567e9 r62315a0  
    132132class ConstructorInit;
    133133
     134class Subrange;
     135
    134136//template <class T>    // emulate a union with templates?
    135137class Constant;
  • src/SynTree/Visitor.h

    rbe567e9 r62315a0  
    123123        virtual void visit( ConstructorInit * ctorInit ) = 0;
    124124
     125        virtual void visit( Subrange * subrange ) = 0;
     126
    125127        virtual void visit( Constant * constant ) = 0;
    126128
Note: See TracChangeset for help on using the changeset viewer.