all-tests-passing

This commit is contained in:
Jacob Dufault 2017-02-18 16:53:31 -08:00
parent a8cdadc201
commit e54d70e464
22 changed files with 89 additions and 29 deletions

View File

@ -19,10 +19,24 @@ std::string Type::get_usr() const {
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 {
return ToString(clang_getTypeSpelling(cx_type));
}
SourceLocation Cursor::get_source_location() const {
return SourceLocation(clang_getCursorLocation(cx_cursor));
}
Type Type::get_return_type() const {
return Type(clang_getResultType(cx_type));
}
@ -64,10 +78,6 @@ Type Cursor::get_type() const {
return Type(clang_getCursorType(cx_cursor));
}
SourceLocation Cursor::get_source_location() const {
return SourceLocation(clang_getCursorLocation(cx_cursor));
}
/*
SourceRange Cursor::get_source_range() const {
return SourceRange(clang_getCursorExtent(cx_cursor));

View File

@ -21,6 +21,10 @@ public:
std::string get_usr() 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;
std::vector<Type> get_arguments() const;

View File

@ -84,7 +84,9 @@ struct TypeDef {
// Usages.
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 {
@ -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) {
@ -549,6 +556,11 @@ void HandleVarDecl(ParsingDatabase* db, NamespaceStack* ns, clang::Cursor var, s
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.
if (!var.is_definition()) {
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
// 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().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) {
for (std::string path : GetFilesInFolder("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.
std::string expected_output;

View File

@ -13,7 +13,8 @@ void user() {
OUTPUT:
{
"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": [{
"id": 0,

View File

@ -18,7 +18,8 @@ OUTPUT:
"definition": "tests/usage/func_usage_addr_method.cc:1:8",
"funcs": [0]
}, {
"id": 1
"id": 1,
"uses": ["tests/usage/func_usage_addr_method.cc:6:8"]
}],
"functions": [{
"id": 0,

View File

@ -16,9 +16,8 @@ OUTPUT:
"short_name": "Foo",
"qualified_name": "Foo",
"definition": "tests/usage/func_usage_call_method.cc:1:8",
"funcs": [0]
}, {
"id": 1
"funcs": [0],
"uses": ["tests/usage/func_usage_call_method.cc:6:8"]
}],
"functions": [{
"id": 0,
@ -44,7 +43,7 @@ OUTPUT:
"qualified_name": "f",
"declaration": "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
}]
}
*/

View File

@ -20,7 +20,8 @@ OUTPUT:
"definition": "tests/usage/func_usage_class_inline_var_def.cc:5:7",
"vars": [0]
}, {
"id": 1
"id": 1,
"uses": ["tests/usage/func_usage_class_inline_var_def.cc:6:7"]
}],
"functions": [{
"id": 0,

View File

@ -15,9 +15,8 @@ OUTPUT:
"short_name": "Foo",
"qualified_name": "Foo",
"definition": "tests/usage/func_usage_forward_decl_method.cc:1:8",
"funcs": [0]
}, {
"id": 1
"funcs": [0],
"uses": ["tests/usage/func_usage_forward_decl_method.cc:6:8"]
}],
"functions": [{
"id": 0,
@ -43,7 +42,7 @@ OUTPUT:
"qualified_name": "f",
"declaration": "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
}]
}
*/

View File

@ -0,0 +1,8 @@
/*
OUTPUT:
{
"types": [],
"functions": [],
"variables": []
}
*/

View File

@ -9,7 +9,8 @@ OUTPUT:
"usr": "c:@S@T",
"short_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": [],
"variables": [{

View File

@ -0,0 +1,8 @@
/*
OUTPUT:
{
"types": [],
"functions": [],
"variables": []
}
*/

View File

@ -1,4 +1,6 @@
/*
// TODO: Idea with this test is to verify we will capture std::unique_ptr<T>
OUTPUT:
{
"types": [],

View File

@ -12,7 +12,8 @@ OUTPUT:
"definition": "tests/vars/class_member.cc:1:7",
"vars": [0]
}, {
"id": 1
"id": 1,
"uses": ["tests/vars/class_member.cc:2:7"]
}],
"functions": [],
"variables": [{

View File

@ -13,7 +13,8 @@ OUTPUT:
"definition": "tests/vars/class_static_member.cc:1:7",
"vars": [0]
}, {
"id": 1
"id": 1,
"uses": ["tests/vars/class_static_member.cc:2:14", "tests/vars/class_static_member.cc:4:10"]
}],
"functions": [],
"variables": [{

View File

@ -11,6 +11,9 @@ OUTPUT:
"qualified_name": "Foo",
"definition": "tests/vars/class_static_member_decl_only.cc:1:7",
"vars": [0]
}, {
"id": 1,
"uses": ["tests/vars/class_static_member_decl_only.cc:2:14"]
}],
"functions": [],
"variables": [{

View File

@ -5,7 +5,8 @@ void foo() {
OUTPUT:
{
"types": [{
"id": 0
"id": 0,
"uses": ["tests/vars/function_local.cc:2:7"]
}],
"functions": [{
"id": 0,

View File

@ -3,7 +3,8 @@ void foo(int p0, int p1) {}
OUTPUT:
{
"types": [{
"id": 0
"id": 0,
"uses": ["tests/vars/function_param.cc:1:14", "tests/vars/function_param.cc:1:22"]
}],
"functions": [{
"id": 0,

View File

@ -8,7 +8,8 @@ void foo(int, int) {}
OUTPUT:
{
"types": [{
"id": 0
"id": 0,
"uses": ["tests/vars/function_param_unnamed.cc:1:13", "tests/vars/function_param_unnamed.cc:1:18"]
}],
"functions": [{
"id": 0,

View File

@ -8,7 +8,8 @@ void foo() {
OUTPUT:
{
"types": [{
"id": 0
"id": 0,
"uses": ["tests/vars/function_shadow_local.cc:2:7", "tests/vars/function_shadow_local.cc:4:9"]
}],
"functions": [{
"id": 0,

View File

@ -5,7 +5,8 @@ void foo(int p) {
OUTPUT:
{
"types": [{
"id": 0
"id": 0,
"uses": ["tests/vars/function_shadow_param.cc:1:14", "tests/vars/function_shadow_param.cc:2:7"]
}],
"functions": [{
"id": 0,

View File

@ -3,7 +3,8 @@ static int global = 0;
OUTPUT:
{
"types": [{
"id": 0
"id": 0,
"uses": ["tests/vars/global_variable.cc:1:12"]
}],
"functions": [],
"variables": [{

View File

@ -2,7 +2,10 @@ extern int global;
/*
OUTPUT:
{
"types": [],
"types": [{
"id": 0,
"uses": ["tests/vars/global_variable_decl_only.cc:1:12"]
}],
"functions": [],
"variables": [{
"id": 0,