Skip to content

Commit 955f23d

Browse files
committed
C#: Introduce extractor support for scoped variables and parameters.
1 parent dd6ceb7 commit 955f23d

File tree

5 files changed

+26
-0
lines changed

5 files changed

+26
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,19 @@ protected void PopulateRefKind(TextWriter trapFile, RefKind kind)
5959
}
6060
}
6161

62+
protected void PopulateScopedKind(TextWriter trapFile, ScopedKind kind)
63+
{
64+
switch (kind)
65+
{
66+
case ScopedKind.ScopedRef:
67+
trapFile.scoped_annotation(this, Kinds.ScopedAnnotation.ScopedRef);
68+
break;
69+
case ScopedKind.ScopedValue:
70+
trapFile.scoped_annotation(this, Kinds.ScopedAnnotation.ScopedValue);
71+
break;
72+
}
73+
}
74+
6275
protected void ExtractCompilerGenerated(TextWriter trapFile)
6376
{
6477
if (Symbol.IsImplicitlyDeclared)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public void PopulateManual(Expression parent, bool isVar)
3232
trapFile.localvars(this, kind, Symbol.Name, @var, Type.Create(Context, type).TypeRef, parent);
3333

3434
PopulateNullability(trapFile, local.GetAnnotatedType());
35+
PopulateScopedKind(trapFile, local.ScopedKind);
3536
if (local.IsRef)
3637
trapFile.type_annotation(this, Kinds.TypeAnnotation.Ref);
3738
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public override void Populate(TextWriter trapFile)
100100
PopulateAttributes();
101101
PopulateNullability(trapFile, Symbol.GetAnnotatedType());
102102
PopulateRefKind(trapFile, Symbol.RefKind);
103+
PopulateScopedKind(trapFile, Symbol.ScopedKind);
103104

104105
if (Symbol.Name != Original.Symbol.Name)
105106
Context.ModelError(Symbol, "Inconsistent parameter declaration");
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Semmle.Extraction.Kinds;
2+
3+
public enum ScopedAnnotation
4+
{
5+
None = 0,
6+
ScopedRef = 1,
7+
ScopedValue = 2
8+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,5 +462,8 @@ internal static void locations_mapped(this System.IO.TextWriter trapFile, NonGen
462462

463463
internal static void file_extraction_mode(this System.IO.TextWriter trapFile, Entities.File file, ExtractorMode mode) =>
464464
trapFile.WriteTuple("file_extraction_mode", file, mode);
465+
466+
internal static void scoped_annotation(this TextWriter trapFile, IEntity element, ScopedAnnotation @scoped) =>
467+
trapFile.WriteTuple("scoped_annotation", element, (int)@scoped);
465468
}
466469
}

0 commit comments

Comments
 (0)