mirror of
https://github.com/MaskRay/ccls.git
synced 2025-01-31 18:00:26 +00:00
Make NTString nullable
This commit is contained in:
parent
68c5c317f0
commit
0f8734c416
@ -228,12 +228,12 @@ std::string ClangCursor::get_type_description() const {
|
|||||||
return ::ToString(clang_getTypeSpelling(type));
|
return ::ToString(clang_getTypeSpelling(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ClangCursor::get_comments() const {
|
NTString ClangCursor::get_comments() const {
|
||||||
if (!g_index_comments)
|
if (!g_index_comments)
|
||||||
return "";
|
return {};
|
||||||
CXSourceRange range = clang_Cursor_getCommentRange(cx_cursor);
|
CXSourceRange range = clang_Cursor_getCommentRange(cx_cursor);
|
||||||
if (clang_Range_isNull(range))
|
if (clang_Range_isNull(range))
|
||||||
return "";
|
return {};
|
||||||
|
|
||||||
unsigned start_column;
|
unsigned start_column;
|
||||||
clang_getSpellingLocation(clang_getRangeStart(range), nullptr, nullptr,
|
clang_getSpellingLocation(clang_getRangeStart(range), nullptr, nullptr,
|
||||||
@ -286,7 +286,9 @@ std::string ClangCursor::get_comments() const {
|
|||||||
}
|
}
|
||||||
while (ret.size() && isspace(ret.back()))
|
while (ret.size() && isspace(ret.back()))
|
||||||
ret.pop_back();
|
ret.pop_back();
|
||||||
return ret;
|
if (ret.empty())
|
||||||
|
return {};
|
||||||
|
return static_cast<std::string_view>(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ClangCursor::ToString() const {
|
std::string ClangCursor::ToString() const {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "position.h"
|
#include "position.h"
|
||||||
|
#include "ntstring.h"
|
||||||
|
|
||||||
#include <clang-c/Index.h>
|
#include <clang-c/Index.h>
|
||||||
#include <optional.h>
|
#include <optional.h>
|
||||||
@ -79,7 +80,7 @@ class ClangCursor {
|
|||||||
bool is_valid_kind() const;
|
bool is_valid_kind() const;
|
||||||
|
|
||||||
std::string get_type_description() const;
|
std::string get_type_description() const;
|
||||||
std::string get_comments() const;
|
NTString get_comments() const;
|
||||||
|
|
||||||
std::string ToString() const;
|
std::string ToString() const;
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ REGISTER_IPC_MESSAGE(Ipc_CqueryRandom);
|
|||||||
|
|
||||||
const double kDeclWeight = 3;
|
const double kDeclWeight = 3;
|
||||||
const double kDamping = 0.1;
|
const double kDamping = 0.1;
|
||||||
const double kAlpha = 0.3;
|
const double kAlpha = 2.80777024202851936522;
|
||||||
|
|
||||||
template <typename Q>
|
template <typename Q>
|
||||||
struct Kind;
|
struct Kind;
|
||||||
|
@ -9,32 +9,26 @@
|
|||||||
class Reader;
|
class Reader;
|
||||||
class Writer;
|
class Writer;
|
||||||
|
|
||||||
// Null-terminated string
|
// Nullable null-terminated string, which is null if default constructed,
|
||||||
|
// but non-null if assigned.
|
||||||
// This is used in Query{Func,Type,Var}::def to reduce memory footprint.
|
// This is used in Query{Func,Type,Var}::def to reduce memory footprint.
|
||||||
class NTString {
|
class NTString {
|
||||||
using size_type = std::string::size_type;
|
using size_type = std::string::size_type;
|
||||||
std::unique_ptr<char[]> str;
|
std::unique_ptr<char[]> str;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NTString() : str(new char[1]()) {}
|
NTString() = default;
|
||||||
NTString(const NTString& o) : str(new char[strlen(o.c_str()) + 1]) {
|
|
||||||
strcpy(str.get(), o.c_str());
|
|
||||||
}
|
|
||||||
NTString(NTString&& o) = default;
|
NTString(NTString&& o) = default;
|
||||||
NTString(std::string_view sv) {
|
NTString(const NTString& o) { *this = o; }
|
||||||
*this = sv;
|
NTString(std::string_view sv) { *this = sv; }
|
||||||
}
|
|
||||||
|
|
||||||
operator std::string_view() const { return str.get(); }
|
|
||||||
const char* c_str() const { return str.get(); }
|
const char* c_str() const { return str.get(); }
|
||||||
std::string_view substr(size_type pos, size_type cnt) const {
|
operator std::string_view() const {
|
||||||
return std::string_view(c_str() + pos, cnt);
|
if (c_str())
|
||||||
}
|
return c_str();
|
||||||
bool empty() const { return !str || str.get()[0] == '\0'; }
|
return {};
|
||||||
size_type find(const char* s) {
|
|
||||||
const char *p = strstr(c_str(), s);
|
|
||||||
return p ? std::string::size_type(p - c_str()) : std::string::npos;
|
|
||||||
}
|
}
|
||||||
|
bool empty() const { return !str || *c_str() == '\0'; }
|
||||||
|
|
||||||
void operator=(std::string_view sv) {
|
void operator=(std::string_view sv) {
|
||||||
str = std::unique_ptr<char[]>(new char[sv.size() + 1]);
|
str = std::unique_ptr<char[]>(new char[sv.size() + 1]);
|
||||||
@ -45,6 +39,7 @@ class NTString {
|
|||||||
*this = static_cast<std::string_view>(o);
|
*this = static_cast<std::string_view>(o);
|
||||||
}
|
}
|
||||||
bool operator==(const NTString& o) const {
|
bool operator==(const NTString& o) const {
|
||||||
return strcmp(c_str(), o.c_str()) == 0;
|
return str && o.str ? strcmp(c_str(), o.c_str()) == 0
|
||||||
|
: c_str() == o.c_str();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
24
src/query.cc
24
src/query.cc
@ -40,8 +40,10 @@ optional<QueryType::Def> ToQuery(const IdMap& id_map,
|
|||||||
result.short_name_offset = type.short_name_offset;
|
result.short_name_offset = type.short_name_offset;
|
||||||
result.short_name_size = type.short_name_size;
|
result.short_name_size = type.short_name_size;
|
||||||
result.kind = type.kind;
|
result.kind = type.kind;
|
||||||
result.hover = type.hover;
|
if (!type.hover.empty())
|
||||||
result.comments = type.comments;
|
result.hover = type.hover;
|
||||||
|
if (!type.comments.empty())
|
||||||
|
result.comments = type.comments;
|
||||||
result.file = id_map.primary_file;
|
result.file = id_map.primary_file;
|
||||||
result.spell = id_map.ToQuery(type.spell);
|
result.spell = id_map.ToQuery(type.spell);
|
||||||
result.extent = id_map.ToQuery(type.extent);
|
result.extent = id_map.ToQuery(type.extent);
|
||||||
@ -64,8 +66,10 @@ optional<QueryFunc::Def> ToQuery(const IdMap& id_map,
|
|||||||
result.short_name_size = func.short_name_size;
|
result.short_name_size = func.short_name_size;
|
||||||
result.kind = func.kind;
|
result.kind = func.kind;
|
||||||
result.storage = func.storage;
|
result.storage = func.storage;
|
||||||
result.hover = func.hover;
|
if (!func.hover.empty())
|
||||||
result.comments = func.comments;
|
result.hover = func.hover;
|
||||||
|
if (!func.comments.empty())
|
||||||
|
result.comments = func.comments;
|
||||||
result.file = id_map.primary_file;
|
result.file = id_map.primary_file;
|
||||||
result.spell = id_map.ToQuery(func.spell);
|
result.spell = id_map.ToQuery(func.spell);
|
||||||
result.extent = id_map.ToQuery(func.extent);
|
result.extent = id_map.ToQuery(func.extent);
|
||||||
@ -84,13 +88,13 @@ optional<QueryVar::Def> ToQuery(const IdMap& id_map, const IndexVar::Def& var) {
|
|||||||
result.detailed_name = var.detailed_name;
|
result.detailed_name = var.detailed_name;
|
||||||
result.short_name_offset = var.short_name_offset;
|
result.short_name_offset = var.short_name_offset;
|
||||||
result.short_name_size = var.short_name_size;
|
result.short_name_size = var.short_name_size;
|
||||||
result.hover = var.hover;
|
if (!var.hover.empty())
|
||||||
result.comments = var.comments;
|
result.hover = var.hover;
|
||||||
|
if (!var.comments.empty())
|
||||||
|
result.comments = var.comments;
|
||||||
result.file = id_map.primary_file;
|
result.file = id_map.primary_file;
|
||||||
if (var.spell)
|
result.spell = id_map.ToQuery(var.spell);
|
||||||
result.spell = id_map.ToQuery(*var.spell);
|
result.extent = id_map.ToQuery(var.extent);
|
||||||
if (var.extent)
|
|
||||||
result.extent = id_map.ToQuery(*var.extent);
|
|
||||||
result.variable_type = id_map.ToQuery(var.variable_type);
|
result.variable_type = id_map.ToQuery(var.variable_type);
|
||||||
if (result.parent_id)
|
if (result.parent_id)
|
||||||
switch (var.parent_kind) {
|
switch (var.parent_kind) {
|
||||||
|
Loading…
Reference in New Issue
Block a user