Ignore:
Timestamp:
Aug 3, 2018, 11:56:53 AM (3 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer
Children:
f271bdd
Parents:
3537dd7
Message:

Resolve enumerator initializers early to allow other passes to determine if expression is constexpr and to evaluate constexprs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/AggregateDecl.cc

    r3537dd7 rac3362c  
    8686std::string TraitDecl::typeString() const { return "trait"; }
    8787
    88 namespace {
    89         long long int getConstValue( Expression * expr ) {
    90                 if ( CastExpr * castExpr = dynamic_cast< CastExpr * > ( expr ) ) {
    91                         return getConstValue( castExpr->arg );
    92                 } else if ( ConstantExpr * constExpr = dynamic_cast< ConstantExpr * >( expr ) ) {
    93                         return constExpr->intValue();
    94                 // can be -1, +1, etc.
    95                 // } else if ( UntypedExpr * untypedExpr = dynamic_cast< UntypedExpr * >( expr ) ) {
    96                 //      if ( untypedExpr-> )
    97                 } else {
    98                         assertf( false, "Unhandled expression type in getConstValue for enumerators: %s", toString( expr ).c_str() );
    99                 }
    100         }
    101 }
    102 
    10388bool EnumDecl::valueOf( Declaration * enumerator, long long int & value ) {
    10489        if ( enumValues.empty() ) {
     
    10893                        if ( field->init ) {
    10994                                SingleInit * init = strict_dynamic_cast< SingleInit * >( field->init );
    110                                 currentValue = getConstValue( init->value );
     95                                auto result = eval( init->value );
     96                                if ( ! result.second ) SemanticError( init->location, toString( "Non-constexpr in initialization of enumerator: ", field ) );
     97                                currentValue = result.first;
    11198                        }
    11299                        assertf( enumValues.count( field->name ) == 0, "Enum %s has multiple members with the name %s", name.c_str(), field->name.c_str() );
Note: See TracChangeset for help on using the changeset viewer.