29 ASTContext *Context) {
30 SmallVector<const Stmt *, 1>
Result;
32 ASTContext::DynTypedNodeList Parents = Context->getParents(*S);
34 SmallVector<ast_type_traits::DynTypedNode, 1> NodesToProcess(Parents.begin(),
37 while (!NodesToProcess.empty()) {
38 ast_type_traits::DynTypedNode Node = NodesToProcess.back();
39 NodesToProcess.pop_back();
41 if (
const auto *S = Node.get<Stmt>()) {
44 Parents = Context->getParents(Node);
45 NodesToProcess.append(Parents.begin(), Parents.end());
53 bool isDescendantOrEqual(
const Stmt *Descendant,
const Stmt *Ancestor,
54 ASTContext *Context) {
55 if (Descendant == Ancestor)
58 if (isDescendantOrEqual(Parent, Ancestor, Context))
67 ASTContext *TheContext)
68 : Context(TheContext), Root(Root) {
69 for (
const auto &SyntheticStmt : TheCFG->synthetic_stmts()) {
70 SyntheticStmtSourceMap[SyntheticStmt.first] = SyntheticStmt.second;
75 Before = resolveSyntheticStmt(Before);
76 After = resolveSyntheticStmt(After);
80 for (
const Stmt *Successor = getSequenceSuccessor(Before); Successor;
81 Successor = getSequenceSuccessor(Successor)) {
82 if (isDescendantOrEqual(After, Successor, Context))
89 if (Parent == After ||
inSequence(Parent, After))
97 const Stmt *Before)
const {
101 const Stmt *ExprSequence::getSequenceSuccessor(
const Stmt *S)
const {
105 if (!isDescendantOrEqual(Parent, Root, Context))
108 if (
const auto *BO = dyn_cast<BinaryOperator>(Parent)) {
110 if (BO->getLHS() == S && BO->getOpcode() == BO_Comma)
112 }
else if (
const auto *InitList = dyn_cast<InitListExpr>(Parent)) {
115 for (
unsigned I = 1; I < InitList->getNumInits(); ++I) {
116 if (InitList->getInit(I - 1) == S)
117 return InitList->getInit(I);
119 }
else if (
const auto *Compound = dyn_cast<CompoundStmt>(Parent)) {
122 const Stmt *Previous =
nullptr;
123 for (
const auto *Child : Compound->body()) {
128 }
else if (
const auto *TheDeclStmt = dyn_cast<DeclStmt>(Parent)) {
131 const Expr *PreviousInit =
nullptr;
132 for (
const Decl *TheDecl : TheDeclStmt->decls()) {
133 if (
const auto *TheVarDecl = dyn_cast<VarDecl>(TheDecl)) {
134 if (
const Expr *Init = TheVarDecl->getInit()) {
135 if (PreviousInit == S)
141 }
else if (
const auto *ForRange = dyn_cast<CXXForRangeStmt>(Parent)) {
145 if (S == ForRange->getLoopVarStmt())
146 return ForRange->getBody();
147 }
else if (
const auto *TheIfStmt = dyn_cast<IfStmt>(Parent)) {
152 if (S == TheIfStmt->getInit())
153 return TheIfStmt->getConditionVariableDeclStmt();
154 if (S == TheIfStmt->getConditionVariableDeclStmt())
155 return TheIfStmt->getCond();
156 }
else if (
const auto *TheSwitchStmt = dyn_cast<SwitchStmt>(Parent)) {
158 if (S == TheSwitchStmt->getInit())
159 return TheSwitchStmt->getConditionVariableDeclStmt();
160 if (S == TheSwitchStmt->getConditionVariableDeclStmt())
161 return TheSwitchStmt->getCond();
162 }
else if (
const auto *TheWhileStmt = dyn_cast<WhileStmt>(Parent)) {
166 if (S == TheWhileStmt->getConditionVariableDeclStmt())
167 return TheWhileStmt->getCond();
174 const Stmt *ExprSequence::resolveSyntheticStmt(
const Stmt *S)
const {
175 if (SyntheticStmtSourceMap.count(S))
176 return SyntheticStmtSourceMap.lookup(S);
181 : Context(TheContext) {
182 for (
const auto *B : *TheCFG) {
183 for (
const auto &Elem : *B) {
184 if (Optional<CFGStmt> S = Elem.getAs<CFGStmt>())
185 Map[S->getStmt()] = B;
191 while (!Map.count(S)) {
192 SmallVector<const Stmt *, 1> Parents =
getParentStmts(S, Context);
198 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.
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
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++ -*-===//
static SmallVector< const Stmt *, 1 > getParentStmts(const Stmt *S, ASTContext *Context)