import_cpp.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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_IMPORT_CPP_H_
  5. #define CARBON_TOOLCHAIN_CHECK_IMPORT_CPP_H_
  6. #include "llvm/ADT/ArrayRef.h"
  7. #include "llvm/ADT/IntrusiveRefCntPtr.h"
  8. #include "llvm/ADT/StringRef.h"
  9. #include "llvm/Support/VirtualFileSystem.h"
  10. #include "toolchain/check/context.h"
  11. #include "toolchain/check/diagnostic_helpers.h"
  12. #include "toolchain/diagnostics/diagnostic_emitter.h"
  13. namespace Carbon::Check {
  14. // Generates a C++ header that includes the imported cpp files, parses it,
  15. // generates the AST from it and links `SemIR::File` to it. Report C++ errors
  16. // and warnings. If successful, adds a `Cpp` namespace and returns the AST.
  17. auto ImportCppFiles(Context& context,
  18. llvm::ArrayRef<Parse::Tree::PackagingNames> imports,
  19. llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs,
  20. std::shared_ptr<clang::CompilerInvocation> invocation)
  21. -> std::unique_ptr<clang::ASTUnit>;
  22. // Looks up the given name in the Clang AST generated when importing C++ code
  23. // and returns a lookup result. If using the injected class name (`X.X()`),
  24. // imports the class constructor as a function named as the class.
  25. auto ImportNameFromCpp(Context& context, SemIR::LocId loc_id,
  26. SemIR::NameScopeId scope_id, SemIR::NameId name_id)
  27. -> SemIR::ScopeLookupResult;
  28. // Given a class declaration that was imported from C++, attempt to import a
  29. // corresponding class definition. Returns true if nothing went wrong (whether
  30. // or not a definition could be imported), false if a diagnostic was produced.
  31. auto ImportCppClassDefinition(Context& context, SemIR::LocId loc_id,
  32. SemIR::ClassId class_id,
  33. SemIR::ClangDeclId clang_decl_id) -> bool;
  34. } // namespace Carbon::Check
  35. #endif // CARBON_TOOLCHAIN_CHECK_IMPORT_CPP_H_