From c6fb11d13041cbbf6a5cdd52d5304875919d1232 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Mon, 29 May 2023 09:34:07 +0800 Subject: [PATCH] work save --- RedPandaIDE/parser/cppparser.cpp | 74 +++++++++++++++------------ RedPandaIDE/parser/cppparser.h | 1 + RedPandaIDE/widgets/bookmarkmodel.cpp | 2 +- 3 files changed, 42 insertions(+), 35 deletions(-) diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index 2a481913..2cdde67d 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -1402,6 +1402,35 @@ PStatement CppParser::addStatement(const PStatement &parent, properties); } +void CppParser::addMethodParameterStatement(QStringList words, int line, const PStatement &functionStatement) +{ + if (words.isEmpty()) + return; + QString args,suffix; + QString cmd=words.last(); + parseCommandTypeAndArgs(cmd,suffix,args); + words.pop_back(); + if (!cmd.isEmpty()) { + PStatement statement = doFindStatementOf(mCurrentFile,cmd,functionStatement); + bool noCmd = (statement && isTypeStatement(statement->kind)); + if (!noCmd) { + addStatement( + functionStatement, + mCurrentFile, + words.join(" ")+" "+suffix, // 'int*' + cmd, // a + args, + "", + "", + line, + StatementKind::skParameter, + StatementScope::Local, + StatementAccessibility::None, + StatementProperty::spHasDefinition); + } + } +} + void CppParser::setInheritance(int index, const PStatement& classStatement, bool isStruct) { int tokenCount = mTokenizer.tokenCount(); @@ -5338,7 +5367,7 @@ void CppParser::scanMethodArgs(const PStatement& functionStatement, int argStart int paramStart = argStart+1; int i = paramStart ; // assume it starts with ( and ends with ) // Keep going and stop on top of the variable name - QString varType = ""; + QStringList words; while (i < argEnd) { if (mTokenizer[i]->text=='(' && mTokenizer[i]->matchIndex+1text=='{') { i=mTokenizer[i]->matchIndex+1; - } else if (mTokenizer[i]->text=='(') { - i=mTokenizer[i]->matchIndex+1; } else if (mTokenizer[i]->text.endsWith('=')) { + addMethodParameterStatement(words,mTokenizer[i]->line,functionStatement); i=skipAssignment(i,argEnd); } else if (mTokenizer[i]->text=="::") { - varType+=mTokenizer[i]->text; + words.append(mTokenizer[i]->text); i++; + } else if (mTokenizer[i]->text==',') { + addMethodParameterStatement(words,mTokenizer[i]->line,functionStatement); + i++; + words.clear(); } else if (isWordChar(mTokenizer[i]->text[0])) { QString cmd=mTokenizer[i]->text; - if (i+1==argEnd || mTokenizer[i+1]->text==',' || mTokenizer[i+1]->text=='=') { - QString args,suffix; - parseCommandTypeAndArgs(cmd,suffix,args); - if (!cmd.isEmpty()) { - PStatement statement = doFindStatementOf(mCurrentFile,cmd,functionStatement); - bool noCmd = (statement && isTypeStatement(statement->kind)); - if (!noCmd) { - addStatement( - functionStatement, - mCurrentFile, - varType+suffix, // 'int*' - cmd, // a - args, - "", - "", - mTokenizer[i]->line, - StatementKind::skParameter, - StatementScope::Local, - StatementAccessibility::None, - StatementProperty::spHasDefinition); - } - } - } else { - if (!varType.isEmpty()) - varType+=' '; - varType+=cmd; - } + words.append(cmd); i++; } else { i++; - varType=""; } } + addMethodParameterStatement(words,mTokenizer[i-1]->line,functionStatement); } diff --git a/RedPandaIDE/parser/cppparser.h b/RedPandaIDE/parser/cppparser.h index 84cc0f0e..6643d1f4 100644 --- a/RedPandaIDE/parser/cppparser.h +++ b/RedPandaIDE/parser/cppparser.h @@ -196,6 +196,7 @@ private: const StatementScope& scope, const StatementAccessibility& classScope, StatementProperties properties); + void addMethodParameterStatement(QStringList words,int line, const PStatement& functionStatement); void setInheritance(int index, const PStatement& classStatement, bool isStruct); bool isCurrentScope(const QString& command) const; void addSoloScopeLevel(PStatement& statement, int line, bool shouldResetBlock=false); // adds new solo level diff --git a/RedPandaIDE/widgets/bookmarkmodel.cpp b/RedPandaIDE/widgets/bookmarkmodel.cpp index 8789307b..84cefb6e 100644 --- a/RedPandaIDE/widgets/bookmarkmodel.cpp +++ b/RedPandaIDE/widgets/bookmarkmodel.cpp @@ -236,7 +236,7 @@ void BookmarkModel::save(const QString &filename, const QString& projectFolder) QFile file(filename); if (file.open(QFile::WriteOnly | QFile::Truncate)) { - QList saveBookmarks; +// QList saveBookmarks; QDir dir(projectFolder); foreach (const PBookmark& bookmark, fileBookmarks) {