AST: Exclude empty then/else/do statements

This commit is contained in:
Tom Hvitved
2021-03-25 09:53:30 +01:00
parent ca7c0584c7
commit 58ecd771d3
10 changed files with 130 additions and 9 deletions

View File

@@ -94,10 +94,10 @@ private module Cached {
not strictcount(int i | exists(g.getParent().(Generated::LeftAssignmentList).getChild(i))) = 1
} or
TDivExpr(Generated::Binary g) { g instanceof @binary_slash } or
TDo(Generated::Do g) or
TDo(Generated::Do g) { exists(g.getChild(_)) } or
TDoBlock(Generated::DoBlock g) { not g.getParent() instanceof Generated::Lambda } or
TElementReference(Generated::ElementReference g) or
TElse(Generated::Else g) or
TElse(Generated::Else g) { exists(g.getChild(_)) } or
TElsif(Generated::Elsif g) or
TEmptyStmt(Generated::EmptyStatement g) or
TEndBlock(Generated::EndBlock g) or
@@ -198,7 +198,7 @@ private module Cached {
TSubshellLiteral(Generated::Subshell g) or
TSymbolArrayLiteral(Generated::SymbolArray g) or
TTernaryIfExpr(Generated::Conditional g) or
TThen(Generated::Then g) or
TThen(Generated::Then g) { exists(g.getChild(_)) } or
TTokenConstantAccess(Generated::Constant g) {
// A tree-sitter `constant` token is a read of that constant in any context
// where an identifier would be a vcall.

View File

@@ -643,10 +643,17 @@ module Trees {
final override predicate first(AstNode first) { first(this.getCondition(), first) }
private AstNode getConditionSucc() {
result = this.getBody()
or
not exists(this.getBody()) and
result = this.getCondition()
}
final override predicate succ(AstNode pred, AstNode succ, Completion c) {
last(this.getCondition(), pred, c) and
this.entersLoopWhenConditionIs(c.(BooleanCompletion).getValue()) and
first(this.getBody(), succ)
first(this.getConditionSucc(), succ)
or
last(this.getBody(), pred, c) and
first(this.getCondition(), succ) and