Changeset ac3362c for src


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

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

Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Validate.cc

    r3537dd7 rac3362c  
    738738                                forwardEnums.erase( fwds );
    739739                        } // if
     740
     741                        for ( Declaration * member : enumDecl->members ) {
     742                                ObjectDecl * field = strict_dynamic_cast<ObjectDecl *>( member );
     743                                if ( field->init ) {
     744                                        // need to resolve enumerator initializers early so that other passes that determine if an expression is constexpr have the appropriate information.
     745                                        SingleInit * init = strict_dynamic_cast<SingleInit *>( field->init );
     746                                        ResolvExpr::findSingleExpression( init->value, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), indexer );
     747                                }
     748                        }
    740749                } // if
    741750        }
  • 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.