summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/cpp11-migrate/UseAuto/UseAutoMatchers.cpp
diff options
context:
space:
mode:
authorEdwin Vane <edwin.vane@intel.com>2013-04-02 20:43:57 +0000
committerEdwin Vane <edwin.vane@intel.com>2013-04-02 20:43:57 +0000
commiteeed39a58372135639c0b5918efb13ca552daec5 (patch)
tree320828cd2dfd70e37e60973c788deec4ccda2f39 /clang-tools-extra/cpp11-migrate/UseAuto/UseAutoMatchers.cpp
parent1afa68ed14ad9636dda390add3bf74e32b5c0303 (diff)
downloadbcm5719-llvm-eeed39a58372135639c0b5918efb13ca552daec5.tar.gz
bcm5719-llvm-eeed39a58372135639c0b5918efb13ca552daec5.zip
Use 'auto' with 'new' expressions
For variable declarations initialized with new expressions, use 'auto' for the type specifier. The 'auto' replacement happens only when the type of the VarDecl exactly matches the type of the initializer and the VarDecl is *not* CV-qualified. The only case that is currently handled is if the pointer type of the VarDecl is itself CV qualified. Some improvements need to be made to Clang's TypeLoc information in order for other CV qualifier cases to be successfully handled. See the new test suite new_cv_failing.cpp for examples of usages that could be handled with such an improvement. Function pointers are, for now, not transformed until the identifier info can be extracted. Reviewer: klimek llvm-svn: 178575
Diffstat (limited to 'clang-tools-extra/cpp11-migrate/UseAuto/UseAutoMatchers.cpp')
-rw-r--r--clang-tools-extra/cpp11-migrate/UseAuto/UseAutoMatchers.cpp35
1 files changed, 32 insertions, 3 deletions
diff --git a/clang-tools-extra/cpp11-migrate/UseAuto/UseAutoMatchers.cpp b/clang-tools-extra/cpp11-migrate/UseAuto/UseAutoMatchers.cpp
index b17708eabd4..08f9a7e52f6 100644
--- a/clang-tools-extra/cpp11-migrate/UseAuto/UseAutoMatchers.cpp
+++ b/clang-tools-extra/cpp11-migrate/UseAuto/UseAutoMatchers.cpp
@@ -18,7 +18,9 @@
using namespace clang::ast_matchers;
using namespace clang;
-const char *DeclNodeId = "decl";
+const char *IteratorDeclId = "iterator_decl";
+const char *DeclWithNewId = "decl_new";
+const char *NewExprId = "new_expr";
namespace clang {
namespace ast_matchers {
@@ -230,7 +232,7 @@ TypeMatcher iteratorFromUsingDeclaration() {
}
} // namespace
-DeclarationMatcher makeIteratorMatcher() {
+DeclarationMatcher makeIteratorDeclMatcher() {
return varDecl(allOf(
hasWrittenNonListInitializer(),
unless(hasType(autoType())),
@@ -243,5 +245,32 @@ DeclarationMatcher makeIteratorMatcher() {
)
)
)
- )).bind(DeclNodeId);
+ )).bind(IteratorDeclId);
+}
+
+DeclarationMatcher makeDeclWithNewMatcher() {
+ return varDecl(
+ hasInitializer(
+ ignoringParenImpCasts(
+ newExpr().bind(NewExprId)
+ )
+ ),
+
+ // FIXME: TypeLoc information is not reliable where CV qualifiers are
+ // concerned so these types can't be handled for now.
+ unless(hasType(pointerType(pointee(hasLocalQualifiers())))),
+
+ // FIXME: Handle function pointers. For now we ignore them because
+ // the replacement replaces the entire type specifier source range
+ // which includes the identifier.
+ unless(
+ hasType(
+ pointsTo(
+ pointsTo(
+ parenType(innerType(functionType()))
+ )
+ )
+ )
+ )
+ ).bind(DeclWithNewId);
}
OpenPOWER on IntegriCloud