Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3f6fb0f

Browse files
authored
Merge pull request #364 from calumgrant/cs/extractor/fix-violations
C#: Remove results from cs/local-shadows-member
2 parents 72012a9 + 68194b4 commit 3f6fb0f

13 files changed

Lines changed: 40 additions & 38 deletions

File tree

change-notes/1.19/analysis-csharp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
## Changes to existing queries
1616

1717
| Inconsistent lock sequence (`cs/inconsistent-lock-sequence`) | More results | This query now finds inconsistent lock sequences globally across calls. |
18-
18+
| Local scope variable shadows member (`cs/local-shadows-member`) | Fewer results | Results have been removed where a constructor parameter shadows a member, because the parameter is probably used to initialize the member. |
1919
| *@name of query (Query ID)*| *Impact on results* | *How/why the query has changed* |
2020

2121

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ public virtual IEnumerable<IExtractionProduct> Contents
6262
}
6363
}
6464

65-
public void Extract(Context cx)
65+
public void Extract(Context cx2)
6666
{
67-
cx.Populate(this);
67+
cx2.Populate(this);
6868
}
6969

7070
TrapStackBehaviour IEntity.TrapStackBehaviour => TrapStackBehaviour.NoLabel;

csharp/extractor/Semmle.Extraction.CIL/Entities/Type.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ protected TypeContainer(Context cx) : base(cx)
6060

6161
Location IEntity.ReportingLocation => throw new NotImplementedException();
6262

63-
public void Extract(Context cx) { cx.Populate(this); }
63+
public void Extract(Context cx2) { cx2.Populate(this); }
6464

6565
public abstract IEnumerable<IExtractionProduct> Contents { get; }
6666

@@ -83,13 +83,13 @@ public abstract class Type : TypeContainer, IMember, IType
8383
/// <summary>
8484
/// Find the method in this type matching the name and signature.
8585
/// </summary>
86-
/// <param name="Name">The handle to the name.</param>
86+
/// <param name="methodName">The handle to the name.</param>
8787
/// <param name="signature">
8888
/// The handle to the signature. Note that comparing handles is a valid
8989
/// shortcut to comparing the signature bytes since handles are unique.
9090
/// </param>
9191
/// <returns>The method, or 'null' if not found or not supported.</returns>
92-
internal virtual Method LookupMethod(StringHandle Name, BlobHandle signature)
92+
internal virtual Method LookupMethod(StringHandle methodName, BlobHandle signature)
9393
{
9494
return null;
9595
}
@@ -338,16 +338,16 @@ IEnumerable<TypeTypeParameter> MakeTypeParameters()
338338
if (ThisTypeParameters == 0)
339339
return Enumerable.Empty<TypeTypeParameter>();
340340

341-
var typeParams = new TypeTypeParameter[ThisTypeParameters];
341+
var newTypeParams = new TypeTypeParameter[ThisTypeParameters];
342342
var genericParams = td.GetGenericParameters();
343-
int toSkip = genericParams.Count - typeParams.Length;
343+
int toSkip = genericParams.Count - newTypeParams.Length;
344344

345345
// Two-phase population because type parameters can be mutually dependent
346-
for (int i = 0; i < typeParams.Length; ++i)
347-
typeParams[i] = cx.Populate(new TypeTypeParameter(this, this, i));
348-
for (int i = 0; i < typeParams.Length; ++i)
349-
typeParams[i].PopulateHandle(this, genericParams[i + toSkip]);
350-
return typeParams;
346+
for (int i = 0; i < newTypeParams.Length; ++i)
347+
newTypeParams[i] = cx.Populate(new TypeTypeParameter(this, this, i));
348+
for (int i = 0; i < newTypeParams.Length; ++i)
349+
newTypeParams[i].PopulateHandle(this, genericParams[i + toSkip]);
350+
return newTypeParams;
351351
}
352352

353353
readonly Lazy<IEnumerable<TypeTypeParameter>> typeParams;
@@ -482,12 +482,12 @@ public TypeReferenceType(Context cx, TypeReference tr) : base(cx)
482482

483483
TypeTypeParameter[] MakeTypeParameters()
484484
{
485-
var typeParams = new TypeTypeParameter[ThisTypeParameters];
486-
for (int i = 0; i < typeParams.Length; ++i)
485+
var newTypeParams = new TypeTypeParameter[ThisTypeParameters];
486+
for (int i = 0; i < newTypeParams.Length; ++i)
487487
{
488-
typeParams[i] = new TypeTypeParameter(this, this, i);
488+
newTypeParams[i] = new TypeTypeParameter(this, this, i);
489489
}
490-
return typeParams;
490+
return newTypeParams;
491491
}
492492

493493
public override IEnumerable<IExtractionProduct> Contents

csharp/extractor/Semmle.Extraction.CIL/ExtractionProduct.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ public abstract class UnlabelledEntity : IExtractedEntity
4949

5050
public virtual IId Id => FreshId.Instance;
5151

