clang-tools 20.0.0git
Enumerations | Functions
clang::tidy::utils::fixit Namespace Reference

Enumerations

enum class  QualifierPolicy { Left , Right }
 This enum defines where the qualifier shall be preferably added. More...
 
enum class  QualifierTarget { Pointee , Value }
 This enum defines which entity is the target for adding the qualifier. More...
 

Functions

FixItHint changeVarDeclToReference (const VarDecl &Var, ASTContext &Context)
 Creates fix to make VarDecl a reference by adding &.
 
static bool isValueType (const Type *T)
 
static bool isValueType (QualType QT)
 
static bool isMemberOrFunctionPointer (QualType QT)
 
static bool locDangerous (SourceLocation S)
 
static std::optional< SourceLocation > skipLParensBackwards (SourceLocation Start, const ASTContext &Context)
 
static std::optional< FixItHint > fixIfNotDangerous (SourceLocation Loc, StringRef Text)
 
static std::string buildQualifier (DeclSpec::TQ Qualifier, bool WhitespaceBefore=false)
 
static std::optional< FixItHint > changeValue (const VarDecl &Var, DeclSpec::TQ Qualifier, QualifierTarget QualTarget, QualifierPolicy QualPolicy, const ASTContext &Context)
 
static std::optional< FixItHint > changePointerItself (const VarDecl &Var, DeclSpec::TQ Qualifier, const ASTContext &Context)
 
static std::optional< FixItHint > changePointer (const VarDecl &Var, DeclSpec::TQ Qualifier, const Type *Pointee, QualifierTarget QualTarget, QualifierPolicy QualPolicy, const ASTContext &Context)
 
static std::optional< FixItHint > changeReferencee (const VarDecl &Var, DeclSpec::TQ Qualifier, QualType Pointee, QualifierTarget QualTarget, QualifierPolicy QualPolicy, const ASTContext &Context)
 
std::optional< FixItHint > addQualifierToVarDecl (const VarDecl &Var, const ASTContext &Context, DeclSpec::TQ Qualifier, QualifierTarget QualTarget=QualifierTarget::Pointee, QualifierPolicy QualPolicy=QualifierPolicy::Left)
 Creates fix to qualify VarDecl with the specified Qualifier.
 
bool areParensNeededForStatement (const Stmt &Node)
 
static bool needParensAfterUnaryOperator (const Expr &ExprNode)
 
std::string formatDereference (const Expr &ExprNode, const ASTContext &Context)
 

Enumeration Type Documentation

◆ QualifierPolicy

This enum defines where the qualifier shall be preferably added.

Enumerator
Left 
Right 

Definition at line 23 of file FixItHintUtils.h.

◆ QualifierTarget

This enum defines which entity is the target for adding the qualifier.

This makes only a difference for pointer-types. Other types behave identical for either value of ConstTarget.

Enumerator
Pointee 
Value 

Transforming a pointer attaches to the pointee and not the pointer itself.

For references and normal values this option has no effect. int * p = &i; -> const int * p = &i or int const

  • p = &i.

Definition at line 31 of file FixItHintUtils.h.

Function Documentation

◆ addQualifierToVarDecl()

std::optional< FixItHint > clang::tidy::utils::fixit::addQualifierToVarDecl ( const VarDecl &  Var,
const ASTContext &  Context,
DeclSpec::TQ  Qualifier,
QualifierTarget  QualTarget = QualifierTarget::Pointee,
QualifierPolicy  QualPolicy = QualifierPolicy::Left 
)

Creates fix to qualify VarDecl with the specified Qualifier.

Requires that Var is isolated in written code like in int foo = 42;.

Definition at line 184 of file FixItHintUtils.cpp.

References changePointer(), changePointerItself(), changeReferencee(), changeValue(), isMemberOrFunctionPointer(), isValueType(), Left, Pointee, Right, Type, and Value.

