/proc/self/cwd/src/ir/field_selector.h
Line | Count | Source (jump to first uncovered line) |
1 | | //----------------------------------------------------------------------------- |
2 | | // Copyright 2021 Google LLC |
3 | | // |
4 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
5 | | // you may not use this file except in compliance with the License. |
6 | | // You may obtain a copy of the License at |
7 | | // |
8 | | // https://www.apache.org/licenses/LICENSE-2.0 |
9 | | // |
10 | | // Unless required by applicable law or agreed to in writing, software |
11 | | // distributed under the License is distributed on an "AS IS" BASIS, |
12 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | | // See the License for the specific language governing permissions and |
14 | | // limitations under the License. |
15 | | //---------------------------------------------------------------------------- |
16 | | #ifndef SRC_FRONTENDS_ARCS_FIELD_SELECTOR_H_ |
17 | | #define SRC_FRONTENDS_ARCS_FIELD_SELECTOR_H_ |
18 | | |
19 | | #include <string> |
20 | | |
21 | | #include "absl/strings/str_cat.h" |
22 | | |
23 | | namespace raksha::ir { |
24 | | |
25 | | // Represents descending through the type tree by taking the field of an |
26 | | // EntityType in an AccessPath. |
27 | | class FieldSelector { |
28 | | public: |
29 | 0 | FieldSelector(std::string field_name) : field_name_(std::move(field_name)) {} |
30 | | |
31 | 0 | const std::string &field_name() const { return field_name_; } |
32 | | |
33 | | // Prints the string representing dereferencing the field in the AccessPath. |
34 | | // This will just be the "." punctuation plus the name of the field. |
35 | 0 | std::string ToString() const { return absl::StrCat(".", field_name_); } |
36 | | |
37 | | // Two fields selectors are equal exactly when their names are equal. |
38 | 0 | bool operator==(const FieldSelector &other) const { |
39 | 0 | return field_name_ == other.field_name_; |
40 | 0 | } |
41 | | |
42 | | template <typename H> |
43 | 0 | friend H AbslHashValue(H h, const FieldSelector &field_selector) { |
44 | 0 | return H::combine(std::move(h), field_selector.field_name_); |
45 | 0 | } |
46 | | |
47 | | private: |
48 | | // All of the specialness of a FieldSelector is contained within its name. |
49 | | std::string field_name_; |
50 | | }; |
51 | | |
52 | | } // namespace raksha::ir |
53 | | |
54 | | #endif // SRC_FRONTENDS_ARCS_FIELD_SELECTOR_H_ |