clang-tools 17.0.0git
Namespaces | Classes | Functions
clang::tidy::utils Namespace Reference

Namespaces

namespace  decl_ref_expr
 
namespace  fixit
 
namespace  lexer
 
namespace  options
 
namespace  type_traits
 

Classes

class  ExceptionAnalyzer
 This class analysis if a FunctionDecl can in principle throw an exception, either directly or indirectly. More...
 
class  ExprSequence
 Provides information about the evaluation order of (sub-)expressions within a CFGBlock. More...
 
class  HeaderGuardCheck
 Finds and fixes header guards. More...
 
class  IncludeInserter
 Produces fixes to insert specified includes to source files, if not yet present. More...
 
class  IncludeInserterCallback
 
class  IncludeSorter
 Class used by IncludeInserterCallback to record the names of the inclusions in a given source file being processed and generate the necessary commands to sort the inclusions according to the precedence encoded in IncludeKinds. More...
 
class  NamespaceAliaser
 
class  StmtToBlockMap
 Maps Stmts to the CFGBlock that contains them. More...
 
class  TransformerClangTidyCheck
 A base class for defining a ClangTidy check based on a RewriteRule. More...
 
class  UsingInserter
 

Functions

static bool isAccessForVar (const Stmt *S, const VarDecl *Var)
 Return whether S is a reference to the declaration of Var.
 
static bool capturesByRef (const CXXRecordDecl *RD, const VarDecl *Var)
 
static bool isPtrOrReferenceForVar (const Stmt *S, const VarDecl *Var)
 Return whether Var has a pointer or reference in S.
 
static bool hasPtrOrReferenceInStmt (const Stmt *S, const VarDecl *Var)
 Return whether Var has a pointer or reference in S.
 
static bool refersToEnclosingLambdaCaptureByRef (const Decl *Func, const VarDecl *Var)
 
bool hasPtrOrReferenceInFunc (const Decl *Func, const VarDecl *Var)
 Returns whether Var has a pointer or reference in Func.
 
const FunctionDecl * getSurroundingFunction (ASTContext &Context, const Stmt &Statement)
 
bool isBinaryOrTernary (const Expr *E)
 
bool exprHasBitFlagWithSpelling (const Expr *Flags, const SourceManager &SM, const LangOptions &LangOpts, StringRef FlagName)
 Checks whether a macro flag is present in the given argument.
 
bool rangeIsEntirelyWithinMacroArgument (SourceRange Range, const SourceManager *SM)
 
bool rangeContainsMacroExpansion (SourceRange Range, const SourceManager *SM)
 
bool rangeCanBeFixed (SourceRange Range, const SourceManager *SM)
 
static SmallVector< const Stmt *, 1 > getParentStmts (const Stmt *S, ASTContext *Context)
 
bool isExpansionLocInHeaderFile (SourceLocation Loc, const SourceManager &SM, const FileExtensionsSet &HeaderFileExtensions)
 Checks whether expansion location of Loc is in header file.
 
bool isPresumedLocInHeaderFile (SourceLocation Loc, SourceManager &SM, const FileExtensionsSet &HeaderFileExtensions)
 Checks whether presumed location of Loc is in header file.
 
bool isSpellingLocInHeaderFile (SourceLocation Loc, SourceManager &SM, const FileExtensionsSet &HeaderFileExtensions)
 Checks whether spelling location of Loc is in header file.
 
bool parseFileExtensions (StringRef AllFileExtensions, FileExtensionsSet &FileExtensions, StringRef Delimiters)
 Parses header file extensions from a semicolon-separated list.
 
std::optional< StringRef > getFileExtension (StringRef FileName, const FileExtensionsSet &FileExtensions)
 Decides whether a file has a header file extension.
 
bool isFileExtension (StringRef FileName, const FileExtensionsSet &FileExtensions)
 Decides whether a file has one of the specified file extensions.
 
StringRef defaultHeaderFileExtensions ()
 Returns recommended default value for the list of header file extensions.
 
StringRef defaultImplementationFileExtensions ()
 Returns recommended default value for the list of implementation file extensions.
 
StringRef defaultFileExtensionDelimiters ()
 Returns recommended default value for the list of file extension delimiters.
 
static std::string cleanPath (StringRef Path)
 canonicalize a path by removing ./ and ../ components.
 
 AST_MATCHER_P (NamespaceAliasDecl, hasTargetNamespace, ast_matchers::internal::Matcher< NamespaceDecl >, innerMatcher)
 
static bool hasGenerator (const transformer::Generator< std::string > &G)
 
