data: Saving TokenLocations in Storage

This change adds structures for saving TokenLocations in the Storage and improves the location derival in the
ASTVisitor:
* TokenLocation saves an Id of a Token. For each Token two TokenLocations are created for both start- and endpoint. They
  keep a reference to each other and know whether they are start or end.
* TokenLocationLine saves all TokenLocations in a line and the lineNumber.
* TokenLocationFile saves all TokenLocationLines of a specific file and the filePath.
* TokenLocationCollection saves multiple TokenLocationFiles.
* TokenLocation can derive it's lineNumber and filePath through references to first TokenLocationLine and from there to
  TokenLocationFile.
This commit is contained in:
Eberhard Graether
2014-07-01 10:49:12 +02:00
parent e3cf57e2ec
commit cf6d17584f
27 changed files with 1109 additions and 243 deletions
@@ -0,0 +1,51 @@
#ifndef TOKEN_LOCATION_COLLECTION_H
#define TOKEN_LOCATION_COLLECTION_H
#include <map>
#include <memory>
#include <ostream>
#include <string>
#include "utility/types.h"
class TokenLocation;
class TokenLocationFile;
class TokenLocationCollection
{
public:
typedef std::map<std::string, std::shared_ptr<TokenLocationFile> > TokenLocationFileMapType;
typedef std::pair<std::string, std::shared_ptr<TokenLocationFile> > TokenLocationFilePairType;
TokenLocationCollection();
~TokenLocationCollection();
const TokenLocationFileMapType& getTokenLocationFiles() const;
size_t getTokenLocationFileCount() const;
const std::map<Id, TokenLocation*>& getTokenLocations() const;
size_t getTokenLocationCount() const;
TokenLocation* addTokenLocation(
Id tokenId, const std::string& 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;
void forEachTokenLocationFile(std::function<void(TokenLocationFile*)> func) const;
TokenLocation* addTokenLocationAsPlainCopy(const TokenLocation* location);
private:
TokenLocationFile* createTokenLocationFile(const std::string& filePath);
TokenLocationFileMapType m_files;
std::map<Id, TokenLocation*> m_locations;
};
std::ostream& operator<<(std::ostream& ostream, const TokenLocationCollection& base);
#endif // TOKEN_LOCATION_COLLECTION_H