diff options
Diffstat (limited to 'clang-tools-extra/change-namespace/ChangeNamespace.cpp')
-rw-r--r-- | clang-tools-extra/change-namespace/ChangeNamespace.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/clang-tools-extra/change-namespace/ChangeNamespace.cpp b/clang-tools-extra/change-namespace/ChangeNamespace.cpp index 44eec1a4dba..7de4690ac11 100644 --- a/clang-tools-extra/change-namespace/ChangeNamespace.cpp +++ b/clang-tools-extra/change-namespace/ChangeNamespace.cpp @@ -41,7 +41,7 @@ SourceLocation startLocationForType(TypeLoc TLoc) { return TLoc.getLocStart(); } -SourceLocation EndLocationForType(TypeLoc TLoc) { +SourceLocation endLocationForType(TypeLoc TLoc) { // Dig past any namespace or keyword qualifications. while (TLoc.getTypeLocClass() == TypeLoc::Elaborated || TLoc.getTypeLocClass() == TypeLoc::Qualified) @@ -249,7 +249,7 @@ ChangeNamespaceTool::ChangeNamespaceTool( llvm::StringRef FallbackStyle) : FallbackStyle(FallbackStyle), FileToReplacements(*FileToReplacements), OldNamespace(OldNs.ltrim(':')), NewNamespace(NewNs.ltrim(':')), - FilePattern(FilePattern) { + FilePattern(FilePattern), FilePatternRE(FilePattern) { FileToReplacements->clear(); llvm::SmallVector<llvm::StringRef, 4> OldNsSplitted; llvm::SmallVector<llvm::StringRef, 4> NewNsSplitted; @@ -407,7 +407,7 @@ void ChangeNamespaceTool::run( Result.Nodes.getNodeAs<NestedNameSpecifierLoc>( "nested_specifier_loc")) { SourceLocation Start = Specifier->getBeginLoc(); - SourceLocation End = EndLocationForType(Specifier->getTypeLoc()); + SourceLocation End = endLocationForType(Specifier->getTypeLoc()); fixTypeLoc(Result, Start, End, Specifier->getTypeLoc()); } else if (const auto *BaseInitializer = Result.Nodes.getNodeAs<CXXCtorInitializer>( @@ -415,7 +415,7 @@ void ChangeNamespaceTool::run( BaseCtorInitializerTypeLocs.push_back( BaseInitializer->getTypeSourceInfo()->getTypeLoc()); } else if (const auto *TLoc = Result.Nodes.getNodeAs<TypeLoc>("type")) { - fixTypeLoc(Result, startLocationForType(*TLoc), EndLocationForType(*TLoc), + fixTypeLoc(Result, startLocationForType(*TLoc), endLocationForType(*TLoc), *TLoc); } else if (const auto *VarRef = Result.Nodes.getNodeAs<DeclRefExpr>("var_ref")) { @@ -667,8 +667,7 @@ void ChangeNamespaceTool::fixTypeLoc( return false; llvm::StringRef Filename = Result.SourceManager->getFilename(ExpansionLoc); - llvm::Regex RE(FilePattern); - return RE.match(Filename); + return FilePatternRE.match(Filename); }; // Don't fix the \p Type if it refers to a type alias decl in the moved // namespace since the alias decl will be moved along with the type @@ -779,6 +778,12 @@ void ChangeNamespaceTool::onEndOfTranslationUnit() { } FileToReplacements[FilePath] = *CleanReplacements; } + + // Make sure we don't generate replacements for files that do not match + // FilePattern. + for (auto &Entry : FileToReplacements) + if (!FilePatternRE.match(Entry.first)) + Entry.second.clear(); } } // namespace change_namespace |