@@ -11,12 +11,13 @@ class VariableDeclaration : Expression
1111 {
1212 VariableDeclaration ( IExpressionInfo info ) : base ( info ) { }
1313
14- public static VariableDeclaration Create ( Context cx , ISymbol symbol , AnnotatedType type , TypeSyntax optionalSyntax , Extraction . Entities . Location exprLocation , Extraction . Entities . Location declLocation , bool isVar , IExpressionParentEntity parent , int child )
14+ public static VariableDeclaration Create ( Context cx , ISymbol symbol , AnnotatedType type , TypeSyntax optionalSyntax , Extraction . Entities . Location exprLocation , bool isVar , IExpressionParentEntity parent , int child )
1515 {
1616 var ret = new VariableDeclaration ( new ExpressionInfo ( cx , type , exprLocation , ExprKind . LOCAL_VAR_DECL , parent , child , false , null ) ) ;
1717 cx . Try ( null , null , ( ) =>
1818 {
19- LocalVariable . Create ( cx , symbol , ret , isVar , declLocation ) ;
19+ var l = LocalVariable . Create ( cx , symbol ) ;
20+ l . PopulateInfo ( ret , isVar ) ;
2021 if ( optionalSyntax != null )
2122 TypeMention . Create ( cx , optionalSyntax , parent , type ) ;
2223 } ) ;
@@ -25,20 +26,20 @@ public static VariableDeclaration Create(Context cx, ISymbol symbol, AnnotatedTy
2526
2627 static VariableDeclaration CreateSingle ( Context cx , DeclarationExpressionSyntax node , SingleVariableDesignationSyntax designation , IExpressionParentEntity parent , int child )
2728 {
28- bool isVar = node . Type . IsVar ;
29-
3029 var variableSymbol = cx . GetModel ( designation ) . GetDeclaredSymbol ( designation ) as ILocalSymbol ;
3130 if ( variableSymbol == null )
3231 {
3332 cx . ModelError ( node , "Failed to determine local variable" ) ;
34- return Create ( cx , node , NullType . Create ( cx ) , isVar , parent , child ) ;
33+ return Create ( cx , node , NullType . Create ( cx ) , parent , child ) ;
3534 }
3635
3736 var type = Entities . Type . Create ( cx , variableSymbol . GetAnnotatedType ( ) ) ;
38- var location = cx . Create ( designation . GetLocation ( ) ) ;
39-
40- var ret = Create ( cx , designation , type , isVar , parent , child ) ;
41- cx . Try ( null , null , ( ) => LocalVariable . Create ( cx , variableSymbol , ret , isVar , location ) ) ;
37+ var ret = Create ( cx , designation , type , parent , child ) ;
38+ cx . Try ( null , null , ( ) =>
39+ {
40+ var l = LocalVariable . Create ( cx , variableSymbol ) ;
41+ l . PopulateInfo ( ret , node . Type . IsVar ) ;
42+ } ) ;
4243 return ret ;
4344 }
4445
@@ -78,10 +79,9 @@ public static Expression CreateParenthesized(Context cx, VarPatternSyntax varPat
7879 case SingleVariableDesignationSyntax single :
7980 if ( cx . GetModel ( variable ) . GetDeclaredSymbol ( single ) is ILocalSymbol local )
8081 {
81- var decl = Create ( cx , variable , Entities . Type . Create ( cx , local . GetAnnotatedType ( ) ) , true , tuple , child0 ++ ) ;
82- var id = single . Identifier ;
83- var location = cx . Create ( id . GetLocation ( ) ) ;
84- LocalVariable . Create ( cx , local , decl , true , location ) ;
82+ var decl = Create ( cx , variable , Entities . Type . Create ( cx , local . GetAnnotatedType ( ) ) , tuple , child0 ++ ) ;
83+ var l = LocalVariable . Create ( cx , local ) ;
84+ l . PopulateInfo ( decl , true ) ;
8585 }
8686 else
8787 {
@@ -111,51 +111,49 @@ static Expression Create(Context cx, DeclarationExpressionSyntax node, VariableD
111111 case DiscardDesignationSyntax discard :
112112 var ti = cx . GetType ( discard ) ;
113113 var type = Entities . Type . Create ( cx , ti ) ;
114- return Create ( cx , node , type , node . Type . IsVar , parent , child ) ;
114+ return Create ( cx , node , type , parent , child ) ;
115115 default :
116116 cx . ModelError ( node , "Failed to determine designation type" ) ;
117- return Create ( cx , node , Entities . NullType . Create ( cx ) , node . Type . IsVar , parent , child ) ;
117+ return Create ( cx , node , NullType . Create ( cx ) , parent , child ) ;
118118 }
119119 }
120120
121121 public static Expression Create ( Context cx , DeclarationExpressionSyntax node , IExpressionParentEntity parent , int child ) =>
122122 Create ( cx , node , node . Designation , parent , child ) ;
123123
124- public static VariableDeclaration Create ( Context cx , CSharpSyntaxNode c , AnnotatedType type , bool isVar , IExpressionParentEntity parent , int child ) =>
124+ public static VariableDeclaration Create ( Context cx , CSharpSyntaxNode c , AnnotatedType type , IExpressionParentEntity parent , int child ) =>
125125 new VariableDeclaration ( new ExpressionInfo ( cx , type , cx . Create ( c . FixedLocation ( ) ) , ExprKind . LOCAL_VAR_DECL , parent , child , false , null ) ) ;
126126
127127 public static VariableDeclaration Create ( Context cx , CatchDeclarationSyntax d , bool isVar , IExpressionParentEntity parent , int child )
128128 {
129129 var symbol = cx . GetModel ( d ) . GetDeclaredSymbol ( d ) ;
130130 var type = Entities . Type . Create ( cx , symbol . GetAnnotatedType ( ) ) ;
131- var ret = Create ( cx , d , type , isVar , parent , child ) ;
131+ var ret = Create ( cx , d , type , parent , child ) ;
132132 cx . Try ( d , null , ( ) =>
133133 {
134- var id = d . Identifier ;
135134 var declSymbol = cx . GetModel ( d ) . GetDeclaredSymbol ( d ) ;
136- var location = cx . Create ( id . GetLocation ( ) ) ;
137- LocalVariable . Create ( cx , declSymbol , ret , isVar , location ) ;
135+ var l = LocalVariable . Create ( cx , declSymbol ) ;
136+ l . PopulateInfo ( ret , isVar ) ;
138137 TypeMention . Create ( cx , d . Type , ret , type ) ;
139138 } ) ;
140139 return ret ;
141140 }
142141
143142 public static VariableDeclaration CreateDeclarator ( Context cx , VariableDeclaratorSyntax d , AnnotatedType type , bool isVar , IExpressionParentEntity parent , int child )
144143 {
145- var ret = Create ( cx , d , type , isVar , parent , child ) ;
144+ var ret = Create ( cx , d , type , parent , child ) ;
146145 cx . Try ( d , null , ( ) =>
147146 {
148- var id = d . Identifier ;
149147 var declSymbol = cx . GetModel ( d ) . GetDeclaredSymbol ( d ) ;
150- var location = cx . Create ( id . GetLocation ( ) ) ;
151- var localVar = LocalVariable . Create ( cx , declSymbol , ret , isVar , location ) ;
148+ var localVar = LocalVariable . Create ( cx , declSymbol ) ;
149+ localVar . PopulateInfo ( ret , isVar ) ;
152150
153151 if ( d . Initializer != null )
154152 {
155153 Create ( cx , d . Initializer . Value , ret , 0 ) ;
156154
157155 // Create an access
158- var access = new Expression ( new ExpressionInfo ( cx , type , location , ExprKind . LOCAL_VARIABLE_ACCESS , ret , 1 , false , null ) ) ;
156+ var access = new Expression ( new ExpressionInfo ( cx , type , localVar . Location , ExprKind . LOCAL_VARIABLE_ACCESS , ret , 1 , false , null ) ) ;
159157 cx . TrapWriter . Writer . expr_access ( access , localVar ) ;
160158 }
161159
0 commit comments