Skip to content

Commit 051b83f

Browse files
committed
C#: Only extract the unbound location for fields and parameters and use this location in the QL code.
1 parent f200c3c commit 051b83f

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ public override void Populate(TextWriter trapFile)
4949
}
5050
}
5151

52-
WriteLocationsToTrap(trapFile.field_location, this, Locations);
52+
if (Context.ExtractLocation(Symbol))
53+
{
54+
WriteLocationsToTrap(trapFile.field_location, this, Locations);
55+
}
5356

5457
if (!IsSourceDeclaration || !Symbol.FromSource())
5558
return;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,10 @@ public override void Populate(TextWriter trapFile)
115115
var type = Type.Create(Context, Symbol.Type);
116116
trapFile.@params(this, Name, type.TypeRef, Ordinal, ParamKind, Parent!, Original);
117117

118-
foreach (var l in Symbol.Locations)
118+
if (Context.ExtractLocation(Symbol))
119119
{
120-
WriteLocationToTrap(trapFile.param_location, this, Context.CreateLocation(l));
120+
var locations = Context.GetLocations(Symbol);
121+
WriteLocationsToTrap(trapFile.param_location, this, locations);
121122
}
122123

123124
if (!Symbol.Locations.Any() &&

csharp/ql/lib/semmle/code/csharp/Variable.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ class Parameter extends LocalScopeVariable, Attributable, TopLevelExprParent, @p
213213
params(this, _, getTypeRef(result), _, _, _, _)
214214
}
215215

216-
override Location getALocation() { param_location(this, result) }
216+
override Location getALocation() { param_location(this.getUnboundDeclaration(), result) }
217217

218218
override string toString() { result = this.getName() }
219219

@@ -449,7 +449,7 @@ class Field extends Variable, AssignableMember, Attributable, TopLevelExprParent
449449
fields(this, _, _, _, getTypeRef(result), _)
450450
}
451451

452-
override Location getALocation() { field_location(this, result) }
452+
override Location getALocation() { field_location(this.getUnboundDeclaration(), result) }
453453

454454
override string toString() { result = Variable.super.toString() }
455455

0 commit comments

Comments
 (0)