52-
public virtual void Extract(Context cx)
52+
public virtual void Extract(Context cx2)
5353
{
54-
cx.Extract(this);
54+
cx2.Extract(this);
5555
}
5656

5757
public readonly Context cx;
@@ -79,9 +79,9 @@ public abstract class LabelledEntity : ILabelledEntity
7979
public abstract Id IdSuffix { get; }
8080
public IId Id => ShortId + IdSuffix;
8181

82-
public void Extract(Context cx)
82+
public void Extract(Context cx2)
8383
{
84-
cx.Populate(this);
84+
cx2.Populate(this);
8585
}
8686

8787
public readonly Context cx;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ public Attribute(Context cx, AttributeData attribute, IEntity entity)
2121
// existence of a syntax tree. This is not the case for compiled
2222
// attributes.
2323
var syntax = attribute.ApplicationSyntaxReference.GetSyntax() as AttributeSyntax;
24-
ExtractAttribute(cx, syntax, attribute.AttributeClass, entity);
24+
ExtractAttribute(syntax, attribute.AttributeClass, entity);
2525
}
2626
}
2727

2828
public Attribute(Context cx, AttributeSyntax attribute, IEntity entity)
2929
: base(cx)
3030
{
3131
var info = cx.GetSymbolInfo(attribute);
32-
ExtractAttribute(cx, attribute, info.Symbol.ContainingType, entity);
32+
ExtractAttribute(attribute, info.Symbol.ContainingType, entity);
3333
}
3434

35-
void ExtractAttribute(Context cx, AttributeSyntax syntax, ITypeSymbol attributeClass, IEntity entity)
35+
void ExtractAttribute(AttributeSyntax syntax, ITypeSymbol attributeClass, IEntity entity)
3636
{
3737
var type = Type.Create(cx, attributeClass);
3838
cx.Emit(Tuples.attributes(this, type.TypeRef, entity));

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,13 @@ public void MakeConditional()
202202
cx.Emit(Tuples.conditional_access(this));
203203
}
204204

205-
public void PopulateArguments(Context cx, BaseArgumentListSyntax args, int child)
205+
public void PopulateArguments(BaseArgumentListSyntax args, int child)
206206
{
207207
foreach (var arg in args.Arguments)
208-
PopulateArgument(cx, arg, child++);
208+
PopulateArgument(arg, child++);
209209
}
210210

211-
private void PopulateArgument(Context cx, ArgumentSyntax arg, int child)
211+
private void PopulateArgument(ArgumentSyntax arg, int child)
212212
{
213213
var expr = Create(cx, arg.Expression, this, child);
214214
int mode;

csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/ElementAccess.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ protected override void Populate()
2727
var add = new Expression(new ExpressionInfo(cx, qualifierInfo.Type, Location, ExprKind.ADD, this, 0, false, null));
2828
qualifierInfo.SetParent(add, 0);
2929
CreateFromNode(qualifierInfo);
30-
PopulateArguments(cx, ArgumentList, 1);
30+
PopulateArguments(ArgumentList, 1);
3131
}
3232
else
3333
{

csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/Invocation.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ protected override void Populate()
2222
{
2323
if (IsNameof(Syntax))
2424
{
25-
PopulateArguments(cx, Syntax.ArgumentList, 0);
25+
PopulateArguments(Syntax.ArgumentList, 0);
2626
return;
2727
}
2828

@@ -80,7 +80,7 @@ protected override void Populate()
8080
cx.ModelError(Syntax, "Unable to get name for dynamic call.");
8181
}
8282

83-
PopulateArguments(cx, Syntax.ArgumentList, child);
83+
PopulateArguments(Syntax.ArgumentList, child);
8484

8585
if (target == null)
8686
{

csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/Lambda.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Lambda : Expression<AnonymousFunctionExpressionSyntax>, IStatementParentEn
1414

1515
protected override void Populate() { }
1616

17-
void VisitParameter(Context cx, ParameterSyntax p)
17+
void VisitParameter(ParameterSyntax p)
1818
{
1919
var symbol = cx.Model(p).GetDeclaredSymbol(p);
2020
Parameter.Create(cx, symbol, this);
@@ -27,7 +27,7 @@ void VisitParameter(Context cx, ParameterSyntax p)
2727
cx.PopulateLater(() =>
2828
{
2929
foreach (var param in @params)
30-
VisitParameter(cx, param);
30+
VisitParameter(param);
3131

3232
if (body is ExpressionSyntax)
3333
Create(cx, (ExpressionSyntax)body, this, 0);

csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/ObjectCreation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected override void Populate()
3737
{
3838
if (Syntax.ArgumentList != null)
3939
{
40-
PopulateArguments(cx, Syntax.ArgumentList, 0);
40+
PopulateArguments(Syntax.ArgumentList, 0);
4141
}
4242

4343
var target = cx.Model(Syntax).GetSymbolInfo(Syntax);

0 commit comments

Comments
 (0)