mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-25 00:55:08 +00:00
wip-linux-build
This commit is contained in:
parent
683cac602e
commit
358b4434c2
27
CMakeLists.txt
Normal file
27
CMakeLists.txt
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
cmake_minimum_required (VERSION 3.3.1)
|
||||||
|
|
||||||
|
project (SuperClangIndex)
|
||||||
|
|
||||||
|
set (CMAKE_CXX_STANDARD 11)
|
||||||
|
#set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
|
||||||
|
|
||||||
|
file (GLOB SOURCE_FILES *.cc *.cpp)
|
||||||
|
|
||||||
|
include_directories("${PROJECT_SOURCE_DIR}/third_party")
|
||||||
|
|
||||||
|
add_executable (indexer ${SOURCE_FILES})
|
||||||
|
|
||||||
|
find_program (llvm_config llvm-config)
|
||||||
|
|
||||||
|
set (llvm_param --libdir)
|
||||||
|
message (${llvm_config})
|
||||||
|
execute_process (
|
||||||
|
COMMAND ${llvm_config} ${llvm_param}
|
||||||
|
OUTPUT_VARIABLE libclang_libdir)
|
||||||
|
|
||||||
|
message ("Using libclang at " ${libclang_libdir})
|
||||||
|
|
||||||
|
#find_package (clang COMPONENTS REQUIRED libclang)
|
||||||
|
#ind_package (libclang REQUIRED)
|
||||||
|
#target_link_libraries (indexer ${libclang})
|
||||||
|
|
51
main.cpp
51
main.cpp
@ -1,5 +1,4 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <optional>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
@ -11,6 +10,7 @@
|
|||||||
|
|
||||||
#include "bitfield.h"
|
#include "bitfield.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "optional.h"
|
||||||
|
|
||||||
#include <rapidjson/writer.h>
|
#include <rapidjson/writer.h>
|
||||||
#include <rapidjson/prettywriter.h>
|
#include <rapidjson/prettywriter.h>
|
||||||
@ -22,6 +22,7 @@ struct FuncDef;
|
|||||||
struct VarDef;
|
struct VarDef;
|
||||||
|
|
||||||
using FileId = int64_t;
|
using FileId = int64_t;
|
||||||
|
using namespace std::experimental;
|
||||||
|
|
||||||
|
|
||||||
// TODO: Move off of this weird wrapper, use struct with custom wrappers
|
// TODO: Move off of this weird wrapper, use struct with custom wrappers
|
||||||
@ -182,11 +183,11 @@ struct TypeDef {
|
|||||||
// It's also difficult to identify a `class Foo;` statement with the clang
|
// It's also difficult to identify a `class Foo;` statement with the clang
|
||||||
// indexer API (it's doable using cursor AST traversal), so we don't bother
|
// indexer API (it's doable using cursor AST traversal), so we don't bother
|
||||||
// supporting the feature.
|
// supporting the feature.
|
||||||
std::optional<Location> definition;
|
optional<Location> definition;
|
||||||
|
|
||||||
// If set, then this is the same underlying type as the given value (ie, this
|
// If set, then this is the same underlying type as the given value (ie, this
|
||||||
// type comes from a using or typedef statement).
|
// type comes from a using or typedef statement).
|
||||||
std::optional<TypeId> alias_of;
|
optional<TypeId> alias_of;
|
||||||
|
|
||||||
// Immediate parent and immediate derived types.
|
// Immediate parent and immediate derived types.
|
||||||
std::vector<TypeId> parents;
|
std::vector<TypeId> parents;
|
||||||
@ -231,13 +232,13 @@ struct FuncDef {
|
|||||||
std::string usr;
|
std::string usr;
|
||||||
std::string short_name;
|
std::string short_name;
|
||||||
std::string qualified_name;
|
std::string qualified_name;
|
||||||
std::optional<Location> declaration;
|
optional<Location> declaration;
|
||||||
std::optional<Location> definition;
|
optional<Location> definition;
|
||||||
|
|
||||||
// Type which declares this one (ie, it is a method)
|
// Type which declares this one (ie, it is a method)
|
||||||
std::optional<TypeId> declaring_type;
|
optional<TypeId> declaring_type;
|
||||||
// Method this method overrides.
|
// Method this method overrides.
|
||||||
std::optional<FuncId> base;
|
optional<FuncId> base;
|
||||||
// Methods which directly override this one.
|
// Methods which directly override this one.
|
||||||
std::vector<FuncId> derived;
|
std::vector<FuncId> derived;
|
||||||
|
|
||||||
@ -270,16 +271,16 @@ struct VarDef {
|
|||||||
std::string usr;
|
std::string usr;
|
||||||
std::string short_name;
|
std::string short_name;
|
||||||
std::string qualified_name;
|
std::string qualified_name;
|
||||||
std::optional<Location> declaration;
|
optional<Location> declaration;
|
||||||
// TODO: definitions should be a list of locations, since there can be more
|
// TODO: definitions should be a list of locations, since there can be more
|
||||||
// than one.
|
// than one.
|
||||||
std::optional<Location> definition;
|
optional<Location> definition;
|
||||||
|
|
||||||
// Type of the variable.
|
// Type of the variable.
|
||||||
std::optional<TypeId> variable_type;
|
optional<TypeId> variable_type;
|
||||||
|
|
||||||
// Type which declares this one (ie, it is a method)
|
// Type which declares this one (ie, it is a method)
|
||||||
std::optional<TypeId> declaring_type;
|
optional<TypeId> declaring_type;
|
||||||
|
|
||||||
// Usages.
|
// Usages.
|
||||||
std::vector<Location> uses;
|
std::vector<Location> uses;
|
||||||
@ -385,7 +386,7 @@ void Write(Writer& writer, const char* key, Location location) {
|
|||||||
writer.String(s.c_str());
|
writer.String(s.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Write(Writer& writer, const char* key, std::optional<Location> location) {
|
void Write(Writer& writer, const char* key, optional<Location> location) {
|
||||||
if (location) {
|
if (location) {
|
||||||
Write(writer, key, location.value());
|
Write(writer, key, location.value());
|
||||||
}
|
}
|
||||||
@ -413,7 +414,7 @@ void Write(Writer& writer, const char* key, LocalId<T> id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void Write(Writer& writer, const char* key, std::optional<LocalId<T>> id) {
|
void Write(Writer& writer, const char* key, optional<LocalId<T>> id) {
|
||||||
if (id) {
|
if (id) {
|
||||||
Write(writer, key, id.value());
|
Write(writer, key, id.value());
|
||||||
}
|
}
|
||||||
@ -640,7 +641,7 @@ void Dump(clang::Cursor cursor) {
|
|||||||
|
|
||||||
struct FindChildOfKindParam {
|
struct FindChildOfKindParam {
|
||||||
CXCursorKind target_kind;
|
CXCursorKind target_kind;
|
||||||
std::optional<clang::Cursor> result;
|
optional<clang::Cursor> result;
|
||||||
|
|
||||||
FindChildOfKindParam(CXCursorKind target_kind) : target_kind(target_kind) {}
|
FindChildOfKindParam(CXCursorKind target_kind) : target_kind(target_kind) {}
|
||||||
};
|
};
|
||||||
@ -654,7 +655,7 @@ clang::VisiterResult FindChildOfKindVisitor(clang::Cursor cursor, clang::Cursor
|
|||||||
return clang::VisiterResult::Recurse;
|
return clang::VisiterResult::Recurse;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<clang::Cursor> FindChildOfKind(clang::Cursor cursor, CXCursorKind kind) {
|
optional<clang::Cursor> FindChildOfKind(clang::Cursor cursor, CXCursorKind kind) {
|
||||||
FindChildOfKindParam param(kind);
|
FindChildOfKindParam param(kind);
|
||||||
cursor.VisitChildren(&FindChildOfKindVisitor, ¶m);
|
cursor.VisitChildren(&FindChildOfKindVisitor, ¶m);
|
||||||
return param.result;
|
return param.result;
|
||||||
@ -664,7 +665,7 @@ std::optional<clang::Cursor> FindChildOfKind(clang::Cursor cursor, CXCursorKind
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
clang::VisiterResult FindTypeVisitor(clang::Cursor cursor, clang::Cursor parent, std::optional<clang::Cursor>* result) {
|
clang::VisiterResult FindTypeVisitor(clang::Cursor cursor, clang::Cursor parent, optional<clang::Cursor>* result) {
|
||||||
switch (cursor.get_kind()) {
|
switch (cursor.get_kind()) {
|
||||||
case CXCursor_TypeRef:
|
case CXCursor_TypeRef:
|
||||||
case CXCursor_TemplateRef:
|
case CXCursor_TemplateRef:
|
||||||
@ -675,8 +676,8 @@ clang::VisiterResult FindTypeVisitor(clang::Cursor cursor, clang::Cursor parent,
|
|||||||
return clang::VisiterResult::Recurse;
|
return clang::VisiterResult::Recurse;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<clang::Cursor> FindType(clang::Cursor cursor) {
|
optional<clang::Cursor> FindType(clang::Cursor cursor) {
|
||||||
std::optional<clang::Cursor> result;
|
optional<clang::Cursor> result;
|
||||||
cursor.VisitChildren(&FindTypeVisitor, &result);
|
cursor.VisitChildren(&FindTypeVisitor, &result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -765,8 +766,8 @@ struct VisitDeclForTypeUsageParam {
|
|||||||
ParsingDatabase* db;
|
ParsingDatabase* db;
|
||||||
bool is_interesting;
|
bool is_interesting;
|
||||||
int has_processed_any = false;
|
int has_processed_any = false;
|
||||||
std::optional<clang::Cursor> previous_cursor;
|
optional<clang::Cursor> previous_cursor;
|
||||||
std::optional<TypeId> initial_type;
|
optional<TypeId> initial_type;
|
||||||
|
|
||||||
VisitDeclForTypeUsageParam(ParsingDatabase* db, bool is_interesting)
|
VisitDeclForTypeUsageParam(ParsingDatabase* db, bool is_interesting)
|
||||||
: db(db), is_interesting(is_interesting) {}
|
: db(db), is_interesting(is_interesting) {}
|
||||||
@ -815,7 +816,7 @@ clang::VisiterResult VisitDeclForTypeUsageVisitor(clang::Cursor cursor, clang::C
|
|||||||
return clang::VisiterResult::Continue;
|
return clang::VisiterResult::Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<TypeId> ResolveDeclToType(ParsingDatabase* db, clang::Cursor decl_cursor,
|
optional<TypeId> ResolveDeclToType(ParsingDatabase* db, clang::Cursor decl_cursor,
|
||||||
bool is_interesting, const CXIdxContainerInfo* semantic_container,
|
bool is_interesting, const CXIdxContainerInfo* semantic_container,
|
||||||
const CXIdxContainerInfo* lexical_container) {
|
const CXIdxContainerInfo* lexical_container) {
|
||||||
//
|
//
|
||||||
@ -922,7 +923,7 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
|||||||
// interesting reference for parameter declarations - that is handled when
|
// interesting reference for parameter declarations - that is handled when
|
||||||
// the function declaration is encountered since we won't receive ParmDecl
|
// the function declaration is encountered since we won't receive ParmDecl
|
||||||
// declarations for unnamed parameters.
|
// declarations for unnamed parameters.
|
||||||
std::optional<TypeId> var_type = ResolveDeclToType(db, decl_cursor, decl_cursor.get_kind() != CXCursor_ParmDecl /*is_interesting*/, decl->semanticContainer, decl->lexicalContainer);
|
optional<TypeId> var_type = ResolveDeclToType(db, decl_cursor, decl_cursor.get_kind() != CXCursor_ParmDecl /*is_interesting*/, decl->semanticContainer, decl->lexicalContainer);
|
||||||
if (var_type.has_value())
|
if (var_type.has_value())
|
||||||
var_def->variable_type = var_type.value();
|
var_def->variable_type = var_type.value();
|
||||||
|
|
||||||
@ -1047,7 +1048,7 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
std::optional<FuncId> base;
|
optional<FuncId> base;
|
||||||
std::vector<FuncId> derived;
|
std::vector<FuncId> derived;
|
||||||
std::vector<VarId> locals;
|
std::vector<VarId> locals;
|
||||||
std::vector<FuncRef> callers;
|
std::vector<FuncRef> callers;
|
||||||
@ -1060,7 +1061,7 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
|||||||
case CXIdxEntity_Typedef:
|
case CXIdxEntity_Typedef:
|
||||||
case CXIdxEntity_CXXTypeAlias:
|
case CXIdxEntity_CXXTypeAlias:
|
||||||
{
|
{
|
||||||
std::optional<TypeId> alias_of = ResolveDeclToType(db, decl->cursor, true /*is_interesting*/, decl->semanticContainer, decl->lexicalContainer);
|
optional<TypeId> alias_of = ResolveDeclToType(db, decl->cursor, true /*is_interesting*/, decl->semanticContainer, decl->lexicalContainer);
|
||||||
|
|
||||||
TypeId type_id = db->ToTypeId(decl->entityInfo->USR);
|
TypeId type_id = db->ToTypeId(decl->entityInfo->USR);
|
||||||
TypeDef* type_def = db->Resolve(type_id);
|
TypeDef* type_def = db->Resolve(type_id);
|
||||||
@ -1123,7 +1124,7 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
|||||||
for (unsigned int i = 0; i < class_info->numBases; ++i) {
|
for (unsigned int i = 0; i < class_info->numBases; ++i) {
|
||||||
const CXIdxBaseClassInfo* base_class = class_info->bases[i];
|
const CXIdxBaseClassInfo* base_class = class_info->bases[i];
|
||||||
|
|
||||||
std::optional<TypeId> parent_type_id = ResolveDeclToType(db, base_class->cursor, true /*is_interesting*/, decl->semanticContainer, decl->lexicalContainer);
|
optional<TypeId> parent_type_id = ResolveDeclToType(db, base_class->cursor, true /*is_interesting*/, decl->semanticContainer, decl->lexicalContainer);
|
||||||
TypeDef* type_def = db->Resolve(type_id); // type_def ptr could be invalidated by ResolveDeclToType.
|
TypeDef* type_def = db->Resolve(type_id); // type_def ptr could be invalidated by ResolveDeclToType.
|
||||||
if (parent_type_id) {
|
if (parent_type_id) {
|
||||||
TypeDef* parent_type_def = db->Resolve(parent_type_id.value());
|
TypeDef* parent_type_def = db->Resolve(parent_type_id.value());
|
||||||
|
1052
optional.h
Normal file
1052
optional.h
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,10 +1,10 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <optional>
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "cxxopts.hpp"
|
#include "cxxopts.hpp"
|
||||||
|
#include "optional.h"
|
||||||
|
|
||||||
using FileId = uint64_t;
|
using FileId = uint64_t;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user