14 #include "llvm/ADT/Twine.h" 17 using namespace clang;
18 using namespace tooling;
22 if (
const auto *CE = dyn_cast<CXXConstructExpr>(Expr)) {
23 if (CE->getNumArgs() > 0 &&
34 if (isa<UnaryOperator>(Expr) || isa<BinaryOperator>(Expr) ||
35 isa<AbstractConditionalOperator>(Expr))
43 if (
const auto *Op = dyn_cast<CXXOperatorCallExpr>(Expr))
44 return Op->getOperator() != OO_Call && Op->getOperator() != OO_Subscript &&
45 Op->getOperator() != OO_Arrow;
52 if (isa<BinaryOperator>(Expr) || isa<AbstractConditionalOperator>(Expr))
55 if (
const auto *Op = dyn_cast<CXXOperatorCallExpr>(Expr))
56 return Op->getNumArgs() == 2 && Op->getOperator() != OO_PlusPlus &&
57 Op->getOperator() != OO_MinusMinus && Op->getOperator() != OO_Call &&
58 Op->getOperator() != OO_Subscript;
69 return (
"(" + Text +
")").str();
75 if (
const auto *Op = dyn_cast<UnaryOperator>(&E))
76 if (Op->getOpcode() == UO_AddrOf) {
79 getText(*Op->getSubExpr()->IgnoreParenImpCasts(), Context);
90 return (
"*(" + Text +
")").str();
91 return (
"*" + Text).str();
96 if (
const auto *Op = dyn_cast<UnaryOperator>(&E))
97 if (Op->getOpcode() == UO_Deref) {
100 getText(*Op->getSubExpr()->IgnoreParenImpCasts(), Context);
110 return (
"&(" + Text +
")").str();
112 return (
"&" + Text).str();
117 if (
const auto *Op = llvm::dyn_cast<UnaryOperator>(&E))
118 if (Op->getOpcode() == UO_Deref) {
121 StringRef DerefText =
getText(*SubExpr, Context);
122 if (DerefText.empty())
125 return (
"(" + DerefText +
")->").str();
126 return (DerefText +
"->").str();
134 return (
"(" + Text +
").").str();
136 return (Text +
".").str();
141 if (
const auto *Op = llvm::dyn_cast<UnaryOperator>(&E))
142 if (Op->getOpcode() == UO_AddrOf) {
145 StringRef DerefText =
getText(*SubExpr, Context);
146 if (DerefText.empty())
149 return (
"(" + DerefText +
").").str();
150 return (DerefText +
".").str();
158 return (
"(" + Text +
")->").str();
159 return (Text +
"->").str();
Defines the clang::ASTContext interface.
Defines the clang::Expr interface and subclasses for C++ expressions.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
This represents one expression.
This file collects facilities for generating source code strings.
Dataflow Directional Tag Classes.
Expr * IgnoreParenImpCasts() LLVM_READONLY
Skip past any parentheses and implicit casts which might surround this expression until reaching a fi...
Expr * IgnoreImplicit() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point...
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...