1 //===--- Replacement.cpp - Framework for clang refactoring tools ----------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 //  Implements classes to support/store refactorings.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "clang/Tooling/Core/Replacement.h"
15 
16 #include "clang/Basic/Diagnostic.h"
17 #include "clang/Basic/DiagnosticIDs.h"
18 #include "clang/Basic/DiagnosticOptions.h"
19 #include "clang/Basic/FileManager.h"
20 #include "clang/Basic/SourceManager.h"
21 #include "clang/Lex/Lexer.h"
22 #include "clang/Rewrite/Core/Rewriter.h"
23 #include "llvm/Support/FileSystem.h"
24 #include "llvm/Support/Path.h"
25 #include "llvm/Support/raw_os_ostream.h"
26 
27 namespace clang {
28 namespace tooling {
29 
30 static const char * const InvalidLocation = "";
31 
32 Replacement::Replacement()
33   : FilePath(InvalidLocation) {}
34 
35 Replacement::Replacement(StringRef FilePath, unsigned Offset, unsigned Length,
36                          StringRef ReplacementText)
37     : FilePath(FilePath), ReplacementRange(Offset, Length),
38       ReplacementText(ReplacementText) {}
39 
40 Replacement::Replacement(const SourceManager &Sources, SourceLocation Start,
41                          unsigned Length, StringRef ReplacementText) {
42   setFromSourceLocation(Sources, Start, Length, ReplacementText);
43 }
44 
45 Replacement::Replacement(const SourceManager &Sources,
46                          const CharSourceRange &Range,
47                          StringRef ReplacementText,
48                          const LangOptions &LangOpts) {
49   setFromSourceRange(Sources, Range, ReplacementText, LangOpts);
50 }
51 
52 bool Replacement::isApplicable() const {
53   return FilePath != InvalidLocation;
54 }
55 
56 bool Replacement::apply(Rewriter &Rewrite) const {
57   SourceManager &SM = Rewrite.getSourceMgr();
58   const FileEntry *Entry = SM.getFileManager().getFile(FilePath);
59   if (!Entry)
60     return false;
61 
62   FileID ID = SM.getOrCreateFileID(Entry, SrcMgr::C_User);
63   const SourceLocation Start =
64     SM.getLocForStartOfFile(ID).
65     getLocWithOffset(ReplacementRange.getOffset());
66   // ReplaceText returns false on success.
67   // ReplaceText only fails if the source location is not a file location, in
68   // which case we already returned false earlier.
69   bool RewriteSucceeded = !Rewrite.ReplaceText(
70       Start, ReplacementRange.getLength(), ReplacementText);
71   assert(RewriteSucceeded);
72   return RewriteSucceeded;
73 }
74 
75 std::string Replacement::toString() const {
76   std::string Result;
77   llvm::raw_string_ostream Stream(Result);
78   Stream << FilePath << ": " << ReplacementRange.getOffset() << ":+"
79          << ReplacementRange.getLength() << ":\"" << ReplacementText << "\"";
80   return Stream.str();
81 }
82 
83 bool operator<(const Replacement &LHS, const Replacement &RHS) {
84   if (LHS.getOffset() != RHS.getOffset())
85     return LHS.getOffset() < RHS.getOffset();
86 
87   if (LHS.getLength() != RHS.getLength())
88     return LHS.getLength() < RHS.getLength();
89 
90   if (LHS.getFilePath() != RHS.getFilePath())
91     return LHS.getFilePath() < RHS.getFilePath();
92   return LHS.getReplacementText() < RHS.getReplacementText();
93 }
94 
95 bool operator==(const Replacement &LHS, const Replacement &RHS) {
96   return LHS.getOffset() == RHS.getOffset() &&
97          LHS.getLength() == RHS.getLength() &&
98          LHS.getFilePath() == RHS.getFilePath() &&
99          LHS.getReplacementText() == RHS.getReplacementText();
100 }
101 
102 void Replacement::setFromSourceLocation(const SourceManager &Sources,
103                                         SourceLocation Start, unsigned Length,
104                                         StringRef ReplacementText) {
105   const std::pair<FileID, unsigned> DecomposedLocation =
106       Sources.getDecomposedLoc(Start);
107   const FileEntry *Entry = Sources.getFileEntryForID(DecomposedLocation.first);
108   this->FilePath = Entry ? Entry->getName() : InvalidLocation;
109   this->ReplacementRange = Range(DecomposedLocation.second, Length);
110   this->ReplacementText = ReplacementText;
111 }
112 
113 // FIXME: This should go into the Lexer, but we need to figure out how
114 // to handle ranges for refactoring in general first - there is no obvious
115 // good way how to integrate this into the Lexer yet.
116 static int getRangeSize(const SourceManager &Sources,
117                         const CharSourceRange &Range,
118                         const LangOptions &LangOpts) {
119   SourceLocation SpellingBegin = Sources.getSpellingLoc(Range.getBegin());
120   SourceLocation SpellingEnd = Sources.getSpellingLoc(Range.getEnd());
121   std::pair<FileID, unsigned> Start = Sources.getDecomposedLoc(SpellingBegin);
122   std::pair<FileID, unsigned> End = Sources.getDecomposedLoc(SpellingEnd);
123   if (Start.first != End.first) return -1;
124   if (Range.isTokenRange())
125     End.second += Lexer::MeasureTokenLength(SpellingEnd, Sources, LangOpts);
126   return End.second - Start.second;
127 }
128 
129 void Replacement::setFromSourceRange(const SourceManager &Sources,
130                                      const CharSourceRange &Range,
131                                      StringRef ReplacementText,
132                                      const LangOptions &LangOpts) {
133   setFromSourceLocation(Sources, Sources.getSpellingLoc(Range.getBegin()),
134                         getRangeSize(Sources, Range, LangOpts),
135                         ReplacementText);
136 }
137 
138 Replacement
139 Replacements::getReplacementInChangedCode(const Replacement &R) const {
140   unsigned NewStart = getShiftedCodePosition(R.getOffset());
141   unsigned NewEnd = getShiftedCodePosition(R.getOffset() + R.getLength());
142   return Replacement(R.getFilePath(), NewStart, NewEnd - NewStart,
143                      R.getReplacementText());
144 }
145 
146 static llvm::Error makeConflictReplacementsError(const Replacement &New,
147                                                  const Replacement &Existing) {
148   return llvm::make_error<llvm::StringError>(
149       "New replacement:\n" + New.toString() +
150           "\nconflicts with existing replacement:\n" + Existing.toString(),
151       llvm::inconvertibleErrorCode());
152 }
153 
154 Replacements Replacements::getCanonicalReplacements() const {
155   std::vector<Replacement> NewReplaces;
156   // Merge adjacent replacements.
157   for (const auto &R : Replaces) {
158     if (NewReplaces.empty()) {
159       NewReplaces.push_back(R);
160       continue;
161     }
162     auto &Prev = NewReplaces.back();
163     unsigned PrevEnd = Prev.getOffset() + Prev.getLength();
164     if (PrevEnd < R.getOffset()) {
165       NewReplaces.push_back(R);
166     } else {
167       assert(PrevEnd == R.getOffset() &&
168              "Existing replacements must not overlap.");
169       Replacement NewR(
170           R.getFilePath(), Prev.getOffset(), Prev.getLength() + R.getLength(),
171           (Prev.getReplacementText() + R.getReplacementText()).str());
172       Prev = NewR;
173     }
174   }
175   ReplacementsImpl NewReplacesImpl(NewReplaces.begin(), NewReplaces.end());
176   return Replacements(NewReplacesImpl.begin(), NewReplacesImpl.end());
177 }
178 
179 // `R` and `Replaces` are order-independent if applying them in either order
180 // has the same effect, so we need to compare replacements associated to
181 // applying them in either order.
182 llvm::Expected<Replacements>
183 Replacements::mergeIfOrderIndependent(const Replacement &R) const {
184   Replacements Rs(R);
185   // A Replacements set containg a single replacement that is `R` referring to
186   // the code after the existing replacements `Replaces` are applied.
187   Replacements RsShiftedByReplaces(getReplacementInChangedCode(R));
188   // A Replacements set that is `Replaces` referring to the code after `R` is
189   // applied.
190   Replacements ReplacesShiftedByRs;
191   for (const auto &Replace : Replaces)
192     ReplacesShiftedByRs.Replaces.insert(
193         Rs.getReplacementInChangedCode(Replace));
194   // This is equivalent to applying `Replaces` first and then `R`.
195   auto MergeShiftedRs = merge(RsShiftedByReplaces);
196   // This is equivalent to applying `R` first and then `Replaces`.
197   auto MergeShiftedReplaces = Rs.merge(ReplacesShiftedByRs);
198 
199   // Since empty or segmented replacements around existing replacements might be
200   // produced above, we need to compare replacements in canonical forms.
201   if (MergeShiftedRs.getCanonicalReplacements() ==
202       MergeShiftedReplaces.getCanonicalReplacements())
203     return MergeShiftedRs;
204   return makeConflictReplacementsError(R, *Replaces.begin());
205 }
206 
207 llvm::Error Replacements::add(const Replacement &R) {
208   // Check the file path.
209   if (!Replaces.empty() && R.getFilePath() != Replaces.begin()->getFilePath())
210     return llvm::make_error<llvm::StringError>(
211         "All replacements must have the same file path. New replacement: " +
212             R.getFilePath() + ", existing replacements: " +
213             Replaces.begin()->getFilePath() + "\n",
214         llvm::inconvertibleErrorCode());
215 
216   // Special-case header insertions.
217   if (R.getOffset() == UINT_MAX) {
218     Replaces.insert(R);
219     return llvm::Error::success();
220   }
221 
222   // This replacement cannot conflict with replacements that end before
223   // this replacement starts or start after this replacement ends.
224   // We also know that there currently are no overlapping replacements.
225   // Thus, we know that all replacements that start after the end of the current
226   // replacement cannot overlap.
227   Replacement AtEnd(R.getFilePath(), R.getOffset() + R.getLength(), 0, "");
228 
229   // Find the first entry that starts after or at the end of R. Note that
230   // entries that start at the end can still be conflicting if R is an
231   // insertion.
232   auto I = Replaces.lower_bound(AtEnd);
233   // If `I` starts at the same offset as `R`, `R` must be an insertion.
234   if (I != Replaces.end() && R.getOffset() == I->getOffset()) {
235     assert(R.getLength() == 0);
236     // `I` is also an insertion, `R` and `I` conflict.
237     if (I->getLength() == 0) {
238       // Check if two insertions are order-indepedent: if inserting them in
239       // either order produces the same text, they are order-independent.
240       if ((R.getReplacementText() + I->getReplacementText()).str() !=
241           (I->getReplacementText() + R.getReplacementText()).str()) {
242         return makeConflictReplacementsError(R, *I);
243       }
244       // If insertions are order-independent, we can merge them.
245       Replacement NewR(
246           R.getFilePath(), R.getOffset(), 0,
247           (R.getReplacementText() + I->getReplacementText()).str());
248       Replaces.erase(I);
249       Replaces.insert(std::move(NewR));
250       return llvm::Error::success();
251     }
252     // Insertion `R` is adjacent to a non-insertion replacement `I`, so they
253     // are order-independent. It is safe to assume that `R` will not conflict
254     // with any replacement before `I` since all replacements before `I` must
255     // either end before `R` or end at `R` but has length > 0 (if the
256     // replacement before `I` is an insertion at `R`, it would have been `I`
257     // since it is a lower bound of `AtEnd` and ordered before the current `I`
258     // in the set).
259     Replaces.insert(R);
260     return llvm::Error::success();
261   }
262 
263   // `I` is the smallest iterator (after `R`) whose entry cannot overlap.
264   // If that is begin(), there are no overlaps.
265   if (I == Replaces.begin()) {
266     Replaces.insert(R);
267     return llvm::Error::success();
268   }
269   --I;
270   auto Overlap = [](const Replacement &R1, const Replacement &R2) -> bool {
271     return Range(R1.getOffset(), R1.getLength())
272         .overlapsWith(Range(R2.getOffset(), R2.getLength()));
273   };
274   // If the previous entry does not overlap, we know that entries before it
275   // can also not overlap.
276   if (!Overlap(R, *I)) {
277     // If `R` and `I` do not have the same offset, it is safe to add `R` since
278     // it must come after `I`. Otherwise:
279     //   - If `R` is an insertion, `I` must not be an insertion since it would
280     //   have come after `AtEnd`.
281     //   - If `R` is not an insertion, `I` must be an insertion; otherwise, `R`
282     //   and `I` would have overlapped.
283     // In either case, we can safely insert `R`.
284     Replaces.insert(R);
285   } else {
286     // `I` overlaps with `R`. We need to check `R` against all overlapping
287     // replacements to see if they are order-indepedent. If they are, merge `R`
288     // with them and replace them with the merged replacements.
289     auto MergeBegin = I;
290     auto MergeEnd = std::next(I);
291     while (I != Replaces.begin()) {
292       --I;
293       // If `I` doesn't overlap with `R`, don't merge it.
294       if (!Overlap(R, *I))
295         break;
296       MergeBegin = I;
297     }
298     Replacements OverlapReplaces(MergeBegin, MergeEnd);
299     llvm::Expected<Replacements> Merged =
300         OverlapReplaces.mergeIfOrderIndependent(R);
301     if (!Merged)
302       return Merged.takeError();
303     Replaces.erase(MergeBegin, MergeEnd);
304     Replaces.insert(Merged->begin(), Merged->end());
305   }
306   return llvm::Error::success();
307 }
308 
309 namespace {
310 
311 // Represents a merged replacement, i.e. a replacement consisting of multiple
312 // overlapping replacements from 'First' and 'Second' in mergeReplacements.
313 //
314 // Position projection:
315 // Offsets and lengths of the replacements can generally refer to two different
316 // coordinate spaces. Replacements from 'First' refer to the original text
317 // whereas replacements from 'Second' refer to the text after applying 'First'.
318 //
319 // MergedReplacement always operates in the coordinate space of the original
320 // text, i.e. transforms elements from 'Second' to take into account what was
321 // changed based on the elements from 'First'.
322 //
323 // We can correctly calculate this projection as we look at the replacements in
324 // order of strictly increasing offsets.
325 //
326 // Invariants:
327 // * We always merge elements from 'First' into elements from 'Second' and vice
328 //   versa. Within each set, the replacements are non-overlapping.
329 // * We only extend to the right, i.e. merge elements with strictly increasing
330 //   offsets.
331 class MergedReplacement {
332 public:
333   MergedReplacement(const Replacement &R, bool MergeSecond, int D)
334       : MergeSecond(MergeSecond), Delta(D), FilePath(R.getFilePath()),
335         Offset(R.getOffset() + (MergeSecond ? 0 : Delta)), Length(R.getLength()),
336         Text(R.getReplacementText()) {
337     Delta += MergeSecond ? 0 : Text.size() - Length;
338     DeltaFirst = MergeSecond ? Text.size() - Length : 0;
339   }
340 
341   // Merges the next element 'R' into this merged element. As we always merge
342   // from 'First' into 'Second' or vice versa, the MergedReplacement knows what
343   // set the next element is coming from.
344   void merge(const Replacement &R) {
345     if (MergeSecond) {
346       unsigned REnd = R.getOffset() + Delta + R.getLength();
347       unsigned End = Offset + Text.size();
348       if (REnd > End) {
349         Length += REnd - End;
350         MergeSecond = false;
351       }
352       StringRef TextRef = Text;
353       StringRef Head = TextRef.substr(0, R.getOffset() + Delta - Offset);
354       StringRef Tail = TextRef.substr(REnd - Offset);
355       Text = (Head + R.getReplacementText() + Tail).str();
356       Delta += R.getReplacementText().size() - R.getLength();
357     } else {
358       unsigned End = Offset + Length;
359       StringRef RText = R.getReplacementText();
360       StringRef Tail = RText.substr(End - R.getOffset());
361       Text = (Text + Tail).str();
362       if (R.getOffset() + RText.size() > End) {
363         Length = R.getOffset() + R.getLength() - Offset;
364         MergeSecond = true;
365       } else {
366         Length += R.getLength() - RText.size();
367       }
368       DeltaFirst += RText.size() - R.getLength();
369     }
370   }
371 
372   // Returns 'true' if 'R' starts strictly after the MergedReplacement and thus
373   // doesn't need to be merged.
374   bool endsBefore(const Replacement &R) const {
375     if (MergeSecond)
376       return Offset + Text.size() < R.getOffset() + Delta;
377     return Offset + Length < R.getOffset();
378   }
379 
380   // Returns 'true' if an element from the second set should be merged next.
381   bool mergeSecond() const { return MergeSecond; }
382   int deltaFirst() const { return DeltaFirst; }
383   Replacement asReplacement() const { return {FilePath, Offset, Length, Text}; }
384 
385 private:
386   bool MergeSecond;
387 
388   // Amount of characters that elements from 'Second' need to be shifted by in
389   // order to refer to the original text.
390   int Delta;
391 
392   // Sum of all deltas (text-length - length) of elements from 'First' merged
393   // into this element. This is used to update 'Delta' once the
394   // MergedReplacement is completed.
395   int DeltaFirst;
396 
397   // Data of the actually merged replacement. FilePath and Offset aren't changed
398   // as the element is only extended to the right.
399   const StringRef FilePath;
400   const unsigned Offset;
401   unsigned Length;
402   std::string Text;
403 };
404 
405 } // namespace
406 
407 Replacements Replacements::merge(const Replacements &ReplacesToMerge) const {
408   if (empty() || ReplacesToMerge.empty())
409     return empty() ? ReplacesToMerge : *this;
410 
411   auto &First = Replaces;
412   auto &Second = ReplacesToMerge.Replaces;
413   // Delta is the amount of characters that replacements from 'Second' need to
414   // be shifted so that their offsets refer to the original text.
415   int Delta = 0;
416   ReplacementsImpl Result;
417 
418   // Iterate over both sets and always add the next element (smallest total
419   // Offset) from either 'First' or 'Second'. Merge that element with
420   // subsequent replacements as long as they overlap. See more details in the
421   // comment on MergedReplacement.
422   for (auto FirstI = First.begin(), SecondI = Second.begin();
423        FirstI != First.end() || SecondI != Second.end();) {
424     bool NextIsFirst = SecondI == Second.end() ||
425                        (FirstI != First.end() &&
426                         FirstI->getOffset() < SecondI->getOffset() + Delta);
427     MergedReplacement Merged(NextIsFirst ? *FirstI : *SecondI, NextIsFirst,
428                              Delta);
429     ++(NextIsFirst ? FirstI : SecondI);
430 
431     while ((Merged.mergeSecond() && SecondI != Second.end()) ||
432            (!Merged.mergeSecond() && FirstI != First.end())) {
433       auto &I = Merged.mergeSecond() ? SecondI : FirstI;
434       if (Merged.endsBefore(*I))
435         break;
436       Merged.merge(*I);
437       ++I;
438     }
439     Delta -= Merged.deltaFirst();
440     Result.insert(Merged.asReplacement());
441   }
442   return Replacements(Result.begin(), Result.end());
443 }
444 
445 // Combines overlapping ranges in \p Ranges and sorts the combined ranges.
446 // Returns a set of non-overlapping and sorted ranges that is equivalent to
447 // \p Ranges.
448 static std::vector<Range> combineAndSortRanges(std::vector<Range> Ranges) {
449   std::sort(Ranges.begin(), Ranges.end(),
450             [](const Range &LHS, const Range &RHS) {
451               if (LHS.getOffset() != RHS.getOffset())
452                 return LHS.getOffset() < RHS.getOffset();
453               return LHS.getLength() < RHS.getLength();
454             });
455   std::vector<Range> Result;
456   for (const auto &R : Ranges) {
457     if (Result.empty() ||
458         Result.back().getOffset() + Result.back().getLength() < R.getOffset()) {
459       Result.push_back(R);
460     } else {
461       unsigned NewEnd =
462           std::max(Result.back().getOffset() + Result.back().getLength(),
463                    R.getOffset() + R.getLength());
464       Result[Result.size() - 1] =
465           Range(Result.back().getOffset(), NewEnd - Result.back().getOffset());
466     }
467   }
468   return Result;
469 }
470 
471 std::vector<Range>
472 calculateRangesAfterReplacements(const Replacements &Replaces,
473                                  const std::vector<Range> &Ranges) {
474   // To calculate the new ranges,
475   //   - Turn \p Ranges into Replacements at (offset, length) with an empty
476   //     (unimportant) replacement text of length "length".
477   //   - Merge with \p Replaces.
478   //   - The new ranges will be the affected ranges of the merged replacements.
479   auto MergedRanges = combineAndSortRanges(Ranges);
480   if (Replaces.empty())
481     return MergedRanges;
482   tooling::Replacements FakeReplaces;
483   for (const auto &R : MergedRanges) {
484     auto Err = FakeReplaces.add(Replacement(Replaces.begin()->getFilePath(),
485                                             R.getOffset(), R.getLength(),
486                                             std::string(R.getLength(), ' ')));
487     assert(!Err &&
488            "Replacements must not conflict since ranges have been merged.");
489     (void)Err;
490   }
491   return FakeReplaces.merge(Replaces).getAffectedRanges();
492 }
493 
494 std::vector<Range> Replacements::getAffectedRanges() const {
495   std::vector<Range> ChangedRanges;
496   int Shift = 0;
497   for (const Replacement &R : Replaces) {
498     unsigned Offset = R.getOffset() + Shift;
499     unsigned Length = R.getReplacementText().size();
500     Shift += Length - R.getLength();
501     ChangedRanges.push_back(Range(Offset, Length));
502   }
503   return combineAndSortRanges(ChangedRanges);
504 }
505 
506 unsigned Replacements::getShiftedCodePosition(unsigned Position) const {
507   unsigned Offset = 0;
508   for (const auto& R : Replaces) {
509     if (R.getOffset() + R.getLength() <= Position) {
510       Offset += R.getReplacementText().size() - R.getLength();
511       continue;
512     }
513     if (R.getOffset() < Position &&
514         R.getOffset() + R.getReplacementText().size() <= Position) {
515       Position = R.getOffset() + R.getReplacementText().size();
516       if (R.getReplacementText().size() > 0)
517         Position--;
518     }
519     break;
520   }
521   return Position + Offset;
522 }
523 
524 bool applyAllReplacements(const Replacements &Replaces, Rewriter &Rewrite) {
525   bool Result = true;
526   for (auto I = Replaces.rbegin(), E = Replaces.rend(); I != E; ++I) {
527     if (I->isApplicable()) {
528       Result = I->apply(Rewrite) && Result;
529     } else {
530       Result = false;
531     }
532   }
533   return Result;
534 }
535 
536 llvm::Expected<std::string> applyAllReplacements(StringRef Code,
537                                                 const Replacements &Replaces) {
538   if (Replaces.empty())
539     return Code.str();
540 
541   IntrusiveRefCntPtr<vfs::InMemoryFileSystem> InMemoryFileSystem(
542       new vfs::InMemoryFileSystem);
543   FileManager Files(FileSystemOptions(), InMemoryFileSystem);
544   DiagnosticsEngine Diagnostics(
545       IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs),
546       new DiagnosticOptions);
547   SourceManager SourceMgr(Diagnostics, Files);
548   Rewriter Rewrite(SourceMgr, LangOptions());
549   InMemoryFileSystem->addFile(
550       "<stdin>", 0, llvm::MemoryBuffer::getMemBuffer(Code, "<stdin>"));
551   FileID ID = SourceMgr.createFileID(Files.getFile("<stdin>"), SourceLocation(),
552                                      clang::SrcMgr::C_User);
553   for (auto I = Replaces.rbegin(), E = Replaces.rend(); I != E; ++I) {
554     Replacement Replace("<stdin>", I->getOffset(), I->getLength(),
555                         I->getReplacementText());
556     if (!Replace.apply(Rewrite))
557       return llvm::make_error<llvm::StringError>(
558           "Failed to apply replacement: " + Replace.toString(),
559           llvm::inconvertibleErrorCode());
560   }
561   std::string Result;
562   llvm::raw_string_ostream OS(Result);
563   Rewrite.getEditBuffer(ID).write(OS);
564   OS.flush();
565   return Result;
566 }
567 
568 std::map<std::string, Replacements> groupReplacementsByFile(
569     const std::map<std::string, Replacements> &FileToReplaces) {
570   std::map<std::string, Replacements> Result;
571   for (const auto &Entry : FileToReplaces) {
572     llvm::SmallString<256> CleanPath(Entry.first.data());
573     llvm::sys::path::remove_dots(CleanPath, /*remove_dot_dot=*/true);
574     Result[CleanPath.str()] = std::move(Entry.second);
575   }
576   return Result;
577 }
578 
579 } // end namespace tooling
580 } // end namespace clang
581