2017-11-11 19:31:05 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-02-11 22:08:05 +00:00
|
|
|
#include "nt_string.h"
|
2018-02-22 07:34:32 +00:00
|
|
|
#include "position.h"
|
2018-01-01 07:27:33 +00:00
|
|
|
|
2017-11-11 19:31:05 +00:00
|
|
|
#include <clang-c/Index.h>
|
2018-03-31 03:16:33 +00:00
|
|
|
#include <optional>
|
2017-11-11 19:31:05 +00:00
|
|
|
|
2018-01-13 06:13:08 +00:00
|
|
|
#include <array>
|
2017-11-11 19:31:05 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2018-01-13 08:10:39 +00:00
|
|
|
using Usr = uint64_t;
|
2018-01-13 06:13:08 +00:00
|
|
|
|
2018-01-01 07:56:35 +00:00
|
|
|
Range ResolveCXSourceRange(const CXSourceRange& range,
|
|
|
|
CXFile* cx_file = nullptr);
|
|
|
|
|
2018-01-21 06:55:29 +00:00
|
|
|
class ClangCursor;
|
|
|
|
|
2017-11-11 19:31:05 +00:00
|
|
|
class ClangType {
|
|
|
|
public:
|
2018-04-08 04:24:21 +00:00
|
|
|
ClangType() = default;
|
|
|
|
ClangType(const CXType& cx) : cx_type(cx) {}
|
2017-11-11 19:31:05 +00:00
|
|
|
|
|
|
|
// Returns true if this is a fundamental type like int.
|
2018-02-27 01:23:45 +00:00
|
|
|
bool is_builtin() const {
|
|
|
|
// NOTE: This will return false for pointed types. Should we call
|
|
|
|
// strip_qualifiers for the user?
|
|
|
|
return cx_type.kind >= CXType_FirstBuiltin &&
|
2018-03-20 02:51:42 +00:00
|
|
|
cx_type.kind <= CXType_LastBuiltin;
|
2018-02-27 01:23:45 +00:00
|
|
|
}
|
2017-11-11 19:31:05 +00:00
|
|
|
|
2018-01-21 06:55:29 +00:00
|
|
|
ClangCursor get_declaration() const;
|
2017-11-11 19:31:05 +00:00
|
|
|
std::string get_usr() const;
|
2018-01-13 08:10:39 +00:00
|
|
|
Usr get_usr_hash() const;
|
2018-02-18 18:07:13 +00:00
|
|
|
std::string get_spell_name() const;
|
2017-11-11 19:31:05 +00:00
|
|
|
ClangType get_canonical() const;
|
|
|
|
|
|
|
|
// Try to resolve this type and remove qualifies, ie, Foo* will become Foo
|
|
|
|
ClangType strip_qualifiers() const;
|
|
|
|
|
|
|
|
ClangType get_return_type() const;
|
|
|
|
std::vector<ClangType> get_arguments() const;
|
|
|
|
std::vector<ClangType> get_template_arguments() const;
|
|
|
|
|
|
|
|
CXType cx_type;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ClangCursor {
|
|
|
|
public:
|
2018-04-08 04:24:21 +00:00
|
|
|
ClangCursor() = default;
|
|
|
|
ClangCursor(CXCursor cx) : cx_cursor(cx) {}
|
|
|
|
bool operator==(const ClangCursor& o) const {
|
|
|
|
return clang_equalCursors(cx_cursor, o.cx_cursor);
|
|
|
|
}
|
|
|
|
bool operator!=(const ClangCursor& o) const {
|
|
|
|
return !(*this == o);
|
|
|
|
}
|
2017-11-11 19:31:05 +00:00
|
|
|
|
2018-04-08 04:24:21 +00:00
|
|
|
CXCursorKind get_kind() const {
|
|
|
|
return cx_cursor.kind;
|
|
|
|
}
|
2017-11-11 19:31:05 +00:00
|
|
|
ClangType get_type() const;
|
2018-02-18 18:07:13 +00:00
|
|
|
std::string get_spell_name() const;
|
|
|
|
Range get_spell(CXFile* cx_file = nullptr) const;
|
2018-01-01 07:56:35 +00:00
|
|
|
Range get_extent() const;
|
2017-11-11 19:31:05 +00:00
|
|
|
std::string get_display_name() const;
|
|
|
|
std::string get_usr() const;
|
2018-01-13 08:10:39 +00:00
|
|
|
Usr get_usr_hash() const;
|
2018-05-09 05:01:58 +00:00
|
|
|
std::optional<Usr> get_opt_usr_hash() const;
|
2017-11-11 19:31:05 +00:00
|
|
|
|
|
|
|
bool is_definition() const;
|
|
|
|
|
|
|
|
// If the given cursor points to a template specialization, this
|
|
|
|
// will return the cursor pointing to the template definition.
|
|
|
|
// If the given cursor is not a template specialization, this will
|
|
|
|
// just return the same cursor.
|
|
|
|
//
|
|
|
|
// This means it is always safe to call this method.
|
|
|
|
ClangCursor template_specialization_to_template_definition() const;
|
|
|
|
|
|
|
|
ClangCursor get_referenced() const;
|
|
|
|
ClangCursor get_canonical() const;
|
|
|
|
ClangCursor get_definition() const;
|
2018-02-10 20:53:18 +00:00
|
|
|
ClangCursor get_lexical_parent() const;
|
2017-11-11 19:31:05 +00:00
|
|
|
ClangCursor get_semantic_parent() const;
|
|
|
|
std::vector<ClangCursor> get_arguments() const;
|
|
|
|
bool is_valid_kind() const;
|
|
|
|
|
|
|
|
std::string get_type_description() const;
|
2018-02-11 22:08:05 +00:00
|
|
|
NtString get_comments() const;
|
2017-11-11 19:31:05 +00:00
|
|
|
|
|
|
|
std::string ToString() const;
|
|
|
|
|
|
|
|
enum class VisitResult { Break, Continue, Recurse };
|
|
|
|
|
|
|
|
template <typename TClientData>
|
|
|
|
using Visitor = VisitResult (*)(ClangCursor cursor,
|
|
|
|
ClangCursor parent,
|
|
|
|
TClientData* client_data);
|
|
|
|
|
|
|
|
template <typename TClientData>
|
|
|
|
void VisitChildren(Visitor<TClientData> visitor,
|
|
|
|
TClientData* client_data) const {
|
|
|
|
clang_visitChildren(cx_cursor, reinterpret_cast<CXCursorVisitor>(visitor),
|
|
|
|
client_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
CXCursor cx_cursor;
|
|
|
|
};
|
2017-12-21 03:52:34 +00:00
|
|
|
|
2018-03-31 05:05:21 +00:00
|
|
|
// Simple RAII wrapper about CXIndex.
|
|
|
|
// Note: building a ClangIndex instance acquires a global lock, since libclang
|
|
|
|
// API does not appear to be thread-safe here.
|
|
|
|
class ClangIndex {
|
|
|
|
public:
|
|
|
|
ClangIndex();
|
|
|
|
ClangIndex(int exclude_declarations_from_pch, int display_diagnostics);
|
|
|
|
~ClangIndex();
|
|
|
|
CXIndex cx_index;
|
|
|
|
};
|