JSSpecCompiler: Let FunctionDeclaration know its name and category

This is achieved by moving ClauseHeader::{AbstractOperation,Accessor,
Method} to Function.h itself and storing them in FunctionDeclaration.

This commit also introduces QualifiedName class that is used to store
function's name split by '.' (just like it appear in the spec).
This commit is contained in:
Dan Klishch 2024-03-11 15:51:14 -04:00 committed by Andrew Kaster
commit 0e7c33b1be
Notes: sideshowbarker 2024-07-17 01:46:43 +09:00
12 changed files with 170 additions and 96 deletions

View file

@ -71,8 +71,8 @@ private:
};
template<>
struct AK::Formatter<Vector<FunctionArgument>> : AK::Formatter<StringView> {
ErrorOr<void> format(FormatBuilder& builder, Vector<FunctionArgument> const& arguments)
struct AK::Formatter<ReadonlySpan<FunctionArgument>> : AK::Formatter<StringView> {
ErrorOr<void> format(FormatBuilder& builder, ReadonlySpan<FunctionArgument> const& arguments)
{
size_t previous_optional_group = 0;
for (size_t i = 0; i < arguments.size(); ++i) {
@ -139,17 +139,6 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TranslationUnit translation_unit(filename);
// Functions referenced in DifferenceISODate
// TODO: This is here just for testing. In a long run, we need some place, which is not
// `serenity_main`, to store built-in functions.
translation_unit.adopt_declaration(make_ref_counted<FunctionDeclaration>("CompareISODate"sv, Vector<FunctionArgument> {}));
translation_unit.adopt_declaration(make_ref_counted<FunctionDeclaration>("CreateDateDurationRecord"sv, Vector<FunctionArgument> {}));
translation_unit.adopt_declaration(make_ref_counted<FunctionDeclaration>("AddISODate"sv, Vector<FunctionArgument> {}));
translation_unit.adopt_declaration(make_ref_counted<FunctionDeclaration>("ISODaysInMonth"sv, Vector<FunctionArgument> {}));
translation_unit.adopt_declaration(make_ref_counted<FunctionDeclaration>("ISODateToEpochDays"sv, Vector<FunctionArgument> {}));
translation_unit.adopt_declaration(make_ref_counted<FunctionDeclaration>("truncate"sv, Vector<FunctionArgument> {}));
translation_unit.adopt_declaration(make_ref_counted<FunctionDeclaration>("remainder"sv, Vector<FunctionArgument> {}));
for (auto const& step : pipeline.pipeline()) {
step.step->run(&translation_unit);
@ -161,14 +150,14 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
if (step.dump_ast) {
outln(stderr, "===== AST after {} =====", step.step->name());
for (auto const& function : translation_unit.functions_to_compile()) {
outln(stderr, "{}({}):", function->m_name, function->m_arguments);
outln(stderr, "{}({}):", function->name(), function->arguments());
outln(stderr, "{}", function->m_ast);
}
}
if (step.dump_cfg && translation_unit.functions_to_compile().size() && translation_unit.functions_to_compile()[0]->m_cfg != nullptr) {
outln(stderr, "===== CFG after {} =====", step.step->name());
for (auto const& function : translation_unit.functions_to_compile()) {
outln(stderr, "{}({}):", function->m_name, function->m_arguments);
outln(stderr, "{}({}):", function->name(), function->arguments());
outln(stderr, "{}", *function->m_cfg);
}
}