/* * Copyright (c) 2023, Dan Klishch * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include "DiagnosticEngine.h" #include "Forward.h" namespace JSSpecCompiler { class TranslationUnit { public: TranslationUnit(StringView filename); ~TranslationUnit(); void adopt_declaration(NonnullRefPtr&& declaration); FunctionDefinitionRef adopt_function(NonnullRefPtr&& definition); FunctionDeclarationRef find_declaration_by_name(StringView name) const; StringView filename() const { return m_filename; } DiagnosticEngine& diag() { return m_diagnostic_engine; } Vector functions_to_compile() const { return m_functions_to_compile; } EnumeratorRef get_node_for_enumerator_value(StringView value); private: StringView m_filename; DiagnosticEngine m_diagnostic_engine; Vector m_functions_to_compile; Vector> m_declarations_owner; HashMap m_function_index; HashMap m_enumerator_nodes; }; struct FunctionArgument { StringView name; size_t optional_arguments_group; }; class FunctionDeclaration : public RefCounted { public: FunctionDeclaration(StringView name, Vector&& arguments); virtual ~FunctionDeclaration() = default; TranslationUnitRef m_translation_unit = nullptr; StringView m_name; Vector m_arguments; }; class FunctionDefinition : public FunctionDeclaration { public: FunctionDefinition(StringView name, Tree ast, Vector&& arguments); void reindex_ssa_variables(); Tree m_ast; // Populates during reference resolving // NOTE: The hash map here is ordered since we do not want random hash changes to break our test // expectations (looking at you, SipHash). OrderedHashMap m_local_variables; // Fields populate during CFG building NamedVariableDeclarationRef m_named_return_value; RefPtr m_cfg; // Fields populate during SSA building Vector m_ssa_arguments; SSAVariableDeclarationRef m_return_value; Vector m_local_ssa_variables; }; }