pattern.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  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 `ref self: Self`.
  11. auto IsSelfPattern(const File& sem_ir, InstId pattern_id) -> bool;
  12. // If `pattern_id` introduces any name bindings, this returns the `EntityNameId`
  13. // of the lexically-first such binding. Otherwise, returns `None`.
  14. auto GetFirstBindingNameFromPatternId(const File& sem_ir, InstId pattern_id)
  15. -> EntityNameId;
  16. // If `pattern_id` is a declaration of a single name, this returns that name,
  17. // and otherwise returns `None`. This tries to "see through" wrappers like
  18. // `AddrPattern` and `*ParamPattern`, so this may return the same name for
  19. // different insts if one is an ancestor of the other (or if they represent
  20. // separate declarations of the same name).
  21. //
  22. // This should only be used for decorative purposes such as SemIR
  23. // pretty-printing or LLVM parameter naming.
  24. auto GetPrettyNameFromPatternId(const File& sem_ir, InstId pattern_id)
  25. -> NameId;
  26. } // namespace Carbon::SemIR
  27. #endif // CARBON_TOOLCHAIN_SEM_IR_PATTERN_H_