diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1eed37bac..4748558bc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -97,7 +97,6 @@ target_link_libraries(shared rct) set(RTAGS_SOURCES CompilerManager.cpp CompletionThread.cpp - CursorInfo.cpp CursorInfoJob.cpp DependenciesJob.cpp Diagnostic.cpp diff --git a/src/Cursor.cpp b/src/Cursor.cpp index f2a86a89b..e9e5c762d 100644 --- a/src/Cursor.cpp +++ b/src/Cursor.cpp @@ -16,8 +16,53 @@ #include "Cursor.h" #include "RTags.h" +#include "RTagsClang.h" uint16_t Cursor::targetsValue() const { return RTags::createTargetsValue(kind, isDefinition()); } + + +String Cursor::toString(unsigned cursorInfoFlags, unsigned keyFlags) const +{ + String ret = String::format<1024>("SymbolName: %s\n" + "Kind: %s\n" + "Type: %s\n" // type + "SymbolLength: %u\n" + "%s" // range + "%s" // enumValue + "%s", // definition + symbolName.constData(), + kindSpelling().constData(), + RTags::eatString(clang_getTypeKindSpelling(type)).constData(), + symbolLength, + startLine != -1 ? String::format<32>("Range: %d:%d-%d:%d\n", startLine, startColumn, endLine, endColumn).constData() : "", +#if CINDEX_VERSION_MINOR > 1 + kind == CXCursor_EnumConstantDecl ? String::format<32>("Enum Value: %lld\n", enumValue).constData() : +#endif + "", + isDefinition() ? "Definition\n" : ""); + + // if (!targets.isEmpty() && !(cursorInfoFlags & IgnoreTargets)) { + // ret.append("Targets:\n"); + // for (auto tit = targets.begin(); tit != targets.end(); ++tit) { + // const Location &l = *tit; + // ret.append(String::format<128>(" %s\n", l.key(keyFlags).constData())); + // } + // } + + // if (!references.isEmpty() && !(cursorInfoFlags & IgnoreReferences)) { + // ret.append("References:\n"); + // for (auto rit = references.begin(); rit != references.end(); ++rit) { + // const Location &l = *rit; + // ret.append(String::format<128>(" %s\n", l.key(keyFlags).constData())); + // } + // } + return ret; +} + +String Cursor::kindSpelling(uint16_t kind) +{ + return RTags::eatString(clang_getCursorKindSpelling(static_cast(kind))); +} diff --git a/src/Cursor.h b/src/Cursor.h index f5ac7e047..4a4a219c9 100644 --- a/src/Cursor.h +++ b/src/Cursor.h @@ -1,5 +1,5 @@ -#ifndef Cursor_h -#define Cursor_h +#ifndef RTagsCursor_h +#define RTagsCursor_h /* This file is part of RTags. @@ -26,7 +26,7 @@ struct Cursor { Cursor() : symbolLength(0), kind(CXCursor_FirstInvalid), type(CXType_Invalid), enumValue(0), - startLine(0), startColumn(0), endLine(0), endColumn(0) + startLine(-1), startColumn(-1), endLine(-1), endColumn(-1) {} Location location; @@ -38,7 +38,7 @@ struct Cursor bool definition; int64_t enumValue; // only used if type == CXCursor_EnumConstantDecl }; - unsigned startLine, startColumn, endLine, endColumn; + int startLine, startColumn, endLine, endColumn; bool isNull() const { return !symbolLength; } @@ -57,6 +57,15 @@ struct Cursor } inline bool isDefinition() const { return kind == CXCursor_EnumConstantDecl || definition; } + + enum Flag { + IgnoreTargets = 0x1, + IgnoreReferences = 0x2, + DefaultFlags = 0x0 + }; + String toString(unsigned cursorInfoFlags = DefaultFlags, unsigned keyFlags = 0) const; + String kindSpelling() const { return kindSpelling(kind); } + static String kindSpelling(uint16_t kind); }; diff --git a/src/CursorInfo.cpp b/src/CursorInfo.cpp deleted file mode 100644 index cea396054..000000000 --- a/src/CursorInfo.cpp +++ /dev/null @@ -1,285 +0,0 @@ -/* This file is part of RTags. - -RTags is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -RTags is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -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 . */ - - -#include "CursorInfo.h" -#include "RTagsClang.h" - -String CursorInfo::kindSpelling(uint16_t kind) -{ - return RTags::eatString(clang_getCursorKindSpelling(static_cast(kind))); -} - -String CursorInfo::toString(unsigned cursorInfoFlags, unsigned keyFlags) const -{ - String ret = String::format<1024>("SymbolName: %s\n" - "Kind: %s\n" - "Type: %s\n" // type - "SymbolLength: %u\n" - "%s" // range - "%s" // enumValue - "%s", // definition - symbolName.constData(), - kindSpelling().constData(), - RTags::eatString(clang_getTypeKindSpelling(type)).constData(), - symbolLength, - startLine != -1 ? String::format<32>("Range: %d:%d-%d:%d\n", startLine, startColumn, endLine, endColumn).constData() : "", -#if CINDEX_VERSION_MINOR > 1 - kind == CXCursor_EnumConstantDecl ? String::format<32>("Enum Value: %lld\n", enumValue).constData() : -#endif - "", - isDefinition() ? "Definition\n" : ""); - - if (!targets.isEmpty() && !(cursorInfoFlags & IgnoreTargets)) { - ret.append("Targets:\n"); - for (auto tit = targets.begin(); tit != targets.end(); ++tit) { - const Location &l = *tit; - ret.append(String::format<128>(" %s\n", l.key(keyFlags).constData())); - } - } - - if (!references.isEmpty() && !(cursorInfoFlags & IgnoreReferences)) { - ret.append("References:\n"); - for (auto rit = references.begin(); rit != references.end(); ++rit) { - const Location &l = *rit; - ret.append(String::format<128>(" %s\n", l.key(keyFlags).constData())); - } - } - return ret; -} - -int CursorInfo::targetRank(const std::shared_ptr &target) const -{ - switch (target->kind) { - case CXCursor_Constructor: // this one should be more than class/struct decl - return 1; - case CXCursor_ClassDecl: - case CXCursor_StructDecl: - case CXCursor_ClassTemplate: - return 0; - case CXCursor_FieldDecl: - case CXCursor_VarDecl: - case CXCursor_FunctionDecl: - case CXCursor_CXXMethod: - // functiondecl and cxx method must be more than cxx - // CXCursor_FunctionTemplate. Since constructors for templatatized - // objects seem to come out as function templates - return 3; - case CXCursor_MacroDefinition: - return 4; - default: - return 2; - } -} - -std::shared_ptr CursorInfo::bestTarget(const SymbolMap &map, Location *loc) const -{ - const SymbolMap targets = targetInfos(map); - - auto best = targets.end(); - int bestRank = -1; - for (auto it = targets.begin(); it != targets.end(); ++it) { - const std::shared_ptr &ci = it->second; - const int r = targetRank(ci); - if (r > bestRank || (r == bestRank && ci->isDefinition())) { - bestRank = r; - best = it; - } - } - if (best != targets.end()) { - if (loc) - *loc = best->first; - return best->second; - } - return std::shared_ptr(); -} - -SymbolMap CursorInfo::targetInfos(const SymbolMap &map) const -{ - SymbolMap ret; - for (auto it = targets.begin(); it != targets.end(); ++it) { - auto found = RTags::findCursorInfo(map, *it); - if (found != map.end()) { - ret[*it] = found->second; - } else { - ret[*it] = std::make_shared(); - // we need this one for inclusion directives which target a - // non-existing CursorInfo - } - } - return ret; -} - -SymbolMap CursorInfo::referenceInfos(const SymbolMap &map) const -{ - SymbolMap ret; - for (auto it = references.begin(); it != references.end(); ++it) { - auto found = RTags::findCursorInfo(map, *it); - if (found != map.end()) { - ret[*it] = found->second; - } - } - return ret; -} - -SymbolMap CursorInfo::callers(const Location &loc, const SymbolMap &map) const -{ - SymbolMap ret; - const SymbolMap cursors = virtuals(loc, map); - const bool isClazz = isClass(); - for (auto c = cursors.begin(); c != cursors.end(); ++c) { - for (auto it = c->second->references.begin(); it != c->second->references.end(); ++it) { - const auto found = RTags::findCursorInfo(map, *it); - if (found == map.end()) - continue; - if (isClazz && found->second->kind == CXCursor_CallExpr) - continue; - if (RTags::isReference(found->second->kind)) { // is this always right? - ret[*it] = found->second; - } else if (kind == CXCursor_Constructor && (found->second->kind == CXCursor_VarDecl || found->second->kind == CXCursor_FieldDecl)) { - ret[*it] = found->second; - } - } - } - return ret; -} - -enum Mode { - ClassRefs, - VirtualRefs, - NormalRefs -}; - -static inline void allImpl(const SymbolMap &map, const Location &loc, const std::shared_ptr &info, SymbolMap &out, Mode mode, unsigned kind) -{ - if (out.contains(loc)) - return; - out[loc] = info; - const SymbolMap targets = info->targetInfos(map); - for (auto t = targets.begin(); t != targets.end(); ++t) { - bool ok = false; - switch (mode) { - case VirtualRefs: - case NormalRefs: - ok = (t->second->kind == kind); - break; - case ClassRefs: - ok = (t->second->isClass() || t->second->kind == CXCursor_Destructor || t->second->kind == CXCursor_Constructor); - break; - } - if (ok) - allImpl(map, t->first, t->second, out, mode, kind); - } - const SymbolMap refs = info->referenceInfos(map); - for (auto r = refs.begin(); r != refs.end(); ++r) { - switch (mode) { - case NormalRefs: - out[r->first] = r->second; - break; - case VirtualRefs: - if (r->second->kind == kind) { - allImpl(map, r->first, r->second, out, mode, kind); - } else { - out[r->first] = r->second; - } - break; - case ClassRefs: - if (info->isClass()) // for class/struct we want the references inserted directly regardless and also recursed - out[r->first] = r->second; - if (r->second->isClass() - || r->second->kind == CXCursor_Destructor - || r->second->kind == CXCursor_Constructor) { // if is a constructor/destructor/class reference we want to recurse it - allImpl(map, r->first, r->second, out, mode, kind); - } - } - } -} - -SymbolMap CursorInfo::allReferences(const Location &loc, const SymbolMap &map) const -{ - SymbolMap ret; - Mode mode = NormalRefs; - switch (kind) { - case CXCursor_Constructor: - case CXCursor_Destructor: - mode = ClassRefs; - break; - case CXCursor_CXXMethod: - mode = VirtualRefs; - break; - default: - mode = isClass() ? ClassRefs : VirtualRefs; - break; - } - - allImpl(map, loc, copy(), ret, mode, kind); - return ret; -} - -SymbolMap CursorInfo::virtuals(const Location &loc, const SymbolMap &map) const -{ - SymbolMap ret; - ret[loc] = copy(); - const SymbolMap s = (kind == CXCursor_CXXMethod ? allReferences(loc, map) : targetInfos(map)); - for (auto it = s.begin(); it != s.end(); ++it) { - if (it->second->kind == kind) - ret[it->first] = it->second; - } - return ret; -} - -SymbolMap CursorInfo::declarationAndDefinition(const Location &loc, const SymbolMap &map) const -{ - SymbolMap cursors; - cursors[loc] = copy(); - - Location l; - const std::shared_ptr t = bestTarget(map, &l); - - if (t->kind == kind) - cursors[l] = t; - return cursors; -} - -String CursorInfo::displayName() const -{ - switch (kind) { - case CXCursor_FunctionTemplate: - case CXCursor_FunctionDecl: - case CXCursor_CXXMethod: - case CXCursor_Destructor: - case CXCursor_Constructor: { - const int end = symbolName.indexOf('('); - if (end != -1) - return symbolName.left(end); - break; } - case CXCursor_FieldDecl: { - int colon = symbolName.indexOf(':'); - if (colon != -1) { - const int end = colon + 2; - while (colon > 0 && RTags::isSymbol(symbolName.at(colon - 1))) - --colon; - return symbolName.left(colon + 1) + symbolName.mid(end); - } - break; } - default: - break; - } - return symbolName; -} -std::shared_ptr CursorInfo::copy() const -{ - return std::shared_ptr(std::make_shared(*this)); -} diff --git a/src/CursorInfo.h b/src/CursorInfo.h deleted file mode 100644 index 4285da2d2..000000000 --- a/src/CursorInfo.h +++ /dev/null @@ -1,231 +0,0 @@ -/* This file is part of RTags. - -RTags is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -RTags is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -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 CursorInfo_h -#define CursorInfo_h - -#include -#include "Location.h" -#include -#include -#include -#include - -class CursorInfo; -typedef Map > SymbolMap; -class CursorInfo -{ -public: - CursorInfo() - : symbolLength(0), kind(CXCursor_FirstInvalid), type(CXType_Invalid), enumValue(0), - startLine(-1), startColumn(-1), endLine(-1), endColumn(-1) - {} - - void clear() - { - symbolLength = 0; - kind = CXCursor_FirstInvalid; - type = CXType_Invalid; - enumValue = 0; - targets.clear(); - references.clear(); - symbolName.clear(); - } - - String kindSpelling() const { return kindSpelling(kind); } - static String kindSpelling(uint16_t kind); - bool dirty(const Set &dirty) - { - bool changed = false; - Set *locations[] = { &targets, &references }; - for (int i=0; i<2; ++i) { - Set &l = *locations[i]; - Set::iterator it = l.begin(); - while (it != l.end()) { - if (dirty.contains(it->fileId())) { - changed = true; - l.erase(it++); - } else { - ++it; - } - } - } - return changed; - } - - String displayName() const; - - int targetRank(const std::shared_ptr &target) const; - - bool isValid() const - { - return !isEmpty(); - } - - bool isNull() const - { - return isEmpty(); - } - - std::shared_ptr bestTarget(const SymbolMap &map, Location *loc = 0) const; - SymbolMap targetInfos(const SymbolMap &map) const; - SymbolMap referenceInfos(const SymbolMap &map) const; - SymbolMap callers(const Location &loc, const SymbolMap &map) const; - SymbolMap allReferences(const Location &loc, const SymbolMap &map) const; - SymbolMap virtuals(const Location &loc, const SymbolMap &map) const; - SymbolMap declarationAndDefinition(const Location &loc, const SymbolMap &map) const; - - std::shared_ptr copy() const; - - bool isClass() const - { - switch (kind) { - case CXCursor_ClassDecl: - case CXCursor_ClassTemplate: - case CXCursor_StructDecl: - return true; - default: - break; - } - return false; - } - - inline bool isDefinition() const - { - return kind == CXCursor_EnumConstantDecl || definition; - } - - bool isEmpty() const - { - return !symbolLength && targets.isEmpty() && references.isEmpty(); - } - - bool unite(const std::shared_ptr &other) - { - bool changed = false; - if (targets.isEmpty() && !other->targets.isEmpty()) { - targets = other->targets; - changed = true; - } else if (!other->targets.isEmpty()) { - int count = 0; - targets.unite(other->targets, &count); - if (count) - changed = true; - } - - if (startLine == -1 && other->startLine != -1) { - startLine = other->startLine; - startColumn = other->startColumn; - endLine = other->endLine; - endColumn = other->endColumn; - changed = true; - } - - if (!symbolLength && other->symbolLength) { - symbolLength = other->symbolLength; - kind = other->kind; - enumValue = other->enumValue; - type = other->type; - symbolName = other->symbolName; - changed = true; - } - const int oldSize = references.size(); - if (!oldSize) { - references = other->references; - if (!references.isEmpty()) - changed = true; - } else { - int inserted = 0; - references.unite(other->references, &inserted); - if (inserted) - changed = true; - } - - return changed; - } - - template - static inline void serialize(T &s, const SymbolMap &t); - template - static inline void deserialize(T &s, SymbolMap &t); - - enum Flag { - IgnoreTargets = 0x1, - IgnoreReferences = 0x2, - DefaultFlags = 0x0 - }; - String toString(unsigned cursorInfoFlags = DefaultFlags, unsigned keyFlags = 0) const; - uint16_t symbolLength; // this is just the symbol name length e.g. foo => 3 - String symbolName; // this is fully qualified Foobar::Barfoo::foo - uint16_t kind; - CXTypeKind type; - union { - bool definition; - int64_t enumValue; // only used if type == CXCursor_EnumConstantDecl - }; - Set targets, references; - int startLine, startColumn, endLine, endColumn; -}; - -template <> inline Serializer &operator<<(Serializer &s, const CursorInfo &t) -{ - s << t.symbolLength << t.symbolName << static_cast(t.kind) - << static_cast(t.type) << t.enumValue << t.targets << t.references - << t.startLine << t.startColumn << t.endLine << t.endColumn; - return s; -} - -template <> inline Deserializer &operator>>(Deserializer &s, CursorInfo &t) -{ - int kind, type; - s >> t.symbolLength >> t.symbolName >> kind >> type - >> t.enumValue >> t.targets >> t.references - >> t.startLine >> t.startColumn >> t.endLine >> t.endColumn; - t.kind = static_cast(kind); - t.type = static_cast(type); - return s; -} - -template -inline void CursorInfo::serialize(T &s, const SymbolMap &t) -{ - const uint32_t size = t.size(); - s << size; - for (const auto &it : t) - s << it.first << *it.second; -} - -template -inline void CursorInfo::deserialize(T &s, SymbolMap &t) -{ - uint32_t size; - s >> size; - t.clear(); - while (size--) { - Location location; - s >> location; - std::shared_ptr &ci = t[location]; - ci = std::make_shared(); - s >> *ci; - } -} - -inline Log operator<<(Log log, const CursorInfo &info) -{ - log << info.toString(); - return log; -} - -#endif diff --git a/src/CursorInfoJob.cpp b/src/CursorInfoJob.cpp index 6a36a2361..8d898a761 100644 --- a/src/CursorInfoJob.cpp +++ b/src/CursorInfoJob.cpp @@ -16,7 +16,6 @@ along with RTags. If not, see . */ #include "CursorInfoJob.h" #include "RTags.h" #include "Server.h" -#include "CursorInfo.h" #include "Project.h" #include "QueryMessage.h" @@ -27,6 +26,8 @@ CursorInfoJob::CursorInfoJob(const Location &loc, const std::shared_ptrsymbols(); if (map.isEmpty()) return 1; @@ -71,4 +72,5 @@ int CursorInfoJob::execute() } } return ret; +#endif } diff --git a/src/DependenciesJob.cpp b/src/DependenciesJob.cpp index 5d267e556..80c878b67 100644 --- a/src/DependenciesJob.cpp +++ b/src/DependenciesJob.cpp @@ -16,7 +16,6 @@ along with RTags. If not, see . */ #include "DependenciesJob.h" #include "RTags.h" #include "Server.h" -#include "CursorInfo.h" #include "FileManager.h" #include "Project.h" diff --git a/src/FindFileJob.cpp b/src/FindFileJob.cpp index 015714ffb..e55ed9b75 100644 --- a/src/FindFileJob.cpp +++ b/src/FindFileJob.cpp @@ -16,7 +16,6 @@ along with RTags. If not, see . */ #include "FindFileJob.h" #include "RTags.h" #include "Server.h" -#include "CursorInfo.h" #include "FileManager.h" #include "Project.h" diff --git a/src/FollowLocationJob.cpp b/src/FollowLocationJob.cpp index d22d5d820..d2a94b8da 100644 --- a/src/FollowLocationJob.cpp +++ b/src/FollowLocationJob.cpp @@ -16,7 +16,6 @@ along with RTags. If not, see . */ #include "FollowLocationJob.h" #include "RTags.h" #include "Server.h" -#include "CursorInfo.h" #include "Project.h" FollowLocationJob::FollowLocationJob(const Location &loc, const std::shared_ptr &query, const std::shared_ptr &project) @@ -26,6 +25,9 @@ FollowLocationJob::FollowLocationJob(const Location &loc, const std::shared_ptr< int FollowLocationJob::execute() { +#warning not done +#if 0 + const SymbolMap &map = project()->symbols(); SymbolMap::const_iterator it = RTags::findCursorInfo(map, location); @@ -89,4 +91,5 @@ int FollowLocationJob::execute() } } return ret; +#endif } diff --git a/src/IndexerMessage.h b/src/IndexerMessage.h index 1073b13cb..f2d7b8c00 100644 --- a/src/IndexerMessage.h +++ b/src/IndexerMessage.h @@ -16,7 +16,6 @@ #ifndef IndexerMessage_h #define IndexerMessage_h -#include "CursorInfo.h" #include "IndexData.h" #include "RTagsMessage.h" #include "Diagnostic.h" diff --git a/src/ListSymbolsJob.cpp b/src/ListSymbolsJob.cpp index 0bfc43fcf..234f04619 100644 --- a/src/ListSymbolsJob.cpp +++ b/src/ListSymbolsJob.cpp @@ -68,7 +68,9 @@ int ListSymbolsJob::execute() Set ListSymbolsJob::imenu(const std::shared_ptr &project) { +#warning not done Set out; +#if 0 const SymbolMap &map = project->symbols(); const List paths = pathFilters(); @@ -112,6 +114,7 @@ Set ListSymbolsJob::imenu(const std::shared_ptr &project) } } } +#endif return out; } diff --git a/src/Project.cpp b/src/Project.cpp index 7090a5729..c66b079d5 100644 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -88,22 +88,12 @@ class RestoreThread : public Thread return false; } - CursorInfo::deserialize(file, mSymbols); - file >> mSymbolNames >> mUsr >> mDependencies >> mSources >> mVisitedFiles; - for (const auto &source : mSources) { - mDependencies[source.second.fileId].insert(source.second.fileId); - // if we save before finishing a sync we may have saved mSources - // without ever having parsed them, if so they won't depend on - // anything. Make sure they depend on themselves - } + file >> mSymbolNames >> mSources >> mVisitedFiles; return true; } const Path mPath; - SymbolMap mSymbols; SymbolNameMap mSymbolNames; - UsrMap mUsr; - DependencyMap mDependencies; SourceMap mSources; Hash mVisitedFiles; std::weak_ptr mWeak; @@ -317,10 +307,7 @@ void Project::updateContents(RestoreThread *thread) bool needsSave = false; std::unique_ptr dirty; if (thread) { - mSymbols = std::move(thread->mSymbols); mSymbolNames = std::move(thread->mSymbolNames); - mUsr = std::move(thread->mUsr); - mDependencies = std::move(thread->mDependencies); mSources = std::move(thread->mSources); for (const auto& dep : mDependencies) { @@ -716,27 +703,6 @@ List Project::sources(uint32_t fileId) const return ret; } -void Project::addDependencies(const DependencyMap &deps, Set &newFiles) -{ - StopWatch timer; - - const auto end = deps.end(); - for (auto it = deps.begin(); it != end; ++it) { - Set &values = mDependencies[it->first]; - if (values.isEmpty()) { - values = it->second; - } else { - values.unite(it->second); - } - if (newFiles.isEmpty()) { - newFiles = it->second; - } else { - newFiles.unite(it->second); - } - newFiles.insert(it->first); - } -} - Set Project::dependencies(uint32_t fileId, DependencyMode mode) const { if (mode == DependsOnArg) @@ -983,14 +949,19 @@ bool Project::isSuspended(uint32_t file) const return mSuspendedFiles.contains(file); } -void Project::addFixIts(const DependencyMap &visited, const FixItMap &fixIts) // lock always held +void Project::addFixIts(const Hash &visited, + const FixItMap &fixIts, + Set &newFiles) { - for (auto it = visited.begin(); it != visited.end(); ++it) { - const auto fit = fixIts.find(it->first); - if (fit == fixIts.end()) { - mFixIts.erase(it->first); - } else { - mFixIts[it->first] = fit->second; + for (auto v : visited) { + if (v.second) { + newFiles.insert(v.first); + const auto fit = fixIts.find(v.first); + if (fit == fixIts.end()) { + mFixIts.erase(v.first); + } else { + mFixIts[v.first] = fit->second; + } } } } @@ -1183,8 +1154,6 @@ void Project::onSynced() String Project::sync() { - return String(); -#if 0 mJobCounter = mActiveJobs.size(); StopWatch sw; if (mDirtyFiles.isEmpty() && mIndexData.isEmpty()) { @@ -1192,31 +1161,19 @@ String Project::sync() } if (!mDirtyFiles.isEmpty()) { - RTags::dirtySymbols(mSymbols, mDirtyFiles); RTags::dirtySymbolNames(mSymbolNames, mDirtyFiles); - RTags::dirtyUsr(mUsr, mDirtyFiles); mDirtyFiles.clear(); } const int dirtyTime = sw.restart(); Set newFiles; - List pendingReferences; - int symbols = 0; int symbolNames = 0; for (auto it = mIndexData.begin(); it != mIndexData.end(); ++it) { const std::shared_ptr &data = it->second; - addDependencies(data->dependencies, newFiles); - addFixIts(data->dependencies, data->fixIts); - if (!data->pendingReferenceMap.isEmpty()) - pendingReferences.append(&data->pendingReferenceMap); - symbols += writeSymbols(data->symbols, mSymbols); - writeUsr(data->usrMap, mUsr, mSymbols); + addFixIts(data->visited, data->fixIts, newFiles); symbolNames += writeSymbolNames(data->symbolNames, mSymbolNames); } - for (const UsrMap *map : pendingReferences) - resolvePendingReferences(mSymbols, mUsr, *map); - for (auto it = newFiles.constBegin(); it != newFiles.constEnd(); ++it) { watch(Location::path(*it)); } @@ -1227,13 +1184,12 @@ String Project::sync() const double averageJobTime = timerElapsed / mIndexData.size(); const String msg = String::format<1024>("Jobs took %.2fs, %sdirtying took %.2fs, " "syncing took %.2fs, saving took %.2fs. We're using %lldmb of memory. " - "%d symbols, %d symbolNames", timerElapsed, + "%d symbolNames", timerElapsed, mIndexData.size() > 1 ? String::format("(avg %.2fs), ", averageJobTime).constData() : "", dirtyTime / 1000.0, syncTime / 1000.0, saveTime / 1000.0, MemoryMonitor::usage() / (1024 * 1024), - symbols, symbolNames); + symbolNames); mIndexData.clear(); mTimer.start(); -#endif } String Project::toCompilationDatabase() const diff --git a/src/Project.h b/src/Project.h index b3a6a9475..0b32cb44e 100644 --- a/src/Project.h +++ b/src/Project.h @@ -16,7 +16,6 @@ along with RTags. If not, see . */ #ifndef Project_h #define Project_h -#include "CursorInfo.h" #include "IndexerJob.h" #include "Match.h" #include "QueryMessage.h" @@ -64,9 +63,6 @@ class Project : public std::enable_shared_from_this bool match(const Match &match, bool *indexed = 0) const; - const SymbolMap &symbols() const { return mSymbols; } - SymbolMap &symbols() { return mSymbols; } - const SymbolNameMap &symbolNames() const { return mSymbolNames; } SymbolNameMap &symbolNames() { return mSymbolNames; } @@ -82,9 +78,6 @@ class Project : public std::enable_shared_from_this const FilesMap &files() const { return mFiles; } FilesMap &files() { return mFiles; } - const UsrMap &usrs() const { return mUsr; } - UsrMap &usrs() { return mUsr; } - const Set &suspendedFiles() const; bool toggleSuspendFile(uint32_t file); bool isSuspended(uint32_t file) const; @@ -107,7 +100,7 @@ class Project : public std::enable_shared_from_this int remove(const Match &match); void onJobFinished(const std::shared_ptr &job, const std::shared_ptr &indexData); SourceMap sources() const { return mSources; } - DependencyMap dependencies() const { return mDependencies; } + DependencyMap dependencies(uint32_t fileId) const; String toCompilationDatabase() const; Set watchedPaths() const { return mWatchedPaths; } bool isIndexing() const { return !mActiveJobs.isEmpty(); } @@ -132,8 +125,9 @@ class Project : public std::enable_shared_from_this void updateContents(RestoreThread *thread); void watch(const Path &file); void reloadFileManager(); - void addDependencies(const DependencyMap &hash, Set &newFiles); - void addFixIts(const DependencyMap &dependencies, const FixItMap &fixIts); + void addFixIts(const Hash &visited, + const FixItMap &fixIts, + Set &newFiles); int startDirtyJobs(Dirty *dirty, const UnsavedFiles &unsavedFiles = UnsavedFiles()); bool save(); void onSynced(); @@ -142,9 +136,7 @@ class Project : public std::enable_shared_from_this const Path mPath; State mState; - SymbolMap mSymbols; SymbolNameMap mSymbolNames; - UsrMap mUsr; FilesMap mFiles; Hash mVisitedFiles; diff --git a/src/QueryJob.cpp b/src/QueryJob.cpp index a180c8339..8db33a432 100644 --- a/src/QueryJob.cpp +++ b/src/QueryJob.cpp @@ -17,7 +17,6 @@ along with RTags. If not, see . */ #include "RTags.h" #include #include "Server.h" -#include "CursorInfo.h" #include #include "QueryMessage.h" #include "Project.h" @@ -140,6 +139,8 @@ bool QueryJob::write(const Location &location, unsigned /* flags */) const bool cursorKind = queryFlags() & QueryMessage::CursorKind; const bool displayName = queryFlags() & QueryMessage::DisplayName; if (containingFunction || cursorKind || displayName) { +#warning not done +#if 0 const SymbolMap &symbols = project()->symbols(); SymbolMap::const_iterator it = symbols.find(location); if (it == symbols.end()) { @@ -169,20 +170,11 @@ bool QueryJob::write(const Location &location, unsigned /* flags */) } } } +#endif } return write(out); } -bool QueryJob::write(const std::shared_ptr &ci, unsigned ciflags) -{ - if (!ci || ci->isNull()) - return false; - const unsigned kf = keyFlags(); - if (!write(ci->toString(ciflags, kf).constData())) - return false; - return true; -} - bool QueryJob::filter(const String &value) const { if (!mPathFilters && !mPathFiltersRegExp && !(queryFlags() & QueryMessage::FilterSystemIncludes)) diff --git a/src/QueryJob.h b/src/QueryJob.h index ac7c1091d..52f3b8143 100644 --- a/src/QueryJob.h +++ b/src/QueryJob.h @@ -26,7 +26,6 @@ along with RTags. If not, see . */ #include "QueryMessage.h" #include -class CursorInfo; class Location; class QueryMessage; class Project; @@ -55,7 +54,6 @@ class QueryJob Unfiltered = 0x4 }; bool write(const String &out, unsigned flags = NoWriteFlags); - bool write(const std::shared_ptr &info, unsigned flags = NoWriteFlags); bool write(const Location &location, unsigned flags = NoWriteFlags); template bool write(unsigned flags, const char *format, ...); diff --git a/src/RTags.cpp b/src/RTags.cpp index 7c44c6f50..8afd0cc66 100644 --- a/src/RTags.cpp +++ b/src/RTags.cpp @@ -14,7 +14,6 @@ You should have received a copy of the GNU General Public License along with RTags. If not, see . */ #include "RTags.h" -#include "CursorInfo.h" #include "Server.h" #include "VisitFileMessage.h" #include "VisitFileResponseMessage.h" @@ -68,39 +67,6 @@ void dirtySymbolNames(SymbolNameMap &map, const Set &dirty) } } -void dirtySymbols(SymbolMap &map, const Set &dirty) -{ - SymbolMap::iterator it = map.begin(); - while (it != map.end()) { - if (dirty.contains(it->first.fileId())) { - map.erase(it++); - } else { - it->second->dirty(dirty); - ++it; - } - } -} -void dirtyUsr(UsrMap &map, const Set &dirty) -{ - UsrMap::iterator it = map.begin(); - while (it != map.end()) { - Set &locations = it->second; - Set::iterator i = locations.begin(); - while (i != locations.end()) { - if (dirty.contains(i->fileId())) { - locations.erase(i++); - } else { - ++i; - } - } - if (locations.isEmpty()) { - map.erase(it++); - } else { - ++it; - } - } -} - Path findAncestor(Path path, const char *fn, unsigned flags) { Path ret; diff --git a/src/RTags.h b/src/RTags.h index c686f2fa0..f9bacf073 100644 --- a/src/RTags.h +++ b/src/RTags.h @@ -46,10 +46,10 @@ enum UnitType { CompileCPlusPlus }; enum CursorType { - Include, - Cursor, - Reference, - Other + Type_Include, + Type_Cursor, + Type_Reference, + Type_Other }; void initMessages(); } @@ -71,8 +71,6 @@ typedef Hash UnsavedFiles; namespace RTags { Path encodeSourceFilePath(const Path &dataDir, const Path &project, uint64_t build); void dirtySymbolNames(SymbolNameMap &map, const Set &dirty); -void dirtySymbols(SymbolMap &map, const Set &dirty); -void dirtyUsr(UsrMap &map, const Set &dirty); template inline bool addTo(Container &container, const Value &value) diff --git a/src/RTagsClang.cpp b/src/RTagsClang.cpp index c9eaa5421..1a9a07e71 100644 --- a/src/RTagsClang.cpp +++ b/src/RTagsClang.cpp @@ -46,16 +46,16 @@ String cursorToString(CXCursor cursor, unsigned flags) return ret; switch (RTags::cursorType(kind)) { - case Reference: + case Type_Reference: ret += " r"; break; - case Cursor: + case Type_Cursor: ret += " c"; break; - case Other: + case Type_Other: ret += " o"; break; - case Include: + case Type_Include: ret += " i"; break; } @@ -96,20 +96,20 @@ String cursorToString(CXCursor cursor, unsigned flags) return ret; } -SymbolMap::const_iterator findCursorInfo(const SymbolMap &map, const Location &location) +Cursor findCursor(const Table &tbl, const Location &location) { - SymbolMap::const_iterator it = map.lower_bound(location); - if (it != map.end() && it->first == location) { - return it; - } else if (it != map.begin()) { - --it; - if (it->first.fileId() == location.fileId() && location.line() == it->first.line()) { - const int off = location.column() - it->first.column(); - if (it->second->symbolLength > off) - return it; + bool exact = false; + const int idx = tbl.find(location, &exact); + Cursor ret; + if (idx != -1) { + ret = tbl.valueAt(idx); + if (!exact && (ret.location.fileId() != location.fileId() + || ret.location.line() != location.line() + || (location.column() - ret.location.column() <= ret.symbolLength))) { + ret = Cursor(); } } - return map.end(); + return ret; } void parseTranslationUnit(const Path &sourceFile, const List &args, diff --git a/src/RTagsClang.h b/src/RTagsClang.h index bcffaf8a0..a5f89aacc 100644 --- a/src/RTagsClang.h +++ b/src/RTagsClang.h @@ -16,9 +16,10 @@ along with RTags. If not, see . */ #ifndef __RTAGSCLANG_H__ #define __RTAGSCLANG_H__ +#include "Table.h" #include "Source.h" #include "RTags.h" -#include "CursorInfo.h" +#include "Cursor.h" #define __STDC_CONSTANT_MACROS #define __STDC_LIMIT_MACROS #include @@ -56,7 +57,7 @@ enum CursorToStringFlags { AllCursorToStringFlags = IncludeUSR|IncludeRange }; String cursorToString(CXCursor cursor, unsigned = DefaultCursorToStringFlags); -SymbolMap::const_iterator findCursorInfo(const SymbolMap &map, const Location &location); +Cursor findCursor(const Table &map, const Location &location); void parseTranslationUnit(const Path &sourceFile, const List &args, CXTranslationUnit &unit, CXIndex index, @@ -203,16 +204,16 @@ static inline CursorType cursorType(uint16_t kind) { switch (kind) { case CXCursor_InclusionDirective: - return Include; + return Type_Include; } if (clang_isStatement(static_cast(kind))) { - return Other; + return Type_Other; } else if (RTags::isCursor(kind)) { - return Cursor; + return Type_Cursor; } else if (RTags::isReference(kind)) { - return Reference; + return Type_Reference; } - return Other; + return Type_Other; } static inline bool isContainer(uint16_t kind) diff --git a/src/ReferencesJob.cpp b/src/ReferencesJob.cpp index 33275d6b8..56009eb34 100644 --- a/src/ReferencesJob.cpp +++ b/src/ReferencesJob.cpp @@ -16,7 +16,6 @@ along with RTags. If not, see . */ #include "ReferencesJob.h" #include "Server.h" #include "RTags.h" -#include "CursorInfo.h" #include "Project.h" ReferencesJob::ReferencesJob(const Location &loc, const std::shared_ptr &query, const std::shared_ptr &proj) @@ -32,6 +31,8 @@ ReferencesJob::ReferencesJob(const String &sym, const std::shared_ptr proj = project(); Location startLocation; Map > references; @@ -164,4 +165,5 @@ int ReferencesJob::execute() return 0; } return 1; +#endif } diff --git a/src/StatusJob.cpp b/src/StatusJob.cpp index 8417c2ed9..1dfbc8d8d 100644 --- a/src/StatusJob.cpp +++ b/src/StatusJob.cpp @@ -14,7 +14,6 @@ You should have received a copy of the GNU General Public License along with RTags. If not, see . */ #include "StatusJob.h" -#include "CursorInfo.h" #include "RTags.h" #include "Server.h" #include @@ -76,6 +75,8 @@ int StatusJob::execute() return 1; } +#warning not done +#if 0 if (query.isEmpty() || !strcasecmp(query.constData(), "dependencies")) { matched = true; const DependencyMap map = proj->dependencies(); @@ -123,6 +124,7 @@ int StatusJob::execute() return 1; } } +#endif if (query.isEmpty() || !strcasecmp(query.constData(), "symbolnames")) { matched = true; diff --git a/src/Table.h b/src/Table.h index dd38ceada..50a562aaa 100644 --- a/src/Table.h +++ b/src/Table.h @@ -21,6 +21,7 @@ #include #include #include +#include "Location.h" #include template inline static int compare(const T &l, const T &r) @@ -87,7 +88,7 @@ class Table Value value(const Key &key) const { bool match; - const int idx = lowerBound(key, &match); + const int idx = find(key, &match); // error() << "value" << idx << key << match; if (match) return valueAt(idx); @@ -112,7 +113,7 @@ class Table const size_t offset = read(data); return read(mPointer + offset); } - size_t lowerBound(const Key &k, bool *match = 0) const + size_t find(const Key &k, bool *match = 0) const { int lower = 0; int upper = mCount - 1;