- fix: crash when source files contains macro definitions like "#define cfun (cfun + 0)"

This commit is contained in:
Roy Qu 2023-07-01 13:41:27 +08:00
parent 88b592f829
commit 58b92a6360
2 changed files with 10 additions and 2 deletions

View File

@ -19,6 +19,7 @@ Red Panda C++ Version 2.23
- enhancement: correctly highlight multiline raw string literals. - enhancement: correctly highlight multiline raw string literals.
- change: remove "Assembly" color scheme item (it's not used anymore). - change: remove "Assembly" color scheme item (it's not used anymore).
- fix: crash when parsing files containing inline assembly code. - fix: crash when parsing files containing inline assembly code.
- fix: crash when source files contains macro definitions like "#define cfun (cfun + 0)"
Red Panda C++ Version 2.22 Red Panda C++ Version 2.22

View File

@ -4904,10 +4904,10 @@ PEvalStatement CppParser::doEvalTerm(const QString &fileName,
result = doCreateEvalFunction(fileName,statement); result = doCreateEvalFunction(fileName,statement);
break; break;
case StatementKind::skPreprocessor: case StatementKind::skPreprocessor:
//qDebug()<<"before"<<phraseExpression; // qDebug()<<"before"<<phraseExpression;
pos--; pos--;
if (expandMacro(phraseExpression,pos,statement)) { if (expandMacro(phraseExpression,pos,statement)) {
//qDebug()<<"after"<<phraseExpression; // qDebug()<<"after"<<phraseExpression;
result = doEvalExpression(fileName,phraseExpression,pos,scope,previousResult,freeScoped); result = doEvalExpression(fileName,phraseExpression,pos,scope,previousResult,freeScoped);
} else } else
result = PEvalStatement(); result = PEvalStatement();
@ -5068,6 +5068,13 @@ bool CppParser::expandMacro(QStringList &phraseExpression, int &pos, const PStat
case QSynedit::TokenType::Space: case QSynedit::TokenType::Space:
case QSynedit::TokenType::Comment: case QSynedit::TokenType::Comment:
break; break;
case QSynedit::TokenType::Identifier:
if (token!=macro->command)
phraseExpression.insert(pos+i,token);
else
phraseExpression.insert(pos+i,token+"_expanded");
i++;
break;
default: default:
phraseExpression.insert(pos+i,token); phraseExpression.insert(pos+i,token);
i++; i++;