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.
- 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.

View File

@ -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(),"");
}
}

View File

@ -43,6 +43,10 @@ QSynedit::PSyntaxer SyntaxerManager::getSyntaxer(QSynedit::ProgrammingLanguage l
return std::make_shared<QSynedit::ASMSyntaxer>();
case QSynedit::ProgrammingLanguage::ATTAssembly:
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:
return std::make_shared<QSynedit::MakefileSyntaxer>();
case QSynedit::ProgrammingLanguage::GLSL:

View File

@ -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()

View File

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

View File

@ -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();
}

View File

@ -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);

View File

@ -147,8 +147,9 @@ const QSet<QString> 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<TokenAttribute>(SYNS_AttrNumber, TokenType::Number);
@ -1661,7 +1662,7 @@ void ASMSyntaxer::next()
SlashProc();
break;
case ';':
if (mATT) {
if (mATT || mCppMixed) {
SymbolProc();
} else
CommentProc();

View File

@ -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<QString> mKeywordsCache;
private:

View File

@ -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;
}
}

View File

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