clang 19.0.0git
Public Member Functions | Static Public Member Functions | List of all members
clang::IfStmt Class Referencefinal

IfStmt - This represents an if/then/else. More...

#include "clang/AST/Stmt.h"

Inheritance diagram for clang::IfStmt:
Inheritance graph
[legend]

Public Member Functions

bool hasInitStorage () const
 True if this IfStmt has the storage for an init statement.
 
bool hasVarStorage () const
 True if this IfStmt has storage for a variable declaration.
 
bool hasElseStorage () const
 True if this IfStmt has storage for an else statement.
 
ExprgetCond ()
 
const ExprgetCond () const
 
void setCond (Expr *Cond)
 
StmtgetThen ()
 
const StmtgetThen () const
 
void setThen (Stmt *Then)
 
StmtgetElse ()
 
const StmtgetElse () const
 
void setElse (Stmt *Else)
 
VarDeclgetConditionVariable ()
 Retrieve the variable declared in this "if" statement, if any.
 
const VarDeclgetConditionVariable () const
 
void setConditionVariable (const ASTContext &Ctx, VarDecl *V)
 Set the condition variable for this if statement.
 
DeclStmtgetConditionVariableDeclStmt ()
 If this IfStmt has a condition variable, return the faux DeclStmt associated with the creation of that condition variable.
 
const DeclStmtgetConditionVariableDeclStmt () const
 
void setConditionVariableDeclStmt (DeclStmt *CondVar)
 
StmtgetInit ()
 
const StmtgetInit () const
 
void setInit (Stmt *Init)
 
SourceLocation getIfLoc () const
 
void setIfLoc (SourceLocation IfLoc)
 
SourceLocation getElseLoc () const
 
void setElseLoc (SourceLocation ElseLoc)
 
bool isConsteval () const
 
bool isNonNegatedConsteval () const
 
bool isNegatedConsteval () const
 
bool isConstexpr () const
 
void setStatementKind (IfStatementKind Kind)
 
IfStatementKind getStatementKind () const
 
std::optional< const Stmt * > getNondiscardedCase (const ASTContext &Ctx) const
 If this is an 'if constexpr', determine which substatement will be taken.
 
std::optional< Stmt * > getNondiscardedCase (const ASTContext &Ctx)
 
bool isObjCAvailabilityCheck () const
 
SourceLocation getBeginLoc () const
 
SourceLocation getEndLoc () const LLVM_READONLY
 
SourceLocation getLParenLoc () const
 
void setLParenLoc (SourceLocation Loc)
 
SourceLocation getRParenLoc () const
 
void setRParenLoc (SourceLocation Loc)
 
child_range children ()
 
const_child_range children () const
 
- Public Member Functions inherited from clang::Stmt
void * operator new (size_t bytes, const ASTContext &C, unsigned alignment=8)
 
void * operator new (size_t bytes, const ASTContext *C, unsigned alignment=8)
 
void * operator new (size_t bytes, void *mem) noexcept
 
void operator delete (void *, const ASTContext &, unsigned) noexcept
 
void operator delete (void *, const ASTContext *, unsigned) noexcept
 
void operator delete (void *, size_t) noexcept
 
void operator delete (void *, void *) noexcept
 
 Stmt ()=delete
 
 Stmt (const Stmt &)=delete
 
 Stmt (Stmt &&)=delete
 
Stmtoperator= (const Stmt &)=delete
 
Stmtoperator= (Stmt &&)=delete
 
 Stmt (StmtClass SC)
 
StmtClass getStmtClass () const
 
const char * getStmtClassName () const
 
SourceRange getSourceRange () const LLVM_READONLY
 SourceLocation tokens are not useful in isolation - they are low level value objects created/interpreted by SourceManager.
 
SourceLocation getBeginLoc () const LLVM_READONLY
 
SourceLocation getEndLoc () const LLVM_READONLY
 
