static
| 176 | |
| 177 | // static |
| 178 | bool ExprToSubfieldFilterParser::toSubfield( |
| 179 | const core::ITypedExpr* field, |
| 180 | common::Subfield& subfield) { |
| 181 | std::vector<std::unique_ptr<common::Subfield::PathElement>> path; |
| 182 | for (auto* current = field;;) { |
| 183 | if (auto* fieldAccess = |
| 184 | dynamic_cast<const core::FieldAccessTypedExpr*>(current)) { |
| 185 | path.push_back( |
| 186 | std::make_unique<common::Subfield::NestedField>(fieldAccess->name())); |
| 187 | } else if ( |
| 188 | auto* dereference = |
| 189 | dynamic_cast<const core::DereferenceTypedExpr*>(current)) { |
| 190 | const auto& name = dereference->name(); |
| 191 | // When the field name is empty string, it typically means that the |
| 192 | // field name was not set in the parent type. |
| 193 | if (name.empty()) { |
| 194 | return false; |
| 195 | } |
| 196 | path.push_back(std::make_unique<common::Subfield::NestedField>(name)); |
| 197 | } else if (dynamic_cast<const core::InputTypedExpr*>(current) == nullptr) { |
| 198 | return false; |
| 199 | } else { |
| 200 | break; |
| 201 | } |
| 202 | |
| 203 | if (current->inputs().empty()) { |
| 204 | break; |
| 205 | } |
| 206 | if (current->inputs().size() != 1) { |
| 207 | return false; |
| 208 | } |
| 209 | current = current->inputs()[0].get(); |
| 210 | if (current == nullptr) { |
| 211 | return false; |
| 212 | } |
| 213 | } |
| 214 | std::reverse(path.begin(), path.end()); |
| 215 | subfield = common::Subfield(std::move(path)); |
| 216 | return true; |
| 217 | } |
| 218 | |
| 219 | // static |
| 220 | std::unique_ptr<common::Filter> ExprToSubfieldFilterParser::makeNotEqualFilter( |