Skip to content

Commit

Permalink
More error symbols code
Browse files Browse the repository at this point in the history
  • Loading branch information
Andersbakken committed Apr 7, 2013
1 parent e245a13 commit 202acbb
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 46 deletions.
48 changes: 23 additions & 25 deletions src/CursorInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ int CursorInfo::targetRank(const CursorInfo &target) const
}
}

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

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

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

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

SymbolMap CursorInfo::callers(const Location &loc, const SymbolMap &map) const
SymbolMap CursorInfo::callers(const Location &loc, const SymbolMap &map, const SymbolMap *errors) const
{
SymbolMap ret;
const SymbolMap cursors = virtuals(loc, map);
const SymbolMap cursors = virtuals(loc, map, errors);
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);
const SymbolMap::const_iterator found = RTags::findCursorInfo(map, *it, String(), errors);
if (found == map.end())
continue;
if (RTags::isReference(found->second.kind)) { // is this always right?
Expand All @@ -154,13 +155,12 @@ enum Mode {
NormalRefs
};

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

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

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

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

Location l;
CursorInfo t = bestTarget(map, &l);
CursorInfo t = bestTarget(map, errors, &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 @@ -74,13 +74,13 @@ class CursorInfo

bool isValid(const Location &location) 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;
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;

bool isClass() const
{
Expand Down
14 changes: 7 additions & 7 deletions src/FollowLocationJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ void FollowLocationJob::execute()
const SymbolMap &map = scope.data();

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

bool foundInError = false;
SymbolMap::const_iterator it = RTags::findCursorInfo(map, location, context(),
e == errorScope.data().end() ? 0 : &e->second, &foundInError);
SymbolMap::const_iterator it = RTags::findCursorInfo(map, location, context(), errors, &foundInError);

if (it == map.end())
return;
Expand All @@ -35,9 +35,9 @@ void FollowLocationJob::execute()
}

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

break;
default:
Expand All @@ -65,7 +65,7 @@ void FollowLocationJob::execute()
if (!loc.isNull()) {
if (queryFlags() & QueryMessage::DeclarationOnly && target.isDefinition()) {
Location declLoc;
const CursorInfo decl = target.bestTarget(map, &declLoc);
const CursorInfo decl = target.bestTarget(map, errors, &declLoc);
if (!declLoc.isNull()) {
write(declLoc);
}
Expand Down
2 changes: 1 addition & 1 deletion src/JSONJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void JSONJob::execute()
SymbolMap::const_iterator sit = map.lower_bound(loc);
while (sit != map.end() && sit->first.fileId() == it->first) {
Location targetLocation;
CursorInfo target = sit->second.bestTarget(map, &targetLocation);
CursorInfo target = sit->second.bestTarget(map, 0, &targetLocation);
const String type = sit->second.kindSpelling();
if (firstSymbol) {
firstSymbol = false;
Expand Down
27 changes: 21 additions & 6 deletions src/ReferencesJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,36 @@ void ReferencesJob::execute()
if (scope.isNull())
return;

Scope<const ErrorSymbolMap&> errorScope = proj->lockErrorSymbolsForRead();
if (errorScope.isNull())
return;

const SymbolMap &map = scope.data();
const ErrorSymbolMap &errorMap = errorScope.data();
const ErrorSymbolMap::const_iterator e = symbolName.isEmpty() ? errorMap.find(locations.begin()->fileId()) : errorMap.end();
const SymbolMap *errors = e == errorMap.end() ? 0 : &e->second;

// ### return if e != errorMap && queryFlags() & QueryMessage::AllReferences?

for (Set<Location>::const_iterator it = locations.begin(); it != locations.end(); ++it) {
Location pos;
const SymbolMap::const_iterator found = RTags::findCursorInfo(map, *it, symbolName.isEmpty() ? context() : String());
SymbolMap::const_iterator found;
bool foundInError = false;
found = RTags::findCursorInfo(map, *it, context(), errors, &foundInError);
if (found == map.end())
continue;
pos = found->first;
if (startLocation.isNull())
startLocation = pos;
CursorInfo cursorInfo = found->second;
if (RTags::isReference(cursorInfo.kind)) {
cursorInfo = cursorInfo.bestTarget(map, &pos);
cursorInfo = cursorInfo.bestTarget(map, errors, &pos);
if (cursorInfo.isNull() && foundInError)
cursorInfo = cursorInfo.bestTarget(e->second, errors, &pos);
}
if (queryFlags() & QueryMessage::AllReferences) {
const SymbolMap all = cursorInfo.allReferences(pos, map);
const SymbolMap all = cursorInfo.allReferences(pos, map, errors);

bool classRename = false;
switch (cursorInfo.kind) {
case CXCursor_Constructor:
Expand All @@ -68,7 +83,7 @@ void ReferencesJob::execute()
FoundReferences = 0x4
};
unsigned state = 0;
const SymbolMap targets = a->second.targetInfos(map);
const SymbolMap targets = a->second.targetInfos(map, errors);
for (SymbolMap::const_iterator t = targets.begin(); t != targets.end(); ++t) {
if (t->second.kind != a->second.kind)
state |= FoundReferences;
Expand All @@ -85,14 +100,14 @@ void ReferencesJob::execute()
}
} else if (queryFlags() & QueryMessage::FindVirtuals) {
// ### not supporting DeclarationOnly
const SymbolMap virtuals = cursorInfo.virtuals(pos, map);
const SymbolMap virtuals = cursorInfo.virtuals(pos, map, errors);
List<RTags::SortedCursor> sortedCursors;
sortedCursors.reserve(virtuals.size());
for (SymbolMap::const_iterator v = virtuals.begin(); v != virtuals.end(); ++v) {
references[v->first] = std::make_pair(v->second.isDefinition(), v->second.kind);
}
} else {
const SymbolMap callers = cursorInfo.callers(pos, map);
const SymbolMap callers = cursorInfo.callers(pos, map, errors);
for (SymbolMap::const_iterator c = callers.begin(); c != callers.end(); ++c) {
references[c->first] = std::make_pair(false, CXCursor_FirstInvalid);
// For find callers we don't want to prefer definitions or do ranks on cursors
Expand Down

0 comments on commit 202acbb

Please sign in to comment.