Skip to content

Commit 841ef9a

Browse files
committed
Make derived 'Context' classes internal and adjust visibility of members in base 'Context'
1 parent 539fdf9 commit 841ef9a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+145
-136
lines changed

csharp/extractor/Semmle.Extraction.CIL.Driver/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ private static void ExtractAssembly(Layout layout, string assemblyPath, ILogger
2424
{
2525
var sw = new Stopwatch();
2626
sw.Start();
27-
Entities.Assembly.ExtractCIL(layout, assemblyPath, logger, nocache, extractPdbs, trapCompression, out _, out _);
27+
Analyser.ExtractCIL(layout, assemblyPath, logger, nocache, extractPdbs, trapCompression, out _, out _);
2828
sw.Stop();
2929
logger.Log(Severity.Info, " {0} ({1})", assemblyPath, sw.Elapsed);
3030
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using Semmle.Util.Logging;
2+
using System;
3+
using Semmle.Util;
4+
using Semmle.Extraction.CIL.Entities;
5+
6+
namespace Semmle.Extraction.CIL
7+
{
8+
public static class Analyser
9+
{
10+
private static void ExtractCIL(Extractor extractor, TrapWriter trapWriter, bool extractPdbs)
11+
{
12+
using var cilContext = new Context(extractor, trapWriter, extractor.OutputPath, extractPdbs);
13+
cilContext.Populate(new Assembly(cilContext));
14+
cilContext.PopulateAll();
15+
}
16+
17+
/// <summary>
18+
/// Main entry point to the CIL extractor.
19+
/// Call this to extract a given assembly.
20+
/// </summary>
21+
/// <param name="layout">The trap layout.</param>
22+
/// <param name="assemblyPath">The full path of the assembly to extract.</param>
23+
/// <param name="logger">The logger.</param>
24+
/// <param name="nocache">True to overwrite existing trap file.</param>
25+
/// <param name="extractPdbs">Whether to extract PDBs.</param>
26+
/// <param name="trapFile">The path of the trap file.</param>
27+
/// <param name="extracted">Whether the file was extracted (false=cached).</param>
28+
public static void ExtractCIL(Layout layout, string assemblyPath, ILogger logger, bool nocache, bool extractPdbs, TrapWriter.CompressionMode trapCompression, out string trapFile, out bool extracted)
29+
{
30+
trapFile = "";
31+
extracted = false;
32+
try
33+
{
34+
var canonicalPathCache = CanonicalPathCache.Create(logger, 1000);
35+
var pathTransformer = new PathTransformer(canonicalPathCache);
36+
var extractor = new Extractor(false, assemblyPath, logger, pathTransformer);
37+
var transformedAssemblyPath = pathTransformer.Transform(assemblyPath);
38+
var project = layout.LookupProjectOrDefault(transformedAssemblyPath);
39+
using var trapWriter = project.CreateTrapWriter(logger, transformedAssemblyPath.WithSuffix(".cil"), trapCompression, discardDuplicates: true);
40+
trapFile = trapWriter.TrapFile;
41+
if (nocache || !System.IO.File.Exists(trapFile))
42+
{
43+
ExtractCIL(extractor, trapWriter, extractPdbs);
44+
extracted = true;
45+
}
46+
}
47+
catch (Exception ex) // lgtm[cs/catch-of-all-exceptions]
48+
{
49+
logger.Log(Severity.Error, string.Format("Exception extracting {0}: {1}", assemblyPath, ex));
50+
}
51+
}
52+
}
53+
}

csharp/extractor/Semmle.Extraction.CIL/Context.Factories.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ namespace Semmle.Extraction.CIL
99
/// <summary>
1010
/// Provides methods for creating and caching various entities.
1111
/// </summary>
12-
public sealed partial class Context
12+
internal sealed partial class Context
1313
{
1414
private readonly Dictionary<object, Label> ids = new Dictionary<object, Label>();
1515

16-
public T Populate<T>(T e) where T : IExtractedEntity
16+
internal T Populate<T>(T e) where T : IExtractedEntity
1717
{
1818
if (e.Label.Valid)
1919
{
@@ -28,7 +28,7 @@ public T Populate<T>(T e) where T : IExtractedEntity
2828
else
2929
{
3030
e.Label = GetNewLabel();
31-
DefineLabel(e, TrapWriter.Writer, Extractor);
31+
DefineLabel(e);
3232
ids.Add(e, e.Label);
3333
PopulateLater(() =>
3434
{
@@ -76,7 +76,7 @@ public PrimitiveType Create(PrimitiveTypeCode code)
7676
{
7777
Label = GetNewLabel()
7878
};
79-
DefineLabel(e, TrapWriter.Writer, Extractor);
79+
DefineLabel(e);
8080
primitiveTypes[(int)code] = e;
8181
}
8282

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Semmle.Extraction.CIL
1010
/// Adds additional context that is specific for CIL extraction.
1111
/// One context = one DLL/EXE.
1212
/// </summary>
13-
public sealed partial class Context : Extraction.Context, IDisposable
13+
internal sealed partial class Context : Extraction.Context, IDisposable
1414
{
1515
private readonly FileStream stream;
1616
private Entities.Assembly? assemblyNull;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Semmle.Extraction.CIL
55
/// <summary>
66
/// A generic context which does not contain any type parameters.
77
/// </summary>
8-
public class EmptyContext : IGenericContext
8+
internal class EmptyContext : IGenericContext
99
{
1010
public EmptyContext(Context cx)
1111
{

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

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
using System.Reflection;
22
using System.Globalization;
33
using System.Collections.Generic;
4-
using Semmle.Util.Logging;
5-
using System;
64
using Semmle.Extraction.Entities;
75
using System.IO;
8-
using Semmle.Util;
96

107
namespace Semmle.Extraction.CIL.Entities
118
{
129
/// <summary>
1310
/// An assembly to extract.
1411
/// </summary>
15-
public class Assembly : LabelledEntity, ILocation
12+
internal class Assembly : LabelledEntity, ILocation
1613
{
1714
private readonly File file;
1815
private readonly AssemblyName assemblyName;
@@ -101,48 +98,5 @@ public override IEnumerable<IExtractionProduct> Contents
10198
}
10299
}
103100
}
104-
105-
private static void ExtractCIL(Extractor extractor, TrapWriter trapWriter, bool extractPdbs)
106-
{
107-
using var cilContext = new Context(extractor, trapWriter, extractor.OutputPath, extractPdbs);
108-
cilContext.Populate(new Assembly(cilContext));
109-
cilContext.PopulateAll();
110-
}
111-
112-
/// <summary>
113-
/// Main entry point to the CIL extractor.
114-
/// Call this to extract a given assembly.
115-
/// </summary>
116-
/// <param name="layout">The trap layout.</param>
117-
/// <param name="assemblyPath">The full path of the assembly to extract.</param>
118-
/// <param name="logger">The logger.</param>
119-
/// <param name="nocache">True to overwrite existing trap file.</param>
120-
/// <param name="extractPdbs">Whether to extract PDBs.</param>
121-
/// <param name="trapFile">The path of the trap file.</param>
122-
/// <param name="extracted">Whether the file was extracted (false=cached).</param>
123-
public static void ExtractCIL(Layout layout, string assemblyPath, ILogger logger, bool nocache, bool extractPdbs, TrapWriter.CompressionMode trapCompression, out string trapFile, out bool extracted)
124-
{
125-
trapFile = "";
126-
extracted = false;
127-
try
128-
{
129-
var canonicalPathCache = CanonicalPathCache.Create(logger, 1000);
130-
var pathTransformer = new PathTransformer(canonicalPathCache);
131-
var extractor = new Extractor(false, assemblyPath, logger, pathTransformer);
132-
var transformedAssemblyPath = pathTransformer.Transform(assemblyPath);
133-
var project = layout.LookupProjectOrDefault(transformedAssemblyPath);
134-
using var trapWriter = project.CreateTrapWriter(logger, transformedAssemblyPath.WithSuffix(".cil"), trapCompression, discardDuplicates: true);
135-
trapFile = trapWriter.TrapFile;
136-
if (nocache || !System.IO.File.Exists(trapFile))
137-
{
138-
ExtractCIL(extractor, trapWriter, extractPdbs);
139-
extracted = true;
140-
}
141-
}
142-
catch (Exception ex) // lgtm[cs/catch-of-all-exceptions]
143-
{
144-
logger.Log(Severity.Error, string.Format("Exception extracting {0}: {1}", assemblyPath, ex));
145-
}
146-
}
147101
}
148102
}

csharp/extractor/Semmle.Extraction.CIL/Entities/Base/IExtractedEntity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Semmle.Extraction.CIL
55
/// <summary>
66
/// A CIL entity which has been extracted.
77
/// </summary>
8-
public interface IExtractedEntity : IExtractionProduct, IEntity
8+
internal interface IExtractedEntity : IExtractionProduct, IEntity
99
{
1010
/// <summary>
1111
/// The contents of the entity.

csharp/extractor/Semmle.Extraction.CIL/Entities/Base/IExtractionProduct.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Semmle.Extraction.CIL
1212
/// - Enumerate Contents to produce more extraction products
1313
/// - Extract these until there is nothing left to extract
1414
/// </remarks>
15-
public interface IExtractionProduct
15+
internal interface IExtractionProduct
1616
{
1717
/// <summary>
1818
/// Perform further extraction/population of this item as necessary.

csharp/extractor/Semmle.Extraction.CIL/Entities/Base/IGenericContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Semmle.Extraction.CIL
66
/// When we decode a type/method signature, we need access to
77
/// generic parameters.
88
/// </summary>
9-
public interface IGenericContext
9+
internal interface IGenericContext
1010
{
1111
Context Cx { get; }
1212

csharp/extractor/Semmle.Extraction.CIL/Entities/Base/LabelledEntity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Semmle.Extraction.CIL
88
/// An entity that needs to be populated during extraction.
99
/// This assigns a key and optionally extracts its contents.
1010
/// </summary>
11-
public abstract class LabelledEntity : Extraction.LabelledEntity, IExtractedEntity
11+
internal abstract class LabelledEntity : Extraction.LabelledEntity, IExtractedEntity
1212
{
1313
// todo: with .NET 5 this can override the base context, and change the return type.
1414
public Context Cx => (Context)base.Context;

0 commit comments

Comments
 (0)