void dump () const
 Dumps the specified AST fragment and all subtrees to llvm::errs().
 
void dump (raw_ostream &OS, const ASTContext &Context) const
 
int64_t getID (const ASTContext &Context) const
 
void dumpColor () const
 dumpColor - same as dump(), but forces color highlighting.
 
void dumpPretty (const ASTContext &Context) const
 dumpPretty/printPretty - These two methods do a "pretty print" of the AST back to its original source language syntax.
 
void printPretty (raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\n", const ASTContext *Context=nullptr) const
 
void printPrettyControlled (raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\n", const ASTContext *Context=nullptr) const
 
void printJson (raw_ostream &Out, PrinterHelper *Helper, const PrintingPolicy &Policy, bool AddQuotes) const
 Pretty-prints in JSON format.
 
void viewAST () const
 viewAST - Visualize an AST rooted at this Stmt* using GraphViz.
 
StmtIgnoreContainers (bool IgnoreCaptured=false)
 Skip no-op (attributed, compound) container stmts and skip captured stmt at the top, if IgnoreCaptured is true.
 
const StmtIgnoreContainers (bool IgnoreCaptured=false) const
 
const StmtstripLabelLikeStatements () const
 Strip off all label-like statements.
 
StmtstripLabelLikeStatements ()
 
child_range children ()
 
const_child_range children () const
 
child_iterator child_begin ()
 
child_iterator child_end ()
 
const_child_iterator child_begin () const
 
const_child_iterator child_end () const
 
void Profile (llvm::FoldingSetNodeID &ID, const ASTContext &Context, bool Canonical, bool ProfileLambdaExpr=false) const
 Produce a unique representation of the given statement.
 
void ProcessODRHash (llvm::FoldingSetNodeID &ID, ODRHash &Hash) const
 Calculate a unique representation for a statement that is stable across compiler invocations.
 

Static Public Member Functions

static IfStmtCreate (const ASTContext &Ctx, SourceLocation IL, IfStatementKind Kind, Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LPL, SourceLocation RPL, Stmt *Then, SourceLocation EL=SourceLocation(), Stmt *Else=nullptr)
 Create an IfStmt.
 
static IfStmtCreateEmpty (const ASTContext &Ctx, bool HasElse, bool HasVar, bool HasInit)
 Create an empty IfStmt optionally with storage for an else statement, condition variable and init expression.
 
static bool classof (const Stmt *T)
 
- Static Public Member Functions inherited from clang::Stmt
static void addStmtClass (const StmtClass s)
 
static void EnableStatistics ()
 
static void PrintStats ()
 
static Likelihood getLikelihood (ArrayRef< const Attr * > Attrs)
 
static Likelihood getLikelihood (const Stmt *S)
 
static const AttrgetLikelihoodAttr (const Stmt *S)
 
static Likelihood getLikelihood (const Stmt *Then, const Stmt *Else)
 
static std::tuple< bool, const Attr *, const Attr * > determineLikelihoodConflict (const Stmt *Then, const Stmt *Else)
 

Additional Inherited Members

- Public Types inherited from clang::Stmt
enum  StmtClass { NoStmtClass = 0 }
 
enum  Likelihood { LH_Unlikely = -1 , LH_None , LH_Likely }
 The likelihood of a branch being taken. More...
 
using child_iterator = StmtIterator
 Child Iterators: All subclasses must implement 'children' to permit easy iteration over the substatements/subexpressions of an AST node.
 
using const_child_iterator = ConstStmtIterator
 
using child_range = llvm::iterator_range< child_iterator >
 
using const_child_range = llvm::iterator_range< const_child_iterator >
 
- Protected Types inherited from clang::Stmt
enum  { NumStmtBits = 8 }
 
enum  { NumExprBits = NumStmtBits + 5 + llvm::BitWidth<ExprDependence> }
 
enum  { NumCallExprBits = 32 }
 
enum  { NumOverloadExprBits = NumExprBits + 1 }
 
template<typename T >
using ConstCastIterator = CastIterator< T, const T *const, const Stmt *const >
 Const iterator for iterating over Stmt * arrays that contain only T *.
 
using ExprIterator = CastIterator< Expr >
 
using ConstExprIterator = ConstCastIterator< Expr >
 
- Protected Member Functions inherited from clang::Stmt
void * operator new (size_t bytes) noexcept
 
void operator delete (void *data) noexcept
 
 Stmt (StmtClass SC, EmptyShell)
 Construct an empty statement.
 
- Protected Attributes inherited from clang::Stmt
union {
   StmtBitfields   StmtBits
 
   NullStmtBitfields   NullStmtBits
 
   CompoundStmtBitfields   CompoundStmtBits
 
   LabelStmtBitfields   LabelStmtBits
 
   AttributedStmtBitfields   AttributedStmtBits
 
   IfStmtBitfields   IfStmtBits
 
   SwitchStmtBitfields   SwitchStmtBits
 
   WhileStmtBitfields   WhileStmtBits
 
   DoStmtBitfields   DoStmtBits
 
   ForStmtBitfields   ForStmtBits
 
   GotoStmtBitfields   GotoStmtBits
 
   ContinueStmtBitfields   ContinueStmtBits
 
   BreakStmtBitfields   BreakStmtBits
 
   ReturnStmtBitfields   ReturnStmtBits
 
   SwitchCaseBitfields   SwitchCaseBits
 
   ExprBitfields   ExprBits
 
   ConstantExprBitfields   ConstantExprBits
 
   PredefinedExprBitfields   PredefinedExprBits
 
   DeclRefExprBitfields   DeclRefExprBits
 
   FloatingLiteralBitfields   FloatingLiteralBits
 
   StringLiteralBitfields   StringLiteralBits
 
   CharacterLiteralBitfields   CharacterLiteralBits
 
   UnaryOperatorBitfields   UnaryOperatorBits
 
   UnaryExprOrTypeTraitExprBitfields   UnaryExprOrTypeTraitExprBits
 
   ArrayOrMatrixSubscriptExprBitfields   ArrayOrMatrixSubscriptExprBits
 
   CallExprBitfields   CallExprBits
 
   MemberExprBitfields   MemberExprBits
 
   CastExprBitfields   CastExprBits
 
   BinaryOperatorBitfields   BinaryOperatorBits
 
   InitListExprBitfields   InitListExprBits
 
   ParenListExprBitfields   ParenListExprBits
 
   GenericSelectionExprBitfields   GenericSelectionExprBits
 
   PseudoObjectExprBitfields   PseudoObjectExprBits
 
   SourceLocExprBitfields   SourceLocExprBits
 
   StmtExprBitfields   StmtExprBits
 
   CXXOperatorCallExprBitfields   CXXOperatorCallExprBits
 
   CXXRewrittenBinaryOperatorBitfields   CXXRewrittenBinaryOperatorBits
 
   CXXBoolLiteralExprBitfields   CXXBoolLiteralExprBits
 
   CXXNullPtrLiteralExprBitfields   CXXNullPtrLiteralExprBits
 
   CXXThisExprBitfields   CXXThisExprBits
 
   CXXThrowExprBitfields   CXXThrowExprBits
 
   CXXDefaultArgExprBitfields   CXXDefaultArgExprBits
 
   CXXDefaultInitExprBitfields   CXXDefaultInitExprBits
 
   CXXScalarValueInitExprBitfields   CXXScalarValueInitExprBits
 
   CXXNewExprBitfields   CXXNewExprBits
 
   CXXDeleteExprBitfields   CXXDeleteExprBits
 
   TypeTraitExprBitfields   TypeTraitExprBits
 
   DependentScopeDeclRefExprBitfields   DependentScopeDeclRefExprBits
 
   CXXConstructExprBitfields   CXXConstructExprBits
 
   ExprWithCleanupsBitfields   ExprWithCleanupsBits
 
   CXXUnresolvedConstructExprBitfields   CXXUnresolvedConstructExprBits
 
   CXXDependentScopeMemberExprBitfields   CXXDependentScopeMemberExprBits
 
   OverloadExprBitfields   OverloadExprBits
 
   UnresolvedLookupExprBitfields   UnresolvedLookupExprBits
 
   UnresolvedMemberExprBitfields   UnresolvedMemberExprBits
 
   CXXNoexceptExprBitfields   CXXNoexceptExprBits
 
   SubstNonTypeTemplateParmExprBitfields   SubstNonTypeTemplateParmExprBits
 
   LambdaExprBitfields   LambdaExprBits
 
   RequiresExprBitfields   RequiresExprBits
 
   CoawaitExprBitfields   CoawaitBits
 
   ObjCIndirectCopyRestoreExprBitfields   ObjCIndirectCopyRestoreExprBits
 
   OpaqueValueExprBitfields   OpaqueValueExprBits
 
}; 
 

Detailed Description

IfStmt - This represents an if/then/else.

Definition at line 2136 of file Stmt.h.

Member Function Documentation

◆ children() [1/2]

child_range clang::IfStmt::children ( )
inline

Definition at line 2363 of file Stmt.h.

References isConsteval().

◆ children() [2/2]

const_child_range clang::IfStmt::children ( ) const
inline

Definition at line 2372 of file Stmt.h.

References isConsteval().

◆ classof()

static bool clang::IfStmt::classof ( const Stmt T)
inlinestatic

Definition at line 2381 of file Stmt.h.

References clang::T.

◆ Create()

IfStmt * IfStmt::Create ( const ASTContext Ctx,
SourceLocation  IL,
IfStatementKind  Kind,
Stmt Init,
VarDecl Var,
Expr Cond,
SourceLocation  LPL,
SourceLocation  RPL,
Stmt Then,
SourceLocation  EL = SourceLocation(),
Stmt Else = nullptr 
)
static

◆ CreateEmpty()

IfStmt * IfStmt::CreateEmpty ( const ASTContext Ctx,
bool  HasElse,
bool  HasVar,
bool  HasInit 
)
static

Create an empty IfStmt optionally with storage for an else statement, condition variable and init expression.

Definition at line 973 of file Stmt.cpp.

References clang::ASTContext::Allocate().

◆ getBeginLoc()

SourceLocation clang::IfStmt::getBeginLoc ( ) const
inline

Definition at line 2350 of file Stmt.h.

References getIfLoc().

◆ getCond() [1/2]

Expr * clang::IfStmt::getCond ( )
inline

◆ getCond() [2/2]

const Expr * clang::IfStmt::getCond ( ) const
inline

Definition at line 2219 of file Stmt.h.

◆ getConditionVariable() [1/2]

VarDecl * IfStmt::getConditionVariable ( )

Retrieve the variable declared in this "if" statement, if any.

In the following example, "x" is the condition variable.

if (int x = foo()) {
printf("x is %d", x);
}
int printf(__constant const char *st,...) __attribute__((format(printf

Definition at line 982 of file Stmt.cpp.

References getConditionVariableDeclStmt().

Referenced by EvaluateStmt(), and getConditionVariable().

◆ getConditionVariable() [2/2]

const VarDecl * clang::IfStmt::getConditionVariable ( ) const
inline

Definition at line 2261 of file Stmt.h.

References getConditionVariable().

◆ getConditionVariableDeclStmt() [1/2]

DeclStmt * clang::IfStmt::getConditionVariableDeclStmt ( )
inline

If this IfStmt has a condition variable, return the faux DeclStmt associated with the creation of that condition variable.

Definition at line 2271 of file Stmt.h.

References hasVarStorage().

Referenced by getConditionVariable().

◆ getConditionVariableDeclStmt() [2/2]

const DeclStmt * clang::IfStmt::getConditionVariableDeclStmt ( ) const
inline

Definition at line 2277 of file Stmt.h.

References hasVarStorage().

◆ getElse() [1/2]

Stmt * clang::IfStmt::getElse ( )
inline

Definition at line 2236 of file Stmt.h.

References hasElseStorage().

Referenced by DiagUninitUse(), EvaluateStmt(), getEndLoc(), getNondiscardedCase(), and isIdenticalStmt().

◆ getElse() [2/2]

const Stmt * clang::IfStmt::getElse ( ) const
inline

Definition at line 2241 of file Stmt.h.

References hasElseStorage().

◆ getElseLoc()

SourceLocation clang::IfStmt::getElseLoc ( ) const
inline

Definition at line 2307 of file Stmt.h.

References hasElseStorage().

◆ getEndLoc()

SourceLocation clang::IfStmt::getEndLoc ( ) const
inline

Definition at line 2351 of file Stmt.h.

References getElse(), clang::Stmt::getEndLoc(), and getThen().

◆ getIfLoc()

SourceLocation clang::IfStmt::getIfLoc ( ) const
inline

Definition at line 2304 of file Stmt.h.

References clang::Stmt::IfStmtBits.

Referenced by getBeginLoc().

◆ getInit() [1/2]

Stmt * clang::IfStmt::getInit ( )
inline

Definition at line 2288 of file Stmt.h.

References hasInitStorage().

Referenced by EvaluateStmt().

◆ getInit() [2/2]

const Stmt * clang::IfStmt::getInit ( ) const
inline

Definition at line 2293 of file Stmt.h.

References hasInitStorage().

◆ getLParenLoc()

SourceLocation clang::IfStmt::getLParenLoc ( ) const
inline

Definition at line 2356 of file Stmt.h.

◆ getNondiscardedCase() [1/2]

std::optional< Stmt * > IfStmt::getNondiscardedCase ( const ASTContext Ctx)

◆ getNondiscardedCase() [2/2]

std::optional< const Stmt * > IfStmt::getNondiscardedCase ( const ASTContext Ctx) const

If this is an 'if constexpr', determine which substatement will be taken.

Otherwise, or if the condition is value-dependent, returns std::nullopt.

Definition at line 1014 of file Stmt.cpp.

References getNondiscardedCase(), and clang::Result.

Referenced by getNondiscardedCase().

◆ getRParenLoc()

SourceLocation clang::IfStmt::getRParenLoc ( ) const
inline

Definition at line 2358 of file Stmt.h.

◆ getStatementKind()

IfStatementKind clang::IfStmt::getStatementKind ( ) const
inline

Definition at line 2339 of file Stmt.h.

References clang::Stmt::IfStmtBits.

Referenced by isConsteval(), isConstexpr(), isNegatedConsteval(), and isNonNegatedConsteval().

◆ getThen() [1/2]

Stmt * clang::IfStmt::getThen ( )
inline

Definition at line 2227 of file Stmt.h.

Referenced by DiagUninitUse(), EvaluateStmt(), getEndLoc(), getNondiscardedCase(), and isIdenticalStmt().

◆ getThen() [2/2]

const Stmt * clang::IfStmt::getThen ( ) const
inline

Definition at line 2228 of file Stmt.h.

◆ hasElseStorage()

bool clang::IfStmt::hasElseStorage ( ) const
inline

True if this IfStmt has storage for an else statement.

Definition at line 2213 of file Stmt.h.

References clang::Stmt::IfStmtBits.

Referenced by getElse(), getElseLoc(), setElse(), setElseLoc(), and clang::JSONNodeDumper::VisitIfStmt().

◆ hasInitStorage()

bool clang::IfStmt::hasInitStorage ( ) const
inline

True if this IfStmt has the storage for an init statement.

Definition at line 2207 of file Stmt.h.

References clang::Stmt::IfStmtBits.

Referenced by getInit(), setInit(), and clang::JSONNodeDumper::VisitIfStmt().

◆ hasVarStorage()

bool clang::IfStmt::hasVarStorage ( ) const
inline

True if this IfStmt has storage for a variable declaration.

Definition at line 2210 of file Stmt.h.

References clang::Stmt::IfStmtBits.

Referenced by getConditionVariableDeclStmt(), setConditionVariable(), setConditionVariableDeclStmt(), and clang::JSONNodeDumper::VisitIfStmt().

◆ isConsteval()

bool clang::IfStmt::isConsteval ( ) const
inline

◆ isConstexpr()

bool clang::IfStmt::isConstexpr ( ) const
inline

Definition at line 2331 of file Stmt.h.

References clang::Constexpr, and getStatementKind().

Referenced by getNondiscardedCase(), and clang::JSONNodeDumper::VisitIfStmt().

◆ isNegatedConsteval()

bool clang::IfStmt::isNegatedConsteval ( ) const
inline

Definition at line 2327 of file Stmt.h.

References clang::ConstevalNegated, and getStatementKind().

Referenced by clang::JSONNodeDumper::VisitIfStmt().

◆ isNonNegatedConsteval()

bool clang::IfStmt::isNonNegatedConsteval ( ) const
inline

Definition at line 2323 of file Stmt.h.

References clang::ConstevalNonNegated, and getStatementKind().

Referenced by EvaluateStmt().

◆ isObjCAvailabilityCheck()

bool IfStmt::isObjCAvailabilityCheck ( ) const

Definition at line 1003 of file Stmt.cpp.

References getCond().

◆ setCond()

void clang::IfStmt::setCond ( Expr Cond)
inline

Definition at line 2223 of file Stmt.h.

◆ setConditionVariable()

void IfStmt::setConditionVariable ( const ASTContext Ctx,
VarDecl V 
)

Set the condition variable for this if statement.

The if statement must have storage for the condition variable.

Definition at line 989 of file Stmt.cpp.

References clang::SourceRange::getBegin(), clang::SourceRange::getEnd(), hasVarStorage(), and V.

◆ setConditionVariableDeclStmt()

void clang::IfStmt::setConditionVariableDeclStmt ( DeclStmt CondVar)
inline

Definition at line 2283 of file Stmt.h.

References hasVarStorage().

◆ setElse()

void clang::IfStmt::setElse ( Stmt Else)
inline

Definition at line 2246 of file Stmt.h.

References hasElseStorage().

◆ setElseLoc()

void clang::IfStmt::setElseLoc ( SourceLocation  ElseLoc)
inline

Definition at line 2312 of file Stmt.h.

References hasElseStorage().

◆ setIfLoc()

void clang::IfStmt::setIfLoc ( SourceLocation  IfLoc)
inline

Definition at line 2305 of file Stmt.h.

References clang::Stmt::IfStmtBits.

◆ setInit()

void clang::IfStmt::setInit ( Stmt Init)
inline

Definition at line 2298 of file Stmt.h.

References hasInitStorage(), and clang::Init.

◆ setLParenLoc()

void clang::IfStmt::setLParenLoc ( SourceLocation  Loc)
inline

Definition at line 2357 of file Stmt.h.

◆ setRParenLoc()

void clang::IfStmt::setRParenLoc ( SourceLocation  Loc)
inline

Definition at line 2359 of file Stmt.h.

◆ setStatementKind()

void clang::IfStmt::setStatementKind ( IfStatementKind  Kind)
inline

Definition at line 2335 of file Stmt.h.

References clang::Stmt::IfStmtBits.

◆ setThen()

void clang::IfStmt::setThen ( Stmt Then)
inline

Definition at line 2232 of file Stmt.h.


The documentation for this class was generated from the following files: