Changeset b6f2e7ab for src/ResolvExpr


Ignore:
Timestamp:
Sep 9, 2024, 5:15:32 PM (41 hours ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
master
Children:
f5dbc8d
Parents:
5c6d439
Message:

Removed SizeofExpr::expr and AlignofExpr::expr, expressions that would be stored there are wrapped in TypeofType? and stored in the type field. Some special cases to hide the typeof in code generation were added. In addition, initializer length is calculated in more cases so that the full type of more arrays is known sooner. Other than that, most of the code changes were just stripping out the conditional code and checks no longer needed. Some tests had to be updated, because the typeof is not hidden in dumps and the resolver replaces known typeof expressions with the type. The extension case caused some concern but it appears that just hides warnings in the expression which no longer exists.

Location:
src/ResolvExpr
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CandidateFinder.cpp

    r5c6d439 rb6f2e7ab  
    14821482
    14831483        void Finder::postvisit( const ast::SizeofExpr * sizeofExpr ) {
    1484                 if ( sizeofExpr->type ) {
    1485                         addCandidate(
    1486                                 new ast::SizeofExpr{
    1487                                         sizeofExpr->location, resolveTypeof( sizeofExpr->type, context ) },
    1488                                 tenv );
    1489                 } else {
    1490                         // find all candidates for the argument to sizeof
    1491                         CandidateFinder finder( context, tenv );
    1492                         finder.find( sizeofExpr->expr );
    1493                         // find the lowest-cost candidate, otherwise ambiguous
    1494                         CandidateList winners = findMinCost( finder.candidates );
    1495                         if ( winners.size() != 1 ) {
    1496                                 SemanticError(
    1497                                         sizeofExpr->expr.get(), "Ambiguous expression in sizeof operand: " );
    1498                         }
    1499                         // return the lowest-cost candidate
    1500                         CandidateRef & choice = winners.front();
    1501                         choice->expr = referenceToRvalueConversion( choice->expr, choice->cost );
    1502                         choice->cost = Cost::zero;
    1503                         addCandidate( *choice, new ast::SizeofExpr{ sizeofExpr->location, choice->expr } );
    1504                 }
     1484                addCandidate(
     1485                        new ast::SizeofExpr{
     1486                                sizeofExpr->location, resolveTypeof( sizeofExpr->type, context ) },
     1487                        tenv );
    15051488        }
    15061489
     
    15371520
    15381521        void Finder::postvisit( const ast::AlignofExpr * alignofExpr ) {
    1539                 if ( alignofExpr->type ) {
    1540                         addCandidate(
    1541                                 new ast::AlignofExpr{
    1542                                         alignofExpr->location, resolveTypeof( alignofExpr->type, context ) },
    1543                                 tenv );
    1544                 } else {
    1545                         // find all candidates for the argument to alignof
    1546                         CandidateFinder finder( context, tenv );
    1547                         finder.find( alignofExpr->expr );
    1548                         // find the lowest-cost candidate, otherwise ambiguous
    1549                         CandidateList winners = findMinCost( finder.candidates );
    1550                         if ( winners.size() != 1 ) {
    1551                                 SemanticError(
    1552                                         alignofExpr->expr.get(), "Ambiguous expression in alignof operand: " );
    1553                         }
    1554                         // return the lowest-cost candidate
    1555                         CandidateRef & choice = winners.front();
    1556                         choice->expr = referenceToRvalueConversion( choice->expr, choice->cost );
    1557                         choice->cost = Cost::zero;
    1558                         addCandidate(
    1559                                 *choice, new ast::AlignofExpr{ alignofExpr->location, choice->expr } );
    1560                 }
     1522                addCandidate(
     1523                        new ast::AlignofExpr{
     1524                                alignofExpr->location, resolveTypeof( alignofExpr->type, context ) },
     1525                        tenv );
    15611526        }
    15621527
  • src/ResolvExpr/Unify.cpp

    r5c6d439 rb6f2e7ab  
    234234                        if ( !e2so ) return;
    235235
    236                         assert((e1->type != nullptr) ^ (e1->expr != nullptr));
    237                         assert((e2so->type != nullptr) ^ (e2so->expr != nullptr));
    238                         if ( !(e1->type && e2so->type) ) return;
    239 
    240236                        // expression unification calls type unification (mutual recursion)
    241237                        result = unifyExact( e1->type, e2so->type, tenv, need, have, open, widen );
Note: See TracChangeset for help on using the changeset viewer.