Skip to content

Commit e75448e

Browse files
committed
remove redundant inline casts
1 parent d425b37 commit e75448e

File tree

38 files changed

+60
-79
lines changed

38 files changed

+60
-79
lines changed

cpp/ql/lib/semmle/code/cpp/commons/Dependency.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,17 +275,17 @@ private predicate dependsOnDeclarationEntry(Element src, DeclarationEntry dest)
275275
dependsOnTransitive(src, mid) and
276276
not mid instanceof Type and
277277
not mid instanceof EnumConstant and
278-
getDeclarationEntries(mid, dest.(DeclarationEntry)) and
278+
getDeclarationEntries(mid, dest) and
279279
not dest instanceof TypeDeclarationEntry
280280
)
281281
or
282282
exists(Declaration mid |
283283
// dependency from a Type / Variable / Function use -> any (visible) definition
284284
dependsOnTransitive(src, mid) and
285285
not mid instanceof EnumConstant and
286-
getDeclarationEntries(mid, dest.(DeclarationEntry)) and
286+
getDeclarationEntries(mid, dest) and
287287
// must be definition
288-
dest.(DeclarationEntry).isDefinition()
288+
dest.isDefinition()
289289
)
290290
}
291291

cpp/ql/lib/semmle/code/cpp/commons/Printf.qll

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,7 @@ class FormattingFunctionCall extends Expr {
175175
/**
176176
* Gets the index at which the format string occurs in the argument list.
177177
*/
178-
int getFormatParameterIndex() {
179-
result = this.getTarget().(FormattingFunction).getFormatParameterIndex()
180-
}
178+
int getFormatParameterIndex() { result = this.getTarget().getFormatParameterIndex() }
181179

182180
/**
183181
* Gets the format expression used in this call.
@@ -191,7 +189,7 @@ class FormattingFunctionCall extends Expr {
191189
exists(int i |
192190
result = this.getArgument(i) and
193191
n >= 0 and
194-
n = i - this.getTarget().(FormattingFunction).getFirstFormatArgumentIndex()
192+
n = i - this.getTarget().getFirstFormatArgumentIndex()
195193
)
196194
}
197195

@@ -251,7 +249,7 @@ class FormattingFunctionCall extends Expr {
251249
int getNumFormatArgument() {
252250
result = count(this.getFormatArgument(_)) and
253251
// format arguments must be known
254-
exists(this.getTarget().(FormattingFunction).getFirstFormatArgumentIndex())
252+
exists(this.getTarget().getFirstFormatArgumentIndex())
255253
}
256254

257255
/**
@@ -289,35 +287,27 @@ class FormatLiteral extends Literal {
289287
* a `char *` (either way, `%S` will have the opposite meaning).
290288
* DEPRECATED: Use getDefaultCharType() instead.
291289
*/
292-
deprecated predicate isWideCharDefault() {
293-
this.getUse().getTarget().(FormattingFunction).isWideCharDefault()
294-
}
290+
deprecated predicate isWideCharDefault() { this.getUse().getTarget().isWideCharDefault() }
295291

296292
/**
297293
* Gets the default character type expected for `%s` by this format literal. Typically
298294
* `char` or `wchar_t`.
299295
*/
300-
Type getDefaultCharType() {
301-
result = this.getUse().getTarget().(FormattingFunction).getDefaultCharType()
302-
}
296+
Type getDefaultCharType() { result = this.getUse().getTarget().getDefaultCharType() }
303297

304298
/**
305299
* Gets the non-default character type expected for `%S` by this format literal. Typically
306300
* `wchar_t` or `char`. On some snapshots there may be multiple results where we can't tell
307301
* which is correct for a particular function.
308302
*/
309-
Type getNonDefaultCharType() {
310-
result = this.getUse().getTarget().(FormattingFunction).getNonDefaultCharType()
311-
}
303+
Type getNonDefaultCharType() { result = this.getUse().getTarget().getNonDefaultCharType() }
312304

313305
/**
314306
* Gets the wide character type for this format literal. This is usually `wchar_t`. On some
315307
* snapshots there may be multiple results where we can't tell which is correct for a
316308
* particular function.
317309
*/
318-
Type getWideCharType() {
319-
result = this.getUse().getTarget().(FormattingFunction).getWideCharType()
320-
}
310+
Type getWideCharType() { result = this.getUse().getTarget().getWideCharType() }
321311

322312
/**
323313
* Holds if this `FormatLiteral` is in a context that supports
@@ -896,7 +886,7 @@ class FormatLiteral extends Literal {
896886
exists(string len, string conv |
897887
this.parseConvSpec(n, _, _, _, _, _, len, conv) and
898888
(len != "l" and len != "w" and len != "h") and
899-
this.getUse().getTarget().(FormattingFunction).getFormatCharType().getSize() > 1 and // wide function
889+
this.getUse().getTarget().getFormatCharType().getSize() > 1 and // wide function
900890
(
901891
conv = "c" and
902892
result = this.getNonDefaultCharType()

cpp/ql/lib/semmle/code/cpp/controlflow/internal/CFG.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ private class PostOrderInitializer extends Initializer {
231231
or
232232
this.getDeclaration() = for.getRangeVariable()
233233
or
234-
this.getDeclaration() = for.getBeginEndDeclaration().(DeclStmt).getADeclaration()
234+
this.getDeclaration() = for.getBeginEndDeclaration().getADeclaration()
235235
)
236236
}
237237
}
@@ -1143,7 +1143,7 @@ private class ExceptionSource extends Node {
11431143
this.reachesParent(mid) and
11441144
not mid = any(TryStmt try).getStmt() and
11451145
not mid = any(MicrosoftTryStmt try).getStmt() and
1146-
parent = mid.(Node).getParentNode()
1146+
parent = mid.getParentNode()
11471147
)
11481148
}
11491149

cpp/ql/lib/semmle/code/cpp/internal/AddressConstantExpression.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ private predicate addressConstantVariable(Variable v) {
3131
private predicate constantAddressLValue(Expr lvalue) {
3232
lvalue.(VariableAccess).getTarget() =
3333
any(Variable v |
34-
v.(Variable).isStatic()
34+
v.isStatic()
3535
or
3636
v instanceof GlobalOrNamespaceVariable
3737
)

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowPrivate.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ private predicate fieldStoreStepNoChi(Node node1, FieldContent f, PostUpdateNode
188188
exists(StoreInstruction store, Class c |
189189
store = node2.asInstruction() and
190190
store.getSourceValueOperand() = node1.asOperand() and
191-
getWrittenField(store, f.(FieldContent).getAField(), c) and
191+
getWrittenField(store, f.getAField(), c) and
192192
f.hasOffset(c, _, _)
193193
)
194194
}

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedExpr.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,7 @@ abstract class TranslatedConversion extends TranslatedNonConstantExpr {
10321032

10331033
final override TranslatedElement getChild(int id) { id = 0 and result = this.getOperand() }
10341034

1035-
final TranslatedExpr getOperand() { result = getTranslatedExpr(expr.(Conversion).getExpr()) }
1035+
final TranslatedExpr getOperand() { result = getTranslatedExpr(expr.getExpr()) }
10361036
}
10371037

10381038
/**

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedStmt.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,7 @@ class TranslatedDeclStmt extends TranslatedStmt {
103103
class TranslatedExprStmt extends TranslatedStmt {
104104
override ExprStmt stmt;
105105

106-
TranslatedExpr getExpr() {
107-
result = getTranslatedExpr(stmt.(ExprStmt).getExpr().getFullyConverted())
108-
}
106+
TranslatedExpr getExpr() { result = getTranslatedExpr(stmt.getExpr().getFullyConverted()) }
109107

110108
override TranslatedElement getChild(int id) { id = 0 and result = getExpr() }
111109

cpp/ql/lib/semmle/code/cpp/security/FileWrite.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,6 @@ private predicate fileWriteWithConvChar(FormattingFunctionCall ffc, Expr source,
173173
source = ffc.getFormatArgument(n)
174174
|
175175
exists(f.getOutputParameterIndex(true)) and
176-
conv = ffc.(FormattingFunctionCall).getFormat().(FormatLiteral).getConversionChar(n)
176+
conv = ffc.getFormat().(FormatLiteral).getConversionChar(n)
177177
)
178178
}

cpp/ql/lib/semmle/code/cpp/valuenumbering/HashCons.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ private predicate mk_HasAlloc(HashCons hc, NewOrNewArrayExpr new) {
589589
}
590590

591591
private predicate mk_HasExtent(HashCons hc, NewArrayExpr new) {
592-
hc = hashCons(new.(NewArrayExpr).getExtent().getFullyConverted())
592+
hc = hashCons(new.getExtent().getFullyConverted())
593593
}
594594

595595
private predicate analyzableNewExpr(NewExpr new) {
@@ -619,7 +619,7 @@ private predicate analyzableNewArrayExpr(NewArrayExpr new) {
619619
strictcount(new.getAllocatedType().getUnspecifiedType()) = 1 and
620620
count(new.getAllocatorCall().getFullyConverted()) <= 1 and
621621
count(new.getInitializer().getFullyConverted()) <= 1 and
622-
count(new.(NewArrayExpr).getExtent().getFullyConverted()) <= 1
622+
count(new.getExtent().getFullyConverted()) <= 1
623623
}
624624

625625
private predicate mk_NewArrayExpr(

cpp/ql/src/Best Practices/Likely Errors/EmptyBlock.ql

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,8 @@ class BlockOrNonChild extends Element {
8181
predicate emptyBlockContainsNonchild(BlockStmt b) {
8282
emptyBlock(_, b) and
8383
exists(BlockOrNonChild c, AffectedFile file |
84-
c.(BlockOrNonChild).getStartRankIn(file) = 1 + b.(BlockOrNonChild).getStartRankIn(file) and
85-
c.(BlockOrNonChild).getNonContiguousEndRankIn(file) <
86-
b.(BlockOrNonChild).getNonContiguousEndRankIn(file)
84+
c.getStartRankIn(file) = 1 + b.(BlockOrNonChild).getStartRankIn(file) and
85+
c.getNonContiguousEndRankIn(file) < b.(BlockOrNonChild).getNonContiguousEndRankIn(file)
8786
)
8887
}
8988

0 commit comments

Comments
 (0)