fix #358 : C++ source after ';' are treated as comments in cpu info window.

This commit is contained in:
Roy Qu 2024-03-31 21:27:02 +08:00
parent 8fc621829e
commit 158945f8db
11 changed files with 52 additions and 25 deletions

View File

@ -110,6 +110,7 @@ Red Panda C++ Version 2.27
- Change: Change background color for highlighted buttons in the default theme. - 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 code suggestion popup consistent with the editor.
- enhancement: Make colors in header 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 Red Panda C++ Version 2.26
- enhancement: Code suggestion for embedded std::vectors. - enhancement: Code suggestion for embedded std::vectors.

View File

@ -2093,10 +2093,7 @@ void Editor::onTooltipTimer()
} }
} }
if (reason == TipType::Number) { if (reason == TipType::Number) {
if ((syntaxer()->language() != QSynedit::ProgrammingLanguage::Assembly if (!QSynedit::isAssemblyLanguage(syntaxer()->language())) {
&& syntaxer()->language() != QSynedit::ProgrammingLanguage::ATTAssembly
)
) {
reason=TipType::None; reason=TipType::None;
} }
} }
@ -2130,9 +2127,7 @@ void Editor::onTooltipTimer()
} }
break; break;
case TipType::Keyword: case TipType::Keyword:
if ((syntaxer()->language() == QSynedit::ProgrammingLanguage::Assembly if (QSynedit::isAssemblyLanguage(syntaxer()->language())) {
|| syntaxer()->language() == QSynedit::ProgrammingLanguage::ATTAssembly)
) {
if (!mCompletionPopup->isVisible() if (!mCompletionPopup->isVisible()
&& !mHeaderCompletionPopup->isVisible()) { && !mHeaderCompletionPopup->isVisible()) {
s = wordAtRowCol(p); s = wordAtRowCol(p);
@ -2200,9 +2195,7 @@ void Editor::onTooltipTimer()
} }
break; break;
case TipType::Number: case TipType::Number:
if ((syntaxer()->language() == QSynedit::ProgrammingLanguage::Assembly if (QSynedit::isAssemblyLanguage(syntaxer()->language())) {
|| syntaxer()->language() == QSynedit::ProgrammingLanguage::ATTAssembly)
) {
bool neg=false; bool neg=false;
qlonglong val; qlonglong val;
bool ok; bool ok;
@ -2226,9 +2219,7 @@ void Editor::onTooltipTimer()
break; break;
case TipType::Keyword: case TipType::Keyword:
if (pSettings->editor().enableIdentifierToolTips()) { if (pSettings->editor().enableIdentifierToolTips()) {
if ((syntaxer()->language() == QSynedit::ProgrammingLanguage::Assembly if (QSynedit::isAssemblyLanguage(syntaxer()->language())) {
|| syntaxer()->language() == QSynedit::ProgrammingLanguage::ATTAssembly)
) {
hint = QSynedit::ASMSyntaxer::Instructions.value(s.toLower(),""); hint = QSynedit::ASMSyntaxer::Instructions.value(s.toLower(),"");
} }
} }

View File

@ -43,6 +43,10 @@ QSynedit::PSyntaxer SyntaxerManager::getSyntaxer(QSynedit::ProgrammingLanguage l
return std::make_shared<QSynedit::ASMSyntaxer>(); return std::make_shared<QSynedit::ASMSyntaxer>();
case QSynedit::ProgrammingLanguage::ATTAssembly: case QSynedit::ProgrammingLanguage::ATTAssembly:
return std::make_shared<QSynedit::ASMSyntaxer>(true); return std::make_shared<QSynedit::ASMSyntaxer>(true);
case QSynedit::ProgrammingLanguage::MixedAssembly:
return std::make_shared<QSynedit::ASMSyntaxer>(false, true);
case QSynedit::ProgrammingLanguage::MixedATTAssembly:
return std::make_shared<QSynedit::ASMSyntaxer>(true, true);
case QSynedit::ProgrammingLanguage::Makefile: case QSynedit::ProgrammingLanguage::Makefile:
return std::make_shared<QSynedit::MakefileSyntaxer>(); return std::make_shared<QSynedit::MakefileSyntaxer>();
case QSynedit::ProgrammingLanguage::GLSL: case QSynedit::ProgrammingLanguage::GLSL:

View File

@ -33,7 +33,7 @@ CPUDialog::CPUDialog(QWidget *parent) :
setWindowFlags(windowFlags() | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint); setWindowFlags(windowFlags() | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint);
setWindowFlag(Qt::WindowContextHelpButtonHint,false); setWindowFlag(Qt::WindowContextHelpButtonHint,false);
ui->setupUi(this); ui->setupUi(this);
ui->txtCode->setSyntaxer(syntaxerManager.getSyntaxer(QSynedit::ProgrammingLanguage::Assembly)); updateSyntaxer();
ui->txtCode->setReadOnly(true); ui->txtCode->setReadOnly(true);
ui->txtCode->gutter().setShowLineNumbers(false); ui->txtCode->gutter().setShowLineNumbers(false);
ui->txtCode->setCaretUseTextColor(true); ui->txtCode->setCaretUseTextColor(true);
@ -47,8 +47,6 @@ CPUDialog::CPUDialog(QWidget *parent) :
options.setFlag(QSynedit::EditorOption::eoScrollPastEof,false); options.setFlag(QSynedit::EditorOption::eoScrollPastEof,false);
options.setFlag(QSynedit::EditorOption::eoScrollPastEol,false); options.setFlag(QSynedit::EditorOption::eoScrollPastEol,false);
ui->txtCode->setOptions(options); ui->txtCode->setOptions(options);
syntaxerManager.applyColorScheme(ui->txtCode->syntaxer(),
pSettings->editor().colorScheme());
PColorSchemeItem item = pColorManager->getItem(pSettings->editor().colorScheme(),COLOR_SCHEME_ACTIVE_LINE); PColorSchemeItem item = pColorManager->getItem(pSettings->editor().colorScheme(),COLOR_SCHEME_ACTIVE_LINE);
if (item) { if (item) {
ui->txtCode->setActiveLineColor(item->background()); 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->document()->setContents(lines);
ui->txtCode->reparseDocument();
ui->txtCode->invalidate();
if (activeLine!=-1) if (activeLine!=-1)
ui->txtCode->setCaretXYCentered(QSynedit::BufferCoord{1,activeLine+1}); ui->txtCode->setCaretXYCentered(QSynedit::BufferCoord{1,activeLine+1});
mSetting=false; mSetting=false;
@ -157,6 +157,23 @@ void CPUDialog::sendSyntaxCommand()
pMainWindow->debugger()->setDisassemblyLanguage(ui->rdIntel->isChecked()); 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) void CPUDialog::closeEvent(QCloseEvent *event)
{ {
pSettings->ui().setCPUDialogWidth(width()); pSettings->ui().setCPUDialogWidth(width());
@ -174,6 +191,7 @@ void CPUDialog::on_rdIntel_toggled(bool)
updateInfo(); updateInfo();
pSettings->debugger().setUseIntelStyle(ui->rdIntel->isChecked()); pSettings->debugger().setUseIntelStyle(ui->rdIntel->isChecked());
pSettings->debugger().save(); pSettings->debugger().save();
updateSyntaxer();
} }
void CPUDialog::on_rdATT_toggled(bool) void CPUDialog::on_rdATT_toggled(bool)
@ -181,6 +199,7 @@ void CPUDialog::on_rdATT_toggled(bool)
updateInfo(); updateInfo();
pSettings->debugger().setUseIntelStyle(ui->rdIntel->isChecked()); pSettings->debugger().setUseIntelStyle(ui->rdIntel->isChecked());
pSettings->debugger().save(); pSettings->debugger().save();
updateSyntaxer();
} }
void CPUDialog::on_chkBlendMode_stateChanged(int) void CPUDialog::on_chkBlendMode_stateChanged(int)
@ -188,6 +207,7 @@ void CPUDialog::on_chkBlendMode_stateChanged(int)
updateInfo(); updateInfo();
pSettings->debugger().setBlendMode(ui->chkBlendMode->isCheckable()); pSettings->debugger().setBlendMode(ui->chkBlendMode->isCheckable());
pSettings->debugger().save(); pSettings->debugger().save();
updateSyntaxer();
} }
void CPUDialog::on_btnStepOverInstruction_clicked() void CPUDialog::on_btnStepOverInstruction_clicked()

View File

@ -41,6 +41,7 @@ signals:
void closed(); void closed();
private: private:
void sendSyntaxCommand(); void sendSyntaxCommand();
void updateSyntaxer();
private: private:
Ui::CPUDialog *ui; Ui::CPUDialog *ui;
bool mInited; bool mInited;

View File

@ -4662,12 +4662,9 @@ void QSynEdit::setSyntaxer(const PSyntaxer &syntaxer)
if (oldSyntaxer ->language() != syntaxer->language()) { if (oldSyntaxer ->language() != syntaxer->language()) {
recalcCharExtent(); recalcCharExtent();
mDocument->beginUpdate(); mDocument->beginUpdate();
auto action=finally([this]{
mDocument->endUpdate();
});
reparseDocument(); reparseDocument();
mDocument->endUpdate();
} }
//onSizeOrFontChanged(true);
invalidate(); invalidate();
} }

