From 09d6c9d0deea0e6de5c1c0a2af4d4f4e068f057c Mon Sep 17 00:00:00 2001 From: Anders Bakken Date: Thu, 16 Apr 2015 22:36:55 -0700 Subject: [PATCH] Use Flags everywhere (well, almost everywhere). --- src/ClangIndexer.cpp | 24 ++++++++--------- src/ClassHierarchyJob.cpp | 2 +- src/CompletionThread.cpp | 5 ++-- src/CompletionThread.h | 8 ++++-- src/DependenciesJob.cpp | 2 +- src/DumpThread.cpp | 2 +- src/DumpThread.h | 2 +- src/FindFileJob.cpp | 6 ++--- src/FindSymbolsJob.cpp | 10 +++---- src/FollowLocationJob.cpp | 2 +- src/IncludeFileJob.cpp | 2 +- src/IndexDataMessage.h | 57 ++++++++++++++++++++++----------------- src/IndexMessage.h | 11 +++++--- src/IndexerJob.cpp | 4 +-- src/IndexerJob.h | 9 ++++--- src/JobScheduler.cpp | 12 ++++----- src/ListSymbolsJob.cpp | 6 +++-- src/Location.cpp | 4 +-- src/Location.h | 7 +++-- src/Match.h | 9 ++++--- src/Preprocessor.cpp | 18 ++++++------- src/Project.cpp | 12 ++++++--- src/Project.h | 7 +++-- src/QueryJob.cpp | 25 ++++++++--------- src/QueryJob.h | 43 +++++++++++++++++------------ src/QueryMessage.cpp | 8 +++--- src/QueryMessage.h | 23 +++++++--------- src/RClient.cpp | 14 +++++----- src/RClient.h | 7 ++--- src/RTags.cpp | 34 +++++++++++------------ src/RTags.h | 4 ++- src/RTagsClang.cpp | 8 +++--- src/RTagsClang.h | 26 +++++++++--------- src/ReferencesJob.cpp | 11 ++++---- src/Server.cpp | 37 ++++++++++--------------- src/Server.h | 15 +++++++---- src/Source.cpp | 8 +++--- src/Source.h | 47 ++++++++++++++++++-------------- src/StatusJob.cpp | 4 +-- src/Symbol.cpp | 4 ++- src/Symbol.h | 6 +++-- src/SymbolInfoJob.cpp | 14 +++++----- 42 files changed, 303 insertions(+), 256 deletions(-) diff --git a/src/ClangIndexer.cpp b/src/ClangIndexer.cpp index 109293fa6..8d285d77f 100644 --- a/src/ClangIndexer.cpp +++ b/src/ClangIndexer.cpp @@ -76,7 +76,7 @@ bool ClangIndexer::exec(const String &data) } uint64_t id; String socketFile; - uint32_t flags; + Flags indexerJobFlags; uint32_t connectTimeout; int32_t niceValue; Hash blockedFiles; @@ -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; @@ -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); @@ -231,7 +231,7 @@ Location ClangIndexer::createLocation(const Path &sourceFile, unsigned int line, if (id) { if (blockedPtr) { - Hash::iterator it = mIndexDataMessage.files().find(id); + Hash >::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. @@ -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) { @@ -278,7 +278,7 @@ Location ClangIndexer::createLocation(const Path &sourceFile, unsigned int line, id = mVisitFileResponseMessageFileId; break; } - unsigned int &flags = mIndexDataMessage.files()[id]; + Flags &flags = mIndexDataMessage.files()[id]; if (mVisitFileResponseMessageVisit) { flags |= IndexDataMessage::Visited; ++mIndexed; @@ -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 commandLineFlags = Source::Default; + const Flags flags = CXTranslationUnit_DetailedPreprocessingRecord; List unsavedFiles(mUnsavedFiles.size() + 1); int unsavedIndex = 0; for (const auto &it : mUnsavedFiles) { @@ -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 &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 @@ -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)]; diff --git a/src/ClassHierarchyJob.cpp b/src/ClassHierarchyJob.cpp index 5baf62fd0..5a5b80c1d 100644 --- a/src/ClassHierarchyJob.cpp +++ b/src/ClassHierarchyJob.cpp @@ -21,7 +21,7 @@ along with RTags. If not, see . */ ClassHierarchyJob::ClassHierarchyJob(const Location &loc, const std::shared_ptr &query, const std::shared_ptr &project) - : QueryJob(query, 0, project), location(loc) + : QueryJob(query, project), location(loc) { } diff --git a/src/CompletionThread.cpp b/src/CompletionThread.cpp index cb459b4c1..44f6ceae2 100644 --- a/src/CompletionThread.cpp +++ b/src/CompletionThread.cpp @@ -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 &conn) + Flags flags, const String &unsaved, + const std::shared_ptr &conn) { Request *request = new Request({ source, location, flags, unsaved, conn}); std::unique_lock lock(mMutex); @@ -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 flags = static_cast(clang_defaultEditingTranslationUnitOptions()); flags |= CXTranslationUnit_PrecompiledPreamble; flags |= CXTranslationUnit_CacheCompletionResults; flags |= CXTranslationUnit_SkipFunctionBodies; diff --git a/src/CompletionThread.h b/src/CompletionThread.h index 9ee894783..d935549f4 100644 --- a/src/CompletionThread.h +++ b/src/CompletionThread.h @@ -26,6 +26,7 @@ #include #include #include +#include class CompletionThread : public Thread { @@ -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 &conn); + void completeAt(const Source &source, const Location &location, Flags flags, + const String &unsaved, const std::shared_ptr &conn); void stop(); String dump(); private: @@ -57,7 +59,7 @@ class CompletionThread : public Thread } Source source; Location location; - unsigned int flags; + Flags flags; String unsaved; std::shared_ptr conn; }; @@ -107,4 +109,6 @@ class CompletionThread : public Thread std::condition_variable mCondition; }; +RCT_FLAGS(CompletionThread::Flag); + #endif diff --git a/src/DependenciesJob.cpp b/src/DependenciesJob.cpp index 417e77974..7f4bafae6 100644 --- a/src/DependenciesJob.cpp +++ b/src/DependenciesJob.cpp @@ -20,7 +20,7 @@ along with RTags. If not, see . */ #include "Project.h" DependenciesJob::DependenciesJob(const std::shared_ptr &query, const std::shared_ptr &project) - : QueryJob(query, QuietJob, project) + : QueryJob(query, project, QuietJob) { Path p = query->query(); p.resolve(); diff --git a/src/DumpThread.cpp b/src/DumpThread.cpp index 4d71cf068..a751db148 100644 --- a/src/DumpThread.cpp +++ b/src/DumpThread.cpp @@ -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 locationFlags; if (that->mQueryFlags & QueryMessage::NoColor) locationFlags |= Location::NoColor; CXString file; diff --git a/src/DumpThread.h b/src/DumpThread.h index f460ed447..af7972301 100644 --- a/src/DumpThread.h +++ b/src/DumpThread.h @@ -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 mQueryFlags; const Source mSource; std::shared_ptr mConnection; Hash mFiles; diff --git a/src/FindFileJob.cpp b/src/FindFileJob.cpp index 4d1eb5ae4..b1789bae6 100644 --- a/src/FindFileJob.cpp +++ b/src/FindFileJob.cpp @@ -19,16 +19,16 @@ along with RTags. If not, see . */ #include "FileManager.h" #include "Project.h" -static unsigned int flags(unsigned int queryFlags) +static Flags flags(Flags queryFlags) { - unsigned int flags = QueryJob::QuietJob; + Flags flags = QueryJob::QuietJob; if (queryFlags & QueryMessage::ElispList) flags |= QueryJob::QuoteOutput; return flags; } FindFileJob::FindFileJob(const std::shared_ptr &query, const std::shared_ptr &project) - : QueryJob(query, ::flags(query->flags()), project) + : QueryJob(query, project, ::flags(query->flags())) { const String q = query->query(); if (!q.isEmpty()) { diff --git a/src/FindSymbolsJob.cpp b/src/FindSymbolsJob.cpp index 0e9c98ee4..24fd683f9 100644 --- a/src/FindSymbolsJob.cpp +++ b/src/FindSymbolsJob.cpp @@ -19,13 +19,13 @@ along with RTags. If not, see . */ #include "RTagsClang.h" #include "Project.h" -static inline unsigned int jobFlags(unsigned int queryFlags) +static inline Flags jobFlags(Flags 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 &query, const std::shared_ptr &proj) - : QueryJob(query, ::jobFlags(query->flags()), proj), string(query->query()) + : QueryJob(query, proj, ::jobFlags(query->flags())), string(query->query()) { } @@ -49,14 +49,14 @@ int FindSymbolsJob::execute() }; proj->findSymbols(string, inserter, queryFlags()); if (!symbols.isEmpty()) { - unsigned int sortFlags = Project::Sort_None; + Flags sortFlags = Project::Sort_None; if (queryFlags() & QueryMessage::DeclarationOnly) sortFlags |= Project::Sort_DeclarationOnly; if (queryFlags() & QueryMessage::ReverseSort) sortFlags |= Project::Sort_Reverse; const List sorted = proj->sort(symbols, sortFlags); - const unsigned int writeFlags = filter ? Unfiltered : NoWriteFlags; + const Flags writeFlags = filter ? Unfiltered : NoWriteFlags; const int count = sorted.size(); ret = count ? 0 : 1; for (int i=0; i. */ FollowLocationJob::FollowLocationJob(const Location &loc, const std::shared_ptr &query, const std::shared_ptr &project) - : QueryJob(query, 0, project), location(loc) + : QueryJob(query, project), location(loc) { } diff --git a/src/IncludeFileJob.cpp b/src/IncludeFileJob.cpp index 88d561680..d5a1c526b 100644 --- a/src/IncludeFileJob.cpp +++ b/src/IncludeFileJob.cpp @@ -19,7 +19,7 @@ along with RTags. If not, see . */ #include "Project.h" IncludeFileJob::IncludeFileJob(const std::shared_ptr &query, const std::shared_ptr &project) - : QueryJob(query, 0, project) + : QueryJob(query, project) { const uint32_t fileId = Location::fileId(query->currentFile()); mSource = project->sources(fileId).value(query->buildIndex()); diff --git a/src/IndexDataMessage.h b/src/IndexDataMessage.h index a088c50d0..b87f8bf87 100644 --- a/src/IndexDataMessage.h +++ b/src/IndexDataMessage.h @@ -22,6 +22,7 @@ #include #include #include "IndexerJob.h" +#include class IndexDataMessage : public RTagsMessage { @@ -30,36 +31,24 @@ class IndexDataMessage : public RTagsMessage IndexDataMessage(const std::shared_ptr &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 flags() const { return mFlags; } + void setFlags(Flags flags) { mFlags = flags; } + void setFlag(Flag flag, bool on = true) { mFlags.set(flag, on); } Set visitedFiles() const { @@ -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 indexerJobFlags() const { return mIndexerJobFlags; } + void setIndexerJobFlags(Flags flags) { mIndexerJobFlags = flags; } uint64_t key() const { return mKey; } void setKey(uint64_t key) { mKey = key; } @@ -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 &files() { return mFiles; } + Hash > &files() { return mFiles; } private: Path mProject; uint64_t mParseTime, mKey, mId; - uint32_t mIndexerJobFlags; // indexerjobflags + Flags 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 mFiles; - unsigned int mFlags; + Hash > mFiles; + Flags 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 diff --git a/src/IndexMessage.h b/src/IndexMessage.h index 39c442d36..fe6d1a784 100644 --- a/src/IndexMessage.h +++ b/src/IndexMessage.h @@ -20,6 +20,7 @@ along with RTags. If not, see . */ #include #include "RTagsMessage.h" #include "RTags.h" +#include class IndexMessage : public RTagsMessage { @@ -41,9 +42,9 @@ 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 flags() const { return mFlags; } + void setFlags(Flags 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: @@ -51,7 +52,9 @@ class IndexMessage : public RTagsMessage String mArgs; Path mProjectRoot; Path mCompilationDatabaseDir; - unsigned int mFlags; + Flags mFlags; }; +RCT_FLAGS(IndexMessage::Flag); + #endif diff --git a/src/IndexerJob.cpp b/src/IndexerJob.cpp index 283236f9f..fed3ddd3c 100644 --- a/src/IndexerJob.cpp +++ b/src/IndexerJob.cpp @@ -22,7 +22,7 @@ uint64_t IndexerJob::sNextId = 1; IndexerJob::IndexerJob(const Source &s, - uint32_t f, + Flags f, const std::shared_ptr &p, const UnsavedFiles &u) : id(0), source(s), sourceFile(s.sourceFile()), flags(f), @@ -128,7 +128,7 @@ String IndexerJob::encode() const return ret; } -String IndexerJob::dumpFlags(unsigned int flags) +String IndexerJob::dumpFlags(Flags flags) { List ret; if (flags & Dirty) { diff --git a/src/IndexerJob.h b/src/IndexerJob.h index 0187b2495..a1d962180 100644 --- a/src/IndexerJob.h +++ b/src/IndexerJob.h @@ -23,6 +23,7 @@ along with RTags. If not, see . */ #include #include #include "Source.h" +#include class IndexerJob { @@ -38,10 +39,10 @@ class IndexerJob Type_Mask = Dirty|Compile }; - static String dumpFlags(unsigned int); + static String dumpFlags(Flags flags); IndexerJob(const Source &source, - uint32_t flags, + Flags flags, const std::shared_ptr &project, const UnsavedFiles &unsavedFiles = UnsavedFiles()); void acquireId(); @@ -50,7 +51,7 @@ class IndexerJob uint64_t id; Source source; Path sourceFile; - uint32_t flags; + Flags flags; Path project; int priority; enum { HeaderError = -1 }; @@ -61,4 +62,6 @@ class IndexerJob static uint64_t sNextId; }; +RCT_FLAGS(IndexerJob::Flag); + #endif diff --git a/src/JobScheduler.cpp b/src/JobScheduler.cpp index dba9a4559..1dc2bbdb5 100644 --- a/src/JobScheduler.cpp +++ b/src/JobScheduler.cpp @@ -248,18 +248,18 @@ void JobScheduler::dump(const std::shared_ptr &conn) if (!mPendingJobs.isEmpty()) { conn->write("Pending:"); for (const auto &node : mPendingJobs) { - conn->write<128>("%s: 0x%x %s", + conn->write<128>("%s: %s %s", node->job->sourceFile.constData(), - node->job->flags, + node->job->flags.toString().constData(), IndexerJob::dumpFlags(node->job->flags).constData()); } } if (!mActiveById.isEmpty()) { conn->write("Active:"); for (const auto &node : mActiveById) { - conn->write<128>("%s: 0x%x %s", + conn->write<128>("%s: %s %s", node.second->job->sourceFile.constData(), - node.second->job->flags, + node.second->job->flags.toString().constData(), IndexerJob::dumpFlags(node.second->job->flags).constData()); } } @@ -269,9 +269,9 @@ void JobScheduler::dump(const std::shared_ptr &conn) for (uint64_t headerErrorJobId : mHeaderErrorJobIds) { auto node = mActiveById.value(headerErrorJobId); assert(node); - conn->write<128>("%s: 0x%x %s", + conn->write<128>("%s: %s %s", node->job->sourceFile.constData(), - node->job->flags, + node->job->flags.toString().constData(), IndexerJob::dumpFlags(node->job->flags).constData()); } diff --git a/src/ListSymbolsJob.cpp b/src/ListSymbolsJob.cpp index b53919f41..4bbe6e61b 100644 --- a/src/ListSymbolsJob.cpp +++ b/src/ListSymbolsJob.cpp @@ -19,10 +19,12 @@ #include #include "RTags.h" -enum { DefaultFlags = QueryJob::WriteUnfiltered | QueryJob::QuietJob, ElispFlags = DefaultFlags | QueryJob::QuoteOutput }; +const Flags defaultFlags = (QueryJob::WriteUnfiltered | QueryJob::QuietJob); +const Flags elispFlags = (defaultFlags | QueryJob::QuoteOutput); ListSymbolsJob::ListSymbolsJob(const std::shared_ptr &query, const std::shared_ptr &proj) - : QueryJob(query, query->flags() & QueryMessage::ElispList ? ElispFlags : DefaultFlags, proj), string(query->query()) + : QueryJob(query, proj, query->flags() & QueryMessage::ElispList ? elispFlags : defaultFlags), + string(query->query()) { } diff --git a/src/Location.cpp b/src/Location.cpp index 2e1754183..7585b5e7c 100644 --- a/src/Location.cpp +++ b/src/Location.cpp @@ -34,7 +34,7 @@ const uint64_t Location::FILEID_MASK = createMask(0, FileBits); const uint64_t Location::LINE_MASK = createMask(FileBits, LineBits); const uint64_t Location::COLUMN_MASK = createMask(FileBits + LineBits, ColumnBits); -String Location::key(unsigned int flags) const +String Location::key(Flags flags) const { if (isNull()) return String(); @@ -59,7 +59,7 @@ String Location::key(unsigned int flags) const return ret; } -String Location::context(unsigned int flags) const +String Location::context(Flags flags) const { const String code = path().readAll(); String ret; diff --git a/src/Location.h b/src/Location.h index 1355f7961..b287c2481 100644 --- a/src/Location.h +++ b/src/Location.h @@ -23,6 +23,7 @@ #include #include #include +#include #if defined(OS_Linux) #include #endif @@ -158,8 +159,8 @@ class Location NoColor = 0x2 }; - String key(unsigned int flags = NoFlag) const; - String context(unsigned int flags) const; + String key(Flags flags = NoFlag) const; + String context(Flags flags) const; static Location decode(const String &data) { @@ -261,6 +262,8 @@ class Location static const uint64_t COLUMN_MASK; }; +RCT_FLAGS(Location::KeyFlag); + template <> struct FixedSize { static constexpr size_t value = sizeof(Location::value); diff --git a/src/Match.h b/src/Match.h index 47fe23c22..c07897856 100644 --- a/src/Match.h +++ b/src/Match.h @@ -19,6 +19,7 @@ along with RTags. If not, see . */ #include #include #include +#include class Match { @@ -31,10 +32,9 @@ class Match }; inline Match() - : mFlags(0) {} - inline Match(const String &pattern, unsigned int flags = Flag_StringMatch) + inline Match(const String &pattern, Flags flags = Flag_StringMatch) : mFlags(flags) { if (flags & Flag_Regex) @@ -42,7 +42,7 @@ class Match mPattern = pattern; } - unsigned int flags() const { return mFlags; } + Flags flags() const { return mFlags; } inline bool match(const String &text) const { @@ -80,8 +80,9 @@ class Match private: std::regex mRegex; String mPattern; - unsigned int mFlags; + Flags mFlags; }; +RCT_FLAGS(Match::Flag); inline Log operator<<(Log log, const Match &match) { diff --git a/src/Preprocessor.cpp b/src/Preprocessor.cpp index 42ea51023..36dd79025 100644 --- a/src/Preprocessor.cpp +++ b/src/Preprocessor.cpp @@ -26,18 +26,16 @@ Preprocessor::Preprocessor(const Source &source, const std::shared_ptrfinished().connect(std::bind(&Preprocessor::onProcessFinished, this)); } -enum { - Flags = (Source::IncludeSourceFile - | Source::ExcludeDefaultArguments - | Source::ExcludeDefaultIncludePaths - | Source::ExcludeDefaultDefines - | Source::IncludeIncludepaths - | Source::IncludeDefines) -}; +const Flags SourceFlags = (Source::IncludeSourceFile + | Source::ExcludeDefaultArguments + | Source::ExcludeDefaultIncludePaths + | Source::ExcludeDefaultDefines + | Source::IncludeIncludepaths + | Source::IncludeDefines); void Preprocessor::preprocess() { - List args = mSource.toCommandLine(Flags); + List args = mSource.toCommandLine(SourceFlags); args.append("-E"); mProcess->start(mSource.compiler(), args); @@ -46,7 +44,7 @@ void Preprocessor::preprocess() void Preprocessor::onProcessFinished() { mConnection->client()->setWriteMode(SocketClient::Synchronous); - const unsigned int flags = (Flags | Source::IncludeCompiler); + const Flags flags = (SourceFlags | Source::IncludeCompiler); mConnection->write<256>("// %s", String::join(mSource.toCommandLine(flags), ' ').constData()); mConnection->write(mProcess->readAllStdOut()); const String err = mProcess->readAllStdErr(); diff --git a/src/Project.cpp b/src/Project.cpp index 8230e5787..0f68eadfb 100644 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -1102,7 +1102,7 @@ void Project::reloadFileManager() void Project::findSymbols(const String &string, const std::function &)> &inserter, - unsigned int queryFlags, + Flags queryFlags, uint32_t fileFilter) { const bool wildcard = queryFlags & QueryMessage::WildcardSymbolNames && (string.contains('*') || string.contains('?')); @@ -1171,7 +1171,7 @@ void Project::findSymbols(const String &string, } } -List Project::sort(const Set &symbols, unsigned int flags) +List Project::sort(const Set &symbols, Flags flags) { List sorted; sorted.reserve(symbols.size()); @@ -1217,8 +1217,12 @@ void Project::watch(const Path &file) String Project::toCompilationDatabase() const { - const unsigned int flags = (Source::IncludeCompiler | Source::IncludeSourceFile | Source::IncludeDefines - | Source::IncludeIncludepaths | Source::QuoteDefines | Source::FilterBlacklist); + const Flags flags = (Source::IncludeCompiler + | Source::IncludeSourceFile + | Source::IncludeDefines + | Source::IncludeIncludepaths + | Source::QuoteDefines + | Source::FilterBlacklist); Value ret(List(mSources.size())); int i = 0; for (const auto &source : mSources) { diff --git a/src/Project.h b/src/Project.h index 37005b064..d6195f47a 100644 --- a/src/Project.h +++ b/src/Project.h @@ -29,6 +29,7 @@ #include #include #include +#include class IndexDataMessage; class FileManager; @@ -124,7 +125,7 @@ class Project : public std::enable_shared_from_this }; void findSymbols(const String &symbolName, const std::function &)> &func, - unsigned int queryFlags, + Flags queryFlags, uint32_t fileFilter = 0); Symbol findSymbol(const Location &location, int *index = 0); @@ -150,7 +151,7 @@ class Project : public std::enable_shared_from_this Sort_DeclarationOnly = 0x1, Sort_Reverse = 0x2 }; - List sort(const Set &symbols, unsigned int flags = Sort_None); + List sort(const Set &symbols, Flags flags = Sort_None); const Files &files() const { return mFiles; } Files &files() { return mFiles; } @@ -341,6 +342,8 @@ class Project : public std::enable_shared_from_this mutable std::mutex mMutex; }; +RCT_FLAGS(Project::SortFlag); + inline bool Project::visitFile(uint32_t visitFileId, const Path &path, uint64_t key) { std::lock_guard lock(mMutex); diff --git a/src/QueryJob.cpp b/src/QueryJob.cpp index 9d0acfc4d..f98034343 100644 --- a/src/QueryJob.cpp +++ b/src/QueryJob.cpp @@ -21,12 +21,11 @@ along with RTags. If not, see . */ #include "QueryMessage.h" #include "Project.h" -// static int count = 0; -// static int active = 0; - -QueryJob::QueryJob(const std::shared_ptr &query, unsigned int jobFlags, const std::shared_ptr &proj) - : mAborted(false), mLinesWritten(0), mQueryMessage(query), mJobFlags(jobFlags), mProject(proj), mPathFilters(0), - mPathFiltersRegex(0) +QueryJob::QueryJob(const std::shared_ptr &query, + const std::shared_ptr &proj, + Flags jobFlags) + : mAborted(false), mLinesWritten(0), mQueryMessage(query), mJobFlags(jobFlags), + mProject(proj), mPathFilters(0), mPathFiltersRegex(0) { if (mProject) mProject->beginScope(); @@ -48,7 +47,7 @@ QueryJob::QueryJob(const std::shared_ptr &query, unsigned int jobF } } -QueryJob::QueryJob(unsigned int jobFlags, const std::shared_ptr &proj) +QueryJob::QueryJob(const std::shared_ptr &proj, Flags jobFlags) : mAborted(false), mLinesWritten(0), mJobFlags(jobFlags), mProject(proj), mPathFilters(0), mPathFiltersRegex(0), mConnection(0) { @@ -72,7 +71,7 @@ uint32_t QueryJob::fileFilter() const return 0; } -bool QueryJob::write(const String &out, unsigned int flags) +bool QueryJob::write(const String &out, Flags flags) { if ((mJobFlags & WriteUnfiltered) || (flags & Unfiltered) || filter(out)) { if ((mJobFlags & QuoteOutput) && !(flags & DontQuote)) { @@ -99,7 +98,7 @@ bool QueryJob::write(const String &out, unsigned int flags) return true; } -bool QueryJob::writeRaw(const String &out, unsigned int flags) +bool QueryJob::writeRaw(const String &out, Flags flags) { assert(mConnection); if (!(flags & IgnoreMax) && mQueryMessage) { @@ -125,7 +124,7 @@ bool QueryJob::writeRaw(const String &out, unsigned int flags) return true; } -bool QueryJob::write(const Location &location, unsigned int flags) +bool QueryJob::write(const Location &location, Flags flags) { if (location.isNull()) return false; @@ -179,12 +178,14 @@ bool QueryJob::write(const Location &location, unsigned int flags) return write(out, flags); } -bool QueryJob::write(const Symbol &symbol, unsigned int cflags, unsigned int flags) +bool QueryJob::write(const Symbol &symbol, + Flags toStringFlags, + Flags writeFlags) { if (symbol.isNull()) return false; - return write(symbol.toString(cflags, keyFlags(), project()), flags); + return write(symbol.toString(toStringFlags, keyFlags(), project()), writeFlags); } bool QueryJob::filter(const String &value) const diff --git a/src/QueryJob.h b/src/QueryJob.h index 570e3fe7e..777f2179e 100644 --- a/src/QueryJob.h +++ b/src/QueryJob.h @@ -13,8 +13,8 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with RTags. If not, see . */ -#ifndef Job_h -#define Job_h +#ifndef QueryJob_h +#define QueryJob_h #include #include @@ -25,6 +25,7 @@ along with RTags. If not, see . */ #include "RTagsClang.h" #include "QueryMessage.h" #include +#include class Location; class QueryMessage; @@ -34,15 +35,18 @@ struct Symbol; class QueryJob { public: - enum Flag { + enum JobFlag { None = 0x0, WriteUnfiltered = 0x1, QuoteOutput = 0x2, QuietJob = 0x4 }; enum { Priority = 10 }; - QueryJob(const std::shared_ptr &msg, unsigned int jobFlags, const std::shared_ptr &proj); - QueryJob(unsigned int jobFlags, const std::shared_ptr &project); + QueryJob(const std::shared_ptr &msg, + const std::shared_ptr &proj, + Flags jobFlags = Flags()); + QueryJob(const std::shared_ptr &project, + Flags jobFlags = Flags()); ~QueryJob(); bool hasFilter() const { return mPathFilters || mPathFiltersRegex; } @@ -54,18 +58,20 @@ class QueryJob DontQuote = 0x2, Unfiltered = 0x4 }; - bool write(const String &out, unsigned int flags = NoWriteFlags); - bool write(const Symbol &symbol, unsigned int cursorInfoFlags = 0, unsigned int flags = NoWriteFlags); - bool write(const Location &location, unsigned int flags = NoWriteFlags); + bool write(const String &out, Flags flags = Flags()); + bool write(const Symbol &symbol, + Flags sourceFlags = Flags(), + Flags writeFlags = Flags()); + bool write(const Location &location, Flags writeFlags = Flags()); - template bool write(unsigned int flags, const char *format, ...); + template bool write(Flags writeFlags, const char *format, ...); template bool write(const char *format, ...); - unsigned int jobFlags() const { return mJobFlags; } - void setJobFlags(unsigned int flags) { mJobFlags = flags; } - void setJobFlag(Flag flag, bool on = true) { if (on) { mJobFlags |= flag; } else { mJobFlags &= ~flag; } } - unsigned int queryFlags() const { return mQueryMessage ? mQueryMessage->flags() : 0; } + Flags jobFlags() const { return mJobFlags; } + void setJobFlags(Flags flags) { mJobFlags = flags; } + void setJobFlag(JobFlag flag, bool on = true) { mJobFlags.set(flag, on); } + Flags queryFlags() const { return mQueryMessage ? mQueryMessage->flags() : Flags(); } std::shared_ptr queryMessage() const { return mQueryMessage; } - unsigned int keyFlags() const { return QueryMessage::keyFlags(queryFlags()); } + Flags keyFlags() const { return QueryMessage::keyFlags(queryFlags()); } bool filter(const String &val) const; Signal > &output() { return mOutput; } std::shared_ptr project() const { return mProject; } @@ -80,9 +86,9 @@ class QueryJob mutable std::mutex mMutex; bool mAborted; int mLinesWritten; - bool writeRaw(const String &out, unsigned int flags); + bool writeRaw(const String &out, Flags flags); std::shared_ptr mQueryMessage; - unsigned int mJobFlags; + Flags mJobFlags; Signal > mOutput; std::shared_ptr mProject; List *mPathFilters; @@ -91,8 +97,11 @@ class QueryJob std::shared_ptr mConnection; }; +RCT_FLAGS(QueryJob::JobFlag); +RCT_FLAGS(QueryJob::WriteFlag); + template -inline bool QueryJob::write(unsigned int flags, const char *format, ...) +inline bool QueryJob::write(Flags flags, const char *format, ...) { va_list args; va_start(args, format); diff --git a/src/QueryMessage.cpp b/src/QueryMessage.cpp index 172b743e3..6416c89e2 100644 --- a/src/QueryMessage.cpp +++ b/src/QueryMessage.cpp @@ -18,7 +18,7 @@ along with RTags. If not, see . */ #include QueryMessage::QueryMessage(Type type) - : RTagsMessage(MessageId), mType(type), mFlags(0), mMax(-1), mMinLine(-1), mMaxLine(-1), mBuildIndex(0) + : RTagsMessage(MessageId), mType(type), mMax(-1), mMinLine(-1), mMaxLine(-1), mBuildIndex(0) { } @@ -36,9 +36,9 @@ void QueryMessage::decode(Deserializer &deserializer) >> mUnsavedFiles; } -unsigned int QueryMessage::keyFlags(unsigned int queryFlags) +Flags QueryMessage::keyFlags(Flags queryFlags) { - unsigned int ret = Location::NoFlag; + Flags ret; if (!(queryFlags & NoContext)) ret |= Location::ShowContext; if (queryFlags & NoColor) @@ -48,7 +48,7 @@ unsigned int QueryMessage::keyFlags(unsigned int queryFlags) Match QueryMessage::match() const { - unsigned int flags = Match::Flag_StringMatch; + Flags flags = Match::Flag_StringMatch; if (mFlags & MatchRegex) flags |= Match::Flag_Regex; diff --git a/src/QueryMessage.h b/src/QueryMessage.h index 605dda3f1..79e63a88b 100644 --- a/src/QueryMessage.h +++ b/src/QueryMessage.h @@ -23,6 +23,7 @@ along with RTags. If not, see . */ #include #include "Match.h" #include "Location.h" +#include class QueryMessage : public RTagsMessage { @@ -136,8 +137,8 @@ class QueryMessage : public RTagsMessage int max() const { return mMax; } void setMax(int max) { mMax = max; } - unsigned int flags() const { return mFlags; } - void setFlags(unsigned int flags) + Flags flags() const { return mFlags; } + void setFlags(Flags flags) { mFlags = flags; switch (mType) { @@ -154,18 +155,10 @@ class QueryMessage : public RTagsMessage } } - void setFlag(Flag flag, bool on = true) - { - if (on) { - mFlags |= flag; - } else { - mFlags &= ~flag; - } - } - + void setFlag(Flag flag, bool on = true) { mFlags.set(flag, on); } static Flag flagFromString(const String &string); - static unsigned int keyFlags(unsigned int queryFlags); - inline unsigned int keyFlags() const { return keyFlags(mFlags); } + static Flags keyFlags(Flags queryFlags); + inline Flags keyFlags() const { return keyFlags(mFlags); } virtual void encode(Serializer &serializer) const override; virtual void decode(Deserializer &deserializer) override; @@ -175,13 +168,15 @@ class QueryMessage : public RTagsMessage private: String mQuery; Type mType; - unsigned int mFlags; + Flags mFlags; int mMax, mMinLine, mMaxLine, mBuildIndex; List mPathFilters; Path mCurrentFile; UnsavedFiles mUnsavedFiles; }; +RCT_FLAGS(QueryMessage::Flag); + DECLARE_NATIVE_TYPE(QueryMessage::Type); #endif // QUERYMESSAGE_H diff --git a/src/RClient.cpp b/src/RClient.cpp index 3686da693..7689161f8 100644 --- a/src/RClient.cpp +++ b/src/RClient.cpp @@ -246,12 +246,12 @@ class QueryCommand : public RCCommand { public: QueryCommand(QueryMessage::Type t, const String &q) - : RCCommand(), type(t), query(q), extraQueryFlags(0) + : RCCommand(), type(t), query(q) {} const QueryMessage::Type type; const String query; - unsigned int extraQueryFlags; + Flags extraQueryFlags; virtual bool exec(RClient *rc, const std::shared_ptr &connection) override { @@ -367,9 +367,9 @@ class CompileCommand : public RCCommand }; RClient::RClient() - : mQueryFlags(0), mMax(-1), mLogLevel(0), mTimeout(-1), - mMinOffset(-1), mMaxOffset(-1), mConnectTimeout(DEFAULT_CONNECT_TIMEOUT), - mBuildIndex(0), mEscapeMode(Escape_Auto), mGuessFlags(false), mArgc(0), mArgv(0) + : mMax(-1), mLogLevel(0), mTimeout(-1), mMinOffset(-1), mMaxOffset(-1), + mConnectTimeout(DEFAULT_CONNECT_TIMEOUT), mBuildIndex(0), + mEscapeMode(Escape_Auto), mGuessFlags(false), mArgc(0), mArgv(0) { } @@ -378,7 +378,7 @@ RClient::~RClient() cleanupLogging(); } -void RClient::addQuery(QueryMessage::Type type, const String &query, unsigned int extraQueryFlags) +void RClient::addQuery(QueryMessage::Type type, const String &query, Flags extraQueryFlags) { std::shared_ptr cmd(new QueryCommand(type, query)); cmd->extraQueryFlags = extraQueryFlags; @@ -842,7 +842,7 @@ RClient::ParseStatus RClient::parse(int &argc, char **argv) case IncludeFile: case JobCount: case Status: { - unsigned int extraQueryFlags = 0; + Flags extraQueryFlags; QueryMessage::Type type = QueryMessage::Invalid; bool resolve = true; switch (opt->option) { diff --git a/src/RClient.h b/src/RClient.h index b9f0e8fec..2b88820e7 100644 --- a/src/RClient.h +++ b/src/RClient.h @@ -152,13 +152,14 @@ class RClient String socketFile() const { return mSocketFile; } Path projectRoot() const { return mProjectRoot; } - unsigned int queryFlags() const { return mQueryFlags; } + Flags queryFlags() const { return mQueryFlags; } int argc() const { return mArgc; } char **argv() const { return mArgv; } void onNewMessage(const std::shared_ptr &message, const std::shared_ptr &); private: - void addQuery(QueryMessage::Type t, const String &query = String(), unsigned int extraQueryFlags = 0); + void addQuery(QueryMessage::Type t, const String &query = String(), + Flags extraQueryFlags = Flags()); void addQuitCommand(int exitCode); void addLog(int level); @@ -171,7 +172,7 @@ class RClient void addCompile(const Path &cwd, const String &args, EscapeMode escapeMode); void addCompile(const Path &dir, EscapeMode escapeMode); - unsigned int mQueryFlags; + Flags mQueryFlags; int mMax, mLogLevel, mTimeout, mMinOffset, mMaxOffset, mConnectTimeout, mBuildIndex; Set mPathFilters; UnsavedFiles mUnsavedFiles; diff --git a/src/RTags.cpp b/src/RTags.cpp index 4d867a9af..aafc607e8 100644 --- a/src/RTags.cpp +++ b/src/RTags.cpp @@ -48,7 +48,7 @@ Path encodeSourceFilePath(const Path &dataDir, const Path &project, uint32_t fil } -Path findAncestor(Path path, const char *fn, unsigned int flags) +Path findAncestor(Path path, const char *fn, Flags flags = Flags()) { Path ret; int slash = path.size(); @@ -155,7 +155,7 @@ Map rtagsConfig(const Path &path) struct Entry { const char *name; - const unsigned int flags; + const Flags flags; }; static inline Path checkEntries(const Entry *entries, const Path &path, const Path &home) @@ -194,23 +194,23 @@ Path findProjectRoot(const Path &path, ProjectRootMode mode) static const Path home = Path::home(); if (mode == SourceRoot) { const Entry before[] = { - { ".git", 0 }, - { ".svn", 0 }, - { ".bzr", 0 }, - { ".tup", 0 }, - { "GTAGS", 0 }, - { "configure", 0 }, - { "CMakeLists.txt", 0 }, + { ".git", Flags() }, + { ".svn", Flags() }, + { ".bzr", Flags() }, + { ".tup", Flags() }, + { "GTAGS", Flags() }, + { "configure", Flags() }, + { "CMakeLists.txt", Flags() }, { "*.pro", Wildcard }, - { "scons.1", 0 }, + { "scons.1", Flags() }, { "*.scons", Wildcard }, - { "SConstruct", 0 }, + { "SConstruct", Flags() }, { "autogen.*", Wildcard }, { "GNUMakefile*", Wildcard }, { "INSTALL*", Wildcard }, { "README*", Wildcard }, - { "compile_commands.json", 0 }, - { 0, 0 } + { "compile_commands.json", Flags() }, + { 0, Flags() } }; { const Path e = checkEntries(before, path, home); @@ -221,7 +221,7 @@ Path findProjectRoot(const Path &path, ProjectRootMode mode) if (!ret.isEmpty()) return ret; { - const Path configStatus = findAncestor(path, "config.status", 0); + const Path configStatus = findAncestor(path, "config.status"); if (!configStatus.isEmpty()) { if (mode == BuildRoot) return configStatus; @@ -259,7 +259,7 @@ Path findProjectRoot(const Path &path, ProjectRootMode mode) } } { - const Path cmakeCache = findAncestor(path, "CMakeCache.txt", 0); + const Path cmakeCache = findAncestor(path, "CMakeCache.txt"); if (!cmakeCache.isEmpty()) { if (mode == BuildRoot) return cmakeCache; @@ -313,9 +313,9 @@ Path findProjectRoot(const Path &path, ProjectRootMode mode) } } const Entry after[] = { - { "build.ninja", 0 }, + { "build.ninja", Flags() }, { "Makefile*", Wildcard }, - { 0, 0 } + { 0, Flags() } }; { diff --git a/src/RTags.h b/src/RTags.h index 63d4044da..fa01228cf 100644 --- a/src/RTags.h +++ b/src/RTags.h @@ -28,6 +28,7 @@ along with RTags. If not, see . */ #include #include #include +#include class Database; class Project; @@ -220,7 +221,8 @@ enum FindAncestorFlag { Shallow = 0x1, Wildcard = 0x2 }; -Path findAncestor(Path path, const char *fn, unsigned int flags); +RCT_FLAGS(FindAncestorFlag); +Path findAncestor(Path path, const char *fn, Flags flags); Map rtagsConfig(const Path &path); enum { DefinitionBit = 0x1000 }; diff --git a/src/RTagsClang.cpp b/src/RTagsClang.cpp index 92e042d6b..41387708f 100644 --- a/src/RTagsClang.cpp +++ b/src/RTagsClang.cpp @@ -34,7 +34,7 @@ String eatString(CXString str) return ret; } -String cursorToString(CXCursor cursor, unsigned int flags) +String cursorToString(CXCursor cursor, Flags flags) { const CXCursorKind kind = clang_getCursorKind(cursor); String ret; @@ -111,7 +111,7 @@ String cursorToString(CXCursor cursor, unsigned int flags) void parseTranslationUnit(const Path &sourceFile, const List &args, CXTranslationUnit &unit, CXIndex index, CXUnsavedFile *unsaved, int unsavedCount, - unsigned int translationUnitFlags, + Flags translationUnitFlags, String *clangLine) { @@ -142,14 +142,14 @@ void parseTranslationUnit(const Path &sourceFile, const List &args, for (int i=0; i<3; ++i) { auto error = clang_parseTranslationUnit2(index, sourceFile.constData(), clangArgs.data(), idx, unsaved, unsavedCount, - translationUnitFlags, &unit); + translationUnitFlags.cast(), &unit); if (error != CXError_Crashed) break; } #else unit = clang_parseTranslationUnit(index, sourceFile.constData(), clangArgs.data(), idx, unsaved, unsavedCount, - translationUnitFlags); + translationUnitFlags.cast()); #endif // error() << sourceFile << sw.elapsed(); } diff --git a/src/RTagsClang.h b/src/RTagsClang.h index 8d48344be..a659c9f08 100644 --- a/src/RTagsClang.h +++ b/src/RTagsClang.h @@ -21,6 +21,7 @@ along with RTags. If not, see . */ #include "RTags.h" #include "Symbol.h" #include +#include struct Unit; inline bool operator==(const CXCursor &l, CXCursorKind r) @@ -63,12 +64,15 @@ enum CursorToStringFlags { IncludeSpecializedUsr = 0x4, AllCursorToStringFlags = IncludeUSR|IncludeRange|IncludeSpecializedUsr }; -String cursorToString(CXCursor cursor, unsigned int = DefaultCursorToStringFlags); +RCT_FLAGS(CursorToStringFlags); +String cursorToString(CXCursor cursor, Flags = DefaultCursorToStringFlags); + +RCT_FLAGS(CXTranslationUnit_Flags); void parseTranslationUnit(const Path &sourceFile, const List &args, CXTranslationUnit &unit, CXIndex index, CXUnsavedFile *unsaved, int unsavedCount, - unsigned int translationUnitFlags = 0, + Flags translationUnitFlags = CXTranslationUnit_None, String *clangLine = 0); void reparseTranslationUnit(CXTranslationUnit &unit, CXUnsavedFile *unsaved, int unsavedCount); CXCursor resolveAutoTypeRef(const CXCursor &cursor, bool *isAuto = 0); @@ -156,7 +160,7 @@ inline bool startsWith(const List &list, const T &str) return false; } -inline bool isReference(unsigned int kind) +inline bool isReference(CXCursorKind kind) { if (clang_isReference(static_cast(kind))) return true; @@ -175,7 +179,7 @@ inline bool isReference(unsigned int kind) return false; } -inline bool isFunction(unsigned int kind) +inline bool isFunction(CXCursorKind kind) { switch (kind) { case CXCursor_FunctionTemplate: @@ -192,7 +196,7 @@ inline bool isFunction(unsigned int kind) return false; } -inline bool isCursor(uint16_t kind) +inline bool isCursor(CXCursorKind kind) { switch (kind) { case CXCursor_LabelStmt: @@ -207,12 +211,10 @@ inline bool isCursor(uint16_t kind) return clang_isDeclaration(static_cast(kind)); } -static inline CursorType cursorType(uint16_t kind) +static inline CursorType cursorType(CXCursorKind kind) { - switch (kind) { - case CXCursor_InclusionDirective: + if (kind == CXCursor_InclusionDirective) return Type_Include; - } if (clang_isStatement(static_cast(kind))) { return Type_Other; } else if (RTags::isCursor(kind)) { @@ -223,7 +225,7 @@ static inline CursorType cursorType(uint16_t kind) return Type_Other; } -static inline bool isContainer(uint16_t kind) +static inline bool isContainer(CXCursorKind kind) { switch (kind) { case CXCursor_CXXMethod: @@ -309,13 +311,13 @@ struct SortedSymbol { SortedSymbol(const Location &loc = Location(), bool definition = false, - uint16_t k = CXCursor_FirstInvalid) + CXCursorKind k = CXCursor_FirstInvalid) : location(loc), isDefinition(definition), kind(k) {} Location location; bool isDefinition; - uint16_t kind; + CXCursorKind kind; int rank() const { diff --git a/src/ReferencesJob.cpp b/src/ReferencesJob.cpp index e5a63d175..4fa3dda82 100644 --- a/src/ReferencesJob.cpp +++ b/src/ReferencesJob.cpp @@ -19,13 +19,13 @@ #include "Project.h" ReferencesJob::ReferencesJob(const Location &loc, const std::shared_ptr &query, const std::shared_ptr &proj) - : QueryJob(query, 0, proj) + : QueryJob(query, proj) { locations.insert(loc); } ReferencesJob::ReferencesJob(const String &sym, const std::shared_ptr &query, const std::shared_ptr &proj) - : QueryJob(query, 0, proj), symbolName(sym) + : QueryJob(query, proj), symbolName(sym) { } @@ -36,7 +36,7 @@ int ReferencesJob::execute() if (!proj) return 1; Set refs; - Map > references; + Map > references; if (!symbolName.isEmpty()) { const bool hasFilter = QueryJob::hasFilter(); auto inserter = [this, hasFilter](Project::SymbolMatchType type, const String &string, const Set &locs) { @@ -66,6 +66,7 @@ int ReferencesJob::execute() first = false; startLocation = sym.location; } + if (sym.isReference()) sym = proj->findTarget(sym); if (sym.isNull()) @@ -129,7 +130,7 @@ int ReferencesJob::execute() if (rename) { if (!references.isEmpty()) { if (queryFlags() & QueryMessage::ReverseSort) { - Map >::const_iterator it = references.end(); + Map >::const_iterator it = references.end(); do { --it; write(it->first); @@ -144,7 +145,7 @@ int ReferencesJob::execute() } else { List sorted; sorted.reserve(references.size()); - for (Map >::const_iterator it = references.begin(); + for (Map >::const_iterator it = references.begin(); it != references.end(); ++it) { sorted.append(RTags::SortedSymbol(it->first, it->second.first, it->second.second)); } diff --git a/src/Server.cpp b/src/Server.cpp index e9078550e..0f1c9f768 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -434,10 +434,14 @@ String Server::guessArguments(const String &args, const Path &pwd, const Path &p return String::join(ret, ' '); } -bool Server::index(const String &args, const Path &pwd, - const Path &projectRootOverride, unsigned int indexMessageFlags) +bool Server::index(const String &args, + const Path &pwd, + const Path &projectRootOverride, + Flags indexMessageFlags) { - const unsigned int sourceParseFlags = indexMessageFlags & IndexMessage::Escape ? Source::Escape : Source::None; + const Flags sourceParseFlags = (indexMessageFlags & IndexMessage::Escape + ? Source::Escape + : Source::None); String arguments; List unresolvedPaths; List sources; @@ -838,23 +842,10 @@ void Server::generateTest(const std::shared_ptr &query, const std: const Source source = project->sources(fileId).value(query->buildIndex()); if (!source.isNull()) { - enum CommandLineMode { - IncludeCompiler = 0x001, - IncludeSourceFile = 0x002, - IncludeDefines = 0x004, - IncludeIncludepaths = 0x008, - QuoteDefines = 0x010, - FilterBlacklist = 0x020, - ExcludeDefaultArguments = 0x040, - ExcludeDefaultIncludePaths = 0x080, - ExcludeDefaultDefines = 0x100, - Default = IncludeDefines|IncludeIncludepaths|FilterBlacklist - }; - - const unsigned int flags = (Source::Default - |Source::ExcludeDefaultDefines - |Source::ExcludeDefaultIncludePaths - |Source::ExcludeDefaultArguments); + const Flags flags = (Source::Default + | Source::ExcludeDefaultDefines + | Source::ExcludeDefaultIncludePaths + | Source::ExcludeDefaultArguments); const Path root = source.sourceFile().parentDir().ensureTrailingSlash(); List compile = source.toCommandLine(flags); @@ -1357,7 +1348,7 @@ void Server::sources(const std::shared_ptr &query, const std::shar if (sources.size() > 1) out = String::format<4>("%d: ", idx); if (flagsOnly) { - out += String::join(it.toCommandLine(0), splitLine ? '\n' : ' '); + out += String::join(it.toCommandLine(), splitLine ? '\n' : ' '); } else { out += it.toString(); } @@ -1378,7 +1369,7 @@ void Server::sources(const std::shared_ptr &query, const std::shar conn->write<128>("%s%s%s", it.second.sourceFile().constData(), splitLine ? "\n" : ": ", - String::join(it.second.toCommandLine(0), splitLine ? '\n' : ' ').constData()); + String::join(it.second.toCommandLine(), splitLine ? '\n' : ' ').constData()); } else { conn->write(it.second.toString()); } @@ -1616,7 +1607,7 @@ void Server::codeCompleteAt(const std::shared_ptr &query, const st } const Location loc(fileId, line, column); - unsigned int flags = CompletionThread::None; + Flags flags; if (query->type() == QueryMessage::PrepareCodeCompleteAt) flags |= CompletionThread::Refresh; if (query->flags() & QueryMessage::ElispList) diff --git a/src/Server.h b/src/Server.h index 5d85c26b3..74b68fcad 100644 --- a/src/Server.h +++ b/src/Server.h @@ -22,6 +22,7 @@ along with RTags. If not, see . */ #include "Source.h" #include "IndexerJob.h" #include "Match.h" +#include "IndexMessage.h" #include #include #include @@ -29,8 +30,8 @@ along with RTags. If not, see . */ #include #include #include +#include -class IndexMessage; class CompletionThread; class Connection; class ErrorMessage; @@ -74,14 +75,14 @@ class Server }; struct Options { Options() - : options(0), jobCount(0), headerErrorJobCount(0), + : jobCount(0), headerErrorJobCount(0), rpVisitFileTimeout(0), rpIndexDataMessageTimeout(0), rpConnectTimeout(0), rpNiceValue(0), threadStackSize(0), maxCrashCount(0), completionCacheSize(0), testTimeout(60 * 1000 * 5), maxFileMapScopeCacheSize(512) {} Path socketFile, dataDir, argTransform; - unsigned int options; + Flags