diff --git a/clang/include/clang/Tooling/Transformer/SourceCode.h b/clang/include/clang/Tooling/Transformer/SourceCode.h --- a/clang/include/clang/Tooling/Transformer/SourceCode.h +++ b/clang/include/clang/Tooling/Transformer/SourceCode.h @@ -104,13 +104,14 @@ /// will be rewritten to /// foo(6) std::optional -getRangeForEdit(const CharSourceRange &EditRange, const SourceManager &SM, - const LangOptions &LangOpts, bool IncludeMacroExpansion = true); +getFileRangeForEdit(const CharSourceRange &EditRange, const SourceManager &SM, + const LangOptions &LangOpts, + bool IncludeMacroExpansion = true); inline std::optional -getRangeForEdit(const CharSourceRange &EditRange, const ASTContext &Context, - bool IncludeMacroExpansion = true) { - return getRangeForEdit(EditRange, Context.getSourceManager(), - Context.getLangOpts(), IncludeMacroExpansion); +getFileRangeForEdit(const CharSourceRange &EditRange, const ASTContext &Context, + bool IncludeMacroExpansion = true) { + return getFileRangeForEdit(EditRange, Context.getSourceManager(), + Context.getLangOpts(), IncludeMacroExpansion); } /// Attempts to resolve the given range to one that starts and ends in a diff --git a/clang/lib/Tooling/Transformer/RewriteRule.cpp b/clang/lib/Tooling/Transformer/RewriteRule.cpp --- a/clang/lib/Tooling/Transformer/RewriteRule.cpp +++ b/clang/lib/Tooling/Transformer/RewriteRule.cpp @@ -39,7 +39,7 @@ if (!Range) return Range.takeError(); std::optional EditRange = - tooling::getRangeForEdit(*Range, *Result.Context); + tooling::getFileRangeForEdit(*Range, *Result.Context); // FIXME: let user specify whether to treat this case as an error or ignore // it as is currently done. This behavior is problematic in that it hides // failures from bad ranges. Also, the behavior here differs from @@ -449,7 +449,7 @@ auto &NodesMap = Result.Nodes.getMap(); auto Root = NodesMap.find(RootID); assert(Root != NodesMap.end() && "Transformation failed: missing root node."); - std::optional RootRange = tooling::getRangeForEdit( + std::optional RootRange = tooling::getFileRangeForEdit( CharSourceRange::getTokenRange(Root->second.getSourceRange()), *Result.Context); if (RootRange) diff --git a/clang/lib/Tooling/Transformer/SourceCode.cpp b/clang/lib/Tooling/Transformer/SourceCode.cpp --- a/clang/lib/Tooling/Transformer/SourceCode.cpp +++ b/clang/lib/Tooling/Transformer/SourceCode.cpp @@ -122,7 +122,7 @@ return Range; } -std::optional clang::tooling::getRangeForEdit( +std::optional clang::tooling::getFileRangeForEdit( const CharSourceRange &EditRange, const SourceManager &SM, const LangOptions &LangOpts, bool IncludeMacroExpansion) { CharSourceRange Range = diff --git a/clang/unittests/Tooling/SourceCodeTest.cpp b/clang/unittests/Tooling/SourceCodeTest.cpp --- a/clang/unittests/Tooling/SourceCodeTest.cpp +++ b/clang/unittests/Tooling/SourceCodeTest.cpp @@ -25,7 +25,7 @@ using tooling::getAssociatedRange; using tooling::getExtendedRange; using tooling::getExtendedText; -using tooling::getRangeForEdit; +using tooling::getFileRangeForEdit; using tooling::getText; using tooling::maybeExtendRange; using tooling::validateEditRange; @@ -469,7 +469,7 @@ CallsVisitor Visitor; Visitor.OnCall = [&Code](CallExpr *CE, ASTContext *Context) { auto Range = CharSourceRange::getTokenRange(CE->getSourceRange()); - EXPECT_THAT(getRangeForEdit(Range, *Context, GetParam()), + EXPECT_THAT(getFileRangeForEdit(Range, *Context, GetParam()), ValueIs(AsRange(Context->getSourceManager(), Code.range("r")))); }; Visitor.runOver(Code.code()); @@ -484,7 +484,7 @@ IntLitVisitor Visitor; Visitor.OnIntLit = [&Code](IntegerLiteral *Expr, ASTContext *Context) { auto Range = CharSourceRange::getTokenRange(Expr->getSourceRange()); - EXPECT_THAT(getRangeForEdit(Range, *Context), + EXPECT_THAT(getFileRangeForEdit(Range, *Context), ValueIs(AsRange(Context->getSourceManager(), Code.range("r")))); }; Visitor.runOver(Code.code()); @@ -507,7 +507,7 @@ Visitor.OnCall = [](CallExpr *CE, ASTContext *Context) { auto Range = CharSourceRange::getTokenRange(CE->getSourceRange()); EXPECT_FALSE( - getRangeForEdit(Range, *Context, /*IncludeMacroExpansion=*/false)); + getFileRangeForEdit(Range, *Context, /*IncludeMacroExpansion=*/false)); }; Visitor.runOver(Code.code()); } @@ -521,7 +521,7 @@ IntLitVisitor Visitor; Visitor.OnIntLit = [](IntegerLiteral *Expr, ASTContext *Context) { auto Range = CharSourceRange::getTokenRange(Expr->getSourceRange()); - EXPECT_FALSE(getRangeForEdit(Range, *Context, GetParam())); + EXPECT_FALSE(getFileRangeForEdit(Range, *Context, GetParam())); }; Visitor.runOver(Code); } @@ -535,7 +535,7 @@ IntLitVisitor Visitor; Visitor.OnIntLit = [&Code](IntegerLiteral *Expr, ASTContext *Context) { auto Range = CharSourceRange::getTokenRange(Expr->getSourceRange()); - EXPECT_THAT(getRangeForEdit(Range, *Context, GetParam()), + EXPECT_THAT(getFileRangeForEdit(Range, *Context, GetParam()), ValueIs(AsRange(Context->getSourceManager(), Code.range("r")))); }; Visitor.runOver(Code.code()); @@ -550,7 +550,7 @@ IntLitVisitor Visitor; Visitor.OnIntLit = [&Code](IntegerLiteral *Expr, ASTContext *Context) { auto Range = CharSourceRange::getTokenRange(Expr->getSourceRange()); - EXPECT_THAT(getRangeForEdit(Range, *Context, GetParam()), + EXPECT_THAT(getFileRangeForEdit(Range, *Context, GetParam()), ValueIs(AsRange(Context->getSourceManager(), Code.range("r")))); }; Visitor.runOver(Code.code());