fix: Value of noname enum members are not shown in the class browser.

This commit is contained in:
Roy Qu 2023-08-07 14:42:42 +08:00
parent 6a06b5b3d6
commit d1214e3d63
2 changed files with 7 additions and 25 deletions

View File

@ -1877,21 +1877,6 @@ int CppParser::evaluateConstExprTerm(int endIndex, bool &ok)
if (statement->kind == StatementKind::skEnum) { if (statement->kind == StatementKind::skEnum) {
result = statement->value.toInt(&ok); result = statement->value.toInt(&ok);
break; break;
} else if (statement->kind == StatementKind::skPreprocessor) {
if (!statement->args.isEmpty()) {
ok=false;
return result;
}
QString macroText = statement->value;
if (macroText.isEmpty()) {
ok=false;
return result;
}
if (isDigitChar(macroText[0])) {
result = evaluateLiteralNumber(endIndex,ok);
} else {
s = macroText;
}
} }
} }
} else { } else {
@ -2687,12 +2672,8 @@ void CppParser::handleEnum(bool isTypedef)
mTokenizer[mIndex+1]->text=="=") { mTokenizer[mIndex+1]->text=="=") {
mIndex+=2; mIndex+=2;
if (mIndex<tokenCount) { if (mIndex<tokenCount) {
bool ok;
int endIndex = indexOfNextPeriodOrSemicolon(mIndex); int endIndex = indexOfNextPeriodOrSemicolon(mIndex);
value = evaluateConstExpr(endIndex,ok); value = evaluateConstExpr(endIndex,canCalcValue);
if (!ok) {
canCalcValue=false;
}
mIndex = endIndex - 1; mIndex = endIndex - 1;
} }
} }

View File

@ -154,13 +154,14 @@ QVariant ClassBrowserModel::data(const QModelIndex &index, int role) const
|| (node->statement->kind == StatementKind::skTypedef) || (node->statement->kind == StatementKind::skTypedef)
) { ) {
return node->statement->command + node->statement->args + " : " + node->statement->type; return node->statement->command + node->statement->args + " : " + node->statement->type;
} else if (node->statement->kind == StatementKind::skEnum) { }
}
if (node->statement->kind == StatementKind::skEnum) {
if (!node->statement->value.isEmpty()) if (!node->statement->value.isEmpty())
return node->statement->command + node->statement->args + QString("(%1)").arg(node->statement->value); return node->statement->command + node->statement->args + QString("(%1)").arg(node->statement->value);
else else
return node->statement->command; return node->statement->command;
} }
}
return node->statement->command + node->statement->args; return node->statement->command + node->statement->args;
} }
} else if (role == Qt::ForegroundRole) { } else if (role == Qt::ForegroundRole) {