зеркало из https://github.com/github/codeql.git
C#: Add support for explicit return types in the extractor.
This commit is contained in:
Родитель
ae62704d3a
Коммит
eb8c226749
|
@ -22,7 +22,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
Parameter.Create(Context, symbol, this);
|
||||
}
|
||||
|
||||
private Lambda(ExpressionNodeInfo info, CSharpSyntaxNode body, IEnumerable<ParameterSyntax> @params)
|
||||
private Lambda(ExpressionNodeInfo info, CSharpSyntaxNode body, IEnumerable<ParameterSyntax> @params, TypeSyntax? @return)
|
||||
: base(info)
|
||||
{
|
||||
if (Context.GetModel(info.Node).GetSymbolInfo(info.Node).Symbol is IMethodSymbol symbol)
|
||||
|
@ -40,6 +40,13 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
foreach (var param in @params)
|
||||
VisitParameter(param);
|
||||
|
||||
if (@return is not null)
|
||||
{
|
||||
var symbol = Context.GetType(@return);
|
||||
var type = Entities.Type.Create(Context, symbol);
|
||||
var trapFile = Context.TrapWriter.Writer;
|
||||
trapFile.lambda_expr_return_type(this, type.TypeRef);
|
||||
}
|
||||
if (body is ExpressionSyntax exprBody)
|
||||
Create(Context, exprBody, this, 0);
|
||||
else if (body is BlockSyntax blockBody)
|
||||
|
@ -50,17 +57,17 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
}
|
||||
|
||||
private Lambda(ExpressionNodeInfo info, ParenthesizedLambdaExpressionSyntax node)
|
||||
: this(info.SetKind(ExprKind.LAMBDA), node.Body, node.ParameterList.Parameters) { }
|
||||
: this(info.SetKind(ExprKind.LAMBDA), node.Body, node.ParameterList.Parameters, node.ReturnType) { }
|
||||
|
||||
public static Lambda Create(ExpressionNodeInfo info, ParenthesizedLambdaExpressionSyntax node) => new Lambda(info, node);
|
||||
|
||||
private Lambda(ExpressionNodeInfo info, SimpleLambdaExpressionSyntax node)
|
||||
: this(info.SetKind(ExprKind.LAMBDA), node.Body, Enumerators.Singleton(node.Parameter)) { }
|
||||
: this(info.SetKind(ExprKind.LAMBDA), node.Body, Enumerators.Singleton(node.Parameter), null) { }
|
||||
|
||||
public static Lambda Create(ExpressionNodeInfo info, SimpleLambdaExpressionSyntax node) => new Lambda(info, node);
|
||||
|
||||
private Lambda(ExpressionNodeInfo info, AnonymousMethodExpressionSyntax node) :
|
||||
this(info.SetKind(ExprKind.ANONYMOUS_METHOD), node.Body, node.ParameterList is null ? Enumerable.Empty<ParameterSyntax>() : node.ParameterList.Parameters)
|
||||
this(info.SetKind(ExprKind.ANONYMOUS_METHOD), node.Body, node.ParameterList is null ? Enumerable.Empty<ParameterSyntax>() : node.ParameterList.Parameters, null)
|
||||
{ }
|
||||
|
||||
public static Lambda Create(ExpressionNodeInfo info, AnonymousMethodExpressionSyntax node) => new Lambda(info, node);
|
||||
|
|
|
@ -215,6 +215,9 @@ namespace Semmle.Extraction.CSharp
|
|||
internal static void indexers(this TextWriter trapFile, Indexer propKey, string name, Type declaringType, Type memberType, Indexer unboundProperty) =>
|
||||
trapFile.WriteTuple("indexers", propKey, name, declaringType, memberType, unboundProperty);
|
||||
|
||||
internal static void lambda_expr_return_type(this TextWriter trapFile, Lambda expr, Type returnType) =>
|
||||
trapFile.WriteTuple("lambda_expr_return_type", expr, returnType);
|
||||
|
||||
internal static void local_function_stmts(this TextWriter trapFile, Entities.Statements.LocalFunction fnStmt, LocalFunction fn) =>
|
||||
trapFile.WriteTuple("local_function_stmts", fnStmt, fn);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче