mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Address review comments
This commit is contained in:
@@ -655,6 +655,11 @@ private predicate fileModule(SourceFile f, string name, Folder folder) {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the `Meta` of the module `m`'s [path attribute][1].
|
||||
*
|
||||
* [1]: https://doc.rust-lang.org/reference/items/modules.html#r-items.mod.outlined.path
|
||||
*/
|
||||
private Meta getPathAttrMeta(Module m) {
|
||||
result = m.getAnAttr().getMeta() and
|
||||
result.getPath().getText() = "path"
|
||||
@@ -725,7 +730,7 @@ private predicate pathAttrImport(Folder f, Module m, string relativePath) {
|
||||
)
|
||||
}
|
||||
|
||||
private predicate append(Folder f, string relativePath) { pathAttrImport(f, _, relativePath) }
|
||||
private predicate shouldAppend(Folder f, string relativePath) { pathAttrImport(f, _, relativePath) }
|
||||
|
||||
/** Holds if `m` is a `mod name;` item importing file `f`. */
|
||||
private predicate fileImport(Module m, SourceFile f) {
|
||||
@@ -743,7 +748,7 @@ private predicate fileImport(Module m, SourceFile f) {
|
||||
or
|
||||
exists(Folder folder, string relativePath |
|
||||
pathAttrImport(folder, m, relativePath) and
|
||||
f.getFile() = Folder::Append<append/2>::append(folder, relativePath)
|
||||
f.getFile() = Folder::Append<shouldAppend/2>::append(folder, relativePath)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -222,20 +222,27 @@ module Make<InputSig Input> {
|
||||
/** Provides logic related to `Folder`s. */
|
||||
module Folder {
|
||||
/** Holds if `relativePath` needs to be appended to `f`. */
|
||||
signature predicate appendSig(Folder f, string relativePath);
|
||||
signature predicate shouldAppendSig(Folder f, string relativePath);
|
||||
|
||||
/** Provides the `append` predicate for appending a relative path onto a folder. */
|
||||
module Append<appendSig/2 app> {
|
||||
module Append<shouldAppendSig/2 shouldAppend> {
|
||||
pragma[nomagic]
|
||||
private string getComponent(string relativePath, int i) {
|
||||
app(_, relativePath) and
|
||||
shouldAppend(_, relativePath) and
|
||||
result = relativePath.replaceAll("\\", "/").regexpFind("[^/]+", i, _)
|
||||
}
|
||||
|
||||
private int getNumberOfComponents(string relativePath) {
|
||||
result = strictcount(int i | exists(getComponent(relativePath, i)) | i)
|
||||
or
|
||||
relativePath = "" and
|
||||
result = 0
|
||||
}
|
||||
|
||||
pragma[nomagic]
|
||||
private Container appendStep(Folder f, string relativePath, int i) {
|
||||
i = -1 and
|
||||
app(f, relativePath) and
|
||||
shouldAppend(f, relativePath) and
|
||||
result = f
|
||||
or
|
||||
exists(Container mid, string comp |
|
||||
@@ -258,9 +265,9 @@ module Make<InputSig Input> {
|
||||
*/
|
||||
pragma[nomagic]
|
||||
Container append(Folder f, string relativePath) {
|
||||
exists(int components |
|
||||
components = (-1).maximum(max(int comp | exists(getComponent(relativePath, comp)) | comp)) and
|
||||
result = appendStep(f, relativePath, components)
|
||||
exists(int last |
|
||||
last = getNumberOfComponents(relativePath) - 1 and
|
||||
result = appendStep(f, relativePath, last)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user