[clang-tidy] Cleanup namespace in utils folder.

Summary:
This is a step forward cleaning up the namespaces in clang-tidy/utils.
There is no behavior change.

Reviewers: alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D19819

llvm-svn: 268356
This commit is contained in:
Etienne Bergeron 2016-05-03 02:54:05 +00:00
parent 15a297212f
commit 2a4c00f243
30 changed files with 93 additions and 63 deletions

View File

@ -22,7 +22,7 @@ namespace cppcoreguidelines {
ProBoundsConstantArrayIndexCheck::ProBoundsConstantArrayIndexCheck(
StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context), GslHeader(Options.get("GslHeader", "")),
IncludeStyle(IncludeSorter::parseIncludeStyle(
IncludeStyle(utils::IncludeSorter::parseIncludeStyle(
Options.get("IncludeStyle", "llvm"))) {}
void ProBoundsConstantArrayIndexCheck::storeOptions(
@ -36,8 +36,8 @@ void ProBoundsConstantArrayIndexCheck::registerPPCallbacks(
if (!getLangOpts().CPlusPlus)
return;
Inserter.reset(new IncludeInserter(Compiler.getSourceManager(),
Compiler.getLangOpts(), IncludeStyle));
Inserter.reset(new utils::IncludeInserter(
Compiler.getSourceManager(), Compiler.getLangOpts(), IncludeStyle));
Compiler.getPreprocessor().addPPCallbacks(Inserter->CreatePPCallbacks());
}

View File

@ -24,8 +24,8 @@ namespace cppcoreguidelines {
/// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-pro-bounds-constant-array-index.html
class ProBoundsConstantArrayIndexCheck : public ClangTidyCheck {
const std::string GslHeader;
const IncludeSorter::IncludeStyle IncludeStyle;
std::unique_ptr<IncludeInserter> Inserter;
const utils::IncludeSorter::IncludeStyle IncludeStyle;
std::unique_ptr<utils::IncludeInserter> Inserter;
public:
ProBoundsConstantArrayIndexCheck(StringRef Name, ClangTidyContext *Context);

View File

@ -35,7 +35,7 @@ void fieldsRequiringInit(const RecordDecl::field_range &Fields,
continue;
QualType Type = F->getType();
if (!F->hasInClassInitializer() &&
type_traits::isTriviallyDefaultConstructible(Type, Context))
utils::type_traits::isTriviallyDefaultConstructible(Type, Context))
FieldsToInit.insert(F);
}
}
@ -114,12 +114,12 @@ struct IntializerInsertion {
SourceLocation Location;
switch (Placement) {
case InitializerPlacement::New:
Location = lexer_utils::getPreviousNonCommentToken(
Location = utils::lexer::getPreviousNonCommentToken(
Context, Constructor.getBody()->getLocStart())
.getLocation();
break;
case InitializerPlacement::Before:
Location = lexer_utils::getPreviousNonCommentToken(
Location = utils::lexer::getPreviousNonCommentToken(
Context, Where->getSourceRange().getBegin())
.getLocation();
break;
@ -389,7 +389,8 @@ void ProTypeMemberInitCheck::checkMissingBaseClassInitializer(
if (const auto *BaseClassDecl = getCanonicalRecordDecl(Base.getType())) {
AllBases.emplace_back(BaseClassDecl);
if (!BaseClassDecl->field_empty() &&
type_traits::isTriviallyDefaultConstructible(Base.getType(), Context))
utils::type_traits::isTriviallyDefaultConstructible(
Base.getType(), Context))
BasesToInit.insert(BaseClassDecl);
}
}

View File

@ -17,7 +17,7 @@ namespace tidy {
namespace llvm {
/// Finds and fixes header guards that do not adhere to LLVM style.
class LLVMHeaderGuardCheck : public HeaderGuardCheck {
class LLVMHeaderGuardCheck : public utils::HeaderGuardCheck {
public:
LLVMHeaderGuardCheck(StringRef Name, ClangTidyContext *Context)
: HeaderGuardCheck(Name, Context) {}

View File

@ -42,7 +42,7 @@ parmVarDeclRefExprOccurences(const ParmVarDecl &MovableParam,
MoveConstructorInitCheck::MoveConstructorInitCheck(StringRef Name,
ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
IncludeStyle(IncludeSorter::parseIncludeStyle(
IncludeStyle(utils::IncludeSorter::parseIncludeStyle(
Options.get("IncludeStyle", "llvm"))),
UseCERTSemantics(Context->isCheckEnabled("cert-oop11-cpp")) {}
@ -167,13 +167,14 @@ void MoveConstructorInitCheck::handleMoveConstructor(
}
void MoveConstructorInitCheck::registerPPCallbacks(CompilerInstance &Compiler) {
Inserter.reset(new IncludeInserter(Compiler.getSourceManager(),
Compiler.getLangOpts(), IncludeStyle));
Inserter.reset(new utils::IncludeInserter(
Compiler.getSourceManager(), Compiler.getLangOpts(), IncludeStyle));
Compiler.getPreprocessor().addPPCallbacks(Inserter->CreatePPCallbacks());
}
void MoveConstructorInitCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "IncludeStyle", IncludeSorter::toString(IncludeStyle));
Options.store(Opts, "IncludeStyle",
utils::IncludeSorter::toString(IncludeStyle));
}
} // namespace misc

View File

@ -38,8 +38,8 @@ private:
void
handleParamNotMoved(const ast_matchers::MatchFinder::MatchResult &Result);
std::unique_ptr<IncludeInserter> Inserter;
const IncludeSorter::IncludeStyle IncludeStyle;
std::unique_ptr<utils::IncludeInserter> Inserter;
const utils::IncludeSorter::IncludeStyle IncludeStyle;
const bool UseCERTSemantics;
};

View File

@ -40,7 +40,7 @@ void SuspiciousSemicolonCheck::check(const MatchFinder::MatchResult &Result) {
return;
ASTContext &Ctxt = *Result.Context;
auto Token = lexer_utils::getPreviousNonCommentToken(Ctxt, LocStart);
auto Token = utils::lexer::getPreviousNonCommentToken(Ctxt, LocStart);
auto &SM = *Result.SourceManager;
unsigned SemicolonLine = SM.getSpellingLineNumber(LocStart);

View File

@ -118,11 +118,12 @@ collectParamDecls(const CXXConstructorDecl *Ctor,
PassByValueCheck::PassByValueCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
IncludeStyle(IncludeSorter::parseIncludeStyle(
IncludeStyle(utils::IncludeSorter::parseIncludeStyle(
Options.get("IncludeStyle", "llvm"))) {}
void PassByValueCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "IncludeStyle", IncludeSorter::toString(IncludeStyle));
Options.store(Opts, "IncludeStyle",
utils::IncludeSorter::toString(IncludeStyle));
}
void PassByValueCheck::registerMatchers(MatchFinder *Finder) {
@ -162,8 +163,8 @@ void PassByValueCheck::registerPPCallbacks(CompilerInstance &Compiler) {
// currently does not provide any benefit to other languages, despite being
// benign.
if (getLangOpts().CPlusPlus) {
Inserter.reset(new IncludeInserter(Compiler.getSourceManager(),
Compiler.getLangOpts(), IncludeStyle));
Inserter.reset(new utils::IncludeInserter(
Compiler.getSourceManager(), Compiler.getLangOpts(), IncludeStyle));
Compiler.getPreprocessor().addPPCallbacks(Inserter->CreatePPCallbacks());
}
}

View File

@ -28,8 +28,8 @@ public:
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
private:
std::unique_ptr<IncludeInserter> Inserter;
const IncludeSorter::IncludeStyle IncludeStyle;
std::unique_ptr<utils::IncludeInserter> Inserter;
const utils::IncludeSorter::IncludeStyle IncludeStyle;
};
} // namespace modernize

View File

@ -189,11 +189,12 @@ static bool checkTokenIsAutoPtr(SourceLocation TokenStart,
ReplaceAutoPtrCheck::ReplaceAutoPtrCheck(StringRef Name,
ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
IncludeStyle(IncludeSorter::parseIncludeStyle(
IncludeStyle(utils::IncludeSorter::parseIncludeStyle(
Options.get("IncludeStyle", "llvm"))) {}
void ReplaceAutoPtrCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "IncludeStyle", IncludeSorter::toString(IncludeStyle));
Options.store(Opts, "IncludeStyle",
utils::IncludeSorter::toString(IncludeStyle));
}
void ReplaceAutoPtrCheck::registerMatchers(MatchFinder *Finder) {
@ -211,8 +212,8 @@ void ReplaceAutoPtrCheck::registerPPCallbacks(CompilerInstance &Compiler) {
// currently does not provide any benefit to other languages, despite being
// benign.
if (getLangOpts().CPlusPlus) {
Inserter.reset(new IncludeInserter(Compiler.getSourceManager(),
Compiler.getLangOpts(), IncludeStyle));
Inserter.reset(new utils::IncludeInserter(
Compiler.getSourceManager(), Compiler.getLangOpts(), IncludeStyle));
Compiler.getPreprocessor().addPPCallbacks(Inserter->CreatePPCallbacks());
}
}

View File

@ -50,8 +50,8 @@ public:
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
private:
std::unique_ptr<IncludeInserter> Inserter;
const IncludeSorter::IncludeStyle IncludeStyle;
std::unique_ptr<utils::IncludeInserter> Inserter;
const utils::IncludeSorter::IncludeStyle IncludeStyle;
};
} // namespace modernize

View File

@ -59,16 +59,16 @@ bool ForRangeCopyCheck::handleConstValueCopy(const VarDecl &LoopVar,
return false;
}
llvm::Optional<bool> Expensive =
type_traits::isExpensiveToCopy(LoopVar.getType(), Context);
utils::type_traits::isExpensiveToCopy(LoopVar.getType(), Context);
if (!Expensive || !*Expensive)
return false;
auto Diagnostic =
diag(LoopVar.getLocation(),
"the loop variable's type is not a reference type; this creates a "
"copy in each iteration; consider making this a reference")
<< utils::create_fix_it::changeVarDeclToReference(LoopVar, Context);
<< utils::fixit::changeVarDeclToReference(LoopVar, Context);
if (!LoopVar.getType().isConstQualified())
Diagnostic << utils::create_fix_it::changeVarDeclToConst(LoopVar);
Diagnostic << utils::fixit::changeVarDeclToConst(LoopVar);
return true;
}
@ -76,16 +76,17 @@ bool ForRangeCopyCheck::handleCopyIsOnlyConstReferenced(
const VarDecl &LoopVar, const CXXForRangeStmt &ForRange,
ASTContext &Context) {
llvm::Optional<bool> Expensive =
type_traits::isExpensiveToCopy(LoopVar.getType(), Context);
utils::type_traits::isExpensiveToCopy(LoopVar.getType(), Context);
if (LoopVar.getType().isConstQualified() || !Expensive || !*Expensive)
return false;
if (!decl_ref_expr_utils::isOnlyUsedAsConst(LoopVar, *ForRange.getBody(), Context))
if (!utils::decl_ref_expr::isOnlyUsedAsConst(LoopVar, *ForRange.getBody(),
Context))
return false;
diag(LoopVar.getLocation(),
"loop variable is copied but only used as const reference; consider "
"making it a const reference")
<< utils::create_fix_it::changeVarDeclToConst(LoopVar)
<< utils::create_fix_it::changeVarDeclToReference(LoopVar, Context);
<< utils::fixit::changeVarDeclToConst(LoopVar)
<< utils::fixit::changeVarDeclToReference(LoopVar, Context);
return true;
}

View File

@ -24,16 +24,16 @@ void recordFixes(const VarDecl &Var, ASTContext &Context,
if (Var.getLocation().isMacroID())
return;
Diagnostic << utils::create_fix_it::changeVarDeclToReference(Var, Context);
Diagnostic << utils::fixit::changeVarDeclToReference(Var, Context);
if (!Var.getType().isLocalConstQualified())
Diagnostic << utils::create_fix_it::changeVarDeclToConst(Var);
Diagnostic << utils::fixit::changeVarDeclToConst(Var);
}
} // namespace
using namespace ::clang::ast_matchers;
using decl_ref_expr_utils::isOnlyUsedAsConst;
using utils::decl_ref_expr::isOnlyUsedAsConst;
void UnnecessaryCopyInitialization::registerMatchers(MatchFinder *Finder) {
auto ConstReference = referenceType(pointee(qualType(isConstQualified())));

View File

@ -61,7 +61,7 @@ void UnnecessaryValueParamCheck::check(const MatchFinder::MatchResult &Result) {
// 2. they are not only used as const.
if (!IsConstQualified && (llvm::isa<CXXConstructorDecl>(Function) ||
!Function->doesThisDeclarationHaveABody() ||
!decl_ref_expr_utils::isOnlyUsedAsConst(
!utils::decl_ref_expr::isOnlyUsedAsConst(
*Param, *Function->getBody(), *Result.Context)))
return;
auto Diag =
@ -79,10 +79,10 @@ void UnnecessaryValueParamCheck::check(const MatchFinder::MatchResult &Result) {
for (const auto *FunctionDecl = Function; FunctionDecl != nullptr;
FunctionDecl = FunctionDecl->getPreviousDecl()) {
const auto &CurrentParam = *FunctionDecl->getParamDecl(Index);
Diag << utils::create_fix_it::changeVarDeclToReference(CurrentParam,
Diag << utils::fixit::changeVarDeclToReference(CurrentParam,
*Result.Context);
if (!IsConstQualified)
Diag << utils::create_fix_it::changeVarDeclToConst(CurrentParam);
Diag << utils::fixit::changeVarDeclToConst(CurrentParam);
}
}

View File

@ -15,7 +15,8 @@
namespace clang {
namespace tidy {
namespace decl_ref_expr_utils {
namespace utils {
namespace decl_ref_expr {
using namespace ::clang::ast_matchers;
using llvm::SmallPtrSet;
@ -93,6 +94,7 @@ bool isOnlyUsedAsConst(const VarDecl &Var, const Stmt &Stmt,
return isSetDifferenceEmpty(AllDeclRefs, ConstReferenceDeclRefs);
}
} // namespace decl_ref_expr_utils
} // namespace decl_ref_expr
} // namespace utils
} // namespace tidy
} // namespace clang

View File

@ -15,7 +15,8 @@
namespace clang {
namespace tidy {
namespace decl_ref_expr_utils {
namespace utils {
namespace decl_ref_expr {
/// \brief Returns true if all DeclRefExpr to the variable within Stmt do not
/// modify it.
@ -25,7 +26,8 @@ namespace decl_ref_expr_utils {
bool isOnlyUsedAsConst(const VarDecl &Var, const Stmt &Stmt,
ASTContext &Context);
} // namespace decl_ref_expr_utils
} // namespace decl_ref_expr
} // namespace utils
} // namespace tidy
} // namespace clang

View File

@ -14,11 +14,11 @@
namespace clang {
namespace tidy {
namespace utils {
namespace create_fix_it {
namespace fixit {
FixItHint changeVarDeclToReference(const VarDecl &Var, ASTContext &Context) {
SourceLocation AmpLocation = Var.getLocation();
auto Token = lexer_utils::getPreviousNonCommentToken(Context, AmpLocation);
auto Token = utils::lexer::getPreviousNonCommentToken(Context, AmpLocation);
if (!Token.is(tok::unknown))
AmpLocation = Lexer::getLocForEndOfToken(Token.getLocation(), 0,
Context.getSourceManager(),
@ -30,7 +30,7 @@ FixItHint changeVarDeclToConst(const VarDecl &Var) {
return FixItHint::CreateInsertion(Var.getTypeSpecStartLoc(), "const ");
}
} // namespace create_fix_it
} // namespace fixit
} // namespace utils
} // namespace tidy
} // namespace clang

View File

@ -16,7 +16,7 @@
namespace clang {
namespace tidy {
namespace utils {
namespace create_fix_it {
namespace fixit {
/// \brief Creates fix to make VarDecl a reference by adding '&'.
FixItHint changeVarDeclToReference(const VarDecl &Var, ASTContext &Context);
@ -24,8 +24,8 @@ FixItHint changeVarDeclToReference(const VarDecl &Var, ASTContext &Context);
/// \brief Creates fix to make VarDecl const qualified.
FixItHint changeVarDeclToConst(const VarDecl &Var);
} // namespace create_fix_it
} // utils
} // namespace fixit
} // namespace utils
} // namespace tidy
} // namespace clang

View File

@ -16,6 +16,7 @@
namespace clang {
namespace tidy {
namespace utils {
/// \brief canonicalize a path by removing ./ and ../ components.
// FIXME: Consider moving this to llvm::sys::path.
@ -299,5 +300,6 @@ std::string HeaderGuardCheck::formatEndIf(StringRef HeaderGuard) {
return "endif // " + HeaderGuard.str();
}
} // namespace utils
} // namespace tidy
} // namespace clang

View File

@ -14,6 +14,7 @@
namespace clang {
namespace tidy {
namespace utils {
/// Finds and fixes header guards.
class HeaderGuardCheck : public ClangTidyCheck {
@ -40,6 +41,7 @@ public:
StringRef OldGuard = StringRef()) = 0;
};
} // namespace utils
} // namespace tidy
} // namespace clang

View File

@ -12,6 +12,7 @@
namespace clang {
namespace tidy {
namespace utils {
class IncludeInserterCallback : public PPCallbacks {
public:
@ -80,5 +81,6 @@ void IncludeInserter::AddInclude(StringRef file_name, bool IsAngled,
end_location);
}
} // namespace utils
} // namespace tidy
} // namespace clang

View File

@ -20,6 +20,7 @@
namespace clang {
namespace tidy {
namespace utils {
// IncludeInserter can be used by ClangTidyChecks in the following fashion:
// class MyCheck : public ClangTidyCheck {
@ -70,6 +71,7 @@ private:
friend class IncludeInserterCallback;
};
} // namespace utils
} // namespace tidy
} // namespace clang
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_INCLUDEINSERTER_H

View File

@ -12,6 +12,7 @@
namespace clang {
namespace tidy {
namespace utils {
namespace {
@ -291,5 +292,6 @@ StringRef IncludeSorter::toString(IncludeStyle Style) {
return Style == IS_LLVM ? "llvm" : "google";
}
} // namespace utils
} // namespace tidy
} // namespace clang

View File

@ -15,6 +15,7 @@
namespace clang {
namespace tidy {
namespace utils {
// Class used by IncludeSorterCallback and IncludeInserterCallback to record the
// names of the inclusions in a given source file being processed and generate
@ -83,6 +84,7 @@ private:
SmallVector<std::string, 1> IncludeBucket[IK_InvalidInclude];
};
} // namespace utils
} // namespace tidy
} // namespace clang
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_INCLUDESORTER_H

View File

@ -11,7 +11,8 @@
namespace clang {
namespace tidy {
namespace lexer_utils {
namespace utils {
namespace lexer {
Token getPreviousNonCommentToken(const ASTContext &Context,
SourceLocation Location) {
@ -34,6 +35,7 @@ Token getPreviousNonCommentToken(const ASTContext &Context,
return Token;
}
} // namespace lexer_utils
} // namespace lexer
} // namespace utils
} // namespace tidy
} // namespace clang

View File

@ -15,14 +15,16 @@
namespace clang {
namespace tidy {
namespace lexer_utils {
namespace utils {
namespace lexer {
// Returns previous non-comment token skipping over any comment text or
// tok::unknown if not found.
Token getPreviousNonCommentToken(const ASTContext &Context,
SourceLocation Location);
} // namespace lexer_utils
} // namespace lexer
} // namespace utils
} // namespace tidy
} // namespace clang

View File

@ -31,12 +31,12 @@ AST_MATCHER(BinaryOperator, isComparisonOperator) {
AST_MATCHER(QualType, isExpensiveToCopy) {
llvm::Optional<bool> IsExpensive =
type_traits::isExpensiveToCopy(Node, Finder->getASTContext());
utils::type_traits::isExpensiveToCopy(Node, Finder->getASTContext());
return IsExpensive && *IsExpensive;
}
AST_MATCHER(RecordDecl, isTriviallyDefaultConstructible) {
return type_traits::recordIsTriviallyDefaultConstructible(
return utils::type_traits::recordIsTriviallyDefaultConstructible(
Node, Finder->getASTContext());
}

View File

@ -13,6 +13,7 @@
namespace clang {
namespace tidy {
namespace utils {
namespace type_traits {
namespace {
@ -106,6 +107,7 @@ bool isTriviallyDefaultConstructible(QualType Type, const ASTContext &Context) {
return false;
}
} // type_traits
} // namespace type_traits
} // namespace utils
} // namespace tidy
} // namespace clang

View File

@ -15,6 +15,7 @@
namespace clang {
namespace tidy {
namespace utils {
namespace type_traits {
// \brief Returns true If \c Type is expensive to copy.
@ -28,6 +29,7 @@ bool recordIsTriviallyDefaultConstructible(const RecordDecl &RecordDecl,
const ASTContext &Context);
} // type_traits
} // namespace utils
} // namespace tidy
} // namespace clang

View File

@ -33,9 +33,10 @@ public:
: ClangTidyCheck(CheckName, Context) {}
void registerPPCallbacks(CompilerInstance &Compiler) override {
Inserter.reset(new IncludeInserter(Compiler.getSourceManager(),
Compiler.getLangOpts(),
IncludeSorter::IS_Google));
Inserter.reset(new utils::IncludeInserter(
Compiler.getSourceManager(),
Compiler.getLangOpts(),
utils::IncludeSorter::IS_Google));
Compiler.getPreprocessor().addPPCallbacks(Inserter->CreatePPCallbacks());
}
@ -58,7 +59,7 @@ public:
virtual std::vector<StringRef> HeadersToInclude() const = 0;
virtual bool IsAngledInclude() const = 0;
std::unique_ptr<IncludeInserter> Inserter;
std::unique_ptr<utils::IncludeInserter> Inserter;
};
class NonSystemHeaderInserterCheck : public IncludeInserterCheckBase {