5.6.13 Index Expressions
Note
This section describes the implementation of MS-VBAL §5.6.13 Index Expressions.
Syntax
| Expression | AST node |
|---|---|
| Index | IndexExpressionNode |
See RD-VBAL §3.0.2 Node Types.
Runtime Semantics
RuntimeExpressionEvaluator.EvaluateIndex evaluates an index expression.
Procedure Callee
For an IndexExpressionNode, whether its Callee is a bare name resolving to a Sub, Function or Property Get
is checked before the usual recursive Evaluate(Callee). Such an index expression invokes the procedure with the
index expression's own arguments. See
RD-VBAL §5.3.1.11 Procedure Invocation Argument Processing.
The check precedes Evaluate(Callee) because, otherwise, a bare-name Callee would already have been auto-invoked
with zero arguments by SimpleName's own dispatch, before the index expression could supply its arguments. See
RD-VBAL §5.6.10 Simple Name Expressions.
An index expression with a procedure Callee is the only expression form that recurses (e.g. Foo(n - 1), even
from within Foo's own body). A bare Foo, from within Foo's own body, reads the function result variable instead
(RD-VBAL §5.6.10 Simple Name Expressions).
Variant Holding an Array
RuntimeExpressionEvaluator.EvaluateIndex unwraps a
VBVariantValue before matching a wrapped
VBArrayValue, so v(0) indexes a Variant holding an
array the same as a declared array. See
RD-VBAL §5.5.1.2.12 Let-coercion to Variant.
Object Callee
An index expression whose Callee is an object - or a Variant holding one - calls the object's default member, the one its class marks with VB_UserMemId = 0: c(1) is
c.Item(1), and c(1)(2) indexes what that returns. A class of the workspace and a class of the library are found alike
(RD-VBAL §6.1.3.1 Collection Object). An object with no such member is runtime error 438, and Nothing is runtime error 91.
5.6.13.1 Argument Lists
This section corresponds to MS-VBAL §5.6.13.1 Argument Lists.
The ByVal keyword (argument-expression = ["byval"] expression) flags one argument as passed by value, whatever mechanism
its parameter declares. It is a token of the source and stays one in the tree: a
ByValArgumentExpressionNode wraps the argument
it is written before, in an argument list of a call and of a named argument alike. Such an argument is a value bound to nothing, so
it is never aliased to a ByRef parameter (RD-VBAL §5.3.1.11).
It is invalid for an argument list to have a ByVal argument unless it is that of an invocation of an external procedure. The
parser cannot tell what is invoked, so this is a compile error where the callee is known,
VBC09327, not a syntax error: Foo ByVal x parses, and is valid when Foo is a Declare. The
argument list of a RaiseEvent is the exception, being known not to be that of an external procedure: there it is a syntax
error (RD-VBAL §5.4.2.20).
See RD-VBAL §5.3.1.11 Procedure Invocation Argument Processing.
5.6.13.2 Argument List Queues
This section corresponds to MS-VBAL §5.6.13.2 Argument List Queues.
Note
Reserved. This section has no content yet.
⏮️ RD-VBAL §5.6.12 Member Access Expressions | ⏭️ RD-VBAL §5.6.14 Dictionary Access Expressions