utility: added FilePath abstraction and rewrote data management to use it
The utility class FilePath wraps an instance of boost::filesystem::path. Using FilePath allows for easy comparision of file paths on different platforms using absolute or relative paths. Whereever file paths are compared, this wrapper should be used.
This commit is contained in:
@@ -84,7 +84,7 @@ unsigned int TokenLocation::getLineNumber() const
|
||||
return m_line->getLineNumber();
|
||||
}
|
||||
|
||||
const std::string& TokenLocation::getFilePath() const
|
||||
const FilePath& TokenLocation::getFilePath() const
|
||||
{
|
||||
return m_line->getFilePath();
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
class Token;
|
||||
@@ -36,7 +37,7 @@ public:
|
||||
|
||||
unsigned int getColumnNumber() const;
|
||||
unsigned int getLineNumber() const;
|
||||
const std::string& getFilePath() const;
|
||||
const FilePath& getFilePath() const;
|
||||
|
||||
TokenLocation* getOtherTokenLocation() const;
|
||||
void setOtherTokenLocation(TokenLocation* location);
|
||||
|
||||
@@ -38,7 +38,7 @@ size_t TokenLocationCollection::getTokenLocationCount() const
|
||||
}
|
||||
|
||||
TokenLocation* TokenLocationCollection::addTokenLocation(
|
||||
Id tokenId, const std::string& filePath,
|
||||
Id tokenId, const FilePath& filePath,
|
||||
unsigned int startLineNumber, unsigned int startColumnNumber,
|
||||
unsigned int endLineNumber, unsigned int endColumnNumber)
|
||||
{
|
||||
@@ -87,13 +87,13 @@ TokenLocation* TokenLocationCollection::findTokenLocationById(Id id) const
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TokenLocationFile* TokenLocationCollection::findTokenLocationFileByPath(const std::string& filePath) const
|
||||
TokenLocationFile* TokenLocationCollection::findTokenLocationFileByPath(const FilePath& filePath) const
|
||||
{
|
||||
std::map<std::string, std::shared_ptr<TokenLocationFile>>::const_iterator it =
|
||||
std::map<FilePath, std::shared_ptr<TokenLocationFile>>::const_iterator it =
|
||||
find_if(m_files.begin(), m_files.end(),
|
||||
[&](const std::pair<std::string, std::shared_ptr<TokenLocationFile>>& p)
|
||||
[&](const std::pair<FilePath, std::shared_ptr<TokenLocationFile>>& p)
|
||||
{
|
||||
return FileSystem::equivalent(p.first, filePath);
|
||||
return p.first == filePath;
|
||||
}
|
||||
);
|
||||
|
||||
@@ -143,7 +143,7 @@ void TokenLocationCollection::removeTokenLocationFile(TokenLocationFile* file)
|
||||
|
||||
TokenLocation* TokenLocationCollection::addTokenLocationAsPlainCopy(const TokenLocation* location)
|
||||
{
|
||||
const std::string& filePath = location->getTokenLocationLine()->getTokenLocationFile()->getFilePath();
|
||||
const FilePath& filePath = location->getTokenLocationLine()->getTokenLocationFile()->getFilePath();
|
||||
TokenLocationFile* file = createTokenLocationFile(filePath);
|
||||
TokenLocation* copy = file->addTokenLocationAsPlainCopy(location);
|
||||
|
||||
@@ -157,7 +157,7 @@ void TokenLocationCollection::clear()
|
||||
m_files.clear();
|
||||
}
|
||||
|
||||
TokenLocationFile* TokenLocationCollection::createTokenLocationFile(const std::string& filePath)
|
||||
TokenLocationFile* TokenLocationCollection::createTokenLocationFile(const FilePath& filePath)
|
||||
{
|
||||
TokenLocationFile* file = findTokenLocationFileByPath(filePath);
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
class TokenLocation;
|
||||
@@ -16,8 +17,8 @@ class TokenLocationLine;
|
||||
class TokenLocationCollection
|
||||
{
|
||||
public:
|
||||
typedef std::map<std::string, std::shared_ptr<TokenLocationFile> > TokenLocationFileMapType;
|
||||
typedef std::pair<std::string, std::shared_ptr<TokenLocationFile> > TokenLocationFilePairType;
|
||||
typedef std::map<FilePath, std::shared_ptr<TokenLocationFile> > TokenLocationFileMapType;
|
||||
typedef std::pair<FilePath, std::shared_ptr<TokenLocationFile> > TokenLocationFilePairType;
|
||||
|
||||
TokenLocationCollection();
|
||||
~TokenLocationCollection();
|
||||
@@ -29,13 +30,13 @@ public:
|
||||
size_t getTokenLocationCount() const;
|
||||
|
||||
TokenLocation* addTokenLocation(
|
||||
Id tokenId, const std::string& filePath,
|
||||
Id tokenId, const FilePath& filePath,
|
||||
unsigned int startLineNumber, unsigned int startColumnNumber,
|
||||
unsigned int endLineNumber, unsigned int endColumnNumber);
|
||||
void removeTokenLocation(TokenLocation* location);
|
||||
|
||||
TokenLocation* findTokenLocationById(Id id) const;
|
||||
TokenLocationFile* findTokenLocationFileByPath(const std::string& filePath) const;
|
||||
TokenLocationFile* findTokenLocationFileByPath(const FilePath& filePath) const;
|
||||
|
||||
void forEachTokenLocationFile(std::function<void(TokenLocationFile*)> func) const;
|
||||
void forEachTokenLocationLine(std::function<void(TokenLocationLine*)> func) const;
|
||||
@@ -48,7 +49,7 @@ public:
|
||||
void clear();
|
||||
|
||||
private:
|
||||
TokenLocationFile* createTokenLocationFile(const std::string& filePath);
|
||||
TokenLocationFile* createTokenLocationFile(const FilePath& filePath);
|
||||
|
||||
TokenLocationFileMapType m_files;
|
||||
std::map<Id, TokenLocation*> m_locations;
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
|
||||
#include "utility/logging/logging.h"
|
||||
|
||||
#include "data/location/TokenLocation.h"
|
||||
#include "data/location/TokenLocationLine.h"
|
||||
#include "utility/logging/logging.h"
|
||||
|
||||
TokenLocationFile::TokenLocationFile(const std::string& filePath)
|
||||
TokenLocationFile::TokenLocationFile(const FilePath& filePath)
|
||||
: m_filePath(filePath)
|
||||
{
|
||||
}
|
||||
@@ -23,7 +24,7 @@ size_t TokenLocationFile::getTokenLocationLineCount() const
|
||||
return m_lines.size();
|
||||
}
|
||||
|
||||
const std::string& TokenLocationFile::getFilePath() const
|
||||
const FilePath& TokenLocationFile::getFilePath() const
|
||||
{
|
||||
return m_filePath;
|
||||
}
|
||||
@@ -156,7 +157,7 @@ TokenLocationLine* TokenLocationFile::createTokenLocationLine(unsigned int lineN
|
||||
|
||||
std::ostream& operator<<(std::ostream& ostream, const TokenLocationFile& file)
|
||||
{
|
||||
ostream << "file \"" << file.getFilePath() << "\"\n";
|
||||
ostream << "file \"" << file.getFilePath().str() << "\"\n";
|
||||
file.forEachTokenLocationLine([&ostream](TokenLocationLine* l)
|
||||
{
|
||||
ostream << *l << '\n';
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
class TokenLocation;
|
||||
@@ -15,16 +16,16 @@ class TokenLocationLine;
|
||||
class TokenLocationFile
|
||||
{
|
||||
public:
|
||||
typedef std::map<unsigned int, std::shared_ptr<TokenLocationLine> > TokenLocationLineMapType;
|
||||
typedef std::pair<unsigned int, std::shared_ptr<TokenLocationLine> > TokenLocationLinePairType;
|
||||
typedef std::map<unsigned int, std::shared_ptr<TokenLocationLine>> TokenLocationLineMapType;
|
||||
typedef std::pair<unsigned int, std::shared_ptr<TokenLocationLine>> TokenLocationLinePairType;
|
||||
|
||||
TokenLocationFile(const std::string& filePath);
|
||||
TokenLocationFile(const FilePath& filePath);
|
||||
~TokenLocationFile();
|
||||
|
||||
const TokenLocationLineMapType& getTokenLocationLines() const;
|
||||
size_t getTokenLocationLineCount() const;
|
||||
|
||||
const std::string& getFilePath() const;
|
||||
const FilePath& getFilePath() const;
|
||||
|
||||
TokenLocation* addTokenLocation(
|
||||
Id tokenId,
|
||||
@@ -44,7 +45,7 @@ private:
|
||||
TokenLocationLine* createTokenLocationLine(unsigned int lineNumber);
|
||||
|
||||
std::map<unsigned int, std::shared_ptr<TokenLocationLine> > m_lines;
|
||||
std::string m_filePath;
|
||||
FilePath m_filePath;
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& ostream, const TokenLocationFile& file);
|
||||
|
||||
@@ -29,7 +29,7 @@ TokenLocationFile* TokenLocationLine::getTokenLocationFile() const
|
||||
return m_file;
|
||||
}
|
||||
|
||||
const std::string& TokenLocationLine::getFilePath() const
|
||||
const FilePath& TokenLocationLine::getFilePath() const
|
||||
{
|
||||
return m_file->getFilePath();
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
class TokenLocation;
|
||||
@@ -25,7 +26,7 @@ public:
|
||||
size_t getTokenLocationCount() const;
|
||||
|
||||
TokenLocationFile* getTokenLocationFile() const;
|
||||
const std::string& getFilePath() const;
|
||||
const FilePath& getFilePath() const;
|
||||
|
||||
unsigned int getLineNumber() const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user