Skip to content

Commit 31fc0f2

Browse files
committed
Python: Moves library and queries over to the new predicates, removes old ones
1 parent 7930037 commit 31fc0f2

File tree

8 files changed

+23
-23
lines changed

8 files changed

+23
-23
lines changed

python/ql/src/Expressions/Formatting/AdvancedFormatting.qll

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import python
2+
private import semmle.python.types.Builtins
23

34

45
library class PossibleAdvancedFormatString extends StrConst {
@@ -104,39 +105,38 @@ private predicate brace_pair(PossibleAdvancedFormatString fmt, int start, int en
104105
)
105106
}
106107

107-
private predicate advanced_format_call_objectapi(Call format_expr, PossibleAdvancedFormatString fmt, int args) {
108+
private predicate advanced_format_call(Call format_expr, PossibleAdvancedFormatString fmt, int args) {
108109
exists(CallNode call |
109110
call = format_expr.getAFlowNode() |
110-
call.getFunction().refersTo(Object::builtin("format")) and call.getArg(0).refersTo(_, fmt.getAFlowNode()) and
111+
call.getFunction().pointsTo(Value::named("format")) and call.getArg(0).pointsTo(_, fmt.getAFlowNode()) and
111112
args = count(format_expr.getAnArg()) - 1
112113
or
113-
call.getFunction().(AttrNode).getObject("format").refersTo(_, fmt.getAFlowNode()) and
114+
call.getFunction().(AttrNode).getObject("format").pointsTo(_, fmt.getAFlowNode()) and
114115
args = count(format_expr.getAnArg())
115116
)
116117
}
117118

118-
class AdvancedFormatString_objectapi extends PossibleAdvancedFormatString {
119+
class AdvancedFormatString extends PossibleAdvancedFormatString {
119120

120-
AdvancedFormatString_objectapi() {
121-
advanced_format_call_objectapi(_, this, _)
121+
AdvancedFormatString() {
122+
advanced_format_call(_, this, _)
122123
}
123124

124125
}
125126

126-
class AdvancedFormattingCall_objectapi extends Call {
127+
class AdvancedFormattingCall extends Call {
127128

128-
AdvancedFormattingCall_objectapi() {
129-
advanced_format_call_objectapi(this, _, _)
129+
AdvancedFormattingCall() {
130+
advanced_format_call(this, _, _)
130131
}
131132

132133
/** Count of the arguments actually provided */
133134
int providedArgCount() {
134-
advanced_format_call_objectapi(this, _, result)
135+
advanced_format_call(this, _, result)
135136
}
136137

137-
AdvancedFormatString_objectapi getAFormat() {
138-
advanced_format_call_objectapi(this, result, _)
138+
AdvancedFormatString getAFormat() {
139+
advanced_format_call(this, result, _)
139140
}
140141

141142
}
142-

python/ql/src/Expressions/Formatting/MixedExplicitImplicitIn3101Format.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
import python
1414
import AdvancedFormatting
1515

16-
from AdvancedFormattingCall_objectapi call, AdvancedFormatString_objectapi fmt
16+
from AdvancedFormattingCall call, AdvancedFormatString fmt
1717
where call.getAFormat() = fmt and fmt.isImplicitlyNumbered() and fmt.isExplicitlyNumbered()
1818
select fmt, "Formatting string mixes implicitly and explicitly numbered fields."

python/ql/src/Expressions/Formatting/UnusedArgumentIn3101Format.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ import python
1616
import python
1717
import AdvancedFormatting
1818

19-
int field_count(AdvancedFormatString_objectapi fmt) { result = max(fmt.getFieldNumber(_, _)) + 1 }
19+
int field_count(AdvancedFormatString fmt) { result = max(fmt.getFieldNumber(_, _)) + 1 }
2020

21-
from AdvancedFormattingCall_objectapi call, AdvancedFormatString_objectapi fmt, int arg_count, int max_field
21+
from AdvancedFormattingCall call, AdvancedFormatString fmt, int arg_count, int max_field
2222
where arg_count = call.providedArgCount() and max_field = field_count(fmt) and
2323
call.getAFormat() = fmt and not exists(call.getStarargs()) and
24-
forall(AdvancedFormatString_objectapi other | other = call.getAFormat() | field_count(other) < arg_count)
24+
forall(AdvancedFormatString other | other = call.getAFormat() | field_count(other) < arg_count)
2525
select call, "Too many arguments for string format. Format $@ requires only " + max_field + ", but " +
2626
arg_count.toString() + " are provided.", fmt, "\"" + fmt.getText() + "\""

python/ql/src/Expressions/Formatting/UnusedNamedArgumentIn3101Format.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
import python
1414
import AdvancedFormatting
1515

16-
from AdvancedFormattingCall_objectapi call, AdvancedFormatString_objectapi fmt, string name, string fmt_repr
16+
from AdvancedFormattingCall call, AdvancedFormatString fmt, string name, string fmt_repr
1717
where call.getAFormat() = fmt and
1818
name = call.getAKeyword().getArg() and
19-
forall(AdvancedFormatString_objectapi format | format = call.getAFormat() | not format.getFieldName(_, _) = name)
19+
forall(AdvancedFormatString format | format = call.getAFormat() | not format.getFieldName(_, _) = name)
2020
and not exists(call.getKwargs()) and
2121
(strictcount(call.getAFormat()) = 1 and fmt_repr = "format \"" + fmt.getText() + "\""
2222
or

python/ql/src/Expressions/Formatting/WrongNameInArgumentsFor3101Format.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import python
1515
import AdvancedFormatting
1616

17-
from AdvancedFormattingCall_objectapi call, AdvancedFormatString_objectapi fmt, string name
17+
from AdvancedFormattingCall call, AdvancedFormatString fmt, string name
1818
where call.getAFormat() = fmt and
1919
not name = call.getAKeyword().getArg() and
2020
fmt.getFieldName(_, _) = name

python/ql/src/Expressions/Formatting/WrongNumberArgumentsFor3101Format.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import python
1515
import AdvancedFormatting
1616

17-
from AdvancedFormattingCall_objectapi call, AdvancedFormatString_objectapi fmt,
17+
from AdvancedFormattingCall call, AdvancedFormatString fmt,
1818
int arg_count, int max_field, string provided
1919
where arg_count = call.providedArgCount() and max_field = max(fmt.getFieldNumber(_, _)) and
2020
call.getAFormat() = fmt and not exists(call.getStarargs()) and arg_count <= max_field and

python/ql/test/library-tests/formatting/FormatArguments.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import python
33
import Expressions.Formatting.AdvancedFormatting
44

5-
from AdvancedFormatString_objectapi a, string name, int start, int end
5+
from AdvancedFormatString a, string name, int start, int end
66
where
77
name = "'" + a.getFieldName(start, end) + "'"
88
or

python/ql/test/library-tests/formatting/FormatFields.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
import python
33
import Expressions.Formatting.AdvancedFormatting
44

5-
from AdvancedFormatString_objectapi a, int start, int end
5+
from AdvancedFormatString a, int start, int end
66
select a.getLocation().getStartLine(), a.getText(), start, end, a.getField(start, end)

0 commit comments

Comments
 (0)