C#: Only extract the unbound location for fields and parameters and use this location in the QL code.

This commit is contained in:
Michael Nebel
2025-10-09 11:44:57 +02:00
parent f200c3ce85
commit 051b83f036
3 changed files with 9 additions and 5 deletions

View File

@@ -49,7 +49,10 @@ namespace Semmle.Extraction.CSharp.Entities
} }
} }
WriteLocationsToTrap(trapFile.field_location, this, Locations); if (Context.ExtractLocation(Symbol))
{
WriteLocationsToTrap(trapFile.field_location, this, Locations);
}
if (!IsSourceDeclaration || !Symbol.FromSource()) if (!IsSourceDeclaration || !Symbol.FromSource())
return; return;

View File

@@ -115,9 +115,10 @@ namespace Semmle.Extraction.CSharp.Entities
var type = Type.Create(Context, Symbol.Type); var type = Type.Create(Context, Symbol.Type);
trapFile.@params(this, Name, type.TypeRef, Ordinal, ParamKind, Parent!, Original); trapFile.@params(this, Name, type.TypeRef, Ordinal, ParamKind, Parent!, Original);
foreach (var l in Symbol.Locations) if (Context.ExtractLocation(Symbol))
{ {
WriteLocationToTrap(trapFile.param_location, this, Context.CreateLocation(l)); var locations = Context.GetLocations(Symbol);
WriteLocationsToTrap(trapFile.param_location, this, locations);
} }
if (!Symbol.Locations.Any() && if (!Symbol.Locations.Any() &&

View File

@@ -213,7 +213,7 @@ class Parameter extends LocalScopeVariable, Attributable, TopLevelExprParent, @p
params(this, _, getTypeRef(result), _, _, _, _) params(this, _, getTypeRef(result), _, _, _, _)
} }
override Location getALocation() { param_location(this, result) } override Location getALocation() { param_location(this.getUnboundDeclaration(), result) }
override string toString() { result = this.getName() } override string toString() { result = this.getName() }
@@ -449,7 +449,7 @@ class Field extends Variable, AssignableMember, Attributable, TopLevelExprParent
fields(this, _, _, _, getTypeRef(result), _) fields(this, _, _, _, getTypeRef(result), _)
} }
override Location getALocation() { field_location(this, result) } override Location getALocation() { field_location(this.getUnboundDeclaration(), result) }
override string toString() { result = Variable.super.toString() } override string toString() { result = Variable.super.toString() }