Changeset 7f6a7c9 for src/Validate


Ignore:
Timestamp:
Sep 21, 2022, 11:02:15 AM (3 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, ast-experimental, master, pthread-emulation
Children:
95dab9e
Parents:
428adbc (diff), 0bd46fd (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into pthread-emulation

Location:
src/Validate
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/Validate/Autogen.cpp

    r428adbc r7f6a7c9  
    1010// Created On       : Thu Dec  2 13:44:00 2021
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Jan 27  9:29:00 2022
    13 // Update Count     : 1
     12// Last Modified On : Tue Sep 20 16:00:00 2022
     13// Update Count     : 2
    1414//
    1515
     
    2525
    2626#include "AST/Attribute.hpp"
     27#include "AST/Create.hpp"
    2728#include "AST/Decl.hpp"
    2829#include "AST/DeclReplacer.hpp"
     
    236237        if ( !enumDecl->body ) return;
    237238
     239        // if ( auto enumBaseType = enumDecl->base ) {
     240        //      if ( auto enumBaseTypeAsStructInst = dynamic_cast<const ast::StructInstType *>(enumBaseType.get()) ) {
     241        //              const ast::StructDecl * structDecl = enumBaseTypeAsStructInst->base.get();
     242        //              this->previsit( structDecl );
     243        //      }
     244        // }
     245
    238246        ast::EnumInstType enumInst( enumDecl->name );
    239247        enumInst.base = enumDecl;
     
    321329void FuncGenerator::produceForwardDecl( const ast::FunctionDecl * decl ) {
    322330        if (0 != functionNesting) return;
    323         ast::FunctionDecl * fwd = ast::deepCopy( decl );
    324         fwd->stmts = nullptr;
     331        ast::FunctionDecl * fwd =
     332                ( decl->stmts ) ? ast::asForward( decl ) : ast::deepCopy( decl ) ;
    325333        fwd->fixUniqueId();
    326334        forwards.push_back( fwd );
  • src/Validate/EnumAndPointerDecay.cpp

    r428adbc r7f6a7c9  
    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

    r428adbc r7f6a7c9  
    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
     
    1919#include "AST/TranslationUnit.hpp"
    2020#include "Validate/NoIdSymbolTable.hpp"
     21#include "SymTab/Mangler.h"            // for Mangler
     22#include "AST/LinkageSpec.hpp"                     // for Linkage
    2123
    2224namespace Validate {
     
    2527
    2628struct FixQualifiedTypesCore :
    27                 public WithNoIdSymbolTable, public ast::WithGuards {
    28         CodeLocation const * location = nullptr;
    29 
    30         void previsit( ast::ParseNode const * node ) {
    31                 GuardValue( location ) = &node->location;
    32         }
    33 
     29                public WithNoIdSymbolTable,
     30                public ast::WithCodeLocation {
    3431        ast::Type const * postvisit( ast::QualifiedType const * type ) {
    3532                assert( location );
     
    8986                }
    9087        }
     88
     89        ast::Expr const * postvisit( ast::QualifiedNameExpr const * t) {
     90                assert( location );
     91                if ( t->type_decl ) {
     92                auto enumName = t->type_decl->name;
     93                const ast::EnumDecl * enumDecl = symtab.lookupEnum( enumName );
     94                        for ( ast::ptr<ast::Decl> const & member : enumDecl->members ) {
     95                                if ( auto memberAsObj = member.as<ast::ObjectDecl>() ) {
     96                                        if ( memberAsObj->name == t->name ) {
     97                                                return new ast::VariableExpr( t->location, memberAsObj );
     98                                        }
     99                                } else {
     100                                        assertf( false, "unhandled qualified child type");
     101                                }
     102                        }
     103
     104
     105                auto var = new ast::ObjectDecl( t->var->location, t->name,
     106                         new ast::EnumInstType(enumDecl, ast::CV::Const), nullptr, {}, ast::Linkage::Cforall );
     107                        var->scopeLevel = 1; // 1 for now; should copy the scopeLevel of the enumValue
     108                        var->mangleName = Mangle::mangle( var );
     109                        return new ast::VariableExpr( t->location, var );
     110                // return ret;
     111        }
     112
     113                return t;
     114        }
     115
    91116};
    92117
  • src/Validate/GenericParameter.cpp

    r428adbc r7f6a7c9  
    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

    r428adbc r7f6a7c9  
    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 );
     
    4644        void postvisit( ast::UnionDecl const * decl );
    4745        ast::TraitDecl const * postvisit( ast::TraitDecl const * decl );
     46        ast::QualifiedNameExpr const * previsit( ast::QualifiedNameExpr const * decl);
    4847
    4948private:
     
    5958        ForwardEnumsType forwardEnums;
    6059
    61         const CodeLocation * location = nullptr;
    6260        /// true if currently in a generic type body,
    6361        /// so that type parameter instances can be renamed appropriately
     
    176174        // Linking only makes sense for the 'oldest ancestor' of the qualified type.
    177175        type->parent->accept( *visitor );
    178 }
    179 
    180 void LinkTypesCore::previsit( ast::ParseNode const * node ) {
    181         GuardValue( location ) = &node->location;
    182176}
    183177
     
    224218        GuardValue( inGeneric ) = !decl->params.empty();
    225219        if ( !inGeneric ) {
    226                 GuardValue( location ) = &decl->location;
    227220                return decl;
    228221        }
    229222        auto mut = ast::mutate( decl );
    230         GuardValue( location ) = &mut->location;
    231223        for ( ast::ptr<ast::TypeDecl> & typeDecl : mut->params ) {
    232224                typeDecl.get_and_mutate()->name = "__" + typeDecl->name + "_generic_";
     
    292284}
    293285
     286ast::QualifiedNameExpr const * LinkTypesCore::previsit( ast::QualifiedNameExpr const * decl ) {
     287        // Try to lookup type
     288        if ( auto objDecl = decl->type_decl.as<ast::ObjectDecl>() ) {
     289                if ( auto inst = objDecl->type.as<ast::TypeInstType>()) {
     290                        if ( auto enumDecl = symtab.lookupEnum ( inst->name ) ) {
     291                                auto mut = ast::mutate( decl );
     292                                mut->type_decl = enumDecl;
     293                                auto enumInst = new ast::EnumInstType( enumDecl );
     294                                enumInst->name = decl->name;
     295                                // Adding result; addCandidate() use result
     296                                mut->result = enumInst;
     297                                decl = mut;
     298                        }
     299                }
     300        } else if ( auto enumDecl = decl->type_decl.as<ast::EnumDecl>() ) {
     301                auto mut = ast::mutate( decl );
     302                auto enumInst = new ast::EnumInstType( enumDecl );
     303                enumInst->name = decl->name;
     304                // Adding result; addCandidate() use result
     305                mut->result = enumInst;
     306                decl = mut;
     307        }
     308        // ast::EnumDecl const * decl = symtab.lookupEnum( type->name );
     309        // // It's not a semantic error if the enum is not found, just an implicit forward declaration.
     310        // if ( decl ) {
     311        //      // Just linking in the node.
     312        //      auto mut = ast::mutate( type );
     313        //      mut->base = const_cast<ast::EnumDecl *>( decl );
     314        //      type = mut;
     315        // }
     316        return decl;
     317}
     318
    294319} // namespace
    295320
  • src/Validate/ReplaceTypedef.cpp

    r428adbc r7f6a7c9  
    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 );
     
    183178        } else if ( auto enumType = dynamic_cast<ast::EnumInstType const *>( designatorType ) ) {
    184179                declsToAddBefore.push_back( new ast::EnumDecl(
    185                         decl->location, enumType->name, {}, decl->linkage,
     180                        decl->location, enumType->name, false, {}, decl->linkage,
    186181                        ( (enumType->base) ? enumType->base->base : nullptr )
    187182                        ) );
     
    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() ) {
     
    199193}
    200194
    201 void ReplaceTypedefCore::previsit( ast::FunctionDecl const * decl ) {
    202         previsit( (ast::ParseNode const *)decl );
     195void ReplaceTypedefCore::previsit( ast::FunctionDecl const * ) {
    203196        GuardScope( typedefNames );
    204197        GuardScope( typedeclNames );
     
    206199}
    207200
    208 void ReplaceTypedefCore::previsit( ast::ObjectDecl const * decl ) {
    209         previsit( (ast::ParseNode const *)decl );
     201void ReplaceTypedefCore::previsit( ast::ObjectDecl const * ) {
    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,
     
    249241}
    250242
    251 void ReplaceTypedefCore::previsit( ast::CastExpr const * expr ) {
    252         previsit( (ast::ParseNode const *)expr );
    253         GuardScope( typedefNames );
    254         GuardScope( typedeclNames );
    255 }
    256 
    257 void ReplaceTypedefCore::previsit( ast::CompoundStmt const * expr ) {
    258         previsit( (ast::ParseNode const *)expr );
     243void ReplaceTypedefCore::previsit( ast::CastExpr const * ) {
     244        GuardScope( typedefNames );
     245        GuardScope( typedeclNames );
     246}
     247
     248void ReplaceTypedefCore::previsit( ast::CompoundStmt const * ) {
    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
    288 void ReplaceTypedefCore::previsit( ast::TraitDecl const * decl ) {
    289         previsit( (ast::ParseNode const *)decl );
     275void ReplaceTypedefCore::previsit( ast::TraitDecl const * ) {
    290276        GuardScope( typedefNames );
    291277        GuardScope( typedeclNames );
Note: See TracChangeset for help on using the changeset viewer.