mirror of
https://github.com/github/codeql.git
synced 2026-07-03 10:35:29 +02:00
Compare commits
2 Commits
python-two
...
copilot/up
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2e6bc6612c | ||
|
|
5c2614283d |
@@ -3,13 +3,13 @@ class C
|
||||
void Problems()
|
||||
{
|
||||
// correct expectation comment, but only for `problem-query`
|
||||
var x = "Alert"; // $ Alert
|
||||
var x = "Alert"; // $ Alert[problem-query]
|
||||
|
||||
// irrelevant expectation comment, will be ignored
|
||||
x = "Not an alert"; // $ IrrelevantTag
|
||||
|
||||
// incorrect expectation comment
|
||||
x = "Also not an alert"; // $ Alert
|
||||
x = "Also not an alert"; // $ MISSING: Alert[problem-query]
|
||||
|
||||
// missing expectation comment, but only for `problem-query`
|
||||
x = "Alert";
|
||||
|
||||
@@ -13,8 +13,6 @@
|
||||
| InlineTests.cs:88:13:88:23 | "Alert:0:1" | InlineTests.cs:88:13:88:23 | "Alert:0:1" | InlineTests.cs:87:16:87:21 | "Sink" | This is a problem |
|
||||
edges
|
||||
testFailures
|
||||
| InlineTests.cs:6:26:6:35 | // ... | Missing result: Alert |
|
||||
| InlineTests.cs:12:34:12:43 | // ... | Missing result: Alert |
|
||||
| InlineTests.cs:37:28:37:38 | // ... | Missing result: Source |
|
||||
| InlineTests.cs:38:24:38:32 | // ... | Missing result: Sink |
|
||||
| InlineTests.cs:39:33:39:42 | // ... | Missing result: Alert |
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
| InlineTests.cs:100:13:100:25 | "Alert:3:2:1" | InlineTests.cs:97:18:97:25 | "Source" | InlineTests.cs:98:16:98:21 | "Sink" | This is a problem with $@ | InlineTests.cs:99:19:99:27 | "Related" | a related location |
|
||||
edges
|
||||
testFailures
|
||||
| InlineTests.cs:6:26:6:35 | // ... | Missing result: Alert |
|
||||
| InlineTests.cs:12:34:12:43 | // ... | Missing result: Alert |
|
||||
| InlineTests.cs:32:32:32:42 | // ... | Missing result: Source |
|
||||
| InlineTests.cs:33:28:33:36 | // ... | Missing result: Sink |
|
||||
| InlineTests.cs:34:30:34:39 | // ... | Missing result: Alert |
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
| InlineTests.cs:15:13:15:19 | "Alert" | This is a problem |
|
||||
| InlineTests.cs:18:13:18:19 | "Alert" | This is a problem |
|
||||
testFailures
|
||||
| InlineTests.cs:12:34:12:43 | // ... | Missing result: Alert |
|
||||
| InlineTests.cs:15:13:15:19 | This is a problem | Unexpected result: Alert |
|
||||
| InlineTests.cs:34:30:34:39 | // ... | Missing result: Alert |
|
||||
| InlineTests.cs:39:33:39:42 | // ... | Missing result: Alert |
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
| InlineTests.cs:22:13:22:21 | "Alert:1" | This is a problem with $@ | InlineTests.cs:21:23:21:31 | "Related" | a related location |
|
||||
| InlineTests.cs:26:13:26:21 | "Alert:1" | This is a problem with $@ | InlineTests.cs:25:19:25:27 | "Related" | a related location |
|
||||
testFailures
|
||||
| InlineTests.cs:6:26:6:35 | // ... | Missing result: Alert |
|
||||
| InlineTests.cs:12:34:12:43 | // ... | Missing result: Alert |
|
||||
| InlineTests.cs:25:19:25:27 | "Related" | Unexpected result: RelatedLocation |
|
||||
| InlineTests.cs:34:30:34:39 | // ... | Missing result: Alert |
|
||||
| InlineTests.cs:39:33:39:42 | // ... | Missing result: Alert |
|
||||
|
||||
@@ -33,11 +33,9 @@ module StoredXss {
|
||||
walkFn.getACall().getArgument(1) = f.getASuccessor*()
|
||||
)
|
||||
or
|
||||
// The return value of a call to `os.DirEntry.Name`, `os.FileInfo.Name`
|
||||
// or `os.File.ReadDirNames`.
|
||||
exists(DataFlow::CallNode cn, Method m | m = cn.getTarget() and this = cn.getResult(0) |
|
||||
m.implements("io/fs", ["DirEntry", "FileInfo"], "Name") or
|
||||
m.hasQualifiedName("os", "File", "ReadDirNames")
|
||||
// A call to os.FileInfo.Name
|
||||
exists(Method m | m.implements("io/fs", "FileInfo", "Name") |
|
||||
m = this.(DataFlow::CallNode).getTarget()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,3 +156,12 @@ nodes
|
||||
| websocketXss.go:54:3:54:38 | ... := ...[1] | semmle.label | ... := ...[1] |
|
||||
| websocketXss.go:55:24:55:31 | gorilla3 | semmle.label | gorilla3 |
|
||||
subpaths
|
||||
testFailures
|
||||
| websocketXss.go:30:32:30:60 | comment | Missing result: Source[go/reflected-xss] |
|
||||
| websocketXss.go:31:11:31:14 | xnet [postupdate] | Unexpected result: Source |
|
||||
| websocketXss.go:34:30:34:58 | comment | Missing result: Source[go/reflected-xss] |
|
||||
| websocketXss.go:35:21:35:25 | xnet2 [postupdate] | Unexpected result: Source |
|
||||
| websocketXss.go:46:38:46:66 | comment | Missing result: Source[go/reflected-xss] |
|
||||
| websocketXss.go:47:26:47:35 | gorillaMsg [postupdate] | Unexpected result: Source |
|
||||
| websocketXss.go:50:33:50:61 | comment | Missing result: Source[go/reflected-xss] |
|
||||
| websocketXss.go:51:17:51:24 | gorilla2 [postupdate] | Unexpected result: Source |
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
#select
|
||||
| StoredXss.go:13:21:13:36 | ...+... | StoredXss.go:13:21:13:31 | call to Name | StoredXss.go:13:21:13:36 | ...+... | Stored cross-site scripting vulnerability due to $@. | StoredXss.go:13:21:13:31 | call to Name | stored value |
|
||||
| stored.go:30:22:30:25 | name | stored.go:18:3:18:28 | ... := ...[0] | stored.go:30:22:30:25 | name | Stored cross-site scripting vulnerability due to $@. | stored.go:18:3:18:28 | ... := ...[0] | stored value |
|
||||
| stored.go:61:22:61:25 | path | stored.go:59:30:59:33 | SSA def(path) | stored.go:61:22:61:25 | path | Stored cross-site scripting vulnerability due to $@. | stored.go:59:30:59:33 | SSA def(path) | stored value |
|
||||
edges
|
||||
| StoredXss.go:13:21:13:31 | call to Name | StoredXss.go:13:21:13:36 | ...+... | provenance | |
|
||||
| stored.go:18:3:18:28 | ... := ...[0] | stored.go:25:14:25:17 | rows | provenance | Src:MaD:1 |
|
||||
| stored.go:25:14:25:17 | rows | stored.go:25:29:25:33 | &... [postupdate] | provenance | FunctionModel |
|
||||
| stored.go:25:29:25:33 | &... [postupdate] | stored.go:30:22:30:25 | name | provenance | |
|
||||
@@ -11,8 +9,6 @@ edges
|
||||
models
|
||||
| 1 | Source: database/sql; DB; true; Query; ; ; ReturnValue[0]; database; manual |
|
||||
nodes
|
||||
| StoredXss.go:13:21:13:31 | call to Name | semmle.label | call to Name |
|
||||
| StoredXss.go:13:21:13:36 | ...+... | semmle.label | ...+... |
|
||||
| stored.go:18:3:18:28 | ... := ...[0] | semmle.label | ... := ...[0] |
|
||||
| stored.go:25:14:25:17 | rows | semmle.label | rows |
|
||||
| stored.go:25:29:25:33 | &... [postupdate] | semmle.label | &... [postupdate] |
|
||||
@@ -20,3 +16,5 @@ nodes
|
||||
| stored.go:59:30:59:33 | SSA def(path) | semmle.label | SSA def(path) |
|
||||
| stored.go:61:22:61:25 | path | semmle.label | path |
|
||||
subpaths
|
||||
testFailures
|
||||
| StoredXss.go:13:39:13:63 | comment | Missing result: Alert[go/stored-xss] |
|
||||
|
||||
@@ -27,12 +27,12 @@ func xss(w http.ResponseWriter, r *http.Request) {
|
||||
origin := "test"
|
||||
{
|
||||
ws, _ := websocket.Dial(uri, "", origin)
|
||||
var xnet = make([]byte, 512)
|
||||
ws.Read(xnet) // $ Source[go/reflected-xss]
|
||||
var xnet = make([]byte, 512) // $ Source[go/reflected-xss]
|
||||
ws.Read(xnet)
|
||||
fmt.Fprintf(w, "%v", xnet) // $ Alert[go/reflected-xss]
|
||||
codec := &websocket.Codec{Marshal: marshal, Unmarshal: unmarshal}
|
||||
xnet2 := make([]byte, 512)
|
||||
codec.Receive(ws, xnet2) // $ Source[go/reflected-xss]
|
||||
xnet2 := make([]byte, 512) // $ Source[go/reflected-xss]
|
||||
codec.Receive(ws, xnet2)
|
||||
fmt.Fprintf(w, "%v", xnet2) // $ Alert[go/reflected-xss]
|
||||
}
|
||||
{
|
||||
@@ -43,12 +43,12 @@ func xss(w http.ResponseWriter, r *http.Request) {
|
||||
{
|
||||
dialer := gorilla.Dialer{}
|
||||
conn, _, _ := dialer.Dial(uri, nil)
|
||||
var gorillaMsg = make([]byte, 512)
|
||||
gorilla.ReadJSON(conn, gorillaMsg) // $ Source[go/reflected-xss]
|
||||
fmt.Fprintf(w, "%v", gorillaMsg) // $ Alert[go/reflected-xss]
|
||||
var gorillaMsg = make([]byte, 512) // $ Source[go/reflected-xss]
|
||||
gorilla.ReadJSON(conn, gorillaMsg)
|
||||
fmt.Fprintf(w, "%v", gorillaMsg) // $ Alert[go/reflected-xss]
|
||||
|
||||
gorilla2 := make([]byte, 512)
|
||||
conn.ReadJSON(gorilla2) // $ Source[go/reflected-xss]
|
||||
gorilla2 := make([]byte, 512) // $ Source[go/reflected-xss]
|
||||
conn.ReadJSON(gorilla2)
|
||||
fmt.Fprintf(w, "%v", gorilla2) // $ Alert[go/reflected-xss]
|
||||
|
||||
_, gorilla3, _ := conn.ReadMessage() // $ Source[go/reflected-xss]
|
||||
|
||||
@@ -14,9 +14,7 @@ pluginManagement {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
google()
|
||||
maven {
|
||||
url = 'https://maven-central.storage-download.googleapis.com/maven2/'
|
||||
}
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
dependencyResolutionManagement {
|
||||
@@ -35,9 +33,7 @@ dependencyResolutionManagement {
|
||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||
repositories {
|
||||
google()
|
||||
maven {
|
||||
url = 'https://maven-central.storage-download.googleapis.com/maven2/'
|
||||
}
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
rootProject.name = "Android Sample"
|
||||
|
||||
@@ -14,9 +14,7 @@ pluginManagement {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
google()
|
||||
maven {
|
||||
url = uri("https://maven-central.storage-download.googleapis.com/maven2/")
|
||||
}
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
dependencyResolutionManagement {
|
||||
@@ -35,9 +33,7 @@ dependencyResolutionManagement {
|
||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||
repositories {
|
||||
google()
|
||||
maven {
|
||||
url = uri("https://maven-central.storage-download.googleapis.com/maven2/")
|
||||
}
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
rootProject.name = "Android Sample"
|
||||
|
||||
@@ -14,9 +14,7 @@ pluginManagement {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
google()
|
||||
maven {
|
||||
url = uri("https://maven-central.storage-download.googleapis.com/maven2/")
|
||||
}
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
dependencyResolutionManagement {
|
||||
@@ -35,9 +33,7 @@ dependencyResolutionManagement {
|
||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||
repositories {
|
||||
google()
|
||||
maven {
|
||||
url = uri("https://maven-central.storage-download.googleapis.com/maven2/")
|
||||
}
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
rootProject.name = "Android Sample"
|
||||
|
||||
@@ -14,9 +14,7 @@ pluginManagement {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
google()
|
||||
maven {
|
||||
url = 'https://maven-central.storage-download.googleapis.com/maven2/'
|
||||
}
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
dependencyResolutionManagement {
|
||||
@@ -35,9 +33,7 @@ dependencyResolutionManagement {
|
||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||
repositories {
|
||||
google()
|
||||
maven {
|
||||
url = 'https://maven-central.storage-download.googleapis.com/maven2/'
|
||||
}
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
rootProject.name = "Android Sample"
|
||||
|
||||
@@ -13,9 +13,7 @@ buildscript {
|
||||
|
||||
repositories {
|
||||
google()
|
||||
maven {
|
||||
url = uri("https://maven-central.storage-download.googleapis.com/maven2/")
|
||||
}
|
||||
jcenter()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,8 +39,6 @@ buildscript {
|
||||
allprojects {
|
||||
repositories {
|
||||
google()
|
||||
maven {
|
||||
url = uri("https://maven-central.storage-download.googleapis.com/maven2/")
|
||||
}
|
||||
jcenter()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,9 +13,7 @@ buildscript {
|
||||
|
||||
repositories {
|
||||
google()
|
||||
maven {
|
||||
url = uri("https://maven-central.storage-download.googleapis.com/maven2/")
|
||||
}
|
||||
jcenter()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,8 +39,6 @@ buildscript {
|
||||
allprojects {
|
||||
repositories {
|
||||
google()
|
||||
maven {
|
||||
url = uri("https://maven-central.storage-download.googleapis.com/maven2/")
|
||||
}
|
||||
jcenter()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,9 +13,7 @@ buildscript {
|
||||
|
||||
repositories {
|
||||
google()
|
||||
maven {
|
||||
url = 'https://maven-central.storage-download.googleapis.com/maven2/'
|
||||
}
|
||||
jcenter()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,8 +39,6 @@ buildscript {
|
||||
allprojects {
|
||||
repositories {
|
||||
google()
|
||||
maven {
|
||||
url = 'https://maven-central.storage-download.googleapis.com/maven2/'
|
||||
}
|
||||
jcenter()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,9 +13,7 @@ buildscript {
|
||||
|
||||
repositories {
|
||||
google()
|
||||
maven {
|
||||
url = 'https://maven-central.storage-download.googleapis.com/maven2/'
|
||||
}
|
||||
jcenter()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -34,15 +32,13 @@ buildscript {
|
||||
* dependencies used by all modules in your project, such as third-party plugins
|
||||
* or libraries. However, you should configure module-specific dependencies in
|
||||
* each module-level build.gradle file. For new projects, Android Studio
|
||||
* includes Maven Central and Google's Maven repository by default, but it does not
|
||||
* includes JCenter and Google's Maven repository by default, but it does not
|
||||
* configure any dependencies (unless you select a template that requires some).
|
||||
*/
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
google()
|
||||
maven {
|
||||
url = 'https://maven-central.storage-download.googleapis.com/maven2/'
|
||||
}
|
||||
jcenter()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,9 +14,7 @@ pluginManagement {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
google()
|
||||
maven {
|
||||
url = 'https://maven-central.storage-download.googleapis.com/maven2/'
|
||||
}
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
dependencyResolutionManagement {
|
||||
@@ -35,9 +33,7 @@ dependencyResolutionManagement {
|
||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||
repositories {
|
||||
google()
|
||||
maven {
|
||||
url = 'https://maven-central.storage-download.googleapis.com/maven2/'
|
||||
}
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
rootProject.name = "Android Sample"
|
||||
|
||||
@@ -8,9 +8,7 @@
|
||||
apply plugin: 'java-library'
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
url = 'https://maven-central.storage-download.googleapis.com/maven2/'
|
||||
}
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
https://maven-central.storage-download.googleapis.com/maven2/org/apache/commons/commons-math3/3.6.1/commons-math3-3.6.1.jar
|
||||
https://maven-central.storage-download.googleapis.com/maven2/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar
|
||||
https://maven-central.storage-download.googleapis.com/maven2/org/junit/jupiter/junit-jupiter-api/5.12.1/junit-jupiter-api-5.12.1.jar
|
||||
https://maven-central.storage-download.googleapis.com/maven2/org/junit/platform/junit-platform-commons/1.12.1/junit-platform-commons-1.12.1.jar
|
||||
https://maven-central.storage-download.googleapis.com/maven2/org/opentest4j/opentest4j/1.3.0/opentest4j-1.3.0.jar
|
||||
https://repo.maven.apache.org/maven2/org/apache/commons/commons-math3/3.6.1/commons-math3-3.6.1.jar
|
||||
https://repo.maven.apache.org/maven2/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar
|
||||
https://repo.maven.apache.org/maven2/org/junit/jupiter/junit-jupiter-api/5.12.1/junit-jupiter-api-5.12.1.jar
|
||||
https://repo.maven.apache.org/maven2/org/junit/platform/junit-platform-commons/1.12.1/junit-platform-commons-1.12.1.jar
|
||||
https://repo.maven.apache.org/maven2/org/opentest4j/opentest4j/1.3.0/opentest4j-1.3.0.jar
|
||||
|
||||
@@ -8,9 +8,7 @@
|
||||
apply plugin: 'java-library'
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
url = 'https://maven-central.storage-download.googleapis.com/maven2/'
|
||||
}
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
https://maven-central.storage-download.googleapis.com/maven2/joda-time/joda-time/2.12.7/joda-time-2.12.7-no-tzdb.jar
|
||||
https://maven-central.storage-download.googleapis.com/maven2/org/apache/commons/commons-math3/3.6.1/commons-math3-3.6.1.jar
|
||||
https://repo.maven.apache.org/maven2/joda-time/joda-time/2.12.7/joda-time-2.12.7-no-tzdb.jar
|
||||
https://repo.maven.apache.org/maven2/org/apache/commons/commons-math3/3.6.1/commons-math3-3.6.1.jar
|
||||
|
||||
@@ -12,9 +12,9 @@ apply plugin: 'java'
|
||||
|
||||
// In this section you declare where to find the dependencies of your project
|
||||
repositories {
|
||||
maven {
|
||||
url = 'https://maven-central.storage-download.googleapis.com/maven2/'
|
||||
}
|
||||
// Use 'jcenter' for resolving your dependencies.
|
||||
// You can declare any Maven/Ivy/file repository here.
|
||||
jcenter()
|
||||
}
|
||||
|
||||
// In this section you declare the dependencies for your production and test code
|
||||
|
||||
@@ -8,9 +8,7 @@
|
||||
apply plugin: 'java-library'
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
url = 'https://maven-central.storage-download.googleapis.com/maven2/'
|
||||
}
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
@@ -1 +1 @@
|
||||
https://maven-central.storage-download.googleapis.com/maven2/org/apache/commons/commons-math3/3.6.1/commons-math3-3.6.1.jar
|
||||
https://repo.maven.apache.org/maven2/org/apache/commons/commons-math3/3.6.1/commons-math3-3.6.1.jar
|
||||
|
||||
@@ -8,9 +8,7 @@
|
||||
apply plugin: 'java-library'
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
url = 'https://maven-central.storage-download.googleapis.com/maven2/'
|
||||
}
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
@@ -1 +1 @@
|
||||
https://maven-central.storage-download.googleapis.com/maven2/org/apache/commons/commons-math3/3.6.1/commons-math3-3.6.1.jar
|
||||
https://repo.maven.apache.org/maven2/org/apache/commons/commons-math3/3.6.1/commons-math3-3.6.1.jar
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
https://maven-central.storage-download.googleapis.com/maven2/junit/junit/4.11/junit-4.11.jar
|
||||
https://maven-central.storage-download.googleapis.com/maven2/junit/junit/4.12/junit-4.12.jar
|
||||
https://maven-central.storage-download.googleapis.com/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar
|
||||
https://maven-central.storage-download.googleapis.com/maven2/org/slf4j/slf4j-api/1.7.21/slf4j-api-1.7.21.jar
|
||||
https://jcenter.bintray.com/junit/junit/4.12/junit-4.12.jar
|
||||
https://jcenter.bintray.com/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar
|
||||
https://jcenter.bintray.com/org/slf4j/slf4j-api/1.7.21/slf4j-api-1.7.21.jar
|
||||
https://repo.maven.apache.org/maven2/com/feiniaojin/naaf/naaf-graceful-response-example/1.0/naaf-graceful-response-example-1.0.jar
|
||||
https://repo.maven.apache.org/maven2/com/github/MoebiusSolutions/avro-registry-in-source/avro-registry-in-source-tests/1.8/avro-registry-in-source-tests-1.8.jar
|
||||
https://repo.maven.apache.org/maven2/com/github/MoebiusSolutions/avro-registry-in-source/example-project/1.5/example-project-1.5.jar
|
||||
@@ -13,6 +12,7 @@ https://repo.maven.apache.org/maven2/de/knutwalker/rx-redis-example_2.11/0.1.2/r
|
||||
https://repo.maven.apache.org/maven2/de/knutwalker/rx-redis-java-example_2.11/0.1.2/rx-redis-java-example_2.11-0.1.2.jar
|
||||
https://repo.maven.apache.org/maven2/io/github/scrollsyou/example-spring-boot-starter/1.0.0/example-spring-boot-starter-1.0.0.jar
|
||||
https://repo.maven.apache.org/maven2/io/streamnative/com/example/maven-central-template/server/3.0.0/server-3.0.0.jar
|
||||
https://repo.maven.apache.org/maven2/junit/junit/4.11/junit-4.11.jar
|
||||
https://repo.maven.apache.org/maven2/no/nav/security/token-validation-ktor-demo/3.1.0/token-validation-ktor-demo-3.1.0.jar
|
||||
https://repo.maven.apache.org/maven2/org/minijax/minijax-example-fileupload/0.5.10/minijax-example-fileupload-0.5.10.jar
|
||||
https://repo.maven.apache.org/maven2/org/minijax/minijax-example-inject/0.5.10/minijax-example-inject-0.5.10.jar
|
||||
|
||||
@@ -12,9 +12,9 @@ apply plugin: 'java'
|
||||
|
||||
// In this section you declare where to find the dependencies of your project
|
||||
repositories {
|
||||
maven {
|
||||
url = 'https://maven-central.storage-download.googleapis.com/maven2/'
|
||||
}
|
||||
// Use 'jcenter' for resolving your dependencies.
|
||||
// You can declare any Maven/Ivy/file repository here.
|
||||
jcenter()
|
||||
}
|
||||
|
||||
// In this section you declare the dependencies for your production and test code
|
||||
|
||||
@@ -12,9 +12,9 @@ apply plugin: 'java'
|
||||
|
||||
// In this section you declare where to find the dependencies of your project
|
||||
repositories {
|
||||
maven {
|
||||
url = 'https://maven-central.storage-download.googleapis.com/maven2/'
|
||||
}
|
||||
// Use 'jcenter' for resolving your dependencies.
|
||||
// You can declare any Maven/Ivy/file repository here.
|
||||
jcenter()
|
||||
}
|
||||
|
||||
// In this section you declare the dependencies for your production and test code
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
<settings>
|
||||
<mirrors>
|
||||
<mirror>
|
||||
<id>google-maven-central</id>
|
||||
<name>GCS Maven Central mirror</name>
|
||||
<url>https://maven-central.storage-download.googleapis.com/maven2/</url>
|
||||
<mirrorOf>central</mirrorOf>
|
||||
</mirror>
|
||||
</mirrors>
|
||||
</settings>
|
||||
@@ -26,5 +26,4 @@ maven-project-2/src/main/resources/my-app.properties
|
||||
maven-project-2/src/main/resources/page.xml
|
||||
maven-project-2/src/main/resources/struts.xml
|
||||
maven-project-2/src/test/java/com/example/AppTest4.java
|
||||
settings.xml
|
||||
test-db/working/settings.xml
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import os
|
||||
|
||||
def test(codeql, use_java_11, java, actions_toolchains_file, check_diagnostics_java):
|
||||
# The version of gradle used doesn't work on java 17
|
||||
codeql.database.create(
|
||||
@@ -7,6 +5,5 @@ def test(codeql, use_java_11, java, actions_toolchains_file, check_diagnostics_j
|
||||
"CODEQL_EXTRACTOR_JAVA_OPTION_BUILDLESS": "true",
|
||||
"CODEQL_EXTRACTOR_JAVA_OPTION_BUILDLESS_CLASSPATH_FROM_BUILD_FILES": "true",
|
||||
"LGTM_INDEX_MAVEN_TOOLCHAINS_FILE": str(actions_toolchains_file),
|
||||
"LGTM_INDEX_MAVEN_SETTINGS_FILE": os.path.join(os.path.dirname(os.path.realpath(__file__)), "settings.xml"),
|
||||
}
|
||||
)
|
||||
|
||||
@@ -14,9 +14,7 @@ pluginManagement {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
google()
|
||||
maven {
|
||||
url = 'https://maven-central.storage-download.googleapis.com/maven2/'
|
||||
}
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
dependencyResolutionManagement {
|
||||
@@ -35,9 +33,7 @@ dependencyResolutionManagement {
|
||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||
repositories {
|
||||
google()
|
||||
maven {
|
||||
url = 'https://maven-central.storage-download.googleapis.com/maven2/'
|
||||
}
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
rootProject.name = "Android Sample"
|
||||
|
||||
@@ -12,9 +12,9 @@ apply plugin: 'java'
|
||||
|
||||
// In this section you declare where to find the dependencies of your project
|
||||
repositories {
|
||||
maven {
|
||||
url = 'https://maven-central.storage-download.googleapis.com/maven2/'
|
||||
}
|
||||
// Use 'jcenter' for resolving your dependencies.
|
||||
// You can declare any Maven/Ivy/file repository here.
|
||||
jcenter()
|
||||
}
|
||||
|
||||
// In this section you declare the dependencies for your production and test code
|
||||
|
||||
@@ -12,9 +12,9 @@ apply plugin: 'java'
|
||||
|
||||
// In this section you declare where to find the dependencies of your project
|
||||
repositories {
|
||||
maven {
|
||||
url = 'https://maven-central.storage-download.googleapis.com/maven2/'
|
||||
}
|
||||
// Use 'jcenter' for resolving your dependencies.
|
||||
// You can declare any Maven/Ivy/file repository here.
|
||||
jcenter()
|
||||
}
|
||||
|
||||
// In this section you declare the dependencies for your production and test code
|
||||
|
||||
@@ -12,9 +12,8 @@ plugins {
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
url = uri("https://maven-central.storage-download.googleapis.com/maven2/")
|
||||
}
|
||||
// Use Maven Central for resolving dependencies.
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
@@ -12,9 +12,9 @@ apply plugin: 'java'
|
||||
|
||||
// In this section you declare where to find the dependencies of your project
|
||||
repositories {
|
||||
maven {
|
||||
url = 'https://maven-central.storage-download.googleapis.com/maven2/'
|
||||
}
|
||||
// Use 'jcenter' for resolving your dependencies.
|
||||
// You can declare any Maven/Ivy/file repository here.
|
||||
jcenter()
|
||||
}
|
||||
|
||||
// In this section you declare the dependencies for your production and test code
|
||||
|
||||
@@ -12,9 +12,9 @@ apply plugin: 'java'
|
||||
|
||||
// In this section you declare where to find the dependencies of your project
|
||||
repositories {
|
||||
maven {
|
||||
url = 'https://maven-central.storage-download.googleapis.com/maven2/'
|
||||
}
|
||||
// Use 'jcenter' for resolving your dependencies.
|
||||
// You can declare any Maven/Ivy/file repository here.
|
||||
jcenter()
|
||||
}
|
||||
|
||||
// In this section you declare the dependencies for your production and test code
|
||||
|
||||
@@ -12,9 +12,9 @@ apply plugin: 'java'
|
||||
|
||||
// In this section you declare where to find the dependencies of your project
|
||||
repositories {
|
||||
maven {
|
||||
url = 'https://maven-central.storage-download.googleapis.com/maven2/'
|
||||
}
|
||||
// Use 'jcenter' for resolving your dependencies.
|
||||
// You can declare any Maven/Ivy/file repository here.
|
||||
jcenter()
|
||||
}
|
||||
|
||||
// In this section you declare the dependencies for your production and test code
|
||||
|
||||
@@ -12,9 +12,9 @@ apply plugin: 'java'
|
||||
|
||||
// In this section you declare where to find the dependencies of your project
|
||||
repositories {
|
||||
maven {
|
||||
url = 'https://maven-central.storage-download.googleapis.com/maven2/'
|
||||
}
|
||||
// Use 'jcenter' for resolving your dependencies.
|
||||
// You can declare any Maven/Ivy/file repository here.
|
||||
jcenter()
|
||||
}
|
||||
|
||||
// In this section you declare the dependencies for your production and test code
|
||||
|
||||
@@ -11,9 +11,7 @@ version = '0.0.1-SNAPSHOT'
|
||||
// but I omit it to test we recognise the Spring Boot plugin version.
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
url = 'https://maven-central.storage-download.googleapis.com/maven2/'
|
||||
}
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
@@ -15,9 +15,8 @@ plugins {
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
url = 'https://maven-central.storage-download.googleapis.com/maven2/'
|
||||
}
|
||||
// Use Maven Central for resolving dependencies.
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
application {
|
||||
|
||||
@@ -15,9 +15,8 @@ plugins {
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
url = 'https://maven-central.storage-download.googleapis.com/maven2/'
|
||||
}
|
||||
// Use Maven Central for resolving dependencies.
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
application {
|
||||
|
||||
@@ -4,9 +4,7 @@ plugins {
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
url = 'https://maven-central.storage-download.googleapis.com/maven2/'
|
||||
}
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
@@ -15,9 +15,8 @@ plugins {
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
url = 'https://maven-central.storage-download.googleapis.com/maven2/'
|
||||
}
|
||||
// Use Maven Central for resolving dependencies.
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
application {
|
||||
|
||||
@@ -30,7 +30,5 @@ nodes
|
||||
| BadMacUse.java:152:42:152:51 | ciphertext | semmle.label | ciphertext |
|
||||
subpaths
|
||||
testFailures
|
||||
| BadMacUse.java:50:56:50:66 | // $ Source | Missing result: Source |
|
||||
| BadMacUse.java:63:118:63:128 | // $ Source | Missing result: Source |
|
||||
| BadMacUse.java:92:31:92:35 | bytes : byte[] | Unexpected result: Source |
|
||||
| BadMacUse.java:146:95:146:105 | // $ Source | Missing result: Source |
|
||||
|
||||
@@ -31,7 +31,7 @@ nodes
|
||||
| BadMacUse.java:124:42:124:51 | ciphertext | semmle.label | ciphertext |
|
||||
subpaths
|
||||
testFailures
|
||||
| BadMacUse.java:63:118:63:128 | // $ Source | Missing result: Source |
|
||||
| BadMacUse.java:50:28:50:53 | doFinal(...) : byte[] | Fixed missing result: Source |
|
||||
| BadMacUse.java:92:16:92:36 | doFinal(...) : byte[] | Unexpected result: Source |
|
||||
| BadMacUse.java:124:42:124:51 | ciphertext | Unexpected result: Alert |
|
||||
| BadMacUse.java:146:95:146:105 | // $ Source | Missing result: Source |
|
||||
|
||||
@@ -45,7 +45,7 @@ nodes
|
||||
| BadMacUse.java:152:42:152:51 | ciphertext | semmle.label | ciphertext |
|
||||
subpaths
|
||||
testFailures
|
||||
| BadMacUse.java:50:56:50:66 | // $ Source | Missing result: Source |
|
||||
| BadMacUse.java:63:82:63:97 | plaintext : byte[] | Fixed missing result: Source |
|
||||
| BadMacUse.java:139:79:139:90 | input : byte[] | Unexpected result: Source |
|
||||
| BadMacUse.java:146:95:146:105 | // $ Source | Missing result: Source |
|
||||
| BadMacUse.java:152:42:152:51 | ciphertext | Unexpected result: Alert |
|
||||
|
||||
@@ -47,7 +47,7 @@ class BadMacUse {
|
||||
SecretKey encryptionKey = new SecretKeySpec(encryptionKeyBytes, "AES");
|
||||
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
|
||||
cipher.init(Cipher.DECRYPT_MODE, encryptionKey, new SecureRandom());
|
||||
byte[] plaintext = cipher.doFinal(ciphertext); // $ Source
|
||||
byte[] plaintext = cipher.doFinal(ciphertext); // $ MISSING: Source
|
||||
|
||||
// Now verify MAC (too late)
|
||||
SecretKey macKey = new SecretKeySpec(macKeyBytes, "HmacSHA256");
|
||||
@@ -60,7 +60,7 @@ class BadMacUse {
|
||||
}
|
||||
}
|
||||
|
||||
public void BadMacOnPlaintext(byte[] encryptionKeyBytes, byte[] macKeyBytes, byte[] plaintext) throws Exception {// $ Source
|
||||
public void BadMacOnPlaintext(byte[] encryptionKeyBytes, byte[] macKeyBytes, byte[] plaintext) throws Exception {// $ MISSING: Source
|
||||
// Create keys directly from provided byte arrays
|
||||
SecretKey encryptionKey = new SecretKeySpec(encryptionKeyBytes, "AES");
|
||||
SecretKey macKey = new SecretKeySpec(macKeyBytes, "HmacSHA256");
|
||||
|
||||
@@ -126,5 +126,3 @@ nodes
|
||||
| InsecureIVorNonceSource.java:202:54:202:55 | iv : byte[] | semmle.label | iv : byte[] |
|
||||
| InsecureIVorNonceSource.java:206:51:206:56 | ivSpec | semmle.label | ivSpec |
|
||||
subpaths
|
||||
testFailures
|
||||
| InsecureIVorNonceSource.java:42:21:42:21 | 1 : Number | Unexpected result: Source |
|
||||
|
||||
@@ -39,7 +39,7 @@ public class InsecureIVorNonceSource {
|
||||
public byte[] encryptWithStaticIvByteArray(byte[] key, byte[] plaintext) throws Exception {
|
||||
byte[] iv = new byte[16];
|
||||
for (byte i = 0; i < iv.length; i++) {
|
||||
iv[i] = 1;
|
||||
iv[i] = 1; // $ Source
|
||||
}
|
||||
|
||||
IvParameterSpec ivSpec = new IvParameterSpec(iv);
|
||||
|
||||
@@ -40,11 +40,11 @@ public class Test {
|
||||
* SAST/CBOM: - Parent: PBKDF2. - Iteration count is only 10, which is far
|
||||
* below acceptable security standards. - Flagged as insecure.
|
||||
*/
|
||||
public void pbkdf2LowIteration(String password, int iterationCount) throws Exception { // $ Source
|
||||
public void pbkdf2LowIteration(String password, int iterationCount) throws Exception { // $ MISSING: Source
|
||||
byte[] salt = generateSalt(16);
|
||||
PBEKeySpec spec = new PBEKeySpec(password.toCharArray(), salt, iterationCount, 256); // $ Alert[java/quantum/examples/unknown-kdf-iteration-count]
|
||||
PBEKeySpec spec = new PBEKeySpec(password.toCharArray(), salt, iterationCount, 256);
|
||||
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256");
|
||||
byte[] key = factory.generateSecret(spec).getEncoded();
|
||||
byte[] key = factory.generateSecret(spec).getEncoded(); // $ Alert[java/quantum/examples/unknown-kdf-iteration-count]
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1 @@
|
||||
#select
|
||||
| Test.java:47:22:47:49 | KeyDerivation | Key derivation operation with unknown iteration: $@ | Test.java:43:53:43:70 | iterationCount | iterationCount |
|
||||
testFailures
|
||||
| Test.java:45:94:45:154 | // $ Alert[java/quantum/examples/unknown-kdf-iteration-count] | Missing result: Alert[java/quantum/examples/unknown-kdf-iteration-count] |
|
||||
| Test.java:47:22:47:49 | Key derivation operation with unknown iteration: $@ | Unexpected result: Alert |
|
||||
|
||||
@@ -12,5 +12,3 @@ nodes
|
||||
| Test.java:58:30:58:38 | 1_000_000 : Number | semmle.label | 1_000_000 : Number |
|
||||
| Test.java:59:72:59:85 | iterationCount | semmle.label | iterationCount |
|
||||
subpaths
|
||||
testFailures
|
||||
| Test.java:43:92:43:102 | // $ Source | Missing result: Source |
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
---
|
||||
category: minorAnalysis
|
||||
---
|
||||
* Added support for Angular's `@HostListener('window:message', ...)` and `@HostListener('document:message', ...)` decorators as `postMessage` event handlers. The decorated method's event parameter is now recognized as a client-side remote flow source, and is considered by the `js/missing-origin-check` query.
|
||||
@@ -195,18 +195,6 @@ class PostMessageEventHandler extends Function {
|
||||
rhs = DataFlow::globalObjectRef().getAPropertyWrite("onmessage").getRhs() and
|
||||
rhs.getABoundFunctionValue(paramIndex).getFunction() = this
|
||||
)
|
||||
or
|
||||
// Angular's `@HostListener('window:message', ['$event'])` decorator registers
|
||||
// a method as a `message` event handler on the global `window` or `document`
|
||||
// target. The decorated method receives the `MessageEvent` as its first
|
||||
// parameter, so it is equivalent to `window.addEventListener('message', ...)`.
|
||||
exists(MethodDefinition method, DataFlow::CallNode decorator |
|
||||
decorator = DataFlow::moduleMember("@angular/core", "HostListener").getACall() and
|
||||
decorator = method.getADecorator().getExpression().flow() and
|
||||
decorator.getArgument(0).mayHaveStringValue(["window:message", "document:message"]) and
|
||||
method.getBody() = this and
|
||||
paramIndex = 0
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
import { Component, HostListener } from '@angular/core';
|
||||
|
||||
@Component({ selector: 'app-root' })
|
||||
class AngularComponent {
|
||||
// Angular registers this as a `window` message handler via the decorator,
|
||||
// equivalent to `window.addEventListener('message', ...)`.
|
||||
@HostListener('window:message', ['$event'])
|
||||
onWindowMessage(event: MessageEvent): void { // $ Alert - no origin check
|
||||
eval(event.data);
|
||||
}
|
||||
|
||||
@HostListener('document:message', ['$event'])
|
||||
onDocumentMessage(event: MessageEvent): void { // $ Alert - no origin check
|
||||
eval(event.data);
|
||||
}
|
||||
|
||||
@HostListener('window:message', ['$event'])
|
||||
onCheckedMessage(event: MessageEvent): void { // OK - has an origin check
|
||||
if (event.origin === 'https://www.example.com') {
|
||||
eval(event.data);
|
||||
}
|
||||
}
|
||||
|
||||
// Not a message event, so it is not a postMessage handler.
|
||||
@HostListener('window:resize', ['$event'])
|
||||
onResize(event: MessageEvent): void { // OK - not a message handler
|
||||
eval(event.data);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
| Angular.ts:8:19:8:23 | event | Postmessage handler has no origin check. |
|
||||
| Angular.ts:13:21:13:25 | event | Postmessage handler has no origin check. |
|
||||
| tst.js:11:20:11:24 | event | Postmessage handler has no origin check. |
|
||||
| tst.js:24:27:24:27 | e | Postmessage handler has no origin check. |
|
||||
| tst.js:40:27:40:27 | e | Postmessage handler has no origin check. |
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
---
|
||||
category: minorAnalysis
|
||||
---
|
||||
|
||||
- Temporarily disabled the `instanceFieldStep` disjunct of the internal `TypeTrackingInput::levelStepCall` predicate, which was introduced in 7.2.0 and caused catastrophic query slowdowns on some OOP-heavy Python codebases (e.g. `mypy` and `dask`).
|
||||
@@ -1138,9 +1138,7 @@ predicate clearsContent(Node n, ContentSet cs) {
|
||||
* Holds if the value that is being tracked is expected to be stored inside content `c`
|
||||
* at node `n`.
|
||||
*/
|
||||
predicate expectsContent(Node n, ContentSet c) {
|
||||
FlowSummaryImpl::Private::Steps::summaryExpectsContent(n.(FlowSummaryNode).getSummaryNode(), c)
|
||||
}
|
||||
predicate expectsContent(Node n, ContentSet c) { none() }
|
||||
|
||||
/**
|
||||
* Holds if values stored inside attribute `c` are cleared at node `n`.
|
||||
|
||||
@@ -91,8 +91,6 @@ module Input implements InputSig<Location, DataFlowImplSpecific::PythonDataFlow>
|
||||
cs.isAnyTupleOrDictionaryElement() and result = "AnyTupleOrDictionaryElement" and arg = ""
|
||||
}
|
||||
|
||||
string encodeWithContent(ContentSet c, string arg) { result = "With" + encodeContent(c, arg) }
|
||||
|
||||
bindingset[token]
|
||||
ParameterPosition decodeUnknownParameterPosition(AccessPath::AccessPathTokenBase token) {
|
||||
// needed to support `Argument[x..y]` ranges
|
||||
|
||||
@@ -170,13 +170,7 @@ module TypeTrackingInput implements Shared::TypeTrackingInput<Location> {
|
||||
|
||||
/** Holds if there is a level step from `nodeFrom` to `nodeTo`, which may depend on the call graph. */
|
||||
predicate levelStepCall(Node nodeFrom, LocalSourceNode nodeTo) {
|
||||
// HOTFIX: `instanceFieldStep` is temporarily disabled (via `and none()`).
|
||||
// It uses `classInstanceTracker(cls)` -- itself a type-tracker run --
|
||||
// from inside `levelStepCall`, creating a structural mutual recursion
|
||||
// that causes catastrophic query slowdowns on some OOP-heavy Python
|
||||
// codebases (e.g. mypy and dask). The `and none()` should be removed
|
||||
// once that recursion is redesigned.
|
||||
instanceFieldStep(nodeFrom, nodeTo) and none()
|
||||
instanceFieldStep(nodeFrom, nodeTo)
|
||||
or
|
||||
inheritedFieldStep(nodeFrom, nodeTo)
|
||||
}
|
||||
|
||||
@@ -4199,9 +4199,11 @@ module StdlibPrivate {
|
||||
// The positional argument contains a mapping.
|
||||
// TODO: these values can be overwritten by keyword arguments
|
||||
// - dict mapping
|
||||
input = "Argument[0].WithAnyDictionaryElement" and
|
||||
output = "ReturnValue" and
|
||||
preservesValue = true
|
||||
exists(DataFlow::DictionaryElementContent dc, string key | key = dc.getKey() |
|
||||
input = "Argument[0].DictionaryElement[" + key + "]" and
|
||||
output = "ReturnValue.DictionaryElement[" + key + "]" and
|
||||
preservesValue = true
|
||||
)
|
||||
or
|
||||
// - list-of-pairs mapping
|
||||
input = "Argument[0].ListElement.TupleElement[1]" and
|
||||
@@ -4238,7 +4240,9 @@ module StdlibPrivate {
|
||||
or
|
||||
input = "Argument[0].SetElement"
|
||||
or
|
||||
input = "Argument[0].AnyTupleElement"
|
||||
exists(DataFlow::TupleElementContent tc, int i | i = tc.getIndex() |
|
||||
input = "Argument[0].TupleElement[" + i.toString() + "]"
|
||||
)
|
||||
// TODO: Once we have DictKeyContent, we need to transform that into ListElementContent
|
||||
) and
|
||||
// Element content is mutated into list element content
|
||||
@@ -4262,9 +4266,11 @@ module StdlibPrivate {
|
||||
}
|
||||
|
||||
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
|
||||
input = "Argument[0].WithAnyTupleElement" and
|
||||
output = "ReturnValue" and
|
||||
preservesValue = true
|
||||
exists(DataFlow::TupleElementContent tc, int i | i = tc.getIndex() |
|
||||
input = "Argument[0].TupleElement[" + i.toString() + "]" and
|
||||
output = "ReturnValue.TupleElement[" + i.toString() + "]" and
|
||||
preservesValue = true
|
||||
)
|
||||
or
|
||||
input = "Argument[0].ListElement" and
|
||||
output = "ReturnValue" and
|
||||
@@ -4288,7 +4294,9 @@ module StdlibPrivate {
|
||||
or
|
||||
input = "Argument[0].SetElement"
|
||||
or
|
||||
input = "Argument[0].AnyTupleElement"
|
||||
exists(DataFlow::TupleElementContent tc, int i | i = tc.getIndex() |
|
||||
input = "Argument[0].TupleElement[" + i.toString() + "]"
|
||||
)
|
||||
// TODO: Once we have DictKeyContent, we need to transform that into ListElementContent
|
||||
) and
|
||||
output = "ReturnValue.SetElement" and
|
||||
@@ -4334,7 +4342,9 @@ module StdlibPrivate {
|
||||
or
|
||||
input = "Argument[0].SetElement"
|
||||
or
|
||||
input = "Argument[0].AnyTupleElement"
|
||||
exists(DataFlow::TupleElementContent tc, int i | i = tc.getIndex() |
|
||||
input = "Argument[0].TupleElement[" + i.toString() + "]"
|
||||
)
|
||||
// TODO: Once we have DictKeyContent, we need to transform that into ListElementContent
|
||||
) and
|
||||
output = "ReturnValue.ListElement" and
|
||||
@@ -4362,7 +4372,9 @@ module StdlibPrivate {
|
||||
or
|
||||
content = "SetElement"
|
||||
or
|
||||
content = "AnyTupleElement"
|
||||
exists(DataFlow::TupleElementContent tc, int i | i = tc.getIndex() |
|
||||
content = "TupleElement[" + i.toString() + "]"
|
||||
)
|
||||
|
|
||||
// TODO: Once we have DictKeyContent, we need to transform that into ListElementContent
|
||||
input = "Argument[0]." + content and
|
||||
@@ -4392,7 +4404,9 @@ module StdlibPrivate {
|
||||
or
|
||||
input = "Argument[0].SetElement"
|
||||
or
|
||||
input = "Argument[0].AnyTupleElement"
|
||||
exists(DataFlow::TupleElementContent tc, int i | i = tc.getIndex() |
|
||||
input = "Argument[0].TupleElement[" + i.toString() + "]"
|
||||
)
|
||||
// TODO: Once we have DictKeyContent, we need to transform that into ListElementContent
|
||||
) and
|
||||
output = "ReturnValue.ListElement" and
|
||||
@@ -4420,7 +4434,9 @@ module StdlibPrivate {
|
||||
or
|
||||
input = "Argument[0].SetElement"
|
||||
or
|
||||
input = "Argument[0].AnyTupleElement"
|
||||
exists(DataFlow::TupleElementContent tc, int i | i = tc.getIndex() |
|
||||
input = "Argument[0].TupleElement[" + i.toString() + "]"
|
||||
)
|
||||
// TODO: Once we have DictKeyContent, we need to transform that into ListElementContent
|
||||
) and
|
||||
output = "ReturnValue" and
|
||||
@@ -4452,7 +4468,9 @@ module StdlibPrivate {
|
||||
// We reduce generality slightly by not tracking tuple contents on list arguments beyond the first, for performance.
|
||||
// TODO: Once we have TupleElementAny, this generality can be increased.
|
||||
i = 0 and
|
||||
input = "Argument[1].AnyTupleElement"
|
||||
exists(DataFlow::TupleElementContent tc, int j | j = tc.getIndex() |
|
||||
input = "Argument[1].TupleElement[" + j.toString() + "]"
|
||||
)
|
||||
// TODO: Once we have DictKeyContent, we need to transform that into ListElementContent
|
||||
) and
|
||||
output = "Argument[0].Parameter[" + i.toString() + "]" and
|
||||
@@ -4481,7 +4499,9 @@ module StdlibPrivate {
|
||||
or
|
||||
input = "Argument[1].SetElement"
|
||||
or
|
||||
input = "Argument[1].AnyTupleElement"
|
||||
exists(DataFlow::TupleElementContent tc, int i | i = tc.getIndex() |
|
||||
input = "Argument[1].TupleElement[" + i.toString() + "]"
|
||||
)
|
||||
// TODO: Once we have DictKeyContent, we need to transform that into ListElementContent
|
||||
) and
|
||||
(output = "Argument[0].Parameter[0]" or output = "ReturnValue.ListElement") and
|
||||
@@ -4505,7 +4525,9 @@ module StdlibPrivate {
|
||||
or
|
||||
input = "Argument[0].SetElement"
|
||||
or
|
||||
input = "Argument[0].AnyTupleElement"
|
||||
exists(DataFlow::TupleElementContent tc, int i | i = tc.getIndex() |
|
||||
input = "Argument[0].TupleElement[" + i.toString() + "]"
|
||||
)
|
||||
// TODO: Once we have DictKeyContent, we need to transform that into ListElementContent
|
||||
) and
|
||||
output = "ReturnValue.ListElement.TupleElement[1]" and
|
||||
@@ -4530,7 +4552,12 @@ module StdlibPrivate {
|
||||
or
|
||||
input = "Argument[" + i.toString() + "].SetElement"
|
||||
or
|
||||
input = "Argument[" + i.toString() + "].AnyTupleElement"
|
||||
// We reduce generality slightly by not tracking tuple contents on arguments beyond the first two, for performance.
|
||||
// TODO: Once we have TupleElementAny, this generality can be increased.
|
||||
i in [0 .. 1] and
|
||||
exists(DataFlow::TupleElementContent tc, int j | j = tc.getIndex() |
|
||||
input = "Argument[" + i.toString() + "].TupleElement[" + j.toString() + "]"
|
||||
)
|
||||
// TODO: Once we have DictKeyContent, we need to transform that into ListElementContent
|
||||
) and
|
||||
output = "ReturnValue.ListElement.TupleElement[" + i.toString() + "]" and
|
||||
@@ -4553,6 +4580,12 @@ module StdlibPrivate {
|
||||
override DataFlow::ArgumentNode getACallback() { none() }
|
||||
|
||||
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
|
||||
exists(DataFlow::Content c |
|
||||
input = "Argument[self]." + c.getMaDRepresentation() and
|
||||
output = "ReturnValue." + c.getMaDRepresentation() and
|
||||
preservesValue = true
|
||||
)
|
||||
or
|
||||
input = "Argument[self]" and
|
||||
output = "ReturnValue" and
|
||||
preservesValue = true
|
||||
@@ -4708,10 +4741,12 @@ module StdlibPrivate {
|
||||
override DataFlow::ArgumentNode getACallback() { none() }
|
||||
|
||||
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
|
||||
input = "Argument[self].AnyDictionaryElement" and
|
||||
output = "ReturnValue.TupleElement[1]" and
|
||||
preservesValue = true
|
||||
// TODO: put `key` into "ReturnValue.TupleElement[0]"
|
||||
exists(DataFlow::DictionaryElementContent dc, string key | key = dc.getKey() |
|
||||
input = "Argument[self].DictionaryElement[" + key + "]" and
|
||||
output = "ReturnValue.TupleElement[1]" and
|
||||
preservesValue = true
|
||||
// TODO: put `key` into "ReturnValue.TupleElement[0]"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4790,9 +4825,11 @@ module StdlibPrivate {
|
||||
}
|
||||
|
||||
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
|
||||
input = "Argument[self].AnyDictionaryElement" and
|
||||
output = "ReturnValue.ListElement" and
|
||||
preservesValue = true
|
||||
exists(DataFlow::DictionaryElementContent dc, string key | key = dc.getKey() |
|
||||
input = "Argument[self].DictionaryElement[" + key + "]" and
|
||||
output = "ReturnValue.ListElement" and
|
||||
preservesValue = true
|
||||
)
|
||||
or
|
||||
input = "Argument[self]" and
|
||||
output = "ReturnValue" and
|
||||
@@ -4839,9 +4876,11 @@ module StdlibPrivate {
|
||||
}
|
||||
|
||||
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
|
||||
input = "Argument[self].AnyDictionaryElement" and
|
||||
output = "ReturnValue.ListElement.TupleElement[1]" and
|
||||
preservesValue = true
|
||||
exists(DataFlow::DictionaryElementContent dc, string key | key = dc.getKey() |
|
||||
input = "Argument[self].DictionaryElement[" + key + "]" and
|
||||
output = "ReturnValue.ListElement.TupleElement[1]" and
|
||||
preservesValue = true
|
||||
)
|
||||
or
|
||||
// TODO: Add the keys to output list
|
||||
input = "Argument[self]" and
|
||||
|
||||
@@ -3,5 +3,5 @@ argumentToEnsureNotTaintedNotMarkedAsSpurious
|
||||
untaintedArgumentToEnsureTaintedNotMarkedAsMissing
|
||||
| taint_test.py:32:9:32:25 | taint_test.py:32 | ERROR, you should add `# $ MISSING: tainted` annotation | should_be_tainted |
|
||||
| taint_test.py:37:24:37:40 | taint_test.py:37 | ERROR, you should add `# $ MISSING: tainted` annotation | should_be_tainted |
|
||||
| taint_test.py:41:24:41:40 | taint_test.py:41 | ERROR, you should add `# $ MISSING: tainted` annotation | should_be_tainted |
|
||||
testFailures
|
||||
| taint_test.py:41:20:41:21 | ts | Fixed missing result: tainted |
|
||||
|
||||
@@ -38,7 +38,7 @@ def bad_usage():
|
||||
|
||||
# if you try to get around it by adding BOTH annotations, that results in a problem
|
||||
# from the default set of inline-test-expectation rules
|
||||
ensure_tainted(ts, should_be_tainted) # $ tainted MISSING: tainted
|
||||
ensure_tainted(ts, should_be_tainted) # $ tainted
|
||||
|
||||
# simulating handling something we _want_ to treat at untainted, but we currently treat as tainted
|
||||
should_not_be_tainted = "pretend this is now safe" + ts
|
||||
|
||||
@@ -589,11 +589,11 @@ def test_zip_tuple():
|
||||
|
||||
SINK(z[0][0]) # $ flow="SOURCE, l:-7 -> z[0][0]"
|
||||
SINK(z[0][1]) # $ flow="SOURCE, l:-7 -> z[0][1]"
|
||||
SINK_F(z[0][2]) # $ SPURIOUS: flow="SOURCE, l:-7 -> z[0][2]"
|
||||
SINK_F(z[0][2])
|
||||
SINK_F(z[0][3])
|
||||
SINK(z[1][0]) # $ flow="SOURCE, l:-11 -> z[1][0]"
|
||||
SINK_F(z[1][1]) # $ SPURIOUS: flow="SOURCE, l:-11 -> z[1][1]"
|
||||
SINK(z[1][2]) # $ flow="SOURCE, l:-11 -> z[1][2]"
|
||||
SINK(z[1][2]) # $ MISSING: flow="SOURCE, l:-11 -> z[1][2]" # Tuple contents are not tracked beyond the first two arguments for performance.
|
||||
SINK_F(z[1][3])
|
||||
|
||||
@expects(4)
|
||||
|
||||
@@ -157,7 +157,7 @@ class MyClass2(object):
|
||||
print(self.foo) # $ tracked MISSING: tracked=foo
|
||||
|
||||
instance = MyClass2()
|
||||
print(instance.foo) # $ MISSING: tracked=foo tracked
|
||||
print(instance.foo) # $ tracked MISSING: tracked=foo
|
||||
instance.print_foo() # $ MISSING: tracked=foo
|
||||
|
||||
|
||||
@@ -195,7 +195,7 @@ class Sub1(Base1):
|
||||
|
||||
sub1 = Sub1()
|
||||
sub1.read_foo()
|
||||
print(sub1.foo) # $ MISSING: tracked=foo tracked
|
||||
print(sub1.foo) # $ tracked MISSING: tracked=foo
|
||||
|
||||
|
||||
# attribute written in a subclass method, read in an inherited base class method
|
||||
@@ -210,7 +210,7 @@ class Sub2(Base2):
|
||||
|
||||
sub2 = Sub2()
|
||||
sub2.read_bar()
|
||||
print(sub2.bar) # $ MISSING: tracked=bar tracked
|
||||
print(sub2.bar) # $ tracked MISSING: tracked=bar
|
||||
|
||||
|
||||
# attribute written in a base class method, read on an instance of the subclass
|
||||
@@ -223,4 +223,4 @@ class Sub3(Base3):
|
||||
pass
|
||||
|
||||
sub3 = Sub3()
|
||||
print(sub3.baz) # $ MISSING: tracked=baz tracked
|
||||
print(sub3.baz) # $ tracked MISSING: tracked=baz
|
||||
|
||||
@@ -362,7 +362,7 @@ def test_load_in_bulk():
|
||||
# see https://docs.djangoproject.com/en/4.0/ref/models/querysets/#in-bulk
|
||||
d = TestLoad.objects.in_bulk([1])
|
||||
for val in d.values():
|
||||
SINK(val.text) # $ flow="SOURCE, l:-65 -> val.text"
|
||||
SINK(val.text) # $ MISSING: flow
|
||||
SINK(d[1].text) # $ flow="SOURCE, l:-66 -> d[1].text"
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#select
|
||||
| app.py:23:20:23:24 | ControlFlowNode for query | app.py:20:18:20:21 | ControlFlowNode for name | app.py:23:20:23:24 | ControlFlowNode for query | This SQL query depends on a $@. | app.py:20:18:20:21 | ControlFlowNode for name | user-provided value |
|
||||
| app.py:30:20:30:24 | ControlFlowNode for query | app.py:27:19:27:22 | ControlFlowNode for name | app.py:30:20:30:24 | ControlFlowNode for query | This SQL query depends on a $@. | app.py:27:19:27:22 | ControlFlowNode for name | user-provided value |
|
||||
| app.py:37:20:37:24 | ControlFlowNode for query | app.py:34:19:34:22 | ControlFlowNode for name | app.py:37:20:37:24 | ControlFlowNode for query | This SQL query depends on a $@. | app.py:34:19:34:22 | ControlFlowNode for name | user-provided value |
|
||||
| app.py:44:20:44:24 | ControlFlowNode for query | app.py:41:19:41:22 | ControlFlowNode for name | app.py:44:20:44:24 | ControlFlowNode for query | This SQL query depends on a $@. | app.py:41:19:41:22 | ControlFlowNode for name | user-provided value |
|
||||
| app.py:51:20:51:24 | ControlFlowNode for query | app.py:48:19:48:22 | ControlFlowNode for name | app.py:51:20:51:24 | ControlFlowNode for query | This SQL query depends on a $@. | app.py:48:19:48:22 | ControlFlowNode for name | user-provided value |
|
||||
| sql_injection.py:21:24:21:77 | ControlFlowNode for BinaryExpr | sql_injection.py:14:15:14:22 | ControlFlowNode for username | sql_injection.py:21:24:21:77 | ControlFlowNode for BinaryExpr | This SQL query depends on a $@. | sql_injection.py:14:15:14:22 | ControlFlowNode for username | user-provided value |
|
||||
@@ -24,6 +25,8 @@ edges
|
||||
| app.py:21:5:21:9 | ControlFlowNode for query | app.py:23:20:23:24 | ControlFlowNode for query | provenance | |
|
||||
| app.py:27:19:27:22 | ControlFlowNode for name | app.py:28:5:28:9 | ControlFlowNode for query | provenance | |
|
||||
| app.py:28:5:28:9 | ControlFlowNode for query | app.py:30:20:30:24 | ControlFlowNode for query | provenance | |
|
||||
| app.py:34:19:34:22 | ControlFlowNode for name | app.py:35:5:35:9 | ControlFlowNode for query | provenance | |
|
||||
| app.py:35:5:35:9 | ControlFlowNode for query | app.py:37:20:37:24 | ControlFlowNode for query | provenance | |
|
||||
| app.py:41:19:41:22 | ControlFlowNode for name | app.py:42:5:42:9 | ControlFlowNode for query | provenance | |
|
||||
| app.py:42:5:42:9 | ControlFlowNode for query | app.py:44:20:44:24 | ControlFlowNode for query | provenance | |
|
||||
| app.py:48:19:48:22 | ControlFlowNode for name | app.py:49:5:49:9 | ControlFlowNode for query | provenance | |
|
||||
@@ -51,6 +54,9 @@ nodes
|
||||
| app.py:27:19:27:22 | ControlFlowNode for name | semmle.label | ControlFlowNode for name |
|
||||
| app.py:28:5:28:9 | ControlFlowNode for query | semmle.label | ControlFlowNode for query |
|
||||
| app.py:30:20:30:24 | ControlFlowNode for query | semmle.label | ControlFlowNode for query |
|
||||
| app.py:34:19:34:22 | ControlFlowNode for name | semmle.label | ControlFlowNode for name |
|
||||
| app.py:35:5:35:9 | ControlFlowNode for query | semmle.label | ControlFlowNode for query |
|
||||
| app.py:37:20:37:24 | ControlFlowNode for query | semmle.label | ControlFlowNode for query |
|
||||
| app.py:41:19:41:22 | ControlFlowNode for name | semmle.label | ControlFlowNode for name |
|
||||
| app.py:42:5:42:9 | ControlFlowNode for query | semmle.label | ControlFlowNode for query |
|
||||
| app.py:44:20:44:24 | ControlFlowNode for query | semmle.label | ControlFlowNode for query |
|
||||
|
||||
@@ -31,10 +31,10 @@ async def unsafe2(name: str): # $ Source
|
||||
cursor.close()
|
||||
|
||||
@app.get("/unsafe3/")
|
||||
async def unsafe3(name: str): # $ MISSING: Source
|
||||
async def unsafe3(name: str): # $ Source
|
||||
query = "select * from users where name=" + name
|
||||
cursor = hdb_con3.cursor()
|
||||
cursor.execute(query) # $ MISSING: Alert
|
||||
cursor.execute(query) # $ Alert
|
||||
cursor.close()
|
||||
|
||||
@app.get("/unsafe4/")
|
||||
|
||||
@@ -1312,244 +1312,6 @@ module QL {
|
||||
/** Gets a field or child node of this node. */
|
||||
final override AstNode getAFieldOrChild() { ql_variable_def(this, result) }
|
||||
}
|
||||
|
||||
/** Provides predicates for mapping AST nodes to their named children. */
|
||||
module PrintAst {
|
||||
/** Gets a child of `node` returned by the member predicate with the given `name`. If the predicate takes an index argument, `i` is bound to that index, otherwise `i` is `-1` (which is never a valid index). */
|
||||
AstNode getChild(AstNode node, string name, int i) {
|
||||
result = node.(AddExpr).getLeft() and i = -1 and name = "getLeft"
|
||||
or
|
||||
result = node.(AddExpr).getRight() and i = -1 and name = "getRight"
|
||||
or
|
||||
result = node.(AddExpr).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(Aggregate).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(AnnotArg).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(Annotation).getArgs(i) and name = "getArgs"
|
||||
or
|
||||
result = node.(Annotation).getName() and i = -1 and name = "getName"
|
||||
or
|
||||
result = node.(AritylessPredicateExpr).getName() and i = -1 and name = "getName"
|
||||
or
|
||||
result = node.(AritylessPredicateExpr).getQualifier() and i = -1 and name = "getQualifier"
|
||||
or
|
||||
result = node.(AsExpr).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(AsExprs).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(Body).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(Bool).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(CallBody).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(CallOrUnqualAggExpr).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(Charpred).getBody() and i = -1 and name = "getBody"
|
||||
or
|
||||
result = node.(Charpred).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(ClassMember).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(ClasslessPredicate).getName() and i = -1 and name = "getName"
|
||||
or
|
||||
result = node.(ClasslessPredicate).getReturnType() and i = -1 and name = "getReturnType"
|
||||
or
|
||||
result = node.(ClasslessPredicate).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(CompTerm).getLeft() and i = -1 and name = "getLeft"
|
||||
or
|
||||
result = node.(CompTerm).getRight() and i = -1 and name = "getRight"
|
||||
or
|
||||
result = node.(CompTerm).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(Conjunction).getLeft() and i = -1 and name = "getLeft"
|
||||
or
|
||||
result = node.(Conjunction).getRight() and i = -1 and name = "getRight"
|
||||
or
|
||||
result = node.(Dataclass).getExtends(i) and name = "getExtends"
|
||||
or
|
||||
result = node.(Dataclass).getInstanceof(i) and name = "getInstanceof"
|
||||
or
|
||||
result = node.(Dataclass).getName() and i = -1 and name = "getName"
|
||||
or
|
||||
result = node.(Dataclass).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(Datatype).getName() and i = -1 and name = "getName"
|
||||
or
|
||||
result = node.(Datatype).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(DatatypeBranch).getName() and i = -1 and name = "getName"
|
||||
or
|
||||
result = node.(DatatypeBranch).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(DatatypeBranches).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(Disjunction).getLeft() and i = -1 and name = "getLeft"
|
||||
or
|
||||
result = node.(Disjunction).getRight() and i = -1 and name = "getRight"
|
||||
or
|
||||
result = node.(ExprAggregateBody).getAsExprs() and i = -1 and name = "getAsExprs"
|
||||
or
|
||||
result = node.(ExprAggregateBody).getOrderBys() and i = -1 and name = "getOrderBys"
|
||||
or
|
||||
result = node.(ExprAnnotation).getAnnotArg() and i = -1 and name = "getAnnotArg"
|
||||
or
|
||||
result = node.(ExprAnnotation).getName() and i = -1 and name = "getName"
|
||||
or
|
||||
result = node.(ExprAnnotation).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(Field).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(FullAggregateBody).getAsExprs() and i = -1 and name = "getAsExprs"
|
||||
or
|
||||
result = node.(FullAggregateBody).getGuard() and i = -1 and name = "getGuard"
|
||||
or
|
||||
result = node.(FullAggregateBody).getOrderBys() and i = -1 and name = "getOrderBys"
|
||||
or
|
||||
result = node.(FullAggregateBody).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(HigherOrderTerm).getName() and i = -1 and name = "getName"
|
||||
or
|
||||
result = node.(HigherOrderTerm).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(IfTerm).getCond() and i = -1 and name = "getCond"
|
||||
or
|
||||
result = node.(IfTerm).getFirst() and i = -1 and name = "getFirst"
|
||||
or
|
||||
result = node.(IfTerm).getSecond() and i = -1 and name = "getSecond"
|
||||
or
|
||||
result = node.(Implication).getLeft() and i = -1 and name = "getLeft"
|
||||
or
|
||||
result = node.(Implication).getRight() and i = -1 and name = "getRight"
|
||||
or
|
||||
result = node.(ImportDirective).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(ImportModuleExpr).getQualName(i) and name = "getQualName"
|
||||
or
|
||||
result = node.(ImportModuleExpr).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(InExpr).getLeft() and i = -1 and name = "getLeft"
|
||||
or
|
||||
result = node.(InExpr).getRight() and i = -1 and name = "getRight"
|
||||
or
|
||||
result = node.(InstanceOf).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(Literal).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(MemberPredicate).getName() and i = -1 and name = "getName"
|
||||
or
|
||||
result = node.(MemberPredicate).getReturnType() and i = -1 and name = "getReturnType"
|
||||
or
|
||||
result = node.(MemberPredicate).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(Module).getImplements(i) and name = "getImplements"
|
||||
or
|
||||
result = node.(Module).getName() and i = -1 and name = "getName"
|
||||
or
|
||||
result = node.(Module).getParameter(i) and name = "getParameter"
|
||||
or
|
||||
result = node.(Module).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(ModuleAliasBody).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(ModuleExpr).getName() and i = -1 and name = "getName"
|
||||
or
|
||||
result = node.(ModuleExpr).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(ModuleInstantiation).getName() and i = -1 and name = "getName"
|
||||
or
|
||||
result = node.(ModuleInstantiation).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(ModuleMember).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(ModuleName).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(ModuleParam).getParameter() and i = -1 and name = "getParameter"
|
||||
or
|
||||
result = node.(ModuleParam).getSignature() and i = -1 and name = "getSignature"
|
||||
or
|
||||
result = node.(MulExpr).getLeft() and i = -1 and name = "getLeft"
|
||||
or
|
||||
result = node.(MulExpr).getRight() and i = -1 and name = "getRight"
|
||||
or
|
||||
result = node.(MulExpr).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(Negation).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(OrderBy).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(OrderBys).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(ParExpr).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(PredicateAliasBody).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(PredicateExpr).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(PrefixCast).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(Ql).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(QualifiedRhs).getName() and i = -1 and name = "getName"
|
||||
or
|
||||
result = node.(QualifiedRhs).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(QualifiedExpr).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(Quantified).getExpr() and i = -1 and name = "getExpr"
|
||||
or
|
||||
result = node.(Quantified).getFormula() and i = -1 and name = "getFormula"
|
||||
or
|
||||
result = node.(Quantified).getRange() and i = -1 and name = "getRange"
|
||||
or
|
||||
result = node.(Quantified).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(Range).getLower() and i = -1 and name = "getLower"
|
||||
or
|
||||
result = node.(Range).getUpper() and i = -1 and name = "getUpper"
|
||||
or
|
||||
result = node.(Select).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(SetLiteral).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(SignatureExpr).getModExpr() and i = -1 and name = "getModExpr"
|
||||
or
|
||||
result = node.(SignatureExpr).getPredicate() and i = -1 and name = "getPredicate"
|
||||
or
|
||||
result = node.(SignatureExpr).getTypeExpr() and i = -1 and name = "getTypeExpr"
|
||||
or
|
||||
result = node.(SpecialCall).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(SuperRef).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(TypeAliasBody).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(TypeExpr).getName() and i = -1 and name = "getName"
|
||||
or
|
||||
result = node.(TypeExpr).getQualifier() and i = -1 and name = "getQualifier"
|
||||
or
|
||||
result = node.(TypeExpr).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(TypeUnionBody).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(UnaryExpr).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(UnqualAggBody).getAsExprs(i) and name = "getAsExprs"
|
||||
or
|
||||
result = node.(UnqualAggBody).getGuard() and i = -1 and name = "getGuard"
|
||||
or
|
||||
result = node.(UnqualAggBody).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(VarDecl).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(VarName).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(Variable).getChild() and i = -1 and name = "getChild"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
overlay[local]
|
||||
@@ -1907,60 +1669,6 @@ module Dbscheme {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
final override string getAPrimaryQlClass() { result = "Varchar" }
|
||||
}
|
||||
|
||||
/** Provides predicates for mapping AST nodes to their named children. */
|
||||
module PrintAst {
|
||||
/** Gets a child of `node` returned by the member predicate with the given `name`. If the predicate takes an index argument, `i` is bound to that index, otherwise `i` is `-1` (which is never a valid index). */
|
||||
AstNode getChild(AstNode node, string name, int i) {
|
||||
result = node.(Annotation).getArgsAnnotation() and i = -1 and name = "getArgsAnnotation"
|
||||
or
|
||||
result = node.(Annotation).getSimpleAnnotation() and i = -1 and name = "getSimpleAnnotation"
|
||||
or
|
||||
result = node.(ArgsAnnotation).getName() and i = -1 and name = "getName"
|
||||
or
|
||||
result = node.(ArgsAnnotation).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(Branch).getQldoc() and i = -1 and name = "getQldoc"
|
||||
or
|
||||
result = node.(Branch).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(CaseDecl).getBase() and i = -1 and name = "getBase"
|
||||
or
|
||||
result = node.(CaseDecl).getDiscriminator() and i = -1 and name = "getDiscriminator"
|
||||
or
|
||||
result = node.(CaseDecl).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(ColType).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(Column).getColName() and i = -1 and name = "getColName"
|
||||
or
|
||||
result = node.(Column).getColType() and i = -1 and name = "getColType"
|
||||
or
|
||||
result = node.(Column).getIsRef() and i = -1 and name = "getIsRef"
|
||||
or
|
||||
result = node.(Column).getIsUnique() and i = -1 and name = "getIsUnique"
|
||||
or
|
||||
result = node.(Column).getQldoc() and i = -1 and name = "getQldoc"
|
||||
or
|
||||
result = node.(Column).getReprType() and i = -1 and name = "getReprType"
|
||||
or
|
||||
result = node.(Dbscheme).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(Entry).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(ReprType).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(Table).getTableName() and i = -1 and name = "getTableName"
|
||||
or
|
||||
result = node.(Table).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(TableName).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(UnionDecl).getBase() and i = -1 and name = "getBase"
|
||||
or
|
||||
result = node.(UnionDecl).getChild(i) and name = "getChild"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
overlay[local]
|
||||
@@ -2095,24 +1803,6 @@ module Blame {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
final override string getAPrimaryQlClass() { result = "Number" }
|
||||
}
|
||||
|
||||
/** Provides predicates for mapping AST nodes to their named children. */
|
||||
module PrintAst {
|
||||
/** Gets a child of `node` returned by the member predicate with the given `name`. If the predicate takes an index argument, `i` is bound to that index, otherwise `i` is `-1` (which is never a valid index). */
|
||||
AstNode getChild(AstNode node, string name, int i) {
|
||||
result = node.(BlameEntry).getDate() and i = -1 and name = "getDate"
|
||||
or
|
||||
result = node.(BlameEntry).getLine(i) and name = "getLine"
|
||||
or
|
||||
result = node.(BlameInfo).getFileEntry(i) and name = "getFileEntry"
|
||||
or
|
||||
result = node.(BlameInfo).getToday() and i = -1 and name = "getToday"
|
||||
or
|
||||
result = node.(FileEntry).getBlameEntry(i) and name = "getBlameEntry"
|
||||
or
|
||||
result = node.(FileEntry).getFileName() and i = -1 and name = "getFileName"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
overlay[local]
|
||||
@@ -2287,22 +1977,4 @@ module JSON {
|
||||
/** Gets the name of the primary QL class for this element. */
|
||||
final override string getAPrimaryQlClass() { result = "True" }
|
||||
}
|
||||
|
||||
/** Provides predicates for mapping AST nodes to their named children. */
|
||||
module PrintAst {
|
||||
/** Gets a child of `node` returned by the member predicate with the given `name`. If the predicate takes an index argument, `i` is bound to that index, otherwise `i` is `-1` (which is never a valid index). */
|
||||
AstNode getChild(AstNode node, string name, int i) {
|
||||
result = node.(Array).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(Document).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(Object).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(Pair).getKey() and i = -1 and name = "getKey"
|
||||
or
|
||||
result = node.(Pair).getValue() and i = -1 and name = "getValue"
|
||||
or
|
||||
result = node.(String).getChild(i) and name = "getChild"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1964,340 +1964,6 @@ module Ruby {
|
||||
/** Gets a field or child node of this node. */
|
||||
final override AstNode getAFieldOrChild() { ruby_yield_child(this, result) }
|
||||
}
|
||||
|
||||
/** Provides predicates for mapping AST nodes to their named children. */
|
||||
module PrintAst {
|
||||
/** Gets a child of `node` returned by the member predicate with the given `name`. If the predicate takes an index argument, `i` is bound to that index, otherwise `i` is `-1` (which is never a valid index). */
|
||||
AstNode getChild(AstNode node, string name, int i) {
|
||||
result = node.(Alias).getAlias() and i = -1 and name = "getAlias"
|
||||
or
|
||||
result = node.(Alias).getName() and i = -1 and name = "getName"
|
||||
or
|
||||
result = node.(AlternativePattern).getAlternatives(i) and name = "getAlternatives"
|
||||
or
|
||||
result = node.(ArgumentList).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(Array).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(ArrayPattern).getClass() and i = -1 and name = "getClass"
|
||||
or
|
||||
result = node.(ArrayPattern).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(AsPattern).getName() and i = -1 and name = "getName"
|
||||
or
|
||||
result = node.(AsPattern).getValue() and i = -1 and name = "getValue"
|
||||
or
|
||||
result = node.(Assignment).getLeft() and i = -1 and name = "getLeft"
|
||||
or
|
||||
result = node.(Assignment).getRight() and i = -1 and name = "getRight"
|
||||
or
|
||||
result = node.(BareString).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(BareSymbol).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(Begin).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(BeginBlock).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(Binary).getLeft() and i = -1 and name = "getLeft"
|
||||
or
|
||||
result = node.(Binary).getRight() and i = -1 and name = "getRight"
|
||||
or
|
||||
result = node.(Block).getBody() and i = -1 and name = "getBody"
|
||||
or
|
||||
result = node.(Block).getParameters() and i = -1 and name = "getParameters"
|
||||
or
|
||||
result = node.(BlockArgument).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(BlockBody).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(BlockParameter).getName() and i = -1 and name = "getName"
|
||||
or
|
||||
result = node.(BlockParameters).getLocals(i) and name = "getLocals"
|
||||
or
|
||||
result = node.(BlockParameters).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(BodyStatement).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(Break).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(Call).getArguments() and i = -1 and name = "getArguments"
|
||||
or
|
||||
result = node.(Call).getBlock() and i = -1 and name = "getBlock"
|
||||
or
|
||||
result = node.(Call).getMethod() and i = -1 and name = "getMethod"
|
||||
or
|
||||
result = node.(Call).getOperator() and i = -1 and name = "getOperator"
|
||||
or
|
||||
result = node.(Call).getReceiver() and i = -1 and name = "getReceiver"
|
||||
or
|
||||
result = node.(Case).getValue() and i = -1 and name = "getValue"
|
||||
or
|
||||
result = node.(Case).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(CaseMatch).getClauses(i) and name = "getClauses"
|
||||
or
|
||||
result = node.(CaseMatch).getElse() and i = -1 and name = "getElse"
|
||||
or
|
||||
result = node.(CaseMatch).getValue() and i = -1 and name = "getValue"
|
||||
or
|
||||
result = node.(ChainedString).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(Class).getBody() and i = -1 and name = "getBody"
|
||||
or
|
||||
result = node.(Class).getName() and i = -1 and name = "getName"
|
||||
or
|
||||
result = node.(Class).getSuperclass() and i = -1 and name = "getSuperclass"
|
||||
or
|
||||
result = node.(Complex).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(Conditional).getAlternative() and i = -1 and name = "getAlternative"
|
||||
or
|
||||
result = node.(Conditional).getCondition() and i = -1 and name = "getCondition"
|
||||
or
|
||||
result = node.(Conditional).getConsequence() and i = -1 and name = "getConsequence"
|
||||
or
|
||||
result = node.(DelimitedSymbol).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(DestructuredLeftAssignment).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(DestructuredParameter).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(Do).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(DoBlock).getBody() and i = -1 and name = "getBody"
|
||||
or
|
||||
result = node.(DoBlock).getParameters() and i = -1 and name = "getParameters"
|
||||
or
|
||||
result = node.(ElementReference).getBlock() and i = -1 and name = "getBlock"
|
||||
or
|
||||
result = node.(ElementReference).getObject() and i = -1 and name = "getObject"
|
||||
or
|
||||
result = node.(ElementReference).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(Else).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(Elsif).getAlternative() and i = -1 and name = "getAlternative"
|
||||
or
|
||||
result = node.(Elsif).getCondition() and i = -1 and name = "getCondition"
|
||||
or
|
||||
result = node.(Elsif).getConsequence() and i = -1 and name = "getConsequence"
|
||||
or
|
||||
result = node.(EndBlock).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(Ensure).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(ExceptionVariable).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(Exceptions).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(ExpressionReferencePattern).getValue() and i = -1 and name = "getValue"
|
||||
or
|
||||
result = node.(FindPattern).getClass() and i = -1 and name = "getClass"
|
||||
or
|
||||
result = node.(FindPattern).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(For).getBody() and i = -1 and name = "getBody"
|
||||
or
|
||||
result = node.(For).getPattern() and i = -1 and name = "getPattern"
|
||||
or
|
||||
result = node.(For).getValue() and i = -1 and name = "getValue"
|
||||
or
|
||||
result = node.(Hash).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(HashPattern).getClass() and i = -1 and name = "getClass"
|
||||
or
|
||||
result = node.(HashPattern).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(HashSplatArgument).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(HashSplatParameter).getName() and i = -1 and name = "getName"
|
||||
or
|
||||
result = node.(HeredocBody).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(If).getAlternative() and i = -1 and name = "getAlternative"
|
||||
or
|
||||
result = node.(If).getCondition() and i = -1 and name = "getCondition"
|
||||
or
|
||||
result = node.(If).getConsequence() and i = -1 and name = "getConsequence"
|
||||
or
|
||||
result = node.(IfGuard).getCondition() and i = -1 and name = "getCondition"
|
||||
or
|
||||
result = node.(IfModifier).getBody() and i = -1 and name = "getBody"
|
||||
or
|
||||
result = node.(IfModifier).getCondition() and i = -1 and name = "getCondition"
|
||||
or
|
||||
result = node.(In).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(InClause).getBody() and i = -1 and name = "getBody"
|
||||
or
|
||||
result = node.(InClause).getGuard() and i = -1 and name = "getGuard"
|
||||
or
|
||||
result = node.(InClause).getPattern() and i = -1 and name = "getPattern"
|
||||
or
|
||||
result = node.(Interpolation).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(KeywordParameter).getName() and i = -1 and name = "getName"
|
||||
or
|
||||
result = node.(KeywordParameter).getValue() and i = -1 and name = "getValue"
|
||||
or
|
||||
result = node.(KeywordPattern).getKey() and i = -1 and name = "getKey"
|
||||
or
|
||||
result = node.(KeywordPattern).getValue() and i = -1 and name = "getValue"
|
||||
or
|
||||
result = node.(Lambda).getBody() and i = -1 and name = "getBody"
|
||||
or
|
||||
result = node.(Lambda).getParameters() and i = -1 and name = "getParameters"
|
||||
or
|
||||
result = node.(LambdaParameters).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(LeftAssignmentList).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(MatchPattern).getPattern() and i = -1 and name = "getPattern"
|
||||
or
|
||||
result = node.(MatchPattern).getValue() and i = -1 and name = "getValue"
|
||||
or
|
||||
result = node.(Method).getBody() and i = -1 and name = "getBody"
|
||||
or
|
||||
result = node.(Method).getName() and i = -1 and name = "getName"
|
||||
or
|
||||
result = node.(Method).getParameters() and i = -1 and name = "getParameters"
|
||||
or
|
||||
result = node.(MethodParameters).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(Module).getBody() and i = -1 and name = "getBody"
|
||||
or
|
||||
result = node.(Module).getName() and i = -1 and name = "getName"
|
||||
or
|
||||
result = node.(Next).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(OperatorAssignment).getLeft() and i = -1 and name = "getLeft"
|
||||
or
|
||||
result = node.(OperatorAssignment).getRight() and i = -1 and name = "getRight"
|
||||
or
|
||||
result = node.(OptionalParameter).getName() and i = -1 and name = "getName"
|
||||
or
|
||||
result = node.(OptionalParameter).getValue() and i = -1 and name = "getValue"
|
||||
or
|
||||
result = node.(Pair).getKey() and i = -1 and name = "getKey"
|
||||
or
|
||||
result = node.(Pair).getValue() and i = -1 and name = "getValue"
|
||||
or
|
||||
result = node.(ParenthesizedPattern).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(ParenthesizedStatements).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(Pattern).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(Program).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(Range).getBegin() and i = -1 and name = "getBegin"
|
||||
or
|
||||
result = node.(Range).getEnd() and i = -1 and name = "getEnd"
|
||||
or
|
||||
result = node.(Rational).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(Redo).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(Regex).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(Rescue).getBody() and i = -1 and name = "getBody"
|
||||
or
|
||||
result = node.(Rescue).getExceptions() and i = -1 and name = "getExceptions"
|
||||
or
|
||||
result = node.(Rescue).getVariable() and i = -1 and name = "getVariable"
|
||||
or
|
||||
result = node.(RescueModifier).getBody() and i = -1 and name = "getBody"
|
||||
or
|
||||
result = node.(RescueModifier).getHandler() and i = -1 and name = "getHandler"
|
||||
or
|
||||
result = node.(RestAssignment).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(Retry).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(Return).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(RightAssignmentList).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(ScopeResolution).getName() and i = -1 and name = "getName"
|
||||
or
|
||||
result = node.(ScopeResolution).getScope() and i = -1 and name = "getScope"
|
||||
or
|
||||
result = node.(Setter).getName() and i = -1 and name = "getName"
|
||||
or
|
||||
result = node.(SingletonClass).getBody() and i = -1 and name = "getBody"
|
||||
or
|
||||
result = node.(SingletonClass).getValue() and i = -1 and name = "getValue"
|
||||
or
|
||||
result = node.(SingletonMethod).getBody() and i = -1 and name = "getBody"
|
||||
or
|
||||
result = node.(SingletonMethod).getName() and i = -1 and name = "getName"
|
||||
or
|
||||
result = node.(SingletonMethod).getObject() and i = -1 and name = "getObject"
|
||||
or
|
||||
result = node.(SingletonMethod).getParameters() and i = -1 and name = "getParameters"
|
||||
or
|
||||
result = node.(SplatArgument).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(SplatParameter).getName() and i = -1 and name = "getName"
|
||||
or
|
||||
result = node.(String).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(StringArray).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(Subshell).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(Superclass).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(SymbolArray).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(TestPattern).getPattern() and i = -1 and name = "getPattern"
|
||||
or
|
||||
result = node.(TestPattern).getValue() and i = -1 and name = "getValue"
|
||||
or
|
||||
result = node.(Then).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(Unary).getOperand() and i = -1 and name = "getOperand"
|
||||
or
|
||||
result = node.(Undef).getChild(i) and name = "getChild"
|
||||
or
|
||||
result = node.(Unless).getAlternative() and i = -1 and name = "getAlternative"
|
||||
or
|
||||
result = node.(Unless).getCondition() and i = -1 and name = "getCondition"
|
||||
or
|
||||
result = node.(Unless).getConsequence() and i = -1 and name = "getConsequence"
|
||||
or
|
||||
result = node.(UnlessGuard).getCondition() and i = -1 and name = "getCondition"
|
||||
or
|
||||
result = node.(UnlessModifier).getBody() and i = -1 and name = "getBody"
|
||||
or
|
||||
result = node.(UnlessModifier).getCondition() and i = -1 and name = "getCondition"
|
||||
or
|
||||
result = node.(Until).getBody() and i = -1 and name = "getBody"
|
||||
or
|
||||
result = node.(Until).getCondition() and i = -1 and name = "getCondition"
|
||||
or
|
||||
result = node.(UntilModifier).getBody() and i = -1 and name = "getBody"
|
||||
or
|
||||
result = node.(UntilModifier).getCondition() and i = -1 and name = "getCondition"
|
||||
or
|
||||
result = node.(VariableReferencePattern).getName() and i = -1 and name = "getName"
|
||||
or
|
||||
result = node.(When).getBody() and i = -1 and name = "getBody"
|
||||
or
|
||||
result = node.(When).getPattern(i) and name = "getPattern"
|
||||
or
|
||||
result = node.(While).getBody() and i = -1 and name = "getBody"
|
||||
or
|
||||
result = node.(While).getCondition() and i = -1 and name = "getCondition"
|
||||
or
|
||||
result = node.(WhileModifier).getBody() and i = -1 and name = "getBody"
|
||||
or
|
||||
result = node.(WhileModifier).getCondition() and i = -1 and name = "getCondition"
|
||||
or
|
||||
result = node.(Yield).getChild() and i = -1 and name = "getChild"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
overlay[local]
|
||||
@@ -2441,20 +2107,4 @@ module Erb {
|
||||
/** Gets a field or child node of this node. */
|
||||
final override AstNode getAFieldOrChild() { erb_template_child(this, _, result) }
|
||||
}
|
||||
|
||||
/** Provides predicates for mapping AST nodes to their named children. */
|
||||
module PrintAst {
|
||||
/** Gets a child of `node` returned by the member predicate with the given `name`. If the predicate takes an index argument, `i` is bound to that index, otherwise `i` is `-1` (which is never a valid index). */
|
||||
AstNode getChild(AstNode node, string name, int i) {
|
||||
result = node.(CommentDirective).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(Directive).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(GraphqlDirective).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(OutputDirective).getChild() and i = -1 and name = "getChild"
|
||||
or
|
||||
result = node.(Template).getChild(i) and name = "getChild"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ nodes
|
||||
| string_flow.rb:227:10:227:10 | a | semmle.label | a |
|
||||
subpaths
|
||||
testFailures
|
||||
| string_flow.rb:85:10:85:10 | a | Unexpected result: hasValueFlow=a |
|
||||
| string_flow.rb:227:10:227:10 | a | Unexpected result: hasValueFlow=a |
|
||||
#select
|
||||
| string_flow.rb:3:10:3:22 | call to new | string_flow.rb:2:9:2:18 | call to source | string_flow.rb:3:10:3:22 | call to new | $@ | string_flow.rb:2:9:2:18 | call to source | call to source |
|
||||
|
||||
@@ -82,7 +82,7 @@ end
|
||||
def m_clear
|
||||
a = source "a"
|
||||
a.clear
|
||||
sink a
|
||||
sink a # $ hasValueFlow=a
|
||||
end
|
||||
|
||||
# concat and prepend omitted because they clash with the summaries for
|
||||
|
||||
@@ -18,7 +18,7 @@ class OneController < ActionController::Base
|
||||
end
|
||||
|
||||
def c
|
||||
sink @foo
|
||||
sink @foo # $ hasTaintFlow
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -270,7 +270,6 @@ nodes
|
||||
| params_flow.rb:205:10:205:10 | a | semmle.label | a |
|
||||
subpaths
|
||||
testFailures
|
||||
| filter_flow.rb:21:10:21:13 | @foo | Unexpected result: hasTaintFlow |
|
||||
| filter_flow.rb:38:10:38:13 | @foo | Unexpected result: hasTaintFlow |
|
||||
| filter_flow.rb:55:10:55:13 | @foo | Unexpected result: hasTaintFlow |
|
||||
| filter_flow.rb:71:10:71:17 | call to bar | Unexpected result: hasTaintFlow |
|
||||
|
||||
@@ -497,7 +497,6 @@ nodes
|
||||
| hash_extensions.rb:126:10:126:19 | call to sole | semmle.label | call to sole |
|
||||
subpaths
|
||||
testFailures
|
||||
| hash_extensions.rb:126:10:126:19 | call to sole | Unexpected result: hasValueFlow=b |
|
||||
#select
|
||||
| active_support.rb:182:10:182:13 | ...[...] | active_support.rb:180:10:180:17 | call to source | active_support.rb:182:10:182:13 | ...[...] | $@ | active_support.rb:180:10:180:17 | call to source | call to source |
|
||||
| active_support.rb:188:10:188:13 | ...[...] | active_support.rb:186:10:186:18 | call to source | active_support.rb:188:10:188:13 | ...[...] | $@ | active_support.rb:186:10:186:18 | call to source | call to source |
|
||||
|
||||
@@ -123,7 +123,7 @@ def m_sole
|
||||
multi = [source("b"), source("c")]
|
||||
sink(empty.sole)
|
||||
sink(single.sole) # $ hasValueFlow=a
|
||||
sink(multi.sole) # TODO: model that 'sole' does not return if the receiver has multiple elements
|
||||
sink(multi.sole) # $ hasValueFlow=b # TODO: model that 'sole' does not return if the receiver has multiple elements
|
||||
end
|
||||
|
||||
m_sole()
|
||||
|
||||
@@ -23,7 +23,6 @@ nodes
|
||||
| views/index.erb:2:10:2:12 | call to foo | semmle.label | call to foo |
|
||||
subpaths
|
||||
testFailures
|
||||
| views/index.erb:2:10:2:12 | call to foo | Unexpected result: hasTaintFlow |
|
||||
#select
|
||||
| app.rb:95:10:95:14 | @user | app.rb:103:13:103:22 | call to source | app.rb:95:10:95:14 | @user | $@ | app.rb:103:13:103:22 | call to source | call to source |
|
||||
| views/index.erb:2:10:2:12 | call to foo | app.rb:75:12:75:17 | call to params | views/index.erb:2:10:2:12 | call to foo | $@ | app.rb:75:12:75:17 | call to params | call to params |
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
<%= @foo %>
|
||||
<%= sink foo %>
|
||||
<%= sink foo # $ hasTaintFlow %>
|
||||
@@ -1,5 +1,4 @@
|
||||
testFailures
|
||||
| improper_memoization.rb:100:1:104:3 | m14 | Unexpected result: result=BAD |
|
||||
#select
|
||||
| improper_memoization.rb:50:1:55:3 | m7 | improper_memoization.rb:50:8:50:10 | arg | improper_memoization.rb:51:3:53:5 | ... \|\|= ... |
|
||||
| improper_memoization.rb:58:1:63:3 | m8 | improper_memoization.rb:58:8:58:10 | arg | improper_memoization.rb:59:3:61:5 | ... \|\|= ... |
|
||||
|
||||
@@ -101,4 +101,4 @@ def m14(arg)
|
||||
@m14 ||= {}
|
||||
key = "foo/#{arg}"
|
||||
@m14[key] ||= long_running_method(arg)
|
||||
end
|
||||
end # $ SPURIOUS: result=BAD
|
||||
|
||||
@@ -280,11 +280,10 @@ pub fn location_label(writer: &mut trap::Writer, location: trap::Location) -> tr
|
||||
}
|
||||
|
||||
/// Extracts the source file at `path`, which is assumed to be canonicalized.
|
||||
/// When `desugarer` is `Some`, the parsed tree is first transformed
|
||||
/// through the supplied yeast desugarer before TRAP extraction. Building
|
||||
/// the desugarer (which parses YAML and constructs the schema) is the
|
||||
/// caller's responsibility, allowing it to be done once and shared across
|
||||
/// files.
|
||||
/// When `yeast_runner` is `Some`, the parsed tree is first transformed
|
||||
/// through the supplied yeast `Runner` before TRAP extraction. Building the
|
||||
/// `Runner` (which parses YAML and constructs the schema) is the caller's
|
||||
/// responsibility, allowing it to be done once and shared across files.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn extract(
|
||||
language: &Language,
|
||||
@@ -296,7 +295,7 @@ pub fn extract(
|
||||
path: &Path,
|
||||
source: &[u8],
|
||||
ranges: &[Range],
|
||||
desugarer: Option<&dyn yeast::Desugarer>,
|
||||
yeast_runner: Option<&yeast::Runner<'_>>,
|
||||
) {
|
||||
let path_str = file_paths::normalize_and_transform_path(path, transformer);
|
||||
let source_root = std::env::current_dir()
|
||||
@@ -329,8 +328,8 @@ pub fn extract(
|
||||
schema,
|
||||
);
|
||||
|
||||
if let Some(desugarer) = desugarer {
|
||||
let ast = desugarer
|
||||
if let Some(yeast_runner) = yeast_runner {
|
||||
let ast = yeast_runner
|
||||
.run_from_tree(&tree, source)
|
||||
.unwrap_or_else(|e| panic!("Desugaring failed for {path_str}: {e}"));
|
||||
traverse_yeast(&ast, &mut visitor);
|
||||
|
||||
@@ -13,14 +13,11 @@ pub struct LanguageSpec {
|
||||
pub prefix: &'static str,
|
||||
pub ts_language: tree_sitter::Language,
|
||||
pub node_types: &'static str,
|
||||
/// Optional desugarer. When set, the parsed tree is rewritten through
|
||||
/// the desugarer before TRAP extraction. The desugarer's
|
||||
/// `output_node_types_yaml()` (if set) provides the schema used both
|
||||
/// at runtime (for the rewriter) and for TRAP validation.
|
||||
///
|
||||
/// `Box<dyn yeast::Desugarer>` so the shared extractor is agnostic to
|
||||
/// the user-defined context type the desugarer uses internally.
|
||||
pub desugar: Option<Box<dyn yeast::Desugarer>>,
|
||||
/// Optional yeast desugaring configuration. When set, the parsed
|
||||
/// tree is rewritten through yeast before TRAP extraction. The
|
||||
/// config's `output_node_types_yaml` (if set) provides the schema
|
||||
/// used both at runtime (for the rewriter) and for TRAP validation.
|
||||
pub desugar: Option<yeast::DesugaringConfig>,
|
||||
pub file_globs: Vec<String>,
|
||||
}
|
||||
|
||||
@@ -94,22 +91,35 @@ impl Extractor {
|
||||
.collect();
|
||||
|
||||
let mut schemas = vec![];
|
||||
let mut yeast_runners = Vec::new();
|
||||
for lang in &self.languages {
|
||||
let effective_node_types: String = match lang
|
||||
.desugar
|
||||
.as_ref()
|
||||
.and_then(|d| d.output_node_types_yaml())
|
||||
{
|
||||
Some(yaml) => yeast::node_types_yaml::convert(yaml).map_err(|e| {
|
||||
std::io::Error::other(format!(
|
||||
"Failed to convert YAML node-types to JSON for {}: {e}",
|
||||
lang.prefix
|
||||
))
|
||||
})?,
|
||||
None => lang.node_types.to_string(),
|
||||
};
|
||||
let effective_node_types: String =
|
||||
match lang.desugar.as_ref().and_then(|c| c.output_node_types_yaml) {
|
||||
Some(yaml) => yeast::node_types_yaml::convert(yaml).map_err(|e| {
|
||||
std::io::Error::other(format!(
|
||||
"Failed to convert YAML node-types to JSON for {}: {e}",
|
||||
lang.prefix
|
||||
))
|
||||
})?,
|
||||
None => lang.node_types.to_string(),
|
||||
};
|
||||
let schema = node_types::read_node_types_str(lang.prefix, &effective_node_types)?;
|
||||
schemas.push(schema);
|
||||
|
||||
// Build the yeast runner once per language so the YAML schema
|
||||
// isn't re-parsed for every file.
|
||||
let yeast_runner = lang
|
||||
.desugar
|
||||
.as_ref()
|
||||
.map(|config| yeast::Runner::from_config(lang.ts_language.clone(), config))
|
||||
.transpose()
|
||||
.map_err(|e| {
|
||||
std::io::Error::other(format!(
|
||||
"Failed to build desugaring runner for {}: {e}",
|
||||
lang.prefix
|
||||
))
|
||||
})?;
|
||||
yeast_runners.push(yeast_runner);
|
||||
}
|
||||
|
||||
// Construct a single globset containing all language globs,
|
||||
@@ -184,7 +194,7 @@ impl Extractor {
|
||||
&path,
|
||||
&source,
|
||||
&[],
|
||||
lang.desugar.as_deref(),
|
||||
yeast_runners[i].as_ref(),
|
||||
);
|
||||
std::fs::create_dir_all(src_archive_file.parent().unwrap())?;
|
||||
std::fs::copy(&path, &src_archive_file)?;
|
||||
|
||||
@@ -159,7 +159,6 @@ pub fn generate(
|
||||
));
|
||||
|
||||
body.append(&mut ql_gen::convert_nodes(&nodes));
|
||||
body.push(ql_gen::create_print_ast_module(&nodes));
|
||||
ql::write(
|
||||
&mut ql_writer,
|
||||
&[ql::TopLevel::Module(ql::Module {
|
||||
|
||||
@@ -150,14 +150,12 @@ impl fmt::Display for Type<'_> {
|
||||
pub enum Expression<'a> {
|
||||
Var(&'a str),
|
||||
String(&'a str),
|
||||
Integer(i64),
|
||||
Integer(usize),
|
||||
Pred(&'a str, Vec<Expression<'a>>),
|
||||
And(Vec<Expression<'a>>),
|
||||
Or(Vec<Expression<'a>>),
|
||||
Equals(Box<Expression<'a>>, Box<Expression<'a>>),
|
||||
Dot(Box<Expression<'a>>, &'a str, Vec<Expression<'a>>),
|
||||
/// A type cast, rendered as `x.(Type)`.
|
||||
Cast(Box<Expression<'a>>, &'a str),
|
||||
Aggregate {
|
||||
name: &'a str,
|
||||
vars: Vec<FormalParameter<'a>>,
|
||||
@@ -221,7 +219,6 @@ impl fmt::Display for Expression<'_> {
|
||||
}
|
||||
write!(f, ")")
|
||||
}
|
||||
Expression::Cast(x, type_name) => write!(f, "{x}.({type_name})"),
|
||||
Expression::Aggregate {
|
||||
name,
|
||||
vars,
|
||||
|
||||
@@ -705,7 +705,7 @@ fn create_field_getters<'a>(
|
||||
),
|
||||
ql::Expression::Equals(
|
||||
Box::new(ql::Expression::Var("value")),
|
||||
Box::new(ql::Expression::Integer(*value as i64)),
|
||||
Box::new(ql::Expression::Integer(*value)),
|
||||
),
|
||||
])
|
||||
})
|
||||
@@ -874,99 +874,3 @@ pub fn convert_nodes(nodes: &node_types::NodeTypeMap) -> Vec<ql::TopLevel<'_>> {
|
||||
|
||||
classes
|
||||
}
|
||||
|
||||
/// Creates a `PrintAst` module containing a `getChild` predicate that maps each
|
||||
/// AST node to its children together with the name of the member predicate that
|
||||
/// produced them (and, for indexed fields, the index). This mirrors the
|
||||
/// information exposed by `getAFieldOrChild`, but keeps the member predicate
|
||||
/// name and index so that an AST printer can render labelled edges.
|
||||
pub fn create_print_ast_module(nodes: &node_types::NodeTypeMap) -> ql::TopLevel<'_> {
|
||||
let mut disjuncts: Vec<ql::Expression> = Vec::new();
|
||||
for node in nodes.values() {
|
||||
if let node_types::EntryKind::Table { name: _, fields } = &node.kind {
|
||||
for field in fields {
|
||||
// `ReservedWordInt` fields have string-valued getters, so they
|
||||
// are not children and are excluded (just as they are from
|
||||
// `getAFieldOrChild`).
|
||||
if matches!(
|
||||
field.type_info,
|
||||
node_types::FieldTypeInfo::ReservedWordInt(_)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
let has_index = matches!(
|
||||
field.storage,
|
||||
node_types::Storage::Table {
|
||||
has_index: true,
|
||||
..
|
||||
}
|
||||
);
|
||||
let getter_call = ql::Expression::Dot(
|
||||
Box::new(ql::Expression::Cast(
|
||||
Box::new(ql::Expression::Var("node")),
|
||||
&node.ql_class_name,
|
||||
)),
|
||||
&field.getter_name,
|
||||
if has_index {
|
||||
vec![ql::Expression::Var("i")]
|
||||
} else {
|
||||
vec![]
|
||||
},
|
||||
);
|
||||
let mut conjuncts = vec![ql::Expression::Equals(
|
||||
Box::new(ql::Expression::Var("result")),
|
||||
Box::new(getter_call),
|
||||
)];
|
||||
if !has_index {
|
||||
conjuncts.push(ql::Expression::Equals(
|
||||
Box::new(ql::Expression::Var("i")),
|
||||
Box::new(ql::Expression::Integer(-1)),
|
||||
));
|
||||
}
|
||||
conjuncts.push(ql::Expression::Equals(
|
||||
Box::new(ql::Expression::Var("name")),
|
||||
Box::new(ql::Expression::String(&field.getter_name)),
|
||||
));
|
||||
disjuncts.push(ql::Expression::And(conjuncts));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let get_child = ql::Predicate {
|
||||
qldoc: Some(String::from(
|
||||
"Gets a child of `node` returned by the member predicate with the given `name`. \
|
||||
If the predicate takes an index argument, `i` is bound to that index, otherwise \
|
||||
`i` is `-1` (which is never a valid index).",
|
||||
)),
|
||||
name: "getChild",
|
||||
overridden: false,
|
||||
is_private: false,
|
||||
is_final: false,
|
||||
return_type: Some(ql::Type::Normal("AstNode")),
|
||||
formal_parameters: vec![
|
||||
ql::FormalParameter {
|
||||
name: "node",
|
||||
param_type: ql::Type::Normal("AstNode"),
|
||||
},
|
||||
ql::FormalParameter {
|
||||
name: "name",
|
||||
param_type: ql::Type::String,
|
||||
},
|
||||
ql::FormalParameter {
|
||||
name: "i",
|
||||
param_type: ql::Type::Int,
|
||||
},
|
||||
],
|
||||
body: ql::Expression::Or(disjuncts),
|
||||
overlay: None,
|
||||
};
|
||||
|
||||
ql::TopLevel::Module(ql::Module {
|
||||
qldoc: Some(String::from(
|
||||
"Provides predicates for mapping AST nodes to their named children.",
|
||||
)),
|
||||
name: "PrintAst",
|
||||
body: vec![ql::TopLevel::Predicate(get_child)],
|
||||
overlay: None,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -121,37 +121,3 @@ pub fn rule(input: TokenStream) -> TokenStream {
|
||||
Err(err) => err.to_compile_error().into(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Define a desugaring rule whose transform is a hand-written Rust block.
|
||||
///
|
||||
/// Use `manual_rule!` when the transform needs control over capture
|
||||
/// translation timing — for example, when an outer rule needs to set
|
||||
/// state in `ctx` (the `BuildCtx`'s user context) before recursive
|
||||
/// translation reaches inner rules that read that state.
|
||||
///
|
||||
/// ```text
|
||||
/// manual_rule!(
|
||||
/// (query_pattern field: (_) @name)
|
||||
/// {
|
||||
/// // `ctx` is a `&mut BuildCtx<'_, C>`; capture variables
|
||||
/// // (`name: NodeRef`, etc.) are bound from the query.
|
||||
/// let translated = ctx.translate(name)?;
|
||||
/// Ok(translated)
|
||||
/// }
|
||||
/// )
|
||||
/// ```
|
||||
///
|
||||
/// Differences from [`rule!`]:
|
||||
/// - Captures are **not** auto-translated before the body runs; they
|
||||
/// refer to raw input-schema nodes. Use [`BuildCtx::translate`] (or
|
||||
/// [`BuildCtx::translate_opt`]) to translate them when you choose.
|
||||
/// - The body is plain Rust returning `Result<Vec<Id>, String>` — no
|
||||
/// tree template, no `Ok(...)` wrap.
|
||||
#[proc_macro]
|
||||
pub fn manual_rule(input: TokenStream) -> TokenStream {
|
||||
let input2: TokenStream2 = input.into();
|
||||
match parse::parse_manual_rule_top(input2) {
|
||||
Ok(output) => output.into(),
|
||||
Err(err) => err.to_compile_error().into(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,9 +121,9 @@ fn parse_query_fields(tokens: &mut Tokens) -> Result<Vec<TokenStream>> {
|
||||
std::collections::HashMap::new();
|
||||
let mut bare_children: Vec<TokenStream> = Vec::new();
|
||||
let push_field_elem = |order: &mut Vec<String>,
|
||||
map: &mut std::collections::HashMap<String, Vec<TokenStream>>,
|
||||
name: String,
|
||||
elem: TokenStream| {
|
||||
map: &mut std::collections::HashMap<String, Vec<TokenStream>>,
|
||||
name: String,
|
||||
elem: TokenStream| {
|
||||
if !map.contains_key(&name) {
|
||||
order.push(name.clone());
|
||||
map.insert(name, vec![elem]);
|
||||
@@ -160,7 +160,8 @@ fn parse_query_fields(tokens: &mut Tokens) -> Result<Vec<TokenStream>> {
|
||||
} else {
|
||||
let child = if peek_is_at(tokens) {
|
||||
tokens.next();
|
||||
let capture_name = expect_ident(tokens, "expected capture name after @")?;
|
||||
let capture_name =
|
||||
expect_ident(tokens, "expected capture name after @")?;
|
||||
let name_str = capture_name.to_string();
|
||||
quote! {
|
||||
yeast::query::QueryNode::Capture {
|
||||
@@ -295,10 +296,10 @@ fn parse_query_list(tokens: &mut Tokens) -> Result<Vec<TokenStream>> {
|
||||
// tree! / trees! parsing — direct code generation against BuildCtx
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const IMPLICIT_CTX: &str = "ctx";
|
||||
const IMPLICIT_CTX: &str = "__yeast_ctx";
|
||||
|
||||
/// Determine the context identifier: either explicit `ctx,` or the implicit
|
||||
/// `ctx` from an enclosing `rule!`.
|
||||
/// `__yeast_ctx` from an enclosing `rule!`.
|
||||
fn parse_ctx_or_implicit(tokens: &mut Tokens) -> Ident {
|
||||
// Check if first token is an ident followed by a comma
|
||||
let mut lookahead = tokens.clone();
|
||||
@@ -358,7 +359,7 @@ fn parse_direct_node(tokens: &mut Tokens, ctx: &Ident) -> Result<TokenStream> {
|
||||
Some(TokenTree::Group(g)) if g.delimiter() == Delimiter::Brace => {
|
||||
let group = expect_group(tokens, Delimiter::Brace)?;
|
||||
let expr = group.stream();
|
||||
Ok(quote! { ::std::convert::Into::<usize>::into({ #expr }) })
|
||||
Ok(quote! { ::std::convert::Into::<usize>::into(#expr) })
|
||||
}
|
||||
Some(TokenTree::Group(g)) if g.delimiter() == Delimiter::Parenthesis => {
|
||||
let group = expect_group(tokens, Delimiter::Parenthesis)?;
|
||||
@@ -395,7 +396,7 @@ fn parse_direct_node_inner(tokens: &mut Tokens, ctx: &Ident) -> Result<TokenStre
|
||||
let expr = group.stream();
|
||||
return Ok(quote! {
|
||||
{
|
||||
let __expr = { #expr };
|
||||
let __expr = (#expr);
|
||||
let __value = yeast::YeastDisplay::yeast_to_string(&__expr, &*#ctx.ast);
|
||||
let __source_range = yeast::YeastSourceRange::yeast_source_range(&__expr, &*#ctx.ast);
|
||||
#ctx.literal_with_source_range(#kind_str, &__value, __source_range)
|
||||
@@ -419,11 +420,7 @@ fn parse_direct_node_inner(tokens: &mut Tokens, ctx: &Ident) -> Result<TokenStre
|
||||
// Named fields — compute each value into a temp, then reference it
|
||||
while peek_is_field(tokens) {
|
||||
let field_name = expect_ident(tokens, "expected field name")?;
|
||||
let field_str = field_name
|
||||
.to_string()
|
||||
.strip_prefix("r#")
|
||||
.unwrap_or(&field_name.to_string())
|
||||
.to_string();
|
||||
let field_str = field_name.to_string().strip_prefix("r#").unwrap_or(&field_name.to_string()).to_string();
|
||||
expect_punct(tokens, ':', "expected `:` after field name")?;
|
||||
let temp = Ident::new(
|
||||
&format!("__field_{field_str}_{field_counter}"),
|
||||
@@ -441,8 +438,7 @@ fn parse_direct_node_inner(tokens: &mut Tokens, ctx: &Ident) -> Result<TokenStre
|
||||
// Determine if a chain (.map(..)) follows the `{}` group.
|
||||
let mut after = tokens.clone();
|
||||
after.next(); // skip the brace group
|
||||
let has_chain =
|
||||
matches!(after.peek(), Some(TokenTree::Punct(p)) if p.as_char() == '.');
|
||||
let has_chain = matches!(after.peek(), Some(TokenTree::Punct(p)) if p.as_char() == '.');
|
||||
|
||||
if is_splice || has_chain {
|
||||
let group = expect_group(tokens, Delimiter::Brace)?;
|
||||
@@ -452,11 +448,11 @@ fn parse_direct_node_inner(tokens: &mut Tokens, ctx: &Ident) -> Result<TokenStre
|
||||
inner.next(); // consume second .
|
||||
let expr: TokenStream = inner.collect();
|
||||
quote! {
|
||||
{ #expr }.into_iter().map(::std::convert::Into::<usize>::into)
|
||||
(#expr).into_iter().map(::std::convert::Into::<usize>::into)
|
||||
}
|
||||
} else {
|
||||
let expr = group.stream();
|
||||
quote! { { #expr }.into_iter() }
|
||||
quote! { (#expr).into_iter() }
|
||||
};
|
||||
let chained = parse_chain_suffix(tokens, ctx, base)?;
|
||||
stmts.push(quote! {
|
||||
@@ -510,7 +506,11 @@ fn parse_direct_node_inner(tokens: &mut Tokens, ctx: &Ident) -> Result<TokenStre
|
||||
/// Each call expects the receiver to be an iterator. The `base` argument
|
||||
/// should therefore already be an iterator (use `.into_iter()` on it before
|
||||
/// calling this function).
|
||||
fn parse_chain_suffix(tokens: &mut Tokens, ctx: &Ident, base: TokenStream) -> Result<TokenStream> {
|
||||
fn parse_chain_suffix(
|
||||
tokens: &mut Tokens,
|
||||
ctx: &Ident,
|
||||
base: TokenStream,
|
||||
) -> Result<TokenStream> {
|
||||
let mut current = base;
|
||||
while matches!(tokens.peek(), Some(TokenTree::Punct(p)) if p.as_char() == '.') {
|
||||
tokens.next(); // consume .
|
||||
@@ -608,8 +608,7 @@ fn parse_direct_list(tokens: &mut Tokens, ctx: &Ident) -> Result<Vec<TokenStream
|
||||
// {expr} or {..expr} (with optional .chain) — single node or splice
|
||||
if peek_is_group(tokens, Delimiter::Brace) {
|
||||
let group = expect_group(tokens, Delimiter::Brace)?;
|
||||
let has_chain =
|
||||
matches!(tokens.peek(), Some(TokenTree::Punct(p)) if p.as_char() == '.');
|
||||
let has_chain = matches!(tokens.peek(), Some(TokenTree::Punct(p)) if p.as_char() == '.');
|
||||
let mut inner = group.stream().into_iter().peekable();
|
||||
let is_splice = peek_is_dotdot(&inner);
|
||||
if is_splice || has_chain {
|
||||
@@ -618,11 +617,11 @@ fn parse_direct_list(tokens: &mut Tokens, ctx: &Ident) -> Result<Vec<TokenStream
|
||||
inner.next(); // consume second .
|
||||
let expr: TokenStream = inner.collect();
|
||||
quote! {
|
||||
{ #expr }.into_iter().map(::std::convert::Into::<usize>::into)
|
||||
(#expr).into_iter().map(::std::convert::Into::<usize>::into)
|
||||
}
|
||||
} else {
|
||||
let expr = group.stream();
|
||||
quote! { { #expr }.into_iter() }
|
||||
quote! { (#expr).into_iter() }
|
||||
};
|
||||
let chained = parse_chain_suffix(tokens, ctx, base)?;
|
||||
items.push(quote! {
|
||||
@@ -631,7 +630,7 @@ fn parse_direct_list(tokens: &mut Tokens, ctx: &Ident) -> Result<Vec<TokenStream
|
||||
} else {
|
||||
let expr = group.stream();
|
||||
items.push(quote! {
|
||||
__nodes.push(::std::convert::Into::<usize>::into({ #expr }));
|
||||
__nodes.push(::std::convert::Into::<usize>::into(#expr));
|
||||
});
|
||||
}
|
||||
continue;
|
||||
@@ -889,117 +888,10 @@ pub fn parse_rule_top(input: TokenStream) -> Result<TokenStream> {
|
||||
Ok(quote! {
|
||||
{
|
||||
let __query = #query_code;
|
||||
yeast::Rule::new(__query, Box::new(|__ast: &mut yeast::Ast, mut __captures: yeast::captures::Captures, __fresh: &yeast::tree_builder::FreshScope, __source_range: Option<tree_sitter::Range>, __user_ctx: &mut _, __translator: yeast::TranslatorHandle<'_, _>| {
|
||||
// Auto-translation prefix: recursively translate every
|
||||
// captured node before invoking the user's transform body.
|
||||
// For OneShot rules this preserves the legacy behaviour
|
||||
// (input-schema captures translated to output-schema
|
||||
// nodes); for Repeating rules it is a no-op.
|
||||
__translator.auto_translate_captures(&mut __captures, __ast, __user_ctx)?;
|
||||
yeast::Rule::new(__query, Box::new(|__ast: &mut yeast::Ast, __captures: yeast::captures::Captures, __fresh: &yeast::tree_builder::FreshScope, __source_range: Option<tree_sitter::Range>| {
|
||||
#(#bindings)*
|
||||
let mut #ctx_ident = yeast::build::BuildCtx::with_translator(__ast, &__captures, __fresh, __source_range, __user_ctx, __translator);
|
||||
let __result: Vec<usize> = { #transform_body };
|
||||
Ok(__result)
|
||||
}))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Parse `manual_rule!( query { body } )`.
|
||||
///
|
||||
/// Like [`parse_rule_top`] but:
|
||||
/// - Expects a Rust block `{ ... }` after the query (no `=>` arrow).
|
||||
/// - Generates code that does NOT auto-translate captures before
|
||||
/// running the body. Capture variables refer to raw (input-schema)
|
||||
/// nodes; the body is responsible for explicit translation via
|
||||
/// `ctx.translate(...)`.
|
||||
/// - The body is included verbatim and must evaluate to
|
||||
/// `Result<Vec<usize>, String>`.
|
||||
pub fn parse_manual_rule_top(input: TokenStream) -> Result<TokenStream> {
|
||||
let mut tokens = input.into_iter().peekable();
|
||||
|
||||
// Collect query tokens up to the body block `{ ... }`.
|
||||
let mut query_tokens = Vec::new();
|
||||
loop {
|
||||
match tokens.peek() {
|
||||
None => {
|
||||
return Err(syn::Error::new(
|
||||
Span::call_site(),
|
||||
"expected a Rust block `{ ... }` after the query in manual_rule!",
|
||||
))
|
||||
}
|
||||
Some(TokenTree::Group(g)) if g.delimiter() == Delimiter::Brace => break,
|
||||
_ => {
|
||||
query_tokens.push(tokens.next().unwrap());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let query_stream: TokenStream = query_tokens.into_iter().collect();
|
||||
|
||||
// Extract captures from the query (same as in `rule!`).
|
||||
let captures = extract_captures(&query_stream);
|
||||
|
||||
// Parse the query into the QueryNode-building expression.
|
||||
let query_code = parse_query_top(query_stream)?;
|
||||
|
||||
// Generate capture bindings (same as in `rule!`).
|
||||
let ctx_ident = Ident::new(IMPLICIT_CTX, Span::call_site());
|
||||
let bindings: Vec<TokenStream> = captures
|
||||
.iter()
|
||||
.map(|cap| {
|
||||
let name = Ident::new(&cap.name, Span::call_site());
|
||||
let name_str = &cap.name;
|
||||
match cap.multiplicity {
|
||||
CaptureMultiplicity::Repeated => quote! {
|
||||
let #name: Vec<yeast::NodeRef> = __captures.get_all(#name_str)
|
||||
.into_iter()
|
||||
.map(yeast::NodeRef)
|
||||
.collect();
|
||||
},
|
||||
CaptureMultiplicity::Optional => quote! {
|
||||
let #name: Option<yeast::NodeRef> =
|
||||
__captures.get_opt(#name_str).map(yeast::NodeRef);
|
||||
},
|
||||
CaptureMultiplicity::Single => quote! {
|
||||
let #name: yeast::NodeRef =
|
||||
yeast::NodeRef(__captures.get_var(#name_str).unwrap());
|
||||
},
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
// Consume the body block.
|
||||
let body_group = match tokens.next() {
|
||||
Some(TokenTree::Group(g)) if g.delimiter() == Delimiter::Brace => g,
|
||||
other => {
|
||||
return Err(syn::Error::new(
|
||||
Span::call_site(),
|
||||
format!(
|
||||
"expected a Rust block `{{ ... }}` after the query in manual_rule!, found: {other:?}"
|
||||
),
|
||||
))
|
||||
}
|
||||
};
|
||||
let body_stream = body_group.stream();
|
||||
|
||||
// No tokens should follow the body.
|
||||
if let Some(tok) = tokens.next() {
|
||||
return Err(syn::Error::new_spanned(
|
||||
tok,
|
||||
"unexpected token after manual_rule! body",
|
||||
));
|
||||
}
|
||||
|
||||
Ok(quote! {
|
||||
{
|
||||
let __query = #query_code;
|
||||
yeast::Rule::new(__query, Box::new(|__ast: &mut yeast::Ast, __captures: yeast::captures::Captures, __fresh: &yeast::tree_builder::FreshScope, __source_range: Option<tree_sitter::Range>, __user_ctx: &mut _, __translator: yeast::TranslatorHandle<'_, _>| {
|
||||
// No auto-translate prefix for manual rules — the body
|
||||
// is responsible for translating captures explicitly.
|
||||
#(#bindings)*
|
||||
let mut #ctx_ident = yeast::build::BuildCtx::with_translator(__ast, &__captures, __fresh, __source_range, __user_ctx, __translator);
|
||||
#body_stream
|
||||
let mut #ctx_ident = yeast::build::BuildCtx::with_source_range(__ast, &__captures, __fresh, __source_range);
|
||||
#transform_body
|
||||
}))
|
||||
}
|
||||
})
|
||||
|
||||
@@ -265,21 +265,7 @@ occurrences of the same `$name` within one `BuildCtx` share the same value:
|
||||
)
|
||||
```
|
||||
|
||||
The contents of `{…}` are treated as a Rust block, so multi-statement
|
||||
expressions (with `let` bindings) work too:
|
||||
|
||||
```rust
|
||||
(assignment
|
||||
left: {tmp}
|
||||
right: {
|
||||
let lit = ctx.literal("integer", "0");
|
||||
tree!((binary_expr op: (operator "+") left: {tmp} right: {lit}))
|
||||
})
|
||||
```
|
||||
|
||||
`{..expr}` splices a `Vec<Id>` (or any iterable of `Id`); the contents
|
||||
are likewise a Rust block, so the splice can be the result of arbitrary
|
||||
computation:
|
||||
`{..expr}` splices a `Vec<Id>` (or any iterable of `Id`):
|
||||
|
||||
```rust
|
||||
yeast::trees!(ctx,
|
||||
|
||||
@@ -20,7 +20,7 @@ fn main() {
|
||||
let args = Cli::parse();
|
||||
let language = get_language(&args.language);
|
||||
let source = std::fs::read_to_string(&args.file).unwrap();
|
||||
let runner: yeast::Runner = yeast::Runner::new(language, &[]);
|
||||
let runner = yeast::Runner::new(language, &[]);
|
||||
let ast = runner.run(&source).unwrap();
|
||||
println!("{}", ast.print(&source, ast.get_root()));
|
||||
}
|
||||
|
||||
@@ -2,60 +2,28 @@ use std::collections::BTreeMap;
|
||||
|
||||
use crate::captures::Captures;
|
||||
use crate::tree_builder::FreshScope;
|
||||
use crate::{Ast, FieldId, Id, NodeContent, TranslatorHandle};
|
||||
use crate::{Ast, FieldId, Id, NodeContent};
|
||||
|
||||
/// Context for building new AST nodes during a transformation.
|
||||
///
|
||||
/// Used by the `tree!` and `trees!` macros. Holds a mutable reference to the
|
||||
/// AST, a reference to the captures from a query match, a `FreshScope` for
|
||||
/// generating unique identifiers, and a mutable reference to a user-defined
|
||||
/// context of type `C`.
|
||||
///
|
||||
/// The user context `C` is shared across rules via the framework's driver:
|
||||
/// outer rules can write to it before recursive translation, and inner rules
|
||||
/// can read (or further mutate) it during their transforms. The framework
|
||||
/// snapshots and restores the user context around each rule application, so
|
||||
/// mutations made by a rule are visible to its descendants (via recursive
|
||||
/// translation) but not to its parent's siblings.
|
||||
///
|
||||
/// `BuildCtx` implements [`Deref`] and [`DerefMut`] targeting `C`, so user
|
||||
/// context fields are accessible as `ctx.my_field` directly (provided they
|
||||
/// don't collide with `BuildCtx`'s own fields like `ast`, `captures`, etc.).
|
||||
///
|
||||
/// The default `C = ()` means rules that don't need any user context don't
|
||||
/// pay any cost.
|
||||
///
|
||||
/// When constructed by the framework (via the rule! macro), `BuildCtx` also
|
||||
/// carries a [`TranslatorHandle`] that the [`translate`] method delegates
|
||||
/// to. When constructed by hand (e.g. in tests), the translator is `None`
|
||||
/// and [`translate`] returns an error.
|
||||
pub struct BuildCtx<'a, C: 'a = ()> {
|
||||
/// AST, a reference to the captures from a query match, and a `FreshScope` for
|
||||
/// generating unique identifiers.
|
||||
pub struct BuildCtx<'a> {
|
||||
pub ast: &'a mut Ast,
|
||||
pub captures: &'a Captures,
|
||||
pub fresh: &'a FreshScope,
|
||||
/// Source range of the matched node, inherited by synthetic nodes.
|
||||
pub source_range: Option<tree_sitter::Range>,
|
||||
/// User-supplied context, accessible directly via `ctx.field` (via Deref).
|
||||
pub user_ctx: &'a mut C,
|
||||
/// Optional translator handle, populated when the context is built by
|
||||
/// the framework's rule driver. None when the context is built by hand.
|
||||
pub(crate) translator: Option<TranslatorHandle<'a, C>>,
|
||||
}
|
||||
|
||||
impl<'a, C> BuildCtx<'a, C> {
|
||||
pub fn new(
|
||||
ast: &'a mut Ast,
|
||||
captures: &'a Captures,
|
||||
fresh: &'a FreshScope,
|
||||
user_ctx: &'a mut C,
|
||||
) -> Self {
|
||||
impl<'a> BuildCtx<'a> {
|
||||
pub fn new(ast: &'a mut Ast, captures: &'a Captures, fresh: &'a FreshScope) -> Self {
|
||||
Self {
|
||||
ast,
|
||||
captures,
|
||||
fresh,
|
||||
source_range: None,
|
||||
user_ctx,
|
||||
translator: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,35 +32,12 @@ impl<'a, C> BuildCtx<'a, C> {
|
||||
captures: &'a Captures,
|
||||
fresh: &'a FreshScope,
|
||||
source_range: Option<tree_sitter::Range>,
|
||||
user_ctx: &'a mut C,
|
||||
) -> Self {
|
||||
Self {
|
||||
ast,
|
||||
captures,
|
||||
fresh,
|
||||
source_range,
|
||||
user_ctx,
|
||||
translator: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Construct a `BuildCtx` carrying a translator handle. Used by the
|
||||
/// `rule!` macro to enable [`translate`] inside rule transforms.
|
||||
pub fn with_translator(
|
||||
ast: &'a mut Ast,
|
||||
captures: &'a Captures,
|
||||
fresh: &'a FreshScope,
|
||||
source_range: Option<tree_sitter::Range>,
|
||||
user_ctx: &'a mut C,
|
||||
translator: TranslatorHandle<'a, C>,
|
||||
) -> Self {
|
||||
Self {
|
||||
ast,
|
||||
captures,
|
||||
fresh,
|
||||
source_range,
|
||||
user_ctx,
|
||||
translator: Some(translator),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,52 +113,3 @@ impl<'a, C> BuildCtx<'a, C> {
|
||||
self.ast.prepend_field_child(node_id, field_id, value_id);
|
||||
}
|
||||
}
|
||||
|
||||
impl<C: Clone> BuildCtx<'_, C> {
|
||||
/// Recursively translate a node via the framework's rule machinery.
|
||||
/// In a OneShot phase, applies OneShot rules to the given node and
|
||||
/// returns the resulting node ids. In a Repeating phase, errors
|
||||
/// (translation is not meaningful when input and output share a
|
||||
/// schema).
|
||||
///
|
||||
/// Accepts any value convertible to [`Id`] (including [`crate::NodeRef`]),
|
||||
/// so manual rules can pass capture bindings directly without unwrapping.
|
||||
///
|
||||
/// Errors if this `BuildCtx` was constructed by hand (without a
|
||||
/// translator handle) — for example, in unit tests that don't go
|
||||
/// through the rule driver.
|
||||
pub fn translate<I: Into<Id>>(&mut self, id: I) -> Result<Vec<Id>, String> {
|
||||
let id = id.into();
|
||||
match &self.translator {
|
||||
Some(t) => t.translate(self.ast, self.user_ctx, id),
|
||||
None => Err("translate() called on a BuildCtx without a translator handle".into()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Translate an optional capture, returning the first translated id or
|
||||
/// `None`. Convenience for `?`-quantifier captures (`Option<NodeRef>`).
|
||||
///
|
||||
/// If the underlying translation produces multiple ids for a single
|
||||
/// input, only the first is returned. For most use cases (e.g.
|
||||
/// translating a single type annotation) this is what you want; if
|
||||
/// you need all ids, use [`translate`] directly.
|
||||
pub fn translate_opt<I: Into<Id>>(&mut self, id: Option<I>) -> Result<Option<Id>, String> {
|
||||
match id {
|
||||
Some(id) => Ok(self.translate(id)?.into_iter().next()),
|
||||
None => Ok(None),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<C> std::ops::Deref for BuildCtx<'_, C> {
|
||||
type Target = C;
|
||||
fn deref(&self) -> &C {
|
||||
&*self.user_ctx
|
||||
}
|
||||
}
|
||||
|
||||
impl<C> std::ops::DerefMut for BuildCtx<'_, C> {
|
||||
fn deref_mut(&mut self) -> &mut C {
|
||||
&mut *self.user_ctx
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,12 @@ pub fn dump_ast_with_options(
|
||||
///
|
||||
/// Any node that does not match the expected type set for its parent field is
|
||||
/// rendered with a trailing `" <-- ERROR: ..."` annotation on the same line.
|
||||
pub fn dump_ast_with_type_errors(ast: &Ast, root: usize, source: &str, schema: &Schema) -> String {
|
||||
pub fn dump_ast_with_type_errors(
|
||||
ast: &Ast,
|
||||
root: usize,
|
||||
source: &str,
|
||||
schema: &Schema,
|
||||
) -> String {
|
||||
dump_ast_with_type_errors_and_options(ast, root, source, schema, &DumpOptions::default())
|
||||
}
|
||||
|
||||
@@ -69,15 +74,7 @@ pub fn dump_ast_with_type_errors_and_options(
|
||||
options: &DumpOptions,
|
||||
) -> String {
|
||||
let mut out = String::new();
|
||||
dump_node(
|
||||
ast,
|
||||
root,
|
||||
source,
|
||||
options,
|
||||
0,
|
||||
Some((schema, None, None)),
|
||||
&mut out,
|
||||
);
|
||||
dump_node(ast, root, source, options, 0, Some((schema, None, None)), &mut out);
|
||||
out
|
||||
}
|
||||
|
||||
@@ -235,8 +232,8 @@ fn dump_node(
|
||||
}
|
||||
let field_name = ast.field_name_for_id(field_id).unwrap_or("?");
|
||||
let child_type_check = type_check.map(|(schema, _, _)| {
|
||||
let expected =
|
||||
expected_for_field(schema, node.kind_name(), field_id).or(Some(EMPTY_NODE_TYPES));
|
||||
let expected = expected_for_field(schema, node.kind_name(), field_id)
|
||||
.or(Some(EMPTY_NODE_TYPES));
|
||||
let parent_field = Some((node.kind_name(), field_name));
|
||||
(schema, expected, parent_field)
|
||||
});
|
||||
|
||||
@@ -16,7 +16,7 @@ pub mod schema;
|
||||
pub mod tree_builder;
|
||||
mod visitor;
|
||||
|
||||
pub use yeast_macros::{manual_rule, query, rule, tree, trees};
|
||||
pub use yeast_macros::{query, rule, tree, trees};
|
||||
|
||||
use captures::Captures;
|
||||
pub use cursor::Cursor;
|
||||
@@ -297,9 +297,7 @@ impl Ast {
|
||||
/// Returns the source text for `id`, resolving `NodeContent::Range`
|
||||
/// against the stored source bytes when available.
|
||||
pub fn source_text(&self, id: Id) -> String {
|
||||
let Some(node) = self.get_node(id) else {
|
||||
return String::new();
|
||||
};
|
||||
let Some(node) = self.get_node(id) else { return String::new(); };
|
||||
let read_range = |range: &tree_sitter::Range| {
|
||||
let start = range.start_byte;
|
||||
let end = range.end_byte;
|
||||
@@ -490,10 +488,7 @@ impl Ast {
|
||||
|
||||
/// Prepend a child id to the given field of the given node.
|
||||
pub fn prepend_field_child(&mut self, node_id: Id, field_id: FieldId, value_id: Id) {
|
||||
let node = self
|
||||
.nodes
|
||||
.get_mut(node_id)
|
||||
.expect("prepend_field_child: invalid node id");
|
||||
let node = self.nodes.get_mut(node_id).expect("prepend_field_child: invalid node id");
|
||||
node.fields.entry(field_id).or_default().insert(0, value_id);
|
||||
}
|
||||
|
||||
@@ -705,118 +700,18 @@ impl From<tree_sitter::Range> for NodeContent {
|
||||
}
|
||||
}
|
||||
|
||||
/// A handle that lets a rule transform recursively translate AST nodes via
|
||||
/// the framework's rule machinery. Constructed by the driver and passed as
|
||||
/// the last argument of every [`Transform`] invocation.
|
||||
///
|
||||
/// The `rule!` macro uses [`TranslatorHandle::auto_translate_captures`] in
|
||||
/// its generated prefix to translate captures before running the user's
|
||||
/// transform body. Manually-written transforms (using [`Rule::new`]
|
||||
/// directly) can call [`TranslatorHandle::translate`] selectively on
|
||||
/// specific node ids to control when translation happens.
|
||||
pub struct TranslatorHandle<'a, C> {
|
||||
inner: TranslatorImpl<'a, C>,
|
||||
}
|
||||
|
||||
/// Internal phase-specific translation state. Kept private — callers
|
||||
/// interact with [`TranslatorHandle`] only.
|
||||
enum TranslatorImpl<'a, C> {
|
||||
/// OneShot phase translator: recursively applies OneShot rules.
|
||||
OneShot {
|
||||
index: &'a RuleIndex<'a, C>,
|
||||
fresh: &'a tree_builder::FreshScope,
|
||||
rewrite_depth: usize,
|
||||
/// The id of the node the current rule is matching. Used by
|
||||
/// [`auto_translate_captures`] to avoid infinite recursion when a
|
||||
/// rule captures its own match root (e.g. via `(_) @_`).
|
||||
matched_root: Id,
|
||||
},
|
||||
/// Repeating phase translator: translation is not meaningful here
|
||||
/// (input and output schemas are the same). [`translate`] errors;
|
||||
/// [`auto_translate_captures`] is a no-op so the macro's auto-prefix
|
||||
/// works unchanged for Repeating rules.
|
||||
Repeating,
|
||||
}
|
||||
|
||||
impl<'a, C: Clone> TranslatorHandle<'a, C> {
|
||||
/// Recursively apply OneShot rules to `id` and return the resulting
|
||||
/// node ids. Errors in a Repeating phase (where translation is not
|
||||
/// meaningful).
|
||||
pub fn translate(&self, ast: &mut Ast, user_ctx: &mut C, id: Id) -> Result<Vec<Id>, String> {
|
||||
match &self.inner {
|
||||
TranslatorImpl::OneShot {
|
||||
index,
|
||||
fresh,
|
||||
rewrite_depth,
|
||||
..
|
||||
} => apply_one_shot_rules_inner(index, ast, user_ctx, id, fresh, rewrite_depth + 1),
|
||||
TranslatorImpl::Repeating => {
|
||||
Err("translate() is not available in a Repeating phase".into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Translate every captured node in `captures` in place (OneShot phase
|
||||
/// only). In a Repeating phase this is a no-op — Repeating rules
|
||||
/// receive raw captures.
|
||||
///
|
||||
/// Used by the `rule!` macro's generated prefix to preserve the
|
||||
/// pre-existing "auto-translate captures before running the transform
|
||||
/// body" behavior. Manually-written transforms typically translate
|
||||
/// captures selectively via [`translate`] instead.
|
||||
///
|
||||
/// To avoid infinite recursion, a capture whose id matches the rule's
|
||||
/// matched root (e.g. from a `(_) @_` pattern) is left unchanged.
|
||||
pub fn auto_translate_captures(
|
||||
&self,
|
||||
captures: &mut Captures,
|
||||
ast: &mut Ast,
|
||||
user_ctx: &mut C,
|
||||
) -> Result<(), String> {
|
||||
match &self.inner {
|
||||
TranslatorImpl::OneShot { matched_root, .. } => {
|
||||
let root = *matched_root;
|
||||
captures.try_map_all_captures(|cid| {
|
||||
if cid == root {
|
||||
Ok(vec![cid])
|
||||
} else {
|
||||
self.translate(ast, user_ctx, cid)
|
||||
}
|
||||
})
|
||||
}
|
||||
TranslatorImpl::Repeating => Ok(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The transform function for a rule.
|
||||
///
|
||||
/// Takes the AST, the (raw, untranslated) captured variables, a fresh-name
|
||||
/// scope, the source range of the matched node, a mutable reference to the
|
||||
/// user context of type `C`, and a [`TranslatorHandle`] for recursively
|
||||
/// translating nodes. Returns the IDs of the replacement nodes, or an
|
||||
/// error message if the transform could not be completed.
|
||||
///
|
||||
/// Transforms produced by [`Rule::new`] receive **raw** captures and must
|
||||
/// translate them themselves (via the handle). Transforms produced by the
|
||||
/// `rule!` macro have an auto-translation prefix injected for backward
|
||||
/// compatibility.
|
||||
pub type Transform<C = ()> = Box<
|
||||
dyn Fn(
|
||||
&mut Ast,
|
||||
Captures,
|
||||
&tree_builder::FreshScope,
|
||||
Option<tree_sitter::Range>,
|
||||
&mut C,
|
||||
TranslatorHandle<'_, C>,
|
||||
) -> Result<Vec<Id>, String>
|
||||
/// The transform function for a rule: takes the AST, captured variables, a
|
||||
/// fresh-name scope, and the source range of the matched node, and returns
|
||||
/// the IDs of the replacement nodes.
|
||||
pub type Transform = Box<
|
||||
dyn Fn(&mut Ast, Captures, &tree_builder::FreshScope, Option<tree_sitter::Range>) -> Vec<Id>
|
||||
+ Send
|
||||
+ Sync,
|
||||
>;
|
||||
|
||||
pub struct Rule<C = ()> {
|
||||
pub struct Rule {
|
||||
query: QueryNode,
|
||||
transform: Transform<C>,
|
||||
transform: Transform,
|
||||
/// If true, after this rule fires on a node the engine will try to
|
||||
/// re-apply this same rule on the result root. Defaults to false:
|
||||
/// each rule fires at most once on a given node, which prevents
|
||||
@@ -824,8 +719,8 @@ pub struct Rule<C = ()> {
|
||||
repeated: bool,
|
||||
}
|
||||
|
||||
impl<C> Rule<C> {
|
||||
pub fn new(query: QueryNode, transform: Transform<C>) -> Self {
|
||||
impl Rule {
|
||||
pub fn new(query: QueryNode, transform: Transform) -> Self {
|
||||
Self {
|
||||
query,
|
||||
transform,
|
||||
@@ -847,13 +742,9 @@ impl<C> Rule<C> {
|
||||
ast: &mut Ast,
|
||||
node: Id,
|
||||
fresh: &tree_builder::FreshScope,
|
||||
user_ctx: &mut C,
|
||||
translator: TranslatorHandle<'_, C>,
|
||||
) -> Result<Option<Vec<Id>>, String> {
|
||||
match self.try_match(ast, node)? {
|
||||
Some(captures) => Ok(Some(
|
||||
self.run_transform(ast, captures, node, fresh, user_ctx, translator)?,
|
||||
)),
|
||||
Some(captures) => Ok(Some(self.run_transform(ast, captures, node, fresh))),
|
||||
None => Ok(None),
|
||||
}
|
||||
}
|
||||
@@ -877,31 +768,29 @@ impl<C> Rule<C> {
|
||||
captures: Captures,
|
||||
node: Id,
|
||||
fresh: &tree_builder::FreshScope,
|
||||
user_ctx: &mut C,
|
||||
translator: TranslatorHandle<'_, C>,
|
||||
) -> Result<Vec<Id>, String> {
|
||||
) -> Vec<Id> {
|
||||
fresh.next_scope();
|
||||
let source_range = ast.get_node(node).and_then(|n| match n.content {
|
||||
NodeContent::Range(r) => Some(r),
|
||||
_ => n.source_range,
|
||||
});
|
||||
(self.transform)(ast, captures, fresh, source_range, user_ctx, translator)
|
||||
(self.transform)(ast, captures, fresh, source_range)
|
||||
}
|
||||
}
|
||||
|
||||
const MAX_REWRITE_DEPTH: usize = 100;
|
||||
|
||||
/// Index of rules by their root query kind for fast lookup.
|
||||
struct RuleIndex<'a, C> {
|
||||
struct RuleIndex<'a> {
|
||||
/// Rules indexed by root node kind name.
|
||||
by_kind: BTreeMap<&'static str, Vec<&'a Rule<C>>>,
|
||||
by_kind: BTreeMap<&'static str, Vec<&'a Rule>>,
|
||||
/// Rules with wildcard queries (Any) that apply to all nodes.
|
||||
wildcard: Vec<&'a Rule<C>>,
|
||||
wildcard: Vec<&'a Rule>,
|
||||
}
|
||||
|
||||
impl<'a, C> RuleIndex<'a, C> {
|
||||
fn new(rules: &'a [Rule<C>]) -> Self {
|
||||
let mut by_kind: BTreeMap<&'static str, Vec<&'a Rule<C>>> = BTreeMap::new();
|
||||
impl<'a> RuleIndex<'a> {
|
||||
fn new(rules: &'a [Rule]) -> Self {
|
||||
let mut by_kind: BTreeMap<&'static str, Vec<&'a Rule>> = BTreeMap::new();
|
||||
let mut wildcard = Vec::new();
|
||||
for rule in rules {
|
||||
match rule.query.root_kind() {
|
||||
@@ -912,7 +801,7 @@ impl<'a, C> RuleIndex<'a, C> {
|
||||
Self { by_kind, wildcard }
|
||||
}
|
||||
|
||||
fn rules_for_kind(&self, kind: &str) -> impl Iterator<Item = &&'a Rule<C>> {
|
||||
fn rules_for_kind(&self, kind: &str) -> impl Iterator<Item = &&'a Rule> {
|
||||
self.by_kind
|
||||
.get(kind)
|
||||
.into_iter()
|
||||
@@ -921,25 +810,23 @@ impl<'a, C> RuleIndex<'a, C> {
|
||||
}
|
||||
}
|
||||
|
||||
fn apply_repeating_rules<C: Clone>(
|
||||
rules: &[Rule<C>],
|
||||
fn apply_repeating_rules(
|
||||
rules: &[Rule],
|
||||
ast: &mut Ast,
|
||||
user_ctx: &mut C,
|
||||
id: Id,
|
||||
fresh: &tree_builder::FreshScope,
|
||||
) -> Result<Vec<Id>, String> {
|
||||
let index = RuleIndex::new(rules);
|
||||
apply_repeating_rules_inner(&index, ast, user_ctx, id, fresh, 0, None)
|
||||
apply_repeating_rules_inner(&index, ast, id, fresh, 0, None)
|
||||
}
|
||||
|
||||
fn apply_repeating_rules_inner<C: Clone>(
|
||||
index: &RuleIndex<C>,
|
||||
fn apply_repeating_rules_inner(
|
||||
index: &RuleIndex,
|
||||
ast: &mut Ast,
|
||||
user_ctx: &mut C,
|
||||
id: Id,
|
||||
fresh: &tree_builder::FreshScope,
|
||||
rewrite_depth: usize,
|
||||
skip_rule: Option<*const Rule<C>>,
|
||||
skip_rule: Option<*const Rule>,
|
||||
) -> Result<Vec<Id>, String> {
|
||||
if rewrite_depth > MAX_REWRITE_DEPTH {
|
||||
return Err(format!(
|
||||
@@ -950,23 +837,11 @@ fn apply_repeating_rules_inner<C: Clone>(
|
||||
|
||||
let node_kind = ast.get_node(id).map(|n| n.kind()).unwrap_or("");
|
||||
for rule in index.rules_for_kind(node_kind) {
|
||||
let rule_ptr = *rule as *const Rule<C>;
|
||||
let rule_ptr = *rule as *const Rule;
|
||||
if Some(rule_ptr) == skip_rule {
|
||||
continue;
|
||||
}
|
||||
// Snapshot the user context before invoking the rule so that any
|
||||
// mutations the rule makes are visible during recursive translation
|
||||
// of its result, but not leaked to the parent's siblings.
|
||||
let snapshot = user_ctx.clone();
|
||||
// Repeating rules don't need a real translator: their captures
|
||||
// aren't auto-translated (Repeating preserves the input schema),
|
||||
// and `ctx.translate(id)` errors if invoked from a Repeating
|
||||
// transform.
|
||||
let translator = TranslatorHandle {
|
||||
inner: TranslatorImpl::Repeating,
|
||||
};
|
||||
let try_result = rule.try_rule(ast, id, fresh, user_ctx, translator)?;
|
||||
if let Some(result_node) = try_result {
|
||||
if let Some(result_node) = rule.try_rule(ast, id, fresh)? {
|
||||
// For non-repeated rules, suppress further application of *this*
|
||||
// rule on the result root, so a rule whose output matches its own
|
||||
// query doesn't loop. Other rules and child traversal are
|
||||
@@ -977,19 +852,14 @@ fn apply_repeating_rules_inner<C: Clone>(
|
||||
results.extend(apply_repeating_rules_inner(
|
||||
index,
|
||||
ast,
|
||||
user_ctx,
|
||||
node,
|
||||
fresh,
|
||||
rewrite_depth + 1,
|
||||
next_skip,
|
||||
)?);
|
||||
}
|
||||
*user_ctx = snapshot;
|
||||
return Ok(results);
|
||||
}
|
||||
// Rule didn't match; restore any speculative changes (none expected
|
||||
// since try_rule only mutates on match, but be defensive).
|
||||
*user_ctx = snapshot;
|
||||
}
|
||||
|
||||
// Take the parent's fields by ownership: the recursion will rewrite
|
||||
@@ -1004,15 +874,7 @@ fn apply_repeating_rules_inner<C: Clone>(
|
||||
for children in fields.values_mut() {
|
||||
let mut new_children: Option<Vec<Id>> = None;
|
||||
for (i, &child_id) in children.iter().enumerate() {
|
||||
let result = apply_repeating_rules_inner(
|
||||
index,
|
||||
ast,
|
||||
user_ctx,
|
||||
child_id,
|
||||
fresh,
|
||||
rewrite_depth,
|
||||
None,
|
||||
)?;
|
||||
let result = apply_repeating_rules_inner(index, ast, child_id, fresh, rewrite_depth, None)?;
|
||||
let unchanged = result.len() == 1 && result[0] == child_id;
|
||||
match (&mut new_children, unchanged) {
|
||||
(None, true) => {} // unchanged so far, no allocation needed
|
||||
@@ -1041,25 +903,24 @@ fn apply_repeating_rules_inner<C: Clone>(
|
||||
/// each visited node, recursion proceeds only through captured nodes (not
|
||||
/// through the input node's children directly), and an error is returned if
|
||||
/// no rule matches a visited node.
|
||||
fn apply_one_shot_rules<C: Clone>(
|
||||
rules: &[Rule<C>],
|
||||
fn apply_one_shot_rules(
|
||||
rules: &[Rule],
|
||||
ast: &mut Ast,
|
||||
user_ctx: &mut C,
|
||||
id: Id,
|
||||
fresh: &tree_builder::FreshScope,
|
||||
) -> Result<Vec<Id>, String> {
|
||||
let index = RuleIndex::new(rules);
|
||||
apply_one_shot_rules_inner(&index, ast, user_ctx, id, fresh, 0)
|
||||
apply_one_shot_rules_inner(&index, ast, id, fresh, 0)
|
||||
}
|
||||
|
||||
fn apply_one_shot_rules_inner<C: Clone>(
|
||||
index: &RuleIndex<C>,
|
||||
fn apply_one_shot_rules_inner(
|
||||
index: &RuleIndex,
|
||||
ast: &mut Ast,
|
||||
user_ctx: &mut C,
|
||||
id: Id,
|
||||
fresh: &tree_builder::FreshScope,
|
||||
rewrite_depth: usize,
|
||||
) -> Result<Vec<Id>, String> {
|
||||
|
||||
if rewrite_depth > MAX_REWRITE_DEPTH {
|
||||
return Err(format!(
|
||||
"Desugaring exceeded maximum rewrite depth ({MAX_REWRITE_DEPTH}). \
|
||||
@@ -1070,27 +931,22 @@ fn apply_one_shot_rules_inner<C: Clone>(
|
||||
let node_kind = ast.get_node(id).map(|n| n.kind()).unwrap_or("");
|
||||
|
||||
for rule in index.rules_for_kind(node_kind) {
|
||||
if let Some(captures) = rule.try_match(ast, id)? {
|
||||
// Snapshot the user context before invoking the rule so that any
|
||||
// mutations the rule (or its transitively-translated captures)
|
||||
// make are visible during this rule's transform, but not leaked
|
||||
// to the parent's siblings.
|
||||
let snapshot = user_ctx.clone();
|
||||
// Build the translator handle the transform will use to
|
||||
// recursively translate captures (or, for macro-generated
|
||||
// rules, the auto-translate prefix uses it to translate every
|
||||
// capture up front, preserving the legacy behavior).
|
||||
let translator = TranslatorHandle {
|
||||
inner: TranslatorImpl::OneShot {
|
||||
index,
|
||||
fresh,
|
||||
rewrite_depth,
|
||||
matched_root: id,
|
||||
},
|
||||
};
|
||||
let result = rule.run_transform(ast, captures, id, fresh, user_ctx, translator)?;
|
||||
*user_ctx = snapshot;
|
||||
return Ok(result);
|
||||
if let Some(mut captures) = rule.try_match(ast, id)? {
|
||||
// Recursively translate every captured node before invoking the
|
||||
// transform. The transform's output uses output-schema kinds, so
|
||||
// we must translate captured input-schema nodes to their
|
||||
// output-schema equivalents first.
|
||||
captures.try_map_all_captures(|captured_id| {
|
||||
// Avoid infinite recursion when a capture refers to the root
|
||||
// node of the matched tree (e.g. an `@_` capture on the
|
||||
// pattern root): re-analyzing it would match the same rule
|
||||
// again indefinitely.
|
||||
if captured_id == id {
|
||||
return Ok(vec![captured_id]);
|
||||
}
|
||||
apply_one_shot_rules_inner(index, ast, captured_id, fresh, rewrite_depth + 1)
|
||||
})?;
|
||||
return Ok(rule.run_transform(ast, captures, id, fresh));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1118,15 +974,15 @@ pub enum PhaseKind {
|
||||
/// starts. Rules within a phase compete for matches as usual; rules in
|
||||
/// different phases never compete because each traversal only considers the
|
||||
/// current phase's rules.
|
||||
pub struct Phase<C = ()> {
|
||||
pub struct Phase {
|
||||
/// Name used in error messages.
|
||||
pub name: String,
|
||||
pub rules: Vec<Rule<C>>,
|
||||
pub rules: Vec<Rule>,
|
||||
pub kind: PhaseKind,
|
||||
}
|
||||
|
||||
impl<C> Phase<C> {
|
||||
pub fn new(name: impl Into<String>, kind: PhaseKind, rules: Vec<Rule<C>>) -> Self {
|
||||
impl Phase {
|
||||
pub fn new(name: impl Into<String>, kind: PhaseKind, rules: Vec<Rule>) -> Self {
|
||||
Self {
|
||||
name: name.into(),
|
||||
rules,
|
||||
@@ -1152,30 +1008,17 @@ impl<C> Phase<C> {
|
||||
/// .add_phase("desugar", PhaseKind::Repeating, desugar_rules)
|
||||
/// .with_output_node_types_yaml(yaml);
|
||||
/// ```
|
||||
///
|
||||
/// The optional type parameter `C` is the user context type threaded through
|
||||
/// rule transforms. Defaults to `()` (no user context).
|
||||
pub struct DesugaringConfig<C = ()> {
|
||||
#[derive(Default)]
|
||||
pub struct DesugaringConfig {
|
||||
/// Phases of rule application, applied in order.
|
||||
pub phases: Vec<Phase<C>>,
|
||||
pub phases: Vec<Phase>,
|
||||
/// Output node-types in YAML format. If `None`, the input grammar's
|
||||
/// node types are used (i.e. the desugared AST has the same node types
|
||||
/// as the tree-sitter grammar).
|
||||
pub output_node_types_yaml: Option<&'static str>,
|
||||
}
|
||||
|
||||
// Manual `Default` impl so users with a custom `C` that doesn't implement
|
||||
// `Default` can still construct an empty config.
|
||||
impl<C> Default for DesugaringConfig<C> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
phases: Vec::new(),
|
||||
output_node_types_yaml: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<C> DesugaringConfig<C> {
|
||||
impl DesugaringConfig {
|
||||
/// Create an empty configuration. Add phases via [`add_phase`] and an
|
||||
/// optional output schema via [`with_output_node_types_yaml`].
|
||||
pub fn new() -> Self {
|
||||
@@ -1187,7 +1030,7 @@ impl<C> DesugaringConfig<C> {
|
||||
mut self,
|
||||
name: impl Into<String>,
|
||||
kind: PhaseKind,
|
||||
rules: Vec<Rule<C>>,
|
||||
rules: Vec<Rule>,
|
||||
) -> Self {
|
||||
self.phases.push(Phase::new(name, kind, rules));
|
||||
self
|
||||
@@ -1209,15 +1052,15 @@ impl<C> DesugaringConfig<C> {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Runner<'a, C = ()> {
|
||||
pub struct Runner<'a> {
|
||||
language: tree_sitter::Language,
|
||||
schema: schema::Schema,
|
||||
phases: &'a [Phase<C>],
|
||||
phases: &'a [Phase],
|
||||
}
|
||||
|
||||
impl<'a, C> Runner<'a, C> {
|
||||
impl<'a> Runner<'a> {
|
||||
/// Create a runner using the input grammar's schema for output.
|
||||
pub fn new(language: tree_sitter::Language, phases: &'a [Phase<C>]) -> Self {
|
||||
pub fn new(language: tree_sitter::Language, phases: &'a [Phase]) -> Self {
|
||||
let schema = schema::Schema::from_language(&language);
|
||||
Self {
|
||||
language,
|
||||
@@ -1230,7 +1073,7 @@ impl<'a, C> Runner<'a, C> {
|
||||
pub fn with_schema(
|
||||
language: tree_sitter::Language,
|
||||
schema: &schema::Schema,
|
||||
phases: &'a [Phase<C>],
|
||||
phases: &'a [Phase],
|
||||
) -> Self {
|
||||
Self {
|
||||
language,
|
||||
@@ -1242,7 +1085,7 @@ impl<'a, C> Runner<'a, C> {
|
||||
/// Create a runner from a [`DesugaringConfig`].
|
||||
pub fn from_config(
|
||||
language: tree_sitter::Language,
|
||||
config: &'a DesugaringConfig<C>,
|
||||
config: &'a DesugaringConfig,
|
||||
) -> Result<Self, String> {
|
||||
let schema = config.build_schema(&language)?;
|
||||
Ok(Self {
|
||||
@@ -1251,17 +1094,11 @@ impl<'a, C> Runner<'a, C> {
|
||||
phases: &config.phases,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, C: Clone> Runner<'a, C> {
|
||||
/// Parse `tree` against `source` and run all phases, threading
|
||||
/// `user_ctx` through every rule transform. The caller owns the
|
||||
/// initial context state.
|
||||
pub fn run_from_tree_with_ctx(
|
||||
pub fn run_from_tree(
|
||||
&self,
|
||||
tree: &tree_sitter::Tree,
|
||||
source: &[u8],
|
||||
user_ctx: &mut C,
|
||||
) -> Result<Ast, String> {
|
||||
let mut ast = Ast::from_tree_with_schema_and_source(
|
||||
self.schema.clone(),
|
||||
@@ -1269,13 +1106,11 @@ impl<'a, C: Clone> Runner<'a, C> {
|
||||
&self.language,
|
||||
source.to_vec(),
|
||||
);
|
||||
self.run_phases(&mut ast, user_ctx)?;
|
||||
self.run_phases(&mut ast)?;
|
||||
Ok(ast)
|
||||
}
|
||||
|
||||
/// Parse `input` and run all phases, threading `user_ctx` through
|
||||
/// every rule transform. The caller owns the initial context state.
|
||||
pub fn run_with_ctx(&self, input: &str, user_ctx: &mut C) -> Result<Ast, String> {
|
||||
pub fn run(&self, input: &str) -> Result<Ast, String> {
|
||||
let mut parser = tree_sitter::Parser::new();
|
||||
parser
|
||||
.set_language(&self.language)
|
||||
@@ -1289,24 +1124,20 @@ impl<'a, C: Clone> Runner<'a, C> {
|
||||
&self.language,
|
||||
input.as_bytes().to_vec(),
|
||||
);
|
||||
self.run_phases(&mut ast, user_ctx)?;
|
||||
self.run_phases(&mut ast)?;
|
||||
Ok(ast)
|
||||
}
|
||||
|
||||
/// Apply each phase in turn to the AST, threading the root through.
|
||||
/// A single `FreshScope` is shared across phases so that fresh
|
||||
/// identifiers generated in different phases don't collide.
|
||||
fn run_phases(&self, ast: &mut Ast, user_ctx: &mut C) -> Result<(), String> {
|
||||
fn run_phases(&self, ast: &mut Ast) -> Result<(), String> {
|
||||
let fresh = tree_builder::FreshScope::new();
|
||||
let mut root = ast.get_root();
|
||||
for phase in self.phases {
|
||||
let res = match phase.kind {
|
||||
PhaseKind::Repeating => {
|
||||
apply_repeating_rules(&phase.rules, ast, user_ctx, root, &fresh)
|
||||
}
|
||||
PhaseKind::OneShot => {
|
||||
apply_one_shot_rules(&phase.rules, ast, user_ctx, root, &fresh)
|
||||
}
|
||||
PhaseKind::Repeating => apply_repeating_rules(&phase.rules, ast, root, &fresh),
|
||||
PhaseKind::OneShot => apply_one_shot_rules(&phase.rules, ast, root, &fresh),
|
||||
}
|
||||
.map_err(|e| format!("Phase `{}`: {e}", phase.name))?;
|
||||
if res.len() != 1 {
|
||||
@@ -1322,78 +1153,3 @@ impl<'a, C: Clone> Runner<'a, C> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, C: Clone + Default> Runner<'a, C> {
|
||||
/// Parse `tree` against `source` and run all phases, using the
|
||||
/// default context (`C::default()`) as the initial context state.
|
||||
pub fn run_from_tree(&self, tree: &tree_sitter::Tree, source: &[u8]) -> Result<Ast, String> {
|
||||
let mut user_ctx = C::default();
|
||||
self.run_from_tree_with_ctx(tree, source, &mut user_ctx)
|
||||
}
|
||||
|
||||
/// Parse `input` and run all phases, using the default context
|
||||
/// (`C::default()`) as the initial context state.
|
||||
pub fn run(&self, input: &str) -> Result<Ast, String> {
|
||||
let mut user_ctx = C::default();
|
||||
self.run_with_ctx(input, &mut user_ctx)
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Desugarer: type-erased view of a DesugaringConfig + Runner
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/// Type-erased interface to a desugaring pipeline for a single language.
|
||||
///
|
||||
/// Consumers (e.g. a generic tree-sitter extractor) hold
|
||||
/// `Box<dyn Desugarer>` so they can dispatch through the trait without
|
||||
/// knowing the user context type `C` that's internal to yeast.
|
||||
///
|
||||
/// Construct one via [`ConcreteDesugarer::new`] from a
|
||||
/// [`DesugaringConfig<C>`] and a [`tree_sitter::Language`].
|
||||
pub trait Desugarer: Send + Sync {
|
||||
/// The output AST schema (in YAML format), or `None` if the input
|
||||
/// grammar's schema should be used.
|
||||
fn output_node_types_yaml(&self) -> Option<&'static str>;
|
||||
|
||||
/// Parse `tree` against `source` and run the desugaring pipeline.
|
||||
/// Each call constructs a fresh default user context internally.
|
||||
fn run_from_tree(&self, tree: &tree_sitter::Tree, source: &[u8]) -> Result<Ast, String>;
|
||||
}
|
||||
|
||||
/// A concrete [`Desugarer`] backed by a [`DesugaringConfig<C>`] for a
|
||||
/// specific user context type `C`. Stores the language and a pre-built
|
||||
/// schema so that per-call cost is bounded to constructing a transient
|
||||
/// [`Runner`] and cloning the schema (no YAML re-parsing).
|
||||
pub struct ConcreteDesugarer<C: Default + Clone + Send + Sync + 'static> {
|
||||
language: tree_sitter::Language,
|
||||
schema: schema::Schema,
|
||||
config: DesugaringConfig<C>,
|
||||
}
|
||||
|
||||
impl<C: Default + Clone + Send + Sync + 'static> ConcreteDesugarer<C> {
|
||||
/// Build a desugarer for `language` from `config`. Parses the output
|
||||
/// schema YAML once (if set) and stores it for reuse across files.
|
||||
pub fn new(
|
||||
language: tree_sitter::Language,
|
||||
config: DesugaringConfig<C>,
|
||||
) -> Result<Self, String> {
|
||||
let schema = config.build_schema(&language)?;
|
||||
Ok(Self {
|
||||
language,
|
||||
schema,
|
||||
config,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<C: Default + Clone + Send + Sync + 'static> Desugarer for ConcreteDesugarer<C> {
|
||||
fn output_node_types_yaml(&self) -> Option<&'static str> {
|
||||
self.config.output_node_types_yaml
|
||||
}
|
||||
|
||||
fn run_from_tree(&self, tree: &tree_sitter::Tree, source: &[u8]) -> Result<Ast, String> {
|
||||
let runner = Runner::with_schema(self.language.clone(), &self.schema, &self.config.phases);
|
||||
runner.run_from_tree(tree, source)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,7 +242,10 @@ pub fn convert(yaml_input: &str) -> Result<String, String> {
|
||||
|
||||
/// Apply YAML node-type definitions to a mutable Schema.
|
||||
/// Registers all types, fields, and allowed types from the YAML into the schema.
|
||||
fn apply_yaml_to_schema(yaml: &YamlNodeTypes, schema: &mut crate::schema::Schema) {
|
||||
fn apply_yaml_to_schema(
|
||||
yaml: &YamlNodeTypes,
|
||||
schema: &mut crate::schema::Schema,
|
||||
) {
|
||||
// Register all supertypes as node kinds
|
||||
for name in yaml.supertypes.keys() {
|
||||
schema.register_kind(name);
|
||||
@@ -304,8 +307,7 @@ fn apply_yaml_to_schema(yaml: &YamlNodeTypes, schema: &mut crate::schema::Schema
|
||||
.into_vec()
|
||||
.into_iter()
|
||||
.map(|type_ref| {
|
||||
let (kind, named) =
|
||||
resolve_type_ref_pair(&type_ref, &named_types, &unnamed_types);
|
||||
let (kind, named) = resolve_type_ref_pair(&type_ref, &named_types, &unnamed_types);
|
||||
crate::schema::NodeType { kind, named }
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
@@ -198,8 +198,13 @@ impl Schema {
|
||||
.insert((parent_kind.to_string(), field_id), node_types);
|
||||
}
|
||||
|
||||
pub fn field_types(&self, parent_kind: &str, field_id: FieldId) -> Option<&Vec<NodeType>> {
|
||||
self.field_types.get(&(parent_kind.to_string(), field_id))
|
||||
pub fn field_types(
|
||||
&self,
|
||||
parent_kind: &str,
|
||||
field_id: FieldId,
|
||||
) -> Option<&Vec<NodeType>> {
|
||||
self.field_types
|
||||
.get(&(parent_kind.to_string(), field_id))
|
||||
}
|
||||
|
||||
pub fn set_field_cardinality(
|
||||
|
||||
@@ -7,7 +7,7 @@ const OUTPUT_SCHEMA_YAML: &str = include_str!("node-types.yml");
|
||||
|
||||
/// Helper: parse Ruby source with no rules, return dump.
|
||||
fn parse_and_dump(input: &str) -> String {
|
||||
let runner: Runner = Runner::new(tree_sitter_ruby::LANGUAGE.into(), &[]);
|
||||
let runner = Runner::new(tree_sitter_ruby::LANGUAGE.into(), &[]);
|
||||
let ast = runner.run(input).unwrap();
|
||||
dump_ast(&ast, ast.get_root(), input)
|
||||
}
|
||||
@@ -24,7 +24,7 @@ fn run_and_ast(input: &str, rules: Vec<Rule>) -> Ast {
|
||||
let schema =
|
||||
yeast::node_types_yaml::schema_from_yaml_with_language(OUTPUT_SCHEMA_YAML, &lang).unwrap();
|
||||
let phases = vec![Phase::new("test", PhaseKind::Repeating, rules)];
|
||||
let runner: Runner = Runner::with_schema(lang, &schema, &phases);
|
||||
let runner = Runner::with_schema(lang, &schema, &phases);
|
||||
runner.run(input).unwrap()
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ fn run_phased_and_dump(input: &str, phases: Vec<Phase>) -> String {
|
||||
let lang: tree_sitter::Language = tree_sitter_ruby::LANGUAGE.into();
|
||||
let schema =
|
||||
yeast::node_types_yaml::schema_from_yaml_with_language(OUTPUT_SCHEMA_YAML, &lang).unwrap();
|
||||
let runner: Runner = Runner::with_schema(lang, &schema, &phases);
|
||||
let runner = Runner::with_schema(lang, &schema, &phases);
|
||||
let ast = runner.run(input).unwrap();
|
||||
dump_ast(&ast, ast.get_root(), input)
|
||||
}
|
||||
@@ -46,7 +46,7 @@ fn run_and_get_error(input: &str, rules: Vec<Rule>) -> String {
|
||||
let schema =
|
||||
yeast::node_types_yaml::schema_from_yaml_with_language(OUTPUT_SCHEMA_YAML, &lang).unwrap();
|
||||
let phases = vec![Phase::new("test", PhaseKind::Repeating, rules)];
|
||||
let runner: Runner = Runner::with_schema(lang, &schema, &phases);
|
||||
let runner = Runner::with_schema(lang, &schema, &phases);
|
||||
runner
|
||||
.run(input)
|
||||
.expect_err("expected runner to return an error")
|
||||
@@ -54,7 +54,7 @@ fn run_and_get_error(input: &str, rules: Vec<Rule>) -> String {
|
||||
|
||||
/// Helper: parse Ruby source with no rules and dump with schema type errors.
|
||||
fn parse_and_dump_typed(input: &str, schema_yaml: &str) -> String {
|
||||
let runner: Runner = Runner::new(tree_sitter_ruby::LANGUAGE.into(), &[]);
|
||||
let runner = Runner::new(tree_sitter_ruby::LANGUAGE.into(), &[]);
|
||||
let ast = runner.run(input).unwrap();
|
||||
let schema = yeast::node_types_yaml::schema_from_yaml(schema_yaml).unwrap();
|
||||
dump_ast_with_type_errors(&ast, ast.get_root(), input, &schema)
|
||||
@@ -64,10 +64,10 @@ fn parse_and_dump_typed(input: &str, schema_yaml: &str) -> String {
|
||||
/// building schema with language IDs so field checks align with parser fields.
|
||||
fn parse_and_dump_typed_with_language(input: &str, schema_yaml: &str) -> String {
|
||||
let lang: tree_sitter::Language = tree_sitter_ruby::LANGUAGE.into();
|
||||
let runner: Runner = Runner::new(lang.clone(), &[]);
|
||||
let runner = Runner::new(lang.clone(), &[]);
|
||||
let ast = runner.run(input).unwrap();
|
||||
let schema =
|
||||
yeast::node_types_yaml::schema_from_yaml_with_language(schema_yaml, &lang).unwrap();
|
||||
let schema = yeast::node_types_yaml::schema_from_yaml_with_language(schema_yaml, &lang)
|
||||
.unwrap();
|
||||
dump_ast_with_type_errors(&ast, ast.get_root(), input, &schema)
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ fn run_and_dump_typed(input: &str, rules: Vec<Rule>, schema_yaml: &str) -> Strin
|
||||
let lang: tree_sitter::Language = tree_sitter_ruby::LANGUAGE.into();
|
||||
let schema = yeast::node_types_yaml::schema_from_yaml(schema_yaml).unwrap();
|
||||
let phases = vec![Phase::new("test", PhaseKind::Repeating, rules)];
|
||||
let runner: Runner = Runner::with_schema(lang, &schema, &phases);
|
||||
let runner = Runner::with_schema(lang, &schema, &phases);
|
||||
let ast = runner.run(input).unwrap();
|
||||
dump_ast_with_type_errors(&ast, ast.get_root(), input, &schema)
|
||||
}
|
||||
@@ -166,7 +166,7 @@ fn test_parse_for_loop() {
|
||||
|
||||
#[test]
|
||||
fn test_dump_highlights_type_errors_inline() {
|
||||
let schema_yaml = r#"
|
||||
let schema_yaml = r#"
|
||||
named:
|
||||
program:
|
||||
$children*: assignment
|
||||
@@ -176,13 +176,13 @@ named:
|
||||
identifier:
|
||||
"#;
|
||||
|
||||
let dump = parse_and_dump_typed("x = 1", schema_yaml);
|
||||
assert!(dump.contains("integer \"1\" <-- ERROR:"));
|
||||
let dump = parse_and_dump_typed("x = 1", schema_yaml);
|
||||
assert!(dump.contains("integer \"1\" <-- ERROR:"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dump_reports_preserved_unknown_kind_after_transformation() {
|
||||
let schema_yaml = r#"
|
||||
let schema_yaml = r#"
|
||||
named:
|
||||
program:
|
||||
$children*: assignment
|
||||
@@ -192,25 +192,25 @@ named:
|
||||
identifier:
|
||||
"#;
|
||||
|
||||
// This rewrite runs and preserves the RHS node kind via capture.
|
||||
// With schema above, preserving `integer` should be reported inline.
|
||||
let rules: Vec<Rule> = vec![yeast::rule!(
|
||||
(assignment left: (_) @left right: (_) @right)
|
||||
=>
|
||||
(assignment
|
||||
left: {left}
|
||||
right: {right}
|
||||
)
|
||||
)];
|
||||
// This rewrite runs and preserves the RHS node kind via capture.
|
||||
// With schema above, preserving `integer` should be reported inline.
|
||||
let rules = vec![yeast::rule!(
|
||||
(assignment left: (_) @left right: (_) @right)
|
||||
=>
|
||||
(assignment
|
||||
left: {left}
|
||||
right: {right}
|
||||
)
|
||||
)];
|
||||
|
||||
let dump = run_and_dump_typed("x = 1", rules, schema_yaml);
|
||||
assert!(dump.contains("integer \"1\" <-- ERROR:"));
|
||||
assert!(dump.contains("node kind 'integer' not in schema"));
|
||||
let dump = run_and_dump_typed("x = 1", rules, schema_yaml);
|
||||
assert!(dump.contains("integer \"1\" <-- ERROR:"));
|
||||
assert!(dump.contains("node kind 'integer' not in schema"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dump_reports_undeclared_field_on_node() {
|
||||
let schema_yaml = r#"
|
||||
let schema_yaml = r#"
|
||||
named:
|
||||
program:
|
||||
$children*: assignment
|
||||
@@ -219,14 +219,14 @@ named:
|
||||
identifier:
|
||||
"#;
|
||||
|
||||
let dump = parse_and_dump_typed_with_language("x = y", schema_yaml);
|
||||
assert!(dump.contains("right: identifier \"y\" <-- ERROR:"));
|
||||
assert!(dump.contains("the node 'assignment' has no field 'right'"));
|
||||
let dump = parse_and_dump_typed_with_language("x = y", schema_yaml);
|
||||
assert!(dump.contains("right: identifier \"y\" <-- ERROR:"));
|
||||
assert!(dump.contains("the node 'assignment' has no field 'right'"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dump_reports_disallowed_kind_in_field_type() {
|
||||
let schema_yaml = r#"
|
||||
let schema_yaml = r#"
|
||||
named:
|
||||
program:
|
||||
$children*: assignment
|
||||
@@ -237,17 +237,17 @@ named:
|
||||
integer:
|
||||
"#;
|
||||
|
||||
let dump = parse_and_dump_typed_with_language("x = 1", schema_yaml);
|
||||
assert!(dump.contains("right: integer \"1\" <-- ERROR:"));
|
||||
assert!(dump.contains("should contain"));
|
||||
assert!(dump.contains("but got integer"));
|
||||
let dump = parse_and_dump_typed_with_language("x = 1", schema_yaml);
|
||||
assert!(dump.contains("right: integer \"1\" <-- ERROR:"));
|
||||
assert!(dump.contains("should contain"));
|
||||
assert!(dump.contains("but got integer"));
|
||||
}
|
||||
|
||||
// ---- Query tests ----
|
||||
|
||||
#[test]
|
||||
fn test_query_match() {
|
||||
let runner: Runner = Runner::new(tree_sitter_ruby::LANGUAGE.into(), &[]);
|
||||
let runner = Runner::new(tree_sitter_ruby::LANGUAGE.into(), &[]);
|
||||
let ast = runner.run("x = 1").unwrap();
|
||||
|
||||
let query = yeast::query!(
|
||||
@@ -268,7 +268,7 @@ fn test_query_match() {
|
||||
|
||||
#[test]
|
||||
fn test_query_no_match() {
|
||||
let runner: Runner = Runner::new(tree_sitter_ruby::LANGUAGE.into(), &[]);
|
||||
let runner = Runner::new(tree_sitter_ruby::LANGUAGE.into(), &[]);
|
||||
let ast = runner.run("x = 1").unwrap();
|
||||
|
||||
let query = yeast::query!(
|
||||
@@ -293,7 +293,7 @@ fn test_query_skips_extras_in_positional_match() {
|
||||
// captured comment to nothing (a common idiom, e.g.
|
||||
// `(comment) => ()` in Swift) leaves the capture's match-list empty
|
||||
// and causes the transform to fail with "Variable X has 0 matches".
|
||||
let runner: Runner = Runner::new(tree_sitter_ruby::LANGUAGE.into(), &[]);
|
||||
let runner = Runner::new(tree_sitter_ruby::LANGUAGE.into(), &[]);
|
||||
let ast = runner.run("[1, # comment\n2]").unwrap();
|
||||
|
||||
// Navigate to the `array` node: program -> array.
|
||||
@@ -309,11 +309,15 @@ fn test_query_skips_extras_in_positional_match() {
|
||||
let matched = query.do_match(&ast, array_id, &mut captures).unwrap();
|
||||
assert!(matched);
|
||||
assert_eq!(
|
||||
ast.get_node(captures.get_var("a").unwrap()).unwrap().kind(),
|
||||
ast.get_node(captures.get_var("a").unwrap())
|
||||
.unwrap()
|
||||
.kind(),
|
||||
"integer"
|
||||
);
|
||||
assert_eq!(
|
||||
ast.get_node(captures.get_var("b").unwrap()).unwrap().kind(),
|
||||
ast.get_node(captures.get_var("b").unwrap())
|
||||
.unwrap()
|
||||
.kind(),
|
||||
"integer"
|
||||
);
|
||||
}
|
||||
@@ -321,14 +325,14 @@ fn test_query_skips_extras_in_positional_match() {
|
||||
#[test]
|
||||
fn test_reachable_nodes_excludes_orphaned_rewrite_nodes() {
|
||||
let lang: tree_sitter::Language = tree_sitter_ruby::LANGUAGE.into();
|
||||
let schema =
|
||||
yeast::node_types_yaml::schema_from_yaml_with_language(OUTPUT_SCHEMA_YAML, &lang).unwrap();
|
||||
let phases: Vec<Phase> = vec![Phase::new(
|
||||
let schema = yeast::node_types_yaml::schema_from_yaml_with_language(OUTPUT_SCHEMA_YAML, &lang)
|
||||
.unwrap();
|
||||
let phases = vec![Phase::new(
|
||||
"test",
|
||||
PhaseKind::Repeating,
|
||||
vec![yeast::rule!((integer) => (identifier "replaced"))],
|
||||
)];
|
||||
let runner: Runner = Runner::with_schema(lang, &schema, &phases);
|
||||
let runner = Runner::with_schema(lang, &schema, &phases);
|
||||
|
||||
let input = "x = 1";
|
||||
let ast = runner.run(input).unwrap();
|
||||
@@ -346,7 +350,7 @@ fn test_reachable_nodes_excludes_orphaned_rewrite_nodes() {
|
||||
|
||||
#[test]
|
||||
fn test_query_repeated_capture() {
|
||||
let runner: Runner = Runner::new(tree_sitter_ruby::LANGUAGE.into(), &[]);
|
||||
let runner = Runner::new(tree_sitter_ruby::LANGUAGE.into(), &[]);
|
||||
let ast = runner.run("x, y, z = 1").unwrap();
|
||||
|
||||
let query = yeast::query!(
|
||||
@@ -371,7 +375,7 @@ fn test_query_repeated_capture() {
|
||||
#[test]
|
||||
fn test_capture_unnamed_node_parenthesized() {
|
||||
// `("=") @op` captures the unnamed `=` token between left and right.
|
||||
let runner: Runner = Runner::new(tree_sitter_ruby::LANGUAGE.into(), &[]);
|
||||
let runner = Runner::new(tree_sitter_ruby::LANGUAGE.into(), &[]);
|
||||
let ast = runner.run("x = 1").unwrap();
|
||||
|
||||
let query = yeast::query!(
|
||||
@@ -399,7 +403,7 @@ fn test_capture_unnamed_node_parenthesized() {
|
||||
fn test_capture_bare_underscore_repeated() {
|
||||
// `_` matches named and unnamed nodes in bare-child position. On this
|
||||
// assignment shape, bare children correspond to unnamed tokens (the `=`).
|
||||
let runner: Runner = Runner::new(tree_sitter_ruby::LANGUAGE.into(), &[]);
|
||||
let runner = Runner::new(tree_sitter_ruby::LANGUAGE.into(), &[]);
|
||||
let ast = runner.run("x = 1").unwrap();
|
||||
|
||||
let query = yeast::query!((assignment _* @all));
|
||||
@@ -421,7 +425,7 @@ fn test_capture_bare_underscore_repeated() {
|
||||
#[test]
|
||||
fn test_capture_unnamed_node_bare_literal() {
|
||||
// `"=" @op` (without surrounding parens) is the same as `("=") @op`.
|
||||
let runner: Runner = Runner::new(tree_sitter_ruby::LANGUAGE.into(), &[]);
|
||||
let runner = Runner::new(tree_sitter_ruby::LANGUAGE.into(), &[]);
|
||||
let ast = runner.run("x = 1").unwrap();
|
||||
|
||||
let query = yeast::query!(
|
||||
@@ -450,7 +454,7 @@ fn test_bare_underscore_matches_unnamed() {
|
||||
// Bare `_` matches any node, including unnamed tokens, while `(_)`
|
||||
// matches only named nodes. Demonstrate by matching the unnamed `=`
|
||||
// token in the implicit `child` field of an `assignment`.
|
||||
let runner: Runner = Runner::new(tree_sitter_ruby::LANGUAGE.into(), &[]);
|
||||
let runner = Runner::new(tree_sitter_ruby::LANGUAGE.into(), &[]);
|
||||
let ast = runner.run("x = 1").unwrap();
|
||||
|
||||
let mut cursor = AstCursor::new(&ast);
|
||||
@@ -489,7 +493,7 @@ fn test_bare_forms_in_field_position() {
|
||||
// field's value, not just in the bare-children position. This is
|
||||
// syntactic sugar for `(_)` / `("…")` and goes through the same
|
||||
// code paths.
|
||||
let runner: Runner = Runner::new(tree_sitter_ruby::LANGUAGE.into(), &[]);
|
||||
let runner = Runner::new(tree_sitter_ruby::LANGUAGE.into(), &[]);
|
||||
let ast = runner.run("x = 1").unwrap();
|
||||
|
||||
let mut cursor = AstCursor::new(&ast);
|
||||
@@ -528,7 +532,7 @@ fn test_forward_scan_finds_unnamed_token_late() {
|
||||
// query for `("end")` skip past the first two and match the third.
|
||||
// Without forward-scan, the matcher took the first child unconditionally
|
||||
// and failed.
|
||||
let runner: Runner = Runner::new(tree_sitter_ruby::LANGUAGE.into(), &[]);
|
||||
let runner = Runner::new(tree_sitter_ruby::LANGUAGE.into(), &[]);
|
||||
let ast = runner.run("for x in list do\n y\nend").unwrap();
|
||||
|
||||
// Navigate: program > for > do (the body wrapper).
|
||||
@@ -555,7 +559,7 @@ fn test_forward_scan_preserves_order() {
|
||||
// order. A query for ("end") then ("do") should fail because `do`
|
||||
// appears before `end` in the source order; once forward-scan has
|
||||
// consumed `end`, the iterator is exhausted.
|
||||
let runner: Runner = Runner::new(tree_sitter_ruby::LANGUAGE.into(), &[]);
|
||||
let runner = Runner::new(tree_sitter_ruby::LANGUAGE.into(), &[]);
|
||||
let ast = runner.run("for x in list do\n y\nend").unwrap();
|
||||
|
||||
let mut cursor = AstCursor::new(&ast);
|
||||
@@ -576,7 +580,7 @@ fn test_forward_scan_preserves_order() {
|
||||
|
||||
#[test]
|
||||
fn test_tree_builder() {
|
||||
let runner: Runner = Runner::new(tree_sitter_ruby::LANGUAGE.into(), &[]);
|
||||
let runner = Runner::new(tree_sitter_ruby::LANGUAGE.into(), &[]);
|
||||
let mut ast = runner.run("x = 1").unwrap();
|
||||
let input = "x = 1";
|
||||
|
||||
@@ -594,8 +598,7 @@ fn test_tree_builder() {
|
||||
|
||||
// Swap left and right
|
||||
let fresh = yeast::tree_builder::FreshScope::new();
|
||||
let mut user_ctx = ();
|
||||
let mut ctx = yeast::build::BuildCtx::new(&mut ast, &captures, &fresh, &mut user_ctx);
|
||||
let mut ctx = yeast::build::BuildCtx::new(&mut ast, &captures, &fresh);
|
||||
let new_id = yeast::tree!(ctx,
|
||||
(program
|
||||
child: (assignment
|
||||
@@ -623,7 +626,7 @@ fn test_tree_builder() {
|
||||
// tree-sitter-ruby grammar with named fields for nodes that only have
|
||||
// unnamed children in tree-sitter (e.g. block_body.stmt, block_parameters.parameter).
|
||||
fn ruby_rules() -> Vec<Rule> {
|
||||
let assign_rule: Rule = yeast::rule!(
|
||||
let assign_rule = yeast::rule!(
|
||||
(assignment
|
||||
left: (left_assignment_list
|
||||
(identifier)* @left
|
||||
@@ -648,7 +651,7 @@ fn ruby_rules() -> Vec<Rule> {
|
||||
)}
|
||||
);
|
||||
|
||||
let for_rule: Rule = yeast::rule!(
|
||||
let for_rule = yeast::rule!(
|
||||
(for
|
||||
pattern: (_) @pat
|
||||
value: (in (_) @val)
|
||||
@@ -730,7 +733,7 @@ fn test_desugar_for_loop() {
|
||||
|
||||
#[test]
|
||||
fn test_shorthand_rule() {
|
||||
let rule: Rule = yeast::rule!(
|
||||
let rule = yeast::rule!(
|
||||
(assignment
|
||||
left: (_) @method
|
||||
right: (_) @receiver
|
||||
@@ -882,7 +885,7 @@ fn test_phase_error_includes_phase_name() {
|
||||
PhaseKind::Repeating,
|
||||
vec![swap_assignment_rule().repeated()],
|
||||
)];
|
||||
let runner: Runner = Runner::with_schema(lang, &schema, &phases);
|
||||
let runner = Runner::with_schema(lang, &schema, &phases);
|
||||
let err = runner
|
||||
.run("x = 1")
|
||||
.expect_err("expected runner to return an error");
|
||||
@@ -925,7 +928,7 @@ fn test_one_shot_phase() {
|
||||
PhaseKind::OneShot,
|
||||
one_shot_xeq1_rules(),
|
||||
)];
|
||||
let runner: Runner = Runner::with_schema(lang, &schema, &phases);
|
||||
let runner = Runner::with_schema(lang, &schema, &phases);
|
||||
|
||||
let input = "x = 1";
|
||||
let ast = runner.run(input).unwrap();
|
||||
@@ -951,7 +954,7 @@ fn test_one_shot_phase_errors_when_no_rule_matches() {
|
||||
let mut rules = one_shot_xeq1_rules();
|
||||
rules.pop();
|
||||
let phases = vec![Phase::new("translate", PhaseKind::OneShot, rules)];
|
||||
let runner: Runner = Runner::with_schema(lang, &schema, &phases);
|
||||
let runner = Runner::with_schema(lang, &schema, &phases);
|
||||
|
||||
let err = runner
|
||||
.run("x = 1")
|
||||
@@ -975,7 +978,7 @@ fn test_one_shot_recurses_into_returned_capture() {
|
||||
let lang: tree_sitter::Language = tree_sitter_ruby::LANGUAGE.into();
|
||||
let schema =
|
||||
yeast::node_types_yaml::schema_from_yaml_with_language(OUTPUT_SCHEMA_YAML, &lang).unwrap();
|
||||
let rules: Vec<Rule> = vec![
|
||||
let rules = vec![
|
||||
yeast::rule!(
|
||||
(program (_)* @stmts)
|
||||
=>
|
||||
@@ -991,7 +994,7 @@ fn test_one_shot_recurses_into_returned_capture() {
|
||||
yeast::rule!((integer) => (integer "INT")),
|
||||
];
|
||||
let phases = vec![Phase::new("translate", PhaseKind::OneShot, rules)];
|
||||
let runner: Runner = Runner::with_schema(lang, &schema, &phases);
|
||||
let runner = Runner::with_schema(lang, &schema, &phases);
|
||||
|
||||
let input = "x = 1";
|
||||
let ast = runner.run(input).unwrap();
|
||||
@@ -1017,7 +1020,7 @@ fn test_one_shot_does_not_recurse_into_wrapper_output() {
|
||||
let lang: tree_sitter::Language = tree_sitter_ruby::LANGUAGE.into();
|
||||
let schema =
|
||||
yeast::node_types_yaml::schema_from_yaml_with_language(OUTPUT_SCHEMA_YAML, &lang).unwrap();
|
||||
let rules: Vec<Rule> = vec![
|
||||
let rules = vec![
|
||||
yeast::rule!(
|
||||
(program (_)* @stmts)
|
||||
=>
|
||||
@@ -1038,7 +1041,7 @@ fn test_one_shot_does_not_recurse_into_wrapper_output() {
|
||||
yeast::rule!((integer) => (integer "INT")),
|
||||
];
|
||||
let phases = vec![Phase::new("translate", PhaseKind::OneShot, rules)];
|
||||
let runner: Runner = Runner::with_schema(lang, &schema, &phases);
|
||||
let runner = Runner::with_schema(lang, &schema, &phases);
|
||||
|
||||
let input = "x = 1";
|
||||
let ast = runner.run(input).unwrap();
|
||||
@@ -1062,7 +1065,7 @@ fn test_one_shot_does_not_recurse_into_wrapper_output() {
|
||||
|
||||
#[test]
|
||||
fn test_cursor_navigation() {
|
||||
let runner: Runner = Runner::new(tree_sitter_ruby::LANGUAGE.into(), &[]);
|
||||
let runner = Runner::new(tree_sitter_ruby::LANGUAGE.into(), &[]);
|
||||
let ast = runner.run("x = 1").unwrap();
|
||||
let mut cursor = AstCursor::new(&ast);
|
||||
|
||||
@@ -1136,7 +1139,7 @@ fn test_desugar_for_with_multiple_assignment() {
|
||||
/// resolves to the captured node's source text via `YeastDisplay`.
|
||||
#[test]
|
||||
fn test_hash_brace_renders_capture_source_text() {
|
||||
let rule: Rule = rule!(
|
||||
let rule = rule!(
|
||||
(call
|
||||
method: (identifier) @name
|
||||
receiver: (identifier) @recv
|
||||
@@ -1165,7 +1168,7 @@ fn test_hash_brace_renders_capture_source_text() {
|
||||
/// `Display` impl (covered by `YeastDisplay`'s blanket impls for primitives).
|
||||
#[test]
|
||||
fn test_hash_brace_renders_integer_expression() {
|
||||
let rule: Rule = rule!(
|
||||
let rule = rule!(
|
||||
(identifier) @_
|
||||
=>
|
||||
(identifier #{1 + 2})
|
||||
@@ -1184,7 +1187,7 @@ fn test_hash_brace_renders_integer_expression() {
|
||||
/// source location, not the full source range of the matched rule root.
|
||||
#[test]
|
||||
fn test_hash_brace_uses_capture_location_for_leaf() {
|
||||
let rule: Rule = rule!(
|
||||
let rule = rule!(
|
||||
(call
|
||||
method: (identifier) @name
|
||||
receiver: (identifier) @recv
|
||||
@@ -1201,9 +1204,7 @@ fn test_hash_brace_uses_capture_location_for_leaf() {
|
||||
|
||||
let mut bar_ids: Vec<usize> = Vec::new();
|
||||
for id in ast.reachable_node_ids() {
|
||||
let Some(node) = ast.get_node(id) else {
|
||||
continue;
|
||||
};
|
||||
let Some(node) = ast.get_node(id) else { continue; };
|
||||
if node.kind() == "identifier" && ast.source_text(id) == "bar" {
|
||||
bar_ids.push(id);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ codeql_rust_binary(
|
||||
name = "extractor",
|
||||
srcs = glob(["src/**/*.rs"]),
|
||||
aliases = aliases(),
|
||||
compile_data = ["ast_types.yml"],
|
||||
proc_macro_deps = all_crate_deps(
|
||||
proc_macro = True,
|
||||
),
|
||||
|
||||
@@ -42,7 +42,6 @@ supertypes:
|
||||
- name_pattern
|
||||
- tuple_pattern
|
||||
- constructor_pattern
|
||||
- or_pattern
|
||||
- ignore_pattern
|
||||
- expr_equality_pattern
|
||||
- bulk_importing_pattern
|
||||
@@ -360,12 +359,12 @@ named:
|
||||
case*: switch_case
|
||||
|
||||
# A single `case ...:` (or `default:`) entry in a switch.
|
||||
# An entry with multiple `case p1, p2:` patterns uses an `or_pattern`.
|
||||
# A `default:` entry has no pattern.
|
||||
# An entry with multiple `case p1, p2:` patterns has multiple `pattern`s.
|
||||
# A `default:` entry has no patterns.
|
||||
# An optional `guard` corresponds to a `where`-clause on the case.
|
||||
switch_case:
|
||||
modifier*: modifier
|
||||
pattern?: pattern
|
||||
pattern*: pattern
|
||||
guard?: expr
|
||||
body: block
|
||||
|
||||
@@ -422,11 +421,6 @@ named:
|
||||
constructor: expr_or_type
|
||||
element*: pattern_element
|
||||
|
||||
# A disjunction pattern that matches if any of its sub-patterns match.
|
||||
or_pattern:
|
||||
modifier*: modifier
|
||||
pattern*: pattern
|
||||
|
||||
# A pattern with an optional associated name.
|
||||
pattern_element:
|
||||
modifier*: modifier
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user