Skip to content

Commit 9628e94

Browse files
committed
Split actual Print statement and unqualified object Print member access
1 parent 05036b0 commit 9628e94

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

Rubberduck.Parsing/Binding/DefaultBindingContext.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ public IExpressionBinding Visit(Declaration module, Declaration parent, IParseTr
7373
return Visit(module, parent, integerExpressionContext, withBlockVariable);
7474
case VBAParser.OutputListContext outputListContext:
7575
return Visit(module, parent, outputListContext, withBlockVariable);
76-
case VBAParser.PrintStmtContext printStmtContext:
77-
return Visit(module, parent, printStmtContext, withBlockVariable);
76+
case VBAParser.UnqualifiedObjectPrintStmtContext unqualifiedObjectPrintStmtContext:
77+
return Visit(module, parent, unqualifiedObjectPrintStmtContext, withBlockVariable);
7878
default:
7979
throw new NotSupportedException($"Unexpected context type {expression.GetType()}");
8080
}
@@ -266,7 +266,7 @@ private IExpressionBinding Visit(Declaration module, Declaration parent, VBAPars
266266
return new ObjectPrintDefaultBinding(expression, memberAccessBinding, outputListBinding);
267267
}
268268

269-
private IExpressionBinding Visit(Declaration module, Declaration parent, VBAParser.PrintStmtContext expression, IBoundExpression withBlockVariable)
269+
private IExpressionBinding Visit(Declaration module, Declaration parent, VBAParser.UnqualifiedObjectPrintStmtContext expression, IBoundExpression withBlockVariable)
270270
{
271271
var printMethodContext = expression.printMethod();
272272
var simpleNameBinding = new SimpleNameDefaultBinding(

Rubberduck.Parsing/Grammar/VBAParser.g4

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ mainBlockStmt :
172172
| circleSpecialForm
173173
| scaleSpecialForm
174174
| pSetSpecialForm
175+
| unqualifiedObjectPrintStmt
175176
| callStmt
176177
| nameStmt
177178
;
@@ -257,10 +258,10 @@ lineWidth : expression;
257258

258259

259260
// 5.4.5.8 Print Statement
260-
//We make the part regarding the file handle optional to support VB6's print statement in forms.
261-
//It is an invocation of the Print member of the enclosing form, which also takes an output list as argument.
261+
//The unqualifiedObjectPrintStmt is an invocation of the Print member of the enclosing form or report, which also takes an output list as argument.
262262
printMethod : PRINT;
263-
printStmt : printMethod (whiteSpace markedFileNumber whiteSpace? COMMA)? (whiteSpace? outputList)?;
263+
printStmt : printMethod whiteSpace markedFileNumber whiteSpace? COMMA (whiteSpace? outputList)?;
264+
unqualifiedObjectPrintStmt : printMethod (whiteSpace outputList)?;
264265

265266
// 5.4.5.8.1 Output Lists
266267
outputList : outputItem (whiteSpace? outputItem)*;

Rubberduck.Parsing/VBA/ReferenceManagement/IdentifierReferenceListener.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,11 @@ public override void EnterPrintStmt([NotNull] VBAParser.PrintStmtContext context
237237
_resolver.Resolve(context);
238238
}
239239

240+
public override void EnterUnqualifiedObjectPrintStmt([NotNull] VBAParser.UnqualifiedObjectPrintStmtContext context)
241+
{
242+
_resolver.Resolve(context);
243+
}
244+
240245
public override void EnterWriteStmt([NotNull] VBAParser.WriteStmtContext context)
241246
{
242247
_resolver.Resolve(context);

Rubberduck.Parsing/VBA/ReferenceManagement/IdentifierReferenceResolver.cs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -501,21 +501,13 @@ public void Resolve(VBAParser.WidthStmtContext context)
501501

502502
public void Resolve(VBAParser.PrintStmtContext context)
503503
{
504-
if (context.markedFileNumber() != null)
505-
{
506-
ResolvePrintStatement(context);
507-
}
508-
else
509-
{
510-
//Since there is no file handle, this must be an unqualified print member call in a VB6 form.
511-
ResolveDefault(context);
512-
}
504+
ResolveDefault(context.markedFileNumber().expression(), true);
505+
ResolveOutputList(context.outputList());
513506
}
514507

515-
public void ResolvePrintStatement(VBAParser.PrintStmtContext context)
508+
public void Resolve(VBAParser.UnqualifiedObjectPrintStmtContext context)
516509
{
517-
ResolveDefault(context.markedFileNumber().expression(), true);
518-
ResolveOutputList(context.outputList());
510+
ResolveDefault(context);
519511
}
520512

521513
public void Resolve(VBAParser.WriteStmtContext context)

0 commit comments

Comments
 (0)