Update clang-format
This commit is contained in:
parent
c755a885bf
commit
9f18b7f4d8
89 changed files with 11377 additions and 11546 deletions
|
|
@ -4,80 +4,77 @@
|
|||
|
||||
#include <cppast/cpp_enum.hpp>
|
||||
|
||||
#include "parse_functions.hpp"
|
||||
#include "libclang_visitor.hpp"
|
||||
#include "parse_functions.hpp"
|
||||
|
||||
using namespace cppast;
|
||||
|
||||
namespace
|
||||
{
|
||||
std::unique_ptr<cpp_enum_value> parse_enum_value(const detail::parse_context& context,
|
||||
const CXCursor& cur)
|
||||
std::unique_ptr<cpp_enum_value> parse_enum_value(const detail::parse_context& context,
|
||||
const CXCursor& cur)
|
||||
{
|
||||
if (clang_isAttribute(clang_getCursorKind(cur)))
|
||||
return nullptr;
|
||||
|
||||
DEBUG_ASSERT(cur.kind == CXCursor_EnumConstantDecl, detail::parse_error_handler{}, cur,
|
||||
"unexpected child cursor of enum");
|
||||
|
||||
detail::cxtokenizer tokenizer(context.tu, context.file, cur);
|
||||
detail::cxtoken_stream stream(tokenizer, cur);
|
||||
|
||||
// <identifier> [<attribute>],
|
||||
// or: <identifier> [<attribute>] = <expression>,
|
||||
auto& name = stream.get().value();
|
||||
auto attributes = detail::parse_attributes(stream);
|
||||
|
||||
std::unique_ptr<cpp_expression> value;
|
||||
if (detail::skip_if(stream, "="))
|
||||
{
|
||||
if (clang_isAttribute(clang_getCursorKind(cur)))
|
||||
return nullptr;
|
||||
detail::visit_children(cur, [&](const CXCursor& child) {
|
||||
DEBUG_ASSERT(clang_isExpression(child.kind) && !value, detail::parse_error_handler{},
|
||||
cur, "unexpected child cursor of enum value");
|
||||
|
||||
DEBUG_ASSERT(cur.kind == CXCursor_EnumConstantDecl, detail::parse_error_handler{}, cur,
|
||||
"unexpected child cursor of enum");
|
||||
|
||||
detail::cxtokenizer tokenizer(context.tu, context.file, cur);
|
||||
detail::cxtoken_stream stream(tokenizer, cur);
|
||||
|
||||
// <identifier> [<attribute>],
|
||||
// or: <identifier> [<attribute>] = <expression>,
|
||||
auto& name = stream.get().value();
|
||||
auto attributes = detail::parse_attributes(stream);
|
||||
|
||||
std::unique_ptr<cpp_expression> value;
|
||||
if (detail::skip_if(stream, "="))
|
||||
{
|
||||
detail::visit_children(cur, [&](const CXCursor& child) {
|
||||
DEBUG_ASSERT(clang_isExpression(child.kind) && !value,
|
||||
detail::parse_error_handler{}, cur,
|
||||
"unexpected child cursor of enum value");
|
||||
|
||||
value = detail::parse_expression(context, child);
|
||||
});
|
||||
}
|
||||
|
||||
auto result = cpp_enum_value::build(*context.idx, detail::get_entity_id(cur), name.c_str(),
|
||||
std::move(value));
|
||||
result->add_attribute(attributes);
|
||||
return result;
|
||||
value = detail::parse_expression(context, child);
|
||||
});
|
||||
}
|
||||
|
||||
cpp_enum::builder make_enum_builder(const detail::parse_context& context, const CXCursor& cur,
|
||||
type_safe::optional<cpp_entity_ref>& semantic_parent)
|
||||
{
|
||||
auto name = detail::get_cursor_name(cur);
|
||||
detail::cxtokenizer tokenizer(context.tu, context.file, cur);
|
||||
detail::cxtoken_stream stream(tokenizer, cur);
|
||||
|
||||
// enum [class/struct] [<attribute>] name [: type] {
|
||||
detail::skip(stream, "enum");
|
||||
auto scoped = detail::skip_if(stream, "class") || detail::skip_if(stream, "struct");
|
||||
auto attributes = detail::parse_attributes(stream);
|
||||
|
||||
std::string scope;
|
||||
while (!detail::skip_if(stream, name.c_str()))
|
||||
if (!detail::append_scope(stream, scope))
|
||||
DEBUG_UNREACHABLE(detail::parse_error_handler{}, cur,
|
||||
"unexpected tokens in enum name");
|
||||
if (!scope.empty())
|
||||
semantic_parent =
|
||||
cpp_entity_ref(detail::get_entity_id(clang_getCursorSemanticParent(cur)),
|
||||
std::move(scope));
|
||||
|
||||
// parse type
|
||||
auto type = detail::parse_type(context, cur, clang_getEnumDeclIntegerType(cur));
|
||||
auto type_given = detail::skip_if(stream, ":");
|
||||
|
||||
auto result = cpp_enum::builder(name.c_str(), scoped, std::move(type), type_given);
|
||||
result.get().add_attribute(attributes);
|
||||
return result;
|
||||
}
|
||||
auto result = cpp_enum_value::build(*context.idx, detail::get_entity_id(cur), name.c_str(),
|
||||
std::move(value));
|
||||
result->add_attribute(attributes);
|
||||
return result;
|
||||
}
|
||||
|
||||
cpp_enum::builder make_enum_builder(const detail::parse_context& context, const CXCursor& cur,
|
||||
type_safe::optional<cpp_entity_ref>& semantic_parent)
|
||||
{
|
||||
auto name = detail::get_cursor_name(cur);
|
||||
detail::cxtokenizer tokenizer(context.tu, context.file, cur);
|
||||
detail::cxtoken_stream stream(tokenizer, cur);
|
||||
|
||||
// enum [class/struct] [<attribute>] name [: type] {
|
||||
detail::skip(stream, "enum");
|
||||
auto scoped = detail::skip_if(stream, "class") || detail::skip_if(stream, "struct");
|
||||
auto attributes = detail::parse_attributes(stream);
|
||||
|
||||
std::string scope;
|
||||
while (!detail::skip_if(stream, name.c_str()))
|
||||
if (!detail::append_scope(stream, scope))
|
||||
DEBUG_UNREACHABLE(detail::parse_error_handler{}, cur, "unexpected tokens in enum name");
|
||||
if (!scope.empty())
|
||||
semantic_parent = cpp_entity_ref(detail::get_entity_id(clang_getCursorSemanticParent(cur)),
|
||||
std::move(scope));
|
||||
|
||||
// parse type
|
||||
auto type = detail::parse_type(context, cur, clang_getEnumDeclIntegerType(cur));
|
||||
auto type_given = detail::skip_if(stream, ":");
|
||||
|
||||
auto result = cpp_enum::builder(name.c_str(), scoped, std::move(type), type_given);
|
||||
result.get().add_attribute(attributes);
|
||||
return result;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
std::unique_ptr<cpp_entity> detail::parse_cpp_enum(const detail::parse_context& context,
|
||||
const CXCursor& cur)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue