================ @@ -0,0 +1,256 @@ +//===-- tools/extra/clang-reorder-fields/utils/Designator.cpp ---*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// This file contains the definition of the DesignatorIter and Designators +/// utility classes. +/// +//===----------------------------------------------------------------------===// + +#include "Designator.h" +#include "clang/AST/ASTContext.h" +#include "clang/AST/Expr.h" + +namespace clang { +namespace reorder_fields { + +DesignatorIter::DesignatorIter(const QualType Type, + RecordDecl::field_iterator Field, + const RecordDecl *RD) + : Tag(STRUCT), Type(Type), StructIt({Field, RD}) {} + +DesignatorIter::DesignatorIter(const QualType Type, uint64_t Idx, uint64_t Size) + : Tag(ARRAY), Type(Type), ArrayIt({Idx, Size}) {} + +DesignatorIter::DesignatorIter(const QualType Type, uint64_t Start, + uint64_t End, uint64_t Size) + : Tag(ARRAY_RANGE), Type(Type), ArrayRangeIt({Start, End, Size}) {} + +DesignatorIter &DesignatorIter::operator++() { + assert(!isFinished() && "Iterator is already finished"); + switch (Tag) { + case STRUCT: + if (StructIt.Record->isUnion()) { + // Union always finishes on first increment. + StructIt.Field = StructIt.Record->field_end(); + Type = QualType(); + break; + } + ++StructIt.Field; + if (StructIt.Field != StructIt.Record->field_end()) { + Type = StructIt.Field->getType(); + } else { + Type = QualType(); + } + break; + case ARRAY: + ++ArrayIt.Index; + break; + case ARRAY_RANGE: + ArrayIt.Index = ArrayRangeIt.End + 1; + ArrayIt.Size = ArrayRangeIt.Size; + Tag = ARRAY; + break; + } + return *this; +} + +bool DesignatorIter::isFinished() { + switch (Tag) { + case STRUCT: + return StructIt.Field == StructIt.Record->field_end(); + case ARRAY: + return ArrayIt.Index == ArrayIt.Size; + case ARRAY_RANGE: + return ArrayRangeIt.End == ArrayRangeIt.Size; + } + return false; +} + +DesignatorIter::Kind DesignatorIter::getTag() const { return Tag; } + +QualType DesignatorIter::getType() const { return Type; } + +RecordDecl::field_iterator &DesignatorIter::getStructIter() { ---------------- legrosbuffle wrote:
Inline all those ? https://github.com/llvm/llvm-project/pull/142150 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits