From 56972d168e589e9c1c9c7d4ac1be7d17f8aa9f75 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Wed, 1 Mar 2023 22:53:14 +0800 Subject: [PATCH] - fix: Can't correctly parse function pointer var definition. --- NEWS.md | 2 ++ RedPandaIDE/compiler/compilerinfo.cpp | 12 ++++++------ RedPandaIDE/parser/cppparser.cpp | 27 +++++++++++++++++++-------- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/NEWS.md b/NEWS.md index 7a215a32..650590e0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,10 +4,12 @@ Red Panda C++ Version 2.16 - enhancement: Improve support for function pointer typedefs. - fix: Can't debug project when project is saved after it's compiled. - fix: Icons for buttons in the cpu info dialog is not correctly set. + - fix: Can't locate the corresponding line in the generated asm file under linux. - enhancement: Add cfi directives for asm syntaxer in linux. - change: Editor option "Scroll past end of line" default to false. - emhancement: Improve display of disassembled codes in the cpu info dialog. - change: Set optimization level to -Og for Debug compiler settings by default. + - fix: Can't correctly parse function pointer var definition. Red Panda C++ Version 2.15 diff --git a/RedPandaIDE/compiler/compilerinfo.cpp b/RedPandaIDE/compiler/compilerinfo.cpp index 90acfee3..0b81d138 100644 --- a/RedPandaIDE/compiler/compilerinfo.cpp +++ b/RedPandaIDE/compiler/compilerinfo.cpp @@ -60,12 +60,12 @@ void CompilerInfo::prepareCompilerOptions() groupName = QObject::tr("Code Generation"); // Optimization sl.clear(); - sl.append(QPair("Low","1")); - sl.append(QPair("Med","2")); - sl.append(QPair("High","3")); - sl.append(QPair("Highest (fast)","fast")); - sl.append(QPair("Size (s)","s")); - sl.append(QPair("Debug (g)","g")); + sl.append(QPair("Low (-O1)","1")); + sl.append(QPair("Med (-O2)","2")); + sl.append(QPair("High (-O3)","3")); + sl.append(QPair("Highest (-Ofast)","fast")); + sl.append(QPair("Size (-Os)","s")); + sl.append(QPair("Debug (-Og)","g")); addOption(CC_CMD_OPT_OPTIMIZE, QObject::tr("Optimization level (-Ox)"), groupName, true, true, false, "-O", sl); // C++ Language Standards diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index 3b1f1ff6..aa455b6c 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -1719,10 +1719,12 @@ void CppParser::checkAndHandleMethodOrVar(KeywordType keywordType) return; } QString currentText=mTokenizer[mIndex]->text; + bool declAuto=false; if (keywordType==KeywordType::DeclType) { if (mTokenizer[mIndex+1]->text=='(') { currentText="auto"; mIndex=mTokenizer[mIndex+1]->matchIndex+1; + declAuto=true; } else { currentText=mTokenizer[mIndex+1]->text; mIndex+=2; @@ -1742,14 +1744,10 @@ void CppParser::checkAndHandleMethodOrVar(KeywordType keywordType) handleMethod(StatementKind::skFunction,"", mergeArgs(mIndex+1,mTokenizer[mIndex]->matchIndex-1), indexAfterParentheis,false,false); -// } else if (currentText.endsWith("::operator")) { -// mIndex=indexAfterParentheis; -// handleMethod(StatementKind::skFunction,"", -// mergeArgs(mIndex+1,mTokenizer[mIndex]->matchIndex-1), -// indexAfterParentheis,false,false); } else { //function pointer var - handleVar(currentText,false,false); + mIndex--; + handleVar("",false,false); } } else { if (currentText=="operator") { @@ -3602,7 +3600,8 @@ void CppParser::handleVar(const QString& typePrefix,bool isExtern,bool isStatic) } } else if (mTokenizer[mIndex]->text==';') { break; - } else if (isIdentChar(mTokenizer[mIndex]->text[0])) { + } else if (isIdentChar(mTokenizer[mIndex]->text[0]) + || mTokenizer[mIndex]->text[0]==')') { //decltype(auto) QString cmd=mTokenizer[mIndex]->text; if (mIndex+1< mTokenizer.tokenCount() && mTokenizer[mIndex+1]->text=='(' && mTokenizer[mIndex+1]->matchIndex+1text; + if (s1==")") // decltype(auto) + s1="auto"; + if(type.endsWith("::")) + type+=tempType; + else + type+=" "+tempType; + if(type.endsWith("::")) + type+=s1; + else + type+=" "+s1; + addedVar = addChildStatement( getCurrentScope(), mCurrentFile, - (lastType+" "+tempType+" "+mTokenizer[mIndex]->text).trimmed(), + type.trimmed(), cmd, mergeArgs(argStart,argEnd), "",