Merge pull request #4222 from jbj/BlockStmt

C++/Java/JS: Rename Block -> BlockStmt
This commit is contained in:
Mathias Vorreiter Pedersen
2020-09-09 10:02:37 +02:00
committed by GitHub
75 changed files with 474 additions and 437 deletions

View File

@@ -20,6 +20,7 @@ The following changes in version 1.26 affect C/C++ analysis in all applications.
## Changes to libraries ## Changes to libraries
* The QL class `Block`, denoting the `{ ... }` statement, is renamed to `BlockStmt`.
* The models library now models many taint flows through `std::array`, `std::vector`, `std::deque`, `std::list` and `std::forward_list`. * The models library now models many taint flows through `std::array`, `std::vector`, `std::deque`, `std::list` and `std::forward_list`.
* The models library now models many more taint flows through `std::string`. * The models library now models many more taint flows through `std::string`.
* The `SimpleRangeAnalysis` library now supports multiplications of the form * The `SimpleRangeAnalysis` library now supports multiplications of the form

View File

@@ -0,0 +1,21 @@
# Improvements to Java analysis
The following changes in version 1.26 affect Java analysis in all applications.
## General improvements
## New queries
| **Query** | **Tags** | **Purpose** |
|-----------------------------|-----------|--------------------------------------------------------------------|
## Changes to existing queries
| **Query** | **Expected impact** | **Change** |
|------------------------------|------------------------|-----------------------------------|
## Changes to libraries
* The QL class `Block`, denoting the `{ ... }` statement, is renamed to `BlockStmt`.

View File

@@ -9,6 +9,6 @@
import cpp import cpp
from Block blk from BlockStmt blk
where blk.getNumStmt() = 0 where blk.getNumStmt() = 0
select blk select blk

View File

@@ -13,5 +13,5 @@
import cpp import cpp
from IfStmt i from IfStmt i
where i.getThen().(Block).getNumStmt() = 0 where i.getThen().(BlockStmt).getNumStmt() = 0
select i select i

View File

@@ -8,6 +8,6 @@
import cpp import cpp
from Block b from BlockStmt b
where b.getNumStmt() = 1 where b.getNumStmt() = 1
select b select b

View File

