Skip to content

Commit

Permalink
C#: Clear TRAP stack when calling PopulateGenerics
Browse files Browse the repository at this point in the history
  • Loading branch information
hvitved committed Sep 6, 2023
1 parent eef3cc2 commit f8ace6a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 28 deletions.
55 changes: 29 additions & 26 deletions csharp/extractor/Semmle.Extraction.CSharp/Entities/Types/Type.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,41 +250,44 @@ public void ExtractRecursive()
/// </summary>
public void PopulateGenerics()
{
if (Symbol is null || !NeedsPopulation || !Context.ExtractGenerics(this))
return;
Context.PopulateLater(() =>
{
if (Symbol is null || !NeedsPopulation || !Context.ExtractGenerics(this))
return;

var members = new List<ISymbol>();
var members = new List<ISymbol>();

foreach (var member in Symbol.GetMembers())
members.Add(member);
foreach (var member in Symbol.GetTypeMembers())
members.Add(member);
foreach (var member in Symbol.GetMembers())
members.Add(member);
foreach (var member in Symbol.GetTypeMembers())
members.Add(member);

// Mono extractor puts all BASE interface members as members of the current interface.
// Mono extractor puts all BASE interface members as members of the current interface.

if (Symbol.TypeKind == TypeKind.Interface)
{
foreach (var baseInterface in Symbol.Interfaces)
if (Symbol.TypeKind == TypeKind.Interface)
{
foreach (var member in baseInterface.GetMembers())
members.Add(member);
foreach (var member in baseInterface.GetTypeMembers())
members.Add(member);
foreach (var baseInterface in Symbol.Interfaces)
{
foreach (var member in baseInterface.GetMembers())
members.Add(member);
foreach (var member in baseInterface.GetTypeMembers())
members.Add(member);
}
}
}

foreach (var member in members)
{
Context.CreateEntity(member);
}
foreach (var member in members)
{
Context.CreateEntity(member);
}

if (Symbol.BaseType is not null)
Create(Context, Symbol.BaseType).PopulateGenerics();
if (Symbol.BaseType is not null)
Create(Context, Symbol.BaseType).PopulateGenerics();

foreach (var i in Symbol.Interfaces)
{
Create(Context, i).PopulateGenerics();
}
foreach (var i in Symbol.Interfaces)
{
Create(Context, i).PopulateGenerics();
}
}, preserveDuplicationKey: false);
}

public void ExtractRecursive(TextWriter trapFile, IEntity parent)
Expand Down
4 changes: 2 additions & 2 deletions csharp/extractor/Semmle.Extraction/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ internal void AddFreshLabel(Entity entity)
/// Enqueue the given action to be performed later.
/// </summary>
/// <param name="toRun">The action to run.</param>
public void PopulateLater(Action a)
public void PopulateLater(Action a, bool preserveDuplicationKey = true)
{
var key = GetCurrentTagStackKey();
var key = preserveDuplicationKey ? GetCurrentTagStackKey() : null;
if (key is not null)
{
// If we are currently executing with a duplication guard, then the same
Expand Down

0 comments on commit f8ace6a

Please sign in to comment.