Changeset a8404d9


Ignore:
Timestamp:
Feb 12, 2025, 11:33:33 AM (2 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
master
Children:
5e8d75bb
Parents:
54cd1a51
Message:

Just some formatting clean-up I did while investigating EnumDecl::inlinedDecl.

Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/ResolvExpr/CandidateFinder.cpp

    r54cd1a51 ra8404d9  
    21502150}
    21512151
    2152 const ast::Expr * CandidateFinder::makeEnumOffsetCast( const ast::EnumInstType * src, 
    2153         const ast::EnumInstType * dst, const ast::Expr * expr, Cost minCost ) {
     2152const ast::Expr * CandidateFinder::makeEnumOffsetCast( const ast::EnumInstType * src,
     2153                const ast::EnumInstType * dst, const ast::Expr * expr, Cost minCost ) {
    21542154        auto srcDecl = src->base;
    21552155        auto dstDecl = dst->base;
    21562156
    2157         if (srcDecl->name == dstDecl->name) return expr;
    2158 
    2159         for (auto& dstChild: dstDecl->inlinedDecl) {
     2157        if ( srcDecl->name == dstDecl->name ) return expr;
     2158
     2159        for ( auto& dstChild : dstDecl->inlinedDecl ) {
    21602160                Cost c = castCost(src, dstChild, false, context.symtab, env);
    2161                 ast::CastExpr * castToDst;
    2162                 if (c<minCost) {
    2163                         unsigned offset = findChildOffset( dstDecl, dstChild.get()->base );
    2164                         if (offset > 0) {
    2165                                 auto untyped = ast::UntypedExpr::createCall(
    2166                                         expr->location,
    2167                                         "?+?",
    2168                                         { new ast::CastExpr( expr->location,
    2169                                                 expr,
    2170                                                 new ast::BasicType(ast::BasicKind::SignedInt),
    2171                                                 ast::GeneratedFlag::ExplicitCast ),
    2172                                                 ast::ConstantExpr::from_int(expr->location, offset)} );
    2173                                 CandidateFinder finder(context, env);
    2174                                 finder.find( untyped );
    2175                                 CandidateList winners = findMinCost( finder.candidates );
    2176                                 CandidateRef & choice = winners.front();
    2177                                 choice->expr = new ast::CastExpr(expr->location, choice->expr, dstChild, ast::GeneratedFlag::ExplicitCast);
    2178                                 auto destExpr = makeEnumOffsetCast( src, dstChild, choice->expr, minCost );
    2179                                 if ( !destExpr ) continue;
    2180                                 castToDst = new ast::CastExpr( destExpr, dst );
    2181                         } else {
    2182                                 castToDst = new ast::CastExpr( expr, dst );
    2183                         }
    2184                         return castToDst;
     2161                if ( minCost <= c ) continue;
     2162                unsigned offset = findChildOffset( dstDecl, dstChild.get()->base );
     2163                if ( offset <= 0 ) return new ast::CastExpr( expr, dst );
     2164
     2165                auto untyped = ast::UntypedExpr::createCall(
     2166                        expr->location,
     2167                        "?+?",
     2168                        { new ast::CastExpr( expr->location,
     2169                                expr,
     2170                                new ast::BasicType( ast::BasicKind::SignedInt ),
     2171                                ast::GeneratedFlag::ExplicitCast ),
     2172                                ast::ConstantExpr::from_int( expr->location, offset ) } );
     2173                CandidateFinder finder(context, env);
     2174                finder.find( untyped );
     2175                CandidateList winners = findMinCost( finder.candidates );
     2176                CandidateRef & choice = winners.front();
     2177                choice->expr = new ast::CastExpr( expr->location, choice->expr, dstChild, ast::GeneratedFlag::ExplicitCast );
     2178                if ( auto destExpr = makeEnumOffsetCast( src, dstChild, choice->expr, minCost ) ) {
     2179                        return new ast::CastExpr( destExpr, dst );
    21852180                }
    21862181        }
  • TabularUnified src/ResolvExpr/ConversionCost.cpp

    r54cd1a51 ra8404d9  
    518518        auto srcDecl = src->base;
    519519        auto dstDecl = dst->base;
    520         if (srcDecl->name == dstDecl->name) return Cost::safe;
     520        if ( srcDecl->name == dstDecl->name ) return Cost::safe;
    521521        Cost minCost = Cost::infinity;
    522         for (auto child: dstDecl->inlinedDecl) {
    523                 Cost c = enumCastCost(src, child, symtab, env) + Cost::safe;
    524                 if (c<minCost) minCost = c;
     522        for ( auto child : dstDecl->inlinedDecl ) {
     523                Cost c = enumCastCost( src, child, symtab, env ) + Cost::safe;
     524                if ( c < minCost ) minCost = c;
    525525        }
    526526        return minCost;
  • TabularUnified src/ResolvExpr/Cost.hpp

    r54cd1a51 ra8404d9  
    169169}
    170170
     171inline bool operator<=( const Cost lhs, const Cost rhs ) {
     172        return !(rhs < lhs);
     173}
     174
    171175inline Cost operator+( const Cost lhs, const Cost rhs ) {
    172176        if ( lhs.all == Cost::infinity || rhs.all == Cost::infinity ) return Cost{ Cost::infinity };
  • TabularUnified src/Validate/EnumAndPointerDecay.cpp

    r54cd1a51 ra8404d9  
    4848                } else if ( auto value = member.as<ast::InlineMemberDecl>() ) {
    4949                        auto targetEnum = symtab.lookupEnum( value->name );
    50                         // assert( targetEnum );
    5150                        if (!targetEnum) {
    5251                                SemanticError(value, "Only another enum is allowed for enum inline syntax ");
    5352                        }
    5453                        const ast::EnumInstType * instType = new ast::EnumInstType(targetEnum);
    55                         mut->inlinedDecl.push_back( std::move(instType) );
     54                        mut->inlinedDecl.emplace_back( instType );
    5655                        for ( auto enumMember : targetEnum->members ) {
    5756                                auto enumObject = enumMember.strict_as<ast::ObjectDecl>();
Note: See TracChangeset for help on using the changeset viewer.