From 56c71f321f8760ef834415f2dc298f3412b9012c Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Mon, 18 Apr 2022 16:56:31 +0800 Subject: [PATCH] - fix: parse error for definition of functions whose return type is pointer --- NEWS.md | 1 + RedPandaIDE/parser/cppparser.cpp | 41 ++++++++++++++------------- RedPandaIDE/parser/statementmodel.cpp | 3 ++ 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/NEWS.md b/NEWS.md index 477f1b02..d49f1aa1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -15,6 +15,7 @@ Red Panda C++ Version 1.0.4 - enhancement: add Traditional Chinese translation - fix: index of the longest line not correctly updated ( which will cause selection errors) - fix: scroll bar not correctly updated when collapse/uncollapse folders + - fix: parse error for definition of functions whose return type is pointer Red Panda C++ Version 1.0.3 - fix: when oj problem grabbed by competitive companion received, diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index c4ceecec..e98807e5 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -1158,27 +1158,30 @@ PStatement CppParser::addStatement(const PStatement& parent, if (kind == StatementKind::skConstructor || kind == StatementKind::skFunction || kind == StatementKind::skDestructor - || kind == StatementKind::skVariable) { + || kind == StatementKind::skVariable + ) { noNameArgs = removeArgNames(args); //find - PStatement oldStatement = findStatementInScope(command,noNameArgs,kind,parent); - if (oldStatement && isDefinition && !oldStatement->hasDefinition) { - oldStatement->hasDefinition = true; - if (oldStatement->fileName!=fileName) { - PFileIncludes fileIncludes1=mPreprocessor.includesList().value(fileName); - if (fileIncludes1) { - fileIncludes1->statements.insert(oldStatement->fullName, - oldStatement); - fileIncludes1->dependingFiles.insert(oldStatement->fileName); - PFileIncludes fileIncludes2=mPreprocessor.includesList().value(oldStatement->fileName); - if (fileIncludes2) { - fileIncludes2->dependedFiles.insert(fileName); + if (isDefinition) { + PStatement oldStatement = findStatementInScope(newCommand,noNameArgs,kind,parent); + if (oldStatement && !oldStatement->hasDefinition) { + oldStatement->hasDefinition = true; + if (oldStatement->fileName!=fileName) { + PFileIncludes fileIncludes1=mPreprocessor.includesList().value(fileName); + if (fileIncludes1) { + fileIncludes1->statements.insert(oldStatement->fullName, + oldStatement); + fileIncludes1->dependingFiles.insert(oldStatement->fileName); + PFileIncludes fileIncludes2=mPreprocessor.includesList().value(oldStatement->fileName); + if (fileIncludes2) { + fileIncludes2->dependedFiles.insert(fileName); + } } } + oldStatement->definitionLine = line; + oldStatement->definitionFileName = fileName; + return oldStatement; } - oldStatement->definitionLine = line; - oldStatement->definitionFileName = fileName; - return oldStatement; } } PStatement result = std::make_shared(); @@ -3246,9 +3249,9 @@ void CppParser::internalParse(const QString &fileName) //reduce memory usage internalClear(); #ifdef QT_DEBUG -// mTokenizer.dumpTokens("r:\\tokens.txt"); -// mStatementList.dump("r:\\stats.txt"); -// mStatementList.dumpAll("r:\\all-stats.txt"); +// mTokenizer.dumpTokens("z:\\tokens.txt"); +// +// mStatementList.dumpAll("r:\\all-stats.txt"); #endif //reduce memory usage mTokenizer.reset(); diff --git a/RedPandaIDE/parser/statementmodel.cpp b/RedPandaIDE/parser/statementmodel.cpp index f915d1e3..06d5c268 100644 --- a/RedPandaIDE/parser/statementmodel.cpp +++ b/RedPandaIDE/parser/statementmodel.cpp @@ -138,12 +138,15 @@ void StatementModel::dumpStatementMap(StatementMap &map, QTextStream &out, int l out<command).arg(int(statement->kind)) .arg(statement->type,statement->fullName) + .arg(statement->noNameArgs) + .arg(statement->args) .arg((size_t)(statement->parentScope.lock().get())) .arg((int)statement->classScope) .arg(statement->fileName) .arg(statement->line) .arg(statement->definitionFileName) .arg(statement->definitionLine); + out<children.isEmpty()) continue; out<command<<" {"<