Re: [clang-tools-extra] r283981 - [ClangTidy] Add UsingInserter and NamespaceAliaser

2016-10-12 Thread Renato Golin via cfe-commits
On 12 October 2016 at 08:59, Haojian Wu via cfe-commits
 wrote:
> Author: hokein
> Date: Wed Oct 12 02:59:54 2016
> New Revision: 283981
>
> URL: http://llvm.org/viewvc/llvm-project?rev=283981=rev
> Log:
> [ClangTidy] Add UsingInserter and NamespaceAliaser

Hi Haojian,

Many, if not all buildbots building Clang *also* build
clang-tools-extra. Any commit you make to your projects are bound to
affect many more buildbots than you would expect. So I'm asking you to
be careful with your commits, as this is not the first time.

One rule of thumb that I took it to heart very early on, after making
the same mistakes myself, is to *always* build and test someone else's
patch on my machine, in a configuration that is likely to be present
in most buildbots.

That practically means the following:

1. Have a check-out with LLVM+Clang+RT
2. Update it to the latest trunk, apply the patch
2.1 If it doesn't apply cleanly, refuse the patch, ask to rebase (you
could rebase it wrong and not notice, I've done that)
2.2 The original author rebases and updates the review
2.3 Goto 2
3. Run "make check-all" and it has to pass.
4. Commit, and hope for the best.

If even after that, it broke some obscure buildbot, that's life, we
can deal with that.

cheers,
--renato
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r283981 - [ClangTidy] Add UsingInserter and NamespaceAliaser

2016-10-12 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Wed Oct 12 02:59:54 2016
New Revision: 283981

URL: http://llvm.org/viewvc/llvm-project?rev=283981=rev
Log:
[ClangTidy] Add UsingInserter and NamespaceAliaser

Summary: This adds helper classes to add using declaractions and namespace 
aliases to function bodies. These help making function calls to deeply nested 
functions concise (e.g. when calling helpers in a refactoring)

Patch by Julian Bangert!

Reviewers: alexfh, hokein

Subscribers: cfe-commits

Tags: #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D24997

Added:
clang-tools-extra/trunk/clang-tidy/utils/ASTUtils.cpp
clang-tools-extra/trunk/clang-tidy/utils/ASTUtils.h
clang-tools-extra/trunk/clang-tidy/utils/NamespaceAliaser.cpp
clang-tools-extra/trunk/clang-tidy/utils/NamespaceAliaser.h
clang-tools-extra/trunk/clang-tidy/utils/UsingInserter.cpp
clang-tools-extra/trunk/clang-tidy/utils/UsingInserter.h
clang-tools-extra/trunk/unittests/clang-tidy/NamespaceAliaserTest.cpp
clang-tools-extra/trunk/unittests/clang-tidy/UsingInserterTest.cpp

Added: clang-tools-extra/trunk/clang-tidy/utils/ASTUtils.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/utils/ASTUtils.cpp?rev=283981=auto
==
--- clang-tools-extra/trunk/clang-tidy/utils/ASTUtils.cpp (added)
+++ clang-tools-extra/trunk/clang-tidy/utils/ASTUtils.cpp Wed Oct 12 02:59:54 
2016
@@ -0,0 +1,28 @@
+//===-- ASTUtils.cpp - clang-tidy ===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "ASTUtils.h"
+
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+
+namespace clang {
+namespace tidy {
+namespace utils {
+using namespace ast_matchers;
+
+const FunctionDecl *getSurroundingFunction(ASTContext ,
+   const Stmt ) {
+  return selectFirst(
+  "function", match(stmt(hasAncestor(functionDecl().bind("function"))),
+Statement, Context));
+}
+} // namespace utils
+} // namespace tidy
+} // namespace clang

Added: clang-tools-extra/trunk/clang-tidy/utils/ASTUtils.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/utils/ASTUtils.h?rev=283981=auto
==
--- clang-tools-extra/trunk/clang-tidy/utils/ASTUtils.h (added)
+++ clang-tools-extra/trunk/clang-tidy/utils/ASTUtils.h Wed Oct 12 02:59:54 2016
@@ -0,0 +1,25 @@
+//===-- ASTUtils.h - clang-tidy ===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ASTUTILS_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ASTUTILS_H
+
+#include "clang/AST/AST.h"
+
+namespace clang {
+namespace tidy {
+namespace utils {
+// Returns the (closest) Function declaration surrounding |Statement| or NULL.
+const FunctionDecl *getSurroundingFunction(ASTContext ,
+   const Stmt );
+} // namespace utils
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ASTUTILS_H

Added: clang-tools-extra/trunk/clang-tidy/utils/NamespaceAliaser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/utils/NamespaceAliaser.cpp?rev=283981=auto
==
--- clang-tools-extra/trunk/clang-tidy/utils/NamespaceAliaser.cpp (added)
+++ clang-tools-extra/trunk/clang-tidy/utils/NamespaceAliaser.cpp Wed Oct 12 
02:59:54 2016
@@ -0,0 +1,99 @@
+//===-- NamespaceAliaser.cpp - clang-tidy 
-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "NamespaceAliaser.h"
+
+#include "ASTUtils.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Lex/Lexer.h"
+namespace clang {
+namespace tidy {
+namespace utils {
+
+using namespace ast_matchers;
+
+NamespaceAliaser::NamespaceAliaser(const SourceManager )
+: SourceMgr(SourceMgr) {}
+
+AST_MATCHER_P(NamespaceAliasDecl, hasTargetNamespace,
+  ast_matchers::internal::Matcher, innerMatcher) {
+  return innerMatcher.matches(*Node.getNamespace(), Finder,