ui: display fatal errors

* added ErrorCountInfo to incorporate reporting of fatal errors during code analysis.
This commit is contained in:
malte_langkabel
2016-03-02 10:53:04 +01:00
parent 4425b39ea1
commit 2ebfbbf88e
21 changed files with 105 additions and 213 deletions
+1
View File
@@ -158,6 +158,7 @@ add_files(
data/type/ReferenceModifiedDataType.cpp
data/type/ReferenceModifiedDataType.h
data/ErrorCountInfo.h
data/HierarchyCache.cpp
data/HierarchyCache.h
data/SqliteStorage.cpp
@@ -65,12 +65,12 @@ void CodeController::handleMessage(MessageActivateAll* message)
ss << "\t" + std::to_string(stats.nodeCount) + " symbols\n";
ss << "\t" + std::to_string(stats.edgeCount) + " relations\n";
ss << "\n";
ss << "\t" + std::to_string(stats.errorCount) + " errors\n";
ss << "\t" + std::to_string(stats.errorCount.total) + " errors (" + std::to_string(stats.errorCount.fatal) + " fatal)\n";
ss << "\n";
if (stats.errorCount > 0)
if (stats.errorCount.total > 0)
{
ss << "\tWarning: The analysis may be incomplete as long as it yields errors.\n";
ss << "\tWarning: The analysis may be incomplete as long as it yields fatal errors.\n";
ss << "\tTry resolving them and refresh the project.\n";
ss << "\n";
}
@@ -19,7 +19,7 @@ StatusBarView* StatusBarController::getView()
void StatusBarController::handleMessage(MessageClearErrorCount* message)
{
getView()->setErrorCount(0);
getView()->setErrorCount(ErrorCountInfo());
}
void StatusBarController::handleMessage(MessageFinishedParsing* message)
@@ -29,7 +29,7 @@ void StatusBarController::handleMessage(MessageFinishedParsing* message)
void StatusBarController::handleMessage(MessageShowErrors* message)
{
if (message->errorCount >= 0)
if (message->errorCount.total >= 0)
{
getView()->setErrorCount(message->errorCount);
}
@@ -126,7 +126,7 @@ std::shared_ptr<MessageActivateTokens> ActivationTranslator::translateMessage(co
else if (match.searchType == SearchMatch::SEARCH_COMMAND &&
match.getFullName() == SearchMatch::getCommandName(SearchMatch::COMMAND_ERROR))
{
MessageShowErrors msg(-1);
MessageShowErrors msg(ErrorCountInfo(-1, 0));
msg.undoRedoType = message->undoRedoType;
msg.dispatchImmediately();
return nullptr;
+2 -1
View File
@@ -2,6 +2,7 @@
#define STATUS_BAR_VIEW_H
#include "component/view/View.h"
#include "data/ErrorCountInfo.h"
class StatusBarController;
@@ -13,7 +14,7 @@ public:
virtual std::string getName() const;
virtual void showMessage(const std::string& message, bool isError, bool showLoader) = 0;
virtual void setErrorCount(size_t count) = 0;
virtual void setErrorCount(ErrorCountInfo errorCount) = 0;
protected:
StatusBarController* getController();
+20
View File
@@ -0,0 +1,20 @@
#ifndef ERROR_COUNT_INFO_H
#define ERROR_COUNT_INFO_H
struct ErrorCountInfo
{
ErrorCountInfo()
: total(0)
, fatal(0)
{}
ErrorCountInfo(int total, size_t fatal)
: total(total)
, fatal(fatal)
{}
int total;
size_t fatal;
};
#endif // ERROR_COUNT_INFO_H
+25 -3
View File
@@ -169,9 +169,9 @@ Id SqliteStorage::addCommentLocation(Id fileNodeId, uint startLine, uint startCo
return m_database.lastRowId();
}
Id SqliteStorage::addError(const std::string& message, const std::string& filePath, uint lineNumber, uint columnNumber)
Id SqliteStorage::addError(const std::string& message, bool fatal, const std::string& filePath, uint lineNumber, uint columnNumber)
{
std::string sanitizedMessage = utility::replace(message, "'", "''");
std::string sanitizedMessage = utility::replace((fatal ? "Fatal: " : "") + message, "'", "''");
// check for duplicate
CppSQLite3Query q = m_database.execQuery((
@@ -630,7 +630,29 @@ std::vector<StorageError> SqliteStorage::getAllErrors() const
{
CppSQLite3Query q = m_database.execQuery(
"SELECT message, file_path, line_number, column_number FROM error;"
);
);
std::vector<StorageError> errors;
while (!q.eof())
{
const std::string message = q.getStringField(0, "");
const std::string filePath = q.getStringField(1, "");
const uint lineNumber = q.getIntField(2, 0);
const uint columnNumber = q.getIntField(3, 0);
errors.push_back(StorageError(message, filePath, lineNumber, columnNumber));
q.nextRow();
}
return errors;
}
std::vector<StorageError> SqliteStorage::getFatalErrors() const
{
CppSQLite3Query q = m_database.execQuery(
"SELECT message, file_path, line_number, column_number FROM error WHERE message LIKE 'Fatal: %';"
);
std::vector<StorageError> errors;
while (!q.eof())
+2 -1
View File
@@ -42,7 +42,7 @@ public:
Id addComponentAccess(Id memberEdgeId, int type);
Id addCommentLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol);
Id addError(const std::string& message, const std::string& filePath, uint lineNumber, uint columnNumber);
Id addError(const std::string& message, bool fatal, const std::string& filePath, uint lineNumber, uint columnNumber);
void removeElement(Id id);
void removeElements(const std::vector<Id>& ids);
@@ -95,6 +95,7 @@ public:
std::vector<StorageCommentLocation> getCommentLocationsInFile(const FilePath& filePath) const;
std::vector<StorageError> getAllErrors() const;
std::vector<StorageError> getFatalErrors() const;
int getNodeCount() const;
int getEdgeCount() const;
+7 -7
View File
@@ -188,20 +188,20 @@ void Storage::finishParsingFile(const FilePath& filePath)
m_sqliteStorage.commitTransaction();
}
void Storage::onError(const ParseLocation& location, const std::string& message)
void Storage::onError(const ParseLocation& location, const std::string& message, bool fatal)
{
log("ERROR", message, location);
log(std::string(fatal ? "FATAL " : "") + "ERROR", message, location);
if (!location.isValid())
{
return;
}
size_t errorCount = getErrorCount();
size_t totalErrorCount = getErrorCount().total;
m_sqliteStorage.addError(message, location.filePath.str(), location.startLineNumber, location.startColumnNumber);
m_sqliteStorage.addError(message, fatal, location.filePath.str(), location.startLineNumber, location.startColumnNumber);
if (errorCount != getErrorCount())
if (totalErrorCount != getErrorCount().total)
{
MessageShowErrors msg(getErrorCount());
msg.setSendAsTask(false);
@@ -209,9 +209,9 @@ void Storage::onError(const ParseLocation& location, const std::string& message)
}
}
size_t Storage::getErrorCount() const
ErrorCountInfo Storage::getErrorCount() const
{
return m_sqliteStorage.getAllErrors().size();
return ErrorCountInfo(m_sqliteStorage.getAllErrors().size(), m_sqliteStorage.getFatalErrors().size());
}
Id Storage::onTypedefParsed(
+2 -2
View File
@@ -46,8 +46,8 @@ public:
virtual void startParsingFile(const FilePath& filePath);
virtual void finishParsingFile(const FilePath& filePath);
virtual void onError(const ParseLocation& location, const std::string& message);
virtual size_t getErrorCount() const;
virtual void onError(const ParseLocation& location, const std::string& message, bool fatal);
virtual ErrorCountInfo getErrorCount() const;
virtual Id onTypedefParsed(
const ParseLocation& location, const NameHierarchy& typedefName, AccessType access);
+4 -2
View File
@@ -1,6 +1,8 @@
#ifndef STORAGE_STATS_H
#define STORAGE_STATS_H
#include "data/ErrorCountInfo.h"
struct StorageStats
{
StorageStats()
@@ -12,7 +14,7 @@ struct StorageStats
, fileCount(0)
, fileLOCCount(0)
, sourceLocationCount(0)
, errorCount(0)
, errorCount(ErrorCountInfo())
{}
size_t nodeCount;
@@ -26,7 +28,7 @@ struct StorageStats
size_t fileLOCCount;
size_t sourceLocationCount;
size_t errorCount;
ErrorCountInfo errorCount;
};
#endif // STORAGE_STATS_H
+3 -2
View File
@@ -6,6 +6,7 @@
#include "utility/types.h"
#include "data/name/NameHierarchy.h"
#include "data/ErrorCountInfo.h"
#include "utility/file/FileInfo.h"
@@ -61,8 +62,8 @@ public:
virtual void startParsingFile(const FilePath& filePath) = 0;
virtual void finishParsingFile(const FilePath& filePath) = 0;
virtual void onError(const ParseLocation& location, const std::string& message) = 0;
virtual size_t getErrorCount() const = 0;
virtual void onError(const ParseLocation& location, const std::string& message, bool fatal) = 0;
virtual ErrorCountInfo getErrorCount() const = 0;
virtual Id onTypedefParsed(
const ParseLocation& location, const NameHierarchy& typedefName, AccessType access) = 0;
@@ -4,6 +4,7 @@
#include <sstream>
#include <iomanip>
#include "data/ErrorCountInfo.h"
#include "utility/messaging/Message.h"
#include "utility/messaging/type/MessageStatus.h"
@@ -11,7 +12,7 @@ class MessageFinishedParsing
: public Message<MessageFinishedParsing>
{
public:
MessageFinishedParsing(size_t fileCount, size_t totalFileCount, float parseTime, size_t errorCount)
MessageFinishedParsing(size_t fileCount, size_t totalFileCount, float parseTime, ErrorCountInfo errorCount)
: fileCount(fileCount)
, totalFileCount(totalFileCount)
, parseTime(parseTime)
@@ -26,7 +27,7 @@ public:
virtual void dispatch()
{
MessageStatus(getStatusStr(), errorCount > 0).dispatch();
MessageStatus(getStatusStr(), errorCount.total > 0).dispatch();
Message<MessageFinishedParsing>::dispatch();
}
@@ -37,7 +38,11 @@ public:
ss << "Finished analysis: ";
ss << fileCount << "/" << totalFileCount << " files, ";
ss << std::setprecision(2) << std::fixed << parseTime << " seconds, ";
ss << errorCount << " error(s)";
ss << errorCount.total << " error" << (errorCount.total > 1 ? "s" : "");
if (errorCount.fatal > 0)
{
ss << " (" << errorCount.fatal << " fatal)";
}
return ss.str();
}
@@ -49,7 +54,7 @@ public:
size_t fileCount;
size_t totalFileCount;
float parseTime;
size_t errorCount;
ErrorCountInfo errorCount;
};
#endif // MESSAGE_FINISHED_PARSING_H
@@ -1,13 +1,14 @@
#ifndef MESSAGE_SHOW_ERRORS_H
#define MESSAGE_SHOW_ERRORS_H
#include "data/ErrorCountInfo.h"
#include "utility/messaging/Message.h"
class MessageShowErrors
: public Message<MessageShowErrors>
{
public:
MessageShowErrors(int errorCount)
MessageShowErrors(ErrorCountInfo errorCount)
: errorCount(errorCount)
{
}
@@ -17,7 +18,7 @@ public:
return "MessageShowErrors";
}
int errorCount;
ErrorCountInfo errorCount;
};
#endif // MESSAGE_SHOW_ERRORS_H