Changes in / [c671112:41b24c8]


Ignore:
Location:
src
Files:
1 added
20 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Attribute.hpp

    rc671112 r41b24c8  
    5050        /// Must be copied in ALL derived classes
    5151        template<typename node_t>
    52         friend auto mutate(const node_t * node);
     52        friend node_t * mutate(const node_t * node);
    5353};
    5454
    55 
    56 
    57 //=================================================================================================
    58 /// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency
    59 /// remove only if there is a better solution
    60 /// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with
    61 /// forward declarations
    62 inline void increment( const class Attribute * node, Node::ref_type ref ) { node->increment( ref ); }
    63 inline void decrement( const class Attribute * node, Node::ref_type ref ) { node->decrement( ref ); }
    6455}
    6556
  • src/AST/Convert.cpp

    rc671112 r41b24c8  
    230230
    231231                decl->assertions = asserts;
    232                 decl->params = params;
     232                decl->params     = params;
    233233                decl->extension  = old->extension;
    234234                decl->uniqueId   = old->uniqueId;
  • src/AST/Decl.cpp

    rc671112 r41b24c8  
    2020#include <unordered_map>
    2121
     22#include "Common/utility.h"
     23
    2224#include "Fwd.hpp"             // for UniqueId
    2325#include "Init.hpp"
    2426#include "Node.hpp"            // for readonly
     27#include "Type.hpp"            // for readonly
    2528#include "Parser/ParseNode.h"  // for DeclarationNode
    2629
     
    4750// --- FunctionDecl
    4851
    49 const Type * FunctionDecl::get_type() const override { return type.get(); }
    50 void FunctionDecl::set_type(Type * t) override { type = strict_dynamic_cast< FunctionType* >( t ); }
     52const Type * FunctionDecl::get_type() const { return type.get(); }
     53void FunctionDecl::set_type(Type * t) { type = strict_dynamic_cast< FunctionType* >( t ); }
    5154
    5255// --- TypeDecl
     
    7578                        const ObjectDecl* field = strict_dynamic_cast< const ObjectDecl* >( member );
    7679                        if ( field->init ) {
    77                                 const SingleInit* init = strict_dynamic_cast< const SingleInit* >( field->init );
     80                                const SingleInit * init = strict_dynamic_cast< const SingleInit* >( field->init.get() );
    7881                                auto result = eval( init->value );
    7982                                if ( ! result.second ) {
  • src/AST/Decl.hpp

    rc671112 r41b24c8  
    3131
    3232// Must be included in *all* AST classes; should be #undef'd at the end of the file
    33 #define MUTATE_FRIEND template<typename node_t> friend auto mutate(const node_t * node);
     33#define MUTATE_FRIEND template<typename node_t> friend node_t * mutate(const node_t * node);
    3434
    3535namespace ast {
     
    341341};
    342342
    343 //=================================================================================================
    344 /// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency
    345 /// remove only if there is a better solution
    346 /// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with
    347 /// forward declarations
    348 inline void increment( const class Decl * node, Node::ref_type ref ) { node->increment(ref); }
    349 inline void decrement( const class Decl * node, Node::ref_type ref ) { node->decrement(ref); }
    350 inline void increment( const class DeclWithType * node, Node::ref_type ref ) { node->increment(ref); }
    351 inline void decrement( const class DeclWithType * node, Node::ref_type ref ) { node->decrement(ref); }
    352 inline void increment( const class ObjectDecl * node, Node::ref_type ref ) { node->increment(ref); }
    353 inline void decrement( const class ObjectDecl * node, Node::ref_type ref ) { node->decrement(ref); }
    354 inline void increment( const class FunctionDecl * node, Node::ref_type ref ) { node->increment(ref); }
    355 inline void decrement( const class FunctionDecl * node, Node::ref_type ref ) { node->decrement(ref); }
    356 inline void increment( const class AggregateDecl * node, Node::ref_type ref ) { node->increment(ref); }
    357 inline void decrement( const class AggregateDecl * node, Node::ref_type ref ) { node->decrement(ref); }
    358 inline void increment( const class StructDecl * node, Node::ref_type ref ) { node->increment(ref); }
    359 inline void decrement( const class StructDecl * node, Node::ref_type ref ) { node->decrement(ref); }
    360 inline void increment( const class UnionDecl * node, Node::ref_type ref ) { node->increment(ref); }
    361 inline void decrement( const class UnionDecl * node, Node::ref_type ref ) { node->decrement(ref); }
    362 inline void increment( const class EnumDecl * node, Node::ref_type ref ) { node->increment(ref); }
    363 inline void decrement( const class EnumDecl * node, Node::ref_type ref ) { node->decrement(ref); }
    364 inline void increment( const class TraitDecl * node, Node::ref_type ref ) { node->increment(ref); }
    365 inline void decrement( const class TraitDecl * node, Node::ref_type ref ) { node->decrement(ref); }
    366 inline void increment( const class NamedTypeDecl * node, Node::ref_type ref ) { node->increment(ref); }
    367 inline void decrement( const class NamedTypeDecl * node, Node::ref_type ref ) { node->decrement(ref); }
    368 inline void increment( const class TypeDecl * node, Node::ref_type ref ) { node->increment(ref); }
    369 inline void decrement( const class TypeDecl * node, Node::ref_type ref ) { node->decrement(ref); }
    370 inline void increment( const class TypedefDecl * node, Node::ref_type ref ) { node->increment(ref); }
    371 inline void decrement( const class TypedefDecl * node, Node::ref_type ref ) { node->decrement(ref); }
    372 inline void increment( const class AsmDecl * node, Node::ref_type ref ) { node->increment(ref); }
    373 inline void decrement( const class AsmDecl * node, Node::ref_type ref ) { node->decrement(ref); }
    374 inline void increment( const class StaticAssertDecl * node, Node::ref_type ref ) { node->increment(ref); }
    375 inline void decrement( const class StaticAssertDecl * node, Node::ref_type ref ) { node->decrement(ref); }
    376 
    377343}
    378344
  • src/AST/Expr.cpp

    rc671112 r41b24c8  
    3030// --- ApplicationExpr
    3131
    32 ApplicationExpr::ApplicationExpr( const CodeLocation & loc, const Expr * f, 
    33         std::vector<ptr<Expr>> && as ) 
    34 : Expr( loc ), func( f ), args( std::move(args) ) {
     32ApplicationExpr::ApplicationExpr( const CodeLocation & loc, const Expr * f,
     33        std::vector<ptr<Expr>> && as )
     34: Expr( loc ), func( f ), args( std::move(as) ) {
    3535        // ensure that `ApplicationExpr` result type is `FuncExpr`
    3636        const PointerType * pt = strict_dynamic_cast< const PointerType * >( f->result.get() );
     
    4646        assert( arg );
    4747
    48         UntypedExpr * ret = new UntypedExpr{ 
    49                 loc, new NameExpr{loc, "*?"}, std::vector<ptr<Expr>>{ ptr<Expr>{ arg } } 
     48        UntypedExpr * ret = new UntypedExpr{
     49                loc, new NameExpr{loc, "*?"}, std::vector<ptr<Expr>>{ ptr<Expr>{ arg } }
    5050        };
    5151        if ( const Type * ty = arg->result ) {
     
    5757                        ret->result = new ReferenceType{ base };
    5858                } else {
    59                         // references have been removed, in which case dereference returns an lvalue of the 
     59                        // references have been removed, in which case dereference returns an lvalue of the
    6060                        // base type
    6161                        ret->result.set_and_mutate( base )->set_lvalue( true );
     
    110110                } else {
    111111                        // taking address of non-lvalue, must be a reference, loses one layer of reference
    112                         if ( const ReferenceType * refType = 
     112                        if ( const ReferenceType * refType =
    113113                                        dynamic_cast< const ReferenceType * >( arg->result.get() ) ) {
    114114                                Type * res = addrType( refType->base );
     
    116116                                result = res;
    117117                        } else {
    118                                 SemanticError( loc, arg->result, 
     118                                SemanticError( loc, arg->result,
    119119                                        "Attempt to take address of non-lvalue expression: " );
    120120                        }
     
    126126
    127127// label address always has type `void*`
    128 LabelAddressExpr::LabelAddressExpr( const CodeLocation & loc, Label && a ) 
     128LabelAddressExpr::LabelAddressExpr( const CodeLocation & loc, Label && a )
    129129: Expr( loc, new PointerType{ new VoidType{} } ), arg( a ) {}
    130130
    131131// --- CastExpr
    132132
    133 CastExpr::CastExpr( const CodeLocation & loc, const Expr * a, GeneratedFlag g ) 
     133CastExpr::CastExpr( const CodeLocation & loc, const Expr * a, GeneratedFlag g )
    134134: Expr( loc, new VoidType{} ), arg( a ), isGenerated( g ) {}
    135135
     
    167167}
    168168
    169 VariableExpr * VariableExpr::functionPointer( 
     169VariableExpr * VariableExpr::functionPointer(
    170170                const CodeLocation & loc, const FunctionDecl * decl ) {
    171171        // wrap usually-determined result type in a pointer
     
    200200
    201201ConstantExpr * ConstantExpr::from_bool( const CodeLocation & loc, bool b ) {
    202         return new ConstantExpr{ 
     202        return new ConstantExpr{
    203203                loc, new BasicType{ BasicType::Bool }, b ? "1" : "0", (unsigned long long)b };
    204204}
    205205
    206206ConstantExpr * ConstantExpr::from_char( const CodeLocation & loc, char c ) {
    207         return new ConstantExpr{ 
     207        return new ConstantExpr{
    208208                loc, new BasicType{ BasicType::Char }, std::to_string( c ), (unsigned long long)c };
    209209}
    210210
    211211ConstantExpr * ConstantExpr::from_int( const CodeLocation & loc, int i ) {
    212         return new ConstantExpr{ 
     212        return new ConstantExpr{
    213213                loc, new BasicType{ BasicType::SignedInt }, std::to_string( i ), (unsigned long long)i };
    214214}
    215215
    216216ConstantExpr * ConstantExpr::from_ulong( const CodeLocation & loc, unsigned long i ) {
    217         return new ConstantExpr{ 
    218                 loc, new BasicType{ BasicType::LongUnsignedInt }, std::to_string( i ), 
     217        return new ConstantExpr{
     218                loc, new BasicType{ BasicType::LongUnsignedInt }, std::to_string( i ),
    219219                (unsigned long long)i };
    220220}
     
    227227        return new ConstantExpr{
    228228                loc,
    229                 new ArrayType{ 
     229                new ArrayType{
    230230                        new BasicType{ BasicType::Char, CV::Const },
    231231                        ConstantExpr::from_int( loc, s.size() + 1 /* null terminator */ ),
     
    258258// --- UntypedOffsetofExpr
    259259
    260 UntypedOffsetofExpr::UntypedOffsetofExpr( 
     260UntypedOffsetofExpr::UntypedOffsetofExpr(
    261261        const CodeLocation & loc, const Type * ty, const std::string & mem )
    262262: Expr( loc, new BasicType{ BasicType::LongUnsignedInt } ), type( ty ), member( mem ) {
     
    275275
    276276OffsetPackExpr::OffsetPackExpr( const CodeLocation & loc, const StructInstType * ty )
    277 : Expr( loc, new ArrayType{ 
    278         new BasicType{ BasicType::LongUnsignedInt }, nullptr, FixedLen, DynamicDim } 
     277: Expr( loc, new ArrayType{
     278        new BasicType{ BasicType::LongUnsignedInt }, nullptr, FixedLen, DynamicDim }
    279279), type( ty ) {
    280280        assert( type );
     
    283283// --- LogicalExpr
    284284
    285 LogicalExpr::LogicalExpr( 
     285LogicalExpr::LogicalExpr(
    286286        const CodeLocation & loc, const Expr * a1, const Expr * a2, LogicalFlag ia )
    287287: Expr( loc, new BasicType{ BasicType::SignedInt } ), arg1( a1 ), arg2( a2 ), isAnd( ia ) {}
  • src/AST/Expr.hpp

    rc671112 r41b24c8  
    133133};
    134134
    135 /// The application of a function to a set of parameters. 
     135/// The application of a function to a set of parameters.
    136136/// Post-resolver form of `UntypedExpr`
    137137class ApplicationExpr final : public Expr {
     
    218218        GeneratedFlag isGenerated;
    219219
    220         CastExpr( const CodeLocation & loc, const Expr * a, const Type * to, 
     220        CastExpr( const CodeLocation & loc, const Expr * a, const Type * to,
    221221                GeneratedFlag g = GeneratedCast ) : Expr( loc, to ), arg( a ), isGenerated( g ) {}
    222222        /// Cast-to-void
     
    311311                unsigned long long ival;
    312312                double dval;
    313                
     313
    314314                Val( unsigned long long i ) : ival( i ) {}
    315315                Val( double d ) : dval( d ) {}
     
    318318        std::string rep;
    319319
    320         ConstantExpr( 
     320        ConstantExpr(
    321321                const CodeLocation & loc, const Type * ty, const std::string & r, unsigned long long v )
    322322        : Expr( loc, ty ), val( v ), rep( r ) {}
    323323        ConstantExpr( const CodeLocation & loc, const Type * ty, const std::string & r, double v )
    324324        : Expr( loc, ty ), val( v ), rep( r ) {}
    325        
     325
    326326        /// Gets the value of this constant as an integer
    327327        long long int intValue() const;
     
    464464        ptr<Expr> arg2;
    465465
    466         CommaExpr( const CodeLocation & loc, const Expr * a1, const Expr * a2 ) 
     466        CommaExpr( const CodeLocation & loc, const Expr * a1, const Expr * a2 )
    467467        : Expr( loc ), arg1( a1 ), arg2( a2 ) {}
    468468
     
    491491public:
    492492        ptr<Expr> inout;
    493         ptr<Expr> constraint;
    494 };
    495 
    496 //=================================================================================================
    497 /// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency
    498 /// remove only if there is a better solution
    499 /// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with
    500 /// forward declarations
    501 inline void increment( const class Expr * node, Node::ref_type ref ) { node->increment(ref); }
    502 inline void decrement( const class Expr * node, Node::ref_type ref ) { node->decrement(ref); }
    503 inline void increment( const class ApplicationExpr * node, Node::ref_type ref ) { node->increment(ref); }
    504 inline void decrement( const class ApplicationExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    505 inline void increment( const class UntypedExpr * node, Node::ref_type ref ) { node->increment(ref); }
    506 inline void decrement( const class UntypedExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    507 inline void increment( const class NameExpr * node, Node::ref_type ref ) { node->increment(ref); }
    508 inline void decrement( const class NameExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    509 inline void increment( const class AddressExpr * node, Node::ref_type ref ) { node->increment(ref); }
    510 inline void decrement( const class AddressExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    511 inline void increment( const class LabelAddressExpr * node, Node::ref_type ref ) { node->increment(ref); }
    512 inline void decrement( const class LabelAddressExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    513 inline void increment( const class CastExpr * node, Node::ref_type ref ) { node->increment(ref); }
    514 inline void decrement( const class CastExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    515 inline void increment( const class KeywordCastExpr * node, Node::ref_type ref ) { node->increment(ref); }
    516 inline void decrement( const class KeywordCastExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    517 inline void increment( const class VirtualCastExpr * node, Node::ref_type ref ) { node->increment(ref); }
    518 inline void decrement( const class VirtualCastExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    519 inline void increment( const class MemberExpr * node, Node::ref_type ref ) { node->increment(ref); }
    520 inline void decrement( const class MemberExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    521 inline void increment( const class UntypedMemberExpr * node, Node::ref_type ref ) { node->increment(ref); }
    522 inline void decrement( const class UntypedMemberExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    523 inline void increment( const class VariableExpr * node, Node::ref_type ref ) { node->increment(ref); }
    524 inline void decrement( const class VariableExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    525 inline void increment( const class ConstantExpr * node, Node::ref_type ref ) { node->increment(ref); }
    526 inline void decrement( const class ConstantExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    527 inline void increment( const class SizeofExpr * node, Node::ref_type ref ) { node->increment(ref); }
    528 inline void decrement( const class SizeofExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    529 inline void increment( const class AlignofExpr * node, Node::ref_type ref ) { node->increment(ref); }
    530 inline void decrement( const class AlignofExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    531 inline void increment( const class UntypedOffsetofExpr * node, Node::ref_type ref ) { node->increment(ref); }
    532 inline void decrement( const class UntypedOffsetofExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    533 inline void increment( const class OffsetofExpr * node, Node::ref_type ref ) { node->increment(ref); }
    534 inline void decrement( const class OffsetofExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    535 inline void increment( const class OffsetPackExpr * node, Node::ref_type ref ) { node->increment(ref); }
    536 inline void decrement( const class OffsetPackExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    537 inline void increment( const class LogicalExpr * node, Node::ref_type ref ) { node->increment(ref); }
    538 inline void decrement( const class LogicalExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    539 inline void increment( const class ConditionalExpr * node, Node::ref_type ref ) { node->increment(ref); }
    540 inline void decrement( const class ConditionalExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    541 inline void increment( const class CommaExpr * node, Node::ref_type ref ) { node->increment(ref); }
    542 inline void decrement( const class CommaExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    543 inline void increment( const class TypeExpr * node, Node::ref_type ref ) { node->increment(ref); }
    544 inline void decrement( const class TypeExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    545 inline void increment( const class AsmExpr * node, Node::ref_type ref ) { node->increment(ref); }
    546 inline void decrement( const class AsmExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    547 // inline void increment( const class ImplicitCopyCtorExpr * node, Node::ref_type ref ) { node->increment(ref); }
    548 // inline void decrement( const class ImplicitCopyCtorExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    549 // inline void increment( const class ConstructorExpr * node, Node::ref_type ref ) { node->increment(ref); }
    550 // inline void decrement( const class ConstructorExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    551 // inline void increment( const class CompoundLiteralExpr * node, Node::ref_type ref ) { node->increment(ref); }
    552 // inline void decrement( const class CompoundLiteralExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    553 // inline void increment( const class UntypedValofExpr * node, Node::ref_type ref ) { node->increment(ref); }
    554 // inline void decrement( const class UntypedValofExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    555 // inline void increment( const class RangeExpr * node, Node::ref_type ref ) { node->increment(ref); }
    556 // inline void decrement( const class RangeExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    557 // inline void increment( const class UntypedTupleExpr * node, Node::ref_type ref ) { node->increment(ref); }
    558 // inline void decrement( const class UntypedTupleExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    559 // inline void increment( const class TupleExpr * node, Node::ref_type ref ) { node->increment(ref); }
    560 // inline void decrement( const class TupleExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    561 // inline void increment( const class TupleIndexExpr * node, Node::ref_type ref ) { node->increment(ref); }
    562 // inline void decrement( const class TupleIndexExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    563 // inline void increment( const class TupleAssignExpr * node, Node::ref_type ref ) { node->increment(ref); }
    564 // inline void decrement( const class TupleAssignExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    565 // inline void increment( const class StmtExpr * node, Node::ref_type ref ) { node->increment(ref); }
    566 // inline void decrement( const class StmtExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    567 // inline void increment( const class UniqueExpr * node, Node::ref_type ref ) { node->increment(ref); }
    568 // inline void decrement( const class UniqueExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    569 // inline void increment( const class UntypedInitExpr * node, Node::ref_type ref ) { node->increment(ref); }
    570 // inline void decrement( const class UntypedInitExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    571 // inline void increment( const class InitExpr * node, Node::ref_type ref ) { node->increment(ref); }
    572 // inline void decrement( const class InitExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    573 // inline void increment( const class DeletedExpr * node, Node::ref_type ref ) { node->increment(ref); }
    574 // inline void decrement( const class DeletedExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    575 // inline void increment( const class DefaultArgExpr * node, Node::ref_type ref ) { node->increment(ref); }
    576 // inline void decrement( const class DefaultArgExpr * node, Node::ref_type ref ) { node->decrement(ref); }
    577 // inline void increment( const class GenericExpr * node, Node::ref_type ref ) { node->increment(ref); }
    578 // inline void decrement( const class GenericExpr * node, Node::ref_type ref ) { node->decrement(ref); }
     493        ptr<Expr> constraint;
     494};
     495
    579496}
    580497
  • src/AST/Fwd.hpp

    rc671112 r41b24c8  
    136136std::string toString( const Node * );
    137137
    138 //=================================================================================================
    139 /// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency
    140 /// remove only if there is a better solution
    141 /// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with
    142 /// forward declarations
    143 inline void decrement( const class Node * node, Node::ref_type ref ) { node->decrement(ref); }
    144 inline void increment( const class Node * node, Node::ref_type ref ) { node->increment(ref); }
    145 inline void increment( const class ParseNode *, Node::ref_type );
    146 inline void decrement( const class ParseNode *, Node::ref_type );
    147 inline void increment( const class Decl *, Node::ref_type );
    148 inline void decrement( const class Decl *, Node::ref_type );
    149 inline void increment( const class DeclWithType *, Node::ref_type );
    150 inline void decrement( const class DeclWithType *, Node::ref_type );
    151 inline void increment( const class ObjectDecl *, Node::ref_type );
    152 inline void decrement( const class ObjectDecl *, Node::ref_type );
    153 inline void increment( const class FunctionDecl *, Node::ref_type );
    154 inline void decrement( const class FunctionDecl *, Node::ref_type );
    155 inline void increment( const class AggregateDecl *, Node::ref_type );
    156 inline void decrement( const class AggregateDecl *, Node::ref_type );
    157 inline void increment( const class StructDecl *, Node::ref_type );
    158 inline void decrement( const class StructDecl *, Node::ref_type );
    159 inline void increment( const class UnionDecl *, Node::ref_type );
    160 inline void decrement( const class UnionDecl *, Node::ref_type );
    161 inline void increment( const class EnumDecl *, Node::ref_type );
    162 inline void decrement( const class EnumDecl *, Node::ref_type );
    163 inline void increment( const class TraitDecl *, Node::ref_type );
    164 inline void decrement( const class TraitDecl *, Node::ref_type );
    165 inline void increment( const class NamedTypeDecl *, Node::ref_type );
    166 inline void decrement( const class NamedTypeDecl *, Node::ref_type );
    167 inline void increment( const class TypeDecl *, Node::ref_type );
    168 inline void decrement( const class TypeDecl *, Node::ref_type );
    169 inline void increment( const class TypedefDecl *, Node::ref_type );
    170 inline void decrement( const class TypedefDecl *, Node::ref_type );
    171 inline void increment( const class AsmDecl *, Node::ref_type );
    172 inline void decrement( const class AsmDecl *, Node::ref_type );
    173 inline void increment( const class StaticAssertDecl *, Node::ref_type );
    174 inline void decrement( const class StaticAssertDecl *, Node::ref_type );
    175 inline void increment( const class Stmt *, Node::ref_type );
    176 inline void decrement( const class Stmt *, Node::ref_type );
    177 inline void increment( const class CompoundStmt *, Node::ref_type );
    178 inline void decrement( const class CompoundStmt *, Node::ref_type );
    179 inline void increment( const class ExprStmt *, Node::ref_type );
    180 inline void decrement( const class ExprStmt *, Node::ref_type );
    181 inline void increment( const class AsmStmt *, Node::ref_type );
    182 inline void decrement( const class AsmStmt *, Node::ref_type );
    183 inline void increment( const class DirectiveStmt *, Node::ref_type );
    184 inline void decrement( const class DirectiveStmt *, Node::ref_type );
    185 inline void increment( const class IfStmt *, Node::ref_type );
    186 inline void decrement( const class IfStmt *, Node::ref_type );
    187 inline void increment( const class WhileStmt *, Node::ref_type );
    188 inline void decrement( const class WhileStmt *, Node::ref_type );
    189 inline void increment( const class ForStmt *, Node::ref_type );
    190 inline void decrement( const class ForStmt *, Node::ref_type );
    191 inline void increment( const class SwitchStmt *, Node::ref_type );
    192 inline void decrement( const class SwitchStmt *, Node::ref_type );
    193 inline void increment( const class CaseStmt *, Node::ref_type );
    194 inline void decrement( const class CaseStmt *, Node::ref_type );
    195 inline void increment( const class BranchStmt *, Node::ref_type );
    196 inline void decrement( const class BranchStmt *, Node::ref_type );
    197 inline void increment( const class ReturnStmt *, Node::ref_type );
    198 inline void decrement( const class ReturnStmt *, Node::ref_type );
    199 inline void increment( const class ThrowStmt *, Node::ref_type );
    200 inline void decrement( const class ThrowStmt *, Node::ref_type );
    201 inline void increment( const class TryStmt *, Node::ref_type );
    202 inline void decrement( const class TryStmt *, Node::ref_type );
    203 inline void increment( const class CatchStmt *, Node::ref_type );
    204 inline void decrement( const class CatchStmt *, Node::ref_type );
    205 inline void increment( const class FinallyStmt *, Node::ref_type );
    206 inline void decrement( const class FinallyStmt *, Node::ref_type );
    207 inline void increment( const class WaitForStmt *, Node::ref_type );
    208 inline void decrement( const class WaitForStmt *, Node::ref_type );
    209 inline void increment( const class WithStmt *, Node::ref_type );
    210 inline void decrement( const class WithStmt *, Node::ref_type );
    211 inline void increment( const class DeclStmt *, Node::ref_type );
    212 inline void decrement( const class DeclStmt *, Node::ref_type );
    213 inline void increment( const class NullStmt *, Node::ref_type );
    214 inline void decrement( const class NullStmt *, Node::ref_type );
    215 inline void increment( const class ImplicitCtorDtorStmt *, Node::ref_type );
    216 inline void decrement( const class ImplicitCtorDtorStmt *, Node::ref_type );
    217 inline void increment( const class Expr *, Node::ref_type );
    218 inline void decrement( const class Expr *, Node::ref_type );
    219 inline void increment( const class ApplicationExpr *, Node::ref_type );
    220 inline void decrement( const class ApplicationExpr *, Node::ref_type );
    221 inline void increment( const class UntypedExpr *, Node::ref_type );
    222 inline void decrement( const class UntypedExpr *, Node::ref_type );
    223 inline void increment( const class NameExpr *, Node::ref_type );
    224 inline void decrement( const class NameExpr *, Node::ref_type );
    225 inline void increment( const class AddressExpr *, Node::ref_type );
    226 inline void decrement( const class AddressExpr *, Node::ref_type );
    227 inline void increment( const class LabelAddressExpr *, Node::ref_type );
    228 inline void decrement( const class LabelAddressExpr *, Node::ref_type );
    229 inline void increment( const class CastExpr *, Node::ref_type );
    230 inline void decrement( const class CastExpr *, Node::ref_type );
    231 inline void increment( const class KeywordCastExpr *, Node::ref_type );
    232 inline void decrement( const class KeywordCastExpr *, Node::ref_type );
    233 inline void increment( const class VirtualCastExpr *, Node::ref_type );
    234 inline void decrement( const class VirtualCastExpr *, Node::ref_type );
    235 inline void increment( const class MemberExpr *, Node::ref_type );
    236 inline void decrement( const class MemberExpr *, Node::ref_type );
    237 inline void increment( const class UntypedMemberExpr *, Node::ref_type );
    238 inline void decrement( const class UntypedMemberExpr *, Node::ref_type );
    239 inline void increment( const class VariableExpr *, Node::ref_type );
    240 inline void decrement( const class VariableExpr *, Node::ref_type );
    241 inline void increment( const class ConstantExpr *, Node::ref_type );
    242 inline void decrement( const class ConstantExpr *, Node::ref_type );
    243 inline void increment( const class SizeofExpr *, Node::ref_type );
    244 inline void decrement( const class SizeofExpr *, Node::ref_type );
    245 inline void increment( const class AlignofExpr *, Node::ref_type );
    246 inline void decrement( const class AlignofExpr *, Node::ref_type );
    247 inline void increment( const class UntypedOffsetofExpr *, Node::ref_type );
    248 inline void decrement( const class UntypedOffsetofExpr *, Node::ref_type );
    249 inline void increment( const class OffsetofExpr *, Node::ref_type );
    250 inline void decrement( const class OffsetofExpr *, Node::ref_type );
    251 inline void increment( const class OffsetPackExpr *, Node::ref_type );
    252 inline void decrement( const class OffsetPackExpr *, Node::ref_type );
    253 inline void increment( const class LogicalExpr *, Node::ref_type );
    254 inline void decrement( const class LogicalExpr *, Node::ref_type );
    255 inline void increment( const class ConditionalExpr *, Node::ref_type );
    256 inline void decrement( const class ConditionalExpr *, Node::ref_type );
    257 inline void increment( const class CommaExpr *, Node::ref_type );
    258 inline void decrement( const class CommaExpr *, Node::ref_type );
    259 inline void increment( const class TypeExpr *, Node::ref_type );
    260 inline void decrement( const class TypeExpr *, Node::ref_type );
    261 inline void increment( const class AsmExpr *, Node::ref_type );
    262 inline void decrement( const class AsmExpr *, Node::ref_type );
    263 inline void increment( const class ImplicitCopyCtorExpr *, Node::ref_type );
    264 inline void decrement( const class ImplicitCopyCtorExpr *, Node::ref_type );
    265 inline void increment( const class ConstructorExpr *, Node::ref_type );
    266 inline void decrement( const class ConstructorExpr *, Node::ref_type );
    267 inline void increment( const class CompoundLiteralExpr *, Node::ref_type );
    268 inline void decrement( const class CompoundLiteralExpr *, Node::ref_type );
    269 inline void increment( const class UntypedValofExpr *, Node::ref_type );
    270 inline void decrement( const class UntypedValofExpr *, Node::ref_type );
    271 inline void increment( const class RangeExpr *, Node::ref_type );
    272 inline void decrement( const class RangeExpr *, Node::ref_type );
    273 inline void increment( const class UntypedTupleExpr *, Node::ref_type );
    274 inline void decrement( const class UntypedTupleExpr *, Node::ref_type );
    275 inline void increment( const class TupleExpr *, Node::ref_type );
    276 inline void decrement( const class TupleExpr *, Node::ref_type );
    277 inline void increment( const class TupleIndexExpr *, Node::ref_type );
    278 inline void decrement( const class TupleIndexExpr *, Node::ref_type );
    279 inline void increment( const class TupleAssignExpr *, Node::ref_type );
    280 inline void decrement( const class TupleAssignExpr *, Node::ref_type );
    281 inline void increment( const class StmtExpr *, Node::ref_type );
    282 inline void decrement( const class StmtExpr *, Node::ref_type );
    283 inline void increment( const class UniqueExpr *, Node::ref_type );
    284 inline void decrement( const class UniqueExpr *, Node::ref_type );
    285 inline void increment( const class UntypedInitExpr *, Node::ref_type );
    286 inline void decrement( const class UntypedInitExpr *, Node::ref_type );
    287 inline void increment( const class InitExpr *, Node::ref_type );
    288 inline void decrement( const class InitExpr *, Node::ref_type );
    289 inline void increment( const class DeletedExpr *, Node::ref_type );
    290 inline void decrement( const class DeletedExpr *, Node::ref_type );
    291 inline void increment( const class DefaultArgExpr *, Node::ref_type );
    292 inline void decrement( const class DefaultArgExpr *, Node::ref_type );
    293 inline void increment( const class GenericExpr *, Node::ref_type );
    294 inline void decrement( const class GenericExpr *, Node::ref_type );
    295 inline void increment( const class Type *, Node::ref_type );
    296 inline void decrement( const class Type *, Node::ref_type );
    297 inline void increment( const class VoidType *, Node::ref_type );
    298 inline void decrement( const class VoidType *, Node::ref_type );
    299 inline void increment( const class BasicType *, Node::ref_type );
    300 inline void decrement( const class BasicType *, Node::ref_type );
    301 inline void increment( const class PointerType *, Node::ref_type );
    302 inline void decrement( const class PointerType *, Node::ref_type );
    303 inline void increment( const class ArrayType *, Node::ref_type );
    304 inline void decrement( const class ArrayType *, Node::ref_type );
    305 inline void increment( const class ReferenceType *, Node::ref_type );
    306 inline void decrement( const class ReferenceType *, Node::ref_type );
    307 inline void increment( const class QualifiedType *, Node::ref_type );
    308 inline void decrement( const class QualifiedType *, Node::ref_type );
    309 inline void increment( const class FunctionType *, Node::ref_type );
    310 inline void decrement( const class FunctionType *, Node::ref_type );
    311 inline void increment( const class ReferenceToType *, Node::ref_type );
    312 inline void decrement( const class ReferenceToType *, Node::ref_type );
    313 inline void increment( const class StructInstType *, Node::ref_type );
    314 inline void decrement( const class StructInstType *, Node::ref_type );
    315 inline void increment( const class UnionInstType *, Node::ref_type );
    316 inline void decrement( const class UnionInstType *, Node::ref_type );
    317 inline void increment( const class EnumInstType *, Node::ref_type );
    318 inline void decrement( const class EnumInstType *, Node::ref_type );
    319 inline void increment( const class TraitInstType *, Node::ref_type );
    320 inline void decrement( const class TraitInstType *, Node::ref_type );
    321 inline void increment( const class TypeInstType *, Node::ref_type );
    322 inline void decrement( const class TypeInstType *, Node::ref_type );
    323 inline void increment( const class TupleType *, Node::ref_type );
    324 inline void decrement( const class TupleType *, Node::ref_type );
    325 inline void increment( const class TypeofType *, Node::ref_type );
    326 inline void decrement( const class TypeofType *, Node::ref_type );
    327 inline void increment( const class VarArgsType *, Node::ref_type );
    328 inline void decrement( const class VarArgsType *, Node::ref_type );
    329 inline void increment( const class ZeroType *, Node::ref_type );
    330 inline void decrement( const class ZeroType *, Node::ref_type );
    331 inline void increment( const class OneType *, Node::ref_type );
    332 inline void decrement( const class OneType *, Node::ref_type );
    333 inline void increment( const class GlobalScopeType *, Node::ref_type );
    334 inline void decrement( const class GlobalScopeType *, Node::ref_type );
    335 inline void increment( const class Designation *, Node::ref_type );
    336 inline void decrement( const class Designation *, Node::ref_type );
    337 inline void increment( const class Init *, Node::ref_type );
    338 inline void decrement( const class Init *, Node::ref_type );
    339 inline void increment( const class SingleInit *, Node::ref_type );
    340 inline void decrement( const class SingleInit *, Node::ref_type );
    341 inline void increment( const class ListInit *, Node::ref_type );
    342 inline void decrement( const class ListInit *, Node::ref_type );
    343 inline void increment( const class ConstructorInit *, Node::ref_type );
    344 inline void decrement( const class ConstructorInit *, Node::ref_type );
    345 inline void increment( const class Constant *, Node::ref_type );
    346 inline void decrement( const class Constant *, Node::ref_type );
    347 inline void increment( const class Attribute *, Node::ref_type );
    348 inline void decrement( const class Attribute *, Node::ref_type );
    349 inline void increment( const class TypeSubstitution *, Node::ref_type );
    350 inline void decrement( const class TypeSubstitution *, Node::ref_type );
    351 
    352138typedef unsigned int UniqueId;
    353139
  • src/AST/Init.cpp

    rc671112 r41b24c8  
    2222namespace ast {
    2323
    24 ListInit::ListInit( const CodeLocation& loc, std::vector<ptr<Init>>&& is, 
    25         std::vector<ptr<Designation>>&& ds, bool mc)
     24ListInit::ListInit( const CodeLocation& loc, std::vector<ptr<Init>>&& is,
     25        std::vector<ptr<Designation>>&& ds, ConstructFlag mc)
    2626: Init( loc, mc ), initializers( std::move(is) ), designations( std::move(ds) ) {
    27         // handle common case where ListInit is created without designations by making an 
     27        // handle common case where ListInit is created without designations by making an
    2828        // equivalent-length empty list
    2929        if ( designations.empty() ) {
     
    3232                }
    3333        }
    34        
     34
    3535        assertf( initializers.size() == designations.size(), "Created ListInit with mismatching "
    3636                "initializers (%zd) and designations (%zd)", initializers.size(), designations.size() );
  • src/AST/Init.hpp

    rc671112 r41b24c8  
    2424
    2525// Must be included in *all* AST classes; should be #undef'd at the end of the file
    26 #define MUTATE_FRIEND template<typename node_t> friend auto mutate(const node_t * node);
     26#define MUTATE_FRIEND template<typename node_t> friend node_t * mutate(const node_t * node);
    2727
    2828namespace ast {
     
    5858        const Init * accept( Visitor& v ) const override = 0;
    5959private:
    60         const Init * clone() const override = 0;
     60        Init * clone() const override = 0;
    6161        MUTATE_FRIEND
    6262};
     
    122122};
    123123
    124 
    125 //=================================================================================================
    126 /// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency
    127 /// remove only if there is a better solution
    128 /// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with
    129 /// forward declarations
    130 inline void increment( const class Init * node, Node::ref_type ref ) { node->increment( ref ); }
    131 inline void decrement( const class Init * node, Node::ref_type ref ) { node->decrement( ref ); }
    132 inline void increment( const class SingleInit * node, Node::ref_type ref ) { node->increment( ref ); }
    133 inline void decrement( const class SingleInit * node, Node::ref_type ref ) { node->decrement( ref ); }
    134 inline void increment( const class ListInit * node, Node::ref_type ref ) { node->increment( ref ); }
    135 inline void decrement( const class ListInit * node, Node::ref_type ref ) { node->decrement( ref ); }
    136 inline void increment( const class ConstructorInit * node, Node::ref_type ref ) { node->increment( ref ); }
    137 inline void decrement( const class ConstructorInit * node, Node::ref_type ref ) { node->decrement( ref ); }
    138124}
    139125
  • src/AST/LinkageSpec.cpp

    rc671112 r41b24c8  
    4343
    4444        std::string name( Spec spec ) {
    45                 switch ( spec ) {
    46                 case Intrinsic:  return "intrinsic";
    47                 case C:          return "C";
    48                 case Cforall:    return "Cforall";
    49                 case AutoGen:    return "autogenerated cfa";
    50                 case Compiler:   return "compiler built-in";
    51                 case BuiltinCFA: return "cfa built-in";
    52                 case BuiltinC:   return "c built-in";
     45                switch ( spec.val ) {
     46                case Intrinsic.val:  return "intrinsic";
     47                case C.val:          return "C";
     48                case Cforall.val:    return "Cforall";
     49                case AutoGen.val:    return "autogenerated cfa";
     50                case Compiler.val:   return "compiler built-in";
     51                case BuiltinCFA.val: return "cfa built-in";
     52                case BuiltinC.val:   return "c built-in";
    5353                default:         return "<unnamed linkage spec>";
    5454                }
  • src/AST/Node.hpp

    rc671112 r41b24c8  
    4444        };
    4545
    46         inline void increment(ref_type ref) const {
     46private:
     47        /// Make a copy of this node; should be overridden in subclass with more precise return type
     48        virtual Node * clone() const = 0;
     49
     50        /// Must be copied in ALL derived classes
     51        template<typename node_t>
     52        friend node_t * mutate(const node_t * node);
     53
     54        mutable size_t strong_count = 0;
     55        mutable size_t weak_count = 0;
     56
     57        void increment(ref_type ref) const {
    4758                switch (ref) {
    4859                        case ref_type::strong: strong_count++; break;
     
    5162        }
    5263
    53         inline void decrement(ref_type ref) const {
     64        void decrement(ast::Node::ref_type ref) const {
    5465                switch (ref) {
    5566                        case ref_type::strong: strong_count--; break;
     
    6172                }
    6273        }
    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;
    6674
    67         /// Must be copied in ALL derived classes
    68         template<typename node_t>
    69         friend auto mutate(const node_t * node);
    70 
    71         mutable size_t strong_count = 0;
    72         mutable size_t weak_count = 0;
     75        template< typename node_t, enum Node::ref_type ref_t >
     76        friend class ptr_base;
    7377};
    7478
     
    7680// problems and be able to use auto return
    7781template<typename node_t>
    78 auto mutate( const node_t * node ) {
    79         assertf(
    80                 node->strong_count >= 1,
    81                 "Error: attempting to mutate a node that appears to have been linked"
    82         );
    83         if (node->strong_count == 1) {
     82node_t * mutate( const node_t * node ) {
     83        if (node->strong_count <= 1) {
    8484                return const_cast<node_t *>(node);
    8585        }
     
    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( const node_t * n ) : node(n) { if( node ) _inc(node); }
     103        ~ptr_base() { if( node ) _dec(node); }
    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) {
    107                 if( node ) increment(node, ref_t);
     107                if( node ) _inc(node);
    108108        }
    109109
    110110        template< enum Node::ref_type o_ref_t >
    111111        ptr_base( ptr_base<node_t, o_ref_t> && o ) : node(o.node) {
    112                 if( node ) increment(node, ref_t);
     112                if( node ) _inc(node);
    113113        }
    114114
     
    147147                assign( n );
    148148                // get mutable version of `n`
    149                 auto r = mutate( node ); 
     149                auto r = mutate( node );
    150150                // re-assign mutable version in case `mutate()` produced a new pointer
    151151                assign( r );
     
    157157private:
    158158        void assign( const node_t * other ) {
    159                 if( other ) increment(other, ref_t);
    160                 if( node  ) decrement(node , ref_t);
     159                if( other ) _inc(other);
     160                if( node  ) _dec(node );
    161161                node = other;
    162162        }
     163
     164        void _inc( const node_t * other );
     165        void _dec( const node_t * other );
    163166
    164167protected:
  • src/AST/ParseNode.hpp

    rc671112 r41b24c8  
    3434
    3535        ParseNode( const ParseNode& o ) = default;
     36private:
     37        ParseNode * clone() const override = 0;
     38
     39        /// Must be copied in ALL derived classes
     40        template<typename node_t>
     41        friend node_t * mutate(const node_t * node);
    3642};
    3743
    38 
    39 //=================================================================================================
    40 /// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency
    41 /// remove only if there is a better solution
    42 /// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with
    43 /// forward declarations
    44 inline void increment( const class ParseNode * node, Node::ref_type ref ) { node->increment( ref ); }
    45 inline void decrement( const class ParseNode * node, Node::ref_type ref ) { node->decrement( ref ); }
    4644}
    4745
  • src/AST/Pass.impl.hpp

    rc671112 r41b24c8  
    464464        VISIT({
    465465                guard_indexer guard { * this };
    466                 maybe_accept( node, &StructDecl::params );
    467                 maybe_accept( node, &StructDecl::members    );
     466                maybe_accept( node, &StructDecl::params  );
     467                maybe_accept( node, &StructDecl::members );
    468468        })
    469469
     
    485485        VISIT({
    486486                guard_indexer guard { * this };
    487                 maybe_accept( node, &UnionDecl::params );
    488                 maybe_accept( node, &UnionDecl::members    );
     487                maybe_accept( node, &UnionDecl::params  );
     488                maybe_accept( node, &UnionDecl::members );
    489489        })
    490490
     
    504504        VISIT(
    505505                // unlike structs, traits, and unions, enums inject their members into the global scope
    506                 maybe_accept( node, &EnumDecl::params );
    507                 maybe_accept( node, &EnumDecl::members    );
     506                maybe_accept( node, &EnumDecl::params  );
     507                maybe_accept( node, &EnumDecl::members );
    508508        )
    509509
     
    519519        VISIT({
    520520                guard_indexer guard { *this };
    521                 maybe_accept( node, &TraitDecl::params );
    522                 maybe_accept( node, &TraitDecl::members    );
     521                maybe_accept( node, &TraitDecl::params  );
     522                maybe_accept( node, &TraitDecl::members );
    523523        })
    524524
     
    537537                guard_indexer guard { *this };
    538538                maybe_accept( node, &TypeDecl::params );
    539                 maybe_accept( node, &TypeDecl::base       );
     539                maybe_accept( node, &TypeDecl::base   );
    540540        })
    541541
     
    566566                guard_indexer guard { *this };
    567567                maybe_accept( node, &TypedefDecl::params );
    568                 maybe_accept( node, &TypedefDecl::base       );
     568                maybe_accept( node, &TypedefDecl::base   );
    569569        })
    570570
     
    690690                maybe_accept( node, &WhileStmt::body  );
    691691        })
     692
     693        VISIT_END( Stmt, node );
     694}
     695
     696//--------------------------------------------------------------------------
     697// ForStmt
     698template< typename pass_t >
     699const ast::Stmt * ast::Pass< pass_t >::visit( const ast::ForStmt * node ) {
     700        VISIT_START( node );
     701
     702        VISIT({
     703                // for statements introduce a level of scope (for the initialization)
     704                guard_indexer guard { *this };
     705                maybe_accept( node, &ForStmt::inits );
     706                maybe_accept( node, &ForStmt::cond  );
     707                maybe_accept( node, &ForStmt::inc   );
     708                maybe_accept( node, &ForStmt::body  );
     709        })
     710
     711        VISIT_END( Stmt, node );
     712}
     713
     714//--------------------------------------------------------------------------
     715// SwitchStmt
     716template< typename pass_t >
     717const ast::Stmt * ast::Pass< pass_t >::visit( const ast::SwitchStmt * node ) {
     718        VISIT_START( node );
     719
     720        VISIT(
     721                maybe_accept( node, &SwitchStmt::cond  );
     722                maybe_accept( node, &SwitchStmt::stmts );
     723        )
     724
     725        VISIT_END( Stmt, node );
     726}
     727
     728//--------------------------------------------------------------------------
     729// CaseStmt
     730template< typename pass_t >
     731const ast::Stmt * ast::Pass< pass_t >::visit( const ast::CaseStmt * node ) {
     732        VISIT_START( node );
     733
     734        VISIT(
     735                maybe_accept( node, &CaseStmt::cond  );
     736                maybe_accept( node, &CaseStmt::stmts );
     737        )
     738
     739        VISIT_END( Stmt, node );
     740}
     741
     742//--------------------------------------------------------------------------
     743// BranchStmt
     744template< typename pass_t >
     745const ast::Stmt * ast::Pass< pass_t >::visit( const ast::BranchStmt * node ) {
     746        VISIT_START( node );
     747        VISIT_END( Stmt, node );
     748}
     749
     750//--------------------------------------------------------------------------
     751// ReturnStmt
     752template< typename pass_t >
     753const ast::Stmt * ast::Pass< pass_t >::visit( const ast::ReturnStmt * node ) {
     754        VISIT_START( node );
     755
     756        VISIT(
     757                maybe_accept( node, &ReturnStmt::expr );
     758        )
     759
     760        VISIT_END( Stmt, node );
     761}
     762
     763//--------------------------------------------------------------------------
     764// ThrowStmt
     765template< typename pass_t >
     766const ast::Stmt * ast::Pass< pass_t >::visit( const ast::ThrowStmt * node ) {
     767        VISIT_START( node );
     768
     769        VISIT(
     770                maybe_accept( node, &ThrowStmt::expr   );
     771                maybe_accept( node, &ThrowStmt::target );
     772        )
     773
     774        VISIT_END( Stmt, node );
     775}
     776
     777//--------------------------------------------------------------------------
     778// TryStmt
     779template< typename pass_t >
     780const ast::Stmt * ast::Pass< pass_t >::visit( const ast::TryStmt * node ) {
     781        VISIT_START( node );
     782
     783        VISIT(
     784                maybe_accept( node, &TryStmt::block        );
     785                maybe_accept( node, &TryStmt::handlers     );
     786                maybe_accept( node, &TryStmt::finallyBlock );
     787        )
    692788
    693789        VISIT_END( Stmt, node );
  • src/AST/Stmt.cpp

    rc671112 r41b24c8  
    2626
    2727// --- BranchStmt
    28 BranchStmt( const CodeLocation& loc, Kind kind, Label target, std::vector<Label>&& labels )
     28BranchStmt::BranchStmt( const CodeLocation& loc, Kind kind, Label target, std::vector<Label>&& labels )
    2929: Stmt(loc, std::move(labels)), originalTarget(target), target(target), kind(kind) {
    3030        // Make sure a syntax error hasn't slipped through.
     
    3434const char * BranchStmt::kindNames[] = {
    3535    "Goto", "Break", "Continue", "FallThrough", "FallThroughDefault"
    36 }
     36};
    3737
    3838}
  • src/AST/Stmt.hpp

    rc671112 r41b24c8  
    404404};
    405405
    406 //=================================================================================================
    407 /// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency
    408 /// remove only if there is a better solution
    409 /// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with
    410 /// forward declarations
    411 inline void increment( const class Stmt * node, Node::ref_type ref ) { node->increment( ref ); }
    412 inline void decrement( const class Stmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    413 inline void increment( const class CompoundStmt * node, Node::ref_type ref ) { node->increment( ref ); }
    414 inline void decrement( const class CompoundStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    415 inline void increment( const class ExprStmt * node, Node::ref_type ref ) { node->increment( ref ); }
    416 inline void decrement( const class ExprStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    417 inline void increment( const class AsmStmt * node, Node::ref_type ref ) { node->increment( ref ); }
    418 inline void decrement( const class AsmStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    419 inline void increment( const class DirectiveStmt * node, Node::ref_type ref ) { node->increment( ref ); }
    420 inline void decrement( const class DirectiveStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    421 inline void increment( const class IfStmt * node, Node::ref_type ref ) { node->increment( ref ); }
    422 inline void decrement( const class IfStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    423 inline void increment( const class WhileStmt * node, Node::ref_type ref ) { node->increment( ref ); }
    424 inline void decrement( const class WhileStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    425 inline void increment( const class ForStmt * node, Node::ref_type ref ) { node->increment( ref ); }
    426 inline void decrement( const class ForStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    427 inline void increment( const class SwitchStmt * node, Node::ref_type ref ) { node->increment( ref ); }
    428 inline void decrement( const class SwitchStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    429 inline void increment( const class CaseStmt * node, Node::ref_type ref ) { node->increment( ref ); }
    430 inline void decrement( const class CaseStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    431 inline void increment( const class BranchStmt * node, Node::ref_type ref ) { node->increment( ref ); }
    432 inline void decrement( const class BranchStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    433 inline void increment( const class ReturnStmt * node, Node::ref_type ref ) { node->increment( ref ); }
    434 inline void decrement( const class ReturnStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    435 inline void increment( const class ThrowStmt * node, Node::ref_type ref ) { node->increment( ref ); }
    436 inline void decrement( const class ThrowStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    437 inline void increment( const class TryStmt * node, Node::ref_type ref ) { node->increment( ref ); }
    438 inline void decrement( const class TryStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    439 inline void increment( const class CatchStmt * node, Node::ref_type ref ) { node->increment( ref ); }
    440 inline void decrement( const class CatchStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    441 inline void increment( const class FinallyStmt * node, Node::ref_type ref ) { node->increment( ref ); }
    442 inline void decrement( const class FinallyStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    443 inline void increment( const class WaitForStmt * node, Node::ref_type ref ) { node->increment( ref ); }
    444 inline void decrement( const class WaitForStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    445 inline void increment( const class WithStmt * node, Node::ref_type ref ) { node->increment( ref ); }
    446 inline void decrement( const class WithStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    447 inline void increment( const class DeclStmt * node, Node::ref_type ref ) { node->increment( ref ); }
    448 inline void decrement( const class DeclStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    449 inline void increment( const class NullStmt * node, Node::ref_type ref ) { node->increment( ref ); }
    450 inline void decrement( const class NullStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    451 inline void increment( const class ImplicitCtorDtorStmt * node, Node::ref_type ref ) { node->increment( ref ); }
    452 inline void decrement( const class ImplicitCtorDtorStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
    453 
    454406}
    455407
  • src/AST/Type.hpp

    rc671112 r41b24c8  
    3737public:
    3838        CV::Qualifiers qualifiers;
    39        
     39
    4040        Type( CV::Qualifiers q = {} ) : qualifiers(q) {}
    4141
     
    8080public:
    8181        VoidType( CV::Qualifiers q = {} ) : Type( q ) {}
    82        
     82
    8383        unsigned size() const override { return 0; }
    8484        bool isVoid() const override { return true; }
     
    171171
    172172        PointerType( const Type * b, CV::Qualifiers q = {} ) : Type(q), base(b), dimension() {}
    173         PointerType( const Type * b, const Expr * d, LengthFlag vl, DimensionFlag s, 
     173        PointerType( const Type * b, const Expr * d, LengthFlag vl, DimensionFlag s,
    174174                CV::Qualifiers q = {} ) : Type(q), base(b), dimension(d), isVarLen(vl), isStatic(s) {}
    175175
     
    193193        DimensionFlag isStatic;
    194194
    195         ArrayType( const Type * b, const Expr * d, LengthFlag vl, DimensionFlag s, 
     195        ArrayType( const Type * b, const Expr * d, LengthFlag vl, DimensionFlag s,
    196196                CV::Qualifiers q = {} ) : Type(q), base(b), dimension(d), isVarLen(vl), isStatic(s) {}
    197197
     
    233233        ptr<Type> child;
    234234
    235         QualifiedType( const Type * p, const Type * c, CV::Qualifiers q = {} ) 
     235        QualifiedType( const Type * p, const Type * c, CV::Qualifiers q = {} )
    236236        : Type(q), parent(p), child(c) {}
    237237
     
    249249        ForallList forall;
    250250
    251         ParameterizedType( ForallList&& fs = {}, CV::Qualifiers q = {} ) 
     251        ParameterizedType( ForallList&& fs = {}, CV::Qualifiers q = {} )
    252252        : Type(q), forall(std::move(fs)) {}
    253253        ParameterizedType( CV::Qualifiers q ) : Type(q), forall() {}
     
    267267        std::vector<ptr<DeclWithType>> params;
    268268
    269         /// Does the function accept a variable number of arguments following the arguments specified 
     269        /// Does the function accept a variable number of arguments following the arguments specified
    270270        /// in the parameters list.
    271271        /// This could be because of
     
    296296        bool hoistType = false;
    297297
    298         ReferenceToType( const std::string& n, CV::Qualifiers q = {}, 
     298        ReferenceToType( const std::string& n, CV::Qualifiers q = {},
    299299                std::vector<ptr<Attribute>> && as = {} )
    300300        : ParameterizedType(q), params(), attributes(std::move(as)), name(n) {}
     
    319319        readonly<StructDecl> base;
    320320
    321         StructInstType( const std::string& n, CV::Qualifiers q = {}, 
     321        StructInstType( const std::string& n, CV::Qualifiers q = {},
    322322                std::vector<ptr<Attribute>> && as = {} )
    323323        : ReferenceToType( n, q, std::move(as) ), base() {}
    324         StructInstType( const StructDecl * b, CV::Qualifiers q = {}, 
     324        StructInstType( const StructDecl * b, CV::Qualifiers q = {},
    325325                std::vector<ptr<Attribute>> && as = {} );
    326        
     326
    327327        bool isComplete() const override;
    328328
     
    342342        readonly<UnionDecl> base;
    343343
    344         UnionInstType( const std::string& n, CV::Qualifiers q = {}, 
     344        UnionInstType( const std::string& n, CV::Qualifiers q = {},
    345345                std::vector<ptr<Attribute>> && as = {} )
    346346        : ReferenceToType( n, q, std::move(as) ), base() {}
    347         UnionInstType( const UnionDecl * b, CV::Qualifiers q = {}, 
     347        UnionInstType( const UnionDecl * b, CV::Qualifiers q = {},
    348348                std::vector<ptr<Attribute>> && as = {} );
    349        
     349
    350350        bool isComplete() const override;
    351351
     
    365365        readonly<EnumDecl> base;
    366366
    367         EnumInstType( const std::string& n, CV::Qualifiers q = {}, 
     367        EnumInstType( const std::string& n, CV::Qualifiers q = {},
    368368                std::vector<ptr<Attribute>> && as = {} )
    369369        : ReferenceToType( n, q, std::move(as) ), base() {}
    370         EnumInstType( const EnumDecl * b, CV::Qualifiers q = {}, 
     370        EnumInstType( const EnumDecl * b, CV::Qualifiers q = {},
    371371                std::vector<ptr<Attribute>> && as = {} );
    372        
     372
    373373        bool isComplete() const override;
    374374
     
    388388        readonly<TraitDecl> base;
    389389
    390         TraitInstType( const std::string& n, CV::Qualifiers q = {}, 
     390        TraitInstType( const std::string& n, CV::Qualifiers q = {},
    391391                std::vector<ptr<Attribute>> && as = {} )
    392392        : ReferenceToType( n, q, std::move(as) ), base() {}
    393         TraitInstType( const TraitDecl * b, CV::Qualifiers q = {}, 
     393        TraitInstType( const TraitDecl * b, CV::Qualifiers q = {},
    394394                std::vector<ptr<Attribute>> && as = {} );
    395        
     395
    396396        // not meaningful for TraitInstType
    397397        bool isComplete() const override { assert(false); }
     
    413413        TypeVar::Kind kind;
    414414
    415         TypeInstType( const std::string& n, const TypeDecl * b, CV::Qualifiers q = {}, 
     415        TypeInstType( const std::string& n, const TypeDecl * b, CV::Qualifiers q = {},
    416416                std::vector<ptr<Attribute>> && as = {} )
    417417        : ReferenceToType( n, q, std::move(as) ), base( b ), kind( b->kind ) {}
    418         TypeInstType( const std::string& n, TypeVar::Kind k, CV::Qualifiers q = {}, 
     418        TypeInstType( const std::string& n, TypeVar::Kind k, CV::Qualifiers q = {},
    419419                std::vector<ptr<Attribute>> && as = {} )
    420420        : ReferenceToType( n, q, std::move(as) ), base(), kind( k ) {}
     
    448448        iterator begin() const { return types.begin(); }
    449449        iterator end() const { return types.end(); }
    450        
     450
    451451        unsigned size() const override { return types.size(); }
    452452
    453453        const Type * getComponent( unsigned i ) override {
    454                 assertf( i < size(), "TupleType::getComponent: index %d must be less than size %d", 
     454                assertf( i < size(), "TupleType::getComponent: index %d must be less than size %d",
    455455                        i, size() );
    456456                return *(begin()+i);
     
    469469        enum Kind { Typeof, Basetypeof } kind;
    470470
    471         TypeofType( const Expr * e, Kind k = Typeof, CV::Qualifiers q = {} ) 
     471        TypeofType( const Expr * e, Kind k = Typeof, CV::Qualifiers q = {} )
    472472        : Type(q), expr(e), kind(k) {}
    473473
     
    482482public:
    483483        VarArgsType( CV::Qualifiers q = {} ) : Type( q ) {}
    484        
     484
    485485        const Type * accept( Visitor & v ) const override { return v.visit( this ); }
    486486private:
     
    493493public:
    494494        ZeroType( CV::Qualifiers q = {} ) : Type( q ) {}
    495        
     495
    496496        const Type * accept( Visitor & v ) const override { return v.visit( this ); }
    497497private:
     
    521521        MUTATE_FRIEND
    522522};
    523 
    524 //=================================================================================================
    525 /// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency
    526 /// remove only if there is a better solution.
    527 /// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with
    528 /// forward declarations
    529 inline void increment( const class Type * node, Node::ref_type ref ) { node->increment( ref ); }
    530 inline void decrement( const class Type * node, Node::ref_type ref ) { node->decrement( ref ); }
    531 inline void increment( const class VoidType * node, Node::ref_type ref ) { node->increment( ref ); }
    532 inline void decrement( const class VoidType * node, Node::ref_type ref ) { node->decrement( ref ); }
    533 inline void increment( const class BasicType * node, Node::ref_type ref ) { node->increment( ref ); }
    534 inline void decrement( const class BasicType * node, Node::ref_type ref ) { node->decrement( ref ); }
    535 inline void increment( const class PointerType * node, Node::ref_type ref ) { node->increment( ref ); }
    536 inline void decrement( const class PointerType * node, Node::ref_type ref ) { node->decrement( ref ); }
    537 inline void increment( const class ArrayType * node, Node::ref_type ref ) { node->increment( ref ); }
    538 inline void decrement( const class ArrayType * node, Node::ref_type ref ) { node->decrement( ref ); }
    539 inline void increment( const class ReferenceType * node, Node::ref_type ref ) { node->increment( ref ); }
    540 inline void decrement( const class ReferenceType * node, Node::ref_type ref ) { node->decrement( ref ); }
    541 inline void increment( const class QualifiedType * node, Node::ref_type ref ) { node->increment( ref ); }
    542 inline void decrement( const class QualifiedType * node, Node::ref_type ref ) { node->decrement( ref ); }
    543 inline void increment( const class FunctionType * node, Node::ref_type ref ) { node->increment( ref ); }
    544 inline void decrement( const class FunctionType * node, Node::ref_type ref ) { node->decrement( ref ); }
    545 inline void increment( const class ReferenceToType * node, Node::ref_type ref ) { node->increment( ref ); }
    546 inline void decrement( const class ReferenceToType * node, Node::ref_type ref ) { node->decrement( ref ); }
    547 inline void increment( const class StructInstType * node, Node::ref_type ref ) { node->increment( ref ); }
    548 inline void decrement( const class StructInstType * node, Node::ref_type ref ) { node->decrement( ref ); }
    549 inline void increment( const class UnionInstType * node, Node::ref_type ref ) { node->increment( ref ); }
    550 inline void decrement( const class UnionInstType * node, Node::ref_type ref ) { node->decrement( ref ); }
    551 inline void increment( const class EnumInstType * node, Node::ref_type ref ) { node->increment( ref ); }
    552 inline void decrement( const class EnumInstType * node, Node::ref_type ref ) { node->decrement( ref ); }
    553 inline void increment( const class TraitInstType * node, Node::ref_type ref ) { node->increment( ref ); }
    554 inline void decrement( const class TraitInstType * node, Node::ref_type ref ) { node->decrement( ref ); }
    555 inline void increment( const class TypeInstType * node, Node::ref_type ref ) { node->increment( ref ); }
    556 inline void decrement( const class TypeInstType * node, Node::ref_type ref ) { node->decrement( ref ); }
    557 inline void increment( const class TupleType * node, Node::ref_type ref ) { node->increment( ref ); }
    558 inline void decrement( const class TupleType * node, Node::ref_type ref ) { node->decrement( ref ); }
    559 inline void increment( const class TypeofType * node, Node::ref_type ref ) { node->increment( ref ); }
    560 inline void decrement( const class TypeofType * node, Node::ref_type ref ) { node->decrement( ref ); }
    561 inline void increment( const class VarArgsType * node, Node::ref_type ref ) { node->increment( ref ); }
    562 inline void decrement( const class VarArgsType * node, Node::ref_type ref ) { node->decrement( ref ); }
    563 inline void increment( const class ZeroType * node, Node::ref_type ref ) { node->increment( ref ); }
    564 inline void decrement( const class ZeroType * node, Node::ref_type ref ) { node->decrement( ref ); }
    565 inline void increment( const class OneType * node, Node::ref_type ref ) { node->increment( ref ); }
    566 inline void decrement( const class OneType * node, Node::ref_type ref ) { node->decrement( ref ); }
    567 inline void increment( const class GlobalScopeType * node, Node::ref_type ref ) { node->increment( ref ); }
    568 inline void decrement( const class GlobalScopeType * node, Node::ref_type ref ) { node->decrement( ref ); }
    569523
    570524}
  • src/AST/porting.md

    rc671112 r41b24c8  
    4848      /// Must be copied in ALL derived classes
    4949      template<typename node_t>
    50       friend auto mutate(const node_t * node);
     50      friend node_t * mutate(const node_t * node);
    5151
    5252All leaves of the `Node` inheritance tree are now declared `final`
  • src/Common/utility.h

    rc671112 r41b24c8  
    463463std::pair<long long int, bool> eval(Expression * expr);
    464464
    465 // -----------------------------------------------------------------------------
    466 /// Reorders the input range in-place so that the minimal-value elements according to the
    467 /// comparator are in front;
     465namespace ast {
     466        class Expr;
     467}
     468
     469std::pair<long long int, bool> eval(const ast::Expr * expr);
     470
     471// -----------------------------------------------------------------------------
     472/// Reorders the input range in-place so that the minimal-value elements according to the
     473/// comparator are in front;
    468474/// returns the iterator after the last minimal-value element.
    469475template<typename Iter, typename Compare>
    470476Iter sort_mins( Iter begin, Iter end, Compare& lt ) {
    471477        if ( begin == end ) return end;
    472        
     478
    473479        Iter min_pos = begin;
    474480        for ( Iter i = begin + 1; i != end; ++i ) {
  • src/Parser/ExpressionNode.cc

    rc671112 r41b24c8  
    6262static inline bool checkB( char c ) { return c == 'b' || c == 'B'; }
    6363static inline bool checkX( char c ) { return c == 'x' || c == 'X'; }
    64 static inline bool checkN( char c ) { return c == 'n' || c == 'N'; }
     64// static inline bool checkN( char c ) { return c == 'n' || c == 'N'; }
    6565
    6666void lnthSuffix( string & str, int & type, int & ltype ) {
     
    217217                } else {                                                                                // explicit length, (length_type)constant
    218218                        ret = new CastExpr( ret, new TypeInstType( Type::Qualifiers(), lnthsInt[Unsigned][ltype], false ), false );
    219                         if ( ltype == 5 ) {                                                     // pointer, intptr( (uintptr_t)constant ) 
    220                                 ret = build_func( new ExpressionNode( build_varref( new string( "intptr" ) ) ), new ExpressionNode( ret ) );                                                             
     219                        if ( ltype == 5 ) {                                                     // pointer, intptr( (uintptr_t)constant )
     220                                ret = build_func( new ExpressionNode( build_varref( new string( "intptr" ) ) ), new ExpressionNode( ret ) );
    221221                        } // if
    222222                } // if
  • src/SynTree/SynTree.h

    rc671112 r41b24c8  
    3434class NamedTypeDecl;
    3535class TypeDecl;
    36 class FtypeDecl;
    37 class DtypeDecl;
    3836class TypedefDecl;
    3937class AsmDecl;
Note: See TracChangeset for help on using the changeset viewer.