From d9063c46f59f4bec47bcbeddca8ca2f789348c03 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Wed, 4 Sep 2013 17:35:07 +0000 Subject: Rename cpp11-migrate to clang-modernize. There is no reason to expect this tool to be limited to C++11, it seems very likely to be of on-going interest. It seems likely to be useful for modernizing even as new libraries come out in TSes and other formats than a complete standard. Fundamentally, we need something a bit more general. After some discussion on the list, going with 'clang-modernize'. I've tried to do a reasonably comprehensive job of fixing up the names, but I may still have missed some. Feel free to poke me if you spot any fallout here. Things I've tried reasonably hard to find and fix: - cpp11-migrate -> clang-modernize - Migrator -> Modernizer - Clean up the introductory documentation that was C++11 specific. I'll also point out that this tool continues to delight me. =] Also, a huge thanks to those who have so carefully, thoroughly documented the tool. The docs here are simply phenomenal. Every tool should be this well documented. I hope I have updated the documentation reasonably well, but I'm not very good at documentation, so review much appreciated. llvm-svn: 189960 --- .../cpp11-migrate/UseAuto/UseAutoActions.cpp | 147 --------------------- 1 file changed, 147 deletions(-) delete mode 100644 clang-tools-extra/cpp11-migrate/UseAuto/UseAutoActions.cpp (limited to 'clang-tools-extra/cpp11-migrate/UseAuto/UseAutoActions.cpp') diff --git a/clang-tools-extra/cpp11-migrate/UseAuto/UseAutoActions.cpp b/clang-tools-extra/cpp11-migrate/UseAuto/UseAutoActions.cpp deleted file mode 100644 index 2a8d5c5935d..00000000000 --- a/clang-tools-extra/cpp11-migrate/UseAuto/UseAutoActions.cpp +++ /dev/null @@ -1,147 +0,0 @@ -//===-- UseAuto/UseAutoActions.cpp - Matcher callback impl ----------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -/// -/// \file -/// \brief This file contains the implementation of callbacks for the UseAuto -/// transform. -/// -//===----------------------------------------------------------------------===// - -#include "UseAutoActions.h" -#include "UseAutoMatchers.h" -#include "clang/AST/ASTContext.h" - -using namespace clang::ast_matchers; -using namespace clang::tooling; -using namespace clang; - -void IteratorReplacer::run(const MatchFinder::MatchResult &Result) { - const DeclStmt *D = Result.Nodes.getNodeAs(IteratorDeclStmtId); - assert(D && "Bad Callback. No node provided"); - - SourceManager &SM = *Result.SourceManager; - if (!Owner.isFileModifiable(SM, D->getLocStart())) - return; - - for (clang::DeclStmt::const_decl_iterator DI = D->decl_begin(), - DE = D->decl_end(); - DI != DE; ++DI) { - const VarDecl *V = cast(*DI); - - const Expr *ExprInit = V->getInit(); - - // Skip expressions with cleanups from the initializer expression. - if (const ExprWithCleanups *E = dyn_cast(ExprInit)) - ExprInit = E->getSubExpr(); - - const CXXConstructExpr *Construct = cast(ExprInit); - - assert(Construct->getNumArgs() == 1u && - "Expected constructor with single argument"); - - // Drill down to the as-written initializer. - const Expr *E = Construct->arg_begin()->IgnoreParenImpCasts(); - if (E != E->IgnoreConversionOperator()) - // We hit a conversion operator. Early-out now as they imply an implicit - // conversion from a different type. Could also mean an explicit - // conversion from the same type but that's pretty rare. - return; - - if (const CXXConstructExpr *NestedConstruct = dyn_cast(E)) - // If we ran into an implicit conversion constructor, can't convert. - // - // FIXME: The following only checks if the constructor can be used - // implicitly, not if it actually was. Cases where the converting - // constructor was used explicitly won't get converted. - if (NestedConstruct->getConstructor()->isConvertingConstructor(false)) - return; - if (!Result.Context->hasSameType(V->getType(), E->getType())) - return; - } - // Get the type location using the first declartion. - const VarDecl *V = cast(*D->decl_begin()); - TypeLoc TL = V->getTypeSourceInfo()->getTypeLoc(); - - // WARNING: TypeLoc::getSourceRange() will include the identifier for things - // like function pointers. Not a concern since this action only works with - // iterators but something to keep in mind in the future. - - CharSourceRange Range(TL.getSourceRange(), true); - Owner.addReplacementForCurrentTU(tooling::Replacement(SM, Range, "auto")); - ++AcceptedChanges; -} - -void NewReplacer::run(const MatchFinder::MatchResult &Result) { - const DeclStmt *D = Result.Nodes.getNodeAs(DeclWithNewId); - assert(D && "Bad Callback. No node provided"); - - SourceManager &SM = *Result.SourceManager; - if (!Owner.isFileModifiable(SM, D->getLocStart())) - return; - - const VarDecl *FirstDecl = cast(*D->decl_begin()); - // Ensure that there is at least one VarDecl within de DeclStmt. - assert(FirstDecl && "No VarDecl provided"); - - const QualType FirstDeclType = FirstDecl->getType().getCanonicalType(); - - std::vector StarLocations; - for (clang::DeclStmt::const_decl_iterator DI = D->decl_begin(), - DE = D->decl_end(); - DI != DE; ++DI) { - - const VarDecl *V = cast(*DI); - // Ensure that every DeclStmt child is a VarDecl. - assert(V && "No VarDecl provided"); - - const CXXNewExpr *NewExpr = - cast(V->getInit()->IgnoreParenImpCasts()); - // Ensure that every VarDecl has a CXXNewExpr initializer. - assert(NewExpr && "No CXXNewExpr provided"); - - // If VarDecl and Initializer have mismatching unqualified types. - if (!Result.Context->hasSameUnqualifiedType(V->getType(), - NewExpr->getType())) - return; - - // Remove explicitly written '*' from declarations where there's more than - // one declaration in the declaration list. - if (DI == D->decl_begin()) - continue; - - // All subsequent delcarations should match the same non-decorated type. - if (FirstDeclType != V->getType().getCanonicalType()) - return; - - PointerTypeLoc Q = - V->getTypeSourceInfo()->getTypeLoc().getAs(); - while (!Q.isNull()) { - StarLocations.push_back(Q.getStarLoc()); - Q = Q.getNextTypeLoc().getAs(); - } - } - - // Remove '*' from declarations using the saved star locations. - for (std::vector::iterator I = StarLocations.begin(), - E = StarLocations.end(); - I != E; ++I) { - Owner.addReplacementForCurrentTU(tooling::Replacement(SM, *I, 1, "")); - } - - // FIXME: There is, however, one case we can address: when the VarDecl - // pointee is the same as the initializer, just more CV-qualified. However, - // TypeLoc information is not reliable where CV qualifiers are concerned so - // we can't do anything about this case for now. - CharSourceRange Range( - FirstDecl->getTypeSourceInfo()->getTypeLoc().getSourceRange(), true); - // Space after 'auto' to handle cases where the '*' in the pointer type - // is next to the identifier. This avoids changing 'int *p' into 'autop'. - Owner.addReplacementForCurrentTU(tooling::Replacement(SM, Range, "auto ")); - ++AcceptedChanges; -} -- cgit v1.2.3