compareLabelsLexicographicNumeric(StringRef A, StringRef B) {
37SmallVector<StringRef, 2> NamesA;
38A.split(NamesA,
"::",
-1,
false);
39SmallVector<StringRef, 2> NamesB;
40B.split(NamesB,
"::",
-1,
false);
41 size_tSizeA = NamesA.size();
42 size_tSizeB = NamesB.size();
43 for(
size_tI = 0,
E= std::min(SizeA, SizeB); I <
E; ++I) {
52 returnNamesA[I].compare_insensitive(NamesB[I]);
61 int C= NamesA[I].compare_insensitive(NamesB[I]);
68intcompareLabelsLexicographic(StringRef A, StringRef B) {
69SmallVector<StringRef, 2> NamesA;
70A.split(NamesA,
"::",
-1,
false);
71SmallVector<StringRef, 2> NamesB;
72B.split(NamesB,
"::",
-1,
false);
73 size_tSizeA = NamesA.size();
74 size_tSizeB = NamesB.size();
75 for(
size_tI = 0,
E= std::min(SizeA, SizeB); I <
E; ++I) {
77 int C= NamesA[I].compare_insensitive(NamesB[I]);
83 returnSizeA == SizeB ? 0 : 1;
87StringRef A, StringRef B,
90 returncompareLabelsLexicographicNumeric(A, B);
91 returncompareLabelsLexicographic(A, B);
94structUsingDeclaration {
95 constAnnotatedLine *Line;
98UsingDeclaration(
constAnnotatedLine *Line,
conststd::string &Label)
110std::string computeUsingDeclarationLabel(
constFormatToken *UsingTok) {
111assert(UsingTok && UsingTok->is(tok::kw_using) &&
"Expecting a using token");
113 constFormatToken *Tok = UsingTok->Next;
114 if(Tok && Tok->is(tok::kw_typename)) {
115 Label.append(
"typename ");
118 if(Tok && Tok->is(tok::coloncolon)) {
119 Label.append(
"::");
122 boolHasIdentifier =
false;
123 while(Tok && Tok->is(tok::identifier)) {
124HasIdentifier =
true;
125 Label.append(Tok->TokenText.str());
127 if(!Tok || Tok->isNot(tok::coloncolon))
129 Label.append(
"::");
132 if(HasIdentifier && Tok && Tok->isOneOf(tok::semi, tok::comma))
137voidendUsingDeclarationBlock(
138SmallVectorImpl<UsingDeclaration> *UsingDeclarations,
139 constSourceManager &SourceMgr, tooling::Replacements *Fixes,
141 boolBlockAffected =
false;
142 for(
constUsingDeclaration &
Declaration: *UsingDeclarations) {
144BlockAffected =
true;
148 if(!BlockAffected) {
149UsingDeclarations->clear();
152SmallVector<UsingDeclaration, 4> SortedUsingDeclarations(
153UsingDeclarations->begin(), UsingDeclarations->end());
154 auto Comp= [SortUsingDeclarations](
constUsingDeclaration &Lhs,
155 constUsingDeclaration &Rhs) ->
bool{
156 returncompareLabels(Lhs.Label, Rhs.Label, SortUsingDeclarations) < 0;
158llvm::stable_sort(SortedUsingDeclarations, Comp);
159SortedUsingDeclarations.erase(
160std::unique(SortedUsingDeclarations.begin(),
161SortedUsingDeclarations.end(),
162[](
constUsingDeclaration &a,
constUsingDeclaration &
b) {
163return a.Label == b.Label;
165SortedUsingDeclarations.end());
166 for(
size_tI = 0,
E= UsingDeclarations->size(); I <
E; ++I) {
167 if(I >= SortedUsingDeclarations.size()) {
170(*UsingDeclarations)[I].Line->First->WhitespaceRange.getBegin();
171 autoEnd = (*UsingDeclarations)[I].Line->Last->Tok.getEndLoc();
173 autoErr = Fixes->add(tooling::Replacement(SourceMgr,
Range,
""));
175llvm::errs() <<
"Error while sorting using declarations: " 176<< llvm::toString(std::move(Err)) <<
"\n";
180 if((*UsingDeclarations)[I].
Line== SortedUsingDeclarations[I].
Line)
182 auto Begin= (*UsingDeclarations)[I].Line->First->Tok.getLocation();
183 autoEnd = (*UsingDeclarations)[I].Line->Last->Tok.getEndLoc();
185SortedUsingDeclarations[I].Line->First->Tok.getLocation();
186 autoSortedEnd = SortedUsingDeclarations[I].Line->Last->Tok.getEndLoc();
187StringRef
Text(SourceMgr.getCharacterData(SortedBegin),
188SourceMgr.getCharacterData(SortedEnd) -
189SourceMgr.getCharacterData(SortedBegin));
191StringRef OldText(SourceMgr.getCharacterData(
Begin),
192SourceMgr.getCharacterData(End) -
193SourceMgr.getCharacterData(
Begin));
194llvm::dbgs() <<
"Replacing '"<< OldText <<
"' with '"<<
Text<<
"'\n";
197 autoErr = Fixes->add(tooling::Replacement(SourceMgr,
Range,
Text));
199llvm::errs() <<
"Error while sorting using declarations: " 200<< llvm::toString(std::move(Err)) <<
"\n";
203UsingDeclarations->clear();
220 const auto*FirstTok =
Line->First;
221 if(
Line->InPPDirective || !
Line->startsWith(tok::kw_using) ||
222FirstTok->Finalized) {
223endUsingDeclarationBlock(&UsingDeclarations, SourceMgr, &Fixes,
227 if(FirstTok->NewlinesBefore > 1) {
228endUsingDeclarationBlock(&UsingDeclarations, SourceMgr, &Fixes,
231 const auto*UsingTok =
232FirstTok->is(tok::comment) ? FirstTok->getNextNonComment() : FirstTok;
233std::string
Label= computeUsingDeclarationLabel(UsingTok);
234 if(
Label.empty()) {
235endUsingDeclarationBlock(&UsingDeclarations, SourceMgr, &Fixes,
239UsingDeclarations.push_back(UsingDeclaration(
Line,
Label));
241endUsingDeclarationBlock(&UsingDeclarations, SourceMgr, &Fixes,
Various functions to configurably format source code.
This file declares UsingDeclarationsSorter, a TokenAnalyzer that sorts consecutive using declarations...
static CharSourceRange getCharRange(SourceRange R)
This class handles loading and caching of source files into memory.
bool computeAffectedLines(SmallVectorImpl< AnnotatedLine * > &Lines)
SourceManager & getSourceManager() const
AffectedRangeManager AffectedRangeMgr
Determines extra information about the tokens comprising an UnwrappedLine.
std::pair< tooling::Replacements, unsigned > analyze(TokenAnnotator &Annotator, SmallVectorImpl< AnnotatedLine * > &AnnotatedLines, FormatTokenLexer &Tokens) override
UsingDeclarationsSorter(const Environment &Env, const FormatStyle &Style)
bool Comp(InterpState &S, CodePtr OpPC)
1) Pops the value from the stack.
The JSON file list parser is used to communicate input to InstallAPI.
The FormatStyle is used to configure the formatting to follow specific guidelines.
SortUsingDeclarationsOptions
Using declaration sorting options.
@ SUD_LexicographicNumeric
Using declarations are sorted in the order defined as follows: Split the strings by :: and discard an...
SortUsingDeclarationsOptions SortUsingDeclarations
Controls if and how clang-format will sort using declarations.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4