Skip to content

Commit 7f18c33

Browse files
authored
Merge pull request #4017 from hvitved/csharp/unqualify-trap-ids3
C#: Remove assembly prefixes from TRAP labels
2 parents b7774b2 + 701e189 commit 7f18c33

File tree

96 files changed

+2637
-1058
lines changed

Some content is hidden

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

96 files changed

+2637
-1058
lines changed

change-notes/1.26/analysis-csharp.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ The following changes in version 1.26 affect C# analysis in all applications.
2121
* Partial method bodies are extracted. Previously, partial method bodies were skipped completely.
2222
* Inferring the lengths of implicitely sized arrays is fixed. Previously, multidimensional arrays were always extracted with the same length for
2323
each dimension. With the fix, the array sizes `2` and `1` are extracted for `new int[,]{{1},{2}}`. Previously `2` and `2` were extracted.
24+
* The extractor is now assembly-insensitive by default. This means that two entities with the same
25+
fully-qualified name are now mapped to the same entity in the resulting database, regardless of
26+
whether they belong to different assemblies. Assembly sensitivity can be reenabled by passing
27+
`--assemblysensitivetrap` to the extractor.
2428

2529
## Changes to libraries
2630

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public static void ExtractCIL(Layout layout, string assemblyPath, ILogger logger
141141
trapFile = trapWriter.TrapFile;
142142
if (nocache || !System.IO.File.Exists(trapFile))
143143
{
144-
var cx = extractor.CreateContext(null, trapWriter, null);
144+
var cx = extractor.CreateContext(null, trapWriter, null, false);
145145
ExtractCIL(cx, assemblyPath, extractPdbs);
146146
extracted = true;
147147
}

csharp/extractor/Semmle.Extraction.CSharp/Analyser.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ public class Analyser : IDisposable
2525

2626
public readonly ILogger Logger;
2727

28-
public Analyser(IProgressMonitor pm, ILogger logger)
28+
public readonly bool AddAssemblyTrapPrefix;
29+
30+
public Analyser(IProgressMonitor pm, ILogger logger, bool addAssemblyTrapPrefix)
2931
{
3032
Logger = logger;
33+
AddAssemblyTrapPrefix = addAssemblyTrapPrefix;
3134
Logger.Log(Severity.Info, "EXTRACTION STARTING at {0}", DateTime.Now);
3235
stopWatch.Start();
3336
progressMonitor = pm;
@@ -231,7 +234,7 @@ void DoAnalyseCompilation(string cwd, string[] args)
231234
var projectLayout = layout.LookupProjectOrDefault(assemblyPath);
232235
var trapWriter = projectLayout.CreateTrapWriter(Logger, assemblyPath, true, options.TrapCompression);
233236
compilationTrapFile = trapWriter; // Dispose later
234-
var cx = extractor.CreateContext(compilation.Clone(), trapWriter, new AssemblyScope(assembly, assemblyPath, true));
237+
var cx = extractor.CreateContext(compilation.Clone(), trapWriter, new AssemblyScope(assembly, assemblyPath, true), AddAssemblyTrapPrefix);
235238

236239
compilationEntity = new Entities.Compilation(cx, cwd, args);
237240
}
@@ -286,7 +289,7 @@ void DoAnalyseAssembly(PortableExecutableReference r)
286289

287290
if (assembly != null)
288291
{
289-
var cx = extractor.CreateContext(c, trapWriter, new AssemblyScope(assembly, assemblyPath, false));
292+
var cx = extractor.CreateContext(c, trapWriter, new AssemblyScope(assembly, assemblyPath, false), AddAssemblyTrapPrefix);
290293

291294
foreach (var module in assembly.Modules)
292295
{
@@ -372,7 +375,7 @@ void DoExtractTree(SyntaxTree tree)
372375

373376
if (!upToDate)
374377
{
375-
Context cx = extractor.CreateContext(compilation.Clone(), trapWriter, new SourceScope(tree));
378+
Context cx = extractor.CreateContext(compilation.Clone(), trapWriter, new SourceScope(tree), AddAssemblyTrapPrefix);
376379
Populators.CompilationUnit.Extract(cx, tree.GetRoot());
377380
cx.PopulateAll();
378381
cx.ExtractComments(cx.CommentGenerator);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public override void Populate(TextWriter trapFile)
7777
}
7878

7979
public new static Accessor Create(Context cx, IMethodSymbol symbol) =>
80-
AccessorFactory.Instance.CreateEntity(cx, symbol);
80+
AccessorFactory.Instance.CreateEntityFromSymbol(cx, symbol);
8181

8282
class AccessorFactory : ICachedEntityFactory<IMethodSymbol, Accessor>
8383
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void BindTo(Label entity, CommentBinding binding)
3535
Context.TrapWriter.Writer.commentblock_binding(this, entity, binding);
3636
}
3737

38-
public static CommentBlock Create(Context cx, ICommentBlock block) => CommentBlockFactory.Instance.CreateEntity(cx, block);
38+
public static CommentBlock Create(Context cx, ICommentBlock block) => CommentBlockFactory.Instance.CreateEntity(cx, block, block);
3939

4040
class CommentBlockFactory : ICachedEntityFactory<ICommentBlock, CommentBlock>
4141
{

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,11 @@ public override void WriteId(TextWriter trapFile)
129129
trapFile.Write(";commentline");
130130
}
131131

132-
static CommentLine Create(Context cx, Microsoft.CodeAnalysis.Location loc, CommentLineType type, string text, string raw) => CommentLineFactory.Instance.CreateEntity(cx, loc, type, text, raw);
132+
static CommentLine Create(Context cx, Microsoft.CodeAnalysis.Location loc, CommentLineType type, string text, string raw)
133+
{
134+
var init = (loc, type, text, raw);
135+
return CommentLineFactory.Instance.CreateEntity(cx, init, init);
136+
}
133137

134138
class CommentLineFactory : ICachedEntityFactory<(Microsoft.CodeAnalysis.Location, CommentLineType, string, string), CommentLine>
135139
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ ConstructorDeclarationSyntax Syntax
104104
{
105105
case MethodKind.StaticConstructor:
106106
case MethodKind.Constructor:
107-
return ConstructorFactory.Instance.CreateEntity(cx, constructor);
107+
return ConstructorFactory.Instance.CreateEntityFromSymbol(cx, constructor);
108108
default:
109109
throw new InternalError(constructor, "Attempt to create a Constructor from a symbol that isn't a constructor");
110110
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Conversion : UserOperator
1111
: base(cx, init) { }
1212

1313
public new static Conversion Create(Context cx, IMethodSymbol symbol) =>
14-
ConversionFactory.Instance.CreateEntity(cx, symbol);
14+
ConversionFactory.Instance.CreateEntityFromSymbol(cx, symbol);
1515

1616
public override Microsoft.CodeAnalysis.Location ReportingLocation
1717
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public override void Populate(TextWriter trapFile)
2424
}
2525

2626
public new static Destructor Create(Context cx, IMethodSymbol symbol) =>
27-
DestructorFactory.Instance.CreateEntity(cx, symbol);
27+
DestructorFactory.Instance.CreateEntityFromSymbol(cx, symbol);
2828

2929
class DestructorFactory : ICachedEntityFactory<IMethodSymbol, Destructor>
3030
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public override void Populate(TextWriter trapFile)
6060
TypeMention.Create(Context, syntaxType, this, type);
6161
}
6262

63-
public static Event Create(Context cx, IEventSymbol symbol) => EventFactory.Instance.CreateEntity(cx, symbol);
63+
public static Event Create(Context cx, IEventSymbol symbol) => EventFactory.Instance.CreateEntityFromSymbol(cx, symbol);
6464

6565
class EventFactory : ICachedEntityFactory<IEventSymbol, Event>
6666
{

0 commit comments

Comments
 (0)