QL语言参考-8公式
公式Formulas
官方文档
https://codeql.github.com/docs/ql-language-reference/formulas/
比较
<expression> <operator> <expression>
顺序运算符
\>, >=, <, <=
相等运算符
=, !=
示例
1 != [1..2] 成立,因为 1!=2
1 = [1..2] 成立,因为 1=1
not 1 = [1..2] 不成立
1 != none 不成立
1 = none 不成立
not 1=none 成立
类型检查
<expression> instanceof <type>
范围检查
语法
<expression> in <range>
示例
predicate getFoo(int i){
i in [1..9]
}
括号公式
用来增加可读性
量化公式
显式量词
exists
forall
forex
隐式量词
dot's care expression
逻辑连接词
默认优先级:not、if then else、and、or、implies
not
from File f
where not f.getFileType().isHtml()
select f
if ... then ... else
string visibility(Class c){
if c.isPublic()
then result = "public"
else result = "private"
}
and
from File f
where f.getExtension() = "js" and
f.getNumberOfLinesOfCode() < 200
select f
or
class OneTwoThree extends int {
OneTwoThree() {
this = 1 or this = 2 or this = 3
}
}
implies
A implies B
<=>
(not A) or B
优先级