Ignore:
Timestamp:
Jul 31, 2023, 11:25:51 AM (14 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
master
Children:
f496046
Parents:
e0332dd
Message:

Added invariant to check that referenced declarations are in scope. This one took a while, I don't remember why forall pointer decay is involved.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Validate/FixQualifiedTypes.cpp

    re0332dd r14c0f7b  
    8989        }
    9090
    91         ast::Expr const * postvisit( ast::QualifiedNameExpr const * t) {
     91        ast::Expr const * postvisit( ast::QualifiedNameExpr const * t ) {
    9292                assert( location );
    93                 if ( t->type_decl ) {
    94                 auto enumName = t->type_decl->name;
    95                 const ast::EnumDecl * enumDecl = symtab.lookupEnum( enumName );
    96                         for ( ast::ptr<ast::Decl> const & member : enumDecl->members ) {
    97                                 if ( auto memberAsObj = member.as<ast::ObjectDecl>() ) {
    98                                         if ( memberAsObj->name == t->name ) {
    99                                                 return new ast::VariableExpr( t->location, memberAsObj );
    100                                         }
    101                                 } else {
    102                                         assertf( false, "unhandled qualified child type");
     93                if ( !t->type_decl ) return t;
     94
     95                auto enumName = t->type_decl->name;
     96                const ast::EnumDecl * enumDecl = symtab.lookupEnum( enumName );
     97                for ( ast::ptr<ast::Decl> const & member : enumDecl->members ) {
     98                        if ( auto memberAsObj = member.as<ast::ObjectDecl>() ) {
     99                                if ( memberAsObj->name == t->name ) {
     100                                        return new ast::VariableExpr( t->location, memberAsObj );
    103101                                }
     102                        } else {
     103                                assertf( false, "unhandled qualified child type" );
    104104                        }
     105                }
    105106
    106                 auto var = new ast::ObjectDecl( t->location, t->name,
    107                         new ast::EnumInstType(enumDecl, ast::CV::Const), nullptr, {}, ast::Linkage::Cforall );
    108                         var->mangleName = Mangle::mangle( var );
    109                         return new ast::VariableExpr( t->location, var );
    110         }
    111 
    112                 return t;
     107                auto var = new ast::ObjectDecl( t->location, t->name,
     108                        new ast::EnumInstType( enumDecl, ast::CV::Const ),
     109                        nullptr, {}, ast::Linkage::Cforall );
     110                var->mangleName = Mangle::mangle( var );
     111                return new ast::VariableExpr( t->location, var );
    113112        }
    114113
Note: See TracChangeset for help on using the changeset viewer.