Function.cpp 1022 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * Copyright (c) 2023, Dan Klishch <danilklishch@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "Function.h"
  7. #include "AST/AST.h"
  8. #include "Compiler/ControlFlowGraph.h"
  9. namespace JSSpecCompiler {
  10. FunctionDefinitionRef TranslationUnit::adopt_function(NonnullRefPtr<FunctionDefinition>&& function)
  11. {
  12. function->m_translation_unit = this;
  13. function_index.set(function->m_name, make_ref_counted<FunctionPointer>(function));
  14. FunctionDefinitionRef result = function.ptr();
  15. function_definitions.append(move(function));
  16. return result;
  17. }
  18. FunctionDeclaration::FunctionDeclaration(StringView name)
  19. : m_name(name)
  20. {
  21. }
  22. FunctionDefinition::FunctionDefinition(StringView name, Tree ast)
  23. : FunctionDeclaration(name)
  24. , m_ast(move(ast))
  25. , m_return_value(make_ref_counted<NamedVariableDeclaration>("$return"sv))
  26. {
  27. }
  28. void FunctionDefinition::reindex_ssa_variables()
  29. {
  30. size_t index = 0;
  31. for (auto const& var : m_local_ssa_variables)
  32. var->m_index = index++;
  33. }
  34. }