diff --git a/NEWS.md b/NEWS.md index 0c872a63..c73ac568 100644 --- a/NEWS.md +++ b/NEWS.md @@ -110,6 +110,7 @@ Red Panda C++ Version 2.27 - Change: Change background color for highlighted buttons in the default theme. - enhancement: Make colors in code suggestion popup consistent with the editor. - enhancement: Make colors in header suggestion popup consistent with the editor. + - fix: C++ source after ';' are treated as comments in cpu info window. Red Panda C++ Version 2.26 - enhancement: Code suggestion for embedded std::vectors. diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index f0c5031e..183d9446 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -2093,10 +2093,7 @@ void Editor::onTooltipTimer() } } if (reason == TipType::Number) { - if ((syntaxer()->language() != QSynedit::ProgrammingLanguage::Assembly - && syntaxer()->language() != QSynedit::ProgrammingLanguage::ATTAssembly - ) - ) { + if (!QSynedit::isAssemblyLanguage(syntaxer()->language())) { reason=TipType::None; } } @@ -2130,9 +2127,7 @@ void Editor::onTooltipTimer() } break; case TipType::Keyword: - if ((syntaxer()->language() == QSynedit::ProgrammingLanguage::Assembly - || syntaxer()->language() == QSynedit::ProgrammingLanguage::ATTAssembly) - ) { + if (QSynedit::isAssemblyLanguage(syntaxer()->language())) { if (!mCompletionPopup->isVisible() && !mHeaderCompletionPopup->isVisible()) { s = wordAtRowCol(p); @@ -2200,9 +2195,7 @@ void Editor::onTooltipTimer() } break; case TipType::Number: - if ((syntaxer()->language() == QSynedit::ProgrammingLanguage::Assembly - || syntaxer()->language() == QSynedit::ProgrammingLanguage::ATTAssembly) - ) { + if (QSynedit::isAssemblyLanguage(syntaxer()->language())) { bool neg=false; qlonglong val; bool ok; @@ -2226,9 +2219,7 @@ void Editor::onTooltipTimer() break; case TipType::Keyword: if (pSettings->editor().enableIdentifierToolTips()) { - if ((syntaxer()->language() == QSynedit::ProgrammingLanguage::Assembly - || syntaxer()->language() == QSynedit::ProgrammingLanguage::ATTAssembly) - ) { + if (QSynedit::isAssemblyLanguage(syntaxer()->language())) { hint = QSynedit::ASMSyntaxer::Instructions.value(s.toLower(),""); } } diff --git a/RedPandaIDE/syntaxermanager.cpp b/RedPandaIDE/syntaxermanager.cpp index f8553908..c85a19c4 100644 --- a/RedPandaIDE/syntaxermanager.cpp +++ b/RedPandaIDE/syntaxermanager.cpp @@ -43,6 +43,10 @@ QSynedit::PSyntaxer SyntaxerManager::getSyntaxer(QSynedit::ProgrammingLanguage l return std::make_shared(); case QSynedit::ProgrammingLanguage::ATTAssembly: return std::make_shared(true); + case QSynedit::ProgrammingLanguage::MixedAssembly: + return std::make_shared(false, true); + case QSynedit::ProgrammingLanguage::MixedATTAssembly: + return std::make_shared(true, true); case QSynedit::ProgrammingLanguage::Makefile: return std::make_shared(); case QSynedit::ProgrammingLanguage::GLSL: diff --git a/RedPandaIDE/widgets/cpudialog.cpp b/RedPandaIDE/widgets/cpudialog.cpp index b397646e..bbe2568c 100644 --- a/RedPandaIDE/widgets/cpudialog.cpp +++ b/RedPandaIDE/widgets/cpudialog.cpp @@ -33,7 +33,7 @@ CPUDialog::CPUDialog(QWidget *parent) : setWindowFlags(windowFlags() | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint); setWindowFlag(Qt::WindowContextHelpButtonHint,false); ui->setupUi(this); - ui->txtCode->setSyntaxer(syntaxerManager.getSyntaxer(QSynedit::ProgrammingLanguage::Assembly)); + updateSyntaxer(); ui->txtCode->setReadOnly(true); ui->txtCode->gutter().setShowLineNumbers(false); ui->txtCode->setCaretUseTextColor(true); @@ -47,8 +47,6 @@ CPUDialog::CPUDialog(QWidget *parent) : options.setFlag(QSynedit::EditorOption::eoScrollPastEof,false); options.setFlag(QSynedit::EditorOption::eoScrollPastEol,false); ui->txtCode->setOptions(options); - syntaxerManager.applyColorScheme(ui->txtCode->syntaxer(), - pSettings->editor().colorScheme()); PColorSchemeItem item = pColorManager->getItem(pSettings->editor().colorScheme(),COLOR_SCHEME_ACTIVE_LINE); if (item) { ui->txtCode->setActiveLineColor(item->background()); @@ -132,6 +130,8 @@ void CPUDialog::setDisassembly(const QString& file, const QString& funcName,cons } } ui->txtCode->document()->setContents(lines); + ui->txtCode->reparseDocument(); + ui->txtCode->invalidate(); if (activeLine!=-1) ui->txtCode->setCaretXYCentered(QSynedit::BufferCoord{1,activeLine+1}); mSetting=false; @@ -157,6 +157,23 @@ void CPUDialog::sendSyntaxCommand() pMainWindow->debugger()->setDisassemblyLanguage(ui->rdIntel->isChecked()); } +void CPUDialog::updateSyntaxer() +{ + if (pSettings->debugger().blendMode()) { + if (pSettings->debugger().useIntelStyle()) + ui->txtCode->setSyntaxer(syntaxerManager.getSyntaxer(QSynedit::ProgrammingLanguage::MixedAssembly)); + else + ui->txtCode->setSyntaxer(syntaxerManager.getSyntaxer(QSynedit::ProgrammingLanguage::MixedATTAssembly)); + } else { + if (pSettings->debugger().useIntelStyle()) + ui->txtCode->setSyntaxer(syntaxerManager.getSyntaxer(QSynedit::ProgrammingLanguage::Assembly)); + else + ui->txtCode->setSyntaxer(syntaxerManager.getSyntaxer(QSynedit::ProgrammingLanguage::ATTAssembly)); + } + syntaxerManager.applyColorScheme(ui->txtCode->syntaxer(), + pSettings->editor().colorScheme()); +} + void CPUDialog::closeEvent(QCloseEvent *event) { pSettings->ui().setCPUDialogWidth(width()); @@ -174,6 +191,7 @@ void CPUDialog::on_rdIntel_toggled(bool) updateInfo(); pSettings->debugger().setUseIntelStyle(ui->rdIntel->isChecked()); pSettings->debugger().save(); + updateSyntaxer(); } void CPUDialog::on_rdATT_toggled(bool) @@ -181,6 +199,7 @@ void CPUDialog::on_rdATT_toggled(bool) updateInfo(); pSettings->debugger().setUseIntelStyle(ui->rdIntel->isChecked()); pSettings->debugger().save(); + updateSyntaxer(); } void CPUDialog::on_chkBlendMode_stateChanged(int) @@ -188,6 +207,7 @@ void CPUDialog::on_chkBlendMode_stateChanged(int) updateInfo(); pSettings->debugger().setBlendMode(ui->chkBlendMode->isCheckable()); pSettings->debugger().save(); + updateSyntaxer(); } void CPUDialog::on_btnStepOverInstruction_clicked() diff --git a/RedPandaIDE/widgets/cpudialog.h b/RedPandaIDE/widgets/cpudialog.h index 6e3c1d41..cb6f4419 100644 --- a/RedPandaIDE/widgets/cpudialog.h +++ b/RedPandaIDE/widgets/cpudialog.h @@ -41,6 +41,7 @@ signals: void closed(); private: void sendSyntaxCommand(); + void updateSyntaxer(); private: Ui::CPUDialog *ui; bool mInited; diff --git a/libs/qsynedit/qsynedit/qsynedit.cpp b/libs/qsynedit/qsynedit/qsynedit.cpp index 2be54273..50c3bfbf 100644 --- a/libs/qsynedit/qsynedit/qsynedit.cpp +++ b/libs/qsynedit/qsynedit/qsynedit.cpp @@ -4662,12 +4662,9 @@ void QSynEdit::setSyntaxer(const PSyntaxer &syntaxer) if (oldSyntaxer ->language() != syntaxer->language()) { recalcCharExtent(); mDocument->beginUpdate(); - auto action=finally([this]{ - mDocument->endUpdate(); - }); reparseDocument(); + mDocument->endUpdate(); } - //onSizeOrFontChanged(true); invalidate(); } diff --git a/libs/qsynedit/qsynedit/qsynedit.h b/libs/qsynedit/qsynedit/qsynedit.h index d0bb1a9d..d7476aea 100644 --- a/libs/qsynedit/qsynedit/qsynedit.h +++ b/libs/qsynedit/qsynedit/qsynedit.h @@ -387,6 +387,7 @@ public: int selCount() const; QStringList getContent(BufferCoord startPos, BufferCoord endPos, SelectionMode mode) const; + void reparseDocument(); QString lineBreak() const; @@ -538,7 +539,6 @@ private: void updateModifiedStatus(); void reparseLines(int startLine, int endLine); //void reparseLine(int line); - void reparseDocument(); void uncollapse(PCodeFoldingRange FoldRange); void collapse(PCodeFoldingRange FoldRange); diff --git a/libs/qsynedit/qsynedit/syntaxer/asm.cpp b/libs/qsynedit/qsynedit/syntaxer/asm.cpp index 65e0676d..7c537a77 100644 --- a/libs/qsynedit/qsynedit/syntaxer/asm.cpp +++ b/libs/qsynedit/qsynedit/syntaxer/asm.cpp @@ -147,8 +147,9 @@ const QSet ASMSyntaxer::ATTDirectives { ".zero",".2byte",".4byte",".8byte" }; -ASMSyntaxer::ASMSyntaxer(bool isATT): - mATT(isATT) +ASMSyntaxer::ASMSyntaxer(bool isATT, bool isCppMixed): + mATT{isATT}, + mCppMixed{isCppMixed} { initData(); mNumberAttribute = std::make_shared(SYNS_AttrNumber, TokenType::Number); @@ -1661,7 +1662,7 @@ void ASMSyntaxer::next() SlashProc(); break; case ';': - if (mATT) { + if (mATT || mCppMixed) { SymbolProc(); } else CommentProc(); diff --git a/libs/qsynedit/qsynedit/syntaxer/asm.h b/libs/qsynedit/qsynedit/syntaxer/asm.h index 3fc96701..ab0c1ce2 100644 --- a/libs/qsynedit/qsynedit/syntaxer/asm.h +++ b/libs/qsynedit/qsynedit/syntaxer/asm.h @@ -44,7 +44,7 @@ class ASMSyntaxer : public Syntaxer }; public: - explicit ASMSyntaxer(bool isATT=false); + explicit ASMSyntaxer(bool isATT=false, bool isCppMixed=false); ASMSyntaxer(const ASMSyntaxer&)=delete; ASMSyntaxer& operator=(const ASMSyntaxer&)=delete; @@ -74,6 +74,7 @@ private: PTokenAttribute mRegisterAttribute; PTokenAttribute mLabelAttribute; bool mATT; + bool mCppMixed; QSet mKeywordsCache; private: diff --git a/libs/qsynedit/qsynedit/types.cpp b/libs/qsynedit/qsynedit/types.cpp index 4a9972ab..969e5ff5 100644 --- a/libs/qsynedit/qsynedit/types.cpp +++ b/libs/qsynedit/qsynedit/types.cpp @@ -54,4 +54,12 @@ bool BufferCoord::operator!=(const BufferCoord &coord) return coord.ch != ch || coord.line != line; } +bool isAssemblyLanguage(ProgrammingLanguage lang) +{ + return lang == ProgrammingLanguage::Assembly + || lang == ProgrammingLanguage::ATTAssembly + || lang == ProgrammingLanguage::MixedAssembly + || lang == ProgrammingLanguage::MixedATTAssembly; +} + } diff --git a/libs/qsynedit/qsynedit/types.h b/libs/qsynedit/qsynedit/types.h index 5dff5fa7..c4047407 100644 --- a/libs/qsynedit/qsynedit/types.h +++ b/libs/qsynedit/qsynedit/types.h @@ -31,6 +31,8 @@ enum class ProgrammingLanguage { Composition, Assembly, ATTAssembly, + MixedAssembly, + MixedATTAssembly, CPP, GLSL, Makefile, @@ -87,6 +89,7 @@ using PEditingArea = std::shared_ptr; using EditingAreaList = QList; using PEditingAreaList = std::shared_ptr; +bool isAssemblyLanguage(ProgrammingLanguage lang); } #endif // TYPES_H