Commit 2500961f authored by thakis@chromium.org's avatar thakis@chromium.org

clang plugin: Put inner classes bugfix behind a flag.

A follow-up to https://chromiumcodereview.appspot.com/10808078

This way, cleaning up existing style issues in inner classes doesn't
have to block a clang roll.

BUG=139346

Review URL: https://chromiumcodereview.appspot.com/10828057

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148814 0039d316-1c4b-4281-b951-d872f2087c98
parent ec5f4330
...@@ -36,18 +36,24 @@ bool ends_with(const std::string& one, const std::string& two) { ...@@ -36,18 +36,24 @@ bool ends_with(const std::string& one, const std::string& two) {
} // namespace } // namespace
ChromeClassTester::ChromeClassTester(CompilerInstance& instance) ChromeClassTester::ChromeClassTester(CompilerInstance& instance,
bool check_inner_classes)
: instance_(instance), : instance_(instance),
diagnostic_(instance.getDiagnostics()) { diagnostic_(instance.getDiagnostics()),
check_inner_classes_(check_inner_classes) {
BuildBannedLists(); BuildBannedLists();
} }
ChromeClassTester::~ChromeClassTester() {} ChromeClassTester::~ChromeClassTester() {}
void ChromeClassTester::HandleTagDeclDefinition(TagDecl* tag) { void ChromeClassTester::HandleTagDeclDefinition(TagDecl* tag) {
// Defer processing of this tag until its containing top-level if (check_inner_classes_) {
// declaration has been fully parsed. See crbug.com/136863. // Defer processing of this tag until its containing top-level
pending_class_decls_.push_back(tag); // declaration has been fully parsed. See crbug.com/136863.
pending_class_decls_.push_back(tag);
} else {
CheckTag(tag);
}
} }
bool ChromeClassTester::HandleTopLevelDecl(DeclGroupRef group_ref) { bool ChromeClassTester::HandleTopLevelDecl(DeclGroupRef group_ref) {
......
...@@ -16,7 +16,8 @@ ...@@ -16,7 +16,8 @@
// headers to subclasses which implement CheckChromeClass(). // headers to subclasses which implement CheckChromeClass().
class ChromeClassTester : public clang::ASTConsumer { class ChromeClassTester : public clang::ASTConsumer {
public: public:
explicit ChromeClassTester(clang::CompilerInstance& instance); explicit ChromeClassTester(clang::CompilerInstance& instance,
bool check_inner_classes);
virtual ~ChromeClassTester(); virtual ~ChromeClassTester();
// clang::ASTConsumer: // clang::ASTConsumer:
...@@ -79,6 +80,9 @@ class ChromeClassTester : public clang::ASTConsumer { ...@@ -79,6 +80,9 @@ class ChromeClassTester : public clang::ASTConsumer {
// List of decls to check once the current top-level decl is parsed. // List of decls to check once the current top-level decl is parsed.
std::vector<clang::TagDecl*> pending_class_decls_; std::vector<clang::TagDecl*> pending_class_decls_;
// TODO: Remove once all inner classes are cleaned up.
bool check_inner_classes_;
}; };
#endif // TOOLS_CLANG_PLUGINS_CHROMECLASSTESTER_H_ #endif // TOOLS_CLANG_PLUGINS_CHROMECLASSTESTER_H_
...@@ -50,8 +50,9 @@ class FindBadConstructsConsumer : public ChromeClassTester { ...@@ -50,8 +50,9 @@ class FindBadConstructsConsumer : public ChromeClassTester {
public: public:
FindBadConstructsConsumer(CompilerInstance& instance, FindBadConstructsConsumer(CompilerInstance& instance,
bool check_refcounted_dtors, bool check_refcounted_dtors,
bool check_virtuals_in_implementations) bool check_virtuals_in_implementations,
: ChromeClassTester(instance), bool check_inner_classes)
: ChromeClassTester(instance, check_inner_classes),
check_refcounted_dtors_(check_refcounted_dtors), check_refcounted_dtors_(check_refcounted_dtors),
check_virtuals_in_implementations_(check_virtuals_in_implementations) { check_virtuals_in_implementations_(check_virtuals_in_implementations) {
} }
...@@ -395,7 +396,8 @@ class FindBadConstructsAction : public PluginASTAction { ...@@ -395,7 +396,8 @@ class FindBadConstructsAction : public PluginASTAction {
public: public:
FindBadConstructsAction() FindBadConstructsAction()
: check_refcounted_dtors_(true), : check_refcounted_dtors_(true),
check_virtuals_in_implementations_(true) { check_virtuals_in_implementations_(true),
check_inner_classes_(false) {
} }
protected: protected:
...@@ -403,7 +405,8 @@ class FindBadConstructsAction : public PluginASTAction { ...@@ -403,7 +405,8 @@ class FindBadConstructsAction : public PluginASTAction {
virtual ASTConsumer* CreateASTConsumer(CompilerInstance& instance, virtual ASTConsumer* CreateASTConsumer(CompilerInstance& instance,
llvm::StringRef ref) { llvm::StringRef ref) {
return new FindBadConstructsConsumer( return new FindBadConstructsConsumer(
instance, check_refcounted_dtors_, check_virtuals_in_implementations_); instance, check_refcounted_dtors_, check_virtuals_in_implementations_,
check_inner_classes_);
} }
virtual bool ParseArgs(const CompilerInstance& instance, virtual bool ParseArgs(const CompilerInstance& instance,
...@@ -415,6 +418,8 @@ class FindBadConstructsAction : public PluginASTAction { ...@@ -415,6 +418,8 @@ class FindBadConstructsAction : public PluginASTAction {
check_refcounted_dtors_ = false; check_refcounted_dtors_ = false;
} else if (args[i] == "skip-virtuals-in-implementations") { } else if (args[i] == "skip-virtuals-in-implementations") {
check_virtuals_in_implementations_ = false; check_virtuals_in_implementations_ = false;
} else if (args[i] == "check-inner-classes") {
check_inner_classes_ = true;
} else { } else {
parsed = false; parsed = false;
llvm::errs() << "Unknown argument: " << args[i] << "\n"; llvm::errs() << "Unknown argument: " << args[i] << "\n";
...@@ -427,6 +432,7 @@ class FindBadConstructsAction : public PluginASTAction { ...@@ -427,6 +432,7 @@ class FindBadConstructsAction : public PluginASTAction {
private: private:
bool check_refcounted_dtors_; bool check_refcounted_dtors_;
bool check_virtuals_in_implementations_; bool check_virtuals_in_implementations_;
bool check_inner_classes_;
}; };
} // namespace } // namespace
......
...@@ -25,6 +25,8 @@ usage() { ...@@ -25,6 +25,8 @@ usage() {
do_testcase() { do_testcase() {
local output="$("${CLANG_DIR}"/bin/clang -c -Wno-c++11-extensions \ local output="$("${CLANG_DIR}"/bin/clang -c -Wno-c++11-extensions \
-Xclang -load -Xclang "${CLANG_DIR}"/lib/libFindBadConstructs.${LIB} \ -Xclang -load -Xclang "${CLANG_DIR}"/lib/libFindBadConstructs.${LIB} \
-Xclang -plugin-arg-find-bad-constructs \
-Xclang check-inner-classes \
-Xclang -plugin -Xclang find-bad-constructs ${1} 2>&1)" -Xclang -plugin -Xclang find-bad-constructs ${1} 2>&1)"
local diffout="$(echo "${output}" | diff - "${2}")" local diffout="$(echo "${output}" | diff - "${2}")"
if [ "${diffout}" = "" ]; then if [ "${diffout}" = "" ]; then
......
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