CppASTConverter.h 1009 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright (c) 2023, Dan Klishch <danilklishch@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/OwnPtr.h>
  8. #include <LibCpp/AST.h>
  9. #include <LibCpp/Parser.h>
  10. #include "CompilationPipeline.h"
  11. namespace JSSpecCompiler {
  12. class CppASTConverter {
  13. public:
  14. CppASTConverter(RefPtr<Cpp::FunctionDeclaration> const& function)
  15. : m_function(function)
  16. {
  17. }
  18. NonnullRefPtr<FunctionDefinition> convert();
  19. private:
  20. template<typename T>
  21. NullableTree convert_node(T const&);
  22. NullableTree as_nullable_tree(Cpp::Statement const* statement);
  23. Tree as_tree(Cpp::Statement const* statement);
  24. Tree as_possibly_empty_tree(Cpp::Statement const* statement);
  25. RefPtr<Cpp::FunctionDeclaration> m_function;
  26. };
  27. class CppParsingStep : public CompilationStep {
  28. public:
  29. CppParsingStep();
  30. ~CppParsingStep();
  31. void run(TranslationUnitRef translation_unit) override;
  32. private:
  33. OwnPtr<Cpp::Parser> m_parser;
  34. ByteBuffer m_input;
  35. };
  36. }