mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-22 07:35:08 +00:00
wip
This commit is contained in:
parent
41f2a75de0
commit
fd1d8c8785
@ -16,6 +16,11 @@ bool Type::operator==(const Type& rhs) const {
|
||||
}
|
||||
|
||||
bool Type::is_fundamental() const {
|
||||
//switch (cx_type.kind) {
|
||||
//case CXType_Auto:
|
||||
//return true;
|
||||
//}
|
||||
|
||||
// NOTE: This will return false for pointed types. Should we call
|
||||
// strip_qualifiers for the user?
|
||||
return cx_type.kind >= CXType_FirstBuiltin &&
|
||||
|
22
main.cpp
22
main.cpp
@ -85,7 +85,8 @@ struct TypeDef {
|
||||
std::vector<clang::SourceLocation> uses;
|
||||
|
||||
TypeDef(TypeId id, const std::string& usr) : id(id), usr(usr) {
|
||||
std::cout << "Creating type with usr " << usr << std::endl;
|
||||
//assert(usr.size() > 0);
|
||||
//std::cout << "Creating type with usr " << usr << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
@ -152,6 +153,8 @@ struct ParsingDatabase {
|
||||
std::vector<FuncDef> funcs;
|
||||
std::vector<VarDef> vars;
|
||||
|
||||
ParsingDatabase();
|
||||
|
||||
TypeId ToTypeId(const std::string& usr);
|
||||
FuncId ToFuncId(const std::string& usr);
|
||||
VarId ToVarId(const std::string& usr);
|
||||
@ -163,6 +166,8 @@ struct ParsingDatabase {
|
||||
std::string ToString();
|
||||
};
|
||||
|
||||
ParsingDatabase::ParsingDatabase() {}
|
||||
|
||||
TypeId ParsingDatabase::ToTypeId(const std::string& usr) {
|
||||
auto it = usr_to_type_id.find(usr);
|
||||
if (it != usr_to_type_id.end())
|
||||
@ -296,6 +301,12 @@ void Write(Writer& writer, const char* key, uint64_t value) {
|
||||
}
|
||||
|
||||
std::string ParsingDatabase::ToString() {
|
||||
auto it = usr_to_type_id.find("");
|
||||
if (it != usr_to_type_id.end()) {
|
||||
Resolve(it->second)->short_name = "<fundamental>";
|
||||
assert(Resolve(it->second)->uses.size() == 0);
|
||||
}
|
||||
|
||||
#define WRITE(name) Write(writer, #name, def.name)
|
||||
|
||||
rapidjson::StringBuffer output;
|
||||
@ -539,7 +550,8 @@ void Dump(clang::Cursor cursor) {
|
||||
void InsertTypeUsageAtLocation(ParsingDatabase* db, clang::Type type, const clang::SourceLocation& location) {
|
||||
clang::Type raw_type = type.strip_qualifiers();
|
||||
|
||||
if (raw_type.is_fundamental())
|
||||
std::string usr = raw_type.get_usr();
|
||||
if (usr == "")
|
||||
return;
|
||||
|
||||
// Add a usage to the type of the variable.
|
||||
@ -583,7 +595,9 @@ void HandleVarDecl(ParsingDatabase* db, NamespaceStack* ns, clang::Cursor var, s
|
||||
// TODO: Figure out how to scan initializations properly. We probably need
|
||||
// to scan for assignment statement, or definition+ctor.
|
||||
var_def->initializations.push_back(var.get_source_location());
|
||||
var_def->variable_type = db->ToTypeId(var.get_type().strip_qualifiers().get_usr());
|
||||
std::string var_type_usr = var.get_type().strip_qualifiers().get_usr();
|
||||
if (var_type_usr != "")
|
||||
var_def->variable_type = db->ToTypeId(var_type_usr);
|
||||
}
|
||||
|
||||
|
||||
@ -945,7 +959,7 @@ void DiffDocuments(rapidjson::Document& expected, rapidjson::Document& actual) {
|
||||
int main(int argc, char** argv) {
|
||||
for (std::string path : GetFilesInFolder("tests")) {
|
||||
// TODO: Fix all existing tests.
|
||||
//if (path != "tests/method_definition.cc") continue;
|
||||
//if (path != "tests/usage/func_usage_addr_func.cc") continue;
|
||||
|
||||
// Parse expected output from the test, parse it into JSON document.
|
||||
std::string expected_output;
|
||||
|
@ -10,10 +10,7 @@ void user() {
|
||||
/*
|
||||
OUTPUT:
|
||||
{
|
||||
"types": [{
|
||||
"id": 0,
|
||||
"uses": ["tests/usage/func_usage_addr_func.cc:6:8"]
|
||||
}],
|
||||
"types": [],
|
||||
"functions": [{
|
||||
"id": 0,
|
||||
"usr": "c:@F@consume#*v#",
|
||||
@ -41,16 +38,14 @@ OUTPUT:
|
||||
"variables": [{
|
||||
"id": 0,
|
||||
"declaration": "tests/usage/func_usage_addr_func.cc:1:19",
|
||||
"initializations": ["tests/usage/func_usage_addr_func.cc:1:19"],
|
||||
"variable_type": 0
|
||||
"initializations": ["tests/usage/func_usage_addr_func.cc:1:19"]
|
||||
}, {
|
||||
"id": 1,
|
||||
"usr": "c:func_usage_addr_func.cc@61@F@user#@x",
|
||||
"short_name": "x",
|
||||
"qualified_name": "x",
|
||||
"declaration": "tests/usage/func_usage_addr_func.cc:6:8",
|
||||
"initializations": ["tests/usage/func_usage_addr_func.cc:6:8"],
|
||||
"variable_type": 0
|
||||
"initializations": ["tests/usage/func_usage_addr_func.cc:6:8"]
|
||||
}]
|
||||
}
|
||||
*/
|
@ -17,9 +17,6 @@ OUTPUT:
|
||||
"qualified_name": "Foo",
|
||||
"definition": "tests/usage/func_usage_addr_method.cc:1:8",
|
||||
"funcs": [0]
|
||||
}, {
|
||||
"id": 1,
|
||||
"uses": ["tests/usage/func_usage_addr_method.cc:6:8"]
|
||||
}],
|
||||
"functions": [{
|
||||
"id": 0,
|
||||
@ -44,8 +41,7 @@ OUTPUT:
|
||||
"short_name": "x",
|
||||
"qualified_name": "x",
|
||||
"declaration": "tests/usage/func_usage_addr_method.cc:6:8",
|
||||
"initializations": ["tests/usage/func_usage_addr_method.cc:6:8"],
|
||||
"variable_type": 1
|
||||
"initializations": ["tests/usage/func_usage_addr_method.cc:6:8"]
|
||||
}]
|
||||
}
|
||||
*/
|
@ -9,8 +9,6 @@ class Foo {
|
||||
// TODO(libclang): libclang doesn't expose the |helper| reference in the ast,
|
||||
// so we can't add the |helper| usage.
|
||||
|
||||
// TODO: Remove "id" 1 output
|
||||
|
||||
/*
|
||||
OUTPUT:
|
||||
{
|
||||
@ -21,8 +19,6 @@ OUTPUT:
|
||||
"qualified_name": "Foo",
|
||||
"definition": "tests/usage/func_usage_class_inline_var_def.cc:5:7",
|
||||
"vars": [0]
|
||||
}, {
|
||||
"id": 1
|
||||
}],
|
||||
"functions": [{
|
||||
"id": 0,
|
||||
@ -38,7 +34,6 @@ OUTPUT:
|
||||
"qualified_name": "Foo::x",
|
||||
"declaration": "tests/usage/func_usage_class_inline_var_def.cc:6:7",
|
||||
"initializations": ["tests/usage/func_usage_class_inline_var_def.cc:6:7"],
|
||||
"variable_type": 1,
|
||||
"declaring_type": 0
|
||||
}]
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
int member;
|
||||
Foo* member;
|
||||
};
|
||||
/*
|
||||
OUTPUT:
|
||||
@ -10,9 +10,8 @@ OUTPUT:
|
||||
"short_name": "Foo",
|
||||
"qualified_name": "Foo",
|
||||
"definition": "tests/vars/class_member.cc:1:7",
|
||||
"vars": [0]
|
||||
}, {
|
||||
"id": 1
|
||||
"vars": [0],
|
||||
"uses": ["tests/vars/class_member.cc:2:8"]
|
||||
}],
|
||||
"functions": [],
|
||||
"variables": [{
|
||||
@ -20,9 +19,9 @@ OUTPUT:
|
||||
"usr": "c:@S@Foo@FI@member",
|
||||
"short_name": "member",
|
||||
"qualified_name": "Foo::member",
|
||||
"declaration": "tests/vars/class_member.cc:2:7",
|
||||
"initializations": ["tests/vars/class_member.cc:2:7"],
|
||||
"variable_type": 1,
|
||||
"declaration": "tests/vars/class_member.cc:2:8",
|
||||
"initializations": ["tests/vars/class_member.cc:2:8"],
|
||||
"variable_type": 0,
|
||||
"declaring_type": 0
|
||||
}]
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
class Foo {
|
||||
static int member;
|
||||
static Foo* member;
|
||||
};
|
||||
int Foo::member = 0;
|
||||
Foo* Foo::member = nullptr;
|
||||
|
||||
/*
|
||||
OUTPUT:
|
||||
{
|
||||
@ -11,9 +12,8 @@ OUTPUT:
|
||||
"short_name": "Foo",
|
||||
"qualified_name": "Foo",
|
||||
"definition": "tests/vars/class_static_member.cc:1:7",
|
||||
"vars": [0]
|
||||
}, {
|
||||
"id": 1
|
||||
"vars": [0],
|
||||
"uses": ["tests/vars/class_static_member.cc:2:15", "tests/vars/class_static_member.cc:4:11"]
|
||||
}],
|
||||
"functions": [],
|
||||
"variables": [{
|
||||
@ -21,9 +21,9 @@ OUTPUT:
|
||||
"usr": "c:@S@Foo@member",
|
||||
"short_name": "member",
|
||||
"qualified_name": "Foo::member",
|
||||
"declaration": "tests/vars/class_static_member.cc:2:14",
|
||||
"initializations": ["tests/vars/class_static_member.cc:4:10"],
|
||||
"variable_type": 1,
|
||||
"declaration": "tests/vars/class_static_member.cc:2:15",
|
||||
"initializations": ["tests/vars/class_static_member.cc:4:11"],
|
||||
"variable_type": 0,
|
||||
"declaring_type": 0
|
||||
}]
|
||||
}
|
||||
|
@ -1,26 +1,33 @@
|
||||
struct Foo;
|
||||
|
||||
void foo() {
|
||||
int a;
|
||||
Foo* a;
|
||||
}
|
||||
/*
|
||||
OUTPUT:
|
||||
{
|
||||
"types": [{
|
||||
"id": 0
|
||||
"id": 0,
|
||||
"usr": "c:@S@Foo",
|
||||
"short_name": "Foo",
|
||||
"qualified_name": "Foo",
|
||||
"declaration": "tests/vars/function_local.cc:1:8",
|
||||
"uses": ["tests/vars/function_local.cc:4:8"]
|
||||
}],
|
||||
"functions": [{
|
||||
"id": 0,
|
||||
"usr": "c:@F@foo#",
|
||||
"short_name": "foo",
|
||||
"qualified_name": "foo",
|
||||
"definition": "tests/vars/function_local.cc:1:6"
|
||||
"definition": "tests/vars/function_local.cc:3:6"
|
||||
}],
|
||||
"variables": [{
|
||||
"id": 0,
|
||||
"usr": "c:function_local.cc@16@F@foo#@a",
|
||||
"usr": "c:function_local.cc@31@F@foo#@a",
|
||||
"short_name": "a",
|
||||
"qualified_name": "a",
|
||||
"declaration": "tests/vars/function_local.cc:2:7",
|
||||
"initializations": ["tests/vars/function_local.cc:2:7"],
|
||||
"declaration": "tests/vars/function_local.cc:4:8",
|
||||
"initializations": ["tests/vars/function_local.cc:4:8"],
|
||||
"variable_type": 0
|
||||
}]
|
||||
}
|
||||
|
@ -1,32 +1,39 @@
|
||||
void foo(int p0, int p1) {}
|
||||
struct Foo;
|
||||
|
||||
void foo(Foo* p0, Foo* p1) {}
|
||||
/*
|
||||
OUTPUT:
|
||||
{
|
||||
"types": [{
|
||||
"id": 0
|
||||
"id": 0,
|
||||
"usr": "c:@S@Foo",
|
||||
"short_name": "Foo",
|
||||
"qualified_name": "Foo",
|
||||
"declaration": "tests/vars/function_param.cc:1:8",
|
||||
"uses": ["tests/vars/function_param.cc:3:15", "tests/vars/function_param.cc:3:24"]
|
||||
}],
|
||||
"functions": [{
|
||||
"id": 0,
|
||||
"usr": "c:@F@foo#I#I#",
|
||||
"usr": "c:@F@foo#*$@S@Foo#S0_#",
|
||||
"short_name": "foo",
|
||||
"qualified_name": "foo",
|
||||
"definition": "tests/vars/function_param.cc:1:6"
|
||||
"definition": "tests/vars/function_param.cc:3:6"
|
||||
}],
|
||||
"variables": [{
|
||||
"id": 0,
|
||||
"usr": "c:function_param.cc@9@F@foo#I#I#@p0",
|
||||
"usr": "c:function_param.cc@24@F@foo#*$@S@Foo#S0_#@p0",
|
||||
"short_name": "p0",
|
||||
"qualified_name": "p0",
|
||||
"declaration": "tests/vars/function_param.cc:1:14",
|
||||
"initializations": ["tests/vars/function_param.cc:1:14"],
|
||||
"declaration": "tests/vars/function_param.cc:3:15",
|
||||
"initializations": ["tests/vars/function_param.cc:3:15"],
|
||||
"variable_type": 0
|
||||
}, {
|
||||
"id": 1,
|
||||
"usr": "c:function_param.cc@17@F@foo#I#I#@p1",
|
||||
"usr": "c:function_param.cc@33@F@foo#*$@S@Foo#S0_#@p1",
|
||||
"short_name": "p1",
|
||||
"qualified_name": "p1",
|
||||
"declaration": "tests/vars/function_param.cc:1:22",
|
||||
"initializations": ["tests/vars/function_param.cc:1:22"],
|
||||
"declaration": "tests/vars/function_param.cc:3:24",
|
||||
"initializations": ["tests/vars/function_param.cc:3:24"],
|
||||
"variable_type": 0
|
||||
}]
|
||||
}
|
||||
|
@ -7,9 +7,7 @@ void foo(int, int) {}
|
||||
|
||||
OUTPUT:
|
||||
{
|
||||
"types": [{
|
||||
"id": 0
|
||||
}],
|
||||
"types": [],
|
||||
"functions": [{
|
||||
"id": 0,
|
||||
"usr": "c:@F@foo#I#I#",
|
||||
@ -20,8 +18,7 @@ OUTPUT:
|
||||
"variables": [{
|
||||
"id": 0,
|
||||
"declaration": "tests/vars/function_param_unnamed.cc:1:13",
|
||||
"initializations": ["tests/vars/function_param_unnamed.cc:1:13", "tests/vars/function_param_unnamed.cc:1:18"],
|
||||
"variable_type": 0
|
||||
"initializations": ["tests/vars/function_param_unnamed.cc:1:13", "tests/vars/function_param_unnamed.cc:1:18"]
|
||||
}]
|
||||
}
|
||||
*/
|
@ -1,15 +1,16 @@
|
||||
void foo() {
|
||||
int a;
|
||||
a = 1;
|
||||
{
|
||||
int a;
|
||||
a = 2;
|
||||
}
|
||||
a = 3;
|
||||
}
|
||||
/*
|
||||
OUTPUT:
|
||||
{
|
||||
"types": [{
|
||||
"id": 0
|
||||
}],
|
||||
"types": [],
|
||||
"functions": [{
|
||||
"id": 0,
|
||||
"usr": "c:@F@foo#",
|
||||
@ -24,15 +25,15 @@ OUTPUT:
|
||||
"qualified_name": "a",
|
||||
"declaration": "tests/vars/function_shadow_local.cc:2:7",
|
||||
"initializations": ["tests/vars/function_shadow_local.cc:2:7"],
|
||||
"variable_type": 0
|
||||
"uses": ["tests/vars/function_shadow_local.cc:3:3", "tests/vars/function_shadow_local.cc:8:3"]
|
||||
}, {
|
||||
"id": 1,
|
||||
"usr": "c:function_shadow_local.cc@33@F@foo#@a",
|
||||
"usr": "c:function_shadow_local.cc@43@F@foo#@a",
|
||||
"short_name": "a",
|
||||
"qualified_name": "a",
|
||||
"declaration": "tests/vars/function_shadow_local.cc:4:9",
|
||||
"initializations": ["tests/vars/function_shadow_local.cc:4:9"],
|
||||
"variable_type": 0
|
||||
"declaration": "tests/vars/function_shadow_local.cc:5:9",
|
||||
"initializations": ["tests/vars/function_shadow_local.cc:5:9"],
|
||||
"uses": ["tests/vars/function_shadow_local.cc:6:5"]
|
||||
}]
|
||||
}
|
||||
*/
|
@ -4,9 +4,7 @@ void foo(int p) {
|
||||
/*
|
||||
OUTPUT:
|
||||
{
|
||||
"types": [{
|
||||
"id": 0
|
||||
}],
|
||||
"types": [],
|
||||
"functions": [{
|
||||
"id": 0,
|
||||
"usr": "c:@F@foo#I#",
|
||||
@ -20,16 +18,14 @@ OUTPUT:
|
||||
"short_name": "p",
|
||||
"qualified_name": "p",
|
||||
"declaration": "tests/vars/function_shadow_param.cc:1:14",
|
||||
"initializations": ["tests/vars/function_shadow_param.cc:1:14"],
|
||||
"variable_type": 0
|
||||
"initializations": ["tests/vars/function_shadow_param.cc:1:14"]
|
||||
}, {
|
||||
"id": 1,
|
||||
"usr": "c:function_shadow_param.cc@21@F@foo#I#@p",
|
||||
"short_name": "p",
|
||||
"qualified_name": "p",
|
||||
"declaration": "tests/vars/function_shadow_param.cc:2:7",
|
||||
"initializations": ["tests/vars/function_shadow_param.cc:2:7"],
|
||||
"variable_type": 0
|
||||
"initializations": ["tests/vars/function_shadow_param.cc:2:7"]
|
||||
}]
|
||||
}
|
||||
*/
|
@ -2,9 +2,7 @@ static int global = 0;
|
||||
/*
|
||||
OUTPUT:
|
||||
{
|
||||
"types": [{
|
||||
"id": 0
|
||||
}],
|
||||
"types": [],
|
||||
"functions": [],
|
||||
"variables": [{
|
||||
"id": 0,
|
||||
@ -12,8 +10,7 @@ OUTPUT:
|
||||
"short_name": "global",
|
||||
"qualified_name": "global",
|
||||
"declaration": "tests/vars/global_variable.cc:1:12",
|
||||
"initializations": ["tests/vars/global_variable.cc:1:12"],
|
||||
"variable_type": 0
|
||||
"initializations": ["tests/vars/global_variable.cc:1:12"]
|
||||
}]
|
||||
}
|
||||
*/
|
Loading…
Reference in New Issue
Block a user