static void verifyRule (const RewriteRuleWith< std::string > &Rule)
 
std::string escapeForDiagnostic (std::string ToEscape)
 
static StringRef getUnqualifiedName (StringRef QualifiedName)
 

Function Documentation

◆ AST_MATCHER_P()

clang::tidy::utils::AST_MATCHER_P ( NamespaceAliasDecl  ,
hasTargetNamespace  ,
ast_matchers::internal::Matcher< NamespaceDecl >  ,
innerMatcher   
)

Definition at line 23 of file NamespaceAliaser.cpp.

References Builder.

◆ capturesByRef()

static bool clang::tidy::utils::capturesByRef ( const CXXRecordDecl *  RD,
const VarDecl *  Var 
)
static

Definition at line 24 of file Aliasing.cpp.

References C.

Referenced by isPtrOrReferenceForVar(), and refersToEnclosingLambdaCaptureByRef().

◆ cleanPath()

static std::string clang::tidy::utils::cleanPath ( StringRef  Path)
static

canonicalize a path by removing ./ and ../ components.

Definition at line 19 of file HeaderGuard.cpp.

References Path.

◆ defaultFileExtensionDelimiters()

StringRef clang::tidy::utils::defaultFileExtensionDelimiters ( )
inline

◆ defaultHeaderFileExtensions()

StringRef clang::tidy::utils::defaultHeaderFileExtensions ( )
inline

◆ defaultImplementationFileExtensions()

StringRef clang::tidy::utils::defaultImplementationFileExtensions ( )
inline

Returns recommended default value for the list of implementation file extensions.

Definition at line 39 of file FileExtensionsUtils.h.

Referenced by clang::tidy::bugprone::SuspiciousIncludeCheck::SuspiciousIncludeCheck().

◆ escapeForDiagnostic()

std::string clang::tidy::utils::escapeForDiagnostic ( std::string  ToEscape)

Definition at line 33 of file TransformerClangTidyCheck.cpp.

References C, and Pos.

Referenced by clang::tidy::utils::TransformerClangTidyCheck::check().

◆ exprHasBitFlagWithSpelling()

bool clang::tidy::utils::exprHasBitFlagWithSpelling ( const Expr *  Flags,
const SourceManager &  SM,
const LangOptions &  LangOpts,
StringRef  FlagName 
)

Checks whether a macro flag is present in the given argument.

Only considers cases of single match or match in a binary OR expression. For example, <needed-flag> or <flag> | <needed-flag> | ...

Definition at line 38 of file ASTUtils.cpp.

References exprHasBitFlagWithSpelling(), Flags, and MacroName.

Referenced by exprHasBitFlagWithSpelling(), and clang::tidy::android::CloexecCheck::insertMacroFlag().

◆ getFileExtension()

std::optional< StringRef > clang::tidy::utils::getFileExtension ( StringRef  FileName,
const FileExtensionsSet FileExtensions 
)

Decides whether a file has a header file extension.

Returns the file extension, if included in the provided set.

Definition at line 56 of file FileExtensionsUtils.cpp.

References FileName.

Referenced by isFileExtension().

◆ getParentStmts()

static SmallVector< const Stmt *, 1 > clang::tidy::utils::getParentStmts ( const Stmt *  S,
ASTContext *  Context 
)
static

◆ getSurroundingFunction()

const FunctionDecl * clang::tidy::utils::getSurroundingFunction ( ASTContext &  Context,
const Stmt &  Statement 
)

◆ getUnqualifiedName()

static StringRef clang::tidy::utils::getUnqualifiedName ( StringRef  QualifiedName)
static

◆ hasGenerator()

static bool clang::tidy::utils::hasGenerator ( const transformer::Generator< std::string > &  G)
static

Definition at line 19 of file TransformerClangTidyCheck.cpp.

Referenced by verifyRule().

◆ hasPtrOrReferenceInFunc()

bool clang::tidy::utils::hasPtrOrReferenceInFunc ( const Decl Func,
const VarDecl *  Var 
)

Returns whether Var has a pointer or reference in Func.

Example: void f() { int n; ... int *p = &n; }

For f() and n the function returns true because p is a pointer to n created in f().

Definition at line 92 of file Aliasing.cpp.

References hasPtrOrReferenceInFunc(), hasPtrOrReferenceInStmt(), and refersToEnclosingLambdaCaptureByRef().

Referenced by hasPtrOrReferenceInFunc().

◆ hasPtrOrReferenceInStmt()

