@@ -123,7 +123,7 @@ private void Visit(VBAParser.LExprContext context)
123
123
}
124
124
125
125
IUCIValue newResult = null ;
126
- if ( TryGetTheLExprValue ( context , out string lexprValue , out string declaredType ) )
126
+ if ( TryGetLExprValue ( context , out string lexprValue , out string declaredType ) )
127
127
{
128
128
newResult = _inspValueFactory . Create ( lexprValue , declaredType ) ;
129
129
}
@@ -237,32 +237,36 @@ private static IEnumerable<IParseTree> NonWhitespaceChildren(ParserRuleContext p
237
237
return ptParent . children . Where ( ch => ! ( ch is VBAParser . WhiteSpaceContext ) ) ;
238
238
}
239
239
240
- private bool TryGetTheLExprValue ( VBAParser . LExprContext ctxt , out string expressionValue , out string declaredTypeName )
240
+ private bool TryGetLExprValue ( VBAParser . LExprContext lExprContext , out string expressionValue , out string declaredTypeName )
241
241
{
242
242
expressionValue = string . Empty ;
243
243
declaredTypeName = string . Empty ;
244
- if ( ctxt . TryGetChildContext ( out VBAParser . MemberAccessExprContext memberAccess ) )
244
+ var isMemberAccess = lExprContext . TryGetChildContext ( out VBAParser . MemberAccessExprContext memberAccess ) ;
245
+ var isSimpleName = lExprContext . TryGetChildContext ( out VBAParser . SimpleNameExprContext smplName ) ;
246
+
247
+ if ( ! ( isMemberAccess || isSimpleName ) )
248
+ {
249
+ return false ;
250
+ }
251
+
252
+ if ( isMemberAccess )
245
253
{
246
254
var member = memberAccess . GetChild < VBAParser . UnrestrictedIdentifierContext > ( ) ;
247
255
248
- if ( TryGetIdentifierReferenceForContext ( member , out IdentifierReference idRef ) )
256
+ if ( TryGetIdentifierReferenceForContext ( member , out IdentifierReference idRef )
257
+ && idRef . Declaration . DeclarationType . HasFlag ( DeclarationType . EnumerationMember )
258
+ && idRef . Declaration . Context is VBAParser . EnumerationStmt_ConstantContext )
249
259
{
250
260
var dec = idRef . Declaration ;
251
- if ( dec . DeclarationType . HasFlag ( DeclarationType . EnumerationMember ) )
252
- {
253
- var theCtxt = dec . Context ;
254
- if ( theCtxt is VBAParser . EnumerationStmt_ConstantContext )
255
- {
256
- expressionValue = GetConstantDeclarationValueToken ( dec ) ;
257
- declaredTypeName = dec . AsTypeIsBaseType ? dec . AsTypeName : dec . AsTypeDeclaration . AsTypeName ;
258
- return true ;
259
- }
260
- }
261
+ var theCtxt = dec . Context ;
262
+ expressionValue = GetConstantDeclarationValueToken ( dec ) ;
263
+ declaredTypeName = dec . AsTypeIsBaseType ? dec . AsTypeName : dec . AsTypeDeclaration . AsTypeName ;
264
+ return true ;
261
265
}
262
266
return false ;
263
267
}
264
268
265
- if ( ctxt . TryGetChildContext ( out VBAParser . SimpleNameExprContext smplName ) )
269
+ if ( isSimpleName )
266
270
{
267
271
if ( TryGetIdentifierReferenceForContext ( smplName , out IdentifierReference rangeClauseIdentifierReference ) )
268
272
{
@@ -279,7 +283,7 @@ private bool TryGetTheLExprValue(VBAParser.LExprContext ctxt, out string express
279
283
return false ;
280
284
}
281
285
282
- private bool TryGetIdentifierReferenceForContext < T > ( T context , out IdentifierReference idRef ) where T : ParserRuleContext
286
+ private bool TryGetIdentifierReferenceForContext ( ParserRuleContext context , out IdentifierReference idRef )
283
287
{
284
288
idRef = null ;
285
289
var identifierReferences = ( _state . DeclarationFinder . MatchName ( context . GetText ( ) ) . Select ( dec => dec . References ) ) . SelectMany ( rf => rf ) ;
@@ -327,8 +331,8 @@ private static string GetBaseTypeForDeclaration(Declaration declaration)
327
331
328
332
private static bool IsBinaryMathContext < T > ( T context )
329
333
{
330
- return context is VBAParser . MultOpContext
331
- || context is VBAParser . AddOpContext
334
+ return context is VBAParser . MultOpContext //MultOpContext includes both * and /
335
+ || context is VBAParser . AddOpContext //AddOpContet includes both + and -
332
336
|| context is VBAParser . PowOpContext
333
337
|| context is VBAParser . ModOpContext ;
334
338
}
0 commit comments