mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-28 13:43:45 +03:00
JSSpecCompiler: Make fields in classes from SpecParser.h private
This commit is contained in:
parent
cb6e75e890
commit
d219c91ca9
Notes:
sideshowbarker
2024-07-17 09:48:50 +09:00
Author: https://github.com/DanShaders Commit: https://github.com/SerenityOS/serenity/commit/d219c91ca9 Pull-request: https://github.com/SerenityOS/serenity/pull/22899 Reviewed-by: https://github.com/ADKaster ✅
@ -72,7 +72,9 @@ Optional<AlgorithmStep> AlgorithmStep::create(SpecificationParsingContext& ctx,
|
||||
}
|
||||
|
||||
auto [tokens, substeps] = tokenization_result.release_value();
|
||||
AlgorithmStep result { .m_tokens = move(tokens), .m_node = element };
|
||||
AlgorithmStep result(ctx);
|
||||
result.m_tokens = move(tokens);
|
||||
result.m_node = element;
|
||||
|
||||
if (substeps) {
|
||||
// FIXME: Remove this once macOS Lagom CI updates to Clang >= 16.
|
||||
@ -81,8 +83,7 @@ Optional<AlgorithmStep> AlgorithmStep::create(SpecificationParsingContext& ctx,
|
||||
auto step_list = ctx.with_new_step_list_nesting_level([&] {
|
||||
return AlgorithmStepList::create(ctx, substeps_copy);
|
||||
});
|
||||
if (step_list.has_value())
|
||||
result.m_substeps = step_list->m_expression;
|
||||
result.m_substeps = step_list.has_value() ? step_list->tree() : error_tree;
|
||||
}
|
||||
|
||||
auto parse_result = result.parse();
|
||||
@ -110,7 +111,6 @@ Optional<AlgorithmStepList> AlgorithmStepList::create(SpecificationParsingContex
|
||||
VERIFY(element->as_element().name == tag_ol);
|
||||
|
||||
AlgorithmStepList result;
|
||||
auto& steps = result.m_steps;
|
||||
|
||||
Vector<Tree> step_expressions;
|
||||
bool all_steps_parsed = true;
|
||||
@ -126,12 +126,10 @@ Optional<AlgorithmStepList> AlgorithmStepList::create(SpecificationParsingContex
|
||||
update_logical_scope_for_step(ctx, parent_scope, step_number);
|
||||
return AlgorithmStep::create(ctx, child);
|
||||
});
|
||||
if (!step_creation_result.has_value()) {
|
||||
if (!step_creation_result.has_value())
|
||||
all_steps_parsed = false;
|
||||
} else {
|
||||
steps.append(step_creation_result.release_value());
|
||||
step_expressions.append(steps.last().m_expression);
|
||||
}
|
||||
else
|
||||
step_expressions.append(step_creation_result.release_value().tree());
|
||||
++step_number;
|
||||
return;
|
||||
}
|
||||
@ -214,8 +212,7 @@ Optional<Algorithm> Algorithm::create(SpecificationParsingContext& ctx, XML::Nod
|
||||
auto steps_creation_result = AlgorithmStepList::create(ctx, steps_list[0]);
|
||||
if (steps_creation_result.has_value()) {
|
||||
Algorithm algorithm;
|
||||
algorithm.m_steps = steps_creation_result.release_value();
|
||||
algorithm.m_tree = algorithm.m_steps.m_expression;
|
||||
algorithm.m_tree = steps_creation_result.release_value().tree();
|
||||
return algorithm;
|
||||
}
|
||||
return {};
|
||||
@ -226,8 +223,8 @@ NonnullOwnPtr<SpecificationClause> SpecificationClause::create(SpecificationPars
|
||||
return ctx.with_new_logical_scope([&] {
|
||||
VERIFY(element->as_element().name == tag_emu_clause);
|
||||
|
||||
SpecificationClause specification_clause;
|
||||
specification_clause.parse(ctx, element);
|
||||
SpecificationClause specification_clause(ctx);
|
||||
specification_clause.parse(element);
|
||||
|
||||
OwnPtr<SpecificationClause> result;
|
||||
|
||||
@ -239,7 +236,7 @@ NonnullOwnPtr<SpecificationClause> SpecificationClause::create(SpecificationPars
|
||||
result = make<SpecFunction>(move(specification_clause));
|
||||
});
|
||||
|
||||
if (!result->post_initialize(ctx, element))
|
||||
if (!result->post_initialize(element))
|
||||
result = make<SpecificationClause>(move(*result));
|
||||
|
||||
return result.release_nonnull();
|
||||
@ -262,8 +259,9 @@ ParseErrorOr<void> SpecificationClause::parse_header(XML::Node const* element)
|
||||
return {};
|
||||
}
|
||||
|
||||
void SpecificationClause::parse(SpecificationParsingContext& ctx, XML::Node const* element)
|
||||
void SpecificationClause::parse(XML::Node const* element)
|
||||
{
|
||||
auto& ctx = context();
|
||||
u32 child_index = 0;
|
||||
|
||||
Optional<NonnullRefPtr<ParseError>> header_parse_error;
|
||||
@ -314,10 +312,12 @@ void SpecificationClause::parse(SpecificationParsingContext& ctx, XML::Node cons
|
||||
}
|
||||
}
|
||||
|
||||
bool SpecFunction::post_initialize(SpecificationParsingContext& ctx, XML::Node const* element)
|
||||
bool SpecFunction::post_initialize(XML::Node const* element)
|
||||
{
|
||||
VERIFY(element->as_element().name == tag_emu_clause);
|
||||
|
||||
auto& ctx = context();
|
||||
|
||||
auto maybe_id = get_attribute_by_name(element, attribute_id);
|
||||
if (!maybe_id.has_value()) {
|
||||
ctx.diag().error(ctx.location_from_xml_offset(element->offset),
|
||||
@ -376,7 +376,7 @@ bool SpecFunction::post_initialize(SpecificationParsingContext& ctx, XML::Node c
|
||||
|
||||
void SpecFunction::do_collect(TranslationUnitRef translation_unit)
|
||||
{
|
||||
translation_unit->adopt_function(make_ref_counted<FunctionDefinition>(m_name, m_algorithm.m_tree, move(m_arguments)));
|
||||
translation_unit->adopt_function(make_ref_counted<FunctionDefinition>(m_name, m_algorithm.tree(), move(m_arguments)));
|
||||
}
|
||||
|
||||
Specification Specification::create(SpecificationParsingContext& ctx, XML::Node const* element)
|
||||
|
@ -50,30 +50,42 @@ class AlgorithmStepList {
|
||||
public:
|
||||
static Optional<AlgorithmStepList> create(SpecificationParsingContext& ctx, XML::Node const* element);
|
||||
|
||||
Vector<AlgorithmStep> m_steps;
|
||||
Tree m_expression = error_tree;
|
||||
Tree tree() const { return m_expression; }
|
||||
|
||||
private:
|
||||
static void update_logical_scope_for_step(SpecificationParsingContext& ctx, LogicalLocation const& parent_scope, int step_number);
|
||||
|
||||
Tree m_expression = error_tree;
|
||||
};
|
||||
|
||||
class AlgorithmStep {
|
||||
public:
|
||||
static Optional<AlgorithmStep> create(SpecificationParsingContext& ctx, XML::Node const* node);
|
||||
|
||||
Tree tree() const { return m_expression; }
|
||||
|
||||
private:
|
||||
AlgorithmStep(SpecificationParsingContext& ctx)
|
||||
: m_ctx(ctx)
|
||||
{
|
||||
}
|
||||
|
||||
ParseErrorOr<Tree> parse();
|
||||
|
||||
Tree m_expression = error_tree;
|
||||
SpecificationParsingContext& m_ctx;
|
||||
Vector<Token> m_tokens;
|
||||
NullableTree m_substeps;
|
||||
XML::Node const* m_node;
|
||||
Tree m_expression = error_tree;
|
||||
NullableTree m_substeps;
|
||||
};
|
||||
|
||||
class Algorithm {
|
||||
public:
|
||||
static Optional<Algorithm> create(SpecificationParsingContext& ctx, XML::Node const* element);
|
||||
|
||||
AlgorithmStepList m_steps;
|
||||
Tree tree() const { return m_tree; }
|
||||
|
||||
private:
|
||||
Tree m_tree = error_tree;
|
||||
};
|
||||
|
||||
@ -88,16 +100,23 @@ public:
|
||||
void collect_into(TranslationUnitRef translation_unit);
|
||||
|
||||
protected:
|
||||
virtual bool post_initialize(SpecificationParsingContext& /*ctx*/, XML::Node const* /*element*/) { return true; }
|
||||
virtual bool post_initialize(XML::Node const* /*element*/) { return true; }
|
||||
virtual void do_collect(TranslationUnitRef /*translation_unit*/) { }
|
||||
|
||||
SpecificationParsingContext& context() { return *m_ctx_pointer; }
|
||||
|
||||
ClauseHeader m_header;
|
||||
|
||||
private:
|
||||
SpecificationClause() = default;
|
||||
ParseErrorOr<void> parse_header(XML::Node const* element);
|
||||
void parse(SpecificationParsingContext& ctx, XML::Node const* element);
|
||||
SpecificationClause(SpecificationParsingContext& ctx)
|
||||
: m_ctx_pointer(&ctx)
|
||||
{
|
||||
}
|
||||
|
||||
ParseErrorOr<void> parse_header(XML::Node const* element);
|
||||
void parse(XML::Node const* element);
|
||||
|
||||
SpecificationParsingContext* m_ctx_pointer;
|
||||
Vector<NonnullOwnPtr<SpecificationClause>> m_subclauses;
|
||||
};
|
||||
|
||||
@ -109,7 +128,7 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
bool post_initialize(SpecificationParsingContext& ctx, XML::Node const* element) override;
|
||||
bool post_initialize(XML::Node const* element) override;
|
||||
void do_collect(TranslationUnitRef translation_unit) override;
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user