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

Skip to content

Commit 5cfa900

Browse files
committed
C#: Add output assembly to compilation
1 parent 7418c05 commit 5cfa900

10 files changed

Lines changed: 39 additions & 8 deletions

File tree

csharp/extractor/Semmle.Extraction.CSharp/Entities/Compilation.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ public Compilation(Context cx, string cwd, string[] args) : base(cx)
2121

2222
protected override void Populate(TextWriter trapFile)
2323
{
24-
Extraction.Entities.Assembly.CreateOutputAssembly(cx);
24+
var assembly = Extraction.Entities.Assembly.CreateOutputAssembly(cx);
2525

26-
trapFile.compilations(this, FileUtils.ConvertToUnix(cwd));
26+
trapFile.compilations(this, FileUtils.ConvertToUnix(cwd), assembly);
2727

2828
// Arguments
2929
var index = 0;

csharp/extractor/Semmle.Extraction.CSharp/Tuples.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ internal static void compilation_time(this TextWriter trapFile, Compilation comp
106106
trapFile.WriteTuple("compilation_time", compilation, num, index, metric);
107107
}
108108

109-
internal static void compilations(this TextWriter trapFile, Compilation compilation, string cwd)
109+
internal static void compilations(this TextWriter trapFile, Compilation compilation, string cwd, Assembly assembly)
110110
{
111-
trapFile.WriteTuple("compilations", compilation, cwd);
111+
trapFile.WriteTuple("compilations", compilation, cwd, assembly);
112112
}
113113

114114
internal static void compiler_generated(this TextWriter trapFile, IEntity entity)

csharp/extractor/Semmle.Extraction/Entities/Assembly.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ private class AssemblyConstructorFactory : ICachedEntityFactory<Microsoft.CodeAn
5858
}
5959

6060
private static readonly object outputAssemblyCacheKey = new object();
61-
public static Location CreateOutputAssembly(Context cx)
61+
62+
public static Assembly CreateOutputAssembly(Context cx)
6263
{
6364
if (cx.Extractor.OutputPath == null)
6465
throw new InternalError("Attempting to create the output assembly in standalone extraction mode");

csharp/ql/src/semmle/code/csharp/Location.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import File
1616
private import Attribute
17+
private import semmle.code.csharp.commons.Compilation
1718

1819
/**
1920
* A location of a program element.
@@ -171,6 +172,9 @@ class Assembly extends Location, Attributable, @assembly {
171172
/** Gets the version of this assembly. */
172173
Version getVersion() { assemblies(this, _, _, _, result) }
173174

175+
/** Gets the compilation producing this assembly if any. */
176+
Compilation getCompilation() { compilations(result, _, this) }
177+
174178
override File getFile() { assemblies(this, result, _, _, _) }
175179

176180
override string toString() { result = this.getFullName() }

csharp/ql/src/semmle/code/csharp/commons/Compilation.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ class Compilation extends @compilation {
77
string toString() { result = "compilation" }
88

99
/** Gets the directory in which this compilation was run, as a string. */
10-
string getDirectoryString() { compilations(this, result) }
10+
string getDirectoryString() { compilations(this, result, _) }
11+
12+
/** Gets the output assembly. */
13+
Assembly getOutputAssembly() { compilations(this, _, result) }
1114

1215
/** Gets the folder in which this compilation was run. */
1316
Folder getFolder() { result.getAbsolutePath() = getDirectoryString() }

csharp/ql/src/semmlecode.csharp.dbscheme

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
* csc f1.cs f2.cs f3.cs
88
*
99
* The `id` simply identifies the invocation, while `cwd` is the working
10-
* directory from which the compiler was invoked.
10+
* directory from which the compiler was invoked. The `assembly` identifies
11+
* the output assembly of the compilation.
1112
*/
1213
compilations(
1314
unique int id : @compilation,
14-
string cwd : string ref
15+
string cwd : string ref,
16+
int assembly: @assembly ref
1517
);
1618

1719
/**
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
| Assembly1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | no compilation |
2+
| Locations, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | has compilation |
3+
| System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 | no compilation |
4+
| System.Console, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a | no compilation |
5+
| System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 | no compilation |
6+
| System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e | no compilation |
7+
| System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a | no compilation |
8+
| System.Runtime.Extensions, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a | no compilation |
9+
| mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 | no compilation |
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import csharp
2+
3+
private string hasCompilation(Assembly a) {
4+
if exists(a.getCompilation()) then result = "has compilation" else result = "no compilation"
5+
}
6+
7+
from Assembly a
8+
select a.getFullName(), hasCompilation(a)

csharp/ql/test/library-tests/compilations/Compilations.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ references
3535
| compilation | mscorlib.dll |
3636
timings
3737
| compilation |
38+
assembly
39+
| compilation | Program.dll:0:0:0:0 | Program, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null |

csharp/ql/test/library-tests/compilations/Compilations.ql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,5 @@ query predicate timings(Compilation c) {
3939
c.getCpuSeconds() > 0 and
4040
c.getElapsedSeconds() > 0
4141
}
42+
43+
query predicate assembly(Compilation c, Assembly a) { c.getOutputAssembly() = a }

0 commit comments

Comments
 (0)