using System.IO; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; namespace Semmle.Extraction.CSharp.Entities { internal abstract class Expression : Expression where TExpressionSyntax : ExpressionSyntax { public TExpressionSyntax Syntax { get; } protected Expression(ExpressionNodeInfo info) : base(info) { Syntax = (TExpressionSyntax)info.Node; } /// /// Populates expression-type specific relations in the trap file. The general relations /// expressions and expr_location 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 /// will /// still be valid. /// protected abstract void PopulateExpression(TextWriter trapFile); protected new Expression TryPopulate() { Context.Try(Syntax, null, () => PopulateExpression(Context.TrapWriter.Writer)); return this; } } }