Skip to content

Commit

Permalink
Work on template refs
Browse files Browse the repository at this point in the history
  • Loading branch information
Andersbakken committed Dec 27, 2016
1 parent 86aad8a commit fdfc5fa
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 53 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.8.6)
project(rtags)
set(RTAGS_VERSION_MAJOR 2)
set(RTAGS_VERSION_MINOR 5)
set(RTAGS_VERSION_DATABASE 110)
set(RTAGS_VERSION_DATABASE 111)
set(RTAGS_VERSION_SOURCES_FILE 7)
set(RTAGS_VERSION ${RTAGS_VERSION_MAJOR}.${RTAGS_VERSION_MINOR}.${RTAGS_VERSION_DATABASE})

Expand Down
198 changes: 156 additions & 42 deletions src/ClangIndexer.cpp

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions src/ClangIndexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ClangIndexer
void addFileSymbol(uint32_t file);
int symbolLength(CXCursorKind kind, const CXCursor &cursor);
void extractArguments(List<Symbol::Argument> *arguments, const CXCursor &cursor);
CXCursor resolveTemplate(CXCursor cursor, Location location = Location());
CXCursor resolveTemplate(CXCursor cursor, Location location = Location(), bool *specialized = 0);
static CXCursor resolveTypedef(CXCursor cursor);

inline Location createLocation(const CXSourceLocation &location, bool *blocked = 0, unsigned *offset = 0)
Expand Down Expand Up @@ -140,11 +140,12 @@ class ClangIndexer
Map<uint32_t, Token> tokens;
};

std::shared_ptr<Unit> unit(uint32_t fileId)
std::shared_ptr<Unit> &unit(uint32_t fileId)
{
std::shared_ptr<Unit> &unit = mUnits[fileId];
if (!unit)
if (!unit) {
unit.reset(new Unit);
}
return unit;
}
std::shared_ptr<Unit> unit(Location loc) { return unit(loc.fileId()); }
Expand Down Expand Up @@ -210,6 +211,8 @@ class ClangIndexer
List<Loop> mLoopStack;

List<CXCursor> mParents;
std::unordered_set<CXCursor> mTemplateSpecializations;
size_t mInTemplateFunction;

static Flags<Server::Option> sServerOpts;
static Path sServerSandboxRoot;
Expand Down
2 changes: 1 addition & 1 deletion src/ClangThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ CXChildVisitResult ClangThread::visit(const CXCursor &cursor)
printCursor(cursor);

writeToConnetion(message);
if (refSpecialized) {
if (refSpecialized && false) {
visit(ref);
}
}
Expand Down
38 changes: 36 additions & 2 deletions src/Project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,12 @@ bool Project::hasSource(uint32_t fileId) const
Set<uint32_t> Project::dependencies(uint32_t fileId, DependencyMode mode) const
{
Set<uint32_t> ret;
if (mode == All) {
for (const auto &node : mDependencies) {
ret.insert(node.first);
}
return ret;
}
ret.insert(fileId);
std::function<void(uint32_t)> fill = [&](uint32_t file) {
if (DependencyNode *node = mDependencies.value(file)) {
Expand Down Expand Up @@ -1483,8 +1489,14 @@ Set<Symbol> Project::findTargets(const Symbol &symbol)
break; }
// fall through
default:
for (const String &usr : findTargetUsrs(symbol.location)) {
ret.unite(findByUsr(usr, symbol.location.fileId(), Project::ArgDependsOn));
if (symbol.flags & Symbol::TemplateReference) {
for (const String &usr : findTargetUsrs(symbol)) {
ret.unite(findByUsr(usr, symbol.location.fileId(), Project::DependsOnArg));
}
} else {
for (const String &usr : findTargetUsrs(symbol.location)) {
ret.unite(findByUsr(usr, symbol.location.fileId(), Project::ArgDependsOn));
}
}
break;
}
Expand Down Expand Up @@ -1732,6 +1744,28 @@ Set<String> Project::findTargetUsrs(Location loc)
return usrs;
}

Set<String> Project::findTargetUsrs(const Symbol &symbol)
{
if (!(symbol.flags & Symbol::TemplateReference)) {
return findTargetUsrs(symbol.location);
}

Set<String> usrs;
for (uint32_t fileId : dependencies(symbol.location.fileId(), DependsOnArg)) {
auto targets = openTargets(fileId);
if (targets) {
const int count = targets->count();
for (int i=0; i<count; ++i) {
if (targets->valueAt(i).contains(symbol.location)) {
// SBROOT
usrs.insert(Sandbox::decoded(targets->keyAt(i)));
}
}
}
}
return usrs;
}

Set<Symbol> Project::findSubclasses(const Symbol &symbol)
{
assert(symbol.isClass() && symbol.isDefinition());
Expand Down
6 changes: 4 additions & 2 deletions src/Project.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ class Project : public std::enable_shared_from_this<Project>

enum DependencyMode {
DependsOnArg,
ArgDependsOn
ArgDependsOn,
All
};

Set<uint32_t> dependencies(uint32_t fileId, DependencyMode mode) const;
Expand Down Expand Up @@ -156,10 +157,11 @@ class Project : public std::enable_shared_from_this<Project>
Set<Symbol> findCallers(const Symbol &symbol);
Set<Symbol> findVirtuals(Location location) { return findVirtuals(findSymbol(location)); }
Set<Symbol> findVirtuals(const Symbol &symbol);
Set<String> findTargetUsrs(const Symbol &symbol);
Set<String> findTargetUsrs(Location loc);
Set<Symbol> findSubclasses(const Symbol &symbol);

Set<Symbol> findByUsr(const String &usr, uint32_t fileId, DependencyMode mode, Location filtered = Location());
Set<Symbol> findByUsr(const String &usr, uint32_t fileId = 0, DependencyMode mode = All, Location filtered = Location());

Path sourceFilePath(uint32_t fileId, const char *path = "") const;

Expand Down
4 changes: 4 additions & 0 deletions src/Symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ String Symbol::toString(Flags<ToStringFlag> cursorInfoFlags,
ret << "MacroExpansion";
if (flags & TemplateSpecialization)
ret << "TemplateSpecialization";
if (flags & TemplateReference)
ret << "TemplateReference";

if (ret.isEmpty())
return String();
Expand Down Expand Up @@ -324,6 +326,8 @@ Value Symbol::toValue(const std::shared_ptr<Project> &project,
ret["macroexpansion"] = true;
if (symbol.flags & Symbol::TemplateSpecialization)
ret["templatespecialization"] = true;
if (symbol.flags & Symbol::TemplateReference)
ret["templatereference"] = true;
if (f & IncludeTargets) {
const auto targets = project->findTargets(symbol);
if (!targets.isEmpty()) {
Expand Down
5 changes: 3 additions & 2 deletions src/Symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ struct Symbol
TemplateSpecialization = 0x0100,
InlineFunction = 0x0200,
ImplicitDestruction = 0x0400,
Definition = 0x0800,
FileSymbol = 0x1000
TemplateReference = 0x0800,
Definition = 0x1000,
FileSymbol = 0x2000
};
String briefComment, xmlComment;
uint16_t flags;
Expand Down

0 comments on commit fdfc5fa

Please sign in to comment.