Changeset 14c0f7b for src/Validate


Ignore:
Timestamp:
Jul 31, 2023, 11:25:51 AM (10 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.

Location:
src/Validate
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/Validate/Autogen.cpp

    re0332dd r14c0f7b  
    532532                )
    533533        );
    534         return genImplicitCall(
     534        auto stmt = genImplicitCall(
    535535                srcParam, dstSelect, location, func->name,
    536536                field, direction
    537537        );
     538        // This could return the above directly, except the generated code is
     539        // built using the structure's members and that means all the scoped
     540        // names (the forall parameters) are incorrect. This corrects them.
     541        if ( stmt && !decl->params.empty() ) {
     542                ast::DeclReplacer::TypeMap oldToNew;
     543                for ( auto pair : group_iterate( decl->params, func->type_params ) ) {
     544                        oldToNew.emplace( std::get<0>(pair), std::get<1>(pair) );
     545                }
     546                auto node = ast::DeclReplacer::replace( stmt, oldToNew );
     547                stmt = strict_dynamic_cast<const ast::Stmt *>( node );
     548        }
     549        return stmt;
    538550}
    539551
  • 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
  • src/Validate/ForallPointerDecay.cpp

    re0332dd r14c0f7b  
    214214                if ( dynamic_cast< const ast::FunctionType * >( type ) ) return;
    215215                SemanticError( obj->location,
    216                         toCString( "operator ", obj->name.c_str(), " is not "
    217                         "a function or function pointer." ) );
     216                        toCString( "operator ", obj->name.c_str(),
     217                        " is not a function or function pointer." ) );
    218218        }
    219219};
     
    237237        ast::Pass<AssertionFunctionFixer>::run( transUnit );
    238238        ast::Pass<OperatorChecker>::run( transUnit );
     239}
     240
     241void fixUniqueIds( ast::TranslationUnit & transUnit ) {
    239242        ast::Pass<UniqueFixCore>::run( transUnit );
    240243}
  • src/Validate/ForallPointerDecay.hpp

    re0332dd r14c0f7b  
    2727
    2828/// Cleans up assertion lists and expands traits.
    29 /// Also checks that operator names are used properly on functions and
    30 /// assigns unique IDs. This is a "legacy" pass.
     29/// Also checks that operator names are used properly on functions.
     30/// This is a "legacy" pass.
     31/// Must happen before auto-gen routines are added.
     32void decayForallPointers( ast::TranslationUnit & transUnit );
     33
     34/// Sets uniqueIds on any declarations that do not have one set.
    3135/// Must be after implement concurrent keywords; because uniqueIds must be
    3236/// set on declaration before resolution.
    33 /// Must happen before auto-gen routines are added.
    34 void decayForallPointers( ast::TranslationUnit & transUnit );
     37void fixUniqueIds( ast::TranslationUnit & transUnit );
    3538
    3639/// Expand all traits in an assertion list.
Note: See TracChangeset for help on using the changeset viewer.