@@ -68,13 +68,12 @@ public override void Populate(TextWriter trapFile)
6868 Context . PopulateLater ( ( ) =>
6969 {
7070 var loc = Context . Create ( initializer . GetLocation ( ) ) ;
71- var simpleAssignExpr = new Expression ( new ExpressionInfo ( Context , Type , loc , ExprKind . SIMPLE_ASSIGN , this , child ++ , false , null ) ) ;
72- Expression . CreateFromNode ( new ExpressionNodeInfo ( Context , initializer . Initializer . Value , simpleAssignExpr , 0 ) ) ;
73- var access = new Expression ( new ExpressionInfo ( Context , Type , Location , ExprKind . FIELD_ACCESS , simpleAssignExpr , 1 , false , null ) ) ;
74- trapFile . expr_access ( access , this ) ;
71+
72+ var fieldAccess = AddInitializerAssignment ( trapFile , initializer . Initializer . Value , loc , null , ref child ) ;
73+
7574 if ( ! symbol . IsStatic )
7675 {
77- This . CreateImplicit ( Context , Entities . Type . Create ( Context , symbol . ContainingType ) , Location , access , - 1 ) ;
76+ This . CreateImplicit ( Context , Entities . Type . Create ( Context , symbol . ContainingType ) , Location , fieldAccess , - 1 ) ;
7877 }
7978 } ) ;
8079 }
@@ -85,8 +84,13 @@ public override void Populate(TextWriter trapFile)
8584 Where ( n => n . EqualsValue != null ) )
8685 {
8786 // Mark fields that have explicit initializers.
88- var expr = new Expression ( new ExpressionInfo ( Context , Type , Context . Create ( initializer . EqualsValue . Value . FixedLocation ( ) ) , Kinds . ExprKind . FIELD_ACCESS , this , child ++ , false , null ) ) ;
89- trapFile . expr_access ( expr , this ) ;
87+ var constValue = symbol . HasConstantValue
88+ ? Expression . ValueAsString ( symbol . ConstantValue )
89+ : null ;
90+
91+ var loc = Context . Create ( initializer . GetLocation ( ) ) ;
92+
93+ AddInitializerAssignment ( trapFile , initializer . EqualsValue . Value , loc , constValue , ref child ) ;
9094 }
9195
9296 if ( IsSourceDeclaration )
@@ -96,6 +100,16 @@ public override void Populate(TextWriter trapFile)
96100 TypeMention . Create ( Context , syntax . Type , this , Type ) ;
97101 }
98102
103+ private Expression AddInitializerAssignment ( TextWriter trapFile , ExpressionSyntax initializer , Extraction . Entities . Location loc ,
104+ string constValue , ref int child )
105+ {
106+ var simpleAssignExpr = new Expression ( new ExpressionInfo ( Context , Type , loc , ExprKind . SIMPLE_ASSIGN , this , child ++ , false , constValue ) ) ;
107+ Expression . CreateFromNode ( new ExpressionNodeInfo ( Context , initializer , simpleAssignExpr , 0 ) ) ;
108+ var access = new Expression ( new ExpressionInfo ( Context , Type , Location , ExprKind . FIELD_ACCESS , simpleAssignExpr , 1 , false , constValue ) ) ;
109+ trapFile . expr_access ( access , this ) ;
110+ return access ;
111+ }
112+
99113 readonly Lazy < AnnotatedType > type ;
100114 public AnnotatedType Type => type . Value ;
101115
0 commit comments