Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2b94bb9

Browse files
committed
C++: Use the word "rank" to denote a rank
Previously, the word "position" was used ambiguously in this library.
1 parent 17ee3f5 commit 2b94bb9

2 files changed

Lines changed: 20 additions & 22 deletions

File tree

cpp/ql/src/semmle/code/cpp/controlflow/SubBasicBlocks.qll

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class SubBasicBlock extends ControlFlowNodeBase {
5757
* predecessors.
5858
*/
5959
predicate firstInBB() {
60-
exists(BasicBlock bb | this.getPosInBasicBlock(bb) = 0)
60+
exists(BasicBlock bb | this.getRankInBasicBlock(bb) = 1)
6161
}
6262

6363
/**
@@ -66,19 +66,18 @@ class SubBasicBlock extends ControlFlowNodeBase {
6666
*/
6767
predicate lastInBB() {
6868
exists(BasicBlock bb |
69-
this.getPosInBasicBlock(bb) = countSubBasicBlocksInBasicBlock(bb) - 1
69+
this.getRankInBasicBlock(bb) = countSubBasicBlocksInBasicBlock(bb)
7070
)
7171
}
7272

7373
/**
74-
* Gets the position of this `SubBasicBlock` in its containing basic block
75-
* `bb`, where `bb` is equal to `getBasicBlock()`.
74+
* Gets the rank of this `SubBasicBlock` among the other `SubBasicBlock`s in
75+
* its containing basic block `bb`, where `bb` is equal to `getBasicBlock()`.
7676
*/
77-
int getPosInBasicBlock(BasicBlock bb) {
78-
exists(int thisIndexInBB, int rnk |
77+
int getRankInBasicBlock(BasicBlock bb) {
78+
exists(int thisIndexInBB |
7979
thisIndexInBB = this.getIndexInBasicBlock(bb) and
80-
thisIndexInBB = rank[rnk](int i | i = any(SubBasicBlock n).getIndexInBasicBlock(bb)) and
81-
result = rnk - 1
80+
thisIndexInBB = rank[result](int i | i = any(SubBasicBlock n).getIndexInBasicBlock(bb))
8281
)
8382
}
8483

@@ -93,7 +92,7 @@ class SubBasicBlock extends ControlFlowNodeBase {
9392
result = this.getBasicBlock().getASuccessor()
9493
or
9594
exists(BasicBlock bb |
96-
result.getPosInBasicBlock(bb) = this.getPosInBasicBlock(bb) + 1
95+
result.getRankInBasicBlock(bb) = this.getRankInBasicBlock(bb) + 1
9796
)
9897
}
9998

@@ -168,9 +167,9 @@ class SubBasicBlock extends ControlFlowNodeBase {
168167
)
169168
or
170169
exists(SubBasicBlock succ, int succPos, int thisRank, int succRank |
171-
thisRank = this.getPosInBasicBlock(bb) and
170+
thisRank = this.getRankInBasicBlock(bb) and
172171
succRank = thisRank + 1 and
173-
succRank = succ.getPosInBasicBlock(bb) and
172+
succRank = succ.getRankInBasicBlock(bb) and
174173
bb.getNode(succPos) = succ and
175174
result = succPos - thisPos
176175
)

cpp/ql/src/semmle/code/cpp/dataflow/internal/SubBasicBlocks.qll

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class SubBasicBlock extends ControlFlowNodeBase {
5757
* predecessors.
5858
*/
5959
predicate firstInBB() {
60-
exists(BasicBlock bb | this.getPosInBasicBlock(bb) = 0)
60+
exists(BasicBlock bb | this.getRankInBasicBlock(bb) = 1)
6161
}
6262

6363
/**
@@ -66,19 +66,18 @@ class SubBasicBlock extends ControlFlowNodeBase {
6666
*/
6767
predicate lastInBB() {
6868
exists(BasicBlock bb |
69-
this.getPosInBasicBlock(bb) = countSubBasicBlocksInBasicBlock(bb) - 1
69+
this.getRankInBasicBlock(bb) = countSubBasicBlocksInBasicBlock(bb)
7070
)
7171
}
7272

7373
/**
74-
* Gets the position of this `SubBasicBlock` in its containing basic block
75-
* `bb`, where `bb` is equal to `getBasicBlock()`.
74+
* Gets the rank of this `SubBasicBlock` among the other `SubBasicBlock`s in
75+
* its containing basic block `bb`, where `bb` is equal to `getBasicBlock()`.
7676
*/
77-
int getPosInBasicBlock(BasicBlock bb) {
78-
exists(int thisIndexInBB, int rnk |
77+
int getRankInBasicBlock(BasicBlock bb) {
78+
exists(int thisIndexInBB |
7979
thisIndexInBB = this.getIndexInBasicBlock(bb) and
80-
thisIndexInBB = rank[rnk](int i | i = any(SubBasicBlock n).getIndexInBasicBlock(bb)) and
81-
result = rnk - 1
80+
thisIndexInBB = rank[result](int i | i = any(SubBasicBlock n).getIndexInBasicBlock(bb))
8281
)
8382
}
8483

@@ -93,7 +92,7 @@ class SubBasicBlock extends ControlFlowNodeBase {
9392
result = this.getBasicBlock().getASuccessor()
9493
or
9594
exists(BasicBlock bb |
96-
result.getPosInBasicBlock(bb) = this.getPosInBasicBlock(bb) + 1
95+
result.getRankInBasicBlock(bb) = this.getRankInBasicBlock(bb) + 1
9796
)
9897
}
9998

@@ -168,9 +167,9 @@ class SubBasicBlock extends ControlFlowNodeBase {
168167
)
169168
or
170169
exists(SubBasicBlock succ, int succPos, int thisRank, int succRank |
171-
thisRank = this.getPosInBasicBlock(bb) and
170+
thisRank = this.getRankInBasicBlock(bb) and
172171
succRank = thisRank + 1 and
173-
succRank = succ.getPosInBasicBlock(bb) and
172+
succRank = succ.getRankInBasicBlock(bb) and
174173
bb.getNode(succPos) = succ and
175174
result = succPos - thisPos
176175
)

0 commit comments

Comments
 (0)