Utility class for generating namespace qualified candidates for reference resolution. This class is expected to be scoped to a single type checking operation and borrows the ExpressionContainer from the TypeCheckEnv.
| 35 | // This class is expected to be scoped to a single type checking operation and |
| 36 | // borrows the ExpressionContainer from the TypeCheckEnv. |
| 37 | class NamespaceGenerator { |
| 38 | public: |
| 39 | static absl::StatusOr<NamespaceGenerator> Create( |
| 40 | const ExpressionContainer& expression_container |
| 41 | ABSL_ATTRIBUTE_LIFETIME_BOUND); |
| 42 | |
| 43 | // Copyable and movable. |
| 44 | NamespaceGenerator(const NamespaceGenerator&) = default; |
| 45 | NamespaceGenerator& operator=(const NamespaceGenerator&) = default; |
| 46 | NamespaceGenerator(NamespaceGenerator&&) = default; |
| 47 | NamespaceGenerator& operator=(NamespaceGenerator&&) = default; |
| 48 | |
| 49 | // For the simple case of an unqualified name, generate all qualified |
| 50 | // candidates and pass them to the provided callback. The callback may return |
| 51 | // false to terminate early. |
| 52 | // |
| 53 | // The supplied string_view is only valid for the duration of the callback |
| 54 | // invocation: the callback must handle copying the underlying string if the |
| 55 | // value needs to be persisted. |
| 56 | // |
| 57 | // Example: |
| 58 | // For container (com.google) |
| 59 | // and unqualified name foo |
| 60 | // |
| 61 | // com.google.foo, com.foo, foo |
| 62 | // |
| 63 | // If aliases are present, they override the normal container resolution. |
| 64 | // |
| 65 | // Example: |
| 66 | // container (com.google) |
| 67 | // alias (foo = com.example) |
| 68 | // unqualified name foo |
| 69 | // |
| 70 | // com.example |
| 71 | void GenerateCandidates( |
| 72 | absl::string_view simple_name, |
| 73 | absl::FunctionRef<bool(absl::string_view)> callback) const; |
| 74 | |
| 75 | // For a partially qualified name, generate all the qualified candidates in |
| 76 | // order of resolution precedence and pass them to the provided callback. The |
| 77 | // callback may return false to terminate early. |
| 78 | // |
| 79 | // The supplied string_view is only valid for the duration of the callback |
| 80 | // invocation: the callback must handle copying the underlying string if the |
| 81 | // value needs to be persisted. |
| 82 | // |
| 83 | // Example: |
| 84 | // For container (com.google) |
| 85 | // and partially qualified name Foo.bar |
| 86 | // |
| 87 | // (com.google.Foo.bar), <com.google.Foo.bar, 1> |
| 88 | // (com.google.Foo).bar, <com.google.Foo, 0> |
| 89 | // (com.Foo.bar), <com.Foo.bar, 1> |
| 90 | // (com.Foo).bar, <com.Foo, 0> |
| 91 | // (Foo.bar), <Foo.bar, 1> |
| 92 | // (Foo).bar, <Foo, 0> |
| 93 | // |
| 94 | // If aliases are present, they override the normal container resolution. |