static bool clang::tidy::utils::hasPtrOrReferenceInStmt ( const Stmt *  S,
const VarDecl *  Var 
)
static

Return whether Var has a pointer or reference in S.

Definition at line 64 of file Aliasing.cpp.

References hasPtrOrReferenceInStmt(), and isPtrOrReferenceForVar().

Referenced by hasPtrOrReferenceInFunc(), and hasPtrOrReferenceInStmt().

◆ isAccessForVar()

static bool clang::tidy::utils::isAccessForVar ( const Stmt *  S,
const VarDecl *  Var 
)
static

Return whether S is a reference to the declaration of Var.

Definition at line 17 of file Aliasing.cpp.

Referenced by isPtrOrReferenceForVar().

◆ isBinaryOrTernary()

bool clang::tidy::utils::isBinaryOrTernary ( const Expr *  E)

Definition at line 25 of file ASTUtils.cpp.

References E, and isBinaryOrTernary().

Referenced by isBinaryOrTernary().

◆ isExpansionLocInHeaderFile()

bool clang::tidy::utils::isExpansionLocInHeaderFile ( SourceLocation  Loc,
const SourceManager &  SM,
const FileExtensionsSet HeaderFileExtensions 
)

Checks whether expansion location of Loc is in header file.

Definition at line 16 of file FileExtensionsUtils.cpp.

References isFileExtension(), and Loc.

◆ isFileExtension()

bool clang::tidy::utils::isFileExtension ( StringRef  FileName,
const FileExtensionsSet FileExtensions 
)

◆ isPresumedLocInHeaderFile()

bool clang::tidy::utils::isPresumedLocInHeaderFile ( SourceLocation  Loc,
SourceManager &  SM,
const FileExtensionsSet HeaderFileExtensions 
)

Checks whether presumed location of Loc is in header file.

Definition at line 22 of file FileExtensionsUtils.cpp.

References isFileExtension(), and Loc.

Referenced by clang::tidy::bugprone::DynamicStaticInitializersCheck::check(), and clang::tidy::google::build::UnnamedNamespaceInHeaderCheck::check().

◆ isPtrOrReferenceForVar()

static bool clang::tidy::utils::isPtrOrReferenceForVar ( const Stmt *  S,
const VarDecl *  Var 
)
static

Return whether Var has a pointer or reference in S.

Definition at line 32 of file Aliasing.cpp.

References capturesByRef(), Decl, and isAccessForVar().

Referenced by hasPtrOrReferenceInStmt().

◆ isSpellingLocInHeaderFile()

bool clang::tidy::utils::isSpellingLocInHeaderFile ( SourceLocation  Loc,
SourceManager &  SM,
const FileExtensionsSet HeaderFileExtensions 
)

Checks whether spelling location of Loc is in header file.

Definition at line 28 of file FileExtensionsUtils.cpp.

References isFileExtension(), and Loc.

Referenced by clang::tidy::google::readability::GlobalNamesInHeadersCheck::check(), and clang::tidy::llvm_libc::InlineFunctionDeclCheck::check().

◆ parseFileExtensions()

bool clang::tidy::utils::parseFileExtensions ( StringRef  AllFileExtensions,
FileExtensionsSet FileExtensions,
StringRef  Delimiters 
)

◆ rangeCanBeFixed()

bool clang::tidy::utils::rangeCanBeFixed ( SourceRange  Range,
const SourceManager *  SM 
)

◆ rangeContainsMacroExpansion()

bool clang::tidy::utils::rangeContainsMacroExpansion ( SourceRange  Range,
const SourceManager *  SM 
)

Definition at line 81 of file ASTUtils.cpp.

References Range, and rangeIsEntirelyWithinMacroArgument().

Referenced by rangeCanBeFixed().

◆ rangeIsEntirelyWithinMacroArgument()

bool clang::tidy::utils::rangeIsEntirelyWithinMacroArgument ( SourceRange  Range,
const SourceManager *  SM 
)

Definition at line 65 of file ASTUtils.cpp.

References Range.

Referenced by rangeCanBeFixed(), and rangeContainsMacroExpansion().

◆ refersToEnclosingLambdaCaptureByRef()

static bool clang::tidy::utils::refersToEnclosingLambdaCaptureByRef ( const Decl Func,
const VarDecl *  Var 
)
static

Definition at line 79 of file Aliasing.cpp.

References capturesByRef().

Referenced by hasPtrOrReferenceInFunc().

◆ verifyRule()

static void clang::tidy::utils::verifyRule ( const RewriteRuleWith< std::string > &  Rule)
static