Ignore:
Timestamp:
Jun 19, 2024, 3:20:39 PM (4 months ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
57e43cd
Parents:
1725989
Message:
  1. Add count_e( enum_name ), a pseudo function that return the number of element in an enum; 2. Implementation of enum range loop.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CandidateFinder.cpp

    r1725989 r525f7ad  
    696696                void postvisit( const ast::UntypedInitExpr * initExpr );
    697697                void postvisit( const ast::QualifiedNameExpr * qualifiedExpr );
     698                void postvisit( const ast::CountExpr * countExpr );
    698699
    699700                const ast::Expr * makeEnumOffsetCast( const ast::EnumInstType * src,
     
    15271528                        addCandidate( *choice, new ast::SizeofExpr{ sizeofExpr->location, choice->expr } );
    15281529                }
     1530        }
     1531
     1532        void Finder::postvisit( const ast::CountExpr * countExpr ) {
     1533                assert( countExpr->type );
     1534                auto enumInst = countExpr->type.as<ast::EnumInstType>();
     1535                if ( !enumInst ) {
     1536                        SemanticError( countExpr, "Count Expression only supports Enum Type as operand: ");
     1537                }
     1538                addCandidate( ast::ConstantExpr::from_ulong(countExpr->location, enumInst->base->members.size()), tenv );
    15291539        }
    15301540
Note: See TracChangeset for help on using the changeset viewer.