diff --git a/src/lib/component/controller/ErrorController.cpp b/src/lib/component/controller/ErrorController.cpp index 441f1dce..39b290ca 100644 --- a/src/lib/component/controller/ErrorController.cpp +++ b/src/lib/component/controller/ErrorController.cpp @@ -22,7 +22,7 @@ void ErrorController::handleMessage(MessageFinishedParsing* message) auto errors = m_storageAccess->getAllErrors(); - for (const StorageError& error : errors) + for (const ErrorInfo& error : errors) { getView()->addError(error); } @@ -30,7 +30,7 @@ void ErrorController::handleMessage(MessageFinishedParsing* message) void ErrorController::handleMessage(MessageNewErrors* message) { - for (const StorageError& error : message->errors) + for (const ErrorInfo& error : message->errors) { getView()->addError(error); } @@ -53,7 +53,7 @@ void ErrorController::handleMessage(MessageShowErrors* message) auto errors = m_storageAccess->getAllErrors(); - for (const StorageError& error : errors) + for (const ErrorInfo& error : errors) { getView()->addError(error); } diff --git a/src/lib/component/view/ErrorView.h b/src/lib/component/view/ErrorView.h index d7f9434a..9d45dbe3 100644 --- a/src/lib/component/view/ErrorView.h +++ b/src/lib/component/view/ErrorView.h @@ -2,7 +2,7 @@ #define ERROR_VIEW_H #include "component/view/View.h" -#include "data/StorageTypes.h" +#include "data/ErrorInfo.h" class ErrorView : public View @@ -17,7 +17,7 @@ public: virtual void clear() = 0; - virtual void addError(const StorageError& error) = 0; + virtual void addError(const ErrorInfo& error) = 0; virtual void setErrorId(Id errorId) = 0; }; diff --git a/src/lib/data/ErrorFilter.h b/src/lib/data/ErrorFilter.h index 5c0ff9e4..6413c1ba 100644 --- a/src/lib/data/ErrorFilter.h +++ b/src/lib/data/ErrorFilter.h @@ -16,26 +16,13 @@ struct ErrorFilter bool filter(const ErrorInfo& info) const { - if (!error && !info.isFatal && info.isIndexed) + if (!error && !info.fatal && info.indexed) return false; - if (!fatal && info.isFatal && info.isIndexed) + if (!fatal && info.fatal && info.indexed) return false; - if (!unindexedError && !info.isFatal && !info.isIndexed) + if (!unindexedError && !info.fatal && !info.indexed) return false; - if (!unindexedFatal && info.isFatal && !info.isIndexed) - return false; - return true; - } - - bool filter(const StorageError& storageError) const - { - if (!error && !storageError.fatal && storageError.indexed) - return false; - if (!fatal && storageError.fatal && storageError.indexed) - return false; - if (!unindexedError && !storageError.fatal && !storageError.indexed) - return false; - if (!unindexedFatal && storageError.fatal && !storageError.indexed) + if (!unindexedFatal && info.fatal && !info.indexed) return false; return true; } diff --git a/src/lib/data/ErrorInfo.h b/src/lib/data/ErrorInfo.h index 63b230ff..386cab65 100644 --- a/src/lib/data/ErrorInfo.h +++ b/src/lib/data/ErrorInfo.h @@ -1,32 +1,8 @@ #ifndef ERROR_INFO_H #define ERROR_INFO_H -#include "utility/file/FilePath.h" -#include "utility/types.h" +#include "data/StorageTypes.h" -struct ErrorInfo -{ - ErrorInfo() - : id(0) - , isFatal(false) - , isIndexed(false) - { - } - - ErrorInfo(const std::string& message, const FilePath& filePath, Id id, bool isFatal, bool isIndexed) - : message(message) - , filePath(filePath) - , id(id) - , isFatal(isFatal) - , isIndexed(isIndexed) - { - } - - std::string message; - FilePath filePath; - Id id; - bool isFatal; - bool isIndexed; -}; +typedef StorageError ErrorInfo; #endif // ERROR_INFO_H diff --git a/src/lib/data/IntermediateStorage.cpp b/src/lib/data/IntermediateStorage.cpp index 1f34658d..2b6ebaa5 100644 --- a/src/lib/data/IntermediateStorage.cpp +++ b/src/lib/data/IntermediateStorage.cpp @@ -160,16 +160,16 @@ void IntermediateStorage::addCommentLocation(Id fileNodeId, uint startLine, uint )); } -void IntermediateStorage::addError(const std::string& message, bool fatal, bool indexed, const std::string& filePath, uint startLine, uint startCol) +void IntermediateStorage::addError(const std::string& message, const FilePath& filePath, uint startLine, uint startCol, bool fatal, bool indexed) { m_errors.push_back(StorageError( 0, message, - fatal, - indexed, filePath, startLine, - startCol + startCol, + fatal, + indexed )); } diff --git a/src/lib/data/IntermediateStorage.h b/src/lib/data/IntermediateStorage.h index 63bd3221..46a85f98 100644 --- a/src/lib/data/IntermediateStorage.h +++ b/src/lib/data/IntermediateStorage.h @@ -24,7 +24,7 @@ public: virtual void addSourceLocation(Id elementId, Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type); virtual void addComponentAccess(Id nodeId , int type); virtual void addCommentLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol); - virtual void addError(const std::string& message, bool fatal, bool indexed, const std::string& filePath, uint startLine, uint startCol); + virtual void addError(const std::string& message, const FilePath& filePath, uint startLine, uint startCol, bool fatal, bool indexed); virtual void forEachFile(std::function callback) const; virtual void forEachNode(std::function callback) const; diff --git a/src/lib/data/PersistentStorage.cpp b/src/lib/data/PersistentStorage.cpp index e5d98e5f..15565eec 100644 --- a/src/lib/data/PersistentStorage.cpp +++ b/src/lib/data/PersistentStorage.cpp @@ -139,15 +139,15 @@ void PersistentStorage::addCommentLocation(Id fileNodeId, uint startLine, uint s } void PersistentStorage::addError( - const std::string& message, bool fatal, bool indexed, const std::string& filePath, uint startLine, uint startCol) + const std::string& message, const FilePath& filePath, uint startLine, uint startCol, bool fatal, bool indexed) { m_sqliteStorage.addError( message, - fatal, - indexed, filePath, startLine, - startCol + startCol, + fatal, + indexed ); } @@ -231,7 +231,7 @@ void PersistentStorage::finishInjection() if (m_preInjectionErrorCount != errors.size()) { - MessageNewErrors(std::vector(errors.begin() + m_preInjectionErrorCount, errors.end())).dispatchImmediately(); + MessageNewErrors(std::vector(errors.begin() + m_preInjectionErrorCount, errors.end())).dispatchImmediately(); } } @@ -1035,13 +1035,13 @@ ErrorCountInfo PersistentStorage::getErrorCount() const return ErrorCountInfo(); } -std::vector PersistentStorage::getErrors() const +std::vector PersistentStorage::getErrors() const { LOG_ERROR("This should never be called."); - return std::vector(); + return std::vector(); } -std::vector PersistentStorage::getAllErrors() const +std::vector PersistentStorage::getAllErrors() const { return m_sqliteStorage.getAllErrors(); } @@ -1052,8 +1052,8 @@ std::shared_ptr PersistentStorage::getErrorTokenLocatio std::shared_ptr errorCollection = std::make_shared(); - std::vector storageErrors = m_sqliteStorage.getAllErrors(); - for (const StorageError& error : storageErrors) + *errors = m_sqliteStorage.getAllErrors(); + for (const ErrorInfo& error : *errors) { // Set first bit to 1 to avoid collisions Id locationId = ~(~size_t(0) >> 1) + error.id; @@ -1061,7 +1061,6 @@ std::shared_ptr PersistentStorage::getErrorTokenLocatio errorCollection->addTokenLocation( locationId, error.id, error.filePath, error.lineNumber, error.columnNumber, error.lineNumber, error.columnNumber )->setType(LOCATION_ERROR); - errors->push_back(ErrorInfo(error.message, error.filePath, error.id, error.fatal, error.indexed)); } return errorCollection; diff --git a/src/lib/data/PersistentStorage.h b/src/lib/data/PersistentStorage.h index cd805d62..6d15f009 100644 --- a/src/lib/data/PersistentStorage.h +++ b/src/lib/data/PersistentStorage.h @@ -34,7 +34,7 @@ public: virtual void addSourceLocation(Id elementId, Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type); virtual void addComponentAccess(Id nodeId , int type); virtual void addCommentLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol); - virtual void addError(const std::string& message, bool fatal, bool indexed, const std::string& filePath, uint startLine, uint startCol); + virtual void addError(const std::string& message, const FilePath& filePath, uint startLine, uint startCol, bool fatal, bool indexed); virtual void forEachFile(std::function callback) const; virtual void forEachNode(std::function callback) const; @@ -114,8 +114,8 @@ public: virtual StorageStats getStorageStats() const; virtual ErrorCountInfo getErrorCount() const; - virtual std::vector getErrors() const; - virtual std::vector getAllErrors() const; + virtual std::vector getErrors() const; + virtual std::vector getAllErrors() const; virtual std::shared_ptr getErrorTokenLocations(std::vector* errors) const; diff --git a/src/lib/data/SqliteStorage.cpp b/src/lib/data/SqliteStorage.cpp index d3eeac1f..7e6b4a5a 100644 --- a/src/lib/data/SqliteStorage.cpp +++ b/src/lib/data/SqliteStorage.cpp @@ -215,7 +215,7 @@ Id SqliteStorage::addCommentLocation(Id fileNodeId, uint startLine, uint startCo return m_database.lastRowId(); } -Id SqliteStorage::addError(const std::string& message, bool fatal, bool indexed, const std::string& filePath, uint lineNumber, uint columnNumber) +Id SqliteStorage::addError(const std::string& message, const FilePath& filePath, uint lineNumber, uint columnNumber, bool fatal, bool indexed) { std::string sanitizedMessage = utility::replace(message, "'", "''"); @@ -225,7 +225,7 @@ Id SqliteStorage::addError(const std::string& message, bool fatal, bool indexed, "SELECT * FROM error WHERE " "message == ? AND " "fatal == " + std::to_string(fatal) + " AND " - "file_path == '" + filePath + "' AND " + "file_path == '" + filePath.str() + "' AND " "line_number == " + std::to_string(lineNumber) + " AND " "column_number == " + std::to_string(columnNumber) + ";" ).c_str()); @@ -242,7 +242,7 @@ Id SqliteStorage::addError(const std::string& message, bool fatal, bool indexed, stmt = m_database.compileStatement(( "INSERT INTO error(message, fatal, indexed, file_path, line_number, column_number) " - "VALUES (?, " + std::to_string(fatal) + ", " + std::to_string(indexed) + ", '" + filePath + + "VALUES (?, " + std::to_string(fatal) + ", " + std::to_string(indexed) + ", '" + filePath.str() + "', " + std::to_string(lineNumber) + ", " + std::to_string(columnNumber) + ");" ).c_str()); @@ -1084,7 +1084,7 @@ std::vector SqliteStorage::getAll(const std::string& if (lineNumber != -1 && columnNumber != -1) { - errors.push_back(StorageError(id, message, fatal, indexed, filePath, lineNumber, columnNumber)); + errors.push_back(StorageError(id, message, filePath, lineNumber, columnNumber, fatal, indexed)); id++; } diff --git a/src/lib/data/SqliteStorage.h b/src/lib/data/SqliteStorage.h index c5175a83..025bb85c 100644 --- a/src/lib/data/SqliteStorage.h +++ b/src/lib/data/SqliteStorage.h @@ -47,7 +47,7 @@ public: Id addSourceLocation(Id elementId, Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type); Id addComponentAccess(Id nodeId, int type); Id addCommentLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol); - Id addError(const std::string& message, bool fatal, bool indexed, const std::string& filePath, uint lineNumber, uint columnNumber); + Id addError(const std::string& message, const FilePath& filePath, uint lineNumber, uint columnNumber, bool fatal, bool indexed); void removeElement(Id id); void removeElements(const std::vector& ids); diff --git a/src/lib/data/Storage.cpp b/src/lib/data/Storage.cpp index 21ff310e..1c5620cc 100644 --- a/src/lib/data/Storage.cpp +++ b/src/lib/data/Storage.cpp @@ -160,11 +160,11 @@ void Storage::inject(Storage* injected) { addError( injectedData.message, - injectedData.fatal, - injectedData.indexed, injectedData.filePath, injectedData.lineNumber, - injectedData.columnNumber + injectedData.columnNumber, + injectedData.fatal, + injectedData.indexed ); } ); diff --git a/src/lib/data/Storage.h b/src/lib/data/Storage.h index eb7015b5..c0bb646e 100644 --- a/src/lib/data/Storage.h +++ b/src/lib/data/Storage.h @@ -22,7 +22,7 @@ public: virtual void addSourceLocation(Id elementId, Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type) = 0; virtual void addComponentAccess(Id nodeId , int type) = 0; virtual void addCommentLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol) = 0; - virtual void addError(const std::string& message, bool fatal, bool indexed, const std::string& filePath, uint startLine, uint startCol) = 0; + virtual void addError(const std::string& message, const FilePath& filePath, uint startLine, uint startCol, bool fatal, bool indexed) = 0; virtual void forEachFile(std::function callback) const = 0; virtual void forEachNode(std::function callback) const = 0; diff --git a/src/lib/data/StorageTypes.h b/src/lib/data/StorageTypes.h index 16461668..80aaf464 100644 --- a/src/lib/data/StorageTypes.h +++ b/src/lib/data/StorageTypes.h @@ -3,6 +3,7 @@ #include +#include "utility/file/FilePath.h" #include "utility/types.h" #include "data/DefinitionType.h" @@ -171,30 +172,39 @@ struct StorageError StorageError() : id(0) , message("") - , fatal(0) - , indexed(0) - , filePath("") , lineNumber(-1) , columnNumber(-1) + , fatal(0) + , indexed(0) {} - StorageError(Id id, const std::string& message, bool fatal, bool indexed, const std::string& filePath, uint lineNumber, uint columnNumber) + StorageError( + Id id, + const std::string& message, + const FilePath& filePath, + uint lineNumber, + uint columnNumber, + bool fatal, + bool indexed + ) : id(id) , message(message) - , fatal(fatal) - , indexed(indexed) , filePath(filePath) , lineNumber(lineNumber) , columnNumber(columnNumber) + , fatal(fatal) + , indexed(indexed) {} Id id; std::string message; - bool fatal; - bool indexed; - std::string filePath; + + FilePath filePath; uint lineNumber; uint columnNumber; + + bool fatal; + bool indexed; }; #endif // STORAGE_TYPES_H diff --git a/src/lib/data/access/StorageAccess.h b/src/lib/data/access/StorageAccess.h index 4cd873b3..8f8342cb 100644 --- a/src/lib/data/access/StorageAccess.h +++ b/src/lib/data/access/StorageAccess.h @@ -15,7 +15,6 @@ #include "data/ErrorCountInfo.h" #include "data/ErrorInfo.h" #include "data/StorageStats.h" -#include "data/StorageTypes.h" class Graph; class TextAccess; @@ -70,8 +69,8 @@ public: virtual StorageStats getStorageStats() const = 0; virtual ErrorCountInfo getErrorCount() const = 0; - virtual std::vector getErrors() const = 0; - virtual std::vector getAllErrors() const = 0; + virtual std::vector getErrors() const = 0; + virtual std::vector getAllErrors() const = 0; virtual std::shared_ptr getErrorTokenLocations(std::vector* errors) const = 0; }; diff --git a/src/lib/data/access/StorageAccessProxy.cpp b/src/lib/data/access/StorageAccessProxy.cpp index 1ed2ad42..8b5ac8f4 100644 --- a/src/lib/data/access/StorageAccessProxy.cpp +++ b/src/lib/data/access/StorageAccessProxy.cpp @@ -274,8 +274,8 @@ ErrorCountInfo StorageAccessProxy::getErrorCount() const { ErrorCountInfo info; - std::vector storageErrors = getErrors(); - for (const StorageError& error : storageErrors) + std::vector errors = getErrors(); + for (const ErrorInfo& error : errors) { info.total++; @@ -288,14 +288,14 @@ ErrorCountInfo StorageAccessProxy::getErrorCount() const return info; } -std::vector StorageAccessProxy::getErrors() const +std::vector StorageAccessProxy::getErrors() const { if (hasSubject()) { - std::vector errors = m_subject->getAllErrors();; - std::vector filteredErrors; + std::vector errors = m_subject->getAllErrors();; + std::vector filteredErrors; - for (const StorageError& error : errors) + for (const ErrorInfo& error : errors) { if (m_errorFilter.filter(error)) { @@ -306,17 +306,17 @@ std::vector StorageAccessProxy::getErrors() const return filteredErrors; } - return std::vector(); + return std::vector(); } -std::vector StorageAccessProxy::getAllErrors() const +std::vector StorageAccessProxy::getAllErrors() const { if (hasSubject()) { return m_subject->getAllErrors(); } - return std::vector(); + return std::vector(); } std::shared_ptr StorageAccessProxy::getErrorTokenLocations(std::vector* errors) const diff --git a/src/lib/data/access/StorageAccessProxy.h b/src/lib/data/access/StorageAccessProxy.h index da1c3e37..e266cc20 100644 --- a/src/lib/data/access/StorageAccessProxy.h +++ b/src/lib/data/access/StorageAccessProxy.h @@ -4,7 +4,6 @@ #include "data/access/StorageAccess.h" #include "data/ErrorFilter.h" -#include "data/StorageTypes.h" #include "utility/messaging/MessageListener.h" #include "utility/messaging/type/MessageErrorFilterChanged.h" @@ -65,8 +64,8 @@ public: virtual StorageStats getStorageStats() const; virtual ErrorCountInfo getErrorCount() const; - virtual std::vector getErrors() const; - virtual std::vector getAllErrors() const; + virtual std::vector getErrors() const; + virtual std::vector getAllErrors() const; virtual std::shared_ptr getErrorTokenLocations(std::vector* errors) const; diff --git a/src/lib/data/parser/ParserClientImpl.cpp b/src/lib/data/parser/ParserClientImpl.cpp index b434f0a9..c8a53f19 100644 --- a/src/lib/data/parser/ParserClientImpl.cpp +++ b/src/lib/data/parser/ParserClientImpl.cpp @@ -634,7 +634,7 @@ void ParserClientImpl::addError(const std::string& message, bool fatal, bool ind return; } - m_storage->addError(message, fatal, indexed, location.filePath.str(), location.startLineNumber, location.startColumnNumber); + m_storage->addError(message, location.filePath, location.startLineNumber, location.startColumnNumber, fatal, indexed); } void ParserClientImpl::log(std::string type, std::string str, const ParseLocation& location) const diff --git a/src/lib_gui/qt/element/QtCodeNavigator.cpp b/src/lib_gui/qt/element/QtCodeNavigator.cpp index 7d9efd83..fb781cde 100644 --- a/src/lib_gui/qt/element/QtCodeNavigator.cpp +++ b/src/lib_gui/qt/element/QtCodeNavigator.cpp @@ -230,7 +230,7 @@ size_t QtCodeNavigator::getFatalErrorCountForFile(const FilePath& filePath) cons for (const std::pair& p : m_errorInfos) { const ErrorInfo& error = p.second; - if (error.filePath == filePath && error.isFatal) + if (error.filePath == filePath && error.fatal) { fatalErrorCount++; } diff --git a/src/lib_gui/qt/view/QtErrorView.cpp b/src/lib_gui/qt/view/QtErrorView.cpp index 81c5f1a1..9cc4852a 100644 --- a/src/lib_gui/qt/view/QtErrorView.cpp +++ b/src/lib_gui/qt/view/QtErrorView.cpp @@ -119,7 +119,7 @@ void QtErrorView::clear() m_clearFunctor(); } -void QtErrorView::addError(const StorageError& error) +void QtErrorView::addError(const ErrorInfo& error) { m_addErrorFunctor(error); } @@ -133,7 +133,7 @@ void QtErrorView::doRefreshView() { m_model->removeRows(0, m_model->rowCount()); - for (StorageError error : m_errors) + for (ErrorInfo error : m_errors) { addErrorToTable(error); } @@ -149,7 +149,7 @@ void QtErrorView::doClear() m_errors.clear(); } -void QtErrorView::doAddError(const StorageError& error) +void QtErrorView::doAddError(const ErrorInfo& error) { m_errors.push_back(error); @@ -189,7 +189,7 @@ void QtErrorView::setStyleSheet() const ); } -void QtErrorView::addErrorToTable(const StorageError& error) +void QtErrorView::addErrorToTable(const ErrorInfo& error) { if (!isShownError(error)) { @@ -208,8 +208,8 @@ void QtErrorView::addErrorToTable(const StorageError& error) m_model->setItem(rowNumber, COLUMN::MESSAGE, new QStandardItem(error.message.c_str())); std::string errorPngPath = ResourcePaths::getGuiPath() + "/indexing_dialog/error.png"; m_model->item(rowNumber, COLUMN::MESSAGE)->setIcon(QIcon(QString(errorPngPath.c_str()))); - m_model->setItem(rowNumber, COLUMN::FILE, new QStandardItem(error.filePath.c_str())); - m_model->item(rowNumber, COLUMN::FILE)->setToolTip(error.filePath.c_str()); + m_model->setItem(rowNumber, COLUMN::FILE, new QStandardItem(error.filePath.str().c_str())); + m_model->item(rowNumber, COLUMN::FILE)->setToolTip(error.filePath.str().c_str()); m_model->setItem(rowNumber, COLUMN::LINE, new QStandardItem(QString::number(error.lineNumber))); m_model->setItem(rowNumber, COLUMN::INDEXED, new QStandardItem(error.indexed ? "yes" : "no")); m_model->setItem(rowNumber, COLUMN::ID, new QStandardItem(QString::number(error.id))); @@ -242,7 +242,7 @@ QCheckBox* QtErrorView::createFilterCheckbox(const QString& name, bool checked, return checkbox; } -bool QtErrorView::isShownError(const StorageError& error) +bool QtErrorView::isShownError(const ErrorInfo& error) { if (!error.fatal && error.indexed && m_showErrors->checkState() == Qt::Checked) { diff --git a/src/lib_gui/qt/view/QtErrorView.h b/src/lib_gui/qt/view/QtErrorView.h index 67d7da53..a724b091 100644 --- a/src/lib_gui/qt/view/QtErrorView.h +++ b/src/lib_gui/qt/view/QtErrorView.h @@ -29,7 +29,7 @@ public: // ErrorView implementation virtual void clear(); - virtual void addError(const StorageError& error); + virtual void addError(const ErrorInfo& error); virtual void setErrorId(Id errorId); private: @@ -44,19 +44,19 @@ private: void doRefreshView(); void doClear(); - void doAddError(const StorageError& error); + void doAddError(const ErrorInfo& error); void doSetErrorId(Id errorId); void setStyleSheet() const; - void addErrorToTable(const StorageError& error); + void addErrorToTable(const ErrorInfo& error); QCheckBox* createFilterCheckbox(const QString& name, bool checked, QBoxLayout* layout); - bool isShownError(const StorageError& error); + bool isShownError(const ErrorInfo& error); QtThreadedFunctor m_clearFunctor; QtThreadedFunctor m_refreshFunctor; - QtThreadedFunctor m_addErrorFunctor; + QtThreadedFunctor m_addErrorFunctor; QtThreadedFunctor m_setErrorIdFunctor; QCheckBox* m_showErrors; @@ -67,7 +67,7 @@ private: QStandardItemModel* m_model; QtTable* m_table; - std::vector m_errors; + std::vector m_errors; QPalette* m_palette; bool m_ignoreNextSelection;