[clang] 92180da - [clang][ExtractAPI] Modify declaration fragment methods to add a new fragment at an arbitrary offset.
via cfe-commits
cfe-commits at lists.llvm.org
Tue May 30 15:31:06 PDT 2023
Author: ruturaj4
Date: 2023-05-30T17:30:22-05:00
New Revision: 92180dae775f66193069279ee7532735ea2fee06
URL: https://github.com/llvm/llvm-project/commit/92180dae775f66193069279ee7532735ea2fee06
DIFF: https://github.com/llvm/llvm-project/commit/92180dae775f66193069279ee7532735ea2fee06.diff
LOG: [clang][ExtractAPI] Modify declaration fragment methods to add a new fragment at an arbitrary offset.
Added:
Modified:
clang/include/clang/ExtractAPI/DeclarationFragments.h
clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
Removed:
################################################################################
diff --git a/clang/include/clang/ExtractAPI/DeclarationFragments.h b/clang/include/clang/ExtractAPI/DeclarationFragments.h
index 0eb240d2b593..4c1b83080704 100644
--- a/clang/include/clang/ExtractAPI/DeclarationFragments.h
+++ b/clang/include/clang/ExtractAPI/DeclarationFragments.h
@@ -97,34 +97,32 @@ class DeclarationFragments {
Declaration(Declaration) {}
};
+ using FragmentIterator = std::vector<Fragment>::iterator;
+ using ConstFragmentIterator = std::vector<Fragment>::const_iterator;
+
const std::vector<Fragment> &getFragments() const { return Fragments; }
- size_t calculateOffset(intmax_t Index) const {
- if (Index >= 0) {
- size_t offset = static_cast<size_t>(Index);
- if (offset > Fragments.size()) {
- offset = Fragments.size();
- }
- return offset;
- }
- return Fragments.size() + static_cast<size_t>(Index);
- }
+ FragmentIterator begin() { return Fragments.begin(); }
+
+ FragmentIterator end() { return Fragments.end(); }
+
+ ConstFragmentIterator cbegin() const { return Fragments.cbegin(); }
+
+ ConstFragmentIterator cend() const { return Fragments.cend(); }
// Add a new Fragment at an arbitrary offset.
- DeclarationFragments &insertAtIndex(intmax_t Index, StringRef Spelling,
- FragmentKind Kind,
- StringRef PreciseIdentifier = "",
- const Decl *Declaration = nullptr) {
- Fragments.insert(
- Fragments.begin() + calculateOffset(Index),
- std::move(Fragment(Spelling, Kind, PreciseIdentifier, Declaration)));
+ DeclarationFragments &insert(FragmentIterator It, StringRef Spelling,
+ FragmentKind Kind,
+ StringRef PreciseIdentifier = "",
+ const Decl *Declaration = nullptr) {
+ Fragments.insert(It, std::move(Fragment(Spelling, Kind, PreciseIdentifier,
+ Declaration)));
return *this;
}
- DeclarationFragments &insertAtIndex(intmax_t Index,
- DeclarationFragments &&Other) {
- Fragments.insert(Fragments.begin() + calculateOffset(Index),
- std::make_move_iterator(Other.Fragments.begin()),
+ DeclarationFragments &insert(FragmentIterator It,
+ DeclarationFragments &&Other) {
+ Fragments.insert(It, std::make_move_iterator(Other.Fragments.begin()),
std::make_move_iterator(Other.Fragments.end()));
Other.Fragments.clear();
return *this;
diff --git a/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h b/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
index 1b82f2604403..f0882afb5a61 100644
--- a/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
+++ b/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
@@ -110,16 +110,16 @@ template <typename T>
static void modifyRecords(const T &Records, const StringRef &Name) {
for (const auto &Record : Records) {
if (Name == Record.second.get()->Name) {
- Record.second.get()
- ->Declaration
- .insertAtIndex(0, "typedef",
- DeclarationFragments::FragmentKind::Keyword, "",
- nullptr)
- .insertAtIndex(1, " ", DeclarationFragments::FragmentKind::Text)
- .insertAtIndex(-1, " { ... } ",
- DeclarationFragments::FragmentKind::Text)
- .insertAtIndex(-1, Name,
- DeclarationFragments::FragmentKind::Identifier);
+ auto &DeclFragment = Record.second->Declaration;
+ DeclFragment.insert(DeclFragment.begin(), " ",
+ DeclarationFragments::FragmentKind::Text);
+ DeclFragment.insert(DeclFragment.begin(), "typedef",
+ DeclarationFragments::FragmentKind::Keyword, "",
+ nullptr);
+ DeclFragment.insert(--DeclFragment.end(), " { ... } ",
+ DeclarationFragments::FragmentKind::Text);
+ DeclFragment.insert(--DeclFragment.end(), Name,
+ DeclarationFragments::FragmentKind::Identifier);
break;
}
}
More information about the cfe-commits
mailing list