|
1 | 1 | using Microsoft.CodeAnalysis; |
2 | 2 | using Microsoft.CodeAnalysis.CSharp.Syntax; |
| 3 | +using Semmle.Extraction.CSharp.Entities.Expressions; |
| 4 | +using Semmle.Extraction.Entities; |
| 5 | +using Semmle.Extraction.Kinds; |
3 | 6 | using System.Linq; |
4 | 7 |
|
5 | 8 | namespace Semmle.Extraction.CSharp.Entities |
@@ -69,12 +72,24 @@ public override void Populate() |
69 | 72 | Context.PopulateLater(() => Expression.Create(Context, expressionBody, this, 0)); |
70 | 73 | } |
71 | 74 |
|
| 75 | + int child = 1; |
72 | 76 | foreach (var initializer in declSyntaxReferences. |
73 | 77 | Select(n => n.Initializer). |
74 | | - Where(i => i != null). |
75 | | - Select(i => i.Value)) |
| 78 | + Where(i => i != null)) |
76 | 79 | { |
77 | | - Context.PopulateLater(() => Expression.Create(Context, initializer, this, 1)); |
| 80 | + Context.PopulateLater(() => |
| 81 | + { |
| 82 | + var loc = Context.Create(initializer.GetLocation()); |
| 83 | + var annotatedType = new AnnotatedType(type, TypeAnnotation.None); |
| 84 | + var simpleAssignExpr = new Expression(new ExpressionInfo(Context, annotatedType, loc, ExprKind.SIMPLE_ASSIGN, this, child++, false, null)); |
| 85 | + Expression.CreateFromNode(new ExpressionNodeInfo(Context, initializer.Value, simpleAssignExpr, 0)); |
| 86 | + var access = new Expression(new ExpressionInfo(Context, annotatedType, Location, ExprKind.PROPERTY_ACCESS, simpleAssignExpr, 1, false, null)); |
| 87 | + Context.Emit(Tuples.expr_access(access, this)); |
| 88 | + if (!symbol.IsStatic) |
| 89 | + { |
| 90 | + This.CreateImplicit(Context, Type.Create(Context, symbol.ContainingType), Location, access, -1); |
| 91 | + } |
| 92 | + }); |
78 | 93 | } |
79 | 94 |
|
80 | 95 | foreach (var syntax in declSyntaxReferences) |
|
0 commit comments