官方文档
https://codeql.github.com/docs/ql-language-reference/expressions/
1、变量引用
2、常量
Boolean、Integer、Float、String
Date类型需要使用toDate谓词转换
"2000-01-01 00:00:01".toDate()
3、括号表达式
4、范围
大于等于N,小于等于M
[N..M]
5、常量表达式
给集合指定具体的数值
[N1, N2, N3, N4, N5]
6、超级表达式
class A extends int {
A() { this = 1 }
int getANumber() { result = 2 }
}
class B extends int {
B() { this = 1 }
int getANumber() { result = 3 }
}
class C extends A, B {
// Need to define `int getANumber()`; otherwise it would be ambiguous
int getANumber() {
result = B.super.getANumber()
}
}
from C c
select c, c.getANumber()
7、调用含返回值的谓词
8、聚合表达式(Aggregations)
聚合在信息科学中是指对有关的数据进行内容挑选、分析、归类,最后分析得到人们想要的结果,主要是指任何能够从数组产生标量值的数据转换过程。 https://baike.baidu.com/item/聚合/20367464
通用语法格式
<aggregate>(<variable declarations> | <formula> | <expression>)
在
可以在
count
min
max
avg
sum
concat
concat(int i | i = [0 .. 3] | i.toString() order by i desc)
如下示例输出:0|1|2|3
concat(int i | i = [0 .. 3] | i.toString(), "|")
Evaluation of aggregates
TODO
省略部分内容
Omitting parts of an aggregation
1、当你要写的聚合表达式形式这样时<aggregate>(<type> v | <expression> = v | v)
,你可以省略<variable declarations>
部分和<formula>
部分
count(int i | i = "hello".indexOf("l") | i)
=>
count("hello".indexOf("l"))
2、当只有一个聚合变量时,可以省略
avg(int i | i = [0 .. 3] | i)
=>
avg(int i | i = [0 .. 3])
3、特例,即使有多个聚合变量时,你可以在count事件中省略
count(int i, int j | i in [1 .. 3] and j in [1 .. 3] | 1)
=>
count(int i, int j | i in [1 .. 3] and j in [1 .. 3])
4、你可以省略
<aggregate>(<variable declarations> | | <expression>)
max(File f | | f.getTotalNumberOfLines())
5、你可以同时省略
count(File f | any() | 1)
=>
count(File f | | 1)
=>
count(File f)
Monotonic aggregates
9、ANY
10、一元操作符(Unary operations)
一个一元操作由一个一元操作符+一个表达式构成
-6.28
+(10 - 4)
11、二元操作符(Binary operations)
一个二元操作由一个表达式+一个二元操作符+一个表达式构成
5 % 2
(9 + 1) / (-2)
"Q" + "L"
12、类型转换(casts)
import java
from Type t
后缀型类型转换
where t.(Class).getASupertype().hasName("List")
前缀型类型转换
where ((Class)t).getASupertype().hasName("List")
13、临时表达式(Don’t-care expressions)
from string s
where s = "hello".charAt(_)
select s
等价于
from string s,int i
where s = "hello".charAt(i)
select s