Commit 7ce04056 authored by dcheng@chromium.org's avatar dcheng@chromium.org

Fix bitrot in Chrome clang tool infrastructure.

- LLVM now uses C++11, so need to use LLVM_OVERRIDE anymore.
- Small changes in Clang interfaces for flags and FrontendFactory
  instantiation.
- clang-format-diff.py works slightly differently now, so update the
  run_tool.py wrapper to invoke it correctly.
- Delete tools that are no longer needed.

BUG=
R=thakis@chromium.org

Review URL: https://codereview.chromium.org/448693003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287841 0039d316-1c4b-4281-b951-d872f2087c98
parent 18fd51c7
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
// take a copy of an empty string) and generates fewer instructions as well. It // take a copy of an empty string) and generates fewer instructions as well. It
// should be run using the tools/clang/scripts/run_tool.py helper. // should be run using the tools/clang/scripts/run_tool.py helper.
#include <memory>
#include "clang/ASTMatchers/ASTMatchers.h" #include "clang/ASTMatchers/ASTMatchers.h"
#include "clang/ASTMatchers/ASTMatchFinder.h" #include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Basic/SourceManager.h" #include "clang/Basic/SourceManager.h"
...@@ -48,7 +49,7 @@ class ConstructorCallback : public MatchFinder::MatchCallback { ...@@ -48,7 +49,7 @@ class ConstructorCallback : public MatchFinder::MatchCallback {
ConstructorCallback(Replacements* replacements) ConstructorCallback(Replacements* replacements)
: replacements_(replacements) {} : replacements_(replacements) {}
virtual void run(const MatchFinder::MatchResult& result) LLVM_OVERRIDE; virtual void run(const MatchFinder::MatchResult& result) override;
private: private:
Replacements* const replacements_; Replacements* const replacements_;
...@@ -61,7 +62,7 @@ class InitializerCallback : public MatchFinder::MatchCallback { ...@@ -61,7 +62,7 @@ class InitializerCallback : public MatchFinder::MatchCallback {
InitializerCallback(Replacements* replacements) InitializerCallback(Replacements* replacements)
: replacements_(replacements) {} : replacements_(replacements) {}
virtual void run(const MatchFinder::MatchResult& result) LLVM_OVERRIDE; virtual void run(const MatchFinder::MatchResult& result) override;
private: private:
Replacements* const replacements_; Replacements* const replacements_;
...@@ -74,7 +75,7 @@ class TemporaryCallback : public MatchFinder::MatchCallback { ...@@ -74,7 +75,7 @@ class TemporaryCallback : public MatchFinder::MatchCallback {
public: public:
TemporaryCallback(Replacements* replacements) : replacements_(replacements) {} TemporaryCallback(Replacements* replacements) : replacements_(replacements) {}
virtual void run(const MatchFinder::MatchResult& result) LLVM_OVERRIDE; virtual void run(const MatchFinder::MatchResult& result) override;
private: private:
Replacements* const replacements_; Replacements* const replacements_;
...@@ -127,7 +128,7 @@ void ConstructorCallback::run(const MatchFinder::MatchResult& result) { ...@@ -127,7 +128,7 @@ void ConstructorCallback::run(const MatchFinder::MatchResult& result) {
const clang::CXXConstructExpr* call = const clang::CXXConstructExpr* call =
result.Nodes.getNodeAs<clang::CXXConstructExpr>("call"); result.Nodes.getNodeAs<clang::CXXConstructExpr>("call");
clang::CharSourceRange range = clang::CharSourceRange range =
clang::CharSourceRange::getTokenRange(call->getParenRange()); clang::CharSourceRange::getTokenRange(call->getParenOrBraceRange());
replacements_->insert(Replacement(*result.SourceManager, range, "")); replacements_->insert(Replacement(*result.SourceManager, range, ""));
} }
...@@ -154,7 +155,7 @@ void TemporaryCallback::run(const MatchFinder::MatchResult& result) { ...@@ -154,7 +155,7 @@ void TemporaryCallback::run(const MatchFinder::MatchResult& result) {
// constructor. An implicitly generated constructor won't have a valid // constructor. An implicitly generated constructor won't have a valid
// source range for the parenthesis. We do this because the matched expression // source range for the parenthesis. We do this because the matched expression
// for |call| in the explicit case doesn't include the closing parenthesis. // for |call| in the explicit case doesn't include the closing parenthesis.
clang::SourceRange range = call->getParenRange(); clang::SourceRange range = call->getParenOrBraceRange();
if (range.isValid()) { if (range.isValid()) {
replacements_->insert(Replacement(*result.SourceManager, literal, "")); replacements_->insert(Replacement(*result.SourceManager, literal, ""));
} else { } else {
...@@ -170,7 +171,8 @@ void TemporaryCallback::run(const MatchFinder::MatchResult& result) { ...@@ -170,7 +171,8 @@ void TemporaryCallback::run(const MatchFinder::MatchResult& result) {
static llvm::cl::extrahelp common_help(CommonOptionsParser::HelpMessage); static llvm::cl::extrahelp common_help(CommonOptionsParser::HelpMessage);
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {
CommonOptionsParser options(argc, argv); llvm::cl::OptionCategory category("EmptyString Tool");
CommonOptionsParser options(argc, argv, category);
clang::tooling::ClangTool tool(options.getCompilations(), clang::tooling::ClangTool tool(options.getCompilations(),
options.getSourcePathList()); options.getSourcePathList());
...@@ -179,20 +181,23 @@ int main(int argc, const char* argv[]) { ...@@ -179,20 +181,23 @@ int main(int argc, const char* argv[]) {
MatchFinder match_finder; MatchFinder match_finder;
converter.SetupMatchers(&match_finder); converter.SetupMatchers(&match_finder);
int result = std::unique_ptr<clang::tooling::FrontendActionFactory> frontend_factory =
tool.run(clang::tooling::newFrontendActionFactory(&match_finder)); clang::tooling::newFrontendActionFactory(&match_finder);
int result = tool.run(frontend_factory.get());
if (result != 0) if (result != 0)
return result; return result;
// Each replacement line should have the following format: // Each replacement line should have the following format:
// r:<file path>:<offset>:<length>:<replacement text> // r:<file path>:<offset>:<length>:<replacement text>
// Only the <replacement text> field can contain embedded ":" characters. // Only the <replacement text> field can contain embedded ":" characters.
// TODO(dcheng): Use a more clever serialization. // TODO(dcheng): Use a more clever serialization. Ideally we'd use the YAML
// serialization and then use clang-apply-replacements, but that would require
// copying and pasting a larger amount of boilerplate for all Chrome clang
// tools.
llvm::outs() << "==== BEGIN EDITS ====\n"; llvm::outs() << "==== BEGIN EDITS ====\n";
for (Replacements::const_iterator it = replacements.begin(); for (const auto& r : replacements) {
it != replacements.end(); ++it) { llvm::outs() << "r:" << r.getFilePath() << ":" << r.getOffset() << ":"
llvm::outs() << "r:" << it->getFilePath() << ":" << it->getOffset() << ":" << r.getLength() << ":" << r.getReplacementText() << "\n";
<< it->getLength() << ":" << it->getReplacementText() << "\n";
} }
llvm::outs() << "==== END EDITS ====\n"; llvm::outs() << "==== END EDITS ====\n";
......
...@@ -13,11 +13,13 @@ NO_INSTALL = 1 ...@@ -13,11 +13,13 @@ NO_INSTALL = 1
include $(CLANG_LEVEL)/../../Makefile.config include $(CLANG_LEVEL)/../../Makefile.config
LINK_COMPONENTS := $(TARGETS_TO_BUILD) asmparser bitreader support mc LINK_COMPONENTS := $(TARGETS_TO_BUILD) asmparser bitreader support mc option
USEDLIBS = clangTooling.a clangFrontend.a clangSerialization.a clangDriver.a \ USEDLIBS = clangFrontend.a clangSerialization.a clangDriver.a \
clangRewriteFrontend.a clangRewriteCore.a clangParse.a clangSema.a \ clangTooling.a clangParse.a clangSema.a \
clangAnalysis.a clangAST.a clangASTMatchers.a clangEdit.a \ clangStaticAnalyzerFrontend.a clangStaticAnalyzerCheckers.a \
clangLex.a clangBasic.a clangStaticAnalyzerCore.a clangAnalysis.a clangRewriteFrontend.a \
clangRewrite.a clangEdit.a clangAST.a clangLex.a clangBasic.a \
clangASTMatchers.a
include $(CLANG_LEVEL)/Makefile include $(CLANG_LEVEL)/Makefile
...@@ -7,14 +7,14 @@ ...@@ -7,14 +7,14 @@
#include <string> #include <string>
// Tests for std::string declarations. // Tests for std::string declarations.
void TestDeclarations() { std::string a, b("abc"), c; } void TestDeclarations() {
std::string a, b("abc"), c;
}
// Tests for std::string allocated with new. // Tests for std::string allocated with new.
void TestNew() { void TestNew() {
std::string* a = new std::string, std::string* a = new std::string, *b = new std::string("abc"),
*b = new std::string("abc"), *c = new std::string, *d = new std::string();
*c = new std::string,
*d = new std::string();
} }
// Tests for std::string construction in initializer lists. // Tests for std::string construction in initializer lists.
...@@ -43,3 +43,4 @@ void TestWideTemporaries(const std::wstring& reference_argument, ...@@ -43,3 +43,4 @@ void TestWideTemporaries(const std::wstring& reference_argument,
TestWideTemporaries(std::wstring(), std::wstring()); TestWideTemporaries(std::wstring(), std::wstring());
TestWideTemporaries(std::wstring(), std::wstring()); TestWideTemporaries(std::wstring(), std::wstring());
} }
# Copyright (c) 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# This Makefile requires the LLVM build system. In order to build this tool,
# please run tools/clang/scripts/build_tool.py.
CLANG_LEVEL := ../..
TOOLNAME = rewrite_scoped_array
NO_INSTALL = 1
include $(CLANG_LEVEL)/../../Makefile.config
LINK_COMPONENTS := $(TARGETS_TO_BUILD) asmparser bitreader support mc
USEDLIBS = clangTooling.a clangFrontend.a clangSerialization.a clangDriver.a \
clangRewriteFrontend.a clangRewriteCore.a clangParse.a clangSema.a \
clangAnalysis.a clangAST.a clangASTMatchers.a clangEdit.a \
clangLex.a clangBasic.a
include $(CLANG_LEVEL)/Makefile
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// This implements a Clang tool to rewrite all instances of scoped_array<T> to
// scoped_ptr<T[]>. The former is being deprecated in favor of the latter, to
// allow for an eventual transition from scoped_ptr to unique_ptr.
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchers.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Frontend/FrontendActions.h"
#include "clang/Lex/Lexer.h"
#include "clang/Tooling/CommonOptionsParser.h"
#include "clang/Tooling/Refactoring.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/Support/CommandLine.h"
using clang::ast_matchers::MatchFinder;
using clang::ast_matchers::hasDeclaration;
using clang::ast_matchers::hasName;
using clang::ast_matchers::id;
using clang::ast_matchers::loc;
using clang::ast_matchers::qualType;
using clang::ast_matchers::recordDecl;
using clang::tooling::CommonOptionsParser;
using clang::tooling::Replacement;
using clang::tooling::Replacements;
using llvm::StringRef;
namespace {
class RewriterCallback : public MatchFinder::MatchCallback {
public:
RewriterCallback(Replacements* replacements) : replacements_(replacements) {}
virtual void run(const MatchFinder::MatchResult& result) LLVM_OVERRIDE;
private:
Replacements* const replacements_;
};
void RewriterCallback::run(const MatchFinder::MatchResult& result) {
const clang::TypeLoc type_location =
*result.Nodes.getNodeAs<clang::TypeLoc>("loc");
clang::CharSourceRange range = clang::CharSourceRange::getTokenRange(
result.SourceManager->getSpellingLoc(type_location.getLocStart()),
result.SourceManager->getSpellingLoc(type_location.getLocEnd()));
// TODO(dcheng): Log an error?
if (!range.isValid())
return;
std::string replacement_text = clang::Lexer::getSourceText(
range, *result.SourceManager, result.Context->getLangOpts());
// TODO(dcheng): Log errors?
if (!StringRef(replacement_text).startswith("scoped_array<") ||
!StringRef(replacement_text).endswith(">"))
return;
replacement_text.replace(strlen("scoped_"), strlen("array"), "ptr");
replacement_text.insert(replacement_text.size() - 1, "[]");
replacements_->insert(
Replacement(*result.SourceManager, range, replacement_text));
}
} // namespace
static llvm::cl::extrahelp common_help(CommonOptionsParser::HelpMessage);
int main(int argc, const char* argv[]) {
CommonOptionsParser options(argc, argv);
clang::tooling::ClangTool tool(options.getCompilations(),
options.getSourcePathList());
Replacements replacements;
RewriterCallback callback(&replacements);
MatchFinder match_finder;
match_finder.addMatcher(
id("loc",
loc(qualType(hasDeclaration(recordDecl(hasName("::scoped_array")))))),
&callback);
int result =
tool.run(clang::tooling::newFrontendActionFactory(&match_finder));
if (result != 0)
return result;
// Serialization format is documented in tools/clang/scripts/run_tool.py
llvm::outs() << "==== BEGIN EDITS ====\n";
for (Replacements::const_iterator it = replacements.begin();
it != replacements.end(); ++it) {
llvm::outs() << "r:" << it->getFilePath() << ":" << it->getOffset() << ":"
<< it->getLength() << ":" << it->getReplacementText() << "\n";
}
llvm::outs() << "==== END EDITS ====\n";
return 0;
}
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
template <class T> class scoped_array {
private:
T* data_;
};
class TestClass {
private:
scoped_ptr<int[]> test_field_;
};
scoped_ptr<int[]> TestFunction(scoped_ptr<int[]> x, scoped_ptr<int[]>) {
scoped_ptr<scoped_array<int>(scoped_array<int> test, scoped_array<int>)[]> y;
scoped_ptr<int[]>(*function_pointer)(scoped_ptr<int[]> test,
scoped_ptr<int[]>);
scoped_ptr<int[]> test_variable;
}
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
template <class T> class scoped_array {
private:
T* data_;
};
class TestClass {
private:
scoped_array<int> test_field_;
};
scoped_array<int> TestFunction(scoped_array<int> x, scoped_array<int>) {
scoped_array<scoped_array<int>(scoped_array<int> test, scoped_array<int>)> y;
scoped_array<int>(*function_pointer)(scoped_array<int> test,
scoped_array<int>);
scoped_array<int> test_variable;
}
# Copyright (c) 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# This Makefile requires the LLVM build system. In order to build this tool,
# please run tools/clang/scripts/build_tool.py.
CLANG_LEVEL := ../..
TOOLNAME = rewrite_scoped_ptr_ctor_null
NO_INSTALL = 1
include $(CLANG_LEVEL)/../../Makefile.config
LINK_COMPONENTS := $(TARGETS_TO_BUILD) asmparser bitreader support mc
USEDLIBS = clangTooling.a clangFrontend.a clangSerialization.a clangDriver.a \
clangRewriteFrontend.a clangRewriteCore.a clangParse.a clangSema.a \
clangAnalysis.a clangAST.a clangASTMatchers.a clangEdit.a \
clangLex.a clangBasic.a
include $(CLANG_LEVEL)/Makefile
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// This implements a Clang tool to convert all instances of std::string("") to
// std::string(). The latter is more efficient (as std::string doesn't have to
// take a copy of an empty string) and generates fewer instructions as well. It
// should be run using the tools/clang/scripts/run_tool.py helper.
#include "clang/ASTMatchers/ASTMatchers.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Frontend/FrontendActions.h"
#include "clang/Tooling/CommonOptionsParser.h"
#include "clang/Tooling/Refactoring.h"
#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::matchesName;
using clang::ast_matchers::id;
using clang::ast_matchers::methodDecl;
using clang::ast_matchers::newExpr;
using clang::ast_matchers::ofClass;
using clang::ast_matchers::unless;
using clang::ast_matchers::varDecl;
using clang::tooling::CommonOptionsParser;
using clang::tooling::Replacement;
using clang::tooling::Replacements;
namespace {
bool IsNullConstant(const clang::Expr& expr, clang::ASTContext* context) {
return expr.isNullPointerConstant(*context,
clang::Expr::NPC_ValueDependentIsNotNull) !=
clang::Expr::NPCK_NotNull;
}
// Handles replacements for stack and heap-allocated instances, e.g.:
// scoped_ptr<T> a(NULL);
// scoped_ptr<T>* b = new scoped_ptr<T>(NULL);
// ...though the latter should be pretty rare.
class ConstructorCallback : public MatchFinder::MatchCallback {
public:
ConstructorCallback(Replacements* replacements)
: replacements_(replacements) {}
virtual void run(const MatchFinder::MatchResult& result) LLVM_OVERRIDE;
private:
Replacements* const replacements_;
};
// Handles replacements for invocations of scoped_ptr<T>(NULL) in an initializer
// list.
class InitializerCallback : public MatchFinder::MatchCallback {
public:
InitializerCallback(Replacements* replacements)
: replacements_(replacements) {}
virtual void run(const MatchFinder::MatchResult& result) LLVM_OVERRIDE;
private:
Replacements* const replacements_;
};
// Handles replacements for invocations of scoped_ptr<T>(NULL) in a temporary
// context, e.g. return scoped_ptr<T>(NULL).
class TemporaryCallback : public MatchFinder::MatchCallback {
public:
TemporaryCallback(Replacements* replacements) : replacements_(replacements) {}
virtual void run(const MatchFinder::MatchResult& result) LLVM_OVERRIDE;
private:
Replacements* const replacements_;
};
class EmptyStringConverter {
public:
explicit EmptyStringConverter(Replacements* replacements)
: constructor_callback_(replacements),
initializer_callback_(replacements),
temporary_callback_(replacements) {}
void SetupMatchers(MatchFinder* match_finder);
private:
ConstructorCallback constructor_callback_;
InitializerCallback initializer_callback_;
TemporaryCallback temporary_callback_;
};
void EmptyStringConverter::SetupMatchers(MatchFinder* match_finder) {
const char kPattern[] = "^::(scoped_ptr|scoped_ptr_malloc)$";
const clang::ast_matchers::StatementMatcher& constructor_call = id(
"call",
constructExpr(hasDeclaration(methodDecl(ofClass(matchesName(kPattern)))),
argumentCountIs(1),
hasArgument(0, id("arg", expr())),
unless(hasArgument(0, defaultArgExpr()))));
match_finder->addMatcher(varDecl(forEach(constructor_call)),
&constructor_callback_);
match_finder->addMatcher(newExpr(has(constructor_call)),
&constructor_callback_);
match_finder->addMatcher(bindTemporaryExpr(has(constructor_call)),
&temporary_callback_);
match_finder->addMatcher(constructorDecl(forEach(constructor_call)),
&initializer_callback_);
}
void ConstructorCallback::run(const MatchFinder::MatchResult& result) {
const clang::Expr* arg = result.Nodes.getNodeAs<clang::Expr>("arg");
if (!IsNullConstant(*arg, result.Context))
return;
const clang::CXXConstructExpr* call =
result.Nodes.getNodeAs<clang::CXXConstructExpr>("call");
clang::CharSourceRange range =
clang::CharSourceRange::getTokenRange(call->getParenRange());
replacements_->insert(Replacement(*result.SourceManager, range, ""));
}
void InitializerCallback::run(const MatchFinder::MatchResult& result) {
const clang::Expr* arg = result.Nodes.getNodeAs<clang::Expr>("arg");
if (!IsNullConstant(*arg, result.Context))
return;
const clang::CXXConstructExpr* call =
result.Nodes.getNodeAs<clang::CXXConstructExpr>("call");
replacements_->insert(Replacement(*result.SourceManager, call, ""));
}
void TemporaryCallback::run(const MatchFinder::MatchResult& result) {
const clang::Expr* arg = result.Nodes.getNodeAs<clang::Expr>("arg");
if (!IsNullConstant(*arg, result.Context))
return;
// TODO(dcheng): File a bug with clang. There should be an easier way to do
// this replacement, but getTokenRange(call->getParenRange()) and the obvious
// (but incorrect) arg both don't work. The former is presumably just buggy,
// while the latter probably has to do with the fact that NULL is actually a
// macro which expands to a built-in.
clang::SourceRange range = arg->getSourceRange();
clang::SourceRange expansion_range(
result.SourceManager->getExpansionLoc(range.getBegin()),
result.SourceManager->getExpansionLoc(range.getEnd()));
replacements_->insert(
Replacement(*result.SourceManager,
clang::CharSourceRange::getTokenRange(expansion_range),
""));
}
} // namespace
static llvm::cl::extrahelp common_help(CommonOptionsParser::HelpMessage);
int main(int argc, const char* argv[]) {
CommonOptionsParser options(argc, argv);
clang::tooling::ClangTool tool(options.getCompilations(),
options.getSourcePathList());
Replacements replacements;
EmptyStringConverter converter(&replacements);
MatchFinder match_finder;
converter.SetupMatchers(&match_finder);
int result =
tool.run(clang::tooling::newFrontendActionFactory(&match_finder));
if (result != 0)
return result;
// Each replacement line should have the following format:
// r:<file path>:<offset>:<length>:<replacement text>
// Only the <replacement text> field can contain embedded ":" characters.
// TODO(dcheng): Use a more clever serialization.
llvm::outs() << "==== BEGIN EDITS ====\n";
for (Replacements::const_iterator it = replacements.begin();
it != replacements.end();
++it) {
llvm::outs() << "r:" << it->getFilePath() << ":" << it->getOffset() << ":"
<< it->getLength() << ":" << it->getReplacementText() << "\n";
}
llvm::outs() << "==== END EDITS ====\n";
return 0;
}
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/memory/scoped_ptr.h"
void TestDeclarations() {
scoped_ptr<int> a, b(new int), c;
scoped_ptr_malloc<int> d;
}
void TestNew() {
scoped_ptr<int>* a = new scoped_ptr<int>, *b = new scoped_ptr<int>(new int),
*c = new scoped_ptr<int>;
}
class TestInitializers {
public:
TestInitializers() {}
TestInitializers(bool) {}
TestInitializers(double)
: b(new int), c(), f(static_cast<int*>(malloc(sizeof(int)))) {}
private:
scoped_ptr<int> a;
scoped_ptr<int> b;
scoped_ptr<int> c;
scoped_ptr_malloc<int> d;
scoped_ptr_malloc<int> e;
scoped_ptr_malloc<int> f;
};
scoped_ptr<int> TestTemporaries(scoped_ptr<int> a, scoped_ptr<int> b) {
scoped_ptr<int> c =
TestTemporaries(scoped_ptr<int>(), scoped_ptr<int>(new int));
return scoped_ptr<int>();
}
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/memory/scoped_ptr.h"
void TestDeclarations() {
scoped_ptr<int> a(NULL), b(new int), c(NULL);
scoped_ptr_malloc<int> d(NULL);
}
void TestNew() {
scoped_ptr<int>* a = new scoped_ptr<int>(NULL),
*b = new scoped_ptr<int>(new int),
*c = new scoped_ptr<int>(NULL);
}
class TestInitializers {
public:
TestInitializers() : a(NULL) {}
TestInitializers(bool) : a(NULL), b(NULL), e(NULL) {}
TestInitializers(double)
: a(NULL), b(new int), c(), f(static_cast<int*>(malloc(sizeof(int)))) {}
private:
scoped_ptr<int> a;
scoped_ptr<int> b;
scoped_ptr<int> c;
scoped_ptr_malloc<int> d;
scoped_ptr_malloc<int> e;
scoped_ptr_malloc<int> f;
};
scoped_ptr<int> TestTemporaries(scoped_ptr<int> a, scoped_ptr<int> b) {
scoped_ptr<int> c =
TestTemporaries(scoped_ptr<int>(NULL), scoped_ptr<int>(new int));
return scoped_ptr<int>(NULL);
}
...@@ -214,7 +214,7 @@ def _ApplyEdits(edits, clang_format_diff_path): ...@@ -214,7 +214,7 @@ def _ApplyEdits(edits, clang_format_diff_path):
f.truncate() f.truncate()
f.write(contents) f.write(contents)
if clang_format_diff_path: if clang_format_diff_path:
if subprocess.call('git diff -U0 %s | python %s -style=Chromium' % ( if subprocess.call('git diff -U0 %s | python %s -i -p1 -style=file ' % (
k, clang_format_diff_path), shell=True) != 0: k, clang_format_diff_path), shell=True) != 0:
print 'clang-format failed for %s' % k print 'clang-format failed for %s' % k
print 'Applied %d edits to %d files' % (edit_count, len(edits)) print 'Applied %d edits to %d files' % (edit_count, len(edits))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment