惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
Check Point Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
L
LangChain Blog
云风的 BLOG
云风的 BLOG
M
MIT News - Artificial intelligence
A
About on SuperTechFans
J
Java Code Geeks
量子位
博客园 - 三生石上(FineUI控件)
博客园 - Franky
博客园_首页
H
Hackread – Cybersecurity News, Data Breaches, AI and More
IT之家
IT之家
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Apple Machine Learning Research
Apple Machine Learning Research
Engineering at Meta
Engineering at Meta
雷峰网
雷峰网
D
DataBreaches.Net
人人都是产品经理
人人都是产品经理
Martin Fowler
Martin Fowler
有赞技术团队
有赞技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻

SumSec's Blog

AI Agent 工程的必然演进:CLI、Skills、Harne… 从安全角度谈Java反射机制--前章 · SUMSEC 从安全角度谈Java反射机制--终章 · SUMSEC 逆向学习fastjson反序列化始 · SUMSEC 2020年研究回顾总结 · SUMSEC Abstract syntax tree classes for … Analyzing data flow in Java · SUM… Annotations in Java · SUMSEC Basic query for Java code · SUMSEC BypassSuper使用介绍说明 · SUMSEC CodeQL Create OpenJdk/Jdk8 Databa… CodeQL library for Java · SUMSEC Navigating the call graph · SUMSEC Overflow-prone comparisons in Jav… Types in Java · SUMSEC Working with source locations · S… Aliases · SUMSEC Expression · SUMSEC Formulas · SUMSEC Javadoc · SUMSEC Modules · SUMSEC Queries · SUMSEC Type · SUMSEC Variables · SUMSEC 一道shiro反序列化题目引发的思考 · SUMSEC 修改ysoserial使其支持任意代码执行 · SUMSEC 自定义 ClassLoader 隔离运行不同版本jar包的方式 ·… 2020网鼎杯---Java文件上传wp · SUMSEC CNVD-2020-10487(CVE-2020-1938)tom… JDSRC安全课笔记 · SUMSEC
Predicates · SUMSEC
2026-07-17 · via SumSec's Blog

Predicates

Predicates–谓词

定义

官方给出的定义

Predicates are used to describe the logical relations that make up a QL program.

谓词用于描述组成QL程序的逻辑关系。


定义谓词

在定义谓词时,官方要求:

  1. 关键字(用于无结果的谓词)或结果类型(用于结果的谓词)。predicate
  2. 谓词的名称。这是一个标识符,以小写字母开始。
  3. 谓词的参数(如果有的话)被逗号隔开。对于每个参数,指定参数类型和参数变量的标识符。
  4. 谓词体本身。这是一个逻辑公式,封闭在括号中。

个人理解其实就是Java、C等语言中的方法或者函数(初步来看,但可以有其特殊性)

注意(之后在看)

抽象外部谓词没有身体。要定义这样的谓词,则用分号 () 结束谓词定义。;


Predicates without result–没有结果谓词

以关键字predicate开头,如果传入的值满足条件就拥有该值。

: ```plain import java predicate isSmall(int i) { i in [1 .. 9] } from int x where x = 2 and isSmall(x) // x = 40 select x >>>2 ``` ![image-20210311163818016](/2021/pic/predicates/18u38er18ec.png) --- ### Predicates with result – 结果谓词 You can define a predicate with result by replacing the keyword with the type of the result. This introduces the special variable .`predicateresult` 通过将关键字替换为结果类型来定义结果的谓词。这里引入特殊的变量`predicateresult`。 : ```plain import java int getSuccessor(int i) { result = i + 1 and // i=3 i in [1 .. 9] // i=2 } from int x where x = 2 select getSuccessor(x) //x =3 >>> 3 ``` ![image-20210311165311442](/2021/pic/predicates/11u53er11ec.png) 结果谓词可以定义一个或多个值 官方文档: ```plain string getANeighbor(string country) { country = "France" and result = "Belgium" or country = "France" and result = "Germany" or country = "Germany" and result = "Austria" or country = "Germany" and result = "Belgium" } ``` 在这种情况下: - 谓词调用返回两个结果:和.``` getANeighbor("Germany")``"Austria"``"Belgium" ``` - 谓词调用不返回任何结果,因为没有定义一个。``` .getANeighbor("Belgium")``getANeighbor``result``"Belgium" ``` --- ### Recursive predicates–递归谓词 ```plain import java string getANeighbor(string country) { country = "France" and result = "Belgium" or country = "France" and result = "Germany" or country = "Germany" and result = "Austria" or country = "Germany" and result = "Belgium" or country = getANeighbor(result) } select getANeighbor("Belgium") //大致流程(个人推断)14(country=Belgium)->4(country=Belgium)->6(country=Belgium)->8(country=Belgium)->10(country=Belgium)->12(country=Belgium)->4(country=France)输出->6(country=Germany)输出 ``` ![image-20210312171843940](/2021/pic/predicates/44u18er44ec.png) 更多解释可以参考[递归](https://codeql.github.com/docs/ql-language-reference/recursion/#recursion) --- ## Kinds of predicates —谓词的种类 ```plain int getSuccessor(int i) { // 1. Non-member predicate 非成员谓词 result = i + 1 and i in [1 .. 9] } class FavoriteNumbers extends int { FavoriteNumbers() { // 2. Characteristic predicate 特征谓词 this = 1 or this = 4 or this = 9 } string getName() { // 3. Member predicate for the class FavoriteNumbers 成员谓词 this = 1 and result = "one" or this = 4 and result = "four" or this = 9 and result = "nine" } } ```