From f763cec8f4646542e466c09d351f651585e91d7d Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Wed, 28 Feb 2024 10:41:03 +0800 Subject: [PATCH] - fix: Function argument infos are not correctly parsed. --- NEWS.md | 3 ++- RedPandaIDE/parser/cppparser.cpp | 24 ++++++++++++++++-------- RedPandaIDE/parser/cpptokenizer.cpp | 9 +++++++-- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/NEWS.md b/NEWS.md index c3f59d80..309ab211 100644 --- a/NEWS.md +++ b/NEWS.md @@ -11,7 +11,8 @@ Red Panda C++ Version 2.27 - enhancement: Don't force fixed-width when using non fixed-width fonts. - change: Replace non-ascii font with fallback font. - enhancement: Display ascii control chars. - - fix: Parser: invalidating file may break class inheritance infos. + - fix: Parser: invalidating file may lost class inheritance infos. + - fix: Function argument infos are not correctly parsed. Red Panda C++ Version 2.26 - enhancement: Code suggestion for embedded std::vectors. diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index 951e6df0..27d80f5e 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -1460,7 +1460,8 @@ PStatement CppParser::addStatement(const PStatement &parent, QChar ch=mTokenizer[i]->text[0]; if (this->isIdentChar(ch)) { QString spaces=(i>argStart)?" ":""; - args+=spaces; + if (args.length()>0 && isWordChar(args.back())) + args+=spaces; word += mTokenizer[i]->text; if (!typeGetted) { noNameArgs+=spaces+word; @@ -1473,12 +1474,17 @@ PStatement CppParser::addStatement(const PStatement &parent, } word=""; } else if (this->isDigitChar(ch)) { - args+=" "; + } else if (mTokenizer[i]->text=="::") { + if (braceLevel==0) { + noNameArgs+= mTokenizer[i]->text; + } } else { switch(ch.unicode()) { case ',': - if (braceLevel==0) + if (braceLevel==0) { typeGetted=false; + noNameArgs+= mTokenizer[i]->text; + } break; case '{': case '[': @@ -1495,15 +1501,17 @@ PStatement CppParser::addStatement(const PStatement &parent, //todo: * and & processing case '*': case '&': - if (braceLevel==0) - word+=ch; + if (braceLevel==0) { + noNameArgs+= mTokenizer[i]->text; + } break; } - noNameArgs+= mTokenizer[i]->text; } args+=mTokenizer[i]->text; } - + if (!word.isEmpty()) { + noNameArgs.append(word); + } args="("+args.trimmed()+")"; noNameArgs="("+noNameArgs.trimmed()+")"; return addStatement( @@ -4493,7 +4501,7 @@ void CppParser::internalParse(const QString &fileName) if (mTokenizer.tokenCount() == 0) return; #ifdef QT_DEBUG -// mTokenizer.dumpTokens(QString("r:\\tokens-%1.txt").arg(extractFileName(fileName))); + // mTokenizer.dumpTokens(QString("r:\\tokens-%1.txt").arg(extractFileName(fileName))); #endif #ifdef QT_DEBUG mLastIndex = -1; diff --git a/RedPandaIDE/parser/cpptokenizer.cpp b/RedPandaIDE/parser/cpptokenizer.cpp index a5130d9c..26ef60c9 100644 --- a/RedPandaIDE/parser/cpptokenizer.cpp +++ b/RedPandaIDE/parser/cpptokenizer.cpp @@ -415,9 +415,14 @@ QString CppTokenizer::getNumber() QString result; if (offset != mCurrent) { + if (*mCurrent=='.') { + // keep '.' for decimal + mCurrent++; + while (isDigitChar(*mCurrent) || isHexChar(*mCurrent)) { + mCurrent++; + } + } result = QString(offset,mCurrent-offset); - if (*mCurrent=='.') // keep '.' for decimal - result += *mCurrent; } return result; }