From cd65ecd74ade6d5616429e0f6c8258613937f282 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Sun, 5 May 2024 16:01:29 +0800 Subject: [PATCH] - fix: Fail to evaluate expressions if macro can't be expanded. --- NEWS.md | 1 + RedPandaIDE/parser/cppparser.cpp | 5 +++-- RedPandaIDE/widgets/codecompletionpopup.cpp | 8 +------- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/NEWS.md b/NEWS.md index 5293e534..bb30f834 100644 --- a/NEWS.md +++ b/NEWS.md @@ -164,6 +164,7 @@ Red Panda C++ Version 2.27 - enhancement: New compiler option "stack size" in the link subpage. - change: Set "Ctrl+G" as the shortcut for "Goto page..." - change: Set "Ctrl+B" as the shortcut for "Toggle Bookmark" + - fix: Fail to evaluate expressions if macro can't be expanded. Red Panda C++ Version 2.26 - enhancement: Code suggestion for embedded std::vectors. diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index 296f44f2..887f2844 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -5507,8 +5507,9 @@ bool CppParser::expandMacro(QStringList &phraseExpression, int pos, PStatement m phraseExpression.removeAt(pos); usedMacros.removeAt(pos); } else { - if (pos+1 >= phraseExpression.length() || phraseExpression[pos+1]!=")") - return false; + //don't expand + if (pos+1 >= phraseExpression.length() || phraseExpression[pos+1]!="(") + return true; QString args=macro->args.mid(1,macro->args.length()-2).trimmed(); // remove '(' ')' if(args=="") diff --git a/RedPandaIDE/widgets/codecompletionpopup.cpp b/RedPandaIDE/widgets/codecompletionpopup.cpp index e192b03f..87ac8dc5 100644 --- a/RedPandaIDE/widgets/codecompletionpopup.cpp +++ b/RedPandaIDE/widgets/codecompletionpopup.cpp @@ -761,17 +761,11 @@ void CodeCompletionPopup::getCompletionFor( PStatement scope = mCurrentScope;//the scope the expression in PStatement parentTypeStatement; -// QString scopeName = ownerExpression.join(""); -// PStatement ownerStatement = mParser->findStatementOf( -// fileName, -// scopeName, -// mCurrentStatement, -// parentTypeStatement); PEvalStatement ownerStatement = mParser->evalExpression(fileName, ownerExpression, scope); - if(!ownerStatement || !ownerStatement->effectiveTypeStatement) { + if(!ownerStatement || !ownerStatement->effectiveTypeStatement) { return; } if (memberOperator == "::") {