diff --git a/csharp/extractor/Semmle.Extraction.CSharp/BUILD.bazel b/csharp/extractor/Semmle.Extraction.CSharp/BUILD.bazel
index 47e8ec48fd4c..42495f63ed44 100644
--- a/csharp/extractor/Semmle.Extraction.CSharp/BUILD.bazel
+++ b/csharp/extractor/Semmle.Extraction.CSharp/BUILD.bazel
@@ -6,7 +6,6 @@ load(
codeql_csharp_library(
name = "Semmle.Extraction.CSharp",
srcs = glob([
- "_Base/**/*.cs",
"CodeAnalysisExtensions/**/*.cs",
"Comments/**/*.cs",
"Entities/**/*.cs",
diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/CachedEntity`1.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/CachedEntity.cs
similarity index 92%
rename from csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/CachedEntity`1.cs
rename to csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/CachedEntity.cs
index 988f813c5198..ed0a21bc0836 100644
--- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/CachedEntity`1.cs
+++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/CachedEntity.cs
@@ -2,14 +2,14 @@
using System.IO;
using Microsoft.CodeAnalysis;
-namespace Semmle.Extraction
+namespace Semmle.Extraction.CSharp.Entities
{
///
/// A cached entity.
///
/// The property is used as label in caching.
///
- public abstract class CachedEntity : CSharp.LabelledEntity
+ public abstract class CachedEntity : LabelledEntity
{
protected CachedEntity(Context context) : base(context)
{
@@ -62,7 +62,7 @@ public override bool Equals(object? obj)
return other?.GetType() == GetType() && Equals(other.Symbol, Symbol);
}
- public override CSharp.TrapStackBehaviour TrapStackBehaviour => CSharp.TrapStackBehaviour.NoLabel;
+ public override TrapStackBehaviour TrapStackBehaviour => TrapStackBehaviour.NoLabel;
}
///
diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/CachedEntityFactory.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/CachedEntityFactory.cs
index 68cb8a393b5e..6753dce9c722 100644
--- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/CachedEntityFactory.cs
+++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/CachedEntityFactory.cs
@@ -3,7 +3,7 @@ namespace Semmle.Extraction.CSharp
///
/// A factory for creating cached entities.
///
- public abstract class CachedEntityFactory where TEntity : CachedEntity
+ public abstract class CachedEntityFactory where TEntity : Entities.CachedEntity
{
public abstract TEntity Create(Context cx, TInit init);
}
diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/CachedEntityFactoryExtensions.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/CachedEntityFactoryExtensions.cs
index 1101db458666..d7ca1293e33c 100644
--- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/CachedEntityFactoryExtensions.cs
+++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/CachedEntityFactoryExtensions.cs
@@ -16,7 +16,7 @@ public static class CachedEntityFactoryExtensions
/// The initializer for the entity.
/// The entity.
public static TEntity CreateEntity(this CachedEntityFactory factory, Context cx, object cacheKey, TInit init)
- where TEntity : CachedEntity => cx.CreateEntity(factory, cacheKey, init);
+ where TEntity : Entities.CachedEntity => cx.CreateEntity(factory, cacheKey, init);
///
/// Creates and populates a new entity from an `ISymbol`, or returns the existing one
@@ -30,6 +30,6 @@ public static TEntity CreateEntity(this CachedEntityFactoryThe entity.
public static TEntity CreateEntityFromSymbol(this CachedEntityFactory factory, Context cx, TSymbol init)
where TSymbol : ISymbol
- where TEntity : CachedEntity => cx.CreateEntityFromSymbol(factory, init);
+ where TEntity : Entities.CachedEntity => cx.CreateEntityFromSymbol(factory, init);
}
}
diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/CachedSymbol.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/CachedSymbol.cs
similarity index 98%
rename from csharp/extractor/Semmle.Extraction.CSharp/Entities/CachedSymbol.cs
rename to csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/CachedSymbol.cs
index ad5640b90e65..c39eb6076b57 100644
--- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/CachedSymbol.cs
+++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/CachedSymbol.cs
@@ -1,8 +1,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
-using System.Reflection.Metadata;
-using System.Reflection.Metadata.Ecma335;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/Entity.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/Entity.cs
index c699c965d931..16e656f3fba2 100644
--- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/Entity.cs
+++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/Entity.cs
@@ -6,9 +6,9 @@ namespace Semmle.Extraction.CSharp
{
public abstract class Entity : IEntity
{
- public virtual Semmle.Extraction.Context Context { get; }
+ public virtual Context Context { get; }
- protected Entity(Semmle.Extraction.Context context)
+ protected Entity(Context context)
{
this.Context = context;
}
diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/FreshEntity.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/FreshEntity.cs
index e4690e940c98..87776fa8c6b1 100644
--- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/FreshEntity.cs
+++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/FreshEntity.cs
@@ -1,11 +1,11 @@
using System.IO;
-namespace Semmle.Extraction
+namespace Semmle.Extraction.CSharp.Entities
{
///
/// An entity which has a default "*" ID assigned to it.
///
- public abstract class FreshEntity : CSharp.UnlabelledEntity
+ public abstract class FreshEntity : UnlabelledEntity
{
protected FreshEntity(Context cx) : base(cx)
{
@@ -33,6 +33,6 @@ public string DebugContents
public override Microsoft.CodeAnalysis.Location? ReportingLocation => null;
- public override CSharp.TrapStackBehaviour TrapStackBehaviour => CSharp.TrapStackBehaviour.NoLabel;
+ public override TrapStackBehaviour TrapStackBehaviour => TrapStackBehaviour.NoLabel;
}
}
diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/LabelledEntity.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/LabelledEntity.cs
index e664d82b2b8f..e458c935b0ee 100644
--- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/LabelledEntity.cs
+++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/LabelledEntity.cs
@@ -2,7 +2,7 @@ namespace Semmle.Extraction.CSharp
{
public abstract class LabelledEntity : Entity
{
- protected LabelledEntity(Semmle.Extraction.Context cx) : base(cx)
+ protected LabelledEntity(Context cx) : base(cx)
{
}
}
diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/UnlabelledEntity.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/UnlabelledEntity.cs
index 61d3dc8527bf..2bfcc35b274c 100644
--- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/UnlabelledEntity.cs
+++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/UnlabelledEntity.cs
@@ -2,7 +2,7 @@ namespace Semmle.Extraction.CSharp
{
public abstract class UnlabelledEntity : Entity
{
- protected UnlabelledEntity(Extraction.Context cx) : base(cx)
+ protected UnlabelledEntity(Context cx) : base(cx)
{
cx.AddFreshLabel(this);
}
diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/CachedEntity.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/CachedEntity.cs
deleted file mode 100644
index 149ed2e142ab..000000000000
--- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/CachedEntity.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-namespace Semmle.Extraction.CSharp.Entities
-{
- public abstract class CachedEntity : Extraction.CachedEntity where T : notnull
- {
- public override Context Context => (Context)base.Context;
-
- protected CachedEntity(Context context, T symbol)
- : base(context, symbol)
- {
- }
- }
-}
diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/CommentLine.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/CommentLine.cs
index 9029eb071d44..7638eefce125 100644
--- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/CommentLine.cs
+++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/CommentLine.cs
@@ -1,5 +1,4 @@
using System.IO;
-using Semmle.Extraction.Entities;
namespace Semmle.Extraction.CSharp.Entities
{
diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Compilations/Compilation.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Compilations/Compilation.cs
index ecb5d51d44d5..2c74775460da 100644
--- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Compilations/Compilation.cs
+++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Compilations/Compilation.cs
@@ -3,7 +3,6 @@
using System.IO;
using System.Linq;
using Microsoft.CodeAnalysis;
-using Semmle.Extraction.Entities;
using Semmle.Util;
namespace Semmle.Extraction.CSharp.Entities
diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/ExtractionMessage.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/ExtractionMessage.cs
index e3a85037d285..f8a771ae6d0e 100644
--- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/ExtractionMessage.cs
+++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/ExtractionMessage.cs
@@ -2,9 +2,8 @@
using System.IO;
using System.Threading;
using Semmle.Util;
-using Semmle.Extraction.CSharp;
-namespace Semmle.Extraction.Entities
+namespace Semmle.Extraction.CSharp.Entities
{
internal class ExtractionMessage : FreshEntity
{
@@ -41,7 +40,7 @@ protected override void Populate(TextWriter trapFile)
if (val == limit + 1)
{
Context.ExtractionContext.Logger.LogWarning($"Stopped logging extractor messages after reaching {limit}");
- _ = new ExtractionMessage(Context, new Message($"Stopped logging extractor messages after reaching {limit}", null, null, null, Util.Logging.Severity.Warning), bypassLimit: true);
+ _ = new ExtractionMessage(Context, new Message($"Stopped logging extractor messages after reaching {limit}", null, null, null, Semmle.Util.Logging.Severity.Warning), bypassLimit: true);
}
return;
}
diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Field.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Field.cs
index d95c0944f0fb..0a91eb57ecdf 100644
--- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Field.cs
+++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Field.cs
@@ -4,7 +4,6 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Semmle.Extraction.CSharp.Entities.Expressions;
-using Semmle.Extraction.Entities;
using Semmle.Extraction.Kinds;
namespace Semmle.Extraction.CSharp.Entities
diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/FreshEntity.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/FreshEntity.cs
deleted file mode 100644
index 79144e109d41..000000000000
--- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/FreshEntity.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-namespace Semmle.Extraction.CSharp.Entities
-{
- internal abstract class FreshEntity : Extraction.FreshEntity
- {
- public override Context Context => (Context)base.Context;
-
- protected FreshEntity(Context cx)
- : base(cx)
- {
- }
- }
-}
diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Locations/File.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Locations/File.cs
index 05b339edf013..f4b9d99af5bc 100644
--- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Locations/File.cs
+++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Locations/File.cs
@@ -6,7 +6,7 @@
namespace Semmle.Extraction.CSharp.Entities
{
- public class File : Extraction.CachedEntity
+ public class File : CachedEntity
{
protected readonly string originalPath;
private readonly Lazy transformedPathLazy;
diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Locations/Location.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Locations/Location.cs
index 0e67eac507b9..9f9e15e33f33 100644
--- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Locations/Location.cs
+++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Locations/Location.cs
@@ -1,7 +1,7 @@
namespace Semmle.Extraction.CSharp.Entities
{
#nullable disable warnings
- public abstract class Location : Extraction.CachedEntity
+ public abstract class Location : CachedEntity
{
#nullable restore warnings
protected Location(Context cx, Microsoft.CodeAnalysis.Location? init)
diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Modifier.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Modifier.cs
index aa68593d7d3c..cb1bb6e930da 100644
--- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Modifier.cs
+++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Modifier.cs
@@ -3,7 +3,7 @@
namespace Semmle.Extraction.CSharp.Entities
{
- internal class Modifier : Extraction.CachedEntity
+ internal class Modifier : CachedEntity
{
private Modifier(Context cx, string init)
: base(cx, init) { }
diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Parameter.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Parameter.cs
index 8c6a65ad5538..76d518776caa 100644
--- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Parameter.cs
+++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Parameter.cs
@@ -4,7 +4,6 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Semmle.Extraction.CSharp.Populators;
-using Semmle.Extraction.Entities;
namespace Semmle.Extraction.CSharp.Entities
{
diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Statement`1.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Statement`1.cs
index 0d7bdd31354b..3b16cfc31f0f 100644
--- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Statement`1.cs
+++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Statement`1.cs
@@ -1,7 +1,6 @@
using System.IO;
using Microsoft.CodeAnalysis.CSharp;
using Semmle.Extraction.CSharp.Populators;
-using Semmle.Extraction.Entities;
namespace Semmle.Extraction.CSharp.Entities
{
diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Statements/SyntheticEmptyBlock.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Statements/SyntheticEmptyBlock.cs
index 670d338d2b3c..6d6ebba24fb9 100644
--- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Statements/SyntheticEmptyBlock.cs
+++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Statements/SyntheticEmptyBlock.cs
@@ -1,7 +1,6 @@
using System.IO;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
-using Semmle.Extraction.Entities;
using Semmle.Extraction.Kinds;
namespace Semmle.Extraction.CSharp.Entities.Statements
diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Extractor/Context.cs b/csharp/extractor/Semmle.Extraction.CSharp/Extractor/Context.cs
index 4146cc810594..8d819d715f9f 100644
--- a/csharp/extractor/Semmle.Extraction.CSharp/Extractor/Context.cs
+++ b/csharp/extractor/Semmle.Extraction.CSharp/Extractor/Context.cs
@@ -2,8 +2,9 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
+using System.Linq;
using Microsoft.CodeAnalysis;
-using Semmle.Extraction.Entities;
+using Semmle.Util.Logging;
namespace Semmle.Extraction.CSharp
{
@@ -11,8 +12,453 @@ namespace Semmle.Extraction.CSharp
/// State that needs to be available throughout the extraction process.
/// There is one Context object per trap output file.
///
- public class Context : Extraction.Context
+ public class Context
{
+ ///
+ /// Access various extraction functions, e.g. logger, trap writer.
+ ///
+ public ExtractionContext ExtractionContext { get; }
+
+ ///
+ /// Access to the trap file.
+ ///
+ public TrapWriter TrapWriter { get; }
+
+ ///
+ /// Holds if assembly information should be prefixed to TRAP labels.
+ ///
+ public bool ShouldAddAssemblyTrapPrefix { get; }
+
+ public IList