generate_ast.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #ifndef CARBON_TOOLCHAIN_CHECK_CPP_GENERATE_AST_H_
  5. #define CARBON_TOOLCHAIN_CHECK_CPP_GENERATE_AST_H_
  6. #include <memory>
  7. #include "llvm/ADT/ArrayRef.h"
  8. #include "llvm/ADT/IntrusiveRefCntPtr.h"
  9. #include "llvm/ADT/StringRef.h"
  10. #include "llvm/Support/VirtualFileSystem.h"
  11. #include "toolchain/check/context.h"
  12. #include "toolchain/parse/tree.h"
  13. #include "toolchain/sem_ir/ids.h"
  14. namespace Carbon::Check {
  15. // Generates a Clang AST for the given C++ imports and sets it as the context's
  16. // `cpp_context` and the SemIR's `cpp_file`. Returns a bool that represents
  17. // whether compilation was successful.
  18. auto GenerateAst(Context& context,
  19. llvm::ArrayRef<Parse::Tree::PackagingNames> imports,
  20. llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs,
  21. llvm::LLVMContext* llvm_context,
  22. std::shared_ptr<clang::CompilerInvocation> base_invocation)
  23. -> bool;
  24. // Injects C++ code from `inline Cpp` into the active Clang AST context.
  25. // Returns a bool representing whether parsing was successful.
  26. auto InjectAstFromInlineCode(Context& context, SemIR::LocId loc_id,
  27. llvm::StringRef source_code) -> void;
  28. // Finishes AST generation for the given checking context. Performs end of file
  29. // steps such as template instantiation and warning on unused declarations.
  30. auto FinishAst(Context& context) -> void;
  31. } // namespace Carbon::Check
  32. #endif // CARBON_TOOLCHAIN_CHECK_CPP_GENERATE_AST_H_