pattern.h 1.2 KB

123456789101112131415161718192021222324252627282930
  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_SEM_IR_PATTERN_H_
  5. #define CARBON_TOOLCHAIN_SEM_IR_PATTERN_H_
  6. #include "toolchain/sem_ir/file.h"
  7. #include "toolchain/sem_ir/ids.h"
  8. namespace Carbon::SemIR {
  9. // Returns true if `pattern_id` is a `self` parameter pattern, such as
  10. // `self: Foo` or `addr self: Self*`.
  11. auto IsSelfPattern(const File& sem_ir, InstId pattern_id) -> bool;
  12. // If `pattern_id` is a declaration of a single name, this returns that name,
  13. // and otherwise returns `None`. This tries to "see through" wrappers like
  14. // `AddrPattern` and `*ParamPattern`, so this may return the same name for
  15. // different insts if one is an ancestor of the other (or if they represent
  16. // separate declarations of the same name).
  17. //
  18. // This should only be used for decorative purposes such as SemIR
  19. // pretty-printing or LLVM parameter naming.
  20. auto GetPrettyNameFromPatternId(const File& sem_ir, InstId pattern_id)
  21. -> NameId;
  22. } // namespace Carbon::SemIR
  23. #endif // CARBON_TOOLCHAIN_SEM_IR_PATTERN_H_