25 if (S->getBeginLoc().isMacroID())
28 if (S->getEndLoc().isMacroID())
31 for (
const Stmt *Child : S->children())
42 if (DR && isa<EnumConstantDecl>(DR->
getDecl()))
45 for (
const Stmt *Child : S->children())
58 if (VD->isStaticLocal())
61 for (
const Stmt *Child : S->children())
70 if (isa<OffsetOfExpr>(S))
73 for (
const Stmt *Child : S->children())
81std::pair<const clang::VarDecl *, const clang::Expr *>
84 const Expr *RHS =
nullptr;
86 if (
auto Assign = dyn_cast_or_null<BinaryOperator>(S)) {
87 if (Assign->isAssignmentOp()) {
89 RHS = Assign->getRHS();
90 if (
auto DE = dyn_cast_or_null<DeclRefExpr>(Assign->getLHS()))
91 VD = dyn_cast_or_null<VarDecl>(DE->getDecl());
93 }
else if (
auto PD = dyn_cast_or_null<DeclStmt>(S)) {
95 assert(PD->isSingleDecl() &&
"We process decls one by one");
96 VD = cast<VarDecl>(PD->getSingleDecl());
100 return std::make_pair(VD, RHS);
107 if (AttrType->getAttrKind() == attr::TypeNullable)
109 else if (AttrType->getAttrKind() == attr::TypeNonNull)
123 std::vector<Token> FilteredTokens;
124 FilteredTokens.reserve(MI->
tokens().size());
125 for (
auto &T : MI->
tokens())
126 if (!T.isOneOf(tok::l_paren, tok::r_paren))
127 FilteredTokens.push_back(T);
130 const Token &T = FilteredTokens.back();
136 llvm::APInt IntValue;
137 constexpr unsigned AutoSenseRadix = 0;
138 if (ValueStr.getAsInteger(AutoSenseRadix, IntValue))
142 size_t Size = FilteredTokens.size();
144 if (FilteredTokens[Size - 2].is(tok::minus))
145 IntValue = -IntValue;
148 return IntValue.getSExtValue();
153 llvm::StringMap<BinaryOperatorKind> BinOps{
154#define BINARY_OPERATION(Name, Spelling) {Spelling, BO_##Name},
155#include "clang/AST/OperationKinds.def"
157 llvm::StringMap<UnaryOperatorKind> UnOps{
158#define UNARY_OPERATION(Name, Spelling) {Spelling, UO_##Name},
159#include "clang/AST/OperationKinds.def"
163#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
166 auto BinOpIt = BinOps.find(Spelling); \
167 if (BinOpIt != BinOps.end()) \
168 return OperatorKind(BinOpIt->second); \
170 llvm_unreachable("operator was expected to be binary but is not"); \
172 auto UnOpIt = UnOps.find(Spelling); \
173 if (UnOpIt != UnOps.end()) \
174 return OperatorKind(UnOpIt->second); \
176 llvm_unreachable("operator was expected to be unary but is not"); \
179#include "clang/Basic/OperatorKinds.def"
181 llvm_unreachable(
"unexpected operator kind");
Defines the clang::Preprocessor interface.
An attributed type is a type to which a type attribute has been applied.
A reference to a declared variable, function, enum, etc.
This represents one expression.
Encapsulates the data about a macro definition (e.g.
ArrayRef< Token > tokens() const
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
const MacroInfo * getMacroInfo(const IdentifierInfo *II) const
IdentifierInfo * getIdentifierInfo(StringRef Name) const
Return information about the specified preprocessor identifier token.
A (possibly-)qualified type.
Stmt - This represents one statement.
Token - This structure provides full information about a lexed token.
bool isLiteral() const
Return true if this is a "literal", like a numeric constant, string, etc.
unsigned getLength() const
const char * getLiteralData() const
getLiteralData - For a literal token (numeric constant, string, etc), this returns a pointer to the s...
The base class of the type hierarchy.
const T * getAs() const
Member-template getAs<specific type>'.
Represents a variable declaration or definition.
const Expr * getAnyInitializer() const
Get the initializer for this variable, no matter which declaration it is attached to.
bool containsEnum(const Stmt *S)
Nullability getNullabilityAnnotation(QualType Type)
Get nullability annotation for a given type.
bool containsStaticLocal(const Stmt *S)
std::pair< const clang::VarDecl *, const clang::Expr * > parseAssignment(const Stmt *S)
OperatorKind operationKindFromOverloadedOperator(OverloadedOperatorKind OOK, bool IsBinary)
bool containsBuiltinOffsetOf(const Stmt *S)
std::optional< int > tryExpandAsInteger(StringRef Macro, const Preprocessor &PP)
Try to parse the value of a defined preprocessor macro.
bool containsMacro(const Stmt *S)
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.