Predicate
predicate name(type arg)
{
statements
}predicate isSmall(int i) {
i in [1 .. 9]
}Last updated
predicate name(type arg)
{
statements
}predicate isSmall(int i) {
i in [1 .. 9]
}Last updated
int getSuccessor(int i) {
result = i + 1 and
i in [1 .. 9]
}Person getAChildOf(Person p) {
p = getAParentOf(result) # result的parent是p, 即p的child是result
}string getFunc(string action) {
action = "rce" and result = "popen"
or
action = "rce" and result = "system"
or
action = "ssrf" and result = "file_get_contents"
or
action = "ssrf" and result = "curl_exec"
}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)
}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"
}
}/*
Compilation errors:
ERROR: "i" is not bound to a value.
ERROR: "result" is not bound to a value.
ERROR: expression "i * 4" is not bound to a value.
*/
int multiplyBy4(int i) {
result = i * 4
}
/*
Compilation errors:
ERROR: "str" is not bound to a value.
ERROR: expression "str.length()" is not bound to a value.
*/
predicate shortString(string str) {
str.length() < 10
}bindingset[x] bindingset[y]
predicate plusOne(int x, int y) {
x + 1 = y
}
from int x, int y
where y = 42 and plusOne(x, y)
select x, ybindingset[str, len]
string truncate(string str, int len) {
if str.length() > len
then result = str.prefix(len)
else result = str
}