Changeset e9e9f56


Ignore:
Timestamp:
Sep 21, 2022, 9:22:24 AM (19 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, ast-experimental, master, pthread-emulation
Children:
20737104
Parents:
b6c3688
Message:

Used the WithCodeLocation? helper in more passes. This cleans up some code and should improve efficiency.

Location:
src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Pass.hpp

    rb6c3688 re9e9f56  
    328328struct PureVisitor {};
    329329
     330/// Keep track of the nearest parent node's location field.
    330331struct WithCodeLocation {
    331332        const CodeLocation * location = nullptr;
  • src/Tuples/TupleExpansionNew.cpp

    rb6c3688 re9e9f56  
    1010// Created On       : Mon Aug 23 15:36:09 2021
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Mon Aug 15 17:00:00 2022
    13 // Update Count     : 3
     12// Last Modified On : Tue Sep 20 16:17:00 2022
     13// Update Count     : 4
    1414//
    1515
     
    102102/// Replaces Tuple Assign & Index Expressions, and Tuple Types.
    103103struct TupleMainExpander final :
     104                public ast::WithCodeLocation,
     105                public ast::WithDeclsToAdd<>,
    104106                public ast::WithGuards,
    105                 public ast::WithVisitorRef<TupleMainExpander>,
    106                 public ast::WithDeclsToAdd<> {
     107                public ast::WithVisitorRef<TupleMainExpander> {
    107108        ast::Expr const * postvisit( ast::TupleAssignExpr const * expr ) {
    108109                // Just move the env on the new top level expression.
     
    111112        }
    112113
    113         void previsit( ast::ParseNode const * node ) {
    114                 GuardValue( location ) = &node->location;
    115         }
    116 
    117         void previsit( ast::CompoundStmt const * stmt ) {
    118                 previsit( (ast::ParseNode const *)stmt );
     114        void previsit( ast::CompoundStmt const * ) {
    119115                GuardScope( typeMap );
    120116        }
     
    217213private:
    218214        ScopedMap< int, ast::StructDecl const * > typeMap;
    219         CodeLocation const * location = nullptr;
    220215};
    221216
  • src/Validate/EnumAndPointerDecay.cpp

    rb6c3688 re9e9f56  
    1010// Created On       : Tue Jun 28 15:50:00 2022
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tue Jul 12 14:45:00 2022
    13 // Update Count     : 0
     12// Last Modified On : Tue Sep 20 16:14:00 2022
     13// Update Count     : 1
    1414//
    1515
     
    2626namespace {
    2727
    28 struct EnumAndPointerDecayCore final : public ast::WithGuards {
    29         CodeLocation const * location = nullptr;
    30         void previsit( ast::ParseNode const * node );
     28struct EnumAndPointerDecayCore final : public ast::WithCodeLocation {
    3129        ast::EnumDecl const * previsit( ast::EnumDecl const * decl );
    3230        ast::FunctionDecl const * previsit( ast::FunctionDecl const * decl );
    3331        ast::FunctionType const * previsit( ast::FunctionType const * type );
    3432};
    35 
    36 void EnumAndPointerDecayCore::previsit( ast::ParseNode const * node ) {
    37         GuardValue( location ) = &node->location;
    38 }
    3933
    4034ast::EnumDecl const * EnumAndPointerDecayCore::previsit(
     
    5044                        new ast::EnumInstType( decl, ast::CV::Const ) );
    5145        }
    52         GuardValue( location ) = &decl->location;
    5346        return mut;
    5447}
     
    7972                ast::FunctionDecl const * decl ) {
    8073        auto mut = ast::mutate( decl );
    81         GuardValue( location ) = &decl->location;
    8274        ast::ArgumentFlag isVarArgs = mut->type->isVarArgs;
    8375        // It seems fixFunction (via fixFunctionList) does the pointer decay part.
  • src/Validate/FixQualifiedTypes.cpp

    rb6c3688 re9e9f56  
    1010// Created On       : Thr Apr 21 11:13:00 2022
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Apr 22 11:36:00 2022
    13 // Update Count     : 0
     12// Last Modified On : Tue Sep 20 16:15:00 2022
     13// Update Count     : 1
    1414//
    1515
     
    2727
    2828struct FixQualifiedTypesCore :
    29                 public WithNoIdSymbolTable, public ast::WithGuards {
    30         CodeLocation const * location = nullptr;
    31 
    32         void previsit( ast::ParseNode const * node ) {
    33                 GuardValue( location ) = &node->location;
    34         }
    35 
     29                public WithNoIdSymbolTable,
     30                public ast::WithCodeLocation {
    3631        ast::Type const * postvisit( ast::QualifiedType const * type ) {
    3732                assert( location );
  • src/Validate/GenericParameter.cpp

    rb6c3688 re9e9f56  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // GenericParameter.hpp -- Generic parameter related passes.
     7// GenericParameter.cpp -- Generic parameter related passes.
    88//
    99// Author           : Andrew Beach
    1010// Created On       : Fri Mar 21 10:02:00 2022
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Apr 22 16:43:00 2022
    13 // Update Count     : 1
     12// Last Modified On : Tue Sep 20 16:28:00 2022
     13// Update Count     : 2
    1414//
    1515
     
    119119}
    120120
    121 struct ValidateGenericParamsCore : public ast::WithGuards {
    122         const CodeLocation * locationPtr = nullptr;
    123 
    124         void previsit( const ast::ParseNode * node ) {
    125                 GuardValue( locationPtr ) = &node->location;
    126         }
    127 
     121struct ValidateGenericParamsCore : public ast::WithCodeLocation {
    128122        const ast::StructInstType * previsit( const ast::StructInstType * type ) {
    129                 assert( locationPtr );
    130                 return validateGeneric( *locationPtr, type );
     123                assert( location );
     124                return validateGeneric( *location, type );
    131125        }
    132126
    133127        const ast::UnionInstType * previsit( const ast::UnionInstType * type ) {
    134                 assert( locationPtr );
    135                 return validateGeneric( *locationPtr, type );
     128                assert( location );
     129                return validateGeneric( *location, type );
    136130        }
    137131};
  • src/Validate/LinkReferenceToTypes.cpp

    rb6c3688 re9e9f56  
    1010// Created On       : Thr Apr 21 11:41:00 2022
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tue Jun 28 14:58:00 2022
    13 // Update Count     : 1
     12// Last Modified On : Tue Sep 20 16:17:00 2022
     13// Update Count     : 2
    1414//
    1515
     
    2626
    2727struct LinkTypesCore : public WithNoIdSymbolTable,
     28                public ast::WithCodeLocation,
    2829                public ast::WithGuards,
    29                 public ast::WithVisitorRef<LinkTypesCore>,
    30                 public ast::WithShortCircuiting {
    31 
     30                public ast::WithShortCircuiting,
     31                public ast::WithVisitorRef<LinkTypesCore> {
    3232        ast::TypeInstType const * postvisit( ast::TypeInstType const * type );
    3333        ast::EnumInstType const * postvisit( ast::EnumInstType const * type );
     
    3838        void postvisit( ast::QualifiedType const * type );
    3939
    40         void previsit( ast::ParseNode const * node );
    41 
    4240        ast::EnumDecl const * postvisit( ast::EnumDecl const * decl );
    4341        ast::StructDecl const * previsit( ast::StructDecl const * decl );
     
    6058        ForwardEnumsType forwardEnums;
    6159
    62         const CodeLocation * location = nullptr;
    6360        /// true if currently in a generic type body,
    6461        /// so that type parameter instances can be renamed appropriately
     
    177174        // Linking only makes sense for the 'oldest ancestor' of the qualified type.
    178175        type->parent->accept( *visitor );
    179 }
    180 
    181 void LinkTypesCore::previsit( ast::ParseNode const * node ) {
    182         GuardValue( location ) = &node->location;
    183176}
    184177
     
    225218        GuardValue( inGeneric ) = !decl->params.empty();
    226219        if ( !inGeneric ) {
    227                 GuardValue( location ) = &decl->location;
    228220                return decl;
    229221        }
    230222        auto mut = ast::mutate( decl );
    231         GuardValue( location ) = &mut->location;
    232223        for ( ast::ptr<ast::TypeDecl> & typeDecl : mut->params ) {
    233224                typeDecl.get_and_mutate()->name = "__" + typeDecl->name + "_generic_";
  • src/Validate/ReplaceTypedef.cpp

    rb6c3688 re9e9f56  
    1010// Created On       : Tue Jun 29 14:59:00 2022
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Jul 13 14:45:00 2022
    13 // Update Count     : 1
     12// Last Modified On : Tue Sep 20 17:00:00 2022
     13// Update Count     : 2
    1414//
    1515
     
    3939
    4040struct ReplaceTypedefCore final :
    41                 public ast::WithVisitorRef<ReplaceTypedefCore>,
     41                public ast::WithCodeLocation,
     42                public ast::WithDeclsToAdd<>,
    4243                public ast::WithGuards,
    4344                public ast::WithShortCircuiting,
    44                 public ast::WithDeclsToAdd<> {
    45 
    46         void previsit( ast::ParseNode const * node );
     45                public ast::WithVisitorRef<ReplaceTypedefCore> {
     46
    4747        void previsit( ast::QualifiedType const * );
    4848        ast::Type const * postvisit( ast::QualifiedType const * );
     
    7474        TypedefMap typedefNames;
    7575        TypeDeclMap typedeclNames;
    76         CodeLocation const * nearestLocation = nullptr;
    7776        int scopeLevel;
    7877        bool isAtFunctionTop = false;
    7978};
    80 
    81 void ReplaceTypedefCore::previsit( ast::ParseNode const * node ) {
    82         GuardValue( nearestLocation ) = &node->location;
    83 }
    8479
    8580void ReplaceTypedefCore::previsit( ast::QualifiedType const * ) {
     
    115110                        auto rtt = dynamic_cast<ast::BaseInstType *>( ret );
    116111                        if ( !rtt ) {
    117                                 assert( nearestLocation );
    118                                 SemanticError( *nearestLocation, "Cannot apply type parameters to base type of " + type->name );
     112                                assert( location );
     113                                SemanticError( *location, "Cannot apply type parameters to base type of " + type->name );
    119114                        }
    120115                        rtt->params.clear();
     
    129124                TypeDeclMap::const_iterator base = typedeclNames.find( type->name );
    130125                if ( base == typedeclNames.end() ) {
    131                         assert( nearestLocation );
    132                         SemanticError( *nearestLocation, toString( "Use of undefined type ", type->name ) );
     126                        assert( location );
     127                        SemanticError( *location, toString( "Use of undefined type ", type->name ) );
    133128                }
    134129                return ast::mutate_field( type, &ast::TypeInstType::base, base->second );
     
    191186
    192187void ReplaceTypedefCore::previsit( ast::TypeDecl const * decl ) {
    193         previsit( (ast::ParseNode const *)decl );
    194188        TypedefMap::iterator iter = typedefNames.find( decl->name );
    195189        if ( iter != typedefNames.end() ) {
     
    200194
    201195void ReplaceTypedefCore::previsit( ast::FunctionDecl const * decl ) {
    202         previsit( (ast::ParseNode const *)decl );
    203196        GuardScope( typedefNames );
    204197        GuardScope( typedeclNames );
     
    207200
    208201void ReplaceTypedefCore::previsit( ast::ObjectDecl const * decl ) {
    209         previsit( (ast::ParseNode const *)decl );
    210202        GuardScope( typedefNames );
    211203        GuardScope( typedeclNames );
     
    217209                using DWTVector = std::vector<ast::ptr<ast::DeclWithType>>;
    218210                using DeclVector = std::vector<ast::ptr<ast::TypeDecl>>;
    219                 CodeLocation const & location = decl->location;
     211                CodeLocation const & declLocation = decl->location;
    220212                UniqueName paramNamer( decl->name + "Param" );
    221213
    222214                // Replace the current object declaration with a function declaration.
    223215                ast::FunctionDecl const * newDecl = new ast::FunctionDecl(
    224                         location,
     216                        declLocation,
    225217                        decl->name,
    226218                        map_range<DeclVector>( type->forall, []( const ast::TypeInstType * inst ) {
     
    230222                                return ast::deepCopy( expr->var );
    231223                        } ),
    232                         map_range<DWTVector>( type->params, [&location, &paramNamer]( const ast::Type * type ) {
     224                        map_range<DWTVector>( type->params, [&declLocation, &paramNamer]( const ast::Type * type ) {
    233225                                assert( type );
    234                                 return new ast::ObjectDecl( location, paramNamer.newName(), ast::deepCopy( type ) );
     226                                return new ast::ObjectDecl( declLocation, paramNamer.newName(), ast::deepCopy( type ) );
    235227                        } ),
    236                         map_range<DWTVector>( type->returns, [&location, &paramNamer]( const ast::Type * type ) {
     228                        map_range<DWTVector>( type->returns, [&declLocation, &paramNamer]( const ast::Type * type ) {
    237229                                assert( type );
    238                                 return new ast::ObjectDecl( location, paramNamer.newName(), ast::deepCopy( type ) );
     230                                return new ast::ObjectDecl( declLocation, paramNamer.newName(), ast::deepCopy( type ) );
    239231                        } ),
    240232                        nullptr,
     
    250242
    251243void ReplaceTypedefCore::previsit( ast::CastExpr const * expr ) {
    252         previsit( (ast::ParseNode const *)expr );
    253244        GuardScope( typedefNames );
    254245        GuardScope( typedeclNames );
     
    256247
    257248void ReplaceTypedefCore::previsit( ast::CompoundStmt const * expr ) {
    258         previsit( (ast::ParseNode const *)expr );
    259249        GuardScope( typedefNames );
    260250        GuardScope( typedeclNames );
     
    268258
    269259ast::StructDecl const * ReplaceTypedefCore::previsit( ast::StructDecl const * decl ) {
    270         previsit( (ast::ParseNode const *)decl );
    271260        visit_children = false;
    272261        addImplicitTypedef( decl );
     
    275264
    276265ast::UnionDecl const * ReplaceTypedefCore::previsit( ast::UnionDecl const * decl ) {
    277         previsit( (ast::ParseNode const *)decl );
    278266        visit_children = false;
    279267        addImplicitTypedef( decl );
     
    282270
    283271void ReplaceTypedefCore::previsit( ast::EnumDecl const * decl ) {
    284         previsit( (ast::ParseNode const *)decl );
    285272        addImplicitTypedef( decl );
    286273}
    287274
    288275void ReplaceTypedefCore::previsit( ast::TraitDecl const * decl ) {
    289         previsit( (ast::ParseNode const *)decl );
    290276        GuardScope( typedefNames );
    291277        GuardScope( typedeclNames );
Note: See TracChangeset for help on using the changeset viewer.