Skip to content

Commit 4628f88

Browse files
authored
Merge pull request github#6489 from hvitved/csharp/files-folders-drop-columns
C#: Drop redundant columns from `files` and `folders` relations
2 parents 31739cd + 2730423 commit 4628f88

File tree

15 files changed

+4206
-572
lines changed

15 files changed

+4206
-572
lines changed

csharp/autobuilder/Semmle.Autobuild.Shared/BuildActions.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,12 @@ private static ProcessStartInfo GetProcessStartInfo(string exe, string arguments
161161
pi.WorkingDirectory = workingDirectory;
162162

163163
// Environment variables can only be used when not redirecting stdout
164-
if (!redirectStandardOutput && environment is not null)
165-
environment.ForEach(kvp => pi.Environment[kvp.Key] = kvp.Value);
164+
if (!redirectStandardOutput)
165+
{
166+
if (environment is not null)
167+
environment.ForEach(kvp => pi.Environment[kvp.Key] = kvp.Value);
168+
pi.Environment["CODEQL_REDUCE_FILES_FOLDERS_RELATIONS"] = "true";
169+
}
166170
return pi;
167171
}
168172

csharp/codeql-extractor.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ extra_env_vars:
1010
CORECLR_ENABLE_PROFILING: "1"
1111
CORECLR_PROFILER: "{A3C70A64-7D41-4A94-A3F6-FD47D9259997}"
1212
CORECLR_PROFILER_PATH_64: "${env.CODEQL_EXTRACTOR_CSHARP_ROOT}/tools/${env.CODEQL_PLATFORM}/clrtracer64${env.CODEQL_PLATFORM_DLL_EXTENSION}"
13+
CODEQL_REDUCE_FILES_FOLDERS_RELATIONS: "true"
1314
file_types:
1415
- name: cs
1516
display_name: C# sources

csharp/extractor/Semmle.Extraction.CIL/Entities/File.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public override IEnumerable<IExtractionProduct> Contents
3737
yield return parent;
3838
yield return Tuples.containerparent(parent, this);
3939
}
40-
yield return Tuples.files(this, TransformedPath.Value, TransformedPath.NameWithoutExtension, TransformedPath.Extension);
40+
yield return Tuples.files(this, TransformedPath.Value);
4141
}
4242
}
4343
}

csharp/extractor/Semmle.Extraction.CIL/Entities/Folder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public override IEnumerable<IExtractionProduct> Contents
2828
yield return parentFolder;
2929
yield return Tuples.containerparent(parentFolder, this);
3030
}
31-
yield return Tuples.folders(this, transformedPath.Value, transformedPath.NameWithoutExtension);
31+
yield return Tuples.folders(this, transformedPath.Value);
3232
}
3333
}
3434

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,14 @@ internal static Tuple cil_type_annotation(IExtractedEntity receiver, TypeAnnotat
203203
internal static Tuple containerparent(Folder parent, IFileOrFolder child) =>
204204
new Tuple("containerparent", parent, child);
205205

206-
internal static Tuple files(File file, string fullName, string name, string extension) =>
207-
new Tuple("files", file, fullName, name, extension, 0);
206+
internal static Tuple files(File file, string fullName) =>
207+
new Tuple("files", file, fullName);
208208

209209
internal static Tuple file_extraction_mode(File file, int mode) =>
210210
new Tuple("file_extraction_mode", file, mode);
211211

212-
internal static Tuple folders(Folder folder, string path, string name) =>
213-
new Tuple("folders", folder, path, name);
212+
internal static Tuple folders(Folder folder, string path) =>
213+
new Tuple("folders", folder, path);
214214

215215
internal static Tuple locations_default(PdbSourceLocation label, File file, int startLine, int startCol, int endLine, int endCol) =>
216216
new Tuple("locations_default", label, file, startLine, startCol, endLine, endCol);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ protected File(Context cx, string path)
1717

1818
public override void Populate(TextWriter trapFile)
1919
{
20-
trapFile.files(this, TransformedPath.Value, TransformedPath.NameWithoutExtension, TransformedPath.Extension);
20+
trapFile.files(this, TransformedPath.Value);
2121

2222
if (TransformedPath.ParentDirectory is PathTransformer.ITransformedPath dir)
2323
trapFile.containerparent(Extraction.Entities.Folder.Create(Context, dir), this);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ private Folder(Context cx, PathTransformer.ITransformedPath init) : base(cx, ini
88

99
public override void Populate(TextWriter trapFile)
1010
{
11-
trapFile.folders(this, Symbol.Value, Symbol.NameWithoutExtension);
11+
trapFile.folders(this, Symbol.Value);
1212
if (Symbol.ParentDirectory is PathTransformer.ITransformedPath parent)
1313
trapFile.containerparent(Create(Context, parent), this);
1414
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ private GeneratedFile(Context cx) : base(cx, "") { }
1010

1111
public override void Populate(TextWriter trapFile)
1212
{
13-
trapFile.files(this, "", "", "");
13+
trapFile.files(this, "");
1414
}
1515

1616
public override void WriteId(EscapingTextWriter trapFile)

csharp/extractor/Semmle.Extraction/Tuples.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ internal static void extractor_messages(this System.IO.TextWriter trapFile, Extr
1818
trapFile.WriteTuple("extractor_messages", error, (int)severity, origin, errorMessage, entityText, ___location, stackTrace);
1919
}
2020

21-
public static void files(this System.IO.TextWriter trapFile, File file, string fullName, string name, string extension)
21+
public static void files(this System.IO.TextWriter trapFile, File file, string fullName)
2222
{
23-
trapFile.WriteTuple("files", file, fullName, name, extension, 0);
23+
trapFile.WriteTuple("files", file, fullName);
2424
}
2525

26-
internal static void folders(this System.IO.TextWriter trapFile, Folder folder, string path, string name)
26+
internal static void folders(this System.IO.TextWriter trapFile, Folder folder, string path)
2727
{
28-
trapFile.WriteTuple("folders", folder, path, name);
28+
trapFile.WriteTuple("folders", folder, path);
2929
}
3030

3131
public static void locations_default(this System.IO.TextWriter trapFile, SourceLocation label, Entities.File file, int startLine, int startCol, int endLine, int endCol)

csharp/ql/lib/semmle/code/csharp/File.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,14 @@ class Container extends @container {
171171

172172
/** A folder. */
173173
class Folder extends Container, @folder {
174-
override string getAbsolutePath() { folders(this, result, _) }
174+
override string getAbsolutePath() { folders(this, result) }
175175

176176
override string getURL() { result = "folder://" + getAbsolutePath() }
177177
}
178178

179179
/** A file. */
180180
class File extends Container, @file {
181-
override string getAbsolutePath() { files(this, result, _, _, _) }
181+
override string getAbsolutePath() { files(this, result) }
182182

183183
/** Gets the number of lines in this file. */
184184
int getNumberOfLines() { numlines(this, result, _, _) }
@@ -192,7 +192,7 @@ class File extends Container, @file {
192192
override string getURL() { result = "file://" + this.getAbsolutePath() + ":0:0:0:0" }
193193

194194
/** Holds if this file contains source code. */
195-
predicate fromSource() { files(this, _, _, "cs", _) }
195+
predicate fromSource() { this.getExtension() = "cs" }
196196

197197
/** Holds if this file is a library. */
198198
predicate fromLibrary() {

0 commit comments

Comments
 (0)