import.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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_IMPORT_H_
  5. #define CARBON_TOOLCHAIN_CHECK_CPP_IMPORT_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. // Imports a function declaration from Clang to Carbon. If successful, returns
  23. // the new Carbon function declaration `InstId`. If the declaration was already
  24. // imported, returns the mapped instruction.
  25. auto ImportCppFunctionDecl(Context& context, SemIR::LocId loc_id,
  26. clang::FunctionDecl* clang_decl, int num_params)
  27. -> SemIR::InstId;
  28. // Imports an overloaded function set from Clang to Carbon.
  29. auto ImportCppOverloadSet(
  30. Context& context, SemIR::NameScopeId scope_id, SemIR::NameId name_id,
  31. clang::CXXRecordDecl* naming_class, clang::UnresolvedSet<4>&& overload_set,
  32. clang::OverloadCandidateSet::OperatorRewriteInfo operator_rewrite_info)
  33. -> SemIR::InstId;
  34. // Looks up the given name in the Clang AST generated when importing C++ code
  35. // and returns a lookup result. If using the injected class name (`X.X()`),
  36. // imports the class constructor as a function named as the class.
  37. auto ImportNameFromCpp(Context& context, SemIR::LocId loc_id,
  38. SemIR::NameScopeId scope_id, SemIR::NameId name_id)
  39. -> SemIR::ScopeLookupResult;
  40. // Given a Carbon class declaration that was imported from some kind of C++
  41. // declaration, such as a class or enum, attempt to import a corresponding class
  42. // definition. Returns true if nothing went wrong (whether or not a definition
  43. // could be imported), false if a diagnostic was produced.
  44. auto ImportClassDefinitionForClangDecl(Context& context, SemIR::LocId loc_id,
  45. SemIR::ClassId class_id,
  46. SemIR::ClangDeclId clang_decl_id)
  47. -> bool;
  48. } // namespace Carbon::Check
  49. #endif // CARBON_TOOLCHAIN_CHECK_CPP_IMPORT_H_