Changes in src/AST/Decl.cpp [2bb4a01:a300e4a]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Decl.cpp
r2bb4a01 ra300e4a 14 14 // 15 15 16 #include <cassert> // for assert, strict_dynamic_cast 16 17 #include <unordered_map> 17 18 18 19 #include "Decl.hpp" 19 20 20 #include "Fwd.hpp" // for UniqueId 21 #include "Node.hpp" // for readonly 21 #include "Fwd.hpp" // for UniqueId 22 #include "Init.hpp" 23 #include "Node.hpp" // for readonly 22 24 23 25 namespace ast { 26 24 27 // To canonicalize declarations 25 28 static UniqueId lastUniqueId = 0; … … 39 42 return {}; 40 43 } 44 45 // --- EnumDecl 46 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 41 77 } 42 78
Note: See TracChangeset
for help on using the changeset viewer.