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

@ -14,7 +14,7 @@ namespace JSSpecCompiler {
void ReferenceResolvingPass::process_function()
{
for (auto argument : m_function->m_arguments)
for (auto argument : m_function->arguments())
m_function->m_local_variables.set(argument.name, make_ref_counted<NamedVariableDeclaration>(argument.name));
GenericASTPass::process_function();
}
@ -51,7 +51,7 @@ void ReferenceResolvingPass::on_leave(Tree tree)
return;
}
if (auto function = m_translation_unit->find_declaration_by_name(name)) {
if (auto function = m_translation_unit->find_abstract_operation_by_name(name)) {
replace_current_node_with(make_ref_counted<FunctionPointer>(function));
return;
}

View file

@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Enumerate.h>
#include <AK/Queue.h>
#include "AST/AST.h"
@ -430,9 +431,9 @@ void SSABuildingPass::rename_variables(Vertex u, Vertex from)
void SSABuildingPass::rename_variables()
{
HashMap<StringView, size_t> argument_index_by_name;
for (size_t i = 0; i < m_function->m_arguments.size(); ++i)
argument_index_by_name.set(m_function->m_arguments[i].name, i);
m_function->m_ssa_arguments.resize(m_function->m_arguments.size());
for (auto [i, argument] : enumerate(m_function->arguments()))
argument_index_by_name.set(argument.name, i);
m_function->m_ssa_arguments.resize(m_function->arguments().size());
for (auto const& [name, var_decl] : m_function->m_local_variables) {
make_new_ssa_variable_for(var_decl);