mirror of
https://github.com/MaskRay/ccls.git
synced 2025-01-31 09:50:26 +00:00
fix usage on specialized template parameters
This commit is contained in:
parent
e06f9472c1
commit
f6967eee48
29
indexer.cpp
29
indexer.cpp
@ -509,9 +509,25 @@ optional<TypeId> AddDeclUsages(IndexedFile* db, clang::Cursor decl_cursor,
|
|||||||
// The second TypeRef is an uninteresting usage.
|
// The second TypeRef is an uninteresting usage.
|
||||||
bool process_last_type_ref = true;
|
bool process_last_type_ref = true;
|
||||||
if (IsTypeDefinition(semantic_container) && !IsTypeDefinition(lexical_container)) {
|
if (IsTypeDefinition(semantic_container) && !IsTypeDefinition(lexical_container)) {
|
||||||
//if (!decl_cursor.is_definition())
|
|
||||||
// decl_cursor = decl_cursor.get_definition();
|
//
|
||||||
assert(decl_cursor.is_definition());
|
// In some code, such as the following example, we receive a cursor which is not
|
||||||
|
// a definition and is not associated with a definition due to an error condition.
|
||||||
|
// In this case, it is the Foo::Foo constructor.
|
||||||
|
//
|
||||||
|
// struct Foo {};
|
||||||
|
//
|
||||||
|
// template<class T>
|
||||||
|
// Foo::Foo() {}
|
||||||
|
//
|
||||||
|
if (!decl_cursor.is_definition()) {
|
||||||
|
// TODO: I don't think this resolution ever works.
|
||||||
|
clang::Cursor def = decl_cursor.get_definition();
|
||||||
|
if (def.get_kind() != CXCursor_FirstInvalid) {
|
||||||
|
std::cerr << "Successful resolution of decl usage to definition" << std::endl;
|
||||||
|
decl_cursor = def;
|
||||||
|
}
|
||||||
|
}
|
||||||
process_last_type_ref = false;
|
process_last_type_ref = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -683,8 +699,9 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
|||||||
switch (arg.get_kind()) {
|
switch (arg.get_kind()) {
|
||||||
case CXCursor_ParmDecl:
|
case CXCursor_ParmDecl:
|
||||||
// We don't need to know the arg type, but we do want to mark it as
|
// We don't need to know the arg type, but we do want to mark it as
|
||||||
// an interesting usage.
|
// an interesting usage. Note that we use semanticContainer twice
|
||||||
AddDeclUsages(db, arg, true /*is_interesting*/, decl->semanticContainer, decl->lexicalContainer);
|
// because a parameter is not really part of the lexical container.
|
||||||
|
AddDeclUsages(db, arg, true /*is_interesting*/, decl->semanticContainer, decl->semanticContainer);
|
||||||
|
|
||||||
//TypeResolution arg_type = ResolveToType(db, arg.get_type());
|
//TypeResolution arg_type = ResolveToType(db, arg.get_type());
|
||||||
//if (arg_type.resolved_type)
|
//if (arg_type.resolved_type)
|
||||||
@ -1006,4 +1023,4 @@ IndexedFile Parse(std::string filename, std::vector<std::string> args, bool dump
|
|||||||
clang_IndexAction_dispose(index_action);
|
clang_IndexAction_dispose(index_action);
|
||||||
|
|
||||||
return db;
|
return db;
|
||||||
}
|
}
|
5
test.cc
5
test.cc
@ -94,9 +94,10 @@ int main(int argc, char** argv) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
for (std::string path : GetFilesInFolder("tests", true /*add_folder_to_path*/)) {
|
for (std::string path : GetFilesInFolder("tests", true /*add_folder_to_path*/)) {
|
||||||
//if (path != "tests/usage/var_usage_cstyle_cast.cc") continue;
|
//if (path != "tests/templates/func_specialized_template_param.cc") continue;
|
||||||
|
//if (path != "tests/constructors/invalid_reference.cc") continue;
|
||||||
//if (path == "tests/inheritance/class_inherit_templated_parent.cc") continue;
|
//if (path == "tests/inheritance/class_inherit_templated_parent.cc") continue;
|
||||||
//if (path != "tests/templates/template_class_type_usage_folded_into_one.cc") continue;
|
if (path == "tests/stl.cc") continue;
|
||||||
|
|
||||||
//if (path != "tests/templates/template_class_type_usage_folded_into_one.cc") continue;
|
//if (path != "tests/templates/template_class_type_usage_folded_into_one.cc") continue;
|
||||||
//path = "C:/Users/jacob/Desktop/superindex/indexer/" + path;
|
//path = "C:/Users/jacob/Desktop/superindex/indexer/" + path;
|
||||||
|
29
tests/constructors/invalid_reference.cc
Normal file
29
tests/constructors/invalid_reference.cc
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
struct Foo {};
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
Foo::Foo() {}
|
||||||
|
|
||||||
|
/*
|
||||||
|
OUTPUT:
|
||||||
|
{
|
||||||
|
"types": [{
|
||||||
|
"id": 0,
|
||||||
|
"usr": "c:@S@Foo",
|
||||||
|
"short_name": "Foo",
|
||||||
|
"qualified_name": "Foo",
|
||||||
|
"definition": "1:1:8",
|
||||||
|
"funcs": [0],
|
||||||
|
"uses": ["*1:1:8", "1:4:6", "1:4:1"]
|
||||||
|
}],
|
||||||
|
"functions": [{
|
||||||
|
"id": 0,
|
||||||
|
"usr": "c:@S@Foo@FT@>1#TFoo#v#",
|
||||||
|
"short_name": "Foo",
|
||||||
|
"qualified_name": "Foo::Foo",
|
||||||
|
"definition": "1:4:6",
|
||||||
|
"declaring_type": 0,
|
||||||
|
"uses": ["1:4:6"]
|
||||||
|
}],
|
||||||
|
"variables": []
|
||||||
|
}
|
||||||
|
*/
|
105
tests/foobar.cc
105
tests/foobar.cc
@ -8,33 +8,6 @@ struct Foo {
|
|||||||
|
|
||||||
Foo<A>::Inner a;
|
Foo<A>::Inner a;
|
||||||
Foo<B> b;
|
Foo<B> b;
|
||||||
|
|
||||||
//#include <string>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if false
|
|
||||||
// We could store how many template parameters Foo has and then skip that many TypeRefs...,
|
|
||||||
// if there was still a TypeRef after (and we are not ignoring it) then we know
|
|
||||||
// that is the variable type.
|
|
||||||
|
|
||||||
EnumDecl A
|
|
||||||
EnumDecl B
|
|
||||||
ClassTemplate Foo
|
|
||||||
TemplateTypeParameter T
|
|
||||||
StructDecl Inner
|
|
||||||
VarDecl a
|
|
||||||
TemplateRef Foo
|
|
||||||
TypeRef enum A
|
|
||||||
TypeRef struct Foo<enum A>::Inner
|
|
||||||
CallExpr Inner
|
|
||||||
VarDecl b
|
|
||||||
TemplateRef Foo
|
|
||||||
TypeRef enum B
|
|
||||||
CallExpr Foo
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
{
|
{
|
||||||
@ -115,34 +88,6 @@ namespace ns {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// TODO: we are not marking interesting usage for a CStyleCastExpr
|
|
||||||
// TODO: we are resoling templates in a weird way (should be 1 type)
|
|
||||||
#if false
|
|
||||||
Namespace ns
|
|
||||||
EnumDecl VarType
|
|
||||||
ClassTemplate Holder
|
|
||||||
TemplateTypeParameter _
|
|
||||||
VarDecl static_var
|
|
||||||
TypeRef enum ns::VarType
|
|
||||||
CStyleCastExpr
|
|
||||||
TypeRef enum ns::VarType
|
|
||||||
IntegerLiteral
|
|
||||||
VarDecl static_var
|
|
||||||
TemplateTypeParameter _
|
|
||||||
TypeRef enum ns::VarType
|
|
||||||
TemplateRef Holder
|
|
||||||
TypeRef _
|
|
||||||
VarDecl Foo
|
|
||||||
UnexposedExpr static_var
|
|
||||||
UnexposedExpr static_var
|
|
||||||
DeclRefExpr static_var
|
|
||||||
TemplateRef Holder
|
|
||||||
VarDecl static_var
|
|
||||||
TypeRef enum ns::VarType
|
|
||||||
TemplateRef Holder
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
{
|
{
|
||||||
@ -218,53 +163,3 @@ OUTPUT:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//#include <string>
|
|
||||||
//#include <xiosbase>
|
|
||||||
|
|
||||||
//#include <sstream>
|
|
||||||
//#include <algorithm>
|
|
||||||
//#include <vector>
|
|
||||||
//#include <string>
|
|
||||||
//#include <cstddef>
|
|
||||||
//#include <sstream>
|
|
||||||
//#include <iomanip>
|
|
||||||
//#include <limits>
|
|
||||||
//#include <vector>
|
|
||||||
//#include <cstddef>
|
|
||||||
//#include <tuple>
|
|
||||||
//#include <type_traits>
|
|
||||||
//#include <string>
|
|
||||||
//#include <string>
|
|
||||||
//#include <type_traits>
|
|
||||||
//#include <iterator>
|
|
||||||
//#include <vector>
|
|
||||||
//#include <string>
|
|
||||||
//#include <stdlib.h>
|
|
||||||
//#include <string>
|
|
||||||
//#include <vector>
|
|
||||||
//#include <string>
|
|
||||||
//#include <cstddef>
|
|
||||||
//#include <cmath>
|
|
||||||
//#include <limits>
|
|
||||||
//#include <type_traits>
|
|
||||||
//#include <set>
|
|
||||||
//#include <string>
|
|
||||||
//#include <vector>
|
|
||||||
//#include <iosfwd>
|
|
||||||
//#include <streambuf>
|
|
||||||
//#include <ostream>
|
|
||||||
//#include <fstream>
|
|
||||||
//#include <memory>
|
|
||||||
//#include <vector>
|
|
||||||
//#include <string>
|
|
||||||
//#include <stdexcept>
|
|
||||||
//#include <string>
|
|
||||||
//#include <vector>
|
|
||||||
//#include <sstream>
|
|
||||||
//#include <algorithm>
|
|
142
tests/stl.cc
Normal file
142
tests/stl.cc
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
#include <assert.h>
|
||||||
|
#include <complex.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <fenv.h>
|
||||||
|
#include <float.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <iso646.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <locale.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <setjmp.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdalign.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdatomic.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdnoreturn.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <tgmath.h>
|
||||||
|
#include <threads.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <uchar.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
#include <wctype.h>
|
||||||
|
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <xiosbase>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <iterator>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cmath>
|
||||||
|
#include <set>
|
||||||
|
#include <iosfwd>
|
||||||
|
#include <streambuf>
|
||||||
|
#include <ostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <memory>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <vector>
|
||||||
|
#include <sstream>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <limits>
|
||||||
|
#include <tuple>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <csignal>
|
||||||
|
#include <csetjmp>
|
||||||
|
#include <cstdarg>
|
||||||
|
#include <typeinfo>
|
||||||
|
#include <typeindex>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <bitset>
|
||||||
|
#include <functional>
|
||||||
|
#include <utility>
|
||||||
|
#include <ctime>
|
||||||
|
#include <chrono>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <initializer_list>
|
||||||
|
#include <tuple>
|
||||||
|
#include <any>
|
||||||
|
#include <optional>
|
||||||
|
#include <variant>
|
||||||
|
#include <new>
|
||||||
|
#include <memory>
|
||||||
|
#include <scoped_allocator>
|
||||||
|
#include <memory_resource>
|
||||||
|
#include <climits>
|
||||||
|
#include <cfloat>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cinttypes>
|
||||||
|
#include <limits>
|
||||||
|
#include <exception>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <cassert>
|
||||||
|
#include <system_error>
|
||||||
|
#include <cerrno>
|
||||||
|
#include <cctype>
|
||||||
|
#include <cwctype>
|
||||||
|
#include <cstring>
|
||||||
|
#include <cwchar>
|
||||||
|
#include <cuchar>
|
||||||
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
#include <array>
|
||||||
|
#include <vector>
|
||||||
|
#include <deque>
|
||||||
|
#include <list>
|
||||||
|
#include <forward_list>
|
||||||
|
#include <set>
|
||||||
|
#include <map>
|
||||||
|
#include <unordered_set>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <stack>
|
||||||
|
#include <queue>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <execution>
|
||||||
|
#include <iterator>
|
||||||
|
#include <cmath>
|
||||||
|
#include <complex>
|
||||||
|
#include <valarray>
|
||||||
|
#include <random>
|
||||||
|
#include <numeric>
|
||||||
|
#include <ratio>
|
||||||
|
#include <cfenv>
|
||||||
|
#include <iosfwd>
|
||||||
|
#include <ios>
|
||||||
|
#include <istream>
|
||||||
|
#include <ostream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <strstream>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <streambuf>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <locale>
|
||||||
|
#include <clocale>
|
||||||
|
#include <codecvt>
|
||||||
|
#include <regex>
|
||||||
|
#include <atomic>
|
||||||
|
#include <thread>
|
||||||
|
#include <mutex>
|
||||||
|
#include <shared_mutex>
|
||||||
|
#include <future>
|
||||||
|
#include <condition_variable>
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
|
/*
|
||||||
|
OUTPUT:
|
||||||
|
{
|
||||||
|
"types": [],
|
||||||
|
"functions": [],
|
||||||
|
"variables": []
|
||||||
|
}
|
||||||
|
*/
|
41
tests/templates/func_specialized_template_param.cc
Normal file
41
tests/templates/func_specialized_template_param.cc
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
template<class T>
|
||||||
|
class Template {};
|
||||||
|
|
||||||
|
struct Foo {
|
||||||
|
void Bar(Template<double>&);
|
||||||
|
};
|
||||||
|
|
||||||
|
void Foo::Bar(Template<double>&) {}
|
||||||
|
|
||||||
|
/*
|
||||||
|
OUTPUT:
|
||||||
|
{
|
||||||
|
"types": [{
|
||||||
|
"id": 0,
|
||||||
|
"usr": "c:@ST>1#T@Template",
|
||||||
|
"short_name": "Template",
|
||||||
|
"qualified_name": "Template",
|
||||||
|
"definition": "1:2:7",
|
||||||
|
"uses": ["*1:2:7", "1:5:12", "*1:8:15"]
|
||||||
|
}, {
|
||||||
|
"id": 1,
|
||||||
|
"usr": "c:@S@Foo",
|
||||||
|
"short_name": "Foo",
|
||||||
|
"qualified_name": "Foo",
|
||||||
|
"definition": "1:4:8",
|
||||||
|
"funcs": [0],
|
||||||
|
"uses": ["*1:4:8", "1:8:6"]
|
||||||
|
}],
|
||||||
|
"functions": [{
|
||||||
|
"id": 0,
|
||||||
|
"usr": "c:@S@Foo@F@Bar#&$@S@Template>#d#",
|
||||||
|
"short_name": "Bar",
|
||||||
|
"qualified_name": "Foo::Bar",
|
||||||
|
"declarations": ["1:5:8"],
|
||||||
|
"definition": "1:8:11",
|
||||||
|
"declaring_type": 1,
|
||||||
|
"uses": ["1:5:8", "1:8:11"]
|
||||||
|
}],
|
||||||
|
"variables": []
|
||||||
|
}
|
||||||
|
*/
|
Loading…
Reference in New Issue
Block a user