diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Comments/CommentBlock.cs b/csharp/extractor/Semmle.Extraction.CSharp/Comments/CommentBlock.cs index 48dcd9f85a18..08db5bba0138 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Comments/CommentBlock.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Comments/CommentBlock.cs @@ -12,7 +12,7 @@ internal class CommentBlock public IEnumerable CommentLines => lines; - public Location Location { get; private set; } + public Microsoft.CodeAnalysis.Location Location { get; private set; } public CommentBlock(CommentLine firstLine) { @@ -49,7 +49,7 @@ public void AddCommentLine(CommentLine line) { Location = !lines.Any() ? line.Location - : Location.Create( + : Microsoft.CodeAnalysis.Location.Create( line.Location.SourceTree!, new TextSpan(Location.SourceSpan.Start, line.Location.SourceSpan.End - Location.SourceSpan.Start)); diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Comments/CommentProcessor.cs b/csharp/extractor/Semmle.Extraction.CSharp/Comments/CommentProcessor.cs index d8c9152bec11..6b6e363ba5f7 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Comments/CommentProcessor.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Comments/CommentProcessor.cs @@ -19,10 +19,10 @@ public void AddComment(CommentLine comment) } // Comments sorted by location. - private readonly SortedDictionary comments = new SortedDictionary(new LocationComparer()); + private readonly SortedDictionary comments = new SortedDictionary(new LocationComparer()); // Program elements sorted by location. - private readonly SortedDictionary elements = new SortedDictionary(new LocationComparer()); + private readonly SortedDictionary elements = new SortedDictionary(new LocationComparer()); private readonly Dictionary duplicationGuardKeys = new Dictionary(); @@ -33,9 +33,9 @@ public void AddComment(CommentLine comment) return null; } - private class LocationComparer : IComparer + private class LocationComparer : IComparer { - public int Compare(Location? l1, Location? l2) => CommentProcessor.Compare(l1, l2); + public int Compare(Microsoft.CodeAnalysis.Location? l1, Microsoft.CodeAnalysis.Location? l2) => CommentProcessor.Compare(l1, l2); } /// @@ -44,7 +44,7 @@ private class LocationComparer : IComparer /// First location /// Second location /// <0 if l1 before l2, >0 if l1 after l2, else 0. - private static int Compare(Location? l1, Location? l2) + private static int Compare(Microsoft.CodeAnalysis.Location? l1, Microsoft.CodeAnalysis.Location? l2) { if (object.ReferenceEquals(l1, l2)) return 0; @@ -68,7 +68,7 @@ private static int Compare(Location? l1, Location? l2) /// The label of the element in the trap file. /// The duplication guard key of the element, if any. /// The location of the element. - public void AddElement(Label elementLabel, Key? duplicationGuardKey, Location? loc) + public void AddElement(Label elementLabel, Key? duplicationGuardKey, Microsoft.CodeAnalysis.Location? loc) { if (loc is not null && loc.IsInSource) elements[loc] = elementLabel; @@ -78,7 +78,7 @@ public void AddElement(Label elementLabel, Key? duplicationGuardKey, Location? l // Ensure that commentBlock and element refer to the same file // which can happen when processing multiple files. - private static void EnsureSameFile(Comments.CommentBlock commentBlock, ref KeyValuePair? element) + private static void EnsureSameFile(Comments.CommentBlock commentBlock, ref KeyValuePair? element) { if (element is not null && element.Value.Key.SourceTree != commentBlock.Location.SourceTree) element = null; @@ -96,9 +96,9 @@ private static void EnsureSameFile(Comments.CommentBlock commentBlock, ref KeyVa /// Output binding information. private void GenerateBindings( Comments.CommentBlock commentBlock, - KeyValuePair? previousElement, - KeyValuePair? nextElement, - KeyValuePair? parentElement, + KeyValuePair? previousElement, + KeyValuePair? nextElement, + KeyValuePair? parentElement, CommentBindingCallback callback ) { @@ -125,7 +125,7 @@ CommentBindingCallback callback } // Heuristic to decide which is the "best" element associated with the comment. - KeyValuePair? bestElement; + KeyValuePair? bestElement; if (previousElement is not null && previousElement.Value.Key.EndLine() == commentBlock.Location.StartLine()) { @@ -180,14 +180,14 @@ CommentBindingCallback callback private class ElementStack { // Invariant: the top of the stack must be contained by items below it. - private readonly Stack> elementStack = new Stack>(); + private readonly Stack> elementStack = new(); /// /// Add a new element to the stack. /// /// The stack is maintained. /// The new element to push. - public void Push(KeyValuePair value) + public void Push(KeyValuePair value) { // Maintain the invariant by popping existing elements while (elementStack.Count > 0 && !elementStack.Peek().Key.Contains(value.Key)) @@ -201,7 +201,7 @@ public void Push(KeyValuePair value) /// /// The location of the comment. /// An element completely containing l, or null if none found. - public KeyValuePair? FindParent(Location l) => + public KeyValuePair? FindParent(Microsoft.CodeAnalysis.Location l) => elementStack.Where(v => v.Key.Contains(l)).FirstOrNull(); /// @@ -209,7 +209,7 @@ public void Push(KeyValuePair value) /// /// The location of the comment. /// The element before l, or null. - public KeyValuePair? FindBefore(Location l) + public KeyValuePair? FindBefore(Microsoft.CodeAnalysis.Location l) { return elementStack .Where(v => v.Key.SourceSpan.End < l.SourceSpan.Start) @@ -222,7 +222,7 @@ public void Push(KeyValuePair value) /// The location of the comment. /// The next element. /// The next element. - public KeyValuePair? FindAfter(Location comment, KeyValuePair? next) + public KeyValuePair? FindAfter(Microsoft.CodeAnalysis.Location comment, KeyValuePair? next) { var p = FindParent(comment); return next.HasValue && p.HasValue && p.Value.Key.Before(next.Value.Key) ? null : next; @@ -233,7 +233,7 @@ public void Push(KeyValuePair value) private void GenerateBindings( Comments.CommentBlock block, ElementStack elementStack, - KeyValuePair? nextElement, + KeyValuePair? nextElement, CommentBindingCallback cb ) { @@ -259,8 +259,8 @@ CommentBindingCallback cb /// Where to send the results. /// true if there are more comments to process, false otherwise. private bool GenerateBindings( - IEnumerator> commentEnumerator, - KeyValuePair? nextElement, + IEnumerator> commentEnumerator, + KeyValuePair? nextElement, ElementStack elementStack, CommentBindingCallback cb ) @@ -319,8 +319,8 @@ public void GenerateBindings(CommentBindingCallback cb) var elementStack = new ElementStack(); - using IEnumerator> elementEnumerator = elements.GetEnumerator(); - using IEnumerator> commentEnumerator = comments.GetEnumerator(); + using IEnumerator> elementEnumerator = elements.GetEnumerator(); + using IEnumerator> commentEnumerator = comments.GetEnumerator(); if (!commentEnumerator.MoveNext()) { // There are no comments to process. diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Assembly.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Assembly.cs index 0fa9422e08ca..ed13fb28a903 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Assembly.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Assembly.cs @@ -3,7 +3,7 @@ namespace Semmle.Extraction.CSharp.Entities { - internal class Assembly : Extraction.Entities.Location + internal class Assembly : Location { public override Context Context => (Context)base.Context; @@ -56,7 +56,7 @@ public override bool Equals(object? obj) return false; } - public static Extraction.Entities.Location Create(Context cx, Microsoft.CodeAnalysis.Location loc) => AssemblyConstructorFactory.Instance.CreateEntity(cx, loc, loc); + public static Location Create(Context cx, Microsoft.CodeAnalysis.Location loc) => AssemblyConstructorFactory.Instance.CreateEntity(cx, loc, loc); private class AssemblyConstructorFactory : CachedEntityFactory { diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Attribute.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Attribute.cs index a70b84dde1df..e4799c05507f 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Attribute.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Attribute.cs @@ -151,9 +151,9 @@ private void ExtractArguments(TextWriter trapFile) public override Microsoft.CodeAnalysis.Location? ReportingLocation => attributeSyntax?.Name.GetLocation(); - private Semmle.Extraction.Entities.Location? location; + private Location? location; - private Semmle.Extraction.Entities.Location Location => + private Location Location => location ??= Context.CreateLocation(attributeSyntax is null ? entity.ReportingLocation : attributeSyntax.Name.GetLocation()); diff --git a/csharp/extractor/Semmle.Extraction.CSharp/_Base/Entities/Base/CachedEntityFactory.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/CachedEntityFactory.cs similarity index 100% rename from csharp/extractor/Semmle.Extraction.CSharp/_Base/Entities/Base/CachedEntityFactory.cs rename to csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/CachedEntityFactory.cs diff --git a/csharp/extractor/Semmle.Extraction.CSharp/_Base/Entities/Base/CachedEntityFactoryExtensions.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/CachedEntityFactoryExtensions.cs similarity index 100% rename from csharp/extractor/Semmle.Extraction.CSharp/_Base/Entities/Base/CachedEntityFactoryExtensions.cs rename to csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/CachedEntityFactoryExtensions.cs diff --git a/csharp/extractor/Semmle.Extraction.CSharp/_Base/Entities/Base/CachedEntity`1.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/CachedEntity`1.cs similarity index 100% rename from csharp/extractor/Semmle.Extraction.CSharp/_Base/Entities/Base/CachedEntity`1.cs rename to csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/CachedEntity`1.cs diff --git a/csharp/extractor/Semmle.Extraction.CSharp/_Base/Entities/Base/Entity.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/Entity.cs similarity index 100% rename from csharp/extractor/Semmle.Extraction.CSharp/_Base/Entities/Base/Entity.cs rename to csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/Entity.cs diff --git a/csharp/extractor/Semmle.Extraction.CSharp/_Base/Entities/Base/FreshEntity.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/FreshEntity.cs similarity index 100% rename from csharp/extractor/Semmle.Extraction.CSharp/_Base/Entities/Base/FreshEntity.cs rename to csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/FreshEntity.cs diff --git a/csharp/extractor/Semmle.Extraction.CSharp/_Base/Entities/Base/IEntity.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/IEntity.cs similarity index 100% rename from csharp/extractor/Semmle.Extraction.CSharp/_Base/Entities/Base/IEntity.cs rename to csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/IEntity.cs diff --git a/csharp/extractor/Semmle.Extraction.CSharp/_Base/Entities/Base/LabelledEntity.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/LabelledEntity.cs similarity index 100% rename from csharp/extractor/Semmle.Extraction.CSharp/_Base/Entities/Base/LabelledEntity.cs rename to csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/LabelledEntity.cs diff --git a/csharp/extractor/Semmle.Extraction.CSharp/_Base/Entities/Base/UnlabelledEntity.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/UnlabelledEntity.cs similarity index 100% rename from csharp/extractor/Semmle.Extraction.CSharp/_Base/Entities/Base/UnlabelledEntity.cs rename to csharp/extractor/Semmle.Extraction.CSharp/Entities/Base/UnlabelledEntity.cs diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/CachedSymbol.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/CachedSymbol.cs index 4a4d483ea372..ad5640b90e65 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/CachedSymbol.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/CachedSymbol.cs @@ -89,7 +89,7 @@ protected void ExtractCompilerGenerated(TextWriter trapFile) /// public virtual Microsoft.CodeAnalysis.Location? FullLocation => Symbol.Locations.BestOrDefault(); - public virtual IEnumerable Locations + public virtual IEnumerable Locations { get { @@ -143,6 +143,6 @@ public ExpressionSyntax? ExpressionBody public override bool NeedsPopulation => Context.Defines(Symbol); - public Extraction.Entities.Location Location => Context.CreateLocation(ReportingLocation); + public Location Location => Context.CreateLocation(ReportingLocation); } } diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Constructor.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Constructor.cs index 047a7b68ae6d..c3ce2bb6d29e 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Constructor.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Constructor.cs @@ -116,7 +116,7 @@ protected override void ExtractInitializers(TextWriter trapFile) } } - private void ExtractSourceInitializer(TextWriter trapFile, ITypeSymbol? type, IMethodSymbol? symbol, ArgumentListSyntax arguments, Location location) + private void ExtractSourceInitializer(TextWriter trapFile, ITypeSymbol? type, IMethodSymbol? symbol, ArgumentListSyntax arguments, Microsoft.CodeAnalysis.Location location) { var initInfo = new ExpressionInfo(Context, AnnotatedTypeSymbol.CreateNotAnnotated(type), diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expression.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expression.cs index cdd2964ff216..f5021d38eeb5 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expression.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expression.cs @@ -15,7 +15,7 @@ internal class Expression : FreshEntity, IExpressionParentEntity { private readonly IExpressionInfo info; public AnnotatedTypeSymbol? Type { get; private set; } - public Extraction.Entities.Location Location { get; } + public Location Location { get; } public ExprKind Kind { get; } internal Expression(IExpressionInfo info, bool shouldPopulate = true) @@ -62,7 +62,7 @@ protected sealed override void Populate(TextWriter trapFile) type.PopulateGenerics(); } - public override Location? ReportingLocation => Location.Symbol; + public override Microsoft.CodeAnalysis.Location? ReportingLocation => Location.Symbol; internal void SetType(ITypeSymbol? type) { @@ -138,7 +138,7 @@ private static bool ContainsPattern(SyntaxNode node) => /// Creates a generated expression from a typed constant. /// public static Expression? CreateGenerated(Context cx, TypedConstant constant, IExpressionParentEntity parent, - int childIndex, Extraction.Entities.Location location) + int childIndex, Location location) { if (constant.IsNull || constant.Type is null) @@ -176,7 +176,7 @@ private static bool ContainsPattern(SyntaxNode node) => /// Creates a generated expression for a default argument value. /// public static Expression? CreateGenerated(Context cx, IParameterSymbol parameter, IExpressionParentEntity parent, - int childIndex, Extraction.Entities.Location location) + int childIndex, Location location) { if (!parameter.HasExplicitDefaultValue || parameter.Type is IErrorTypeSymbol) @@ -315,7 +315,7 @@ public static bool IsDynamic(Context cx, ExpressionSyntax node) /// /// Given `b` in `a?.b.c`, return `(a?.b, a?.b)`. - /// + /// /// Given `c` in `a?.b?.c.d`, return `(b?.c, a?.b?.c)`. /// /// A MemberBindingExpression. diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/ExpressionInfo.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/ExpressionInfo.cs index 3474ad4a8183..8ebc0e2a0efa 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/ExpressionInfo.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/ExpressionInfo.cs @@ -10,14 +10,14 @@ internal class ExpressionInfo : IExpressionInfo { public Context Context { get; } public AnnotatedTypeSymbol? Type { get; } - public Extraction.Entities.Location Location { get; } + public Location Location { get; } public ExprKind Kind { get; } public IExpressionParentEntity Parent { get; } public int Child { get; } public bool IsCompilerGenerated { get; } public string? ExprValue { get; } - public ExpressionInfo(Context cx, AnnotatedTypeSymbol? type, Extraction.Entities.Location location, ExprKind kind, + public ExpressionInfo(Context cx, AnnotatedTypeSymbol? type, Location location, ExprKind kind, IExpressionParentEntity parent, int child, bool isCompilerGenerated, string? value) { Context = cx; diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/ExpressionNodeInfo.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/ExpressionNodeInfo.cs index a78f7e8c80b9..924382a55507 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/ExpressionNodeInfo.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/ExpressionNodeInfo.cs @@ -115,9 +115,9 @@ public string? ExprValue } } - private Extraction.Entities.Location? cachedLocation; + private Location? cachedLocation; - public Extraction.Entities.Location Location + public Location Location { get { diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/ArrayCreation.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/ArrayCreation.cs index 302bcaded39a..72993e2db010 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/ArrayCreation.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/ArrayCreation.cs @@ -88,7 +88,7 @@ private NormalArrayCreation(ExpressionNodeInfo info) : base(info) { } public static Expression Create(ExpressionNodeInfo info) => new NormalArrayCreation(info).TryPopulate(); - public static Expression CreateGenerated(Context cx, IExpressionParentEntity parent, int childIndex, ITypeSymbol type, IEnumerable items, Semmle.Extraction.Entities.Location location) + public static Expression CreateGenerated(Context cx, IExpressionParentEntity parent, int childIndex, ITypeSymbol type, IEnumerable items, Location location) { var info = new ExpressionInfo( cx, diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/Cast.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/Cast.cs index 62e23e3b66dc..20a5dc611a31 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/Cast.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/Cast.cs @@ -32,7 +32,7 @@ protected override void PopulateExpression(TextWriter trapFile) public override Microsoft.CodeAnalysis.Location ReportingLocation => Syntax.GetLocation(); - public static Expression CreateGenerated(Context cx, IExpressionParentEntity parent, int childIndex, Microsoft.CodeAnalysis.ITypeSymbol type, object? value, Action createChild, Extraction.Entities.Location location) + public static Expression CreateGenerated(Context cx, IExpressionParentEntity parent, int childIndex, Microsoft.CodeAnalysis.ITypeSymbol type, object? value, Action createChild, Location location) { var info = new ExpressionInfo( cx, diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/Default.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/Default.cs index 968f2e8f43b7..a7758e4243f9 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/Default.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/Default.cs @@ -15,7 +15,7 @@ protected override void PopulateExpression(TextWriter trapFile) TypeAccess.Create(Context, Syntax.Type, this, 0); } - public static Expression CreateGenerated(Context cx, IExpressionParentEntity parent, int childIndex, Extraction.Entities.Location location, string? value) + public static Expression CreateGenerated(Context cx, IExpressionParentEntity parent, int childIndex, Location location, string? value) { var info = new ExpressionInfo( cx, diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/ImplicitCast.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/ImplicitCast.cs index 3e886a9c3ac9..b0508bf83b7e 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/ImplicitCast.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/ImplicitCast.cs @@ -55,7 +55,7 @@ private void AddOperatorCall(IMethodSymbol method) /// Creates a new generated expression with an implicit conversion added. /// public static Expression CreateGeneratedConversion(Context cx, IExpressionParentEntity parent, int childIndex, ITypeSymbol type, object value, - Extraction.Entities.Location location) + Location location) { ExpressionInfo create(ExprKind kind, string? v) => new ExpressionInfo( @@ -85,7 +85,7 @@ ExpressionInfo create(ExprKind kind, string? v) => /// Creates a new generated cast expression. /// public static Expression CreateGenerated(Context cx, IExpressionParentEntity parent, int childIndex, ITypeSymbol type, object value, - Extraction.Entities.Location location) + Location location) { var info = new ExpressionInfo(cx, AnnotatedTypeSymbol.CreateNotAnnotated(type), diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/Initializer.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/Initializer.cs index cdc2e87798ec..92e2b910f992 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/Initializer.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/Initializer.cs @@ -36,7 +36,7 @@ protected override void PopulateExpression(TextWriter trapFile) } } - public static Expression CreateGenerated(Context cx, IExpressionParentEntity parent, int index, Extraction.Entities.Location location) + public static Expression CreateGenerated(Context cx, IExpressionParentEntity parent, int index, Location location) { var info = new ExpressionInfo( cx, diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/Literal.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/Literal.cs index 72d54abf6c1a..d471839f97a3 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/Literal.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/Literal.cs @@ -37,7 +37,7 @@ private static ExprKind GetKind(ExpressionNodeInfo info) return GetExprKind(type, info.Node, info.Location, info.Context); } - private static ExprKind GetExprKind(ITypeSymbol? type, ExpressionSyntax? expr, Extraction.Entities.Location loc, Context context) + private static ExprKind GetExprKind(ITypeSymbol? type, ExpressionSyntax? expr, Location loc, Context context) { switch (type?.SpecialType) { @@ -87,7 +87,7 @@ private static ExprKind GetExprKind(ITypeSymbol? type, ExpressionSyntax? expr, E } public static Expression CreateGenerated(Context cx, IExpressionParentEntity parent, int childIndex, ITypeSymbol type, object? value, - Extraction.Entities.Location location) + Location location) { var kind = value is null ? ExprKind.NULL_LITERAL : GetExprKind(type, null, location, cx); var info = new ExpressionInfo( @@ -103,7 +103,7 @@ public static Expression CreateGenerated(Context cx, IExpressionParentEntity par return new Expression(info); } - public static Expression CreateGeneratedNullLiteral(Context cx, IExpressionParentEntity parent, int childIndex, Extraction.Entities.Location location) + public static Expression CreateGeneratedNullLiteral(Context cx, IExpressionParentEntity parent, int childIndex, Location location) { var info = new ExpressionInfo( cx, diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/ObjectCreation/DateTimeObjectCreation.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/ObjectCreation/DateTimeObjectCreation.cs index 012a30d81cc4..98f7a8bce924 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/ObjectCreation/DateTimeObjectCreation.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/ObjectCreation/DateTimeObjectCreation.cs @@ -49,7 +49,7 @@ protected void PopulateExpression(TextWriter trapFile) // The `type` symbol must be a System.DateTime type and the value must be a System.DateTime object. // The expression that is being created is a call to the System.DateTime(long) constructor, where // the number of ticks from the `value` object is used as the argument to the constructor call. - public static Expression CreateGenerated(Context cx, IExpressionParentEntity parent, int childIndex, ITypeSymbol type, object? value, Extraction.Entities.Location location) + public static Expression CreateGenerated(Context cx, IExpressionParentEntity parent, int childIndex, ITypeSymbol type, object? value, Location location) { var constructorSymbol = GetDateTimeConstructor(type) ?? throw new InternalError("Could not find symbol for System.DateTime(long)"); var expr = new DateTimeObjectCreation(constructorSymbol, new ExpressionInfo( @@ -68,4 +68,4 @@ public static Expression CreateGenerated(Context cx, IExpressionParentEntity par return expr.TryPopulate(); } } -} \ No newline at end of file +} diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/This.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/This.cs index 33f2ad9fbc78..53dfc84de094 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/This.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/This.cs @@ -7,7 +7,7 @@ internal class This : Expression { private This(IExpressionInfo info) : base(info) { } - public static This CreateImplicit(Context cx, ITypeSymbol @class, Extraction.Entities.Location loc, IExpressionParentEntity parent, int child) => + public static This CreateImplicit(Context cx, ITypeSymbol @class, Location loc, IExpressionParentEntity parent, int child) => new This(new ExpressionInfo(cx, AnnotatedTypeSymbol.CreateNotAnnotated(@class), loc, Kinds.ExprKind.THIS_ACCESS, parent, child, isCompilerGenerated: true, null)); public static This CreateExplicit(ExpressionNodeInfo info) => new This(info.SetKind(ExprKind.THIS_ACCESS)); diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/TypeAccess.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/TypeAccess.cs index b4e678d8ab6b..55afd83318ef 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/TypeAccess.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/TypeAccess.cs @@ -35,7 +35,7 @@ protected override void PopulateExpression(TextWriter trapFile) public static Expression Create(ExpressionNodeInfo info) => new TypeAccess(info).TryPopulate(); - public static Expression CreateGenerated(Context cx, IExpressionParentEntity parent, int childIndex, Microsoft.CodeAnalysis.ITypeSymbol type, Extraction.Entities.Location location) + public static Expression CreateGenerated(Context cx, IExpressionParentEntity parent, int childIndex, Microsoft.CodeAnalysis.ITypeSymbol type, Location location) { var typeAccessInfo = new ExpressionInfo( cx, diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/TypeOf.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/TypeOf.cs index b36c1e425a03..cb205d383ac0 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/TypeOf.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/TypeOf.cs @@ -17,7 +17,7 @@ protected override void PopulateExpression(TextWriter trapFile) TypeAccess.Create(Context, Syntax.Type, this, TypeAccessIndex); } - public static Expression CreateGenerated(Context cx, IExpressionParentEntity parent, int childIndex, Microsoft.CodeAnalysis.ITypeSymbol type, Extraction.Entities.Location location) + public static Expression CreateGenerated(Context cx, IExpressionParentEntity parent, int childIndex, Microsoft.CodeAnalysis.ITypeSymbol type, Location location) { var info = new ExpressionInfo( cx, diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/VariableDeclaration.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/VariableDeclaration.cs index 5931feb070c0..c44f9e2b9468 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/VariableDeclaration.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/VariableDeclaration.cs @@ -13,7 +13,7 @@ internal class VariableDeclaration : Expression { private VariableDeclaration(IExpressionInfo info) : base(info) { } - public static VariableDeclaration Create(Context cx, ISymbol symbol, AnnotatedTypeSymbol? type, TypeSyntax? optionalSyntax, Extraction.Entities.Location exprLocation, bool isVar, IExpressionParentEntity parent, int child) + public static VariableDeclaration Create(Context cx, ISymbol symbol, AnnotatedTypeSymbol? type, TypeSyntax? optionalSyntax, Location exprLocation, bool isVar, IExpressionParentEntity parent, int child) { var ret = new VariableDeclaration(new ExpressionInfo(cx, type, exprLocation, ExprKind.LOCAL_VAR_DECL, parent, child, isCompilerGenerated: false, null)); cx.Try(null, null, () => diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Field.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Field.cs index 4894da062e3f..d95c0944f0fb 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Field.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Field.cs @@ -105,7 +105,7 @@ public override void Populate(TextWriter trapFile) } } - private Expression AddInitializerAssignment(TextWriter trapFile, ExpressionSyntax initializer, Extraction.Entities.Location loc, + private Expression AddInitializerAssignment(TextWriter trapFile, ExpressionSyntax initializer, Location loc, string? constValue, ref int child) { var type = Symbol.GetAnnotatedType(); diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/IExpressionInfo.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/IExpressionInfo.cs index ea43b19456cf..167ad8066718 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/IExpressionInfo.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/IExpressionInfo.cs @@ -18,7 +18,7 @@ internal interface IExpressionInfo /// /// The location of the expression. /// - Extraction.Entities.Location Location { get; } + Location Location { get; } /// /// The kind of the expression. diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/File.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Locations/File.cs similarity index 76% rename from csharp/extractor/Semmle.Extraction.CSharp/Entities/File.cs rename to csharp/extractor/Semmle.Extraction.CSharp/Entities/Locations/File.cs index bd2a7fbd181f..05b339edf013 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/File.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Locations/File.cs @@ -6,21 +6,37 @@ namespace Semmle.Extraction.CSharp.Entities { - internal class File : Extraction.Entities.File + public class File : Extraction.CachedEntity { + protected readonly string originalPath; + private readonly Lazy transformedPathLazy; + protected PathTransformer.ITransformedPath TransformedPath => transformedPathLazy.Value; public override Context Context => (Context)base.Context; + public override Microsoft.CodeAnalysis.Location? ReportingLocation => null; + + public override bool NeedsPopulation => true; protected File(Context cx, string path) : base(cx, path) { + originalPath = path; + var adjustedPath = BinaryLogExtractionContext.GetAdjustedPath(Context.ExtractionContext, originalPath) ?? path; + transformedPathLazy = new Lazy(() => Context.ExtractionContext.PathTransformer.Transform(adjustedPath)); } + public override void WriteId(EscapingTextWriter trapFile) + { + trapFile.Write(TransformedPath.DatabaseId); + trapFile.Write(";sourcefile"); + } + + public override void Populate(TextWriter trapFile) { trapFile.files(this, TransformedPath.Value); if (TransformedPath.ParentDirectory is PathTransformer.ITransformedPath dir) - trapFile.containerparent(Extraction.Entities.Folder.Create(Context, dir), this); + trapFile.containerparent(Folder.Create(Context, dir), this); var trees = Context.Compilation.SyntaxTrees.Where(t => t.FilePath == originalPath); diff --git a/csharp/extractor/Semmle.Extraction.CSharp/_Base/Entities/Folder.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Locations/Folder.cs similarity index 63% rename from csharp/extractor/Semmle.Extraction.CSharp/_Base/Entities/Folder.cs rename to csharp/extractor/Semmle.Extraction.CSharp/Entities/Locations/Folder.cs index 465d545d9833..5d0fdc422b89 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/_Base/Entities/Folder.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Locations/Folder.cs @@ -1,10 +1,10 @@ using System.IO; -namespace Semmle.Extraction.Entities +namespace Semmle.Extraction.CSharp.Entities { - public sealed class Folder : CachedEntity + public sealed class Folder : Extraction.CachedEntity { - private Folder(Context cx, PathTransformer.ITransformedPath init) : base(cx, init) { } + private Folder(Extraction.Context cx, PathTransformer.ITransformedPath init) : base(cx, init) { } public override void Populate(TextWriter trapFile) { @@ -21,16 +21,16 @@ public override void WriteId(EscapingTextWriter trapFile) trapFile.Write(";folder"); } - public static Folder Create(Context cx, PathTransformer.ITransformedPath folder) => + public static Folder Create(Extraction.Context cx, PathTransformer.ITransformedPath folder) => FolderFactory.Instance.CreateEntity(cx, folder, folder); public override Microsoft.CodeAnalysis.Location? ReportingLocation => null; - private class FolderFactory : CachedEntityFactory + private class FolderFactory : Extraction.CachedEntityFactory { public static FolderFactory Instance { get; } = new FolderFactory(); - public override Folder Create(Context cx, PathTransformer.ITransformedPath init) => new Folder(cx, init); + public override Folder Create(Extraction.Context cx, PathTransformer.ITransformedPath init) => new Folder(cx, init); } public override int GetHashCode() => Symbol.GetHashCode(); diff --git a/csharp/extractor/Semmle.Extraction.CSharp/_Base/Entities/GeneratedFile.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Locations/GeneratedFile.cs similarity index 95% rename from csharp/extractor/Semmle.Extraction.CSharp/_Base/Entities/GeneratedFile.cs rename to csharp/extractor/Semmle.Extraction.CSharp/Entities/Locations/GeneratedFile.cs index b4a771f53db1..5a62619fd060 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/_Base/Entities/GeneratedFile.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Locations/GeneratedFile.cs @@ -1,6 +1,6 @@ using System.IO; -namespace Semmle.Extraction.Entities +namespace Semmle.Extraction.CSharp.Entities { internal class GeneratedFile : File { diff --git a/csharp/extractor/Semmle.Extraction.CSharp/_Base/Entities/GeneratedLocation.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Locations/GeneratedLocation.cs similarity index 85% rename from csharp/extractor/Semmle.Extraction.CSharp/_Base/Entities/GeneratedLocation.cs rename to csharp/extractor/Semmle.Extraction.CSharp/Entities/Locations/GeneratedLocation.cs index db552f7e4529..01059bdd8bf9 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/_Base/Entities/GeneratedLocation.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Locations/GeneratedLocation.cs @@ -1,6 +1,6 @@ using System.IO; -namespace Semmle.Extraction.Entities +namespace Semmle.Extraction.CSharp.Entities { public class GeneratedLocation : SourceLocation { @@ -28,7 +28,7 @@ public override void WriteId(EscapingTextWriter trapFile) public override bool Equals(object? obj) => obj is not null && obj.GetType() == typeof(GeneratedLocation); - public static GeneratedLocation Create(Context cx) => GeneratedLocationFactory.Instance.CreateEntity(cx, typeof(GeneratedLocation), null); + public static GeneratedLocation Create(Extraction.Context cx) => GeneratedLocationFactory.Instance.CreateEntity(cx, typeof(GeneratedLocation), null); private class GeneratedLocationFactory : CachedEntityFactory { diff --git a/csharp/extractor/Semmle.Extraction.CSharp/_Base/Entities/Location.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Locations/Location.cs similarity index 72% rename from csharp/extractor/Semmle.Extraction.CSharp/_Base/Entities/Location.cs rename to csharp/extractor/Semmle.Extraction.CSharp/Entities/Locations/Location.cs index d77fb46544d5..0e67eac507b9 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/_Base/Entities/Location.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Locations/Location.cs @@ -1,7 +1,7 @@ -namespace Semmle.Extraction.Entities +namespace Semmle.Extraction.CSharp.Entities { #nullable disable warnings - public abstract class Location : CachedEntity + public abstract class Location : Extraction.CachedEntity { #nullable restore warnings protected Location(Context cx, Microsoft.CodeAnalysis.Location? init) diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/NonGeneratedSourceLocation.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Locations/NonGeneratedSourceLocation.cs similarity index 78% rename from csharp/extractor/Semmle.Extraction.CSharp/Entities/NonGeneratedSourceLocation.cs rename to csharp/extractor/Semmle.Extraction.CSharp/Entities/Locations/NonGeneratedSourceLocation.cs index df41abd524d3..f0db29a606b4 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/NonGeneratedSourceLocation.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Locations/NonGeneratedSourceLocation.cs @@ -1,22 +1,20 @@ -using System; using System.IO; using Microsoft.CodeAnalysis; -using Semmle.Util.Logging; namespace Semmle.Extraction.CSharp.Entities { - internal class NonGeneratedSourceLocation : Extraction.Entities.SourceLocation + internal class NonGeneratedSourceLocation : SourceLocation { public override Context Context => (Context)base.Context; - protected NonGeneratedSourceLocation(Context cx, Location init) + protected NonGeneratedSourceLocation(Context cx, Microsoft.CodeAnalysis.Location init) : base(cx, init) { Position = init.GetLineSpan(); FileEntity = File.Create(Context, Position.Path); } - public static NonGeneratedSourceLocation Create(Context cx, Location loc) => SourceLocationFactory.Instance.CreateEntity(cx, loc, loc); + public static NonGeneratedSourceLocation Create(Context cx, Microsoft.CodeAnalysis.Location loc) => SourceLocationFactory.Instance.CreateEntity(cx, loc, loc); public override void Populate(TextWriter trapFile) { @@ -28,7 +26,7 @@ public override void Populate(TextWriter trapFile) if (mapped.HasMappedPath && mapped.IsValid) { var path = Context.TryAdjustRelativeMappedFilePath(mapped.Path, Position.Path); - var mappedLoc = Create(Context, Location.Create(path, default, mapped.Span)); + var mappedLoc = Create(Context, Microsoft.CodeAnalysis.Location.Create(path, default, mapped.Span)); trapFile.locations_mapped(this, mappedLoc); } @@ -58,11 +56,11 @@ public override void WriteId(EscapingTextWriter trapFile) trapFile.Write(Position.Span.End.Character); } - private class SourceLocationFactory : CachedEntityFactory + private class SourceLocationFactory : CachedEntityFactory { public static SourceLocationFactory Instance { get; } = new SourceLocationFactory(); - public override NonGeneratedSourceLocation Create(Context cx, Location init) => new NonGeneratedSourceLocation(cx, init); + public override NonGeneratedSourceLocation Create(Context cx, Microsoft.CodeAnalysis.Location init) => new NonGeneratedSourceLocation(cx, init); } } } diff --git a/csharp/extractor/Semmle.Extraction.CSharp/_Base/Entities/SourceLocation.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Locations/SourceLocation.cs similarity index 84% rename from csharp/extractor/Semmle.Extraction.CSharp/_Base/Entities/SourceLocation.cs rename to csharp/extractor/Semmle.Extraction.CSharp/Entities/Locations/SourceLocation.cs index d126f5521658..382a4899a833 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/_Base/Entities/SourceLocation.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Locations/SourceLocation.cs @@ -1,4 +1,4 @@ -namespace Semmle.Extraction.Entities +namespace Semmle.Extraction.CSharp.Entities { public abstract class SourceLocation : Location { diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Method.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Method.cs index c1a2082a3ba2..6890ca490847 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Method.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Method.cs @@ -290,7 +290,7 @@ public static void AddExplicitInterfaceQualifierToId(Context cx, EscapingTextWri public Method OriginalDefinition => Create(Context, Symbol.OriginalDefinition); - public override Location? FullLocation => ReportingLocation; + public override Microsoft.CodeAnalysis.Location? FullLocation => ReportingLocation; public override bool IsSourceDeclaration => Symbol.IsSourceDeclaration(); diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Modifier.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Modifier.cs index 390311ca94b1..aa68593d7d3c 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Modifier.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Modifier.cs @@ -8,7 +8,7 @@ internal class Modifier : Extraction.CachedEntity private Modifier(Context cx, string init) : base(cx, init) { } - public override Location? ReportingLocation => null; + public override Microsoft.CodeAnalysis.Location? ReportingLocation => null; public override void WriteId(EscapingTextWriter trapFile) { diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Namespace.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Namespace.cs index 874d8e1b69f3..e431ff0a7202 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Namespace.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Namespace.cs @@ -8,7 +8,7 @@ internal sealed class Namespace : CachedEntity private Namespace(Context cx, INamespaceSymbol init) : base(cx, init) { } - public override Location? ReportingLocation => null; + public override Microsoft.CodeAnalysis.Location? ReportingLocation => null; public override void Populate(TextWriter trapFile) { diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Types/NamedType.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Types/NamedType.cs index 75a931e2266f..189a07f6f476 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Types/NamedType.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Types/NamedType.cs @@ -101,7 +101,7 @@ public override void Populate(TextWriter trapFile) public override IEnumerable TypeMentions => TypeArguments; - public override IEnumerable Locations + public override IEnumerable Locations { get { diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Types/Nullability.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Types/Nullability.cs index 67a68958a0f4..9791f386a199 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Types/Nullability.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Types/Nullability.cs @@ -102,7 +102,7 @@ public NullabilityEntity(Context cx, Nullability init) : base(cx, init) { } - public override Location ReportingLocation => throw new System.NotImplementedException(); + public override Microsoft.CodeAnalysis.Location ReportingLocation => throw new System.NotImplementedException(); public override bool NeedsPopulation => true; diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Types/TypeParameterConstraints.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Types/TypeParameterConstraints.cs index 8684c0b820d1..6f85759dee0f 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Types/TypeParameterConstraints.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Types/TypeParameterConstraints.cs @@ -49,7 +49,7 @@ public override void Populate(TextWriter trapFile) } } - public override Location? ReportingLocation => null; + public override Microsoft.CodeAnalysis.Location? ReportingLocation => null; public static TypeParameterConstraints Create(Context cx, TypeParameter p) => TypeParameterConstraintsFactory.Instance.CreateEntity(cx, (typeof(TypeParameterConstraints), p), p); @@ -62,4 +62,3 @@ private class TypeParameterConstraintsFactory : CachedEntityFactory - internal class Context : Extraction.Context + public class Context : Extraction.Context { /// /// The program database provided by Roslyn. @@ -117,17 +117,17 @@ public override void WithDuplicationGuard(Key key, Action a) } } - public override Extraction.Entities.Location CreateLocation() + public override Entities.Location CreateLocation() { return SourceTree is null - ? GeneratedLocation.Create(this) + ? Entities.GeneratedLocation.Create(this) : CreateLocation(Microsoft.CodeAnalysis.Location.Create(SourceTree, Microsoft.CodeAnalysis.Text.TextSpan.FromBounds(0, 0))); } - public override Extraction.Entities.Location CreateLocation(Microsoft.CodeAnalysis.Location? location) + public override Entities.Location CreateLocation(Microsoft.CodeAnalysis.Location? location) { return (location is null || location.Kind == LocationKind.None) - ? GeneratedLocation.Create(this) + ? Entities.GeneratedLocation.Create(this) : location.IsInSource ? Entities.NonGeneratedSourceLocation.Create(this, location) : Entities.Assembly.Create(this, location); @@ -145,7 +145,7 @@ public void BindComments(Entity entity, Microsoft.CodeAnalysis.Location? l) CommentGenerator.AddElement(entity.Label, duplicationGuardKey, l); } - protected override bool IsEntityDuplicationGuarded(IEntity entity, [NotNullWhen(true)] out Extraction.Entities.Location? loc) + protected override bool IsEntityDuplicationGuarded(IEntity entity, [NotNullWhen(true)] out Entities.Location? loc) { if (CreateLocation(entity.ReportingLocation) is Entities.NonGeneratedSourceLocation l) { diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Tuples.cs b/csharp/extractor/Semmle.Extraction.CSharp/Tuples.cs index 49d08fc80ef7..e8215ce90b52 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Tuples.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Tuples.cs @@ -17,7 +17,7 @@ namespace Semmle.Extraction.CSharp /// internal static class Tuples { - internal static void assemblies(this System.IO.TextWriter trapFile, Assembly assembly, Extraction.Entities.File file, string identifier, string name, string version) => + internal static void assemblies(this System.IO.TextWriter trapFile, Assembly assembly, Entities.File file, string identifier, string name, string version) => trapFile.WriteTuple("assemblies", assembly, file, identifier, name, version); internal static void accessor_location(this TextWriter trapFile, Accessor accessorKey, Location location) => @@ -74,10 +74,10 @@ internal static void compilation_expanded_args(this TextWriter trapFile, Compila internal static void compilation_info(this TextWriter trapFile, Compilation compilation, string infoKey, string infoValue) => trapFile.WriteTuple("compilation_info", compilation, infoKey, infoValue); - internal static void compilation_compiling_files(this TextWriter trapFile, Compilation compilation, int index, Extraction.Entities.File file) => + internal static void compilation_compiling_files(this TextWriter trapFile, Compilation compilation, int index, Entities.File file) => trapFile.WriteTuple("compilation_compiling_files", compilation, index, file); - internal static void compilation_referencing_files(this TextWriter trapFile, Compilation compilation, int index, Extraction.Entities.File file) => + internal static void compilation_referencing_files(this TextWriter trapFile, Compilation compilation, int index, Entities.File file) => trapFile.WriteTuple("compilation_referencing_files", compilation, index, file); internal static void compilation_finished(this TextWriter trapFile, Compilation compilation, float cpuSeconds, float elapsedSeconds) => @@ -398,7 +398,7 @@ internal static void pragma_warnings(this TextWriter trapFile, PragmaWarningDire internal static void pragma_warning_error_codes(this TextWriter trapFile, PragmaWarningDirective pragma, string errorCode, int child) => trapFile.WriteTuple("pragma_warning_error_codes", pragma, errorCode, child); - internal static void pragma_checksums(this TextWriter trapFile, PragmaChecksumDirective pragma, Extraction.Entities.File file, string guid, string bytes) => + internal static void pragma_checksums(this TextWriter trapFile, PragmaChecksumDirective pragma, Entities.File file, string guid, string bytes) => trapFile.WriteTuple("pragma_checksums", pragma, file, guid, bytes); internal static void directive_defines(this TextWriter trapFile, DefineDirective directive, string name) => @@ -422,7 +422,7 @@ internal static void directive_lines(this TextWriter trapFile, LineOrSpanDire internal static void directive_line_value(this TextWriter trapFile, LineDirective directive, int line) => trapFile.WriteTuple("directive_line_value", directive, line); - internal static void directive_line_file(this TextWriter trapFile, LineOrSpanDirective directive, Extraction.Entities.File file) where T : LineOrSpanDirectiveTriviaSyntax => + internal static void directive_line_file(this TextWriter trapFile, LineOrSpanDirective directive, Entities.File file) where T : LineOrSpanDirectiveTriviaSyntax => trapFile.WriteTuple("directive_line_file", directive, file); internal static void directive_line_offset(this TextWriter trapFile, LineSpanDirective directive, int offset) => diff --git a/csharp/extractor/Semmle.Extraction.CSharp/_Base/Context.cs b/csharp/extractor/Semmle.Extraction.CSharp/_Base/Context.cs index 8b7b750768c4..c3281e237250 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/_Base/Context.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/_Base/Context.cs @@ -326,7 +326,7 @@ private void Populate(ISymbol? optionalSymbol, CachedEntity entity) a(); } - protected virtual bool IsEntityDuplicationGuarded(IEntity entity, [NotNullWhen(returnValue: true)] out Entities.Location? loc) + protected virtual bool IsEntityDuplicationGuarded(IEntity entity, [NotNullWhen(returnValue: true)] out CSharp.Entities.Location? loc) { loc = null; return false; @@ -363,7 +363,7 @@ public virtual void WithDuplicationGuard(Key key, Action a) /// The location of the error. /// An optional stack trace of the error, or null. /// The severity of the error. - public void ExtractionError(string message, string? entityText, Entities.Location? location, string? stackTrace = null, Severity severity = Severity.Error) + public void ExtractionError(string message, string? entityText, CSharp.Entities.Location? location, string? stackTrace = null, Severity severity = Severity.Error) { var msg = new Message(message, entityText, location, stackTrace, severity); ExtractionError(msg); @@ -439,7 +439,7 @@ public void ModelError(ISymbol symbol, string msg) /// /// The location of the error. /// The error message. - public void ModelError(Entities.Location loc, string msg) + public void ModelError(CSharp.Entities.Location loc, string msg) { ReportError(new InternalError(loc.ReportingLocation, msg)); } @@ -491,10 +491,10 @@ public void Try(SyntaxNode? node, ISymbol? symbol, Action a) } } - public virtual Entities.Location CreateLocation() => - GeneratedLocation.Create(this); + public virtual CSharp.Entities.Location CreateLocation() => + CSharp.Entities.GeneratedLocation.Create(this); - public virtual Entities.Location CreateLocation(Microsoft.CodeAnalysis.Location? location) => + public virtual CSharp.Entities.Location CreateLocation(Microsoft.CodeAnalysis.Location? location) => CreateLocation(); } } diff --git a/csharp/extractor/Semmle.Extraction.CSharp/_Base/Entities/File.cs b/csharp/extractor/Semmle.Extraction.CSharp/_Base/Entities/File.cs deleted file mode 100644 index dda965920ae1..000000000000 --- a/csharp/extractor/Semmle.Extraction.CSharp/_Base/Entities/File.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; - -namespace Semmle.Extraction.Entities -{ - public abstract class File : CachedEntity - { - protected File(Context cx, string path) - : base(cx, path) - { - originalPath = path; - var adjustedPath = BinaryLogExtractionContext.GetAdjustedPath(Context.ExtractionContext, originalPath) ?? path; - transformedPathLazy = new Lazy(() => Context.ExtractionContext.PathTransformer.Transform(adjustedPath)); - } - - protected readonly string originalPath; - private readonly Lazy transformedPathLazy; - protected PathTransformer.ITransformedPath TransformedPath => transformedPathLazy.Value; - - public override bool NeedsPopulation => true; - - public override void WriteId(EscapingTextWriter trapFile) - { - trapFile.Write(TransformedPath.DatabaseId); - trapFile.Write(";sourcefile"); - } - - public override Microsoft.CodeAnalysis.Location? ReportingLocation => null; - } -} diff --git a/csharp/extractor/Semmle.Extraction.CSharp/_Base/Entities/ExtractionMessage.cs b/csharp/extractor/Semmle.Extraction.CSharp/_Base/ExtractionMessage.cs similarity index 100% rename from csharp/extractor/Semmle.Extraction.CSharp/_Base/Entities/ExtractionMessage.cs rename to csharp/extractor/Semmle.Extraction.CSharp/_Base/ExtractionMessage.cs diff --git a/csharp/extractor/Semmle.Extraction.CSharp/_Base/Message.cs b/csharp/extractor/Semmle.Extraction.CSharp/_Base/Message.cs index 7239c5880cb6..4e05a37eb6c8 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/_Base/Message.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/_Base/Message.cs @@ -14,9 +14,9 @@ public class Message public string Text { get; } public string? StackTrace { get; } public string? EntityText { get; } - public Entities.Location? Location { get; } + public CSharp.Entities.Location? Location { get; } - public Message(string text, string? entityText, Entities.Location? location, string? stackTrace = null, Severity severity = Severity.Error) + public Message(string text, string? entityText, CSharp.Entities.Location? location, string? stackTrace = null, Severity severity = Severity.Error) { Severity = severity; Text = text; diff --git a/csharp/extractor/Semmle.Extraction.CSharp/_Base/Tuples.cs b/csharp/extractor/Semmle.Extraction.CSharp/_Base/Tuples.cs index cddec9322863..fde03699f4ca 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/_Base/Tuples.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/_Base/Tuples.cs @@ -7,27 +7,27 @@ namespace Semmle.Extraction /// public static class Tuples { - public static void containerparent(this System.IO.TextWriter trapFile, Folder parent, IEntity child) + public static void containerparent(this System.IO.TextWriter trapFile, CSharp.Entities.Folder parent, IEntity child) { trapFile.WriteTuple("containerparent", parent, child); } - internal static void extractor_messages(this System.IO.TextWriter trapFile, ExtractionMessage error, Semmle.Util.Logging.Severity severity, string errorMessage, string entityText, Location location, string stackTrace) + internal static void extractor_messages(this System.IO.TextWriter trapFile, ExtractionMessage error, Semmle.Util.Logging.Severity severity, string errorMessage, string entityText, CSharp.Entities.Location location, string stackTrace) { trapFile.WriteTuple("extractor_messages", error, (int)severity, "C# extractor", errorMessage, entityText, location, stackTrace); } - public static void files(this System.IO.TextWriter trapFile, File file, string fullName) + public static void files(this System.IO.TextWriter trapFile, CSharp.Entities.File file, string fullName) { trapFile.WriteTuple("files", file, fullName); } - internal static void folders(this System.IO.TextWriter trapFile, Folder folder, string path) + internal static void folders(this System.IO.TextWriter trapFile, CSharp.Entities.Folder folder, string path) { trapFile.WriteTuple("folders", folder, path); } - public static void locations_default(this System.IO.TextWriter trapFile, SourceLocation label, Entities.File file, int startLine, int startCol, int endLine, int endCol) + public static void locations_default(this System.IO.TextWriter trapFile, CSharp.Entities.SourceLocation label, CSharp.Entities.File file, int startLine, int startCol, int endLine, int endCol) { trapFile.WriteTuple("locations_default", label, file, startLine, startCol, endLine, endCol); }