refactor: structural binding

This commit is contained in:
Roy Qu 2024-05-04 10:31:15 +08:00
parent ae8e8fdaa6
commit 49049b0884
1 changed files with 6 additions and 4 deletions

View File

@ -2299,9 +2299,6 @@ void CppParser::checkAndHandleMethodOrVar(KeywordType keywordType, int maxIndex)
mIndex, mIndex,
isStatic, maxIndex); isStatic, maxIndex);
return; return;
} else if (mTokenizer[mIndex]->text.startsWith("[") && AutoTypes.contains(sType)) {
handleStructredBinding(sType,maxIndex);
return;
} else if (mTokenizer[mIndex + 1]->text == '(') { } else if (mTokenizer[mIndex + 1]->text == '(') {
#ifdef ENABLE_SDCC #ifdef ENABLE_SDCC
if (mLanguage==ParserLanguage::SDCC && mTokenizer[mIndex]->text=="__at") { if (mLanguage==ParserLanguage::SDCC && mTokenizer[mIndex]->text=="__at") {
@ -2406,6 +2403,11 @@ void CppParser::checkAndHandleMethodOrVar(KeywordType keywordType, int maxIndex)
||mTokenizer[mIndex + 1]->text == ':' ||mTokenizer[mIndex + 1]->text == ':'
||mTokenizer[mIndex + 1]->text == '{' ||mTokenizer[mIndex + 1]->text == '{'
|| mTokenizer[mIndex + 1]->text == '=') { || mTokenizer[mIndex + 1]->text == '=') {
if (mTokenizer[mIndex]->text.startsWith("[")
&& AutoTypes.contains(sType)) {
handleStructredBinding(sType,maxIndex);
return;
}
handleVar(sType+" "+sName,isExtern,isStatic, maxIndex); handleVar(sType+" "+sName,isExtern,isStatic, maxIndex);
return; return;
} else if ( mTokenizer[mIndex + 1]->text == "::") { } else if ( mTokenizer[mIndex + 1]->text == "::") {
@ -3958,7 +3960,7 @@ void CppParser::handleStructredBinding(const QString &sType, int maxIndex)
QStringList lst = s.split(","); QStringList lst = s.split(",");
if (lst.length()==2) { if (lst.length()==2) {
QString firstVar = lst[0].trimmed(); QString firstVar = lst[0].trimmed();
QString secondVar = lst[1].trimmed; QString secondVar = lst[1].trimmed();
bool isConst = sType.startsWith("const"); bool isConst = sType.startsWith("const");
QString suffix; QString suffix;
if (sType.endsWith("&&")) suffix = "&&"; if (sType.endsWith("&&")) suffix = "&&";