@@ -14,7 +14,7 @@ import cpp
class ComplexStmt extends Stmt { class ComplexStmt extends Stmt {
ComplexStmt() { ComplexStmt() {
exists(Block body | exists(BlockStmt body |
body = this.(Loop).getStmt() or body = this.(Loop).getStmt() or
body = this.(SwitchStmt).getStmt() body = this.(SwitchStmt).getStmt()
| |
@@ -24,7 +24,7 @@ class ComplexStmt extends Stmt {
} }
} }
from Block b, int n, ComplexStmt complexStmt from BlockStmt b, int n, ComplexStmt complexStmt
where where
n = strictcount(ComplexStmt s | s = b.getAStmt()) and n = strictcount(ComplexStmt s | s = b.getAStmt()) and
n > 3 and n > 3 and

View File

@@ -17,7 +17,7 @@ where
shadowing(lv1, lv2) and shadowing(lv1, lv2) and
not lv1.isCompilerGenerated() and not lv1.isCompilerGenerated() and
not lv2.isCompilerGenerated() and not lv2.isCompilerGenerated() and
not lv1.getParentScope().(Block).isInMacroExpansion() and not lv1.getParentScope().(BlockStmt).isInMacroExpansion() and
not lv2.getParentScope().(Block).isInMacroExpansion() not lv2.getParentScope().(BlockStmt).isInMacroExpansion()
select lv1, "Variable " + lv1.getName() + " hides another variable of the same name (on $@).", lv2, select lv1, "Variable " + lv1.getName() + " hides another variable of the same name (on $@).", lv2,
"line " + lv2.getLocation().getStartLine().toString() "line " + lv2.getLocation().getStartLine().toString()

View File

@@ -14,7 +14,7 @@
import cpp import cpp
predicate emptyBlock(ControlStructure s, Block b) { predicate emptyBlock(ControlStructure s, BlockStmt b) {
b = s.getAChild() and b = s.getAChild() and
not exists(b.getAChild()) and not exists(b.getAChild()) and
not b.isInMacroExpansion() and not b.isInMacroExpansion() and
@@ -23,7 +23,7 @@ predicate emptyBlock(ControlStructure s, Block b) {
class AffectedFile extends File { class AffectedFile extends File {
AffectedFile() { AffectedFile() {
exists(Block b | exists(BlockStmt b |
emptyBlock(_, b) and emptyBlock(_, b) and
this = b.getFile() this = b.getFile()
) )
@@ -37,7 +37,7 @@ class AffectedFile extends File {
class BlockOrNonChild extends Element { class BlockOrNonChild extends Element {
BlockOrNonChild() { BlockOrNonChild() {
( (
this instanceof Block this instanceof BlockStmt
or or
this instanceof Comment this instanceof Comment
or or
@@ -78,7 +78,7 @@ class BlockOrNonChild extends Element {
/** /**
* A block that contains a non-child element. * A block that contains a non-child element.
*/ */
predicate emptyBlockContainsNonchild(Block b) { predicate emptyBlockContainsNonchild(BlockStmt b) {
emptyBlock(_, b) and emptyBlock(_, b) and
exists(BlockOrNonChild c, AffectedFile file | exists(BlockOrNonChild c, AffectedFile file |
c.(BlockOrNonChild).getStartRankIn(file) = 1 + b.(BlockOrNonChild).getStartRankIn(file) and c.(BlockOrNonChild).getStartRankIn(file) = 1 + b.(BlockOrNonChild).getStartRankIn(file) and
@@ -91,7 +91,7 @@ predicate emptyBlockContainsNonchild(Block b) {
* A block that is entirely on one line, which also contains a comment. Chances * A block that is entirely on one line, which also contains a comment. Chances
* are the comment is intended to refer to the block. * are the comment is intended to refer to the block.
*/ */
predicate lineComment(Block b) { predicate lineComment(BlockStmt b) {
emptyBlock(_, b) and emptyBlock(_, b) and
exists(Location bLocation, File f, int line | exists(Location bLocation, File f, int line |
bLocation = b.getLocation() and bLocation = b.getLocation() and
@@ -106,7 +106,7 @@ predicate lineComment(Block b) {
) )
} }
from ControlStructure s, Block eb from ControlStructure s, BlockStmt eb
where where
emptyBlock(s, eb) and emptyBlock(s, eb) and
not emptyBlockContainsNonchild(eb) and not emptyBlockContainsNonchild(eb) and

View File

@@ -12,7 +12,7 @@
import cpp import cpp
import semmle.code.cpp.commons.Exclusions import semmle.code.cpp.commons.Exclusions
Stmt getNextRealStmt(Block b, int i) { Stmt getNextRealStmt(BlockStmt b, int i) {
result = b.getStmt(i + 1) and result = b.getStmt(i + 1) and
not result instanceof EmptyStmt not result instanceof EmptyStmt
or or
@@ -20,7 +20,7 @@ Stmt getNextRealStmt(Block b, int i) {
result = getNextRealStmt(b, i + 1) result = getNextRealStmt(b, i + 1)
} }
from JumpStmt js, Block b, int i, Stmt s from JumpStmt js, BlockStmt b, int i, Stmt s
where where
b.getStmt(i) = js and b.getStmt(i) = js and
s = getNextRealStmt(b, i) and s = getNextRealStmt(b, i) and

View File

@@ -12,7 +12,7 @@
import cpp import cpp
int lineInBlock(File f) { int lineInBlock(File f) {
exists(Block block, Location blockLocation | exists(BlockStmt block, Location blockLocation |
block.getFile() = f and blockLocation = block.getLocation() block.getFile() = f and blockLocation = block.getLocation()
| |
result in [blockLocation.getStartLine() .. blockLocation.getEndLine()] result in [blockLocation.getStartLine() .. blockLocation.getEndLine()]

View File

@@ -27,11 +27,11 @@ predicate macroUseLocation(File f, int start, int end) {
} }
pragma[noopt] pragma[noopt]
predicate emptyIf(IfStmt s, Block b, File f, int start, int end) { predicate emptyIf(IfStmt s, BlockStmt b, File f, int start, int end) {
s instanceof IfStmt and s instanceof IfStmt and
not exists(s.getElse()) and not exists(s.getElse()) and
b = s.getThen() and b = s.getThen() and
b instanceof Block and b instanceof BlockStmt and
not exists(b.getAChild()) and not exists(b.getAChild()) and
f = b.getFile() and f = b.getFile() and
exists(Location l | exists(Location l |
@@ -42,7 +42,7 @@ predicate emptyIf(IfStmt s, Block b, File f, int start, int end) {
} }
pragma[noopt] pragma[noopt]
predicate query(IfStmt s, Block b) { predicate query(IfStmt s, BlockStmt b) {
exists(File f, int blockStart, int blockEnd | exists(File f, int blockStart, int blockEnd |
emptyIf(s, b, f, blockStart, blockEnd) and emptyIf(s, b, f, blockStart, blockEnd) and
not exists(int macroStart, int macroEnd | not exists(int macroStart, int macroEnd |
@@ -53,7 +53,7 @@ predicate query(IfStmt s, Block b) {
) )
} }
from IfStmt s, Block b from IfStmt s, BlockStmt b
where where
query(s, b) and query(s, b) and
not b.isInMacroExpansion() not b.isInMacroExpansion()

View File

@@ -27,7 +27,7 @@ int logicalLength(FunctionDeclarationEntry f) {
count(Stmt s | count(Stmt s |
s.getEnclosingFunction() = f.getFunction() and s.getEnclosingFunction() = f.getFunction() and
s.getFile() = f.getFile() and s.getFile() = f.getFile() and
not s instanceof Block and not s instanceof BlockStmt and
not s instanceof EmptyStmt and not s instanceof EmptyStmt and
not exists(ForStmt for | s = for.getInitialization()) and not exists(ForStmt for | s = for.getInitialization()) and
not s.isAffectedByMacro() not s.isAffectedByMacro()

View File

@@ -14,7 +14,7 @@ import cpp
class OneLineStmt extends Stmt { class OneLineStmt extends Stmt {
OneLineStmt() { OneLineStmt() {
this.getLocation().getStartLine() = this.getLocation().getEndLine() and this.getLocation().getStartLine() = this.getLocation().getEndLine() and
not this instanceof Block and not this instanceof BlockStmt and
not exists(ForStmt for | this = for.getInitialization()) and not exists(ForStmt for | this = for.getInitialization()) and
( (
// Either this statement is not touched by a macro at all... // Either this statement is not touched by a macro at all...

View File

@@ -27,7 +27,7 @@ int logicalLength(FunctionDeclarationEntry f) {
count(Stmt s | count(Stmt s |
s.getEnclosingFunction() = f.getFunction() and s.getEnclosingFunction() = f.getFunction() and
s.getFile() = f.getFile() and s.getFile() = f.getFile() and
not s instanceof Block and not s instanceof BlockStmt and
not s instanceof EmptyStmt and not s instanceof EmptyStmt and
not exists(ForStmt for | s = for.getInitialization()) and not exists(ForStmt for | s = for.getInitialization()) and
not s.isAffectedByMacro() not s.isAffectedByMacro()

View File

@@ -13,7 +13,7 @@
import cpp import cpp
predicate blockDominates(Block check, Block access) { predicate blockDominates(BlockStmt check, BlockStmt access) {
check.getLocation().getStartLine() <= access.getLocation().getStartLine() and check.getLocation().getStartLine() <= access.getLocation().getStartLine() and
check.getLocation().getEndLine() >= access.getLocation().getEndLine() check.getLocation().getEndLine() >= access.getLocation().getEndLine()
} }

View File

@@ -117,7 +117,7 @@ private predicate blockCoversStatement(int equivClass, int first, int last, Stmt
private Stmt statementInMethod(FunctionDeclarationEntry m) { private Stmt statementInMethod(FunctionDeclarationEntry m) {
result.getParent+() = m.getBlock() and result.getParent+() = m.getBlock() and
not result.getLocation() instanceof UnknownStmtLocation and not result.getLocation() instanceof UnknownStmtLocation and
not result instanceof Block not result instanceof BlockStmt
} }
private predicate duplicateStatement( private predicate duplicateStatement(

View File

@@ -13,7 +13,7 @@ import cpp
from Stmt parent, Stmt child from Stmt parent, Stmt child
where where
not child instanceof Block and not child instanceof BlockStmt and
( (
child = parent.(IfStmt).getThen() child = parent.(IfStmt).getThen()
or or

View File

@@ -28,7 +28,7 @@ predicate oppositeOperators(string op1, string op2) {
* `!op2(_, _)`. * `!op2(_, _)`.
*/ */
predicate implementedAsNegationOf(Operator op1, Operator op2) { predicate implementedAsNegationOf(Operator op1, Operator op2) {
exists(Block b, ReturnStmt r, NotExpr n, Expr o | exists(BlockStmt b, ReturnStmt r, NotExpr n, Expr o |
b = op1.getBlock() and b = op1.getBlock() and
b.getNumStmt() = 1 and b.getNumStmt() = 1 and
r = b.getStmt(0) and r = b.getStmt(0) and

View File

@@ -29,7 +29,7 @@ predicate localShadowsParameter(LocalVariable lv, Parameter p) {
from Variable v, Variable shadowed from Variable v, Variable shadowed
where where
not v.getParentScope().(Block).isInMacroExpansion() and not v.getParentScope().(BlockStmt).isInMacroExpansion() and
( (
v.(LocalVariableOrParameter).shadowsGlobal(shadowed.(GlobalVariable)) or v.(LocalVariableOrParameter).shadowsGlobal(shadowed.(GlobalVariable)) or
localShadowsParameter(v, shadowed) or localShadowsParameter(v, shadowed) or

View File

@@ -38,7 +38,7 @@ predicate noDefUsePath(LocalVariable lv, ControlFlowNode n) {
} }
predicate neighbouringStmts(Stmt s1, Stmt s2) { predicate neighbouringStmts(Stmt s1, Stmt s2) {
exists(Block b, int i | exists(BlockStmt b, int i |
i in [0 .. b.getNumStmt() - 2] and i in [0 .. b.getNumStmt() - 2] and
s1 = b.getStmt(i) and s1 = b.getStmt(i) and
s2 = b.getStmt(i + 1) s2 = b.getStmt(i + 1)

View File

@@ -22,6 +22,6 @@ where
not s instanceof ControlStructure and not s instanceof ControlStructure and
// Exclude blocks; if a child of the block violates the rule that will still // Exclude blocks; if a child of the block violates the rule that will still
// be picked up so there is no point in blaming the block as well // be picked up so there is no point in blaming the block as well
not s instanceof Block and not s instanceof BlockStmt and
s.isPure() s.isPure()
select s, "AV Rule 187: All non-null statements shall potentially have a side-effect." select s, "AV Rule 187: All non-null statements shall potentially have a side-effect."

View File

@@ -18,7 +18,7 @@ import cpp
// whether t is the last statement of s, possibly peeling off blocks // whether t is the last statement of s, possibly peeling off blocks
predicate isTerminatingStmt(Stmt s, Stmt t) { predicate isTerminatingStmt(Stmt s, Stmt t) {
s = t or isTerminatingStmt(s.(Block).getLastStmt(), t) s = t or isTerminatingStmt(s.(BlockStmt).getLastStmt(), t)
} }
from BreakStmt s from BreakStmt s

View File

@@ -128,7 +128,7 @@ class Element extends ElementBase {
/** /**
* Gets the parent scope of this `Element`, if any. * Gets the parent scope of this `Element`, if any.
* A scope is a `Type` (`Class` / `Enum`), a `Namespace`, a `Block`, a `Function`, * A scope is a `Type` (`Class` / `Enum`), a `Namespace`, a `BlockStmt`, a `Function`,
* or certain kinds of `Statement`. * or certain kinds of `Statement`.
*/ */
Element getParentScope() { Element getParentScope() {
@@ -161,7 +161,7 @@ class Element extends ElementBase {
exists(EnumConstant e | this = e and result = e.getDeclaringEnum()) exists(EnumConstant e | this = e and result = e.getDeclaringEnum())
or or
// result instanceof block|function // result instanceof block|function
exists(Block b | this = b and blockscope(unresolveElement(b), unresolveElement(result))) exists(BlockStmt b | this = b and blockscope(unresolveElement(b), unresolveElement(result)))
or or
exists(TemplateFunction tf | this = tf.getATemplateArgument() and result = tf) exists(TemplateFunction tf | this = tf.getATemplateArgument() and result = tf)
or or

View File

@@ -268,7 +268,7 @@ class Function extends Declaration, ControlFlowNode, AccessHolder, @function {
* block, this gives the block guarded by the try statement. See * block, this gives the block guarded by the try statement. See
* `FunctionTryStmt` for further information. * `FunctionTryStmt` for further information.
*/ */
Block getBlock() { result.getParentScope() = this } BlockStmt getBlock() { result.getParentScope() = this }
/** Holds if this function has an entry point. */ /** Holds if this function has an entry point. */
predicate hasEntryPoint() { exists(getEntryPoint()) } predicate hasEntryPoint() { exists(getEntryPoint()) }
@@ -276,7 +276,7 @@ class Function extends Declaration, ControlFlowNode, AccessHolder, @function {
/** /**
* Gets the first node in this function's control flow graph. * Gets the first node in this function's control flow graph.
* *
* For most functions, this first node will be the `Block` returned by * For most functions, this first node will be the `BlockStmt` returned by
* `getBlock`. However in C++, the first node can also be a * `getBlock`. However in C++, the first node can also be a
* `FunctionTryStmt`. * `FunctionTryStmt`.
*/ */
@@ -564,7 +564,7 @@ class FunctionDeclarationEntry extends DeclarationEntry, @fun_decl {
* If this is a function definition, get the block containing the * If this is a function definition, get the block containing the
* function body. * function body.
*/ */
Block getBlock() { BlockStmt getBlock() {
this.isDefinition() and this.isDefinition() and
result = getFunction().getBlock() and result = getFunction().getBlock() and
result.getFile() = this.getFile() result.getFile() = this.getFile()
@@ -576,7 +576,7 @@ class FunctionDeclarationEntry extends DeclarationEntry, @fun_decl {
*/ */
pragma[noopt] pragma[noopt]
int getNumberOfLines() { int getNumberOfLines() {
exists(Block b, Location l, int start, int end, int diff | b = getBlock() | exists(BlockStmt b, Location l, int start, int end, int diff | b = getBlock() |
l = b.getLocation() and l = b.getLocation() and
start = l.getStartLine() and start = l.getStartLine() and
end = l.getEndLine() and end = l.getEndLine() and

View File

@@ -136,7 +136,7 @@ deprecated class ObjcTryStmt extends TryStmt {
* DEPRECATED: Objective-C is no longer supported. * DEPRECATED: Objective-C is no longer supported.
* An Objective C `@finally` block. * An Objective C `@finally` block.
*/ */
deprecated class FinallyBlock extends Block { deprecated class FinallyBlock extends BlockStmt {
FinallyBlock() { none() } FinallyBlock() { none() }
/** Gets the try statement corresponding to this finally block. */ /** Gets the try statement corresponding to this finally block. */

View File

@@ -98,7 +98,7 @@ class Parameter extends LocalScopeVariable, @parameter {
* DEPRECATED: this method was used in a previous implementation of * DEPRECATED: this method was used in a previous implementation of
* getName, but is no longer in use. * getName, but is no longer in use.
*/ */
deprecated string getNameInBlock(Block b) { deprecated string getNameInBlock(BlockStmt b) {
exists(ParameterDeclarationEntry pde | exists(ParameterDeclarationEntry pde |
pde.getFunctionDeclarationEntry().getBlock() = b and pde.getFunctionDeclarationEntry().getBlock() = b and
this.getFunction().getBlock() = b and this.getFunction().getBlock() = b and
@@ -127,7 +127,7 @@ class Parameter extends LocalScopeVariable, @parameter {
* Gets the catch block to which this parameter belongs, if it is a catch * Gets the catch block to which this parameter belongs, if it is a catch
* block parameter. * block parameter.
*/ */
Block getCatchBlock() { params(underlyingElement(this), unresolveElement(result), _, _) } BlockStmt getCatchBlock() { params(underlyingElement(this), unresolveElement(result), _, _) }
/** /**
* Gets the zero-based index of this parameter. * Gets the zero-based index of this parameter.

View File

@@ -25,7 +25,7 @@ private predicate exprInVoidContext(Expr e) {
( (
exists(ExprStmt s | exists(ExprStmt s |
s = e.getParent() and s = e.getParent() and
not exists(StmtExpr se | s = se.getStmt().(Block).getLastStmt()) not exists(StmtExpr se | s = se.getStmt().(BlockStmt).getLastStmt())
) )
or or
exists(ConditionalExpr c | c.getThen() = e and c instanceof ExprInVoidContext) exists(ConditionalExpr c | c.getThen() = e and c instanceof ExprInVoidContext)

View File

@@ -118,7 +118,7 @@ private predicate excludeNodeAndNodesBelow(Expr e) {
or or
// Constructor init lists should be evaluated, and we can change this in // Constructor init lists should be evaluated, and we can change this in
// the future, but it would mean that a `Function` entry point is not // the future, but it would mean that a `Function` entry point is not
// always a `Block` or `FunctionTryStmt`. // always a `BlockStmt` or `FunctionTryStmt`.
e instanceof ConstructorInit e instanceof ConstructorInit
or or
// Destructor field destructions should also be hooked into the CFG // Destructor field destructions should also be hooked into the CFG
@@ -408,10 +408,10 @@ private Node getControlOrderChildSparse(Node n, int i) {
// in-line in the block containing their corresponding DeclStmt but should // in-line in the block containing their corresponding DeclStmt but should
// not be evaluated in the order implied by their position in the block. We // not be evaluated in the order implied by their position in the block. We
// do the following. // do the following.
// - Block skips all the VlaDeclStmt and VlaDimensionStmt children. // - BlockStmt skips all the VlaDeclStmt and VlaDimensionStmt children.
// - VlaDeclStmt is inserted as a child of DeclStmt // - VlaDeclStmt is inserted as a child of DeclStmt
// - VlaDimensionStmt is inserted as a child of VlaDeclStmt // - VlaDimensionStmt is inserted as a child of VlaDeclStmt
result = n.(Block).getChild(i) and result = n.(BlockStmt).getChild(i) and
not result instanceof VlaDeclStmt and not result instanceof VlaDeclStmt and
not result instanceof VlaDimensionStmt not result instanceof VlaDimensionStmt
or or
@@ -557,7 +557,7 @@ private class Spec extends Pos {
*/ */
private predicate straightLineSparse(Node scope, int i, Node ni, Spec spec) { private predicate straightLineSparse(Node scope, int i, Node ni, Spec spec) {
scope = scope =
any(Block b | any(BlockStmt b |
i = -1 and ni = b and spec.isAt() i = -1 and ni = b and spec.isAt()
or or
if exists(getLastControlOrderChild(b)) if exists(getLastControlOrderChild(b))
@@ -734,7 +734,7 @@ private predicate straightLineSparse(Node scope, int i, Node ni, Spec spec) {
or or
// If the switch body is not a block then this step is skipped, and the // If the switch body is not a block then this step is skipped, and the
// expression jumps directly to the cases. // expression jumps directly to the cases.
i = 1 and ni = s.getStmt().(Block) and spec.isAt() i = 1 and ni = s.getStmt().(BlockStmt) and spec.isAt()
or or
i = 2 and ni = s.getASwitchCase() and spec.isBefore() i = 2 and ni = s.getASwitchCase() and spec.isBefore()
or or
@@ -1010,7 +1010,7 @@ private predicate subEdgeIncludingDestructors(Pos p1, Node n1, Node n2, Pos p2)
* The exact placement of that call in the CFG depends on the type of * The exact placement of that call in the CFG depends on the type of
* `node` as follows: * `node` as follows:
* *
* - `Block`: after ordinary control flow falls off the end of the block * - `BlockStmt`: after ordinary control flow falls off the end of the block
* without jumps or exceptions. * without jumps or exceptions.
* - `ReturnStmt`: After the statement itself or after its operand (if * - `ReturnStmt`: After the statement itself or after its operand (if
* present). * present).

View File

@@ -182,7 +182,7 @@ private int switchCaseRangeEnd(SwitchCase sc) {
* body `switchBlock`. There may be several such expressions: for example, if * body `switchBlock`. There may be several such expressions: for example, if
* the condition is `(x ? y : z)` then the result is {`y`, `z`}. * the condition is `(x ? y : z)` then the result is {`y`, `z`}.
*/ */
private Node getASwitchExpr(SwitchStmt switch, Block switchBlock) { private Node getASwitchExpr(SwitchStmt switch, BlockStmt switchBlock) {
switch.getStmt() = switchBlock and switch.getStmt() = switchBlock and
successors_extended(result, switchBlock) successors_extended(result, switchBlock)
} }
@@ -192,7 +192,7 @@ private Node getASwitchExpr(SwitchStmt switch, Block switchBlock) {
* from `switchBlock` to `sc` is impossible. This considers only non-`default` * from `switchBlock` to `sc` is impossible. This considers only non-`default`
* switch cases. * switch cases.
*/ */
private predicate impossibleSwitchEdge(Block switchBlock, SwitchCase sc) { private predicate impossibleSwitchEdge(BlockStmt switchBlock, SwitchCase sc) {
not sc instanceof DefaultCase and not sc instanceof DefaultCase and
exists(SwitchStmt switch | exists(SwitchStmt switch |
switch = sc.getSwitchStmt() and switch = sc.getSwitchStmt() and
@@ -215,7 +215,7 @@ private predicate impossibleSwitchEdge(Block switchBlock, SwitchCase sc) {
* If a switch provably always chooses a non-default case, then the edge to * If a switch provably always chooses a non-default case, then the edge to
* the default case is impossible. * the default case is impossible.
*/ */
private predicate impossibleDefaultSwitchEdge(Block switchBlock, DefaultCase dc) { private predicate impossibleDefaultSwitchEdge(BlockStmt switchBlock, DefaultCase dc) {
exists(SwitchStmt switch | exists(SwitchStmt switch |
switch = dc.getSwitchStmt() and switch = dc.getSwitchStmt() and
switch.getStmt() = switchBlock and switch.getStmt() = switchBlock and

View File

@@ -27,7 +27,7 @@ class Expr extends StmtParent, @expr {
Function getEnclosingFunction() { result = exprEnclosingElement(this) } Function getEnclosingFunction() { result = exprEnclosingElement(this) }
/** Gets the nearest enclosing set of curly braces around this expression in the source, if any. */ /** Gets the nearest enclosing set of curly braces around this expression in the source, if any. */
Block getEnclosingBlock() { result = getEnclosingStmt().getEnclosingBlock() } BlockStmt getEnclosingBlock() { result = getEnclosingStmt().getEnclosingBlock() }
override Stmt getEnclosingStmt() { override Stmt getEnclosingStmt() {
result = this.getParent().(Expr).getEnclosingStmt() result = this.getParent().(Expr).getEnclosingStmt()
@@ -1109,7 +1109,7 @@ class StmtExpr extends Expr, @expr_stmt {
/** Get the result expression of a statement. (Helper function for StmtExpr.) */ /** Get the result expression of a statement. (Helper function for StmtExpr.) */
private Expr getStmtResultExpr(Stmt stmt) { private Expr getStmtResultExpr(Stmt stmt) {
result = stmt.(ExprStmt).getExpr() or result = stmt.(ExprStmt).getExpr() or
result = getStmtResultExpr(stmt.(Block).getLastStmt()) result = getStmtResultExpr(stmt.(BlockStmt).getLastStmt())
} }
/** /**

View File

@@ -2905,7 +2905,7 @@ predicate exprNeedsCopyIfNotLoaded(Expr expr) {
private predicate exprImmediatelyDiscarded(Expr expr) { private predicate exprImmediatelyDiscarded(Expr expr) {
exists(ExprStmt s | exists(ExprStmt s |
s = expr.getParent() and s = expr.getParent() and
not exists(StmtExpr se | s = se.getStmt().(Block).getLastStmt()) not exists(StmtExpr se | s = se.getStmt().(BlockStmt).getLastStmt())
) )
or or
exists(CommaExpr c | c.getLeftOperand() = expr) exists(CommaExpr c | c.getLeftOperand() = expr)

View File

@@ -290,7 +290,7 @@ class TranslatedTryStmt extends TranslatedStmt {
} }
class TranslatedBlock extends TranslatedStmt { class TranslatedBlock extends TranslatedStmt {
override Block stmt; override BlockStmt stmt;
override TranslatedElement getChild(int id) { result = getStmt(id) } override TranslatedElement getChild(int id) { result = getStmt(id) }

View File

@@ -334,7 +334,7 @@ private predicate branchingExpr(Expr expr) {
* Gets the number of branching statements and expressions in a block. This is * Gets the number of branching statements and expressions in a block. This is
* for computing cyclomatic complexity. * for computing cyclomatic complexity.
*/ */
int cyclomaticComplexityBranches(Block b) { int cyclomaticComplexityBranches(BlockStmt b) {
result = result =
count(Stmt stmt | count(Stmt stmt |
branchingStmt(stmt) and branchingStmt(stmt) and
@@ -373,7 +373,7 @@ private predicate skipParent(Stmt s) {
exists(Stmt parent | parent = s.getParentStmt() | exists(Stmt parent | parent = s.getParentStmt() |
s instanceof IfStmt and parent.(IfStmt).getElse() = s s instanceof IfStmt and parent.(IfStmt).getElse() = s
or or
parent instanceof Block parent instanceof BlockStmt
or or
exists(File f, int startLine, int startCol | exists(File f, int startLine, int startCol |
startsAt(s, f, startLine, startCol) and startsAt(s, f, startLine, startCol) and

View File

@@ -17,8 +17,8 @@ import semmle.code.cpp.stmts.Stmt
* } * }
* ``` * ```
*/ */
class Block extends Stmt, @stmt_block { class BlockStmt extends Stmt, @stmt_block {
override string getAPrimaryQlClass() { result = "Block" } override string getAPrimaryQlClass() { result = "BlockStmt" }
/** /**
* Gets a child declaration of this block. * Gets a child declaration of this block.
@@ -76,8 +76,8 @@ class Block extends Stmt, @stmt_block {
* the result is the expression statement `a = b`. * the result is the expression statement `a = b`.
*/ */
Stmt getLastStmtIn() { Stmt getLastStmtIn() {
if getLastStmt() instanceof Block if getLastStmt() instanceof BlockStmt
then result = getLastStmt().(Block).getLastStmtIn() then result = getLastStmt().(BlockStmt).getLastStmtIn()
else result = getLastStmt() else result = getLastStmt()
} }
@@ -126,3 +126,9 @@ class Block extends Stmt, @stmt_block {
override predicate mayBeGloballyImpure() { this.getAStmt().mayBeGloballyImpure() } override predicate mayBeGloballyImpure() { this.getAStmt().mayBeGloballyImpure() }
} }
/**
* DEPRECATED: This is now called `BlockStmt` to avoid confusion with
* `BasicBlock`.
*/
deprecated class Block = BlockStmt;

View File

@@ -25,10 +25,10 @@ class Stmt extends StmtParent, @stmt {
/** /**
* Gets the nearest enclosing block of this statement in the source, if any. * Gets the nearest enclosing block of this statement in the source, if any.
*/ */
Block getEnclosingBlock() { BlockStmt getEnclosingBlock() {
if if
getParentStmt() instanceof Block and getParentStmt() instanceof BlockStmt and
not getParentStmt().(Block).getLocation() instanceof UnknownLocation not getParentStmt().(BlockStmt).getLocation() instanceof UnknownLocation
then result = getParentStmt() then result = getParentStmt()
else result = getParentStmt().getEnclosingBlock() else result = getParentStmt().getEnclosingBlock()
} }
@@ -53,7 +53,7 @@ class Stmt extends StmtParent, @stmt {
* to trace the flow of control instead. * to trace the flow of control instead.
*/ */
Stmt getFollowingStmt() { Stmt getFollowingStmt() {
exists(Block b, int i | exists(BlockStmt b, int i |
this = b.getStmt(i) and this = b.getStmt(i) and
result = b.getStmt(i + 1) result = b.getStmt(i + 1)
) )
@@ -240,7 +240,7 @@ class IfStmt extends ConditionalStmt, @stmt_if {
* ``` * ```
* if (b) { x = 1; } * if (b) { x = 1; }
* ``` * ```
* the result is the `Block` `{ x = 1; }`. * the result is the `BlockStmt` `{ x = 1; }`.
*/ */
Stmt getThen() { if_then(underlyingElement(this), unresolveElement(result)) } Stmt getThen() { if_then(underlyingElement(this), unresolveElement(result)) }
@@ -251,7 +251,7 @@ class IfStmt extends ConditionalStmt, @stmt_if {
* ``` * ```
* if (b) { x = 1; } else { x = 2; } * if (b) { x = 1; } else { x = 2; }
* ``` * ```
* the result is the `Block` `{ x = 2; }`, and for * the result is the `BlockStmt` `{ x = 2; }`, and for
* ``` * ```
* if (b) { x = 1; } * if (b) { x = 1; }
* ``` * ```
@@ -326,7 +326,7 @@ class ConstexprIfStmt extends ConditionalStmt, @stmt_constexpr_if {
* ``` * ```
* if constexpr (b) { x = 1; } * if constexpr (b) { x = 1; }
* ``` * ```
* the result is the `Block` `{ x = 1; }`. * the result is the `BlockStmt` `{ x = 1; }`.
*/ */
Stmt getThen() { constexpr_if_then(underlyingElement(this), unresolveElement(result)) } Stmt getThen() { constexpr_if_then(underlyingElement(this), unresolveElement(result)) }
@@ -337,7 +337,7 @@ class ConstexprIfStmt extends ConditionalStmt, @stmt_constexpr_if {
* ``` * ```
* if constexpr (b) { x = 1; } else { x = 2; } * if constexpr (b) { x = 1; } else { x = 2; }
* ``` * ```
* the result is the `Block` `{ x = 2; }`, and for * the result is the `BlockStmt` `{ x = 2; }`, and for
* ``` * ```
* if constexpr (b) { x = 1; } * if constexpr (b) { x = 1; }
* ``` * ```
@@ -842,7 +842,7 @@ class RangeBasedForStmt extends Loop, @stmt_range_based_for {
* ``` * ```
* for (int x : xs) { y += x; } * for (int x : xs) { y += x; }
* ``` * ```
* the result is the `Block` `{ y += x; }`. * the result is the `BlockStmt` `{ y += x; }`.
*/ */
override Stmt getStmt() { result = this.getChild(5) } override Stmt getStmt() { result = this.getChild(5) }
@@ -1229,7 +1229,7 @@ class SwitchCase extends Stmt, @stmt_switch_case {
* DEPRECATED: use `SwitchCase.getAStmt` or `ControlFlowNode.getASuccessor` * DEPRECATED: use `SwitchCase.getAStmt` or `ControlFlowNode.getASuccessor`
* rather than this predicate. * rather than this predicate.
* *
* Gets the `Block` statement immediately following this 'switch case' * Gets the `BlockStmt` statement immediately following this 'switch case'
* statement, if any. * statement, if any.
* *
* For example, for * For example, for
@@ -1250,7 +1250,7 @@ class SwitchCase extends Stmt, @stmt_switch_case {
* the `case 7:` has result `{ x = 2; break; }`, `default:` has result * the `case 7:` has result `{ x = 2; break; }`, `default:` has result
* `{ x = 3; }`, and the others have no result. * `{ x = 3; }`, and the others have no result.
*/ */
deprecated Block getLabelledStmt() { deprecated BlockStmt getLabelledStmt() {
exists(int i, Stmt parent | exists(int i, Stmt parent |
this = parent.getChild(i) and this = parent.getChild(i) and
result = parent.getChild(i + 1) result = parent.getChild(i + 1)
@@ -1331,7 +1331,7 @@ class SwitchCase extends Stmt, @stmt_switch_case {
* `default:` has results `{ x = 3; }, `x = 4;` and `break;`. * `default:` has results `{ x = 3; }, `x = 4;` and `break;`.
*/ */
Stmt getAStmt() { Stmt getAStmt() {
exists(Block b, int i, int j | exists(BlockStmt b, int i, int j |
b.getStmt(i) = this and b.getStmt(i) = this and
b.getStmt(j) = result and b.getStmt(j) = result and
i < j and i < j and
@@ -1370,8 +1370,8 @@ class SwitchCase extends Stmt, @stmt_switch_case {
exists(Stmt lastStmt | exists(Stmt lastStmt |
lastStmt = this.getAStmt() and lastStmt = this.getAStmt() and
not lastStmt.getFollowingStmt() = this.getAStmt() and not lastStmt.getFollowingStmt() = this.getAStmt() and
if lastStmt instanceof Block if lastStmt instanceof BlockStmt
then result = lastStmt.(Block).getLastStmtIn() then result = lastStmt.(BlockStmt).getLastStmtIn()
else result = lastStmt else result = lastStmt
) )
} }
@@ -1528,7 +1528,7 @@ class SwitchStmt extends ConditionalStmt, @stmt_switch {
/** /**
* Gets the body statement of this 'switch' statement. * Gets the body statement of this 'switch' statement.
* *
* In almost all cases the result will be a `Block`, but there are * In almost all cases the result will be a `BlockStmt`, but there are
* other syntactically valid constructions. * other syntactically valid constructions.
* *
* For example, for * For example, for
@@ -1859,7 +1859,7 @@ class FunctionTryStmt extends TryStmt {
* } * }
* ``` * ```
*/ */
class CatchBlock extends Block { class CatchBlock extends BlockStmt {
override string getAPrimaryQlClass() { result = "CatchBlock" } override string getAPrimaryQlClass() { result = "CatchBlock" }
CatchBlock() { ishandler(underlyingElement(this)) } CatchBlock() { ishandler(underlyingElement(this)) }
@@ -1925,7 +1925,7 @@ class MicrosoftTryExceptStmt extends MicrosoftTryStmt {
/** Gets the expression guarding the `__except` statement. */ /** Gets the expression guarding the `__except` statement. */
Expr getCondition() { result = getChild(1) } Expr getCondition() { result = getChild(1) }
/** Gets the `__except` statement (usually a `Block`). */ /** Gets the `__except` statement (usually a `BlockStmt`). */
Stmt getExcept() { result = getChild(2) } Stmt getExcept() { result = getChild(2) }
override string getAPrimaryQlClass() { result = "MicrosoftTryExceptStmt" } override string getAPrimaryQlClass() { result = "MicrosoftTryExceptStmt" }
@@ -1949,7 +1949,7 @@ class MicrosoftTryFinallyStmt extends MicrosoftTryStmt {
override string toString() { result = "__try { ... } __finally { ... }" } override string toString() { result = "__try { ... } __finally { ... }" }
/** Gets the `__finally` statement (usually a `Block`). */ /** Gets the `__finally` statement (usually a `BlockStmt`). */
Stmt getFinally() { result = getChild(1) } Stmt getFinally() { result = getChild(1) }
override string getAPrimaryQlClass() { result = "MicrosoftTryFinallyStmt" } override string getAPrimaryQlClass() { result = "MicrosoftTryFinallyStmt" }
@@ -2108,7 +2108,7 @@ class VlaDeclStmt extends Stmt, @stmt_vla_decl {
* declaration statement. * declaration statement.
*/ */
int getNumberOfVlaDimensionStmts() { int getNumberOfVlaDimensionStmts() {
exists(Block b, int j | exists(BlockStmt b, int j |
this = b.getStmt(j) and this = b.getStmt(j) and
result = result =
j - 1 - j - 1 -
@@ -2125,7 +2125,7 @@ class VlaDeclStmt extends Stmt, @stmt_vla_decl {
*/ */
VlaDimensionStmt getVlaDimensionStmt(int i) { VlaDimensionStmt getVlaDimensionStmt(int i) {
i in [0 .. this.getNumberOfVlaDimensionStmts() - 1] and i in [0 .. this.getNumberOfVlaDimensionStmts() - 1] and
exists(Block b, int j | exists(BlockStmt b, int j |
this = b.getStmt(j) and this = b.getStmt(j) and
result = b.getStmt(j - this.getNumberOfVlaDimensionStmts() + i) result = b.getStmt(j - this.getNumberOfVlaDimensionStmts() + i)
) )

View File

@@ -19,7 +19,7 @@ AddressOf.c:
# 1| params: # 1| params:
# 1| 0: [Parameter] i # 1| 0: [Parameter] i
# 1| Type = [IntType] int # 1| Type = [IntType] int
# 1| body: [Block] { ... } # 1| body: [BlockStmt] { ... }
# 2| 0: [DeclStmt] declaration # 2| 0: [DeclStmt] declaration
# 2| 0: [VariableDeclarationEntry] definition of j # 2| 0: [VariableDeclarationEntry] definition of j
# 2| Type = [IntPointerType] int * # 2| Type = [IntPointerType] int *
@@ -34,7 +34,7 @@ AddressOf.c:
ArrayToPointer.c: ArrayToPointer.c:
# 5| [TopLevelFunction] void ArrayToPointer() # 5| [TopLevelFunction] void ArrayToPointer()
# 5| params: # 5| params:
# 6| body: [Block] { ... } # 6| body: [BlockStmt] { ... }
# 7| 0: [DeclStmt] declaration # 7| 0: [DeclStmt] declaration
# 7| 0: [VariableDeclarationEntry] definition of c # 7| 0: [VariableDeclarationEntry] definition of c
# 7| Type = [ArrayType] char[] # 7| Type = [ArrayType] char[]
@@ -70,7 +70,7 @@ Cast.c:
# 1| Type = [CharPointerType] char * # 1| Type = [CharPointerType] char *
# 1| 1: [Parameter] v # 1| 1: [Parameter] v
# 1| Type = [VoidPointerType] void * # 1| Type = [VoidPointerType] void *
# 1| body: [Block] { ... } # 1| body: [BlockStmt] { ... }
# 2| 0: [ExprStmt] ExprStmt # 2| 0: [ExprStmt] ExprStmt
# 2| 0: [AssignExpr] ... = ... # 2| 0: [AssignExpr] ... = ...
# 2| Type = [CharPointerType] char * # 2| Type = [CharPointerType] char *
@@ -89,7 +89,7 @@ Cast.c:
ConditionDecl.cpp: ConditionDecl.cpp:
# 1| [TopLevelFunction] void ConditionDecl() # 1| [TopLevelFunction] void ConditionDecl()
# 1| params: # 1| params:
# 1| body: [Block] { ... } # 1| body: [BlockStmt] { ... }
# 2| 0: [DeclStmt] declaration # 2| 0: [DeclStmt] declaration
# 2| 0: [VariableDeclarationEntry] definition of j # 2| 0: [VariableDeclarationEntry] definition of j
# 2| Type = [IntType] int # 2| Type = [IntType] int
@@ -109,7 +109,7 @@ ConditionDecl.cpp:
# 3| expr: [VariableAccess] k # 3| expr: [VariableAccess] k
# 3| Type = [IntType] int # 3| Type = [IntType] int
# 3| ValueCategory = prvalue(load) # 3| ValueCategory = prvalue(load)
# 3| 1: [Block] { ... } # 3| 1: [BlockStmt] { ... }
# 5| 2: [ReturnStmt] return ... # 5| 2: [ReturnStmt] return ...
ConstructorCall.cpp: ConstructorCall.cpp:
# 1| [CopyAssignmentOperator] C& C::operator=(C const&) # 1| [CopyAssignmentOperator] C& C::operator=(C const&)
@@ -133,7 +133,7 @@ ConstructorCall.cpp:
# 3| 0: [Parameter] i # 3| 0: [Parameter] i
# 3| Type = [IntType] int # 3| Type = [IntType] int
# 3| initializations: # 3| initializations:
# 3| body: [Block] { ... } # 3| body: [BlockStmt] { ... }
# 4| 0: [ReturnStmt] return ... # 4| 0: [ReturnStmt] return ...
# 7| [CopyAssignmentOperator] D& D::operator=(D const&) # 7| [CopyAssignmentOperator] D& D::operator=(D const&)
# 7| params: # 7| params:
@@ -154,7 +154,7 @@ ConstructorCall.cpp:
# 9| [Constructor] void D::D() # 9| [Constructor] void D::D()
# 9| params: # 9| params:
# 9| initializations: # 9| initializations:
# 9| body: [Block] { ... } # 9| body: [BlockStmt] { ... }
# 10| 0: [ReturnStmt] return ... # 10| 0: [ReturnStmt] return ...
# 13| [CopyAssignmentOperator] E& E::operator=(E const&) # 13| [CopyAssignmentOperator] E& E::operator=(E const&)
# 13| params: # 13| params:
@@ -172,7 +172,7 @@ ConstructorCall.cpp:
# 17| Type = [PointerType] D * # 17| Type = [PointerType] D *
# 17| 2: [Parameter] e # 17| 2: [Parameter] e
# 17| Type = [PointerType] E * # 17| Type = [PointerType] E *
# 17| body: [Block] { ... } # 17| body: [BlockStmt] { ... }
# 18| 0: [ExprStmt] ExprStmt # 18| 0: [ExprStmt] ExprStmt
# 18| 0: [AssignExpr] ... = ... # 18| 0: [AssignExpr] ... = ...
# 18| Type = [PointerType] C * # 18| Type = [PointerType] C *
@@ -221,7 +221,7 @@ ConstructorCall.cpp:
Conversion1.c: Conversion1.c:
# 1| [TopLevelFunction] void Conversion1() # 1| [TopLevelFunction] void Conversion1()
# 1| params: # 1| params:
# 1| body: [Block] { ... } # 1| body: [BlockStmt] { ... }
# 2| 0: [DeclStmt] declaration # 2| 0: [DeclStmt] declaration
# 2| 0: [VariableDeclarationEntry] definition of i # 2| 0: [VariableDeclarationEntry] definition of i
# 2| Type = [IntType] int # 2| Type = [IntType] int
@@ -241,7 +241,7 @@ Conversion2.c:
# 1| params: # 1| params:
# 1| 0: [Parameter] x # 1| 0: [Parameter] x
# 1| Type = [IntType] int # 1| Type = [IntType] int
# 1| body: [Block] { ... } # 1| body: [BlockStmt] { ... }
# 2| 0: [ExprStmt] ExprStmt # 2| 0: [ExprStmt] ExprStmt
# 2| 0: [AssignExpr] ... = ... # 2| 0: [AssignExpr] ... = ...
# 2| Type = [IntType] int # 2| Type = [IntType] int
@@ -277,7 +277,7 @@ Conversion3.cpp:
# 1| params: # 1| params:
# 1| 0: [Parameter] x # 1| 0: [Parameter] x
# 1| Type = [IntType] int # 1| Type = [IntType] int
# 1| body: [Block] { ... } # 1| body: [BlockStmt] { ... }
# 2| 0: [ExprStmt] ExprStmt # 2| 0: [ExprStmt] ExprStmt
# 2| 0: [AssignExpr] ... = ... # 2| 0: [AssignExpr] ... = ...
# 2| Type = [IntType] int # 2| Type = [IntType] int
@@ -327,7 +327,7 @@ Conversion4.c:
# 1| params: # 1| params:
# 1| 0: [Parameter] x # 1| 0: [Parameter] x
# 1| Type = [IntType] int # 1| Type = [IntType] int
# 1| body: [Block] { ... } # 1| body: [BlockStmt] { ... }
# 2| 0: [ExprStmt] ExprStmt # 2| 0: [ExprStmt] ExprStmt
# 2| 0: [AssignExpr] ... = ... # 2| 0: [AssignExpr] ... = ...
# 2| Type = [IntType] int # 2| Type = [IntType] int
@@ -352,7 +352,7 @@ Conversion4.c:
DestructorCall.cpp: DestructorCall.cpp:
# 3| [Destructor] void C::~C() # 3| [Destructor] void C::~C()
# 3| params: # 3| params:
# 3| body: [Block] { ... } # 3| body: [BlockStmt] { ... }
# 4| 0: [ReturnStmt] return ... # 4| 0: [ReturnStmt] return ...
# 3| destructions: # 3| destructions:
# 11| [TopLevelFunction] void DestructorCall(C*, D*) # 11| [TopLevelFunction] void DestructorCall(C*, D*)
@@ -361,7 +361,7 @@ DestructorCall.cpp:
# 11| Type = [PointerType] C * # 11| Type = [PointerType] C *
# 11| 1: [Parameter] d # 11| 1: [Parameter] d
# 11| Type = [PointerType] D * # 11| Type = [PointerType] D *
# 11| body: [Block] { ... } # 11| body: [BlockStmt] { ... }
# 12| 0: [ExprStmt] ExprStmt # 12| 0: [ExprStmt] ExprStmt
# 12| 0: [DeleteExpr] delete # 12| 0: [DeleteExpr] delete
# 12| Type = [VoidType] void # 12| Type = [VoidType] void
@@ -385,7 +385,7 @@ DynamicCast.cpp:
# 1| params: # 1| params:
#-----| 0: [Parameter] p#0 #-----| 0: [Parameter] p#0
#-----| Type = [LValueReferenceType] const Base & #-----| Type = [LValueReferenceType] const Base &
#-----| body: [Block] { ... } #-----| body: [BlockStmt] { ... }
#-----| 0: [ReturnStmt] return ... #-----| 0: [ReturnStmt] return ...
#-----| 0: [ReferenceToExpr] (reference to) #-----| 0: [ReferenceToExpr] (reference to)
#-----| Type = [LValueReferenceType] Base & #-----| Type = [LValueReferenceType] Base &
@@ -412,13 +412,13 @@ DynamicCast.cpp:
#-----| Type = [RValueReferenceType] Base && #-----| Type = [RValueReferenceType] Base &&
# 2| [VirtualFunction] void Base::f() # 2| [VirtualFunction] void Base::f()
# 2| params: # 2| params:
# 2| body: [Block] { ... } # 2| body: [BlockStmt] { ... }
# 2| 0: [ReturnStmt] return ... # 2| 0: [ReturnStmt] return ...
# 4| [CopyAssignmentOperator] Derived& Derived::operator=(Derived const&) # 4| [CopyAssignmentOperator] Derived& Derived::operator=(Derived const&)
# 4| params: # 4| params:
#-----| 0: [Parameter] p#0 #-----| 0: [Parameter] p#0
#-----| Type = [LValueReferenceType] const Derived & #-----| Type = [LValueReferenceType] const Derived &
#-----| body: [Block] { ... } #-----| body: [BlockStmt] { ... }
#-----| 0: [ExprStmt] ExprStmt #-----| 0: [ExprStmt] ExprStmt
#-----| 0: [ReferenceDereferenceExpr] (reference dereference) #-----| 0: [ReferenceDereferenceExpr] (reference dereference)
#-----| Type = [Class] Base #-----| Type = [Class] Base
@@ -478,7 +478,7 @@ DynamicCast.cpp:
#-----| Type = [RValueReferenceType] Derived && #-----| Type = [RValueReferenceType] Derived &&
# 5| [VirtualFunction] void Derived::f() # 5| [VirtualFunction] void Derived::f()
# 5| params: # 5| params:
# 5| body: [Block] { ... } # 5| body: [BlockStmt] { ... }
# 5| 0: [ReturnStmt] return ... # 5| 0: [ReturnStmt] return ...
# 8| [TopLevelFunction] void DynamicCast(Base*, Derived*) # 8| [TopLevelFunction] void DynamicCast(Base*, Derived*)
# 8| params: # 8| params:
@@ -486,7 +486,7 @@ DynamicCast.cpp:
# 8| Type = [PointerType] Base * # 8| Type = [PointerType] Base *
# 8| 1: [Parameter] d # 8| 1: [Parameter] d
# 8| Type = [PointerType] Derived * # 8| Type = [PointerType] Derived *
# 8| body: [Block] { ... } # 8| body: [BlockStmt] { ... }
# 9| 0: [ExprStmt] ExprStmt # 9| 0: [ExprStmt] ExprStmt
# 9| 0: [AssignExpr] ... = ... # 9| 0: [AssignExpr] ... = ...
# 9| Type = [PointerType] Derived * # 9| Type = [PointerType] Derived *
@@ -508,7 +508,7 @@ DynamicCast.cpp:
# 12| Type = [LValueReferenceType] Base & # 12| Type = [LValueReferenceType] Base &
# 12| 1: [Parameter] d # 12| 1: [Parameter] d
# 12| Type = [LValueReferenceType] Derived & # 12| Type = [LValueReferenceType] Derived &
# 12| body: [Block] { ... } # 12| body: [BlockStmt] { ... }
# 13| 0: [ExprStmt] ExprStmt # 13| 0: [ExprStmt] ExprStmt
# 13| 0: [ReferenceDereferenceExpr] (reference dereference) # 13| 0: [ReferenceDereferenceExpr] (reference dereference)
# 13| Type = [Class] Derived # 13| Type = [Class] Derived
@@ -545,7 +545,7 @@ Parenthesis.c:
# 1| params: # 1| params:
# 1| 0: [Parameter] i # 1| 0: [Parameter] i
# 1| Type = [IntType] int # 1| Type = [IntType] int
# 1| body: [Block] { ... } # 1| body: [BlockStmt] { ... }
# 2| 0: [ExprStmt] ExprStmt # 2| 0: [ExprStmt] ExprStmt
# 2| 0: [AssignExpr] ... = ... # 2| 0: [AssignExpr] ... = ...
# 2| Type = [IntType] int # 2| Type = [IntType] int
@@ -581,7 +581,7 @@ PointerDereference.c:
# 1| Type = [IntPointerType] int * # 1| Type = [IntPointerType] int *
# 1| 1: [Parameter] j # 1| 1: [Parameter] j
# 1| Type = [IntType] int # 1| Type = [IntType] int
# 1| body: [Block] { ... } # 1| body: [BlockStmt] { ... }
# 2| 0: [ExprStmt] ExprStmt # 2| 0: [ExprStmt] ExprStmt
# 2| 0: [AssignExpr] ... = ... # 2| 0: [AssignExpr] ... = ...
# 2| Type = [IntType] int # 2| Type = [IntType] int
@@ -603,7 +603,7 @@ ReferenceDereference.cpp:
# 4| Type = [LValueReferenceType] int & # 4| Type = [LValueReferenceType] int &
# 4| 1: [Parameter] j # 4| 1: [Parameter] j
# 4| Type = [IntType] int # 4| Type = [IntType] int
# 4| body: [Block] { ... } # 4| body: [BlockStmt] { ... }
# 5| 0: [ExprStmt] ExprStmt # 5| 0: [ExprStmt] ExprStmt
# 5| 0: [AssignExpr] ... = ... # 5| 0: [AssignExpr] ... = ...
# 5| Type = [IntType] int # 5| Type = [IntType] int
@@ -623,7 +623,7 @@ ReferenceTo.cpp:
# 1| params: # 1| params:
# 1| 0: [Parameter] i # 1| 0: [Parameter] i
# 1| Type = [IntPointerType] int * # 1| Type = [IntPointerType] int *
# 1| body: [Block] { ... } # 1| body: [BlockStmt] { ... }
# 2| 0: [ReturnStmt] return ... # 2| 0: [ReturnStmt] return ...
# 2| 0: [ReferenceToExpr] (reference to) # 2| 0: [ReferenceToExpr] (reference to)
# 2| Type = [LValueReferenceType] int & # 2| Type = [LValueReferenceType] int &
@@ -639,7 +639,7 @@ Sizeof.c:
# 1| params: # 1| params:
# 1| 0: [Parameter] array # 1| 0: [Parameter] array
# 1| Type = [ArrayType] int[] # 1| Type = [ArrayType] int[]
# 1| body: [Block] { ... } # 1| body: [BlockStmt] { ... }
# 2| 0: [DeclStmt] declaration # 2| 0: [DeclStmt] declaration
# 2| 0: [VariableDeclarationEntry] definition of i # 2| 0: [VariableDeclarationEntry] definition of i
# 2| Type = [IntType] int # 2| Type = [IntType] int
@@ -676,7 +676,7 @@ Sizeof.c:
StatementExpr.c: StatementExpr.c:
# 1| [TopLevelFunction] void StatementExpr() # 1| [TopLevelFunction] void StatementExpr()
# 1| params: # 1| params:
# 1| body: [Block] { ... } # 1| body: [BlockStmt] { ... }
# 2| 0: [DeclStmt] declaration # 2| 0: [DeclStmt] declaration
# 2| 0: [VariableDeclarationEntry] definition of j # 2| 0: [VariableDeclarationEntry] definition of j
# 2| Type = [IntType] int # 2| Type = [IntType] int
@@ -700,7 +700,7 @@ StaticMemberAccess.cpp:
# 5| Type = [IntType] int # 5| Type = [IntType] int
# 5| 1: [Parameter] xref # 5| 1: [Parameter] xref
# 5| Type = [LValueReferenceType] X & # 5| Type = [LValueReferenceType] X &
# 5| body: [Block] { ... } # 5| body: [BlockStmt] { ... }
# 7| 0: [ExprStmt] ExprStmt # 7| 0: [ExprStmt] ExprStmt
# 7| 0: [AssignExpr] ... = ... # 7| 0: [AssignExpr] ... = ...
# 7| Type = [IntType] int # 7| Type = [IntType] int
@@ -725,7 +725,7 @@ Subscript.c:
# 1| Type = [ArrayType] int[] # 1| Type = [ArrayType] int[]
# 1| 1: [Parameter] j # 1| 1: [Parameter] j
# 1| Type = [IntType] int # 1| Type = [IntType] int
# 1| body: [Block] { ... } # 1| body: [BlockStmt] { ... }
# 2| 0: [ExprStmt] ExprStmt # 2| 0: [ExprStmt] ExprStmt
# 2| 0: [AssignExpr] ... = ... # 2| 0: [AssignExpr] ... = ...
# 2| Type = [IntType] int # 2| Type = [IntType] int
@@ -762,20 +762,20 @@ Throw.cpp:
#-----| 0: [Parameter] p#0 #-----| 0: [Parameter] p#0
#-----| Type = [RValueReferenceType] F && #-----| Type = [RValueReferenceType] F &&
# 2| initializations: # 2| initializations:
# 2| body: [Block] { ... } # 2| body: [BlockStmt] { ... }
# 2| 0: [ReturnStmt] return ... # 2| 0: [ReturnStmt] return ...
# 4| [Constructor] void F::F() # 4| [Constructor] void F::F()
# 4| params: # 4| params:
# 4| initializations: # 4| initializations:
# 4| body: [Block] { ... } # 4| body: [BlockStmt] { ... }
# 4| 0: [ReturnStmt] return ... # 4| 0: [ReturnStmt] return ...
# 6| [TopLevelFunction] void Throw(int) # 6| [TopLevelFunction] void Throw(int)
# 6| params: # 6| params:
# 6| 0: [Parameter] i # 6| 0: [Parameter] i
# 6| Type = [IntType] int # 6| Type = [IntType] int
# 6| body: [Block] { ... } # 6| body: [BlockStmt] { ... }
# 7| 0: [TryStmt] try { ... } # 7| 0: [TryStmt] try { ... }
# 7| 0: [Block] { ... } # 7| 0: [BlockStmt] { ... }
# 8| 0: [IfStmt] if (...) ... # 8| 0: [IfStmt] if (...) ...
# 8| 0: [CStyleCast] (bool)... # 8| 0: [CStyleCast] (bool)...
# 8| Conversion = [BoolConversion] conversion to bool # 8| Conversion = [BoolConversion] conversion to bool
@@ -818,13 +818,13 @@ Typeid.cpp:
# 7| params: # 7| params:
# 13| [VirtualFunction] void Base::v() # 13| [VirtualFunction] void Base::v()
# 13| params: # 13| params:
# 13| body: [Block] { ... } # 13| body: [BlockStmt] { ... }
# 13| 0: [ReturnStmt] return ... # 13| 0: [ReturnStmt] return ...
# 18| [TopLevelFunction] void TypeId(Base*) # 18| [TopLevelFunction] void TypeId(Base*)
# 18| params: # 18| params:
# 18| 0: [Parameter] bp # 18| 0: [Parameter] bp
# 18| Type = [PointerType] Base * # 18| Type = [PointerType] Base *
# 18| body: [Block] { ... } # 18| body: [BlockStmt] { ... }
# 19| 0: [DeclStmt] declaration # 19| 0: [DeclStmt] declaration
# 19| 0: [VariableDeclarationEntry] definition of name # 19| 0: [VariableDeclarationEntry] definition of name
# 19| Type = [PointerType] const char * # 19| Type = [PointerType] const char *
@@ -846,7 +846,7 @@ VacuousDestructorCall.cpp:
# 2| Type = [TemplateParameter] T # 2| Type = [TemplateParameter] T
# 2| 1: [Parameter] y # 2| 1: [Parameter] y
# 2| Type = [PointerType] T * # 2| Type = [PointerType] T *
# 2| body: [Block] { ... } # 2| body: [BlockStmt] { ... }
# 3| 0: [ExprStmt] ExprStmt # 3| 0: [ExprStmt] ExprStmt
# 3| 0: [ExprCall] call to expression # 3| 0: [ExprCall] call to expression
# 3| Type = [UnknownType] unknown # 3| Type = [UnknownType] unknown
@@ -874,7 +874,7 @@ VacuousDestructorCall.cpp:
# 2| Type = [IntType] int # 2| Type = [IntType] int
# 2| 1: [Parameter] y # 2| 1: [Parameter] y
# 2| Type = [IntPointerType] int * # 2| Type = [IntPointerType] int *
# 2| body: [Block] { ... } # 2| body: [BlockStmt] { ... }
# 3| 0: [ExprStmt] ExprStmt # 3| 0: [ExprStmt] ExprStmt
# 3| 0: [VacuousDestructorCall] (vacuous destructor call) # 3| 0: [VacuousDestructorCall] (vacuous destructor call)
# 3| Type = [VoidType] void # 3| Type = [VoidType] void
@@ -894,7 +894,7 @@ VacuousDestructorCall.cpp:
# 7| params: # 7| params:
# 7| 0: [Parameter] i # 7| 0: [Parameter] i
# 7| Type = [IntType] int # 7| Type = [IntType] int
# 7| body: [Block] { ... } # 7| body: [BlockStmt] { ... }
# 10| 0: [ExprStmt] ExprStmt # 10| 0: [ExprStmt] ExprStmt
# 10| 0: [FunctionCall] call to CallDestructor # 10| 0: [FunctionCall] call to CallDestructor
# 10| Type = [VoidType] void # 10| Type = [VoidType] void
@@ -914,7 +914,7 @@ Varargs.c:
# 8| params: # 8| params:
# 8| 0: [Parameter] text # 8| 0: [Parameter] text
# 8| Type = [PointerType] const char * # 8| Type = [PointerType] const char *
# 8| body: [Block] { ... } # 8| body: [BlockStmt] { ... }
# 9| 0: [DeclStmt] declaration # 9| 0: [DeclStmt] declaration
# 9| 0: [VariableDeclarationEntry] definition of args # 9| 0: [VariableDeclarationEntry] definition of args
# 9| Type = [CTypedefType] va_list # 9| Type = [CTypedefType] va_list
@@ -947,7 +947,7 @@ macro_etc.c:
# 3| params: # 3| params:
# 3| 0: [Parameter] i # 3| 0: [Parameter] i
# 3| Type = [IntType] int # 3| Type = [IntType] int
# 3| body: [Block] { ... } # 3| body: [BlockStmt] { ... }
# 4| 0: [DeclStmt] declaration # 4| 0: [DeclStmt] declaration
# 4| 0: [TypeDeclarationEntry] definition of u # 4| 0: [TypeDeclarationEntry] definition of u
# 4| Type = [LocalUnion] u # 4| Type = [LocalUnion] u
@@ -997,7 +997,7 @@ macro_etc.c:
# 10| ValueCategory = prvalue # 10| ValueCategory = prvalue
# 22| [TopLevelFunction] int foo() # 22| [TopLevelFunction] int foo()
# 22| params: # 22| params:
# 22| body: [Block] { ... } # 22| body: [BlockStmt] { ... }
# 23| 0: [DeclStmt] declaration # 23| 0: [DeclStmt] declaration
# 23| 0: [VariableDeclarationEntry] definition of t # 23| 0: [VariableDeclarationEntry] definition of t
# 23| Type = [IntType] int # 23| Type = [IntType] int
@@ -1059,7 +1059,7 @@ macro_etc.c:
# 27| 0: [VariableAccess] i # 27| 0: [VariableAccess] i
# 27| Type = [PlainCharType] char # 27| Type = [PlainCharType] char
# 27| ValueCategory = lvalue # 27| ValueCategory = lvalue
# 27| 3: [Block] { ... } # 27| 3: [BlockStmt] { ... }
# 27| 0: [ExprStmt] ExprStmt # 27| 0: [ExprStmt] ExprStmt
# 27| 0: [AssignAddExpr] ... += ... # 27| 0: [AssignAddExpr] ... += ...
# 27| Type = [IntType] int # 27| Type = [IntType] int
@@ -1111,7 +1111,7 @@ macro_etc.c:
# 28| 0: [VariableAccess] i # 28| 0: [VariableAccess] i
# 28| Type = [PlainCharType] char # 28| Type = [PlainCharType] char
# 28| ValueCategory = lvalue # 28| ValueCategory = lvalue
# 28| 3: [Block] { ... } # 28| 3: [BlockStmt] { ... }
# 28| 0: [ExprStmt] ExprStmt # 28| 0: [ExprStmt] ExprStmt
# 28| 0: [AssignAddExpr] ... += ... # 28| 0: [AssignAddExpr] ... += ...
# 28| Type = [IntType] int # 28| Type = [IntType] int
@@ -1210,7 +1210,7 @@ union_etc.cpp:
# 2| [Constructor] void S::S() # 2| [Constructor] void S::S()
# 2| params: # 2| params:
# 2| initializations: # 2| initializations:
# 2| body: [Block] { ... } # 2| body: [BlockStmt] { ... }
# 2| 0: [ReturnStmt] return ... # 2| 0: [ReturnStmt] return ...
# 2| [CopyConstructor] void S::S(S const&) # 2| [CopyConstructor] void S::S(S const&)
# 2| params: # 2| params:
@@ -1240,7 +1240,7 @@ union_etc.cpp:
# 6| params: # 6| params:
# 6| 0: [Parameter] val # 6| 0: [Parameter] val
# 6| Type = [IntType] int # 6| Type = [IntType] int
# 6| body: [Block] { ... } # 6| body: [BlockStmt] { ... }
# 6| 0: [ExprStmt] ExprStmt # 6| 0: [ExprStmt] ExprStmt
# 6| 0: [AssignExpr] ... = ... # 6| 0: [AssignExpr] ... = ...
# 6| Type = [IntType] int # 6| Type = [IntType] int
@@ -1305,7 +1305,7 @@ union_etc.cpp:
#-----| Type = [RValueReferenceType] C && #-----| Type = [RValueReferenceType] C &&
# 22| [TopLevelFunction] int foo() # 22| [TopLevelFunction] int foo()
# 22| params: # 22| params:
# 22| body: [Block] { ... } # 22| body: [BlockStmt] { ... }
# 23| 0: [DeclStmt] declaration # 23| 0: [DeclStmt] declaration
# 23| 0: [VariableDeclarationEntry] definition of s # 23| 0: [VariableDeclarationEntry] definition of s
# 23| Type = [Struct] S # 23| Type = [Struct] S
@@ -1423,7 +1423,7 @@ union_etc.cpp:
# 33| params: # 33| params:
# 33| 0: [Parameter] val # 33| 0: [Parameter] val
# 33| Type = [IntType] int # 33| Type = [IntType] int
# 33| body: [Block] { ... } # 33| body: [BlockStmt] { ... }
# 33| 0: [ExprStmt] ExprStmt # 33| 0: [ExprStmt] ExprStmt
# 33| 0: [AssignExpr] ... = ... # 33| 0: [AssignExpr] ... = ...
# 33| Type = [IntType] int # 33| Type = [IntType] int
@@ -1440,7 +1440,7 @@ union_etc.cpp:
# 33| 1: [ReturnStmt] return ... # 33| 1: [ReturnStmt] return ...
# 36| [TopLevelFunction] int bar() # 36| [TopLevelFunction] int bar()
# 36| params: # 36| params:
# 36| body: [Block] { ... } # 36| body: [BlockStmt] { ... }
# 37| 0: [DeclStmt] declaration # 37| 0: [DeclStmt] declaration
# 37| 0: [VariableDeclarationEntry] definition of s # 37| 0: [VariableDeclarationEntry] definition of s
# 37| Type = [PointerType] const T * # 37| Type = [PointerType] const T *

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,5 @@
import cpp import cpp
from Block b, MacroAccess m from BlockStmt b, MacroAccess m
where affectedbymacroexpansion(unresolveElement(b), unresolveElement(m)) where affectedbymacroexpansion(unresolveElement(b), unresolveElement(m))
select b, m select b, m

View File

@@ -1,5 +1,5 @@
import cpp import cpp
from Block b, MacroAccess m from BlockStmt b, MacroAccess m
where inmacroexpansion(unresolveElement(b), unresolveElement(m)) where inmacroexpansion(unresolveElement(b), unresolveElement(m))
select b, m select b, m

View File

@@ -1,5 +1,5 @@
import cpp import cpp
from Function f, Block b from Function f, BlockStmt b
where b = f.getEntryPoint() where b = f.getEntryPoint()
select f, b, b.getAStmt() select f, b, b.getAStmt()

View File

@@ -1,6 +1,6 @@
import cpp import cpp
from Function f1, Block body, Declaration d from Function f1, BlockStmt body, Declaration d
where where
body = f1.getBlock() and body = f1.getBlock() and
d = body.getADeclaration() d = body.getADeclaration()

View File

@@ -1,4 +1,4 @@
import cpp import cpp
from Block b, int i from BlockStmt b, int i
select b, i, b.getStmt(i) select b, i, b.getStmt(i)

View File

@@ -1,6 +1,6 @@
import cpp import cpp
from Block s, int i, Stmt f, boolean succ from BlockStmt s, int i, Stmt f, boolean succ
where where
s.getParentStmt().hasChild(s, i) and s.getParentStmt().hasChild(s, i) and
s.getParentStmt().hasChild(f, i + 1) and s.getParentStmt().hasChild(f, i + 1) and

View File

@@ -8,7 +8,7 @@ import cpp
from DoStmt ds, ExprStmt last, Expr succ from DoStmt ds, ExprStmt last, Expr succ
where where
ds.getEnclosingFunction().hasName("normal") and ds.getEnclosingFunction().hasName("normal") and
last = ds.getStmt().(Block).getLastStmt() and last = ds.getStmt().(BlockStmt).getLastStmt() and
succ = last.getExpr().getASuccessor() and succ = last.getExpr().getASuccessor() and
succ = ds.getCondition().getAChild*() and succ = ds.getCondition().getAChild*() and
count(last.getExpr().getASuccessor()) = 1 count(last.getExpr().getASuccessor()) = 1

View File

@@ -9,7 +9,7 @@ import cpp
from ForStmt fs, ExprStmt last, Expr succ from ForStmt fs, ExprStmt last, Expr succ
where where
fs.getEnclosingFunction().hasName("normal") and fs.getEnclosingFunction().hasName("normal") and
last = fs.getStmt().(Block).getLastStmt() and last = fs.getStmt().(BlockStmt).getLastStmt() and
succ = fs.getCondition().getAChild*() and succ = fs.getCondition().getAChild*() and
succ = last.getExpr().getASuccessor() and succ = last.getExpr().getASuccessor() and
count(last.getExpr().getASuccessor()) = 1 count(last.getExpr().getASuccessor()) = 1

View File

@@ -10,7 +10,7 @@ where
is.getEnclosingFunction().hasName("normal") and is.getEnclosingFunction().hasName("normal") and
is.getParentStmt().hasChild(is, k) and is.getParentStmt().hasChild(is, k) and
is.getParentStmt().hasChild(l3, k + 1) and is.getParentStmt().hasChild(l3, k + 1) and
last = is.getThen().(Block).getLastStmt() and last = is.getThen().(BlockStmt).getLastStmt() and
l3 = last.getASuccessor() and l3 = last.getASuccessor() and
count(last.getASuccessor()) = 1 count(last.getASuccessor()) = 1
select last, l3.getName() select last, l3.getName()

View File

@@ -10,7 +10,7 @@ where
is.getEnclosingFunction().hasName("normal") and is.getEnclosingFunction().hasName("normal") and
is.getParentStmt().hasChild(is, k) and is.getParentStmt().hasChild(is, k) and
is.getParentStmt().hasChild(l3, k + 1) and is.getParentStmt().hasChild(l3, k + 1) and
last = is.getElse().(Block).getLastStmt() and last = is.getElse().(BlockStmt).getLastStmt() and
l3 = last.getASuccessor() and l3 = last.getASuccessor() and
count(last.getASuccessor()) = 1 count(last.getASuccessor()) = 1
select last, l3.getName() select last, l3.getName()

View File

@@ -5,7 +5,7 @@
import cpp import cpp
from IfStmt is, Block t from IfStmt is, BlockStmt t
where where
is.getEnclosingFunction().hasName("normal") and is.getEnclosingFunction().hasName("normal") and
t = is.getThen() and t = is.getThen() and

View File

@@ -10,7 +10,7 @@ where
is.getEnclosingFunction().hasName("normal") and is.getEnclosingFunction().hasName("normal") and
is.getParentStmt().hasChild(is, k) and is.getParentStmt().hasChild(is, k) and
is.getParentStmt().hasChild(l2, k + 1) and is.getParentStmt().hasChild(l2, k + 1) and
last = is.getThen().(Block).getLastStmt() and last = is.getThen().(BlockStmt).getLastStmt() and
l2 = last.getASuccessor() and l2 = last.getASuccessor() and
count(last.getASuccessor()) = 1 count(last.getASuccessor()) = 1
select last, l2.getName() select last, l2.getName()

View File

@@ -8,7 +8,7 @@ import cpp
from WhileStmt ws, ExprStmt last, Expr succ from WhileStmt ws, ExprStmt last, Expr succ
where where
ws.getEnclosingFunction().hasName("normal") and ws.getEnclosingFunction().hasName("normal") and
last = ws.getStmt().(Block).getLastStmt() and last = ws.getStmt().(BlockStmt).getLastStmt() and
succ = last.getExpr().getASuccessor() and succ = last.getExpr().getASuccessor() and
succ = ws.getCondition().getAChild*() and succ = ws.getCondition().getAChild*() and
count(last.getExpr().getASuccessor()) = 1 count(last.getExpr().getASuccessor()) = 1

View File

@@ -9,6 +9,6 @@
import java import java
from Block blk from BlockStmt blk
where blk.getNumStmt() = 0 where blk.getNumStmt() = 0
select blk select blk

View File

@@ -13,5 +13,5 @@
import java import java
from IfStmt i from IfStmt i
where i.getThen().(Block).getNumStmt() = 0 where i.getThen().(BlockStmt).getNumStmt() = 0
select i select i

View File

@@ -8,6 +8,6 @@
import java import java
from Block b from BlockStmt b
where b.getNumStmt() = 1 where b.getNumStmt() = 1
select b select b

View File

@@ -27,7 +27,7 @@ predicate oneLineStatement(Stmt s, File f, int line, int col) {
col = l.getStartColumn() col = l.getStartColumn()
) and ) and
// Exclude blocks: `{break;}` is not really a violation. // Exclude blocks: `{break;}` is not really a violation.
not s instanceof Block and not s instanceof BlockStmt and
// Exclude implicit super constructor invocations. // Exclude implicit super constructor invocations.
not s instanceof SuperConstructorInvocationStmt and not s instanceof SuperConstructorInvocationStmt and
// Java enums are desugared to a whole bunch of generated statements. // Java enums are desugared to a whole bunch of generated statements.

View File

@@ -20,6 +20,6 @@ class ComplexStmt extends Stmt {
} }
} }
from Block b, int n from BlockStmt b, int n
where n = count(ComplexStmt s | s = b.getAStmt()) and n > 3 where n = count(ComplexStmt s | s = b.getAStmt()) and n > 3
select b, "Block with too many statements (" + n.toString() + " complex statements in the block)." select b, "Block with too many statements (" + n.toString() + " complex statements in the block)."

View File

@@ -51,9 +51,9 @@ class ImpureStmt extends Stmt {
/** /**
* Get any non-block stmt in the block, including those nested within blocks. * Get any non-block stmt in the block, including those nested within blocks.
*/ */
private Stmt getANestedStmt(Block block) { private Stmt getANestedStmt(BlockStmt block) {
// Any non-block statement // Any non-block statement
not result instanceof Block and result = block.getAStmt() not result instanceof BlockStmt and result = block.getAStmt()
or or
// Or any statement nested in a block // Or any statement nested in a block
result = getANestedStmt(block.getAStmt()) result = getANestedStmt(block.getAStmt())

View File

@@ -42,7 +42,7 @@ predicate hasTypeTest(Variable v) {
*/ */
class ReferenceEquals extends EqualsMethod { class ReferenceEquals extends EqualsMethod {
ReferenceEquals() { ReferenceEquals() {
exists(Block b, ReturnStmt ret, EQExpr eq | exists(BlockStmt b, ReturnStmt ret, EQExpr eq |
this.getBody() = b and this.getBody() = b and
b.getStmt(0) = ret and b.getStmt(0) = ret and
ret.getResult() = eq and ret.getResult() = eq and

View File

@@ -13,7 +13,7 @@
import semmle.code.java.Statement import semmle.code.java.Statement
/** A block without statements or comments. */ /** A block without statements or comments. */
private Block emptyBlock() { private BlockStmt emptyBlock() {
result.getNumStmt() = 0 and result.getNumStmt() = 0 and
result.getLocation().getNumberOfCommentLines() = 0 result.getLocation().getNumberOfCommentLines() = 0
} }
@@ -48,8 +48,8 @@ predicate blockParent(Stmt empty, string msg) {
or or
empty.getParent() instanceof LoopStmt and msg = "The body of a loop should not be empty." empty.getParent() instanceof LoopStmt and msg = "The body of a loop should not be empty."
or or
empty.getParent() instanceof Block and empty.getParent() instanceof BlockStmt and
empty instanceof Block and empty instanceof BlockStmt and
msg = "This block should not be empty." msg = "This block should not be empty."
) )
} }

View File

@@ -15,11 +15,11 @@ import java
/** /**
* A control structure for which the trailing body (the syntactically last part) * A control structure for which the trailing body (the syntactically last part)
* is not a `Block`. This is either an `IfStmt` or a `LoopStmt`, but not a * is not a `BlockStmt`. This is either an `IfStmt` or a `LoopStmt`, but not a
* `DoStmt`, since do-while statements don't have a trailing body. * `DoStmt`, since do-while statements don't have a trailing body.
*/ */
predicate unbracedTrailingBody(Stmt ctrlStructure, Stmt trailingBody) { predicate unbracedTrailingBody(Stmt ctrlStructure, Stmt trailingBody) {
not trailingBody instanceof Block and not trailingBody instanceof BlockStmt and
( (
exists(IfStmt c | c = ctrlStructure | exists(IfStmt c | c = ctrlStructure |
trailingBody = c.getElse() and not trailingBody instanceof IfStmt trailingBody = c.getElse() and not trailingBody instanceof IfStmt
@@ -33,15 +33,15 @@ predicate unbracedTrailingBody(Stmt ctrlStructure, Stmt trailingBody) {
/* /*
* The body of a `SwitchStmt` is a block, but it isn't represented explicitly * The body of a `SwitchStmt` is a block, but it isn't represented explicitly
* in the AST as a `Block`, so we have to take it into account directly in the * in the AST as a `BlockStmt`, so we have to take it into account directly in the
* following two predicates. * following two predicates.
*/ */
/** /**
* Two consecutive statements in a `Block` statement or `SwitchStmt`. * Two consecutive statements in a `BlockStmt` statement or `SwitchStmt`.
*/ */
Stmt nextInBlock(Stmt s) { Stmt nextInBlock(Stmt s) {
exists(Block b, int i | exists(BlockStmt b, int i |
b.getStmt(i) = s and b.getStmt(i) = s and
b.getStmt(i + 1) = result b.getStmt(i + 1) = result
) )
@@ -52,10 +52,10 @@ Stmt nextInBlock(Stmt s) {
) )
} }
/** The `Stmt.getParent()` relation restricted to not pass through `Block`s or `SwitchStmt`s. */ /** The `Stmt.getParent()` relation restricted to not pass through `BlockStmt`s or `SwitchStmt`s. */
Stmt nonBlockParent(Stmt s) { Stmt nonBlockParent(Stmt s) {
result = s.getParent() and result = s.getParent() and
not result instanceof Block and not result instanceof BlockStmt and
not result instanceof SwitchStmt not result instanceof SwitchStmt
} }
@@ -64,7 +64,7 @@ predicate ifElseIf(IfStmt s, IfStmt elseif) { s.getElse() = elseif }
/** /**
* The statement `body` is an unbraced trailing body of a control structure and * The statement `body` is an unbraced trailing body of a control structure and
* `succ` is the next statement in the surrounding `Block` (or `SwitchStmt`). * `succ` is the next statement in the surrounding `BlockStmt` (or `SwitchStmt`).
*/ */
predicate shouldOutdent( predicate shouldOutdent(
Stmt ctrl, Stmt body, Stmt succ, int bodycol, int succcol, int bodyline, int succline Stmt ctrl, Stmt body, Stmt succ, int bodycol, int succcol, int bodyline, int succline
@@ -79,7 +79,7 @@ predicate shouldOutdent(
/** /**
* The statement `body` is an unbraced trailing body of a control structure and * The statement `body` is an unbraced trailing body of a control structure and
* `succ` is the next statement in the surrounding `Block` (or `SwitchStmt`). * `succ` is the next statement in the surrounding `BlockStmt` (or `SwitchStmt`).
* The indentation of statement `succ` is suspect because it is indented * The indentation of statement `succ` is suspect because it is indented
* the same way as `body` and thus visually suggests to be part of the same * the same way as `body` and thus visually suggests to be part of the same
* syntactic scope as `body`. * syntactic scope as `body`.

View File

@@ -25,7 +25,7 @@ class ComparisonOrEqTestExpr extends Expr {
class Empty extends Stmt { class Empty extends Stmt {
Empty() { Empty() {
this instanceof EmptyStmt or this instanceof EmptyStmt or
this.(Block).getNumStmt() = 0 this.(BlockStmt).getNumStmt() = 0
} }
} }

View File

@@ -26,7 +26,7 @@ predicate skipParent(Stmt s) {
exists(Stmt parent | parent = s.getParent() | exists(Stmt parent | parent = s.getParent() |
s instanceof IfStmt and parent.(IfStmt).getElse() = s s instanceof IfStmt and parent.(IfStmt).getElse() = s
or or
parent instanceof Block parent instanceof BlockStmt
) )
} }

View File

@@ -44,7 +44,7 @@ class PointlessLoop extends WhileStmt {
getCondition().(BooleanLiteral).getBooleanValue() = true and getCondition().(BooleanLiteral).getBooleanValue() = true and
// The only `break` must be the last statement. // The only `break` must be the last statement.
forall(BreakStmt break | break.(JumpStmt).getTarget() = this | forall(BreakStmt break | break.(JumpStmt).getTarget() = this |
this.getStmt().(Block).getLastStmt() = break this.getStmt().(BlockStmt).getLastStmt() = break
) and ) and
// No `continue` statements. // No `continue` statements.
not exists(ContinueStmt continue | continue.(JumpStmt).getTarget() = this) not exists(ContinueStmt continue | continue.(JumpStmt).getTarget() = this)

View File

@@ -16,5 +16,5 @@ import java
from FinalizeMethod finalize from FinalizeMethod finalize
where where
finalize.fromSource() and finalize.fromSource() and
not exists(Stmt s | s.getEnclosingCallable() = finalize | not s instanceof Block) not exists(Stmt s | s.getEnclosingCallable() = finalize | not s instanceof BlockStmt)
select finalize, "Empty finalize method." select finalize, "Empty finalize method."

View File

@@ -14,14 +14,14 @@
import java import java
Block finallyBlock() { exists(TryStmt try | try.getFinally() = result) } BlockStmt finallyBlock() { exists(TryStmt try | try.getFinally() = result) }
Stmt statementIn(Block finally) { Stmt statementIn(BlockStmt finally) {
finallyBlock() = finally and finallyBlock() = finally and
result.getParent+() = finally result.getParent+() = finally
} }
predicate banned(Stmt s, Block finally) { predicate banned(Stmt s, BlockStmt finally) {
s = statementIn(finally) and s = statementIn(finally) and
( (
s instanceof ReturnStmt s instanceof ReturnStmt
@@ -32,6 +32,6 @@ predicate banned(Stmt s, Block finally) {
) )
} }
from Stmt s, Block finally from Stmt s, BlockStmt finally
where banned(s, finally) where banned(s, finally)
select s, "Leaving a finally-block with this statement can cause exceptions to silently disappear." select s, "Leaving a finally-block with this statement can cause exceptions to silently disappear."

View File

@@ -77,7 +77,7 @@ private predicate blockCoversStatement(int equivClass, int first, int last, Stmt
private Stmt statementInMethod(Method m) { private Stmt statementInMethod(Method m) {
result.getEnclosingCallable() = m and result.getEnclosingCallable() = m and
not result instanceof Block not result instanceof BlockStmt
} }
private predicate duplicateStatement(Method m1, Method m2, Stmt s1, Stmt s2) { private predicate duplicateStatement(Method m1, Method m2, Stmt s1, Stmt s2) {

View File

@@ -338,7 +338,7 @@ private module ControlFlowGraphImpl {
/** Holds if a call to `m` indicates that `m` is expected to return. */ /** Holds if a call to `m` indicates that `m` is expected to return. */
private predicate expectedReturn(EffectivelyNonVirtualMethod m) { private predicate expectedReturn(EffectivelyNonVirtualMethod m) {
exists(Stmt s, Block b | exists(Stmt s, BlockStmt b |
m.getAnAccess().getEnclosingStmt() = s and m.getAnAccess().getEnclosingStmt() = s and
b.getAStmt() = s and b.getAStmt() = s and
not b.getLastStmt() = s not b.getLastStmt() = s
@@ -352,7 +352,7 @@ private module ControlFlowGraphImpl {
result instanceof MethodExit result instanceof MethodExit
or or
not result.isOverridable() and not result.isOverridable() and
exists(Block body | exists(BlockStmt body |
body = result.getBody() and body = result.getBody() and
not exists(ReturnStmt ret | ret.getEnclosingCallable() = result) not exists(ReturnStmt ret | ret.getEnclosingCallable() = result)
| |
@@ -388,7 +388,7 @@ private module ControlFlowGraphImpl {
or or
result.(ExprStmt).getExpr() = nonReturningMethodAccess() result.(ExprStmt).getExpr() = nonReturningMethodAccess()
or or
result.(Block).getLastStmt() = nonReturningStmt() result.(BlockStmt).getLastStmt() = nonReturningStmt()
or or
exists(IfStmt ifstmt | ifstmt = result | exists(IfStmt ifstmt | ifstmt = result |
ifstmt.getThen() = nonReturningStmt() and ifstmt.getThen() = nonReturningStmt() and
@@ -450,7 +450,7 @@ private module ControlFlowGraphImpl {
or or
this instanceof SuperAccess this instanceof SuperAccess
or or
this.(Block).getNumStmt() = 0 this.(BlockStmt).getNumStmt() = 0
or or
this instanceof SwitchCase and not this.(SwitchCase).isRule() this instanceof SwitchCase and not this.(SwitchCase).isRule()
or or
@@ -723,7 +723,7 @@ private module ControlFlowGraphImpl {
or or
// The last statement in a block is any statement that does not complete normally, // The last statement in a block is any statement that does not complete normally,
// or the last statement. // or the last statement.
exists(Block blk | blk = n | exists(BlockStmt blk | blk = n |
last(blk.getAStmt(), last, completion) and completion != NormalCompletion() last(blk.getAStmt(), last, completion) and completion != NormalCompletion()
or or
last(blk.getStmt(blk.getNumStmt() - 1), last, completion) last(blk.getStmt(blk.getNumStmt() - 1), last, completion)
@@ -943,9 +943,9 @@ private module ControlFlowGraphImpl {
) )
or or
// Statements within a block execute sequentially. // Statements within a block execute sequentially.
result = first(n.(Block).getStmt(0)) and completion = NormalCompletion() result = first(n.(BlockStmt).getStmt(0)) and completion = NormalCompletion()
or or
exists(Block blk, int i | exists(BlockStmt blk, int i |
last(blk.getStmt(i), n, completion) and last(blk.getStmt(i), n, completion) and
completion = NormalCompletion() and completion = NormalCompletion() and
result = first(blk.getStmt(i + 1)) result = first(blk.getStmt(i + 1))

View File

@@ -1022,7 +1022,7 @@ class LambdaExpr extends FunctionalExpr, @lambdaexpr {
} }
/** Gets the body of this lambda expression, if it is a statement. */ /** Gets the body of this lambda expression, if it is a statement. */
Block getStmtBody() { hasStmtBody() and result = asMethod().getBody() } BlockStmt getStmtBody() { hasStmtBody() and result = asMethod().getBody() }
/** Gets a printable representation of this expression. */ /** Gets a printable representation of this expression. */
override string toString() { result = "...->..." } override string toString() { result = "...->..." }

View File

@@ -215,7 +215,7 @@ class Callable extends StmtParent, Member, @callable {
Call getAReference() { result.getCallee() = this } Call getAReference() { result.getCallee() = this }
/** Gets the body of this callable, if any. */ /** Gets the body of this callable, if any. */
Block getBody() { result.getParent() = this } BlockStmt getBody() { result.getParent() = this }
/** /**
* Gets the source declaration of this callable. * Gets the source declaration of this callable.

View File

@@ -469,7 +469,7 @@ private class PpWildcardTypeAccess extends PpAst, WildcardTypeAccess {
* Statements * Statements
*/ */
private class PpBlock extends PpAst, Block { private class PpBlock extends PpAst, BlockStmt {
override string getPart(int i) { override string getPart(int i) {
i = 0 and result = "{" i = 0 and result = "{"
or or
@@ -493,26 +493,26 @@ private class PpIfStmt extends PpAst, IfStmt {
or or
i = 2 and result = ")" i = 2 and result = ")"
or or
i = 3 and result = " " and this.getThen() instanceof Block i = 3 and result = " " and this.getThen() instanceof BlockStmt
or or
exists(this.getElse()) and exists(this.getElse()) and
( (
i = 5 and result = " " and this.getThen() instanceof Block i = 5 and result = " " and this.getThen() instanceof BlockStmt
or or
i = 6 and result = "else" i = 6 and result = "else"
or or
i = 7 and result = " " and this.getElse() instanceof Block i = 7 and result = " " and this.getElse() instanceof BlockStmt
) )
} }
override predicate newline(int i) { override predicate newline(int i) {
i = 3 and not this.getThen() instanceof Block i = 3 and not this.getThen() instanceof BlockStmt
or or
exists(this.getElse()) and exists(this.getElse()) and
( (
i = 5 and not this.getThen() instanceof Block i = 5 and not this.getThen() instanceof BlockStmt
or or
i = 7 and not this.getElse() instanceof Block i = 7 and not this.getElse() instanceof BlockStmt
) )
} }
@@ -525,9 +525,9 @@ private class PpIfStmt extends PpAst, IfStmt {
} }
override predicate indents(int i) { override predicate indents(int i) {
i = 4 and not this.getThen() instanceof Block i = 4 and not this.getThen() instanceof BlockStmt
or or
i = 8 and not this.getElse() instanceof Block i = 8 and not this.getElse() instanceof BlockStmt
} }
} }
@@ -549,7 +549,7 @@ private class PpForStmt extends PpAst, ForStmt {
or or
i = 1 + lastUpdateIndex() and result = ")" i = 1 + lastUpdateIndex() and result = ")"
or or
i = 2 + lastUpdateIndex() and result = " " and this.getStmt() instanceof Block i = 2 + lastUpdateIndex() and result = " " and this.getStmt() instanceof BlockStmt
} }
private int lastInitIndex() { result = 3 + 2 * max(int j | exists(this.getInit(j))) } private int lastInitIndex() { result = 3 + 2 * max(int j | exists(this.getInit(j))) }
@@ -559,7 +559,7 @@ private class PpForStmt extends PpAst, ForStmt {
} }
override predicate newline(int i) { override predicate newline(int i) {
i = 2 + lastUpdateIndex() and not this.getStmt() instanceof Block i = 2 + lastUpdateIndex() and not this.getStmt() instanceof BlockStmt
} }
override PpAst getChild(int i) { override PpAst getChild(int i) {
@@ -575,7 +575,7 @@ private class PpForStmt extends PpAst, ForStmt {
} }
override predicate indents(int i) { override predicate indents(int i) {
i = 3 + lastUpdateIndex() and not this.getStmt() instanceof Block i = 3 + lastUpdateIndex() and not this.getStmt() instanceof BlockStmt
} }
} }
@@ -588,7 +588,7 @@ private class PpEnhancedForStmt extends PpAst, EnhancedForStmt {
i = 4 and result = " : " i = 4 and result = " : "
or or
i = 6 and i = 6 and
if this.getStmt() instanceof Block then result = ") " else result = ")" if this.getStmt() instanceof BlockStmt then result = ") " else result = ")"
} }
override PpAst getChild(int i) { override PpAst getChild(int i) {
@@ -601,7 +601,7 @@ private class PpEnhancedForStmt extends PpAst, EnhancedForStmt {
i = 7 and result = this.getStmt() i = 7 and result = this.getStmt()
} }
override predicate indents(int i) { i = 7 and not this.getStmt() instanceof Block } override predicate indents(int i) { i = 7 and not this.getStmt() instanceof BlockStmt }
} }
private class PpWhileStmt extends PpAst, WhileStmt { private class PpWhileStmt extends PpAst, WhileStmt {
@@ -610,10 +610,10 @@ private class PpWhileStmt extends PpAst, WhileStmt {
or or
i = 2 and result = ")" i = 2 and result = ")"
or or
i = 3 and result = " " and this.getStmt() instanceof Block i = 3 and result = " " and this.getStmt() instanceof BlockStmt
} }
override predicate newline(int i) { i = 3 and not this.getStmt() instanceof Block } override predicate newline(int i) { i = 3 and not this.getStmt() instanceof BlockStmt }
override PpAst getChild(int i) { override PpAst getChild(int i) {
i = 1 and result = this.getCondition() i = 1 and result = this.getCondition()
@@ -621,21 +621,21 @@ private class PpWhileStmt extends PpAst, WhileStmt {
i = 4 and result = this.getStmt() i = 4 and result = this.getStmt()
} }
override predicate indents(int i) { i = 4 and not this.getStmt() instanceof Block } override predicate indents(int i) { i = 4 and not this.getStmt() instanceof BlockStmt }
} }
private class PpDoStmt extends PpAst, DoStmt { private class PpDoStmt extends PpAst, DoStmt {
override string getPart(int i) { override string getPart(int i) {
i = 0 and result = "do" i = 0 and result = "do"
or or
i in [1, 3] and result = " " and this.getStmt() instanceof Block i in [1, 3] and result = " " and this.getStmt() instanceof BlockStmt
or or
i = 4 and result = "while (" i = 4 and result = "while ("
or or
i = 6 and result = ");" i = 6 and result = ");"
} }
override predicate newline(int i) { i in [1, 3] and not this.getStmt() instanceof Block } override predicate newline(int i) { i in [1, 3] and not this.getStmt() instanceof BlockStmt }
override PpAst getChild(int i) { override PpAst getChild(int i) {
i = 2 and result = this.getStmt() i = 2 and result = this.getStmt()
@@ -643,7 +643,7 @@ private class PpDoStmt extends PpAst, DoStmt {
i = 5 and result = this.getCondition() i = 5 and result = this.getCondition()
} }
override predicate indents(int i) { i = 2 and not this.getStmt() instanceof Block } override predicate indents(int i) { i = 2 and not this.getStmt() instanceof BlockStmt }
} }
private class PpTryStmt extends PpAst, TryStmt { private class PpTryStmt extends PpAst, TryStmt {

View File

@@ -60,7 +60,7 @@ class Stmt extends StmtParent, ExprParent, @stmt {
class StmtParent extends @stmtparent, Top { } class StmtParent extends @stmtparent, Top { }
/** A block of statements. */ /** A block of statements. */
class Block extends Stmt, @block { class BlockStmt extends Stmt, @block {
/** Gets a statement that is an immediate child of this block. */ /** Gets a statement that is an immediate child of this block. */
Stmt getAStmt() { result.getParent() = this } Stmt getAStmt() { result.getParent() = this }
@@ -77,11 +77,17 @@ class Block extends Stmt, @block {
override string pp() { result = "{ ... }" } override string pp() { result = "{ ... }" }
/** This statement's Halstead ID (used to compute Halstead metrics). */ /** This statement's Halstead ID (used to compute Halstead metrics). */
override string getHalsteadID() { result = "Block" } override string getHalsteadID() { result = "BlockStmt" }
} }
/**
* DEPRECATED: This is now called `BlockStmt` to avoid confusion with
* `BasicBlock`.
*/
deprecated class Block = BlockStmt;
/** A block with only a single statement. */ /** A block with only a single statement. */
class SingletonBlock extends Block { class SingletonBlock extends BlockStmt {
SingletonBlock() { this.getNumStmt() = 1 } SingletonBlock() { this.getNumStmt() = 1 }
/** Gets the single statement in this block. */ /** Gets the single statement in this block. */
@@ -304,7 +310,7 @@ class TryStmt extends Stmt, @trystmt {
} }
/** Gets the `finally` block, if any. */ /** Gets the `finally` block, if any. */
Block getFinally() { result.isNthChildOf(this, -2) } BlockStmt getFinally() { result.isNthChildOf(this, -2) }
/** Gets a resource variable declaration, if any. */ /** Gets a resource variable declaration, if any. */
LocalVariableDeclStmt getAResourceDecl() { result.getParent() = this and result.getIndex() <= -3 } LocalVariableDeclStmt getAResourceDecl() { result.getParent() = this and result.getIndex() <= -3 }
@@ -348,7 +354,7 @@ class TryStmt extends Stmt, @trystmt {
/** A `catch` clause in a `try` statement. */ /** A `catch` clause in a `try` statement. */
class CatchClause extends Stmt, @catchclause { class CatchClause extends Stmt, @catchclause {
/** Gets the block of this `catch` clause. */ /** Gets the block of this `catch` clause. */
Block getBlock() { result.getParent() = this } BlockStmt getBlock() { result.getParent() = this }
/** Gets the `try` statement in which this `catch` clause occurs. */ /** Gets the `try` statement in which this `catch` clause occurs. */
TryStmt getTry() { this = result.getACatchClause() } TryStmt getTry() { this = result.getACatchClause() }

View File

@@ -14,7 +14,7 @@ private predicate flowEntry(Stmt entry) {
exists(Callable c | entry = c.getBody()) exists(Callable c | entry = c.getBody())
or or
// This disjunct is technically superfluous, but safeguards against extractor problems. // This disjunct is technically superfluous, but safeguards against extractor problems.
entry instanceof Block and entry instanceof BlockStmt and
not exists(entry.getEnclosingCallable()) and not exists(entry.getEnclosingCallable()) and
not entry.getParent() instanceof Stmt not entry.getParent() instanceof Stmt
} }

View File

@@ -293,7 +293,7 @@ private predicate impossibleEdge(BasicBlock bb1, BasicBlock bb2) {
/** A control flow edge that leaves a finally-block. */ /** A control flow edge that leaves a finally-block. */
private predicate leavingFinally(BasicBlock bb1, BasicBlock bb2, boolean normaledge) { private predicate leavingFinally(BasicBlock bb1, BasicBlock bb2, boolean normaledge) {
exists(TryStmt try, Block finally | exists(TryStmt try, BlockStmt finally |
try.getFinally() = finally and try.getFinally() = finally and
bb1.getABBSuccessor() = bb2 and bb1.getABBSuccessor() = bb2 and
bb1.getEnclosingStmt().getEnclosingStmt*() = finally and bb1.getEnclosingStmt().getEnclosingStmt*() = finally and

View File

@@ -93,8 +93,8 @@ class SuppressedConstructor extends Constructor {
not isDefaultConstructor() and not isDefaultConstructor() and
// Verify that there is only one statement, which is the `super()` call. This exists // Verify that there is only one statement, which is the `super()` call. This exists
// even for empty constructors. // even for empty constructors.
getBody().(Block).getNumStmt() = 1 and getBody().(BlockStmt).getNumStmt() = 1 and
getBody().(Block).getAStmt().(SuperConstructorInvocationStmt).getNumArgument() = 0 and getBody().(BlockStmt).getAStmt().(SuperConstructorInvocationStmt).getNumArgument() = 0 and
// A constructor that is called is not acting to suppress the default constructor. We permit // A constructor that is called is not acting to suppress the default constructor. We permit
// calls from suppressed and default constructors - in both cases, they can only come from // calls from suppressed and default constructors - in both cases, they can only come from
// sub-class constructors. // sub-class constructors.

View File

@@ -1,7 +1,7 @@
import java import java
import semmle.code.java.controlflow.Dominance import semmle.code.java.controlflow.Dominance
from IfStmt i, Block b from IfStmt i, BlockStmt b
where where
b = i.getThen() and b = i.getThen() and
dominates(i.getThen(), b) and dominates(i.getThen(), b) and

View File

@@ -13,7 +13,10 @@ class ArrayAccess = IndexExpr;
class AssignOp = CompoundAssignExpr; class AssignOp = CompoundAssignExpr;
class Block = BlockStmt; /**
* DEPRECATED: The name `BlockStmt` is now preferred in all languages.
*/
deprecated class Block = BlockStmt;
class BoolLiteral = BooleanLiteral; class BoolLiteral = BooleanLiteral;