[PATCH] D17852: Added formatAndApplyAllReplacements that works on multiple files in libTooling.

Eric Liu via cfe-commits cfe-commits at lists.llvm.org
Sun Mar 6 11:58:28 PST 2016

ioeric marked an inline comment as done.

Comment at: include/clang/Tooling/Core/Replacement.h:228
@@ -226,3 +227,3 @@
 /// \pre Replacements must be for the same file.
-calculateChangedRangesInFile(const tooling::Replacements &Replaces);
+std::vector<Range> calculateChangedRangesInFile(const Replacements &Replaces);
djasper wrote:
> This was pre-existing, but I'd remove the "InFile" suffix. It doesn't seem to add any information.
Will remove the "InFile" suffix.

Comment at: include/clang/Tooling/Core/Replacement.h:230
@@ +229,3 @@
+typedef std::map<const std::string, Replacements>
+    FileToReplacementsMap;
djasper wrote:
> I think the key type in a map is always const, so no need for "const".
I think "const" is needed since the `Entry` passed to map's `[]` operator is of type `const FileEntry *` in `FileToReplaces[Entry].push_back(Replace)`. The code didn't compile without the "const" qualifier.  

Comment at: include/clang/Tooling/Core/Replacement.h:235
@@ -229,1 +234,3 @@
+/// related to the same file entry are put into the same vector.
+FileToReplacementsMap groupReplacementsByFile(const Replacements &Replaces);
djasper wrote:
> I also wonder whether this should really return a map. I find such maps in interfaces sometimes a bit difficult as they have some cost and the subsequent analyses might actually prefer a different container. How about instead just returning a vector<Replacements>? I mean the Replacements themselves already have the filename stored in them so the key in the map is redundant anyway.
> Manuel, any thoughts?
But I think the tradeoff of using `vector<Replacements>` is the insertion time since we'd need to index Replcements with the same filename for each insertion. Or maybe we can have a map from filename to vector index as a local variable and return a vector<Replacements>?  


More information about the cfe-commits mailing list