/******************************************************************************** * Copyright (C) 2026 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * * * This software is distributed under the terms of the * * GNU Lesser General Public Licence (LGPL) version 3, * * copied verbatim in the file "LICENSE" * ********************************************************************************/ #include #include #include #include namespace fair::mq::tidy { using namespace clang; bool isDiscarded(Expr const& e, ASTContext& ctx) { DynTypedNode node = DynTypedNode::create(e); while (true) { auto const parents = ctx.getParents(node); if (parents.size() != 1) { return false; } auto const& parent = parents[0]; if (parent.get() || parent.get()) { node = parent; continue; } auto const* stmt = node.get(); if (parent.get() || parent.get() || parent.get() || parent.get() || parent.get()) { return true; } if (auto const* s = parent.get()) { return stmt == s->getThen() || stmt == s->getElse(); } if (auto const* s = parent.get()) { return stmt == s->getBody(); } if (auto const* s = parent.get()) { return stmt == s->getBody(); } if (auto const* s = parent.get()) { return stmt == s->getBody() || stmt == s->getInc(); } if (auto const* s = parent.get()) { return stmt == s->getBody(); } return false; } } } // namespace fair::mq::tidy