diff options
author | dcheng <dcheng@chromium.org> | 2015-12-14 14:47:50 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-12-14 22:49:11 +0000 |
commit | af961540aa1cd578055321f041a7312a84728510 (patch) | |
tree | 5bc2155b5d465034e823b7210234c9872975f42b | |
parent | 0f65ba2bb05c1d262eab2a5357d7be92e19efab7 (diff) | |
download | chromium_src-af961540aa1cd578055321f041a7312a84728510.zip chromium_src-af961540aa1cd578055321f041a7312a84728510.tar.gz chromium_src-af961540aa1cd578055321f041a7312a84728510.tar.bz2 |
clang-format test results to get consistent diffs.
Also fix the empty_string build, which was used to verify the script
changes.
BUG=none
Review URL: https://codereview.chromium.org/1525673002
Cr-Commit-Position: refs/heads/master@{#365114}
-rw-r--r-- | tools/clang/empty_string/EmptyStringConverter.cpp | 48 | ||||
-rw-r--r-- | tools/clang/empty_string/tests/test-expected.cc | 5 | ||||
-rwxr-xr-x | tools/clang/scripts/test_tool.py | 4 |
3 files changed, 21 insertions, 36 deletions
diff --git a/tools/clang/empty_string/EmptyStringConverter.cpp b/tools/clang/empty_string/EmptyStringConverter.cpp index d056755..fce692f 100644 --- a/tools/clang/empty_string/EmptyStringConverter.cpp +++ b/tools/clang/empty_string/EmptyStringConverter.cpp @@ -8,8 +8,8 @@ // should be run using the tools/clang/scripts/run_tool.py helper. #include <memory> -#include "clang/ASTMatchers/ASTMatchers.h" #include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/ASTMatchers/ASTMatchers.h" #include "clang/Basic/SourceManager.h" #include "clang/Frontend/FrontendActions.h" #include "clang/Tooling/CommonOptionsParser.h" @@ -17,24 +17,7 @@ #include "clang/Tooling/Tooling.h" #include "llvm/Support/CommandLine.h" -using clang::ast_matchers::MatchFinder; -using clang::ast_matchers::argumentCountIs; -using clang::ast_matchers::bindTemporaryExpr; -using clang::ast_matchers::constructorDecl; -using clang::ast_matchers::constructExpr; -using clang::ast_matchers::defaultArgExpr; -using clang::ast_matchers::expr; -using clang::ast_matchers::forEach; -using clang::ast_matchers::has; -using clang::ast_matchers::hasArgument; -using clang::ast_matchers::hasDeclaration; -using clang::ast_matchers::hasName; -using clang::ast_matchers::id; -using clang::ast_matchers::methodDecl; -using clang::ast_matchers::newExpr; -using clang::ast_matchers::ofClass; -using clang::ast_matchers::stringLiteral; -using clang::ast_matchers::varDecl; +using namespace clang::ast_matchers; using clang::tooling::CommonOptionsParser; using clang::tooling::Replacement; using clang::tooling::Replacements; @@ -97,25 +80,24 @@ class EmptyStringConverter { }; void EmptyStringConverter::SetupMatchers(MatchFinder* match_finder) { - const clang::ast_matchers::StatementMatcher& constructor_call = - id("call", - constructExpr( - hasDeclaration(methodDecl(ofClass(hasName("std::basic_string")))), - argumentCountIs(2), - hasArgument(0, id("literal", stringLiteral())), - hasArgument(1, defaultArgExpr()))); + const clang::ast_matchers::StatementMatcher& constructor_call = id( + "call", + cxxConstructExpr( + hasDeclaration(cxxMethodDecl(ofClass(hasName("std::basic_string")))), + argumentCountIs(2), hasArgument(0, id("literal", stringLiteral())), + hasArgument(1, cxxDefaultArgExpr()))); // Note that expr(has()) in the matcher is significant; the Clang AST wraps // calls to the std::string constructor with exprWithCleanups nodes. Without // the expr(has()) matcher, the first and last rules would not match anything! match_finder->addMatcher(varDecl(forEach(expr(has(constructor_call)))), &constructor_callback_); - match_finder->addMatcher(newExpr(has(constructor_call)), + match_finder->addMatcher(cxxNewExpr(has(constructor_call)), &constructor_callback_); - match_finder->addMatcher(bindTemporaryExpr(has(constructor_call)), + match_finder->addMatcher(cxxBindTemporaryExpr(has(constructor_call)), &temporary_callback_); match_finder->addMatcher( - constructorDecl(forEach(expr(has(constructor_call)))), + cxxConstructorDecl(forEach(expr(has(constructor_call)))), &initializer_callback_); } @@ -160,8 +142,7 @@ void TemporaryCallback::run(const MatchFinder::MatchResult& result) { replacements_->insert(Replacement(*result.SourceManager, literal, "")); } else { replacements_->insert( - Replacement(*result.SourceManager, - call, + Replacement(*result.SourceManager, call, literal->isWide() ? "std::wstring()" : "std::string()")); } } @@ -196,8 +177,9 @@ int main(int argc, const char* argv[]) { // tools. llvm::outs() << "==== BEGIN EDITS ====\n"; for (const auto& r : replacements) { - llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() << ":::" - << r.getLength() << ":::" << r.getReplacementText() << "\n"; + llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() + << ":::" << r.getLength() << ":::" << r.getReplacementText() + << "\n"; } llvm::outs() << "==== END EDITS ====\n"; diff --git a/tools/clang/empty_string/tests/test-expected.cc b/tools/clang/empty_string/tests/test-expected.cc index 6762e37..3ae6702 100644 --- a/tools/clang/empty_string/tests/test-expected.cc +++ b/tools/clang/empty_string/tests/test-expected.cc @@ -13,8 +13,8 @@ void TestDeclarations() { // Tests for std::string allocated with new. void TestNew() { - std::string* a = new std::string, *b = new std::string("abc"), - *c = new std::string, *d = new std::string(); + std::string *a = new std::string, *b = new std::string("abc"), + *c = new std::string, *d = new std::string(); } // Tests for std::string construction in initializer lists. @@ -43,4 +43,3 @@ void TestWideTemporaries(const std::wstring& reference_argument, TestWideTemporaries(std::wstring(), std::wstring()); TestWideTemporaries(std::wstring(), std::wstring()); } - diff --git a/tools/clang/scripts/test_tool.py b/tools/clang/scripts/test_tool.py index 1f64be4..986216c 100755 --- a/tools/clang/scripts/test_tool.py +++ b/tools/clang/scripts/test_tool.py @@ -83,6 +83,10 @@ def main(argv): print 'run_tool failed:\n%s' % stdout sys.exit(1) + args = ['git', 'cl', 'format'] + args.extend(actual_files) + subprocess.check_call(args) + passed = 0 failed = 0 for expected, actual in zip(expected_files, actual_files): |