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
优先级
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人