Add support for type definitions in using/alias
This commit is contained in:
parent
c87b296d4e
commit
a635f5dd05
5 changed files with 85 additions and 11 deletions
|
|
@ -31,11 +31,17 @@ std::unique_ptr<cpp_expression> detail::parse_expression(const detail::parse_con
|
|||
|
||||
auto type = parse_type(context, clang_getCursorType(cur));
|
||||
auto expr = get_expression_str(stream);
|
||||
|
||||
if (kind == CXCursor_CharacterLiteral || kind == CXCursor_CompoundLiteralExpr
|
||||
|| kind == CXCursor_FloatingLiteral || kind == CXCursor_ImaginaryLiteral
|
||||
|| kind == CXCursor_IntegerLiteral || kind == CXCursor_StringLiteral
|
||||
|| kind == CXCursor_CXXBoolLiteralExpr || kind == CXCursor_CXXNullPtrLiteralExpr)
|
||||
if (kind == CXCursor_CallExpr && (expr.empty() || expr.back() != ')'))
|
||||
{
|
||||
// we have a call expression that doesn't end in a closing parentheses
|
||||
// this means default constructor, don't parse it at all
|
||||
// so, for example a variable doesn't have a default value
|
||||
return nullptr;
|
||||
}
|
||||
else if (kind == CXCursor_CharacterLiteral || kind == CXCursor_CompoundLiteralExpr
|
||||
|| kind == CXCursor_FloatingLiteral || kind == CXCursor_ImaginaryLiteral
|
||||
|| kind == CXCursor_IntegerLiteral || kind == CXCursor_StringLiteral
|
||||
|| kind == CXCursor_CXXBoolLiteralExpr || kind == CXCursor_CXXNullPtrLiteralExpr)
|
||||
return cpp_literal_expression::build(std::move(type), std::move(expr));
|
||||
else
|
||||
return cpp_unexposed_expression::build(std::move(type), std::move(expr));
|
||||
|
|
|
|||
|
|
@ -164,6 +164,12 @@ namespace
|
|||
auto suffix = suffix_cv(spelling);
|
||||
auto cv = merge_cv(prefix, suffix);
|
||||
|
||||
// remove struct/class/union prefix on inline type definition
|
||||
// i.e. C's typedef struct idiom
|
||||
remove_prefix(spelling, "struct");
|
||||
remove_prefix(spelling, "class");
|
||||
remove_prefix(spelling, "union");
|
||||
|
||||
auto entity = b(std::move(spelling));
|
||||
return make_cv_qualified(std::move(entity), cv);
|
||||
}
|
||||
|
|
@ -347,6 +353,8 @@ namespace
|
|||
case CXType_Elaborated:
|
||||
return make_leave_type(type, [&](std::string&& spelling) {
|
||||
auto decl = clang_getTypeDeclaration(type);
|
||||
if (remove_prefix(spelling, "(anonymous"))
|
||||
spelling = ""; // anonymous type
|
||||
return cpp_user_defined_type::build(
|
||||
cpp_type_ref(detail::get_entity_id(decl), std::move(spelling)));
|
||||
});
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ namespace
|
|||
{
|
||||
std::unique_ptr<cpp_expression> expression;
|
||||
detail::visit_children(cur, [&](const CXCursor& child) {
|
||||
if (clang_isDeclaration(clang_getCursorKind(child)))
|
||||
return;
|
||||
DEBUG_ASSERT(clang_isExpression(child.kind) && !expression,
|
||||
detail::parse_error_handler{}, cur, "unexpected child cursor of variable");
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue