import.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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_H_
  5. #define CARBON_TOOLCHAIN_CHECK_IMPORT_H_
  6. #include "toolchain/check/context.h"
  7. #include "toolchain/parse/node_ids.h"
  8. #include "toolchain/sem_ir/file.h"
  9. namespace Carbon::Check {
  10. // Imports the API file's name lookup information into a corresponding
  11. // implementation file. Only information for the current package will be copied;
  12. // information for other packages should be handled through
  13. // ImportLibrariesFromOtherPackage.
  14. auto ImportApiFile(Context& context, SemIR::TypeId namespace_type_id,
  15. const SemIR::File& api_sem_ir) -> void;
  16. // Add the current package's imports to name lookup. This pulls in all names;
  17. // conflicts for things such as `package.a.b.c` will be flagged even though they
  18. // are several layers deep.
  19. auto ImportLibrariesFromCurrentPackage(
  20. Context& context, SemIR::TypeId namespace_type_id,
  21. llvm::ArrayRef<SemIR::ImportIR> import_irs) -> void;
  22. // Adds another package's imports to name lookup. This only adds the package
  23. // name to lookup, so that `package.ImportedPackage` will resolve, and will
  24. // provide a name scope that can be used for further qualified name lookups.
  25. //
  26. // import_irs may be empty. has_load_error is used to indicate if any library in
  27. // the package failed to import correctly.
  28. auto ImportLibrariesFromOtherPackage(Context& context,
  29. SemIR::TypeId namespace_type_id,
  30. SemIR::InstId import_decl_id,
  31. IdentifierId package_id,
  32. llvm::ArrayRef<SemIR::ImportIR> import_irs,
  33. bool has_load_error) -> void;
  34. // Given a name scope that corresponds to another package (having one or more
  35. // `import_irs`), looks for the name in imports. Name resolution results are
  36. // added to the scope, and the `InstId` (possibly `None`) is returned.
  37. //
  38. // In general, this will add an `ImportRef` and load it; it's never left
  39. // unloaded because the result is expected to be immediately used. Namespaces
  40. // will be directly produced, similar to how they function for imports from the
  41. // current package. Conflicts will be resolved and diagnosed.
  42. //
  43. // Arguments are all in the context of the current IR. Scope lookup is expected
  44. // to be resolved first.
  45. auto ImportNameFromOtherPackage(
  46. Context& context, SemIRLoc loc, SemIR::NameScopeId scope_id,
  47. llvm::ArrayRef<std::pair<SemIR::ImportIRId, SemIR::NameScopeId>>
  48. import_ir_scopes,
  49. SemIR::NameId name_id) -> SemIR::InstId;
  50. } // namespace Carbon::Check
  51. #endif // CARBON_TOOLCHAIN_CHECK_IMPORT_H_