#pragma once // // This file is distributed under the MIT License. See LICENSE.md for details. // #include "revng/Model/Binary.h" #include "revng/TupleTree/Visits.h" // // getByPath // namespace tupletree::detail { template struct GetByPathVisitor { ResultT *Result = nullptr; template void visitContainerElement(KeyT, K &) { Result = nullptr; } template void visitContainerElement(KeyT, ResultT &Element) { Result = ∈ } template void visitTupleElement(K &) { Result = nullptr; } template void visitTupleElement(ResultT &Element) { Result = ∈ } }; } // namespace tupletree::detail template ResultT *getByPath(const TupleTreePath &Path, RootT &M) { using namespace tupletree::detail; GetByPathVisitor GBPV; if (not callByPath(GBPV, Path, M)) { return nullptr; } return GBPV.Result; } // // stringAsPath // template std::optional stringAsPath(llvm::StringRef Path) { if (Path.empty()) return std::nullopt; auto Result = PathMatcher::create(Path); if (Result) return Result->path(); else return std::nullopt; } // // PathMatcher // template std::optional PathMatcher::create(llvm::StringRef Path) { revng_assert(Path.startswith("/")); PathMatcher Result; if (visitTupleTreeNode(Path.substr(1), Result)) return Result; else return {}; }