Skip to content

Commit

Permalink
Kill unused errorsymbols rubbish.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andersbakken committed Oct 30, 2013
1 parent 62da707 commit 3b95ae1
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 147 deletions.
42 changes: 21 additions & 21 deletions src/CursorInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ int CursorInfo::targetRank(const CursorInfo &target) const
}
}

CursorInfo CursorInfo::bestTarget(const SymbolMap &map, const SymbolMap *errors, Location *loc) const
CursorInfo CursorInfo::bestTarget(const SymbolMap &map, Location *loc) const
{
const SymbolMap targets = targetInfos(map, errors);
const SymbolMap targets = targetInfos(map);

SymbolMap::const_iterator best = targets.end();
int bestRank = -1;
Expand All @@ -131,11 +131,11 @@ CursorInfo CursorInfo::bestTarget(const SymbolMap &map, const SymbolMap *errors,
return CursorInfo();
}

SymbolMap CursorInfo::targetInfos(const SymbolMap &map, const SymbolMap *errors) const
SymbolMap CursorInfo::targetInfos(const SymbolMap &map) const
{
SymbolMap ret;
for (Set<Location>::const_iterator it = targets.begin(); it != targets.end(); ++it) {
SymbolMap::const_iterator found = RTags::findCursorInfo(map, *it, String(), errors);
SymbolMap::const_iterator found = RTags::findCursorInfo(map, *it, String());
// ### could/should I pass symbolName as context here?
if (found != map.end()) {
ret[*it] = found->second;
Expand All @@ -148,25 +148,25 @@ SymbolMap CursorInfo::targetInfos(const SymbolMap &map, const SymbolMap *errors)
return ret;
}

SymbolMap CursorInfo::referenceInfos(const SymbolMap &map, const SymbolMap *errors) const
SymbolMap CursorInfo::referenceInfos(const SymbolMap &map) const
{
SymbolMap ret;
for (Set<Location>::const_iterator it = references.begin(); it != references.end(); ++it) {
SymbolMap::const_iterator found = RTags::findCursorInfo(map, *it, String(), errors);
SymbolMap::const_iterator found = RTags::findCursorInfo(map, *it, String());
if (found != map.end()) {
ret[*it] = found->second;
}
}
return ret;
}

SymbolMap CursorInfo::callers(const Location &loc, const SymbolMap &map, const SymbolMap *errors) const
SymbolMap CursorInfo::callers(const Location &loc, const SymbolMap &map) const
{
SymbolMap ret;
const SymbolMap cursors = virtuals(loc, map, errors);
const SymbolMap cursors = virtuals(loc, map);
for (SymbolMap::const_iterator c = cursors.begin(); c != cursors.end(); ++c) {
for (Set<Location>::const_iterator it = c->second.references.begin(); it != c->second.references.end(); ++it) {
const SymbolMap::const_iterator found = RTags::findCursorInfo(map, *it, String(), errors);
const SymbolMap::const_iterator found = RTags::findCursorInfo(map, *it, String());
if (found == map.end())
continue;
if (RTags::isReference(found->second.kind)) { // is this always right?
Expand All @@ -185,12 +185,12 @@ enum Mode {
NormalRefs
};

static inline void allImpl(const SymbolMap &map, const SymbolMap *errors, const Location &loc, const CursorInfo &info, SymbolMap &out, Mode mode, unsigned kind)
static inline void allImpl(const SymbolMap &map, const Location &loc, const CursorInfo &info, SymbolMap &out, Mode mode, unsigned kind)
{
if (out.contains(loc))
return;
out[loc] = info;
const SymbolMap targets = info.targetInfos(map, errors);
const SymbolMap targets = info.targetInfos(map);
for (SymbolMap::const_iterator t = targets.begin(); t != targets.end(); ++t) {
bool ok = false;
switch (mode) {
Expand All @@ -203,17 +203,17 @@ static inline void allImpl(const SymbolMap &map, const SymbolMap *errors, const
break;
}
if (ok)
allImpl(map, errors, t->first, t->second, out, mode, kind);
allImpl(map, t->first, t->second, out, mode, kind);
}
const SymbolMap refs = info.referenceInfos(map, errors);
const SymbolMap refs = info.referenceInfos(map);
for (SymbolMap::const_iterator 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, errors, r->first, r->second, out, mode, kind);
allImpl(map, r->first, r->second, out, mode, kind);
} else {
out[r->first] = r->second;
}
Expand All @@ -224,13 +224,13 @@ static inline void allImpl(const SymbolMap &map, const SymbolMap *errors, const
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, errors, r->first, r->second, out, mode, kind);
allImpl(map, r->first, r->second, out, mode, kind);
}
}
}
}

SymbolMap CursorInfo::allReferences(const Location &loc, const SymbolMap &map, const SymbolMap *errors) const
SymbolMap CursorInfo::allReferences(const Location &loc, const SymbolMap &map) const
{
SymbolMap ret;
Mode mode = NormalRefs;
Expand All @@ -247,29 +247,29 @@ SymbolMap CursorInfo::allReferences(const Location &loc, const SymbolMap &map, c
break;
}

allImpl(map, errors, loc, *this, ret, mode, kind);
allImpl(map, loc, *this, ret, mode, kind);
return ret;
}

SymbolMap CursorInfo::virtuals(const Location &loc, const SymbolMap &map, const SymbolMap *errors) const
SymbolMap CursorInfo::virtuals(const Location &loc, const SymbolMap &map) const
{
SymbolMap ret;
ret[loc] = *this;
const SymbolMap s = (kind == CXCursor_CXXMethod ? allReferences(loc, map, errors) : targetInfos(map, errors));
const SymbolMap s = (kind == CXCursor_CXXMethod ? allReferences(loc, map) : targetInfos(map));
for (SymbolMap::const_iterator 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 *errors) const
SymbolMap CursorInfo::declarationAndDefinition(const Location &loc, const SymbolMap &map) const
{
SymbolMap cursors;
cursors[loc] = *this;

Location l;
const CursorInfo t = bestTarget(map, errors, &l);
const CursorInfo t = bestTarget(map, &l);

if (t.kind == kind)
cursors[l] = t;
Expand Down
14 changes: 7 additions & 7 deletions src/CursorInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ class CursorInfo

bool isValid(const Location &location) const;

CursorInfo bestTarget(const SymbolMap &map, const SymbolMap *errors = 0, Location *loc = 0) const;
SymbolMap targetInfos(const SymbolMap &map, const SymbolMap *errors = 0) const;
SymbolMap referenceInfos(const SymbolMap &map, const SymbolMap *errors = 0) const;
SymbolMap callers(const Location &loc, const SymbolMap &map, const SymbolMap *errors = 0) const;
SymbolMap allReferences(const Location &loc, const SymbolMap &map, const SymbolMap *errors = 0) const;
SymbolMap virtuals(const Location &loc, const SymbolMap &map, const SymbolMap *errors = 0) const;
SymbolMap declarationAndDefinition(const Location &loc, const SymbolMap &map, const SymbolMap *errors = 0) const;
CursorInfo 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;

bool isClass() const
{
Expand Down
20 changes: 4 additions & 16 deletions src/FollowLocationJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,7 @@ FollowLocationJob::FollowLocationJob(const Location &loc, const QueryMessage &qu
void FollowLocationJob::execute()
{
const SymbolMap &map = project()->symbols();
const ErrorSymbolMap &errorSymbols = project()->errorSymbols();

const ErrorSymbolMap::const_iterator e = errorSymbols.find(location.fileId());
const SymbolMap *errors = e == errorSymbols.end() ? 0 : &e->second;

bool foundInError = false;
SymbolMap::const_iterator it = RTags::findCursorInfo(map, location, context(), errors, &foundInError);
SymbolMap::const_iterator it = RTags::findCursorInfo(map, location, context());

if (it == map.end())
return;
Expand All @@ -44,10 +38,7 @@ void FollowLocationJob::execute()
}

Location loc;
CursorInfo target = cursorInfo.bestTarget(map, errors, &loc);
if (target.isNull() && foundInError) {
target = cursorInfo.bestTarget(e->second, errors, &loc);
}
CursorInfo target = cursorInfo.bestTarget(map, &loc);
if (!loc.isNull()) {
// ### not respecting DeclarationOnly
if (cursorInfo.kind != target.kind) {
Expand All @@ -61,10 +52,7 @@ void FollowLocationJob::execute()
case CXCursor_Destructor:
case CXCursor_Constructor:
case CXCursor_FunctionTemplate:
target = target.bestTarget(map, errors, &loc);
if (target.isNull() && foundInError)
target = cursorInfo.bestTarget(e->second, errors, &loc);

target = target.bestTarget(map, &loc);
break;
default:
break;
Expand All @@ -74,7 +62,7 @@ void FollowLocationJob::execute()
if (!loc.isNull()) {
if (queryFlags() & QueryMessage::DeclarationOnly && target.isDefinition()) {
Location declLoc;
const CursorInfo decl = target.bestTarget(map, errors, &declLoc);
const CursorInfo decl = target.bestTarget(map, &declLoc);
if (!declLoc.isNull()) {
write(declLoc);
}
Expand Down
25 changes: 0 additions & 25 deletions src/Project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ class RestoreThread : public Thread

std::weak_ptr<Project> mProject;
SymbolMap mSymbols;
ErrorSymbolMap mErrorSymbols;
SymbolNameMap mSymbolNames;
UsrMap mUsr;
FilesMap mFiles;
Expand Down Expand Up @@ -139,7 +138,6 @@ void Project::restore(RestoreThread *thread)
assert(state() == Loading);

mSymbols = std::move(thread->mSymbols);
mErrorSymbols = std::move(thread->mErrorSymbols);
mSymbolNames = std::move(thread->mSymbolNames);
mUsr = std::move(thread->mUsr);;
mFiles = std::move(thread->mFiles);
Expand Down Expand Up @@ -238,7 +236,6 @@ void Project::unload()
fileManager.reset();

mSymbols.clear();
mErrorSymbols.clear();
mSymbolNames.clear();
mUsr.clear();
mFiles.clear();
Expand Down Expand Up @@ -642,25 +639,6 @@ static inline void writeUsr(const UsrMap &usr, UsrMap &current, SymbolMap &symbo
}
}

static inline void writeErrorSymbols(const SymbolMap &symbols, ErrorSymbolMap &errorSymbols, const Hash<uint32_t, int> &errors)
{
for (Hash<uint32_t, int>::const_iterator it = errors.begin(); it != errors.end(); ++it) {
if (it->second) {
SymbolMap &symbolsForFile = errorSymbols[it->first];
if (symbolsForFile.isEmpty()) {
const Location loc(it->first, 1, 0);
SymbolMap::const_iterator sit = symbols.lower_bound(loc);
while (sit != symbols.end() && sit->first.fileId() == it->first) {
symbolsForFile[sit->first] = sit->second;
++sit;
}
}
} else {
errorSymbols.remove(it->first);
}
}
}

static inline void writeSymbols(SymbolMap &symbols, SymbolMap &current)
{
if (!symbols.isEmpty()) {
Expand Down Expand Up @@ -702,9 +680,6 @@ void Project::syncDB(int *dirty, int *sync)
*sync = 0;
return;
}
// for (Hash<uint32_t, std::shared_ptr<IndexData> >::iterator it = mPendingData.begin(); it != mPendingData.end(); ++it) {
// writeErrorSymbols(mSymbols, mErrorSymbols, it->second->errors);
// }

if (!mPendingDirtyFiles.isEmpty()) {
RTags::dirtySymbols(mSymbols, mPendingDirtyFiles);
Expand Down
4 changes: 0 additions & 4 deletions src/Project.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ class Project : public std::enable_shared_from_this<Project>
const SymbolMap &symbols() const { return mSymbols; }
SymbolMap &symbols() { return mSymbols; }

const ErrorSymbolMap &errorSymbols() const { return mErrorSymbols; }
ErrorSymbolMap &errorSymbols() { return mErrorSymbols; }

const SymbolNameMap &symbolNames() const { return mSymbolNames; }
SymbolNameMap &symbolNames() { return mSymbolNames; }

Expand Down Expand Up @@ -129,7 +126,6 @@ class Project : public std::enable_shared_from_this<Project>
State mState;

SymbolMap mSymbols;
ErrorSymbolMap mErrorSymbols;
SymbolNameMap mSymbolNames;
UsrMap mUsr;
FilesMap mFiles;
Expand Down
36 changes: 3 additions & 33 deletions src/RTagsClang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,40 +180,10 @@ static inline SymbolMap::const_iterator findCursorInfo(const SymbolMap &map, con
return map.end();
}

SymbolMap::const_iterator findCursorInfo(const SymbolMap &map, const Location &location, const String &context,
const SymbolMap *errors, bool *foundInErrors)
SymbolMap::const_iterator findCursorInfo(const SymbolMap &map, const Location &location, const String &context)
{
if (foundInErrors)
*foundInErrors = false;
if (map.isEmpty() && !errors)
return map.end();
if (errors) {
SymbolMap::const_iterator ret = findCursorInfo(map, location, context, false);
if (ret != map.end()) {
return ret;
}
ret = findCursorInfo(*errors, location, context, false);
if (ret != errors->end()) {
if (foundInErrors)
*foundInErrors = true;
return ret;
}
// ret = findCursorInfo(*errors, location, context, true);
// if (ret != errors->end()) {
// if (foundInErrors)
// *foundInErrors = true;
// return ret;
// }
// ret = findCursorInfo(map, location, context, true);
// if (ret != map.end()) {
// return ret;
// }

return map.end();
} else {
const SymbolMap::const_iterator ret = findCursorInfo(map, location, context, true);
return ret;
}
const SymbolMap::const_iterator ret = findCursorInfo(map, location, context, true);
return ret;
}

void parseTranslationUnit(const Path &sourceFile, const List<String> &args,
Expand Down
3 changes: 1 addition & 2 deletions src/RTagsClang.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ enum CursorToStringFlags {
};
String cursorToString(CXCursor cursor, unsigned = DefaultCursorToStringFlags);
SymbolMap::const_iterator findCursorInfo(const SymbolMap &map, const Location &location,
const String &context = String(),
const SymbolMap *errors = 0, bool *foundInErrors = 0);
const String &context = String());

void parseTranslationUnit(const Path &sourceFile, const List<String> &args,
const List<String> &defaultArguments,
Expand Down
Loading

0 comments on commit 3b95ae1

Please sign in to comment.