Changeset 119889f


Ignore:
Timestamp:
Apr 9, 2025, 9:07:31 PM (5 months ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
master
Children:
6174ecc
Parents:
50e8125
Message:

Partially fix #185.

This fix applies to functions, but not types.

The added test fails without the cfacpp changes.

Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Util.cpp

    r50e8125 r119889f  
    260260                        }
    261261                }
     262                if ( ! type->assertions.empty() ) visit_children = false;
    262263        }
    263264
  • src/Parser/TypeData.cpp

    r50e8125 r119889f  
    15851585        buildParamList( td->function.params, params );
    15861586        buildForall( td->forall, forall );
    1587         // Functions do not store their assertions there anymore.
     1587        // Functions do not store their assertions there anymore.  <-- FIXME: clarify or remove this comment
     1588        // Assertions were parsed as belonging to the type that preceded them.
     1589        // forall ( T | is_foo(T), U | are_bar(T, U) )
     1590        //   => parse
     1591        // forall( [ typarm( T, [is_foo(T)] ), typarm( U, [are_bar(T, U)] ) ] )
     1592        //   => now, flatten as
     1593        // forall( [ T, U ] ), assns( [ is_foo(T), are_bar(T, U)] )
    15881594        for ( ast::ptr<ast::TypeDecl> & type_param : forall ) {
    15891595                auto mut = type_param.get_and_mutate();
    15901596                splice( assertions, mut->assertions );
     1597        }
     1598        // When assertions without a type preceding them were parsed, placeholder
     1599        // types were invented to hold them.
     1600        // forall ( | is_foo(), U | is_bar(U) )
     1601        //   => parse
     1602        // forall( [ typarm( PLCHLD, [is_foo()] ), typarm( U, [is_bar(U)] ) ] )
     1603        //   => prev step
     1604        // forall( [ PLCHLD, U ] ), assns( [ is_foo(), is_bar(U)] )
     1605        //   => now, remove the placeholders
     1606        // forall( [ U ] ), assns( [ is_foo(), is_bar(U)] )
     1607        for (std::vector<ast::ptr<ast::TypeDecl>>::iterator it = forall.begin();
     1608                        it != forall.end(); ) {
     1609                // placeholder types have empty names
     1610                if ( (*it)->name == "" ) it = forall.erase(it);
     1611                else ++it;
    15911612        }
    15921613        if ( td->base ) {
  • src/Parser/parser.yy

    r50e8125 r119889f  
    31323132        // | type_specifier identifier_parameter_declarator
    31333133        | assertion_list
    3134                 { $$ = DeclarationNode::newTypeParam( ast::TypeDecl::Dtype, new string( DeclarationNode::anonymous.newName() ) )->addAssertions( $1 ); }
     3134                // Invent a placeholder type to wrap these bare assertions.  Rely on buildFunctionDecl to remove the placeholder.
     3135                { $$ = DeclarationNode::newTypeParam( ast::TypeDecl::Dtype, new string( "" ) )->addAssertions( $1 ); }
    31353136        | ENUM '(' identifier_or_type_name ')' identifier_or_type_name new_type_class type_initializer_opt assertion_list_opt
    31363137                {       
  • src/SymTab/Mangler.cpp

    r50e8125 r119889f  
    290290        if ( typeMode ) return;
    291291        auto funcType = dynamic_cast<const ast::FunctionType *>( type );
    292         if ( funcType && !funcType->forall.empty() ) {
     292        if ( funcType && (!funcType->forall.empty() || !funcType->assertions.empty()) ) {
    293293                std::list< std::string > assertionNames;
    294294                int dcount = 0, fcount = 0, vcount = 0, acount = 0;
Note: See TracChangeset for help on using the changeset viewer.