Function.cpp 859 B

1234567891011121314151617181920212223242526272829303132333435
  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<VariableDeclaration>("$return"sv))
  26. {
  27. }
  28. }