Merge Extractor.Standalone and OutputPath

This commit is contained in:
Tamas Vajk
2021-02-18 13:01:38 +01:00
parent 10ab17a7e0
commit 2697677239
7 changed files with 11 additions and 20 deletions

View File

@@ -33,7 +33,7 @@ namespace Semmle.Extraction.CIL
{
var canonicalPathCache = CanonicalPathCache.Create(logger, 1000);
var pathTransformer = new PathTransformer(canonicalPathCache);
var extractor = new Extractor(false, assemblyPath, logger, pathTransformer);
var extractor = new Extractor(assemblyPath, logger, pathTransformer);
var transformedAssemblyPath = pathTransformer.Transform(assemblyPath);
var project = layout.LookupProjectOrDefault(transformedAssemblyPath);
using var trapWriter = project.CreateTrapWriter(logger, transformedAssemblyPath.WithSuffix(".cil"), trapCompression, discardDuplicates: true);

View File

@@ -76,7 +76,7 @@ namespace Semmle.Extraction.CSharp
layout = new Layout();
this.options = options;
this.compilation = compilation;
extractor = new Extraction.Extractor(false, GetOutputName(compilation, commandLineArguments), Logger, PathTransformer);
extractor = new Extraction.Extractor(GetOutputName(compilation, commandLineArguments), Logger, PathTransformer);
LogDiagnostics();
SetReferencePaths();
@@ -126,7 +126,7 @@ namespace Semmle.Extraction.CSharp
{
compilation = compilationIn;
layout = new Layout();
extractor = new Extraction.Extractor(true, null, Logger, PathTransformer);
extractor = new Extraction.Extractor(null, Logger, PathTransformer);
this.options = options;
LogExtractorInfo(Extraction.Extractor.Version);
SetReferencePaths();

View File

@@ -65,7 +65,7 @@ namespace Semmle.Extraction.CSharp.Entities
public static Assembly CreateOutputAssembly(Context cx)
{
if (cx.Extractor.OutputPath == null)
if (cx.Extractor.Standalone)
throw new InternalError("Attempting to create the output assembly in standalone extraction mode");
return AssemblyConstructorFactory.Instance.CreateEntity(cx, outputAssemblyCacheKey, null);
}

View File

@@ -53,7 +53,7 @@ namespace Semmle.Extraction.CSharp.Entities
if (attributeSyntax is object)
{
if (Context.Extractor.OutputPath != null)
if (!Context.Extractor.Standalone)
{
trapFile.attribute_location(this, Assembly.CreateOutputAssembly(Context));
}

View File

@@ -83,7 +83,7 @@ namespace Semmle.Extraction.CSharp.Entities
{
// Some built in operators lack locations, so loc is null.
yield return Context.CreateLocation(ReportingLocation);
if (Context.Extractor.OutputPath != null && loc.Kind == LocationKind.SourceFile)
if (!Context.Extractor.Standalone && loc.Kind == LocationKind.SourceFile)
yield return Assembly.CreateOutputAssembly(Context);
}
}

View File

@@ -108,7 +108,7 @@ namespace Semmle.Extraction.CSharp.Entities
foreach (var l in GetLocations(Symbol))
yield return Context.CreateLocation(l);
if (Context.Extractor.OutputPath != null && Symbol.DeclaringSyntaxReferences.Any())
if (!Context.Extractor.Standalone && Symbol.DeclaringSyntaxReferences.Any())
yield return Assembly.CreateOutputAssembly(Context);
}
}

View File

@@ -9,21 +9,18 @@ namespace Semmle.Extraction
/// </summary>
public class Extractor
{
public bool Standalone
{
get; private set;
}
public bool Standalone => OutputPath is null;
public string OutputPath { get; }
/// <summary>
/// Creates a new extractor instance for one compilation unit.
/// </summary>
/// <param name="standalone">If the extraction is standalone.</param>
/// <param name="outputPath">The name of the output DLL/EXE, or null if not specified (standalone extraction).</param>
/// <param name="logger">The object used for logging.</param>
/// <param name="pathTransformer">The object used for path transformations.</param>
public Extractor(bool standalone, string outputPath, ILogger logger, PathTransformer pathTransformer)
public Extractor(string outputPath, ILogger logger, PathTransformer pathTransformer)
{
Standalone = standalone;
OutputPath = outputPath;
Logger = logger;
PathTransformer = pathTransformer;
@@ -102,12 +99,6 @@ namespace Semmle.Extraction
public IEnumerable<string> MissingNamespaces => missingNamespaces;
public string OutputPath
{
get;
private set;
}
public ILogger Logger { get; private set; }
public static string Version => $"{ThisAssembly.Git.BaseTag} ({ThisAssembly.Git.Sha})";