mirror of
https://github.com/github/codeql.git
synced 2025-12-17 09:13:20 +01:00
35 lines
1.2 KiB
C#
35 lines
1.2 KiB
C#
using System.IO;
|
|
using Microsoft.CodeAnalysis;
|
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|
|
|
namespace Semmle.Extraction.CSharp.Entities
|
|
{
|
|
internal abstract class Expression<TExpressionSyntax> : Expression
|
|
where TExpressionSyntax : ExpressionSyntax
|
|
{
|
|
public TExpressionSyntax Syntax { get; }
|
|
|
|
protected Expression(ExpressionNodeInfo info)
|
|
: base(info)
|
|
{
|
|
Syntax = (TExpressionSyntax)info.Node;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Populates expression-type specific relations in the trap file. The general relations
|
|
/// <code>expressions</code> and <code>expr_location</code> are populated by the constructor
|
|
/// (should not fail), so even if expression-type specific population fails (e.g., in
|
|
/// standalone extraction), the expression created via
|
|
/// <see cref="Expression.Create(Context, ExpressionSyntax, IEntity, int, ITypeSymbol)"/> will
|
|
/// still be valid.
|
|
/// </summary>
|
|
protected abstract void PopulateExpression(TextWriter trapFile);
|
|
|
|
protected new Expression TryPopulate()
|
|
{
|
|
Context.Try(Syntax, null, () => PopulateExpression(Context.TrapWriter.Writer));
|
|
return this;
|
|
}
|
|
}
|
|
}
|