Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions unified/ql/lib/codeql/files/FileSystem.qll
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
overlay[local]
module;

private import unified
private import codeql.Locations
private import codeql.util.FileSystem

Expand Down Expand Up @@ -37,4 +38,23 @@ module Folder = Impl::Folder;
class File extends Container, Impl::File {
/** Holds if this file was extracted from ordinary source code. */
predicate fromSource() { any() }

/**
* Gets the number of lines containing code in this file. This value
* is approximate.
*/
overlay[local?]
int getNumberOfLinesOfCode() {
result =
count(int line |
exists(AstNode node, Location loc |
not node instanceof Comment and
not node instanceof TopLevel and
loc = node.getLocation() and
this = loc.getFile() and
line = loc.getStartLine() and
not loc instanceof EmptyLocation
)
)
}
}
28 changes: 28 additions & 0 deletions unified/ql/src/diagnostic/ExtractorInformation.ql
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,37 @@
private import unified
private import codeql.unified.internal.AnalysisQuality

predicate fileCount(string key, int value) {
key = "Number of files" and
value = strictcount(File f)
}

predicate fileCountByExtension(string key, int value) {
exists(string extension |
key = "Number of files with extension " + extension and
value = strictcount(File f | f.getExtension() = extension)
)
}

predicate numberOfLinesOfCode(string key, int value) {
key = "Number of lines of code" and
value = strictsum(File f | any() | f.getNumberOfLinesOfCode())
}

predicate numberOfLinesOfCodeByExtension(string key, int value) {
exists(string extension |
key = "Number of lines of code with extension " + extension and
value = strictsum(File f | f.getExtension() = extension | f.getNumberOfLinesOfCode())
)
}

from string key, float value
where
(
fileCount(key, value) or
fileCountByExtension(key, value) or
numberOfLinesOfCode(key, value) or
numberOfLinesOfCodeByExtension(key, value) or
StaticNameResolutionStatsReport::keyValuePair(key, value) or
FilesCoveredByModuleManifestStatsReport::keyValuePair(key, value)
) and
Expand Down
Loading