2017-04-08 20:00:08 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-12 07:04:06 +00:00
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
#include <clang-c/Index.h>
|
|
|
|
|
|
|
|
#include <functional>
|
2017-04-08 20:00:08 +00:00
|
|
|
#include <mutex>
|
|
|
|
#include <unordered_set>
|
|
|
|
#include <unordered_map>
|
|
|
|
|
2017-05-12 06:08:15 +00:00
|
|
|
struct IndexFile;
|
2017-04-08 22:54:36 +00:00
|
|
|
|
2017-04-12 07:04:06 +00:00
|
|
|
// Needed for unordered_map usage below.
|
|
|
|
MAKE_HASHABLE(CXFileUniqueID, t.data[0], t.data[1], t.data[2]);
|
|
|
|
bool operator==(const CXFileUniqueID& a, const CXFileUniqueID& b);
|
|
|
|
|
2017-04-08 20:00:08 +00:00
|
|
|
// FileConsumer is used by the indexer. When it encouters a file, it tries to
|
|
|
|
// take ownership over it. If the indexer has ownership over a file, it will
|
|
|
|
// produce an index, otherwise, it will emit nothing for that declarations
|
|
|
|
// and references coming from that file.
|
|
|
|
//
|
|
|
|
// The indexer does this because header files do not have their own translation
|
|
|
|
// units but we still want to index them.
|
|
|
|
struct FileConsumer {
|
|
|
|
struct SharedState {
|
|
|
|
mutable std::unordered_set<std::string> files;
|
2017-04-08 22:54:36 +00:00
|
|
|
mutable std::mutex mutex;
|
2017-04-24 01:01:51 +00:00
|
|
|
|
|
|
|
// Mark the file as used. Returns true if the file was not previously used.
|
|
|
|
bool Mark(const std::string& file);
|
|
|
|
// Reset the used state (ie, mark the file as unused).
|
|
|
|
void Reset(const std::string& file);
|
2017-04-08 20:00:08 +00:00
|
|
|
};
|
|
|
|
|
2017-06-14 03:08:31 +00:00
|
|
|
FileConsumer(SharedState* shared_state, const std::string& parse_file);
|
2017-04-08 20:00:08 +00:00
|
|
|
|
|
|
|
// Returns true if this instance owns given |file|. This will also attempt to
|
|
|
|
// take ownership over |file|.
|
2017-04-08 22:54:36 +00:00
|
|
|
//
|
2017-05-12 06:08:15 +00:00
|
|
|
// Returns IndexFile for the file or nullptr. |is_first_ownership| is set
|
2017-04-11 05:26:27 +00:00
|
|
|
// to true iff the function just took ownership over the file. Otherwise it
|
|
|
|
// is set to false.
|
2017-05-12 06:08:15 +00:00
|
|
|
IndexFile* TryConsumeFile(CXFile file, bool* is_first_ownership);
|
2017-04-08 20:00:08 +00:00
|
|
|
|
2017-04-10 00:08:54 +00:00
|
|
|
// Forcibly create a local file, even if it has already been parsed.
|
2017-05-12 06:08:15 +00:00
|
|
|
IndexFile* ForceLocal(CXFile file);
|
2017-04-10 00:08:54 +00:00
|
|
|
|
2017-04-08 22:54:36 +00:00
|
|
|
// Returns and passes ownership of all local state.
|
2017-05-12 06:08:15 +00:00
|
|
|
std::vector<std::unique_ptr<IndexFile>> TakeLocalState();
|
2017-04-08 20:00:08 +00:00
|
|
|
|
|
|
|
private:
|
2017-05-12 06:08:15 +00:00
|
|
|
std::unordered_map<CXFileUniqueID, std::unique_ptr<IndexFile>> local_;
|
2017-04-08 20:00:08 +00:00
|
|
|
SharedState* shared_;
|
2017-06-14 03:08:31 +00:00
|
|
|
std::string parse_file_;
|
2017-04-08 20:00:08 +00:00
|
|
|
};
|