li.zhe.hua updated this revision to Diff 490248. li.zhe.hua added a comment.
Update test name Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D141636/new/ https://reviews.llvm.org/D141636 Files: clang/include/clang/Tooling/Transformer/SourceCode.h clang/lib/Tooling/Transformer/RewriteRule.cpp clang/lib/Tooling/Transformer/SourceCode.cpp clang/unittests/Tooling/SourceCodeTest.cpp
Index: clang/unittests/Tooling/SourceCodeTest.cpp =================================================================== --- clang/unittests/Tooling/SourceCodeTest.cpp +++ 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; @@ -453,11 +453,11 @@ Visitor.runOver(Code); } -class GetRangeForEditTest : public testing::TestWithParam<bool> {}; -INSTANTIATE_TEST_SUITE_P(WithAndWithoutExpansions, GetRangeForEditTest, +class GetFileRangeForEditTest : public testing::TestWithParam<bool> {}; +INSTANTIATE_TEST_SUITE_P(WithAndWithoutExpansions, GetFileRangeForEditTest, testing::Bool()); -TEST_P(GetRangeForEditTest, EditRangeWithMacroExpansionsShouldSucceed) { +TEST_P(GetFileRangeForEditTest, EditRangeWithMacroExpansionsShouldSucceed) { // The call expression, whose range we are extracting, includes two macro // expansions. llvm::Annotations Code(R"cpp( @@ -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,12 +507,12 @@ 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()); } -TEST_P(GetRangeForEditTest, EditPartialMacroExpansionShouldFail) { +TEST_P(GetFileRangeForEditTest, EditPartialMacroExpansionShouldFail) { std::string Code = R"cpp( #define BAR 10+ int c = BAR 3.0; @@ -521,12 +521,12 @@ 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); } -TEST_P(GetRangeForEditTest, EditWholeMacroArgShouldSucceed) { +TEST_P(GetFileRangeForEditTest, EditWholeMacroArgShouldSucceed) { llvm::Annotations Code(R"cpp( #define FOO(a) a + 7.0; int a = FOO($r[[10]]); @@ -535,13 +535,13 @@ 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()); } -TEST_P(GetRangeForEditTest, EditPartialMacroArgShouldSucceed) { +TEST_P(GetFileRangeForEditTest, EditPartialMacroArgShouldSucceed) { llvm::Annotations Code(R"cpp( #define FOO(a) a + 7.0; int a = FOO($r[[10]] + 10.0); @@ -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()); Index: clang/lib/Tooling/Transformer/SourceCode.cpp =================================================================== --- clang/lib/Tooling/Transformer/SourceCode.cpp +++ clang/lib/Tooling/Transformer/SourceCode.cpp @@ -122,7 +122,7 @@ return Range; } -std::optional<CharSourceRange> clang::tooling::getRangeForEdit( +std::optional<CharSourceRange> clang::tooling::getFileRangeForEdit( const CharSourceRange &EditRange, const SourceManager &SM, const LangOptions &LangOpts, bool IncludeMacroExpansion) { CharSourceRange Range = Index: clang/lib/Tooling/Transformer/RewriteRule.cpp =================================================================== --- clang/lib/Tooling/Transformer/RewriteRule.cpp +++ clang/lib/Tooling/Transformer/RewriteRule.cpp @@ -39,7 +39,7 @@ if (!Range) return Range.takeError(); std::optional<CharSourceRange> 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<CharSourceRange> RootRange = tooling::getRangeForEdit( + std::optional<CharSourceRange> RootRange = tooling::getFileRangeForEdit( CharSourceRange::getTokenRange(Root->second.getSourceRange()), *Result.Context); if (RootRange) Index: clang/include/clang/Tooling/Transformer/SourceCode.h =================================================================== --- clang/include/clang/Tooling/Transformer/SourceCode.h +++ clang/include/clang/Tooling/Transformer/SourceCode.h @@ -104,13 +104,14 @@ /// will be rewritten to /// foo(6) std::optional<CharSourceRange> -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<CharSourceRange> -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
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits