[PATCH] D151048: [clang][ExtractAPI] Modify declaration fragment methods to add a new fragment at an arbitrary offset.
R4444 via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue May 30 15:31:07 PDT 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG135ce2f820d8: [clang][ExtractAPI] Modify declaration fragment methods to add a new fragment… (authored by Ruturaj4).
Changed prior to commit:
https://reviews.llvm.org/D151048?vs=526296&id=526816#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D151048/new/
https://reviews.llvm.org/D151048
Files:
clang/include/clang/ExtractAPI/DeclarationFragments.h
clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
Index: clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
===================================================================
--- clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
+++ clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
@@ -110,15 +110,16 @@
static void modifyRecords(const T &Records, const StringRef &Name) {
for (const auto &Record : Records) {
if (Name == Record.second.get()->Name) {
- Record.second.get()->Declaration.removeLast();
Record.second.get()
->Declaration
- .appendFront(" ", DeclarationFragments::FragmentKind::Text)
- .appendFront("typedef", DeclarationFragments::FragmentKind::Keyword,
- "", nullptr)
- .append(" { ... } ", DeclarationFragments::FragmentKind::Text)
- .append(Name, DeclarationFragments::FragmentKind::Identifier)
- .append(";", DeclarationFragments::FragmentKind::Text);
+ .insertAtIndex(0, "typedef",
+ DeclarationFragments::FragmentKind::Keyword, "",
+ nullptr)
+ .insertAtIndex(1, " ", DeclarationFragments::FragmentKind::Text)
+ .insertAtIndex(-1, " { ... } ",
+ DeclarationFragments::FragmentKind::Text)
+ .insertAtIndex(-1, Name,
+ DeclarationFragments::FragmentKind::Identifier);
break;
}
}
Index: clang/include/clang/ExtractAPI/DeclarationFragments.h
===================================================================
--- clang/include/clang/ExtractAPI/DeclarationFragments.h
+++ clang/include/clang/ExtractAPI/DeclarationFragments.h
@@ -99,25 +99,37 @@
const std::vector<Fragment> &getFragments() const { return Fragments; }
- // Add a new Fragment to the beginning of the Fragments.
- DeclarationFragments &appendFront(StringRef Spelling, FragmentKind Kind,
- StringRef PreciseIdentifier = "",
- const Decl *Declaration = nullptr) {
- Fragments.emplace(Fragments.begin(), Spelling, Kind, PreciseIdentifier,
- Declaration);
+ 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);
+ }
+
+ // 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)));
return *this;
}
- DeclarationFragments &appendFront(DeclarationFragments &&Other) {
- Fragments.insert(Fragments.begin(),
+ DeclarationFragments &insertAtIndex(intmax_t Index,
+ DeclarationFragments &&Other) {
+ Fragments.insert(Fragments.begin() + calculateOffset(Index),
std::make_move_iterator(Other.Fragments.begin()),
std::make_move_iterator(Other.Fragments.end()));
Other.Fragments.clear();
return *this;
}
- void removeLast() { Fragments.pop_back(); }
-
/// Append a new Fragment to the end of the Fragments.
///
/// \returns a reference to the DeclarationFragments object itself after
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151048.526816.patch
Type: text/x-patch
Size: 3642 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230530/def94993/attachment-0001.bin>
More information about the cfe-commits
mailing list