28 ASTContext *Context) {
29 SmallVector<const Stmt *, 1>
Result;
31 ASTContext::DynTypedNodeList Parents = Context->getParents(*S);
33 SmallVector<ast_type_traits::DynTypedNode, 1> NodesToProcess(Parents.begin(),
36 while (!NodesToProcess.empty()) {
37 ast_type_traits::DynTypedNode Node = NodesToProcess.back();
38 NodesToProcess.pop_back();
40 if (
const auto *S = Node.get<Stmt>()) {
43 Parents = Context->getParents(Node);
44 NodesToProcess.append(Parents.begin(), Parents.end());
52 bool isDescendantOrEqual(
const Stmt *Descendant,
const Stmt *Ancestor,
53 ASTContext *Context) {
54 if (Descendant == Ancestor)
57 if (isDescendantOrEqual(Parent, Ancestor, Context))
66 ASTContext *TheContext)
67 : Context(TheContext), Root(Root) {
68 for (
const auto &SyntheticStmt : TheCFG->synthetic_stmts()) {
69 SyntheticStmtSourceMap[SyntheticStmt.first] = SyntheticStmt.second;
74 Before = resolveSyntheticStmt(Before);
75 After = resolveSyntheticStmt(After);
79 for (
const Stmt *Successor = getSequenceSuccessor(Before); Successor;
80 Successor = getSequenceSuccessor(Successor)) {
81 if (isDescendantOrEqual(After, Successor, Context))
88 if (Parent == After ||
inSequence(Parent, After))
96 const Stmt *Before)
const {
100 const Stmt *ExprSequence::getSequenceSuccessor(
const Stmt *S)
const {
104 if (!isDescendantOrEqual(Parent, Root, Context))
107 if (
const auto *BO = dyn_cast<BinaryOperator>(Parent)) {
109 if (BO->getLHS() == S && BO->getOpcode() == BO_Comma)
111 }
else if (
const auto *InitList = dyn_cast<InitListExpr>(Parent)) {
114 for (
unsigned I = 1; I < InitList->getNumInits(); ++I) {
115 if (InitList->getInit(I - 1) == S)
116 return InitList->getInit(I);
118 }
else if (
const auto *Compound = dyn_cast<CompoundStmt>(Parent)) {
121 const Stmt *Previous =
nullptr;
122 for (
const auto *Child : Compound->body()) {
127 }
else if (
const auto *TheDeclStmt = dyn_cast<DeclStmt>(Parent)) {
130 const Expr *PreviousInit =
nullptr;
131 for (
const Decl *TheDecl : TheDeclStmt->decls()) {
132 if (
const auto *TheVarDecl = dyn_cast<VarDecl>(TheDecl)) {
133 if (
const Expr *Init = TheVarDecl->getInit()) {
134 if (PreviousInit == S)
140 }
else if (
const auto *ForRange = dyn_cast<CXXForRangeStmt>(Parent)) {
144 if (S == ForRange->getLoopVarStmt())
145 return ForRange->getBody();
146 }
else if (
const auto *TheIfStmt = dyn_cast<IfStmt>(Parent)) {
151 if (S == TheIfStmt->getInit())
152 return TheIfStmt->getConditionVariableDeclStmt();
153 if (S == TheIfStmt->getConditionVariableDeclStmt())
154 return TheIfStmt->getCond();
155 }
else if (
const auto *TheSwitchStmt = dyn_cast<SwitchStmt>(Parent)) {
157 if (S == TheSwitchStmt->getInit())
158 return TheSwitchStmt->getConditionVariableDeclStmt();
159 if (S == TheSwitchStmt->getConditionVariableDeclStmt())
160 return TheSwitchStmt->getCond();
161 }
else if (
const auto *TheWhileStmt = dyn_cast<WhileStmt>(Parent)) {
165 if (S == TheWhileStmt->getConditionVariableDeclStmt())
166 return TheWhileStmt->getCond();
173 const Stmt *ExprSequence::resolveSyntheticStmt(
const Stmt *S)
const {
174 if (SyntheticStmtSourceMap.count(S))
175 return SyntheticStmtSourceMap.lookup(S);
180 : Context(TheContext) {
181 for (
const auto *B : *TheCFG) {
182 for (
const auto &Elem : *B) {
183 if (Optional<CFGStmt> S = Elem.getAs<CFGStmt>())
184 Map[S->getStmt()] = B;
190 while (!Map.count(S)) {
191 SmallVector<const Stmt *, 1> Parents =
getParentStmts(S, Context);
197 return Map.lookup(S);
bool inSequence(const Stmt *Before, const Stmt *After) const
Returns whether Before is sequenced before After.
const CFGBlock * blockContainingStmt(const Stmt *S) const
Returns the block that S is contained in.
bool potentiallyAfter(const Stmt *After, const Stmt *Before) const
Returns whether After can potentially be evaluated after Before.
StmtToBlockMap(const CFG *TheCFG, ASTContext *TheContext)
Initializes the map for the given CFG.
ExprSequence(const CFG *TheCFG, const Stmt *Root, ASTContext *TheContext)
Initializes this ExprSequence with sequence information for the given CFG.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
static SmallVector< const Stmt *, 1 > getParentStmts(const Stmt *S, ASTContext *Context)