View File

@ -387,6 +387,7 @@ public:
int selCount() const; int selCount() const;
QStringList getContent(BufferCoord startPos, BufferCoord endPos, SelectionMode mode) const; QStringList getContent(BufferCoord startPos, BufferCoord endPos, SelectionMode mode) const;
void reparseDocument();
QString lineBreak() const; QString lineBreak() const;
@ -538,7 +539,6 @@ private:
void updateModifiedStatus(); void updateModifiedStatus();
void reparseLines(int startLine, int endLine); void reparseLines(int startLine, int endLine);
//void reparseLine(int line); //void reparseLine(int line);
void reparseDocument();
void uncollapse(PCodeFoldingRange FoldRange); void uncollapse(PCodeFoldingRange FoldRange);
void collapse(PCodeFoldingRange FoldRange); void collapse(PCodeFoldingRange FoldRange);

View File

@ -147,8 +147,9 @@ const QSet<QString> ASMSyntaxer::ATTDirectives {
".zero",".2byte",".4byte",".8byte" ".zero",".2byte",".4byte",".8byte"
}; };
ASMSyntaxer::ASMSyntaxer(bool isATT): ASMSyntaxer::ASMSyntaxer(bool isATT, bool isCppMixed):
mATT(isATT) mATT{isATT},
mCppMixed{isCppMixed}
{ {
initData(); initData();
mNumberAttribute = std::make_shared<TokenAttribute>(SYNS_AttrNumber, TokenType::Number); mNumberAttribute = std::make_shared<TokenAttribute>(SYNS_AttrNumber, TokenType::Number);
@ -1661,7 +1662,7 @@ void ASMSyntaxer::next()
SlashProc(); SlashProc();
break; break;
case ';': case ';':
if (mATT) { if (mATT || mCppMixed) {
SymbolProc(); SymbolProc();
} else } else
CommentProc(); CommentProc();

View File

@ -44,7 +44,7 @@ class ASMSyntaxer : public Syntaxer
}; };
public: public:
explicit ASMSyntaxer(bool isATT=false); explicit ASMSyntaxer(bool isATT=false, bool isCppMixed=false);
ASMSyntaxer(const ASMSyntaxer&)=delete; ASMSyntaxer(const ASMSyntaxer&)=delete;
ASMSyntaxer& operator=(const ASMSyntaxer&)=delete; ASMSyntaxer& operator=(const ASMSyntaxer&)=delete;
@ -74,6 +74,7 @@ private:
PTokenAttribute mRegisterAttribute; PTokenAttribute mRegisterAttribute;
PTokenAttribute mLabelAttribute; PTokenAttribute mLabelAttribute;
bool mATT; bool mATT;
bool mCppMixed;
QSet<QString> mKeywordsCache; QSet<QString> mKeywordsCache;
private: private:

