Changeset c341b57 for src


Ignore:
Timestamp:
Feb 13, 2025, 5:52:15 PM (8 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
ef9f11c
Parents:
502ff9e (diff), 53f4b55 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Expr.cpp

    r502ff9e rc341b57  
    301301// --- OffsetofExpr
    302302
    303 OffsetofExpr::OffsetofExpr( const CodeLocation & loc, const Type * ty, const DeclWithType * mem )
    304 : OffsetofExpr( loc, ty, mem, nullptr ) {}
    305 
    306303OffsetofExpr::OffsetofExpr( const CodeLocation & loc, const Type * ty, const DeclWithType * mem, const Type * res )
    307304: Expr( loc, res ), type( ty ), member( mem ) {
     
    324321
    325322// --- CommaExpr
     323
    326324bool CommaExpr::get_lvalue() const {
    327325        // This is wrong by C, but the current implementation uses it.
  • src/AST/Expr.hpp

    r502ff9e rc341b57  
    539539        readonly<DeclWithType> member;
    540540
    541         OffsetofExpr( const CodeLocation & loc, const Type * ty, const DeclWithType * mem );
    542541        OffsetofExpr( const CodeLocation & loc, const Type * ty, const DeclWithType * mem, const Type * res );
    543542
  • src/GenPoly/Box.cpp

    r502ff9e rc341b57  
    20022002                        new ast::OffsetofExpr( expr->location,
    20032003                                deepCopy( type ),
    2004                                 memberDecl
     2004                                memberDecl,
     2005                                getLayoutType( transUnit() )
    20052006                        )
    20062007                ) );
  • src/ResolvExpr/CandidateFinder.cpp

    r502ff9e rc341b57  
    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        }
  • src/ResolvExpr/ConversionCost.cpp

    r502ff9e rc341b57  
    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;
  • src/ResolvExpr/Cost.hpp

    r502ff9e rc341b57  
    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 };
  • src/Validate/EnumAndPointerDecay.cpp

    r502ff9e rc341b57  
    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.