Referenced by clang::tidy::performance::UnnecessaryValueParamCheck::handleConstRefFix().

◆ areParensNeededForStatement()

bool clang::tidy::utils::fixit::areParensNeededForStatement ( const Stmt &  Node)

Definition at line 227 of file FixItHintUtils.cpp.

References Node.

Referenced by clang::tidy::readability::RedundantCastingCheck::check().

◆ buildQualifier()

static std::string clang::tidy::utils::fixit::buildQualifier ( DeclSpec::TQ  Qualifier,
bool  WhitespaceBefore = false 
)
static

◆ changePointer()

static std::optional< FixItHint > clang::tidy::utils::fixit::changePointer ( const VarDecl &  Var,
DeclSpec::TQ  Qualifier,
const Type Pointee,
QualifierTarget  QualTarget,
QualifierPolicy  QualPolicy,
const ASTContext &  Context 
)
static

◆ changePointerItself()

static std::optional< FixItHint > clang::tidy::utils::fixit::changePointerItself ( const VarDecl &  Var,
DeclSpec::TQ  Qualifier,
const ASTContext &  Context 
)
static

◆ changeReferencee()

static std::optional< FixItHint > clang::tidy::utils::fixit::changeReferencee ( const VarDecl &  Var,
DeclSpec::TQ  Qualifier,
QualType  Pointee,
QualifierTarget  QualTarget,
QualifierPolicy  QualPolicy,
const ASTContext &  Context 
)
static

◆ changeValue()

static std::optional< FixItHint > clang::tidy::utils::fixit::changeValue ( const VarDecl &  Var,
DeclSpec::TQ  Qualifier,
QualifierTarget  QualTarget,
QualifierPolicy  QualPolicy,
const ASTContext &  Context 
)
static

◆ changeVarDeclToReference()

FixItHint clang::tidy::utils::fixit::changeVarDeclToReference ( const VarDecl &  Var,
ASTContext &  Context 
)

Creates fix to make VarDecl a reference by adding &.

Definition at line 19 of file FixItHintUtils.cpp.

References clang::tidy::utils::lexer::getPreviousToken().

Referenced by clang::tidy::performance::UnnecessaryValueParamCheck::handleConstRefFix().

◆ fixIfNotDangerous()

static std::optional< FixItHint > clang::tidy::utils::fixit::fixIfNotDangerous ( SourceLocation  Loc,
StringRef  Text 
)
static

Definition at line 65 of file FixItHintUtils.cpp.

References Loc, locDangerous(), and Text.

Referenced by changePointer(), changePointerItself(), changeReferencee(), and changeValue().

◆ formatDereference()

std::string clang::tidy::utils::fixit::formatDereference ( const Expr &  ExprNode,
const ASTContext &  Context 
)

◆ isMemberOrFunctionPointer()

static bool clang::tidy::utils::fixit::isMemberOrFunctionPointer ( QualType  QT)
static

Definition at line 35 of file FixItHintUtils.cpp.

Referenced by addQualifierToVarDecl().

◆ isValueType() [1/2]

static bool clang::tidy::utils::fixit::isValueType ( const Type T)
static

◆ isValueType() [2/2]

static bool clang::tidy::utils::fixit::isValueType ( QualType  QT)
static

Definition at line 34 of file FixItHintUtils.cpp.

References isValueType().

◆ locDangerous()

static bool clang::tidy::utils::fixit::locDangerous ( SourceLocation  S)
static

◆ needParensAfterUnaryOperator()

static bool clang::tidy::utils::fixit::needParensAfterUnaryOperator ( const Expr &  ExprNode)
static

Definition at line 264 of file FixItHintUtils.cpp.

Referenced by formatDereference().

◆ skipLParensBackwards()

static std::optional< SourceLocation > clang::tidy::utils::fixit::skipLParensBackwards ( SourceLocation  Start,
const ASTContext &  Context 
)
static