From 982f7dc2b30df491e581850aa6af35a09a299042 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 18 Nov 2018 16:08:08 +0100 Subject: [PATCH] relative paths: show {code} properly when there are relative paths --- lib/errorlogger.cpp | 13 ++++++++++--- lib/errorlogger.h | 7 +++++-- lib/tokenlist.cpp | 7 ++++++- lib/tokenlist.h | 5 +++++ 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/lib/errorlogger.cpp b/lib/errorlogger.cpp index 52621912d..1a08dba2c 100644 --- a/lib/errorlogger.cpp +++ b/lib/errorlogger.cpp @@ -506,7 +506,7 @@ std::string ErrorLogger::ErrorMessage::toString(bool verbose, const std::string endl = "\r\n"; else endl = "\r"; - findAndReplace(result, "{code}", readCode(_callStack.back().getfile(), _callStack.back().line, _callStack.back().col, endl)); + findAndReplace(result, "{code}", readCode(_callStack.back().getOrigFile(), _callStack.back().line, _callStack.back().col, endl)); } } else { findAndReplace(result, "{file}", "nofile"); @@ -587,12 +587,12 @@ std::string ErrorLogger::callStackToString(const std::listfileIndex()), line(tok->linenr()), col(tok->col()), mFileName(tokenList->file(tok)) + : fileIndex(tok->fileIndex()), line(tok->linenr()), col(tok->col()), mOrigFileName(tokenList->getOrigFile(tok)), mFileName(tokenList->file(tok)) { } ErrorLogger::ErrorMessage::FileLocation::FileLocation(const Token* tok, const std::string &info, const TokenList* tokenList) - : fileIndex(tok->fileIndex()), line(tok->linenr()), col(tok->col()), mFileName(tokenList->file(tok)), mInfo(info) + : fileIndex(tok->fileIndex()), line(tok->linenr()), col(tok->col()), mOrigFileName(tokenList->getOrigFile(tok)), mFileName(tokenList->file(tok)), mInfo(info) { } @@ -603,6 +603,13 @@ std::string ErrorLogger::ErrorMessage::FileLocation::getfile(bool convert) const return mFileName; } +std::string ErrorLogger::ErrorMessage::FileLocation::getOrigFile(bool convert) const +{ + if (convert) + return Path::toNativeSeparators(mOrigFileName); + return mOrigFileName; +} + void ErrorLogger::ErrorMessage::FileLocation::setfile(const std::string &file) { mFileName = file; diff --git a/lib/errorlogger.h b/lib/errorlogger.h index 832b42ad9..61554b8d1 100644 --- a/lib/errorlogger.h +++ b/lib/errorlogger.h @@ -194,11 +194,11 @@ public: } FileLocation(const std::string &file, unsigned int aline) - : fileIndex(0), line(aline), col(0), mFileName(file) { + : fileIndex(0), line(aline), col(0), mOrigFileName(file), mFileName(file) { } FileLocation(const std::string &file, const std::string &info, unsigned int aline) - : fileIndex(0), line(aline), col(0), mFileName(file), mInfo(info) { + : fileIndex(0), line(aline), col(0), mOrigFileName(file), mFileName(file), mInfo(info) { } FileLocation(const Token* tok, const TokenList* tokenList); @@ -211,6 +211,8 @@ public: */ std::string getfile(bool convert = true) const; + std::string getOrigFile(bool convert = true) const; + /** * Set the filename. * @param file Filename to set. @@ -234,6 +236,7 @@ public: } private: + std::string mOrigFileName; std::string mFileName; std::string mInfo; }; diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 57ced79c2..a712458d2 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -266,7 +266,7 @@ bool TokenList::createTokens(std::istream &code, const std::string& file0) void TokenList::createTokens(const simplecpp::TokenList *tokenList) { if (tokenList->cfront()) - mFiles = tokenList->cfront()->location.files; + mOrigFiles = mFiles = tokenList->cfront()->location.files; else mFiles.clear(); @@ -1249,6 +1249,11 @@ void TokenList::validateAst() const } } +std::string TokenList::getOrigFile(const Token *tok) const +{ + return mOrigFiles.at(tok->fileIndex()); +} + const std::string& TokenList::file(const Token *tok) const { return mFiles.at(tok->fileIndex()); diff --git a/lib/tokenlist.h b/lib/tokenlist.h index a2106d322..f0baabdb7 100644 --- a/lib/tokenlist.h +++ b/lib/tokenlist.h @@ -128,6 +128,8 @@ public: return mFiles; } + std::string getOrigFile(const Token *tok) const; + /** * get filename for given token * @param tok The given token @@ -187,6 +189,9 @@ private: /** filenames for the tokenized source code (source + included) */ std::vector mFiles; + /** Original filenames for the tokenized source code (source + included) */ + std::vector mOrigFiles; + /** settings */ const Settings* mSettings;