Skip to content

Commit 7e174dc

Browse files
committed
C#: Re-factor. Introduce variablekind enum.
1 parent 89bebe9 commit 7e174dc

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public override void Populate(TextWriter trapFile)
3333
PopulateRefKind(trapFile, Symbol.RefKind);
3434

3535
var unboundFieldKey = Field.Create(Context, Symbol.OriginalDefinition);
36-
trapFile.fields(this, (Symbol.IsConst ? 2 : 1), Symbol.Name, ContainingType, Type.TypeRef, unboundFieldKey);
36+
var kind = Symbol.IsConst ? VariableKind.Const : VariableKind.None;
37+
trapFile.fields(this, kind, Symbol.Name, ContainingType, Type.TypeRef, unboundFieldKey);
3738

3839
PopulateModifiers(trapFile);
3940

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ public void PopulateManual(Expression parent, bool isVar)
2727

2828
if (Symbol is ILocalSymbol local)
2929
{
30-
var @const = local.IsRef ? 3 : local.IsConst ? 2 : 1;
30+
var kind = local.IsRef ? Kinds.VariableKind.Ref : local.IsConst ? Kinds.VariableKind.Const : Kinds.VariableKind.None;
3131
var type = local.GetAnnotatedType();
32-
trapFile.localvars(this, @const, Symbol.Name, @var, Type.Create(Context, type).TypeRef, parent);
32+
trapFile.localvars(this, kind, Symbol.Name, @var, Type.Create(Context, type).TypeRef, parent);
3333

3434
PopulateNullability(trapFile, local.GetAnnotatedType());
3535
if (local.IsRef)
3636
trapFile.type_annotation(this, Kinds.TypeAnnotation.Ref);
3737
}
3838
else
3939
{
40-
trapFile.localvars(this, 1, Symbol.Name, @var, Type.Create(Context, parent.Type).TypeRef, parent);
40+
trapFile.localvars(this, Kinds.VariableKind.None, Symbol.Name, @var, Type.Create(Context, parent.Type).TypeRef, parent);
4141
}
4242

4343
trapFile.localvar_location(this, Location);
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 VariableKind
4+
{
5+
None = 1,
6+
Const = 2,
7+
Ref = 3
8+
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ internal static void anonymous_types(this TextWriter trapFile, Type type) =>
191191
internal static void field_location(this TextWriter trapFile, Field field, Location location) =>
192192
trapFile.WriteTuple("field_location", field, location);
193193

194-
internal static void fields(this TextWriter trapFile, Field field, int @const, string name, Type declaringType, Type fieldType, Field unboundKey) =>
195-
trapFile.WriteTuple("fields", field, @const, name, declaringType, fieldType, unboundKey);
194+
internal static void fields(this TextWriter trapFile, Field field, VariableKind kind, string name, Type declaringType, Type fieldType, Field unboundKey) =>
195+
trapFile.WriteTuple("fields", field, (int)kind, name, declaringType, fieldType, unboundKey);
196196

197197
internal static void general_type_parameter_constraints(this TextWriter trapFile, TypeParameterConstraints constraints, int hasKind) =>
198198
trapFile.WriteTuple("general_type_parameter_constraints", constraints, hasKind);
@@ -227,8 +227,8 @@ internal static void local_functions(this TextWriter trapFile, LocalFunction fn,
227227
internal static void localvar_location(this TextWriter trapFile, LocalVariable var, Location location) =>
228228
trapFile.WriteTuple("localvar_location", var, location);
229229

230-
internal static void localvars(this TextWriter trapFile, LocalVariable key, int @const, string name, int @var, Type type, Expression expr) =>
231-
trapFile.WriteTuple("localvars", key, @const, name, @var, type, expr);
230+
internal static void localvars(this TextWriter trapFile, LocalVariable key, VariableKind kind, string name, int @var, Type type, Expression expr) =>
231+
trapFile.WriteTuple("localvars", key, (int)kind, name, @var, type, expr);
232232

233233
public static void metadata_handle(this TextWriter trapFile, IEntity entity, Location assembly, int handleValue) =>
234234
trapFile.WriteTuple("metadata_handle", entity, assembly, handleValue);

0 commit comments

Comments
 (0)