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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.