mirror of
https://github.com/MaskRay/ccls.git
synced 2025-02-16 21:58:08 +00:00
all-tests-passing
This commit is contained in:
parent
a8cdadc201
commit
e54d70e464
@ -19,10 +19,24 @@ std::string Type::get_usr() const {
|
|||||||
return clang::Cursor(clang_getTypeDeclaration(cx_type)).get_usr();
|
return clang::Cursor(clang_getTypeDeclaration(cx_type)).get_usr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Type Type::strip_qualifiers() const {
|
||||||
|
//CXRefQualifierKind qualifiers = clang_Type_getCXXRefQualifier(cx_type)
|
||||||
|
switch (cx_type.kind) {
|
||||||
|
case CXType_Pointer:
|
||||||
|
return clang_getPointeeType(cx_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
return cx_type;
|
||||||
|
}
|
||||||
|
|
||||||
std::string Type::get_spelling() const {
|
std::string Type::get_spelling() const {
|
||||||
return ToString(clang_getTypeSpelling(cx_type));
|
return ToString(clang_getTypeSpelling(cx_type));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SourceLocation Cursor::get_source_location() const {
|
||||||
|
return SourceLocation(clang_getCursorLocation(cx_cursor));
|
||||||
|
}
|
||||||
|
|
||||||
Type Type::get_return_type() const {
|
Type Type::get_return_type() const {
|
||||||
return Type(clang_getResultType(cx_type));
|
return Type(clang_getResultType(cx_type));
|
||||||
}
|
}
|
||||||
@ -64,10 +78,6 @@ Type Cursor::get_type() const {
|
|||||||
return Type(clang_getCursorType(cx_cursor));
|
return Type(clang_getCursorType(cx_cursor));
|
||||||
}
|
}
|
||||||
|
|
||||||
SourceLocation Cursor::get_source_location() const {
|
|
||||||
return SourceLocation(clang_getCursorLocation(cx_cursor));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
SourceRange Cursor::get_source_range() const {
|
SourceRange Cursor::get_source_range() const {
|
||||||
return SourceRange(clang_getCursorExtent(cx_cursor));
|
return SourceRange(clang_getCursorExtent(cx_cursor));
|
||||||
|
@ -21,6 +21,10 @@ public:
|
|||||||
|
|
||||||
std::string get_usr() const;
|
std::string get_usr() const;
|
||||||
std::string get_spelling() const;
|
std::string get_spelling() const;
|
||||||
|
|
||||||
|
// Try to resolve this type and remove qualifies, ie, Foo* will become Foo
|
||||||
|
Type strip_qualifiers() const;
|
||||||
|
|
||||||
Type get_return_type() const;
|
Type get_return_type() const;
|
||||||
std::vector<Type> get_arguments() const;
|
std::vector<Type> get_arguments() const;
|
||||||
|
|
||||||
|
20
main.cpp
20
main.cpp
@ -84,7 +84,9 @@ struct TypeDef {
|
|||||||
// Usages.
|
// Usages.
|
||||||
std::vector<clang::SourceLocation> uses;
|
std::vector<clang::SourceLocation> uses;
|
||||||
|
|
||||||
TypeDef(TypeId id, const std::string& usr) : id(id), usr(usr) {}
|
TypeDef(TypeId id, const std::string& usr) : id(id), usr(usr) {
|
||||||
|
std::cout << "Creating type type with usr " << usr << std::endl;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FuncDef {
|
struct FuncDef {
|
||||||
@ -527,7 +529,12 @@ void Dump(clang::Cursor cursor) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: See if we can improve type usage reporting, for example
|
||||||
|
// void foo() {
|
||||||
|
// Foo x;
|
||||||
|
// }
|
||||||
|
// The usage on |Foo| will be reported at the |x| variable location. We should
|
||||||
|
// report it at the start of |Foo| instead.
|
||||||
|
|
||||||
|
|
||||||
void HandleVarDecl(ParsingDatabase* db, NamespaceStack* ns, clang::Cursor var, std::optional<TypeId> declaring_type) {
|
void HandleVarDecl(ParsingDatabase* db, NamespaceStack* ns, clang::Cursor var, std::optional<TypeId> declaring_type) {
|
||||||
@ -549,6 +556,11 @@ void HandleVarDecl(ParsingDatabase* db, NamespaceStack* ns, clang::Cursor var, s
|
|||||||
var_def->declaring_type = declaring_type;
|
var_def->declaring_type = declaring_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add a usage to the type of the variable.
|
||||||
|
clang::Type var_type = var.get_type().strip_qualifiers();
|
||||||
|
TypeId var_type_id = db->ToTypeId(var_type.get_usr());
|
||||||
|
db->Resolve(var_type_id)->uses.push_back(var.get_source_location());
|
||||||
|
|
||||||
// We don't do any additional processing for non-definitions.
|
// We don't do any additional processing for non-definitions.
|
||||||
if (!var.is_definition()) {
|
if (!var.is_definition()) {
|
||||||
var_def->declaration = var.get_source_location();
|
var_def->declaration = var.get_source_location();
|
||||||
@ -563,7 +575,7 @@ void HandleVarDecl(ParsingDatabase* db, NamespaceStack* ns, clang::Cursor var, s
|
|||||||
// TODO: Figure out how to scan initializations properly. We probably need
|
// TODO: Figure out how to scan initializations properly. We probably need
|
||||||
// to scan for assignment statement, or definition+ctor.
|
// to scan for assignment statement, or definition+ctor.
|
||||||
var_def->initializations.push_back(var.get_source_location());
|
var_def->initializations.push_back(var.get_source_location());
|
||||||
var_def->variable_type = db->ToTypeId(var.get_type().get_usr());
|
var_def->variable_type = db->ToTypeId(var.get_type().strip_qualifiers().get_usr());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -935,7 +947,7 @@ void DiffDocuments(rapidjson::Document& expected, rapidjson::Document& actual) {
|
|||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
for (std::string path : GetFilesInFolder("tests")) {
|
for (std::string path : GetFilesInFolder("tests")) {
|
||||||
// TODO: Fix all existing tests.
|
// TODO: Fix all existing tests.
|
||||||
//if (path != "tests/usage/func_usage_class_inline_var_def.cc") continue;
|
//if (path != "tests/usage/type_usage_declare_extern.cc") continue;
|
||||||
|
|
||||||
// Parse expected output from the test, parse it into JSON document.
|
// Parse expected output from the test, parse it into JSON document.
|
||||||
std::string expected_output;
|
std::string expected_output;
|
||||||
|
@ -13,7 +13,8 @@ void user() {
|
|||||||
OUTPUT:
|
OUTPUT:
|
||||||
{
|
{
|
||||||
"types": [{
|
"types": [{
|
||||||
"id": 0
|
"id": 0,
|
||||||
|
"uses": ["tests/usage/func_usage_addr_func.cc:1:19", "tests/usage/func_usage_addr_func.cc:6:8"]
|
||||||
}],
|
}],
|
||||||
"functions": [{
|
"functions": [{
|
||||||
"id": 0,
|
"id": 0,
|
||||||
|
@ -18,7 +18,8 @@ OUTPUT:
|
|||||||
"definition": "tests/usage/func_usage_addr_method.cc:1:8",
|
"definition": "tests/usage/func_usage_addr_method.cc:1:8",
|
||||||
"funcs": [0]
|
"funcs": [0]
|
||||||
}, {
|
}, {
|
||||||
"id": 1
|
"id": 1,
|
||||||
|
"uses": ["tests/usage/func_usage_addr_method.cc:6:8"]
|
||||||
}],
|
}],
|
||||||
"functions": [{
|
"functions": [{
|
||||||
"id": 0,
|
"id": 0,
|
||||||
|
@ -16,9 +16,8 @@ OUTPUT:
|
|||||||
"short_name": "Foo",
|
"short_name": "Foo",
|
||||||
"qualified_name": "Foo",
|
"qualified_name": "Foo",
|
||||||
"definition": "tests/usage/func_usage_call_method.cc:1:8",
|
"definition": "tests/usage/func_usage_call_method.cc:1:8",
|
||||||
"funcs": [0]
|
"funcs": [0],
|
||||||
}, {
|
"uses": ["tests/usage/func_usage_call_method.cc:6:8"]
|
||||||
"id": 1
|
|
||||||
}],
|
}],
|
||||||
"functions": [{
|
"functions": [{
|
||||||
"id": 0,
|
"id": 0,
|
||||||
@ -44,7 +43,7 @@ OUTPUT:
|
|||||||
"qualified_name": "f",
|
"qualified_name": "f",
|
||||||
"declaration": "tests/usage/func_usage_call_method.cc:6:8",
|
"declaration": "tests/usage/func_usage_call_method.cc:6:8",
|
||||||
"initializations": ["tests/usage/func_usage_call_method.cc:6:8"],
|
"initializations": ["tests/usage/func_usage_call_method.cc:6:8"],
|
||||||
"variable_type": 1
|
"variable_type": 0
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
*/
|
*/
|
@ -20,7 +20,8 @@ OUTPUT:
|
|||||||
"definition": "tests/usage/func_usage_class_inline_var_def.cc:5:7",
|
"definition": "tests/usage/func_usage_class_inline_var_def.cc:5:7",
|
||||||
"vars": [0]
|
"vars": [0]
|
||||||
}, {
|
}, {
|
||||||
"id": 1
|
"id": 1,
|
||||||
|
"uses": ["tests/usage/func_usage_class_inline_var_def.cc:6:7"]
|
||||||
}],
|
}],
|
||||||
"functions": [{
|
"functions": [{
|
||||||
"id": 0,
|
"id": 0,
|
||||||
|
@ -15,9 +15,8 @@ OUTPUT:
|
|||||||
"short_name": "Foo",
|
"short_name": "Foo",
|
||||||
"qualified_name": "Foo",
|
"qualified_name": "Foo",
|
||||||
"definition": "tests/usage/func_usage_forward_decl_method.cc:1:8",
|
"definition": "tests/usage/func_usage_forward_decl_method.cc:1:8",
|
||||||
"funcs": [0]
|
"funcs": [0],
|
||||||
}, {
|
"uses": ["tests/usage/func_usage_forward_decl_method.cc:6:8"]
|
||||||
"id": 1
|
|
||||||
}],
|
}],
|
||||||
"functions": [{
|
"functions": [{
|
||||||
"id": 0,
|
"id": 0,
|
||||||
@ -43,7 +42,7 @@ OUTPUT:
|
|||||||
"qualified_name": "f",
|
"qualified_name": "f",
|
||||||
"declaration": "tests/usage/func_usage_forward_decl_method.cc:6:8",
|
"declaration": "tests/usage/func_usage_forward_decl_method.cc:6:8",
|
||||||
"initializations": ["tests/usage/func_usage_forward_decl_method.cc:6:8"],
|
"initializations": ["tests/usage/func_usage_forward_decl_method.cc:6:8"],
|
||||||
"variable_type": 1
|
"variable_type": 0
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
*/
|
*/
|
8
tests/usage/type_usage_as_template_parameter.cc
Normal file
8
tests/usage/type_usage_as_template_parameter.cc
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
/*
|
||||||
|
OUTPUT:
|
||||||
|
{
|
||||||
|
"types": [],
|
||||||
|
"functions": [],
|
||||||
|
"variables": []
|
||||||
|
}
|
||||||
|
*/
|
@ -9,7 +9,8 @@ OUTPUT:
|
|||||||
"usr": "c:@S@T",
|
"usr": "c:@S@T",
|
||||||
"short_name": "T",
|
"short_name": "T",
|
||||||
"qualified_name": "T",
|
"qualified_name": "T",
|
||||||
"definition": "tests/usage/type_usage_declare_extern.cc:1:8"
|
"definition": "tests/usage/type_usage_declare_extern.cc:1:8",
|
||||||
|
"uses": ["tests/usage/type_usage_declare_extern.cc:3:10"]
|
||||||
}],
|
}],
|
||||||
"functions": [],
|
"functions": [],
|
||||||
"variables": [{
|
"variables": [{
|
||||||
|
8
tests/usage/type_usage_on_parameter_unnamed.cc
Normal file
8
tests/usage/type_usage_on_parameter_unnamed.cc
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
/*
|
||||||
|
OUTPUT:
|
||||||
|
{
|
||||||
|
"types": [],
|
||||||
|
"functions": [],
|
||||||
|
"variables": []
|
||||||
|
}
|
||||||
|
*/
|
@ -1,4 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
// TODO: Idea with this test is to verify we will capture std::unique_ptr<T>
|
||||||
|
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
{
|
{
|
||||||
"types": [],
|
"types": [],
|
||||||
|
@ -12,7 +12,8 @@ OUTPUT:
|
|||||||
"definition": "tests/vars/class_member.cc:1:7",
|
"definition": "tests/vars/class_member.cc:1:7",
|
||||||
"vars": [0]
|
"vars": [0]
|
||||||
}, {
|
}, {
|
||||||
"id": 1
|
"id": 1,
|
||||||
|
"uses": ["tests/vars/class_member.cc:2:7"]
|
||||||
}],
|
}],
|
||||||
"functions": [],
|
"functions": [],
|
||||||
"variables": [{
|
"variables": [{
|
||||||
|
@ -13,7 +13,8 @@ OUTPUT:
|
|||||||
"definition": "tests/vars/class_static_member.cc:1:7",
|
"definition": "tests/vars/class_static_member.cc:1:7",
|
||||||
"vars": [0]
|
"vars": [0]
|
||||||
}, {
|
}, {
|
||||||
"id": 1
|
"id": 1,
|
||||||
|
"uses": ["tests/vars/class_static_member.cc:2:14", "tests/vars/class_static_member.cc:4:10"]
|
||||||
}],
|
}],
|
||||||
"functions": [],
|
"functions": [],
|
||||||
"variables": [{
|
"variables": [{
|
||||||
|
@ -11,6 +11,9 @@ OUTPUT:
|
|||||||
"qualified_name": "Foo",
|
"qualified_name": "Foo",
|
||||||
"definition": "tests/vars/class_static_member_decl_only.cc:1:7",
|
"definition": "tests/vars/class_static_member_decl_only.cc:1:7",
|
||||||
"vars": [0]
|
"vars": [0]
|
||||||
|
}, {
|
||||||
|
"id": 1,
|
||||||
|
"uses": ["tests/vars/class_static_member_decl_only.cc:2:14"]
|
||||||
}],
|
}],
|
||||||
"functions": [],
|
"functions": [],
|
||||||
"variables": [{
|
"variables": [{
|
||||||
|
@ -5,7 +5,8 @@ void foo() {
|
|||||||
OUTPUT:
|
OUTPUT:
|
||||||
{
|
{
|
||||||
"types": [{
|
"types": [{
|
||||||
"id": 0
|
"id": 0,
|
||||||
|
"uses": ["tests/vars/function_local.cc:2:7"]
|
||||||
}],
|
}],
|
||||||
"functions": [{
|
"functions": [{
|
||||||
"id": 0,
|
"id": 0,
|
||||||
|
@ -3,7 +3,8 @@ void foo(int p0, int p1) {}
|
|||||||
OUTPUT:
|
OUTPUT:
|
||||||
{
|
{
|
||||||
"types": [{
|
"types": [{
|
||||||
"id": 0
|
"id": 0,
|
||||||
|
"uses": ["tests/vars/function_param.cc:1:14", "tests/vars/function_param.cc:1:22"]
|
||||||
}],
|
}],
|
||||||
"functions": [{
|
"functions": [{
|
||||||
"id": 0,
|
"id": 0,
|
||||||
|
@ -8,7 +8,8 @@ void foo(int, int) {}
|
|||||||
OUTPUT:
|
OUTPUT:
|
||||||
{
|
{
|
||||||
"types": [{
|
"types": [{
|
||||||
"id": 0
|
"id": 0,
|
||||||
|
"uses": ["tests/vars/function_param_unnamed.cc:1:13", "tests/vars/function_param_unnamed.cc:1:18"]
|
||||||
}],
|
}],
|
||||||
"functions": [{
|
"functions": [{
|
||||||
"id": 0,
|
"id": 0,
|
||||||
|
@ -8,7 +8,8 @@ void foo() {
|
|||||||
OUTPUT:
|
OUTPUT:
|
||||||
{
|
{
|
||||||
"types": [{
|
"types": [{
|
||||||
"id": 0
|
"id": 0,
|
||||||
|
"uses": ["tests/vars/function_shadow_local.cc:2:7", "tests/vars/function_shadow_local.cc:4:9"]
|
||||||
}],
|
}],
|
||||||
"functions": [{
|
"functions": [{
|
||||||
"id": 0,
|
"id": 0,
|
||||||
|
@ -5,7 +5,8 @@ void foo(int p) {
|
|||||||
OUTPUT:
|
OUTPUT:
|
||||||
{
|
{
|
||||||
"types": [{
|
"types": [{
|
||||||
"id": 0
|
"id": 0,
|
||||||
|
"uses": ["tests/vars/function_shadow_param.cc:1:14", "tests/vars/function_shadow_param.cc:2:7"]
|
||||||
}],
|
}],
|
||||||
"functions": [{
|
"functions": [{
|
||||||
"id": 0,
|
"id": 0,
|
||||||
|
@ -3,7 +3,8 @@ static int global = 0;
|
|||||||
OUTPUT:
|
OUTPUT:
|
||||||
{
|
{
|
||||||
"types": [{
|
"types": [{
|
||||||
"id": 0
|
"id": 0,
|
||||||
|
"uses": ["tests/vars/global_variable.cc:1:12"]
|
||||||
}],
|
}],
|
||||||
"functions": [],
|
"functions": [],
|
||||||
"variables": [{
|
"variables": [{
|
||||||
|
@ -2,7 +2,10 @@ extern int global;
|
|||||||
/*
|
/*
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
{
|
{
|
||||||
"types": [],
|
"types": [{
|
||||||
|
"id": 0,
|
||||||
|
"uses": ["tests/vars/global_variable_decl_only.cc:1:12"]
|
||||||
|
}],
|
||||||
"functions": [],
|
"functions": [],
|
||||||
"variables": [{
|
"variables": [{
|
||||||
"id": 0,
|
"id": 0,
|
||||||
|
Loading…
Reference in New Issue
Block a user