5.4.2.1 Call Statement
Note
This section describes the implementation of MS-VBAL §5.4.2.1 Call Statement.
Syntax
| AST node | Instruction kind(s) | Notes |
|---|---|---|
| CallStatementNode | Simple |
A Call statement or a bare call. |
See RD-VBAL §3.4.2 Simple Statements and RD-VBAL §3.5.2 Instruction.
Without Call, blanks then parentheses right after what the statement calls begin its arguments: F (2) calls F with the parenthesized argument (2), which is passed by value
(RD-VBAL §5.6.6 Parenthesized Expressions). In an expression, the parentheses are the argument list of what is before them: Call F (2) calls F with 2, and F (1) = 2 is an
assignment to F(1) (RD-VBAL §5.6.13 Index Expressions).
Static Semantics
What a call statement calls is a Sub or a Function, of the workspace, of a library or a Declare. A variable, a constant or a property is none,
and a call statement written on one is a compile error, with Call or without, as it is in MS-VBA (recorded in Excel):
| What the statement names | Example | Outcome |
|---|---|---|
| A variable or a constant of the procedure, a parameter included | Dim x As Long … x (1), x, Call x |
VBC09364 Expected Sub, Function, or Property |
| A variable or a constant of a module, bare or qualified | Count (1), Globals.Count (1), Call Count |
VBC09370 Expected procedure, not variable |
A property of an object of a known class, of the target of a With block, or of a module |
t.Value, Call t.Value(), t.Item 1, Call t.Item(1), .Value, Here |
VBC09345 Invalid use of property |
A variable of an object, without Call |
Dim c As New Collection … c (1) |
Valid: the statement calls the object's default member. |
With Call, an argument list that a Property Get with no parameters cannot take |
Call t.Bags(1), where Bags returns an object |
Valid: the arguments index the object it returns, and the statement calls that object's default member (RD-VBAL §5.6.13). |
A Variant is no object: a call statement on one is the error, whatever it holds. A variable hides a procedure of the same name in the procedure that
declares it, so P (1) in a procedure that declares Dim p As Long is VBC09364, though the module has a Sub P.
Runtime Semantics
A Call statement or a bare-call statement whose callee is a bare name (Foo, Foo(...), Call Foo(...)) invokes
it through a callable binding
(ICallableBindingFactory):
| Callee | Invoked through |
|---|---|
| A procedure of the workspace | IProcedureInvoker |
| A member with an external target (a standard-library member) | IExternalDispatcher (RD-VBAL §6.0 Standard Library) |
The unparenthesized argument form of a bare-call statement (Foo 1, 2, p.Grow 2) and a callee reached through a member access (obj.Foo, Call obj.Foo(1)) are invoked the
same way: a member of an object, of a module (Strings.LenB) or of a project (VBA.LenB) is a callee like any other
(RD-VBAL §5.6.12).
A property named on an object bound late (Dim o As Object … o.Value, Call o.Value, o.Item 1) is run-time error
VBR00450 Wrong number of arguments or invalid property assignment, and its Property Get is not called, as in MS-VBA.
A bare reference to a Sub or a Function invokes a procedure the same way
(RD-VBAL §5.3.1.11 Procedure Invocation Argument Processing,
RD-VBAL §5.6.10 Simple Name Expressions).
A callee's run-time error propagates like any other run-time error. The callee's error result
(RuntimeSemanticsEvaluationResult) is
converted back into an Error outcome by the caller's ExecuteCall.
Implementation
- A
Simpleinstruction is dispatched by its statement type throughRDCore.Runtime.Semantics.Statements.IStatementRuntimeSemanticsProvider(RD-VBAL §3.5.4 Execution);ExecuteCallhandles aCallStatementNode. RDCore.Runtime.Execution.RuntimeProcedureInvokeris theIProcedureInvokerimplementation.RDCore.Runtime.Execution.RuntimeCallableBindingFactoryis theICallableBindingFactoryimplementation. A member that carries SymbolProperties.ExternalTargetis bound to the external dispatcher; any other member is bound to the procedure invoker.