[PATCH] D93703: [libTooling] Change `addInclude` to use expansion locs.
Yitzhak Mandelbaum via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 14 19:13:51 PST 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1fabe6e51917: [libTooling] Change `addInclude` to use expansion locs. (authored by ymandel).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D93703/new/
https://reviews.llvm.org/D93703
Files:
clang/include/clang/Tooling/Transformer/RewriteRule.h
clang/lib/Tooling/Transformer/RewriteRule.cpp
Index: clang/lib/Tooling/Transformer/RewriteRule.cpp
===================================================================
--- clang/lib/Tooling/Transformer/RewriteRule.cpp
+++ clang/lib/Tooling/Transformer/RewriteRule.cpp
@@ -42,7 +42,12 @@
llvm::Optional<CharSourceRange> EditRange =
tooling::getRangeForEdit(*Range, *Result.Context);
// FIXME: let user specify whether to treat this case as an error or ignore
- // it as is currently done.
+ // it as is currently done. This behavior is problematic in that it hides
+ // failures from bad ranges. Also, the behavior here differs from
+ // `flatten`. Here, we abort (without error), whereas flatten, if it hits an
+ // empty list, does not abort. As a result, `editList({A,B})` is not
+ // equivalent to `flatten(edit(A), edit(B))`. The former will abort if `A`
+ // produces a bad range, whereas the latter will simply ignore A.
if (!EditRange)
return SmallVector<Edit, 0>();
auto Replacement = E.Replacement->eval(Result);
Index: clang/include/clang/Tooling/Transformer/RewriteRule.h
===================================================================
--- clang/include/clang/Tooling/Transformer/RewriteRule.h
+++ clang/include/clang/Tooling/Transformer/RewriteRule.h
@@ -213,10 +213,12 @@
IncludeFormat Format = IncludeFormat::Quoted);
/// Adds an include directive for the given header to the file associated with
-/// `RootID`.
+/// `RootID`. If `RootID` matches inside a macro expansion, will add the
+/// directive to the file in which the macro was expanded (as opposed to the
+/// file in which the macro is defined).
inline ASTEdit addInclude(StringRef Header,
IncludeFormat Format = IncludeFormat::Quoted) {
- return addInclude(node(RootID), Header, Format);
+ return addInclude(expansion(node(RootID)), Header, Format);
}
// FIXME: If `Metadata` returns an `llvm::Expected<T>` the `AnyGenerator` will
@@ -312,8 +314,8 @@
/// \code
/// auto R = makeRule(callExpr(callee(functionDecl(hasName("foo")))),
/// changeTo(cat("bar()")));
-/// AddInclude(R, "path/to/bar_header.h");
-/// AddInclude(R, "vector", IncludeFormat::Angled);
+/// addInclude(R, "path/to/bar_header.h");
+/// addInclude(R, "vector", IncludeFormat::Angled);
/// \endcode
void addInclude(RewriteRule &Rule, llvm::StringRef Header,
IncludeFormat Format = IncludeFormat::Quoted);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93703.316832.patch
Type: text/x-patch
Size: 2462 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210115/4aa0efa2/attachment.bin>
More information about the cfe-commits
mailing list