mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:07:34 +00:00
LibCpp: Parse inheritance
This commit is contained in:
parent
8cfabbcd93
commit
f4cca20972
8 changed files with 43 additions and 1 deletions
|
@ -333,6 +333,19 @@ void StructOrClassDeclaration::dump(FILE* output, size_t indent) const
|
|||
ASTNode::dump(output, indent);
|
||||
print_indent(output, indent);
|
||||
outln(output, "{}", full_name());
|
||||
if (!m_baseclasses.is_empty()) {
|
||||
print_indent(output, indent + 1);
|
||||
outln(output, ":");
|
||||
for (size_t i = 0; i < m_baseclasses.size(); ++i) {
|
||||
auto& baseclass = m_baseclasses[i];
|
||||
baseclass.dump(output, indent + 1);
|
||||
if (i < m_baseclasses.size() - 1) {
|
||||
print_indent(output, indent + 1);
|
||||
outln(output, ",");
|
||||
}
|
||||
}
|
||||
}
|
||||
outln(output, "");
|
||||
for (auto& member : m_members) {
|
||||
member.dump(output, indent + 1);
|
||||
}
|
||||
|
|
|
@ -705,9 +705,13 @@ public:
|
|||
NonnullRefPtrVector<Declaration> const& members() const { return m_members; }
|
||||
void set_members(NonnullRefPtrVector<Declaration>&& members) { m_members = move(members); }
|
||||
|
||||
NonnullRefPtrVector<Name> const& baseclasses() const { return m_baseclasses; }
|
||||
void set_baseclasses(NonnullRefPtrVector<Name>&& baseclasses) { m_baseclasses = move(baseclasses); }
|
||||
|
||||
private:
|
||||
StructOrClassDeclaration::Type m_type;
|
||||
NonnullRefPtrVector<Declaration> m_members;
|
||||
NonnullRefPtrVector<Name> m_baseclasses;
|
||||
};
|
||||
|
||||
enum class UnaryOp {
|
||||
|
|
|
@ -1151,6 +1151,8 @@ NonnullRefPtr<StructOrClassDeclaration> Parser::parse_class_declaration(ASTNode&
|
|||
|
||||
auto has_final = match_keyword("final");
|
||||
|
||||
NonnullRefPtrVector<Name> baseclasses;
|
||||
|
||||
// FIXME: Don't ignore this.
|
||||
if (peek(has_final ? 1 : 0).type() == Token::Type::Colon) {
|
||||
if (has_final)
|
||||
|
@ -1162,10 +1164,12 @@ NonnullRefPtr<StructOrClassDeclaration> Parser::parse_class_declaration(ASTNode&
|
|||
while (match_keyword("private") || match_keyword("public") || match_keyword("protected") || match_keyword("virtual"))
|
||||
consume();
|
||||
|
||||
(void)parse_name(get_dummy_node());
|
||||
baseclasses.append(parse_name(*decl));
|
||||
} while (peek().type() == Token::Type::Comma);
|
||||
}
|
||||
|
||||
decl->set_baseclasses(move(baseclasses));
|
||||
|
||||
consume(Token::Type::LeftCurly);
|
||||
|
||||
while (!eof() && peek().type() != Token::Type::RightCurly) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
TranslationUnit[0:0->10:1]
|
||||
StructOrClassDeclaration[0:6->10:1]
|
||||
A
|
||||
|
||||
C'tor
|
||||
(
|
||||
Parameter[1:6->1:10]
|
||||
|
|
14
Userland/Libraries/LibCpp/Tests/parser/inheritance.ast
Normal file
14
Userland/Libraries/LibCpp/Tests/parser/inheritance.ast
Normal file
|
@ -0,0 +1,14 @@
|
|||
TranslationUnit[0:0->3:1]
|
||||
StructOrClassDeclaration[0:6->3:1]
|
||||
A
|
||||
:
|
||||
Name[0:17->0:32]
|
||||
SomeNamespace::B
|
||||
,
|
||||
Name[0:43->0:43]
|
||||
C
|
||||
|
||||
VariableDeclaration[2:4->3:0]
|
||||
NamedType[2:4->2:6]
|
||||
int
|
||||
x
|
4
Userland/Libraries/LibCpp/Tests/parser/inheritance.cpp
Normal file
4
Userland/Libraries/LibCpp/Tests/parser/inheritance.cpp
Normal file
|
@ -0,0 +1,4 @@
|
|||
class A : public SomeNamespace::B, private C
|
||||
{
|
||||
int x;
|
||||
};
|
|
@ -1,6 +1,7 @@
|
|||
TranslationUnit[2:0->9:0]
|
||||
StructOrClassDeclaration[2:6->7:0]
|
||||
A
|
||||
|
||||
FunctionDeclaration[4:4->4:14]
|
||||
NamedType[4:4->4:7]
|
||||
bool
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
TranslationUnit[1:0->12:0]
|
||||
StructOrClassDeclaration[1:7->7:0]
|
||||
MyStruct
|
||||
|
||||
VariableDeclaration[3:4->4:4]
|
||||
NamedType[3:4->3:6]
|
||||
int
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue