mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 09:07:35 +00:00
JSSpecCompiler: Make fields in classes from SpecParser.h private
This commit is contained in:
parent
cb6e75e890
commit
d219c91ca9
2 changed files with 46 additions and 27 deletions
|
@ -72,7 +72,9 @@ Optional<AlgorithmStep> AlgorithmStep::create(SpecificationParsingContext& ctx,
|
||||||
}
|
}
|
||||||
|
|
||||||
auto [tokens, substeps] = tokenization_result.release_value();
|
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) {
|
if (substeps) {
|
||||||
// FIXME: Remove this once macOS Lagom CI updates to Clang >= 16.
|
// 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([&] {
|
auto step_list = ctx.with_new_step_list_nesting_level([&] {
|
||||||
return AlgorithmStepList::create(ctx, substeps_copy);
|
return AlgorithmStepList::create(ctx, substeps_copy);
|
||||||
});
|
});
|
||||||
if (step_list.has_value())
|
result.m_substeps = step_list.has_value() ? step_list->tree() : error_tree;
|
||||||
result.m_substeps = step_list->m_expression;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto parse_result = result.parse();
|
auto parse_result = result.parse();
|
||||||
|
@ -110,7 +111,6 @@ Optional<AlgorithmStepList> AlgorithmStepList::create(SpecificationParsingContex
|
||||||
VERIFY(element->as_element().name == tag_ol);
|
VERIFY(element->as_element().name == tag_ol);
|
||||||
|
|
||||||
AlgorithmStepList result;
|
AlgorithmStepList result;
|
||||||
auto& steps = result.m_steps;
|
|
||||||
|
|
||||||
Vector<Tree> step_expressions;
|
Vector<Tree> step_expressions;
|
||||||
bool all_steps_parsed = true;
|
bool all_steps_parsed = true;
|
||||||
|
@ -126,12 +126,10 @@ Optional<AlgorithmStepList> AlgorithmStepList::create(SpecificationParsingContex
|
||||||
update_logical_scope_for_step(ctx, parent_scope, step_number);
|
update_logical_scope_for_step(ctx, parent_scope, step_number);
|
||||||
return AlgorithmStep::create(ctx, child);
|
return AlgorithmStep::create(ctx, child);
|
||||||
});
|
});
|
||||||
if (!step_creation_result.has_value()) {
|
if (!step_creation_result.has_value())
|
||||||
all_steps_parsed = false;
|
all_steps_parsed = false;
|
||||||
} else {
|
else
|
||||||
steps.append(step_creation_result.release_value());
|
step_expressions.append(step_creation_result.release_value().tree());
|
||||||
step_expressions.append(steps.last().m_expression);
|
|
||||||
}
|
|
||||||
++step_number;
|
++step_number;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -214,8 +212,7 @@ Optional<Algorithm> Algorithm::create(SpecificationParsingContext& ctx, XML::Nod
|
||||||
auto steps_creation_result = AlgorithmStepList::create(ctx, steps_list[0]);
|
auto steps_creation_result = AlgorithmStepList::create(ctx, steps_list[0]);
|
||||||
if (steps_creation_result.has_value()) {
|
if (steps_creation_result.has_value()) {
|
||||||
Algorithm algorithm;
|
Algorithm algorithm;
|
||||||
algorithm.m_steps = steps_creation_result.release_value();
|
algorithm.m_tree = steps_creation_result.release_value().tree();
|
||||||
algorithm.m_tree = algorithm.m_steps.m_expression;
|
|
||||||
return algorithm;
|
return algorithm;
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
|
@ -226,8 +223,8 @@ NonnullOwnPtr<SpecificationClause> SpecificationClause::create(SpecificationPars
|
||||||
return ctx.with_new_logical_scope([&] {
|
return ctx.with_new_logical_scope([&] {
|
||||||
VERIFY(element->as_element().name == tag_emu_clause);
|
VERIFY(element->as_element().name == tag_emu_clause);
|
||||||
|
|
||||||
SpecificationClause specification_clause;
|
SpecificationClause specification_clause(ctx);
|
||||||
specification_clause.parse(ctx, element);
|
specification_clause.parse(element);
|
||||||
|
|
||||||
OwnPtr<SpecificationClause> result;
|
OwnPtr<SpecificationClause> result;
|
||||||
|
|
||||||
|
@ -239,7 +236,7 @@ NonnullOwnPtr<SpecificationClause> SpecificationClause::create(SpecificationPars
|
||||||
result = make<SpecFunction>(move(specification_clause));
|
result = make<SpecFunction>(move(specification_clause));
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!result->post_initialize(ctx, element))
|
if (!result->post_initialize(element))
|
||||||
result = make<SpecificationClause>(move(*result));
|
result = make<SpecificationClause>(move(*result));
|
||||||
|
|
||||||
return result.release_nonnull();
|
return result.release_nonnull();
|
||||||
|
@ -262,8 +259,9 @@ ParseErrorOr<void> SpecificationClause::parse_header(XML::Node const* element)
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpecificationClause::parse(SpecificationParsingContext& ctx, XML::Node const* element)
|
void SpecificationClause::parse(XML::Node const* element)
|
||||||
{
|
{
|
||||||
|
auto& ctx = context();
|
||||||
u32 child_index = 0;
|
u32 child_index = 0;
|
||||||
|
|
||||||
Optional<NonnullRefPtr<ParseError>> header_parse_error;
|
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);
|
VERIFY(element->as_element().name == tag_emu_clause);
|
||||||
|
|
||||||
|
auto& ctx = context();
|
||||||
|
|
||||||
auto maybe_id = get_attribute_by_name(element, attribute_id);
|
auto maybe_id = get_attribute_by_name(element, attribute_id);
|
||||||
if (!maybe_id.has_value()) {
|
if (!maybe_id.has_value()) {
|
||||||
ctx.diag().error(ctx.location_from_xml_offset(element->offset),
|
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)
|
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)
|
Specification Specification::create(SpecificationParsingContext& ctx, XML::Node const* element)
|
||||||
|
|
|
@ -50,30 +50,42 @@ class AlgorithmStepList {
|
||||||
public:
|
public:
|
||||||
static Optional<AlgorithmStepList> create(SpecificationParsingContext& ctx, XML::Node const* element);
|
static Optional<AlgorithmStepList> create(SpecificationParsingContext& ctx, XML::Node const* element);
|
||||||
|
|
||||||
Vector<AlgorithmStep> m_steps;
|
Tree tree() const { return m_expression; }
|
||||||
Tree m_expression = error_tree;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void update_logical_scope_for_step(SpecificationParsingContext& ctx, LogicalLocation const& parent_scope, int step_number);
|
static void update_logical_scope_for_step(SpecificationParsingContext& ctx, LogicalLocation const& parent_scope, int step_number);
|
||||||
|
|
||||||
|
Tree m_expression = error_tree;
|
||||||
};
|
};
|
||||||
|
|
||||||
class AlgorithmStep {
|
class AlgorithmStep {
|
||||||
public:
|
public:
|
||||||
static Optional<AlgorithmStep> create(SpecificationParsingContext& ctx, XML::Node const* node);
|
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();
|
ParseErrorOr<Tree> parse();
|
||||||
|
|
||||||
Tree m_expression = error_tree;
|
SpecificationParsingContext& m_ctx;
|
||||||
Vector<Token> m_tokens;
|
Vector<Token> m_tokens;
|
||||||
NullableTree m_substeps;
|
|
||||||
XML::Node const* m_node;
|
XML::Node const* m_node;
|
||||||
|
Tree m_expression = error_tree;
|
||||||
|
NullableTree m_substeps;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Algorithm {
|
class Algorithm {
|
||||||
public:
|
public:
|
||||||
static Optional<Algorithm> create(SpecificationParsingContext& ctx, XML::Node const* element);
|
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;
|
Tree m_tree = error_tree;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -88,16 +100,23 @@ public:
|
||||||
void collect_into(TranslationUnitRef translation_unit);
|
void collect_into(TranslationUnitRef translation_unit);
|
||||||
|
|
||||||
protected:
|
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*/) { }
|
virtual void do_collect(TranslationUnitRef /*translation_unit*/) { }
|
||||||
|
|
||||||
|
SpecificationParsingContext& context() { return *m_ctx_pointer; }
|
||||||
|
|
||||||
ClauseHeader m_header;
|
ClauseHeader m_header;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SpecificationClause() = default;
|
SpecificationClause(SpecificationParsingContext& ctx)
|
||||||
ParseErrorOr<void> parse_header(XML::Node const* element);
|
: m_ctx_pointer(&ctx)
|
||||||
void parse(SpecificationParsingContext& ctx, XML::Node const* element);
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
ParseErrorOr<void> parse_header(XML::Node const* element);
|
||||||
|
void parse(XML::Node const* element);
|
||||||
|
|
||||||
|
SpecificationParsingContext* m_ctx_pointer;
|
||||||
Vector<NonnullOwnPtr<SpecificationClause>> m_subclauses;
|
Vector<NonnullOwnPtr<SpecificationClause>> m_subclauses;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -109,7 +128,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
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;
|
void do_collect(TranslationUnitRef translation_unit) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue