Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CandidateFinder.cpp

    r857b5f9 r6b95feb  
    672672                void postvisit( const ast::SizeofExpr * sizeofExpr );
    673673                void postvisit( const ast::AlignofExpr * alignofExpr );
    674                 void postvisit( const ast::CountofExpr * countExpr );
    675674                void postvisit( const ast::AddressExpr * addressExpr );
    676675                void postvisit( const ast::LabelAddressExpr * labelExpr );
     
    698697                void postvisit( const ast::UntypedInitExpr * initExpr );
    699698                void postvisit( const ast::QualifiedNameExpr * qualifiedExpr );
     699                void postvisit( const ast::CountExpr * countExpr );
    700700
    701701                void postvisit( const ast::InitExpr * ) {
     
    941941                }
    942942        }
     943       
    943944
    944945        /// Adds aggregate member interpretations
     
    12681269                                        ? conversionCost( fromType, toType, cand->expr->get_lvalue(), symtab, cand->env )
    12691270                                        : castCost( fromType, toType, cand->expr->get_lvalue(), symtab, cand->env );
    1270 
     1271                       
    12711272                        // Redefine enum cast
    12721273                        auto argAsEnum = fromType.as<ast::EnumInstType>();
     
    14921493        }
    14931494
    1494         void Finder::postvisit( const ast::CountofExpr * countExpr ) {
    1495                 if ( auto enumInst = countExpr->type.as<ast::EnumInstType>() ) {
    1496                         addCandidate( ast::ConstantExpr::from_ulong( countExpr->location, enumInst->base->members.size()), tenv );
    1497                         return;
    1498                 }
    1499                 auto untypedFirst = ast::UntypedExpr::createCall( countExpr->location, "lowerBound", {} );
    1500                 auto castFirst = new ast::CastExpr( countExpr->location, untypedFirst , countExpr->type );
    1501                 const ast::UntypedExpr * untyped = ast::UntypedExpr::createCall(
    1502                         countExpr->location, "Countof", { castFirst }
     1495        void Finder::postvisit( const ast::CountExpr * countExpr ) {
     1496                const ast::UntypedExpr * untyped = nullptr;
     1497                if ( countExpr->type ) {
     1498                        auto enumInst = countExpr->type.as<ast::EnumInstType>();
     1499                        if ( enumInst ) {
     1500                                addCandidate( ast::ConstantExpr::from_ulong(countExpr->location, enumInst->base->members.size()), tenv );
     1501                                return;
     1502                        }
     1503                        auto untypedFirst = ast::UntypedExpr::createCall( countExpr->location, "lowerBound", {} );
     1504                        auto castFirst = new ast::CastExpr( countExpr->location, untypedFirst , countExpr->type );
     1505                        untyped = ast::UntypedExpr::createCall(
     1506                                countExpr->location, "Countof", { castFirst }
     1507                        );
     1508                }
     1509                if (!untyped) untyped = ast::UntypedExpr::createCall(
     1510                                countExpr->location, "Countof", { countExpr->expr }
    15031511                );
    15041512                CandidateFinder finder( context, tenv );
     
    15061514                CandidateList winners = findMinCost( finder.candidates );
    15071515                if ( winners.size() == 0 ) {
    1508                         SemanticError( countExpr, "Countof is not implemented: " );
    1509                 }
    1510                 if ( winners.size() != 1 ) {
    1511                         SemanticError( countExpr, "Ambiguous expression in countof: " );
     1516                        SemanticError( countExpr->expr, "Countof is not implemented for operand: " );
     1517                }
     1518                if ( winners.size() !=  1 ) {
     1519                        SemanticError( countExpr->expr, "Ambiguous expression in countof operand: " );
    15121520                }
    15131521                CandidateRef & choice = winners.front();
Note: See TracChangeset for help on using the changeset viewer.