diff --git a/.github/workflows/clang-format-check.yml b/.github/workflows/clang-format-check.yml index 6b815cf..b657d00 100644 --- a/.github/workflows/clang-format-check.yml +++ b/.github/workflows/clang-format-check.yml @@ -10,5 +10,5 @@ jobs: uses: jidicula/clang-format-action@v4.14.0 with: clang-format-version: '19' - exclude-regex: '(qt-template|mkinstaller)' + exclude-regex: '(qt-template|mkinstaller|grammar)' fallback-style: 'LLVM' # optional diff --git a/.gitignore b/.gitignore index ab0726c..98ded05 100644 --- a/.gitignore +++ b/.gitignore @@ -78,3 +78,8 @@ CMakeLists.txt.user* #VSCode .vscode/ + +# antlr 4 caches +*.interp +*.tokens +.antlr/ diff --git a/.gitmodules b/.gitmodules index 964fd08..d7f5a76 100644 --- a/.gitmodules +++ b/.gitmodules @@ -17,3 +17,6 @@ [submodule "WingPlugin"] path = WingPlugin url = git@github.com:Wing-summer/WingHexExplorer2-SDK.git +[submodule "3rdparty/antlr4-cpp"] + path = 3rdparty/antlr4-cpp + url = git@github.com:Wing-summer/antlr4-cpp.git diff --git a/3rdparty/QConsoleWidget/QConsoleIODevice.cpp b/3rdparty/QConsoleWidget/QConsoleIODevice.cpp index 8afd39a..4a50a28 100644 --- a/3rdparty/QConsoleWidget/QConsoleIODevice.cpp +++ b/3rdparty/QConsoleWidget/QConsoleIODevice.cpp @@ -62,7 +62,7 @@ qint64 QConsoleIODevice::writeData(const char *data, qint64 len) { writtenSinceLastEmit_ += len; if (!signalsBlocked()) { - emit bytesWritten(writtenSinceLastEmit_); + Q_EMIT bytesWritten(writtenSinceLastEmit_); writtenSinceLastEmit_ = 0; } return len; @@ -82,7 +82,7 @@ void QConsoleIODevice::consoleWidgetInput(const QString &in) { readSinceLastEmit_ += sz; if (!signalsBlocked()) { - emit readyRead(); + Q_EMIT readyRead(); readyReadEmmited_ = true; readSinceLastEmit_ = 0; } diff --git a/3rdparty/QConsoleWidget/QConsoleWidget.cpp b/3rdparty/QConsoleWidget/QConsoleWidget.cpp index 50e6be5..2ae2337 100644 --- a/3rdparty/QConsoleWidget/QConsoleWidget.cpp +++ b/3rdparty/QConsoleWidget/QConsoleWidget.cpp @@ -138,7 +138,7 @@ void QConsoleWidget::handleReturnKey() { if (iodevice_->isOpen()) iodevice_->consoleWidgetInput(code); - emit consoleCommand(code); + Q_EMIT consoleCommand(code); } void QConsoleWidget::handleTabKey() { @@ -167,7 +167,7 @@ void QConsoleWidget::keyPressEvent(QKeyEvent *e) { if (e->modifiers() & Qt::ControlModifier) { if (e->key() == Qt::Key_Q) // Ctrl-Q aborts { - emit abortEvaluation(); + Q_EMIT abortEvaluation(); e->accept(); return; } diff --git a/3rdparty/QHexView/document/qhexcursor.cpp b/3rdparty/QHexView/document/qhexcursor.cpp index de5a86d..aed3e7c 100644 --- a/3rdparty/QHexView/document/qhexcursor.cpp +++ b/3rdparty/QHexView/document/qhexcursor.cpp @@ -129,7 +129,7 @@ bool QHexCursor::hasInternalSelection() const { return !m_sels.isEmpty(); } void QHexCursor::clearPreviewSelection() { m_selection = m_position; m_preMode = SelectionNormal; - emit selectionChanged(); + Q_EMIT selectionChanged(); } void QHexCursor::clearSelection() { m_sels.clear(); } @@ -155,10 +155,10 @@ void QHexCursor::moveTo(qsizetype line, int column, int nibbleindex, } if (clearSelection) { - emit selectionChanged(); + Q_EMIT selectionChanged(); } - emit positionChanged(); + Q_EMIT positionChanged(); } void QHexCursor::select(qsizetype line, int column, SelectionModes modes) { @@ -197,7 +197,7 @@ void QHexCursor::select(qsizetype line, int column, SelectionModes modes) { } } - emit selectionChanged(); + Q_EMIT selectionChanged(); } void QHexCursor::moveTo(qsizetype offset, bool clearSelection) { @@ -223,7 +223,7 @@ void QHexCursor::setInsertionMode(QHexCursor::InsertionMode mode) { m_insertionmode = mode; if (differentmode) - emit insertionModeChanged(); + Q_EMIT insertionModeChanged(); } void QHexCursor::setLineWidth(quint8 width) { @@ -243,7 +243,7 @@ void QHexCursor::switchInsertionMode() { else m_insertionmode = QHexCursor::OverwriteMode; - emit insertionModeChanged(); + Q_EMIT insertionModeChanged(); } bool QHexCursor::hasPreviewSelection() const { @@ -299,5 +299,5 @@ void QHexCursor::mergePreviewSelection() { } clearPreviewSelection(); - emit selectionChanged(); + Q_EMIT selectionChanged(); } diff --git a/3rdparty/QHexView/document/qhexdocument.cpp b/3rdparty/QHexView/document/qhexdocument.cpp index 59e2773..9c99172 100644 --- a/3rdparty/QHexView/document/qhexdocument.cpp +++ b/3rdparty/QHexView/document/qhexdocument.cpp @@ -71,20 +71,20 @@ void QHexDocument::addUndoCommand(QUndoCommand *command) { void QHexDocument::setMetabgVisible(bool b) { m_metabg = b; - emit documentChanged(); - emit metabgVisibleChanged(b); + Q_EMIT documentChanged(); + Q_EMIT metabgVisibleChanged(b); } void QHexDocument::setMetafgVisible(bool b) { m_metafg = b; - emit documentChanged(); - emit metafgVisibleChanged(b); + Q_EMIT documentChanged(); + Q_EMIT metafgVisibleChanged(b); } void QHexDocument::setMetaCommentVisible(bool b) { m_metacomment = b; - emit documentChanged(); - emit metaCommentVisibleChanged(b); + Q_EMIT documentChanged(); + Q_EMIT metaCommentVisibleChanged(b); } bool QHexDocument::metabgVisible() { return m_metabg; } @@ -227,7 +227,7 @@ void QHexDocument::setDocSaved(bool b) { if (b) { m_undostack->setClean(); } - emit documentSaved(b); + Q_EMIT documentSaved(b); } bool QHexDocument::isReadOnly() { return m_readonly; } @@ -242,7 +242,7 @@ bool QHexDocument::setLockedFile(bool b) { if (m_readonly) return false; m_islocked = b; - emit documentLockedFile(b); + Q_EMIT documentLockedFile(b); return true; } bool QHexDocument::setKeepSize(bool b) { @@ -250,7 +250,7 @@ bool QHexDocument::setKeepSize(bool b) { return false; m_keepsize = b; - emit documentKeepSize(b); + Q_EMIT documentKeepSize(b); return true; } @@ -326,8 +326,8 @@ bool QHexDocument::addBookMark(qsizetype pos, QString comment) { if (!existBookMark(pos)) { _bookmarks.insert(pos, comment); setDocSaved(false); - emit documentChanged(); - emit bookMarkChanged(); + Q_EMIT documentChanged(); + Q_EMIT bookMarkChanged(); return true; } return false; @@ -365,7 +365,7 @@ bool QHexDocument::RemoveBookMarks(const QList &pos) { m_undostack->push(new BookMarkRemoveCommand(this, p, bookMark(p))); } m_undostack->endMacro(); - emit documentChanged(); + Q_EMIT documentChanged(); return true; } @@ -395,8 +395,8 @@ bool QHexDocument::clearBookMark() { if (m_keepsize) { _bookmarks.clear(); setDocSaved(false); - emit documentChanged(); - emit bookMarkChanged(); + Q_EMIT documentChanged(); + Q_EMIT bookMarkChanged(); return true; } return false; @@ -411,7 +411,7 @@ qsizetype QHexDocument::bookMarksCount() const { return _bookmarks.count(); } void QHexDocument::applyBookMarks(const QMap &books) { _bookmarks = books; setDocSaved(false); - emit documentChanged(); + Q_EMIT documentChanged(); } void QHexDocument::findAllBytes(qsizetype begin, qsizetype end, @@ -502,7 +502,7 @@ bool QHexDocument::_insert(qsizetype offset, uchar b) { bool QHexDocument::_insert(qsizetype offset, const QByteArray &data) { m_buffer->insert(offset, data); setDocSaved(false); - emit documentChanged(); + Q_EMIT documentChanged(); return true; } @@ -513,14 +513,14 @@ bool QHexDocument::_replace(qsizetype offset, uchar b) { bool QHexDocument::_replace(qsizetype offset, const QByteArray &data) { m_buffer->replace(offset, data); setDocSaved(false); - emit documentChanged(); + Q_EMIT documentChanged(); return true; } bool QHexDocument::_remove(qsizetype offset, qsizetype len) { m_buffer->remove(offset, len); setDocSaved(false); - emit documentChanged(); + Q_EMIT documentChanged(); return true; } @@ -636,7 +636,7 @@ QHexDocument::QHexDocument(QHexBuffer *buffer, bool readonly) connect(m_metadata, &QHexMetadata::metadataChanged, this, [this] { setDocSaved(false); - emit metaDataChanged(); + Q_EMIT metaDataChanged(); }); /*=======================*/ @@ -665,7 +665,7 @@ int QHexDocument::hexLineWidth() const { return m_hexlinewidth; } void QHexDocument::setHexLineWidth(quint8 value) { m_hexlinewidth = value; m_metadata->setLineWidth(value); - emit hexLineWidthChanged(); + Q_EMIT hexLineWidthChanged(); } QHexMetadata *QHexDocument::metadata() const { return m_metadata; } @@ -683,19 +683,19 @@ void QHexDocument::setBaseAddress(quint64 baseaddress) { return; m_baseaddress = baseaddress; - emit documentChanged(); + Q_EMIT documentChanged(); } -void QHexDocument::sync() { emit documentChanged(); } +void QHexDocument::sync() { Q_EMIT documentChanged(); } void QHexDocument::undo() { m_undostack->undo(); - emit documentChanged(); + Q_EMIT documentChanged(); } void QHexDocument::redo() { m_undostack->redo(); - emit documentChanged(); + Q_EMIT documentChanged(); } void QHexDocument::beginMarco(const QString &text) { @@ -727,7 +727,7 @@ bool QHexDocument::Insert(QHexCursor *cursor, qsizetype offset, return false; } - emit documentChanged(); + Q_EMIT documentChanged(); return true; } @@ -743,7 +743,7 @@ void QHexDocument::Append(QHexCursor *cursor, const QByteArray &data, if (cmd) { m_undostack->push(cmd); } - emit documentChanged(); + Q_EMIT documentChanged(); } bool QHexDocument::Replace(QHexCursor *cursor, qsizetype offset, @@ -757,7 +757,7 @@ bool QHexDocument::Replace(QHexCursor *cursor, qsizetype offset, } else { return false; } - emit documentChanged(); + Q_EMIT documentChanged(); return true; } @@ -769,7 +769,7 @@ bool QHexDocument::Remove(QHexCursor *cursor, qsizetype offset, qsizetype len, if (cmd) { m_undostack->push(cmd); } - emit documentChanged(); + Q_EMIT documentChanged(); return true; } diff --git a/3rdparty/QHexView/document/qhexmetadata.cpp b/3rdparty/QHexView/document/qhexmetadata.cpp index 412d094..4ff4bfa 100644 --- a/3rdparty/QHexView/document/qhexmetadata.cpp +++ b/3rdparty/QHexView/document/qhexmetadata.cpp @@ -196,7 +196,7 @@ bool QHexMetadata::removeLineMetadata(const QHexMetadataItem &item) { &item) { return item.second.isEmpty(); }); #endif - emit metadataChanged(); + Q_EMIT metadataChanged(); return true; } @@ -218,7 +218,7 @@ void QHexMetadata::removeMetadata(qsizetype offset) { m_metadata.removeIf(rmfn); #endif - emit metadataChanged(); + Q_EMIT metadataChanged(); } QVector QHexMetadata::getAllMetadata() const { @@ -279,7 +279,7 @@ void QHexMetadata::applyMetas(const QVector &metas) { for (auto &meta : m_metadata) { addMetaLines(meta); } - emit metadataChanged(); + Q_EMIT metadataChanged(); } bool QHexMetadata::hasMetadata() { return m_metadata.count() > 0; } @@ -320,7 +320,7 @@ void QHexMetadata::endMarco() { m_undo->endMacro(); } void QHexMetadata::clear() { m_linemeta.clear(); m_metadata.clear(); - emit metadataChanged(); + Q_EMIT metadataChanged(); } bool QHexMetadata::metadata(qsizetype begin, qsizetype end, @@ -329,7 +329,7 @@ bool QHexMetadata::metadata(qsizetype begin, qsizetype end, if (checkValidMetadata(begin, end, fgcolor, bgcolor, comment)) { QHexMetadataItem absi(begin, end, fgcolor, bgcolor, comment); addMetadata(absi); - emit metadataChanged(); + Q_EMIT metadataChanged(); return true; } return false; @@ -344,7 +344,7 @@ void QHexMetadata::setLineWidth(quint8 width) { addMetadata(item); } - emit metadataChanged(); + Q_EMIT metadataChanged(); } } @@ -368,7 +368,7 @@ void QHexMetadata::insertAdjust(qsizetype offset, qsizetype length) { addMetaLines(meta); } - emit metadataChanged(); + Q_EMIT metadataChanged(); } void QHexMetadata::insertAdjustRevert(qsizetype offset, qsizetype length) { @@ -391,7 +391,7 @@ void QHexMetadata::insertAdjustRevert(qsizetype offset, qsizetype length) { addMetaLines(meta); } - emit metadataChanged(); + Q_EMIT metadataChanged(); } QVector QHexMetadata::removeAdjust(qsizetype offset, @@ -435,7 +435,7 @@ QVector QHexMetadata::removeAdjust(qsizetype offset, addMetaLines(meta); } - emit metadataChanged(); + Q_EMIT metadataChanged(); QtConcurrent::blockingMap( rmmetas, [](QHexMetadataItem &meta) { meta.flag = false; }); @@ -473,7 +473,7 @@ void QHexMetadata::removeAdjustRevert(const QVector &metas, addMetaLines(meta); } - emit metadataChanged(); + Q_EMIT metadataChanged(); } bool QHexMetadata::areColorsContrast(const QColor &color1, diff --git a/3rdparty/QHexView/document/qhexrenderer.cpp b/3rdparty/QHexView/document/qhexrenderer.cpp index acfc1a9..0731270 100644 --- a/3rdparty/QHexView/document/qhexrenderer.cpp +++ b/3rdparty/QHexView/document/qhexrenderer.cpp @@ -44,21 +44,21 @@ bool QHexRenderer::stringVisible() { return m_asciiVisible; } void QHexRenderer::setStringVisible(bool b) { m_asciiVisible = b; - emit m_document->documentChanged(); + Q_EMIT m_document->documentChanged(); } bool QHexRenderer::headerVisible() { return m_headerVisible; } void QHexRenderer::setHeaderVisible(bool b) { m_headerVisible = b; - emit m_document->documentChanged(); + Q_EMIT m_document->documentChanged(); } bool QHexRenderer::addressVisible() { return m_addressVisible; } void QHexRenderer::setAddressVisible(bool b) { m_addressVisible = b; - emit m_document->documentChanged(); + Q_EMIT m_document->documentChanged(); } void QHexRenderer::switchDoc(QHexDocument *doc) { diff --git a/3rdparty/QHexView/qhexview.cpp b/3rdparty/QHexView/qhexview.cpp index a8cdd58..2c58a96 100644 --- a/3rdparty/QHexView/qhexview.cpp +++ b/3rdparty/QHexView/qhexview.cpp @@ -116,15 +116,15 @@ QFont QHexView::getHexeditorFont() { } void QHexView::getStatus() { - emit canUndoChanged(m_document->canUndo()); - emit canRedoChanged(m_document->canRedo()); - emit cursorLocationChanged(); - emit documentSaved(m_document->isDocSaved()); - emit documentKeepSize(m_document->isKeepSize()); - emit documentLockedFile(m_document->isLocked()); - emit metafgVisibleChanged(m_document->metafgVisible()); - emit metabgVisibleChanged(m_document->metabgVisible()); - emit metaCommentVisibleChanged(m_document->metaCommentVisible()); + Q_EMIT canUndoChanged(m_document->canUndo()); + Q_EMIT canRedoChanged(m_document->canRedo()); + Q_EMIT cursorLocationChanged(); + Q_EMIT documentSaved(m_document->isDocSaved()); + Q_EMIT documentKeepSize(m_document->isKeepSize()); + Q_EMIT documentLockedFile(m_document->isLocked()); + Q_EMIT metafgVisibleChanged(m_document->metafgVisible()); + Q_EMIT metabgVisibleChanged(m_document->metabgVisible()); + Q_EMIT metaCommentVisibleChanged(m_document->metaCommentVisible()); } void QHexView::establishSignal(QHexDocument *doc) { @@ -139,16 +139,16 @@ void QHexView::establishSignal(QHexDocument *doc) { &QHexView::canRedoChanged); connect(doc, &QHexDocument::documentSaved, this, &QHexView::documentSaved); connect(doc, &QHexDocument::metabgVisibleChanged, this, [=](bool b) { - emit metabgVisibleChanged(b); - emit metaStatusChanged(); + Q_EMIT metabgVisibleChanged(b); + Q_EMIT metaStatusChanged(); }); connect(doc, &QHexDocument::metafgVisibleChanged, this, [=](bool b) { - emit metafgVisibleChanged(b); - emit metaStatusChanged(); + Q_EMIT metafgVisibleChanged(b); + Q_EMIT metaStatusChanged(); }); connect(doc, &QHexDocument::metaCommentVisibleChanged, this, [=](bool b) { - emit metaCommentVisibleChanged(b); - emit metaStatusChanged(); + Q_EMIT metaCommentVisibleChanged(b); + Q_EMIT metaStatusChanged(); }); connect(doc, &QHexDocument::metaDataChanged, this, [=] { this->viewport()->update(); }); @@ -234,12 +234,12 @@ void QHexView::setDocument(const QSharedPointer &document, &QHexView::moveToSelection); connect(m_cursor, &QHexCursor::selectionChanged, this, [this]() { this->viewport()->update(); - emit cursorSelectionChanged(); + Q_EMIT cursorSelectionChanged(); }); connect(m_cursor, &QHexCursor::insertionModeChanged, this, &QHexView::renderCurrentLine); - emit documentChanged(document.data()); + Q_EMIT documentChanged(document.data()); this->adjustScrollBars(); this->viewport()->update(); @@ -462,7 +462,7 @@ bool QHexView::Cut(bool hex, int nibbleindex) { if (res) { return this->RemoveSelection(nibbleindex); } else { - emit copyLimitRaised(); + Q_EMIT copyLimitRaised(); return res; } } @@ -517,7 +517,7 @@ bool QHexView::cut(bool hex) { if (res) { return this->removeSelection(); } else { - emit copyLimitRaised(); + Q_EMIT copyLimitRaised(); return res; } } @@ -532,7 +532,7 @@ bool QHexView::copy(bool hex) { // 如果拷贝字节超过 ? MB 阻止 if (len > 1024 * 1024 * m_copylimit) { - emit copyLimitRaised(); + Q_EMIT copyLimitRaised(); return false; } @@ -558,7 +558,7 @@ void QHexView::setScaleRate(qreal rate) { if (rate >= 0.2 && rate < 3.01) { m_scaleRate = rate; setFontSize(fontSize()); - emit scaleRateChanged(); + Q_EMIT scaleRateChanged(); update(); } } @@ -569,7 +569,7 @@ QColor QHexView::selBackgroundColor() const { void QHexView::setSelBackgroundColor(const QColor &newSelBackgroundColor) { m_renderer->setSelBackgroundColor(newSelBackgroundColor); - emit selBackgroundColorChanged(); + Q_EMIT selBackgroundColorChanged(); } void QHexView::setFontSize(qreal size) { @@ -583,7 +583,7 @@ QColor QHexView::selectionColor() const { return m_renderer->selectionColor(); } void QHexView::setSelectionColor(const QColor &newSelectionColor) { m_renderer->setSelectionColor(newSelectionColor); - emit selectionColorChanged(); + Q_EMIT selectionColorChanged(); } QColor QHexView::bytesAlterBackground() const { @@ -592,14 +592,14 @@ QColor QHexView::bytesAlterBackground() const { void QHexView::setBytesAlterBackground(const QColor &newBytesAlterBackground) { m_renderer->setBytesAlterBackground(newBytesAlterBackground); - emit bytesAlterBackgroundChanged(); + Q_EMIT bytesAlterBackgroundChanged(); } QColor QHexView::bytesColor() const { return m_renderer->bytesColor(); } void QHexView::setBytesColor(const QColor &newBytesColor) { m_renderer->setBytesColor(newBytesColor); - emit bytesColorChanged(); + Q_EMIT bytesColorChanged(); } QColor QHexView::bytesBackground() const { @@ -608,21 +608,21 @@ QColor QHexView::bytesBackground() const { void QHexView::setBytesBackground(const QColor &newBytesBackground) { m_renderer->setBytesBackground(newBytesBackground); - emit bytesBackgroundChanged(); + Q_EMIT bytesBackgroundChanged(); } QColor QHexView::addressColor() const { return m_renderer->addressColor(); } void QHexView::setAddressColor(const QColor &newAddressColor) { m_renderer->setAddressColor(newAddressColor); - emit addressColorChanged(); + Q_EMIT addressColorChanged(); } QColor QHexView::headerColor() const { return m_renderer->headerColor(); } void QHexView::setHeaderColor(const QColor &newHeaderColor) { m_renderer->setHeaderColor(newHeaderColor); - emit headerColorChanged(); + Q_EMIT headerColorChanged(); } void QHexView::mousePressEvent(QMouseEvent *e) { @@ -794,7 +794,7 @@ void QHexView::moveToSelection() { } else this->viewport()->update(); - emit cursorLocationChanged(); // added by wingsummer + Q_EMIT cursorLocationChanged(); // added by wingsummer } void QHexView::blinkCursor() { diff --git a/3rdparty/QWingRibbon/ribbon.cpp b/3rdparty/QWingRibbon/ribbon.cpp index 87f8772..44d147d 100644 --- a/3rdparty/QWingRibbon/ribbon.cpp +++ b/3rdparty/QWingRibbon/ribbon.cpp @@ -131,7 +131,7 @@ void Ribbon::dropEvent(QDropEvent *event) { pathList.append(urlList.at(i).toLocalFile()); } - emit onDragDropFiles(pathList); + Q_EMIT onDragDropFiles(pathList); event->acceptProposedAction(); } } diff --git a/3rdparty/QWingRibbon/ribbonbuttongroup.cpp b/3rdparty/QWingRibbon/ribbonbuttongroup.cpp index 06a6e25..6015751 100644 --- a/3rdparty/QWingRibbon/ribbonbuttongroup.cpp +++ b/3rdparty/QWingRibbon/ribbonbuttongroup.cpp @@ -64,7 +64,7 @@ void RibbonButtonGroup::addButton(QToolButton *button) { ui->horizontalLayout->addWidget(button); if (_buttons.size() == 1) { - emit emptyStatusChanged(false); + Q_EMIT emptyStatusChanged(false); } } @@ -73,7 +73,7 @@ void RibbonButtonGroup::removeButton(QToolButton *button) { ui->horizontalLayout->removeWidget(button); _buttons.removeOne(button); if (_buttons.empty()) { - emit emptyStatusChanged(true); + Q_EMIT emptyStatusChanged(true); } } } diff --git a/3rdparty/antlr4-cpp b/3rdparty/antlr4-cpp new file mode 160000 index 0000000..b8fc7ca --- /dev/null +++ b/3rdparty/antlr4-cpp @@ -0,0 +1 @@ +Subproject commit b8fc7ca25fc0781ba444b02f2ab203042c0c3f0a diff --git a/3rdparty/qtsingleapplication/src/qtlocalpeer.cpp b/3rdparty/qtsingleapplication/src/qtlocalpeer.cpp index a41813f..f37f59f 100644 --- a/3rdparty/qtsingleapplication/src/qtlocalpeer.cpp +++ b/3rdparty/qtsingleapplication/src/qtlocalpeer.cpp @@ -168,5 +168,5 @@ void QtLocalPeer::receiveConnection() { socket->waitForBytesWritten(1000); socket->waitForDisconnected(1000); // make sure client reads ack delete socket; - emit messageReceived(uMsg); // ### (might take a long time to return) + Q_EMIT messageReceived(uMsg); // ### (might take a long time to return) } diff --git a/CMakeLists.txt b/CMakeLists.txt index 8525c61..53476eb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,16 +46,13 @@ if(WIN32) add_definitions(-DNOMINMAX) endif() -if(${QT_VERSION_MAJOR} EQUAL 5) - if(Qt5Widgets_VERSION VERSION_LESS 5.14.0) - message(FATAL_ERROR "Minimum supported Qt5 version is 5.14!") - endif() -elseif(${QT_VERSION_MAJOR} EQUAL 6) +if(${QT_VERSION_MAJOR} EQUAL 6) if(Qt6Widgets_VERSION VERSION_LESS 6.6.2) message(FATAL_ERROR "Minimum supported Qt6 version is 6.6.2!") endif() else() - message(FATAL_ERROR "Unsupported Qt version!") + message( + FATAL_ERROR "Qt${QT_VERSION_MAJOR} has been dropped and not supported!") endif() if(MSVC) @@ -81,6 +78,26 @@ add_subdirectory(3rdparty/WingCodeEdit) add_subdirectory(3rdparty/Qt-Advanced-Docking-System) add_subdirectory(3rdparty/AngelScript/sdk/angelscript/projects/cmake) +set(DISABLE_WARNINGS ON) +set(ANTLR4_INSTALL OFF) +set(ANTLR_BUILD_CPP_TESTS OFF) +set(ANTLR_BUILD_SHARED OFF) +set(ANTLR_BUILD_STATIC ON) +set(WITH_STATIC_CRT OFF) +add_subdirectory(3rdparty/antlr4-cpp) + +set(NUMCAL_GRAMMAR + src/grammar/NumCal/NumCalBaseVisitor.cpp + src/grammar/NumCal/NumCalBaseVisitor.h + src/grammar/NumCal/NumCalLexer.cpp + src/grammar/NumCal/NumCalLexer.h + src/grammar/NumCal/NumCalParser.cpp + src/grammar/NumCal/NumCalParser.h + src/grammar/NumCal/NumCalVisitor.cpp + src/grammar/NumCal/NumCalVisitor.h) + +set(ANTLR4_GRAMMAR ${NUMCAL_GRAMMAR}) + set(ANGEL_SCRIPT_ADDON_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/AngelScript/sdk/add_on") set(ANGEL_SCRIPT_ADDON @@ -241,8 +258,6 @@ set(CLASS_SRC src/class/asdebugger.cpp src/class/angelobjstring.h src/class/angelobjstring.cpp - src/class/scripteditortheme.h - src/class/scripteditortheme.cpp src/class/appmanager.h src/class/appmanager.cpp src/class/angelscripthelper.h @@ -380,15 +395,8 @@ set(TRANSLATION_PATH ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/QWingRibbon ${CMAKE_CURRENT_SOURCE_DIR}/src) -if(${QT_VERSION_MAJOR} EQUAL 5) - qt5_create_translation(QM_FILES ${TRANSLATION_PATH} ${TS_FILES} OPTIONS - -no-obsolete) -elseif(${QT_VERSION_MAJOR} EQUAL 6) - qt6_create_translation(QM_FILES ${TRANSLATION_PATH} ${TS_FILES} OPTIONS - -no-obsolete) -else() - message(FATAL_ERROR "Unsupported QT version") -endif() +qt_create_translation(QM_FILES ${TRANSLATION_PATH} ${TS_FILES} OPTIONS + -no-obsolete) set(LANG_SRC "${CMAKE_CURRENT_SOURCE_DIR}/lang") set(LANG_DEST "${CMAKE_CURRENT_BINARY_DIR}/.tmp/lang") @@ -453,6 +461,7 @@ set(PROJECT_SOURCES ${SCRIPT_ADDON_SRC} ${ANGEL_SCRIPT_ADDON} ${QM_FILES} + ${ANTLR4_GRAMMAR} theme/breeze.qrc resources.qrc) @@ -472,19 +481,6 @@ if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) qt_add_executable(WingHexExplorer2 MANUAL_FINALIZATION ${PROJECT_SOURCES}) endif() -else() - if(ANDROID) - message(FATAL_ERROR "Android is not supported!") - else() - if(WIN32) - set(app_icon_resource_windows - "${CMAKE_CURRENT_SOURCE_DIR}/favicon.rc") - add_executable(${CMAKE_PROJECT_NAME} ${PROJECT_SOURCES} - ${app_icon_resource_windows}) - else() - add_executable(${CMAKE_PROJECT_NAME} ${PROJECT_SOURCES}) - endif() - endif() endif() target_compile_options( @@ -510,6 +506,7 @@ target_link_libraries( QHexView WingCodeEdit angelscript + antlr4_static qtadvanceddocking-qt${QT_VERSION_MAJOR}) if(WINGHEX_USE_FRAMELESS) @@ -521,6 +518,9 @@ if(WIN32) PRIVATE Qt${QT_VERSION_MAJOR}::AxContainer) endif() +# emit marco in Qt conflicts with antlr4-cpp +target_compile_definitions(WingHexExplorer2 PRIVATE QT_NO_EMIT) + target_include_directories( ${CMAKE_PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty" "${CMAKE_CURRENT_SOURCE_DIR}/src") diff --git a/lang/zh_CN/winghex_zh_CN.ts b/lang/zh_CN/winghex_zh_CN.ts index 369206c..442dfbd 100644 --- a/lang/zh_CN/winghex_zh_CN.ts +++ b/lang/zh_CN/winghex_zh_CN.ts @@ -789,57 +789,57 @@ Logger - + [Trace] 【跟踪】 - + [Warn] 【警告】 - + [Info] 【信息】 - + [Debug] 【调试】 - + [Error] 【错误】 - + Critial 崩溃 - + Error 错误 - + Warning 警告 - + Info 信息 - + Debug 调试 - + Trace 跟踪 diff --git a/lang/zh_TW/winghex_zh_TW.ts b/lang/zh_TW/winghex_zh_TW.ts index 52cf632..c4f7d3d 100644 --- a/lang/zh_TW/winghex_zh_TW.ts +++ b/lang/zh_TW/winghex_zh_TW.ts @@ -789,57 +789,57 @@ Logger - + [Trace] 【跟蹤】 - + [Warn] 【警告】 - + [Info] 【資訊】 - + [Debug] 【調試】 - + [Error] 【錯誤】 - + Critial 崩潰 - + Error 錯誤 - + Warning 警告 - + Info 資訊 - + Debug 調試 - + Trace 跟蹤 diff --git a/src/class/angelobjstring.h b/src/class/angelobjstring.h index f604483..a285ae3 100644 --- a/src/class/angelobjstring.h +++ b/src/class/angelobjstring.h @@ -20,13 +20,10 @@ #include "class/asdebugger.h" -#include #include #include -class AngelObjString : public QObject { - Q_OBJECT - +class AngelObjString { public: static QString stringToString(void *obj, asDebugger *dbg, asUINT tag); diff --git a/src/class/ascompletion.cpp b/src/class/ascompletion.cpp index 983a4c9..72dbf57 100644 --- a/src/class/ascompletion.cpp +++ b/src/class/ascompletion.cpp @@ -60,7 +60,7 @@ AsCompletion::AsCompletion(WingCodeEdit *p) auto v = index.data(Qt::SelfDataRole).value(); if (v.type == CodeInfoTip::Type::Function || v.type == CodeInfoTip::Type::ClsFunction) { - emit onFunctionTip(v.getTooltip()); + Q_EMIT onFunctionTip(v.getTooltip()); } }); @@ -217,7 +217,7 @@ void AsCompletion::clearCompleteDBUnused() { [](const QPair &c) { return c.second.time == 0; }); } -void AsCompletion::clearFunctionTip() { emit onFunctionTip({}); } +void AsCompletion::clearFunctionTip() { Q_EMIT onFunctionTip({}); } QString AsCompletion::wordSeperators() const { static QString eow(QStringLiteral("~!@$%^&*()_+{}|\"<>?,/;'[]\\-=")); diff --git a/src/class/asdebugger.cpp b/src/class/asdebugger.cpp index 8fb203b..9bf1ddd 100644 --- a/src/class/asdebugger.cpp +++ b/src/class/asdebugger.cpp @@ -41,8 +41,8 @@ void asDebugger::registerToStringCallback(const asITypeInfo *ti, } void asDebugger::takeCommands(asIScriptContext *ctx) { - emit onPullVariables(globalVariables(ctx), localVariables(ctx)); - emit onPullCallStack(retriveCallstack(ctx)); + Q_EMIT onPullVariables(globalVariables(ctx), localVariables(ctx)); + Q_EMIT onPullCallStack(retriveCallstack(ctx)); while (m_action == DebugAction::PAUSE) { qApp->processEvents(); @@ -66,7 +66,7 @@ void asDebugger::takeCommands(asIScriptContext *ctx) { break; } - emit onDebugActionExec(); + Q_EMIT onDebugActionExec(); } void asDebugger::lineCallback(asIScriptContext *ctx) { @@ -202,7 +202,7 @@ void asDebugger::lineCallback(asIScriptContext *ctx) { rc(dbgContext, file, lineNbr, col, ctx->GetCallstackSize()); - emit onRunCurrentLine(file, lineNbr); + Q_EMIT onRunCurrentLine(file, lineNbr); takeCommands(ctx); } @@ -210,7 +210,7 @@ void asDebugger::lineCallback(asIScriptContext *ctx) { void asDebugger::addFileBreakPoint(const QString &file, int lineNbr) { BreakPoint bp(file, lineNbr, false); m_breakPoints.push_back(bp); - emit breakPointChanged(); + Q_EMIT breakPointChanged(); } void asDebugger::removeFileBreakPoint(const QString &file, int lineNbr) { @@ -222,7 +222,7 @@ void asDebugger::removeFileBreakPoint(const QString &file, int lineNbr) { return; } m_breakPoints.erase(r); - emit breakPointChanged(); + Q_EMIT breakPointChanged(); } void asDebugger::addFuncBreakPoint(const QString &func) { @@ -231,7 +231,7 @@ void asDebugger::addFuncBreakPoint(const QString &func) { BreakPoint bp(actual, 0, true); m_breakPoints.push_back(bp); - emit breakPointChanged(); + Q_EMIT breakPointChanged(); } void asDebugger::removeFuncBreakPoint(const QString &func) { @@ -240,12 +240,12 @@ void asDebugger::removeFuncBreakPoint(const QString &func) { m_breakPoints.begin(), m_breakPoints.end(), [=](const BreakPoint &bp) { return bp.name == actual && bp.func == true; })); - emit breakPointChanged(); + Q_EMIT breakPointChanged(); } void asDebugger::clearBreakPoint() { m_breakPoints.clear(); - emit breakPointChanged(); + Q_EMIT breakPointChanged(); } const QVector &asDebugger::breakPoints() { @@ -374,7 +374,7 @@ bool asDebugger::checkBreakPoint(asIScriptContext *ctx) { auto old = m_breakPoints[n]; // Move the breakpoint to the next line m_breakPoints[n].lineNbr = line; - emit onAdjustBreakPointLine(old, line); + Q_EMIT onAdjustBreakPointLine(old, line); } } } diff --git a/src/class/eventfilter.h b/src/class/eventfilter.h index daa705c..6426e1e 100644 --- a/src/class/eventfilter.h +++ b/src/class/eventfilter.h @@ -34,7 +34,7 @@ signals: protected: bool eventFilter(QObject *obj, QEvent *event) override { if (event->type() == m_event) { - emit eventTriggered(obj, event); + Q_EMIT eventTriggered(obj, event); } return QObject::eventFilter(obj, event); } diff --git a/src/class/inspectqtloghelper.cpp b/src/class/inspectqtloghelper.cpp index 283b67b..4f6d1e7 100644 --- a/src/class/inspectqtloghelper.cpp +++ b/src/class/inspectqtloghelper.cpp @@ -26,14 +26,14 @@ void InspectQtLogHelper::init() { menu->addSeparator(); auto a = new QAction(tr("Clear"), menu); - connect(a, &QAction::triggered, this, [this]() { _ctx->clear(); }); + QObject::connect(a, &QAction::triggered, qApp, [this]() { _ctx->clear(); }); menu->addAction(a); auto af = ma.at(0); af = menu->insertSeparator(af); a = new QAction(tr("TopMost"), menu); a->setCheckable(true); - connect(a, &QAction::toggled, this, [this](bool b) { + QObject::connect(a, &QAction::toggled, qApp, [this](bool b) { _logger->setWindowFlag(Qt::WindowStaysOnTopHint, b); if (!_logger->isVisible()) { _logger->setVisible(true); @@ -41,10 +41,10 @@ void InspectQtLogHelper::init() { }); menu->insertAction(af, a); - connect(_ctx, &QTextBrowser::customContextMenuRequested, this, - [menu, this](const QPoint &pos) { - menu->popup(_ctx->mapToGlobal(pos)); - }); + QObject::connect(_ctx, &QTextBrowser::customContextMenuRequested, qApp, + [menu, this](const QPoint &pos) { + menu->popup(_ctx->mapToGlobal(pos)); + }); _logger->buildUpContent(_ctx); _logger->setWindowTitle(tr("Inspect")); diff --git a/src/class/inspectqtloghelper.h b/src/class/inspectqtloghelper.h index 4f9bbed..f9d0aad 100644 --- a/src/class/inspectqtloghelper.h +++ b/src/class/inspectqtloghelper.h @@ -3,11 +3,11 @@ #include "dialog/framelessdialogbase.h" -#include +#include #include -class InspectQtLogHelper : public QObject { - Q_OBJECT +class InspectQtLogHelper { + Q_DECLARE_TR_FUNCTIONS(InspectQtLogHelper) public: static InspectQtLogHelper &instance(); diff --git a/src/class/languagemanager.cpp b/src/class/languagemanager.cpp index 8dc6f53..f92a3b1 100644 --- a/src/class/languagemanager.cpp +++ b/src/class/languagemanager.cpp @@ -105,14 +105,14 @@ LanguageManager::LanguageManager() { QLibraryInfo::location(QLibraryInfo::TranslationsPath); #endif - auto qtTranslator = new QTranslator(this); + auto qtTranslator = new QTranslator(qApp); if (qtTranslator->load(_defaultLocale, QStringLiteral("qtbase"), QStringLiteral("_"), qtPath)) { qApp->installTranslator(qtTranslator); } - qtTranslator = new QTranslator(this); + qtTranslator = new QTranslator(qApp); if (qtTranslator->load(_defaultLocale, QStringLiteral("qt"), QStringLiteral("_"), qtPath)) { @@ -122,7 +122,7 @@ LanguageManager::LanguageManager() { if (unpackTr(langPath + QStringLiteral("/") + _defaultLocale.name() + QStringLiteral("/") + QStringLiteral(LANG_PAK_NAME), _defaultLocale)) { - auto translator = new QTranslator(this); + auto translator = new QTranslator(qApp); if (translator->load( reinterpret_cast(_data.trFiles.data()), _data.trFiles.size())) { @@ -193,7 +193,7 @@ QTranslator *LanguageManager::try2LoadPluginLang(const QString &plgID) { if (!langDir.cd(plgID)) { return nullptr; } - auto translator = new QTranslator(this); + auto translator = new QTranslator(qApp); if (translator->load(_defaultLocale, plgID, QStringLiteral("_"), langDir.absolutePath())) { if (qApp->installTranslator(translator)) { diff --git a/src/class/languagemanager.h b/src/class/languagemanager.h index 374a42c..f2333a9 100644 --- a/src/class/languagemanager.h +++ b/src/class/languagemanager.h @@ -24,9 +24,7 @@ #include #include -class LanguageManager : public QObject { - Q_OBJECT - +class LanguageManager { public: struct LanguageData { QByteArray trFiles; diff --git a/src/class/logger.cpp b/src/class/logger.cpp index b5605ae..6787e2c 100644 --- a/src/class/logger.cpp +++ b/src/class/logger.cpp @@ -86,42 +86,44 @@ Logger &Logger::instance() { Logger::Level Logger::logLevel() const { return _level; } -void Logger::logPrint(const QString &message) { emit instance().log(message); } +void Logger::logPrint(const QString &message) { + Q_EMIT instance().log(message); +} void Logger::newLine() { logPrint({}); } void Logger::trace(const QString &message) { if (instance()._level >= q5TRACE) { QString str = message; - emit instance().log(packDebugStr(tr("[Trace]") + str)); + Q_EMIT instance().log(packDebugStr(tr("[Trace]") + str)); } } void Logger::warning(const QString &message) { if (instance()._level >= q2WARN) { QString str = message; - emit instance().log(packWarnStr(tr("[Warn]") + str)); + Q_EMIT instance().log(packWarnStr(tr("[Warn]") + str)); } } void Logger::info(const QString &message) { if (instance()._level >= q3INFO) { QString str = message; - emit instance().log(packInfoStr(tr("[Info]") + str)); + Q_EMIT instance().log(packInfoStr(tr("[Info]") + str)); } } void Logger::debug(const QString &message) { if (instance()._level >= q4DEBUG) { QString str = message; - emit instance().log(packDebugStr(tr("[Debug]") + str)); + Q_EMIT instance().log(packDebugStr(tr("[Debug]") + str)); } } void Logger::critical(const QString &message) { if (instance()._level >= q0FATAL) { QString str = message; - emit instance().log(packErrorStr(tr("[Error]") + str)); + Q_EMIT instance().log(packErrorStr(tr("[Error]") + str)); } } diff --git a/src/class/pluginsystem.cpp b/src/class/pluginsystem.cpp index 3e3db14..f454d32 100644 --- a/src/class/pluginsystem.cpp +++ b/src/class/pluginsystem.cpp @@ -3308,7 +3308,7 @@ void PluginSystem::loadPlugin(IWingPlugin *p, PluginInfo &meta, // dependencies had been checked - emit pluginLoading(p->pluginName()); + Q_EMIT pluginLoading(p->pluginName()); p_tr = LanguageManager::instance().try2LoadPluginLang(meta.id); diff --git a/src/class/recentfilemanager.cpp b/src/class/recentfilemanager.cpp index 0d4c606..8e20959 100644 --- a/src/class/recentfilemanager.cpp +++ b/src/class/recentfilemanager.cpp @@ -158,7 +158,7 @@ void RecentFileManager::addRecentFile(const RecentInfo &info) { hitems.move(idx, 0); } - emit triggered(f); + Q_EMIT triggered(f); } else { auto index = hitems.indexOf(send); if (index < 0) { diff --git a/src/class/scripteditortheme.cpp b/src/class/scripteditortheme.cpp deleted file mode 100644 index 5a3f0b9..0000000 --- a/src/class/scripteditortheme.cpp +++ /dev/null @@ -1,233 +0,0 @@ -/*============================================================================== -** Copyright (C) 2024-2027 WingSummer -** -** This program is free software: you can redistribute it and/or modify it under -** the terms of the GNU Affero General Public License as published by the Free -** Software Foundation, version 3. -** -** This program is distributed in the hope that it will be useful, but WITHOUT -** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -** FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more -** details. -** -** You should have received a copy of the GNU Affero General Public License -** along with this program. If not, see . -** ============================================================================= -*/ - -#include "scripteditortheme.h" - -#include -#include -#include -#include -#include - -ScriptEditorTheme::ScriptEditorTheme(QObject *parent) : QObject(parent) {} - -ScriptEditorTheme::ScriptEditorTheme(const QString &filename, QObject *parent) - : QObject(parent) { - if (!filename.isEmpty() && QFile::exists(filename)) { - loadTheme(filename); - } -} - -ScriptEditorTheme::ColorScheme -ScriptEditorTheme::colorScheme(Styles style) const { - return m_colors.value(style); -} - -void ScriptEditorTheme::setColorScheme(Styles style, - const ColorScheme &scheme) { - m_colors[style] = scheme; -} - -bool ScriptEditorTheme::loadTheme(const QString &filename) { - QFile xmlFile(filename); - if (!xmlFile.open(QIODevice::ReadOnly | QIODevice::Text)) { - return false; - } - QXmlStreamReader xmlReader(&xmlFile); - - QString name; - QString version; - QString author; - QString comment; - - auto e = QMetaEnum::fromType(); - - while (!xmlReader.atEnd() && !xmlReader.hasError()) { - QXmlStreamReader::TokenType token = xmlReader.readNext(); - - if (token == QXmlStreamReader::StartDocument) { - if (xmlReader.name() != QStringLiteral("style-scheme")) { - return false; - } - auto attr = xmlReader.attributes(); - if (readAttr(attr, QStringLiteral("name"), name)) { - readAttr(attr, QStringLiteral("version"), version); - readAttr(attr, QStringLiteral("author"), author); - readAttr(attr, QStringLiteral("comment"), comment); - } else { - return false; - } - continue; - } - - ColorScheme scheme; - QString styleAttr; - if (token == QXmlStreamReader::StartElement) { - if (xmlReader.name() == QStringLiteral("style")) { - auto attr = xmlReader.attributes(); - if (readAttr(attr, QStringLiteral("name"), styleAttr)) { - auto v = e.keyToValue(styleAttr.toUtf8()); - if (v < 0) { - continue; - } - - if (readAttr(attr, QStringLiteral("foreground"), - styleAttr)) { - QColor color(styleAttr); - if (color.isValid()) { - scheme.foreground = color; - } - } - - if (readAttr(attr, QStringLiteral("background"), - styleAttr)) { - QColor color(styleAttr); - if (color.isValid()) { - scheme.background = color; - } - } - - if (readAttr(attr, QStringLiteral("fontfamily"), - styleAttr)) { -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - if (QFontDatabase::hasFamily(styleAttr)) { -#else - if (QFontDatabase().hasFamily(styleAttr)) { -#endif - scheme.fontFamily = styleAttr; - } - } - - if (readAttr(attr, QStringLiteral("underLine"), - styleAttr)) { - scheme.underLine = - QTextCharFormat::UnderlineStyle(styleAttr.toInt()); - } - - if (readAttr(attr, QStringLiteral("bold"), styleAttr)) { - bool ok; - scheme.isBold = string2Bool(styleAttr, ok); - if (!ok) { - scheme.isBold = false; - } - } - - if (readAttr(attr, QStringLiteral("italic"), styleAttr)) { - bool ok; - scheme.isItalic = string2Bool(styleAttr, ok); - if (!ok) { - scheme.isItalic = false; - } - } - - } else { - continue; - } - } - } - } - - m_name = name; - m_version = version; - m_author = author; - m_comment = comment; - m_isValid = true; - return true; -} - -bool ScriptEditorTheme::saveTheme(const QString &filename) { - QFile xmlFile(filename); - if (!xmlFile.open(QFile::WriteOnly | QFile::Text)) { - return false; - } - QXmlStreamWriter stream(&xmlFile); - stream.setAutoFormatting(true); - stream.writeStartDocument(); - - auto e = QMetaEnum::fromType(); - for (auto p = m_colors.begin(); p != m_colors.end(); p++) { - stream.writeStartElement("style"); - stream.writeAttribute(QStringLiteral("name"), - e.valueToKey(int(p.key()))); - auto v = p.value(); - if (v.foreground.isValid()) { - stream.writeAttribute(QStringLiteral("foreground"), - v.foreground.name()); - } - if (v.background.isValid()) { - stream.writeAttribute(QStringLiteral("background"), - v.background.name()); - } - if (!v.fontFamily.isEmpty()) { - stream.writeAttribute(QStringLiteral("fontfamily"), v.fontFamily); - } - if (v.underLine != QTextCharFormat::NoUnderline) { - stream.writeAttribute(QStringLiteral("underLine"), - QString::number(v.underLine)); - } - if (v.isBold) { - stream.writeAttribute(QStringLiteral("bold"), - bool2String(v.isBold)); - } - if (v.isItalic) { - stream.writeAttribute(QStringLiteral("italic"), - bool2String(v.isBold)); - } - stream.writeEndElement(); - } - - stream.writeEndDocument(); - - xmlFile.close(); - return true; -} - -bool ScriptEditorTheme::isValid() const { return m_isValid; } - -bool ScriptEditorTheme::readAttr(const QXmlStreamAttributes &attrs, - const QString &name, QString &output) { - if (attrs.hasAttribute(name)) { - output = attrs.value(name).toString(); - return true; - } - return false; -} - -bool ScriptEditorTheme::string2Bool(const QString &str, bool &ok) { - if (str.compare(QStringLiteral("true"), Qt::CaseInsensitive) == 0) { - ok = true; - return true; - } else if (str.compare(QStringLiteral("false"), Qt::CaseInsensitive) == 0) { - ok = true; - return false; - } else { - ok = false; - return false; - } -} - -QString ScriptEditorTheme::bool2String(bool b) { - return b ? QStringLiteral("true") : QStringLiteral("false"); -} - -QString ScriptEditorTheme::comment() const { return m_comment; } - -QString ScriptEditorTheme::author() const { return m_author; } - -QString ScriptEditorTheme::version() const { return m_version; } - -QString ScriptEditorTheme::name() const { return m_name; } diff --git a/src/class/scripteditortheme.h b/src/class/scripteditortheme.h deleted file mode 100644 index 482543d..0000000 --- a/src/class/scripteditortheme.h +++ /dev/null @@ -1,84 +0,0 @@ -/*============================================================================== -** Copyright (C) 2024-2027 WingSummer -** -** This program is free software: you can redistribute it and/or modify it under -** the terms of the GNU Affero General Public License as published by the Free -** Software Foundation, version 3. -** -** This program is distributed in the hope that it will be useful, but WITHOUT -** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -** FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more -** details. -** -** You should have received a copy of the GNU Affero General Public License -** along with this program. If not, see . -** ============================================================================= -*/ - -#ifndef SCRIPTEDITORTHEME_H -#define SCRIPTEDITORTHEME_H - -#include - -#include -#include - -class ScriptEditorTheme : public QObject { - Q_OBJECT -public: - enum class Styles { - - }; - Q_ENUM(Styles) - - struct ColorScheme { - QColor foreground; - QColor background; - QString fontFamily; - QTextCharFormat::UnderlineStyle underLine = - QTextCharFormat::NoUnderline; - bool isBold = false; - bool isItalic = false; - }; - -public: - explicit ScriptEditorTheme(QObject *parent = nullptr); - explicit ScriptEditorTheme(const QString &filename = QString(), - QObject *parent = nullptr); - - ColorScheme colorScheme(Styles style) const; - - void setColorScheme(Styles style, const ColorScheme &scheme); - - bool loadTheme(const QString &filename); - - bool saveTheme(const QString &filename); - - bool isValid() const; - - QString name() const; - - QString version() const; - - QString author() const; - - QString comment() const; - -private: - bool readAttr(const QXmlStreamAttributes &attr, const QString &name, - QString &output); - - bool string2Bool(const QString &str, bool &ok); - - QString bool2String(bool b); - -private: - bool m_isValid = false; - QString m_name; - QString m_version; - QString m_author; - QString m_comment; - QMap m_colors; -}; - -#endif // SCRIPTEDITORTHEME_H diff --git a/src/class/scriptmachine.cpp b/src/class/scriptmachine.cpp index 0cbabe7..02c64d8 100644 --- a/src/class/scriptmachine.cpp +++ b/src/class/scriptmachine.cpp @@ -670,7 +670,7 @@ bool ScriptMachine::executeScript(ConsoleMode mode, const QString &script, if (isDbg) { _debugger->clearBreakPoint(); - emit onDebugFinished(); + Q_EMIT onDebugFinished(); } if (retCode) { diff --git a/src/class/scriptmanager.cpp b/src/class/scriptmanager.cpp index 52ca34b..348c47a 100644 --- a/src/class/scriptmanager.cpp +++ b/src/class/scriptmanager.cpp @@ -39,7 +39,7 @@ QString ScriptManager::userScriptPath() const { return m_usrScriptsPath; } QString ScriptManager::systemScriptPath() const { return m_sysScriptsPath; } -ScriptManager::ScriptManager() : QObject() { +ScriptManager::ScriptManager() { ASSERT_SINGLETON; // init script directory diff --git a/src/class/scriptmanager.h b/src/class/scriptmanager.h index ba987d7..333d97d 100644 --- a/src/class/scriptmanager.h +++ b/src/class/scriptmanager.h @@ -21,13 +21,12 @@ #include #include #include -#include #include "QWingRibbon/ribbonbuttongroup.h" #include "utilities.h" -class ScriptManager : public QObject { - Q_OBJECT +class ScriptManager { + Q_DECLARE_TR_FUNCTIONS(ScriptManager) public: struct ScriptDirMeta { @@ -100,7 +99,7 @@ private: return a; } -public slots: +public: void runScript(const QString &filename); private: diff --git a/src/class/scriptsettings.cpp b/src/class/scriptsettings.cpp index b487b87..1fd056d 100644 --- a/src/class/scriptsettings.cpp +++ b/src/class/scriptsettings.cpp @@ -184,7 +184,7 @@ void ScriptSettings::save(SETTINGS cat) { m_editorAutoCloseChar); WRITE_CONFIG_EDITOR_SET(CODEEDIT_AUTO_IDEN, SETTING_ITEM::AUTO_IDEN, m_editorAutoIden); - emit editorSettingsUpdate(); + Q_EMIT editorSettingsUpdate(); } if (cat.testFlag(SETTING::CONSOLE)) { @@ -207,7 +207,7 @@ void ScriptSettings::save(SETTINGS cat) { WRITE_CONFIG_CONSOLE_SET(CONSOLE_AUTO_CLOSE_CHAR, SETTING_ITEM::AUTO_CLOSE_CHAR, m_consoleAutoCloseChar); - emit consoleSettingUpdate(); + Q_EMIT consoleSettingUpdate(); } } diff --git a/src/class/settingmanager.cpp b/src/class/settingmanager.cpp index 70d0384..3dbac4a 100644 --- a/src/class/settingmanager.cpp +++ b/src/class/settingmanager.cpp @@ -170,9 +170,9 @@ void SettingManager::load() { } } - emit sigEditorfontSizeChanged(m_editorfontSize); - emit sigCopylimitChanged(m_copylimit); - emit sigDecodeStrlimitChanged(m_decodeStrlimit); + Q_EMIT sigEditorfontSizeChanged(m_editorfontSize); + Q_EMIT sigCopylimitChanged(m_copylimit); + Q_EMIT sigDecodeStrlimitChanged(m_decodeStrlimit); } QList @@ -483,7 +483,7 @@ void SettingManager::setDecodeStrlimit(qsizetype newDecodeStrlimit) { if (m_decodeStrlimit != newDecodeStrlimit) { m_decodeStrlimit = newDecodeStrlimit; _setUnsaved.setFlag(SETTING_ITEM::EDITOR_DECSTRLIMIT); - emit sigDecodeStrlimitChanged(m_decodeStrlimit); + Q_EMIT sigDecodeStrlimitChanged(m_decodeStrlimit); } } @@ -494,7 +494,7 @@ void SettingManager::setCopylimit(qsizetype newCopylimit) { if (m_copylimit != newCopylimit) { m_copylimit = newCopylimit; _setUnsaved.setFlag(SETTING_ITEM::EDITOR_COPY_LIMIT); - emit sigDecodeStrlimitChanged(m_copylimit); + Q_EMIT sigDecodeStrlimitChanged(m_copylimit); } } @@ -522,7 +522,7 @@ void SettingManager::setEditorfontSize(int newEditorfontSize) { if (m_editorfontSize != newEditorfontSize) { m_editorfontSize = newEditorfontSize; _setUnsaved.setFlag(SETTING_ITEM::EDITOR_FONTSIZE); - emit sigEditorfontSizeChanged(newEditorfontSize); + Q_EMIT sigEditorfontSizeChanged(newEditorfontSize); } } diff --git a/src/class/skinmanager.cpp b/src/class/skinmanager.cpp index d4e44a2..fe257e3 100644 --- a/src/class/skinmanager.cpp +++ b/src/class/skinmanager.cpp @@ -26,7 +26,7 @@ #include #include -SkinManager::SkinManager(QObject *parent) : QObject(parent) { +SkinManager::SkinManager() { ASSERT_SINGLETON; int theme = SettingManager::instance().themeID(); diff --git a/src/class/skinmanager.h b/src/class/skinmanager.h index d84d0f6..e0484d0 100644 --- a/src/class/skinmanager.h +++ b/src/class/skinmanager.h @@ -18,10 +18,13 @@ #ifndef SKINMANAGER_H #define SKINMANAGER_H +#include #include -class SkinManager : public QObject { - Q_OBJECT +class SkinManager { + Q_GADGET + Q_DECLARE_TR_FUNCTIONS(SkinManager) + public: enum class Theme { Dark, @@ -30,7 +33,7 @@ public: Q_ENUM(Theme) public: - virtual ~SkinManager() override; + virtual ~SkinManager(); static SkinManager &instance(); @@ -45,7 +48,7 @@ private: private: Theme m_theme; - explicit SkinManager(QObject *parent = nullptr); + explicit SkinManager(); Q_DISABLE_COPY_MOVE(SkinManager) }; diff --git a/src/control/codeedit.cpp b/src/control/codeedit.cpp index 108c729..2f67873 100644 --- a/src/control/codeedit.cpp +++ b/src/control/codeedit.cpp @@ -189,7 +189,7 @@ void CodeEdit::applyEditorSetStyle() { SearchReplaceWidget *CodeEdit::searchWidget() const { return m_searchWidget; } -void CodeEdit::setContentModified(bool b) { emit contentModified(b); } +void CodeEdit::setContentModified(bool b) { Q_EMIT contentModified(b); } void CodeEdit::resizeEvent(QResizeEvent *event) { if (event) diff --git a/src/control/gotolinewidget.cpp b/src/control/gotolinewidget.cpp index 82fd389..e94c341 100644 --- a/src/control/gotolinewidget.cpp +++ b/src/control/gotolinewidget.cpp @@ -45,7 +45,7 @@ GotoLineWidget::GotoLineWidget(QWidget *parent) tbGoto->setAutoRaise(true); tbGoto->setIcon(skin.themeIcon(QStringLiteral("right_arrow"))); connect(tbGoto, &QToolButton::clicked, this, [this]() { - emit onGotoLine(m_sbline->value()); + Q_EMIT onGotoLine(m_sbline->value()); close(); }); @@ -70,6 +70,6 @@ void GotoLineWidget::setOriginLine(int line) { } void GotoLineWidget::cancel() { - emit onGotoLine(m_line); + Q_EMIT onGotoLine(m_line); CodeEditControlWidget::cancel(); } diff --git a/src/control/gotowidget.cpp b/src/control/gotowidget.cpp index cc29f23..bc0c411 100644 --- a/src/control/gotowidget.cpp +++ b/src/control/gotowidget.cpp @@ -18,8 +18,433 @@ #include "gotowidget.h" #include "ui_gotowidget.h" +#include "grammar/NumCal/NumCalBaseVisitor.h" +#include "grammar/NumCal/NumCalLexer.h" +#include "grammar/NumCal/NumCalParser.h" + #include +class Calculator : public NumCalBaseVisitor { +public: + void eval(const QString &exp) { + if (exp.isEmpty()) { + lastPos = GotoWidget::SEEKPOS::Invaild; + lastAddr = 0; + return; + } + + antlr4::ANTLRInputStream input(exp.toStdString()); + + NumCalLexer lexer(&input); + antlr4::CommonTokenStream tokens(&lexer); + + NumCalParser parser(&tokens); + parser.removeErrorListeners(); + parser.setErrorHandler(std::make_shared()); + + try { + visit(parser.entryExpression()); + } catch (...) { + } + } + +public: + virtual std::any + visitEntryExpression(NumCalParser::EntryExpressionContext *ctx) override { + if (ctx == nullptr) { + lastPos = GotoWidget::SEEKPOS::Invaild; + lastAddr = 0; + return defaultResult(); + } + + if (ctx->prefixGoto() == nullptr) { + lastPos = GotoWidget::SEEKPOS::Start; + } else { + auto prefix = ctx->prefixGoto(); + if (prefix->Plus()) { + lastPos = GotoWidget::SEEKPOS::RelativeAdd; + } else if (prefix->Minus()) { + lastPos = GotoWidget::SEEKPOS::RelativeMin; + } else if (prefix->LessThan()) { + lastPos = GotoWidget::SEEKPOS::End; + } else { + lastPos = GotoWidget::SEEKPOS::Invaild; + lastAddr = 0; + return defaultResult(); + } + } + + if (ctx->IntegerConstant()) { + auto r = parseIntegerConstant(ctx->IntegerConstant()->getText()); + if (std::holds_alternative(r)) { + lastAddr = std::get(r); + } else if (std::holds_alternative(r)) { + lastAddr = std::get(r); + } else { + lastPos = GotoWidget::SEEKPOS::Invaild; + lastAddr = 0; + } + } else { + auto r = visitAssignmentExpression(ctx->assignmentExpression()); + if (r.type() == typeid(quint64)) { + lastAddr = std::any_cast(r); + } else if (r.type() == typeid(qint64)) { + auto addr = std::any_cast(r); + if (addr < 0) { + lastPos = GotoWidget::SEEKPOS::Invaild; + lastAddr = 0; + } + lastAddr = quint64(addr); + } else { + lastPos = GotoWidget::SEEKPOS::Invaild; + lastAddr = 0; + } + } + + return defaultResult(); + } + +public: + quint64 lastAddr = 0; + GotoWidget::SEEKPOS lastPos = GotoWidget::SEEKPOS::Invaild; + +public: + std::any + visitCastExpression(NumCalParser::CastExpressionContext *ctx) override { + if (ctx == nullptr) { + return defaultResult(); + } + + if (ctx->IntegerConstant()) { + auto r = parseIntegerConstant(ctx->IntegerConstant()->getText()); + if (std::holds_alternative(r)) { + return std::get(r); + } else if (std::holds_alternative(r)) { + return std::get(r); + } + } else if (ctx->unaryExpression()) { + return visitUnaryExpression(ctx->unaryExpression()); + } + + return defaultResult(); + } + + std::any + visitUnaryExpression(NumCalParser::UnaryExpressionContext *ctx) override { + if (ctx == nullptr) { + return defaultResult(); + } + + auto op = ctx->unaryOperator(); + auto r = visitCastExpression(ctx->castExpression()); + if (r.type() == typeid(quint64)) { + auto v = std::any_cast(r); + if (op->Minus()) { + return -v; + } else if (op->Plus()) { + return +v; + } else if (op->Tilde()) { + return ~v; + } else { + return defaultResult(); + } + } else if (r.type() == typeid(qint64)) { + auto v = std::any_cast(r); + if (op->Minus()) { + return -v; + } else if (op->Plus()) { + return +v; + } else if (op->Tilde()) { + return ~v; + } else { + return defaultResult(); + } + } + + return visitChildren(ctx); + } + + std::any visitInclusiveOrExpression( + NumCalParser::InclusiveOrExpressionContext *ctx) override { + if (ctx == nullptr) { + return defaultResult(); + } + + qulonglong ret = 0; + for (auto &v : ctx->exclusiveOrExpression()) { + auto r = visitExclusiveOrExpression(v); + if (r.type() == typeid(quint64)) { + auto rr = std::any_cast(r); + ret |= rr; + } else if (r.type() == typeid(qint64)) { + auto rr = std::any_cast(r); + ret |= rr; + } else { + // error + return defaultResult(); + } + } + return ret; + } + + std::any visitAssignmentExpression( + NumCalParser::AssignmentExpressionContext *ctx) override { + if (ctx == nullptr) { + return defaultResult(); + } + + if (ctx->IntegerConstant()) { + auto r = parseIntegerConstant(ctx->IntegerConstant()->getText()); + if (std::holds_alternative(r)) { + return std::get(r); + } else if (std::holds_alternative(r)) { + return std::get(r); + } + } else if (ctx->inclusiveOrExpression()) { + return visitInclusiveOrExpression(ctx->inclusiveOrExpression()); + } + + return defaultResult(); + } + + std::any visitExclusiveOrExpression( + NumCalParser::ExclusiveOrExpressionContext *ctx) override { + if (ctx == nullptr) { + return defaultResult(); + } + + quint64 v = 0; + for (auto &ex : ctx->andExpression()) { + auto r = visitAndExpression(ex); + if (r.type() == typeid(qint64)) { + auto rv = std::any_cast(r); + v ^= rv; + } else if (r.type() == typeid(quint64)) { + auto rv = std::any_cast(r); + v ^= rv; + } else { + return defaultResult(); + } + } + + return v; + } + + std::any + visitAndExpression(NumCalParser::AndExpressionContext *ctx) override { + if (ctx == nullptr) { + return defaultResult(); + } + + quint64 v = std::numeric_limits::max(); + for (auto &ex : ctx->shiftExpression()) { + auto r = visitShiftExpression(ex); + if (r.type() == typeid(qint64)) { + auto rv = std::any_cast(r); + v &= rv; + } else if (r.type() == typeid(quint64)) { + auto rv = std::any_cast(r); + v &= rv; + } else { + return defaultResult(); + } + } + return v; + } + + std::any + visitShiftExpression(NumCalParser::ShiftExpressionContext *ctx) override { + if (ctx == nullptr) { + return defaultResult(); + } + + auto data = ctx->additiveExpression(); + auto total = data.size(); + + quint64 ret = 0; + auto retv = visitAdditiveExpression(data.front()); + if (retv.type() == typeid(qint64)) { + ret = std::any_cast(retv); + } else if (retv.type() == typeid(quint64)) { + ret = std::any_cast(retv); + } else { + return defaultResult(); + } + + for (size_t i = 1; i < total; ++i) { + auto op = ctx->children[2 * i - 1]->getText(); + auto r = visitAdditiveExpression(data.at(i)); + if (op == "<<") { + if (r.type() == typeid(qint64)) { + auto rv = std::any_cast(r); + ret <<= rv; + } else if (r.type() == typeid(quint64)) { + auto rv = std::any_cast(r); + ret <<= rv; + } else { + return defaultResult(); + } + } else if (op == ">>") { + if (r.type() == typeid(qint64)) { + auto rv = std::any_cast(r); + ret >>= rv; + } else if (r.type() == typeid(quint64)) { + auto rv = std::any_cast(r); + ret >>= rv; + } else { + return defaultResult(); + } + } else { + return defaultResult(); + } + } + + return ret; + } + + std::any visitAdditiveExpression( + NumCalParser::AdditiveExpressionContext *ctx) override { + if (ctx == nullptr) { + return defaultResult(); + } + + auto data = ctx->multiplicativeExpression(); + auto total = data.size(); + + quint64 ret = 0; + auto retv = visitMultiplicativeExpression(data.front()); + if (retv.type() == typeid(qint64)) { + ret = std::any_cast(retv); + } else if (retv.type() == typeid(quint64)) { + ret = std::any_cast(retv); + } else { + return defaultResult(); + } + + for (size_t i = 1; i < total; i++) { + auto r = visitMultiplicativeExpression(data.at(i)); + auto op = ctx->children[2 * i - 1]->getText(); + if (r.type() == typeid(qint64)) { + auto rv = std::any_cast(r); + if (op == "+") { + ret += rv; + } else if (op == "-") { + ret -= rv; + } else { + return defaultResult(); + } + } else if (r.type() == typeid(quint64)) { + auto rv = std::any_cast(r); + if (op == "+") { + ret += rv; + } else if (op == "-") { + ret -= rv; + } else { + return defaultResult(); + } + } else { + return defaultResult(); + } + } + + return ret; + } + + std::any visitMultiplicativeExpression( + NumCalParser::MultiplicativeExpressionContext *ctx) override { + if (ctx == nullptr) { + return defaultResult(); + } + + auto data = ctx->castExpression(); + auto total = data.size(); + + quint64 ret = 0; + auto retv = visitCastExpression(data.front()); + if (retv.type() == typeid(qint64)) { + ret = std::any_cast(retv); + } else if (retv.type() == typeid(quint64)) { + ret = std::any_cast(retv); + } else { + return defaultResult(); + } + + for (size_t i = 1; i < total; i++) { + auto r = visitCastExpression(data.at(i)); + auto op = ctx->children[2 * i - 1]->getText(); + if (r.type() == typeid(qint64)) { + auto rv = std::any_cast(r); + if (op == "*") { + ret *= rv; + } else if (op == "/") { + ret /= rv; + } else if (op == "%") { + ret %= rv; + } else { + return defaultResult(); + } + } else if (r.type() == typeid(quint64)) { + auto rv = std::any_cast(r); + if (op == "*") { + ret *= rv; + } else if (op == "/") { + ret /= rv; + } else if (op == "%") { + ret %= rv; + } else { + return defaultResult(); + } + } else { + return defaultResult(); + } + } + + return ret; + } + + std::any visitPrimaryExpression( + NumCalParser::PrimaryExpressionContext *ctx) override { + if (ctx == nullptr) { + return defaultResult(); + } + + if (ctx->IntegerConstant()) { + auto r = parseIntegerConstant(ctx->IntegerConstant()->getText()); + if (std::holds_alternative(r)) { + return std::get(r); + } else if (std::holds_alternative(r)) { + return std::get(r); + } + } else if (ctx->assignmentExpression()) { + return visitAssignmentExpression(ctx->assignmentExpression()); + } + + return defaultResult(); + } + +private: + std::variant + parseIntegerConstant(const std::string &text) { + Q_STATIC_ASSERT_X( + QT_VERSION >= QT_VERSION_CHECK(6, 4, 0), + "If you want to support Qt version lower than 6.4.0, You should " + "implement '0b' prefix integer converstion on your own!"); + + bool b; + auto ct = QString::fromStdString(text); + auto num = ct.toLongLong(&b, 0); + if (b) { + return num; + } else { + auto num = ct.toULongLong(&b, 0); + if (b) { + return num; + } + return {}; + } + } +}; + GotoWidget::GotoWidget(QWidget *parent) : QWidget(parent), ui(new Ui::GotoWidget) { ui->setupUi(this); @@ -54,15 +479,15 @@ void GotoWidget::handleLineChanged() { auto isline = ui->rbLine->isChecked(); auto p = convert2Pos(content, ps, isline); if (ps != SEEKPOS::Invaild) { - ui->lineEdit->setStyleSheet(QString()); - emit jumpToLine(p, isline); + ui->lineEdit->setStyleSheet({}); } else { ui->lineEdit->setStyleSheet(QStringLiteral("QLineEdit{color: red}")); } + Q_EMIT jumpToLine(p, isline); } void GotoWidget::jumpCancel() { - emit jumpToLine(m_oldFileOffsetBeforeJump, false); + Q_EMIT jumpToLine(m_oldFileOffsetBeforeJump, false); hide(); } @@ -73,114 +498,86 @@ void GotoWidget::jumpConfirm() { void GotoWidget::on_btnClose_clicked() { this->hide(); } -void GotoWidget::on_btnGoto_clicked() { /*emit onGoto(ui->spinBox->value()); */ -} +qsizetype GotoWidget::convert2Pos(const QString &value, SEEKPOS &ps, + bool isline) { + Calculator cal; + cal.eval(value); -qsizetype GotoWidget::convert2Pos(QString value, SEEKPOS &ps, bool isline) { - qsizetype res = 0; - if (value.length() > 0) { - auto ch = value.at(0); - if (ch == '+') { - ps = SEEKPOS::Relative; - value = value.remove(0, 1); + // you should ensure return value is origin position if invalid - bool ok = false; - res = value.toLongLong(&ok, 0); - - if (!ok) { - ps = SEEKPOS::Invaild; - } else { - if (isline) { - if (res + m_rowBeforeJump > m_maxFilelines) { - ps = SEEKPOS::Invaild; - res = 0; - } else { - res += m_rowBeforeJump; - } - } else { - if (res + m_oldFileOffsetBeforeJump > m_maxFileBytes) { - ps = SEEKPOS::Invaild; - res = 0; - } else { - res += m_oldFileOffsetBeforeJump; - } - } - } - - } else if (ch == '-') { - ps = SEEKPOS::Relative; - - value = value.remove(0, 1); - - bool ok = false; - res = value.toLongLong(&ok, 0); - - if (!ok) { - ps = SEEKPOS::Invaild; - } else { - if (isline) { - if (res - m_rowBeforeJump < 0) { - ps = SEEKPOS::Invaild; - res = 0; - } else { - res -= m_rowBeforeJump; - } - } else { - if (qlonglong(m_oldFileOffsetBeforeJump) - res < 0) { - ps = SEEKPOS::Invaild; - res = 0; - } else { - res = qlonglong(m_oldFileOffsetBeforeJump) - res; - } - } - } - - } else if (ch == '<') { - ps = SEEKPOS::End; - value = value.remove(0, 1); - - bool ok = false; - res = value.toLongLong(&ok, 0); - - if (!ok || res < 0) { - ps = SEEKPOS::Invaild; - } else { - if (isline) { - if (m_maxFilelines - res < 0) { - ps = SEEKPOS::Invaild; - res = 0; - } else { - res = m_maxFilelines - res; - } - } else { - if (qlonglong(m_maxFileBytes) - res < 0) { - ps = SEEKPOS::Invaild; - res = 0; - } else { - res = qlonglong(m_maxFileBytes) - res; - } - } - } - } else { - ps = SEEKPOS::Start; - - bool ok = false; - res = value.toInt(&ok, 0); - - if (!ok) { - ps = SEEKPOS::Invaild; - } else { - if (res < 0 || quint64(res) > (isline ? quint64(m_maxFilelines) - : m_maxFileBytes)) { - ps = SEEKPOS::Invaild; - res = 0; - } - } - } - } else { - ps = SEEKPOS::Relative; + qsizetype res = cal.lastAddr; + ps = cal.lastPos; + switch (cal.lastPos) { + case SEEKPOS::Invaild: res = isline ? qsizetype(m_rowBeforeJump) : qsizetype(m_oldFileOffsetBeforeJump); + break; + case SEEKPOS::Start: + if (res < 0 || quint64(res) > (isline ? quint64(m_maxFilelines) + : m_maxFileBytes)) { + ps = SEEKPOS::Invaild; + res = isline ? qsizetype(m_rowBeforeJump) + : qsizetype(m_oldFileOffsetBeforeJump); + } + break; + case SEEKPOS::End: + if (isline) { + if (m_maxFilelines - res < 0) { + ps = SEEKPOS::Invaild; + res = isline ? qsizetype(m_rowBeforeJump) + : qsizetype(m_oldFileOffsetBeforeJump); + } else { + res = m_maxFilelines - res; + } + } else { + if (qlonglong(m_maxFileBytes) - res < 0) { + ps = SEEKPOS::Invaild; + res = isline ? qsizetype(m_rowBeforeJump) + : qsizetype(m_oldFileOffsetBeforeJump); + } else { + res = qlonglong(m_maxFileBytes) - res; + } + } + break; + case SEEKPOS::RelativeAdd: + if (isline) { + if (res + m_rowBeforeJump > m_maxFilelines) { + ps = SEEKPOS::Invaild; + res = isline ? qsizetype(m_rowBeforeJump) + : qsizetype(m_oldFileOffsetBeforeJump); + } else { + res += m_rowBeforeJump; + } + } else { + if (res + m_oldFileOffsetBeforeJump > m_maxFileBytes) { + ps = SEEKPOS::Invaild; + res = isline ? qsizetype(m_rowBeforeJump) + : qsizetype(m_oldFileOffsetBeforeJump); + } else { + res += m_oldFileOffsetBeforeJump; + } + } + break; + case SEEKPOS::RelativeMin: + if (isline) { + if (res - m_rowBeforeJump < 0) { + ps = SEEKPOS::Invaild; + res = isline ? qsizetype(m_rowBeforeJump) + : qsizetype(m_oldFileOffsetBeforeJump); + } else { + res -= m_rowBeforeJump; + } + } else { + if (qlonglong(m_oldFileOffsetBeforeJump) - res < 0) { + ps = SEEKPOS::Invaild; + res = isline ? qsizetype(m_rowBeforeJump) + : qsizetype(m_oldFileOffsetBeforeJump); + } else { + res = qlonglong(m_oldFileOffsetBeforeJump) - res; + } + } + break; } + return res; } diff --git a/src/control/gotowidget.h b/src/control/gotowidget.h index ad03e3b..8835aa7 100644 --- a/src/control/gotowidget.h +++ b/src/control/gotowidget.h @@ -27,7 +27,8 @@ class GotoWidget; class GotoWidget : public QWidget { Q_OBJECT - enum SEEKPOS { Invaild, Start, End, Relative }; +public: + enum class SEEKPOS { Invaild, Start, End, RelativeAdd, RelativeMin }; public: explicit GotoWidget(QWidget *parent = nullptr); @@ -50,10 +51,8 @@ signals: private slots: void on_btnClose_clicked(); - void on_btnGoto_clicked(); - private: - qsizetype convert2Pos(QString value, SEEKPOS &ps, bool isline); + qsizetype convert2Pos(const QString &value, SEEKPOS &ps, bool isline); private: Ui::GotoWidget *ui; diff --git a/src/control/huecolorpickerslider.cpp b/src/control/huecolorpickerslider.cpp index c7c2194..3231159 100644 --- a/src/control/huecolorpickerslider.cpp +++ b/src/control/huecolorpickerslider.cpp @@ -38,7 +38,7 @@ HueColorPickerSlider::HueColorPickerSlider(Qt::Orientation orientation, connect(this, &HueColorPickerSlider::valueChanged, this, [this](int v) { _color.setHsv(v, _color.hsvSaturation(), _color.value()); this->setToolTip(_color.name()); - emit colorChanged(_color); + Q_EMIT colorChanged(_color); }); this->setContextMenuPolicy(Qt::ActionsContextMenu); @@ -72,7 +72,7 @@ void HueColorPickerSlider::setColor(const QColor &newColor) { {359.0 / 360.0, redColor(colorS, colorV)}}); this->setValue(_color.hsvHue()); - emit colorChanged(newColor); + Q_EMIT colorChanged(newColor); } } diff --git a/src/control/qlistviewext.cpp b/src/control/qlistviewext.cpp index 8c3e7b1..559c394 100644 --- a/src/control/qlistviewext.cpp +++ b/src/control/qlistviewext.cpp @@ -50,5 +50,5 @@ void QListViewExt::setModel(QAbstractItemModel *model) { QListView::setModel(model); - emit modelChanged(); + Q_EMIT modelChanged(); } diff --git a/src/control/qtableviewext.cpp b/src/control/qtableviewext.cpp index 55a2407..0753bdf 100644 --- a/src/control/qtableviewext.cpp +++ b/src/control/qtableviewext.cpp @@ -50,5 +50,5 @@ void QTableViewExt::setModel(QAbstractItemModel *model) { QTableView::setModel(model); - emit modelChanged(); + Q_EMIT modelChanged(); } diff --git a/src/control/scriptingconsole.cpp b/src/control/scriptingconsole.cpp index af0cd03..86fb992 100644 --- a/src/control/scriptingconsole.cpp +++ b/src/control/scriptingconsole.cpp @@ -88,7 +88,7 @@ void ScriptingConsole::handleReturnKey() { iodevice_->consoleWidgetInput(code); if (!_isWaitingRead) { - emit consoleCommand(code); + Q_EMIT consoleCommand(code); } } } diff --git a/src/control/settingspopup.cpp b/src/control/settingspopup.cpp index af069b6..1daf454 100644 --- a/src/control/settingspopup.cpp +++ b/src/control/settingspopup.cpp @@ -65,7 +65,7 @@ void TreeFilterEdit::resizeEvent(QResizeEvent *event) { void TreeFilterEdit::keyPressEvent(QKeyEvent *event) { if (event->key() == Qt::Key_Down) { - emit navigateDown(); + Q_EMIT navigateDown(); return; } QLineEdit::keyPressEvent(event); @@ -212,13 +212,15 @@ void SyntaxPopup::syntaxItemChosen(QTreeWidgetItem *current, int) { return; if (current == m_plainTextItem) { - emit syntaxSelected(WingCodeEdit::nullSyntax()); + Q_EMIT syntaxSelected(WingCodeEdit::nullSyntax()); return; } QVariant itemData = current->data(0, Qt::UserRole); - if (itemData.canConvert()) - emit syntaxSelected(itemData.value()); + if (itemData.canConvert()) { + Q_EMIT syntaxSelected( + itemData.value()); + } } EncodingPopup::EncodingPopup(QWidget *parent) : FilteredTreePopup(parent) { @@ -243,5 +245,5 @@ void EncodingPopup::encodingItemChosen(QTreeWidgetItem *current, int) { QVariant codecName = current->data(0, Qt::UserRole); if (codecName.isValid()) - emit encodingSelected(codecName.toString()); + Q_EMIT encodingSelected(codecName.toString()); } diff --git a/src/dialog/colorpickerdialog.cpp b/src/dialog/colorpickerdialog.cpp index 865284a..3ca39be 100644 --- a/src/dialog/colorpickerdialog.cpp +++ b/src/dialog/colorpickerdialog.cpp @@ -90,7 +90,7 @@ void ColorPickerDialog::updateColor(QColor color) { ui->leColor->setText(color.name()); ui->wcolor->setStyleSheet(QStringLiteral("background-color: ") + color.name()); - emit colorChanged(); + Q_EMIT colorChanged(); } QColor ColorPickerDialog::color() const { return _color; } diff --git a/src/dialog/finddialog.cpp b/src/dialog/finddialog.cpp index 8ee66b6..8714108 100644 --- a/src/dialog/finddialog.cpp +++ b/src/dialog/finddialog.cpp @@ -77,7 +77,7 @@ FindDialog::FindDialog(const FindInfo &info, QWidget *parent) m_lineeditor->clear(); } else { // force update - emit m_lineeditor->textChanged(); + Q_EMIT m_lineeditor->textChanged(); } }); diff --git a/src/dialog/mainwindow.cpp b/src/dialog/mainwindow.cpp index 89ba011..fc38aea 100644 --- a/src/dialog/mainwindow.cpp +++ b/src/dialog/mainwindow.cpp @@ -908,7 +908,7 @@ MainWindow::buildUpHexBookMarkDock(ads::CDockManager *dock, m_bookmarks->clearSelection(); doc->RemoveBookMarks(pos); - emit model->layoutChanged(); + Q_EMIT model->layoutChanged(); }); m_aDelBookMark->setEnabled(false); m_bookmarks->addAction(m_aDelBookMark); @@ -982,7 +982,7 @@ MainWindow::buildUpHexMetaDataDock(ads::CDockManager *dock, m_metadatas->clearSelection(); hexeditor->document()->metadata()->RemoveMetadatas(pmetas); - emit m_metadatas->model()->layoutChanged(); + Q_EMIT m_metadatas->model()->layoutChanged(); }); m_aDelMetaData->setEnabled(false); m_metadatas->addAction(m_aDelMetaData); @@ -3979,7 +3979,7 @@ void MainWindow::closeEvent(QCloseEvent *event) { PluginSystem::instance().destory(); FramelessMainWindow::closeEvent(event); - emit closed(); + Q_EMIT closed(); } bool MainWindow::eventFilter(QObject *watched, QEvent *event) { diff --git a/src/dialog/metadialog.cpp b/src/dialog/metadialog.cpp index 26f5571..bad69d4 100644 --- a/src/dialog/metadialog.cpp +++ b/src/dialog/metadialog.cpp @@ -135,7 +135,7 @@ QColor MetaDialog::backGroundColor() { void MetaDialog::setComment(QString comment) { if (comment.length() > 0) { ccomment->setChecked(true); - emit ccomment->clicked(true); + Q_EMIT ccomment->clicked(true); _comment = comment; m_comment->setText(comment); } @@ -144,7 +144,7 @@ void MetaDialog::setComment(QString comment) { void MetaDialog::setBackGroundColor(QColor color) { if (color.isValid()) { cbackground->setChecked(true); - emit cbackground->clicked(true); + Q_EMIT cbackground->clicked(true); _background = color; ibackground->setColor(color); } @@ -153,7 +153,7 @@ void MetaDialog::setBackGroundColor(QColor color) { void MetaDialog::setForeGroundColor(QColor color) { if (color.isValid()) { cforeground->setChecked(true); - emit cforeground->clicked(true); + Q_EMIT cforeground->clicked(true); _foreground = color; iforeground->setColor(color); } diff --git a/src/grammar/NumCal/NumCal.g4 b/src/grammar/NumCal/NumCal.g4 new file mode 100644 index 0000000..6dc24e7 --- /dev/null +++ b/src/grammar/NumCal/NumCal.g4 @@ -0,0 +1,224 @@ +/*============================================================================== +** Copyright (C) 2025-2028 WingSummer +** +** This program is free software: you can redistribute it and/or modify it under +** the terms of the GNU Affero General Public License as published by the Free +** Software Foundation, version 3. +** +** This program is distributed in the hope that it will be useful, but WITHOUT +** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +** FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more +** details. +** +** You should have received a copy of the GNU Affero General Public License +** along with this program. If not, see . +** ============================================================================= +*/ + +grammar NumCal; + +primaryExpression + : IntegerConstant + | '(' assignmentExpression ')' + ; + +unaryExpression + : primaryExpression + | unaryOperator castExpression + ; + +unaryOperator + : '+' + | '-' + | '~' + ; + +castExpression + : unaryExpression + | IntegerConstant + ; + +multiplicativeExpression + : castExpression (('*' | '/' | '%') castExpression)* + ; + +additiveExpression + : multiplicativeExpression (('+' | '-') multiplicativeExpression)* + ; + +shiftExpression + : additiveExpression (('<<' | '>>') additiveExpression)* + ; + +andExpression + : shiftExpression ('&' shiftExpression)* + ; + +exclusiveOrExpression + : andExpression ('^' andExpression)* + ; + +inclusiveOrExpression + : exclusiveOrExpression ('|' exclusiveOrExpression)* + ; + +assignmentExpression + : IntegerConstant + | inclusiveOrExpression + ; + +entryExpression + : prefixGoto? IntegerConstant EOF + | (prefixGoto Colon)? assignmentExpression EOF + | (prefixGoto LeftBracket)? assignmentExpression RightBracket EOF + | (prefixGoto LeftParen)? assignmentExpression RightParen EOF + ; + +prefixGoto + : (Plus | Minus | LessThan) + ; + + +LeftParen + : '(' + ; + +RightParen + : ')' + ; + +LeftShift + : '<<' + ; + +RightShift + : '>>' + ; + +Plus + : '+' + ; + +Minus + : '-' + ; + +Star + : '*' + ; + +Div + : '/' + ; + +Mod + : '%' + ; + +And + : '&' + ; + +Or + : '|' + ; + +Caret + : '^' + ; + +Tilde + : '~' + ; + +LessThan + : '<' + ; + +Colon + : ':' + ; + +LeftBracket + : '[' + ; + +RightBracket + : ']' + ; + +fragment Digit + : [0-9] + ; + +fragment HexQuad + : HexadecimalDigit HexadecimalDigit HexadecimalDigit HexadecimalDigit + ; + +IntegerConstant + : DecimalConstant + | OctalConstant + | HexadecimalConstant + | BinaryConstant + ; + +fragment BinaryConstant + : '0' [bB] [0-1]+ + ; + +fragment DecimalConstant + : NonzeroDigit Digit* + ; + +fragment OctalConstant + : '0' OctalDigit* + ; + +fragment HexadecimalConstant + : HexadecimalPrefix HexadecimalDigit+ + ; + +fragment HexadecimalPrefix + : '0' [xX] + ; + +fragment NonzeroDigit + : [1-9] + ; + +fragment OctalDigit + : [0-7] + ; + +fragment HexadecimalDigit + : [0-9a-fA-F] + ; + +fragment FractionalConstant + : DigitSequence? '.' DigitSequence + | DigitSequence '.' + ; + +fragment ExponentPart + : [eE] Sign? DigitSequence + ; + +fragment Sign + : [+-] + ; + +fragment DigitSequence + : Digit+ + ; + +fragment BinaryExponentPart + : [pP] Sign? DigitSequence + ; + +fragment HexadecimalDigitSequence + : HexadecimalDigit+ + ; + +Whitespace + : [ \t]+ -> skip + ; diff --git a/src/grammar/NumCal/NumCalBaseVisitor.cpp b/src/grammar/NumCal/NumCalBaseVisitor.cpp new file mode 100644 index 0000000..96c4c14 --- /dev/null +++ b/src/grammar/NumCal/NumCalBaseVisitor.cpp @@ -0,0 +1,7 @@ + +// Generated from NumCal.g4 by ANTLR 4.13.2 + + +#include "NumCalBaseVisitor.h" + + diff --git a/src/grammar/NumCal/NumCalBaseVisitor.h b/src/grammar/NumCal/NumCalBaseVisitor.h new file mode 100644 index 0000000..57f270c --- /dev/null +++ b/src/grammar/NumCal/NumCalBaseVisitor.h @@ -0,0 +1,72 @@ + +// Generated from NumCal.g4 by ANTLR 4.13.2 + +#pragma once + + +#include "antlr4-runtime.h" +#include "NumCalVisitor.h" + + +/** + * This class provides an empty implementation of NumCalVisitor, which can be + * extended to create a visitor which only needs to handle a subset of the available methods. + */ +class NumCalBaseVisitor : public NumCalVisitor { +public: + + virtual std::any visitPrimaryExpression(NumCalParser::PrimaryExpressionContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitUnaryExpression(NumCalParser::UnaryExpressionContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitUnaryOperator(NumCalParser::UnaryOperatorContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitCastExpression(NumCalParser::CastExpressionContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitMultiplicativeExpression(NumCalParser::MultiplicativeExpressionContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitAdditiveExpression(NumCalParser::AdditiveExpressionContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitShiftExpression(NumCalParser::ShiftExpressionContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitAndExpression(NumCalParser::AndExpressionContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitExclusiveOrExpression(NumCalParser::ExclusiveOrExpressionContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitInclusiveOrExpression(NumCalParser::InclusiveOrExpressionContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitAssignmentExpression(NumCalParser::AssignmentExpressionContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitEntryExpression(NumCalParser::EntryExpressionContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitPrefixGoto(NumCalParser::PrefixGotoContext *ctx) override { + return visitChildren(ctx); + } + + +}; + diff --git a/src/grammar/NumCal/NumCalLexer.cpp b/src/grammar/NumCal/NumCalLexer.cpp new file mode 100644 index 0000000..7548443 --- /dev/null +++ b/src/grammar/NumCal/NumCalLexer.cpp @@ -0,0 +1,211 @@ + +// Generated from NumCal.g4 by ANTLR 4.13.2 + + +#include "NumCalLexer.h" + + +using namespace antlr4; + + + +using namespace antlr4; + +namespace { + +struct NumCalLexerStaticData final { + NumCalLexerStaticData(std::vector ruleNames, + std::vector channelNames, + std::vector modeNames, + std::vector literalNames, + std::vector symbolicNames) + : ruleNames(std::move(ruleNames)), channelNames(std::move(channelNames)), + modeNames(std::move(modeNames)), literalNames(std::move(literalNames)), + symbolicNames(std::move(symbolicNames)), + vocabulary(this->literalNames, this->symbolicNames) {} + + NumCalLexerStaticData(const NumCalLexerStaticData&) = delete; + NumCalLexerStaticData(NumCalLexerStaticData&&) = delete; + NumCalLexerStaticData& operator=(const NumCalLexerStaticData&) = delete; + NumCalLexerStaticData& operator=(NumCalLexerStaticData&&) = delete; + + std::vector decisionToDFA; + antlr4::atn::PredictionContextCache sharedContextCache; + const std::vector ruleNames; + const std::vector channelNames; + const std::vector modeNames; + const std::vector literalNames; + const std::vector symbolicNames; + const antlr4::dfa::Vocabulary vocabulary; + antlr4::atn::SerializedATNView serializedATN; + std::unique_ptr atn; +}; + +::antlr4::internal::OnceFlag numcallexerLexerOnceFlag; +#if ANTLR4_USE_THREAD_LOCAL_CACHE +static thread_local +#endif +std::unique_ptr numcallexerLexerStaticData = nullptr; + +void numcallexerLexerInitialize() { +#if ANTLR4_USE_THREAD_LOCAL_CACHE + if (numcallexerLexerStaticData != nullptr) { + return; + } +#else + assert(numcallexerLexerStaticData == nullptr); +#endif + auto staticData = std::make_unique( + std::vector{ + "LeftParen", "RightParen", "LeftShift", "RightShift", "Plus", "Minus", + "Star", "Div", "Mod", "And", "Or", "Caret", "Tilde", "LessThan", "Colon", + "LeftBracket", "RightBracket", "Digit", "HexQuad", "IntegerConstant", + "BinaryConstant", "DecimalConstant", "OctalConstant", "HexadecimalConstant", + "HexadecimalPrefix", "NonzeroDigit", "OctalDigit", "HexadecimalDigit", + "FractionalConstant", "ExponentPart", "Sign", "DigitSequence", "BinaryExponentPart", + "HexadecimalDigitSequence", "Whitespace" + }, + std::vector{ + "DEFAULT_TOKEN_CHANNEL", "HIDDEN" + }, + std::vector{ + "DEFAULT_MODE" + }, + std::vector{ + "", "'('", "')'", "'<<'", "'>>'", "'+'", "'-'", "'*'", "'/'", "'%'", + "'&'", "'|'", "'^'", "'~'", "'<'", "':'", "'['", "']'" + }, + std::vector{ + "", "LeftParen", "RightParen", "LeftShift", "RightShift", "Plus", + "Minus", "Star", "Div", "Mod", "And", "Or", "Caret", "Tilde", "LessThan", + "Colon", "LeftBracket", "RightBracket", "IntegerConstant", "Whitespace" + } + ); + static const int32_t serializedATNSegment[] = { + 4,0,19,197,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7, + 6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2,13,7,13,2,14, + 7,14,2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,2,19,7,19,2,20,7,20,2,21, + 7,21,2,22,7,22,2,23,7,23,2,24,7,24,2,25,7,25,2,26,7,26,2,27,7,27,2,28, + 7,28,2,29,7,29,2,30,7,30,2,31,7,31,2,32,7,32,2,33,7,33,2,34,7,34,1,0, + 1,0,1,1,1,1,1,2,1,2,1,2,1,3,1,3,1,3,1,4,1,4,1,5,1,5,1,6,1,6,1,7,1,7,1, + 8,1,8,1,9,1,9,1,10,1,10,1,11,1,11,1,12,1,12,1,13,1,13,1,14,1,14,1,15, + 1,15,1,16,1,16,1,17,1,17,1,18,1,18,1,18,1,18,1,18,1,19,1,19,1,19,1,19, + 3,19,119,8,19,1,20,1,20,1,20,4,20,124,8,20,11,20,12,20,125,1,21,1,21, + 5,21,130,8,21,10,21,12,21,133,9,21,1,22,1,22,5,22,137,8,22,10,22,12,22, + 140,9,22,1,23,1,23,4,23,144,8,23,11,23,12,23,145,1,24,1,24,1,24,1,25, + 1,25,1,26,1,26,1,27,1,27,1,28,3,28,158,8,28,1,28,1,28,1,28,1,28,1,28, + 3,28,165,8,28,1,29,1,29,3,29,169,8,29,1,29,1,29,1,30,1,30,1,31,4,31,176, + 8,31,11,31,12,31,177,1,32,1,32,3,32,182,8,32,1,32,1,32,1,33,4,33,187, + 8,33,11,33,12,33,188,1,34,4,34,192,8,34,11,34,12,34,193,1,34,1,34,0,0, + 35,1,1,3,2,5,3,7,4,9,5,11,6,13,7,15,8,17,9,19,10,21,11,23,12,25,13,27, + 14,29,15,31,16,33,17,35,0,37,0,39,18,41,0,43,0,45,0,47,0,49,0,51,0,53, + 0,55,0,57,0,59,0,61,0,63,0,65,0,67,0,69,19,1,0,11,1,0,48,57,2,0,66,66, + 98,98,1,0,48,49,2,0,88,88,120,120,1,0,49,57,1,0,48,55,3,0,48,57,65,70, + 97,102,2,0,69,69,101,101,2,0,43,43,45,45,2,0,80,80,112,112,2,0,9,9,32, + 32,194,0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0,7,1,0,0,0,0,9,1,0,0,0,0, + 11,1,0,0,0,0,13,1,0,0,0,0,15,1,0,0,0,0,17,1,0,0,0,0,19,1,0,0,0,0,21,1, + 0,0,0,0,23,1,0,0,0,0,25,1,0,0,0,0,27,1,0,0,0,0,29,1,0,0,0,0,31,1,0,0, + 0,0,33,1,0,0,0,0,39,1,0,0,0,0,69,1,0,0,0,1,71,1,0,0,0,3,73,1,0,0,0,5, + 75,1,0,0,0,7,78,1,0,0,0,9,81,1,0,0,0,11,83,1,0,0,0,13,85,1,0,0,0,15,87, + 1,0,0,0,17,89,1,0,0,0,19,91,1,0,0,0,21,93,1,0,0,0,23,95,1,0,0,0,25,97, + 1,0,0,0,27,99,1,0,0,0,29,101,1,0,0,0,31,103,1,0,0,0,33,105,1,0,0,0,35, + 107,1,0,0,0,37,109,1,0,0,0,39,118,1,0,0,0,41,120,1,0,0,0,43,127,1,0,0, + 0,45,134,1,0,0,0,47,141,1,0,0,0,49,147,1,0,0,0,51,150,1,0,0,0,53,152, + 1,0,0,0,55,154,1,0,0,0,57,164,1,0,0,0,59,166,1,0,0,0,61,172,1,0,0,0,63, + 175,1,0,0,0,65,179,1,0,0,0,67,186,1,0,0,0,69,191,1,0,0,0,71,72,5,40,0, + 0,72,2,1,0,0,0,73,74,5,41,0,0,74,4,1,0,0,0,75,76,5,60,0,0,76,77,5,60, + 0,0,77,6,1,0,0,0,78,79,5,62,0,0,79,80,5,62,0,0,80,8,1,0,0,0,81,82,5,43, + 0,0,82,10,1,0,0,0,83,84,5,45,0,0,84,12,1,0,0,0,85,86,5,42,0,0,86,14,1, + 0,0,0,87,88,5,47,0,0,88,16,1,0,0,0,89,90,5,37,0,0,90,18,1,0,0,0,91,92, + 5,38,0,0,92,20,1,0,0,0,93,94,5,124,0,0,94,22,1,0,0,0,95,96,5,94,0,0,96, + 24,1,0,0,0,97,98,5,126,0,0,98,26,1,0,0,0,99,100,5,60,0,0,100,28,1,0,0, + 0,101,102,5,58,0,0,102,30,1,0,0,0,103,104,5,91,0,0,104,32,1,0,0,0,105, + 106,5,93,0,0,106,34,1,0,0,0,107,108,7,0,0,0,108,36,1,0,0,0,109,110,3, + 55,27,0,110,111,3,55,27,0,111,112,3,55,27,0,112,113,3,55,27,0,113,38, + 1,0,0,0,114,119,3,43,21,0,115,119,3,45,22,0,116,119,3,47,23,0,117,119, + 3,41,20,0,118,114,1,0,0,0,118,115,1,0,0,0,118,116,1,0,0,0,118,117,1,0, + 0,0,119,40,1,0,0,0,120,121,5,48,0,0,121,123,7,1,0,0,122,124,7,2,0,0,123, + 122,1,0,0,0,124,125,1,0,0,0,125,123,1,0,0,0,125,126,1,0,0,0,126,42,1, + 0,0,0,127,131,3,51,25,0,128,130,3,35,17,0,129,128,1,0,0,0,130,133,1,0, + 0,0,131,129,1,0,0,0,131,132,1,0,0,0,132,44,1,0,0,0,133,131,1,0,0,0,134, + 138,5,48,0,0,135,137,3,53,26,0,136,135,1,0,0,0,137,140,1,0,0,0,138,136, + 1,0,0,0,138,139,1,0,0,0,139,46,1,0,0,0,140,138,1,0,0,0,141,143,3,49,24, + 0,142,144,3,55,27,0,143,142,1,0,0,0,144,145,1,0,0,0,145,143,1,0,0,0,145, + 146,1,0,0,0,146,48,1,0,0,0,147,148,5,48,0,0,148,149,7,3,0,0,149,50,1, + 0,0,0,150,151,7,4,0,0,151,52,1,0,0,0,152,153,7,5,0,0,153,54,1,0,0,0,154, + 155,7,6,0,0,155,56,1,0,0,0,156,158,3,63,31,0,157,156,1,0,0,0,157,158, + 1,0,0,0,158,159,1,0,0,0,159,160,5,46,0,0,160,165,3,63,31,0,161,162,3, + 63,31,0,162,163,5,46,0,0,163,165,1,0,0,0,164,157,1,0,0,0,164,161,1,0, + 0,0,165,58,1,0,0,0,166,168,7,7,0,0,167,169,3,61,30,0,168,167,1,0,0,0, + 168,169,1,0,0,0,169,170,1,0,0,0,170,171,3,63,31,0,171,60,1,0,0,0,172, + 173,7,8,0,0,173,62,1,0,0,0,174,176,3,35,17,0,175,174,1,0,0,0,176,177, + 1,0,0,0,177,175,1,0,0,0,177,178,1,0,0,0,178,64,1,0,0,0,179,181,7,9,0, + 0,180,182,3,61,30,0,181,180,1,0,0,0,181,182,1,0,0,0,182,183,1,0,0,0,183, + 184,3,63,31,0,184,66,1,0,0,0,185,187,3,55,27,0,186,185,1,0,0,0,187,188, + 1,0,0,0,188,186,1,0,0,0,188,189,1,0,0,0,189,68,1,0,0,0,190,192,7,10,0, + 0,191,190,1,0,0,0,192,193,1,0,0,0,193,191,1,0,0,0,193,194,1,0,0,0,194, + 195,1,0,0,0,195,196,6,34,0,0,196,70,1,0,0,0,13,0,118,125,131,138,145, + 157,164,168,177,181,188,193,1,6,0,0 + }; + staticData->serializedATN = antlr4::atn::SerializedATNView(serializedATNSegment, sizeof(serializedATNSegment) / sizeof(serializedATNSegment[0])); + + antlr4::atn::ATNDeserializer deserializer; + staticData->atn = deserializer.deserialize(staticData->serializedATN); + + const size_t count = staticData->atn->getNumberOfDecisions(); + staticData->decisionToDFA.reserve(count); + for (size_t i = 0; i < count; i++) { + staticData->decisionToDFA.emplace_back(staticData->atn->getDecisionState(i), i); + } + numcallexerLexerStaticData = std::move(staticData); +} + +} + +NumCalLexer::NumCalLexer(CharStream *input) : Lexer(input) { + NumCalLexer::initialize(); + _interpreter = new atn::LexerATNSimulator(this, *numcallexerLexerStaticData->atn, numcallexerLexerStaticData->decisionToDFA, numcallexerLexerStaticData->sharedContextCache); +} + +NumCalLexer::~NumCalLexer() { + delete _interpreter; +} + +std::string NumCalLexer::getGrammarFileName() const { + return "NumCal.g4"; +} + +const std::vector& NumCalLexer::getRuleNames() const { + return numcallexerLexerStaticData->ruleNames; +} + +const std::vector& NumCalLexer::getChannelNames() const { + return numcallexerLexerStaticData->channelNames; +} + +const std::vector& NumCalLexer::getModeNames() const { + return numcallexerLexerStaticData->modeNames; +} + +const dfa::Vocabulary& NumCalLexer::getVocabulary() const { + return numcallexerLexerStaticData->vocabulary; +} + +antlr4::atn::SerializedATNView NumCalLexer::getSerializedATN() const { + return numcallexerLexerStaticData->serializedATN; +} + +const atn::ATN& NumCalLexer::getATN() const { + return *numcallexerLexerStaticData->atn; +} + + + + +void NumCalLexer::initialize() { +#if ANTLR4_USE_THREAD_LOCAL_CACHE + numcallexerLexerInitialize(); +#else + ::antlr4::internal::call_once(numcallexerLexerOnceFlag, numcallexerLexerInitialize); +#endif +} diff --git a/src/grammar/NumCal/NumCalLexer.h b/src/grammar/NumCal/NumCalLexer.h new file mode 100644 index 0000000..1db2799 --- /dev/null +++ b/src/grammar/NumCal/NumCalLexer.h @@ -0,0 +1,52 @@ + +// Generated from NumCal.g4 by ANTLR 4.13.2 + +#pragma once + + +#include "antlr4-runtime.h" + + + + +class NumCalLexer : public antlr4::Lexer { +public: + enum { + LeftParen = 1, RightParen = 2, LeftShift = 3, RightShift = 4, Plus = 5, + Minus = 6, Star = 7, Div = 8, Mod = 9, And = 10, Or = 11, Caret = 12, + Tilde = 13, LessThan = 14, Colon = 15, LeftBracket = 16, RightBracket = 17, + IntegerConstant = 18, Whitespace = 19 + }; + + explicit NumCalLexer(antlr4::CharStream *input); + + ~NumCalLexer() override; + + + std::string getGrammarFileName() const override; + + const std::vector& getRuleNames() const override; + + const std::vector& getChannelNames() const override; + + const std::vector& getModeNames() const override; + + const antlr4::dfa::Vocabulary& getVocabulary() const override; + + antlr4::atn::SerializedATNView getSerializedATN() const override; + + const antlr4::atn::ATN& getATN() const override; + + // By default the static state used to implement the lexer is lazily initialized during the first + // call to the constructor. You can call this function if you wish to initialize the static state + // ahead of time. + static void initialize(); + +private: + + // Individual action functions triggered by action() above. + + // Individual semantic predicate functions triggered by sempred() above. + +}; + diff --git a/src/grammar/NumCal/NumCalParser.cpp b/src/grammar/NumCal/NumCalParser.cpp new file mode 100644 index 0000000..83ee025 --- /dev/null +++ b/src/grammar/NumCal/NumCalParser.cpp @@ -0,0 +1,1285 @@ + +// Generated from NumCal.g4 by ANTLR 4.13.2 + + +#include "NumCalVisitor.h" + +#include "NumCalParser.h" + + +using namespace antlrcpp; + +using namespace antlr4; + +namespace { + +struct NumCalParserStaticData final { + NumCalParserStaticData(std::vector ruleNames, + std::vector literalNames, + std::vector symbolicNames) + : ruleNames(std::move(ruleNames)), literalNames(std::move(literalNames)), + symbolicNames(std::move(symbolicNames)), + vocabulary(this->literalNames, this->symbolicNames) {} + + NumCalParserStaticData(const NumCalParserStaticData&) = delete; + NumCalParserStaticData(NumCalParserStaticData&&) = delete; + NumCalParserStaticData& operator=(const NumCalParserStaticData&) = delete; + NumCalParserStaticData& operator=(NumCalParserStaticData&&) = delete; + + std::vector decisionToDFA; + antlr4::atn::PredictionContextCache sharedContextCache; + const std::vector ruleNames; + const std::vector literalNames; + const std::vector symbolicNames; + const antlr4::dfa::Vocabulary vocabulary; + antlr4::atn::SerializedATNView serializedATN; + std::unique_ptr atn; +}; + +::antlr4::internal::OnceFlag numcalParserOnceFlag; +#if ANTLR4_USE_THREAD_LOCAL_CACHE +static thread_local +#endif +std::unique_ptr numcalParserStaticData = nullptr; + +void numcalParserInitialize() { +#if ANTLR4_USE_THREAD_LOCAL_CACHE + if (numcalParserStaticData != nullptr) { + return; + } +#else + assert(numcalParserStaticData == nullptr); +#endif + auto staticData = std::make_unique( + std::vector{ + "primaryExpression", "unaryExpression", "unaryOperator", "castExpression", + "multiplicativeExpression", "additiveExpression", "shiftExpression", + "andExpression", "exclusiveOrExpression", "inclusiveOrExpression", + "assignmentExpression", "entryExpression", "prefixGoto" + }, + std::vector{ + "", "'('", "')'", "'<<'", "'>>'", "'+'", "'-'", "'*'", "'/'", "'%'", + "'&'", "'|'", "'^'", "'~'", "'<'", "':'", "'['", "']'" + }, + std::vector{ + "", "LeftParen", "RightParen", "LeftShift", "RightShift", "Plus", + "Minus", "Star", "Div", "Mod", "And", "Or", "Caret", "Tilde", "LessThan", + "Colon", "LeftBracket", "RightBracket", "IntegerConstant", "Whitespace" + } + ); + static const int32_t serializedATNSegment[] = { + 4,1,19,133,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7,6,2, + 7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,1,0,1,0,1,0,1,0,1, + 0,3,0,32,8,0,1,1,1,1,1,1,1,1,3,1,38,8,1,1,2,1,2,1,3,1,3,3,3,44,8,3,1, + 4,1,4,1,4,5,4,49,8,4,10,4,12,4,52,9,4,1,5,1,5,1,5,5,5,57,8,5,10,5,12, + 5,60,9,5,1,6,1,6,1,6,5,6,65,8,6,10,6,12,6,68,9,6,1,7,1,7,1,7,5,7,73,8, + 7,10,7,12,7,76,9,7,1,8,1,8,1,8,5,8,81,8,8,10,8,12,8,84,9,8,1,9,1,9,1, + 9,5,9,89,8,9,10,9,12,9,92,9,9,1,10,1,10,3,10,96,8,10,1,11,3,11,99,8,11, + 1,11,1,11,1,11,1,11,1,11,3,11,106,8,11,1,11,1,11,1,11,1,11,1,11,1,11, + 3,11,114,8,11,1,11,1,11,1,11,1,11,1,11,1,11,1,11,3,11,123,8,11,1,11,1, + 11,1,11,1,11,3,11,129,8,11,1,12,1,12,1,12,0,0,13,0,2,4,6,8,10,12,14,16, + 18,20,22,24,0,5,2,0,5,6,13,13,1,0,7,9,1,0,5,6,1,0,3,4,2,0,5,6,14,14,136, + 0,31,1,0,0,0,2,37,1,0,0,0,4,39,1,0,0,0,6,43,1,0,0,0,8,45,1,0,0,0,10,53, + 1,0,0,0,12,61,1,0,0,0,14,69,1,0,0,0,16,77,1,0,0,0,18,85,1,0,0,0,20,95, + 1,0,0,0,22,128,1,0,0,0,24,130,1,0,0,0,26,32,5,18,0,0,27,28,5,1,0,0,28, + 29,3,20,10,0,29,30,5,2,0,0,30,32,1,0,0,0,31,26,1,0,0,0,31,27,1,0,0,0, + 32,1,1,0,0,0,33,38,3,0,0,0,34,35,3,4,2,0,35,36,3,6,3,0,36,38,1,0,0,0, + 37,33,1,0,0,0,37,34,1,0,0,0,38,3,1,0,0,0,39,40,7,0,0,0,40,5,1,0,0,0,41, + 44,3,2,1,0,42,44,5,18,0,0,43,41,1,0,0,0,43,42,1,0,0,0,44,7,1,0,0,0,45, + 50,3,6,3,0,46,47,7,1,0,0,47,49,3,6,3,0,48,46,1,0,0,0,49,52,1,0,0,0,50, + 48,1,0,0,0,50,51,1,0,0,0,51,9,1,0,0,0,52,50,1,0,0,0,53,58,3,8,4,0,54, + 55,7,2,0,0,55,57,3,8,4,0,56,54,1,0,0,0,57,60,1,0,0,0,58,56,1,0,0,0,58, + 59,1,0,0,0,59,11,1,0,0,0,60,58,1,0,0,0,61,66,3,10,5,0,62,63,7,3,0,0,63, + 65,3,10,5,0,64,62,1,0,0,0,65,68,1,0,0,0,66,64,1,0,0,0,66,67,1,0,0,0,67, + 13,1,0,0,0,68,66,1,0,0,0,69,74,3,12,6,0,70,71,5,10,0,0,71,73,3,12,6,0, + 72,70,1,0,0,0,73,76,1,0,0,0,74,72,1,0,0,0,74,75,1,0,0,0,75,15,1,0,0,0, + 76,74,1,0,0,0,77,82,3,14,7,0,78,79,5,12,0,0,79,81,3,14,7,0,80,78,1,0, + 0,0,81,84,1,0,0,0,82,80,1,0,0,0,82,83,1,0,0,0,83,17,1,0,0,0,84,82,1,0, + 0,0,85,90,3,16,8,0,86,87,5,11,0,0,87,89,3,16,8,0,88,86,1,0,0,0,89,92, + 1,0,0,0,90,88,1,0,0,0,90,91,1,0,0,0,91,19,1,0,0,0,92,90,1,0,0,0,93,96, + 5,18,0,0,94,96,3,18,9,0,95,93,1,0,0,0,95,94,1,0,0,0,96,21,1,0,0,0,97, + 99,3,24,12,0,98,97,1,0,0,0,98,99,1,0,0,0,99,100,1,0,0,0,100,101,5,18, + 0,0,101,129,5,0,0,1,102,103,3,24,12,0,103,104,5,15,0,0,104,106,1,0,0, + 0,105,102,1,0,0,0,105,106,1,0,0,0,106,107,1,0,0,0,107,108,3,20,10,0,108, + 109,5,0,0,1,109,129,1,0,0,0,110,111,3,24,12,0,111,112,5,16,0,0,112,114, + 1,0,0,0,113,110,1,0,0,0,113,114,1,0,0,0,114,115,1,0,0,0,115,116,3,20, + 10,0,116,117,5,17,0,0,117,118,5,0,0,1,118,129,1,0,0,0,119,120,3,24,12, + 0,120,121,5,1,0,0,121,123,1,0,0,0,122,119,1,0,0,0,122,123,1,0,0,0,123, + 124,1,0,0,0,124,125,3,20,10,0,125,126,5,2,0,0,126,127,5,0,0,1,127,129, + 1,0,0,0,128,98,1,0,0,0,128,105,1,0,0,0,128,113,1,0,0,0,128,122,1,0,0, + 0,129,23,1,0,0,0,130,131,7,4,0,0,131,25,1,0,0,0,15,31,37,43,50,58,66, + 74,82,90,95,98,105,113,122,128 + }; + staticData->serializedATN = antlr4::atn::SerializedATNView(serializedATNSegment, sizeof(serializedATNSegment) / sizeof(serializedATNSegment[0])); + + antlr4::atn::ATNDeserializer deserializer; + staticData->atn = deserializer.deserialize(staticData->serializedATN); + + const size_t count = staticData->atn->getNumberOfDecisions(); + staticData->decisionToDFA.reserve(count); + for (size_t i = 0; i < count; i++) { + staticData->decisionToDFA.emplace_back(staticData->atn->getDecisionState(i), i); + } + numcalParserStaticData = std::move(staticData); +} + +} + +NumCalParser::NumCalParser(TokenStream *input) : NumCalParser(input, antlr4::atn::ParserATNSimulatorOptions()) {} + +NumCalParser::NumCalParser(TokenStream *input, const antlr4::atn::ParserATNSimulatorOptions &options) : Parser(input) { + NumCalParser::initialize(); + _interpreter = new atn::ParserATNSimulator(this, *numcalParserStaticData->atn, numcalParserStaticData->decisionToDFA, numcalParserStaticData->sharedContextCache, options); +} + +NumCalParser::~NumCalParser() { + delete _interpreter; +} + +const atn::ATN& NumCalParser::getATN() const { + return *numcalParserStaticData->atn; +} + +std::string NumCalParser::getGrammarFileName() const { + return "NumCal.g4"; +} + +const std::vector& NumCalParser::getRuleNames() const { + return numcalParserStaticData->ruleNames; +} + +const dfa::Vocabulary& NumCalParser::getVocabulary() const { + return numcalParserStaticData->vocabulary; +} + +antlr4::atn::SerializedATNView NumCalParser::getSerializedATN() const { + return numcalParserStaticData->serializedATN; +} + + +//----------------- PrimaryExpressionContext ------------------------------------------------------------------ + +NumCalParser::PrimaryExpressionContext::PrimaryExpressionContext(ParserRuleContext *parent, size_t invokingState) + : ParserRuleContext(parent, invokingState) { +} + +tree::TerminalNode* NumCalParser::PrimaryExpressionContext::IntegerConstant() { + return getToken(NumCalParser::IntegerConstant, 0); +} + +tree::TerminalNode* NumCalParser::PrimaryExpressionContext::LeftParen() { + return getToken(NumCalParser::LeftParen, 0); +} + +NumCalParser::AssignmentExpressionContext* NumCalParser::PrimaryExpressionContext::assignmentExpression() { + return getRuleContext(0); +} + +tree::TerminalNode* NumCalParser::PrimaryExpressionContext::RightParen() { + return getToken(NumCalParser::RightParen, 0); +} + + +size_t NumCalParser::PrimaryExpressionContext::getRuleIndex() const { + return NumCalParser::RulePrimaryExpression; +} + + +std::any NumCalParser::PrimaryExpressionContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitPrimaryExpression(this); + else + return visitor->visitChildren(this); +} + +NumCalParser::PrimaryExpressionContext* NumCalParser::primaryExpression() { + PrimaryExpressionContext *_localctx = _tracker.createInstance(_ctx, getState()); + enterRule(_localctx, 0, NumCalParser::RulePrimaryExpression); + +#if __cplusplus > 201703L + auto onExit = finally([=, this] { +#else + auto onExit = finally([=] { +#endif + exitRule(); + }); + try { + setState(31); + _errHandler->sync(this); + switch (_input->LA(1)) { + case NumCalParser::IntegerConstant: { + enterOuterAlt(_localctx, 1); + setState(26); + match(NumCalParser::IntegerConstant); + break; + } + + case NumCalParser::LeftParen: { + enterOuterAlt(_localctx, 2); + setState(27); + match(NumCalParser::LeftParen); + setState(28); + assignmentExpression(); + setState(29); + match(NumCalParser::RightParen); + break; + } + + default: + throw NoViableAltException(this); + } + + } + catch (RecognitionException &e) { + _errHandler->reportError(this, e); + _localctx->exception = std::current_exception(); + _errHandler->recover(this, _localctx->exception); + } + + return _localctx; +} + +//----------------- UnaryExpressionContext ------------------------------------------------------------------ + +NumCalParser::UnaryExpressionContext::UnaryExpressionContext(ParserRuleContext *parent, size_t invokingState) + : ParserRuleContext(parent, invokingState) { +} + +NumCalParser::PrimaryExpressionContext* NumCalParser::UnaryExpressionContext::primaryExpression() { + return getRuleContext(0); +} + +NumCalParser::UnaryOperatorContext* NumCalParser::UnaryExpressionContext::unaryOperator() { + return getRuleContext(0); +} + +NumCalParser::CastExpressionContext* NumCalParser::UnaryExpressionContext::castExpression() { + return getRuleContext(0); +} + + +size_t NumCalParser::UnaryExpressionContext::getRuleIndex() const { + return NumCalParser::RuleUnaryExpression; +} + + +std::any NumCalParser::UnaryExpressionContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitUnaryExpression(this); + else + return visitor->visitChildren(this); +} + +NumCalParser::UnaryExpressionContext* NumCalParser::unaryExpression() { + UnaryExpressionContext *_localctx = _tracker.createInstance(_ctx, getState()); + enterRule(_localctx, 2, NumCalParser::RuleUnaryExpression); + +#if __cplusplus > 201703L + auto onExit = finally([=, this] { +#else + auto onExit = finally([=] { +#endif + exitRule(); + }); + try { + setState(37); + _errHandler->sync(this); + switch (_input->LA(1)) { + case NumCalParser::LeftParen: + case NumCalParser::IntegerConstant: { + enterOuterAlt(_localctx, 1); + setState(33); + primaryExpression(); + break; + } + + case NumCalParser::Plus: + case NumCalParser::Minus: + case NumCalParser::Tilde: { + enterOuterAlt(_localctx, 2); + setState(34); + unaryOperator(); + setState(35); + castExpression(); + break; + } + + default: + throw NoViableAltException(this); + } + + } + catch (RecognitionException &e) { + _errHandler->reportError(this, e); + _localctx->exception = std::current_exception(); + _errHandler->recover(this, _localctx->exception); + } + + return _localctx; +} + +//----------------- UnaryOperatorContext ------------------------------------------------------------------ + +NumCalParser::UnaryOperatorContext::UnaryOperatorContext(ParserRuleContext *parent, size_t invokingState) + : ParserRuleContext(parent, invokingState) { +} + +tree::TerminalNode* NumCalParser::UnaryOperatorContext::Plus() { + return getToken(NumCalParser::Plus, 0); +} + +tree::TerminalNode* NumCalParser::UnaryOperatorContext::Minus() { + return getToken(NumCalParser::Minus, 0); +} + +tree::TerminalNode* NumCalParser::UnaryOperatorContext::Tilde() { + return getToken(NumCalParser::Tilde, 0); +} + + +size_t NumCalParser::UnaryOperatorContext::getRuleIndex() const { + return NumCalParser::RuleUnaryOperator; +} + + +std::any NumCalParser::UnaryOperatorContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitUnaryOperator(this); + else + return visitor->visitChildren(this); +} + +NumCalParser::UnaryOperatorContext* NumCalParser::unaryOperator() { + UnaryOperatorContext *_localctx = _tracker.createInstance(_ctx, getState()); + enterRule(_localctx, 4, NumCalParser::RuleUnaryOperator); + size_t _la = 0; + +#if __cplusplus > 201703L + auto onExit = finally([=, this] { +#else + auto onExit = finally([=] { +#endif + exitRule(); + }); + try { + enterOuterAlt(_localctx, 1); + setState(39); + _la = _input->LA(1); + if (!((((_la & ~ 0x3fULL) == 0) && + ((1ULL << _la) & 8288) != 0))) { + _errHandler->recoverInline(this); + } + else { + _errHandler->reportMatch(this); + consume(); + } + + } + catch (RecognitionException &e) { + _errHandler->reportError(this, e); + _localctx->exception = std::current_exception(); + _errHandler->recover(this, _localctx->exception); + } + + return _localctx; +} + +//----------------- CastExpressionContext ------------------------------------------------------------------ + +NumCalParser::CastExpressionContext::CastExpressionContext(ParserRuleContext *parent, size_t invokingState) + : ParserRuleContext(parent, invokingState) { +} + +NumCalParser::UnaryExpressionContext* NumCalParser::CastExpressionContext::unaryExpression() { + return getRuleContext(0); +} + +tree::TerminalNode* NumCalParser::CastExpressionContext::IntegerConstant() { + return getToken(NumCalParser::IntegerConstant, 0); +} + + +size_t NumCalParser::CastExpressionContext::getRuleIndex() const { + return NumCalParser::RuleCastExpression; +} + + +std::any NumCalParser::CastExpressionContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitCastExpression(this); + else + return visitor->visitChildren(this); +} + +NumCalParser::CastExpressionContext* NumCalParser::castExpression() { + CastExpressionContext *_localctx = _tracker.createInstance(_ctx, getState()); + enterRule(_localctx, 6, NumCalParser::RuleCastExpression); + +#if __cplusplus > 201703L + auto onExit = finally([=, this] { +#else + auto onExit = finally([=] { +#endif + exitRule(); + }); + try { + setState(43); + _errHandler->sync(this); + switch (getInterpreter()->adaptivePredict(_input, 2, _ctx)) { + case 1: { + enterOuterAlt(_localctx, 1); + setState(41); + unaryExpression(); + break; + } + + case 2: { + enterOuterAlt(_localctx, 2); + setState(42); + match(NumCalParser::IntegerConstant); + break; + } + + default: + break; + } + + } + catch (RecognitionException &e) { + _errHandler->reportError(this, e); + _localctx->exception = std::current_exception(); + _errHandler->recover(this, _localctx->exception); + } + + return _localctx; +} + +//----------------- MultiplicativeExpressionContext ------------------------------------------------------------------ + +NumCalParser::MultiplicativeExpressionContext::MultiplicativeExpressionContext(ParserRuleContext *parent, size_t invokingState) + : ParserRuleContext(parent, invokingState) { +} + +std::vector NumCalParser::MultiplicativeExpressionContext::castExpression() { + return getRuleContexts(); +} + +NumCalParser::CastExpressionContext* NumCalParser::MultiplicativeExpressionContext::castExpression(size_t i) { + return getRuleContext(i); +} + +std::vector NumCalParser::MultiplicativeExpressionContext::Star() { + return getTokens(NumCalParser::Star); +} + +tree::TerminalNode* NumCalParser::MultiplicativeExpressionContext::Star(size_t i) { + return getToken(NumCalParser::Star, i); +} + +std::vector NumCalParser::MultiplicativeExpressionContext::Div() { + return getTokens(NumCalParser::Div); +} + +tree::TerminalNode* NumCalParser::MultiplicativeExpressionContext::Div(size_t i) { + return getToken(NumCalParser::Div, i); +} + +std::vector NumCalParser::MultiplicativeExpressionContext::Mod() { + return getTokens(NumCalParser::Mod); +} + +tree::TerminalNode* NumCalParser::MultiplicativeExpressionContext::Mod(size_t i) { + return getToken(NumCalParser::Mod, i); +} + + +size_t NumCalParser::MultiplicativeExpressionContext::getRuleIndex() const { + return NumCalParser::RuleMultiplicativeExpression; +} + + +std::any NumCalParser::MultiplicativeExpressionContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitMultiplicativeExpression(this); + else + return visitor->visitChildren(this); +} + +NumCalParser::MultiplicativeExpressionContext* NumCalParser::multiplicativeExpression() { + MultiplicativeExpressionContext *_localctx = _tracker.createInstance(_ctx, getState()); + enterRule(_localctx, 8, NumCalParser::RuleMultiplicativeExpression); + size_t _la = 0; + +#if __cplusplus > 201703L + auto onExit = finally([=, this] { +#else + auto onExit = finally([=] { +#endif + exitRule(); + }); + try { + enterOuterAlt(_localctx, 1); + setState(45); + castExpression(); + setState(50); + _errHandler->sync(this); + _la = _input->LA(1); + while ((((_la & ~ 0x3fULL) == 0) && + ((1ULL << _la) & 896) != 0)) { + setState(46); + _la = _input->LA(1); + if (!((((_la & ~ 0x3fULL) == 0) && + ((1ULL << _la) & 896) != 0))) { + _errHandler->recoverInline(this); + } + else { + _errHandler->reportMatch(this); + consume(); + } + setState(47); + castExpression(); + setState(52); + _errHandler->sync(this); + _la = _input->LA(1); + } + + } + catch (RecognitionException &e) { + _errHandler->reportError(this, e); + _localctx->exception = std::current_exception(); + _errHandler->recover(this, _localctx->exception); + } + + return _localctx; +} + +//----------------- AdditiveExpressionContext ------------------------------------------------------------------ + +NumCalParser::AdditiveExpressionContext::AdditiveExpressionContext(ParserRuleContext *parent, size_t invokingState) + : ParserRuleContext(parent, invokingState) { +} + +std::vector NumCalParser::AdditiveExpressionContext::multiplicativeExpression() { + return getRuleContexts(); +} + +NumCalParser::MultiplicativeExpressionContext* NumCalParser::AdditiveExpressionContext::multiplicativeExpression(size_t i) { + return getRuleContext(i); +} + +std::vector NumCalParser::AdditiveExpressionContext::Plus() { + return getTokens(NumCalParser::Plus); +} + +tree::TerminalNode* NumCalParser::AdditiveExpressionContext::Plus(size_t i) { + return getToken(NumCalParser::Plus, i); +} + +std::vector NumCalParser::AdditiveExpressionContext::Minus() { + return getTokens(NumCalParser::Minus); +} + +tree::TerminalNode* NumCalParser::AdditiveExpressionContext::Minus(size_t i) { + return getToken(NumCalParser::Minus, i); +} + + +size_t NumCalParser::AdditiveExpressionContext::getRuleIndex() const { + return NumCalParser::RuleAdditiveExpression; +} + + +std::any NumCalParser::AdditiveExpressionContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitAdditiveExpression(this); + else + return visitor->visitChildren(this); +} + +NumCalParser::AdditiveExpressionContext* NumCalParser::additiveExpression() { + AdditiveExpressionContext *_localctx = _tracker.createInstance(_ctx, getState()); + enterRule(_localctx, 10, NumCalParser::RuleAdditiveExpression); + size_t _la = 0; + +#if __cplusplus > 201703L + auto onExit = finally([=, this] { +#else + auto onExit = finally([=] { +#endif + exitRule(); + }); + try { + enterOuterAlt(_localctx, 1); + setState(53); + multiplicativeExpression(); + setState(58); + _errHandler->sync(this); + _la = _input->LA(1); + while (_la == NumCalParser::Plus + + || _la == NumCalParser::Minus) { + setState(54); + _la = _input->LA(1); + if (!(_la == NumCalParser::Plus + + || _la == NumCalParser::Minus)) { + _errHandler->recoverInline(this); + } + else { + _errHandler->reportMatch(this); + consume(); + } + setState(55); + multiplicativeExpression(); + setState(60); + _errHandler->sync(this); + _la = _input->LA(1); + } + + } + catch (RecognitionException &e) { + _errHandler->reportError(this, e); + _localctx->exception = std::current_exception(); + _errHandler->recover(this, _localctx->exception); + } + + return _localctx; +} + +//----------------- ShiftExpressionContext ------------------------------------------------------------------ + +NumCalParser::ShiftExpressionContext::ShiftExpressionContext(ParserRuleContext *parent, size_t invokingState) + : ParserRuleContext(parent, invokingState) { +} + +std::vector NumCalParser::ShiftExpressionContext::additiveExpression() { + return getRuleContexts(); +} + +NumCalParser::AdditiveExpressionContext* NumCalParser::ShiftExpressionContext::additiveExpression(size_t i) { + return getRuleContext(i); +} + +std::vector NumCalParser::ShiftExpressionContext::LeftShift() { + return getTokens(NumCalParser::LeftShift); +} + +tree::TerminalNode* NumCalParser::ShiftExpressionContext::LeftShift(size_t i) { + return getToken(NumCalParser::LeftShift, i); +} + +std::vector NumCalParser::ShiftExpressionContext::RightShift() { + return getTokens(NumCalParser::RightShift); +} + +tree::TerminalNode* NumCalParser::ShiftExpressionContext::RightShift(size_t i) { + return getToken(NumCalParser::RightShift, i); +} + + +size_t NumCalParser::ShiftExpressionContext::getRuleIndex() const { + return NumCalParser::RuleShiftExpression; +} + + +std::any NumCalParser::ShiftExpressionContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitShiftExpression(this); + else + return visitor->visitChildren(this); +} + +NumCalParser::ShiftExpressionContext* NumCalParser::shiftExpression() { + ShiftExpressionContext *_localctx = _tracker.createInstance(_ctx, getState()); + enterRule(_localctx, 12, NumCalParser::RuleShiftExpression); + size_t _la = 0; + +#if __cplusplus > 201703L + auto onExit = finally([=, this] { +#else + auto onExit = finally([=] { +#endif + exitRule(); + }); + try { + enterOuterAlt(_localctx, 1); + setState(61); + additiveExpression(); + setState(66); + _errHandler->sync(this); + _la = _input->LA(1); + while (_la == NumCalParser::LeftShift + + || _la == NumCalParser::RightShift) { + setState(62); + _la = _input->LA(1); + if (!(_la == NumCalParser::LeftShift + + || _la == NumCalParser::RightShift)) { + _errHandler->recoverInline(this); + } + else { + _errHandler->reportMatch(this); + consume(); + } + setState(63); + additiveExpression(); + setState(68); + _errHandler->sync(this); + _la = _input->LA(1); + } + + } + catch (RecognitionException &e) { + _errHandler->reportError(this, e); + _localctx->exception = std::current_exception(); + _errHandler->recover(this, _localctx->exception); + } + + return _localctx; +} + +//----------------- AndExpressionContext ------------------------------------------------------------------ + +NumCalParser::AndExpressionContext::AndExpressionContext(ParserRuleContext *parent, size_t invokingState) + : ParserRuleContext(parent, invokingState) { +} + +std::vector NumCalParser::AndExpressionContext::shiftExpression() { + return getRuleContexts(); +} + +NumCalParser::ShiftExpressionContext* NumCalParser::AndExpressionContext::shiftExpression(size_t i) { + return getRuleContext(i); +} + +std::vector NumCalParser::AndExpressionContext::And() { + return getTokens(NumCalParser::And); +} + +tree::TerminalNode* NumCalParser::AndExpressionContext::And(size_t i) { + return getToken(NumCalParser::And, i); +} + + +size_t NumCalParser::AndExpressionContext::getRuleIndex() const { + return NumCalParser::RuleAndExpression; +} + + +std::any NumCalParser::AndExpressionContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitAndExpression(this); + else + return visitor->visitChildren(this); +} + +NumCalParser::AndExpressionContext* NumCalParser::andExpression() { + AndExpressionContext *_localctx = _tracker.createInstance(_ctx, getState()); + enterRule(_localctx, 14, NumCalParser::RuleAndExpression); + size_t _la = 0; + +#if __cplusplus > 201703L + auto onExit = finally([=, this] { +#else + auto onExit = finally([=] { +#endif + exitRule(); + }); + try { + enterOuterAlt(_localctx, 1); + setState(69); + shiftExpression(); + setState(74); + _errHandler->sync(this); + _la = _input->LA(1); + while (_la == NumCalParser::And) { + setState(70); + match(NumCalParser::And); + setState(71); + shiftExpression(); + setState(76); + _errHandler->sync(this); + _la = _input->LA(1); + } + + } + catch (RecognitionException &e) { + _errHandler->reportError(this, e); + _localctx->exception = std::current_exception(); + _errHandler->recover(this, _localctx->exception); + } + + return _localctx; +} + +//----------------- ExclusiveOrExpressionContext ------------------------------------------------------------------ + +NumCalParser::ExclusiveOrExpressionContext::ExclusiveOrExpressionContext(ParserRuleContext *parent, size_t invokingState) + : ParserRuleContext(parent, invokingState) { +} + +std::vector NumCalParser::ExclusiveOrExpressionContext::andExpression() { + return getRuleContexts(); +} + +NumCalParser::AndExpressionContext* NumCalParser::ExclusiveOrExpressionContext::andExpression(size_t i) { + return getRuleContext(i); +} + +std::vector NumCalParser::ExclusiveOrExpressionContext::Caret() { + return getTokens(NumCalParser::Caret); +} + +tree::TerminalNode* NumCalParser::ExclusiveOrExpressionContext::Caret(size_t i) { + return getToken(NumCalParser::Caret, i); +} + + +size_t NumCalParser::ExclusiveOrExpressionContext::getRuleIndex() const { + return NumCalParser::RuleExclusiveOrExpression; +} + + +std::any NumCalParser::ExclusiveOrExpressionContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitExclusiveOrExpression(this); + else + return visitor->visitChildren(this); +} + +NumCalParser::ExclusiveOrExpressionContext* NumCalParser::exclusiveOrExpression() { + ExclusiveOrExpressionContext *_localctx = _tracker.createInstance(_ctx, getState()); + enterRule(_localctx, 16, NumCalParser::RuleExclusiveOrExpression); + size_t _la = 0; + +#if __cplusplus > 201703L + auto onExit = finally([=, this] { +#else + auto onExit = finally([=] { +#endif + exitRule(); + }); + try { + enterOuterAlt(_localctx, 1); + setState(77); + andExpression(); + setState(82); + _errHandler->sync(this); + _la = _input->LA(1); + while (_la == NumCalParser::Caret) { + setState(78); + match(NumCalParser::Caret); + setState(79); + andExpression(); + setState(84); + _errHandler->sync(this); + _la = _input->LA(1); + } + + } + catch (RecognitionException &e) { + _errHandler->reportError(this, e); + _localctx->exception = std::current_exception(); + _errHandler->recover(this, _localctx->exception); + } + + return _localctx; +} + +//----------------- InclusiveOrExpressionContext ------------------------------------------------------------------ + +NumCalParser::InclusiveOrExpressionContext::InclusiveOrExpressionContext(ParserRuleContext *parent, size_t invokingState) + : ParserRuleContext(parent, invokingState) { +} + +std::vector NumCalParser::InclusiveOrExpressionContext::exclusiveOrExpression() { + return getRuleContexts(); +} + +NumCalParser::ExclusiveOrExpressionContext* NumCalParser::InclusiveOrExpressionContext::exclusiveOrExpression(size_t i) { + return getRuleContext(i); +} + +std::vector NumCalParser::InclusiveOrExpressionContext::Or() { + return getTokens(NumCalParser::Or); +} + +tree::TerminalNode* NumCalParser::InclusiveOrExpressionContext::Or(size_t i) { + return getToken(NumCalParser::Or, i); +} + + +size_t NumCalParser::InclusiveOrExpressionContext::getRuleIndex() const { + return NumCalParser::RuleInclusiveOrExpression; +} + + +std::any NumCalParser::InclusiveOrExpressionContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitInclusiveOrExpression(this); + else + return visitor->visitChildren(this); +} + +NumCalParser::InclusiveOrExpressionContext* NumCalParser::inclusiveOrExpression() { + InclusiveOrExpressionContext *_localctx = _tracker.createInstance(_ctx, getState()); + enterRule(_localctx, 18, NumCalParser::RuleInclusiveOrExpression); + size_t _la = 0; + +#if __cplusplus > 201703L + auto onExit = finally([=, this] { +#else + auto onExit = finally([=] { +#endif + exitRule(); + }); + try { + enterOuterAlt(_localctx, 1); + setState(85); + exclusiveOrExpression(); + setState(90); + _errHandler->sync(this); + _la = _input->LA(1); + while (_la == NumCalParser::Or) { + setState(86); + match(NumCalParser::Or); + setState(87); + exclusiveOrExpression(); + setState(92); + _errHandler->sync(this); + _la = _input->LA(1); + } + + } + catch (RecognitionException &e) { + _errHandler->reportError(this, e); + _localctx->exception = std::current_exception(); + _errHandler->recover(this, _localctx->exception); + } + + return _localctx; +} + +//----------------- AssignmentExpressionContext ------------------------------------------------------------------ + +NumCalParser::AssignmentExpressionContext::AssignmentExpressionContext(ParserRuleContext *parent, size_t invokingState) + : ParserRuleContext(parent, invokingState) { +} + +tree::TerminalNode* NumCalParser::AssignmentExpressionContext::IntegerConstant() { + return getToken(NumCalParser::IntegerConstant, 0); +} + +NumCalParser::InclusiveOrExpressionContext* NumCalParser::AssignmentExpressionContext::inclusiveOrExpression() { + return getRuleContext(0); +} + + +size_t NumCalParser::AssignmentExpressionContext::getRuleIndex() const { + return NumCalParser::RuleAssignmentExpression; +} + + +std::any NumCalParser::AssignmentExpressionContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitAssignmentExpression(this); + else + return visitor->visitChildren(this); +} + +NumCalParser::AssignmentExpressionContext* NumCalParser::assignmentExpression() { + AssignmentExpressionContext *_localctx = _tracker.createInstance(_ctx, getState()); + enterRule(_localctx, 20, NumCalParser::RuleAssignmentExpression); + +#if __cplusplus > 201703L + auto onExit = finally([=, this] { +#else + auto onExit = finally([=] { +#endif + exitRule(); + }); + try { + setState(95); + _errHandler->sync(this); + switch (getInterpreter()->adaptivePredict(_input, 9, _ctx)) { + case 1: { + enterOuterAlt(_localctx, 1); + setState(93); + match(NumCalParser::IntegerConstant); + break; + } + + case 2: { + enterOuterAlt(_localctx, 2); + setState(94); + inclusiveOrExpression(); + break; + } + + default: + break; + } + + } + catch (RecognitionException &e) { + _errHandler->reportError(this, e); + _localctx->exception = std::current_exception(); + _errHandler->recover(this, _localctx->exception); + } + + return _localctx; +} + +//----------------- EntryExpressionContext ------------------------------------------------------------------ + +NumCalParser::EntryExpressionContext::EntryExpressionContext(ParserRuleContext *parent, size_t invokingState) + : ParserRuleContext(parent, invokingState) { +} + +tree::TerminalNode* NumCalParser::EntryExpressionContext::IntegerConstant() { + return getToken(NumCalParser::IntegerConstant, 0); +} + +tree::TerminalNode* NumCalParser::EntryExpressionContext::EOF() { + return getToken(NumCalParser::EOF, 0); +} + +NumCalParser::PrefixGotoContext* NumCalParser::EntryExpressionContext::prefixGoto() { + return getRuleContext(0); +} + +NumCalParser::AssignmentExpressionContext* NumCalParser::EntryExpressionContext::assignmentExpression() { + return getRuleContext(0); +} + +tree::TerminalNode* NumCalParser::EntryExpressionContext::Colon() { + return getToken(NumCalParser::Colon, 0); +} + +tree::TerminalNode* NumCalParser::EntryExpressionContext::RightBracket() { + return getToken(NumCalParser::RightBracket, 0); +} + +tree::TerminalNode* NumCalParser::EntryExpressionContext::LeftBracket() { + return getToken(NumCalParser::LeftBracket, 0); +} + +tree::TerminalNode* NumCalParser::EntryExpressionContext::RightParen() { + return getToken(NumCalParser::RightParen, 0); +} + +tree::TerminalNode* NumCalParser::EntryExpressionContext::LeftParen() { + return getToken(NumCalParser::LeftParen, 0); +} + + +size_t NumCalParser::EntryExpressionContext::getRuleIndex() const { + return NumCalParser::RuleEntryExpression; +} + + +std::any NumCalParser::EntryExpressionContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitEntryExpression(this); + else + return visitor->visitChildren(this); +} + +NumCalParser::EntryExpressionContext* NumCalParser::entryExpression() { + EntryExpressionContext *_localctx = _tracker.createInstance(_ctx, getState()); + enterRule(_localctx, 22, NumCalParser::RuleEntryExpression); + size_t _la = 0; + +#if __cplusplus > 201703L + auto onExit = finally([=, this] { +#else + auto onExit = finally([=] { +#endif + exitRule(); + }); + try { + setState(128); + _errHandler->sync(this); + switch (getInterpreter()->adaptivePredict(_input, 14, _ctx)) { + case 1: { + enterOuterAlt(_localctx, 1); + setState(98); + _errHandler->sync(this); + + _la = _input->LA(1); + if ((((_la & ~ 0x3fULL) == 0) && + ((1ULL << _la) & 16480) != 0)) { + setState(97); + prefixGoto(); + } + setState(100); + match(NumCalParser::IntegerConstant); + setState(101); + match(NumCalParser::EOF); + break; + } + + case 2: { + enterOuterAlt(_localctx, 2); + setState(105); + _errHandler->sync(this); + + switch (getInterpreter()->adaptivePredict(_input, 11, _ctx)) { + case 1: { + setState(102); + prefixGoto(); + setState(103); + match(NumCalParser::Colon); + break; + } + + default: + break; + } + setState(107); + assignmentExpression(); + setState(108); + match(NumCalParser::EOF); + break; + } + + case 3: { + enterOuterAlt(_localctx, 3); + setState(113); + _errHandler->sync(this); + + switch (getInterpreter()->adaptivePredict(_input, 12, _ctx)) { + case 1: { + setState(110); + prefixGoto(); + setState(111); + match(NumCalParser::LeftBracket); + break; + } + + default: + break; + } + setState(115); + assignmentExpression(); + setState(116); + match(NumCalParser::RightBracket); + setState(117); + match(NumCalParser::EOF); + break; + } + + case 4: { + enterOuterAlt(_localctx, 4); + setState(122); + _errHandler->sync(this); + + switch (getInterpreter()->adaptivePredict(_input, 13, _ctx)) { + case 1: { + setState(119); + prefixGoto(); + setState(120); + match(NumCalParser::LeftParen); + break; + } + + default: + break; + } + setState(124); + assignmentExpression(); + setState(125); + match(NumCalParser::RightParen); + setState(126); + match(NumCalParser::EOF); + break; + } + + default: + break; + } + + } + catch (RecognitionException &e) { + _errHandler->reportError(this, e); + _localctx->exception = std::current_exception(); + _errHandler->recover(this, _localctx->exception); + } + + return _localctx; +} + +//----------------- PrefixGotoContext ------------------------------------------------------------------ + +NumCalParser::PrefixGotoContext::PrefixGotoContext(ParserRuleContext *parent, size_t invokingState) + : ParserRuleContext(parent, invokingState) { +} + +tree::TerminalNode* NumCalParser::PrefixGotoContext::Plus() { + return getToken(NumCalParser::Plus, 0); +} + +tree::TerminalNode* NumCalParser::PrefixGotoContext::Minus() { + return getToken(NumCalParser::Minus, 0); +} + +tree::TerminalNode* NumCalParser::PrefixGotoContext::LessThan() { + return getToken(NumCalParser::LessThan, 0); +} + + +size_t NumCalParser::PrefixGotoContext::getRuleIndex() const { + return NumCalParser::RulePrefixGoto; +} + + +std::any NumCalParser::PrefixGotoContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitPrefixGoto(this); + else + return visitor->visitChildren(this); +} + +NumCalParser::PrefixGotoContext* NumCalParser::prefixGoto() { + PrefixGotoContext *_localctx = _tracker.createInstance(_ctx, getState()); + enterRule(_localctx, 24, NumCalParser::RulePrefixGoto); + size_t _la = 0; + +#if __cplusplus > 201703L + auto onExit = finally([=, this] { +#else + auto onExit = finally([=] { +#endif + exitRule(); + }); + try { + enterOuterAlt(_localctx, 1); + setState(130); + _la = _input->LA(1); + if (!((((_la & ~ 0x3fULL) == 0) && + ((1ULL << _la) & 16480) != 0))) { + _errHandler->recoverInline(this); + } + else { + _errHandler->reportMatch(this); + consume(); + } + + } + catch (RecognitionException &e) { + _errHandler->reportError(this, e); + _localctx->exception = std::current_exception(); + _errHandler->recover(this, _localctx->exception); + } + + return _localctx; +} + +void NumCalParser::initialize() { +#if ANTLR4_USE_THREAD_LOCAL_CACHE + numcalParserInitialize(); +#else + ::antlr4::internal::call_once(numcalParserOnceFlag, numcalParserInitialize); +#endif +} diff --git a/src/grammar/NumCal/NumCalParser.h b/src/grammar/NumCal/NumCalParser.h new file mode 100644 index 0000000..a7963b5 --- /dev/null +++ b/src/grammar/NumCal/NumCalParser.h @@ -0,0 +1,282 @@ + +// Generated from NumCal.g4 by ANTLR 4.13.2 + +#pragma once + + +#include "antlr4-runtime.h" + + + + +class NumCalParser : public antlr4::Parser { +public: + enum { + LeftParen = 1, RightParen = 2, LeftShift = 3, RightShift = 4, Plus = 5, + Minus = 6, Star = 7, Div = 8, Mod = 9, And = 10, Or = 11, Caret = 12, + Tilde = 13, LessThan = 14, Colon = 15, LeftBracket = 16, RightBracket = 17, + IntegerConstant = 18, Whitespace = 19 + }; + + enum { + RulePrimaryExpression = 0, RuleUnaryExpression = 1, RuleUnaryOperator = 2, + RuleCastExpression = 3, RuleMultiplicativeExpression = 4, RuleAdditiveExpression = 5, + RuleShiftExpression = 6, RuleAndExpression = 7, RuleExclusiveOrExpression = 8, + RuleInclusiveOrExpression = 9, RuleAssignmentExpression = 10, RuleEntryExpression = 11, + RulePrefixGoto = 12 + }; + + explicit NumCalParser(antlr4::TokenStream *input); + + NumCalParser(antlr4::TokenStream *input, const antlr4::atn::ParserATNSimulatorOptions &options); + + ~NumCalParser() override; + + std::string getGrammarFileName() const override; + + const antlr4::atn::ATN& getATN() const override; + + const std::vector& getRuleNames() const override; + + const antlr4::dfa::Vocabulary& getVocabulary() const override; + + antlr4::atn::SerializedATNView getSerializedATN() const override; + + + class PrimaryExpressionContext; + class UnaryExpressionContext; + class UnaryOperatorContext; + class CastExpressionContext; + class MultiplicativeExpressionContext; + class AdditiveExpressionContext; + class ShiftExpressionContext; + class AndExpressionContext; + class ExclusiveOrExpressionContext; + class InclusiveOrExpressionContext; + class AssignmentExpressionContext; + class EntryExpressionContext; + class PrefixGotoContext; + + class PrimaryExpressionContext : public antlr4::ParserRuleContext { + public: + PrimaryExpressionContext(antlr4::ParserRuleContext *parent, size_t invokingState); + virtual size_t getRuleIndex() const override; + antlr4::tree::TerminalNode *IntegerConstant(); + antlr4::tree::TerminalNode *LeftParen(); + AssignmentExpressionContext *assignmentExpression(); + antlr4::tree::TerminalNode *RightParen(); + + + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + + }; + + PrimaryExpressionContext* primaryExpression(); + + class UnaryExpressionContext : public antlr4::ParserRuleContext { + public: + UnaryExpressionContext(antlr4::ParserRuleContext *parent, size_t invokingState); + virtual size_t getRuleIndex() const override; + PrimaryExpressionContext *primaryExpression(); + UnaryOperatorContext *unaryOperator(); + CastExpressionContext *castExpression(); + + + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + + }; + + UnaryExpressionContext* unaryExpression(); + + class UnaryOperatorContext : public antlr4::ParserRuleContext { + public: + UnaryOperatorContext(antlr4::ParserRuleContext *parent, size_t invokingState); + virtual size_t getRuleIndex() const override; + antlr4::tree::TerminalNode *Plus(); + antlr4::tree::TerminalNode *Minus(); + antlr4::tree::TerminalNode *Tilde(); + + + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + + }; + + UnaryOperatorContext* unaryOperator(); + + class CastExpressionContext : public antlr4::ParserRuleContext { + public: + CastExpressionContext(antlr4::ParserRuleContext *parent, size_t invokingState); + virtual size_t getRuleIndex() const override; + UnaryExpressionContext *unaryExpression(); + antlr4::tree::TerminalNode *IntegerConstant(); + + + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + + }; + + CastExpressionContext* castExpression(); + + class MultiplicativeExpressionContext : public antlr4::ParserRuleContext { + public: + MultiplicativeExpressionContext(antlr4::ParserRuleContext *parent, size_t invokingState); + virtual size_t getRuleIndex() const override; + std::vector castExpression(); + CastExpressionContext* castExpression(size_t i); + std::vector Star(); + antlr4::tree::TerminalNode* Star(size_t i); + std::vector Div(); + antlr4::tree::TerminalNode* Div(size_t i); + std::vector Mod(); + antlr4::tree::TerminalNode* Mod(size_t i); + + + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + + }; + + MultiplicativeExpressionContext* multiplicativeExpression(); + + class AdditiveExpressionContext : public antlr4::ParserRuleContext { + public: + AdditiveExpressionContext(antlr4::ParserRuleContext *parent, size_t invokingState); + virtual size_t getRuleIndex() const override; + std::vector multiplicativeExpression(); + MultiplicativeExpressionContext* multiplicativeExpression(size_t i); + std::vector Plus(); + antlr4::tree::TerminalNode* Plus(size_t i); + std::vector Minus(); + antlr4::tree::TerminalNode* Minus(size_t i); + + + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + + }; + + AdditiveExpressionContext* additiveExpression(); + + class ShiftExpressionContext : public antlr4::ParserRuleContext { + public: + ShiftExpressionContext(antlr4::ParserRuleContext *parent, size_t invokingState); + virtual size_t getRuleIndex() const override; + std::vector additiveExpression(); + AdditiveExpressionContext* additiveExpression(size_t i); + std::vector LeftShift(); + antlr4::tree::TerminalNode* LeftShift(size_t i); + std::vector RightShift(); + antlr4::tree::TerminalNode* RightShift(size_t i); + + + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + + }; + + ShiftExpressionContext* shiftExpression(); + + class AndExpressionContext : public antlr4::ParserRuleContext { + public: + AndExpressionContext(antlr4::ParserRuleContext *parent, size_t invokingState); + virtual size_t getRuleIndex() const override; + std::vector shiftExpression(); + ShiftExpressionContext* shiftExpression(size_t i); + std::vector And(); + antlr4::tree::TerminalNode* And(size_t i); + + + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + + }; + + AndExpressionContext* andExpression(); + + class ExclusiveOrExpressionContext : public antlr4::ParserRuleContext { + public: + ExclusiveOrExpressionContext(antlr4::ParserRuleContext *parent, size_t invokingState); + virtual size_t getRuleIndex() const override; + std::vector andExpression(); + AndExpressionContext* andExpression(size_t i); + std::vector Caret(); + antlr4::tree::TerminalNode* Caret(size_t i); + + + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + + }; + + ExclusiveOrExpressionContext* exclusiveOrExpression(); + + class InclusiveOrExpressionContext : public antlr4::ParserRuleContext { + public: + InclusiveOrExpressionContext(antlr4::ParserRuleContext *parent, size_t invokingState); + virtual size_t getRuleIndex() const override; + std::vector exclusiveOrExpression(); + ExclusiveOrExpressionContext* exclusiveOrExpression(size_t i); + std::vector Or(); + antlr4::tree::TerminalNode* Or(size_t i); + + + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + + }; + + InclusiveOrExpressionContext* inclusiveOrExpression(); + + class AssignmentExpressionContext : public antlr4::ParserRuleContext { + public: + AssignmentExpressionContext(antlr4::ParserRuleContext *parent, size_t invokingState); + virtual size_t getRuleIndex() const override; + antlr4::tree::TerminalNode *IntegerConstant(); + InclusiveOrExpressionContext *inclusiveOrExpression(); + + + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + + }; + + AssignmentExpressionContext* assignmentExpression(); + + class EntryExpressionContext : public antlr4::ParserRuleContext { + public: + EntryExpressionContext(antlr4::ParserRuleContext *parent, size_t invokingState); + virtual size_t getRuleIndex() const override; + antlr4::tree::TerminalNode *IntegerConstant(); + antlr4::tree::TerminalNode *EOF(); + PrefixGotoContext *prefixGoto(); + AssignmentExpressionContext *assignmentExpression(); + antlr4::tree::TerminalNode *Colon(); + antlr4::tree::TerminalNode *RightBracket(); + antlr4::tree::TerminalNode *LeftBracket(); + antlr4::tree::TerminalNode *RightParen(); + antlr4::tree::TerminalNode *LeftParen(); + + + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + + }; + + EntryExpressionContext* entryExpression(); + + class PrefixGotoContext : public antlr4::ParserRuleContext { + public: + PrefixGotoContext(antlr4::ParserRuleContext *parent, size_t invokingState); + virtual size_t getRuleIndex() const override; + antlr4::tree::TerminalNode *Plus(); + antlr4::tree::TerminalNode *Minus(); + antlr4::tree::TerminalNode *LessThan(); + + + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + + }; + + PrefixGotoContext* prefixGoto(); + + + // By default the static state used to implement the parser is lazily initialized during the first + // call to the constructor. You can call this function if you wish to initialize the static state + // ahead of time. + static void initialize(); + +private: +}; + diff --git a/src/grammar/NumCal/NumCalVisitor.cpp b/src/grammar/NumCal/NumCalVisitor.cpp new file mode 100644 index 0000000..905f5c4 --- /dev/null +++ b/src/grammar/NumCal/NumCalVisitor.cpp @@ -0,0 +1,7 @@ + +// Generated from NumCal.g4 by ANTLR 4.13.2 + + +#include "NumCalVisitor.h" + + diff --git a/src/grammar/NumCal/NumCalVisitor.h b/src/grammar/NumCal/NumCalVisitor.h new file mode 100644 index 0000000..00aadee --- /dev/null +++ b/src/grammar/NumCal/NumCalVisitor.h @@ -0,0 +1,50 @@ + +// Generated from NumCal.g4 by ANTLR 4.13.2 + +#pragma once + + +#include "antlr4-runtime.h" +#include "NumCalParser.h" + + + +/** + * This class defines an abstract visitor for a parse tree + * produced by NumCalParser. + */ +class NumCalVisitor : public antlr4::tree::AbstractParseTreeVisitor { +public: + + /** + * Visit parse trees produced by NumCalParser. + */ + virtual std::any visitPrimaryExpression(NumCalParser::PrimaryExpressionContext *context) = 0; + + virtual std::any visitUnaryExpression(NumCalParser::UnaryExpressionContext *context) = 0; + + virtual std::any visitUnaryOperator(NumCalParser::UnaryOperatorContext *context) = 0; + + virtual std::any visitCastExpression(NumCalParser::CastExpressionContext *context) = 0; + + virtual std::any visitMultiplicativeExpression(NumCalParser::MultiplicativeExpressionContext *context) = 0; + + virtual std::any visitAdditiveExpression(NumCalParser::AdditiveExpressionContext *context) = 0; + + virtual std::any visitShiftExpression(NumCalParser::ShiftExpressionContext *context) = 0; + + virtual std::any visitAndExpression(NumCalParser::AndExpressionContext *context) = 0; + + virtual std::any visitExclusiveOrExpression(NumCalParser::ExclusiveOrExpressionContext *context) = 0; + + virtual std::any visitInclusiveOrExpression(NumCalParser::InclusiveOrExpressionContext *context) = 0; + + virtual std::any visitAssignmentExpression(NumCalParser::AssignmentExpressionContext *context) = 0; + + virtual std::any visitEntryExpression(NumCalParser::EntryExpressionContext *context) = 0; + + virtual std::any visitPrefixGoto(NumCalParser::PrefixGotoContext *context) = 0; + + +}; + diff --git a/src/grammar/NumCal/antlr4-how-to-use.txt b/src/grammar/NumCal/antlr4-how-to-use.txt new file mode 100644 index 0000000..fbde28e --- /dev/null +++ b/src/grammar/NumCal/antlr4-how-to-use.txt @@ -0,0 +1 @@ +antlr4 -Dlanguage=Cpp -visitor -no-listener NumCal.g4 -o . \ No newline at end of file diff --git a/src/model/bookmarksmodel.cpp b/src/model/bookmarksmodel.cpp index bc6b2a9..4a9bbde 100644 --- a/src/model/bookmarksmodel.cpp +++ b/src/model/bookmarksmodel.cpp @@ -69,5 +69,5 @@ QVariant BookMarksModel::headerData(int section, Qt::Orientation orientation, void BookMarksModel::setDocument(QHexDocument *newDoc) { _doc = newDoc; connect(newDoc, &QHexDocument::bookMarkChanged, this, - [=] { emit this->layoutChanged(); }); + [=] { Q_EMIT this->layoutChanged(); }); } diff --git a/src/model/checksummodel.cpp b/src/model/checksummodel.cpp index 63dec7a..a61f550 100644 --- a/src/model/checksummodel.cpp +++ b/src/model/checksummodel.cpp @@ -30,7 +30,7 @@ void CheckSumModel::setCheckSumData(QCryptographicHash::Algorithm algorithm, _checkSumData[algorithm] = data; auto index = this->index( Utilities::supportedHashAlgorithms().indexOf(algorithm), 0); - emit dataChanged(index, index); + Q_EMIT dataChanged(index, index); } } @@ -43,7 +43,7 @@ void CheckSumModel::clearData() { for (auto p = _checkSumData.begin(); p != _checkSumData.end(); ++p) { p->clear(); } - emit dataChanged( + Q_EMIT dataChanged( this->index(0, 0), this->index(Utilities::supportedHashAlgorithms().size() - 1, 0)); } diff --git a/src/model/dbgcallstackmodel.cpp b/src/model/dbgcallstackmodel.cpp index 2b3c356..6acbbf7 100644 --- a/src/model/dbgcallstackmodel.cpp +++ b/src/model/dbgcallstackmodel.cpp @@ -81,5 +81,5 @@ QVariant DbgCallStackModel::headerData(int section, Qt::Orientation orientation, void DbgCallStackModel::updateData( const QList &callstack) { _stack = callstack; - emit layoutChanged(); + Q_EMIT layoutChanged(); } diff --git a/src/model/dbgvarshowmodel.cpp b/src/model/dbgvarshowmodel.cpp index d16fc8e..0b514af 100644 --- a/src/model/dbgvarshowmodel.cpp +++ b/src/model/dbgvarshowmodel.cpp @@ -65,5 +65,5 @@ QVariant DbgVarShowModel::headerData(int section, Qt::Orientation orientation, void DbgVarShowModel::updateData( const QVector &varinfos) { _vars = varinfos; - emit layoutChanged(); + Q_EMIT layoutChanged(); } diff --git a/src/model/findresultmodel.cpp b/src/model/findresultmodel.cpp index 1952395..e200bb9 100644 --- a/src/model/findresultmodel.cpp +++ b/src/model/findresultmodel.cpp @@ -123,7 +123,7 @@ QString FindResultModel::encoding() const { return m_encoding; } void FindResultModel::setEncoding(const QString &newEncoding) { if (m_encoding != newEncoding) { m_encoding = newEncoding; - emit dataChanged(index(0, 4), index(rowCount(QModelIndex()), 4)); + Q_EMIT dataChanged(index(0, 4), index(rowCount(QModelIndex()), 4)); } } @@ -150,7 +150,7 @@ FindResultModel::FindResult FindResultModel::resultAt(qsizetype index) const { void FindResultModel::clear() { m_results.clear(); m_findData.clear(); - emit layoutChanged(); + Q_EMIT layoutChanged(); } QList::size_type FindResultModel::size() const { diff --git a/src/model/metadatamodel.cpp b/src/model/metadatamodel.cpp index 9258f8a..62ada00 100644 --- a/src/model/metadatamodel.cpp +++ b/src/model/metadatamodel.cpp @@ -119,5 +119,5 @@ QVariant MetaDataModel::headerData(int section, Qt::Orientation orientation, void MetaDataModel::setDocument(QHexDocument *newDoc) { _doc = newDoc; connect(newDoc, &QHexDocument::metaDataChanged, this, - [=] { emit this->layoutChanged(); }); + [=] { Q_EMIT this->layoutChanged(); }); } diff --git a/src/model/numshowmodel.cpp b/src/model/numshowmodel.cpp index c22673f..127ff59 100644 --- a/src/model/numshowmodel.cpp +++ b/src/model/numshowmodel.cpp @@ -38,7 +38,7 @@ void NumShowModel::setNumData(NumTableIndex index, const QString &data) { } else { m_num[index] = data; } - emit dataChanged(this->index(index, 0), this->index(index, 0)); + Q_EMIT dataChanged(this->index(index, 0), this->index(index, 0)); } QString NumShowModel::numData(NumTableIndex index) const {