From c1f8489bfd5bc36688196dfc01ac9e31327610bb Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Tue, 21 Feb 2023 22:40:29 +0800 Subject: [PATCH] Assert fail on parser in DEBUG mode, when multiparser working at the same time --- RedPandaIDE/parser/cppparser.cpp | 12 ++++-------- RedPandaIDE/parser/cppparser.h | 4 +++- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index ebbb91bf..cebd32da 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -27,6 +27,7 @@ #include static QAtomicInt cppParserCount(0); + CppParser::CppParser(QObject *parent) : QObject(parent), #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) mMutex() @@ -3010,11 +3011,6 @@ void CppParser::handleScope(KeywordType keywordType) mIndex+=2; // the scope is followed by a ':' } - -#ifdef QT_DEBUG -static int lastIndex=-1; -#endif - bool CppParser::handleStatement() { QString funcType,funcName; @@ -3024,8 +3020,8 @@ bool CppParser::handleStatement() KeywordType keywordType; #ifdef QT_DEBUG // qDebug()<=lastIndex); - lastIndex=mIndex; + Q_ASSERT(mIndex>=mLastIndex); + mLastIndex=mIndex; #endif if (mIndex >= idx2) { @@ -3826,7 +3822,7 @@ void CppParser::internalParse(const QString &fileName) // mTokenizer.dumpTokens(QString("r:\\tokens-%1.txt").arg(extractFileName(fileName))); #endif #ifdef QT_DEBUG - lastIndex = -1; + mLastIndex = -1; #endif // Process the token list while(true) { diff --git a/RedPandaIDE/parser/cppparser.h b/RedPandaIDE/parser/cppparser.h index b9e0e403..f39d9121 100644 --- a/RedPandaIDE/parser/cppparser.h +++ b/RedPandaIDE/parser/cppparser.h @@ -665,7 +665,9 @@ private: bool mParsing; QHash mNamespaces; // namespace and the statements in its scope QSet mInlineNamespaces; - +#ifdef QT_DEBUG + int mLastIndex; +#endif #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) QRecursiveMutex mMutex; #else