Simplify element access extraction

This commit is contained in:
Tamas Vajk
2021-01-19 12:23:06 +01:00
parent c3ef6841d0
commit 046a37b834
3 changed files with 14 additions and 69 deletions

View File

@@ -30,12 +30,8 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
}
else
{
var child = -1;
Create(cx, qualifier, this, child++);
foreach (var a in argumentList.Arguments)
{
cx.Extract(a, this, child++);
}
Create(cx, qualifier, this, -1);
PopulateArguments(trapFile, argumentList, 0);
var symbolInfo = cx.GetSymbolInfo(base.Syntax);

View File

@@ -1,63 +0,0 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Semmle.Extraction.CSharp.Entities;
namespace Semmle.Extraction.CSharp.Populators
{
internal class Ast : CSharpSyntaxVisitor
{
private readonly Context cx;
private readonly IExpressionParentEntity parent;
private readonly int child;
public Ast(Context cx, IExpressionParentEntity parent, int child)
{
this.cx = cx;
this.parent = parent;
this.child = child;
}
public override void DefaultVisit(SyntaxNode node)
{
cx.ModelError(node, $"Unhandled syntax node {node.Kind()}");
}
public override void VisitArgumentList(ArgumentListSyntax node)
{
var c = 0;
foreach (var m in node.Arguments)
{
cx.Extract(m, parent, c++);
}
}
public override void VisitArgument(ArgumentSyntax node)
{
Expression.Create(cx, node.Expression, parent, child);
}
}
public static class AstExtensions
{
public static void Extract(this Context cx, CSharpSyntaxNode node, IExpressionParentEntity parent, int child)
{
using (cx.StackGuard)
{
try
{
node.Accept(new Ast(cx, parent, child));
}
catch (System.Exception ex) // lgtm[cs/catch-of-all-exceptions]
{
cx.ModelError(node, $"Exception processing syntax node of type {node.Kind()}: {ex.Message}");
}
}
}
public static void Extract(this Context cx, SyntaxNode node, IEntity parent, int child)
{
cx.Extract(((CSharpSyntaxNode)node), parent, child);
}
}
}

View File

@@ -22,3 +22,15 @@
| arguments.cs:40:41:40:41 | 0 | 0 |
| arguments.cs:45:12:45:32 | array creation of type Object[] | 0 |
| 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:21:56:21 | 3 | 0 |
| arguments.cs:56:24:56:24 | 4 | 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:62:21:62:22 | 15 | 0 |
| arguments.cs:62:25:62:26 | 16 | 0 |