Skip to content

Commit

Permalink
Add class template instantiations as targets to class templates
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabor Marton committed Sep 23, 2015
1 parent 62bfc5a commit 6ef9bf8
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 0 deletions.
17 changes: 17 additions & 0 deletions automated_tests/templates/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
struct A {
void foo() {}
};
struct B {
void foo() {}
};

template <typename T>
struct X {
void f() {
T t;
t.foo();
}
};

template struct X<A>;
template struct X<B>;
30 changes: 30 additions & 0 deletions automated_tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ def setUp(self):
"--socket-file=" + socket_file,
"--data-dir=~/.rtags_dev",
"--no-filesystem-watcher", "--no-startup-project",
# verbose
"-vvv",
"--log-file", "logfile",
# --clear-project-caches
"-C"],
stdout=sp.PIPE, stderr=sp.STDOUT)
Expand Down Expand Up @@ -186,6 +189,33 @@ def test_find_references(self):
self.assertTrue(compareLocationLists(locations, expected_locations))


class Templates(TestFixture):

def __init__(self, a):
self.name = 'templates'
super(Templates, self).__init__(a)

def test_follow_location(self):
#run_rc(["--status", "targets"])
#run_rc(["--status"])
out = run_rc(
["--references",
toStr(Location(self.main_cpp, 9, 8)),
#"--all-references",
])
# TODO function
locations = []
lines = out.split("\n")
for line in lines:
if len(line) > 0:
loc = Location.fromStr(line)
locations.append(loc)
expected_locations = [
Location(self.main_cpp, 16, 17),
Location(self.main_cpp, 17, 17)]
self.assertTrue(compareLocationLists(locations, expected_locations))


if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Function tests for rtags')
parser.add_argument('--binary_path', '-b', required=True,
Expand Down
11 changes: 11 additions & 0 deletions src/ClangIndexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,17 @@ CXChildVisitResult ClangIndexer::indexVisitor(CXCursor cursor, CXCursor parent,
log << "refs" << ref;
}
}

if (kind == CXCursor_StructDecl) {
Log log(LogLevel::Debug);
log << "StructDecl! " << cursor;
CXCursor c = clang_getSpecializedCursorTemplate(cursor);
if (!(clang_equalCursors(c, nullCursor))) {
log << "Template! " << c;
indexer->unit(loc)->targets[loc][::usr(c)] = 0;
}
}

if (Symbol::isClass(kind)) {
indexer->mLastClass = loc;
} else {
Expand Down
3 changes: 3 additions & 0 deletions src/Project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1645,6 +1645,9 @@ Set<Symbol> Project::findCallers(const Symbol &symbol)
|| (input.kind == CXCursor_Constructor && (ref.kind == CXCursor_VarDecl || ref.kind == CXCursor_FieldDecl))) {
return true;
}
if (input.kind == CXCursor_ClassTemplate) {
return true;
}
return false;
});
}
Expand Down
1 change: 1 addition & 0 deletions src/QueryMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class QueryMessage : public RTagsMessage
enum Flag {
NoFlag = 0x000000000,
NoContext = 0x000000001,
FindInstantiations = 0x000000002,
FilterSystemIncludes = 0x000000004,
StripParentheses = 0x000000008,
AllReferences = 0x000000010,
Expand Down

0 comments on commit 6ef9bf8

Please sign in to comment.