Changeset fc9153d
- Timestamp:
- Dec 22, 2017, 4:17:52 PM (7 years ago)
- 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, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- caab997
- Parents:
- ddb80bd
- Location:
- src/SynTree
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/AggregateDecl.cc
rddb80bd rfc9153d 86 86 std::string TraitDecl::typeString() const { return "trait"; } 87 87 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 } else { 95 assertf( false, "Unhandled expression type in getConstValue for enumerators: %s", toString( expr ).c_str() ); 96 } 97 } 98 } 99 100 bool EnumDecl::valueOf( Declaration * enumerator, long long int & value ) { 101 if ( enumValues.empty() ) { 102 long long int currentValue = 0; 103 for ( Declaration * member : members ) { 104 ObjectDecl * field = strict_dynamic_cast< ObjectDecl * >( member ); 105 if ( field->init ) { 106 SingleInit * init = strict_dynamic_cast< SingleInit * >( field->init ); 107 currentValue = getConstValue( init->value ); 108 } 109 assertf( enumValues.count( field->name ) == 0, "Enum %s has multiple members with the name %s", name.c_str(), field->name.c_str() ); 110 enumValues[ field->name ] = currentValue; 111 ++currentValue; 112 } 113 } 114 if ( enumValues.count( enumerator->name ) ) { 115 value = enumValues[ enumerator->name ]; 116 return true; 117 } 118 return false; 119 } 120 88 121 // Local Variables: // 89 122 // tab-width: 4 // -
src/SynTree/Declaration.h
rddb80bd rfc9153d 319 319 EnumDecl( const EnumDecl &other ) : Parent( other ) {} 320 320 321 bool valueOf( Declaration * enumerator, long long int & value ); 322 321 323 virtual EnumDecl *clone() const override { return new EnumDecl( *this ); } 322 324 virtual void accept( Visitor &v ) override { v.visit( this ); } 323 325 virtual Declaration *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 324 326 private: 327 std::map< std::string, long long int > enumValues; 325 328 virtual std::string typeString() const override; 326 329 };
Note: See TracChangeset
for help on using the changeset viewer.