1//===- StmtVisitor.h - Visitor for Stmt subclasses --------------*- C++ -*-===//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//===----------------------------------------------------------------------===//
9// This file defines the StmtVisitor and ConstStmtVisitor interfaces.
11//===----------------------------------------------------------------------===//
13#ifndef LLVM_CLANG_AST_STMTVISITOR_H
14#define LLVM_CLANG_AST_STMTVISITOR_H
27#include "llvm/ADT/STLExtras.h"
28#include "llvm/Support/Casting.h"
29#include "llvm/Support/ErrorHandling.h"
33/// StmtVisitorBase - This class implements a simple visitor for Stmt
34/// subclasses. Since Expr derives from Stmt, this also includes support for
36template<
template <
typename>
class Ptr,
typename ImplClass,
typename RetTy=void,
40 #define PTR(CLASS) typename Ptr<CLASS>::type
41 #define DISPATCH(NAME, CLASS) \
42 return static_cast<ImplClass*>(this)->Visit ## NAME( \
43 static_cast<PTR(CLASS)>(S), std::forward<ParamTys>(P)...)
46 // If we have a binary expr, dispatch to the subcode of the binop. A smart
47 // optimizer (e.g. LLVM) will fold this comparison into the switch stmt
50 switch (BinOp->getOpcode()) {
88 switch (UnOp->getOpcode()) {
106 // Top switch stmt: dispatch to VisitFooStmt for each FooStmt.
108 default: llvm_unreachable(
"Unknown stmt kind!");
109#define ABSTRACT_STMT(STMT)
110#define STMT(CLASS, PARENT) \
111 case Stmt::CLASS ## Class: DISPATCH(CLASS, CLASS);
112#include "clang/AST/StmtNodes.inc"
116 // If the implementation chooses not to implement a certain visit method, fall
117 // back on VisitExpr or whatever else is the superclass.
118 #define STMT(CLASS, PARENT) \
119 RetTy Visit ## CLASS(PTR(CLASS) S, ParamTys... P) { DISPATCH(PARENT, PARENT); }
120#include "clang/AST/StmtNodes.inc"
122 // If the implementation doesn't implement binary operator methods, fall back
123 // on VisitBinaryOperator.
124 #define BINOP_FALLBACK(NAME) \
125 RetTy VisitBin ## NAME(PTR(BinaryOperator) S, ParamTys... P) { \
126 DISPATCH(BinaryOperator, BinaryOperator); \
144 // If the implementation doesn't implement compound assignment operator
145 // methods, fall back on VisitCompoundAssignOperator.
146#define CAO_FALLBACK(NAME) \
147 RetTy VisitBin ## NAME(PTR(CompoundAssignOperator) S, ParamTys... P) { \
148 DISPATCH(CompoundAssignOperator, CompoundAssignOperator); \
156 // If the implementation doesn't implement unary operator methods, fall back
157 // on VisitUnaryOperator.
158#define UNARYOP_FALLBACK(NAME) \
159 RetTy VisitUnary ## NAME(PTR(UnaryOperator) S, ParamTys... P) { \
160 DISPATCH(UnaryOperator, UnaryOperator); \
170#undef UNARYOP_FALLBACK
172 // Base case, ignore it. :)
173 RetTy VisitStmt(
PTR(
Stmt) Node, ParamTys...
P) {
return RetTy(); }
179/// StmtVisitor - This class implements a simple visitor for Stmt subclasses.
180/// Since Expr derives from Stmt, this also includes support for visiting Exprs.
182/// This class does not preserve constness of Stmt pointers (see also
183/// ConstStmtVisitor).
184template <
typename ImplClass,
typename RetTy = void,
typename... ParamTys>
186 :
public StmtVisitorBase<std::add_pointer, ImplClass, RetTy, ParamTys...> {
189/// ConstStmtVisitor - This class implements a simple visitor for Stmt
190/// subclasses. Since Expr derives from Stmt, this also includes support for
193/// This class preserves constness of Stmt pointers (see also StmtVisitor).
194template <
typename ImplClass,
typename RetTy = void,
typename... ParamTys>
196 RetTy, ParamTys...> {};
200#endif // LLVM_CLANG_AST_STMTVISITOR_H
Defines the clang::Expr interface and subclasses for C++ expressions.
Defines Expressions and AST nodes for C++2a concepts.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the Objective-C statement AST node classes.
This file defines OpenACC AST classes for statement-level contructs.
This file defines OpenMP AST classes for executable directives and clauses.
This file defines SYCL AST classes used to represent calls to SYCL kernels.
#define UNARYOP_FALLBACK(NAME)
#define BINOP_FALLBACK(NAME)
#define CAO_FALLBACK(NAME)
A builtin binary operation expression such as "x + y" or "x <= y".
CompoundAssignOperator - For compound assignments (e.g.
ConstStmtVisitor - This class implements a simple visitor for Stmt subclasses.
StmtVisitorBase - This class implements a simple visitor for Stmt subclasses.
BINOP_FALLBACK(PtrMemD) BINOP_FALLBACK(PtrMemI) BINOP_FALLBACK(Mul) BINOP_FALLBACK(Div) BINOP_FALLBACK(Rem) BINOP_FALLBACK(Add) BINOP_FALLBACK(Sub) BINOP_FALLBACK(Shl) BINOP_FALLBACK(LT) BINOP_FALLBACK(GT) BINOP_FALLBACK(LE) BINOP_FALLBACK(GE) BINOP_FALLBACK(EQ) BINOP_FALLBACK(NE) BINOP_FALLBACK(And) BINOP_FALLBACK(Xor) BINOP_FALLBACK(Or) BINOP_FALLBACK(LAnd) BINOP_FALLBACK(LOr) CAO_FALLBACK(MulAssign) CAO_FALLBACK(DivAssign) CAO_FALLBACK(RemAssign) CAO_FALLBACK(AddAssign) CAO_FALLBACK(SubAssign) CAO_FALLBACK(ShlAssign) CAO_FALLBACK(ShrAssign) CAO_FALLBACK(AndAssign) CAO_FALLBACK(OrAssign) UNARYOP_FALLBACK(PostInc) UNARYOP_FALLBACK(PostDec) UNARYOP_FALLBACK(PreInc) UNARYOP_FALLBACK(PreDec) UNARYOP_FALLBACK(AddrOf) UNARYOP_FALLBACK(Deref) UNARYOP_FALLBACK(Plus) UNARYOP_FALLBACK(Minus) UNARYOP_FALLBACK(Not) UNARYOP_FALLBACK(LNot) UNARYOP_FALLBACK(Real) UNARYOP_FALLBACK(Imag) UNARYOP_FALLBACK(Extension) UNARYOP_FALLBACK(Coawait) RetTy VisitStmt(PTR(Stmt) Node
RetTy Visit(PTR(Stmt) S, ParamTys... P)
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
Stmt - This represents one statement.
StmtClass getStmtClass() const
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
The JSON file list parser is used to communicate input to InstallAPI.