From 9a5f97cc7aab7fd94e43dfede2468736bb97c3da Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Wed, 11 Jan 2023 09:51:05 +0800 Subject: [PATCH] - fix: Function parameters that is pointer,reference or array can't be correctly parsed. --- NEWS.md | 1 + RedPandaIDE/parser/cppparser.cpp | 49 ++++++++++++++---------------- libs/qsynedit/qsynedit/SynEdit.cpp | 4 +-- libs/qsynedit/qsynedit/SynEdit.h | 2 +- 4 files changed, 26 insertions(+), 30 deletions(-) diff --git a/NEWS.md b/NEWS.md index 54c72da3..ee80ac75 100644 --- a/NEWS.md +++ b/NEWS.md @@ -23,6 +23,7 @@ Red Panda C++ Version 2.8 - fix: alt+shift+left/right can't select - fix: Input any content will exit column mode. - fix: Result of scope calculation not right if a for statement immediately follows another for statement. + - fix: Function parameters that is pointer,reference or array can't be correctly parsed. Red Panda C++ Version 2.7 diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index 502e08fe..ed2cfdb5 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -3819,7 +3819,7 @@ void CppParser::internalParse(const QString &fileName) QStringList preprocessResult = mPreprocessor.result(); #ifdef QT_DEBUG -// stringsToFile(mPreprocessor.result(),QString("r:\\preprocess-%1.txt").arg(extractFileName(fileName))); + stringsToFile(mPreprocessor.result(),QString("r:\\preprocess-%1.txt").arg(extractFileName(fileName))); // mPreprocessor.dumpDefinesTo("r:\\defines.txt"); // mPreprocessor.dumpIncludesListTo("r:\\includes.txt"); #endif @@ -3833,7 +3833,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 lastIndex = -1; @@ -3844,8 +3844,8 @@ void CppParser::internalParse(const QString &fileName) break; } #ifdef QT_DEBUG -// mStatementList.dumpAll(QString("r:\\all-stats-%1.txt").arg(extractFileName(fileName))); -// mStatementList.dump(QString("r:\\stats-%1.txt").arg(extractFileName(fileName))); + mStatementList.dumpAll(QString("r:\\all-stats-%1.txt").arg(extractFileName(fileName))); + mStatementList.dump(QString("r:\\stats-%1.txt").arg(extractFileName(fileName))); #endif //reduce memory usage internalClear(); @@ -5116,30 +5116,25 @@ void CppParser::scanMethodArgs(const PStatement& functionStatement, int argStart } else if (isWordChar(mTokenizer[i]->text[0])) { QString cmd=mTokenizer[i]->text; if (i+1==argEnd || mTokenizer[i+1]->text==',' || mTokenizer[i+1]->text=='=') { - bool noCmd=false; - if (!cmd.startsWith('*') - && !cmd.startsWith('&') - && !cmd.endsWith(']')) { - PStatement statement=findStatementOf(mCurrentFile,cmd,functionStatement,true); - noCmd = (statement && isTypeStatement(statement->kind)); + QString args,suffix; + parseCommandTypeAndArgs(cmd,suffix,args); + if (!cmd.isEmpty()) { + PStatement statement = findStatementOf(mCurrentFile,cmd,functionStatement,true); + bool noCmd = (statement && isTypeStatement(statement->kind)); if (!noCmd) { - QString args,suffix; - parseCommandTypeAndArgs(cmd,suffix,args); - if (!cmd.isEmpty()) { - addStatement( - functionStatement, - mCurrentFile, - varType+suffix, // 'int*' - cmd, // a - args, - "", - "", - mTokenizer[i]->line, - StatementKind::skParameter, - StatementScope::Local, - StatementClassScope::None, - StatementProperty::spHasDefinition); - } + addStatement( + functionStatement, + mCurrentFile, + varType+suffix, // 'int*' + cmd, // a + args, + "", + "", + mTokenizer[i]->line, + StatementKind::skParameter, + StatementScope::Local, + StatementClassScope::None, + StatementProperty::spHasDefinition); } } } else { diff --git a/libs/qsynedit/qsynedit/SynEdit.cpp b/libs/qsynedit/qsynedit/SynEdit.cpp index 931e4e3d..180b0134 100644 --- a/libs/qsynedit/qsynedit/SynEdit.cpp +++ b/libs/qsynedit/qsynedit/SynEdit.cpp @@ -5495,7 +5495,7 @@ void SynEdit::doInsertText(const BufferCoord& pos, ensureCursorPosVisible(); break; case SelectionMode::Column: - insertedLines = doInsertTextByColumnMode(pos,text, startLine,endLine); + insertedLines = doInsertTextByColumnMode(text, startLine,endLine); doLinesInserted(endLine-insertedLines+1,insertedLines); if (!text.isEmpty()) { int textLen = text.back().length(); @@ -5612,7 +5612,7 @@ int SynEdit::doInsertTextByNormalMode(const BufferCoord& pos, const QStringList& return result; } -int SynEdit::doInsertTextByColumnMode(const BufferCoord& pos, const QStringList& text, int startLine, int endLine) +int SynEdit::doInsertTextByColumnMode(const QStringList& text, int startLine, int endLine) { QString str; QString tempString; diff --git a/libs/qsynedit/qsynedit/SynEdit.h b/libs/qsynedit/qsynedit/SynEdit.h index a11d6fbe..826372b1 100644 --- a/libs/qsynedit/qsynedit/SynEdit.h +++ b/libs/qsynedit/qsynedit/SynEdit.h @@ -550,7 +550,7 @@ private: void doDeleteText(BufferCoord startPos, BufferCoord endPos, SelectionMode mode); void doInsertText(const BufferCoord& pos, const QStringList& text, SelectionMode mode, int startLine, int endLine); int doInsertTextByNormalMode(const BufferCoord& pos, const QStringList& text, BufferCoord &newPos); - int doInsertTextByColumnMode(const BufferCoord& pos, const QStringList& text, int startLine, int endLine); + int doInsertTextByColumnMode(const QStringList& text, int startLine, int endLine); int doInsertTextByLineMode(const BufferCoord& pos, const QStringList& text, BufferCoord &newPos); void doTrimTrailingSpaces();