Changes in src/AST/Decl.cpp [a300e4a:2bb4a01]
- File:
-
- 1 edited
-
src/AST/Decl.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Decl.cpp
ra300e4a r2bb4a01 14 14 // 15 15 16 #include <cassert> // for assert, strict_dynamic_cast17 16 #include <unordered_map> 18 17 19 18 #include "Decl.hpp" 20 19 21 #include "Fwd.hpp" // for UniqueId 22 #include "Init.hpp" 23 #include "Node.hpp" // for readonly 20 #include "Fwd.hpp" // for UniqueId 21 #include "Node.hpp" // for readonly 24 22 25 23 namespace ast { 26 27 24 // To canonicalize declarations 28 25 static UniqueId lastUniqueId = 0; … … 42 39 return {}; 43 40 } 44 45 // --- EnumDecl46 47 bool EnumDecl::valueOf( Decl* enumerator, long long& value ) const {48 if ( enumValues.empty() ) {49 long long crntVal = 0;50 for ( const Decl* member : members ) {51 const ObjectDecl* field = strict_dynamic_cast< const ObjectDecl* >( member );52 if ( field->init ) {53 const SingleInit* init = strict_dynamic_cast< const SingleInit* >( field->init );54 auto result = eval( init->value );55 if ( ! result.second ) {56 SemanticError( init->location, toString( "Non-constexpr in initialization of "57 "enumerator: ", field ) );58 }59 crntVal = result.first;60 }61 if ( enumValues.count( field->name ) != 0 ) {62 SemanticError( location, toString( "Enum ", name, " has multiple members with the " "name ", field->name ) );63 }64 enumValues[ field->name ] = crntVal;65 ++crntVal;66 }67 }68 69 auto it = enumValues.find( enumerator->name );70 if ( it != enumValues.end() ) {71 value = it->second;72 return true;73 }74 return false;75 }76 77 41 } 78 42
Note:
See TracChangeset
for help on using the changeset viewer.