View File

@ -54,4 +54,12 @@ bool BufferCoord::operator!=(const BufferCoord &coord)
return coord.ch != ch || coord.line != line; return coord.ch != ch || coord.line != line;
} }
bool isAssemblyLanguage(ProgrammingLanguage lang)
{
return lang == ProgrammingLanguage::Assembly
|| lang == ProgrammingLanguage::ATTAssembly
|| lang == ProgrammingLanguage::MixedAssembly
|| lang == ProgrammingLanguage::MixedATTAssembly;
}
} }

View File

@ -31,6 +31,8 @@ enum class ProgrammingLanguage {
Composition, Composition,
Assembly, Assembly,
ATTAssembly, ATTAssembly,
MixedAssembly,
MixedATTAssembly,
CPP, CPP,
GLSL, GLSL,
Makefile, Makefile,
@ -87,6 +89,7 @@ using PEditingArea = std::shared_ptr<EditingArea>;
using EditingAreaList = QList<PEditingArea>; using EditingAreaList = QList<PEditingArea>;
using PEditingAreaList = std::shared_ptr<EditingAreaList>; using PEditingAreaList = std::shared_ptr<EditingAreaList>;
bool isAssemblyLanguage(ProgrammingLanguage lang);
} }
#endif // TYPES_H #endif // TYPES_H