forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterpolatedString.cs
More file actions
36 lines (33 loc) · 1.57 KB
/
InterpolatedString.cs
File metadata and controls
36 lines (33 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System.IO;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Semmle.Extraction.Kinds;
namespace Semmle.Extraction.CSharp.Entities.Expressions
{
internal class InterpolatedString : Expression<InterpolatedStringExpressionSyntax>
{
private InterpolatedString(ExpressionNodeInfo info) : base(info.SetKind(ExprKind.INTERPOLATED_STRING)) { }
public static Expression Create(ExpressionNodeInfo info) => new InterpolatedString(info).TryPopulate();
protected override void PopulateExpression(TextWriter trapFile)
{
var child = 0;
foreach (var c in Syntax.Contents)
{
switch (c.Kind())
{
case SyntaxKind.Interpolation:
var interpolation = (InterpolationSyntax)c;
new InterpolatedStringInsert(Context, interpolation, this, child++);
break;
case SyntaxKind.InterpolatedStringText:
// Create a string literal
var interpolatedText = (InterpolatedStringTextSyntax)c;
new Expression(new ExpressionInfo(Context, Type, Context.CreateLocation(c.GetLocation()), ExprKind.UTF16_STRING_LITERAL, this, child++, isCompilerGenerated: false, interpolatedText.TextToken.ValueText));
break;
default:
throw new InternalError(c, $"Unhandled interpolation kind {c.Kind()}");
}
}
}
}
}