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(
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());
}
/// 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);
continue;
QualType Type = F->getType();
if (!F->hasInClassInitializer() &&
- type_traits::isTriviallyDefaultConstructible(Type, Context))
+ utils::type_traits::isTriviallyDefaultConstructible(Type, Context))
FieldsToInit.insert(F);
}
}
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;
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);
}
}
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) {}
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")) {}
}
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
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;
};
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);
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) {
// 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());
}
}
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
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) {
// 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());
}
}
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
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;
}
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;
}
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())));
// 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 =
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);
}
}
namespace clang {
namespace tidy {
-namespace decl_ref_expr_utils {
+namespace utils {
+namespace decl_ref_expr {
using namespace ::clang::ast_matchers;
using llvm::SmallPtrSet;
return isSetDifferenceEmpty(AllDeclRefs, ConstReferenceDeclRefs);
}
-} // namespace decl_ref_expr_utils
+} // namespace decl_ref_expr
+} // namespace utils
} // namespace tidy
} // namespace clang
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.
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
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(),
return FixItHint::CreateInsertion(Var.getTypeSpecStartLoc(), "const ");
}
-} // namespace create_fix_it
+} // namespace fixit
} // namespace utils
} // namespace tidy
} // namespace clang
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);
/// \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
namespace clang {
namespace tidy {
+namespace utils {
/// \brief canonicalize a path by removing ./ and ../ components.
// FIXME: Consider moving this to llvm::sys::path.
return "endif // " + HeaderGuard.str();
}
+} // namespace utils
} // namespace tidy
} // namespace clang
namespace clang {
namespace tidy {
+namespace utils {
/// Finds and fixes header guards.
class HeaderGuardCheck : public ClangTidyCheck {
StringRef OldGuard = StringRef()) = 0;
};
+} // namespace utils
} // namespace tidy
} // namespace clang
namespace clang {
namespace tidy {
+namespace utils {
class IncludeInserterCallback : public PPCallbacks {
public:
end_location);
}
+} // namespace utils
} // namespace tidy
} // namespace clang
namespace clang {
namespace tidy {
+namespace utils {
// IncludeInserter can be used by ClangTidyChecks in the following fashion:
// class MyCheck : public ClangTidyCheck {
friend class IncludeInserterCallback;
};
+} // namespace utils
} // namespace tidy
} // namespace clang
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_INCLUDEINSERTER_H
namespace clang {
namespace tidy {
+namespace utils {
namespace {
return Style == IS_LLVM ? "llvm" : "google";
}
+} // namespace utils
} // namespace tidy
} // namespace clang
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
SmallVector<std::string, 1> IncludeBucket[IK_InvalidInclude];
};
+} // namespace utils
} // namespace tidy
} // namespace clang
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_INCLUDESORTER_H
namespace clang {
namespace tidy {
-namespace lexer_utils {
+namespace utils {
+namespace lexer {
Token getPreviousNonCommentToken(const ASTContext &Context,
SourceLocation Location) {
return Token;
}
-} // namespace lexer_utils
+} // namespace lexer
+} // namespace utils
} // namespace tidy
} // namespace clang
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
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());
}
namespace clang {
namespace tidy {
+namespace utils {
namespace type_traits {
namespace {
return false;
}
-} // type_traits
+} // namespace type_traits
+} // namespace utils
} // namespace tidy
} // namespace clang
namespace clang {
namespace tidy {
+namespace utils {
namespace type_traits {
// \brief Returns true If \c Type is expensive to copy.
const ASTContext &Context);
} // type_traits
+} // namespace utils
} // namespace tidy
} // namespace clang
: 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());
}
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 {