- fix: Can't correctly parse function pointer var definition.

This commit is contained in:
Roy Qu 2023-03-01 22:53:14 +08:00
parent 683331e848
commit 56972d168e
3 changed files with 27 additions and 14 deletions

View File

@ -4,10 +4,12 @@ Red Panda C++ Version 2.16
- enhancement: Improve support for function pointer typedefs. - enhancement: Improve support for function pointer typedefs.
- fix: Can't debug project when project is saved after it's compiled. - 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: 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. - enhancement: Add cfi directives for asm syntaxer in linux.
- change: Editor option "Scroll past end of line" default to false. - change: Editor option "Scroll past end of line" default to false.
- emhancement: Improve display of disassembled codes in the cpu info dialog. - emhancement: Improve display of disassembled codes in the cpu info dialog.
- change: Set optimization level to -Og for Debug compiler settings by default. - 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 Red Panda C++ Version 2.15

View File

@ -60,12 +60,12 @@ void CompilerInfo::prepareCompilerOptions()
groupName = QObject::tr("Code Generation"); groupName = QObject::tr("Code Generation");
// Optimization // Optimization
sl.clear(); sl.clear();
sl.append(QPair<QString,QString>("Low","1")); sl.append(QPair<QString,QString>("Low (-O1)","1"));
sl.append(QPair<QString,QString>("Med","2")); sl.append(QPair<QString,QString>("Med (-O2)","2"));
sl.append(QPair<QString,QString>("High","3")); sl.append(QPair<QString,QString>("High (-O3)","3"));
sl.append(QPair<QString,QString>("Highest (fast)","fast")); sl.append(QPair<QString,QString>("Highest (-Ofast)","fast"));
sl.append(QPair<QString,QString>("Size (s)","s")); sl.append(QPair<QString,QString>("Size (-Os)","s"));
sl.append(QPair<QString,QString>("Debug (g)","g")); sl.append(QPair<QString,QString>("Debug (-Og)","g"));
addOption(CC_CMD_OPT_OPTIMIZE, QObject::tr("Optimization level (-Ox)"), groupName, true, true, false, "-O", sl); addOption(CC_CMD_OPT_OPTIMIZE, QObject::tr("Optimization level (-Ox)"), groupName, true, true, false, "-O", sl);
// C++ Language Standards // C++ Language Standards

View File

@ -1719,10 +1719,12 @@ void CppParser::checkAndHandleMethodOrVar(KeywordType keywordType)
return; return;
} }
QString currentText=mTokenizer[mIndex]->text; QString currentText=mTokenizer[mIndex]->text;
bool declAuto=false;
if (keywordType==KeywordType::DeclType) { if (keywordType==KeywordType::DeclType) {
if (mTokenizer[mIndex+1]->text=='(') { if (mTokenizer[mIndex+1]->text=='(') {
currentText="auto"; currentText="auto";
mIndex=mTokenizer[mIndex+1]->matchIndex+1; mIndex=mTokenizer[mIndex+1]->matchIndex+1;
declAuto=true;
} else { } else {
currentText=mTokenizer[mIndex+1]->text; currentText=mTokenizer[mIndex+1]->text;
mIndex+=2; mIndex+=2;
@ -1742,14 +1744,10 @@ void CppParser::checkAndHandleMethodOrVar(KeywordType keywordType)
handleMethod(StatementKind::skFunction,"", handleMethod(StatementKind::skFunction,"",
mergeArgs(mIndex+1,mTokenizer[mIndex]->matchIndex-1), mergeArgs(mIndex+1,mTokenizer[mIndex]->matchIndex-1),
indexAfterParentheis,false,false); indexAfterParentheis,false,false);
// } else if (currentText.endsWith("::operator")) {
// mIndex=indexAfterParentheis;
// handleMethod(StatementKind::skFunction,"",
// mergeArgs(mIndex+1,mTokenizer[mIndex]->matchIndex-1),
// indexAfterParentheis,false,false);
} else { } else {
//function pointer var //function pointer var
handleVar(currentText,false,false); mIndex--;
handleVar("",false,false);
} }
} else { } else {
if (currentText=="operator") { if (currentText=="operator") {
@ -3602,7 +3600,8 @@ void CppParser::handleVar(const QString& typePrefix,bool isExtern,bool isStatic)
} }
} else if (mTokenizer[mIndex]->text==';') { } else if (mTokenizer[mIndex]->text==';') {
break; 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; QString cmd=mTokenizer[mIndex]->text;
if (mIndex+1< mTokenizer.tokenCount() && mTokenizer[mIndex+1]->text=='(' if (mIndex+1< mTokenizer.tokenCount() && mTokenizer[mIndex+1]->text=='('
&& mTokenizer[mIndex+1]->matchIndex+1<mTokenizer.tokenCount() && mTokenizer[mIndex+1]->matchIndex+1<mTokenizer.tokenCount()
@ -3615,10 +3614,22 @@ void CppParser::handleVar(const QString& typePrefix,bool isExtern,bool isStatic)
if (!cmd.isEmpty()) { if (!cmd.isEmpty()) {
QString type=lastType; QString type=lastType;
QString s1=mTokenizer[mIndex]->text;
if (s1==")") // decltype(auto)
s1="auto";
if(type.endsWith("::"))
type+=tempType;
else
type+=" "+tempType;
if(type.endsWith("::"))
type+=s1;
else
type+=" "+s1;
addedVar = addChildStatement( addedVar = addChildStatement(
getCurrentScope(), getCurrentScope(),
mCurrentFile, mCurrentFile,
(lastType+" "+tempType+" "+mTokenizer[mIndex]->text).trimmed(), type.trimmed(),
cmd, cmd,
mergeArgs(argStart,argEnd), mergeArgs(argStart,argEnd),
"", "",