C#: More uses of PopulateArguments

This commit is contained in:
Tom Hvitved
2022-01-04 12:18:01 +01:00
parent 8a62778e92
commit a1bbe58516
4 changed files with 17 additions and 12 deletions

View File

@@ -4,6 +4,7 @@ using Microsoft.CodeAnalysis.CSharp.Syntax;
using Semmle.Extraction.CSharp.Entities.Expressions;
using Semmle.Extraction.Kinds;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -324,7 +325,12 @@ namespace Semmle.Extraction.CSharp.Entities
public void PopulateArguments(TextWriter trapFile, BaseArgumentListSyntax args, int child)
{
foreach (var arg in args.Arguments)
PopulateArguments(trapFile, args.Arguments, child);
}
public void PopulateArguments(TextWriter trapFile, IEnumerable<ArgumentSyntax> args, int child)
{
foreach (var arg in args)
PopulateArgument(trapFile, arg, child++);
}

View File

@@ -105,12 +105,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
if (assignment.Left is ImplicitElementAccessSyntax iea)
{
// An array/indexer initializer of the form `[...] = ...`
var indexChild = 0;
foreach (var arg in iea.ArgumentList.Arguments)
{
Expression.Create(Context, arg.Expression, access, indexChild++);
}
access.PopulateArguments(trapFile, iea.ArgumentList.Arguments, 0);
}
}
else

View File

@@ -15,11 +15,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
protected override void PopulateExpression(TextWriter trapFile)
{
var child = 0;
foreach (var argument in Syntax.Arguments.Select(a => a.Expression))
{
Expression.Create(Context, argument, this, child++);
}
PopulateArguments(trapFile, Syntax.Arguments, 0);
}
}
}

View File

@@ -24,13 +24,21 @@
| arguments.cs:45:35:45:38 | null | 0 |
| arguments.cs:55:21:55:21 | 1 | 0 |
| arguments.cs:55:24:55:24 | 2 | 0 |
| arguments.cs:56:10:56:13 | access to property Prop | 0 |
| arguments.cs:56:16:56:25 | access to indexer | 0 |
| arguments.cs:56:21:56:21 | 3 | 0 |
| arguments.cs:56:24:56:24 | 4 | 0 |
| arguments.cs:56:31:56:31 | 5 | 0 |
| arguments.cs:56:34:56:34 | 6 | 0 |
| arguments.cs:59:14:59:14 | 8 | 0 |
| arguments.cs:59:17:59:17 | 9 | 0 |
| arguments.cs:60:14:60:15 | 10 | 0 |
| arguments.cs:60:14:60:15 | 10 | 0 |
| arguments.cs:60:18:60:19 | 11 | 0 |
| arguments.cs:60:18:60:19 | 11 | 0 |
| arguments.cs:61:22:61:23 | 13 | 0 |
| arguments.cs:61:26:61:27 | 14 | 0 |
| arguments.cs:62:10:62:13 | access to property Prop | 0 |
| arguments.cs:62:16:62:27 | access to indexer | 0 |
| arguments.cs:62:21:62:22 | 15 | 0 |
| arguments.cs:62:25:62:26 | 16 | 0 |