Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 651847d

Browse files
committed
Java/Kotlin: Enhance 'compilations' support
1 parent 9e4614e commit 651847d

3 files changed

Lines changed: 115 additions & 1 deletion

File tree

java/ql/lib/config/semmlecode.dbscheme

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,16 @@ compilations(
1717
* javac A.java B.java C.java
1818
*/
1919
unique int id : @compilation,
20-
string cwd : string ref
20+
int kind: int ref,
21+
string cwd : string ref,
22+
string name : string ref
2123
);
2224

25+
case @compilation.kind of
26+
1 = @javacompilation
27+
| 2 = @kotlincompilation
28+
;
29+
2330
compilation_started(
2431
int id : @compilation ref
2532
)

java/ql/lib/java.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import semmle.code.FileSystem
55
import semmle.code.Location
66
import semmle.code.Unit
77
import semmle.code.java.Annotation
8+
import semmle.code.java.Compilation
89
import semmle.code.java.CompilationUnit
910
import semmle.code.java.ControlFlowGraph
1011
import semmle.code.java.Dependency
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/**
2+
* Provides a class representing individual compiler invocations that occurred during the build.
3+
*/
4+
5+
import semmle.code.FileSystem
6+
7+
/**
8+
* An invocation of the compiler. Note that more than one file may be
9+
* compiled per invocation. For example, this command compiles three
10+
* source files:
11+
*
12+
* javac Foo.java Bar.java Baz.java
13+
*
14+
* Two things happen to each file during a compilation:
15+
*
16+
* 1. The file is compiled by a real compiler, such as javac or kotlinc.
17+
* 2. The file is parsed by the CodeQL front-end.
18+
* 3. The parsed representation is converted to database tables by
19+
* the CodeQL extractor.
20+
*
21+
* This class provides CPU and elapsed time information for steps 2 and 3,
22+
* but not for step 1.
23+
*/
24+
class Compilation extends @compilation {
25+
/** Gets a textual representation of this element. */
26+
string toString() {
27+
exists(string name |
28+
compilations(this, _, _, name) and
29+
result = "<compilation " + name + ">"
30+
)
31+
}
32+
33+
/** Gets a file compiled during this invocation. */
34+
File getAFileCompiled() { result = getFileCompiled(_) }
35+
36+
/** Gets the `i`th file compiled during this invocation */
37+
File getFileCompiled(int i) { compilation_compiling_files(this, i, result) }
38+
39+
/**
40+
* Gets the amount of CPU time spent processing file number `i` in the
41+
* front-end.
42+
*/
43+
float getFrontendCpuSeconds(int i) { compilation_time(this, i, 1, result) }
44+
45+
/**
46+
* Gets the amount of elapsed time while processing file number `i` in the
47+
* front-end.
48+
*/
49+
float getFrontendElapsedSeconds(int i) { compilation_time(this, i, 2, result) }
50+
51+
/**
52+
* Gets the amount of CPU time spent processing file number `i` in the
53+
* extractor.
54+
*/
55+
float getExtractorCpuSeconds(int i) { compilation_time(this, i, 3, result) }
56+
57+
/**
58+
* Gets the amount of elapsed time while processing file number `i` in the
59+
* extractor.
60+
*/
61+
float getExtractorElapsedSeconds(int i) { compilation_time(this, i, 4, result) }
62+
63+
/**
64+
* Gets an argument passed to the extractor on this invocation.
65+
*/
66+
string getAnArgument() { result = getArgument(_) }
67+
68+
/**
69+
* Gets the `i`th argument passed to the extractor on this invocation.
70+
*/
71+
string getArgument(int i) { compilation_args(this, i, result) }
72+
73+
/**
74+
* Gets the total amount of CPU time spent processing all the files in the
75+
* front-end and extractor.
76+
*/
77+
float getTotalCpuSeconds() { compilation_finished(this, result, _) }
78+
79+
/**
80+
* Gets the total amount of elapsed time while processing all the files in
81+
* the front-end and extractor.
82+
*/
83+
float getTotalElapsedSeconds() { compilation_finished(this, _, result) }
84+
85+
/**
86+
* Holds if this is a compilation of Java code.
87+
*/
88+
predicate isJava() { this instanceof @javacompilation }
89+
90+
/**
91+
* Holds if this is a compilation of Kotlin code.
92+
*/
93+
predicate isKotlin() { this instanceof @kotlincompilation }
94+
95+
/**
96+
* Holds if extraction for the compilation started.
97+
*/
98+
predicate extractionStarted() { compilation_started(this) }
99+
100+
/**
101+
* Holds if the extractor terminated normally. Terminating with an exit
102+
* code indicating that an error occurred is considered normal
103+
* termination, but crashing due to something like a segfault is not.
104+
*/
105+
predicate normalTermination() { compilation_finished(this, _, _) }
106+
}

0 commit comments

Comments
 (0)