diff options
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibCpp/AST.cpp | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibCpp/AST.h | 8 | ||||
-rw-r--r-- | Userland/Libraries/LibCpp/Parser.cpp | 8 |
3 files changed, 16 insertions, 4 deletions
diff --git a/Userland/Libraries/LibCpp/AST.cpp b/Userland/Libraries/LibCpp/AST.cpp index 237f550dfa..40f960b785 100644 --- a/Userland/Libraries/LibCpp/AST.cpp +++ b/Userland/Libraries/LibCpp/AST.cpp @@ -287,7 +287,9 @@ void EnumDeclaration::dump(FILE* output, size_t indent) const outln(output, "{}", m_name); for (auto& entry : m_entries) { print_indent(output, indent + 1); - outln(output, "{}", entry); + outln(output, "{}", entry.name); + if (entry.value) + entry.value->dump(output, indent + 2); } } diff --git a/Userland/Libraries/LibCpp/AST.h b/Userland/Libraries/LibCpp/AST.h index 2120599e8b..912312770a 100644 --- a/Userland/Libraries/LibCpp/AST.h +++ b/Userland/Libraries/LibCpp/AST.h @@ -616,11 +616,15 @@ public: }; void set_type(Type type) { m_type = type; } - void add_entry(StringView entry) { m_entries.append(move(entry)); } + void add_entry(StringView entry, RefPtr<Expression> value = nullptr) { m_entries.append({ entry, move(value) }); } private: Type m_type { Type::RegularEnum }; - Vector<StringView> m_entries; + struct EnumerationEntry { + StringView name; + RefPtr<Expression> value; + }; + Vector<EnumerationEntry> m_entries; }; class StructOrClassDeclaration : public Declaration { diff --git a/Userland/Libraries/LibCpp/Parser.cpp b/Userland/Libraries/LibCpp/Parser.cpp index 120793bc70..c18f1154d0 100644 --- a/Userland/Libraries/LibCpp/Parser.cpp +++ b/Userland/Libraries/LibCpp/Parser.cpp @@ -1076,7 +1076,13 @@ NonnullRefPtr<EnumDeclaration> Parser::parse_enum_declaration(ASTNode& parent) enum_decl->set_name(text_of_token(name_token)); consume(Token::Type::LeftCurly); while (!eof() && peek().type() != Token::Type::RightCurly) { - enum_decl->add_entry(text_of_token(consume(Token::Type::Identifier))); + auto name = text_of_token(consume(Token::Type::Identifier)); + RefPtr<Expression> value; + if (peek().type() == Token::Type::Equals) { + consume(); + value = parse_expression(enum_decl); + } + enum_decl->add_entry(name, move(value)); if (peek().type() != Token::Type::Comma) { break; } |