Skip to content

Commit

Permalink
clang-12
Browse files Browse the repository at this point in the history
  • Loading branch information
slavek-kucera committed Mar 25, 2022
1 parent 8820587 commit c322ed2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 31 deletions.
7 changes: 0 additions & 7 deletions parser_library/include/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ struct PARSER_LIBRARY_EXPORT completion_item
const lsp::completion_item_s& item_;
};

template class PARSER_LIBRARY_EXPORT sequence<completion_item, const lsp::completion_item_s*>;
using completion_list = sequence<completion_item, const lsp::completion_item_s*>;

enum class PARSER_LIBRARY_EXPORT document_symbol_kind
Expand Down Expand Up @@ -150,8 +149,6 @@ struct PARSER_LIBRARY_EXPORT document_symbol_item
const lsp::document_symbol_item_s& item_;
};

template class PARSER_LIBRARY_EXPORT sequence<document_symbol_item, const lsp::document_symbol_item_s*>;

struct PARSER_LIBRARY_EXPORT position_uri
{
explicit position_uri(const location& item);
Expand All @@ -162,7 +159,6 @@ struct PARSER_LIBRARY_EXPORT position_uri
const location& item_;
};

template class PARSER_LIBRARY_EXPORT sequence<position_uri, const location*>;
using position_uri_list = sequence<position_uri, const location*>;

struct PARSER_LIBRARY_EXPORT range_uri
Expand Down Expand Up @@ -330,7 +326,6 @@ struct PARSER_LIBRARY_EXPORT stack_frame
uint32_t id;
};

template class PARSER_LIBRARY_EXPORT sequence<stack_frame, const debugging::stack_frame*>;
using stack_frames_t = sequence<stack_frame, const debugging::stack_frame*>;

using frame_id_t = size_t;
Expand All @@ -353,7 +348,6 @@ struct PARSER_LIBRARY_EXPORT scope
source source_file;
};

template class PARSER_LIBRARY_EXPORT sequence<scope, const debugging::scope*>;
using scopes_t = sequence<scope, const debugging::scope*>;

struct PARSER_LIBRARY_EXPORT variable
Expand All @@ -366,7 +360,6 @@ struct PARSER_LIBRARY_EXPORT variable
set_type type;
};

template class PARSER_LIBRARY_EXPORT sequence<variable, const debugging::variable_store*>;
using variables_t = sequence<variable, const debugging::variable_store*>;

struct breakpoint
Expand Down
18 changes: 12 additions & 6 deletions parser_library/include/sequence.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ class continuous_storage
template<typename c_type, typename storage = void>
class sequence
{
friend PARSER_LIBRARY_EXPORT c_type sequence_item_get(const sequence*, size_t);

class counter
{
size_t size = 0;
Expand Down Expand Up @@ -145,15 +147,19 @@ class sequence
{}
explicit operator std::vector<c_type>() const { return std::vector<c_type>(begin(), end()); }

// needs to be specialized for every type unless the storage is trivial
[[nodiscard]] c_type item(size_t index) const;

[[nodiscard]] c_type item(size_t index) const noexcept requires(trivial_storage_sequence<storage>)
[[nodiscard]] c_type item(size_t index) const noexcept(trivial_storage_sequence<storage>)
{
return data()[index];
if constexpr (trivial_storage_sequence<storage>)
return data()[index];
else
return sequence_item_get(this, index);
}

[[nodiscard]] auto data() const noexcept requires(trivial_storage_sequence<storage>) { return stor_.data(); }
[[nodiscard]] auto data() const noexcept requires(trivial_storage_sequence<storage>)
{
if constexpr (trivial_storage_sequence<storage>) // clang-12 :(
return stor_.data();
}
[[nodiscard]] size_t size() const noexcept { return size_; }

[[nodiscard]] auto begin() const noexcept
Expand Down
31 changes: 13 additions & 18 deletions parser_library/src/protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ std::string_view completion_item::detail() const { return item_.detail; }
std::string_view completion_item::documentation() const { return item_.documentation; }
std::string_view completion_item::insert_text() const { return item_.insert_text; }

template<>
completion_item sequence<completion_item, const lsp::completion_item_s*>::item(size_t index) const
completion_item sequence_item_get(const sequence<completion_item, const lsp::completion_item_s*>* self, size_t index)
{
return completion_item(stor_[index]);
return completion_item(self->stor_[index]);
}

//********************** document symbol item **********************
Expand All @@ -56,10 +55,10 @@ document_symbol_list document_symbol_item::children() const
return document_symbol_list(item_.children.data(), item_.children.size());
}

template<>
document_symbol_item sequence<document_symbol_item, const lsp::document_symbol_item_s*>::item(size_t index) const
document_symbol_item sequence_item_get(
const sequence<document_symbol_item, const lsp::document_symbol_item_s*>* self, size_t index)
{
return document_symbol_item(stor_[index]);
return document_symbol_item(self->stor_[index]);
}
//********************** location **********************

Expand All @@ -69,10 +68,9 @@ position_uri::position_uri(const location& item)
position position_uri::pos() const { return item_.pos; }
std::string_view position_uri::file() const { return item_.file; }

template<>
position_uri sequence<position_uri, const location*>::item(size_t index) const
position_uri sequence_item_get(const sequence<position_uri, const location*>* self, size_t index)
{
return position_uri(stor_[index]);
return position_uri(self->stor_[index]);
}

diagnostic_related_info::diagnostic_related_info(diagnostic_related_info_s& info)
Expand Down Expand Up @@ -149,10 +147,9 @@ stack_frame::stack_frame(const debugging::stack_frame& frame)
, id(frame.id)
{}

template<>
stack_frame sequence<stack_frame, const debugging::stack_frame*>::item(size_t index) const
stack_frame sequence_item_get(const sequence<stack_frame, const debugging::stack_frame*>* self, size_t index)
{
return stack_frame(stor_[index]);
return stack_frame(self->stor_[index]);
}

//********************* source **********************
Expand All @@ -169,10 +166,9 @@ scope::scope(const debugging::scope& impl)
, source_file(impl.scope_source)
{}

template<>
scope sequence<scope, const debugging::scope*>::item(size_t index) const
scope sequence_item_get(const sequence<scope, const debugging::scope*>* self, size_t index)
{
return scope(stor_[index]);
return scope(self->stor_[index]);
}


Expand All @@ -185,10 +181,9 @@ variable::variable(const debugging::variable& impl)
, type(impl.type())
{}

template<>
variable sequence<variable, const debugging::variable_store*>::item(size_t index) const
variable sequence_item_get(const sequence<variable, const debugging::variable_store*>* self, size_t index)
{
return variable(*stor_->variables[index]);
return variable(*self->stor_->variables[index]);
}


Expand Down

0 comments on commit c322ed2

Please sign in to comment.