mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Ruby: Make module graph queries avoid relying on evalaution order.
This commit is contained in:
@@ -1,25 +1,21 @@
|
||||
#-----| BasicObject
|
||||
|
||||
#-----| Class
|
||||
#-----| super -> Module
|
||||
|
||||
#-----| EsotericInstanceMethods
|
||||
|
||||
#-----| MyStruct
|
||||
|
||||
#-----| Struct
|
||||
|
||||
#-----| UnresolvedNamespace
|
||||
|
||||
#-----| BasicObject
|
||||
|
||||
#-----| Complex
|
||||
#-----| super -> Numeric
|
||||
|
||||
#-----| EsotericInstanceMethods
|
||||
|
||||
#-----| FalseClass
|
||||
#-----| super -> Object
|
||||
|
||||
#-----| Float
|
||||
#-----| super -> Numeric
|
||||
|
||||
#-----| MyStruct
|
||||
|
||||
#-----| NilClass
|
||||
#-----| super -> Object
|
||||
|
||||
@@ -31,11 +27,15 @@
|
||||
#-----| Rational
|
||||
#-----| super -> Numeric
|
||||
|
||||
#-----| Struct
|
||||
|
||||
#-----| Symbol
|
||||
|
||||
#-----| TrueClass
|
||||
#-----| super -> Object
|
||||
|
||||
#-----| UnresolvedNamespace
|
||||
|
||||
#-----| UnresolvedNamespace::X1
|
||||
|
||||
#-----| UnresolvedNamespace::X1::X2
|
||||
|
||||
@@ -5,22 +5,33 @@
|
||||
|
||||
import codeql.ruby.AST
|
||||
|
||||
int locationModuleRank(Module node) {
|
||||
node =
|
||||
rank[result](Module m, Location l |
|
||||
l = m.getLocation()
|
||||
|
|
||||
m
|
||||
order by
|
||||
l.getFile().getBaseName(), l.getFile().getAbsolutePath(), l.getStartLine(),
|
||||
l.getStartColumn(), l.getEndLine(), l.getEndColumn(), m.toString()
|
||||
)
|
||||
}
|
||||
|
||||
int stringModuleRank(Module node) {
|
||||
node = rank[result](Module m | not exists(locationModuleRank(m)) | m order by m.toString())
|
||||
}
|
||||
|
||||
int moduleRank(Module node) {
|
||||
result = locationModuleRank(node) + max(stringModuleRank(_))
|
||||
or
|
||||
result = stringModuleRank(node)
|
||||
}
|
||||
|
||||
query predicate nodes(Module node, string key, string value) {
|
||||
key = "semmle.label" and value = node.toString()
|
||||
or
|
||||
key = "semmle.order" and
|
||||
value =
|
||||
any(int i |
|
||||
node =
|
||||
rank[i](Module m, Location l |
|
||||
l = m.getLocation()
|
||||
|
|
||||
m
|
||||
order by
|
||||
l.getFile().getBaseName(), l.getFile().getAbsolutePath(), l.getStartLine(),
|
||||
l.getStartColumn(), l.getEndLine(), l.getEndColumn(), m.toString()
|
||||
)
|
||||
).toString()
|
||||
value = moduleRank(node).toString()
|
||||
}
|
||||
|
||||
Module getATarget(Module source, string value) {
|
||||
|
||||
@@ -1,25 +1,21 @@
|
||||
#-----| BasicObject
|
||||
|
||||
#-----| Class
|
||||
#-----| -> Module
|
||||
|
||||
#-----| EsotericInstanceMethods
|
||||
|
||||
#-----| MyStruct
|
||||
|
||||
#-----| Struct
|
||||
|
||||
#-----| UnresolvedNamespace
|
||||
|
||||
#-----| BasicObject
|
||||
|
||||
#-----| Complex
|
||||
#-----| -> Numeric
|
||||
|
||||
#-----| EsotericInstanceMethods
|
||||
|
||||
#-----| FalseClass
|
||||
#-----| -> Object
|
||||
|
||||
#-----| Float
|
||||
#-----| -> Numeric
|
||||
|
||||
#-----| MyStruct
|
||||
|
||||
#-----| NilClass
|
||||
#-----| -> Object
|
||||
|
||||
@@ -31,11 +27,15 @@
|
||||
#-----| Rational
|
||||
#-----| -> Numeric
|
||||
|
||||
#-----| Struct
|
||||
|
||||
#-----| Symbol
|
||||
|
||||
#-----| TrueClass
|
||||
#-----| -> Object
|
||||
|
||||
#-----| UnresolvedNamespace
|
||||
|
||||
#-----| UnresolvedNamespace::X1
|
||||
|
||||
#-----| UnresolvedNamespace::X1::X2
|
||||
|
||||
@@ -5,22 +5,33 @@
|
||||
|
||||
import codeql.ruby.AST
|
||||
|
||||
int locationModuleRank(Module node) {
|
||||
node =
|
||||
rank[result](Module m, Location l |
|
||||
l = m.getLocation()
|
||||
|
|
||||
m
|
||||
order by
|
||||
l.getFile().getBaseName(), l.getFile().getAbsolutePath(), l.getStartLine(),
|
||||
l.getStartColumn(), l.getEndLine(), l.getEndColumn(), m.toString()
|
||||
)
|
||||
}
|
||||
|
||||
int stringModuleRank(Module node) {
|
||||
node = rank[result](Module m | not exists(locationModuleRank(m)) | m order by m.toString())
|
||||
}
|
||||
|
||||
int moduleRank(Module node) {
|
||||
result = locationModuleRank(node) + max(stringModuleRank(_))
|
||||
or
|
||||
result = stringModuleRank(node)
|
||||
}
|
||||
|
||||
query predicate nodes(Module node, string key, string value) {
|
||||
key = "semmle.label" and value = node.toString()
|
||||
or
|
||||
key = "semmle.order" and
|
||||
value =
|
||||
any(int i |
|
||||
node =
|
||||
rank[i](Module m, Location l |
|
||||
l = m.getLocation()
|
||||
|
|
||||
m
|
||||
order by
|
||||
l.getFile().getBaseName(), l.getFile().getAbsolutePath(), l.getStartLine(),
|
||||
l.getStartColumn(), l.getEndLine(), l.getEndColumn(), m.toString()
|
||||
)
|
||||
).toString()
|
||||
value = moduleRank(node).toString()
|
||||
}
|
||||
|
||||
query predicate edges(Module source, Module target, string key, string value) {
|
||||
|
||||
Reference in New Issue
Block a user