Skip to content

Commit

Permalink
Use Flags everywhere (well, almost everywhere).
Browse files Browse the repository at this point in the history
  • Loading branch information
Andersbakken committed Apr 17, 2015
1 parent 57f99a4 commit 09d6c9d
Show file tree
Hide file tree
Showing 42 changed files with 303 additions and 256 deletions.
24 changes: 12 additions & 12 deletions src/ClangIndexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ bool ClangIndexer::exec(const String &data)
}
uint64_t id;
String socketFile;
uint32_t flags;
Flags<IndexerJob::Flag> indexerJobFlags;
uint32_t connectTimeout;
int32_t niceValue;
Hash<uint32_t, Path> blockedFiles;
Expand All @@ -87,7 +87,7 @@ bool ClangIndexer::exec(const String &data)
deserializer >> mProject;
deserializer >> mSource;
deserializer >> mSourceFile;
deserializer >> flags;
deserializer >> indexerJobFlags;
deserializer >> mVisitFileTimeout;
deserializer >> mIndexDataMessageTimeout;
deserializer >> connectTimeout;
Expand Down Expand Up @@ -142,7 +142,7 @@ bool ClangIndexer::exec(const String &data)
}
// mLogFile = fopen(String::format("/tmp/%s", mSourceFile.fileName()).constData(), "w");
mIndexDataMessage.setProject(mProject);
mIndexDataMessage.setIndexerJobFlags(flags);
mIndexDataMessage.setIndexerJobFlags(indexerJobFlags);
mIndexDataMessage.setParseTime(parseTime);
mIndexDataMessage.setKey(mSource.key());
mIndexDataMessage.setId(id);
Expand Down Expand Up @@ -231,7 +231,7 @@ Location ClangIndexer::createLocation(const Path &sourceFile, unsigned int line,

if (id) {
if (blockedPtr) {
Hash<uint32_t, unsigned int>::iterator it = mIndexDataMessage.files().find(id);
Hash<uint32_t, Flags<IndexDataMessage::FileFlag> >::iterator it = mIndexDataMessage.files().find(id);
if (it == mIndexDataMessage.files().end()) {
// the only reason we already have an id for a file that isn't
// in the mIndexDataMessage.mFiles is that it's blocked from the outset.
Expand All @@ -245,7 +245,7 @@ Location ClangIndexer::createLocation(const Path &sourceFile, unsigned int line,
if (resolved.isEmpty())
resolved = sourceFile.resolved();
#endif
mIndexDataMessage.files()[id] = 0;
mIndexDataMessage.files()[id] = IndexDataMessage::NoFileFlag;
*blockedPtr = true;
return Location();
} else if (!it->second) {
Expand Down Expand Up @@ -278,7 +278,7 @@ Location ClangIndexer::createLocation(const Path &sourceFile, unsigned int line,
id = mVisitFileResponseMessageFileId;
break;
}
unsigned int &flags = mIndexDataMessage.files()[id];
Flags<IndexDataMessage::FileFlag> &flags = mIndexDataMessage.files()[id];
if (mVisitFileResponseMessageVisit) {
flags |= IndexDataMessage::Visited;
++mIndexed;
Expand Down Expand Up @@ -1151,8 +1151,8 @@ bool ClangIndexer::parse()
assert(!mIndex);
mIndex = clang_createIndex(0, 1);
assert(mIndex);
const unsigned int commandLineFlags = Source::Default;
const unsigned int flags = CXTranslationUnit_DetailedPreprocessingRecord;
const Flags<Source::CommandLineFlag> commandLineFlags = Source::Default;
const Flags<CXTranslationUnit_Flags> flags = CXTranslationUnit_DetailedPreprocessingRecord;
List<CXUnsavedFile> unsavedFiles(mUnsavedFiles.size() + 1);
int unsavedIndex = 0;
for (const auto &it : mUnsavedFiles) {
Expand Down Expand Up @@ -1283,7 +1283,7 @@ bool ClangIndexer::diagnose()
const bool inclusionError = clang_getCursorKind(cursor) == CXCursor_InclusionDirective;
if (inclusionError)
mIndexDataMessage.setFlag(IndexDataMessage::InclusionError);
unsigned int &flags = mIndexDataMessage.files()[fileId];
Flags<IndexDataMessage::FileFlag> &flags = mIndexDataMessage.files()[fileId];
if (fileId != mSource.fileId && !inclusionError && sev >= CXDiagnostic_Error && !(flags & IndexDataMessage::HeaderError)) {
// We don't treat inclusions or code inside a macro expansion as a
// header error
Expand Down Expand Up @@ -1364,14 +1364,14 @@ bool ClangIndexer::diagnose()
assert(string);
if (!*string) {
error("Fixit for %s Remove %d character%s",
loc.key(0).constData(), endOffset - startOffset,
loc.key().constData(), endOffset - startOffset,
endOffset - startOffset > 1 ? "s" : "");
} else if (endOffset == startOffset) {
error("Fixit for %s Insert \"%s\"",
loc.key(0).constData(), string);
loc.key().constData(), string);
} else {
error("Fixit for %s Replace %d character%s with \"%s\"",
loc.key(0).constData(), endOffset - startOffset,
loc.key().constData(), endOffset - startOffset,
endOffset - startOffset > 1 ? "s" : "", string);
}
Diagnostic &entry = mIndexDataMessage.diagnostics()[Location(loc.fileId(), line, column)];
Expand Down
2 changes: 1 addition & 1 deletion src/ClassHierarchyJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ along with RTags. If not, see <http://www.gnu.org/licenses/>. */
ClassHierarchyJob::ClassHierarchyJob(const Location &loc,
const std::shared_ptr<QueryMessage> &query,
const std::shared_ptr<Project> &project)
: QueryJob(query, 0, project), location(loc)
: QueryJob(query, project), location(loc)
{
}

Expand Down
5 changes: 3 additions & 2 deletions src/CompletionThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ void CompletionThread::run()
}

void CompletionThread::completeAt(const Source &source, const Location &location,
unsigned int flags, const String &unsaved, const std::shared_ptr<Connection> &conn)
Flags<Flag> flags, const String &unsaved,
const std::shared_ptr<Connection> &conn)
{
Request *request = new Request({ source, location, flags, unsaved, conn});
std::unique_lock<std::mutex> lock(mMutex);
Expand Down Expand Up @@ -254,7 +255,7 @@ void CompletionThread::process(Request *request)
Rct::LinkedList::deleteAll(cache->firstCompletion);
cache->firstCompletion = cache->lastCompletion = 0;
sw.restart();
unsigned int flags = clang_defaultEditingTranslationUnitOptions();
Flags<CXTranslationUnit_Flags> flags = static_cast<CXTranslationUnit_Flags>(clang_defaultEditingTranslationUnitOptions());
flags |= CXTranslationUnit_PrecompiledPreamble;
flags |= CXTranslationUnit_CacheCompletionResults;
flags |= CXTranslationUnit_SkipFunctionBodies;
Expand Down
8 changes: 6 additions & 2 deletions src/CompletionThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <rct/LinkedList.h>
#include <clang-c/Index.h>
#include <rct/Connection.h>
#include <rct/Flags.h>

class CompletionThread : public Thread
{
Expand All @@ -39,7 +40,8 @@ class CompletionThread : public Thread
Refresh = 0x1,
Elisp = 0x2
};
void completeAt(const Source &source, const Location &location, unsigned int flags, const String &unsaved, const std::shared_ptr<Connection> &conn);
void completeAt(const Source &source, const Location &location, Flags<Flag> flags,
const String &unsaved, const std::shared_ptr<Connection> &conn);
void stop();
String dump();
private:
Expand All @@ -57,7 +59,7 @@ class CompletionThread : public Thread
}
Source source;
Location location;
unsigned int flags;
Flags<Flag> flags;
String unsaved;
std::shared_ptr<Connection> conn;
};
Expand Down Expand Up @@ -107,4 +109,6 @@ class CompletionThread : public Thread
std::condition_variable mCondition;
};

RCT_FLAGS(CompletionThread::Flag);

#endif
2 changes: 1 addition & 1 deletion src/DependenciesJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ along with RTags. If not, see <http://www.gnu.org/licenses/>. */
#include "Project.h"

DependenciesJob::DependenciesJob(const std::shared_ptr<QueryMessage> &query, const std::shared_ptr<Project> &project)
: QueryJob(query, QuietJob, project)
: QueryJob(query, project, QuietJob)
{
Path p = query->query();
p.resolve();
Expand Down
2 changes: 1 addition & 1 deletion src/DumpThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ CXChildVisitResult DumpThread::visitor(CXCursor cursor, CXCursor, CXClientData u
assert(that);
CXSourceLocation location = clang_getCursorLocation(cursor);
if (!clang_equalLocations(location, nullLocation)) {
unsigned int locationFlags = 0;
Flags<Location::KeyFlag> locationFlags;
if (that->mQueryFlags & QueryMessage::NoColor)
locationFlags |= Location::NoColor;
CXString file;
Expand Down
2 changes: 1 addition & 1 deletion src/DumpThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class DumpThread : public Thread
private:
static CXChildVisitResult visitor(CXCursor cursor, CXCursor, CXClientData userData);
void writeToConnetion(const String &message);
const unsigned int mQueryFlags;
const Flags<QueryMessage::Flag> mQueryFlags;
const Source mSource;
std::shared_ptr<Connection> mConnection;
Hash<Path, uint32_t> mFiles;
Expand Down
6 changes: 3 additions & 3 deletions src/FindFileJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ along with RTags. If not, see <http://www.gnu.org/licenses/>. */
#include "FileManager.h"
#include "Project.h"

static unsigned int flags(unsigned int queryFlags)
static Flags<QueryJob::JobFlag> flags(Flags<QueryMessage::Flag> queryFlags)
{
unsigned int flags = QueryJob::QuietJob;
Flags<QueryJob::JobFlag> flags = QueryJob::QuietJob;
if (queryFlags & QueryMessage::ElispList)
flags |= QueryJob::QuoteOutput;
return flags;
}

FindFileJob::FindFileJob(const std::shared_ptr<QueryMessage> &query, const std::shared_ptr<Project> &project)
: QueryJob(query, ::flags(query->flags()), project)
: QueryJob(query, project, ::flags(query->flags()))
{
const String q = query->query();
if (!q.isEmpty()) {
Expand Down
10 changes: 5 additions & 5 deletions src/FindSymbolsJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ along with RTags. If not, see <http://www.gnu.org/licenses/>. */
#include "RTagsClang.h"
#include "Project.h"

static inline unsigned int jobFlags(unsigned int queryFlags)
static inline Flags<QueryJob::JobFlag> jobFlags(Flags<QueryMessage::Flag> queryFlags)
{
return (queryFlags & QueryMessage::ElispList) ? QueryJob::QuoteOutput|QueryJob::QuietJob : QueryJob::None|QueryJob::QuietJob;
return (queryFlags & QueryMessage::ElispList) ? QueryJob::QuoteOutput|QueryJob::QuietJob : QueryJob::QuietJob;
}

FindSymbolsJob::FindSymbolsJob(const std::shared_ptr<QueryMessage> &query, const std::shared_ptr<Project> &proj)
: QueryJob(query, ::jobFlags(query->flags()), proj), string(query->query())
: QueryJob(query, proj, ::jobFlags(query->flags())), string(query->query())
{
}

Expand All @@ -49,14 +49,14 @@ int FindSymbolsJob::execute()
};
proj->findSymbols(string, inserter, queryFlags());
if (!symbols.isEmpty()) {
unsigned int sortFlags = Project::Sort_None;
Flags<Project::SortFlag> sortFlags = Project::Sort_None;
if (queryFlags() & QueryMessage::DeclarationOnly)
sortFlags |= Project::Sort_DeclarationOnly;
if (queryFlags() & QueryMessage::ReverseSort)
sortFlags |= Project::Sort_Reverse;

const List<RTags::SortedSymbol> sorted = proj->sort(symbols, sortFlags);
const unsigned int writeFlags = filter ? Unfiltered : NoWriteFlags;
const Flags<WriteFlag> writeFlags = filter ? Unfiltered : NoWriteFlags;
const int count = sorted.size();
ret = count ? 0 : 1;
for (int i=0; i<count; ++i) {
Expand Down
2 changes: 1 addition & 1 deletion src/FollowLocationJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ along with RTags. If not, see <http://www.gnu.org/licenses/>. */
FollowLocationJob::FollowLocationJob(const Location &loc,
const std::shared_ptr<QueryMessage> &query,
const std::shared_ptr<Project> &project)
: QueryJob(query, 0, project), location(loc)
: QueryJob(query, project), location(loc)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/IncludeFileJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ along with RTags. If not, see <http://www.gnu.org/licenses/>. */
#include "Project.h"

IncludeFileJob::IncludeFileJob(const std::shared_ptr<QueryMessage> &query, const std::shared_ptr<Project> &project)
: QueryJob(query, 0, project)
: QueryJob(query, project)
{
const uint32_t fileId = Location::fileId(query->currentFile());
mSource = project->sources(fileId).value(query->buildIndex());
Expand Down
57 changes: 32 additions & 25 deletions src/IndexDataMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <rct/Serializer.h>
#include <rct/String.h>
#include "IndexerJob.h"
#include <rct/Flags.h>

class IndexDataMessage : public RTagsMessage
{
Expand All @@ -30,36 +31,24 @@ class IndexDataMessage : public RTagsMessage

IndexDataMessage(const std::shared_ptr<IndexerJob> &job)
: RTagsMessage(MessageId), mParseTime(0), mKey(job->source.key()), mId(0),
mIndexerJobFlags(job->flags), mFlags(0)
mIndexerJobFlags(job->flags)
{}

IndexDataMessage()
: RTagsMessage(MessageId), mParseTime(0), mKey(0), mId(0),
mIndexerJobFlags(0), mFlags(0)
: RTagsMessage(MessageId), mParseTime(0), mKey(0), mId(0)
{}

void encode(Serializer &serializer) const
{
serializer << mProject << mParseTime << mKey << mId << mIndexerJobFlags
<< mMessage << mFixIts << mIncludes << mDiagnostics << mFiles
<< mDeclarations << mFlags;
}

void decode(Deserializer &deserializer)
{
deserializer >> mProject >> mParseTime >> mKey >> mId >> mIndexerJobFlags
>> mMessage >> mFixIts >> mIncludes >> mDiagnostics
>> mFiles >> mDeclarations >> mFlags;
}
void encode(Serializer &serializer) const;
void decode(Deserializer &deserializer);

enum Flag {
None = 0x0,
ParseFailure = 0x1,
InclusionError = 0x2
};
unsigned int flags() const { return mFlags; }
void setFlags(unsigned int flags) { mFlags = flags; }
void setFlag(Flag flag, bool on = true) { if (on) { mFlags |= flag; } else { mFlags &= ~flag; } }
Flags<Flag> flags() const { return mFlags; }
void setFlags(Flags<Flag> flags) { mFlags = flags; }
void setFlag(Flag flag, bool on = true) { mFlags.set(flag, on); }

Set<uint32_t> visitedFiles() const
{
Expand Down Expand Up @@ -97,8 +86,8 @@ class IndexDataMessage : public RTagsMessage
uint64_t parseTime() const { return mParseTime; }
void setParseTime(uint64_t parseTime) { mParseTime = parseTime; }

uint32_t indexerJobFlags() const { return mIndexerJobFlags; }
void setIndexerJobFlags(uint32_t flags) { mIndexerJobFlags = flags; }
Flags<IndexerJob::Flag> indexerJobFlags() const { return mIndexerJobFlags; }
void setIndexerJobFlags(Flags<IndexerJob::Flag> flags) { mIndexerJobFlags = flags; }

uint64_t key() const { return mKey; }
void setKey(uint64_t key) { mKey = key; }
Expand All @@ -111,21 +100,39 @@ class IndexDataMessage : public RTagsMessage
Includes &includes() { return mIncludes; }
Declarations &declarations() { return mDeclarations; }
enum FileFlag {
NoFileFlag = 0x0,
Visited = 0x1,
HeaderError = 0x2
};
Hash<uint32_t, unsigned int> &files() { return mFiles; }
Hash<uint32_t, Flags<FileFlag> > &files() { return mFiles; }
private:
Path mProject;
uint64_t mParseTime, mKey, mId;
uint32_t mIndexerJobFlags; // indexerjobflags
Flags<IndexerJob::Flag> mIndexerJobFlags; // indexerjobflags
String mMessage; // used as output for dump when flags & Dump
FixIts mFixIts;
Diagnostics mDiagnostics;
Includes mIncludes;
Declarations mDeclarations; // function declarations and forward declaration
Hash<uint32_t, unsigned int> mFiles;
unsigned int mFlags;
Hash<uint32_t, Flags<FileFlag> > mFiles;
Flags<Flag> mFlags;
};

RCT_FLAGS(IndexDataMessage::Flag);
RCT_FLAGS(IndexDataMessage::FileFlag);

inline void IndexDataMessage::encode(Serializer &serializer) const
{
serializer << mProject << mParseTime << mKey << mId << mIndexerJobFlags
<< mMessage << mFixIts << mIncludes << mDiagnostics << mFiles
<< mDeclarations << mFlags;
}

inline void IndexDataMessage::decode(Deserializer &deserializer)
{
deserializer >> mProject >> mParseTime >> mKey >> mId >> mIndexerJobFlags
>> mMessage >> mFixIts >> mIncludes >> mDiagnostics
>> mFiles >> mDeclarations >> mFlags;
}

#endif
11 changes: 7 additions & 4 deletions src/IndexMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ along with RTags. If not, see <http://www.gnu.org/licenses/>. */
#include <rct/String.h>
#include "RTagsMessage.h"
#include "RTags.h"
#include <rct/Flags.h>

class IndexMessage : public RTagsMessage
{
Expand All @@ -41,17 +42,19 @@ class IndexMessage : public RTagsMessage
Escape = 0x1,
GuessFlags = 0x2
};
unsigned int flags() const { return mFlags; }
void setFlags(unsigned int flags) { mFlags = flags; }
void setFlag(Flag flag, bool on = true) { if (on) { mFlags |= flag; } else { mFlags &= ~flag; } }
Flags<Flag> flags() const { return mFlags; }
void setFlags(Flags<Flag> flags) { mFlags = flags; }
void setFlag(Flag flag, bool on = true) { mFlags.set(flag, on); }
virtual void encode(Serializer &serializer) const override;
virtual void decode(Deserializer &deserializer) override;
private:
Path mWorkingDirectory;
String mArgs;
Path mProjectRoot;
Path mCompilationDatabaseDir;
unsigned int mFlags;
Flags<Flag> mFlags;
};

RCT_FLAGS(IndexMessage::Flag);

#endif
Loading

0 comments on commit 09d6c9d

Please sign in to comment.