Changes in / [302d84c2:fce4e31]


Ignore:
Location:
src
Files:
30 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r302d84c2 rfce4e31  
    13551355        ast::Node * node = nullptr;
    13561356        /// cache of nodes that might be referenced by readonly<> for de-duplication
    1357         std::unordered_map< BaseSyntaxNode *, ast::Node * > cache = {};
     1357        std::unordered_map< const BaseSyntaxNode *, ast::Node * > cache = {};
    13581358
    13591359        // Local Utilities:
     
    14221422                to<std::vector>::from( make_labels( std::move( labels ) ) )
    14231423
    1424         static ast::CV::Qualifiers cv( Type * ty ) { return { ty->get_qualifiers().val }; }
     1424        static ast::CV::Qualifiers cv( const Type * ty ) { return { ty->tq.val }; }
    14251425
    14261426        /// returns true and sets `node` if in cache
    1427         bool inCache( BaseSyntaxNode * old ) {
     1427        bool inCache( const BaseSyntaxNode * old ) {
    14281428                auto it = cache.find( old );
    14291429                if ( it == cache.end() ) return false;
     
    14341434        // Now all the visit functions:
    14351435
    1436         virtual void visit( ObjectDecl * old ) override final {
     1436        virtual void visit( const ObjectDecl * old ) override final {
    14371437                auto&& type = GET_ACCEPT_1(type, Type);
    14381438                auto&& init = GET_ACCEPT_1(init, Init);
     
    14651465        }
    14661466
    1467         virtual void visit( FunctionDecl * old ) override final {
     1467        virtual void visit( const FunctionDecl * old ) override final {
    14681468                if ( inCache( old ) ) return;
    14691469                auto decl = new ast::FunctionDecl{
     
    14981498        }
    14991499
    1500         virtual void visit( StructDecl * old ) override final {
     1500        virtual void visit( const StructDecl * old ) override final {
    15011501                if ( inCache( old ) ) return;
    15021502                auto decl = new ast::StructDecl(
     
    15231523        }
    15241524
    1525         virtual void visit( UnionDecl * old ) override final {
     1525        virtual void visit( const UnionDecl * old ) override final {
    15261526                if ( inCache( old ) ) return;
    15271527                auto decl = new ast::UnionDecl(
     
    15431543        }
    15441544
    1545         virtual void visit( EnumDecl * old ) override final {
     1545        virtual void visit( const EnumDecl * old ) override final {
    15461546                if ( inCache( old ) ) return;
    15471547                auto decl = new ast::EnumDecl(
     
    15631563        }
    15641564
    1565         virtual void visit( TraitDecl * old ) override final {
     1565        virtual void visit( const TraitDecl * old ) override final {
    15661566                if ( inCache( old ) ) return;
    15671567                auto decl = new ast::TraitDecl(
     
    15831583        }
    15841584
    1585         virtual void visit( TypeDecl * old ) override final {
     1585        virtual void visit( const TypeDecl * old ) override final {
    15861586                if ( inCache( old ) ) return;
    15871587                auto decl = new ast::TypeDecl{
     
    16031603        }
    16041604
    1605         virtual void visit( TypedefDecl * old ) override final {
     1605        virtual void visit( const TypedefDecl * old ) override final {
    16061606                auto decl = new ast::TypedefDecl(
    16071607                        old->location,
     
    16201620        }
    16211621
    1622         virtual void visit( AsmDecl * old ) override final {
     1622        virtual void visit( const AsmDecl * old ) override final {
    16231623                auto decl = new ast::AsmDecl{
    16241624                        old->location,
     
    16321632        }
    16331633
    1634         virtual void visit( StaticAssertDecl * old ) override final {
     1634        virtual void visit( const StaticAssertDecl * old ) override final {
    16351635                auto decl = new ast::StaticAssertDecl{
    16361636                        old->location,
     
    16451645        }
    16461646
    1647         virtual void visit( CompoundStmt * old ) override final {
     1647        virtual void visit( const CompoundStmt * old ) override final {
    16481648                if ( inCache( old ) ) return;
    16491649                auto stmt = new ast::CompoundStmt(
     
    16571657        }
    16581658
    1659         virtual void visit( ExprStmt * old ) override final {
     1659        virtual void visit( const ExprStmt * old ) override final {
    16601660                if ( inCache( old ) ) return;
    16611661                this->node = new ast::ExprStmt(
     
    16671667        }
    16681668
    1669         virtual void visit( AsmStmt * old ) override final {
     1669        virtual void visit( const AsmStmt * old ) override final {
    16701670                if ( inCache( old ) ) return;
    16711671                this->node = new ast::AsmStmt(
     
    16821682        }
    16831683
    1684         virtual void visit( DirectiveStmt * old ) override final {
     1684        virtual void visit( const DirectiveStmt * old ) override final {
    16851685                if ( inCache( old ) ) return;
    16861686                this->node = new ast::DirectiveStmt(
     
    16921692        }
    16931693
    1694         virtual void visit( IfStmt * old ) override final {
     1694        virtual void visit( const IfStmt * old ) override final {
    16951695                if ( inCache( old ) ) return;
    16961696                this->node = new ast::IfStmt(
     
    17051705        }
    17061706
    1707         virtual void visit( SwitchStmt * old ) override final {
     1707        virtual void visit( const SwitchStmt * old ) override final {
    17081708                if ( inCache( old ) ) return;
    17091709                this->node = new ast::SwitchStmt(
     
    17161716        }
    17171717
    1718         virtual void visit( CaseStmt * old ) override final {
     1718        virtual void visit( const CaseStmt * old ) override final {
    17191719                if ( inCache( old ) ) return;
    17201720                this->node = new ast::CaseStmt(
     
    17271727        }
    17281728
    1729         virtual void visit( WhileStmt * old ) override final {
     1729        virtual void visit( const WhileStmt * old ) override final {
    17301730                if ( inCache( old ) ) return;
    17311731                this->node = new ast::WhileStmt(
     
    17401740        }
    17411741
    1742         virtual void visit( ForStmt * old ) override final {
     1742        virtual void visit( const ForStmt * old ) override final {
    17431743                if ( inCache( old ) ) return;
    17441744                this->node = new ast::ForStmt(
     
    17531753        }
    17541754
    1755         virtual void visit( BranchStmt * old ) override final {
     1755        virtual void visit( const BranchStmt * old ) override final {
    17561756                if ( inCache( old ) ) return;
    17571757                if (old->computedTarget) {
     
    17901790        }
    17911791
    1792         virtual void visit( ReturnStmt * old ) override final {
     1792        virtual void visit( const ReturnStmt * old ) override final {
    17931793                if ( inCache( old ) ) return;
    17941794                this->node = new ast::ReturnStmt(
     
    18001800        }
    18011801
    1802         virtual void visit( ThrowStmt * old ) override final {
     1802        virtual void visit( const ThrowStmt * old ) override final {
    18031803                if ( inCache( old ) ) return;
    18041804                ast::ExceptionKind kind;
     
    18241824        }
    18251825
    1826         virtual void visit( TryStmt * old ) override final {
     1826        virtual void visit( const TryStmt * old ) override final {
    18271827                if ( inCache( old ) ) return;
    18281828                this->node = new ast::TryStmt(
     
    18361836        }
    18371837
    1838         virtual void visit( CatchStmt * old ) override final {
     1838        virtual void visit( const CatchStmt * old ) override final {
    18391839                if ( inCache( old ) ) return;
    18401840                ast::ExceptionKind kind;
     
    18611861        }
    18621862
    1863         virtual void visit( FinallyStmt * old ) override final {
     1863        virtual void visit( const FinallyStmt * old ) override final {
    18641864                if ( inCache( old ) ) return;
    18651865                this->node = new ast::FinallyStmt(
     
    18711871        }
    18721872
    1873         virtual void visit( WaitForStmt * old ) override final {
     1873        virtual void visit( const WaitForStmt * old ) override final {
    18741874                if ( inCache( old ) ) return;
    18751875                ast::WaitForStmt * stmt = new ast::WaitForStmt(
     
    19031903        }
    19041904
    1905         virtual void visit( WithStmt * old ) override final {
     1905        virtual void visit( const WithStmt * old ) override final {
    19061906                if ( inCache( old ) ) return;
    19071907                this->node = new ast::WithStmt(
     
    19141914        }
    19151915
    1916         virtual void visit( NullStmt * old ) override final {
     1916        virtual void visit( const NullStmt * old ) override final {
    19171917                if ( inCache( old ) ) return;
    19181918                this->node = new ast::NullStmt(
     
    19231923        }
    19241924
    1925         virtual void visit( DeclStmt * old ) override final {
     1925        virtual void visit( const DeclStmt * old ) override final {
    19261926                if ( inCache( old ) ) return;
    19271927                this->node = new ast::DeclStmt(
     
    19331933        }
    19341934
    1935         virtual void visit( ImplicitCtorDtorStmt * old ) override final {
     1935        virtual void visit( const ImplicitCtorDtorStmt * old ) override final {
    19361936                if ( inCache( old ) ) return;
    19371937                auto stmt = new ast::ImplicitCtorDtorStmt(
     
    19901990        }
    19911991
    1992         ast::Expr * visitBaseExpr_SkipResultType(Expression * old, ast::Expr * nw) {
     1992        ast::Expr * visitBaseExpr_SkipResultType( const Expression * old, ast::Expr * nw) {
    19931993
    19941994                nw->env    = convertTypeSubstitution(old->env);
     
    20002000        }
    20012001
    2002         ast::Expr * visitBaseExpr(Expression * old, ast::Expr * nw) {
     2002        ast::Expr * visitBaseExpr( const Expression * old, ast::Expr * nw) {
    20032003
    20042004                nw->result = GET_ACCEPT_1(result, Type);
     
    20062006        }
    20072007
    2008         virtual void visit( ApplicationExpr * old ) override final {
     2008        virtual void visit( const ApplicationExpr * old ) override final {
    20092009                this->node = visitBaseExpr( old,
    20102010                        new ast::ApplicationExpr(
     
    20162016        }
    20172017
    2018         virtual void visit( UntypedExpr * old ) override final {
     2018        virtual void visit( const UntypedExpr * old ) override final {
    20192019                this->node = visitBaseExpr( old,
    20202020                        new ast::UntypedExpr(
     
    20262026        }
    20272027
    2028         virtual void visit( NameExpr * old ) override final {
     2028        virtual void visit( const NameExpr * old ) override final {
    20292029                this->node = visitBaseExpr( old,
    20302030                        new ast::NameExpr(
     
    20352035        }
    20362036
    2037         virtual void visit( CastExpr * old ) override final {
     2037        virtual void visit( const CastExpr * old ) override final {
    20382038                this->node = visitBaseExpr( old,
    20392039                        new ast::CastExpr(
     
    20452045        }
    20462046
    2047         virtual void visit( KeywordCastExpr * old) override final {
     2047        virtual void visit( const KeywordCastExpr * old) override final {
    20482048                ast::KeywordCastExpr::Target castTarget = ast::KeywordCastExpr::NUMBER_OF_TARGETS;
    20492049                switch (old->target) {
     
    20702070        }
    20712071
    2072         virtual void visit( VirtualCastExpr * old ) override final {
     2072        virtual void visit( const VirtualCastExpr * old ) override final {
    20732073                this->node = visitBaseExpr_SkipResultType( old,
    20742074                        new ast::VirtualCastExpr(
     
    20802080        }
    20812081
    2082         virtual void visit( AddressExpr * old ) override final {
     2082        virtual void visit( const AddressExpr * old ) override final {
    20832083                this->node = visitBaseExpr( old,
    20842084                        new ast::AddressExpr(
     
    20892089        }
    20902090
    2091         virtual void visit( LabelAddressExpr * old ) override final {
     2091        virtual void visit( const LabelAddressExpr * old ) override final {
    20922092                this->node = visitBaseExpr( old,
    20932093                        new ast::LabelAddressExpr(
     
    20982098        }
    20992099
    2100         virtual void visit( UntypedMemberExpr * old ) override final {
     2100        virtual void visit( const UntypedMemberExpr * old ) override final {
    21012101                this->node = visitBaseExpr( old,
    21022102                        new ast::UntypedMemberExpr(
     
    21082108        }
    21092109
    2110         virtual void visit( MemberExpr * old ) override final {
     2110        virtual void visit( const MemberExpr * old ) override final {
    21112111                this->node = visitBaseExpr( old,
    21122112                        new ast::MemberExpr(
     
    21182118        }
    21192119
    2120         virtual void visit( VariableExpr * old ) override final {
     2120        virtual void visit( const VariableExpr * old ) override final {
    21212121                auto expr = new ast::VariableExpr(
    21222122                        old->location
     
    21292129        }
    21302130
    2131         virtual void visit( ConstantExpr * old ) override final {
     2131        virtual void visit( const ConstantExpr * old ) override final {
    21322132                ast::ConstantExpr *rslt = new ast::ConstantExpr(
    21332133                        old->location,
    21342134                        GET_ACCEPT_1(result, Type),
    2135                         old->constant.get_value(),
     2135                        old->constant.rep,
    21362136                        old->constant.ival
    21372137                );
    2138                 rslt->underlyer = getAccept1< ast::Type, Type* >( old->constant.get_type() );
     2138                rslt->underlyer = getAccept1< ast::Type, Type* >( old->constant.type );
    21392139                this->node = visitBaseExpr( old, rslt );
    21402140        }
    21412141
    2142         virtual void visit( SizeofExpr * old ) override final {
     2142        virtual void visit( const SizeofExpr * old ) override final {
    21432143                assert (old->expr || old->type);
    21442144                assert (! (old->expr && old->type));
     
    21612161        }
    21622162
    2163         virtual void visit( AlignofExpr * old ) override final {
     2163        virtual void visit( const AlignofExpr * old ) override final {
    21642164                assert (old->expr || old->type);
    21652165                assert (! (old->expr && old->type));
     
    21822182        }
    21832183
    2184         virtual void visit( UntypedOffsetofExpr * old ) override final {
     2184        virtual void visit( const UntypedOffsetofExpr * old ) override final {
    21852185                this->node = visitBaseExpr( old,
    21862186                        new ast::UntypedOffsetofExpr(
     
    21922192        }
    21932193
    2194         virtual void visit( OffsetofExpr * old ) override final {
     2194        virtual void visit( const OffsetofExpr * old ) override final {
    21952195                this->node = visitBaseExpr( old,
    21962196                        new ast::OffsetofExpr(
     
    22022202        }
    22032203
    2204         virtual void visit( OffsetPackExpr * old ) override final {
     2204        virtual void visit( const OffsetPackExpr * old ) override final {
    22052205                this->node = visitBaseExpr( old,
    22062206                        new ast::OffsetPackExpr(
     
    22112211        }
    22122212
    2213         virtual void visit( LogicalExpr * old ) override final {
     2213        virtual void visit( const LogicalExpr * old ) override final {
    22142214                this->node = visitBaseExpr( old,
    22152215                        new ast::LogicalExpr(
     
    22242224        }
    22252225
    2226         virtual void visit( ConditionalExpr * old ) override final {
     2226        virtual void visit( const ConditionalExpr * old ) override final {
    22272227                this->node = visitBaseExpr( old,
    22282228                        new ast::ConditionalExpr(
     
    22352235        }
    22362236
    2237         virtual void visit( CommaExpr * old ) override final {
     2237        virtual void visit( const CommaExpr * old ) override final {
    22382238                this->node = visitBaseExpr( old,
    22392239                        new ast::CommaExpr(
     
    22452245        }
    22462246
    2247         virtual void visit( TypeExpr * old ) override final {
     2247        virtual void visit( const TypeExpr * old ) override final {
    22482248                this->node = visitBaseExpr( old,
    22492249                        new ast::TypeExpr(
     
    22542254        }
    22552255
    2256         virtual void visit( AsmExpr * old ) override final {
     2256        virtual void visit( const AsmExpr * old ) override final {
    22572257                this->node = visitBaseExpr( old,
    22582258                        new ast::AsmExpr(
     
    22652265        }
    22662266
    2267         virtual void visit( ImplicitCopyCtorExpr * old ) override final {
     2267        virtual void visit( const ImplicitCopyCtorExpr * old ) override final {
    22682268                auto rslt = new ast::ImplicitCopyCtorExpr(
    22692269                        old->location,
     
    22742274        }
    22752275
    2276         virtual void visit( ConstructorExpr * old ) override final {
     2276        virtual void visit( const ConstructorExpr * old ) override final {
    22772277                this->node = visitBaseExpr( old,
    22782278                        new ast::ConstructorExpr(
     
    22832283        }
    22842284
    2285         virtual void visit( CompoundLiteralExpr * old ) override final {
     2285        virtual void visit( const CompoundLiteralExpr * old ) override final {
    22862286                this->node = visitBaseExpr_SkipResultType( old,
    22872287                        new ast::CompoundLiteralExpr(
     
    22932293        }
    22942294
    2295         virtual void visit( RangeExpr * old ) override final {
     2295        virtual void visit( const RangeExpr * old ) override final {
    22962296                this->node = visitBaseExpr( old,
    22972297                        new ast::RangeExpr(
     
    23032303        }
    23042304
    2305         virtual void visit( UntypedTupleExpr * old ) override final {
     2305        virtual void visit( const UntypedTupleExpr * old ) override final {
    23062306                this->node = visitBaseExpr( old,
    23072307                        new ast::UntypedTupleExpr(
     
    23122312        }
    23132313
    2314         virtual void visit( TupleExpr * old ) override final {
     2314        virtual void visit( const TupleExpr * old ) override final {
    23152315                this->node = visitBaseExpr( old,
    23162316                        new ast::TupleExpr(
     
    23212321        }
    23222322
    2323         virtual void visit( TupleIndexExpr * old ) override final {
     2323        virtual void visit( const TupleIndexExpr * old ) override final {
    23242324                this->node = visitBaseExpr( old,
    23252325                        new ast::TupleIndexExpr(
     
    23312331        }
    23322332
    2333         virtual void visit( TupleAssignExpr * old ) override final {
     2333        virtual void visit( const TupleAssignExpr * old ) override final {
    23342334                this->node = visitBaseExpr_SkipResultType( old,
    23352335                        new ast::TupleAssignExpr(
     
    23412341        }
    23422342
    2343         virtual void visit( StmtExpr * old ) override final {
     2343        virtual void visit( const StmtExpr * old ) override final {
    23442344                auto rslt = new ast::StmtExpr(
    23452345                        old->location,
     
    23522352        }
    23532353
    2354         virtual void visit( UniqueExpr * old ) override final {
     2354        virtual void visit( const UniqueExpr * old ) override final {
    23552355                auto rslt = new ast::UniqueExpr(
    23562356                        old->location,
     
    23642364        }
    23652365
    2366         virtual void visit( UntypedInitExpr * old ) override final {
     2366        virtual void visit( const UntypedInitExpr * old ) override final {
    23672367                std::deque<ast::InitAlternative> initAlts;
    23682368                for (auto ia : old->initAlts) {
     
    23812381        }
    23822382
    2383         virtual void visit( InitExpr * old ) override final {
     2383        virtual void visit( const InitExpr * old ) override final {
    23842384                this->node = visitBaseExpr( old,
    23852385                        new ast::InitExpr(
     
    23912391        }
    23922392
    2393         virtual void visit( DeletedExpr * old ) override final {
     2393        virtual void visit( const DeletedExpr * old ) override final {
    23942394                this->node = visitBaseExpr( old,
    23952395                        new ast::DeletedExpr(
     
    24032403        }
    24042404
    2405         virtual void visit( DefaultArgExpr * old ) override final {
     2405        virtual void visit( const DefaultArgExpr * old ) override final {
    24062406                this->node = visitBaseExpr( old,
    24072407                        new ast::DefaultArgExpr(
     
    24122412        }
    24132413
    2414         virtual void visit( GenericExpr * old ) override final {
     2414        virtual void visit( const GenericExpr * old ) override final {
    24152415                std::vector<ast::GenericExpr::Association> associations;
    24162416                for (auto association : old->associations) {
     
    24292429        }
    24302430
    2431         void visitType( Type * old, ast::Type * type ) {
     2431        void visitType( const Type * old, ast::Type * type ) {
    24322432                // Some types do this in their constructor so add a check.
    24332433                if ( !old->attributes.empty() && type->attributes.empty() ) {
     
    24372437        }
    24382438
    2439         virtual void visit( VoidType * old ) override final {
     2439        virtual void visit( const VoidType * old ) override final {
    24402440                visitType( old, new ast::VoidType{ cv( old ) } );
    24412441        }
    24422442
    2443         virtual void visit( BasicType * old ) override final {
     2443        virtual void visit( const BasicType * old ) override final {
    24442444                auto type = new ast::BasicType{ (ast::BasicType::Kind)(unsigned)old->kind, cv( old ) };
    24452445                // I believe this should always be a BasicType.
     
    24502450        }
    24512451
    2452         virtual void visit( PointerType * old ) override final {
     2452        virtual void visit( const PointerType * old ) override final {
    24532453                visitType( old, new ast::PointerType{
    24542454                        GET_ACCEPT_1( base, Type ),
     
    24602460        }
    24612461
    2462         virtual void visit( ArrayType * old ) override final {
     2462        virtual void visit( const ArrayType * old ) override final {
    24632463                visitType( old, new ast::ArrayType{
    24642464                        GET_ACCEPT_1( base, Type ),
     
    24702470        }
    24712471
    2472         virtual void visit( ReferenceType * old ) override final {
     2472        virtual void visit( const ReferenceType * old ) override final {
    24732473                visitType( old, new ast::ReferenceType{
    24742474                        GET_ACCEPT_1( base, Type ),
     
    24772477        }
    24782478
    2479         virtual void visit( QualifiedType * old ) override final {
     2479        virtual void visit( const QualifiedType * old ) override final {
    24802480                visitType( old, new ast::QualifiedType{
    24812481                        GET_ACCEPT_1( parent, Type ),
     
    24852485        }
    24862486
    2487         virtual void visit( FunctionType * old ) override final {
     2487        virtual void visit( const FunctionType * old ) override final {
    24882488                auto ty = new ast::FunctionType {
    24892489                        (ast::ArgumentFlag)old->isVarArgs,
     
    24962496        }
    24972497
    2498         void postvisit( ReferenceToType * old, ast::ReferenceToType * ty ) {
     2498        void postvisit( const ReferenceToType * old, ast::ReferenceToType * ty ) {
    24992499                ty->forall = GET_ACCEPT_V( forall, TypeDecl );
    25002500                ty->params = GET_ACCEPT_V( parameters, Expr );
     
    25032503        }
    25042504
    2505         virtual void visit( StructInstType * old ) override final {
     2505        virtual void visit( const StructInstType * old ) override final {
    25062506                ast::StructInstType * ty;
    25072507                if ( old->baseStruct ) {
     
    25212521        }
    25222522
    2523         virtual void visit( UnionInstType * old ) override final {
     2523        virtual void visit( const UnionInstType * old ) override final {
    25242524                ast::UnionInstType * ty;
    25252525                if ( old->baseUnion ) {
     
    25392539        }
    25402540
    2541         virtual void visit( EnumInstType * old ) override final {
     2541        virtual void visit( const EnumInstType * old ) override final {
    25422542                ast::EnumInstType * ty;
    25432543                if ( old->baseEnum ) {
     
    25572557        }
    25582558
    2559         virtual void visit( TraitInstType * old ) override final {
     2559        virtual void visit( const TraitInstType * old ) override final {
    25602560                ast::TraitInstType * ty;
    25612561                if ( old->baseTrait ) {
     
    25752575        }
    25762576
    2577         virtual void visit( TypeInstType * old ) override final {
     2577        virtual void visit( const TypeInstType * old ) override final {
    25782578                ast::TypeInstType * ty;
    25792579                if ( old->baseType ) {
     
    25952595        }
    25962596
    2597         virtual void visit( TupleType * old ) override final {
     2597        virtual void visit( const TupleType * old ) override final {
    25982598                visitType( old, new ast::TupleType{
    25992599                        GET_ACCEPT_V( types, Type ),
     
    26032603        }
    26042604
    2605         virtual void visit( TypeofType * old ) override final {
     2605        virtual void visit( const TypeofType * old ) override final {
    26062606                visitType( old, new ast::TypeofType{
    26072607                        GET_ACCEPT_1( expr, Expr ),
     
    26112611        }
    26122612
    2613         virtual void visit( AttrType * ) override final {
     2613        virtual void visit( const AttrType * ) override final {
    26142614                assertf( false, "AttrType deprecated in new AST." );
    26152615        }
    26162616
    2617         virtual void visit( VarArgsType * old ) override final {
     2617        virtual void visit( const VarArgsType * old ) override final {
    26182618                visitType( old, new ast::VarArgsType{ cv( old ) } );
    26192619        }
    26202620
    2621         virtual void visit( ZeroType * old ) override final {
     2621        virtual void visit( const ZeroType * old ) override final {
    26222622                visitType( old, new ast::ZeroType{ cv( old ) } );
    26232623        }
    26242624
    2625         virtual void visit( OneType * old ) override final {
     2625        virtual void visit( const OneType * old ) override final {
    26262626                visitType( old, new ast::OneType{ cv( old ) } );
    26272627        }
    26282628
    2629         virtual void visit( GlobalScopeType * old ) override final {
     2629        virtual void visit( const GlobalScopeType * old ) override final {
    26302630                visitType( old, new ast::GlobalScopeType{} );
    26312631        }
    26322632
    2633         virtual void visit( Designation * old ) override final {
     2633        virtual void visit( const Designation * old ) override final {
    26342634                this->node = new ast::Designation(
    26352635                        old->location,
     
    26382638        }
    26392639
    2640         virtual void visit( SingleInit * old ) override final {
     2640        virtual void visit( const SingleInit * old ) override final {
    26412641                this->node = new ast::SingleInit(
    26422642                        old->location,
     
    26462646        }
    26472647
    2648         virtual void visit( ListInit * old ) override final {
     2648        virtual void visit( const ListInit * old ) override final {
    26492649                this->node = new ast::ListInit(
    26502650                        old->location,
     
    26552655        }
    26562656
    2657         virtual void visit( ConstructorInit * old ) override final {
     2657        virtual void visit( const ConstructorInit * old ) override final {
    26582658                this->node = new ast::ConstructorInit(
    26592659                        old->location,
     
    26642664        }
    26652665
    2666         virtual void visit( Constant * ) override final {
     2666        virtual void visit( const Constant * ) override final {
    26672667                // Handled in visit( ConstantEpxr * ).
    26682668                // In the new tree, Constant fields are inlined into containing ConstantExpression.
     
    26702670        }
    26712671
    2672         virtual void visit( Attribute * old ) override final {
     2672        virtual void visit( const Attribute * old ) override final {
    26732673                this->node = new ast::Attribute(
    26742674                        old->name,
     
    26772677        }
    26782678
    2679         virtual void visit( AttrExpr * ) override final {
     2679        virtual void visit( const AttrExpr * ) override final {
    26802680                assertf( false, "AttrExpr deprecated in new AST." );
    26812681        }
  • src/AST/Expr.hpp

    r302d84c2 rfce4e31  
    4747
    4848        ParamEntry() : decl( 0 ), declptr( nullptr ), actualType( nullptr ), formalType( nullptr ), expr( nullptr ) {}
    49         ParamEntry( 
    50                 UniqueId id, const Decl * declptr, const Type * actual, const Type * formal, 
     49        ParamEntry(
     50                UniqueId id, const Decl * declptr, const Type * actual, const Type * formal,
    5151                const Expr * e )
    5252        : decl( id ), declptr( declptr ), actualType( actual ), formalType( formal ), expr( e ) {}
     
    112112                        case Empty: new(&data.resnSlots) ResnSlots{}; mode = Slots; // fallthrough
    113113                        case Slots: return data.resnSlots;
    114                         case Params: assert(!"Cannot return to resnSlots from Params");
     114                        case Params: assertf(false, "Cannot return to resnSlots from Params"); abort();
    115115                        }
    116                         return *((ResnSlots*)nullptr);
    117116                }
    118117
     
    121120                                return data.resnSlots;
    122121                        }
    123                         assert(!"Mode was not already resnSlots");
    124                         return *((ResnSlots*)nullptr);
     122                        assertf(false, "Mode was not already resnSlots");
     123                        abort();
    125124                }
    126125
     
    131130                        case Params: return data.inferParams;
    132131                        }
    133                         assert(!"unreachable");
    134                         return *((InferredParams*)nullptr);
     132                        assertf(false, "unreachable");
    135133                }
    136134
     
    139137                                return data.inferParams;
    140138                        }
    141                         assert(!"Mode was not already Params");
    142                         return *((InferredParams*)nullptr);
     139                        assertf(false, "Mode was not already Params");
     140                        abort();
    143141                }
    144142
    145143                void set_inferParams( InferredParams && ps ) {
    146144                        switch(mode) {
    147                         case Slots: 
     145                        case Slots:
    148146                                data.resnSlots.~ResnSlots();
    149147                                // fallthrough
    150                         case Empty: 
     148                        case Empty:
    151149                                new(&data.inferParams) InferredParams{ std::move( ps ) };
    152150                                mode = Params;
     
    172170                                        data.inferParams[p.first] = std::move(p.second);
    173171                                }
    174                         } else assert(!"invalid mode");
     172                        } else assertf(false, "invalid mode");
    175173                }
    176174        };
     
    384382
    385383        ConstantExpr(
    386                 const CodeLocation & loc, const Type * ty, const std::string & r, 
     384                const CodeLocation & loc, const Type * ty, const std::string & r,
    387385                        std::optional<unsigned long long> i )
    388386        : Expr( loc, ty ), rep( r ), ival( i ) {}
  • src/Common/PassVisitor.h

    r302d84c2 rfce4e31  
    6060
    6161        virtual void visit( ObjectDecl * objectDecl ) override final;
     62        virtual void visit( const ObjectDecl * objectDecl ) override final;
    6263        virtual void visit( FunctionDecl * functionDecl ) override final;
     64        virtual void visit( const FunctionDecl * functionDecl ) override final;
    6365        virtual void visit( StructDecl * aggregateDecl ) override final;
     66        virtual void visit( const StructDecl * aggregateDecl ) override final;
    6467        virtual void visit( UnionDecl * aggregateDecl ) override final;
     68        virtual void visit( const UnionDecl * aggregateDecl ) override final;
    6569        virtual void visit( EnumDecl * aggregateDecl ) override final;
     70        virtual void visit( const EnumDecl * aggregateDecl ) override final;
    6671        virtual void visit( TraitDecl * aggregateDecl ) override final;
     72        virtual void visit( const TraitDecl * aggregateDecl ) override final;
    6773        virtual void visit( TypeDecl * typeDecl ) override final;
     74        virtual void visit( const TypeDecl * typeDecl ) override final;
    6875        virtual void visit( TypedefDecl * typeDecl ) override final;
     76        virtual void visit( const TypedefDecl * typeDecl ) override final;
    6977        virtual void visit( AsmDecl * asmDecl ) override final;
     78        virtual void visit( const AsmDecl * asmDecl ) override final;
    7079        virtual void visit( StaticAssertDecl * assertDecl ) override final;
     80        virtual void visit( const StaticAssertDecl * assertDecl ) override final;
    7181
    7282        virtual void visit( CompoundStmt * compoundStmt ) override final;
     83        virtual void visit( const CompoundStmt * compoundStmt ) override final;
    7384        virtual void visit( ExprStmt * exprStmt ) override final;
     85        virtual void visit( const ExprStmt * exprStmt ) override final;
    7486        virtual void visit( AsmStmt * asmStmt ) override final;
     87        virtual void visit( const AsmStmt * asmStmt ) override final;
    7588        virtual void visit( DirectiveStmt * dirStmt ) override final;
     89        virtual void visit( const DirectiveStmt * dirStmt ) override final;
    7690        virtual void visit( IfStmt * ifStmt ) override final;
     91        virtual void visit( const IfStmt * ifStmt ) override final;
    7792        virtual void visit( WhileStmt * whileStmt ) override final;
     93        virtual void visit( const WhileStmt * whileStmt ) override final;
    7894        virtual void visit( ForStmt * forStmt ) override final;
     95        virtual void visit( const ForStmt * forStmt ) override final;
    7996        virtual void visit( SwitchStmt * switchStmt ) override final;
     97        virtual void visit( const SwitchStmt * switchStmt ) override final;
    8098        virtual void visit( CaseStmt * caseStmt ) override final;
     99        virtual void visit( const CaseStmt * caseStmt ) override final;
    81100        virtual void visit( BranchStmt * branchStmt ) override final;
     101        virtual void visit( const BranchStmt * branchStmt ) override final;
    82102        virtual void visit( ReturnStmt * returnStmt ) override final;
     103        virtual void visit( const ReturnStmt * returnStmt ) override final;
    83104        virtual void visit( ThrowStmt * throwStmt ) override final;
     105        virtual void visit( const ThrowStmt * throwStmt ) override final;
    84106        virtual void visit( TryStmt * tryStmt ) override final;
     107        virtual void visit( const TryStmt * tryStmt ) override final;
    85108        virtual void visit( CatchStmt * catchStmt ) override final;
     109        virtual void visit( const CatchStmt * catchStmt ) override final;
    86110        virtual void visit( FinallyStmt * finallyStmt ) override final;
     111        virtual void visit( const FinallyStmt * finallyStmt ) override final;
    87112        virtual void visit( WaitForStmt * waitforStmt ) override final;
     113        virtual void visit( const WaitForStmt * waitforStmt ) override final;
    88114        virtual void visit( WithStmt * withStmt ) override final;
     115        virtual void visit( const WithStmt * withStmt ) override final;
    89116        virtual void visit( NullStmt * nullStmt ) override final;
     117        virtual void visit( const NullStmt * nullStmt ) override final;
    90118        virtual void visit( DeclStmt * declStmt ) override final;
     119        virtual void visit( const DeclStmt * declStmt ) override final;
    91120        virtual void visit( ImplicitCtorDtorStmt * impCtorDtorStmt ) override final;
     121        virtual void visit( const ImplicitCtorDtorStmt * impCtorDtorStmt ) override final;
    92122
    93123        virtual void visit( ApplicationExpr * applicationExpr ) override final;
     124        virtual void visit( const ApplicationExpr * applicationExpr ) override final;
    94125        virtual void visit( UntypedExpr * untypedExpr ) override final;
     126        virtual void visit( const UntypedExpr * untypedExpr ) override final;
    95127        virtual void visit( NameExpr * nameExpr ) override final;
     128        virtual void visit( const NameExpr * nameExpr ) override final;
    96129        virtual void visit( CastExpr * castExpr ) override final;
     130        virtual void visit( const CastExpr * castExpr ) override final;
    97131        virtual void visit( KeywordCastExpr * castExpr ) override final;
     132        virtual void visit( const KeywordCastExpr * castExpr ) override final;
    98133        virtual void visit( VirtualCastExpr * castExpr ) override final;
     134        virtual void visit( const VirtualCastExpr * castExpr ) override final;
    99135        virtual void visit( AddressExpr * addressExpr ) override final;
     136        virtual void visit( const AddressExpr * addressExpr ) override final;
    100137        virtual void visit( LabelAddressExpr * labAddressExpr ) override final;
     138        virtual void visit( const LabelAddressExpr * labAddressExpr ) override final;
    101139        virtual void visit( UntypedMemberExpr * memberExpr ) override final;
     140        virtual void visit( const UntypedMemberExpr * memberExpr ) override final;
    102141        virtual void visit( MemberExpr * memberExpr ) override final;
     142        virtual void visit( const MemberExpr * memberExpr ) override final;
    103143        virtual void visit( VariableExpr * variableExpr ) override final;
     144        virtual void visit( const VariableExpr * variableExpr ) override final;
    104145        virtual void visit( ConstantExpr * constantExpr ) override final;
     146        virtual void visit( const ConstantExpr * constantExpr ) override final;
    105147        virtual void visit( SizeofExpr * sizeofExpr ) override final;
     148        virtual void visit( const SizeofExpr * sizeofExpr ) override final;
    106149        virtual void visit( AlignofExpr * alignofExpr ) override final;
     150        virtual void visit( const AlignofExpr * alignofExpr ) override final;
    107151        virtual void visit( UntypedOffsetofExpr * offsetofExpr ) override final;
     152        virtual void visit( const UntypedOffsetofExpr * offsetofExpr ) override final;
    108153        virtual void visit( OffsetofExpr * offsetofExpr ) override final;
     154        virtual void visit( const OffsetofExpr * offsetofExpr ) override final;
    109155        virtual void visit( OffsetPackExpr * offsetPackExpr ) override final;
     156        virtual void visit( const OffsetPackExpr * offsetPackExpr ) override final;
    110157        virtual void visit( AttrExpr * attrExpr ) override final;
     158        virtual void visit( const AttrExpr * attrExpr ) override final;
    111159        virtual void visit( LogicalExpr * logicalExpr ) override final;
     160        virtual void visit( const LogicalExpr * logicalExpr ) override final;
    112161        virtual void visit( ConditionalExpr * conditionalExpr ) override final;
     162        virtual void visit( const ConditionalExpr * conditionalExpr ) override final;
    113163        virtual void visit( CommaExpr * commaExpr ) override final;
     164        virtual void visit( const CommaExpr * commaExpr ) override final;
    114165        virtual void visit( TypeExpr * typeExpr ) override final;
     166        virtual void visit( const TypeExpr * typeExpr ) override final;
    115167        virtual void visit( AsmExpr * asmExpr ) override final;
     168        virtual void visit( const AsmExpr * asmExpr ) override final;
    116169        virtual void visit( ImplicitCopyCtorExpr * impCpCtorExpr ) override final;
     170        virtual void visit( const ImplicitCopyCtorExpr * impCpCtorExpr ) override final;
    117171        virtual void visit( ConstructorExpr *  ctorExpr ) override final;
     172        virtual void visit( const ConstructorExpr *  ctorExpr ) override final;
    118173        virtual void visit( CompoundLiteralExpr * compLitExpr ) override final;
     174        virtual void visit( const CompoundLiteralExpr * compLitExpr ) override final;
    119175        virtual void visit( RangeExpr * rangeExpr ) override final;
     176        virtual void visit( const RangeExpr * rangeExpr ) override final;
    120177        virtual void visit( UntypedTupleExpr * tupleExpr ) override final;
     178        virtual void visit( const UntypedTupleExpr * tupleExpr ) override final;
    121179        virtual void visit( TupleExpr * tupleExpr ) override final;
     180        virtual void visit( const TupleExpr * tupleExpr ) override final;
    122181        virtual void visit( TupleIndexExpr * tupleExpr ) override final;
     182        virtual void visit( const TupleIndexExpr * tupleExpr ) override final;
    123183        virtual void visit( TupleAssignExpr * assignExpr ) override final;
     184        virtual void visit( const TupleAssignExpr * assignExpr ) override final;
    124185        virtual void visit( StmtExpr *  stmtExpr ) override final;
     186        virtual void visit( const StmtExpr *  stmtExpr ) override final;
    125187        virtual void visit( UniqueExpr *  uniqueExpr ) override final;
     188        virtual void visit( const UniqueExpr *  uniqueExpr ) override final;
    126189        virtual void visit( UntypedInitExpr *  initExpr ) override final;
     190        virtual void visit( const UntypedInitExpr *  initExpr ) override final;
    127191        virtual void visit( InitExpr *  initExpr ) override final;
     192        virtual void visit( const InitExpr *  initExpr ) override final;
    128193        virtual void visit( DeletedExpr *  delExpr ) override final;
     194        virtual void visit( const DeletedExpr *  delExpr ) override final;
    129195        virtual void visit( DefaultArgExpr * argExpr ) override final;
     196        virtual void visit( const DefaultArgExpr * argExpr ) override final;
    130197        virtual void visit( GenericExpr * genExpr ) override final;
     198        virtual void visit( const GenericExpr * genExpr ) override final;
    131199
    132200        virtual void visit( VoidType * basicType ) override final;
     201        virtual void visit( const VoidType * basicType ) override final;
    133202        virtual void visit( BasicType * basicType ) override final;
     203        virtual void visit( const BasicType * basicType ) override final;
    134204        virtual void visit( PointerType * pointerType ) override final;
     205        virtual void visit( const PointerType * pointerType ) override final;
    135206        virtual void visit( ArrayType * arrayType ) override final;
     207        virtual void visit( const ArrayType * arrayType ) override final;
    136208        virtual void visit( ReferenceType * referenceType ) override final;
     209        virtual void visit( const ReferenceType * referenceType ) override final;
    137210        virtual void visit( QualifiedType * qualType ) override final;
     211        virtual void visit( const QualifiedType * qualType ) override final;
    138212        virtual void visit( FunctionType * functionType ) override final;
     213        virtual void visit( const FunctionType * functionType ) override final;
    139214        virtual void visit( StructInstType * aggregateUseType ) override final;
     215        virtual void visit( const StructInstType * aggregateUseType ) override final;
    140216        virtual void visit( UnionInstType * aggregateUseType ) override final;
     217        virtual void visit( const UnionInstType * aggregateUseType ) override final;
    141218        virtual void visit( EnumInstType * aggregateUseType ) override final;
     219        virtual void visit( const EnumInstType * aggregateUseType ) override final;
    142220        virtual void visit( TraitInstType * aggregateUseType ) override final;
     221        virtual void visit( const TraitInstType * aggregateUseType ) override final;
    143222        virtual void visit( TypeInstType * aggregateUseType ) override final;
     223        virtual void visit( const TypeInstType * aggregateUseType ) override final;
    144224        virtual void visit( TupleType * tupleType ) override final;
     225        virtual void visit( const TupleType * tupleType ) override final;
    145226        virtual void visit( TypeofType * typeofType ) override final;
     227        virtual void visit( const TypeofType * typeofType ) override final;
    146228        virtual void visit( AttrType * attrType ) override final;
     229        virtual void visit( const AttrType * attrType ) override final;
    147230        virtual void visit( VarArgsType * varArgsType ) override final;
     231        virtual void visit( const VarArgsType * varArgsType ) override final;
    148232        virtual void visit( ZeroType * zeroType ) override final;
     233        virtual void visit( const ZeroType * zeroType ) override final;
    149234        virtual void visit( OneType * oneType ) override final;
     235        virtual void visit( const OneType * oneType ) override final;
    150236        virtual void visit( GlobalScopeType * globalType ) override final;
     237        virtual void visit( const GlobalScopeType * globalType ) override final;
    151238
    152239        virtual void visit( Designation * designation ) override final;
     240        virtual void visit( const Designation * designation ) override final;
    153241        virtual void visit( SingleInit * singleInit ) override final;
     242        virtual void visit( const SingleInit * singleInit ) override final;
    154243        virtual void visit( ListInit * listInit ) override final;
     244        virtual void visit( const ListInit * listInit ) override final;
    155245        virtual void visit( ConstructorInit * ctorInit ) override final;
     246        virtual void visit( const ConstructorInit * ctorInit ) override final;
    156247
    157248        virtual void visit( Constant * constant ) override final;
     249        virtual void visit( const Constant * constant ) override final;
    158250
    159251        virtual void visit( Attribute * attribute ) override final;
     252        virtual void visit( const Attribute * attribute ) override final;
    160253
    161254        virtual DeclarationWithType * mutate( ObjectDecl * objectDecl ) override final;
     
    265358
    266359        template<typename pass_t> friend void acceptAll( std::list< Declaration* > &decls, PassVisitor< pass_t >& visitor );
     360        template<typename pass_t> friend void acceptAll( const std::list< const Declaration * > &decls, PassVisitor< pass_t >& visitor );
    267361        template<typename pass_t> friend void mutateAll( std::list< Declaration* > &decls, PassVisitor< pass_t >& visitor );
    268362        template< typename TreeType, typename pass_t > friend void maybeAccept_impl( TreeType * tree, PassVisitor< pass_t > & visitor );
     363        template< typename TreeType, typename pass_t > friend void maybeAccept_impl( const TreeType * tree, PassVisitor< pass_t > & visitor );
    269364        template< typename TreeType, typename pass_t > friend void maybeMutate_impl( TreeType *& tree, PassVisitor< pass_t > & mutator );
    270365        template< typename Container, typename pass_t > friend void maybeAccept_impl( Container & container, PassVisitor< pass_t > & visitor );
     366        template< typename Container, typename pass_t > friend void maybeAccept_impl( const Container & container, PassVisitor< pass_t > & visitor );
    271367        template< typename Container, typename pass_t > friend void maybeMutate_impl( Container & container, PassVisitor< pass_t > & mutator );
    272368
    273369        template<typename node_type> void call_previsit ( node_type * node ) { previsit_impl ( pass, node, 0 ); }
     370        template<typename node_type> void call_previsit ( const node_type * node ) { previsit_impl ( pass, node, 0 ); }
    274371        template<typename node_type> void call_postvisit( node_type * node ) { postvisit_impl( pass, node, 0 ); }
     372        template<typename node_type> void call_postvisit( const node_type * node ) { postvisit_impl( pass, node, 0 ); }
    275373
    276374        template<typename node_type> void call_premutate ( node_type * node ) { premutate_impl( pass, node, 0 ); }
     
    286384        void visitStatementList ( std::list< Statement* > &statements );
    287385        void mutateStatementList( std::list< Statement* > &statements );
     386        void visitStatementList ( const std::list< Statement * > & statements );
    288387
    289388        template< typename func_t >
     
    291390        Statement * visitStatement ( Statement * stmt );
    292391        Statement * mutateStatement( Statement * stmt );
     392        void visitStatement ( const Statement * stmt );
    293393
    294394        template< typename func_t >
     
    296396        Expression * visitExpression ( Expression * expr );
    297397        Expression * mutateExpression( Expression * expr );
     398        void visitExpression ( const Expression * expr );
    298399
    299400
  • src/Common/PassVisitor.impl.h

    r302d84c2 rfce4e31  
    8080
    8181template< typename pass_type >
     82inline void acceptAll( const std::list< const Declaration * > & decls, PassVisitor< pass_type >& visitor ) {
     83        SemanticErrorException errors;
     84
     85        pass_visitor_stats.depth++;
     86        pass_visitor_stats.max->push(pass_visitor_stats.depth);
     87        pass_visitor_stats.avg->push(pass_visitor_stats.depth);
     88        for ( const Declaration * decl : decls ) {
     89                try {
     90                        // run visitor on declaration
     91                        maybeAccept_impl( decl, visitor );
     92                }
     93                catch( SemanticErrorException &e ) {
     94                        errors.append( e );
     95                }
     96        }
     97        pass_visitor_stats.depth--;
     98        if ( ! errors.isEmpty() ) {
     99                throw errors;
     100        }
     101}
     102
     103template< typename pass_type >
    82104inline void mutateAll( std::list< Declaration* > &decls, PassVisitor< pass_type >& mutator ) {
    83105        DeclList_t* beforeDecls = mutator.get_beforeDecls();
     
    117139}
    118140
     141template< typename TreeType, typename pass_type >
     142inline void maybeAccept_impl( const TreeType * tree, PassVisitor< pass_type > & visitor ) {
     143        if ( ! visitor.get_visit_children() ) return;
     144        if ( tree ) {
     145                tree->accept( visitor );
     146        }
     147}
     148
    119149template< typename Container, typename pass_type >
    120150inline void maybeAccept_impl( Container & container, PassVisitor< pass_type > & visitor ) {
     
    129159                        if ( *i ) {
    130160                                (*i)->accept( visitor );
     161                        }
     162                } catch( SemanticErrorException &e ) {
     163                        errors.append( e );
     164                }
     165        }
     166        pass_visitor_stats.depth--;
     167        if ( ! errors.isEmpty() ) {
     168                throw errors;
     169        }
     170}
     171
     172template< typename Container, typename pass_type >
     173inline void maybeAccept_impl( const Container & container, PassVisitor< pass_type > & visitor ) {
     174        if ( ! visitor.get_visit_children() ) return;
     175        SemanticErrorException errors;
     176
     177        pass_visitor_stats.depth++;
     178        pass_visitor_stats.max->push(pass_visitor_stats.depth);
     179        pass_visitor_stats.avg->push(pass_visitor_stats.depth);
     180        for ( const auto & i : container ) {
     181                try {
     182                        if ( i ) {
     183                                i->accept( visitor );
    131184                        }
    132185                } catch( SemanticErrorException &e ) {
     
    227280
    228281template< typename pass_type >
     282void PassVisitor< pass_type >::visitStatementList( const std::list< Statement * > & statements ) {
     283        if ( ! get_visit_children() ) return;
     284        SemanticErrorException errors;
     285
     286        pass_visitor_stats.depth++;
     287        pass_visitor_stats.max->push(pass_visitor_stats.depth);
     288        pass_visitor_stats.avg->push(pass_visitor_stats.depth);
     289        for ( const Statement * i : statements ) {
     290                try {
     291                        maybeAccept_impl( i, *this );
     292                } catch ( SemanticErrorException &e ) {
     293                        errors.append( e );
     294                }
     295        }
     296        pass_visitor_stats.depth--;
     297        if ( !errors.isEmpty() ) { throw errors; }
     298}
     299
     300template< typename pass_type >
    229301void PassVisitor< pass_type >::mutateStatementList( std::list< Statement * > & statements ) {
    230302        handleStatementList( statements, [this]( Statement *& stmt) {
     
    275347
    276348template< typename pass_type >
     349void PassVisitor< pass_type >::visitStatement( const Statement * stmt ) {
     350        if ( ! get_visit_children() ) return;
     351
     352        // don't want statements from outer CompoundStmts to be added to this CompoundStmt
     353        ValueGuardPtr< typename std::remove_pointer<decltype(get_env_ptr())>::type >  oldEnv( get_env_ptr() );
     354
     355        maybeAccept_impl( stmt, *this );
     356}
     357
     358template< typename pass_type >
    277359Statement * PassVisitor< pass_type >::mutateStatement( Statement * stmt ) {
    278360        return handleStatement( stmt, [this]( Statement * stmt ) {
     
    306388
    307389template< typename pass_type >
     390void PassVisitor< pass_type >::visitExpression( const Expression * expr ) {
     391        if ( ! get_visit_children() ) return;
     392        if( !expr ) return;
     393
     394        auto env_ptr = get_env_ptr();
     395        if ( env_ptr && expr->get_env() ) {
     396                *env_ptr = expr->get_env();
     397        }
     398
     399        maybeAccept_impl( expr, *this );
     400}
     401
     402template< typename pass_type >
    308403Expression * PassVisitor< pass_type >::mutateExpression( Expression * expr ) {
    309404        return handleExpression(expr, [this]( Expression * expr ) {
     
    315410template< typename TreeType, typename VisitorType >
    316411inline void indexerScopedAccept( TreeType * tree, VisitorType & visitor ) {
     412        if ( ! visitor.get_visit_children() ) return;
     413        auto guard = makeFuncGuard(
     414                [&visitor]() { visitor.indexerScopeEnter(); },
     415                [&visitor]() { visitor.indexerScopeLeave(); }
     416        );
     417        maybeAccept_impl( tree, visitor );
     418}
     419
     420template< typename TreeType, typename VisitorType >
     421inline void indexerScopedAccept( const TreeType * tree, VisitorType & visitor ) {
    317422        if ( ! visitor.get_visit_children() ) return;
    318423        auto guard = makeFuncGuard(
     
    372477
    373478        indexerAddId( node );
     479
     480        VISIT_END( node );
     481}
     482
     483template< typename pass_type >
     484void PassVisitor< pass_type >::visit( const ObjectDecl * node ) {
     485        VISIT_START( node );
     486
     487        maybeAccept_impl( node->type         , *this );
     488        maybeAccept_impl( node->init         , *this );
     489        maybeAccept_impl( node->bitfieldWidth, *this );
     490        maybeAccept_impl( node->attributes   , *this );
    374491
    375492        VISIT_END( node );
     
    428545
    429546template< typename pass_type >
     547void PassVisitor< pass_type >::visit( const FunctionDecl * node ) {
     548        VISIT_START( node );
     549
     550        maybeAccept_impl( node->withExprs, *this );
     551        {
     552                // implicit add __func__ identifier as specified in the C manual 6.4.2.2
     553                static ObjectDecl func(
     554                        "__func__", noStorageClasses, LinkageSpec::C, nullptr,
     555                        new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), nullptr, true, false ),
     556                        nullptr
     557                );
     558                maybeAccept_impl( node->type, *this );
     559                // function body needs to have the same scope as parameters - CompoundStmt will not enter
     560                // a new scope if inFunction is true
     561                ValueGuard< bool > oldInFunction( inFunction );
     562                inFunction = true;
     563                maybeAccept_impl( node->statements, *this );
     564                maybeAccept_impl( node->attributes, *this );
     565        }
     566
     567        VISIT_END( node );
     568}
     569
     570template< typename pass_type >
    430571DeclarationWithType * PassVisitor< pass_type >::mutate( FunctionDecl * node ) {
    431572        MUTATE_START( node );
     
    484625
    485626template< typename pass_type >
     627void PassVisitor< pass_type >::visit( const StructDecl * node ) {
     628        VISIT_START( node );
     629
     630        maybeAccept_impl( node->parameters, *this );
     631        maybeAccept_impl( node->members   , *this );
     632
     633        VISIT_END( node );
     634}
     635
     636template< typename pass_type >
    486637Declaration * PassVisitor< pass_type >::mutate( StructDecl * node ) {
    487638        MUTATE_START( node );
     
    522673        VISIT_END( node );
    523674}
     675template< typename pass_type >
     676void PassVisitor< pass_type >::visit( const UnionDecl * node ) {
     677        VISIT_START( node );
     678
     679        maybeAccept_impl( node->parameters, *this );
     680        maybeAccept_impl( node->members   , *this );
     681
     682        VISIT_END( node );
     683}
    524684
    525685template< typename pass_type >
     
    557717
    558718template< typename pass_type >
     719void PassVisitor< pass_type >::visit( const EnumDecl * node ) {
     720        VISIT_START( node );
     721
     722        // unlike structs, traits, and unions, enums inject their members into the global scope
     723        maybeAccept_impl( node->parameters, *this );
     724        maybeAccept_impl( node->members   , *this );
     725
     726        VISIT_END( node );
     727}
     728
     729template< typename pass_type >
    559730Declaration * PassVisitor< pass_type >::mutate( EnumDecl * node ) {
    560731        MUTATE_START( node );
     
    587758
    588759template< typename pass_type >
     760void PassVisitor< pass_type >::visit( const TraitDecl * node ) {
     761        VISIT_START( node );
     762
     763        maybeAccept_impl( node->parameters, *this );
     764        maybeAccept_impl( node->members   , *this );
     765
     766        VISIT_END( node );
     767}
     768
     769template< typename pass_type >
    589770Declaration * PassVisitor< pass_type >::mutate( TraitDecl * node ) {
    590771        MUTATE_START( node );
     
    625806}
    626807
     808
     809template< typename pass_type >
     810void PassVisitor< pass_type >::visit( const TypeDecl * node ) {
     811        VISIT_START( node );
     812
     813        maybeAccept_impl( node->parameters, *this );
     814        maybeAccept_impl( node->base      , *this );
     815        maybeAccept_impl( node->assertions, *this );
     816
     817        VISIT_END( node );
     818}
     819
    627820template< typename pass_type >
    628821Declaration * PassVisitor< pass_type >::mutate( TypeDecl * node ) {
     
    667860
    668861template< typename pass_type >
     862void PassVisitor< pass_type >::visit( const TypedefDecl * node ) {
     863        VISIT_START( node );
     864
     865        maybeAccept_impl( node->parameters, *this );
     866        maybeAccept_impl( node->base      , *this );
     867        maybeAccept_impl( node->assertions, *this );
     868
     869        VISIT_END( node );
     870}
     871
     872template< typename pass_type >
    669873Declaration * PassVisitor< pass_type >::mutate( TypedefDecl * node ) {
    670874        MUTATE_START( node );
     
    695899
    696900template< typename pass_type >
     901void PassVisitor< pass_type >::visit( const AsmDecl * node ) {
     902        VISIT_START( node );
     903
     904        maybeAccept_impl( node->stmt, *this );
     905
     906        VISIT_END( node );
     907}
     908
     909template< typename pass_type >
    697910AsmDecl * PassVisitor< pass_type >::mutate( AsmDecl * node ) {
    698911        MUTATE_START( node );
     
    710923
    711924        node->condition = visitExpression( node->condition );
     925        maybeAccept_impl( node->message, *this );
     926
     927        VISIT_END( node );
     928}
     929
     930template< typename pass_type >
     931void PassVisitor< pass_type >::visit( const StaticAssertDecl * node ) {
     932        VISIT_START( node );
     933
     934        visitExpression( node->condition );
    712935        maybeAccept_impl( node->message, *this );
    713936
     
    742965
    743966template< typename pass_type >
     967void PassVisitor< pass_type >::visit( const CompoundStmt * node ) {
     968        VISIT_START( node );
     969        {
     970                // do not enter a new scope if inFunction is true - needs to check old state before the assignment
     971                ValueGuard< bool > oldInFunction( inFunction );
     972                auto guard1 = makeFuncGuard( [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeEnter(); }, [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeLeave(); } );
     973                auto guard2 = makeFuncGuard( [this]() { call_beginScope();   }, [this]() { call_endScope();     } );
     974                inFunction = false;
     975                visitStatementList( node->kids );
     976        }
     977        VISIT_END( node );
     978}
     979
     980template< typename pass_type >
    744981CompoundStmt * PassVisitor< pass_type >::mutate( CompoundStmt * node ) {
    745982        MUTATE_START( node );
     
    7671004
    7681005template< typename pass_type >
     1006void PassVisitor< pass_type >::visit( const ExprStmt * node ) {
     1007        VISIT_START( node );
     1008
     1009        visitExpression( node->expr );
     1010
     1011        VISIT_END( node );
     1012}
     1013
     1014template< typename pass_type >
    7691015Statement * PassVisitor< pass_type >::mutate( ExprStmt * node ) {
    7701016        MUTATE_START( node );
     
    7901036
    7911037template< typename pass_type >
     1038void PassVisitor< pass_type >::visit( const AsmStmt * node ) {
     1039        VISIT_START( node )
     1040
     1041        maybeAccept_impl( node->instruction, *this );
     1042        maybeAccept_impl( node->output, *this );
     1043        maybeAccept_impl( node->input, *this );
     1044        maybeAccept_impl( node->clobber, *this );
     1045
     1046        VISIT_END( node );
     1047}
     1048
     1049template< typename pass_type >
    7921050Statement * PassVisitor< pass_type >::mutate( AsmStmt * node ) {
    7931051        MUTATE_START( node );
     
    8111069
    8121070template< typename pass_type >
     1071void PassVisitor< pass_type >::visit( const DirectiveStmt * node ) {
     1072        VISIT_START( node )
     1073
     1074        VISIT_END( node );
     1075}
     1076
     1077template< typename pass_type >
    8131078Statement * PassVisitor< pass_type >::mutate( DirectiveStmt * node ) {
    8141079        MUTATE_START( node );
     
    8251090                // if statements introduce a level of scope (for the initialization)
    8261091                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    827                 maybeAccept_impl( node->get_initialization(), *this );
     1092                maybeAccept_impl( node->initialization, *this );
    8281093                visitExpression ( node->condition );
    8291094                node->thenPart = visitStatement( node->thenPart );
     
    8341099
    8351100template< typename pass_type >
     1101void PassVisitor< pass_type >::visit( const IfStmt * node ) {
     1102        VISIT_START( node );
     1103
     1104        maybeAccept_impl( node->initialization, *this );
     1105        visitExpression ( node->condition );
     1106        visitStatement( node->thenPart );
     1107        visitStatement( node->elsePart );
     1108
     1109        VISIT_END( node );
     1110}
     1111
     1112template< typename pass_type >
    8361113Statement * PassVisitor< pass_type >::mutate( IfStmt * node ) {
    8371114        MUTATE_START( node );
     
    8391116                // if statements introduce a level of scope (for the initialization)
    8401117                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    841                 maybeMutate_impl( node->get_initialization(), *this );
     1118                maybeMutate_impl( node->initialization, *this );
    8421119                node->condition = mutateExpression( node->condition );
    8431120                node->thenPart  = mutateStatement ( node->thenPart  );
     
    8601137                node->body = visitStatement( node->body );
    8611138        }
     1139
     1140        VISIT_END( node );
     1141}
     1142
     1143template< typename pass_type >
     1144void PassVisitor< pass_type >::visit( const WhileStmt * node ) {
     1145        VISIT_START( node );
     1146
     1147        maybeAccept_impl( node->initialization, *this );
     1148        visitExpression ( node->condition );
     1149        visitStatement( node->body );
    8621150
    8631151        VISIT_END( node );
     
    8971185
    8981186template< typename pass_type >
     1187void PassVisitor< pass_type >::visit( const ForStmt * node ) {
     1188        VISIT_START( node );
     1189
     1190        maybeAccept_impl( node->initialization, *this );
     1191        visitExpression( node->condition );
     1192        visitExpression( node->increment );
     1193        visitStatement( node->body );
     1194
     1195        VISIT_END( node );
     1196}
     1197
     1198template< typename pass_type >
    8991199Statement * PassVisitor< pass_type >::mutate( ForStmt * node ) {
    9001200        MUTATE_START( node );
     
    9231223
    9241224template< typename pass_type >
     1225void PassVisitor< pass_type >::visit( const SwitchStmt * node ) {
     1226        VISIT_START( node );
     1227
     1228        visitExpression   ( node->condition  );
     1229        visitStatementList( node->statements );
     1230
     1231        VISIT_END( node );
     1232}
     1233
     1234template< typename pass_type >
    9251235Statement * PassVisitor< pass_type >::mutate( SwitchStmt * node ) {
    9261236        MUTATE_START( node );
     
    9451255
    9461256template< typename pass_type >
     1257void PassVisitor< pass_type >::visit( const CaseStmt * node ) {
     1258        VISIT_START( node );
     1259
     1260        visitExpression   ( node->condition );
     1261        visitStatementList( node->stmts     );
     1262
     1263        VISIT_END( node );
     1264}
     1265
     1266template< typename pass_type >
    9471267Statement * PassVisitor< pass_type >::mutate( CaseStmt * node ) {
    9481268        MUTATE_START( node );
     
    9631283
    9641284template< typename pass_type >
     1285void PassVisitor< pass_type >::visit( const BranchStmt * node ) {
     1286        VISIT_START( node );
     1287        VISIT_END( node );
     1288}
     1289
     1290template< typename pass_type >
    9651291Statement * PassVisitor< pass_type >::mutate( BranchStmt * node ) {
    9661292        MUTATE_START( node );
     
    9801306
    9811307template< typename pass_type >
     1308void PassVisitor< pass_type >::visit( const ReturnStmt * node ) {
     1309        VISIT_START( node );
     1310
     1311        visitExpression( node->expr );
     1312
     1313        VISIT_END( node );
     1314}
     1315
     1316template< typename pass_type >
    9821317Statement * PassVisitor< pass_type >::mutate( ReturnStmt * node ) {
    9831318        MUTATE_START( node );
     
    9901325//--------------------------------------------------------------------------
    9911326// ThrowStmt
    992 
    9931327template< typename pass_type >
    9941328void PassVisitor< pass_type >::visit( ThrowStmt * node ) {
     
    10021336
    10031337template< typename pass_type >
     1338void PassVisitor< pass_type >::visit( const ThrowStmt * node ) {
     1339        VISIT_START( node );
     1340
     1341        maybeAccept_impl( node->expr, *this );
     1342        maybeAccept_impl( node->target, *this );
     1343
     1344        VISIT_END( node );
     1345}
     1346
     1347template< typename pass_type >
    10041348Statement * PassVisitor< pass_type >::mutate( ThrowStmt * node ) {
    10051349        MUTATE_START( node );
     
    10151359template< typename pass_type >
    10161360void PassVisitor< pass_type >::visit( TryStmt * node ) {
     1361        VISIT_START( node );
     1362
     1363        maybeAccept_impl( node->block       , *this );
     1364        maybeAccept_impl( node->handlers    , *this );
     1365        maybeAccept_impl( node->finallyBlock, *this );
     1366
     1367        VISIT_END( node );
     1368}
     1369
     1370template< typename pass_type >
     1371void PassVisitor< pass_type >::visit( const TryStmt * node ) {
    10171372        VISIT_START( node );
    10181373
     
    10511406
    10521407template< typename pass_type >
     1408void PassVisitor< pass_type >::visit( const CatchStmt * node ) {
     1409        VISIT_START( node );
     1410
     1411        maybeAccept_impl( node->decl, *this );
     1412        visitExpression( node->cond );
     1413        visitStatement ( node->body );
     1414
     1415        VISIT_END( node );
     1416}
     1417
     1418template< typename pass_type >
    10531419Statement * PassVisitor< pass_type >::mutate( CatchStmt * node ) {
    10541420        MUTATE_START( node );
     
    10751441
    10761442template< typename pass_type >
     1443void PassVisitor< pass_type >::visit( const FinallyStmt * node ) {
     1444        VISIT_START( node );
     1445
     1446        maybeAccept_impl( node->block, *this );
     1447
     1448        VISIT_END( node );
     1449}
     1450
     1451template< typename pass_type >
    10771452Statement * PassVisitor< pass_type >::mutate( FinallyStmt * node ) {
    10781453        MUTATE_START( node );
     
    11071482
    11081483template< typename pass_type >
     1484void PassVisitor< pass_type >::visit( const WaitForStmt * node ) {
     1485        VISIT_START( node );
     1486
     1487        for( auto & clause : node->clauses ) {
     1488                maybeAccept_impl( clause.target.function, *this );
     1489                maybeAccept_impl( clause.target.arguments, *this );
     1490
     1491                maybeAccept_impl( clause.statement, *this );
     1492                maybeAccept_impl( clause.condition, *this );
     1493        }
     1494
     1495        maybeAccept_impl( node->timeout.time, *this );
     1496        maybeAccept_impl( node->timeout.statement, *this );
     1497        maybeAccept_impl( node->timeout.condition, *this );
     1498        maybeAccept_impl( node->orelse.statement, *this );
     1499        maybeAccept_impl( node->orelse.condition, *this );
     1500
     1501        VISIT_END( node );
     1502}
     1503
     1504template< typename pass_type >
    11091505Statement * PassVisitor< pass_type >::mutate( WaitForStmt * node ) {
    11101506        MUTATE_START( node );
     
    11301526
    11311527//--------------------------------------------------------------------------
    1132 // NullStmt
     1528// WithStmt
    11331529template< typename pass_type >
    11341530void PassVisitor< pass_type >::visit( WithStmt * node ) {
     
    11451541
    11461542template< typename pass_type >
     1543void PassVisitor< pass_type >::visit( const WithStmt * node ) {
     1544        VISIT_START( node );
     1545
     1546        maybeAccept_impl( node->exprs, *this );
     1547        maybeAccept_impl( node->stmt, *this );
     1548
     1549        VISIT_END( node );
     1550}
     1551
     1552template< typename pass_type >
    11471553Statement * PassVisitor< pass_type >::mutate( WithStmt * node ) {
    11481554        MUTATE_START( node );
     
    11661572
    11671573template< typename pass_type >
     1574void PassVisitor< pass_type >::visit( const NullStmt * node ) {
     1575        VISIT_START( node );
     1576        VISIT_END( node );
     1577}
     1578
     1579template< typename pass_type >
    11681580NullStmt * PassVisitor< pass_type >::mutate( NullStmt * node ) {
    11691581        MUTATE_START( node );
     
    11831595
    11841596template< typename pass_type >
     1597void PassVisitor< pass_type >::visit( const DeclStmt * node ) {
     1598        VISIT_START( node );
     1599
     1600        maybeAccept_impl( node->decl, *this );
     1601
     1602        VISIT_END( node );
     1603}
     1604
     1605template< typename pass_type >
    11851606Statement * PassVisitor< pass_type >::mutate( DeclStmt * node ) {
    11861607        MUTATE_START( node );
     
    11951616template< typename pass_type >
    11961617void PassVisitor< pass_type >::visit( ImplicitCtorDtorStmt * node ) {
     1618        VISIT_START( node );
     1619
     1620        maybeAccept_impl( node->callStmt, *this );
     1621
     1622        VISIT_END( node );
     1623}
     1624
     1625template< typename pass_type >
     1626void PassVisitor< pass_type >::visit( const ImplicitCtorDtorStmt * node ) {
    11971627        VISIT_START( node );
    11981628
     
    12201650        maybeAccept_impl        ( node->function, *this );
    12211651        maybeAccept_impl        ( node->args    , *this );
     1652
     1653        VISIT_END( node );
     1654}
     1655
     1656template< typename pass_type >
     1657void PassVisitor< pass_type >::visit( const ApplicationExpr * node ) {
     1658        VISIT_START( node );
     1659
     1660        maybeAccept_impl( node->result  , *this );
     1661        maybeAccept_impl( node->function, *this );
     1662        maybeAccept_impl( node->args    , *this );
    12221663
    12231664        VISIT_END( node );
     
    12531694
    12541695template< typename pass_type >
     1696void PassVisitor< pass_type >::visit( const UntypedExpr * node ) {
     1697        VISIT_START( node );
     1698
     1699        maybeAccept_impl( node->result, *this );
     1700
     1701        for ( auto expr : node->args ) {
     1702                visitExpression( expr );
     1703        }
     1704
     1705        VISIT_END( node );
     1706}
     1707
     1708template< typename pass_type >
    12551709Expression * PassVisitor< pass_type >::mutate( UntypedExpr * node ) {
    12561710        MUTATE_START( node );
     
    12781732
    12791733template< typename pass_type >
     1734void PassVisitor< pass_type >::visit( const NameExpr * node ) {
     1735        VISIT_START( node );
     1736
     1737        maybeAccept_impl( node->result, *this );
     1738
     1739        VISIT_END( node );
     1740}
     1741
     1742template< typename pass_type >
    12801743Expression * PassVisitor< pass_type >::mutate( NameExpr * node ) {
    12811744        MUTATE_START( node );
     
    12951758        indexerScopedAccept( node->result, *this );
    12961759        maybeAccept_impl        ( node->arg   , *this );
     1760
     1761        VISIT_END( node );
     1762}
     1763
     1764template< typename pass_type >
     1765void PassVisitor< pass_type >::visit( const CastExpr * node ) {
     1766        VISIT_START( node );
     1767
     1768        maybeAccept_impl( node->result, *this );
     1769        maybeAccept_impl( node->arg   , *this );
    12971770
    12981771        VISIT_END( node );
     
    13231796
    13241797template< typename pass_type >
     1798void PassVisitor< pass_type >::visit( const KeywordCastExpr * node ) {
     1799        VISIT_START( node );
     1800
     1801        maybeAccept_impl( node->result, *this );
     1802        maybeAccept_impl( node->arg   , *this );
     1803
     1804        VISIT_END( node );
     1805}
     1806
     1807template< typename pass_type >
    13251808Expression * PassVisitor< pass_type >::mutate( KeywordCastExpr * node ) {
    13261809        MUTATE_START( node );
     
    13461829
    13471830template< typename pass_type >
     1831void PassVisitor< pass_type >::visit( const VirtualCastExpr * node ) {
     1832        VISIT_START( node );
     1833
     1834        maybeAccept_impl( node->result, *this );
     1835        maybeAccept_impl( node->arg, *this );
     1836
     1837        VISIT_END( node );
     1838}
     1839
     1840template< typename pass_type >
    13481841Expression * PassVisitor< pass_type >::mutate( VirtualCastExpr * node ) {
    13491842        MUTATE_START( node );
     
    13691862
    13701863template< typename pass_type >
     1864void PassVisitor< pass_type >::visit( const AddressExpr * node ) {
     1865        VISIT_START( node );
     1866
     1867        maybeAccept_impl( node->result, *this );
     1868        maybeAccept_impl( node->arg   , *this );
     1869
     1870        VISIT_END( node );
     1871}
     1872
     1873template< typename pass_type >
    13711874Expression * PassVisitor< pass_type >::mutate( AddressExpr * node ) {
    13721875        MUTATE_START( node );
     
    13911894
    13921895template< typename pass_type >
     1896void PassVisitor< pass_type >::visit( const LabelAddressExpr * node ) {
     1897        VISIT_START( node );
     1898
     1899        maybeAccept_impl( node->result, *this );
     1900
     1901        VISIT_END( node );
     1902}
     1903
     1904template< typename pass_type >
    13931905Expression * PassVisitor< pass_type >::mutate( LabelAddressExpr * node ) {
    13941906        MUTATE_START( node );
     
    14091921        maybeAccept_impl   ( node->aggregate, *this );
    14101922        maybeAccept_impl   ( node->member   , *this );
     1923
     1924        VISIT_END( node );
     1925}
     1926
     1927template< typename pass_type >
     1928void PassVisitor< pass_type >::visit( const UntypedMemberExpr * node ) {
     1929        VISIT_START( node );
     1930
     1931        maybeAccept_impl( node->result   , *this );
     1932        maybeAccept_impl( node->aggregate, *this );
     1933        maybeAccept_impl( node->member   , *this );
    14111934
    14121935        VISIT_END( node );
     
    14381961
    14391962template< typename pass_type >
     1963void PassVisitor< pass_type >::visit( const MemberExpr * node ) {
     1964        VISIT_START( node );
     1965
     1966        maybeAccept_impl( node->result   , *this );
     1967        maybeAccept_impl( node->aggregate, *this );
     1968
     1969        VISIT_END( node );
     1970}
     1971
     1972template< typename pass_type >
    14401973Expression * PassVisitor< pass_type >::mutate( MemberExpr * node ) {
    14411974        MUTATE_START( node );
     
    14601993
    14611994template< typename pass_type >
     1995void PassVisitor< pass_type >::visit( const VariableExpr * node ) {
     1996        VISIT_START( node );
     1997
     1998        maybeAccept_impl( node->result, *this );
     1999
     2000        VISIT_END( node );
     2001}
     2002
     2003template< typename pass_type >
    14622004Expression * PassVisitor< pass_type >::mutate( VariableExpr * node ) {
    14632005        MUTATE_START( node );
     
    14772019        indexerScopedAccept( node->result   , *this );
    14782020        maybeAccept_impl   ( &node->constant, *this );
     2021
     2022        VISIT_END( node );
     2023}
     2024
     2025template< typename pass_type >
     2026void PassVisitor< pass_type >::visit( const ConstantExpr * node ) {
     2027        VISIT_START( node );
     2028
     2029        maybeAccept_impl( node->result   , *this );
     2030        maybeAccept_impl( &node->constant, *this );
    14792031
    14802032        VISIT_END( node );
     
    15012053
    15022054        indexerScopedAccept( node->result, *this );
     2055        if ( node->get_isType() ) {
     2056                maybeAccept_impl( node->type, *this );
     2057        } else {
     2058                maybeAccept_impl( node->expr, *this );
     2059        }
     2060
     2061        VISIT_END( node );
     2062}
     2063
     2064template< typename pass_type >
     2065void PassVisitor< pass_type >::visit( const SizeofExpr * node ) {
     2066        VISIT_START( node );
     2067
     2068        maybeAccept_impl( node->result, *this );
    15032069        if ( node->get_isType() ) {
    15042070                maybeAccept_impl( node->type, *this );
     
    15422108
    15432109template< typename pass_type >
     2110void PassVisitor< pass_type >::visit( const AlignofExpr * node ) {
     2111        VISIT_START( node );
     2112
     2113        maybeAccept_impl( node->result, *this );
     2114        if ( node->get_isType() ) {
     2115                maybeAccept_impl( node->type, *this );
     2116        } else {
     2117                maybeAccept_impl( node->expr, *this );
     2118        }
     2119
     2120        VISIT_END( node );
     2121}
     2122
     2123template< typename pass_type >
    15442124Expression * PassVisitor< pass_type >::mutate( AlignofExpr * node ) {
    15452125        MUTATE_START( node );
     
    15692149
    15702150template< typename pass_type >
     2151void PassVisitor< pass_type >::visit( const UntypedOffsetofExpr * node ) {
     2152        VISIT_START( node );
     2153
     2154        maybeAccept_impl( node->result, *this );
     2155        maybeAccept_impl( node->type  , *this );
     2156
     2157        VISIT_END( node );
     2158}
     2159
     2160template< typename pass_type >
    15712161Expression * PassVisitor< pass_type >::mutate( UntypedOffsetofExpr * node ) {
    15722162        MUTATE_START( node );
     
    15922182
    15932183template< typename pass_type >
     2184void PassVisitor< pass_type >::visit( const OffsetofExpr * node ) {
     2185        VISIT_START( node );
     2186
     2187        maybeAccept_impl( node->result, *this );
     2188        maybeAccept_impl( node->type  , *this );
     2189
     2190        VISIT_END( node );
     2191}
     2192
     2193template< typename pass_type >
    15942194Expression * PassVisitor< pass_type >::mutate( OffsetofExpr * node ) {
    15952195        MUTATE_START( node );
     
    16152215
    16162216template< typename pass_type >
     2217void PassVisitor< pass_type >::visit( const OffsetPackExpr * node ) {
     2218        VISIT_START( node );
     2219
     2220        maybeAccept_impl( node->result, *this );
     2221        maybeAccept_impl( node->type  , *this );
     2222
     2223        VISIT_END( node );
     2224}
     2225
     2226template< typename pass_type >
    16172227Expression * PassVisitor< pass_type >::mutate( OffsetPackExpr * node ) {
    16182228        MUTATE_START( node );
     
    16322242
    16332243        indexerScopedAccept( node->result, *this );
     2244        if ( node->get_isType() ) {
     2245                maybeAccept_impl( node->type, *this );
     2246        } else {
     2247                maybeAccept_impl( node->expr, *this );
     2248        }
     2249
     2250        VISIT_END( node );
     2251}
     2252
     2253template< typename pass_type >
     2254void PassVisitor< pass_type >::visit( const AttrExpr * node ) {
     2255        VISIT_START( node );
     2256
     2257        maybeAccept_impl( node->result, *this );
    16342258        if ( node->get_isType() ) {
    16352259                maybeAccept_impl( node->type, *this );
     
    16702294
    16712295template< typename pass_type >
     2296void PassVisitor< pass_type >::visit( const LogicalExpr * node ) {
     2297        VISIT_START( node );
     2298
     2299        maybeAccept_impl( node->result, *this );
     2300        maybeAccept_impl( node->arg1  , *this );
     2301        maybeAccept_impl( node->arg2  , *this );
     2302
     2303        VISIT_END( node );
     2304}
     2305
     2306template< typename pass_type >
    16722307Expression * PassVisitor< pass_type >::mutate( LogicalExpr * node ) {
    16732308        MUTATE_START( node );
     
    16912326        maybeAccept_impl        ( node->arg2  , *this );
    16922327        maybeAccept_impl        ( node->arg3  , *this );
     2328
     2329        VISIT_END( node );
     2330}
     2331
     2332template< typename pass_type >
     2333void PassVisitor< pass_type >::visit( const ConditionalExpr * node ) {
     2334        VISIT_START( node );
     2335
     2336        maybeAccept_impl( node->result, *this );
     2337        maybeAccept_impl( node->arg1  , *this );
     2338        maybeAccept_impl( node->arg2  , *this );
     2339        maybeAccept_impl( node->arg3  , *this );
    16932340
    16942341        VISIT_END( node );
     
    17222369
    17232370template< typename pass_type >
     2371void PassVisitor< pass_type >::visit( const CommaExpr * node ) {
     2372        VISIT_START( node );
     2373
     2374        maybeAccept_impl( node->result, *this );
     2375        maybeAccept_impl( node->arg1  , *this );
     2376        maybeAccept_impl( node->arg2  , *this );
     2377
     2378        VISIT_END( node );
     2379}
     2380
     2381template< typename pass_type >
    17242382Expression * PassVisitor< pass_type >::mutate( CommaExpr * node ) {
    17252383        MUTATE_START( node );
     
    17462404
    17472405template< typename pass_type >
     2406void PassVisitor< pass_type >::visit( const TypeExpr * node ) {
     2407        VISIT_START( node );
     2408
     2409        maybeAccept_impl( node->result, *this );
     2410        maybeAccept_impl( node->type, *this );
     2411
     2412        VISIT_END( node );
     2413}
     2414
     2415template< typename pass_type >
    17482416Expression * PassVisitor< pass_type >::mutate( TypeExpr * node ) {
    17492417        MUTATE_START( node );
     
    17662434        maybeAccept_impl   ( node->constraint, *this );
    17672435        maybeAccept_impl   ( node->operand   , *this );
     2436
     2437        VISIT_END( node );
     2438}
     2439
     2440template< typename pass_type >
     2441void PassVisitor< pass_type >::visit( const AsmExpr * node ) {
     2442        VISIT_START( node );
     2443
     2444        maybeAccept_impl( node->result    , *this );
     2445        maybeAccept_impl( node->inout     , *this );
     2446        maybeAccept_impl( node->constraint, *this );
     2447        maybeAccept_impl( node->operand   , *this );
    17682448
    17692449        VISIT_END( node );
     
    17962476
    17972477template< typename pass_type >
     2478void PassVisitor< pass_type >::visit( const ImplicitCopyCtorExpr * node ) {
     2479        VISIT_START( node );
     2480
     2481        maybeAccept_impl( node->result    , *this );
     2482        maybeAccept_impl( node->callExpr  , *this );
     2483
     2484        VISIT_END( node );
     2485}
     2486
     2487template< typename pass_type >
    17982488Expression * PassVisitor< pass_type >::mutate( ImplicitCopyCtorExpr * node ) {
    17992489        MUTATE_START( node );
     
    18192509
    18202510template< typename pass_type >
     2511void PassVisitor< pass_type >::visit( const ConstructorExpr * node ) {
     2512        VISIT_START( node );
     2513
     2514        maybeAccept_impl( node->result  , *this );
     2515        maybeAccept_impl( node->callExpr, *this );
     2516
     2517        VISIT_END( node );
     2518}
     2519
     2520template< typename pass_type >
    18212521Expression * PassVisitor< pass_type >::mutate( ConstructorExpr * node ) {
    18222522        MUTATE_START( node );
     
    18422542
    18432543template< typename pass_type >
     2544void PassVisitor< pass_type >::visit( const CompoundLiteralExpr * node ) {
     2545        VISIT_START( node );
     2546
     2547        maybeAccept_impl( node->result     , *this );
     2548        maybeAccept_impl( node->initializer, *this );
     2549
     2550        VISIT_END( node );
     2551}
     2552
     2553template< typename pass_type >
    18442554Expression * PassVisitor< pass_type >::mutate( CompoundLiteralExpr * node ) {
    18452555        MUTATE_START( node );
     
    18612571        maybeAccept_impl   ( node->low   , *this );
    18622572        maybeAccept_impl   ( node->high  , *this );
     2573
     2574        VISIT_END( node );
     2575}
     2576
     2577template< typename pass_type >
     2578void PassVisitor< pass_type >::visit( const RangeExpr * node ) {
     2579        VISIT_START( node );
     2580
     2581        maybeAccept_impl( node->result, *this );
     2582        maybeAccept_impl( node->low   , *this );
     2583        maybeAccept_impl( node->high  , *this );
    18632584
    18642585        VISIT_END( node );
     
    18902611
    18912612template< typename pass_type >
     2613void PassVisitor< pass_type >::visit( const UntypedTupleExpr * node ) {
     2614        VISIT_START( node );
     2615
     2616        maybeAccept_impl( node->result, *this );
     2617        maybeAccept_impl( node->exprs , *this );
     2618
     2619        VISIT_END( node );
     2620}
     2621
     2622template< typename pass_type >
    18922623Expression * PassVisitor< pass_type >::mutate( UntypedTupleExpr * node ) {
    18932624        MUTATE_START( node );
     
    19132644
    19142645template< typename pass_type >
     2646void PassVisitor< pass_type >::visit( const TupleExpr * node ) {
     2647        VISIT_START( node );
     2648
     2649        maybeAccept_impl( node->result, *this );
     2650        maybeAccept_impl( node->exprs , *this );
     2651
     2652        VISIT_END( node );
     2653}
     2654
     2655template< typename pass_type >
    19152656Expression * PassVisitor< pass_type >::mutate( TupleExpr * node ) {
    19162657        MUTATE_START( node );
     
    19362677
    19372678template< typename pass_type >
     2679void PassVisitor< pass_type >::visit( const TupleIndexExpr * node ) {
     2680        VISIT_START( node );
     2681
     2682        maybeAccept_impl( node->result, *this );
     2683        maybeAccept_impl( node->tuple , *this );
     2684
     2685        VISIT_END( node );
     2686}
     2687
     2688template< typename pass_type >
    19382689Expression * PassVisitor< pass_type >::mutate( TupleIndexExpr * node ) {
    19392690        MUTATE_START( node );
     
    19542705        indexerScopedAccept( node->result  , *this );
    19552706        maybeAccept_impl   ( node->stmtExpr, *this );
     2707
     2708        VISIT_END( node );
     2709}
     2710
     2711template< typename pass_type >
     2712void PassVisitor< pass_type >::visit( const TupleAssignExpr * node ) {
     2713        VISIT_START( node );
     2714
     2715        maybeAccept_impl( node->result  , *this );
     2716        maybeAccept_impl( node->stmtExpr, *this );
    19562717
    19572718        VISIT_END( node );
     
    19892750
    19902751template< typename pass_type >
     2752void PassVisitor< pass_type >::visit( const StmtExpr * node ) {
     2753        VISIT_START( node );
     2754
     2755        maybeAccept_impl( node->result     , *this );
     2756        maybeAccept_impl( node->statements , *this );
     2757        maybeAccept_impl( node->returnDecls, *this );
     2758        maybeAccept_impl( node->dtors      , *this );
     2759
     2760        VISIT_END( node );
     2761}
     2762
     2763template< typename pass_type >
    19912764Expression * PassVisitor< pass_type >::mutate( StmtExpr * node ) {
    19922765        MUTATE_START( node );
     
    20182791
    20192792template< typename pass_type >
     2793void PassVisitor< pass_type >::visit( const UniqueExpr * node ) {
     2794        VISIT_START( node );
     2795
     2796        maybeAccept_impl( node->result, *this );
     2797        maybeAccept_impl( node->expr  , *this );
     2798
     2799        VISIT_END( node );
     2800}
     2801
     2802template< typename pass_type >
    20202803Expression * PassVisitor< pass_type >::mutate( UniqueExpr * node ) {
    20212804        MUTATE_START( node );
     
    20362819        indexerScopedAccept( node->result, *this );
    20372820        maybeAccept_impl   ( node->expr  , *this );
     2821        // not currently visiting initAlts, but this doesn't matter since this node is only used in the resolver.
     2822
     2823        VISIT_END( node );
     2824}
     2825
     2826template< typename pass_type >
     2827void PassVisitor< pass_type >::visit( const UntypedInitExpr * node ) {
     2828        VISIT_START( node );
     2829
     2830        maybeAccept_impl( node->result, *this );
     2831        maybeAccept_impl( node->expr  , *this );
    20382832        // not currently visiting initAlts, but this doesn't matter since this node is only used in the resolver.
    20392833
     
    20672861
    20682862template< typename pass_type >
     2863void PassVisitor< pass_type >::visit( const InitExpr * node ) {
     2864        VISIT_START( node );
     2865
     2866        maybeAccept_impl( node->result, *this );
     2867        maybeAccept_impl( node->expr  , *this );
     2868        maybeAccept_impl( node->designation, *this );
     2869
     2870        VISIT_END( node );
     2871}
     2872
     2873template< typename pass_type >
    20692874Expression * PassVisitor< pass_type >::mutate( InitExpr * node ) {
    20702875        MUTATE_START( node );
     
    20922897
    20932898template< typename pass_type >
     2899void PassVisitor< pass_type >::visit( const DeletedExpr * node ) {
     2900        VISIT_START( node );
     2901
     2902        maybeAccept_impl( node->result, *this );
     2903        maybeAccept_impl( node->expr, *this );
     2904        // don't visit deleteStmt, because it is a pointer to somewhere else in the tree.
     2905
     2906        VISIT_END( node );
     2907}
     2908
     2909template< typename pass_type >
    20942910Expression * PassVisitor< pass_type >::mutate( DeletedExpr * node ) {
    20952911        MUTATE_START( node );
     
    21092925
    21102926        indexerScopedAccept( node->result, *this );
     2927        maybeAccept_impl( node->expr, *this );
     2928
     2929        VISIT_END( node );
     2930}
     2931
     2932template< typename pass_type >
     2933void PassVisitor< pass_type >::visit( const DefaultArgExpr * node ) {
     2934        VISIT_START( node );
     2935
     2936        maybeAccept_impl( node->result, *this );
    21112937        maybeAccept_impl( node->expr, *this );
    21122938
     
    21352961        for ( GenericExpr::Association & assoc : node->associations ) {
    21362962                indexerScopedAccept( assoc.type, *this );
     2963                maybeAccept_impl( assoc.expr, *this );
     2964        }
     2965
     2966        VISIT_END( node );
     2967}
     2968
     2969template< typename pass_type >
     2970void PassVisitor< pass_type >::visit( const GenericExpr * node ) {
     2971        VISIT_START( node );
     2972
     2973        maybeAccept_impl( node->result, *this );
     2974        maybeAccept_impl( node->control, *this );
     2975        for ( const GenericExpr::Association & assoc : node->associations ) {
     2976                maybeAccept_impl( assoc.type, *this );
    21372977                maybeAccept_impl( assoc.expr, *this );
    21382978        }
     
    21683008
    21693009template< typename pass_type >
     3010void PassVisitor< pass_type >::visit( const VoidType * node ) {
     3011        VISIT_START( node );
     3012
     3013        maybeAccept_impl( node->forall, *this );
     3014
     3015        VISIT_END( node );
     3016}
     3017
     3018template< typename pass_type >
    21703019Type * PassVisitor< pass_type >::mutate( VoidType * node ) {
    21713020        MUTATE_START( node );
     
    21803029template< typename pass_type >
    21813030void PassVisitor< pass_type >::visit( BasicType * node ) {
     3031        VISIT_START( node );
     3032
     3033        maybeAccept_impl( node->forall, *this );
     3034
     3035        VISIT_END( node );
     3036}
     3037
     3038template< typename pass_type >
     3039void PassVisitor< pass_type >::visit( const BasicType * node ) {
    21823040        VISIT_START( node );
    21833041
     
    22103068
    22113069template< typename pass_type >
     3070void PassVisitor< pass_type >::visit( const PointerType * node ) {
     3071        VISIT_START( node );
     3072
     3073        maybeAccept_impl( node->forall, *this );
     3074        // xxx - should PointerType visit/mutate dimension?
     3075        maybeAccept_impl( node->base, *this );
     3076
     3077        VISIT_END( node );
     3078}
     3079
     3080template< typename pass_type >
    22123081Type * PassVisitor< pass_type >::mutate( PointerType * node ) {
    22133082        MUTATE_START( node );
     
    22343103
    22353104template< typename pass_type >
     3105void PassVisitor< pass_type >::visit( const ArrayType * node ) {
     3106        VISIT_START( node );
     3107
     3108        maybeAccept_impl( node->forall, *this );
     3109        maybeAccept_impl( node->dimension, *this );
     3110        maybeAccept_impl( node->base, *this );
     3111
     3112        VISIT_END( node );
     3113}
     3114
     3115template< typename pass_type >
    22363116Type * PassVisitor< pass_type >::mutate( ArrayType * node ) {
    22373117        MUTATE_START( node );
     
    22573137
    22583138template< typename pass_type >
     3139void PassVisitor< pass_type >::visit( const ReferenceType * node ) {
     3140        VISIT_START( node );
     3141
     3142        maybeAccept_impl( node->forall, *this );
     3143        maybeAccept_impl( node->base, *this );
     3144
     3145        VISIT_END( node );
     3146}
     3147
     3148template< typename pass_type >
    22593149Type * PassVisitor< pass_type >::mutate( ReferenceType * node ) {
    22603150        MUTATE_START( node );
     
    22803170
    22813171template< typename pass_type >
     3172void PassVisitor< pass_type >::visit( const QualifiedType * node ) {
     3173        VISIT_START( node );
     3174
     3175        maybeAccept_impl( node->forall, *this );
     3176        maybeAccept_impl( node->parent, *this );
     3177        maybeAccept_impl( node->child, *this );
     3178
     3179        VISIT_END( node );
     3180}
     3181
     3182template< typename pass_type >
    22823183Type * PassVisitor< pass_type >::mutate( QualifiedType * node ) {
    22833184        MUTATE_START( node );
     
    22943195template< typename pass_type >
    22953196void PassVisitor< pass_type >::visit( FunctionType * node ) {
     3197        VISIT_START( node );
     3198
     3199        maybeAccept_impl( node->forall, *this );
     3200        maybeAccept_impl( node->returnVals, *this );
     3201        maybeAccept_impl( node->parameters, *this );
     3202
     3203        VISIT_END( node );
     3204}
     3205
     3206template< typename pass_type >
     3207void PassVisitor< pass_type >::visit( const FunctionType * node ) {
    22963208        VISIT_START( node );
    22973209
     
    23323244
    23333245template< typename pass_type >
     3246void PassVisitor< pass_type >::visit( const StructInstType * node ) {
     3247        VISIT_START( node );
     3248
     3249        maybeAccept_impl( node->forall    , *this );
     3250        maybeAccept_impl( node->parameters, *this );
     3251
     3252        VISIT_END( node );
     3253}
     3254
     3255template< typename pass_type >
    23343256Type * PassVisitor< pass_type >::mutate( StructInstType * node ) {
    23353257        MUTATE_START( node );
     
    23643286
    23653287template< typename pass_type >
     3288void PassVisitor< pass_type >::visit( const UnionInstType * node ) {
     3289        VISIT_START( node );
     3290
     3291        maybeAccept_impl( node->forall    , *this );
     3292        maybeAccept_impl( node->parameters, *this );
     3293
     3294        VISIT_END( node );
     3295}
     3296
     3297template< typename pass_type >
    23663298Type * PassVisitor< pass_type >::mutate( UnionInstType * node ) {
    23673299        MUTATE_START( node );
     
    23913323
    23923324template< typename pass_type >
     3325void PassVisitor< pass_type >::visit( const EnumInstType * node ) {
     3326        VISIT_START( node );
     3327
     3328        maybeAccept_impl( node->forall, *this );
     3329        maybeAccept_impl( node->parameters, *this );
     3330
     3331        VISIT_END( node );
     3332}
     3333
     3334template< typename pass_type >
    23933335Type * PassVisitor< pass_type >::mutate( EnumInstType * node ) {
    23943336        MUTATE_START( node );
     
    24133355
    24143356template< typename pass_type >
     3357void PassVisitor< pass_type >::visit( const TraitInstType * node ) {
     3358        VISIT_START( node );
     3359
     3360        maybeAccept_impl( node->forall    , *this );
     3361        maybeAccept_impl( node->parameters, *this );
     3362
     3363        VISIT_END( node );
     3364}
     3365
     3366template< typename pass_type >
    24153367Type * PassVisitor< pass_type >::mutate( TraitInstType * node ) {
    24163368        MUTATE_START( node );
     
    24263378template< typename pass_type >
    24273379void PassVisitor< pass_type >::visit( TypeInstType * node ) {
     3380        VISIT_START( node );
     3381
     3382        maybeAccept_impl( node->forall    , *this );
     3383        maybeAccept_impl( node->parameters, *this );
     3384
     3385        VISIT_END( node );
     3386}
     3387
     3388template< typename pass_type >
     3389void PassVisitor< pass_type >::visit( const TypeInstType * node ) {
    24283390        VISIT_START( node );
    24293391
     
    24583420
    24593421template< typename pass_type >
     3422void PassVisitor< pass_type >::visit( const TupleType * node ) {
     3423        VISIT_START( node );
     3424
     3425        maybeAccept_impl( node->forall, *this );
     3426        maybeAccept_impl( node->types, *this );
     3427        maybeAccept_impl( node->members, *this );
     3428
     3429        VISIT_END( node );
     3430}
     3431
     3432template< typename pass_type >
    24603433Type * PassVisitor< pass_type >::mutate( TupleType * node ) {
    24613434        MUTATE_START( node );
     
    24723445template< typename pass_type >
    24733446void PassVisitor< pass_type >::visit( TypeofType * node ) {
     3447        VISIT_START( node );
     3448
     3449        assert( node->expr );
     3450        maybeAccept_impl( node->expr, *this );
     3451
     3452        VISIT_END( node );
     3453}
     3454
     3455template< typename pass_type >
     3456void PassVisitor< pass_type >::visit( const TypeofType * node ) {
    24743457        VISIT_START( node );
    24753458
     
    25083491
    25093492template< typename pass_type >
     3493void PassVisitor< pass_type >::visit( const AttrType * node ) {
     3494        VISIT_START( node );
     3495
     3496        if ( node->isType ) {
     3497                assert( node->type );
     3498                maybeAccept_impl( node->type, *this );
     3499        } else {
     3500                assert( node->expr );
     3501                maybeAccept_impl( node->expr, *this );
     3502        } // if
     3503
     3504        VISIT_END( node );
     3505}
     3506
     3507template< typename pass_type >
    25103508Type * PassVisitor< pass_type >::mutate( AttrType * node ) {
    25113509        MUTATE_START( node );
     
    25343532
    25353533template< typename pass_type >
     3534void PassVisitor< pass_type >::visit( const VarArgsType * node ) {
     3535        VISIT_START( node );
     3536
     3537        maybeAccept_impl( node->forall, *this );
     3538
     3539        VISIT_END( node );
     3540}
     3541
     3542template< typename pass_type >
    25363543Type * PassVisitor< pass_type >::mutate( VarArgsType * node ) {
    25373544        MUTATE_START( node );
     
    25543561
    25553562template< typename pass_type >
     3563void PassVisitor< pass_type >::visit( const ZeroType * node ) {
     3564        VISIT_START( node );
     3565
     3566        maybeAccept_impl( node->forall, *this );
     3567
     3568        VISIT_END( node );
     3569}
     3570
     3571template< typename pass_type >
    25563572Type * PassVisitor< pass_type >::mutate( ZeroType * node ) {
    25573573        MUTATE_START( node );
     
    25743590
    25753591template< typename pass_type >
     3592void PassVisitor< pass_type >::visit( const OneType * node ) {
     3593        VISIT_START( node );
     3594
     3595        maybeAccept_impl( node->forall, *this );
     3596
     3597        VISIT_END( node );
     3598}
     3599
     3600template< typename pass_type >
    25763601Type * PassVisitor< pass_type >::mutate( OneType * node ) {
    25773602        MUTATE_START( node );
     
    25943619
    25953620template< typename pass_type >
     3621void PassVisitor< pass_type >::visit( const GlobalScopeType * node ) {
     3622        VISIT_START( node );
     3623
     3624        maybeAccept_impl( node->forall, *this );
     3625
     3626        VISIT_END( node );
     3627}
     3628
     3629template< typename pass_type >
    25963630Type * PassVisitor< pass_type >::mutate( GlobalScopeType * node ) {
    25973631        MUTATE_START( node );
     
    26143648
    26153649template< typename pass_type >
     3650void PassVisitor< pass_type >::visit( const Designation * node ) {
     3651        VISIT_START( node );
     3652
     3653        maybeAccept_impl( node->designators, *this );
     3654
     3655        VISIT_END( node );
     3656}
     3657
     3658template< typename pass_type >
    26163659Designation * PassVisitor< pass_type >::mutate( Designation * node ) {
    26173660        MUTATE_START( node );
     
    26343677
    26353678template< typename pass_type >
     3679void PassVisitor< pass_type >::visit( const SingleInit * node ) {
     3680        VISIT_START( node );
     3681
     3682        visitExpression( node->value );
     3683
     3684        VISIT_END( node );
     3685}
     3686
     3687template< typename pass_type >
    26363688Initializer * PassVisitor< pass_type >::mutate( SingleInit * node ) {
    26373689        MUTATE_START( node );
     
    26463698template< typename pass_type >
    26473699void PassVisitor< pass_type >::visit( ListInit * node ) {
     3700        VISIT_START( node );
     3701
     3702        maybeAccept_impl( node->designations, *this );
     3703        maybeAccept_impl( node->initializers, *this );
     3704
     3705        VISIT_END( node );
     3706}
     3707
     3708template< typename pass_type >
     3709void PassVisitor< pass_type >::visit( const ListInit * node ) {
    26483710        VISIT_START( node );
    26493711
     
    26783740
    26793741template< typename pass_type >
     3742void PassVisitor< pass_type >::visit( const ConstructorInit * node ) {
     3743        VISIT_START( node );
     3744
     3745        maybeAccept_impl( node->ctor, *this );
     3746        maybeAccept_impl( node->dtor, *this );
     3747        maybeAccept_impl( node->init, *this );
     3748
     3749        VISIT_END( node );
     3750}
     3751
     3752template< typename pass_type >
    26803753Initializer * PassVisitor< pass_type >::mutate( ConstructorInit * node ) {
    26813754        MUTATE_START( node );
     
    26983771
    26993772template< typename pass_type >
     3773void PassVisitor< pass_type >::visit( const Constant * node ) {
     3774        VISIT_START( node );
     3775
     3776        VISIT_END( node );
     3777}
     3778
     3779template< typename pass_type >
    27003780Constant * PassVisitor< pass_type >::mutate( Constant * node  )  {
    27013781        MUTATE_START( node );
     
    27083788template< typename pass_type >
    27093789void PassVisitor< pass_type >::visit( Attribute * node ) {
     3790        VISIT_START( node );
     3791
     3792        maybeAccept_impl( node->parameters, *this );
     3793
     3794        VISIT_END( node );
     3795}
     3796
     3797template< typename pass_type >
     3798void PassVisitor< pass_type >::visit( const Attribute * node ) {
    27103799        VISIT_START( node );
    27113800
  • src/Common/PassVisitor.proto.h

    r302d84c2 rfce4e31  
    118118static inline void postvisit_impl( __attribute__((unused)) pass_type& pass, __attribute__((unused)) node_type * node, __attribute__((unused)) long unused ) {}
    119119
     120template<typename pass_type, typename node_type>
     121static inline auto previsit_impl( pass_type& pass, const node_type * node, __attribute__((unused)) int unused ) -> decltype( pass.previsit( node ), void() ) {
     122        pass.previsit( node );
     123}
     124
     125template<typename pass_type, typename node_type>
     126static inline void previsit_impl( __attribute__((unused)) pass_type& pass, __attribute__((unused)) const node_type * node, __attribute__((unused)) long unused ) {}
     127
     128
     129template<typename pass_type, typename node_type>
     130static inline auto postvisit_impl( pass_type& pass, const node_type * node, __attribute__((unused)) int unused ) -> decltype( pass.postvisit( node ), void() ) {
     131        pass.postvisit( node );
     132}
     133
     134template<typename pass_type, typename node_type>
     135static inline void postvisit_impl( __attribute__((unused)) pass_type& pass, __attribute__((unused)) const node_type * node, __attribute__((unused)) long unused ) {}
     136
    120137//---------------------------------------------------------
    121138// Mutate
     
    200217        pass.indexer.func( arg );                                                                                                \
    201218}                                                                                                                              \
    202                                                                                                                                \
    203 template<typename pass_type>                                                                                                   \
    204 static inline void indexer_impl_##func ( pass_type &, long, type ) { }                                                          \
     219template<typename pass_type>                                                                                                   \
     220static inline void indexer_impl_##func ( pass_type &, long, type ) { }
    205221
    206222#define INDEXER_FUNC2( func, type1, type2 )                                                                                             \
     
    209225        pass.indexer.func( arg1, arg2 );                                                                                                \
    210226}                                                                                                                              \
    211                                                                                                                                \
    212227template<typename pass_type>                                                                                                   \
    213228static inline void indexer_impl_##func ( pass_type &, long, type1, type2 ) { }
     
    233248
    234249template<typename pass_type>
    235 static inline auto indexer_impl_addStructFwd( pass_type &, long, StructDecl * ) {}
     250static inline auto indexer_impl_addStructFwd( pass_type &, long, const StructDecl * ) {}
    236251
    237252template<typename pass_type>
     
    243258
    244259template<typename pass_type>
    245 static inline auto indexer_impl_addUnionFwd( pass_type &, long, UnionDecl * ) {}
     260static inline auto indexer_impl_addUnionFwd( pass_type &, long, const UnionDecl * ) {}
    246261
    247262template<typename pass_type>
  • src/ResolvExpr/AdjustExprType.cc

    r302d84c2 rfce4e31  
    4747                void premutate( OneType * ) { visit_children = false; }
    4848
    49                 Type * postmutate( ArrayType *arrayType );
    50                 Type * postmutate( FunctionType *functionType );
    51                 Type * postmutate( TypeInstType *aggregateUseType );
     49                Type * postmutate( ArrayType * arrayType );
     50                Type * postmutate( FunctionType * functionType );
     51                Type * postmutate( TypeInstType * aggregateUseType );
    5252
    5353                private:
     
    6161
    6262        Type * AdjustExprType_old::postmutate( ArrayType * arrayType ) {
    63                 PointerType *pointerType = new PointerType{ arrayType->get_qualifiers(), arrayType->base };
     63                PointerType * pointerType = new PointerType{ arrayType->get_qualifiers(), arrayType->base };
    6464                arrayType->base = nullptr;
    6565                delete arrayType;
     
    7272
    7373        Type * AdjustExprType_old::postmutate( TypeInstType * typeInst ) {
    74                 if ( const EqvClass* eqvClass = env.lookup( typeInst->get_name() ) ) {
     74                if ( const EqvClass * eqvClass = env.lookup( typeInst->get_name() ) ) {
    7575                        if ( eqvClass->data.kind == TypeDecl::Ftype ) {
    7676                                return new PointerType{ Type::Qualifiers(), typeInst };
    7777                        }
    78                 } else if ( NamedTypeDecl *ntDecl = indexer.lookupType( typeInst->get_name() ) ) {
    79                         if ( TypeDecl *tyDecl = dynamic_cast< TypeDecl* >( ntDecl ) ) {
     78                } else if ( const NamedTypeDecl * ntDecl = indexer.lookupType( typeInst->get_name() ) ) {
     79                        if ( const TypeDecl * tyDecl = dynamic_cast< const TypeDecl * >( ntDecl ) ) {
    8080                                if ( tyDecl->get_kind() == TypeDecl::Ftype ) {
    8181                                        return new PointerType{ Type::Qualifiers(), typeInst };
     
    8989void adjustExprType( Type *&type, const TypeEnvironment &env, const SymTab::Indexer &indexer ) {
    9090        PassVisitor<AdjustExprType_old> adjuster( env, indexer );
    91         Type *newType = type->acceptMutator( adjuster );
     91        Type * newType = type->acceptMutator( adjuster );
    9292        type = newType;
    9393}
     
    148148} // anonymous namespace
    149149
    150 const ast::Type * adjustExprType( 
    151         const ast::Type * type, const ast::TypeEnvironment & env, const ast::SymbolTable & symtab 
     150const ast::Type * adjustExprType(
     151        const ast::Type * type, const ast::TypeEnvironment & env, const ast::SymbolTable & symtab
    152152) {
    153153        ast::Pass<AdjustExprType_new> adjuster{ env, symtab };
  • src/ResolvExpr/CastCost.cc

    r302d84c2 rfce4e31  
    3737        struct CastCost_old : public ConversionCost {
    3838          public:
    39                 CastCost_old( Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env, CostFunction costFunc );
     39                CastCost_old( const Type * dest, const SymTab::Indexer &indexer, const TypeEnvironment &env, CostFunction costFunc );
    4040
    4141                using ConversionCost::previsit;
    4242                using ConversionCost::postvisit;
    43                 void postvisit( BasicType * basicType );
    44                 void postvisit( PointerType * pointerType );
     43                void postvisit( const BasicType * basicType );
     44                void postvisit( const PointerType * pointerType );
    4545        };
    4646
    47         Cost castCost( Type *src, Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env ) {
    48                 if ( TypeInstType *destAsTypeInst = dynamic_cast< TypeInstType* >( dest ) ) {
    49                         if ( const EqvClass* eqvClass = env.lookup( destAsTypeInst->get_name() ) ) {
     47        Cost castCost( const Type * src, const Type * dest, const SymTab::Indexer &indexer, const TypeEnvironment &env ) {
     48                if ( const TypeInstType * destAsTypeInst = dynamic_cast< const TypeInstType * >( dest ) ) {
     49                        if ( const EqvClass * eqvClass = env.lookup( destAsTypeInst->name ) ) {
    5050                                if ( eqvClass->type ) {
    5151                                        return castCost( src, eqvClass->type, indexer, env );
     
    5353                                        return Cost::infinity;
    5454                                }
    55                         } else if ( NamedTypeDecl *namedType = indexer.lookupType( destAsTypeInst->get_name() ) ) {
     55                        } else if ( const NamedTypeDecl * namedType = indexer.lookupType( destAsTypeInst->name ) ) {
    5656                                // all typedefs should be gone by this point
    57                                 TypeDecl *type = strict_dynamic_cast< TypeDecl* >( namedType );
     57                                const TypeDecl * type = strict_dynamic_cast< const TypeDecl * >( namedType );
    5858                                if ( type->base ) {
    5959                                        return castCost( src, type->base, indexer, env ) + Cost::safe;
     
    7474                        PRINT( std::cerr << "compatible!" << std::endl; )
    7575                        return Cost::zero;
    76                 } else if ( dynamic_cast< VoidType* >( dest ) ) {
     76                } else if ( dynamic_cast< const VoidType * >( dest ) ) {
    7777                        return Cost::safe;
    78                 } else if ( ReferenceType * refType = dynamic_cast< ReferenceType * > ( dest ) ) {
     78                } else if ( const ReferenceType * refType = dynamic_cast< const ReferenceType * > ( dest ) ) {
    7979                        PRINT( std::cerr << "conversionCost: dest is reference" << std::endl; )
    80                         return convertToReferenceCost( src, refType, indexer, env, [](Type * t1, Type * t2, const SymTab::Indexer & indexer, const TypeEnvironment & env ) {
     80                        return convertToReferenceCost( src, refType, indexer, env, [](const Type * t1, const Type * t2, const SymTab::Indexer & indexer, const TypeEnvironment & env ) {
    8181                                return ptrsCastable( t1, t2, env, indexer );
    8282                        });
    8383                } else {
    84                         PassVisitor<CastCost_old> converter( 
    85                                 dest, indexer, env, 
    86                                 (Cost (*)( Type *, Type *, const SymTab::Indexer &, const TypeEnvironment & ))
     84                        PassVisitor<CastCost_old> converter(
     85                                dest, indexer, env,
     86                                (Cost (*)( const Type *, const Type *, const SymTab::Indexer &, const TypeEnvironment & ))
    8787                                        castCost );
    8888                        src->accept( converter );
     
    9696        }
    9797
    98         CastCost_old::CastCost_old( Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env, CostFunction costFunc )
     98        CastCost_old::CastCost_old( const Type * dest, const SymTab::Indexer &indexer, const TypeEnvironment &env, CostFunction costFunc )
    9999                : ConversionCost( dest, indexer, env, costFunc ) {
    100100        }
    101101
    102         void CastCost_old::postvisit( BasicType *basicType ) {
    103                 PointerType *destAsPointer = dynamic_cast< PointerType* >( dest );
     102        void CastCost_old::postvisit( const BasicType * basicType ) {
     103                const PointerType * destAsPointer = dynamic_cast< const PointerType * >( dest );
    104104                if ( destAsPointer && basicType->isInteger() ) {
    105                         // necessary for, e.g. unsigned long => void*
     105                        // necessary for, e.g. unsigned long => void *
    106106                        cost = Cost::unsafe;
    107107                } else {
     
    110110        }
    111111
    112         void CastCost_old::postvisit( PointerType *pointerType ) {
    113                 if ( PointerType *destAsPtr = dynamic_cast< PointerType* >( dest ) ) {
    114                         if ( pointerType->get_qualifiers() <= destAsPtr->get_qualifiers() && typesCompatibleIgnoreQualifiers( pointerType->base, destAsPtr->base, indexer, env ) ) {
     112        void CastCost_old::postvisit( const PointerType * pointerType ) {
     113                if ( const PointerType * destAsPtr = dynamic_cast< const PointerType * >( dest ) ) {
     114                        if ( pointerType->tq <= destAsPtr->tq && typesCompatibleIgnoreQualifiers( pointerType->base, destAsPtr->base, indexer, env ) ) {
    115115                                cost = Cost::safe;
    116116                        } else {
     
    125125                                } // if
    126126                        } // if
    127                 } else if ( BasicType *destAsBasic = dynamic_cast< BasicType* >( dest ) ) {
     127                } else if ( const BasicType * destAsBasic = dynamic_cast< const BasicType * >( dest ) ) {
    128128                        if ( destAsBasic->isInteger() ) {
    129                                 // necessary for, e.g. void* => unsigned long
     129                                // necessary for, e.g. void * => unsigned long
    130130                                cost = Cost::unsafe;
    131131                        } // if
     
    138138                using ConversionCost_new::postvisit;
    139139
    140                 CastCost_new( 
    141                         const ast::Type * dst, const ast::SymbolTable & symtab, 
     140                CastCost_new(
     141                        const ast::Type * dst, const ast::SymbolTable & symtab,
    142142                        const ast::TypeEnvironment & env, CostCalculation costFunc )
    143143                : ConversionCost_new( dst, symtab, env, costFunc ) {}
     
    182182} // anonymous namespace
    183183
    184 Cost castCost( 
    185         const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab, 
    186         const ast::TypeEnvironment & env 
     184Cost castCost(
     185        const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab,
     186        const ast::TypeEnvironment & env
    187187) {
    188188        if ( auto typeInst = dynamic_cast< const ast::TypeInstType * >( dst ) ) {
     
    220220                PRINT( std::cerr << "conversionCost: dest is reference" << std::endl; )
    221221                #warning cast on ptrsCastable artifact of having two functions, remove when port done
    222                 return convertToReferenceCost( 
    223                         src, refType, symtab, env, 
    224                         ( int (*)( 
    225                                 const ast::Type *, const ast::Type *, const ast::SymbolTable &, 
     222                return convertToReferenceCost(
     223                        src, refType, symtab, env,
     224                        ( int (*)(
     225                                const ast::Type *, const ast::Type *, const ast::SymbolTable &,
    226226                                const ast::TypeEnvironment & )
    227227                        ) ptrsCastable );
     
    229229                #warning cast on castCost artifact of having two functions, remove when port done
    230230                ast::Pass< CastCost_new > converter{
    231                         dst, symtab, env, 
    232                         ( Cost (*)( 
    233                                 const ast::Type *, const ast::Type *, const ast::SymbolTable &, 
     231                        dst, symtab, env,
     232                        ( Cost (*)(
     233                                const ast::Type *, const ast::Type *, const ast::SymbolTable &,
    234234                                const ast::TypeEnvironment & )
    235235                        ) castCost };
  • src/ResolvExpr/CommonType.cc

    r302d84c2 rfce4e31  
    3838namespace ResolvExpr {
    3939        struct CommonType_old : public WithShortCircuiting {
    40                 CommonType_old( Type *type2, bool widenFirst, bool widenSecond, const SymTab::Indexer &indexer, TypeEnvironment &env, const OpenVarSet &openVars );
    41                 Type *get_result() const { return result; }
     40                CommonType_old( Type * type2, bool widenFirst, bool widenSecond, const SymTab::Indexer &indexer, TypeEnvironment &env, const OpenVarSet &openVars );
     41                Type * get_result() const { return result; }
    4242
    4343                void previsit( BaseSyntaxNode * ) { visit_children = false; }
     
    6060
    6161          private:
    62                 template< typename Pointer > void getCommonWithVoidPointer( Pointer* voidPointer, Pointer* otherPointer );
    63                 template< typename RefType > void handleRefType( RefType *inst, Type *other );
    64 
    65                 Type *result;
    66                 Type *type2;                            // inherited
     62                template< typename Pointer > void getCommonWithVoidPointer( Pointer * voidPointer, Pointer * otherPointer );
     63                template< typename RefType > void handleRefType( RefType * inst, Type * other );
     64
     65                Type * result;
     66                Type * type2;                           // inherited
    6767                bool widenFirst, widenSecond;
    6868                const SymTab::Indexer &indexer;
     
    8080                                std::cerr << "unify success: " << widenFirst << " " << widenSecond << std::endl;
    8181                        )
    82                         if ( (widenFirst || t2->get_qualifiers() <= t1->get_qualifiers()) && (widenSecond || t1->get_qualifiers() <= t2->get_qualifiers()) ) {
     82                        if ( (widenFirst || t2->tq <= t1->tq) && (widenSecond || t1->tq <= t2->tq) ) {
    8383                                PRINT(
    8484                                        std::cerr << "widen okay" << std::endl;
    8585                                )
    86                                 common->get_qualifiers() |= t1->get_qualifiers();
    87                                 common->get_qualifiers() |= t2->get_qualifiers();
     86                                common->tq |= t1->tq;
     87                                common->tq |= t2->tq;
    8888                                return common;
    8989                        }
     
    9595        }
    9696
    97         Type *commonType( Type *type1, Type *type2, bool widenFirst, bool widenSecond, const SymTab::Indexer &indexer, TypeEnvironment &env, const OpenVarSet &openVars ) {
     97        Type * commonType( Type * type1, Type * type2, bool widenFirst, bool widenSecond, const SymTab::Indexer &indexer, TypeEnvironment &env, const OpenVarSet &openVars ) {
    9898                PassVisitor<CommonType_old> visitor( type2, widenFirst, widenSecond, indexer, env, openVars );
    9999
     
    127127                                                std::cerr << "formal is reference; result should be reference" << std::endl;
    128128                                        )
    129                                         result = new ReferenceType( ref1->get_qualifiers(), result );
     129                                        result = new ReferenceType( ref1->tq, result );
    130130                                }
    131131                                PRINT(
     
    138138
    139139                type1->accept( visitor );
    140                 Type *result = visitor.pass.get_result();
     140                Type * result = visitor.pass.get_result();
    141141                if ( ! result ) {
    142142                        // this appears to be handling for opaque type declarations
    143143                        if ( widenSecond ) {
    144                                 if ( TypeInstType *inst = dynamic_cast< TypeInstType* >( type2 ) ) {
    145                                         if ( NamedTypeDecl *nt = indexer.lookupType( inst->get_name() ) ) {
    146                                                 TypeDecl *type = strict_dynamic_cast< TypeDecl* >( nt );
     144                                if ( const TypeInstType * inst = dynamic_cast< const TypeInstType * >( type2 ) ) {
     145                                        if ( const NamedTypeDecl * nt = indexer.lookupType( inst->get_name() ) ) {
     146                                                const TypeDecl * type = strict_dynamic_cast< const TypeDecl * >( nt );
    147147                                                if ( type->get_base() ) {
    148                                                         Type::Qualifiers tq1 = type1->get_qualifiers(), tq2 = type2->get_qualifiers();
     148                                                        Type::Qualifiers tq1 = type1->tq, tq2 = type2->tq;
    149149                                                        AssertionSet have, need;
    150150                                                        OpenVarSet newOpen( openVars );
    151                                                         type1->get_qualifiers() = Type::Qualifiers();
    152                                                         type->get_base()->get_qualifiers() = tq1;
     151                                                        type1->tq = Type::Qualifiers();
     152                                                        type->get_base()->tq = tq1;
    153153                                                        if ( unifyExact( type1, type->get_base(), env, have, need, newOpen, indexer ) ) {
    154154                                                                result = type1->clone();
    155                                                                 result->get_qualifiers() = tq1 | tq2;
     155                                                                result->tq = tq1 | tq2;
    156156                                                        } // if
    157                                                         type1->get_qualifiers() = tq1;
    158                                                         type->get_base()->get_qualifiers() = Type::Qualifiers();
     157                                                        type1->tq = tq1;
     158                                                        type->get_base()->tq = Type::Qualifiers();
    159159                                                } // if
    160160                                        } // if
     
    190190                                 */
    191191                                  {
    192                 /*     B*/                BT Bool,                BT Char,          BT SignedChar,        BT UnsignedChar,      BT ShortSignedInt,    BT ShortUnsignedInt,
     192                /*     B */                BT Bool,                BT Char,          BT SignedChar,        BT UnsignedChar,      BT ShortSignedInt,    BT ShortUnsignedInt,
    193193                                             BT SignedInt,         BT UnsignedInt,       BT LongSignedInt,     BT LongUnsignedInt,   BT LongLongSignedInt, BT LongLongUnsignedInt,
    194194                                          BT SignedInt128,      BT UnsignedInt128,            BT uFloat16,     BT uFloat16Complex,            BT uFloat32,     BT uFloat32Complex,
     
    198198                                  },
    199199                                  {
    200                 /*     C*/                BT Char,                BT Char,          BT SignedChar,        BT UnsignedChar,      BT ShortSignedInt,    BT ShortUnsignedInt,
     200                /*     C */                BT Char,                BT Char,          BT SignedChar,        BT UnsignedChar,      BT ShortSignedInt,    BT ShortUnsignedInt,
    201201                                             BT SignedInt,         BT UnsignedInt,       BT LongSignedInt,     BT LongUnsignedInt,   BT LongLongSignedInt, BT LongLongUnsignedInt,
    202202                                          BT SignedInt128,      BT UnsignedInt128,            BT uFloat16,     BT uFloat16Complex,            BT uFloat32,     BT uFloat32Complex,
     
    206206                                  },
    207207                                  {
    208                 /*    SC*/          BT SignedChar,          BT SignedChar,          BT SignedChar,        BT UnsignedChar,      BT ShortSignedInt,    BT ShortUnsignedInt,
     208                /*    SC */          BT SignedChar,          BT SignedChar,          BT SignedChar,        BT UnsignedChar,      BT ShortSignedInt,    BT ShortUnsignedInt,
    209209                                             BT SignedInt,         BT UnsignedInt,       BT LongSignedInt,     BT LongUnsignedInt,   BT LongLongSignedInt, BT LongLongUnsignedInt,
    210210                                          BT SignedInt128,      BT UnsignedInt128,            BT uFloat16,     BT uFloat16Complex,            BT uFloat32,     BT uFloat32Complex,
     
    214214                                  },
    215215                                  {
    216                 /*    UC*/        BT UnsignedChar,        BT UnsignedChar,        BT UnsignedChar,        BT UnsignedChar,      BT ShortSignedInt,    BT ShortUnsignedInt,
     216                /*    UC */        BT UnsignedChar,        BT UnsignedChar,        BT UnsignedChar,        BT UnsignedChar,      BT ShortSignedInt,    BT ShortUnsignedInt,
    217217                                             BT SignedInt,         BT UnsignedInt,       BT LongSignedInt,     BT LongUnsignedInt,   BT LongLongSignedInt, BT LongLongUnsignedInt,
    218218                                          BT SignedInt128,      BT UnsignedInt128,            BT uFloat16,     BT uFloat16Complex,            BT uFloat32,     BT uFloat32Complex,
     
    222222                                  },
    223223                                  {
    224                 /*    SI*/      BT ShortSignedInt,      BT ShortSignedInt,      BT ShortSignedInt,      BT ShortSignedInt,      BT ShortSignedInt,    BT ShortUnsignedInt,
     224                /*    SI */      BT ShortSignedInt,      BT ShortSignedInt,      BT ShortSignedInt,      BT ShortSignedInt,      BT ShortSignedInt,    BT ShortUnsignedInt,
    225225                                             BT SignedInt,         BT UnsignedInt,       BT LongSignedInt,     BT LongUnsignedInt,   BT LongLongSignedInt, BT LongLongUnsignedInt,
    226226                                          BT SignedInt128,      BT UnsignedInt128,            BT uFloat16,     BT uFloat16Complex,            BT uFloat32,     BT uFloat32Complex,
     
    230230                                  },
    231231                                  {
    232                 /*   SUI*/    BT ShortUnsignedInt,    BT ShortUnsignedInt,    BT ShortUnsignedInt,    BT ShortUnsignedInt,    BT ShortUnsignedInt,    BT ShortUnsignedInt,
     232                /*   SUI */    BT ShortUnsignedInt,    BT ShortUnsignedInt,    BT ShortUnsignedInt,    BT ShortUnsignedInt,    BT ShortUnsignedInt,    BT ShortUnsignedInt,
    233233                                             BT SignedInt,         BT UnsignedInt,       BT LongSignedInt,     BT LongUnsignedInt,   BT LongLongSignedInt, BT LongLongUnsignedInt,
    234234                                          BT SignedInt128,      BT UnsignedInt128,            BT uFloat16,     BT uFloat16Complex,            BT uFloat32,     BT uFloat32Complex,
     
    238238                                  },
    239239                                  {
    240                 /*     I*/           BT SignedInt,           BT SignedInt,           BT SignedInt,           BT SignedInt,           BT SignedInt,           BT SignedInt,
     240                /*     I */           BT SignedInt,           BT SignedInt,           BT SignedInt,           BT SignedInt,           BT SignedInt,           BT SignedInt,
    241241                                             BT SignedInt,         BT UnsignedInt,       BT LongSignedInt,     BT LongUnsignedInt,   BT LongLongSignedInt, BT LongLongUnsignedInt,
    242242                                          BT SignedInt128,      BT UnsignedInt128,            BT uFloat16,     BT uFloat16Complex,            BT uFloat32,     BT uFloat32Complex,
     
    246246                                  },
    247247                                  {
    248                 /*    UI*/         BT UnsignedInt,         BT UnsignedInt,         BT UnsignedInt,         BT UnsignedInt,         BT UnsignedInt,         BT UnsignedInt,
     248                /*    UI */         BT UnsignedInt,         BT UnsignedInt,         BT UnsignedInt,         BT UnsignedInt,         BT UnsignedInt,         BT UnsignedInt,
    249249                                           BT UnsignedInt,         BT UnsignedInt,       BT LongSignedInt,     BT LongUnsignedInt,   BT LongLongSignedInt, BT LongLongUnsignedInt,
    250250                                          BT SignedInt128,      BT UnsignedInt128,            BT uFloat16,     BT uFloat16Complex,            BT uFloat32,     BT uFloat32Complex,
     
    254254                                  },
    255255                                  {
    256                 /*    LI*/       BT LongSignedInt,       BT LongSignedInt,       BT LongSignedInt,       BT LongSignedInt,       BT LongSignedInt,       BT LongSignedInt,
     256                /*    LI */       BT LongSignedInt,       BT LongSignedInt,       BT LongSignedInt,       BT LongSignedInt,       BT LongSignedInt,       BT LongSignedInt,
    257257                                         BT LongSignedInt,       BT LongSignedInt,       BT LongSignedInt,     BT LongUnsignedInt,   BT LongLongSignedInt, BT LongLongUnsignedInt,
    258258                                          BT SignedInt128,      BT UnsignedInt128,            BT uFloat16,     BT uFloat16Complex,            BT uFloat32,     BT uFloat32Complex,
     
    262262                                  },
    263263                                  {
    264                 /*   LUI*/     BT LongUnsignedInt,     BT LongUnsignedInt,     BT LongUnsignedInt,     BT LongUnsignedInt,     BT LongUnsignedInt,     BT LongUnsignedInt,
     264                /*   LUI */     BT LongUnsignedInt,     BT LongUnsignedInt,     BT LongUnsignedInt,     BT LongUnsignedInt,     BT LongUnsignedInt,     BT LongUnsignedInt,
    265265                                       BT LongUnsignedInt,     BT LongUnsignedInt,     BT LongUnsignedInt,     BT LongUnsignedInt,   BT LongLongSignedInt, BT LongLongUnsignedInt,
    266266                                          BT SignedInt128,      BT UnsignedInt128,            BT uFloat16,     BT uFloat16Complex,            BT uFloat32,     BT uFloat32Complex,
     
    270270                                  },
    271271                                  {
    272                 /*   LLI*/   BT LongLongSignedInt,   BT LongLongSignedInt,   BT LongLongSignedInt,   BT LongLongSignedInt,   BT LongLongSignedInt,   BT LongLongSignedInt,
     272                /*   LLI */   BT LongLongSignedInt,   BT LongLongSignedInt,   BT LongLongSignedInt,   BT LongLongSignedInt,   BT LongLongSignedInt,   BT LongLongSignedInt,
    273273                                     BT LongLongSignedInt,   BT LongLongSignedInt,   BT LongLongSignedInt,   BT LongLongSignedInt,   BT LongLongSignedInt, BT LongLongUnsignedInt,
    274274                                          BT SignedInt128,      BT UnsignedInt128,            BT uFloat16,     BT uFloat16Complex,            BT uFloat32,     BT uFloat32Complex,
     
    278278                                  },
    279279                                  {
    280                 /*  LLUI*/ BT LongLongUnsignedInt, BT LongLongUnsignedInt, BT LongLongUnsignedInt, BT LongLongUnsignedInt, BT LongLongUnsignedInt, BT LongLongUnsignedInt,
     280                /*  LLUI */ BT LongLongUnsignedInt, BT LongLongUnsignedInt, BT LongLongUnsignedInt, BT LongLongUnsignedInt, BT LongLongUnsignedInt, BT LongLongUnsignedInt,
    281281                                   BT LongLongUnsignedInt, BT LongLongUnsignedInt, BT LongLongUnsignedInt, BT LongLongUnsignedInt, BT LongLongUnsignedInt, BT LongLongUnsignedInt,
    282282                                          BT SignedInt128,      BT UnsignedInt128,            BT uFloat16,     BT uFloat16Complex,            BT uFloat32,     BT uFloat32Complex,
     
    286286                                  },
    287287                                  {
    288                 /*    IB*/        BT SignedInt128,        BT SignedInt128,        BT SignedInt128,        BT SignedInt128,        BT SignedInt128,        BT SignedInt128,
     288                /*    IB */        BT SignedInt128,        BT SignedInt128,        BT SignedInt128,        BT SignedInt128,        BT SignedInt128,        BT SignedInt128,
    289289                                          BT SignedInt128,        BT SignedInt128,        BT SignedInt128,        BT SignedInt128,        BT SignedInt128,        BT SignedInt128,
    290290                                          BT SignedInt128,      BT UnsignedInt128,            BT uFloat16,     BT uFloat16Complex,            BT uFloat32,     BT uFloat32Complex,
     
    294294                                  },
    295295                                  {
    296                 /*   UIB*/      BT UnsignedInt128,      BT UnsignedInt128,      BT UnsignedInt128,      BT UnsignedInt128,      BT UnsignedInt128,      BT UnsignedInt128,
     296                /*   UIB */      BT UnsignedInt128,      BT UnsignedInt128,      BT UnsignedInt128,      BT UnsignedInt128,      BT UnsignedInt128,      BT UnsignedInt128,
    297297                                        BT UnsignedInt128,      BT UnsignedInt128,      BT UnsignedInt128,      BT UnsignedInt128,      BT UnsignedInt128,      BT UnsignedInt128,
    298298                                        BT UnsignedInt128,      BT UnsignedInt128,            BT uFloat16,     BT uFloat16Complex,            BT uFloat32,     BT uFloat32Complex,
     
    302302                                  },
    303303                                  {
    304                 /*   _FH*/            BT uFloat16,            BT uFloat16,            BT uFloat16,            BT uFloat16,            BT uFloat16,            BT uFloat16,
     304                /*   _FH */            BT uFloat16,            BT uFloat16,            BT uFloat16,            BT uFloat16,            BT uFloat16,            BT uFloat16,
    305305                                              BT uFloat16,            BT uFloat16,            BT uFloat16,            BT uFloat16,            BT uFloat16,            BT uFloat16,
    306306                                              BT uFloat16,            BT uFloat16,            BT uFloat16,     BT uFloat16Complex,            BT uFloat32,     BT uFloat32Complex,
     
    310310                                  },
    311311                                  {
    312                 /*   _FH*/     BT uFloat16Complex,     BT uFloat16Complex,     BT uFloat16Complex,     BT uFloat16Complex,     BT uFloat16Complex,     BT uFloat16Complex,
     312                /*   _FH */     BT uFloat16Complex,     BT uFloat16Complex,     BT uFloat16Complex,     BT uFloat16Complex,     BT uFloat16Complex,     BT uFloat16Complex,
    313313                                       BT uFloat16Complex,     BT uFloat16Complex,     BT uFloat16Complex,     BT uFloat16Complex,     BT uFloat16Complex,     BT uFloat16Complex,
    314314                                       BT uFloat16Complex,     BT uFloat16Complex,     BT uFloat16Complex,     BT uFloat16Complex,     BT uFloat32Complex,     BT uFloat32Complex,
     
    318318                                  },
    319319                                  {
    320                 /*    _F*/            BT uFloat32,            BT uFloat32,            BT uFloat32,            BT uFloat32,            BT uFloat32,            BT uFloat32,
     320                /*    _F */            BT uFloat32,            BT uFloat32,            BT uFloat32,            BT uFloat32,            BT uFloat32,            BT uFloat32,
    321321                                              BT uFloat32,            BT uFloat32,            BT uFloat32,            BT uFloat32,            BT uFloat32,            BT uFloat32,
    322322                                              BT uFloat32,            BT uFloat32,            BT uFloat32,     BT uFloat32Complex,            BT uFloat32,     BT uFloat32Complex,
     
    326326                                  },
    327327                                  {
    328                 /*   _FC*/     BT uFloat32Complex,     BT uFloat32Complex,     BT uFloat32Complex,     BT uFloat32Complex,     BT uFloat32Complex,     BT uFloat32Complex,
     328                /*   _FC */     BT uFloat32Complex,     BT uFloat32Complex,     BT uFloat32Complex,     BT uFloat32Complex,     BT uFloat32Complex,     BT uFloat32Complex,
    329329                                       BT uFloat32Complex,     BT uFloat32Complex,     BT uFloat32Complex,     BT uFloat32Complex,     BT uFloat32Complex,     BT uFloat32Complex,
    330330                                       BT uFloat32Complex,     BT uFloat32Complex,     BT uFloat32Complex,     BT uFloat32Complex,     BT uFloat32Complex,     BT uFloat32Complex,
     
    334334                                  },
    335335                                  {
    336                 /*     F*/               BT Float,               BT Float,               BT Float,               BT Float,               BT Float,               BT Float,
     336                /*     F */               BT Float,               BT Float,               BT Float,               BT Float,               BT Float,               BT Float,
    337337                                                 BT Float,               BT Float,               BT Float,               BT Float,               BT Float,               BT Float,
    338338                                                 BT Float,               BT Float,               BT Float,        BT FloatComplex,               BT Float,        BT FloatComplex,
     
    342342                                  },
    343343                                  {
    344                 /*    FC*/        BT FloatComplex,        BT FloatComplex,        BT FloatComplex,        BT FloatComplex,        BT FloatComplex,        BT FloatComplex,
     344                /*    FC */        BT FloatComplex,        BT FloatComplex,        BT FloatComplex,        BT FloatComplex,        BT FloatComplex,        BT FloatComplex,
    345345                                          BT FloatComplex,        BT FloatComplex,        BT FloatComplex,        BT FloatComplex,        BT FloatComplex,        BT FloatComplex,
    346346                                          BT FloatComplex,        BT FloatComplex,        BT FloatComplex,        BT FloatComplex,        BT FloatComplex,        BT FloatComplex,
     
    350350                                  },
    351351                                  {
    352                 /*   _FX*/           BT uFloat32x,           BT uFloat32x,           BT uFloat32x,           BT uFloat32x,           BT uFloat32x,           BT uFloat32x,
     352                /*   _FX */           BT uFloat32x,           BT uFloat32x,           BT uFloat32x,           BT uFloat32x,           BT uFloat32x,           BT uFloat32x,
    353353                                             BT uFloat32x,           BT uFloat32x,           BT uFloat32x,           BT uFloat32x,           BT uFloat32x,           BT uFloat32x,
    354354                                             BT uFloat32x,           BT uFloat32x,           BT uFloat32x,    BT uFloat32xComplex,           BT uFloat32x,    BT uFloat32xComplex,
     
    358358                                  },
    359359                                  {
    360                 /*  _FXC*/    BT uFloat32xComplex,    BT uFloat32xComplex,    BT uFloat32xComplex,    BT uFloat32xComplex,    BT uFloat32xComplex,    BT uFloat32xComplex,
     360                /*  _FXC */    BT uFloat32xComplex,    BT uFloat32xComplex,    BT uFloat32xComplex,    BT uFloat32xComplex,    BT uFloat32xComplex,    BT uFloat32xComplex,
    361361                                      BT uFloat32xComplex,    BT uFloat32xComplex,    BT uFloat32xComplex,    BT uFloat32xComplex,    BT uFloat32xComplex,    BT uFloat32xComplex,
    362362                                      BT uFloat32xComplex,    BT uFloat32xComplex,    BT uFloat32xComplex,    BT uFloat32xComplex,    BT uFloat32xComplex,    BT uFloat32xComplex,
     
    366366                                  },
    367367                                  {
    368                 /*    FD*/            BT uFloat64,            BT uFloat64,            BT uFloat64,            BT uFloat64,            BT uFloat64,            BT uFloat64,
     368                /*    FD */            BT uFloat64,            BT uFloat64,            BT uFloat64,            BT uFloat64,            BT uFloat64,            BT uFloat64,
    369369                                              BT uFloat64,            BT uFloat64,            BT uFloat64,            BT uFloat64,            BT uFloat64,            BT uFloat64,
    370370                                              BT uFloat64,            BT uFloat64,            BT uFloat64,     BT uFloat64Complex,            BT uFloat64,     BT uFloat64Complex,
     
    374374                                  },
    375375                                  {
    376                 /*  _FDC*/     BT uFloat64Complex,     BT uFloat64Complex,     BT uFloat64Complex,     BT uFloat64Complex,     BT uFloat64Complex,     BT uFloat64Complex,
     376                /*  _FDC */     BT uFloat64Complex,     BT uFloat64Complex,     BT uFloat64Complex,     BT uFloat64Complex,     BT uFloat64Complex,     BT uFloat64Complex,
    377377                                       BT uFloat64Complex,     BT uFloat64Complex,     BT uFloat64Complex,     BT uFloat64Complex,     BT uFloat64Complex,     BT uFloat64Complex,
    378378                                       BT uFloat64Complex,     BT uFloat64Complex,     BT uFloat64Complex,     BT uFloat64Complex,     BT uFloat64Complex,     BT uFloat64Complex,
     
    382382                                  },
    383383                                  {
    384                 /*     D*/              BT Double,              BT Double,              BT Double,              BT Double,              BT Double,              BT Double,
     384                /*     D */              BT Double,              BT Double,              BT Double,              BT Double,              BT Double,              BT Double,
    385385                                                BT Double,              BT Double,              BT Double,              BT Double,              BT Double,              BT Double,
    386386                                                BT Double,              BT Double,              BT Double,       BT DoubleComplex,              BT Double,       BT DoubleComplex,
     
    390390                                  },
    391391                                  {
    392                 /*    DC*/       BT DoubleComplex,       BT DoubleComplex,       BT DoubleComplex,       BT DoubleComplex,       BT DoubleComplex,       BT DoubleComplex,
     392                /*    DC */       BT DoubleComplex,       BT DoubleComplex,       BT DoubleComplex,       BT DoubleComplex,       BT DoubleComplex,       BT DoubleComplex,
    393393                                         BT DoubleComplex,       BT DoubleComplex,       BT DoubleComplex,       BT DoubleComplex,       BT DoubleComplex,       BT DoubleComplex,
    394394                                         BT DoubleComplex,       BT DoubleComplex,       BT DoubleComplex,       BT DoubleComplex,       BT DoubleComplex,       BT DoubleComplex,
     
    398398                                  },
    399399                                  {
    400                 /*  F80X*/           BT uFloat64x,           BT uFloat64x,           BT uFloat64x,           BT uFloat64x,           BT uFloat64x,           BT uFloat64x,
     400                /*  F80X */           BT uFloat64x,           BT uFloat64x,           BT uFloat64x,           BT uFloat64x,           BT uFloat64x,           BT uFloat64x,
    401401                                             BT uFloat64x,           BT uFloat64x,           BT uFloat64x,           BT uFloat64x,           BT uFloat64x,           BT uFloat64x,
    402402                                             BT uFloat64x,           BT uFloat64x,           BT uFloat64x,    BT uFloat64xComplex,           BT uFloat64x,    BT uFloat64xComplex,
     
    406406                                  },
    407407                                  {
    408                 /* _FDXC*/    BT uFloat64xComplex,    BT uFloat64xComplex,    BT uFloat64xComplex,    BT uFloat64xComplex,    BT uFloat64xComplex,    BT uFloat64xComplex,
     408                /* _FDXC */    BT uFloat64xComplex,    BT uFloat64xComplex,    BT uFloat64xComplex,    BT uFloat64xComplex,    BT uFloat64xComplex,    BT uFloat64xComplex,
    409409                                      BT uFloat64xComplex,    BT uFloat64xComplex,    BT uFloat64xComplex,    BT uFloat64xComplex,    BT uFloat64xComplex,    BT uFloat64xComplex,
    410410                                      BT uFloat64xComplex,    BT uFloat64xComplex,    BT uFloat64xComplex,    BT uFloat64xComplex,    BT uFloat64xComplex,    BT uFloat64xComplex,
     
    422422                                  },
    423423                                  {
    424                 /*   _FB*/           BT uFloat128,           BT uFloat128,           BT uFloat128,           BT uFloat128,           BT uFloat128,           BT uFloat128,
     424                /*   _FB */           BT uFloat128,           BT uFloat128,           BT uFloat128,           BT uFloat128,           BT uFloat128,           BT uFloat128,
    425425                                             BT uFloat128,           BT uFloat128,           BT uFloat128,           BT uFloat128,           BT uFloat128,           BT uFloat128,
    426426                                             BT uFloat128,           BT uFloat128,           BT uFloat128,    BT uFloat128Complex,           BT uFloat128,    BT uFloat128Complex,
     
    430430                                  },
    431431                                  {
    432                 /* _FLDC*/    BT uFloat128Complex,    BT uFloat128Complex,    BT uFloat128Complex,    BT uFloat128Complex,    BT uFloat128Complex,    BT uFloat128Complex,
     432                /* _FLDC */    BT uFloat128Complex,    BT uFloat128Complex,    BT uFloat128Complex,    BT uFloat128Complex,    BT uFloat128Complex,    BT uFloat128Complex,
    433433                                      BT uFloat128Complex,    BT uFloat128Complex,    BT uFloat128Complex,    BT uFloat128Complex,    BT uFloat128Complex,    BT uFloat128Complex,
    434434                                      BT uFloat128Complex,    BT uFloat128Complex,    BT uFloat128Complex,    BT uFloat128Complex,    BT uFloat128Complex,    BT uFloat128Complex,
     
    438438                                  },
    439439                                  {
    440                 /*    FB*/          BT uuFloat128,          BT uuFloat128,          BT uuFloat128,          BT uuFloat128,          BT uuFloat128,          BT uuFloat128,
     440                /*    FB */          BT uuFloat128,          BT uuFloat128,          BT uuFloat128,          BT uuFloat128,          BT uuFloat128,          BT uuFloat128,
    441441                                            BT uuFloat128,          BT uuFloat128,          BT uuFloat128,          BT uuFloat128,          BT uuFloat128,          BT uuFloat128,
    442442                                            BT uuFloat128,          BT uuFloat128,          BT uuFloat128,    BT uFloat128Complex,          BT uuFloat128,    BT uFloat128Complex,
     
    446446                                  },
    447447                                  {
    448                 /*    LD*/          BT LongDouble,          BT LongDouble,          BT LongDouble,          BT LongDouble,          BT LongDouble,          BT LongDouble,
     448                /*    LD */          BT LongDouble,          BT LongDouble,          BT LongDouble,          BT LongDouble,          BT LongDouble,          BT LongDouble,
    449449                                            BT LongDouble,          BT LongDouble,          BT LongDouble,          BT LongDouble,          BT LongDouble,          BT LongDouble,
    450450                                            BT LongDouble,          BT LongDouble,          BT LongDouble,   BT LongDoubleComplex,          BT LongDouble,   BT LongDoubleComplex,
     
    454454                                  },
    455455                                  {
    456                 /*   LDC*/   BT LongDoubleComplex,   BT LongDoubleComplex,   BT LongDoubleComplex,   BT LongDoubleComplex,   BT LongDoubleComplex,   BT LongDoubleComplex,
     456                /*   LDC */   BT LongDoubleComplex,   BT LongDoubleComplex,   BT LongDoubleComplex,   BT LongDoubleComplex,   BT LongDoubleComplex,   BT LongDoubleComplex,
    457457                                     BT LongDoubleComplex,   BT LongDoubleComplex,   BT LongDoubleComplex,   BT LongDoubleComplex,   BT LongDoubleComplex,   BT LongDoubleComplex,
    458458                                     BT LongDoubleComplex,   BT LongDoubleComplex,   BT LongDoubleComplex,   BT LongDoubleComplex,   BT LongDoubleComplex,   BT LongDoubleComplex,
     
    462462                                  },
    463463                                  {
    464                 /*  _FBX*/          BT uFloat128x,          BT uFloat128x,          BT uFloat128x,          BT uFloat128x,          BT uFloat128x,          BT uFloat128x,
     464                /*  _FBX */          BT uFloat128x,          BT uFloat128x,          BT uFloat128x,          BT uFloat128x,          BT uFloat128x,          BT uFloat128x,
    465465                                            BT uFloat128x,          BT uFloat128x,          BT uFloat128x,          BT uFloat128x,          BT uFloat128x,          BT uFloat128x,
    466466                                            BT uFloat128x,          BT uFloat128x,          BT uFloat128x,   BT uFloat128xComplex,          BT uFloat128x,   BT uFloat128xComplex,
     
    470470                                  },
    471471                                  {
    472                 /*_FLDXC*/   BT uFloat128xComplex,   BT uFloat128xComplex,   BT uFloat128xComplex,   BT uFloat128xComplex,   BT uFloat128xComplex,   BT uFloat128xComplex,
     472                /* _FLDXC */   BT uFloat128xComplex,   BT uFloat128xComplex,   BT uFloat128xComplex,   BT uFloat128xComplex,   BT uFloat128xComplex,   BT uFloat128xComplex,
    473473                                     BT uFloat128xComplex,   BT uFloat128xComplex,   BT uFloat128xComplex,   BT uFloat128xComplex,   BT uFloat128xComplex,   BT uFloat128xComplex,
    474474                                     BT uFloat128xComplex,   BT uFloat128xComplex,   BT uFloat128xComplex,   BT uFloat128xComplex,   BT uFloat128xComplex,   BT uFloat128xComplex,
     
    481481        // GENERATED END
    482482        static_assert(
    483                 sizeof(commonTypes)/sizeof(commonTypes[0][0]) == BasicType::NUMBER_OF_BASIC_TYPES*BasicType::NUMBER_OF_BASIC_TYPES,
     483                sizeof(commonTypes)/sizeof(commonTypes[0][0]) == BasicType::NUMBER_OF_BASIC_TYPES * BasicType::NUMBER_OF_BASIC_TYPES,
    484484                "Each basic type kind should have a corresponding row in the combined type matrix"
    485485        );
    486486
    487         CommonType_old::CommonType_old( Type *type2, bool widenFirst, bool widenSecond, const SymTab::Indexer &indexer, TypeEnvironment &env, const OpenVarSet &openVars )
     487        CommonType_old::CommonType_old( Type * type2, bool widenFirst, bool widenSecond, const SymTab::Indexer &indexer, TypeEnvironment &env, const OpenVarSet &openVars )
    488488                : result( 0 ), type2( type2 ), widenFirst( widenFirst ), widenSecond( widenSecond ), indexer( indexer ), env( env ), openVars( openVars ) {
    489489        }
     
    491491        void CommonType_old::postvisit( VoidType * ) {}
    492492
    493         void CommonType_old::postvisit( BasicType *basicType ) {
    494                 if ( BasicType *otherBasic = dynamic_cast< BasicType* >( type2 ) ) {
     493        void CommonType_old::postvisit( BasicType * basicType ) {
     494                if ( BasicType * otherBasic = dynamic_cast< BasicType * >( type2 ) ) {
    495495                        BasicType::Kind newType = commonTypes[ basicType->get_kind() ][ otherBasic->get_kind() ];
    496                         if ( ( ( newType == basicType->get_kind() && basicType->get_qualifiers() >= otherBasic->get_qualifiers() ) || widenFirst ) && ( ( newType == otherBasic->get_kind() && basicType->get_qualifiers() <= otherBasic->get_qualifiers() ) || widenSecond ) ) {
    497                                 result = new BasicType( basicType->get_qualifiers() | otherBasic->get_qualifiers(), newType );
     496                        if ( ( ( newType == basicType->get_kind() && basicType->tq >= otherBasic->tq ) || widenFirst ) && ( ( newType == otherBasic->get_kind() && basicType->tq <= otherBasic->tq ) || widenSecond ) ) {
     497                                result = new BasicType( basicType->tq | otherBasic->tq, newType );
    498498                        } // if
    499                 } else if ( dynamic_cast< EnumInstType * > ( type2 ) || dynamic_cast< ZeroType* >( type2 ) || dynamic_cast< OneType* >( type2 ) ) {
     499                } else if ( dynamic_cast< EnumInstType * > ( type2 ) || dynamic_cast< ZeroType * >( type2 ) || dynamic_cast< OneType * >( type2 ) ) {
    500500                        // use signed int in lieu of the enum/zero/one type
    501501                        BasicType::Kind newType = commonTypes[ basicType->get_kind() ][ BasicType::SignedInt ];
    502                         if ( ( ( newType == basicType->get_kind() && basicType->get_qualifiers() >= type2->get_qualifiers() ) || widenFirst ) && ( ( newType != basicType->get_kind() && basicType->get_qualifiers() <= type2->get_qualifiers() ) || widenSecond ) ) {
    503                                 result = new BasicType( basicType->get_qualifiers() | type2->get_qualifiers(), newType );
     502                        if ( ( ( newType == basicType->get_kind() && basicType->tq >= type2->tq ) || widenFirst ) && ( ( newType != basicType->get_kind() && basicType->tq <= type2->tq ) || widenSecond ) ) {
     503                                result = new BasicType( basicType->tq | type2->tq, newType );
    504504                        } // if
    505505                } // if
     
    507507
    508508        template< typename Pointer >
    509         void CommonType_old::getCommonWithVoidPointer( Pointer* voidPointer, Pointer* otherPointer ) {
    510                 if ( TypeInstType* var = dynamic_cast< TypeInstType* >( otherPointer->get_base() ) ) {
     509        void CommonType_old::getCommonWithVoidPointer( Pointer * voidPointer, Pointer * otherPointer ) {
     510                if ( TypeInstType * var = dynamic_cast< TypeInstType * >( otherPointer->get_base() ) ) {
    511511                        OpenVarSet::const_iterator entry = openVars.find( var->get_name() );
    512512                        if ( entry != openVars.end() ) {
     
    517517                }
    518518                result = voidPointer->clone();
    519                 result->get_qualifiers() |= otherPointer->get_qualifiers();
    520         }
    521 
    522         void CommonType_old::postvisit( PointerType *pointerType ) {
    523                 if ( PointerType *otherPointer = dynamic_cast< PointerType* >( type2 ) ) {
     519                result->tq |= otherPointer->tq;
     520        }
     521
     522        void CommonType_old::postvisit( PointerType * pointerType ) {
     523                if ( PointerType * otherPointer = dynamic_cast< PointerType * >( type2 ) ) {
    524524                        // std::cerr << "commonType: two pointers: " << pointerType << " / " << otherPointer << std::endl;
    525                         if ( widenFirst && dynamic_cast< VoidType* >( otherPointer->get_base() ) && ! isFtype(pointerType->get_base()) ) {
     525                        if ( widenFirst && dynamic_cast< VoidType * >( otherPointer->get_base() ) && ! isFtype(pointerType->get_base()) ) {
    526526                                getCommonWithVoidPointer( otherPointer, pointerType );
    527                         } else if ( widenSecond && dynamic_cast< VoidType* >( pointerType->get_base() ) && ! isFtype(otherPointer->get_base()) ) {
     527                        } else if ( widenSecond && dynamic_cast< VoidType * >( pointerType->get_base() ) && ! isFtype(otherPointer->get_base()) ) {
    528528                                getCommonWithVoidPointer( pointerType, otherPointer );
    529                         } else if ( ( pointerType->get_base()->get_qualifiers() >= otherPointer->get_base()->get_qualifiers() || widenFirst )
    530                                            && ( pointerType->get_base()->get_qualifiers() <= otherPointer->get_base()->get_qualifiers() || widenSecond ) ) {
     529                        } else if ( ( pointerType->get_base()->tq >= otherPointer->get_base()->tq || widenFirst )
     530                                           && ( pointerType->get_base()->tq <= otherPointer->get_base()->tq || widenSecond ) ) {
    531531                                // std::cerr << "middle case" << std::endl;
    532                                 Type::Qualifiers tq1 = pointerType->get_base()->get_qualifiers(), tq2 = otherPointer->get_base()->get_qualifiers();
    533                                 pointerType->get_base()->get_qualifiers() = Type::Qualifiers();
    534                                 otherPointer->get_base()->get_qualifiers() = Type::Qualifiers();
     532                                Type::Qualifiers tq1 = pointerType->get_base()->tq, tq2 = otherPointer->get_base()->tq;
     533                                pointerType->get_base()->tq = Type::Qualifiers();
     534                                otherPointer->get_base()->tq = Type::Qualifiers();
    535535                                AssertionSet have, need;
    536536                                OpenVarSet newOpen( openVars );
     
    542542                                                result = otherPointer->clone();
    543543                                        } // if
    544                                         strict_dynamic_cast<PointerType*>(result)->base->get_qualifiers() = tq1 | tq2;
     544                                        strict_dynamic_cast<PointerType *>(result)->base->tq = tq1 | tq2;
    545545                                } else {
    546546                                        /// std::cerr << "place for ptr-to-type" << std::endl;
    547547                                } // if
    548                                 pointerType->get_base()->get_qualifiers() = tq1;
    549                                 otherPointer->get_base()->get_qualifiers() = tq2;
     548                                pointerType->get_base()->tq = tq1;
     549                                otherPointer->get_base()->tq = tq2;
    550550                        } // if
    551                 } else if ( widenSecond && dynamic_cast< ZeroType* >( type2 ) ) {
     551                } else if ( widenSecond && dynamic_cast< ZeroType * >( type2 ) ) {
    552552                        result = pointerType->clone();
    553                         result->get_qualifiers() |= type2->get_qualifiers();
     553                        result->tq |= type2->tq;
    554554                } // if
    555555        }
     
    557557        void CommonType_old::postvisit( ArrayType * ) {}
    558558
    559         void CommonType_old::postvisit( ReferenceType *refType ) {
    560                 if ( ReferenceType *otherRef = dynamic_cast< ReferenceType* >( type2 ) ) {
     559        void CommonType_old::postvisit( ReferenceType * refType ) {
     560                if ( ReferenceType * otherRef = dynamic_cast< ReferenceType * >( type2 ) ) {
    561561                        // std::cerr << "commonType: both references: " << refType << " / " << otherRef << std::endl;
    562                         // std::cerr << ( refType->get_base()->get_qualifiers() >= otherRef->get_base()->get_qualifiers() || widenFirst ) << (refType->get_base()->get_qualifiers() <= otherRef->get_base()->get_qualifiers() || widenSecond) << std::endl;
    563                         if ( widenFirst && dynamic_cast< VoidType* >( otherRef->get_base() ) && ! isFtype(refType->get_base()) ) {
     562                        // std::cerr << ( refType->get_base()->tq >= otherRef->get_base()->tq || widenFirst ) << (refType->get_base()->tq <= otherRef->get_base()->tq || widenSecond) << std::endl;
     563                        if ( widenFirst && dynamic_cast< VoidType * >( otherRef->get_base() ) && ! isFtype(refType->get_base()) ) {
    564564                                getCommonWithVoidPointer( otherRef, refType );
    565                         } else if ( widenSecond && dynamic_cast< VoidType* >( refType->get_base() ) && ! isFtype(otherRef->get_base()) ) {
     565                        } else if ( widenSecond && dynamic_cast< VoidType * >( refType->get_base() ) && ! isFtype(otherRef->get_base()) ) {
    566566                                getCommonWithVoidPointer( refType, otherRef );
    567                         } else if ( ( refType->get_base()->get_qualifiers() >= otherRef->get_base()->get_qualifiers() || widenFirst )
    568                                            && ( refType->get_base()->get_qualifiers() <= otherRef->get_base()->get_qualifiers() || widenSecond ) ) {
     567                        } else if ( ( refType->get_base()->tq >= otherRef->get_base()->tq || widenFirst )
     568                                           && ( refType->get_base()->tq <= otherRef->get_base()->tq || widenSecond ) ) {
    569569                                // std::cerr << "middle case" << std::endl;
    570                                 Type::Qualifiers tq1 = refType->get_base()->get_qualifiers(), tq2 = otherRef->get_base()->get_qualifiers();
    571                                 refType->get_base()->get_qualifiers() = Type::Qualifiers();
    572                                 otherRef->get_base()->get_qualifiers() = Type::Qualifiers();
     570                                Type::Qualifiers tq1 = refType->get_base()->tq, tq2 = otherRef->get_base()->tq;
     571                                refType->get_base()->tq = Type::Qualifiers();
     572                                otherRef->get_base()->tq = Type::Qualifiers();
    573573                                AssertionSet have, need;
    574574                                OpenVarSet newOpen( openVars );
     
    579579                                                result = otherRef->clone();
    580580                                        } // if
    581                                         strict_dynamic_cast<ReferenceType*>(result)->base->get_qualifiers() = tq1 | tq2;
     581                                        strict_dynamic_cast<ReferenceType *>(result)->base->tq = tq1 | tq2;
    582582                                } else {
    583583                                        /// std::cerr << "place for ptr-to-type" << std::endl;
    584584                                } // if
    585                                 refType->get_base()->get_qualifiers() = tq1;
    586                                 otherRef->get_base()->get_qualifiers() = tq2;
     585                                refType->get_base()->tq = tq1;
     586                                otherRef->get_base()->tq = tq2;
    587587                        } // if
    588                 } else if ( widenSecond && dynamic_cast< ZeroType* >( type2 ) ) {
     588                } else if ( widenSecond && dynamic_cast< ZeroType * >( type2 ) ) {
    589589                        result = refType->clone();
    590                         result->get_qualifiers() |= type2->get_qualifiers();
     590                        result->tq |= type2->tq;
    591591                } // if
    592592        }
     
    596596        void CommonType_old::postvisit( UnionInstType * ) {}
    597597
    598         void CommonType_old::postvisit( EnumInstType *enumInstType ) {
    599                 if ( dynamic_cast< BasicType * >( type2 ) || dynamic_cast< ZeroType* >( type2 ) || dynamic_cast< OneType* >( type2 ) ) {
     598        void CommonType_old::postvisit( EnumInstType * enumInstType ) {
     599                if ( dynamic_cast< BasicType * >( type2 ) || dynamic_cast< ZeroType * >( type2 ) || dynamic_cast< OneType * >( type2 ) ) {
    600600                        // reuse BasicType, EnumInstType code by swapping type2 with enumInstType
    601601                        result = commonType( type2, enumInstType, widenSecond, widenFirst, indexer, env, openVars );
     
    606606        }
    607607
    608         void CommonType_old::postvisit( TypeInstType *inst ) {
     608        void CommonType_old::postvisit( TypeInstType * inst ) {
    609609                if ( widenFirst ) {
    610                         NamedTypeDecl *nt = indexer.lookupType( inst->get_name() );
     610                        const NamedTypeDecl * nt = indexer.lookupType( inst->get_name() );
    611611                        if ( nt ) {
    612                                 TypeDecl *type = strict_dynamic_cast< TypeDecl* >( nt );
     612                                const TypeDecl * type = strict_dynamic_cast< const TypeDecl * >( nt );
    613613                                if ( type->get_base() ) {
    614                                         Type::Qualifiers tq1 = inst->get_qualifiers(), tq2 = type2->get_qualifiers();
     614                                        Type::Qualifiers tq1 = inst->tq, tq2 = type2->tq;
    615615                                        AssertionSet have, need;
    616616                                        OpenVarSet newOpen( openVars );
    617                                         type2->get_qualifiers() = Type::Qualifiers();
    618                                         type->get_base()->get_qualifiers() = tq1;
     617                                        type2->tq = Type::Qualifiers();
     618                                        type->get_base()->tq = tq1;
    619619                                        if ( unifyExact( type->get_base(), type2, env, have, need, newOpen, indexer ) ) {
    620620                                                result = type2->clone();
    621                                                 result->get_qualifiers() = tq1 | tq2;
     621                                                result->tq = tq1 | tq2;
    622622                                        } // if
    623                                         type2->get_qualifiers() = tq2;
    624                                         type->get_base()->get_qualifiers() = Type::Qualifiers();
     623                                        type2->tq = tq2;
     624                                        type->get_base()->tq = Type::Qualifiers();
    625625                                } // if
    626626                        } // if
     
    631631        void CommonType_old::postvisit( VarArgsType * ) {}
    632632
    633         void CommonType_old::postvisit( ZeroType *zeroType ) {
     633        void CommonType_old::postvisit( ZeroType * zeroType ) {
    634634                if ( widenFirst ) {
    635                         if ( dynamic_cast< BasicType* >( type2 ) || dynamic_cast< PointerType* >( type2 ) || dynamic_cast< EnumInstType* >( type2 ) ) {
    636                                 if ( widenSecond || zeroType->get_qualifiers() <= type2->get_qualifiers() ) {
     635                        if ( dynamic_cast< BasicType * >( type2 ) || dynamic_cast< PointerType * >( type2 ) || dynamic_cast< EnumInstType * >( type2 ) ) {
     636                                if ( widenSecond || zeroType->tq <= type2->tq ) {
    637637                                        result = type2->clone();
    638                                         result->get_qualifiers() |= zeroType->get_qualifiers();
    639                                 }
    640                         } else if ( widenSecond && dynamic_cast< OneType* >( type2 ) ) {
    641                                 result = new BasicType( zeroType->get_qualifiers(), BasicType::SignedInt );
    642                                 result->get_qualifiers() |= type2->get_qualifiers();
    643                         }
    644                 }
    645         }
    646 
    647         void CommonType_old::postvisit( OneType *oneType ) {
     638                                        result->tq |= zeroType->tq;
     639                                }
     640                        } else if ( widenSecond && dynamic_cast< OneType * >( type2 ) ) {
     641                                result = new BasicType( zeroType->tq, BasicType::SignedInt );
     642                                result->tq |= type2->tq;
     643                        }
     644                }
     645        }
     646
     647        void CommonType_old::postvisit( OneType * oneType ) {
    648648                if ( widenFirst ) {
    649                         if ( dynamic_cast< BasicType* >( type2 ) || dynamic_cast< EnumInstType* >( type2 ) ) {
    650                                 if ( widenSecond || oneType->get_qualifiers() <= type2->get_qualifiers() ) {
     649                        if ( dynamic_cast< BasicType * >( type2 ) || dynamic_cast< EnumInstType * >( type2 ) ) {
     650                                if ( widenSecond || oneType->tq <= type2->tq ) {
    651651                                        result = type2->clone();
    652                                         result->get_qualifiers() |= oneType->get_qualifiers();
    653                                 }
    654                         } else if ( widenSecond && dynamic_cast< ZeroType* >( type2 ) ) {
    655                                 result = new BasicType( oneType->get_qualifiers(), BasicType::SignedInt );
    656                                 result->get_qualifiers() |= type2->get_qualifiers();
     652                                        result->tq |= oneType->tq;
     653                                }
     654                        } else if ( widenSecond && dynamic_cast< ZeroType * >( type2 ) ) {
     655                                result = new BasicType( oneType->tq, BasicType::SignedInt );
     656                                result->tq |= type2->tq;
    657657                        }
    658658                }
     
    668668                ast::ptr< ast::Type > result;
    669669
    670                 CommonType_new( 
    671                         const ast::Type * t2, WidenMode w, const ast::SymbolTable & st, 
     670                CommonType_new(
     671                        const ast::Type * t2, WidenMode w, const ast::SymbolTable & st,
    672672                        ast::TypeEnvironment & env, const ast::OpenVarSet & o )
    673673                : type2( t2 ), widen( w ), symtab( st ), tenv( env ), open( o ), result() {}
     
    681681                                #warning remove casts when `commonTypes` moved to new AST
    682682                                ast::BasicType::Kind kind = (ast::BasicType::Kind)(int)commonTypes[ (BasicType::Kind)(int)basic->kind ][ (BasicType::Kind)(int)basic2->kind ];
    683                                 if ( 
    684                                         ( ( kind == basic->kind && basic->qualifiers >= basic2->qualifiers ) 
    685                                                 || widen.first ) 
    686                                         && ( ( kind == basic2->kind && basic->qualifiers <= basic2->qualifiers ) 
    687                                                 || widen.second ) 
     683                                if (
     684                                        ( ( kind == basic->kind && basic->qualifiers >= basic2->qualifiers )
     685                                                || widen.first )
     686                                        && ( ( kind == basic2->kind && basic->qualifiers <= basic2->qualifiers )
     687                                                || widen.second )
    688688                                ) {
    689689                                        result = new ast::BasicType{ kind, basic->qualifiers | basic2->qualifiers };
    690690                                }
    691                         } else if ( 
    692                                 dynamic_cast< const ast::EnumInstType * >( type2 ) 
     691                        } else if (
     692                                dynamic_cast< const ast::EnumInstType * >( type2 )
    693693                                || dynamic_cast< const ast::ZeroType * >( type2 )
    694694                                || dynamic_cast< const ast::OneType * >( type2 )
     
    696696                                #warning remove casts when `commonTypes` moved to new AST
    697697                                ast::BasicType::Kind kind = (ast::BasicType::Kind)(int)commonTypes[ (BasicType::Kind)(int)basic->kind ][ (BasicType::Kind)(int)ast::BasicType::SignedInt ];
    698                                 if ( 
    699                                         ( ( kind == basic->kind && basic->qualifiers >= type2->qualifiers ) 
    700                                                 || widen.first ) 
    701                                         && ( ( kind != basic->kind && basic->qualifiers <= type2->qualifiers ) 
    702                                                 || widen.second ) 
     698                                if (
     699                                        ( ( kind == basic->kind && basic->qualifiers >= type2->qualifiers )
     700                                                || widen.first )
     701                                        && ( ( kind != basic->kind && basic->qualifiers <= type2->qualifiers )
     702                                                || widen.second )
    703703                                ) {
    704704                                        result = new ast::BasicType{ kind, basic->qualifiers | type2->qualifiers };
     
    715715                                if ( entry != open.end() ) {
    716716                                        ast::AssertionSet need, have;
    717                                         if ( ! tenv.bindVar( 
    718                                                 var, voidPtr->base, entry->second, need, have, open, widen, symtab ) 
     717                                        if ( ! tenv.bindVar(
     718                                                var, voidPtr->base, entry->second, need, have, open, widen, symtab )
    719719                                        ) return;
    720720                                }
     
    727727                void postvisit( const ast::PointerType * pointer ) {
    728728                        if ( auto pointer2 = dynamic_cast< const ast::PointerType * >( type2 ) ) {
    729                                 if ( 
    730                                         widen.first 
    731                                         && pointer2->base.as< ast::VoidType >() 
    732                                         && ! ast::isFtype( pointer->base ) 
     729                                if (
     730                                        widen.first
     731                                        && pointer2->base.as< ast::VoidType >()
     732                                        && ! ast::isFtype( pointer->base )
    733733                                ) {
    734734                                        getCommonWithVoidPointer( pointer2, pointer );
    735                                 } else if ( 
    736                                         widen.second 
    737                                         && pointer->base.as< ast::VoidType >() 
    738                                         && ! ast::isFtype( pointer2->base ) 
     735                                } else if (
     736                                        widen.second
     737                                        && pointer->base.as< ast::VoidType >()
     738                                        && ! ast::isFtype( pointer2->base )
    739739                                ) {
    740740                                        getCommonWithVoidPointer( pointer, pointer2 );
     
    746746                                        ast::CV::Qualifiers q2 = pointer2->base->qualifiers;
    747747
    748                                         // force t{1,2} to be cloned if their qualifiers must be stripped, so that 
     748                                        // force t{1,2} to be cloned if their qualifiers must be stripped, so that
    749749                                        // pointer{,2}->base are unchanged
    750750                                        ast::ptr< ast::Type > t1{ pointer->base }, t2{ pointer2->base };
    751751                                        reset_qualifiers( t1 );
    752752                                        reset_qualifiers( t2 );
    753                                        
     753
    754754                                        ast::AssertionSet have, need;
    755755                                        ast::OpenVarSet newOpen{ open };
     
    758758                                                if ( q1.val != q2.val ) {
    759759                                                        // reset result->base->qualifiers to be union of two base qualifiers
    760                                                         strict_dynamic_cast< ast::PointerType * >( 
    761                                                                 result.get_and_mutate() 
     760                                                        strict_dynamic_cast< ast::PointerType * >(
     761                                                                result.get_and_mutate()
    762762                                                        )->base.get_and_mutate()->qualifiers = q1 | q2;
    763763                                                }
     
    775775                        if ( auto ref2 = dynamic_cast< const ast::ReferenceType * >( type2 ) ) {
    776776                                if (
    777                                         widen.first && ref2->base.as< ast::VoidType >() && ! ast::isFtype( ref->base ) 
     777                                        widen.first && ref2->base.as< ast::VoidType >() && ! ast::isFtype( ref->base )
    778778                                ) {
    779779                                        getCommonWithVoidPointer( ref2, ref );
    780                                 } else if ( 
    781                                         widen.second && ref->base.as< ast::VoidType>() && ! ast::isFtype( ref2->base ) 
     780                                } else if (
     781                                        widen.second && ref->base.as< ast::VoidType>() && ! ast::isFtype( ref2->base )
    782782                                ) {
    783783                                        getCommonWithVoidPointer( ref, ref2 );
     
    788788                                        ast::CV::Qualifiers q1 = ref->base->qualifiers, q2 = ref2->base->qualifiers;
    789789
    790                                         // force t{1,2} to be cloned if their qualifiers must be stripped, so that 
     790                                        // force t{1,2} to be cloned if their qualifiers must be stripped, so that
    791791                                        // ref{,2}->base are unchanged
    792792                                        ast::ptr< ast::Type > t1{ ref->base }, t2{ ref2->base };
     
    800800                                                if ( q1.val != q2.val ) {
    801801                                                        // reset result->base->qualifiers to be union of two base qualifiers
    802                                                         strict_dynamic_cast< ast::ReferenceType * >( 
    803                                                                 result.get_and_mutate() 
     802                                                        strict_dynamic_cast< ast::ReferenceType * >(
     803                                                                result.get_and_mutate()
    804804                                                        )->base.get_and_mutate()->qualifiers = q1 | q2;
    805805                                                }
     
    819819
    820820                void postvisit( const ast::EnumInstType * enumInst ) {
    821                         if ( 
    822                                 dynamic_cast< const ast::BasicType * >( type2 ) 
     821                        if (
     822                                dynamic_cast< const ast::BasicType * >( type2 )
    823823                                || dynamic_cast< const ast::ZeroType * >( type2 )
    824824                                || dynamic_cast< const ast::OneType * >( type2 )
     
    834834                        if ( ! widen.first ) return;
    835835                        if ( const ast::NamedTypeDecl * nt = symtab.lookupType( inst->name ) ) {
    836                                 if ( const ast::Type * base = 
    837                                                 strict_dynamic_cast< const ast::TypeDecl * >( nt )->base 
     836                                if ( const ast::Type * base =
     837                                                strict_dynamic_cast< const ast::TypeDecl * >( nt )->base
    838838                                ) {
    839839                                        ast::CV::Qualifiers q1 = inst->qualifiers, q2 = type2->qualifiers;
     
    860860                void postvisit( const ast::ZeroType * zero ) {
    861861                        if ( ! widen.first ) return;
    862                         if ( 
     862                        if (
    863863                                dynamic_cast< const ast::BasicType * >( type2 )
    864864                                || dynamic_cast< const ast::PointerType * >( type2 )
     
    870870                                }
    871871                        } else if ( widen.second && dynamic_cast< const ast::OneType * >( type2 ) ) {
    872                                 result = new ast::BasicType{ 
     872                                result = new ast::BasicType{
    873873                                        ast::BasicType::SignedInt, zero->qualifiers | type2->qualifiers };
    874874                        }
     
    877877                void postvisit( const ast::OneType * one ) {
    878878                        if ( ! widen.first ) return;
    879                         if ( 
     879                        if (
    880880                                dynamic_cast< const ast::BasicType * >( type2 )
    881881                                || dynamic_cast< const ast::EnumInstType * >( type2 )
     
    886886                                }
    887887                        } else if ( widen.second && dynamic_cast< const ast::ZeroType * >( type2 ) ) {
    888                                 result = new ast::BasicType{ 
     888                                result = new ast::BasicType{
    889889                                        ast::BasicType::SignedInt, one->qualifiers | type2->qualifiers };
    890890                        }
     
    894894
    895895        namespace {
    896                 ast::ptr< ast::Type > handleReference( 
    897                         const ast::ptr< ast::Type > & t1, const ast::ptr< ast::Type > & t2, WidenMode widen, 
    898                         const ast::SymbolTable & symtab, ast::TypeEnvironment & env, 
    899                         const ast::OpenVarSet & open 
     896                ast::ptr< ast::Type > handleReference(
     897                        const ast::ptr< ast::Type > & t1, const ast::ptr< ast::Type > & t2, WidenMode widen,
     898                        const ast::SymbolTable & symtab, ast::TypeEnvironment & env,
     899                        const ast::OpenVarSet & open
    900900                ) {
    901901                        ast::ptr<ast::Type> common;
     
    926926
    927927        ast::ptr< ast::Type > commonType(
    928                         const ast::ptr< ast::Type > & type1, const ast::ptr< ast::Type > & type2, 
    929                         WidenMode widen, const ast::SymbolTable & symtab, ast::TypeEnvironment & env, 
    930                         const ast::OpenVarSet & open 
     928                        const ast::ptr< ast::Type > & type1, const ast::ptr< ast::Type > & type2,
     929                        WidenMode widen, const ast::SymbolTable & symtab, ast::TypeEnvironment & env,
     930                        const ast::OpenVarSet & open
    931931        ) {
    932932                unsigned depth1 = type1->referenceDepth();
     
    940940                        const ast::ReferenceType * ref1 = type1.as< ast::ReferenceType >();
    941941                        const ast::ReferenceType * ref2 = type1.as< ast::ReferenceType >();
    942                        
     942
    943943                        if ( depth1 > depth2 ) {
    944944                                assert( ref1 );
     
    978978                                                ast::OpenVarSet newOpen{ open };
    979979
    980                                                 // force t{1,2} to be cloned if its qualifiers must be stripped, so that 
    981                                                 // type1 and type->base are left unchanged; calling convention forces 
     980                                                // force t{1,2} to be cloned if its qualifiers must be stripped, so that
     981                                                // type1 and type->base are left unchanged; calling convention forces
    982982                                                // {type1,type->base}->strong_ref >= 1
    983983                                                ast::ptr<ast::Type> t1{ type1 }, t2{ type->base };
    984984                                                reset_qualifiers( t1 );
    985985                                                reset_qualifiers( t2, q1 );
    986                                                
     986
    987987                                                if ( unifyExact( t1, t2, env, have, need, newOpen, noWiden(), symtab ) ) {
    988988                                                        result = t1;
  • src/ResolvExpr/ConversionCost.cc

    r302d84c2 rfce4e31  
    4646#endif
    4747
    48         Cost conversionCost( Type *src, Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env ) {
    49                 if ( TypeInstType *destAsTypeInst = dynamic_cast< TypeInstType* >( dest ) ) {
     48        Cost conversionCost( const Type * src, const Type * dest, const SymTab::Indexer &indexer, const TypeEnvironment &env ) {
     49                if ( const TypeInstType * destAsTypeInst = dynamic_cast< const TypeInstType * >( dest ) ) {
    5050                        PRINT( std::cerr << "type inst " << destAsTypeInst->name; )
    51                         if ( const EqvClass* eqvClass = env.lookup( destAsTypeInst->name ) ) {
     51                        if ( const EqvClass * eqvClass = env.lookup( destAsTypeInst->name ) ) {
    5252                                if ( eqvClass->type ) {
    5353                                        return conversionCost( src, eqvClass->type, indexer, env );
     
    5555                                        return Cost::infinity;
    5656                                }
    57                         } else if ( NamedTypeDecl *namedType = indexer.lookupType( destAsTypeInst->name ) ) {
     57                        } else if ( const NamedTypeDecl * namedType = indexer.lookupType( destAsTypeInst->name ) ) {
    5858                                PRINT( std::cerr << " found" << std::endl; )
    59                                 TypeDecl *type = dynamic_cast< TypeDecl* >( namedType );
     59                                const TypeDecl * type = dynamic_cast< const TypeDecl * >( namedType );
    6060                                // all typedefs should be gone by this point
    6161                                assert( type );
     
    7777                        PRINT( std::cerr << "compatible!" << std::endl; )
    7878                        return Cost::zero;
    79                 } else if ( dynamic_cast< VoidType* >( dest ) ) {
     79                } else if ( dynamic_cast< const VoidType * >( dest ) ) {
    8080                        return Cost::safe;
    81                 } else if ( ReferenceType * refType = dynamic_cast< ReferenceType * > ( dest ) ) {
     81                } else if ( const ReferenceType * refType = dynamic_cast< const ReferenceType * > ( dest ) ) {
    8282                        PRINT( std::cerr << "conversionCost: dest is reference" << std::endl; )
    83                         return convertToReferenceCost( src, refType, indexer, env, [](Type * t1, Type * t2, const SymTab::Indexer &, const TypeEnvironment & env ){
     83                        return convertToReferenceCost( src, refType, indexer, env, [](const Type * const t1, const Type * t2, const SymTab::Indexer &, const TypeEnvironment & env ){
    8484                                return ptrsAssignable( t1, t2, env );
    8585                        });
    8686                } else {
    87                         PassVisitor<ConversionCost> converter( 
    88                                 dest, indexer, env, 
    89                                 (Cost (*)(Type*, Type*, const SymTab::Indexer&, const TypeEnvironment&))
     87                        PassVisitor<ConversionCost> converter(
     88                                dest, indexer, env,
     89                                (Cost (*)(const Type *, const Type *, const SymTab::Indexer&, const TypeEnvironment&))
    9090                                        conversionCost );
    9191                        src->accept( converter );
     
    9898        }
    9999
    100         Cost convertToReferenceCost( Type * src, Type * dest, int diff, const SymTab::Indexer & indexer, const TypeEnvironment & env, PtrsFunction func ) {
     100        Cost convertToReferenceCost( const Type * src, const Type * dest, int diff, const SymTab::Indexer & indexer, const TypeEnvironment & env, PtrsFunction func ) {
    101101                PRINT( std::cerr << "convert to reference cost... diff " << diff << " " << src << " / " << dest << std::endl; )
    102102                if ( diff > 0 ) {
    103103                        // TODO: document this
    104                         Cost cost = convertToReferenceCost( strict_dynamic_cast< ReferenceType * >( src )->base, dest, diff-1, indexer, env, func );
     104                        Cost cost = convertToReferenceCost( strict_dynamic_cast< const ReferenceType * >( src )->base, dest, diff-1, indexer, env, func );
    105105                        cost.incReference();
    106106                        return cost;
    107107                } else if ( diff < -1 ) {
    108108                        // TODO: document this
    109                         Cost cost = convertToReferenceCost( src, strict_dynamic_cast< ReferenceType * >( dest )->base, diff+1, indexer, env, func );
     109                        Cost cost = convertToReferenceCost( src, strict_dynamic_cast< const ReferenceType * >( dest )->base, diff+1, indexer, env, func );
    110110                        cost.incReference();
    111111                        return cost;
    112112                } else if ( diff == 0 ) {
    113                         ReferenceType * srcAsRef = dynamic_cast< ReferenceType * >( src );
    114                         ReferenceType * destAsRef = dynamic_cast< ReferenceType * >( dest );
     113                        const ReferenceType * srcAsRef = dynamic_cast< const ReferenceType * >( src );
     114                        const ReferenceType * destAsRef = dynamic_cast< const ReferenceType * >( dest );
    115115                        if ( srcAsRef && destAsRef ) { // pointer-like conversions between references
    116116                                PRINT( std::cerr << "converting between references" << std::endl; )
    117                                 Type::Qualifiers tq1 = srcAsRef->base->get_qualifiers();
    118                                 Type::Qualifiers tq2 = destAsRef->base->get_qualifiers();
     117                                Type::Qualifiers tq1 = srcAsRef->base->tq;
     118                                Type::Qualifiers tq2 = destAsRef->base->tq;
    119119                                if ( tq1 <= tq2 && typesCompatibleIgnoreQualifiers( srcAsRef->base, destAsRef->base, indexer, env ) ) {
    120120                                        PRINT( std::cerr << " :: compatible and good qualifiers" << std::endl; )
     
    137137                        } else {
    138138                                PRINT( std::cerr << "reference to rvalue conversion" << std::endl; )
    139                                 PassVisitor<ConversionCost> converter( 
    140                                         dest, indexer, env, 
    141                                         (Cost (*)(Type*, Type*, const SymTab::Indexer&, const TypeEnvironment&))
     139                                PassVisitor<ConversionCost> converter(
     140                                        dest, indexer, env,
     141                                        (Cost (*)(const Type *, const Type *, const SymTab::Indexer&, const TypeEnvironment&))
    142142                                                conversionCost );
    143143                                src->accept( converter );
     
    145145                        } // if
    146146                } else {
    147                         ReferenceType * destAsRef = dynamic_cast< ReferenceType * >( dest );
     147                        const ReferenceType * destAsRef = dynamic_cast< const ReferenceType * >( dest );
    148148                        assert( diff == -1 && destAsRef );
    149149                        PRINT( std::cerr << "dest is: " << dest << " / src is: " << src << std::endl; )
     
    156156                                        )
    157157                                        // lvalue-to-reference conversion:  cv lvalue T => cv T &
    158                                         if ( src->get_qualifiers() == destAsRef->base->get_qualifiers() ) {
     158                                        if ( src->tq == destAsRef->base->tq ) {
    159159                                                return Cost::reference; // cost needs to be non-zero to add cast
    160                                         } if ( src->get_qualifiers() < destAsRef->base->get_qualifiers() ) {
     160                                        } if ( src->tq < destAsRef->base->tq ) {
    161161                                                return Cost::safe; // cost needs to be higher than previous cast to differentiate adding qualifiers vs. keeping same
    162162                                        } else {
     
    178178        }
    179179
    180         Cost convertToReferenceCost( Type * src, ReferenceType * dest, const SymTab::Indexer & indexer, const TypeEnvironment & env, PtrsFunction func ) {
     180        Cost convertToReferenceCost( const Type * src, const ReferenceType * dest, const SymTab::Indexer & indexer, const TypeEnvironment & env, PtrsFunction func ) {
    181181                int sdepth = src->referenceDepth(), ddepth = dest->referenceDepth();
    182182                Cost cost = convertToReferenceCost( src, dest, sdepth-ddepth, indexer, env, func );
     
    185185        }
    186186
    187         ConversionCost::ConversionCost( Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env, CostFunction costFunc )
     187        ConversionCost::ConversionCost( const Type * dest, const SymTab::Indexer &indexer, const TypeEnvironment &env, CostFunction costFunc )
    188188                : dest( dest ), indexer( indexer ), cost( Cost::infinity ), env( env ), costFunc( costFunc ) {
    189189        }
     
    193193        /* EXTENDED INTEGRAL RANK HIERARCHY (root to leaves)
    194194                                 _Bool
    195         char                signed char         unsigned char       
    196                   signed short int         unsigned short int       
    197                   signed int               unsigned int             
    198                   signed long int          unsigned long int       
    199                   signed long long int     unsigned long long int   
    200                   __int128                 unsigned __int128       
    201                   _Float16                 _Float16 _Complex       
    202                   _Float32                 _Float32 _Complex       
    203                   float                    float _Complex           
    204                   _Float32x                _Float32x _Complex       
    205                   _Float64                 _Float64 _Complex       
    206                   double                   double _Complex         
    207                   _Float64x                _Float64x _Complex       
     195        char                signed char         unsigned char
     196                  signed short int         unsigned short int
     197                  signed int               unsigned int
     198                  signed long int          unsigned long int
     199                  signed long long int     unsigned long long int
     200                  __int128                 unsigned __int128
     201                  _Float16                 _Float16 _Complex
     202                  _Float32                 _Float32 _Complex
     203                  float                    float _Complex
     204                  _Float32x                _Float32x _Complex
     205                  _Float64                 _Float64 _Complex
     206                  double                   double _Complex
     207                  _Float64x                _Float64x _Complex
    208208                             __float80
    209                   _Float128                _Float128 _Complex       
     209                  _Float128                _Float128 _Complex
    210210                            __float128
    211                   long double              long double _Complex     
    212                   _Float128x               _Float128x _Complex     
     211                  long double              long double _Complex
     212                  _Float128x               _Float128x _Complex
    213213        */
    214214        // GENERATED END
     
    218218        static const int costMatrix[BasicType::NUMBER_OF_BASIC_TYPES][BasicType::NUMBER_OF_BASIC_TYPES] = { // path length from root to node
    219219                /*             B    C   SC   UC   SI  SUI    I   UI   LI  LUI  LLI LLUI   IB  UIB  _FH  _FH   _F  _FC    F   FC  _FX _FXC   FD _FDC    D   DC F80X_FDXC  F80  _FB_FLDC   FB   LD  LDC _FBX_FLDXC */
    220                 /*     B*/ {   0,   1,   1,   2,   2,   3,   3,   4,   4,   5,   5,   6,   6,   7,   7,   8,   8,   9,   9,  10,  10,  11,  11,  12,  12,  13,  13,  14,  14,  15,  15,  16,  17,  16,  18,  17, },
    221                 /*     C*/ {  -1,   0,   1,   1,   1,   2,   2,   3,   3,   4,   4,   5,   5,   6,   6,   7,   7,   8,   8,   9,   9,  10,  10,  11,  11,  12,  12,  13,  13,  14,  14,  15,  16,  15,  17,  16, },
    222                 /*    SC*/ {  -1,  -1,   0,   1,   1,   2,   2,   3,   3,   4,   4,   5,   5,   6,   6,   7,   7,   8,   8,   9,   9,  10,  10,  11,  11,  12,  12,  13,  13,  14,  14,  15,  16,  15,  17,  16, },
    223                 /*    UC*/ {  -1,  -1,  -1,   0,   1,   1,   2,   2,   3,   3,   4,   4,   5,   5,   6,   7,   7,   8,   8,   9,   9,  10,  10,  11,  11,  12,  12,  13,  13,  14,  14,  15,  16,  15,  17,  16, },
    224                 /*    SI*/ {  -1,  -1,  -1,  -1,   0,   1,   1,   2,   2,   3,   3,   4,   4,   5,   5,   6,   6,   7,   7,   8,   8,   9,   9,  10,  10,  11,  11,  12,  12,  13,  13,  14,  15,  14,  16,  15, },
    225                 /*   SUI*/ {  -1,  -1,  -1,  -1,  -1,   0,   1,   1,   2,   2,   3,   3,   4,   4,   5,   6,   6,   7,   7,   8,   8,   9,   9,  10,  10,  11,  11,  12,  12,  13,  13,  14,  15,  14,  16,  15, },
    226                 /*     I*/ {  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   1,   2,   2,   3,   3,   4,   4,   5,   5,   6,   6,   7,   7,   8,   8,   9,   9,  10,  10,  11,  11,  12,  12,  13,  14,  13,  15,  14, },
    227                 /*    UI*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   1,   2,   2,   3,   3,   4,   5,   5,   6,   6,   7,   7,   8,   8,   9,   9,  10,  10,  11,  11,  12,  12,  13,  14,  13,  15,  14, },
    228                 /*    LI*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   1,   2,   2,   3,   3,   4,   4,   5,   5,   6,   6,   7,   7,   8,   8,   9,   9,  10,  10,  11,  11,  12,  13,  12,  14,  13, },
    229                 /*   LUI*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   1,   2,   2,   3,   4,   4,   5,   5,   6,   6,   7,   7,   8,   8,   9,   9,  10,  10,  11,  11,  12,  13,  12,  14,  13, },
    230                 /*   LLI*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   1,   2,   2,   3,   3,   4,   4,   5,   5,   6,   6,   7,   7,   8,   8,   9,   9,  10,  10,  11,  12,  11,  13,  12, },
    231                 /*  LLUI*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   1,   2,   3,   3,   4,   4,   5,   5,   6,   6,   7,   7,   8,   8,   9,   9,  10,  10,  11,  12,  11,  13,  12, },
    232                 /*    IB*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   1,   2,   2,   3,   3,   4,   4,   5,   5,   6,   6,   7,   7,   8,   8,   9,   9,  10,  11,  10,  12,  11, },
    233                 /*   UIB*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   2,   2,   3,   3,   4,   4,   5,   5,   6,   6,   7,   7,   8,   8,   9,   9,  10,  11,  10,  12,  11, },
    234                 /*   _FH*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   1,   2,   2,   3,   3,   4,   4,   5,   5,   6,   6,   7,   7,   8,   8,   9,  10,   9,  11,  10, },
    235                 /*   _FH*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,  -1,   1,  -1,   2,  -1,   3,  -1,   4,  -1,   5,  -1,   6,  -1,  -1,   7,  -1,  -1,   8,  -1,   9, },
    236                 /*    _F*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   1,   2,   2,   3,   3,   4,   4,   5,   5,   6,   6,   7,   7,   8,   9,   8,  10,   9, },
    237                 /*   _FC*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,  -1,   1,  -1,   2,  -1,   3,  -1,   4,  -1,   5,  -1,  -1,   6,  -1,  -1,   7,  -1,   8, },
    238                 /*     F*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   1,   2,   2,   3,   3,   4,   4,   5,   5,   6,   6,   7,   8,   7,   9,   8, },
    239                 /*    FC*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,  -1,   1,  -1,   2,  -1,   3,  -1,   4,  -1,  -1,   5,  -1,  -1,   6,  -1,   7, },
    240                 /*   _FX*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   1,   2,   2,   3,   3,   4,   4,   5,   5,   6,   7,   6,   8,   7, },
    241                 /*  _FXC*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,  -1,   1,  -1,   2,  -1,   3,  -1,  -1,   4,  -1,  -1,   5,  -1,   6, },
    242                 /*    FD*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   1,   2,   2,   3,   3,   4,   4,   5,   6,   5,   7,   6, },
    243                 /*  _FDC*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,  -1,   1,  -1,   2,  -1,  -1,   3,  -1,  -1,   4,  -1,   5, },
    244                 /*     D*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   1,   2,   2,   3,   3,   4,   5,   4,   6,   5, },
    245                 /*    DC*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,  -1,   1,  -1,  -1,   2,  -1,  -1,   3,  -1,   4, },
    246                 /*  F80X*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   1,   2,   2,   3,   4,   3,   5,   4, },
    247                 /* _FDXC*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,  -1,  -1,   1,  -1,  -1,   2,  -1,   3, },
     220                /*     B */ {   0,   1,   1,   2,   2,   3,   3,   4,   4,   5,   5,   6,   6,   7,   7,   8,   8,   9,   9,  10,  10,  11,  11,  12,  12,  13,  13,  14,  14,  15,  15,  16,  17,  16,  18,  17, },
     221                /*     C */ {  -1,   0,   1,   1,   1,   2,   2,   3,   3,   4,   4,   5,   5,   6,   6,   7,   7,   8,   8,   9,   9,  10,  10,  11,  11,  12,  12,  13,  13,  14,  14,  15,  16,  15,  17,  16, },
     222                /*    SC */ {  -1,  -1,   0,   1,   1,   2,   2,   3,   3,   4,   4,   5,   5,   6,   6,   7,   7,   8,   8,   9,   9,  10,  10,  11,  11,  12,  12,  13,  13,  14,  14,  15,  16,  15,  17,  16, },
     223                /*    UC */ {  -1,  -1,  -1,   0,   1,   1,   2,   2,   3,   3,   4,   4,   5,   5,   6,   7,   7,   8,   8,   9,   9,  10,  10,  11,  11,  12,  12,  13,  13,  14,  14,  15,  16,  15,  17,  16, },
     224                /*    SI */ {  -1,  -1,  -1,  -1,   0,   1,   1,   2,   2,   3,   3,   4,   4,   5,   5,   6,   6,   7,   7,   8,   8,   9,   9,  10,  10,  11,  11,  12,  12,  13,  13,  14,  15,  14,  16,  15, },
     225                /*   SUI */ {  -1,  -1,  -1,  -1,  -1,   0,   1,   1,   2,   2,   3,   3,   4,   4,   5,   6,   6,   7,   7,   8,   8,   9,   9,  10,  10,  11,  11,  12,  12,  13,  13,  14,  15,  14,  16,  15, },
     226                /*     I */ {  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   1,   2,   2,   3,   3,   4,   4,   5,   5,   6,   6,   7,   7,   8,   8,   9,   9,  10,  10,  11,  11,  12,  12,  13,  14,  13,  15,  14, },
     227                /*    UI */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   1,   2,   2,   3,   3,   4,   5,   5,   6,   6,   7,   7,   8,   8,   9,   9,  10,  10,  11,  11,  12,  12,  13,  14,  13,  15,  14, },
     228                /*    LI */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   1,   2,   2,   3,   3,   4,   4,   5,   5,   6,   6,   7,   7,   8,   8,   9,   9,  10,  10,  11,  11,  12,  13,  12,  14,  13, },
     229                /*   LUI */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   1,   2,   2,   3,   4,   4,   5,   5,   6,   6,   7,   7,   8,   8,   9,   9,  10,  10,  11,  11,  12,  13,  12,  14,  13, },
     230                /*   LLI */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   1,   2,   2,   3,   3,   4,   4,   5,   5,   6,   6,   7,   7,   8,   8,   9,   9,  10,  10,  11,  12,  11,  13,  12, },
     231                /*  LLUI */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   1,   2,   3,   3,   4,   4,   5,   5,   6,   6,   7,   7,   8,   8,   9,   9,  10,  10,  11,  12,  11,  13,  12, },
     232                /*    IB */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   1,   2,   2,   3,   3,   4,   4,   5,   5,   6,   6,   7,   7,   8,   8,   9,   9,  10,  11,  10,  12,  11, },
     233                /*   UIB */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   2,   2,   3,   3,   4,   4,   5,   5,   6,   6,   7,   7,   8,   8,   9,   9,  10,  11,  10,  12,  11, },
     234                /*   _FH */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   1,   2,   2,   3,   3,   4,   4,   5,   5,   6,   6,   7,   7,   8,   8,   9,  10,   9,  11,  10, },
     235                /*   _FH */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,  -1,   1,  -1,   2,  -1,   3,  -1,   4,  -1,   5,  -1,   6,  -1,  -1,   7,  -1,  -1,   8,  -1,   9, },
     236                /*    _F */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   1,   2,   2,   3,   3,   4,   4,   5,   5,   6,   6,   7,   7,   8,   9,   8,  10,   9, },
     237                /*   _FC */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,  -1,   1,  -1,   2,  -1,   3,  -1,   4,  -1,   5,  -1,  -1,   6,  -1,  -1,   7,  -1,   8, },
     238                /*     F */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   1,   2,   2,   3,   3,   4,   4,   5,   5,   6,   6,   7,   8,   7,   9,   8, },
     239                /*    FC */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,  -1,   1,  -1,   2,  -1,   3,  -1,   4,  -1,  -1,   5,  -1,  -1,   6,  -1,   7, },
     240                /*   _FX */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   1,   2,   2,   3,   3,   4,   4,   5,   5,   6,   7,   6,   8,   7, },
     241                /*  _FXC */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,  -1,   1,  -1,   2,  -1,   3,  -1,  -1,   4,  -1,  -1,   5,  -1,   6, },
     242                /*    FD */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   1,   2,   2,   3,   3,   4,   4,   5,   6,   5,   7,   6, },
     243                /*  _FDC */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,  -1,   1,  -1,   2,  -1,  -1,   3,  -1,  -1,   4,  -1,   5, },
     244                /*     D */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   1,   2,   2,   3,   3,   4,   5,   4,   6,   5, },
     245                /*    DC */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,  -1,   1,  -1,  -1,   2,  -1,  -1,   3,  -1,   4, },
     246                /*  F80X */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   1,   2,   2,   3,   4,   3,   5,   4, },
     247                /* _FDXC */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,  -1,  -1,   1,  -1,  -1,   2,  -1,   3, },
    248248                /*   F80*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   1,   0,   1,   2,   2,   3,   3,   4,   4, },
    249                 /*   _FB*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   1,   2,   2,   3,   3, },
    250                 /* _FLDC*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,  -1,  -1,   1,  -1,   2, },
    251                 /*    FB*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   1,   0,   1,   2,   2,   3, },
    252                 /*    LD*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   1,   2, },
    253                 /*   LDC*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,  -1,   1, },
    254                 /*  _FBX*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1, },
    255                 /*_FLDXC*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0, },
     249                /*   _FB */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   1,   2,   2,   3,   3, },
     250                /* _FLDC */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,  -1,  -1,   1,  -1,   2, },
     251                /*    FB */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   1,   0,   1,   2,   2,   3, },
     252                /*    LD */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   1,   2, },
     253                /*   LDC */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,  -1,   1, },
     254                /*  _FBX */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1, },
     255                /* _FLDXC */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0, },
    256256        }; // costMatrix
    257257        static const int maxIntCost = 15;
    258258        // GENERATED END
    259259        static_assert(
    260                 sizeof(costMatrix)/sizeof(costMatrix[0][0]) == BasicType::NUMBER_OF_BASIC_TYPES*BasicType::NUMBER_OF_BASIC_TYPES,
     260                sizeof(costMatrix)/sizeof(costMatrix[0][0]) == BasicType::NUMBER_OF_BASIC_TYPES * BasicType::NUMBER_OF_BASIC_TYPES,
    261261                "Missing row in the cost matrix"
    262262        );
     
    266266        static const int signMatrix[BasicType::NUMBER_OF_BASIC_TYPES][BasicType::NUMBER_OF_BASIC_TYPES] = { // number of sign changes in safe conversion
    267267                /*             B    C   SC   UC   SI  SUI    I   UI   LI  LUI  LLI LLUI   IB  UIB  _FH  _FH   _F  _FC    F   FC  _FX _FXC   FD _FDC    D   DC F80X_FDXC  F80  _FB_FLDC   FB   LD  LDC _FBX_FLDXC */
    268                 /*     B*/ {   0,   0,   0,   1,   0,   1,   0,   1,   0,   1,   0,   1,   0,   1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
    269                 /*     C*/ {  -1,   0,   0,   1,   0,   1,   0,   1,   0,   1,   0,   1,   0,   1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
    270                 /*    SC*/ {  -1,  -1,   0,   1,   0,   1,   0,   1,   0,   1,   0,   1,   0,   1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
    271                 /*    UC*/ {  -1,  -1,  -1,   0,   1,   0,   1,   0,   1,   0,   1,   0,   1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
    272                 /*    SI*/ {  -1,  -1,  -1,  -1,   0,   1,   0,   1,   0,   1,   0,   1,   0,   1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
    273                 /*   SUI*/ {  -1,  -1,  -1,  -1,  -1,   0,   1,   0,   1,   0,   1,   0,   1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
    274                 /*     I*/ {  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   0,   1,   0,   1,   0,   1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
    275                 /*    UI*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   0,   1,   0,   1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
    276                 /*    LI*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   0,   1,   0,   1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
    277                 /*   LUI*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   0,   1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
    278                 /*   LLI*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   0,   1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
    279                 /*  LLUI*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
    280                 /*    IB*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
    281                 /*   UIB*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
    282                 /*   _FH*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
    283                 /*   _FH*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,  -1,   0,  -1,   0,  -1,   0,  -1,   0,  -1,   0,  -1,   0,  -1,  -1,   0,  -1,  -1,   0,  -1,   0, },
    284                 /*    _F*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
    285                 /*   _FC*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,  -1,   0,  -1,   0,  -1,   0,  -1,   0,  -1,   0,  -1,  -1,   0,  -1,  -1,   0,  -1,   0, },
    286                 /*     F*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
    287                 /*    FC*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,  -1,   0,  -1,   0,  -1,   0,  -1,   0,  -1,  -1,   0,  -1,  -1,   0,  -1,   0, },
    288                 /*   _FX*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
    289                 /*  _FXC*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,  -1,   0,  -1,   0,  -1,   0,  -1,  -1,   0,  -1,  -1,   0,  -1,   0, },
    290                 /*    FD*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
    291                 /*  _FDC*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,  -1,   0,  -1,   0,  -1,  -1,   0,  -1,  -1,   0,  -1,   0, },
    292                 /*     D*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
    293                 /*    DC*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,  -1,   0,  -1,  -1,   0,  -1,  -1,   0,  -1,   0, },
    294                 /*  F80X*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
    295                 /* _FDXC*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,  -1,  -1,   0,  -1,  -1,   0,  -1,   0, },
     268                /*     B */ {   0,   0,   0,   1,   0,   1,   0,   1,   0,   1,   0,   1,   0,   1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
     269                /*     C */ {  -1,   0,   0,   1,   0,   1,   0,   1,   0,   1,   0,   1,   0,   1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
     270                /*    SC */ {  -1,  -1,   0,   1,   0,   1,   0,   1,   0,   1,   0,   1,   0,   1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
     271                /*    UC */ {  -1,  -1,  -1,   0,   1,   0,   1,   0,   1,   0,   1,   0,   1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
     272                /*    SI */ {  -1,  -1,  -1,  -1,   0,   1,   0,   1,   0,   1,   0,   1,   0,   1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
     273                /*   SUI */ {  -1,  -1,  -1,  -1,  -1,   0,   1,   0,   1,   0,   1,   0,   1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
     274                /*     I */ {  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   0,   1,   0,   1,   0,   1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
     275                /*    UI */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   0,   1,   0,   1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
     276                /*    LI */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   0,   1,   0,   1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
     277                /*   LUI */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   0,   1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
     278                /*   LLI */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   0,   1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
     279                /*  LLUI */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
     280                /*    IB */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
     281                /*   UIB */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
     282                /*   _FH */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
     283                /*   _FH */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,  -1,   0,  -1,   0,  -1,   0,  -1,   0,  -1,   0,  -1,   0,  -1,  -1,   0,  -1,  -1,   0,  -1,   0, },
     284                /*    _F */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
     285                /*   _FC */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,  -1,   0,  -1,   0,  -1,   0,  -1,   0,  -1,   0,  -1,  -1,   0,  -1,  -1,   0,  -1,   0, },
     286                /*     F */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
     287                /*    FC */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,  -1,   0,  -1,   0,  -1,   0,  -1,   0,  -1,  -1,   0,  -1,  -1,   0,  -1,   0, },
     288                /*   _FX */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
     289                /*  _FXC */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,  -1,   0,  -1,   0,  -1,   0,  -1,  -1,   0,  -1,  -1,   0,  -1,   0, },
     290                /*    FD */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
     291                /*  _FDC */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,  -1,   0,  -1,   0,  -1,  -1,   0,  -1,  -1,   0,  -1,   0, },
     292                /*     D */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
     293                /*    DC */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,  -1,   0,  -1,  -1,   0,  -1,  -1,   0,  -1,   0, },
     294                /*  F80X */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
     295                /* _FDXC */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,  -1,  -1,   0,  -1,  -1,   0,  -1,   0, },
    296296                /*   F80*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
    297                 /*   _FB*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,   0,   0,   0,   0,   0, },
    298                 /* _FLDC*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,  -1,  -1,   0,  -1,   0, },
    299                 /*    FB*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,   0,   0,   0,   0, },
    300                 /*    LD*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,   0,   0, },
    301                 /*   LDC*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,  -1,   0, },
    302                 /*  _FBX*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0, },
    303                 /*_FLDXC*/ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0, },
     297                /*   _FB */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,   0,   0,   0,   0,   0, },
     298                /* _FLDC */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,  -1,  -1,   0,  -1,   0, },
     299                /*    FB */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,   0,   0,   0,   0, },
     300                /*    LD */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,   0,   0, },
     301                /*   LDC */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,  -1,   0, },
     302                /*  _FBX */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0, },
     303                /* _FLDXC */ {  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0, },
    304304        }; // signMatrix
    305305        // GENERATED END
    306306        static_assert(
    307                 sizeof(signMatrix)/sizeof(signMatrix[0][0]) == BasicType::NUMBER_OF_BASIC_TYPES*BasicType::NUMBER_OF_BASIC_TYPES,
     307                sizeof(signMatrix)/sizeof(signMatrix[0][0]) == BasicType::NUMBER_OF_BASIC_TYPES * BasicType::NUMBER_OF_BASIC_TYPES,
    308308                "Missing row in the sign matrix"
    309309        );
    310310
    311         void ConversionCost::postvisit( VoidType * ) {
     311        void ConversionCost::postvisit( const VoidType * ) {
    312312                cost = Cost::infinity;
    313313        }
    314314
    315         void ConversionCost::postvisit(BasicType *basicType) {
    316                 if ( BasicType *destAsBasic = dynamic_cast< BasicType* >( dest ) ) {
    317                         int tableResult = costMatrix[ basicType->get_kind() ][ destAsBasic->get_kind() ];
     315        void ConversionCost::postvisit(const BasicType * basicType) {
     316                if ( const BasicType * destAsBasic = dynamic_cast< const BasicType * >( dest ) ) {
     317                        int tableResult = costMatrix[ basicType->kind ][ destAsBasic->kind ];
    318318                        if ( tableResult == -1 ) {
    319319                                cost = Cost::unsafe;
     
    321321                                cost = Cost::zero;
    322322                                cost.incSafe( tableResult );
    323                                 cost.incSign( signMatrix[ basicType->get_kind() ][ destAsBasic->get_kind() ] );
    324                         } // if
    325                 } else if ( dynamic_cast< EnumInstType *>( dest ) ) {
     323                                cost.incSign( signMatrix[ basicType->kind ][ destAsBasic->kind ] );
     324                        } // if
     325                } else if ( dynamic_cast< const EnumInstType * >( dest ) ) {
    326326                        // xxx - not positive this is correct, but appears to allow casting int => enum
    327327                        cost = Cost::unsafe;
     
    330330        }
    331331
    332         void ConversionCost::postvisit( PointerType * pointerType ) {
    333                 if ( PointerType *destAsPtr = dynamic_cast< PointerType* >( dest ) ) {
     332        void ConversionCost::postvisit( const PointerType * pointerType ) {
     333                if ( const PointerType * destAsPtr = dynamic_cast< const PointerType * >( dest ) ) {
    334334                        PRINT( std::cerr << pointerType << " ===> " << destAsPtr << std::endl; )
    335                         Type::Qualifiers tq1 = pointerType->base->get_qualifiers();
    336                         Type::Qualifiers tq2 = destAsPtr->base->get_qualifiers();
     335                        Type::Qualifiers tq1 = pointerType->base->tq;
     336                        Type::Qualifiers tq2 = destAsPtr->base->tq;
    337337                        if ( tq1 <= tq2 && typesCompatibleIgnoreQualifiers( pointerType->base, destAsPtr->base, indexer, env ) ) {
    338338                                PRINT( std::cerr << " :: compatible and good qualifiers" << std::endl; )
     
    363363        }
    364364
    365         void ConversionCost::postvisit( ArrayType * ) {}
    366 
    367         void ConversionCost::postvisit( ReferenceType * refType ) {
     365        void ConversionCost::postvisit( const ArrayType * ) {}
     366
     367        void ConversionCost::postvisit( const ReferenceType * refType ) {
    368368                // Note: dest can never be a reference, since it would have been caught in an earlier check
    369                 assert( ! dynamic_cast< ReferenceType * >( dest ) );
     369                assert( ! dynamic_cast< const ReferenceType * >( dest ) );
    370370                // convert reference to rvalue: cv T1 & => T2
    371371                // recursively compute conversion cost from T1 to T2.
    372372                // cv can be safely dropped because of 'implicit dereference' behavior.
    373373                cost = costFunc( refType->base, dest, indexer, env );
    374                 if ( refType->base->get_qualifiers() == dest->get_qualifiers() ) {
     374                if ( refType->base->tq == dest->tq ) {
    375375                        cost.incReference();  // prefer exact qualifiers
    376                 } else if ( refType->base->get_qualifiers() < dest->get_qualifiers() ) {
     376                } else if ( refType->base->tq < dest->tq ) {
    377377                        cost.incSafe(); // then gaining qualifiers
    378378                } else {
     
    382382        }
    383383
    384         void ConversionCost::postvisit( FunctionType * ) {}
    385 
    386         void ConversionCost::postvisit( StructInstType * inst ) {
    387                 if ( StructInstType *destAsInst = dynamic_cast< StructInstType* >( dest ) ) {
     384        void ConversionCost::postvisit( const FunctionType * ) {}
     385
     386        void ConversionCost::postvisit( const StructInstType * inst ) {
     387                if ( const StructInstType * destAsInst = dynamic_cast< const StructInstType * >( dest ) ) {
    388388                        if ( inst->name == destAsInst->name ) {
    389389                                cost = Cost::zero;
     
    392392        }
    393393
    394         void ConversionCost::postvisit( UnionInstType * inst ) {
    395                 if ( UnionInstType *destAsInst = dynamic_cast< UnionInstType* >( dest ) ) {
     394        void ConversionCost::postvisit( const UnionInstType * inst ) {
     395                if ( const UnionInstType * destAsInst = dynamic_cast< const UnionInstType * >( dest ) ) {
    396396                        if ( inst->name == destAsInst->name ) {
    397397                                cost = Cost::zero;
     
    400400        }
    401401
    402         void ConversionCost::postvisit( EnumInstType * ) {
     402        void ConversionCost::postvisit( const EnumInstType * ) {
    403403                static Type::Qualifiers q;
    404404                static BasicType integer( q, BasicType::SignedInt );
     
    409409        }
    410410
    411         void ConversionCost::postvisit( TraitInstType * ) {}
    412 
    413         void ConversionCost::postvisit( TypeInstType *inst ) {
    414                 if ( const EqvClass *eqvClass = env.lookup( inst->name ) ) {
     411        void ConversionCost::postvisit( const TraitInstType * ) {}
     412
     413        void ConversionCost::postvisit( const TypeInstType * inst ) {
     414                if ( const EqvClass * eqvClass = env.lookup( inst->name ) ) {
    415415                        cost = costFunc( eqvClass->type, dest, indexer, env );
    416                 } else if ( TypeInstType *destAsInst = dynamic_cast< TypeInstType* >( dest ) ) {
     416                } else if ( const TypeInstType * destAsInst = dynamic_cast< const TypeInstType * >( dest ) ) {
    417417                        if ( inst->name == destAsInst->name ) {
    418418                                cost = Cost::zero;
    419419                        }
    420                 } else if ( NamedTypeDecl *namedType = indexer.lookupType( inst->name ) ) {
    421                         TypeDecl *type = dynamic_cast< TypeDecl* >( namedType );
     420                } else if ( const NamedTypeDecl * namedType = indexer.lookupType( inst->name ) ) {
     421                        const TypeDecl * type = dynamic_cast< const TypeDecl * >( namedType );
    422422                        // all typedefs should be gone by this point
    423423                        assert( type );
     
    428428        }
    429429
    430         void ConversionCost::postvisit( TupleType * tupleType ) {
     430        void ConversionCost::postvisit( const TupleType * tupleType ) {
    431431                Cost c = Cost::zero;
    432                 if ( TupleType * destAsTuple = dynamic_cast< TupleType * >( dest ) ) {
     432                if ( const TupleType * destAsTuple = dynamic_cast< const TupleType * >( dest ) ) {
    433433                        std::list< Type * >::const_iterator srcIt = tupleType->types.begin();
    434434                        std::list< Type * >::const_iterator destIt = destAsTuple->types.begin();
    435435                        while ( srcIt != tupleType->types.end() && destIt != destAsTuple->types.end() ) {
    436                                 Cost newCost = costFunc( *srcIt++, *destIt++, indexer, env );
     436                                Cost newCost = costFunc( * srcIt++, * destIt++, indexer, env );
    437437                                if ( newCost == Cost::infinity ) {
    438438                                        return;
     
    448448        }
    449449
    450         void ConversionCost::postvisit( VarArgsType * ) {
    451                 if ( dynamic_cast< VarArgsType* >( dest ) ) {
    452                         cost = Cost::zero;
    453                 }
    454         }
    455 
    456         void ConversionCost::postvisit( ZeroType * ) {
    457                 if ( dynamic_cast< ZeroType * >( dest ) ) {
    458                         cost = Cost::zero;
    459                 } else if ( BasicType *destAsBasic = dynamic_cast< BasicType* >( dest ) ) {
    460                         // copied from visit(BasicType*) for signed int, but +1 for safe conversions
    461                         int tableResult = costMatrix[ BasicType::SignedInt ][ destAsBasic->get_kind() ];
     450        void ConversionCost::postvisit( const VarArgsType * ) {
     451                if ( dynamic_cast< const VarArgsType * >( dest ) ) {
     452                        cost = Cost::zero;
     453                }
     454        }
     455
     456        void ConversionCost::postvisit( const ZeroType * ) {
     457                if ( dynamic_cast< const ZeroType * >( dest ) ) {
     458                        cost = Cost::zero;
     459                } else if ( const BasicType * destAsBasic = dynamic_cast< const BasicType * >( dest ) ) {
     460                        // copied from visit(BasicType *) for signed int, but +1 for safe conversions
     461                        int tableResult = costMatrix[ BasicType::SignedInt ][ destAsBasic->kind ];
    462462                        if ( tableResult == -1 ) {
    463463                                cost = Cost::unsafe;
     
    465465                                cost = Cost::zero;
    466466                                cost.incSafe( tableResult + 1 );
    467                                 cost.incSign( signMatrix[ BasicType::SignedInt ][ destAsBasic->get_kind() ] );
    468                         } // if
    469                 } else if ( dynamic_cast< PointerType* >( dest ) ) {
     467                                cost.incSign( signMatrix[ BasicType::SignedInt ][ destAsBasic->kind ] );
     468                        } // if
     469                } else if ( dynamic_cast< const PointerType * >( dest ) ) {
    470470                        cost = Cost::zero;
    471471                        cost.incSafe( maxIntCost + 2 ); // +1 for zero_t -> int, +1 for disambiguation
     
    473473        }
    474474
    475         void ConversionCost::postvisit( OneType * ) {
    476                 if ( dynamic_cast< OneType * >( dest ) ) {
    477                         cost = Cost::zero;
    478                 } else if ( BasicType *destAsBasic = dynamic_cast< BasicType* >( dest ) ) {
    479                         // copied from visit(BasicType*) for signed int, but +1 for safe conversions
    480                         int tableResult = costMatrix[ BasicType::SignedInt ][ destAsBasic->get_kind() ];
     475        void ConversionCost::postvisit( const OneType * ) {
     476                if ( dynamic_cast< const OneType * >( dest ) ) {
     477                        cost = Cost::zero;
     478                } else if ( const BasicType * destAsBasic = dynamic_cast< const BasicType * >( dest ) ) {
     479                        // copied from visit(BasicType *) for signed int, but +1 for safe conversions
     480                        int tableResult = costMatrix[ BasicType::SignedInt ][ destAsBasic->kind ];
    481481                        if ( tableResult == -1 ) {
    482482                                cost = Cost::unsafe;
     
    484484                                cost = Cost::zero;
    485485                                cost.incSafe( tableResult + 1 );
    486                                 cost.incSign( signMatrix[ BasicType::SignedInt ][ destAsBasic->get_kind() ] );
     486                                cost.incSign( signMatrix[ BasicType::SignedInt ][ destAsBasic->kind ] );
    487487                        } // if
    488488                } // if
     
    729729                auto dstEnd = dstAsTuple->types.end();
    730730                while ( srcIt != srcEnd && dstIt != dstEnd ) {
    731                         Cost newCost = costCalc( *srcIt++, *dstIt++, symtab, env );
     731                        Cost newCost = costCalc( * srcIt++, * dstIt++, symtab, env );
    732732                        if ( newCost == Cost::infinity ) {
    733733                                return;
  • src/ResolvExpr/ConversionCost.h

    r302d84c2 rfce4e31  
    3333        class TypeEnvironment;
    3434
    35         typedef std::function<Cost(Type *, Type *, const SymTab::Indexer &, const TypeEnvironment &)> CostFunction;
     35        typedef std::function<Cost(const Type *, const Type *, const SymTab::Indexer &, const TypeEnvironment &)> CostFunction;
    3636        struct ConversionCost : public WithShortCircuiting {
    3737          public:
    38                 ConversionCost( Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env, CostFunction );
     38                ConversionCost( const Type * dest, const SymTab::Indexer &indexer, const TypeEnvironment &env, CostFunction );
    3939
    4040                Cost get_cost() const { return cost; }
    4141
    42                 void previsit( BaseSyntaxNode * ) { visit_children = false; }
     42                void previsit( const BaseSyntaxNode * ) { visit_children = false; }
    4343
    44                 void postvisit( VoidType * voidType );
    45                 void postvisit( BasicType * basicType );
    46                 void postvisit( PointerType * pointerType );
    47                 void postvisit( ArrayType * arrayType );
    48                 void postvisit( ReferenceType * refType );
    49                 void postvisit( FunctionType * functionType );
    50                 void postvisit( StructInstType * aggregateUseType );
    51                 void postvisit( UnionInstType * aggregateUseType );
    52                 void postvisit( EnumInstType * aggregateUseType );
    53                 void postvisit( TraitInstType * aggregateUseType );
    54                 void postvisit( TypeInstType * aggregateUseType );
    55                 void postvisit( TupleType * tupleType );
    56                 void postvisit( VarArgsType * varArgsType );
    57                 void postvisit( ZeroType * zeroType );
    58                 void postvisit( OneType * oneType );
     44                void postvisit( const VoidType * voidType );
     45                void postvisit( const BasicType * basicType );
     46                void postvisit( const PointerType * pointerType );
     47                void postvisit( const ArrayType * arrayType );
     48                void postvisit( const ReferenceType * refType );
     49                void postvisit( const FunctionType * functionType );
     50                void postvisit( const StructInstType * aggregateUseType );
     51                void postvisit( const UnionInstType * aggregateUseType );
     52                void postvisit( const EnumInstType * aggregateUseType );
     53                void postvisit( const TraitInstType * aggregateUseType );
     54                void postvisit( const TypeInstType * aggregateUseType );
     55                void postvisit( const TupleType * tupleType );
     56                void postvisit( const VarArgsType * varArgsType );
     57                void postvisit( const ZeroType * zeroType );
     58                void postvisit( const OneType * oneType );
    5959          protected:
    60                 Type *dest;
     60                const Type * dest;
    6161                const SymTab::Indexer &indexer;
    6262                Cost cost;
     
    6565        };
    6666
    67         typedef std::function<int(Type *, Type *, const SymTab::Indexer &, const TypeEnvironment &)> PtrsFunction;
    68         Cost convertToReferenceCost( Type * src, ReferenceType * dest, const SymTab::Indexer & indexer, const TypeEnvironment & env, PtrsFunction func );
     67        typedef std::function<int(const Type *, const Type *, const SymTab::Indexer &, const TypeEnvironment &)> PtrsFunction;
     68        Cost convertToReferenceCost( const Type * src, const ReferenceType * dest, const SymTab::Indexer & indexer, const TypeEnvironment & env, PtrsFunction func );
    6969
    7070// Some function pointer types, differ in return type.
  • src/ResolvExpr/PtrsAssignable.cc

    r302d84c2 rfce4e31  
    2727namespace ResolvExpr {
    2828        struct PtrsAssignable : public WithShortCircuiting {
    29                 PtrsAssignable( Type *dest, const TypeEnvironment &env );
     29                PtrsAssignable( const Type * dest, const TypeEnvironment &env );
    3030
    3131                int get_result() const { return result; }
    3232
    33                 void previsit( Type * ) { visit_children = false; }
    34 
    35                 void postvisit( VoidType * voidType );
    36                 void postvisit( BasicType * basicType );
    37                 void postvisit( PointerType * pointerType );
    38                 void postvisit( ArrayType * arrayType );
    39                 void postvisit( FunctionType * functionType );
    40                 void postvisit( StructInstType * inst );
    41                 void postvisit( UnionInstType * inst );
    42                 void postvisit( EnumInstType * inst );
    43                 void postvisit( TraitInstType * inst );
    44                 void postvisit( TypeInstType * inst );
    45                 void postvisit( TupleType * tupleType );
    46                 void postvisit( VarArgsType * varArgsType );
    47                 void postvisit( ZeroType * zeroType );
    48                 void postvisit( OneType * oneType );
     33                void previsit( const Type * ) { visit_children = false; }
     34
     35                void postvisit( const VoidType * voidType );
     36                void postvisit( const BasicType * basicType );
     37                void postvisit( const PointerType * pointerType );
     38                void postvisit( const ArrayType * arrayType );
     39                void postvisit( const FunctionType * functionType );
     40                void postvisit( const StructInstType * inst );
     41                void postvisit( const UnionInstType * inst );
     42                void postvisit( const EnumInstType * inst );
     43                void postvisit( const TraitInstType * inst );
     44                void postvisit( const TypeInstType * inst );
     45                void postvisit( const TupleType * tupleType );
     46                void postvisit( const VarArgsType * varArgsType );
     47                void postvisit( const ZeroType * zeroType );
     48                void postvisit( const OneType * oneType );
    4949          private:
    50                 Type *dest;
     50                const Type * dest;
    5151                int result;
    5252                const TypeEnvironment &env;
    5353        };
    5454
    55         int ptrsAssignable( Type *src, Type *dest, const TypeEnvironment &env ) {
     55        int ptrsAssignable( const Type *src, const Type * dest, const TypeEnvironment &env ) {
    5656                // std::cerr << "assignable: " << src << " | " << dest << std::endl;
    57                 if ( TypeInstType *destAsTypeInst = dynamic_cast< TypeInstType* >( dest ) ) {
    58                         if ( const EqvClass *eqvClass = env.lookup( destAsTypeInst->get_name() ) ) {
     57                if ( const TypeInstType * destAsTypeInst = dynamic_cast< const TypeInstType* >( dest ) ) {
     58                        if ( const EqvClass * eqvClass = env.lookup( destAsTypeInst->get_name() ) ) {
    5959                                return ptrsAssignable( src, eqvClass->type, env );
    6060                        } // if
    6161                } // if
    62                 if ( dynamic_cast< VoidType* >( dest ) ) {
     62                if ( dynamic_cast< const VoidType* >( dest ) ) {
    6363                        // void * = T * for any T is unsafe
    6464                        // xxx - this should be safe, but that currently breaks the build
     
    7171        }
    7272
    73         PtrsAssignable::PtrsAssignable( Type *dest, const TypeEnvironment &env ) : dest( dest ), result( 0 ), env( env ) {}
    74 
    75         void PtrsAssignable::postvisit( VoidType * ) {
     73        PtrsAssignable::PtrsAssignable( const Type * dest, const TypeEnvironment &env ) : dest( dest ), result( 0 ), env( env ) {}
     74
     75        void PtrsAssignable::postvisit( const VoidType * ) {
    7676                // T * = void * is disallowed - this is a change from C, where any
    7777                // void * can be assigned or passed to a non-void pointer without a cast.
    7878        }
    7979
    80         void PtrsAssignable::postvisit( __attribute__((unused)) BasicType *basicType ) {}
    81         void PtrsAssignable::postvisit( __attribute__((unused)) PointerType *pointerType ) {}
    82         void PtrsAssignable::postvisit( __attribute__((unused)) ArrayType *arrayType ) {}
    83         void PtrsAssignable::postvisit( __attribute__((unused)) FunctionType *functionType ) {}
    84 
    85         void PtrsAssignable::postvisit(  __attribute__((unused)) StructInstType *inst ) {}
    86         void PtrsAssignable::postvisit(  __attribute__((unused)) UnionInstType *inst ) {}
    87 
    88         void PtrsAssignable::postvisit( EnumInstType * ) {
    89                 if ( dynamic_cast< BasicType* >( dest ) ) {
     80        void PtrsAssignable::postvisit( const BasicType * ) {}
     81        void PtrsAssignable::postvisit( const PointerType * ) {}
     82        void PtrsAssignable::postvisit( const ArrayType * ) {}
     83        void PtrsAssignable::postvisit( const FunctionType * ) {}
     84
     85        void PtrsAssignable::postvisit( const StructInstType * ) {}
     86        void PtrsAssignable::postvisit( const UnionInstType * ) {}
     87
     88        void PtrsAssignable::postvisit( const EnumInstType * ) {
     89                if ( dynamic_cast< const BasicType* >( dest ) ) {
    9090                        // int * = E *, etc. is safe. This isn't technically correct, as each
    9191                        // enum has one basic type that it is compatible with, an that type can
     
    9797        }
    9898
    99         void PtrsAssignable::postvisit(  __attribute__((unused)) TraitInstType *inst ) {}
    100         void PtrsAssignable::postvisit( TypeInstType *inst ) {
    101                 if ( const EqvClass *eqvClass = env.lookup( inst->get_name() ) ) {
     99        void PtrsAssignable::postvisit(  const TraitInstType * ) {}
     100        void PtrsAssignable::postvisit( const TypeInstType * inst ) {
     101                if ( const EqvClass * eqvClass = env.lookup( inst->name ) ) {
    102102                        if ( eqvClass->type ) {
    103103                                // T * = S * for any S depends on the type bound to T
     
    107107        }
    108108
    109         void PtrsAssignable::postvisit(  __attribute__((unused)) TupleType *tupleType ) {}
    110         void PtrsAssignable::postvisit(  __attribute__((unused)) VarArgsType *varArgsType ) {}
    111         void PtrsAssignable::postvisit(  __attribute__((unused)) ZeroType *zeroType ) {}
    112         void PtrsAssignable::postvisit(  __attribute__((unused)) OneType *oneType ) {}
     109        void PtrsAssignable::postvisit( const TupleType * ) {}
     110        void PtrsAssignable::postvisit( const VarArgsType * ) {}
     111        void PtrsAssignable::postvisit( const ZeroType * ) {}
     112        void PtrsAssignable::postvisit( const OneType * ) {}
    113113
    114114// TODO: Get rid of the `_new` suffix when the old version is removed.
  • src/ResolvExpr/PtrsCastable.cc

    r302d84c2 rfce4e31  
    2929        struct PtrsCastable_old : public WithShortCircuiting  {
    3030          public:
    31                 PtrsCastable_old( Type *dest, const TypeEnvironment &env, const SymTab::Indexer &indexer );
     31                PtrsCastable_old( const Type * dest, const TypeEnvironment &env, const SymTab::Indexer &indexer );
    3232
    3333                int get_result() const { return result; }
    3434
    35                 void previsit( Type * ) { visit_children = false; }
    36 
    37                 void postvisit( VoidType * voidType );
    38                 void postvisit( BasicType * basicType );
    39                 void postvisit( PointerType * pointerType );
    40                 void postvisit( ArrayType * arrayType );
    41                 void postvisit( FunctionType * functionType );
    42                 void postvisit( StructInstType * inst );
    43                 void postvisit( UnionInstType * inst );
    44                 void postvisit( EnumInstType * inst );
    45                 void postvisit( TraitInstType * inst );
    46                 void postvisit( TypeInstType * inst );
    47                 void postvisit( TupleType * tupleType );
    48                 void postvisit( VarArgsType * varArgsType );
    49                 void postvisit( ZeroType * zeroType );
    50                 void postvisit( OneType * oneType );
     35                void previsit( const Type * ) { visit_children = false; }
     36
     37                void postvisit( const VoidType * voidType );
     38                void postvisit( const BasicType * basicType );
     39                void postvisit( const PointerType * pointerType );
     40                void postvisit( const ArrayType * arrayType );
     41                void postvisit( const FunctionType * functionType );
     42                void postvisit( const StructInstType * inst );
     43                void postvisit( const UnionInstType * inst );
     44                void postvisit( const EnumInstType * inst );
     45                void postvisit( const TraitInstType * inst );
     46                void postvisit( const TypeInstType * inst );
     47                void postvisit( const TupleType * tupleType );
     48                void postvisit( const VarArgsType * varArgsType );
     49                void postvisit( const ZeroType * zeroType );
     50                void postvisit( const OneType * oneType );
    5151          private:
    52                 Type *dest;
     52                const Type * dest;
    5353                int result;
    5454                const TypeEnvironment &env;
     
    5757
    5858        namespace {
    59                 int objectCast( Type *src, const TypeEnvironment &env, const SymTab::Indexer &indexer ) {
    60                         if ( dynamic_cast< FunctionType* >( src ) ) {
     59                int objectCast( const Type * src, const TypeEnvironment &env, const SymTab::Indexer &indexer ) {
     60                        if ( dynamic_cast< const FunctionType* >( src ) ) {
    6161                                return -1;
    62                         } else if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( src ) ) {
    63                                 if ( NamedTypeDecl *ntDecl = indexer.lookupType( typeInst->get_name() ) ) {
    64                                         if ( TypeDecl *tyDecl = dynamic_cast< TypeDecl* >( ntDecl ) ) {
    65                                                 if ( tyDecl->get_kind() == TypeDecl::Ftype ) {
     62                        } else if ( const TypeInstType * typeInst = dynamic_cast< const TypeInstType* >( src ) ) {
     63                                if ( const NamedTypeDecl * ntDecl = indexer.lookupType( typeInst->name ) ) {
     64                                        if ( const TypeDecl * tyDecl = dynamic_cast< const TypeDecl* >( ntDecl ) ) {
     65                                                if ( tyDecl->kind == TypeDecl::Ftype ) {
    6666                                                        return -1;
    6767                                                } // if
    6868                                        } //if
    69                                 } else if ( const EqvClass *eqvClass = env.lookup( typeInst->get_name() ) ) {
     69                                } else if ( const EqvClass * eqvClass = env.lookup( typeInst->get_name() ) ) {
    7070                                        if ( eqvClass->data.kind == TypeDecl::Ftype ) {
    7171                                                return -1;
     
    7575                        return 1;
    7676                }
    77                 int functionCast( Type *src, const TypeEnvironment &env, const SymTab::Indexer &indexer ) {
     77                int functionCast( const Type * src, const TypeEnvironment &env, const SymTab::Indexer &indexer ) {
    7878                        return -1 * objectCast( src, env, indexer );  // reverse the sense of objectCast
    7979                }
    8080        }
    8181
    82         int ptrsCastable( Type *src, Type *dest, const TypeEnvironment &env, const SymTab::Indexer &indexer ) {
    83                 if ( TypeInstType *destAsTypeInst = dynamic_cast< TypeInstType* >( dest ) ) {
    84                         if ( const EqvClass *eqvClass = env.lookup( destAsTypeInst->get_name() ) ) {
     82        int ptrsCastable( const Type * src, const Type * dest, const TypeEnvironment &env, const SymTab::Indexer &indexer ) {
     83                if ( const TypeInstType * destAsTypeInst = dynamic_cast< const TypeInstType* >( dest ) ) {
     84                        if ( const EqvClass * eqvClass = env.lookup( destAsTypeInst->get_name() ) ) {
    8585                                // xxx - should this be ptrsCastable?
    8686                                return ptrsAssignable( src, eqvClass->type, env );
    8787                        } // if
    8888                } // if
    89                 if ( dynamic_cast< VoidType* >( dest ) ) {
     89                if ( dynamic_cast< const VoidType* >( dest ) ) {
    9090                        return objectCast( src, env, indexer );
    9191                } else {
     
    9696        }
    9797
    98         PtrsCastable_old::PtrsCastable_old( Type *dest, const TypeEnvironment &env, const SymTab::Indexer &indexer )
     98        PtrsCastable_old::PtrsCastable_old( const Type * dest, const TypeEnvironment &env, const SymTab::Indexer &indexer )
    9999                : dest( dest ), result( 0 ), env( env ), indexer( indexer )     {
    100100        }
    101101
    102         void PtrsCastable_old::postvisit( VoidType * ) {
    103                 result = objectCast( dest, env, indexer );
    104         }
    105 
    106         void PtrsCastable_old::postvisit( BasicType * ) {
    107                 result = objectCast( dest, env, indexer );
    108         }
    109 
    110         void PtrsCastable_old::postvisit( PointerType * ) {
    111                 result = objectCast( dest, env, indexer );
    112         }
    113 
    114         void PtrsCastable_old::postvisit( ArrayType * ) {
    115                 result = objectCast( dest, env, indexer );
    116         }
    117 
    118         void PtrsCastable_old::postvisit( FunctionType * ) {
     102        void PtrsCastable_old::postvisit( const VoidType * ) {
     103                result = objectCast( dest, env, indexer );
     104        }
     105
     106        void PtrsCastable_old::postvisit( const BasicType * ) {
     107                result = objectCast( dest, env, indexer );
     108        }
     109
     110        void PtrsCastable_old::postvisit( const PointerType * ) {
     111                result = objectCast( dest, env, indexer );
     112        }
     113
     114        void PtrsCastable_old::postvisit( const ArrayType * ) {
     115                result = objectCast( dest, env, indexer );
     116        }
     117
     118        void PtrsCastable_old::postvisit( const FunctionType * ) {
    119119                // result = -1;
    120120                result = functionCast( dest, env, indexer );
    121121        }
    122122
    123         void PtrsCastable_old::postvisit( StructInstType * ) {
    124                 result = objectCast( dest, env, indexer );
    125         }
    126 
    127         void PtrsCastable_old::postvisit( UnionInstType * ) {
    128                 result = objectCast( dest, env, indexer );
    129         }
    130 
    131         void PtrsCastable_old::postvisit( EnumInstType * ) {
    132                 if ( dynamic_cast< EnumInstType* >( dest ) ) {
     123        void PtrsCastable_old::postvisit( const StructInstType * ) {
     124                result = objectCast( dest, env, indexer );
     125        }
     126
     127        void PtrsCastable_old::postvisit( const UnionInstType * ) {
     128                result = objectCast( dest, env, indexer );
     129        }
     130
     131        void PtrsCastable_old::postvisit( const EnumInstType * ) {
     132                if ( dynamic_cast< const EnumInstType * >( dest ) ) {
    133133                        result = 1;
    134                 } else if ( BasicType *bt = dynamic_cast< BasicType* >( dest ) ) {
    135                         if ( bt->get_kind() == BasicType::SignedInt ) {
     134                } else if ( const BasicType * bt = dynamic_cast< const BasicType * >( dest ) ) {
     135                        if ( bt->kind == BasicType::SignedInt ) {
    136136                                result = 0;
    137137                        } else {
     
    143143        }
    144144
    145         void PtrsCastable_old::postvisit( TraitInstType * ) {}
    146 
    147         void PtrsCastable_old::postvisit(TypeInstType *inst ) {
     145        void PtrsCastable_old::postvisit( const TraitInstType * ) {}
     146
     147        void PtrsCastable_old::postvisit( const TypeInstType *inst ) {
    148148                //result = objectCast( inst, env, indexer ) > 0 && objectCast( dest, env, indexer ) > 0 ? 1 : -1;
    149149                result = objectCast( inst, env, indexer ) == objectCast( dest, env, indexer ) ? 1 : -1;
    150150        }
    151151
    152         void PtrsCastable_old::postvisit( TupleType * ) {
    153                 result = objectCast( dest, env, indexer );
    154         }
    155 
    156         void PtrsCastable_old::postvisit( VarArgsType * ) {
    157                 result = objectCast( dest, env, indexer );
    158         }
    159 
    160         void PtrsCastable_old::postvisit( ZeroType * ) {
    161                 result = objectCast( dest, env, indexer );
    162         }
    163 
    164         void PtrsCastable_old::postvisit( OneType * ) {
     152        void PtrsCastable_old::postvisit( const TupleType * ) {
     153                result = objectCast( dest, env, indexer );
     154        }
     155
     156        void PtrsCastable_old::postvisit( const VarArgsType * ) {
     157                result = objectCast( dest, env, indexer );
     158        }
     159
     160        void PtrsCastable_old::postvisit( const ZeroType * ) {
     161                result = objectCast( dest, env, indexer );
     162        }
     163
     164        void PtrsCastable_old::postvisit( const OneType * ) {
    165165                result = objectCast( dest, env, indexer );
    166166        }
     
    168168namespace {
    169169        // can this type be cast to an object (1 for yes, -1 for no)
    170         int objectCast( 
    171                 const ast::Type * src, const ast::TypeEnvironment & env, const ast::SymbolTable & symtab 
     170        int objectCast(
     171                const ast::Type * src, const ast::TypeEnvironment & env, const ast::SymbolTable & symtab
    172172        ) {
    173173                if ( dynamic_cast< const ast::FunctionType * >( src ) ) {
     
    191191
    192192        // can this type be cast to a function (inverse of objectCast)
    193         int functionCast( 
    194                 const ast::Type * src, const ast::TypeEnvironment & env, const ast::SymbolTable & symtab 
     193        int functionCast(
     194                const ast::Type * src, const ast::TypeEnvironment & env, const ast::SymbolTable & symtab
    195195        ) {
    196196                return -1 * objectCast( src, env, symtab );
     
    204204                int result;
    205205
    206                 PtrsCastable_new( 
     206                PtrsCastable_new(
    207207                        const ast::Type * d, const ast::TypeEnvironment & e, const ast::SymbolTable & syms )
    208208                : dst( d ), env( e ), symtab( syms ), result( 0 ) {}
     
    278278} // anonymous namespace
    279279
    280 int ptrsCastable( 
    281         const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab, 
    282         const ast::TypeEnvironment & env 
     280int ptrsCastable(
     281        const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab,
     282        const ast::TypeEnvironment & env
    283283) {
    284284        if ( auto inst = dynamic_cast< const ast::TypeInstType * >( dst ) ) {
  • src/ResolvExpr/Resolver.cc

    r302d84c2 rfce4e31  
    562562                // TODO: Replace *exception type with &exception type.
    563563                if ( throwStmt->get_expr() ) {
    564                         StructDecl * exception_decl =
    565                                 indexer.lookupStruct( "__cfaabi_ehm__base_exception_t" );
     564                        StructDecl * exception_decl = indexer.lookupMutableStruct( "__cfaabi_ehm__base_exception_t" );
    566565                        assert( exception_decl );
    567566                        Type * exceptType = new PointerType( noQualifiers, new StructInstType( noQualifiers, exception_decl ) );
     
    972971                /// Calls the CandidateFinder and finds the single best candidate
    973972                CandidateRef findUnfinishedKindExpression(
    974                         const ast::Expr * untyped, const ast::SymbolTable & symtab, const std::string & kind, 
     973                        const ast::Expr * untyped, const ast::SymbolTable & symtab, const std::string & kind,
    975974                        std::function<bool(const Candidate &)> pred = anyCandidate, ResolvMode mode = {}
    976975                ) {
     
    994993                        // produce invalid error if no candidates
    995994                        if ( candidates.empty() ) {
    996                                 SemanticError( untyped, 
    997                                         toString( "No reasonable alternatives for ", kind, (kind != "" ? " " : ""), 
     995                                SemanticError( untyped,
     996                                        toString( "No reasonable alternatives for ", kind, (kind != "" ? " " : ""),
    998997                                        "expression: ") );
    999998                        }
     
    10311030                        if ( winners.size() != 1 ) {
    10321031                                std::ostringstream stream;
    1033                                 stream << "Cannot choose between " << winners.size() << " alternatives for " 
     1032                                stream << "Cannot choose between " << winners.size() << " alternatives for "
    10341033                                        << kind << (kind != "" ? " " : "") << "expression\n";
    10351034                                ast::print( stream, untyped );
     
    10541053                struct StripCasts_new final {
    10551054                        const ast::Expr * postmutate( const ast::CastExpr * castExpr ) {
    1056                                 if ( 
    1057                                         castExpr->isGenerated 
    1058                                         && typesCompatible( castExpr->arg->result, castExpr->result ) 
     1055                                if (
     1056                                        castExpr->isGenerated
     1057                                        && typesCompatible( castExpr->arg->result, castExpr->result )
    10591058                                ) {
    10601059                                        // generated cast is the same type as its argument, remove it after keeping env
    1061                                         return ast::mutate_field( 
     1060                                        return ast::mutate_field(
    10621061                                                castExpr->arg.get(), &ast::Expr::env, castExpr->env );
    10631062                                }
     
    10881087
    10891088                /// Establish post-resolver invariants for expressions
    1090                 void finishExpr( 
    1091                         ast::ptr< ast::Expr > & expr, const ast::TypeEnvironment & env, 
     1089                void finishExpr(
     1090                        ast::ptr< ast::Expr > & expr, const ast::TypeEnvironment & env,
    10921091                        const ast::TypeSubstitution * oldenv = nullptr
    10931092                ) {
    10941093                        // set up new type substitution for expression
    1095                         ast::ptr< ast::TypeSubstitution > newenv = 
     1094                        ast::ptr< ast::TypeSubstitution > newenv =
    10961095                                 oldenv ? oldenv : new ast::TypeSubstitution{};
    10971096                        env.writeToSubstitution( *newenv.get_and_mutate() );
     
    11021101        } // anonymous namespace
    11031102
    1104                
     1103
    11051104        ast::ptr< ast::Expr > resolveInVoidContext(
    11061105                const ast::Expr * expr, const ast::SymbolTable & symtab, ast::TypeEnvironment & env
    11071106        ) {
    11081107                assertf( expr, "expected a non-null expression" );
    1109                
     1108
    11101109                // set up and resolve expression cast to void
    11111110                ast::CastExpr * untyped = new ast::CastExpr{ expr };
    1112                 CandidateRef choice = findUnfinishedKindExpression( 
     1111                CandidateRef choice = findUnfinishedKindExpression(
    11131112                        untyped, symtab, "", anyCandidate, ResolvMode::withAdjustment() );
    1114                
     1113
    11151114                // a cast expression has either 0 or 1 interpretations (by language rules);
    11161115                // if 0, an exception has already been thrown, and this code will not run
     
    11221121
    11231122        namespace {
    1124                 /// Resolve `untyped` to the expression whose candidate is the best match for a `void` 
     1123                /// Resolve `untyped` to the expression whose candidate is the best match for a `void`
    11251124                /// context.
    1126                 ast::ptr< ast::Expr > findVoidExpression( 
     1125                ast::ptr< ast::Expr > findVoidExpression(
    11271126                        const ast::Expr * untyped, const ast::SymbolTable & symtab
    11281127                ) {
     
    11341133                }
    11351134
    1136                 /// resolve `untyped` to the expression whose candidate satisfies `pred` with the 
     1135                /// resolve `untyped` to the expression whose candidate satisfies `pred` with the
    11371136                /// lowest cost, returning the resolved version
    11381137                ast::ptr< ast::Expr > findKindExpression(
    1139                         const ast::Expr * untyped, const ast::SymbolTable & symtab, 
    1140                         std::function<bool(const Candidate &)> pred = anyCandidate, 
     1138                        const ast::Expr * untyped, const ast::SymbolTable & symtab,
     1139                        std::function<bool(const Candidate &)> pred = anyCandidate,
    11411140                        const std::string & kind = "", ResolvMode mode = {}
    11421141                ) {
    11431142                        if ( ! untyped ) return {};
    1144                         CandidateRef choice = 
     1143                        CandidateRef choice =
    11451144                                findUnfinishedKindExpression( untyped, symtab, kind, pred, mode );
    11461145                        finishExpr( choice->expr, choice->env, untyped->env );
     
    11491148
    11501149                /// Resolve `untyped` to the single expression whose candidate is the best match
    1151                 ast::ptr< ast::Expr > findSingleExpression( 
    1152                         const ast::Expr * untyped, const ast::SymbolTable & symtab 
     1150                ast::ptr< ast::Expr > findSingleExpression(
     1151                        const ast::Expr * untyped, const ast::SymbolTable & symtab
    11531152                ) {
    11541153                        return findKindExpression( untyped, symtab );
     
    11701169                bool hasIntegralType( const Candidate & i ) {
    11711170                        const ast::Type * type = i.expr->result;
    1172                        
     1171
    11731172                        if ( auto bt = dynamic_cast< const ast::BasicType * >( type ) ) {
    11741173                                return bt->isInteger();
    1175                         } else if ( 
    1176                                 dynamic_cast< const ast::EnumInstType * >( type ) 
     1174                        } else if (
     1175                                dynamic_cast< const ast::EnumInstType * >( type )
    11771176                                || dynamic_cast< const ast::ZeroType * >( type )
    11781177                                || dynamic_cast< const ast::OneType * >( type )
     
    11831182
    11841183                /// Resolve `untyped` as an integral expression, returning the resolved version
    1185                 ast::ptr< ast::Expr > findIntegralExpression( 
    1186                         const ast::Expr * untyped, const ast::SymbolTable & symtab 
     1184                ast::ptr< ast::Expr > findIntegralExpression(
     1185                        const ast::Expr * untyped, const ast::SymbolTable & symtab
    11871186                ) {
    11881187                        return findKindExpression( untyped, symtab, hasIntegralType, "condition" );
     
    11921191                bool isCharType( const ast::Type * t ) {
    11931192                        if ( auto bt = dynamic_cast< const ast::BasicType * >( t ) ) {
    1194                                 return bt->kind == ast::BasicType::Char 
    1195                                         || bt->kind == ast::BasicType::SignedChar 
     1193                                return bt->kind == ast::BasicType::Char
     1194                                        || bt->kind == ast::BasicType::SignedChar
    11961195                                        || bt->kind == ast::BasicType::UnsignedChar;
    11971196                        }
     
    12531252        }
    12541253
    1255         ast::ptr< ast::Init > resolveCtorInit( 
    1256                 const ast::ConstructorInit * ctorInit, const ast::SymbolTable & symtab 
     1254        ast::ptr< ast::Init > resolveCtorInit(
     1255                const ast::ConstructorInit * ctorInit, const ast::SymbolTable & symtab
    12571256        ) {
    12581257                assert( ctorInit );
     
    12611260        }
    12621261
    1263         ast::ptr< ast::Expr > resolveStmtExpr( 
    1264                 const ast::StmtExpr * stmtExpr, const ast::SymbolTable & symtab 
     1262        ast::ptr< ast::Expr > resolveStmtExpr(
     1263                const ast::StmtExpr * stmtExpr, const ast::SymbolTable & symtab
    12651264        ) {
    12661265                assert( stmtExpr );
     
    13031302
    13041303        void Resolver_new::previsit( const ast::ObjectDecl * objectDecl ) {
    1305                 // To handle initialization of routine pointers [e.g. int (*fp)(int) = foo()], 
    1306                 // class-variable `initContext` is changed multiple times because the LHS is analyzed 
    1307                 // twice. The second analysis changes `initContext` because a function type can contain 
    1308                 // object declarations in the return and parameter types. Therefore each value of 
    1309                 // `initContext` is retained so the type on the first analysis is preserved and used for 
     1304                // To handle initialization of routine pointers [e.g. int (*fp)(int) = foo()],
     1305                // class-variable `initContext` is changed multiple times because the LHS is analyzed
     1306                // twice. The second analysis changes `initContext` because a function type can contain
     1307                // object declarations in the return and parameter types. Therefore each value of
     1308                // `initContext` is retained so the type on the first analysis is preserved and used for
    13101309                // selecting the RHS.
    13111310                GuardValue( currentObject );
    13121311                currentObject = ast::CurrentObject{ objectDecl->location, objectDecl->get_type() };
    13131312                if ( inEnumDecl && dynamic_cast< const ast::EnumInstType * >( objectDecl->get_type() ) ) {
    1314                         // enumerator initializers should not use the enum type to initialize, since the 
     1313                        // enumerator initializers should not use the enum type to initialize, since the
    13151314                        // enum type is still incomplete at this point. Use `int` instead.
    1316                         currentObject = ast::CurrentObject{ 
     1315                        currentObject = ast::CurrentObject{
    13171316                                objectDecl->location, new ast::BasicType{ ast::BasicType::SignedInt } };
    13181317                }
     
    13251324        }
    13261325
    1327         const ast::StaticAssertDecl * Resolver_new::previsit( 
    1328                 const ast::StaticAssertDecl * assertDecl 
     1326        const ast::StaticAssertDecl * Resolver_new::previsit(
     1327                const ast::StaticAssertDecl * assertDecl
    13291328        ) {
    1330                 return ast::mutate_field( 
    1331                         assertDecl, &ast::StaticAssertDecl::cond, 
     1329                return ast::mutate_field(
     1330                        assertDecl, &ast::StaticAssertDecl::cond,
    13321331                        findIntegralExpression( assertDecl->cond, symtab ) );
    13331332        }
     
    13381337                        #warning should use new equivalent to Validate::SizeType rather than sizeType here
    13391338                        ast::ptr< ast::Type > sizeType = new ast::BasicType{ ast::BasicType::LongUnsignedInt };
    1340                         ast::mutate_field( 
    1341                                 type, &PtrType::dimension, 
     1339                        ast::mutate_field(
     1340                                type, &PtrType::dimension,
    13421341                                findSingleExpression( type->dimension, sizeType, symtab ) );
    13431342                }
     
    13561355                visit_children = false;
    13571356                assertf( exprStmt->expr, "ExprStmt has null expression in resolver" );
    1358                
    1359                 return ast::mutate_field( 
     1357
     1358                return ast::mutate_field(
    13601359                        exprStmt, &ast::ExprStmt::expr, findVoidExpression( exprStmt->expr, symtab ) );
    13611360        }
     
    13641363                visit_children = false;
    13651364
    1366                 asmExpr = ast::mutate_field( 
     1365                asmExpr = ast::mutate_field(
    13671366                        asmExpr, &ast::AsmExpr::operand, findVoidExpression( asmExpr->operand, symtab ) );
    1368                
     1367
    13691368                if ( asmExpr->inout ) {
    13701369                        asmExpr = ast::mutate_field(
    13711370                                asmExpr, &ast::AsmExpr::inout, findVoidExpression( asmExpr->inout, symtab ) );
    13721371                }
    1373                
     1372
    13741373                return asmExpr;
    13751374        }
     
    13881387
    13891388        const ast::WhileStmt * Resolver_new::previsit( const ast::WhileStmt * whileStmt ) {
    1390                 return ast::mutate_field( 
     1389                return ast::mutate_field(
    13911390                        whileStmt, &ast::WhileStmt::cond, findIntegralExpression( whileStmt->cond, symtab ) );
    13921391        }
     
    14091408                GuardValue( currentObject );
    14101409                switchStmt = ast::mutate_field(
    1411                         switchStmt, &ast::SwitchStmt::cond, 
     1410                        switchStmt, &ast::SwitchStmt::cond,
    14121411                        findIntegralExpression( switchStmt->cond, symtab ) );
    14131412                currentObject = ast::CurrentObject{ switchStmt->location, switchStmt->cond->result };
     
    14201419                        assertf( initAlts.size() == 1, "SwitchStmt did not correctly resolve an integral "
    14211420                                "expression." );
    1422                        
    1423                         ast::ptr< ast::Expr > untyped = 
     1421
     1422                        ast::ptr< ast::Expr > untyped =
    14241423                                new ast::CastExpr{ caseStmt->location, caseStmt->cond, initAlts.front().type };
    14251424                        ast::ptr< ast::Expr > newExpr = findSingleExpression( untyped, symtab );
    1426                        
    1427                         // case condition cannot have a cast in C, so it must be removed here, regardless of 
     1425
     1426                        // case condition cannot have a cast in C, so it must be removed here, regardless of
    14281427                        // whether it would perform a conversion.
    14291428                        if ( const ast::CastExpr * castExpr = newExpr.as< ast::CastExpr >() ) {
    14301429                                swap_and_save_env( newExpr, castExpr->arg );
    14311430                        }
    1432                        
     1431
    14331432                        caseStmt = ast::mutate_field( caseStmt, &ast::CaseStmt::cond, newExpr );
    14341433                }
     
    14431442                        ast::ptr< ast::Type > target = new ast::PointerType{ new ast::VoidType{} };
    14441443                        branchStmt = ast::mutate_field(
    1445                                 branchStmt, &ast::BranchStmt::computedTarget, 
     1444                                branchStmt, &ast::BranchStmt::computedTarget,
    14461445                                findSingleExpression( branchStmt->computedTarget, target, symtab ) );
    14471446                }
     
    14531452                if ( returnStmt->expr ) {
    14541453                        returnStmt = ast::mutate_field(
    1455                                 returnStmt, &ast::ReturnStmt::expr, 
     1454                                returnStmt, &ast::ReturnStmt::expr,
    14561455                                findSingleExpression( returnStmt->expr, functionReturn, symtab ) );
    14571456                }
     
    14621461                visit_children = false;
    14631462                if ( throwStmt->expr ) {
    1464                         const ast::StructDecl * exceptionDecl = 
     1463                        const ast::StructDecl * exceptionDecl =
    14651464                                symtab.lookupStruct( "__cfaabi_ehm__base_exception_t" );
    14661465                        assert( exceptionDecl );
    1467                         ast::ptr< ast::Type > exceptType = 
     1466                        ast::ptr< ast::Type > exceptType =
    14681467                                new ast::PointerType{ new ast::StructInstType{ exceptionDecl } };
    14691468                        throwStmt = ast::mutate_field(
    1470                                 throwStmt, &ast::ThrowStmt::expr, 
     1469                                throwStmt, &ast::ThrowStmt::expr,
    14711470                                findSingleExpression( throwStmt->expr, exceptType, symtab ) );
    14721471                }
     
    14771476                if ( catchStmt->cond ) {
    14781477                        ast::ptr< ast::Type > boolType = new ast::BasicType{ ast::BasicType::Bool };
    1479                         catchStmt = ast::mutate_field( 
    1480                                 catchStmt, &ast::CatchStmt::cond, 
     1478                        catchStmt = ast::mutate_field(
     1479                                catchStmt, &ast::CatchStmt::cond,
    14811480                                findSingleExpression( catchStmt->cond, boolType, symtab ) );
    14821481                }
     
    15061505
    15071506                        if ( clause.target.args.empty() ) {
    1508                                 SemanticError( stmt->location, 
     1507                                SemanticError( stmt->location,
    15091508                                        "Waitfor clause must have at least one mutex parameter");
    15101509                        }
    15111510
    15121511                        // Find all alternatives for all arguments in canonical form
    1513                         std::vector< CandidateFinder > argFinders = 
     1512                        std::vector< CandidateFinder > argFinders =
    15141513                                funcFinder.findSubExprs( clause.target.args );
    1515                        
     1514
    15161515                        // List all combinations of arguments
    15171516                        std::vector< CandidateList > possibilities;
     
    15191518
    15201519                        // For every possible function:
    1521                         // * try matching the arguments to the parameters, not the other way around because 
     1520                        // * try matching the arguments to the parameters, not the other way around because
    15221521                        //   more arguments than parameters
    15231522                        CandidateList funcCandidates;
     
    15261525                        for ( CandidateRef & func : funcFinder.candidates ) {
    15271526                                try {
    1528                                         auto pointerType = dynamic_cast< const ast::PointerType * >( 
     1527                                        auto pointerType = dynamic_cast< const ast::PointerType * >(
    15291528                                                func->expr->result->stripReferences() );
    15301529                                        if ( ! pointerType ) {
    1531                                                 SemanticError( stmt->location, func->expr->result.get(), 
     1530                                                SemanticError( stmt->location, func->expr->result.get(),
    15321531                                                        "candidate not viable: not a pointer type\n" );
    15331532                                        }
     
    15351534                                        auto funcType = pointerType->base.as< ast::FunctionType >();
    15361535                                        if ( ! funcType ) {
    1537                                                 SemanticError( stmt->location, func->expr->result.get(), 
     1536                                                SemanticError( stmt->location, func->expr->result.get(),
    15381537                                                        "candidate not viable: not a function type\n" );
    15391538                                        }
     
    15441543
    15451544                                                if( ! nextMutex( param, paramEnd ) ) {
    1546                                                         SemanticError( stmt->location, funcType, 
     1545                                                        SemanticError( stmt->location, funcType,
    15471546                                                                "candidate function not viable: no mutex parameters\n");
    15481547                                                }
     
    15601559                                                        ast::AssertionSet need, have;
    15611560                                                        ast::TypeEnvironment resultEnv{ func->env };
    1562                                                         // Add all type variables as open so that those not used in the 
     1561                                                        // Add all type variables as open so that those not used in the
    15631562                                                        // parameter list are still considered open
    15641563                                                        resultEnv.add( funcType->forall );
     
    15801579                                                        unsigned n_mutex_param = 0;
    15811580
    1582                                                         // For every argument of its set, check if it matches one of the 
     1581                                                        // For every argument of its set, check if it matches one of the
    15831582                                                        // parameters. The order is important
    15841583                                                        for ( auto & arg : argsList ) {
     
    15871586                                                                        // We ran out of parameters but still have arguments.
    15881587                                                                        // This function doesn't match
    1589                                                                         SemanticError( stmt->location, funcType, 
     1588                                                                        SemanticError( stmt->location, funcType,
    15901589                                                                                toString("candidate function not viable: too many mutex "
    15911590                                                                                "arguments, expected ", n_mutex_param, "\n" ) );
     
    15941593                                                                ++n_mutex_param;
    15951594
    1596                                                                 // Check if the argument matches the parameter type in the current 
     1595                                                                // Check if the argument matches the parameter type in the current
    15971596                                                                // scope
    15981597                                                                ast::ptr< ast::Type > paramType = (*param)->get_type();
    1599                                                                 if ( 
    1600                                                                         ! unify( 
    1601                                                                                 arg->expr->result, paramType, resultEnv, need, have, open, 
    1602                                                                                 symtab ) 
     1598                                                                if (
     1599                                                                        ! unify(
     1600                                                                                arg->expr->result, paramType, resultEnv, need, have, open,
     1601                                                                                symtab )
    16031602                                                                ) {
    16041603                                                                        // Type doesn't match
     
    16271626                                                                } while ( nextMutex( param, paramEnd ) );
    16281627
    1629                                                                 // We ran out of arguments but still have parameters left; this 
     1628                                                                // We ran out of arguments but still have parameters left; this
    16301629                                                                // function doesn't match
    1631                                                                 SemanticError( stmt->location, funcType, 
     1630                                                                SemanticError( stmt->location, funcType,
    16321631                                                                        toString( "candidate function not viable: too few mutex "
    16331632                                                                        "arguments, expected ", n_mutex_param, "\n" ) );
     
    16571656                        // Make sure correct number of arguments
    16581657                        if( funcCandidates.empty() ) {
    1659                                 SemanticErrorException top( stmt->location, 
     1658                                SemanticErrorException top( stmt->location,
    16601659                                        "No alternatives for function in call to waitfor" );
    16611660                                top.append( errors );
     
    16641663
    16651664                        if( argsCandidates.empty() ) {
    1666                                 SemanticErrorException top( stmt->location, 
    1667                                         "No alternatives for arguments in call to waitfor" ); 
     1665                                SemanticErrorException top( stmt->location,
     1666                                        "No alternatives for arguments in call to waitfor" );
    16681667                                top.append( errors );
    16691668                                throw top;
     
    16711670
    16721671                        if( funcCandidates.size() > 1 ) {
    1673                                 SemanticErrorException top( stmt->location, 
     1672                                SemanticErrorException top( stmt->location,
    16741673                                        "Ambiguous function in call to waitfor" );
    16751674                                top.append( errors );
     
    16861685                        // build new clause
    16871686                        ast::WaitForStmt::Clause clause2;
    1688                        
     1687
    16891688                        clause2.target.func = funcCandidates.front()->expr;
    1690                        
     1689
    16911690                        clause2.target.args.reserve( clause.target.args.size() );
    16921691                        for ( auto arg : argsCandidates.front() ) {
     
    17081707                        ast::WaitForStmt::Timeout timeout2;
    17091708
    1710                         ast::ptr< ast::Type > target = 
     1709                        ast::ptr< ast::Type > target =
    17111710                                new ast::BasicType{ ast::BasicType::LongLongUnsignedInt };
    17121711                        timeout2.time = findSingleExpression( stmt->timeout.time, target, symtab );
     
    17401739        const ast::SingleInit * Resolver_new::previsit( const ast::SingleInit * singleInit ) {
    17411740                visit_children = false;
    1742                 // resolve initialization using the possibilities as determined by the `currentObject` 
     1741                // resolve initialization using the possibilities as determined by the `currentObject`
    17431742                // cursor.
    1744                 ast::ptr< ast::Expr > untyped = new ast::UntypedInitExpr{ 
     1743                ast::ptr< ast::Expr > untyped = new ast::UntypedInitExpr{
    17451744                        singleInit->location, singleInit->value, currentObject.getOptions() };
    17461745                ast::ptr<ast::Expr> newExpr = findSingleExpression( untyped, symtab );
     
    17511750
    17521751                // discard InitExpr wrapper and retain relevant pieces.
    1753                 // `initExpr` may have inferred params in the case where the expression specialized a 
    1754                 // function pointer, and newExpr may already have inferParams of its own, so a simple 
     1752                // `initExpr` may have inferred params in the case where the expression specialized a
     1753                // function pointer, and newExpr may already have inferParams of its own, so a simple
    17551754                // swap is not sufficient
    17561755                ast::Expr::InferUnion inferred = initExpr->inferred;
     
    17581757                newExpr.get_and_mutate()->inferred.splice( std::move(inferred) );
    17591758
    1760                 // get the actual object's type (may not exactly match what comes back from the resolver 
     1759                // get the actual object's type (may not exactly match what comes back from the resolver
    17611760                // due to conversions)
    17621761                const ast::Type * initContext = currentObject.getCurrentType();
     
    17701769                                if ( auto pt = newExpr->result.as< ast::PointerType >() ) {
    17711770                                        if ( isCharType( pt->base ) ) {
    1772                                                 // strip cast if we're initializing a char[] with a char* 
     1771                                                // strip cast if we're initializing a char[] with a char*
    17731772                                                // e.g. char x[] = "hello"
    17741773                                                if ( auto ce = newExpr.as< ast::CastExpr >() ) {
     
    17931792                assert( listInit->designations.size() == listInit->initializers.size() );
    17941793                for ( unsigned i = 0; i < listInit->designations.size(); ++i ) {
    1795                         // iterate designations and initializers in pairs, moving the cursor to the current 
     1794                        // iterate designations and initializers in pairs, moving the cursor to the current
    17961795                        // designated object and resolving the initializer against that object
    17971796                        listInit = ast::mutate_field_index(
    1798                                 listInit, &ast::ListInit::designations, i, 
     1797                                listInit, &ast::ListInit::designations, i,
    17991798                                currentObject.findNext( listInit->designations[i] ) );
    18001799                        listInit = ast::mutate_field_index(
     
    18181817                ctorInit = ast::mutate_field( ctorInit, &ast::ConstructorInit::init, nullptr );
    18191818
    1820                 // intrinsic single-parameter constructors and destructors do nothing. Since this was 
    1821                 // implicitly generated, there's no way for it to have side effects, so get rid of it to 
     1819                // intrinsic single-parameter constructors and destructors do nothing. Since this was
     1820                // implicitly generated, there's no way for it to have side effects, so get rid of it to
    18221821                // clean up generated code
    18231822                if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->ctor ) ) {
  • src/ResolvExpr/Unify.cc

    r302d84c2 rfce4e31  
    9797        bool unifyExact( Type *type1, Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, WidenMode widen, const SymTab::Indexer &indexer );
    9898
    99         bool unifyExact( 
    100                 const ast::Type * type1, const ast::Type * type2, ast::TypeEnvironment & env, 
    101                 ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open, 
     99        bool unifyExact(
     100                const ast::Type * type1, const ast::Type * type2, ast::TypeEnvironment & env,
     101                ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open,
    102102                WidenMode widen, const ast::SymbolTable & symtab );
    103103
     
    121121        }
    122122
    123         bool typesCompatible( 
    124                         const ast::Type * first, const ast::Type * second, const ast::SymbolTable & symtab, 
     123        bool typesCompatible(
     124                        const ast::Type * first, const ast::Type * second, const ast::SymbolTable & symtab,
    125125                        const ast::TypeEnvironment & env ) {
    126126                ast::TypeEnvironment newEnv;
     
    135135                findOpenVars( newSecond, open, closed, need, have, FirstOpen );
    136136
    137                 return unifyExact( 
     137                return unifyExact(
    138138                        newFirst, newSecond, newEnv, need, have, open, noWiden(), symtab );
    139139        }
    140140
    141         bool typesCompatibleIgnoreQualifiers( Type *first, Type *second, const SymTab::Indexer &indexer, const TypeEnvironment &env ) {
     141        bool typesCompatibleIgnoreQualifiers( const Type * first, const Type * second, const SymTab::Indexer &indexer, const TypeEnvironment &env ) {
    142142                TypeEnvironment newEnv;
    143143                OpenVarSet openVars;
     
    163163        }
    164164
    165         bool typesCompatibleIgnoreQualifiers( 
    166                         const ast::Type * first, const ast::Type * second, const ast::SymbolTable & symtab, 
     165        bool typesCompatibleIgnoreQualifiers(
     166                        const ast::Type * first, const ast::Type * second, const ast::SymbolTable & symtab,
    167167                        const ast::TypeEnvironment & env ) {
    168168                ast::TypeEnvironment newEnv;
    169169                ast::OpenVarSet open;
    170170                ast::AssertionSet need, have;
    171                
     171
    172172                ast::ptr<ast::Type> newFirst{ first }, newSecond{ second };
    173173                env.apply( newFirst );
     
    176176                reset_qualifiers( newSecond );
    177177
    178                 return unifyExact( 
     178                return unifyExact(
    179179                        newFirst, newSecond, newEnv, need, have, open, noWiden(), symtab );
    180180        }
     
    490490
    491491                        // sizes don't have to match if ttypes are involved; need to be more precise wrt where the ttype is to prevent errors
    492                         if ( 
    493                                         (flatFunc->parameters.size() == flatOther->parameters.size() && 
    494                                                 flatFunc->returnVals.size() == flatOther->returnVals.size()) 
    495                                         || flatFunc->isTtype() 
    496                                         || flatOther->isTtype() 
     492                        if (
     493                                        (flatFunc->parameters.size() == flatOther->parameters.size() &&
     494                                                flatFunc->returnVals.size() == flatOther->returnVals.size())
     495                                        || flatFunc->isTtype()
     496                                        || flatOther->isTtype()
    497497                        ) {
    498498                                if ( unifyDeclList( flatFunc->parameters.begin(), flatFunc->parameters.end(), flatOther->parameters.begin(), flatOther->parameters.end(), env, needAssertions, haveAssertions, openVars, indexer ) ) {
     
    711711                bool result;
    712712
    713                 Unify_new( 
    714                         const ast::Type * type2, ast::TypeEnvironment & env, ast::AssertionSet & need, 
    715                         ast::AssertionSet & have, const ast::OpenVarSet & open, WidenMode widen, 
     713                Unify_new(
     714                        const ast::Type * type2, ast::TypeEnvironment & env, ast::AssertionSet & need,
     715                        ast::AssertionSet & have, const ast::OpenVarSet & open, WidenMode widen,
    716716                        const ast::SymbolTable & symtab )
    717                 : type2(type2), tenv(env), need(need), have(have), open(open), widen(widen), 
     717                : type2(type2), tenv(env), need(need), have(have), open(open), widen(widen),
    718718                  symtab(symtab), result(false) {}
    719719
    720720                void previsit( const ast::Node * ) { visit_children = false; }
    721                
     721
    722722                void postvisit( const ast::VoidType * ) {
    723723                        result = dynamic_cast< const ast::VoidType * >( type2 );
     
    732732                void postvisit( const ast::PointerType * pointer ) {
    733733                        if ( auto pointer2 = dynamic_cast< const ast::PointerType * >( type2 ) ) {
    734                                 result = unifyExact( 
    735                                         pointer->base, pointer2->base, tenv, need, have, open, 
     734                                result = unifyExact(
     735                                        pointer->base, pointer2->base, tenv, need, have, open,
    736736                                        noWiden(), symtab );
    737737                        }
     
    742742                        if ( ! array2 ) return;
    743743
    744                         // to unify, array types must both be VLA or both not VLA and both must have a 
     744                        // to unify, array types must both be VLA or both not VLA and both must have a
    745745                        // dimension expression or not have a dimension
    746746                        if ( array->isVarLen != array2->isVarLen ) return;
    747                         if ( ! array->isVarLen && ! array2->isVarLen 
     747                        if ( ! array->isVarLen && ! array2->isVarLen
    748748                                        && array->dimension && array2->dimension ) {
    749749                                auto ce1 = array->dimension.as< ast::ConstantExpr >();
     
    751751
    752752                                // see C11 Reference Manual 6.7.6.2.6
    753                                 // two array types with size specifiers that are integer constant expressions are 
     753                                // two array types with size specifiers that are integer constant expressions are
    754754                                // compatible if both size specifiers have the same constant value
    755755                                if ( ce1 && ce2 && ce1->intValue() != ce2->intValue() ) return;
    756756                        }
    757757
    758                         result = unifyExact( 
    759                                 array->base, array2->base, tenv, need, have, open, noWiden(), 
     758                        result = unifyExact(
     759                                array->base, array2->base, tenv, need, have, open, noWiden(),
    760760                                symtab );
    761761                }
     
    763763                void postvisit( const ast::ReferenceType * ref ) {
    764764                        if ( auto ref2 = dynamic_cast< const ast::ReferenceType * >( type2 ) ) {
    765                                 result = unifyExact( 
    766                                         ref->base, ref2->base, tenv, need, have, open, noWiden(), 
     765                                result = unifyExact(
     766                                        ref->base, ref2->base, tenv, need, have, open, noWiden(),
    767767                                        symtab );
    768768                        }
     
    771771        private:
    772772                /// Replaces ttype variables with their bound types.
    773                 /// If this isn't done when satifying ttype assertions, then argument lists can have 
     773                /// If this isn't done when satifying ttype assertions, then argument lists can have
    774774                /// different size and structure when they should be compatible.
    775775                struct TtypeExpander_new : public ast::WithShortCircuiting {
     
    800800                                auto types = flatten( d->get_type() );
    801801                                for ( ast::ptr< ast::Type > & t : types ) {
    802                                         // outermost const, volatile, _Atomic qualifiers in parameters should not play 
    803                                         // a role in the unification of function types, since they do not determine 
     802                                        // outermost const, volatile, _Atomic qualifiers in parameters should not play
     803                                        // a role in the unification of function types, since they do not determine
    804804                                        // whether a function is callable.
    805                                         // NOTE: **must** consider at least mutex qualifier, since functions can be 
    806                                         // overloaded on outermost mutex and a mutex function has different 
     805                                        // NOTE: **must** consider at least mutex qualifier, since functions can be
     806                                        // overloaded on outermost mutex and a mutex function has different
    807807                                        // requirements than a non-mutex function
    808808                                        remove_qualifiers( t, ast::CV::Const | ast::CV::Volatile | ast::CV::Atomic );
     
    818818                        std::vector< ast::ptr< ast::Type > > types;
    819819                        while ( crnt != end ) {
    820                                 // it is guaranteed that a ttype variable will be bound to a flat tuple, so ensure 
     820                                // it is guaranteed that a ttype variable will be bound to a flat tuple, so ensure
    821821                                // that this results in a flat tuple
    822822                                flatten( (*crnt)->get_type(), types );
     
    829829
    830830                template< typename Iter >
    831                 static bool unifyDeclList( 
    832                         Iter crnt1, Iter end1, Iter crnt2, Iter end2, ast::TypeEnvironment & env, 
    833                         ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open, 
     831                static bool unifyDeclList(
     832                        Iter crnt1, Iter end1, Iter crnt2, Iter end2, ast::TypeEnvironment & env,
     833                        ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open,
    834834                        const ast::SymbolTable & symtab
    835835                ) {
     
    843843                                if ( isTuple1 && ! isTuple2 ) {
    844844                                        // combine remainder of list2, then unify
    845                                         return unifyExact( 
    846                                                 t1, tupleFromDecls( crnt2, end2 ), env, need, have, open, 
     845                                        return unifyExact(
     846                                                t1, tupleFromDecls( crnt2, end2 ), env, need, have, open,
    847847                                                noWiden(), symtab );
    848848                                } else if ( ! isTuple1 && isTuple2 ) {
    849849                                        // combine remainder of list1, then unify
    850                                         return unifyExact( 
    851                                                 tupleFromDecls( crnt1, end1 ), t2, env, need, have, open, 
     850                                        return unifyExact(
     851                                                tupleFromDecls( crnt1, end1 ), t2, env, need, have, open,
    852852                                                noWiden(), symtab );
    853853                                }
    854854
    855                                 if ( ! unifyExact( 
    856                                         t1, t2, env, need, have, open, noWiden(), symtab ) 
     855                                if ( ! unifyExact(
     856                                        t1, t2, env, need, have, open, noWiden(), symtab )
    857857                                ) return false;
    858858
     
    860860                        }
    861861
    862                         // May get to the end of one argument list before the other. This is only okay if the 
     862                        // May get to the end of one argument list before the other. This is only okay if the
    863863                        // other is a ttype
    864864                        if ( crnt1 != end1 ) {
     
    866866                                const ast::Type * t1 = (*crnt1)->get_type();
    867867                                if ( ! Tuples::isTtype( t1 ) ) return false;
    868                                 return unifyExact( 
    869                                         t1, tupleFromDecls( crnt2, end2 ), env, need, have, open, 
     868                                return unifyExact(
     869                                        t1, tupleFromDecls( crnt2, end2 ), env, need, have, open,
    870870                                        noWiden(), symtab );
    871871                        } else if ( crnt2 != end2 ) {
     
    873873                                const ast::Type * t2 = (*crnt2)->get_type();
    874874                                if ( ! Tuples::isTtype( t2 ) ) return false;
    875                                 return unifyExact( 
    876                                         tupleFromDecls( crnt1, end1 ), t2, env, need, have, open, 
     875                                return unifyExact(
     876                                        tupleFromDecls( crnt1, end1 ), t2, env, need, have, open,
    877877                                        noWiden(), symtab );
    878878                        }
     
    881881                }
    882882
    883                 static bool unifyDeclList( 
    884                         const std::vector< ast::ptr< ast::DeclWithType > > & list1, 
    885                         const std::vector< ast::ptr< ast::DeclWithType > > & list2, 
    886                         ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have, 
     883                static bool unifyDeclList(
     884                        const std::vector< ast::ptr< ast::DeclWithType > > & list1,
     885                        const std::vector< ast::ptr< ast::DeclWithType > > & list2,
     886                        ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have,
    887887                        const ast::OpenVarSet & open, const ast::SymbolTable & symtab
    888888                ) {
    889                         return unifyDeclList( 
    890                                 list1.begin(), list1.end(), list2.begin(), list2.end(), env, need, have, open, 
     889                        return unifyDeclList(
     890                                list1.begin(), list1.end(), list2.begin(), list2.end(), env, need, have, open,
    891891                                symtab );
    892892                }
     
    900900
    901901                /// mark all assertions in `type` used in both `assn1` and `assn2`
    902                 static void markAssertions( 
    903                         ast::AssertionSet & assn1, ast::AssertionSet & assn2, 
    904                         const ast::ParameterizedType * type 
     902                static void markAssertions(
     903                        ast::AssertionSet & assn1, ast::AssertionSet & assn2,
     904                        const ast::ParameterizedType * type
    905905                ) {
    906906                        for ( const auto & tyvar : type->forall ) {
     
    918918
    919919                        if ( func->isVarArgs != func2->isVarArgs ) return;
    920                        
    921                         // Flatten the parameter lists for both functions so that tuple structure does not 
     920
     921                        // Flatten the parameter lists for both functions so that tuple structure does not
    922922                        // affect unification. Does not actually mutate function parameters.
    923923                        auto params = flattenList( func->params, tenv );
    924924                        auto params2 = flattenList( func2->params, tenv );
    925925
    926                         // sizes don't have to match if ttypes are involved; need to be more precise w.r.t. 
     926                        // sizes don't have to match if ttypes are involved; need to be more precise w.r.t.
    927927                        // where the ttype is to prevent errors
    928                         if ( 
     928                        if (
    929929                                ( params.size() != params2.size() || func->returns.size() != func2->returns.size() )
    930930                                && ! func->isTtype()
     
    933933
    934934                        if ( ! unifyDeclList( params, params2, tenv, need, have, open, symtab ) ) return;
    935                         if ( ! unifyDeclList( 
     935                        if ( ! unifyDeclList(
    936936                                func->returns, func2->returns, tenv, need, have, open, symtab ) ) return;
    937                        
     937
    938938                        markAssertions( have, need, func );
    939939                        markAssertions( have, need, func2 );
     
    941941                        result = true;
    942942                }
    943        
     943
    944944        private:
    945945                template< typename RefType >
     
    953953                /// Creates a tuple type based on a list of TypeExpr
    954954                template< typename Iter >
    955                 static const ast::Type * tupleFromExprs( 
     955                static const ast::Type * tupleFromExprs(
    956956                        const ast::TypeExpr * param, Iter & crnt, Iter end, ast::CV::Qualifiers qs
    957957                ) {
     
    973973                        const RefType * inst2 = handleRefType( inst, other );
    974974                        if ( ! inst2 ) return;
    975                        
     975
    976976                        // check that parameters of types unify, if any
    977977                        const std::vector< ast::ptr< ast::Expr > > & params = inst->params;
     
    10021002                                }
    10031003
    1004                                 if ( ! unifyExact( 
     1004                                if ( ! unifyExact(
    10051005                                                pty, pty2, tenv, need, have, open, noWiden(), symtab ) ) {
    10061006                                        result = false;
     
    10381038        private:
    10391039                /// Creates a tuple type based on a list of Type
    1040                 static ast::ptr< ast::Type > tupleFromTypes( 
     1040                static ast::ptr< ast::Type > tupleFromTypes(
    10411041                        const std::vector< ast::ptr< ast::Type > > & tys
    10421042                ) {
    10431043                        std::vector< ast::ptr< ast::Type > > out;
    10441044                        for ( const ast::Type * ty : tys ) {
    1045                                 // it is guaranteed that a ttype variable will be bound to a flat tuple, so ensure 
     1045                                // it is guaranteed that a ttype variable will be bound to a flat tuple, so ensure
    10461046                                // that this results in a flat tuple
    10471047                                flatten( ty, out );
     
    10511051                }
    10521052
    1053                 static bool unifyList( 
    1054                         const std::vector< ast::ptr< ast::Type > > & list1, 
    1055                         const std::vector< ast::ptr< ast::Type > > & list2, ast::TypeEnvironment & env, 
    1056                         ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open, 
     1053                static bool unifyList(
     1054                        const std::vector< ast::ptr< ast::Type > > & list1,
     1055                        const std::vector< ast::ptr< ast::Type > > & list2, ast::TypeEnvironment & env,
     1056                        ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open,
    10571057                        const ast::SymbolTable & symtab
    10581058                ) {
     
    10681068                                if ( isTuple1 && ! isTuple2 ) {
    10691069                                        // combine entirety of list2, then unify
    1070                                         return unifyExact( 
    1071                                                 t1, tupleFromTypes( list2 ), env, need, have, open, 
     1070                                        return unifyExact(
     1071                                                t1, tupleFromTypes( list2 ), env, need, have, open,
    10721072                                                noWiden(), symtab );
    10731073                                } else if ( ! isTuple1 && isTuple2 ) {
    10741074                                        // combine entirety of list1, then unify
    10751075                                        return unifyExact(
    1076                                                 tupleFromTypes( list1 ), t2, env, need, have, open, 
     1076                                                tupleFromTypes( list1 ), t2, env, need, have, open,
    10771077                                                noWiden(), symtab );
    10781078                                }
    10791079
    1080                                 if ( ! unifyExact( 
    1081                                         t1, t2, env, need, have, open, noWiden(), symtab ) 
     1080                                if ( ! unifyExact(
     1081                                        t1, t2, env, need, have, open, noWiden(), symtab )
    10821082                                ) return false;
    10831083
     
    10891089                                const ast::Type * t1 = *crnt1;
    10901090                                if ( ! Tuples::isTtype( t1 ) ) return false;
    1091                                 // xxx - this doesn't generate an empty tuple, contrary to comment; both ported 
     1091                                // xxx - this doesn't generate an empty tuple, contrary to comment; both ported
    10921092                                // from Rob's code
    1093                                 return unifyExact( 
    1094                                                 t1, tupleFromTypes( list2 ), env, need, have, open, 
     1093                                return unifyExact(
     1094                                                t1, tupleFromTypes( list2 ), env, need, have, open,
    10951095                                                noWiden(), symtab );
    10961096                        } else if ( crnt2 != list2.end() ) {
     
    10981098                                const ast::Type * t2 = *crnt2;
    10991099                                if ( ! Tuples::isTtype( t2 ) ) return false;
    1100                                 // xxx - this doesn't generate an empty tuple, contrary to comment; both ported 
     1100                                // xxx - this doesn't generate an empty tuple, contrary to comment; both ported
    11011101                                // from Rob's code
    11021102                                return unifyExact(
    1103                                                 tupleFromTypes( list1 ), t2, env, need, have, open, 
     1103                                                tupleFromTypes( list1 ), t2, env, need, have, open,
    11041104                                                noWiden(), symtab );
    11051105                        }
     
    11331133                void postvisit( const ast::OneType * ) {
    11341134                        result = dynamic_cast< const ast::OneType * >( type2 );
    1135                 }       
     1135                }
    11361136
    11371137          private:
     
    11401140        };
    11411141
    1142         bool unify( 
    1143                         const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2, 
    1144                         ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have, 
     1142        bool unify(
     1143                        const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2,
     1144                        ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have,
    11451145                        ast::OpenVarSet & open, const ast::SymbolTable & symtab
    11461146        ) {
     
    11491149        }
    11501150
    1151         bool unify( 
    1152                         const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2, 
    1153                         ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have, 
    1154                         ast::OpenVarSet & open, const ast::SymbolTable & symtab, ast::ptr<ast::Type> & common 
     1151        bool unify(
     1152                        const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2,
     1153                        ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have,
     1154                        ast::OpenVarSet & open, const ast::SymbolTable & symtab, ast::ptr<ast::Type> & common
    11551155        ) {
    11561156                ast::OpenVarSet closed;
    11571157                findOpenVars( type1, open, closed, need, have, FirstClosed );
    11581158                findOpenVars( type2, open, closed, need, have, FirstOpen );
    1159                 return unifyInexact( 
     1159                return unifyInexact(
    11601160                        type1, type2, env, need, have, open, WidenMode{ true, true }, symtab, common );
    11611161        }
    11621162
    1163         bool unifyExact( 
    1164                         const ast::Type * type1, const ast::Type * type2, ast::TypeEnvironment & env, 
    1165                         ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open, 
     1163        bool unifyExact(
     1164                        const ast::Type * type1, const ast::Type * type2, ast::TypeEnvironment & env,
     1165                        ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open,
    11661166                        WidenMode widen, const ast::SymbolTable & symtab
    11671167        ) {
     
    11701170                auto var1 = dynamic_cast< const ast::TypeInstType * >( type1 );
    11711171                auto var2 = dynamic_cast< const ast::TypeInstType * >( type2 );
    1172                 ast::OpenVarSet::const_iterator 
    1173                         entry1 = var1 ? open.find( var1->name ) : open.end(), 
     1172                ast::OpenVarSet::const_iterator
     1173                        entry1 = var1 ? open.find( var1->name ) : open.end(),
    11741174                        entry2 = var2 ? open.find( var2->name ) : open.end();
    11751175                bool isopen1 = entry1 != open.end();
     
    11781178                if ( isopen1 && isopen2 ) {
    11791179                        if ( entry1->second.kind != entry2->second.kind ) return false;
    1180                         return env.bindVarToVar( 
    1181                                 var1, var2, ast::TypeDecl::Data{ entry1->second, entry2->second }, need, have, 
     1180                        return env.bindVarToVar(
     1181                                var1, var2, ast::TypeDecl::Data{ entry1->second, entry2->second }, need, have,
    11821182                                open, widen, symtab );
    11831183                } else if ( isopen1 ) {
     
    11921192        }
    11931193
    1194         bool unifyInexact( 
    1195                         const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2, 
    1196                         ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have, 
    1197                         const ast::OpenVarSet & open, WidenMode widen, const ast::SymbolTable & symtab, 
    1198                         ast::ptr<ast::Type> & common 
     1194        bool unifyInexact(
     1195                        const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2,
     1196                        ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have,
     1197                        const ast::OpenVarSet & open, WidenMode widen, const ast::SymbolTable & symtab,
     1198                        ast::ptr<ast::Type> & common
    11991199        ) {
    12001200                ast::CV::Qualifiers q1 = type1->qualifiers, q2 = type2->qualifiers;
    1201                
    1202                 // force t1 and t2 to be cloned if their qualifiers must be stripped, so that type1 and 
     1201
     1202                // force t1 and t2 to be cloned if their qualifiers must be stripped, so that type1 and
    12031203                // type2 are left unchanged; calling convention forces type{1,2}->strong_ref >= 1
    12041204                ast::ptr<ast::Type> t1{ type1 }, t2{ type2 };
    12051205                reset_qualifiers( t1 );
    12061206                reset_qualifiers( t2 );
    1207                
     1207
    12081208                if ( unifyExact( t1, t2, env, need, have, open, widen, symtab ) ) {
    12091209                        t1 = nullptr; t2 = nullptr; // release t1, t2 to avoid spurious clones
  • src/ResolvExpr/typeops.h

    r302d84c2 rfce4e31  
    7373
    7474        /// Replaces array types with equivalent pointer, and function types with a pointer-to-function
    75         const ast::Type * adjustExprType( 
     75        const ast::Type * adjustExprType(
    7676                const ast::Type * type, const ast::TypeEnvironment & env, const ast::SymbolTable & symtab );
    7777
    7878        // in CastCost.cc
    79         Cost castCost( Type *src, Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env );
    80         Cost castCost( 
    81                 const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab, 
     79        Cost castCost( const Type * src, const Type * dest, const SymTab::Indexer &indexer, const TypeEnvironment &env );
     80        Cost castCost(
     81                const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab,
    8282                const ast::TypeEnvironment & env );
    8383
    8484        // in ConversionCost.cc
    85         Cost conversionCost( Type *src, Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env );
    86         Cost conversionCost( 
    87                 const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab, 
     85        Cost conversionCost( const Type *src, const Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env );
     86        Cost conversionCost(
     87                const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab,
    8888                const ast::TypeEnvironment & env );
    8989
    9090        // in AlternativeFinder.cc
    91         Cost computeConversionCost( Type *actualType, Type *formalType, 
     91        Cost computeConversionCost( Type *actualType, Type *formalType,
    9292                const SymTab::Indexer &indexer, const TypeEnvironment &env );
    9393
    9494        // in PtrsAssignable.cc
    95         int ptrsAssignable( Type *src, Type *dest, const TypeEnvironment &env );
     95        int ptrsAssignable( const Type * src, const Type * dest, const TypeEnvironment &env );
    9696        int ptrsAssignable( const ast::Type * src, const ast::Type * dst,
    9797                const ast::TypeEnvironment & env );
    9898
    9999        // in PtrsCastable.cc
    100         int ptrsCastable( Type *src, Type *dest, const TypeEnvironment &env, const SymTab::Indexer &indexer );
    101         int ptrsCastable( 
    102                 const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab, 
     100        int ptrsCastable( const Type * src, const Type * dest, const TypeEnvironment &env, const SymTab::Indexer &indexer );
     101        int ptrsCastable(
     102                const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab,
    103103                const ast::TypeEnvironment & env );
    104104
    105105        // in Unify.cc
    106106        bool typesCompatible( Type *, Type *, const SymTab::Indexer &indexer, const TypeEnvironment &env );
    107         bool typesCompatibleIgnoreQualifiers( Type *, Type *, const SymTab::Indexer &indexer, const TypeEnvironment &env );
     107        bool typesCompatibleIgnoreQualifiers( const Type *, const Type *, const SymTab::Indexer &indexer, const TypeEnvironment &env );
    108108
    109109        inline bool typesCompatible( Type *t1, Type *t2, const SymTab::Indexer &indexer ) {
     
    112112        }
    113113
    114         inline bool typesCompatibleIgnoreQualifiers( Type *t1, Type *t2, const SymTab::Indexer &indexer ) {
     114        inline bool typesCompatibleIgnoreQualifiers( const Type * t1, const Type * t2, const SymTab::Indexer &indexer ) {
    115115                TypeEnvironment env;
    116116                return typesCompatibleIgnoreQualifiers( t1, t2, indexer, env );
    117117        }
    118118
    119         bool typesCompatible( 
    120                 const ast::Type *, const ast::Type *, const ast::SymbolTable & symtab = {}, 
     119        bool typesCompatible(
     120                const ast::Type *, const ast::Type *, const ast::SymbolTable & symtab = {},
    121121                const ast::TypeEnvironment & env = {} );
    122        
     122
    123123        bool typesCompatibleIgnoreQualifiers(
    124                 const ast::Type *, const ast::Type *, const ast::SymbolTable &, 
     124                const ast::Type *, const ast::Type *, const ast::SymbolTable &,
    125125                const ast::TypeEnvironment & env = {} );
    126126
     
    133133        Type * commonType( Type *type1, Type *type2, bool widenFirst, bool widenSecond, const SymTab::Indexer &indexer, TypeEnvironment &env, const OpenVarSet &openVars );
    134134        ast::ptr< ast::Type > commonType(
    135                 const ast::ptr< ast::Type > & type1, const ast::ptr< ast::Type > & type2, WidenMode widen, 
     135                const ast::ptr< ast::Type > & type1, const ast::ptr< ast::Type > & type2, WidenMode widen,
    136136                const ast::SymbolTable & symtab, ast::TypeEnvironment & env, const ast::OpenVarSet & open );
    137137
    138138        // in PolyCost.cc
    139139        int polyCost( Type *type, const TypeEnvironment &env, const SymTab::Indexer &indexer );
    140         int polyCost( 
     140        int polyCost(
    141141                const ast::Type * type, const ast::SymbolTable & symtab, const ast::TypeEnvironment & env );
    142142
     
    149149        // new AST version in TypeEnvironment.cpp (only place it was used in old AST)
    150150
    151         template<typename Iter> 
     151        template<typename Iter>
    152152        bool occursIn( Type* ty, Iter begin, Iter end, const TypeEnvironment &env ) {
    153153                while ( begin != end ) {
     
    176176
    177177        /// flatten tuple type into existing list of types
    178         static inline void flatten( 
    179                 const ast::Type * type, std::vector< ast::ptr< ast::Type > > & out 
     178        static inline void flatten(
     179                const ast::Type * type, std::vector< ast::ptr< ast::Type > > & out
    180180        ) {
    181                 if ( auto tupleType = dynamic_cast< const ast::TupleType * >( type ) ) {       
     181                if ( auto tupleType = dynamic_cast< const ast::TupleType * >( type ) ) {
    182182                        for ( const ast::Type * t : tupleType->types ) {
    183183                                flatten( t, out );
  • src/SymTab/Indexer.cc

    r302d84c2 rfce4e31  
    7474        }
    7575
    76         Indexer::Indexer() 
    77         : idTable(), typeTable(), structTable(), enumTable(), unionTable(), traitTable(), 
    78           prevScope(), scope( 0 ), repScope( 0 ) { ++*stats().count; }
     76        Indexer::Indexer()
     77        : idTable(), typeTable(), structTable(), enumTable(), unionTable(), traitTable(),
     78          prevScope(), scope( 0 ), repScope( 0 ) { ++* stats().count; }
    7979
    8080        Indexer::~Indexer() {
     
    8484        void Indexer::lazyInitScope() {
    8585                if ( repScope < scope ) {
    86                         ++*stats().lazy_scopes;
     86                        ++* stats().lazy_scopes;
    8787                        // create rollback
    88                         prevScope = std::make_shared<Indexer>( *this );
     88                        prevScope = std::make_shared<Indexer>( * this );
    8989                        // update repScope
    9090                        repScope = scope;
     
    9595                ++scope;
    9696
    97                 ++*stats().new_scopes;
     97                ++* stats().new_scopes;
    9898                stats().avg_scope_depth->push( scope );
    9999                stats().max_scope_depth->push( scope );
     
    103103                if ( repScope == scope ) {
    104104                        Ptr prev = prevScope;           // make sure prevScope stays live
    105                         *this = std::move(*prevScope);  // replace with previous scope
     105                        * this = std::move(* prevScope);  // replace with previous scope
    106106                }
    107107
     
    109109        }
    110110
    111         void Indexer::lookupId( const std::string &id, std::list< IdData > &out ) const {
    112                 ++*stats().lookup_calls;
     111        void Indexer::lookupId( const std::string & id, std::list< IdData > &out ) const {
     112                ++* stats().lookup_calls;
    113113                if ( ! idTable ) return;
    114114
    115                 ++*stats().map_lookups;
     115                ++* stats().map_lookups;
    116116                auto decls = idTable->find( id );
    117117                if ( decls == idTable->end() ) return;
     
    122122        }
    123123
    124         NamedTypeDecl *Indexer::lookupType( const std::string &id ) const {
    125                 ++*stats().lookup_calls;
     124        const NamedTypeDecl * Indexer::lookupType( const std::string & id ) const { return lookupMutableType(id); }
     125        NamedTypeDecl * Indexer::lookupMutableType( const std::string & id ) const {
     126                ++* stats().lookup_calls;
    126127                if ( ! typeTable ) return nullptr;
    127                 ++*stats().map_lookups;
     128                ++* stats().map_lookups;
    128129                auto it = typeTable->find( id );
    129130                return it == typeTable->end() ? nullptr : it->second.decl;
    130131        }
    131132
    132         StructDecl *Indexer::lookupStruct( const std::string &id ) const {
    133                 ++*stats().lookup_calls;
     133        const StructDecl * Indexer::lookupStruct( const std::string & id ) const { return lookupMutableStruct(id); }
     134        StructDecl * Indexer::lookupMutableStruct( const std::string & id ) const {
     135                ++* stats().lookup_calls;
    134136                if ( ! structTable ) return nullptr;
    135                 ++*stats().map_lookups;
     137                ++* stats().map_lookups;
    136138                auto it = structTable->find( id );
    137139                return it == structTable->end() ? nullptr : it->second.decl;
    138140        }
    139141
    140         EnumDecl *Indexer::lookupEnum( const std::string &id ) const {
    141                 ++*stats().lookup_calls;
     142        const EnumDecl * Indexer::lookupEnum( const std::string & id ) const { return lookupMutableEnum(id); }
     143        EnumDecl * Indexer::lookupMutableEnum( const std::string & id ) const {
     144                ++* stats().lookup_calls;
    142145                if ( ! enumTable ) return nullptr;
    143                 ++*stats().map_lookups;
     146                ++* stats().map_lookups;
    144147                auto it = enumTable->find( id );
    145148                return it == enumTable->end() ? nullptr : it->second.decl;
    146149        }
    147150
    148         UnionDecl *Indexer::lookupUnion( const std::string &id ) const {
    149                 ++*stats().lookup_calls;
     151        const UnionDecl * Indexer::lookupUnion( const std::string & id ) const { return lookupMutableUnion(id); }
     152        UnionDecl * Indexer::lookupMutableUnion( const std::string & id ) const {
     153                ++* stats().lookup_calls;
    150154                if ( ! unionTable ) return nullptr;
    151                 ++*stats().map_lookups;
     155                ++* stats().map_lookups;
    152156                auto it = unionTable->find( id );
    153157                return it == unionTable->end() ? nullptr : it->second.decl;
    154158        }
    155159
    156         TraitDecl *Indexer::lookupTrait( const std::string &id ) const {
    157                 ++*stats().lookup_calls;
     160        const TraitDecl * Indexer::lookupTrait( const std::string & id ) const { return lookupMutableTrait(id); }
     161        TraitDecl * Indexer::lookupMutableTrait( const std::string & id ) const {
     162                ++* stats().lookup_calls;
    158163                if ( ! traitTable ) return nullptr;
    159                 ++*stats().map_lookups;
     164                ++* stats().map_lookups;
    160165                auto it = traitTable->find( id );
    161166                return it == traitTable->end() ? nullptr : it->second.decl;
    162167        }
    163168
    164         const Indexer* Indexer::atScope( unsigned long target ) const {
     169        const Indexer * Indexer::atScope( unsigned long target ) const {
    165170                // by lazy construction, final indexer in list has repScope 0, cannot be > target
    166171                // otherwise, will find first scope representing the target
    167                 const Indexer* indexer = this;
     172                const Indexer * indexer = this;
    168173                while ( indexer->repScope > target ) {
    169174                        indexer = indexer->prevScope.get();
     
    172177        }
    173178
    174         NamedTypeDecl *Indexer::globalLookupType( const std::string &id ) const {
     179        const NamedTypeDecl * Indexer::globalLookupType( const std::string & id ) const {
    175180                return atScope( 0 )->lookupType( id );
    176181        }
    177182
    178         StructDecl *Indexer::globalLookupStruct( const std::string &id ) const {
     183        const StructDecl * Indexer::globalLookupStruct( const std::string & id ) const {
    179184                return atScope( 0 )->lookupStruct( id );
    180185        }
    181186
    182         UnionDecl *Indexer::globalLookupUnion( const std::string &id ) const {
     187        const UnionDecl * Indexer::globalLookupUnion( const std::string & id ) const {
    183188                return atScope( 0 )->lookupUnion( id );
    184189        }
    185190
    186         EnumDecl *Indexer::globalLookupEnum( const std::string &id ) const {
     191        const EnumDecl * Indexer::globalLookupEnum( const std::string & id ) const {
    187192                return atScope( 0 )->lookupEnum( id );
    188193        }
     
    207212        }
    208213
    209        
    210         bool Indexer::addedIdConflicts( 
    211                         const Indexer::IdData & existing, DeclarationWithType *added,
     214
     215        bool Indexer::addedIdConflicts(
     216                        const Indexer::IdData & existing, DeclarationWithType * added,
    212217                        Indexer::OnConflict handleConflicts, BaseSyntaxNode * deleteStmt ) {
    213                 // if we're giving the same name mangling to things of different types then there is 
     218                // if we're giving the same name mangling to things of different types then there is
    214219                // something wrong
    215220                assert( (isObject( added ) && isObject( existing.id ) )
     
    219224                        // new definition shadows the autogenerated one, even at the same scope
    220225                        return false;
    221                 } else if ( LinkageSpec::isMangled( added->linkage ) 
    222                                 || ResolvExpr::typesCompatible( 
     226                } else if ( LinkageSpec::isMangled( added->linkage )
     227                                || ResolvExpr::typesCompatible(
    223228                                        added->get_type(), existing.id->get_type(), Indexer() ) ) {
    224229
     
    238243                        if ( isDefinition( added ) && isDefinition( existing.id ) ) {
    239244                                if ( handleConflicts.mode == OnConflict::Error ) {
    240                                         SemanticError( added, 
    241                                                 isFunction( added ) ? 
    242                                                         "duplicate function definition for " : 
     245                                        SemanticError( added,
     246                                                isFunction( added ) ?
     247                                                        "duplicate function definition for " :
    243248                                                        "duplicate object definition for " );
    244249                                }
     
    255260        }
    256261
    257         bool Indexer::hasCompatibleCDecl( const std::string &id, const std::string &mangleName ) const {
     262        bool Indexer::hasCompatibleCDecl( const std::string & id, const std::string &mangleName ) const {
    258263                if ( ! idTable ) return false;
    259264
    260                 ++*stats().map_lookups;
     265                ++* stats().map_lookups;
    261266                auto decls = idTable->find( id );
    262267                if ( decls == idTable->end() ) return false;
     
    270275                        }
    271276                }
    272                
     277
    273278                return false;
    274279        }
    275280
    276         bool Indexer::hasIncompatibleCDecl( 
    277                         const std::string &id, const std::string &mangleName ) const {
     281        bool Indexer::hasIncompatibleCDecl(
     282                        const std::string & id, const std::string &mangleName ) const {
    278283                if ( ! idTable ) return false;
    279284
    280                 ++*stats().map_lookups;
     285                ++* stats().map_lookups;
    281286                auto decls = idTable->find( id );
    282287                if ( decls == idTable->end() ) return false;
     
    295300
    296301        /// gets the base type of the first parameter; decl must be a ctor/dtor/assignment function
    297         std::string getOtypeKey( FunctionDecl* function ) {
     302        std::string getOtypeKey( FunctionDecl * function ) {
    298303                auto& params = function->type->parameters;
    299304                assert( ! params.empty() );
    300305                // use base type of pointer, so that qualifiers on the pointer type aren't considered.
    301                 Type* base = InitTweak::getPointerBase( params.front()->get_type() );
     306                Type * base = InitTweak::getPointerBase( params.front()->get_type() );
    302307                assert( base );
    303308                return Mangler::mangle( base );
    304309        }
    305310
    306         /// gets the declaration for the function acting on a type specified by otype key, 
     311        /// gets the declaration for the function acting on a type specified by otype key,
    307312        /// nullptr if none such
    308313        FunctionDecl * getFunctionForOtype( DeclarationWithType * decl, const std::string& otypeKey ) {
     
    312317        }
    313318
    314         bool Indexer::removeSpecialOverrides( 
     319        bool Indexer::removeSpecialOverrides(
    315320                        Indexer::IdData& data, Indexer::MangleTable::Ptr& mangleTable ) {
    316                 // if a type contains user defined ctor/dtor/assign, then special rules trigger, which 
    317                 // determinethe set of ctor/dtor/assign that can be used  by the requester. In particular, 
    318                 // if the user defines a default ctor, then the generated default ctor is unavailable, 
    319                 // likewise for copy ctor and dtor. If the user defines any ctor/dtor, then no generated 
    320                 // field ctors are available. If the user defines any ctor then the generated default ctor 
    321                 // is unavailable (intrinsic default ctor must be overridden exactly). If the user defines 
    322                 // anything that looks like a copy constructor, then the generated copy constructor is 
     321                // if a type contains user defined ctor/dtor/assign, then special rules trigger, which
     322                // determinethe set of ctor/dtor/assign that can be used  by the requester. In particular,
     323                // if the user defines a default ctor, then the generated default ctor is unavailable,
     324                // likewise for copy ctor and dtor. If the user defines any ctor/dtor, then no generated
     325                // field ctors are available. If the user defines any ctor then the generated default ctor
     326                // is unavailable (intrinsic default ctor must be overridden exactly). If the user defines
     327                // anything that looks like a copy constructor, then the generated copy constructor is
    323328                // unavailable, and likewise for the assignment operator.
    324329
     
    340345                        std::vector< MangleTable::value_type > deleted;
    341346                        bool alreadyUserDefinedFunc = false;
    342                        
    343                         for ( const auto& entry : *mangleTable ) {
     347
     348                        for ( const auto& entry : * mangleTable ) {
    344349                                // skip decls that aren't functions or are for the wrong type
    345350                                FunctionDecl * decl = getFunctionForOtype( entry.second.id, dataOtypeKey );
     
    368373                        // perform removals from mangle table, and deletions if necessary
    369374                        for ( const auto& key : removed ) {
    370                                 ++*stats().map_mutations;
     375                                ++* stats().map_mutations;
    371376                                mangleTable = mangleTable->erase( key );
    372377                        }
    373378                        if ( ! alreadyUserDefinedFunc ) for ( const auto& entry : deleted ) {
    374                                 ++*stats().map_mutations;
     379                                ++* stats().map_mutations;
    375380                                mangleTable = mangleTable->set( entry.first, IdData{ entry.second, function } );
    376381                        }
     
    379384                        // if this is the first user-defined function, delete non-user-defined overloads
    380385                        std::vector< MangleTable::value_type > deleted;
    381                        
    382                         for ( const auto& entry : *mangleTable ) {
     386
     387                        for ( const auto& entry : * mangleTable ) {
    383388                                // skip decls that aren't functions or are for the wrong type
    384389                                FunctionDecl * decl = getFunctionForOtype( entry.second.id, dataOtypeKey );
     
    402407                        // this needs to be a separate loop because of iterator invalidation
    403408                        for ( const auto& entry : deleted ) {
    404                                 ++*stats().map_mutations;
     409                                ++* stats().map_mutations;
    405410                                mangleTable = mangleTable->set( entry.first, IdData{ entry.second, function } );
    406411                        }
     
    408413                        // this is an overridable generated function
    409414                        // if there already exists a matching user-defined function, delete this appropriately
    410                         for ( const auto& entry : *mangleTable ) {
     415                        for ( const auto& entry : * mangleTable ) {
    411416                                // skip decls that aren't functions or are for the wrong type
    412417                                FunctionDecl * decl = getFunctionForOtype( entry.second.id, dataOtypeKey );
     
    418423                                if ( dataIsCopyFunc ) {
    419424                                        // remove current function if exists a user-defined copy function
    420                                         // since the signatures for copy functions don't need to match exactly, using 
     425                                        // since the signatures for copy functions don't need to match exactly, using
    421426                                        // a delete statement is the wrong approach
    422427                                        if ( InitTweak::isCopyFunction( decl, decl->name ) ) return false;
     
    428433                        }
    429434                }
    430                
     435
    431436                // nothing (more) to fix, return true
    432437                return true;
    433438        }
    434439
    435         void Indexer::addId( 
    436                         DeclarationWithType *decl, OnConflict handleConflicts, Expression * baseExpr,
     440        void Indexer::addId(
     441                        DeclarationWithType * decl, OnConflict handleConflicts, Expression * baseExpr,
    437442                        BaseSyntaxNode * deleteStmt ) {
    438                 ++*stats().add_calls;
     443                ++* stats().add_calls;
    439444                const std::string &name = decl->name;
    440445                if ( name == "" ) return;
    441                
     446
    442447                std::string mangleName;
    443448                if ( LinkageSpec::isOverridable( decl->linkage ) ) {
    444                         // mangle the name without including the appropriate suffix, so overridable routines 
     449                        // mangle the name without including the appropriate suffix, so overridable routines
    445450                        // are placed into the same "bucket" as their user defined versions.
    446451                        mangleName = Mangler::mangle( decl, false );
     
    449454                } // if
    450455
    451                 // this ensures that no two declarations with the same unmangled name at the same scope 
     456                // this ensures that no two declarations with the same unmangled name at the same scope
    452457                // both have C linkage
    453458                if ( LinkageSpec::isMangled( decl->linkage ) ) {
     
    457462                        }
    458463                } else {
    459                         // NOTE: only correct if name mangling is completely isomorphic to C 
     464                        // NOTE: only correct if name mangling is completely isomorphic to C
    460465                        // type-compatibility, which it may not be.
    461466                        if ( hasIncompatibleCDecl( name, mangleName ) ) {
     
    470475                        mangleTable = MangleTable::new_ptr();
    471476                } else {
    472                         ++*stats().map_lookups;
     477                        ++* stats().map_lookups;
    473478                        auto decls = idTable->find( name );
    474479                        if ( decls == idTable->end() ) {
     
    477482                                mangleTable = decls->second;
    478483                                // skip in-scope repeat declarations of same identifier
    479                                 ++*stats().map_lookups;
     484                                ++* stats().map_lookups;
    480485                                auto existing = mangleTable->find( mangleName );
    481486                                if ( existing != mangleTable->end()
     
    486491                                                        // set delete expression for conflicting identifier
    487492                                                        lazyInitScope();
    488                                                         *stats().map_mutations += 2;
     493                                                        * stats().map_mutations += 2;
    489494                                                        idTable = idTable->set(
    490495                                                                name,
    491                                                                 mangleTable->set( 
    492                                                                         mangleName, 
     496                                                                mangleTable->set(
     497                                                                        mangleName,
    493498                                                                        IdData{ existing->second, handleConflicts.deleteStmt } ) );
    494499                                                }
     
    504509                // Ensure that auto-generated ctor/dtor/assignment are deleted if necessary
    505510                if ( ! removeSpecialOverrides( data, mangleTable ) ) return;
    506                 *stats().map_mutations += 2;
     511                * stats().map_mutations += 2;
    507512                idTable = idTable->set( name, mangleTable->set( mangleName, std::move(data) ) );
    508513        }
     
    518523        }
    519524
    520         bool addedTypeConflicts( NamedTypeDecl *existing, NamedTypeDecl *added ) {
     525        bool addedTypeConflicts( NamedTypeDecl * existing, NamedTypeDecl * added ) {
    521526                if ( existing->base == nullptr ) {
    522527                        return false;
     
    530535                        }
    531536                }
    532                 // does not need to be added to the table if both existing and added have a base that are 
     537                // does not need to be added to the table if both existing and added have a base that are
    533538                // the same
    534539                return true;
    535540        }
    536541
    537         void Indexer::addType( NamedTypeDecl *decl ) {
    538                 ++*stats().add_calls;
    539                 const std::string &id = decl->name;
    540 
    541                 if ( ! typeTable ) { 
     542        void Indexer::addType( NamedTypeDecl * decl ) {
     543                ++* stats().add_calls;
     544                const std::string & id = decl->name;
     545
     546                if ( ! typeTable ) {
    542547                        typeTable = TypeTable::new_ptr();
    543548                } else {
    544                         ++*stats().map_lookups;
     549                        ++* stats().map_lookups;
    545550                        auto existing = typeTable->find( id );
    546                         if ( existing != typeTable->end() 
    547                                 && existing->second.scope == scope 
     551                        if ( existing != typeTable->end()
     552                                && existing->second.scope == scope
    548553                                && addedTypeConflicts( existing->second.decl, decl ) ) return;
    549554                }
    550                
     555
    551556                lazyInitScope();
    552                 ++*stats().map_mutations;
     557                ++* stats().map_mutations;
    553558                typeTable = typeTable->set( id, Scoped<NamedTypeDecl>{ decl, scope } );
    554559        }
    555560
    556         bool addedDeclConflicts( AggregateDecl *existing, AggregateDecl *added ) {
     561        bool addedDeclConflicts( AggregateDecl * existing, AggregateDecl * added ) {
    557562                if ( ! existing->body ) {
    558563                        return false;
     
    563568        }
    564569
    565         void Indexer::addStruct( const std::string &id ) {
     570        void Indexer::addStruct( const std::string & id ) {
    566571                addStruct( new StructDecl( id ) );
    567572        }
    568573
    569         void Indexer::addStruct( StructDecl *decl ) {
    570                 ++*stats().add_calls;
    571                 const std::string &id = decl->name;
     574        void Indexer::addStruct( StructDecl * decl ) {
     575                ++* stats().add_calls;
     576                const std::string & id = decl->name;
    572577
    573578                if ( ! structTable ) {
    574579                        structTable = StructTable::new_ptr();
    575580                } else {
    576                         ++*stats().map_lookups;
     581                        ++* stats().map_lookups;
    577582                        auto existing = structTable->find( id );
    578                         if ( existing != structTable->end() 
    579                                 && existing->second.scope == scope 
     583                        if ( existing != structTable->end()
     584                                && existing->second.scope == scope
    580585                                && addedDeclConflicts( existing->second.decl, decl ) ) return;
    581586                }
    582587
    583588                lazyInitScope();
    584                 ++*stats().map_mutations;
     589                ++* stats().map_mutations;
    585590                structTable = structTable->set( id, Scoped<StructDecl>{ decl, scope } );
    586591        }
    587592
    588         void Indexer::addEnum( EnumDecl *decl ) {
    589                 ++*stats().add_calls;
    590                 const std::string &id = decl->name;
     593        void Indexer::addEnum( EnumDecl * decl ) {
     594                ++* stats().add_calls;
     595                const std::string & id = decl->name;
    591596
    592597                if ( ! enumTable ) {
    593598                        enumTable = EnumTable::new_ptr();
    594599                } else {
    595                         ++*stats().map_lookups;
     600                        ++* stats().map_lookups;
    596601                        auto existing = enumTable->find( id );
    597                         if ( existing != enumTable->end() 
    598                                 && existing->second.scope == scope 
     602                        if ( existing != enumTable->end()
     603                                && existing->second.scope == scope
    599604                                && addedDeclConflicts( existing->second.decl, decl ) ) return;
    600605                }
    601                
     606
    602607                lazyInitScope();
    603                 ++*stats().map_mutations;
     608                ++* stats().map_mutations;
    604609                enumTable = enumTable->set( id, Scoped<EnumDecl>{ decl, scope } );
    605610        }
    606611
    607         void Indexer::addUnion( const std::string &id ) {
     612        void Indexer::addUnion( const std::string & id ) {
    608613                addUnion( new UnionDecl( id ) );
    609614        }
    610615
    611         void Indexer::addUnion( UnionDecl *decl ) {
    612                 ++*stats().add_calls;
    613                 const std::string &id = decl->name;
     616        void Indexer::addUnion( UnionDecl * decl ) {
     617                ++* stats().add_calls;
     618                const std::string & id = decl->name;
    614619
    615620                if ( ! unionTable ) {
    616621                        unionTable = UnionTable::new_ptr();
    617622                } else {
    618                         ++*stats().map_lookups;
     623                        ++* stats().map_lookups;
    619624                        auto existing = unionTable->find( id );
    620                         if ( existing != unionTable->end() 
    621                                 && existing->second.scope == scope 
     625                        if ( existing != unionTable->end()
     626                                && existing->second.scope == scope
    622627                                && addedDeclConflicts( existing->second.decl, decl ) ) return;
    623628                }
    624629
    625630                lazyInitScope();
    626                 ++*stats().map_mutations;
     631                ++* stats().map_mutations;
    627632                unionTable = unionTable->set( id, Scoped<UnionDecl>{ decl, scope } );
    628633        }
    629634
    630         void Indexer::addTrait( TraitDecl *decl ) {
    631                 ++*stats().add_calls;
    632                 const std::string &id = decl->name;
     635        void Indexer::addTrait( TraitDecl * decl ) {
     636                ++* stats().add_calls;
     637                const std::string & id = decl->name;
    633638
    634639                if ( ! traitTable ) {
    635640                        traitTable = TraitTable::new_ptr();
    636641                } else {
    637                         ++*stats().map_lookups;
     642                        ++* stats().map_lookups;
    638643                        auto existing = traitTable->find( id );
    639                         if ( existing != traitTable->end() 
    640                                 && existing->second.scope == scope 
     644                        if ( existing != traitTable->end()
     645                                && existing->second.scope == scope
    641646                                && addedDeclConflicts( existing->second.decl, decl ) ) return;
    642647                }
    643648
    644649                lazyInitScope();
    645                 ++*stats().map_mutations;
     650                ++* stats().map_mutations;
    646651                traitTable = traitTable->set( id, Scoped<TraitDecl>{ decl, scope } );
    647652        }
    648653
    649         void Indexer::addMembers( AggregateDecl * aggr, Expression * expr, 
     654        void Indexer::addMembers( AggregateDecl * aggr, Expression * expr,
    650655                        OnConflict handleConflicts ) {
    651656                for ( Declaration * decl : aggr->members ) {
     
    654659                                if ( dwt->name == "" ) {
    655660                                        Type * t = dwt->get_type()->stripReferences();
    656                                         if ( dynamic_cast<StructInstType*>( t ) || dynamic_cast<UnionInstType*>( t ) ) {
     661                                        if ( dynamic_cast<StructInstType *>( t ) || dynamic_cast<UnionInstType *>( t ) ) {
    657662                                                Expression * base = expr->clone();
    658663                                                ResolvExpr::Cost cost = ResolvExpr::Cost::zero; // xxx - carry this cost into the indexer as a base cost?
  • src/SymTab/Indexer.h

    r302d84c2 rfce4e31  
    3434                virtual ~Indexer();
    3535
    36                 // when using an indexer manually (e.g., within a mutator traversal), it is necessary to 
     36                // when using an indexer manually (e.g., within a mutator traversal), it is necessary to
    3737                // tell the indexer explicitly when scopes begin and end
    3838                void enterScope();
     
    5050                        // NOTE: shouldn't need either of these constructors, but gcc-4 does not properly support initializer lists with default members.
    5151                        IdData() = default;
    52                         IdData( 
     52                        IdData(
    5353                                DeclarationWithType * id, Expression * baseExpr, BaseSyntaxNode * deleteStmt,
    54                                 unsigned long scope ) 
     54                                unsigned long scope )
    5555                                : id( id ), baseExpr( baseExpr ), deleteStmt( deleteStmt ), scope( scope ) {}
    5656                        IdData( const IdData& o, BaseSyntaxNode * deleteStmt )
     
    6161
    6262                /// Gets all declarations with the given ID
    63                 void lookupId( const std::string &id, std::list< IdData > &out ) const;
     63                void lookupId( const std::string & id, std::list< IdData > &out ) const;
    6464                /// Gets the top-most type declaration with the given ID
    65                 NamedTypeDecl *lookupType( const std::string &id ) const;
     65                const NamedTypeDecl * lookupType( const std::string & id ) const;
     66                NamedTypeDecl * lookupMutableType( const std::string & id ) const;
    6667                /// Gets the top-most struct declaration with the given ID
    67                 StructDecl *lookupStruct( const std::string &id ) const;
     68                const StructDecl * lookupStruct( const std::string & id ) const;
     69                StructDecl * lookupMutableStruct( const std::string & id ) const;
    6870                /// Gets the top-most enum declaration with the given ID
    69                 EnumDecl *lookupEnum( const std::string &id ) const;
     71                const EnumDecl * lookupEnum( const std::string & id ) const;
     72                EnumDecl * lookupMutableEnum( const std::string & id ) const;
    7073                /// Gets the top-most union declaration with the given ID
    71                 UnionDecl *lookupUnion( const std::string &id ) const;
     74                const UnionDecl * lookupUnion( const std::string & id ) const;
     75                UnionDecl * lookupMutableUnion( const std::string & id ) const;
    7276                /// Gets the top-most trait declaration with the given ID
    73                 TraitDecl *lookupTrait( const std::string &id ) const;
     77                const TraitDecl * lookupTrait( const std::string & id ) const;
     78                TraitDecl * lookupMutableTrait( const std::string & id ) const;
    7479
    7580                /// Gets the type declaration with the given ID at global scope
    76                 NamedTypeDecl *globalLookupType( const std::string &id ) const;
     81                const NamedTypeDecl * globalLookupType( const std::string & id ) const;
    7782                /// Gets the struct declaration with the given ID at global scope
    78                 StructDecl *globalLookupStruct( const std::string &id ) const;
     83                const StructDecl * globalLookupStruct( const std::string & id ) const;
    7984                /// Gets the union declaration with the given ID at global scope
    80                 UnionDecl *globalLookupUnion( const std::string &id ) const;
     85                const UnionDecl * globalLookupUnion( const std::string & id ) const;
    8186                /// Gets the enum declaration with the given ID at global scope
    82                 EnumDecl *globalLookupEnum( const std::string &id ) const;
     87                const EnumDecl * globalLookupEnum( const std::string & id ) const;
    8388
    8489                void addId( DeclarationWithType * decl, Expression * baseExpr = nullptr );
    8590                void addDeletedId( DeclarationWithType * decl, BaseSyntaxNode * deleteStmt );
    8691
    87                 void addType( NamedTypeDecl *decl );
    88                 void addStruct( const std::string &id );
    89                 void addStruct( StructDecl *decl );
    90                 void addEnum( EnumDecl *decl );
    91                 void addUnion( const std::string &id );
    92                 void addUnion( UnionDecl *decl );
    93                 void addTrait( TraitDecl *decl );
     92                void addType( NamedTypeDecl * decl );
     93                void addStruct( const std::string & id );
     94                void addStruct( StructDecl * decl );
     95                void addEnum( EnumDecl * decl );
     96                void addUnion( const std::string & id );
     97                void addUnion( UnionDecl * decl );
     98                void addTrait( TraitDecl * decl );
    9499
    95100                /// adds all of the IDs from WithStmt exprs
     
    106111
    107112          private:
    108                 /// Wraps a Decl* with a scope
     113                /// Wraps a Decl * with a scope
    109114                template<typename Decl>
    110115                struct Scoped {
    111                         Decl* decl;           ///< declaration
     116                        Decl * decl;           ///< declaration
    112117                        unsigned long scope;  ///< scope of this declaration
    113118
    114                         Scoped(Decl* d, unsigned long s) : decl(d), scope(s) {}
     119                        Scoped(Decl * d, unsigned long s) : decl(d), scope(s) {}
    115120                };
    116121
     
    140145
    141146                /// Gets the indexer at the given scope
    142                 const Indexer* atScope( unsigned long scope ) const;
     147                const Indexer * atScope( unsigned long scope ) const;
    143148
    144                 /// Removes matching autogenerated constructors and destructors so that they will not be 
     149                /// Removes matching autogenerated constructors and destructors so that they will not be
    145150                /// selected. If returns false, passed decl should not be added.
    146151                bool removeSpecialOverrides( IdData& decl, MangleTable::Ptr& mangleTable );
     
    166171                /// true if the existing identifier conflicts with the added identifier
    167172                bool addedIdConflicts(
    168                         const IdData& existing, DeclarationWithType * added, OnConflict handleConflicts, 
     173                        const IdData& existing, DeclarationWithType * added, OnConflict handleConflicts,
    169174                        BaseSyntaxNode * deleteStmt );
    170175
    171176                /// common code for addId, addDeletedId, etc.
    172                 void addId( 
    173                         DeclarationWithType * decl, OnConflict handleConflicts, 
     177                void addId(
     178                        DeclarationWithType * decl, OnConflict handleConflicts,
    174179                        Expression * baseExpr = nullptr, BaseSyntaxNode * deleteStmt = nullptr );
    175180
     
    178183
    179184                /// returns true if there exists a declaration with C linkage and the given name with the same mangled name
    180                 bool hasCompatibleCDecl( const std::string &id, const std::string &mangleName ) const;
     185                bool hasCompatibleCDecl( const std::string & id, const std::string &mangleName ) const;
    181186                /// returns true if there exists a declaration with C linkage and the given name with a different mangled name
    182                 bool hasIncompatibleCDecl( const std::string &id, const std::string &mangleName ) const;
     187                bool hasIncompatibleCDecl( const std::string & id, const std::string &mangleName ) const;
    183188        };
    184189} // namespace SymTab
  • src/SymTab/Validate.cc

    r302d84c2 rfce4e31  
    119119
    120120          private:
    121                 template< typename AggDecl > void handleAggregate( AggDecl *aggregateDecl );
     121                template< typename AggDecl > void handleAggregate( AggDecl * aggregateDecl );
    122122
    123123                AggregateDecl * parentAggr = nullptr;
     
    134134        /// Replaces enum types by int, and function or array types in function parameter and return lists by appropriate pointers.
    135135        struct EnumAndPointerDecay_old {
    136                 void previsit( EnumDecl *aggregateDecl );
    137                 void previsit( FunctionType *func );
     136                void previsit( EnumDecl * aggregateDecl );
     137                void previsit( FunctionType * func );
    138138        };
    139139
    140140        /// Associates forward declarations of aggregates with their definitions
    141141        struct LinkReferenceToTypes_old final : public WithIndexer, public WithGuards, public WithVisitorRef<LinkReferenceToTypes_old>, public WithShortCircuiting {
    142                 LinkReferenceToTypes_old( const Indexer *indexer );
    143                 void postvisit( TypeInstType *typeInst );
    144 
    145                 void postvisit( EnumInstType *enumInst );
    146                 void postvisit( StructInstType *structInst );
    147                 void postvisit( UnionInstType *unionInst );
    148                 void postvisit( TraitInstType *traitInst );
     142                LinkReferenceToTypes_old( const Indexer * indexer );
     143                void postvisit( TypeInstType * typeInst );
     144
     145                void postvisit( EnumInstType * enumInst );
     146                void postvisit( StructInstType * structInst );
     147                void postvisit( UnionInstType * unionInst );
     148                void postvisit( TraitInstType * traitInst );
    149149                void previsit( QualifiedType * qualType );
    150150                void postvisit( QualifiedType * qualType );
    151151
    152                 void postvisit( EnumDecl *enumDecl );
    153                 void postvisit( StructDecl *structDecl );
    154                 void postvisit( UnionDecl *unionDecl );
     152                void postvisit( EnumDecl * enumDecl );
     153                void postvisit( StructDecl * structDecl );
     154                void postvisit( UnionDecl * unionDecl );
    155155                void postvisit( TraitDecl * traitDecl );
    156156
    157                 void previsit( StructDecl *structDecl );
    158                 void previsit( UnionDecl *unionDecl );
     157                void previsit( StructDecl * structDecl );
     158                void previsit( UnionDecl * unionDecl );
    159159
    160160                void renameGenericParams( std::list< TypeDecl * > & params );
    161161
    162162          private:
    163                 const Indexer *local_indexer;
     163                const Indexer * local_indexer;
    164164
    165165                typedef std::map< std::string, std::list< EnumInstType * > > ForwardEnumsType;
     
    239239
    240240                template<typename AggDecl>
    241                 void handleAggregate( AggDecl *aggregateDecl );
     241                void handleAggregate( AggDecl * aggregateDecl );
    242242
    243243                void previsit( StructDecl * aggregateDecl );
     
    252252                static void verify( std::list< Declaration * > &translationUnit );
    253253
    254                 void previsit( FunctionDecl *funcDecl );
     254                void previsit( FunctionDecl * funcDecl );
    255255        };
    256256
     
    287287                Type::StorageClasses storageClasses;
    288288
    289                 void premutate( ObjectDecl *objectDecl );
    290                 Expression * postmutate( CompoundLiteralExpr *compLitExpr );
     289                void premutate( ObjectDecl * objectDecl );
     290                Expression * postmutate( CompoundLiteralExpr * compLitExpr );
    291291        };
    292292
     
    393393        }
    394394
    395         void validateType( Type *type, const Indexer *indexer ) {
     395        void validateType( Type * type, const Indexer * indexer ) {
    396396                PassVisitor<EnumAndPointerDecay_old> epc;
    397397                PassVisitor<LinkReferenceToTypes_old> lrt( indexer );
     
    496496        }
    497497
    498         bool shouldHoist( Declaration *decl ) {
     498        bool shouldHoist( Declaration * decl ) {
    499499                return dynamic_cast< StructDecl * >( decl ) || dynamic_cast< UnionDecl * >( decl ) || dynamic_cast< StaticAssertDecl * >( decl );
    500500        }
     
    515515
    516516        template< typename AggDecl >
    517         void HoistStruct::handleAggregate( AggDecl *aggregateDecl ) {
     517        void HoistStruct::handleAggregate( AggDecl * aggregateDecl ) {
    518518                if ( parentAggr ) {
    519519                        aggregateDecl->parent = parentAggr;
     
    560560
    561561
    562         bool isTypedef( Declaration *decl ) {
     562        bool isTypedef( Declaration * decl ) {
    563563                return dynamic_cast< TypedefDecl * >( decl );
    564564        }
     
    571571
    572572        template< typename AggDecl >
    573         void EliminateTypedef::handleAggregate( AggDecl *aggregateDecl ) {
     573        void EliminateTypedef::handleAggregate( AggDecl * aggregateDecl ) {
    574574                filter( aggregateDecl->members, isTypedef, true );
    575575        }
     
    586586                // remove and delete decl stmts
    587587                filter( compoundStmt->kids, [](Statement * stmt) {
    588                         if ( DeclStmt *declStmt = dynamic_cast< DeclStmt * >( stmt ) ) {
     588                        if ( DeclStmt * declStmt = dynamic_cast< DeclStmt * >( stmt ) ) {
    589589                                if ( dynamic_cast< TypedefDecl * >( declStmt->decl ) ) {
    590590                                        return true;
     
    595595        }
    596596
    597         void EnumAndPointerDecay_old::previsit( EnumDecl *enumDecl ) {
     597        void EnumAndPointerDecay_old::previsit( EnumDecl * enumDecl ) {
    598598                // Set the type of each member of the enumeration to be EnumConstant
    599599                for ( std::list< Declaration * >::iterator i = enumDecl->members.begin(); i != enumDecl->members.end(); ++i ) {
    600                         ObjectDecl * obj = dynamic_cast< ObjectDecl * >( *i );
     600                        ObjectDecl * obj = dynamic_cast< ObjectDecl * >( * i );
    601601                        assert( obj );
    602602                        obj->set_type( new EnumInstType( Type::Qualifiers( Type::Const ), enumDecl->name ) );
     
    627627        }
    628628
    629         void EnumAndPointerDecay_old::previsit( FunctionType *func ) {
     629        void EnumAndPointerDecay_old::previsit( FunctionType * func ) {
    630630                // Fix up parameters and return types
    631631                fixFunctionList( func->parameters, func->isVarArgs, func );
     
    633633        }
    634634
    635         LinkReferenceToTypes_old::LinkReferenceToTypes_old( const Indexer *other_indexer ) {
     635        LinkReferenceToTypes_old::LinkReferenceToTypes_old( const Indexer * other_indexer ) {
    636636                if ( other_indexer ) {
    637637                        local_indexer = other_indexer;
     
    641641        }
    642642
    643         void LinkReferenceToTypes_old::postvisit( EnumInstType *enumInst ) {
    644                 EnumDecl *st = local_indexer->lookupEnum( enumInst->name );
     643        void LinkReferenceToTypes_old::postvisit( EnumInstType * enumInst ) {
     644                EnumDecl * st = local_indexer->lookupMutableEnum( enumInst->name );
    645645                // it's not a semantic error if the enum is not found, just an implicit forward declaration
    646646                if ( st ) {
     
    661661        }
    662662
    663         void LinkReferenceToTypes_old::postvisit( StructInstType *structInst ) {
    664                 StructDecl *st = local_indexer->lookupStruct( structInst->name );
     663        void LinkReferenceToTypes_old::postvisit( StructInstType * structInst ) {
     664                StructDecl * st = local_indexer->lookupMutableStruct( structInst->name );
    665665                // it's not a semantic error if the struct is not found, just an implicit forward declaration
    666666                if ( st ) {
     
    674674        }
    675675
    676         void LinkReferenceToTypes_old::postvisit( UnionInstType *unionInst ) {
    677                 UnionDecl *un = local_indexer->lookupUnion( unionInst->name );
     676        void LinkReferenceToTypes_old::postvisit( UnionInstType * unionInst ) {
     677                UnionDecl * un = local_indexer->lookupMutableUnion( unionInst->name );
    678678                // it's not a semantic error if the union is not found, just an implicit forward declaration
    679679                if ( un ) {
     
    693693        void LinkReferenceToTypes_old::postvisit( QualifiedType * qualType ) {
    694694                // linking only makes sense for the 'oldest ancestor' of the qualified type
    695                 qualType->parent->accept( *visitor );
     695                qualType->parent->accept( * visitor );
    696696        }
    697697
     
    762762        void LinkReferenceToTypes_old::postvisit( TraitInstType * traitInst ) {
    763763                // handle other traits
    764                 TraitDecl *traitDecl = local_indexer->lookupTrait( traitInst->name );
     764                TraitDecl * traitDecl = local_indexer->lookupMutableTrait( traitInst->name );
    765765                if ( ! traitDecl ) {
    766766                        SemanticError( traitInst->location, "use of undeclared trait " + traitInst->name );
     
    786786        }
    787787
    788         void LinkReferenceToTypes_old::postvisit( EnumDecl *enumDecl ) {
     788        void LinkReferenceToTypes_old::postvisit( EnumDecl * enumDecl ) {
    789789                // visit enum members first so that the types of self-referencing members are updated properly
    790790                if ( enumDecl->body ) {
     
    792792                        if ( fwds != forwardEnums.end() ) {
    793793                                for ( std::list< EnumInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {
    794                                         (*inst)->baseEnum = enumDecl;
     794                                        (* inst)->baseEnum = enumDecl;
    795795                                } // for
    796796                                forwardEnums.erase( fwds );
     
    834834        }
    835835
    836         void LinkReferenceToTypes_old::postvisit( StructDecl *structDecl ) {
     836        void LinkReferenceToTypes_old::postvisit( StructDecl * structDecl ) {
    837837                // visit struct members first so that the types of self-referencing members are updated properly
    838838                // xxx - need to ensure that type parameters match up between forward declarations and definition (most importantly, number of type parameters and their defaults)
     
    841841                        if ( fwds != forwardStructs.end() ) {
    842842                                for ( std::list< StructInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {
    843                                         (*inst)->baseStruct = structDecl;
     843                                        (* inst)->baseStruct = structDecl;
    844844                                } // for
    845845                                forwardStructs.erase( fwds );
     
    848848        }
    849849
    850         void LinkReferenceToTypes_old::postvisit( UnionDecl *unionDecl ) {
     850        void LinkReferenceToTypes_old::postvisit( UnionDecl * unionDecl ) {
    851851                if ( unionDecl->body ) {
    852852                        ForwardUnionsType::iterator fwds = forwardUnions.find( unionDecl->name );
    853853                        if ( fwds != forwardUnions.end() ) {
    854854                                for ( std::list< UnionInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {
    855                                         (*inst)->baseUnion = unionDecl;
     855                                        (* inst)->baseUnion = unionDecl;
    856856                                } // for
    857857                                forwardUnions.erase( fwds );
     
    860860        }
    861861
    862         void LinkReferenceToTypes_old::postvisit( TypeInstType *typeInst ) {
     862        void LinkReferenceToTypes_old::postvisit( TypeInstType * typeInst ) {
    863863                // ensure generic parameter instances are renamed like the base type
    864864                if ( inGeneric && typeInst->baseType ) typeInst->name = typeInst->baseType->name;
    865                 if ( NamedTypeDecl *namedTypeDecl = local_indexer->lookupType( typeInst->name ) ) {
    866                         if ( TypeDecl *typeDecl = dynamic_cast< TypeDecl * >( namedTypeDecl ) ) {
    867                                 typeInst->set_isFtype( typeDecl->get_kind() == TypeDecl::Ftype );
     865                if ( const NamedTypeDecl * namedTypeDecl = local_indexer->lookupType( typeInst->name ) ) {
     866                        if ( const TypeDecl * typeDecl = dynamic_cast< const TypeDecl * >( namedTypeDecl ) ) {
     867                                typeInst->set_isFtype( typeDecl->kind == TypeDecl::Ftype );
    868868                        } // if
    869869                } // if
     
    877877                        // expand trait instances into their members
    878878                        for ( DeclarationWithType * assertion : asserts ) {
    879                                 if ( TraitInstType *traitInst = dynamic_cast< TraitInstType * >( assertion->get_type() ) ) {
     879                                if ( TraitInstType * traitInst = dynamic_cast< TraitInstType * >( assertion->get_type() ) ) {
    880880                                        // expand trait instance into all of its members
    881881                                        expandAssertions( traitInst, back_inserter( type->assertions ) );
     
    897897        }
    898898
    899         void ForallPointerDecay_old::previsit( ObjectDecl *object ) {
     899        void ForallPointerDecay_old::previsit( ObjectDecl * object ) {
    900900                // ensure that operator names only apply to functions or function pointers
    901901                if ( CodeGen::isOperator( object->name ) && ! dynamic_cast< FunctionType * >( object->type->stripDeclarator() ) ) {
     
    905905        }
    906906
    907         void ForallPointerDecay_old::previsit( FunctionDecl *func ) {
     907        void ForallPointerDecay_old::previsit( FunctionDecl * func ) {
    908908                func->fixUniqueId();
    909909        }
     
    961961        Type * ReplaceTypedef::postmutate( QualifiedType * qualType ) {
    962962                // replacing typedefs only makes sense for the 'oldest ancestor' of the qualified type
    963                 qualType->parent = qualType->parent->acceptMutator( *visitor );
     963                qualType->parent = qualType->parent->acceptMutator( * visitor );
    964964                return qualType;
    965965        }
     
    970970                TypedefMap::const_iterator def = typedefNames.find( typeInst->name );
    971971                if ( def != typedefNames.end() ) {
    972                         Type *ret = def->second.first->base->clone();
     972                        Type * ret = def->second.first->base->clone();
    973973                        ret->location = typeInst->location;
    974974                        ret->get_qualifiers() |= typeInst->get_qualifiers();
     
    982982                        // place instance parameters on the typedef'd type
    983983                        if ( ! typeInst->parameters.empty() ) {
    984                                 ReferenceToType *rtt = dynamic_cast<ReferenceToType*>(ret);
     984                                ReferenceToType * rtt = dynamic_cast<ReferenceToType *>(ret);
    985985                                if ( ! rtt ) {
    986986                                        SemanticError( typeInst->location, "Cannot apply type parameters to base type of " + typeInst->name );
     
    988988                                rtt->parameters.clear();
    989989                                cloneAll( typeInst->parameters, rtt->parameters );
    990                                 mutateAll( rtt->parameters, *visitor );  // recursively fix typedefs on parameters
     990                                mutateAll( rtt->parameters, * visitor );  // recursively fix typedefs on parameters
    991991                        } // if
    992992                        delete typeInst;
     
    10431043                //    struct screen;
    10441044                // because the expansion of the typedef is:
    1045                 //    void rtn( SCREEN *p ) => void rtn( struct screen *p )
     1045                //    void rtn( SCREEN * p ) => void rtn( struct screen * p )
    10461046                // hence the type-name "screen" must be defined.
    10471047                // Note, qualifiers on the typedef are superfluous for the forward declaration.
    10481048
    1049                 Type *designatorType = tyDecl->base->stripDeclarator();
    1050                 if ( StructInstType *aggDecl = dynamic_cast< StructInstType * >( designatorType ) ) {
     1049                Type * designatorType = tyDecl->base->stripDeclarator();
     1050                if ( StructInstType * aggDecl = dynamic_cast< StructInstType * >( designatorType ) ) {
    10511051                        declsToAddBefore.push_back( new StructDecl( aggDecl->name, DeclarationNode::Struct, noAttributes, tyDecl->linkage ) );
    1052                 } else if ( UnionInstType *aggDecl = dynamic_cast< UnionInstType * >( designatorType ) ) {
     1052                } else if ( UnionInstType * aggDecl = dynamic_cast< UnionInstType * >( designatorType ) ) {
    10531053                        declsToAddBefore.push_back( new UnionDecl( aggDecl->name, noAttributes, tyDecl->linkage ) );
    1054                 } else if ( EnumInstType *enumDecl = dynamic_cast< EnumInstType * >( designatorType ) ) {
     1054                } else if ( EnumInstType * enumDecl = dynamic_cast< EnumInstType * >( designatorType ) ) {
    10551055                        declsToAddBefore.push_back( new EnumDecl( enumDecl->name, noAttributes, tyDecl->linkage ) );
    10561056                } // if
     
    10781078
    10791079        DeclarationWithType * ReplaceTypedef::postmutate( ObjectDecl * objDecl ) {
    1080                 if ( FunctionType *funtype = dynamic_cast<FunctionType *>( objDecl->type ) ) { // function type?
     1080                if ( FunctionType * funtype = dynamic_cast<FunctionType *>( objDecl->type ) ) { // function type?
    10811081                        // replace the current object declaration with a function declaration
    10821082                        FunctionDecl * newDecl = new FunctionDecl( objDecl->name, objDecl->get_storageClasses(), objDecl->linkage, funtype, 0, objDecl->attributes, objDecl->get_funcSpec() );
     
    11041104        void ReplaceTypedef::addImplicitTypedef( AggDecl * aggDecl ) {
    11051105                if ( typedefNames.count( aggDecl->get_name() ) == 0 ) {
    1106                         Type *type = nullptr;
     1106                        Type * type = nullptr;
    11071107                        if ( StructDecl * newDeclStructDecl = dynamic_cast< StructDecl * >( aggDecl ) ) {
    11081108                                type = new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() );
     
    11301130                GuardScope( typedefNames );
    11311131                GuardScope( typedeclNames );
    1132                 mutateAll( aggr->parameters, *visitor );
     1132                mutateAll( aggr->parameters, * visitor );
    11331133
    11341134                // unroll mutateAll for aggr->members so that implicit typedefs for nested types are added to the aggregate body.
     
    11371137
    11381138                        try {
    1139                                 *i = maybeMutate( *i, *visitor );
     1139                                * i = maybeMutate( * i, * visitor );
    11401140                        } catch ( SemanticErrorException &e ) {
    11411141                                errors.append( e );
     
    12171217                        for ( size_t i = 0; paramIter != params->end(); ++paramIter, ++i ) {
    12181218                                if ( i < args.size() ) {
    1219                                         TypeExpr * expr = strict_dynamic_cast< TypeExpr * >( *std::next( args.begin(), i ) );
    1220                                         sub.add( (*paramIter)->get_name(), expr->get_type()->clone() );
     1219                                        TypeExpr * expr = strict_dynamic_cast< TypeExpr * >( * std::next( args.begin(), i ) );
     1220                                        sub.add( (* paramIter)->get_name(), expr->get_type()->clone() );
    12211221                                } else if ( i == args.size() ) {
    1222                                         Type * defaultType = (*paramIter)->get_init();
     1222                                        Type * defaultType = (* paramIter)->get_init();
    12231223                                        if ( defaultType ) {
    12241224                                                args.push_back( new TypeExpr( defaultType->clone() ) );
    1225                                                 sub.add( (*paramIter)->get_name(), defaultType->clone() );
     1225                                                sub.add( (* paramIter)->get_name(), defaultType->clone() );
    12261226                                        }
    12271227                                }
     
    12421242        }
    12431243
    1244         void CompoundLiteral::premutate( ObjectDecl *objectDecl ) {
     1244        void CompoundLiteral::premutate( ObjectDecl * objectDecl ) {
    12451245                storageClasses = objectDecl->get_storageClasses();
    12461246        }
    12471247
    1248         Expression *CompoundLiteral::postmutate( CompoundLiteralExpr *compLitExpr ) {
     1248        Expression * CompoundLiteral::postmutate( CompoundLiteralExpr * compLitExpr ) {
    12491249                // transform [storage_class] ... (struct S){ 3, ... };
    12501250                // into [storage_class] struct S temp =  { 3, ... };
    12511251                static UniqueName indexName( "_compLit" );
    12521252
    1253                 ObjectDecl *tempvar = new ObjectDecl( indexName.newName(), storageClasses, LinkageSpec::C, nullptr, compLitExpr->get_result(), compLitExpr->get_initializer() );
     1253                ObjectDecl * tempvar = new ObjectDecl( indexName.newName(), storageClasses, LinkageSpec::C, nullptr, compLitExpr->get_result(), compLitExpr->get_initializer() );
    12541254                compLitExpr->set_result( nullptr );
    12551255                compLitExpr->set_initializer( nullptr );
     
    12891289                        TupleType * tupleType = strict_dynamic_cast< TupleType * >( ResolvExpr::extractResultType( ftype ) );
    12901290                        // ensure return value is not destructed by explicitly creating an empty ListInit node wherein maybeConstruct is false.
    1291                         ObjectDecl * newRet = new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, 0, tupleType, new ListInit( std::list<Initializer*>(), noDesignators, false ) );
     1291                        ObjectDecl * newRet = new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, 0, tupleType, new ListInit( std::list<Initializer *>(), noDesignators, false ) );
    12921292                        deleteAll( retVals );
    12931293                        retVals.clear();
     
    13021302
    13031303        void FixObjectType::previsit( ObjectDecl * objDecl ) {
    1304                 Type *new_type = ResolvExpr::resolveTypeof( objDecl->get_type(), indexer );
     1304                Type * new_type = ResolvExpr::resolveTypeof( objDecl->get_type(), indexer );
    13051305                new_type->get_qualifiers() -= Type::Lvalue; // even if typeof is lvalue, variable can never have lvalue-qualified type
    13061306                objDecl->set_type( new_type );
     
    13081308
    13091309        void FixObjectType::previsit( FunctionDecl * funcDecl ) {
    1310                 Type *new_type = ResolvExpr::resolveTypeof( funcDecl->type, indexer );
     1310                Type * new_type = ResolvExpr::resolveTypeof( funcDecl->type, indexer );
    13111311                new_type->get_qualifiers() -= Type::Lvalue; // even if typeof is lvalue, variable can never have lvalue-qualified type
    13121312                funcDecl->set_type( new_type );
    13131313        }
    13141314
    1315         void FixObjectType::previsit( TypeDecl *typeDecl ) {
     1315        void FixObjectType::previsit( TypeDecl * typeDecl ) {
    13161316                if ( typeDecl->get_base() ) {
    1317                         Type *new_type = ResolvExpr::resolveTypeof( typeDecl->get_base(), indexer );
     1317                        Type * new_type = ResolvExpr::resolveTypeof( typeDecl->get_base(), indexer );
    13181318                        new_type->get_qualifiers() -= Type::Lvalue; // even if typeof is lvalue, variable can never have lvalue-qualified type
    13191319                        typeDecl->set_base( new_type );
     
    13781378
    13791379namespace {
    1380         /// Replaces enum types by int, and function/array types in function parameter and return 
     1380        /// Replaces enum types by int, and function/array types in function parameter and return
    13811381        /// lists by appropriate pointers
    13821382        struct EnumAndPointerDecay_new {
     
    13851385                        for ( unsigned i = 0; i < enumDecl->members.size(); ++i ) {
    13861386                                // build new version of object with EnumConstant
    1387                                 ast::ptr< ast::ObjectDecl > obj = 
     1387                                ast::ptr< ast::ObjectDecl > obj =
    13881388                                        enumDecl->members[i].strict_as< ast::ObjectDecl >();
    1389                                 obj.get_and_mutate()->type = 
     1389                                obj.get_and_mutate()->type =
    13901390                                        new ast::EnumInstType{ enumDecl->name, ast::CV::Const };
    1391                                
     1391
    13921392                                // set into decl
    13931393                                ast::EnumDecl * mut = mutate( enumDecl );
     
    13991399
    14001400                static const ast::FunctionType * fixFunctionList(
    1401                         const ast::FunctionType * func, 
     1401                        const ast::FunctionType * func,
    14021402                        std::vector< ast::ptr< ast::DeclWithType > > ast::FunctionType::* field,
    14031403                        ast::ArgumentFlag isVarArgs = ast::FixedArgs
    14041404                ) {
    1405                         const auto & dwts = func->*field;
     1405                        const auto & dwts = func->* field;
    14061406                        unsigned nvals = dwts.size();
    14071407                        bool hasVoid = false;
     
    14091409                                func = ast::mutate_field_index( func, field, i, fixFunction( dwts[i], hasVoid ) );
    14101410                        }
    1411                        
     1411
    14121412                        // the only case in which "void" is valid is where it is the only one in the list
    14131413                        if ( hasVoid && ( nvals > 1 || isVarArgs ) ) {
    1414                                 SemanticError( 
     1414                                SemanticError(
    14151415                                        dwts.front()->location, func, "invalid type void in function type" );
    14161416                        }
     
    14181418                        // one void is the only thing in the list, remove it
    14191419                        if ( hasVoid ) {
    1420                                 func = ast::mutate_field( 
     1420                                func = ast::mutate_field(
    14211421                                        func, field, std::vector< ast::ptr< ast::DeclWithType > >{} );
    14221422                        }
     
    14321432
    14331433        /// expand assertions from a trait instance, performing appropriate type variable substitutions
    1434         void expandAssertions( 
    1435                 const ast::TraitInstType * inst, std::vector< ast::ptr< ast::DeclWithType > > & out 
     1434        void expandAssertions(
     1435                const ast::TraitInstType * inst, std::vector< ast::ptr< ast::DeclWithType > > & out
    14361436        ) {
    14371437                assertf( inst->base, "Trait instance not linked to base trait: %s", toCString( inst ) );
    14381438
    14391439                // build list of trait members, substituting trait decl parameters for instance parameters
    1440                 ast::TypeSubstitution sub{ 
     1440                ast::TypeSubstitution sub{
    14411441                        inst->base->params.begin(), inst->base->params.end(), inst->params.begin() };
    14421442                // deliberately take ast::ptr by-value to ensure this does not mutate inst->base
     
    14491449
    14501450        /// Associates forward declarations of aggregates with their definitions
    1451         class LinkReferenceToTypes_new final 
    1452         : public ast::WithSymbolTable, public ast::WithGuards, public 
     1451        class LinkReferenceToTypes_new final
     1452        : public ast::WithSymbolTable, public ast::WithGuards, public
    14531453          ast::WithVisitorRef<LinkReferenceToTypes_new>, public ast::WithShortCircuiting {
    1454                
    1455                 // these maps of uses of forward declarations of types need to have the actual type 
    1456                 // declaration switched in *after* they have been traversed. To enable this in the
    1457                 // ast::Pass framework, any node that needs to be so mutated has mutate() called on it 
    1458                 // before it is placed in the map, properly updating its parents in the usual traversal, 
     1454
     1455                // these maps of uses of forward declarations of types need to have the actual type
     1456                // declaration switched in * after * they have been traversed. To enable this in the
     1457                // ast::Pass framework, any node that needs to be so mutated has mutate() called on it
     1458                // before it is placed in the map, properly updating its parents in the usual traversal,
    14591459                // then can have the actual mutation applied later
    14601460                using ForwardEnumsType = std::unordered_multimap< std::string, ast::EnumInstType * >;
    14611461                using ForwardStructsType = std::unordered_multimap< std::string, ast::StructInstType * >;
    14621462                using ForwardUnionsType = std::unordered_multimap< std::string, ast::UnionInstType * >;
    1463                
     1463
    14641464                const CodeLocation & location;
    14651465                const ast::SymbolTable * localSymtab;
    1466                
     1466
    14671467                ForwardEnumsType forwardEnums;
    14681468                ForwardStructsType forwardStructs;
    14691469                ForwardUnionsType forwardUnions;
    14701470
    1471                 /// true if currently in a generic type body, so that type parameter instances can be 
     1471                /// true if currently in a generic type body, so that type parameter instances can be
    14721472                /// renamed appropriately
    14731473                bool inGeneric = false;
     
    14751475        public:
    14761476                /// contstruct using running symbol table
    1477                 LinkReferenceToTypes_new( const CodeLocation & loc ) 
     1477                LinkReferenceToTypes_new( const CodeLocation & loc )
    14781478                : location( loc ), localSymtab( &symtab ) {}
    1479                
     1479
    14801480                /// construct using provided symbol table
    1481                 LinkReferenceToTypes_new( const CodeLocation & loc, const ast::SymbolTable & syms ) 
     1481                LinkReferenceToTypes_new( const CodeLocation & loc, const ast::SymbolTable & syms )
    14821482                : location( loc ), localSymtab( &syms ) {}
    14831483
     
    14851485                        // ensure generic parameter instances are renamed like the base type
    14861486                        if ( inGeneric && typeInst->base ) {
    1487                                 typeInst = ast::mutate_field( 
     1487                                typeInst = ast::mutate_field(
    14881488                                        typeInst, &ast::TypeInstType::name, typeInst->base->name );
    14891489                        }
    14901490
    1491                         if ( 
    1492                                 auto typeDecl = dynamic_cast< const ast::TypeDecl * >( 
    1493                                         localSymtab->lookupType( typeInst->name ) ) 
     1491                        if (
     1492                                auto typeDecl = dynamic_cast< const ast::TypeDecl * >(
     1493                                        localSymtab->lookupType( typeInst->name ) )
    14941494                        ) {
    14951495                                typeInst = ast::mutate_field( typeInst, &ast::TypeInstType::kind, typeDecl->kind );
     
    15171517                        for ( const ast::Expr * param : inst->params ) {
    15181518                                if ( ! dynamic_cast< const ast::TypeExpr * >( param ) ) {
    1519                                         SemanticError( 
     1519                                        SemanticError(
    15201520                                                location, inst, "Expression parameters for generic types are currently "
    15211521                                                "unsupported: " );
     
    15711571                                auto expr = traitInst->params[i].as< ast::TypeExpr >();
    15721572                                if ( ! expr ) {
    1573                                         SemanticError( 
     1573                                        SemanticError(
    15741574                                                traitInst->params[i].get(), "Expression parameters for trait instances "
    15751575                                                "are currently unsupported: " );
     
    15931593                        return traitInst;
    15941594                }
    1595                
     1595
    15961596                void previsit( const ast::QualifiedType * ) { visit_children = false; }
    1597                
     1597
    15981598                const ast::Type * postvisit( const ast::QualifiedType * qualType ) {
    15991599                        // linking only makes sense for the "oldest ancestor" of the qualified type
    1600                         return ast::mutate_field( 
    1601                                 qualType, &ast::QualifiedType::parent, qualType->parent->accept( *visitor ) );
     1600                        return ast::mutate_field(
     1601                                qualType, &ast::QualifiedType::parent, qualType->parent->accept( * visitor ) );
    16021602                }
    16031603
    16041604                const ast::Decl * postvisit( const ast::EnumDecl * enumDecl ) {
    1605                         // visit enum members first so that the types of self-referencing members are updated 
     1605                        // visit enum members first so that the types of self-referencing members are updated
    16061606                        // properly
    16071607                        if ( ! enumDecl->body ) return enumDecl;
     
    16121612                                auto inst = fwds.first;
    16131613                                do {
    1614                                         // forward decl is stored *mutably* in map, can thus be updated
     1614                                        // forward decl is stored * mutably * in map, can thus be updated
    16151615                                        inst->second->base = enumDecl;
    16161616                                } while ( ++inst != fwds.second );
    16171617                                forwardEnums.erase( fwds.first, fwds.second );
    16181618                        }
    1619                        
     1619
    16201620                        // ensure that enumerator initializers are properly set
    16211621                        for ( unsigned i = 0; i < enumDecl->members.size(); ++i ) {
    16221622                                auto field = enumDecl->members[i].strict_as< ast::ObjectDecl >();
    16231623                                if ( field->init ) {
    1624                                         // need to resolve enumerator initializers early so that other passes that 
     1624                                        // need to resolve enumerator initializers early so that other passes that
    16251625                                        // determine if an expression is constexpr have appropriate information
    16261626                                        auto init = field->init.strict_as< ast::SingleInit >();
    1627                                        
    1628                                         enumDecl = ast::mutate_field_index( 
    1629                                                 enumDecl, &ast::EnumDecl::members, i, 
    1630                                                 ast::mutate_field( field, &ast::ObjectDecl::init, 
     1627
     1628                                        enumDecl = ast::mutate_field_index(
     1629                                                enumDecl, &ast::EnumDecl::members, i,
     1630                                                ast::mutate_field( field, &ast::ObjectDecl::init,
    16311631                                                        ast::mutate_field( init, &ast::SingleInit::value,
    1632                                                                 ResolvExpr::findSingleExpression( 
     1632                                                                ResolvExpr::findSingleExpression(
    16331633                                                                        init->value, new ast::BasicType{ ast::BasicType::SignedInt },
    16341634                                                                        symtab ) ) ) );
     
    16391639                }
    16401640
    1641                 /// rename generic type parameters uniquely so that they do not conflict with user defined 
     1641                /// rename generic type parameters uniquely so that they do not conflict with user defined
    16421642                /// function forall parameters, e.g. the T in Box and the T in f, below
    16431643                ///   forall(otype T)
     
    16571657                                const ast::TypeDecl * td = aggr->params[i];
    16581658
    1659                                 aggr = ast::mutate_field_index( 
    1660                                         aggr, &AggrDecl::params, i, 
     1659                                aggr = ast::mutate_field_index(
     1660                                        aggr, &AggrDecl::params, i,
    16611661                                        ast::mutate_field( td, &ast::TypeDecl::name, "__" + td->name + "_generic_" ) );
    16621662                        }
     
    16691669
    16701670                void postvisit( const ast::StructDecl * structDecl ) {
    1671                         // visit struct members first so that the types of self-referencing members are 
     1671                        // visit struct members first so that the types of self-referencing members are
    16721672                        // updated properly
    16731673                        if ( ! structDecl->body ) return;
     
    16781678                                auto inst = fwds.first;
    16791679                                do {
    1680                                         // forward decl is stored *mutably* in map, can thus be updated
     1680                                        // forward decl is stored * mutably * in map, can thus be updated
    16811681                                        inst->second->base = structDecl;
    16821682                                } while ( ++inst != fwds.second );
     
    16901690
    16911691                void postvisit( const ast::UnionDecl * unionDecl ) {
    1692                         // visit union members first so that the types of self-referencing members are updated 
     1692                        // visit union members first so that the types of self-referencing members are updated
    16931693                        // properly
    16941694                        if ( ! unionDecl->body ) return;
     
    16991699                                auto inst = fwds.first;
    17001700                                do {
    1701                                         // forward decl is stored *mutably* in map, can thus be updated
     1701                                        // forward decl is stored * mutably * in map, can thus be updated
    17021702                                        inst->second->base = unionDecl;
    17031703                                } while ( ++inst != fwds.second );
     
    17121712                                        "number of parameters: %zd", traitDecl->params.size() );
    17131713
    1714                                 traitDecl = ast::mutate_field_index( 
    1715                                         traitDecl, &ast::TraitDecl::params, 0, 
    1716                                         ast::mutate_field( 
     1714                                traitDecl = ast::mutate_field_index(
     1715                                        traitDecl, &ast::TraitDecl::params, 0,
     1716                                        ast::mutate_field(
    17171717                                                traitDecl->params.front().get(), &ast::TypeDecl::sized, true ) );
    17181718                        }
     
    17371737                                traitDecl = mut;
    17381738                        }
    1739                        
     1739
    17401740                        return traitDecl;
    17411741                }
    17421742        };
    17431743
    1744         /// Replaces array and function types in forall lists by appropriate pointer type and assigns 
     1744        /// Replaces array and function types in forall lists by appropriate pointer type and assigns
    17451745        /// each object and function declaration a unique ID
    17461746        class ForallPointerDecay_new {
     
    17511751                const ast::ObjectDecl * previsit( const ast::ObjectDecl * obj ) {
    17521752                        // ensure that operator names only apply to functions or function pointers
    1753                         if ( 
    1754                                 CodeGen::isOperator( obj->name ) 
     1753                        if (
     1754                                CodeGen::isOperator( obj->name )
    17551755                                && ! dynamic_cast< const ast::FunctionType * >( obj->type->stripDeclarator() )
    17561756                        ) {
     
    17761776                /// Fix up assertions -- flattens assertion lists, removing all trait instances
    17771777                template< typename node_t, typename parent_t >
    1778                 static const node_t * forallFixer( 
    1779                         const CodeLocation & loc, const node_t * node, 
     1778                static const node_t * forallFixer(
     1779                        const CodeLocation & loc, const node_t * node,
    17801780                        ast::ParameterizedType::ForallList parent_t::* forallField
    17811781                ) {
    1782                         for ( unsigned i = 0; i < (node->*forallField).size(); ++i ) {
    1783                                 const ast::TypeDecl * type = (node->*forallField)[i];
     1782                        for ( unsigned i = 0; i < (node->* forallField).size(); ++i ) {
     1783                                const ast::TypeDecl * type = (node->* forallField)[i];
    17841784                                if ( type->assertions.empty() ) continue;
    17851785
     
    17891789                                // expand trait instances into their members
    17901790                                for ( const ast::DeclWithType * assn : type->assertions ) {
    1791                                         auto traitInst = 
    1792                                                 dynamic_cast< const ast::TraitInstType * >( assn->get_type() ); 
     1791                                        auto traitInst =
     1792                                                dynamic_cast< const ast::TraitInstType * >( assn->get_type() );
    17931793                                        if ( traitInst ) {
    17941794                                                // expand trait instance to all its members
     
    18311831} // anonymous namespace
    18321832
    1833 const ast::Type * validateType( 
     1833const ast::Type * validateType(
    18341834                const CodeLocation & loc, const ast::Type * type, const ast::SymbolTable & symtab ) {
    18351835        ast::Pass< EnumAndPointerDecay_new > epc;
  • src/SymTab/Validate.h

    r302d84c2 rfce4e31  
    1919#include <list>  // for list
    2020
    21 class CodeLocation;
    22 class Declaration;
    23 class Type;
     21struct CodeLocation;
     22class  Declaration;
     23class  Type;
    2424
    2525namespace ast {
     
    3535        void validateType( Type *type, const Indexer *indexer );
    3636
    37         const ast::Type * validateType( 
     37        const ast::Type * validateType(
    3838                const CodeLocation & loc, const ast::Type * type, const ast::SymbolTable & symtab );
    3939} // namespace SymTab
  • src/SynTree/Attribute.h

    r302d84c2 rfce4e31  
    5050        Attribute * clone() const override { return new Attribute( *this ); }
    5151        virtual void accept( Visitor & v ) override { v.visit( this ); }
     52        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    5253        virtual Attribute * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    5354        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
  • src/SynTree/BaseSyntaxNode.h

    r302d84c2 rfce4e31  
    3232        BaseSyntaxNode( const BaseSyntaxNode & o ) : location(o.location) { ++*new_nodes; }
    3333        BaseSyntaxNode & operator=( const BaseSyntaxNode & ) = default;
    34        
     34
    3535        virtual ~BaseSyntaxNode() {}
    3636
    3737        virtual BaseSyntaxNode * clone() const = 0;
    3838        virtual void accept( Visitor & v ) = 0;
     39        virtual void accept( Visitor & v ) const = 0;
    3940        virtual BaseSyntaxNode * acceptMutator( Mutator & m ) = 0;
    4041        /// Notes:
  • src/SynTree/Constant.h

    r302d84c2 rfce4e31  
    3333        virtual ~Constant();
    3434
    35         virtual Constant * clone() const { return new Constant( *this ); }
     35        virtual Constant * clone() const override { return new Constant( *this ); }
    3636
    3737        Type * get_type() { return type; }
     
    5151        static Constant null( Type * ptrtype = nullptr );
    5252
    53         virtual void accept( Visitor & v ) { v.visit( this ); }
    54         virtual Constant * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    55         virtual void print( std::ostream & os, Indenter indent = 0 ) const;
    56   private:
     53        virtual void accept( Visitor & v ) override { v.visit( this ); }
     54        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     55        virtual Constant * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     56        virtual void print( std::ostream & os, Indenter indent = 0 ) const override;
     57
    5758        Type * type;
    5859        std::string rep;
    5960        std::optional<unsigned long long> ival;
    60 
    61         friend class ConverterOldToNew;
    6261};
    6362
  • src/SynTree/Declaration.h

    r302d84c2 rfce4e31  
    6363        void fixUniqueId( void );
    6464        virtual Declaration *clone() const override = 0;
    65         virtual void accept( Visitor &v ) override = 0;
     65        virtual void accept( Visitor & v ) override = 0;
     66        virtual void accept( Visitor & v ) const override = 0;
    6667        virtual Declaration *acceptMutator( Mutator &m ) override = 0;
    6768        virtual void print( std::ostream &os, Indenter indent = {} ) const override = 0;
     
    139140
    140141        virtual ObjectDecl *clone() const override { return new ObjectDecl( *this ); }
    141         virtual void accept( Visitor &v ) override { v.visit( this ); }
     142        virtual void accept( Visitor & v ) override { v.visit( this ); }
     143        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    142144        virtual DeclarationWithType *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    143145        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
     
    169171
    170172        virtual FunctionDecl *clone() const override { return new FunctionDecl( *this ); }
    171         virtual void accept( Visitor &v ) override { v.visit( this ); }
     173        virtual void accept( Visitor & v ) override { v.visit( this ); }
     174        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    172175        virtual DeclarationWithType *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    173176        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
     
    238241
    239242        virtual TypeDecl *clone() const override { return new TypeDecl( *this ); }
    240         virtual void accept( Visitor &v ) override { v.visit( this ); }
     243        virtual void accept( Visitor & v ) override { v.visit( this ); }
     244        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    241245        virtual Declaration *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    242246        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
     
    256260
    257261        virtual TypedefDecl *clone() const override { return new TypedefDecl( *this ); }
    258         virtual void accept( Visitor &v ) override { v.visit( this ); }
     262        virtual void accept( Visitor & v ) override { v.visit( this ); }
     263        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    259264        virtual Declaration *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    260265  private:
     
    300305
    301306        virtual StructDecl *clone() const override { return new StructDecl( *this ); }
    302         virtual void accept( Visitor &v ) override { v.visit( this ); }
     307        virtual void accept( Visitor & v ) override { v.visit( this ); }
     308        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    303309        virtual Declaration *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    304310        DeclarationNode::Aggregate kind;
     
    314320
    315321        virtual UnionDecl *clone() const override { return new UnionDecl( *this ); }
    316         virtual void accept( Visitor &v ) override { v.visit( this ); }
     322        virtual void accept( Visitor & v ) override { v.visit( this ); }
     323        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    317324        virtual Declaration *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    318325  private:
     
    329336
    330337        virtual EnumDecl *clone() const override { return new EnumDecl( *this ); }
    331         virtual void accept( Visitor &v ) override { v.visit( this ); }
     338        virtual void accept( Visitor & v ) override { v.visit( this ); }
     339        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    332340        virtual Declaration *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    333341  private:
     
    345353
    346354        virtual TraitDecl *clone() const override { return new TraitDecl( *this ); }
    347         virtual void accept( Visitor &v ) override { v.visit( this ); }
     355        virtual void accept( Visitor & v ) override { v.visit( this ); }
     356        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    348357        virtual Declaration *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    349358  private:
     
    363372
    364373        virtual AsmDecl *clone() const override { return new AsmDecl( *this ); }
    365         virtual void accept( Visitor &v ) override { v.visit( this ); }
     374        virtual void accept( Visitor & v ) override { v.visit( this ); }
     375        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    366376        virtual AsmDecl *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    367377        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
     
    379389
    380390        virtual StaticAssertDecl * clone() const override { return new StaticAssertDecl( *this ); }
    381         virtual void accept( Visitor &v ) override { v.visit( this ); }
     391        virtual void accept( Visitor & v ) override { v.visit( this ); }
     392        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    382393        virtual StaticAssertDecl * acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    383394        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
  • src/SynTree/Expression.h

    r302d84c2 rfce4e31  
    8282        virtual Expression * clone() const override = 0;
    8383        virtual void accept( Visitor & v ) override = 0;
     84        virtual void accept( Visitor & v ) const override = 0;
    8485        virtual Expression * acceptMutator( Mutator & m ) override = 0;
    8586        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    101102        std::list<Expression *>& get_args() { return args; }
    102103
    103         virtual ApplicationExpr * clone() const { return new ApplicationExpr( * this ); }
    104         virtual void accept( Visitor & v ) { v.visit( this ); }
    105         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    106         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     104        virtual ApplicationExpr * clone() const override { return new ApplicationExpr( * this ); }
     105        virtual void accept( Visitor & v ) override { v.visit( this ); }
     106        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     107        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     108        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    107109};
    108110
     
    129131        static UntypedExpr * createAssign( Expression * arg1, Expression * arg2 );
    130132
    131         virtual UntypedExpr * clone() const { return new UntypedExpr( * this ); }
    132         virtual void accept( Visitor & v ) { v.visit( this ); }
    133         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    134         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     133        virtual UntypedExpr * clone() const override { return new UntypedExpr( * this ); }
     134        virtual void accept( Visitor & v ) override { v.visit( this ); }
     135        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     136        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     137        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    135138};
    136139
     
    147150        void set_name( std::string newValue ) { name = newValue; }
    148151
    149         virtual NameExpr * clone() const { return new NameExpr( * this ); }
    150         virtual void accept( Visitor & v ) { v.visit( this ); }
    151         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    152         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     152        virtual NameExpr * clone() const override { return new NameExpr( * this ); }
     153        virtual void accept( Visitor & v ) override { v.visit( this ); }
     154        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     155        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     156        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    153157};
    154158
     
    168172        void set_arg(Expression * newValue ) { arg = newValue; }
    169173
    170         virtual AddressExpr * clone() const { return new AddressExpr( * this ); }
    171         virtual void accept( Visitor & v ) { v.visit( this ); }
    172         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    173         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     174        virtual AddressExpr * clone() const override { return new AddressExpr( * this ); }
     175        virtual void accept( Visitor & v ) override { v.visit( this ); }
     176        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     177        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     178        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    174179};
    175180
     
    184189        virtual ~LabelAddressExpr();
    185190
    186         virtual LabelAddressExpr * clone() const { return new LabelAddressExpr( * this ); }
    187         virtual void accept( Visitor & v ) { v.visit( this ); }
    188         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    189         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     191        virtual LabelAddressExpr * clone() const override { return new LabelAddressExpr( * this ); }
     192        virtual void accept( Visitor & v ) override { v.visit( this ); }
     193        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     194        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     195        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    190196};
    191197
     
    205211        void set_arg( Expression * newValue ) { arg = newValue; }
    206212
    207         virtual CastExpr * clone() const { return new CastExpr( * this ); }
    208         virtual void accept( Visitor & v ) { v.visit( this ); }
    209         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    210         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     213        virtual CastExpr * clone() const override { return new CastExpr( * this ); }
     214        virtual void accept( Visitor & v ) override { v.visit( this ); }
     215        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     216        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     217        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    211218};
    212219
     
    225232        const std::string & targetString() const;
    226233
    227         virtual KeywordCastExpr * clone() const { return new KeywordCastExpr( * this ); }
    228         virtual void accept( Visitor & v ) { v.visit( this ); }
    229         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    230         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     234        virtual KeywordCastExpr * clone() const override { return new KeywordCastExpr( * this ); }
     235        virtual void accept( Visitor & v ) override { v.visit( this ); }
     236        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     237        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     238        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    231239};
    232240
     
    243251        void set_arg( Expression * newValue ) { arg = newValue; }
    244252
    245         virtual VirtualCastExpr * clone() const { return new VirtualCastExpr( * this ); }
    246         virtual void accept( Visitor & v ) { v.visit( this ); }
    247         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    248         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     253        virtual VirtualCastExpr * clone() const override { return new VirtualCastExpr( * this ); }
     254        virtual void accept( Visitor & v ) override { v.visit( this ); }
     255        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     256        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     257        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    249258};
    250259
     
    264273        void set_aggregate( Expression * newValue ) { aggregate = newValue; }
    265274
    266         virtual UntypedMemberExpr * clone() const { return new UntypedMemberExpr( * this ); }
    267         virtual void accept( Visitor & v ) { v.visit( this ); }
    268         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    269         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     275        virtual UntypedMemberExpr * clone() const override { return new UntypedMemberExpr( * this ); }
     276        virtual void accept( Visitor & v ) override { v.visit( this ); }
     277        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     278        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     279        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    270280};
    271281
     
    286296        void set_aggregate( Expression * newValue ) { aggregate = newValue; }
    287297
    288         virtual MemberExpr * clone() const { return new MemberExpr( * this ); }
    289         virtual void accept( Visitor & v ) { v.visit( this ); }
    290         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    291         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     298        virtual MemberExpr * clone() const override { return new MemberExpr( * this ); }
     299        virtual void accept( Visitor & v ) override { v.visit( this ); }
     300        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     301        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     302        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    292303};
    293304
     
    308319        static VariableExpr * functionPointer( FunctionDecl * decl );
    309320
    310         virtual VariableExpr * clone() const { return new VariableExpr( * this ); }
    311         virtual void accept( Visitor & v ) { v.visit( this ); }
    312         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    313         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     321        virtual VariableExpr * clone() const override { return new VariableExpr( * this ); }
     322        virtual void accept( Visitor & v ) override { v.visit( this ); }
     323        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     324        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     325        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    314326};
    315327
     
    329341        long long int intValue() const;
    330342
    331         virtual ConstantExpr * clone() const { return new ConstantExpr( * this ); }
    332         virtual void accept( Visitor & v ) { v.visit( this ); }
    333         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    334         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     343        virtual ConstantExpr * clone() const override { return new ConstantExpr( * this ); }
     344        virtual void accept( Visitor & v ) override { v.visit( this ); }
     345        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     346        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     347        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    335348};
    336349
     
    354367        void set_isType( bool newValue ) { isType = newValue; }
    355368
    356         virtual SizeofExpr * clone() const { return new SizeofExpr( * this ); }
    357         virtual void accept( Visitor & v ) { v.visit( this ); }
    358         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    359         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     369        virtual SizeofExpr * clone() const override { return new SizeofExpr( * this ); }
     370        virtual void accept( Visitor & v ) override { v.visit( this ); }
     371        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     372        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     373        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    360374};
    361375
     
    379393        void set_isType( bool newValue ) { isType = newValue; }
    380394
    381         virtual AlignofExpr * clone() const { return new AlignofExpr( * this ); }
    382         virtual void accept( Visitor & v ) { v.visit( this ); }
    383         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    384         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     395        virtual AlignofExpr * clone() const override { return new AlignofExpr( * this ); }
     396        virtual void accept( Visitor & v ) override { v.visit( this ); }
     397        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     398        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     399        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    385400};
    386401
     
    400415        void set_type( Type * newValue ) { type = newValue; }
    401416
    402         virtual UntypedOffsetofExpr * clone() const { return new UntypedOffsetofExpr( * this ); }
    403         virtual void accept( Visitor & v ) { v.visit( this ); }
    404         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    405         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     417        virtual UntypedOffsetofExpr * clone() const override { return new UntypedOffsetofExpr( * this ); }
     418        virtual void accept( Visitor & v ) override { v.visit( this ); }
     419        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     420        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     421        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    406422};
    407423
     
    421437        void set_member( DeclarationWithType * newValue ) { member = newValue; }
    422438
    423         virtual OffsetofExpr * clone() const { return new OffsetofExpr( * this ); }
    424         virtual void accept( Visitor & v ) { v.visit( this ); }
    425         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    426         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     439        virtual OffsetofExpr * clone() const override { return new OffsetofExpr( * this ); }
     440        virtual void accept( Visitor & v ) override { v.visit( this ); }
     441        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     442        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     443        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    427444};
    428445
     
    439456        void set_type( StructInstType * newValue ) { type = newValue; }
    440457
    441         virtual OffsetPackExpr * clone() const { return new OffsetPackExpr( * this ); }
    442         virtual void accept( Visitor & v ) { v.visit( this ); }
    443         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    444         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     458        virtual OffsetPackExpr * clone() const override { return new OffsetPackExpr( * this ); }
     459        virtual void accept( Visitor & v ) override { v.visit( this ); }
     460        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     461        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     462        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    445463};
    446464
     
    467485        void set_isType( bool newValue ) { isType = newValue; }
    468486
    469         virtual AttrExpr * clone() const { return new AttrExpr( * this ); }
    470         virtual void accept( Visitor & v ) { v.visit( this ); }
    471         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    472         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     487        virtual AttrExpr * clone() const override { return new AttrExpr( * this ); }
     488        virtual void accept( Visitor & v ) override { v.visit( this ); }
     489        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     490        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     491        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    473492};
    474493
     
    489508        void set_arg2( Expression * newValue ) { arg2 = newValue; }
    490509
    491         virtual LogicalExpr * clone() const { return new LogicalExpr( * this ); }
    492         virtual void accept( Visitor & v ) { v.visit( this ); }
    493         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    494         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     510        virtual LogicalExpr * clone() const override { return new LogicalExpr( * this ); }
     511        virtual void accept( Visitor & v ) override { v.visit( this ); }
     512        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     513        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     514        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    495515
    496516  private:
     
    516536        void set_arg3( Expression * newValue ) { arg3 = newValue; }
    517537
    518         virtual ConditionalExpr * clone() const { return new ConditionalExpr( * this ); }
    519         virtual void accept( Visitor & v ) { v.visit( this ); }
    520         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    521         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     538        virtual ConditionalExpr * clone() const override { return new ConditionalExpr( * this ); }
     539        virtual void accept( Visitor & v ) override { v.visit( this ); }
     540        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     541        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     542        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    522543};
    523544
     
    537558        void set_arg2( Expression * newValue ) { arg2 = newValue; }
    538559
    539         virtual CommaExpr * clone() const { return new CommaExpr( * this ); }
    540         virtual void accept( Visitor & v ) { v.visit( this ); }
    541         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    542         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     560        virtual CommaExpr * clone() const override { return new CommaExpr( * this ); }
     561        virtual void accept( Visitor & v ) override { v.visit( this ); }
     562        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     563        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     564        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    543565};
    544566
     
    555577        void set_type( Type * newValue ) { type = newValue; }
    556578
    557         virtual TypeExpr * clone() const { return new TypeExpr( * this ); }
    558         virtual void accept( Visitor & v ) { v.visit( this ); }
    559         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    560         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     579        virtual TypeExpr * clone() const override { return new TypeExpr( * this ); }
     580        virtual void accept( Visitor & v ) override { v.visit( this ); }
     581        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     582        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     583        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    561584};
    562585
     
    581604        void set_operand( Expression * newValue ) { operand = newValue; }
    582605
    583         virtual AsmExpr * clone() const { return new AsmExpr( * this ); }
    584         virtual void accept( Visitor & v ) { v.visit( this ); }
    585         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    586         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     606        virtual AsmExpr * clone() const override { return new AsmExpr( * this ); }
     607        virtual void accept( Visitor & v ) override { v.visit( this ); }
     608        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     609        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     610        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    587611
    588612        // https://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Machine-Constraints.html#Machine-Constraints
     
    599623        virtual ~ImplicitCopyCtorExpr();
    600624
    601         virtual ImplicitCopyCtorExpr * clone() const { return new ImplicitCopyCtorExpr( * this ); }
    602         virtual void accept( Visitor & v ) { v.visit( this ); }
    603         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    604         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     625        virtual ImplicitCopyCtorExpr * clone() const override { return new ImplicitCopyCtorExpr( * this ); }
     626        virtual void accept( Visitor & v ) override { v.visit( this ); }
     627        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     628        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     629        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    605630};
    606631
     
    617642        void set_callExpr( Expression * newValue ) { callExpr = newValue; }
    618643
    619         virtual ConstructorExpr * clone() const { return new ConstructorExpr( * this ); }
    620         virtual void accept( Visitor & v ) { v.visit( this ); }
    621         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    622         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     644        virtual ConstructorExpr * clone() const override { return new ConstructorExpr( * this ); }
     645        virtual void accept( Visitor & v ) override { v.visit( this ); }
     646        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     647        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     648        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    623649};
    624650
     
    635661        void set_initializer( Initializer * i ) { initializer = i; }
    636662
    637         virtual CompoundLiteralExpr * clone() const { return new CompoundLiteralExpr( * this ); }
    638         virtual void accept( Visitor & v ) { v.visit( this ); }
    639         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    640         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     663        virtual CompoundLiteralExpr * clone() const override { return new CompoundLiteralExpr( * this ); }
     664        virtual void accept( Visitor & v ) override { v.visit( this ); }
     665        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     666        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     667        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    641668};
    642669
     
    654681        RangeExpr * set_high( Expression * high ) { RangeExpr::high = high; return this; }
    655682
    656         virtual RangeExpr * clone() const { return new RangeExpr( * this ); }
    657         virtual void accept( Visitor & v ) { v.visit( this ); }
    658         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    659         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     683        virtual RangeExpr * clone() const override { return new RangeExpr( * this ); }
     684        virtual void accept( Visitor & v ) override { v.visit( this ); }
     685        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     686        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     687        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    660688};
    661689
     
    671699        std::list<Expression*>& get_exprs() { return exprs; }
    672700
    673         virtual UntypedTupleExpr * clone() const { return new UntypedTupleExpr( * this ); }
    674         virtual void accept( Visitor & v ) { v.visit( this ); }
    675         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    676         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     701        virtual UntypedTupleExpr * clone() const override { return new UntypedTupleExpr( * this ); }
     702        virtual void accept( Visitor & v ) override { v.visit( this ); }
     703        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     704        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     705        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    677706};
    678707
     
    688717        std::list<Expression*>& get_exprs() { return exprs; }
    689718
    690         virtual TupleExpr * clone() const { return new TupleExpr( * this ); }
    691         virtual void accept( Visitor & v ) { v.visit( this ); }
    692         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    693         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     719        virtual TupleExpr * clone() const override { return new TupleExpr( * this ); }
     720        virtual void accept( Visitor & v ) override { v.visit( this ); }
     721        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     722        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     723        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    694724};
    695725
     
    709739        TupleIndexExpr * set_index( unsigned int newValue ) { index = newValue; return this; }
    710740
    711         virtual TupleIndexExpr * clone() const { return new TupleIndexExpr( * this ); }
    712         virtual void accept( Visitor & v ) { v.visit( this ); }
    713         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    714         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     741        virtual TupleIndexExpr * clone() const override { return new TupleIndexExpr( * this ); }
     742        virtual void accept( Visitor & v ) override { v.visit( this ); }
     743        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     744        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     745        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    715746};
    716747
     
    727758        StmtExpr * get_stmtExpr() const { return stmtExpr; }
    728759
    729         virtual TupleAssignExpr * clone() const { return new TupleAssignExpr( * this ); }
    730         virtual void accept( Visitor & v ) { v.visit( this ); }
    731         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    732         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     760        virtual TupleAssignExpr * clone() const override { return new TupleAssignExpr( * this ); }
     761        virtual void accept( Visitor & v ) override { v.visit( this ); }
     762        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     763        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     764        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    733765
    734766        friend class ConverterNewToOld;
     
    760792        std::list< Expression * > & get_dtors() { return dtors; }
    761793
    762         virtual StmtExpr * clone() const { return new StmtExpr( * this ); }
    763         virtual void accept( Visitor & v ) { v.visit( this ); }
    764         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    765         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     794        virtual StmtExpr * clone() const override { return new StmtExpr( * this ); }
     795        virtual void accept( Visitor & v ) override { v.visit( this ); }
     796        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     797        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     798        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    766799};
    767800
     
    787820        int get_id() const { return id; }
    788821
    789         virtual UniqueExpr * clone() const { return new UniqueExpr( * this ); }
    790         virtual void accept( Visitor & v ) { v.visit( this ); }
    791         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    792         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     822        virtual UniqueExpr * clone() const override { return new UniqueExpr( * this ); }
     823        virtual void accept( Visitor & v ) override { v.visit( this ); }
     824        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     825        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     826        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    793827
    794828private:
     
    821855        std::list<InitAlternative> & get_initAlts() { return initAlts; }
    822856
    823         virtual UntypedInitExpr * clone() const { return new UntypedInitExpr( * this ); }
    824         virtual void accept( Visitor & v ) { v.visit( this ); }
    825         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    826         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     857        virtual UntypedInitExpr * clone() const override { return new UntypedInitExpr( * this ); }
     858        virtual void accept( Visitor & v ) override { v.visit( this ); }
     859        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     860        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     861        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    827862};
    828863
     
    842877        InitExpr * set_designation( Designation * newValue ) { designation = newValue; return this; }
    843878
    844         virtual InitExpr * clone() const { return new InitExpr( * this ); }
    845         virtual void accept( Visitor & v ) { v.visit( this ); }
    846         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    847         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     879        virtual InitExpr * clone() const override { return new InitExpr( * this ); }
     880        virtual void accept( Visitor & v ) override { v.visit( this ); }
     881        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     882        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     883        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    848884};
    849885
     
    858894        ~DeletedExpr();
    859895
    860         virtual DeletedExpr * clone() const { return new DeletedExpr( * this ); }
    861         virtual void accept( Visitor & v ) { v.visit( this ); }
    862         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    863         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     896        virtual DeletedExpr * clone() const override { return new DeletedExpr( * this ); }
     897        virtual void accept( Visitor & v ) override { v.visit( this ); }
     898        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     899        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     900        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    864901};
    865902
     
    873910        ~DefaultArgExpr();
    874911
    875         virtual DefaultArgExpr * clone() const { return new DefaultArgExpr( * this ); }
    876         virtual void accept( Visitor & v ) { v.visit( this ); }
    877         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    878         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     912        virtual DefaultArgExpr * clone() const override { return new DefaultArgExpr( * this ); }
     913        virtual void accept( Visitor & v ) override { v.visit( this ); }
     914        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     915        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     916        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    879917};
    880918
     
    901939        virtual ~GenericExpr();
    902940
    903         virtual GenericExpr * clone() const { return new GenericExpr( * this ); }
    904         virtual void accept( Visitor & v ) { v.visit( this ); }
    905         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    906         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     941        virtual GenericExpr * clone() const override { return new GenericExpr( * this ); }
     942        virtual void accept( Visitor & v ) override { v.visit( this ); }
     943        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     944        virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     945        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    907946};
    908947
  • src/SynTree/Initializer.h

    r302d84c2 rfce4e31  
    3838
    3939        virtual Designation * clone() const override { return new Designation( *this ); };
    40         virtual void accept( Visitor &v ) override { v.visit( this ); }
     40        virtual void accept( Visitor & v ) override { v.visit( this ); }
     41        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    4142        virtual Designation * acceptMutator( Mutator &m ) override { return m.mutate( this ); }
    4243        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
     
    5253        virtual ~Initializer();
    5354
    54         bool get_maybeConstructed() { return maybeConstructed; }
     55        bool get_maybeConstructed() const { return maybeConstructed; }
    5556
    5657        virtual Initializer *clone() const override = 0;
    57         virtual void accept( Visitor &v ) override = 0;
     58        virtual void accept( Visitor & v ) override = 0;
     59        virtual void accept( Visitor & v ) const override = 0;
    5860        virtual Initializer *acceptMutator( Mutator &m ) override = 0;
    5961        virtual void print( std::ostream &os, Indenter indent = {} ) const override = 0;
     
    7678
    7779        virtual SingleInit *clone() const override { return new SingleInit( *this); }
    78         virtual void accept( Visitor &v ) override { v.visit( this ); }
     80        virtual void accept( Visitor & v ) override { v.visit( this ); }
     81        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    7982        virtual Initializer *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    8083        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
     
    104107
    105108        virtual ListInit *clone() const override { return new ListInit( *this ); }
    106         virtual void accept( Visitor &v ) override { v.visit( this ); }
     109        virtual void accept( Visitor & v ) override { v.visit( this ); }
     110        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    107111        virtual Initializer *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    108112        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
     
    133137
    134138        ConstructorInit *clone() const override { return new ConstructorInit( *this ); }
    135         virtual void accept( Visitor &v ) override { v.visit( this ); }
     139        virtual void accept( Visitor & v ) override { v.visit( this ); }
     140        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    136141        virtual Initializer *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    137142        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
  • src/SynTree/Statement.h

    r302d84c2 rfce4e31  
    4545        virtual Statement * clone() const override = 0;
    4646        virtual void accept( Visitor & v ) override = 0;
     47        virtual void accept( Visitor & v ) const override = 0;
    4748        virtual Statement * acceptMutator( Mutator & m ) override = 0;
    4849        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    6465        virtual CompoundStmt * clone() const override { return new CompoundStmt( *this ); }
    6566        virtual void accept( Visitor & v ) override { v.visit( this ); }
     67        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    6668        virtual CompoundStmt * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
    6769        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    7476        virtual NullStmt * clone() const override { return new NullStmt( *this ); }
    7577        virtual void accept( Visitor & v ) override { v.visit( this ); }
     78        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    7679        virtual NullStmt * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
    7780        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    9194        virtual ExprStmt * clone() const override { return new ExprStmt( *this ); }
    9295        virtual void accept( Visitor & v ) override { v.visit( this ); }
     96        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    9397        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
    9498        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    120124        void set_gotolabels( const std::list<Label> & newValue ) { gotolabels = newValue; }
    121125
    122         virtual AsmStmt * clone() const { return new AsmStmt( *this ); }
    123         virtual void accept( Visitor & v ) { v.visit( this ); }
    124         virtual Statement * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    125         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     126        virtual AsmStmt * clone() const override { return new AsmStmt( *this ); }
     127        virtual void accept( Visitor & v ) override { v.visit( this ); }
     128        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     129        virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     130        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    126131};
    127132
     
    133138        virtual ~DirectiveStmt(){}
    134139
    135         virtual DirectiveStmt * clone() const { return new DirectiveStmt( *this ); }
    136         virtual void accept( Visitor & v ) { v.visit( this ); }
    137         virtual Statement * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    138         virtual void print( std::ostream & os, Indenter indent = {} ) const;
     140        virtual DirectiveStmt * clone() const override { return new DirectiveStmt( *this ); }
     141        virtual void accept( Visitor & v ) override { v.visit( this ); }
     142        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     143        virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
     144        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    139145};
    140146
     
    161167        virtual IfStmt * clone() const override { return new IfStmt( *this ); }
    162168        virtual void accept( Visitor & v ) override { v.visit( this ); }
     169        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    163170        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
    164171        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    180187
    181188        virtual void accept( Visitor & v ) override { v.visit( this ); }
     189        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    182190        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
    183191
     
    208216
    209217        virtual void accept( Visitor & v ) override { v.visit( this ); }
     218        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    210219        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
    211220
     
    236245        virtual WhileStmt * clone() const override { return new WhileStmt( *this ); }
    237246        virtual void accept( Visitor & v ) override { v.visit( this ); }
     247        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    238248        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
    239249        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    261271        virtual ForStmt * clone() const override { return new ForStmt( *this ); }
    262272        virtual void accept( Visitor & v ) override { v.visit( this ); }
     273        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    263274        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
    264275        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    290301        virtual BranchStmt * clone() const override { return new BranchStmt( *this ); }
    291302        virtual void accept( Visitor & v ) override { v.visit( this ); }
     303        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    292304        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
    293305        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    309321        virtual ReturnStmt * clone() const override { return new ReturnStmt( *this ); }
    310322        virtual void accept( Visitor & v ) override { v.visit( this ); }
     323        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    311324        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
    312325        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    333346        virtual ThrowStmt * clone() const override { return new ThrowStmt( *this ); }
    334347        virtual void accept( Visitor & v ) override { v.visit( this ); }
     348        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    335349        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
    336350        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    356370        virtual TryStmt * clone() const override { return new TryStmt( *this ); }
    357371        virtual void accept( Visitor & v ) override { v.visit( this ); }
     372        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    358373        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
    359374        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    384399        virtual CatchStmt * clone() const override { return new CatchStmt( *this ); }
    385400        virtual void accept( Visitor & v ) override { v.visit( this ); }
     401        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    386402        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
    387403        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    401417        virtual FinallyStmt * clone() const override { return new FinallyStmt( *this ); }
    402418        virtual void accept( Visitor & v ) override { v.visit( this ); }
     419        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    403420        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
    404421        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    438455        virtual WaitForStmt * clone() const override { return new WaitForStmt( *this ); }
    439456        virtual void accept( Visitor & v ) override { v.visit( this ); }
     457        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    440458        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
    441459        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    454472        virtual WithStmt * clone() const override { return new WithStmt( *this ); }
    455473        virtual void accept( Visitor & v ) override { v.visit( this ); }
     474        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    456475        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
    457476        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    473492        virtual DeclStmt * clone() const override { return new DeclStmt( *this ); }
    474493        virtual void accept( Visitor & v ) override { v.visit( this ); }
     494        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    475495        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
    476496        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    494514        virtual ImplicitCtorDtorStmt * clone() const override { return new ImplicitCtorDtorStmt( *this ); }
    495515        virtual void accept( Visitor & v ) override { v.visit( this ); }
     516        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    496517        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
    497518        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
  • src/SynTree/Type.h

    r302d84c2 rfce4e31  
    144144
    145145        Qualifiers & get_qualifiers() { return tq; }
    146         bool get_const() { return tq.is_const; }
    147         bool get_volatile() { return tq.is_volatile; }
    148         bool get_restrict() { return tq.is_restrict; }
    149         bool get_lvalue() { return tq.is_lvalue; }
    150         bool get_mutex() { return tq.is_mutex; }
    151         bool get_atomic() { return tq.is_atomic; }
     146        bool get_const() const { return tq.is_const; }
     147        bool get_volatile() const { return tq.is_volatile; }
     148        bool get_restrict() const { return tq.is_restrict; }
     149        bool get_lvalue() const { return tq.is_lvalue; }
     150        bool get_mutex() const { return tq.is_mutex; }
     151        bool get_atomic() const { return tq.is_atomic; }
    152152        void set_const( bool newValue ) { tq.is_const = newValue; }
    153153        void set_volatile( bool newValue ) { tq.is_volatile = newValue; }
     
    184184        virtual Type *clone() const = 0;
    185185        virtual void accept( Visitor & v ) = 0;
     186        virtual void accept( Visitor & v ) const = 0;
    186187        virtual Type *acceptMutator( Mutator & m ) = 0;
    187188        virtual void print( std::ostream & os, Indenter indent = {} ) const;
     
    201202        virtual VoidType *clone() const override { return new VoidType( *this ); }
    202203        virtual void accept( Visitor & v ) override { v.visit( this ); }
     204        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    203205        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    204206        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    259261        virtual BasicType *clone() const override { return new BasicType( *this ); }
    260262        virtual void accept( Visitor & v ) override { v.visit( this ); }
     263        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    261264        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    262265        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    294297        virtual PointerType *clone() const override { return new PointerType( *this ); }
    295298        virtual void accept( Visitor & v ) override { v.visit( this ); }
     299        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    296300        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    297301        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    325329        virtual ArrayType *clone() const override { return new ArrayType( *this ); }
    326330        virtual void accept( Visitor & v ) override { v.visit( this ); }
     331        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    327332        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    328333        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    340345        virtual QualifiedType *clone() const override { return new QualifiedType( *this ); }
    341346        virtual void accept( Visitor & v ) override { v.visit( this ); }
     347        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    342348        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    343349        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    366372        virtual ReferenceType *clone() const override { return new ReferenceType( *this ); }
    367373        virtual void accept( Visitor & v ) override { v.visit( this ); }
     374        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    368375        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    369376        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    395402        virtual FunctionType *clone() const override { return new FunctionType( *this ); }
    396403        virtual void accept( Visitor & v ) override { v.visit( this ); }
     404        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    397405        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    398406        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    455463        virtual StructInstType *clone() const override { return new StructInstType( *this ); }
    456464        virtual void accept( Visitor & v ) override { v.visit( this ); }
     465        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    457466        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    458467
     
    492501        virtual UnionInstType *clone() const override { return new UnionInstType( *this ); }
    493502        virtual void accept( Visitor & v ) override { v.visit( this ); }
     503        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    494504        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    495505
     
    519529        virtual EnumInstType *clone() const override { return new EnumInstType( *this ); }
    520530        virtual void accept( Visitor & v ) override { v.visit( this ); }
     531        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    521532        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    522533
     
    542553        virtual TraitInstType *clone() const override { return new TraitInstType( *this ); }
    543554        virtual void accept( Visitor & v ) override { v.visit( this ); }
     555        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    544556        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    545557  private:
     
    569581        virtual TypeInstType *clone() const override { return new TypeInstType( *this ); }
    570582        virtual void accept( Visitor & v ) override { v.visit( this ); }
     583        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    571584        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    572585        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    606619        virtual TupleType *clone() const override { return new TupleType( *this ); }
    607620        virtual void accept( Visitor & v ) override { v.visit( this ); }
     621        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    608622        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    609623        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    616630
    617631        TypeofType( const Type::Qualifiers & tq, Expression *expr, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
    618         TypeofType( const Type::Qualifiers & tq, Expression *expr, bool is_basetypeof, 
     632        TypeofType( const Type::Qualifiers & tq, Expression *expr, bool is_basetypeof,
    619633                const std::list< Attribute * > & attributes = std::list< Attribute * >() );
    620634        TypeofType( const TypeofType& );
     
    628642        virtual TypeofType *clone() const override { return new TypeofType( *this ); }
    629643        virtual void accept( Visitor & v ) override { v.visit( this ); }
     644        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    630645        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    631646        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    657672        virtual AttrType *clone() const override { return new AttrType( *this ); }
    658673        virtual void accept( Visitor & v ) override { v.visit( this ); }
     674        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    659675        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    660676        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    671687        virtual VarArgsType *clone() const override { return new VarArgsType( *this ); }
    672688        virtual void accept( Visitor & v ) override { v.visit( this ); }
     689        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    673690        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    674691        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    683700        virtual ZeroType *clone() const override { return new ZeroType( *this ); }
    684701        virtual void accept( Visitor & v ) override { v.visit( this ); }
     702        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    685703        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    686704        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    695713        virtual OneType *clone() const override { return new OneType( *this ); }
    696714        virtual void accept( Visitor & v ) override { v.visit( this ); }
     715        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    697716        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    698717        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     
    705724        virtual GlobalScopeType *clone() const override { return new GlobalScopeType( *this ); }
    706725        virtual void accept( Visitor & v ) override { v.visit( this ); }
     726        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    707727        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    708728        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
  • src/SynTree/Visitor.h

    r302d84c2 rfce4e31  
    2727        // of the given syntax node, but performs no other action.
    2828
    29         virtual void visit( ObjectDecl * objectDecl ) = 0;
    30         virtual void visit( FunctionDecl * functionDecl ) = 0;
    31         virtual void visit( StructDecl * aggregateDecl ) = 0;
    32         virtual void visit( UnionDecl * aggregateDecl ) = 0;
    33         virtual void visit( EnumDecl * aggregateDecl ) = 0;
    34         virtual void visit( TraitDecl * aggregateDecl ) = 0;
    35         virtual void visit( TypeDecl * typeDecl ) = 0;
    36         virtual void visit( TypedefDecl * typeDecl ) = 0;
    37         virtual void visit( AsmDecl * asmDecl ) = 0;
    38         virtual void visit( StaticAssertDecl * assertDecl ) = 0;
    39 
    40         virtual void visit( CompoundStmt * compoundStmt ) = 0;
    41         virtual void visit( ExprStmt * exprStmt ) = 0;
    42         virtual void visit( AsmStmt * asmStmt ) = 0;
    43         virtual void visit( DirectiveStmt * directiveStmt ) = 0;
    44         virtual void visit( IfStmt * ifStmt ) = 0;
    45         virtual void visit( WhileStmt * whileStmt ) = 0;
    46         virtual void visit( ForStmt * forStmt ) = 0;
    47         virtual void visit( SwitchStmt * switchStmt ) = 0;
    48         virtual void visit( CaseStmt * caseStmt ) = 0;
    49         virtual void visit( BranchStmt * branchStmt ) = 0;
    50         virtual void visit( ReturnStmt * returnStmt ) = 0;
    51         virtual void visit( ThrowStmt * throwStmt ) = 0;
    52         virtual void visit( TryStmt * tryStmt ) = 0;
    53         virtual void visit( CatchStmt * catchStmt ) = 0;
    54         virtual void visit( FinallyStmt * finallyStmt ) = 0;
    55         virtual void visit( WaitForStmt * waitforStmt ) = 0;
    56         virtual void visit( WithStmt * withStmt ) = 0;
    57         virtual void visit( NullStmt * nullStmt ) = 0;
    58         virtual void visit( DeclStmt * declStmt ) = 0;
    59         virtual void visit( ImplicitCtorDtorStmt * impCtorDtorStmt ) = 0;
    60 
    61         virtual void visit( ApplicationExpr * applicationExpr ) = 0;
    62         virtual void visit( UntypedExpr * untypedExpr ) = 0;
    63         virtual void visit( NameExpr * nameExpr ) = 0;
    64         virtual void visit( CastExpr * castExpr ) = 0;
    65         virtual void visit( KeywordCastExpr * castExpr ) = 0;
    66         virtual void visit( VirtualCastExpr * castExpr ) = 0;
    67         virtual void visit( AddressExpr * addressExpr ) = 0;
    68         virtual void visit( LabelAddressExpr * labAddressExpr ) = 0;
    69         virtual void visit( UntypedMemberExpr * memberExpr ) = 0;
    70         virtual void visit( MemberExpr * memberExpr ) = 0;
    71         virtual void visit( VariableExpr * variableExpr ) = 0;
    72         virtual void visit( ConstantExpr * constantExpr ) = 0;
    73         virtual void visit( SizeofExpr * sizeofExpr ) = 0;
    74         virtual void visit( AlignofExpr * alignofExpr ) = 0;
    75         virtual void visit( UntypedOffsetofExpr * offsetofExpr ) = 0;
    76         virtual void visit( OffsetofExpr * offsetofExpr ) = 0;
    77         virtual void visit( OffsetPackExpr * offsetPackExpr ) = 0;
    78         virtual void visit( AttrExpr * attrExpr ) = 0;
    79         virtual void visit( LogicalExpr * logicalExpr ) = 0;
    80         virtual void visit( ConditionalExpr * conditionalExpr ) = 0;
    81         virtual void visit( CommaExpr * commaExpr ) = 0;
    82         virtual void visit( TypeExpr * typeExpr ) = 0;
    83         virtual void visit( AsmExpr * asmExpr ) = 0;
    84         virtual void visit( ImplicitCopyCtorExpr * impCpCtorExpr ) = 0;
    85         virtual void visit( ConstructorExpr *  ctorExpr ) = 0;
    86         virtual void visit( CompoundLiteralExpr * compLitExpr ) = 0;
    87         virtual void visit( RangeExpr * rangeExpr ) = 0;
    88         virtual void visit( UntypedTupleExpr * tupleExpr ) = 0;
    89         virtual void visit( TupleExpr * tupleExpr ) = 0;
    90         virtual void visit( TupleIndexExpr * tupleExpr ) = 0;
    91         virtual void visit( TupleAssignExpr * assignExpr ) = 0;
    92         virtual void visit( StmtExpr *  stmtExpr ) = 0;
    93         virtual void visit( UniqueExpr *  uniqueExpr ) = 0;
    94         virtual void visit( UntypedInitExpr *  initExpr ) = 0;
    95         virtual void visit( InitExpr *  initExpr ) = 0;
    96         virtual void visit( DeletedExpr * delExpr ) = 0;
    97         virtual void visit( DefaultArgExpr * argExpr ) = 0;
    98         virtual void visit( GenericExpr * genExpr ) = 0;
    99 
    100         virtual void visit( VoidType * basicType ) = 0;
    101         virtual void visit( BasicType * basicType ) = 0;
    102         virtual void visit( PointerType * pointerType ) = 0;
    103         virtual void visit( ArrayType * arrayType ) = 0;
    104         virtual void visit( ReferenceType * refType ) = 0;
    105         virtual void visit( QualifiedType * qualType ) = 0;
    106         virtual void visit( FunctionType * functionType ) = 0;
    107         virtual void visit( StructInstType * aggregateUseType ) = 0;
    108         virtual void visit( UnionInstType * aggregateUseType ) = 0;
    109         virtual void visit( EnumInstType * aggregateUseType ) = 0;
    110         virtual void visit( TraitInstType * aggregateUseType ) = 0;
    111         virtual void visit( TypeInstType * aggregateUseType ) = 0;
    112         virtual void visit( TupleType * tupleType ) = 0;
    113         virtual void visit( TypeofType * typeofType ) = 0;
    114         virtual void visit( AttrType * attrType ) = 0;
    115         virtual void visit( VarArgsType * varArgsType ) = 0;
    116         virtual void visit( ZeroType * zeroType ) = 0;
    117         virtual void visit( OneType * oneType ) = 0;
    118         virtual void visit( GlobalScopeType * globalType ) = 0;
    119 
    120         virtual void visit( Designation * designation ) = 0;
    121         virtual void visit( SingleInit * singleInit ) = 0;
    122         virtual void visit( ListInit * listInit ) = 0;
    123         virtual void visit( ConstructorInit * ctorInit ) = 0;
    124 
    125         virtual void visit( Constant * constant ) = 0;
    126 
    127         virtual void visit( Attribute * attribute ) = 0;
     29        virtual void visit( ObjectDecl * node ) { visit( const_cast<const ObjectDecl *>(node) ); }
     30        virtual void visit( const ObjectDecl * objectDecl ) = 0;
     31        virtual void visit( FunctionDecl * node ) { visit( const_cast<const FunctionDecl *>(node) ); }
     32        virtual void visit( const FunctionDecl * functionDecl ) = 0;
     33        virtual void visit( StructDecl * node ) { visit( const_cast<const StructDecl *>(node) ); }
     34        virtual void visit( const StructDecl * aggregateDecl ) = 0;
     35        virtual void visit( UnionDecl * node ) { visit( const_cast<const UnionDecl *>(node) ); }
     36        virtual void visit( const UnionDecl * aggregateDecl ) = 0;
     37        virtual void visit( EnumDecl * node ) { visit( const_cast<const EnumDecl *>(node) ); }
     38        virtual void visit( const EnumDecl * aggregateDecl ) = 0;
     39        virtual void visit( TraitDecl * node ) { visit( const_cast<const TraitDecl *>(node) ); }
     40        virtual void visit( const TraitDecl * aggregateDecl ) = 0;
     41        virtual void visit( TypeDecl * node ) { visit( const_cast<const TypeDecl *>(node) ); }
     42        virtual void visit( const TypeDecl * typeDecl ) = 0;
     43        virtual void visit( TypedefDecl * node ) { visit( const_cast<const TypedefDecl *>(node) ); }
     44        virtual void visit( const TypedefDecl * typeDecl ) = 0;
     45        virtual void visit( AsmDecl * node ) { visit( const_cast<const AsmDecl *>(node) ); }
     46        virtual void visit( const AsmDecl * asmDecl ) = 0;
     47        virtual void visit( StaticAssertDecl * node ) { visit( const_cast<const StaticAssertDecl *>(node) ); }
     48        virtual void visit( const StaticAssertDecl * assertDecl ) = 0;
     49
     50        virtual void visit( CompoundStmt * node ) { visit( const_cast<const CompoundStmt *>(node) ); }
     51        virtual void visit( const CompoundStmt * compoundStmt ) = 0;
     52        virtual void visit( ExprStmt * node ) { visit( const_cast<const ExprStmt *>(node) ); }
     53        virtual void visit( const ExprStmt * exprStmt ) = 0;
     54        virtual void visit( AsmStmt * node ) { visit( const_cast<const AsmStmt *>(node) ); }
     55        virtual void visit( const AsmStmt * asmStmt ) = 0;
     56        virtual void visit( DirectiveStmt * node ) { visit( const_cast<const DirectiveStmt *>(node) ); }
     57        virtual void visit( const DirectiveStmt * directiveStmt ) = 0;
     58        virtual void visit( IfStmt * node ) { visit( const_cast<const IfStmt *>(node) ); }
     59        virtual void visit( const IfStmt * ifStmt ) = 0;
     60        virtual void visit( WhileStmt * node ) { visit( const_cast<const WhileStmt *>(node) ); }
     61        virtual void visit( const WhileStmt * whileStmt ) = 0;
     62        virtual void visit( ForStmt * node ) { visit( const_cast<const ForStmt *>(node) ); }
     63        virtual void visit( const ForStmt * forStmt ) = 0;
     64        virtual void visit( SwitchStmt * node ) { visit( const_cast<const SwitchStmt *>(node) ); }
     65        virtual void visit( const SwitchStmt * switchStmt ) = 0;
     66        virtual void visit( CaseStmt * node ) { visit( const_cast<const CaseStmt *>(node) ); }
     67        virtual void visit( const CaseStmt * caseStmt ) = 0;
     68        virtual void visit( BranchStmt * node ) { visit( const_cast<const BranchStmt *>(node) ); }
     69        virtual void visit( const BranchStmt * branchStmt ) = 0;
     70        virtual void visit( ReturnStmt * node ) { visit( const_cast<const ReturnStmt *>(node) ); }
     71        virtual void visit( const ReturnStmt * returnStmt ) = 0;
     72        virtual void visit( ThrowStmt * node ) { visit( const_cast<const ThrowStmt *>(node) ); }
     73        virtual void visit( const ThrowStmt * throwStmt ) = 0;
     74        virtual void visit( TryStmt * node ) { visit( const_cast<const TryStmt *>(node) ); }
     75        virtual void visit( const TryStmt * tryStmt ) = 0;
     76        virtual void visit( CatchStmt * node ) { visit( const_cast<const CatchStmt *>(node) ); }
     77        virtual void visit( const CatchStmt * catchStmt ) = 0;
     78        virtual void visit( FinallyStmt * node ) { visit( const_cast<const FinallyStmt *>(node) ); }
     79        virtual void visit( const FinallyStmt * finallyStmt ) = 0;
     80        virtual void visit( WaitForStmt * node ) { visit( const_cast<const WaitForStmt *>(node) ); }
     81        virtual void visit( const WaitForStmt * waitforStmt ) = 0;
     82        virtual void visit( WithStmt * node ) { visit( const_cast<const WithStmt *>(node) ); }
     83        virtual void visit( const WithStmt * withStmt ) = 0;
     84        virtual void visit( NullStmt * node ) { visit( const_cast<const NullStmt *>(node) ); }
     85        virtual void visit( const NullStmt * nullStmt ) = 0;
     86        virtual void visit( DeclStmt * node ) { visit( const_cast<const DeclStmt *>(node) ); }
     87        virtual void visit( const DeclStmt * declStmt ) = 0;
     88        virtual void visit( ImplicitCtorDtorStmt * node ) { visit( const_cast<const ImplicitCtorDtorStmt *>(node) ); }
     89        virtual void visit( const ImplicitCtorDtorStmt * impCtorDtorStmt ) = 0;
     90
     91        virtual void visit( ApplicationExpr * node ) { visit( const_cast<const ApplicationExpr *>(node) ); }
     92        virtual void visit( const ApplicationExpr * applicationExpr ) = 0;
     93        virtual void visit( UntypedExpr * node ) { visit( const_cast<const UntypedExpr *>(node) ); }
     94        virtual void visit( const UntypedExpr * untypedExpr ) = 0;
     95        virtual void visit( NameExpr * node ) { visit( const_cast<const NameExpr *>(node) ); }
     96        virtual void visit( const NameExpr * nameExpr ) = 0;
     97        virtual void visit( CastExpr * node ) { visit( const_cast<const CastExpr *>(node) ); }
     98        virtual void visit( const CastExpr * castExpr ) = 0;
     99        virtual void visit( KeywordCastExpr * node ) { visit( const_cast<const KeywordCastExpr *>(node) ); }
     100        virtual void visit( const KeywordCastExpr * castExpr ) = 0;
     101        virtual void visit( VirtualCastExpr * node ) { visit( const_cast<const VirtualCastExpr *>(node) ); }
     102        virtual void visit( const VirtualCastExpr * castExpr ) = 0;
     103        virtual void visit( AddressExpr * node ) { visit( const_cast<const AddressExpr *>(node) ); }
     104        virtual void visit( const AddressExpr * addressExpr ) = 0;
     105        virtual void visit( LabelAddressExpr * node ) { visit( const_cast<const LabelAddressExpr *>(node) ); }
     106        virtual void visit( const LabelAddressExpr * labAddressExpr ) = 0;
     107        virtual void visit( UntypedMemberExpr * node ) { visit( const_cast<const UntypedMemberExpr *>(node) ); }
     108        virtual void visit( const UntypedMemberExpr * memberExpr ) = 0;
     109        virtual void visit( MemberExpr * node ) { visit( const_cast<const MemberExpr *>(node) ); }
     110        virtual void visit( const MemberExpr * memberExpr ) = 0;
     111        virtual void visit( VariableExpr * node ) { visit( const_cast<const VariableExpr *>(node) ); }
     112        virtual void visit( const VariableExpr * variableExpr ) = 0;
     113        virtual void visit( ConstantExpr * node ) { visit( const_cast<const ConstantExpr *>(node) ); }
     114        virtual void visit( const ConstantExpr * constantExpr ) = 0;
     115        virtual void visit( SizeofExpr * node ) { visit( const_cast<const SizeofExpr *>(node) ); }
     116        virtual void visit( const SizeofExpr * sizeofExpr ) = 0;
     117        virtual void visit( AlignofExpr * node ) { visit( const_cast<const AlignofExpr *>(node) ); }
     118        virtual void visit( const AlignofExpr * alignofExpr ) = 0;
     119        virtual void visit( UntypedOffsetofExpr * node ) { visit( const_cast<const UntypedOffsetofExpr *>(node) ); }
     120        virtual void visit( const UntypedOffsetofExpr * offsetofExpr ) = 0;
     121        virtual void visit( OffsetofExpr * node ) { visit( const_cast<const OffsetofExpr *>(node) ); }
     122        virtual void visit( const OffsetofExpr * offsetofExpr ) = 0;
     123        virtual void visit( OffsetPackExpr * node ) { visit( const_cast<const OffsetPackExpr *>(node) ); }
     124        virtual void visit( const OffsetPackExpr * offsetPackExpr ) = 0;
     125        virtual void visit( AttrExpr * node ) { visit( const_cast<const AttrExpr *>(node) ); }
     126        virtual void visit( const AttrExpr * attrExpr ) = 0;
     127        virtual void visit( LogicalExpr * node ) { visit( const_cast<const LogicalExpr *>(node) ); }
     128        virtual void visit( const LogicalExpr * logicalExpr ) = 0;
     129        virtual void visit( ConditionalExpr * node ) { visit( const_cast<const ConditionalExpr *>(node) ); }
     130        virtual void visit( const ConditionalExpr * conditionalExpr ) = 0;
     131        virtual void visit( CommaExpr * node ) { visit( const_cast<const CommaExpr *>(node) ); }
     132        virtual void visit( const CommaExpr * commaExpr ) = 0;
     133        virtual void visit( TypeExpr * node ) { visit( const_cast<const TypeExpr *>(node) ); }
     134        virtual void visit( const TypeExpr * typeExpr ) = 0;
     135        virtual void visit( AsmExpr * node ) { visit( const_cast<const AsmExpr *>(node) ); }
     136        virtual void visit( const AsmExpr * asmExpr ) = 0;
     137        virtual void visit( ImplicitCopyCtorExpr * node ) { visit( const_cast<const ImplicitCopyCtorExpr *>(node) ); }
     138        virtual void visit( const ImplicitCopyCtorExpr * impCpCtorExpr ) = 0;
     139        virtual void visit( ConstructorExpr * node ) { visit( const_cast<const ConstructorExpr *>(node) ); }
     140        virtual void visit( const ConstructorExpr *  ctorExpr ) = 0;
     141        virtual void visit( CompoundLiteralExpr * node ) { visit( const_cast<const CompoundLiteralExpr *>(node) ); }
     142        virtual void visit( const CompoundLiteralExpr * compLitExpr ) = 0;
     143        virtual void visit( RangeExpr * node ) { visit( const_cast<const RangeExpr *>(node) ); }
     144        virtual void visit( const RangeExpr * rangeExpr ) = 0;
     145        virtual void visit( UntypedTupleExpr * node ) { visit( const_cast<const UntypedTupleExpr *>(node) ); }
     146        virtual void visit( const UntypedTupleExpr * tupleExpr ) = 0;
     147        virtual void visit( TupleExpr * node ) { visit( const_cast<const TupleExpr *>(node) ); }
     148        virtual void visit( const TupleExpr * tupleExpr ) = 0;
     149        virtual void visit( TupleIndexExpr * node ) { visit( const_cast<const TupleIndexExpr *>(node) ); }
     150        virtual void visit( const TupleIndexExpr * tupleExpr ) = 0;
     151        virtual void visit( TupleAssignExpr * node ) { visit( const_cast<const TupleAssignExpr *>(node) ); }
     152        virtual void visit( const TupleAssignExpr * assignExpr ) = 0;
     153        virtual void visit( StmtExpr * node ) { visit( const_cast<const StmtExpr *>(node) ); }
     154        virtual void visit( const StmtExpr *  stmtExpr ) = 0;
     155        virtual void visit( UniqueExpr * node ) { visit( const_cast<const UniqueExpr *>(node) ); }
     156        virtual void visit( const UniqueExpr *  uniqueExpr ) = 0;
     157        virtual void visit( UntypedInitExpr * node ) { visit( const_cast<const UntypedInitExpr *>(node) ); }
     158        virtual void visit( const UntypedInitExpr *  initExpr ) = 0;
     159        virtual void visit( InitExpr * node ) { visit( const_cast<const InitExpr *>(node) ); }
     160        virtual void visit( const InitExpr *  initExpr ) = 0;
     161        virtual void visit( DeletedExpr * node ) { visit( const_cast<const DeletedExpr *>(node) ); }
     162        virtual void visit( const DeletedExpr * delExpr ) = 0;
     163        virtual void visit( DefaultArgExpr * node ) { visit( const_cast<const DefaultArgExpr *>(node) ); }
     164        virtual void visit( const DefaultArgExpr * argExpr ) = 0;
     165        virtual void visit( GenericExpr * node ) { visit( const_cast<const GenericExpr *>(node) ); }
     166        virtual void visit( const GenericExpr * genExpr ) = 0;
     167
     168        virtual void visit( VoidType * node ) { visit( const_cast<const VoidType *>(node) ); }
     169        virtual void visit( const VoidType * basicType ) = 0;
     170        virtual void visit( BasicType * node ) { visit( const_cast<const BasicType *>(node) ); }
     171        virtual void visit( const BasicType * basicType ) = 0;
     172        virtual void visit( PointerType * node ) { visit( const_cast<const PointerType *>(node) ); }
     173        virtual void visit( const PointerType * pointerType ) = 0;
     174        virtual void visit( ArrayType * node ) { visit( const_cast<const ArrayType *>(node) ); }
     175        virtual void visit( const ArrayType * arrayType ) = 0;
     176        virtual void visit( ReferenceType * node ) { visit( const_cast<const ReferenceType *>(node) ); }
     177        virtual void visit( const ReferenceType * refType ) = 0;
     178        virtual void visit( QualifiedType * node ) { visit( const_cast<const QualifiedType *>(node) ); }
     179        virtual void visit( const QualifiedType * qualType ) = 0;
     180        virtual void visit( FunctionType * node ) { visit( const_cast<const FunctionType *>(node) ); }
     181        virtual void visit( const FunctionType * functionType ) = 0;
     182        virtual void visit( StructInstType * node ) { visit( const_cast<const StructInstType *>(node) ); }
     183        virtual void visit( const StructInstType * aggregateUseType ) = 0;
     184        virtual void visit( UnionInstType * node ) { visit( const_cast<const UnionInstType *>(node) ); }
     185        virtual void visit( const UnionInstType * aggregateUseType ) = 0;
     186        virtual void visit( EnumInstType * node ) { visit( const_cast<const EnumInstType *>(node) ); }
     187        virtual void visit( const EnumInstType * aggregateUseType ) = 0;
     188        virtual void visit( TraitInstType * node ) { visit( const_cast<const TraitInstType *>(node) ); }
     189        virtual void visit( const TraitInstType * aggregateUseType ) = 0;
     190        virtual void visit( TypeInstType * node ) { visit( const_cast<const TypeInstType *>(node) ); }
     191        virtual void visit( const TypeInstType * aggregateUseType ) = 0;
     192        virtual void visit( TupleType * node ) { visit( const_cast<const TupleType *>(node) ); }
     193        virtual void visit( const TupleType * tupleType ) = 0;
     194        virtual void visit( TypeofType * node ) { visit( const_cast<const TypeofType *>(node) ); }
     195        virtual void visit( const TypeofType * typeofType ) = 0;
     196        virtual void visit( AttrType * node ) { visit( const_cast<const AttrType *>(node) ); }
     197        virtual void visit( const AttrType * attrType ) = 0;
     198        virtual void visit( VarArgsType * node ) { visit( const_cast<const VarArgsType *>(node) ); }
     199        virtual void visit( const VarArgsType * varArgsType ) = 0;
     200        virtual void visit( ZeroType * node ) { visit( const_cast<const ZeroType *>(node) ); }
     201        virtual void visit( const ZeroType * zeroType ) = 0;
     202        virtual void visit( OneType * node ) { visit( const_cast<const OneType *>(node) ); }
     203        virtual void visit( const OneType * oneType ) = 0;
     204        virtual void visit( GlobalScopeType * node ) { visit( const_cast<const GlobalScopeType *>(node) ); }
     205        virtual void visit( const GlobalScopeType * globalType ) = 0;
     206
     207        virtual void visit( Designation * node ) { visit( const_cast<const Designation *>(node) ); }
     208        virtual void visit( const Designation * designation ) = 0;
     209        virtual void visit( SingleInit * node ) { visit( const_cast<const SingleInit *>(node) ); }
     210        virtual void visit( const SingleInit * singleInit ) = 0;
     211        virtual void visit( ListInit * node ) { visit( const_cast<const ListInit *>(node) ); }
     212        virtual void visit( const ListInit * listInit ) = 0;
     213        virtual void visit( ConstructorInit * node ) { visit( const_cast<const ConstructorInit *>(node) ); }
     214        virtual void visit( const ConstructorInit * ctorInit ) = 0;
     215
     216        virtual void visit( Constant * node ) { visit( const_cast<const Constant *>(node) ); }
     217        virtual void visit( const Constant * constant ) = 0;
     218
     219        virtual void visit( Attribute * node ) { visit( const_cast<const Attribute *>(node) ); }
     220        virtual void visit( const Attribute * attribute ) = 0;
    128221};
    129222
  • src/Tuples/Explode.h

    r302d84c2 rfce4e31  
    5151        template<typename OutputIterator>
    5252        void append( OutputIterator out, Expression* expr, const ResolvExpr::TypeEnvironment& env,
    53                         const ResolvExpr::OpenVarSet& openVars, const ResolvExpr::AssertionList& need, 
     53                        const ResolvExpr::OpenVarSet& openVars, const ResolvExpr::AssertionList& need,
    5454                        const ResolvExpr::Cost& cost, const ResolvExpr::Cost& cvtCost ) {
    5555                *out++ = ResolvExpr::Alternative{ expr, env, openVars, need, cost, cvtCost };
     
    5858        /// Append alternative to an ExplodedActual
    5959        static inline void append( ResolvExpr::ExplodedActual& ea, Expression* expr,
    60                         const ResolvExpr::TypeEnvironment&, const ResolvExpr::OpenVarSet&, 
     60                        const ResolvExpr::TypeEnvironment&, const ResolvExpr::OpenVarSet&,
    6161                        const ResolvExpr::AssertionList&, const ResolvExpr::Cost&, const ResolvExpr::Cost& ) {
    6262                ea.exprs.emplace_back( expr );
     
    111111                } else {
    112112                        // atomic (non-tuple) type - output a clone of the expression in a new alternative
    113                         append( std::forward<Output>(out), expr->clone(), alt.env, alt.openVars, alt.need, 
     113                        append( std::forward<Output>(out), expr->clone(), alt.env, alt.openVars, alt.need,
    114114                                alt.cost, alt.cvtCost );
    115115                }
     
    174174template< typename Output >
    175175void explodeRecursive(
    176         const ast::CastExpr * expr, const ResolvExpr::Candidate & arg,
    177         const ast::SymbolTable & symtab, Output && out
     176        const ast::CastExpr *, const ResolvExpr::Candidate &,
     177        const ast::SymbolTable &, Output &&
    178178) {
    179179}
     
    240240/// explode list of candidates into flattened list of candidates
    241241template< typename Output >
    242 void explode( 
    243         const ResolvExpr::CandidateList & cands, const ast::SymbolTable & symtab, Output && out, 
     242void explode(
     243        const ResolvExpr::CandidateList & cands, const ast::SymbolTable & symtab, Output && out,
    244244        bool isTupleAssign = false
    245245) {
  • src/Tuples/TupleAssignment.cc

    r302d84c2 rfce4e31  
    6767                struct Matcher {
    6868                  public:
    69                         Matcher( TupleAssignSpotter_old &spotter, const ResolvExpr::AltList& lhs, 
     69                        Matcher( TupleAssignSpotter_old &spotter, const ResolvExpr::AltList& lhs,
    7070                                const ResolvExpr::AltList& rhs );
    7171                        virtual ~Matcher() {}
    72                        
     72
    7373                        virtual void match( std::list< Expression * > &out ) = 0;
    7474                        ObjectDecl * newObject( UniqueName & namer, Expression * expr );
     
    8383                                for ( const ResolvExpr::Alternative& alt : alts ) { combineState( alt ); }
    8484                        }
    85                        
     85
    8686                        ResolvExpr::AltList lhs, rhs;
    8787                        TupleAssignSpotter_old &spotter;
     
    264264                }
    265265
    266                 // extract expressions from the assignment alternatives to produce a list of assignments 
     266                // extract expressions from the assignment alternatives to produce a list of assignments
    267267                // that together form a single alternative
    268268                std::list< Expression *> solved_assigns;
     
    271271                        matcher->combineState( alt );
    272272                }
    273                
     273
    274274                // xxx -- was push_front
    275275                currentFinder.get_alternatives().push_back( ResolvExpr::Alternative{
    276                         new TupleAssignExpr{ solved_assigns, matcher->tmpDecls }, matcher->compositeEnv, 
    277                         matcher->openVars, 
    278                         ResolvExpr::AssertionList( matcher->need.begin(), matcher->need.end() ), 
     276                        new TupleAssignExpr{ solved_assigns, matcher->tmpDecls }, matcher->compositeEnv,
     277                        matcher->openVars,
     278                        ResolvExpr::AssertionList( matcher->need.begin(), matcher->need.end() ),
    279279                        ResolvExpr::sumCost( current ) + matcher->baseCost } );
    280280        }
     
    284284        : lhs(lhs), rhs(rhs), spotter(spotter),
    285285          baseCost( ResolvExpr::sumCost( lhs ) + ResolvExpr::sumCost( rhs ) ) {
    286                 combineState( lhs ); 
     286                combineState( lhs );
    287287                combineState( rhs );
    288288        }
     
    390390                return dynamic_cast< const ast::TupleType * >( expr->result->stripReferences() );
    391391        }
    392        
     392
    393393        /// true if `expr` is of tuple type or a reference to one
    394394        bool refToTuple( const ast::Expr * expr ) {
     
    421421                        }
    422422
    423                         Matcher( 
     423                        Matcher(
    424424                                TupleAssignSpotter_new & s, const CodeLocation & loc,
    425425                                const ResolvExpr::CandidateList & l, const ResolvExpr::CandidateList & r )
    426                         : lhs( l ), rhs( r ), spotter( s ), location( loc ), 
    427                           baseCost( ResolvExpr::sumCost( lhs ) + ResolvExpr::sumCost( rhs ) ), tmpDecls(), 
     426                        : lhs( l ), rhs( r ), spotter( s ), location( loc ),
     427                          baseCost( ResolvExpr::sumCost( lhs ) + ResolvExpr::sumCost( rhs ) ), tmpDecls(),
    428428                          env(), open(), need() {
    429429                                for ( auto & cand : lhs ) combineState( *cand );
    430430                                for ( auto & cand : rhs ) combineState( *cand );
    431431                        }
     432                        virtual ~Matcher() = default;
    432433
    433434                        virtual std::vector< ast::ptr< ast::Expr > > match() = 0;
    434435
    435                         /// removes environments from subexpressions within statement expressions, which could 
    436                         /// throw off later passes like those in Box which rely on PolyMutator, and adds the 
     436                        /// removes environments from subexpressions within statement expressions, which could
     437                        /// throw off later passes like those in Box which rely on PolyMutator, and adds the
    437438                        /// bindings to the env
    438439                        struct EnvRemover {
     
    455456                        ast::ObjectDecl * newObject( UniqueName & namer, const ast::Expr * expr ) {
    456457                                assert( expr->result && ! expr->result->isVoid() );
    457                                
    458                                 ast::ObjectDecl * ret = new ast::ObjectDecl{ 
    459                                         location, namer.newName(), expr->result, new ast::SingleInit{ location, expr }, 
     458
     459                                ast::ObjectDecl * ret = new ast::ObjectDecl{
     460                                        location, namer.newName(), expr->result, new ast::SingleInit{ location, expr },
    460461                                        ast::Storage::Classes{}, ast::Linkage::Cforall };
    461                                
     462
    462463                                // if expression type is a reference, just need an initializer, otherwise construct
    463464                                if ( ! expr->result.as< ast::ReferenceType >() ) {
    464465                                        // resolve ctor/dtor for the new object
    465                                         ast::ptr< ast::Init > ctorInit = ResolvExpr::resolveCtorInit( 
     466                                        ast::ptr< ast::Init > ctorInit = ResolvExpr::resolveCtorInit(
    466467                                                        InitTweak::genCtorInit( location, ret ), spotter.crntFinder.symtab );
    467468                                        // remove environments from subexpressions of stmtExpr
     
    474475                        }
    475476
    476                         ast::UntypedExpr * createFunc( 
    477                                 const std::string & fname, const ast::ObjectDecl * left, 
    478                                 const ast::ObjectDecl * right 
     477                        ast::UntypedExpr * createFunc(
     478                                const std::string & fname, const ast::ObjectDecl * left,
     479                                const ast::ObjectDecl * right
    479480                        ) {
    480481                                assert( left );
     
    486487                                        args.front() = new ast::AddressExpr{ location, args.front() };
    487488                                        if ( right ) { args.back() = new ast::AddressExpr{ location, args.back() }; }
    488                                         return new ast::UntypedExpr{ 
     489                                        return new ast::UntypedExpr{
    489490                                                location, new ast::NameExpr{ location, "?=?" }, std::move(args) };
    490491                                } else {
    491                                         return new ast::UntypedExpr{ 
     492                                        return new ast::UntypedExpr{
    492493                                                location, new ast::NameExpr{ location, fname }, std::move(args) };
    493494                                }
     
    498499                struct MassAssignMatcher final : public Matcher {
    499500                        MassAssignMatcher(
    500                                 TupleAssignSpotter_new & s, const CodeLocation & loc, 
     501                                TupleAssignSpotter_new & s, const CodeLocation & loc,
    501502                                const ResolvExpr::CandidateList & l, const ResolvExpr::CandidateList & r )
    502503                        : Matcher( s, loc, l, r ) {}
     
    508509                                assert( lhs.empty() ? rhs.empty() : rhs.size() <= 1 );
    509510
    510                                 ast::ptr< ast::ObjectDecl > rtmp = 
     511                                ast::ptr< ast::ObjectDecl > rtmp =
    511512                                        rhs.size() == 1 ? newObject( rhsNamer, rhs.front()->expr ) : nullptr;
    512513
    513514                                std::vector< ast::ptr< ast::Expr > > out;
    514515                                for ( ResolvExpr::CandidateRef & lhsCand : lhs ) {
    515                                         // create a temporary object for each value in the LHS and create a call 
     516                                        // create a temporary object for each value in the LHS and create a call
    516517                                        // involving the RHS
    517518                                        ast::ptr< ast::ObjectDecl > ltmp = newObject( lhsNamer, lhsCand->expr );
     
    528529                struct MultipleAssignMatcher final : public Matcher {
    529530                        MultipleAssignMatcher(
    530                                 TupleAssignSpotter_new & s, const CodeLocation & loc, 
     531                                TupleAssignSpotter_new & s, const CodeLocation & loc,
    531532                                const ResolvExpr::CandidateList & l, const ResolvExpr::CandidateList & r )
    532533                        : Matcher( s, loc, l, r ) {}
     
    538539                                if ( lhs.size() != rhs.size() ) return {};
    539540
    540                                 // produce a new temporary object for each value in the LHS and RHS and pairwise 
     541                                // produce a new temporary object for each value in the LHS and RHS and pairwise
    541542                                // create the calls
    542543                                std::vector< ast::ptr< ast::ObjectDecl > > ltmp, rtmp;
     
    547548                                        ResolvExpr::CandidateRef & rhsCand = rhs[i];
    548549
    549                                         // convert RHS to LHS type minus one reference -- important for case where LHS 
     550                                        // convert RHS to LHS type minus one reference -- important for case where LHS
    550551                                        // is && and RHS is lvalue
    551552                                        auto lhsType = lhsCand->expr->result.strict_as< ast::ReferenceType >();
     
    557558                                        rtmp.emplace_back( std::move( robj ) );
    558559
    559                                         // resolve the cast expression so that rhsCand return type is bound by the cast 
     560                                        // resolve the cast expression so that rhsCand return type is bound by the cast
    560561                                        // type as needed, and transfer the resulting environment
    561562                                        ResolvExpr::CandidateFinder finder{ spotter.crntFinder.symtab, env };
     
    564565                                        env = std::move( finder.candidates.front()->env );
    565566                                }
    566                                
     567
    567568                                splice( tmpDecls, ltmp );
    568569                                splice( tmpDecls, rtmp );
    569                                
     570
    570571                                return out;
    571572                        }
     
    575576                std::string fname;
    576577                std::unique_ptr< Matcher > matcher;
    577        
     578
    578579        public:
    579                 TupleAssignSpotter_new( ResolvExpr::CandidateFinder & f ) 
     580                TupleAssignSpotter_new( ResolvExpr::CandidateFinder & f )
    580581                : crntFinder( f ), fname(), matcher() {}
    581582
    582583                // find left- and right-hand-sides for mass or multiple assignment
    583                 void spot( 
    584                         const ast::UntypedExpr * expr, std::vector< ResolvExpr::CandidateFinder > & args 
     584                void spot(
     585                        const ast::UntypedExpr * expr, std::vector< ResolvExpr::CandidateFinder > & args
    585586                ) {
    586587                        if ( auto op = expr->func.as< ast::NameExpr >() ) {
     
    599600                                        if ( ! refToTuple( lhsCand->expr ) ) continue;
    600601
    601                                         // explode is aware of casts - ensure every LHS is sent into explode with a 
     602                                        // explode is aware of casts - ensure every LHS is sent into explode with a
    602603                                        // reference cast
    603604                                        if ( ! lhsCand->expr.as< ast::CastExpr >() ) {
    604                                                 lhsCand->expr = new ast::CastExpr{ 
     605                                                lhsCand->expr = new ast::CastExpr{
    605606                                                        lhsCand->expr, new ast::ReferenceType{ lhsCand->expr->result } };
    606607                                        }
     
    610611                                        explode( *lhsCand, crntFinder.symtab, back_inserter(lhs), true );
    611612                                        for ( ResolvExpr::CandidateRef & cand : lhs ) {
    612                                                 // each LHS value must be a reference - some come in with a cast, if not 
     613                                                // each LHS value must be a reference - some come in with a cast, if not
    613614                                                // just cast to reference here
    614615                                                if ( ! cand->expr->result.as< ast::ReferenceType >() ) {
     
    629630                                                                // multiple assignment
    630631                                                                explode( *rhsCand, crntFinder.symtab, back_inserter(rhs), true );
    631                                                                 matcher.reset( 
     632                                                                matcher.reset(
    632633                                                                        new MultipleAssignMatcher{ *this, expr->location, lhs, rhs } );
    633634                                                        } else {
    634635                                                                // mass assignment
    635636                                                                rhs.emplace_back( rhsCand );
    636                                                                 matcher.reset( 
     637                                                                matcher.reset(
    637638                                                                        new MassAssignMatcher{ *this, expr->location, lhs, rhs } );
    638639                                                        }
     
    642643                                                // expand all possible RHS possibilities
    643644                                                std::vector< ResolvExpr::CandidateList > rhsCands;
    644                                                 combos( 
     645                                                combos(
    645646                                                        std::next( args.begin(), 1 ), args.end(), back_inserter( rhsCands ) );
    646647                                                for ( const ResolvExpr::CandidateList & rhsCand : rhsCands ) {
     
    648649                                                        ResolvExpr::CandidateList rhs;
    649650                                                        explode( rhsCand, crntFinder.symtab, back_inserter(rhs), true );
    650                                                         matcher.reset( 
     651                                                        matcher.reset(
    651652                                                                new MultipleAssignMatcher{ *this, expr->location, lhs, rhs } );
    652653                                                        match();
     
    663664
    664665                        if ( ! ( matcher->lhs.empty() && matcher->rhs.empty() ) ) {
    665                                 // if both LHS and RHS are empty than this is the empty tuple case, wherein it's 
    666                                 // okay for newAssigns to be empty. Otherwise, return early so that no new 
     666                                // if both LHS and RHS are empty than this is the empty tuple case, wherein it's
     667                                // okay for newAssigns to be empty. Otherwise, return early so that no new
    667668                                // candidates are generated
    668669                                if ( newAssigns.empty() ) return;
     
    692693                        }
    693694
    694                         // extract expressions from the assignment candidates to produce a list of assignments 
     695                        // extract expressions from the assignment candidates to produce a list of assignments
    695696                        // that together form a sigle candidate
    696697                        std::vector< ast::ptr< ast::Expr > > solved;
     
    701702
    702703                        crntFinder.candidates.emplace_back( std::make_shared< ResolvExpr::Candidate >(
    703                                 new ast::TupleAssignExpr{ 
    704                                         matcher->location, std::move( solved ), std::move( matcher->tmpDecls ) }, 
    705                                 std::move( matcher->env ), std::move( matcher->open ), std::move( matcher->need ), 
     704                                new ast::TupleAssignExpr{
     705                                        matcher->location, std::move( solved ), std::move( matcher->tmpDecls ) },
     706                                std::move( matcher->env ), std::move( matcher->open ), std::move( matcher->need ),
    706707                                ResolvExpr::sumCost( crnt ) + matcher->baseCost ) );
    707708                }
     
    709710} // anonymous namespace
    710711
    711 void handleTupleAssignment( 
    712         ResolvExpr::CandidateFinder & finder, const ast::UntypedExpr * assign, 
     712void handleTupleAssignment(
     713        ResolvExpr::CandidateFinder & finder, const ast::UntypedExpr * assign,
    713714        std::vector< ResolvExpr::CandidateFinder > & args
    714715) {
Note: See TracChangeset for help on using the changeset viewer.