2
2
using Rubberduck . Parsing . Grammar ;
3
3
using Rubberduck . Parsing . Symbols ;
4
4
using System ;
5
+ using System . Collections . Generic ;
5
6
using Antlr4 . Runtime . Tree ;
6
7
using Rubberduck . Parsing . VBA . DeclarationCaching ;
7
8
@@ -29,7 +30,26 @@ public IBoundExpression Resolve(Declaration module, Declaration parent, IParseTr
29
30
return bindingTree ? . Resolve ( ) ;
30
31
}
31
32
32
- public IExpressionBinding BuildTree ( Declaration module , Declaration parent , IParseTree expression , IBoundExpression withBlockVariable , StatementResolutionContext statementContext , bool requiresLetCoercion = false , bool isLetAssignment = false )
33
+ public IExpressionBinding BuildTree (
34
+ Declaration module ,
35
+ Declaration parent ,
36
+ IParseTree expression ,
37
+ IBoundExpression withBlockVariable ,
38
+ StatementResolutionContext statementContext ,
39
+ bool requiresLetCoercion = false ,
40
+ bool isLetAssignment = false )
41
+ {
42
+ return Visit (
43
+ module ,
44
+ parent ,
45
+ expression ,
46
+ withBlockVariable ,
47
+ statementContext ,
48
+ requiresLetCoercion ,
49
+ isLetAssignment ) ;
50
+ }
51
+
52
+ public IExpressionBinding Visit ( Declaration module , Declaration parent , IParseTree expression , IBoundExpression withBlockVariable , StatementResolutionContext statementContext , bool requiresLetCoercion = false , bool isLetAssignment = false )
33
53
{
34
54
if ( requiresLetCoercion && expression is ParserRuleContext context )
35
55
{
@@ -51,6 +71,10 @@ public IExpressionBinding BuildTree(Declaration module, Declaration parent, IPar
51
71
return Visit ( module , parent , booleanExpressionContext , withBlockVariable ) ;
52
72
case VBAParser . IntegerExpressionContext integerExpressionContext :
53
73
return Visit ( module , parent , integerExpressionContext , withBlockVariable ) ;
74
+ case VBAParser . OutputListContext outputListContext :
75
+ return Visit ( module , parent , outputListContext , withBlockVariable ) ;
76
+ case VBAParser . UnqualifiedObjectPrintStmtContext unqualifiedObjectPrintStmtContext :
77
+ return Visit ( module , parent , unqualifiedObjectPrintStmtContext , withBlockVariable ) ;
54
78
default :
55
79
throw new NotSupportedException ( $ "Unexpected context type { expression . GetType ( ) } ") ;
56
80
}
@@ -160,6 +184,8 @@ private IExpressionBinding Visit(Declaration module, Declaration parent, VBAPars
160
184
return Visit ( module , parent , dictionaryAccessExprContext , withBlockVariable ) ;
161
185
case VBAParser . WithDictionaryAccessExprContext withDictionaryAccessExprContext :
162
186
return Visit ( module , parent , withDictionaryAccessExprContext , withBlockVariable ) ;
187
+ case VBAParser . ObjectPrintExprContext objectPrintExprContext :
188
+ return Visit ( module , parent , objectPrintExprContext , withBlockVariable ) ;
163
189
default :
164
190
throw new NotSupportedException ( $ "Unexpected lExpression type { expression . GetType ( ) } ") ;
165
191
}
@@ -208,7 +234,61 @@ private IExpressionBinding Visit(Declaration module, Declaration parent, VBAPars
208
234
{
209
235
var lExpression = expression . lExpression ( ) ;
210
236
var lExpressionBinding = Visit ( module , parent , lExpression , withBlockVariable , StatementResolutionContext . Undefined ) ;
211
- return new MemberAccessDefaultBinding ( _declarationFinder , Declaration . GetProjectParent ( parent ) , module , parent , expression , lExpressionBinding , statementContext , expression . unrestrictedIdentifier ( ) ) ;
237
+ return new MemberAccessDefaultBinding (
238
+ _declarationFinder ,
239
+ Declaration . GetProjectParent ( parent ) ,
240
+ module ,
241
+ parent ,
242
+ expression ,
243
+ lExpressionBinding ,
244
+ statementContext ,
245
+ expression . unrestrictedIdentifier ( ) ) ;
246
+ }
247
+
248
+ private IExpressionBinding Visit ( Declaration module , Declaration parent , VBAParser . ObjectPrintExprContext expression , IBoundExpression withBlockVariable )
249
+ {
250
+ var lExpression = expression . lExpression ( ) ;
251
+ var lExpressionBinding = Visit ( module , parent , lExpression , withBlockVariable , StatementResolutionContext . Undefined ) ;
252
+ var memberAccessBinding = new MemberAccessDefaultBinding (
253
+ _declarationFinder ,
254
+ Declaration . GetProjectParent ( parent ) ,
255
+ module ,
256
+ parent ,
257
+ expression ,
258
+ lExpressionBinding ,
259
+ StatementResolutionContext . Undefined ,
260
+ expression . printMethod ( ) ) ;
261
+ var outputListContext = expression . outputList ( ) ;
262
+ var outputListBinding = outputListContext != null
263
+ ? Visit (
264
+ module ,
265
+ parent ,
266
+ outputListContext ,
267
+ withBlockVariable )
268
+ : null ;
269
+ return new ObjectPrintDefaultBinding ( expression , memberAccessBinding , outputListBinding ) ;
270
+ }
271
+
272
+ private IExpressionBinding Visit ( Declaration module , Declaration parent , VBAParser . UnqualifiedObjectPrintStmtContext expression , IBoundExpression withBlockVariable )
273
+ {
274
+ var printMethodContext = expression . printMethod ( ) ;
275
+ var simpleNameBinding = new SimpleNameDefaultBinding (
276
+ _declarationFinder ,
277
+ Declaration . GetProjectParent ( parent ) ,
278
+ module ,
279
+ parent ,
280
+ printMethodContext ,
281
+ printMethodContext . GetText ( ) ,
282
+ StatementResolutionContext . Undefined ) ;
283
+ var outputListContext = expression . outputList ( ) ;
284
+ var outputListBinding = outputListContext != null
285
+ ? Visit (
286
+ module ,
287
+ parent ,
288
+ outputListContext ,
289
+ withBlockVariable )
290
+ : null ;
291
+ return new ObjectPrintDefaultBinding ( expression , simpleNameBinding , outputListBinding ) ;
212
292
}
213
293
214
294
private IExpressionBinding Visit ( Declaration module , Declaration parent , VBAParser . IndexExprContext expression , IBoundExpression withBlockVariable )
@@ -416,6 +496,49 @@ private IExpressionBinding Visit(Declaration module, Declaration parent, VBAPars
416
496
return new LetCoercionDefaultBinding ( expression , innerExpression ) ;
417
497
}
418
498
499
+ private IExpressionBinding Visit ( Declaration module , Declaration parent , VBAParser . OutputListContext outputListContext , IBoundExpression withBlockVariable )
500
+ {
501
+ var itemBindings = new List < IExpressionBinding > ( ) ;
502
+ foreach ( var outputItem in outputListContext . outputItem ( ) )
503
+ {
504
+ if ( outputItem . outputClause ( ) != null )
505
+ {
506
+ if ( outputItem . outputClause ( ) . spcClause ( ) != null )
507
+ {
508
+ itemBindings . Add ( Visit (
509
+ module ,
510
+ parent ,
511
+ outputItem . outputClause ( ) . spcClause ( ) . spcNumber ( ) . expression ( ) ,
512
+ withBlockVariable ,
513
+ StatementResolutionContext . Undefined ,
514
+ requiresLetCoercion : true ) ) ;
515
+ }
516
+ if ( outputItem . outputClause ( ) . tabClause ( ) != null && outputItem . outputClause ( ) . tabClause ( ) . tabNumberClause ( ) != null )
517
+ {
518
+ itemBindings . Add ( Visit (
519
+ module ,
520
+ parent ,
521
+ outputItem . outputClause ( ) . tabClause ( ) . tabNumberClause ( ) . tabNumber ( ) . expression ( ) ,
522
+ withBlockVariable ,
523
+ StatementResolutionContext . Undefined ,
524
+ requiresLetCoercion : true ) ) ;
525
+ }
526
+ if ( outputItem . outputClause ( ) . outputExpression ( ) != null )
527
+ {
528
+ itemBindings . Add ( Visit (
529
+ module ,
530
+ parent ,
531
+ outputItem . outputClause ( ) . outputExpression ( ) . expression ( ) ,
532
+ withBlockVariable ,
533
+ StatementResolutionContext . Undefined ,
534
+ requiresLetCoercion : true ) ) ;
535
+ }
536
+ }
537
+ }
538
+
539
+ return new OutputListDefaultBinding ( outputListContext , itemBindings ) ;
540
+ }
541
+
419
542
private static IExpressionBinding Visit ( Declaration module , VBAParser . InstanceExprContext expression )
420
543
{
421
544
return new InstanceDefaultBinding ( expression , module ) ;
0 commit comments