@@ -6599,6 +6599,16 @@ void Parser::parse_enumerator_list(List<EnumeratorAST*>*& yyast,
65996599 *it = make_list_node (pool_, enumerator);
66006600 it = &(*it)->next ;
66016601
6602+ std::optional<ConstValue> lastValue;
6603+ ASTInterpreter interp{unit};
6604+
6605+ if (enumerator->expression ) {
6606+ lastValue = enumerator->symbol ->value ();
6607+ } else {
6608+ lastValue = std::intmax_t {0 };
6609+ enumerator->symbol ->setValue (*lastValue);
6610+ }
6611+
66026612 SourceLocation commaLoc;
66036613
66046614 while (match (TokenKind::T_COMMA, commaLoc)) {
@@ -6610,6 +6620,27 @@ void Parser::parse_enumerator_list(List<EnumeratorAST*>*& yyast,
66106620 EnumeratorAST* enumerator = nullptr ;
66116621 parse_enumerator (enumerator, type);
66126622
6623+ if (!enumerator->expression ) {
6624+ if (lastValue.has_value ()) {
6625+ if (control_->is_unsigned (type)) {
6626+ if (auto v = interp.toUInt (lastValue.value ())) {
6627+ lastValue = v.value () + 1 ;
6628+ } else {
6629+ lastValue = std::nullopt ;
6630+ }
6631+ } else {
6632+ if (auto v = interp.toInt (lastValue.value ())) {
6633+ lastValue = v.value () + 1 ;
6634+ } else {
6635+ lastValue = std::nullopt ;
6636+ }
6637+ }
6638+ }
6639+ enumerator->symbol ->setValue (*lastValue);
6640+ } else {
6641+ lastValue = enumerator->symbol ->value ();
6642+ }
6643+
66136644 *it = make_list_node (pool_, enumerator);
66146645 it = &(*it)->next ;
66156646 }
0 commit comments