vba-interpreter 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +96 -2
- package/dist/contract-CBGNXslV.d.ts +226 -0
- package/dist/exec/index.d.ts +12 -0
- package/dist/exec/index.js +1 -0
- package/dist/exec-DYWJe-eU.js +306 -0
- package/dist/exec-DYWJe-eU.js.map +1 -0
- package/dist/index-DnrotnmB.d.ts +2015 -0
- package/dist/index-DtaSNo0V.d.ts +111 -0
- package/dist/index-DyoT9JOJ.d.ts +4 -0
- package/dist/index-gM7FYTaq.d.ts +1353 -0
- package/dist/index-zKYgEJdV.d.ts +900 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +3 -0
- package/dist/interp/index.d.ts +10 -0
- package/dist/interp/index.js +1 -0
- package/dist/interp-ChrsgBCf.js +3433 -0
- package/dist/interp-ChrsgBCf.js.map +1 -0
- package/dist/lang/index.d.ts +10 -0
- package/dist/lang/index.js +1 -0
- package/dist/lang-Bo63dJb9.js +4740 -0
- package/dist/lang-Bo63dJb9.js.map +1 -0
- package/dist/runtime/index.d.ts +33 -0
- package/dist/runtime/index.js +1 -0
- package/dist/runtime-C8-PPxmH.js +8284 -0
- package/dist/runtime-C8-PPxmH.js.map +1 -0
- package/dist/semantic/index.d.ts +12 -0
- package/dist/semantic/index.js +1 -0
- package/dist/semantic-CAVxm72C.js +2877 -0
- package/dist/semantic-CAVxm72C.js.map +1 -0
- package/package.json +91 -5
|
@@ -0,0 +1,900 @@
|
|
|
1
|
+
import { $ as ProcedureDeclaration, C as ParseOptions, F as ModuleKind, G as EnumDeclaration, I as ModuleNode, It as WithStatement, L as ArrayBound, O as VbaDiagnostic, Pt as Statement, Q as Parameter, St as LabelStatement, U as DeclareStatement, V as ConstDeclaration, at as VariableDeclarator, et as ProcedureKind, kn as Span, nt as TypeDeclaration, q as EventDeclaration, rn as Expression, un as NameRef } from "./index-gM7FYTaq.js";
|
|
2
|
+
/**
|
|
3
|
+
* Where a variable lives: `local` in the frame, `static` in the procedure's static store (per
|
|
4
|
+
* instance in a class module), `module` once per standard or document module, `instance` once per
|
|
5
|
+
* object of a class module, `result` the return value of a Function or Property Get.
|
|
6
|
+
*/
|
|
7
|
+
type VariableScope = 'local' | 'static' | 'module' | 'instance' | 'result';
|
|
8
|
+
/** How a variable is used, collected while binding (both executors use it to optimise). */
|
|
9
|
+
declare class UsageFacts {
|
|
10
|
+
/** Read anywhere. */
|
|
11
|
+
read: boolean;
|
|
12
|
+
/** Assigned with Let (`x = ...`). */
|
|
13
|
+
letWritten: boolean;
|
|
14
|
+
/** Assigned with Set. */
|
|
15
|
+
setWritten: boolean;
|
|
16
|
+
/** A For or For Each counter. */
|
|
17
|
+
forCounter: boolean;
|
|
18
|
+
/** ReDim or Erase target. */
|
|
19
|
+
redimmed: boolean;
|
|
20
|
+
/** An element or field of it is written (`a(1) = ...`, `u.x = ...`). */
|
|
21
|
+
partWritten: boolean;
|
|
22
|
+
/** Target of `Mid(x, ...) =`, `LSet` or `RSet`. */
|
|
23
|
+
stringStatement: boolean;
|
|
24
|
+
/** Passed ByRef (as a variable reference) to a procedure that may write it. */
|
|
25
|
+
passedByRef: boolean;
|
|
26
|
+
/** True when any of the write facts above is set. */
|
|
27
|
+
get written(): boolean;
|
|
28
|
+
}
|
|
29
|
+
/** A variable: a local, a Static local, a module or instance variable, or a function result. */
|
|
30
|
+
interface VariableSymbol {
|
|
31
|
+
/** Marks a variable symbol. */
|
|
32
|
+
readonly kind: 'variable';
|
|
33
|
+
/** Unique in the program. */
|
|
34
|
+
readonly id: number;
|
|
35
|
+
/** The name, as declared. */
|
|
36
|
+
readonly name: string;
|
|
37
|
+
/** Where the variable lives. */
|
|
38
|
+
readonly scope: VariableScope;
|
|
39
|
+
/** The module that declares it. */
|
|
40
|
+
readonly module: string;
|
|
41
|
+
/** Visible from other modules (`Public`/`Global` at module level). */
|
|
42
|
+
readonly isPublic: boolean;
|
|
43
|
+
/** The declared type (for an array, the array type). */
|
|
44
|
+
readonly type: StaticType;
|
|
45
|
+
/** Array bounds as written (`Dim a(1 To 3, 5)`); empty for `a()`; null when not an array. */
|
|
46
|
+
readonly bounds: readonly ArrayBound[] | null;
|
|
47
|
+
/** `As New Class`: created on first use, and again after `Set x = Nothing`. */
|
|
48
|
+
readonly isNew: boolean;
|
|
49
|
+
/** Declared `WithEvents`: its `name_Event` Subs handle the object's events. */
|
|
50
|
+
readonly withEvents: boolean;
|
|
51
|
+
/** True for an undeclared variable created implicitly (no `Option Explicit`). */
|
|
52
|
+
readonly implicit: boolean;
|
|
53
|
+
/** The index in its storage (see the file comment). */
|
|
54
|
+
readonly slot: number;
|
|
55
|
+
/** Its declarator; null for a function result or an implicit variable. */
|
|
56
|
+
readonly declaration: VariableDeclarator | null;
|
|
57
|
+
/** How the body uses it. */
|
|
58
|
+
readonly usage: UsageFacts;
|
|
59
|
+
}
|
|
60
|
+
/** A parameter of a procedure. */
|
|
61
|
+
interface ParamSymbol {
|
|
62
|
+
/** Marks a parameter symbol. */
|
|
63
|
+
readonly kind: 'param';
|
|
64
|
+
/** Unique in the program. */
|
|
65
|
+
readonly id: number;
|
|
66
|
+
/** The name, as declared. */
|
|
67
|
+
readonly name: string;
|
|
68
|
+
/** Its 0-based position in the parameter list. */
|
|
69
|
+
readonly index: number;
|
|
70
|
+
/** The frame slot (equal to `index`). */
|
|
71
|
+
readonly slot: number;
|
|
72
|
+
/** How it is passed: `ByRef` when the declaration says neither. */
|
|
73
|
+
readonly passing: 'ByRef' | 'ByVal';
|
|
74
|
+
/** Declared `Optional`. */
|
|
75
|
+
readonly optional: boolean;
|
|
76
|
+
/** The default of an Optional parameter, a constant expression bound in the module scope. */
|
|
77
|
+
readonly defaultValue: Expression | null;
|
|
78
|
+
/** Declared `ParamArray`: it collects the remaining arguments. */
|
|
79
|
+
readonly paramArray: boolean;
|
|
80
|
+
/** The declared type; `name()` parameters are arrays. */
|
|
81
|
+
readonly type: StaticType;
|
|
82
|
+
/** Its AST node. */
|
|
83
|
+
readonly declaration: Parameter;
|
|
84
|
+
/** How the body uses it. */
|
|
85
|
+
readonly usage: UsageFacts;
|
|
86
|
+
}
|
|
87
|
+
/** A constant declared with `Const`, at module level or in a procedure. */
|
|
88
|
+
interface ConstSymbol {
|
|
89
|
+
/** Marks a constant symbol. */
|
|
90
|
+
readonly kind: 'const';
|
|
91
|
+
/** Unique in the program. */
|
|
92
|
+
readonly id: number;
|
|
93
|
+
/** The name, as declared. */
|
|
94
|
+
readonly name: string;
|
|
95
|
+
/** The module that declares it. */
|
|
96
|
+
readonly module: string;
|
|
97
|
+
/** The procedure for a local `Const`, else null. */
|
|
98
|
+
readonly procedure: string | null;
|
|
99
|
+
/** Visible from other modules (`Public Const` in a standard module). */
|
|
100
|
+
readonly isPublic: boolean;
|
|
101
|
+
/** The declared type, or null when the type comes from the value. */
|
|
102
|
+
readonly type: StaticType | null;
|
|
103
|
+
/** The value expression, a constant expression. */
|
|
104
|
+
readonly value: Expression;
|
|
105
|
+
/** The `Const` statement that declares it. */
|
|
106
|
+
readonly declaration: ConstDeclaration;
|
|
107
|
+
/** The name as written in that statement. */
|
|
108
|
+
readonly nameRef: NameRef;
|
|
109
|
+
}
|
|
110
|
+
/** A member of an `Enum`. */
|
|
111
|
+
interface EnumMemberSymbol {
|
|
112
|
+
/** Marks an enum member symbol. */
|
|
113
|
+
readonly kind: 'enumMember';
|
|
114
|
+
/** Unique in the program. */
|
|
115
|
+
readonly id: number;
|
|
116
|
+
/** The member name, as declared. */
|
|
117
|
+
readonly name: string;
|
|
118
|
+
/** The name of the `Enum` it belongs to. */
|
|
119
|
+
readonly enumName: string;
|
|
120
|
+
/** The module that declares the `Enum`. */
|
|
121
|
+
readonly module: string;
|
|
122
|
+
/** The value expression; null means one more than `previous` (or 0 for the first member). */
|
|
123
|
+
readonly value: Expression | null;
|
|
124
|
+
/** The member before it in the `Enum`, or null for the first. */
|
|
125
|
+
readonly previous: EnumMemberSymbol | null;
|
|
126
|
+
/** Visible from other modules, as its `Enum` is. */
|
|
127
|
+
readonly isPublic: boolean;
|
|
128
|
+
}
|
|
129
|
+
/** An `Enum` declaration. */
|
|
130
|
+
interface EnumSymbol {
|
|
131
|
+
/** Marks an enum symbol. */
|
|
132
|
+
readonly kind: 'enum';
|
|
133
|
+
/** Unique in the program. */
|
|
134
|
+
readonly id: number;
|
|
135
|
+
/** The name, as declared. */
|
|
136
|
+
readonly name: string;
|
|
137
|
+
/** The module that declares it. */
|
|
138
|
+
readonly module: string;
|
|
139
|
+
/** Visible from other modules (an `Enum` is public unless declared `Private`). */
|
|
140
|
+
readonly isPublic: boolean;
|
|
141
|
+
/** Its members, in source order. */
|
|
142
|
+
readonly members: readonly EnumMemberSymbol[];
|
|
143
|
+
/** Its AST node. */
|
|
144
|
+
readonly declaration: EnumDeclaration;
|
|
145
|
+
}
|
|
146
|
+
/** A field of a user-defined type. */
|
|
147
|
+
interface UdtFieldSymbol {
|
|
148
|
+
/** The field name, as declared. */
|
|
149
|
+
readonly name: string;
|
|
150
|
+
/** The field's type (for an array field, the array type). */
|
|
151
|
+
readonly type: StaticType;
|
|
152
|
+
/** Array bounds of an array field; null when not an array. */
|
|
153
|
+
readonly bounds: readonly ArrayBound[] | null;
|
|
154
|
+
}
|
|
155
|
+
/** A user-defined type, declared with `Type ... End Type`. */
|
|
156
|
+
interface UdtSymbol {
|
|
157
|
+
/** Marks a user-defined type symbol. */
|
|
158
|
+
readonly kind: 'udt';
|
|
159
|
+
/** Unique in the program. */
|
|
160
|
+
readonly id: number;
|
|
161
|
+
/** The name, as declared. */
|
|
162
|
+
readonly name: string;
|
|
163
|
+
/** The module that declares it. */
|
|
164
|
+
readonly module: string;
|
|
165
|
+
/** Visible from other modules (a `Type` is public unless declared `Private`). */
|
|
166
|
+
readonly isPublic: boolean;
|
|
167
|
+
/** Filled in once every type of the project is known (a field may name a later Type). */
|
|
168
|
+
readonly fields: UdtFieldSymbol[];
|
|
169
|
+
/** Its AST node. */
|
|
170
|
+
readonly declaration: TypeDeclaration;
|
|
171
|
+
}
|
|
172
|
+
/** An `Event` declared in a class module, raised with `RaiseEvent`. */
|
|
173
|
+
interface EventSymbol {
|
|
174
|
+
/** Marks an event symbol. */
|
|
175
|
+
readonly kind: 'event';
|
|
176
|
+
/** Unique in the program. */
|
|
177
|
+
readonly id: number;
|
|
178
|
+
/** The event name, as declared. */
|
|
179
|
+
readonly name: string;
|
|
180
|
+
/** The class module that declares it. */
|
|
181
|
+
readonly module: string;
|
|
182
|
+
/** The event's parameters, as written. */
|
|
183
|
+
readonly parameters: readonly Parameter[];
|
|
184
|
+
/** Its AST node. */
|
|
185
|
+
readonly declaration: EventDeclaration;
|
|
186
|
+
}
|
|
187
|
+
/** A `Declare` statement: kept so calls bind, but executors refuse to call it (error 445). */
|
|
188
|
+
interface DeclareSymbol {
|
|
189
|
+
/** Marks a `Declare` symbol. */
|
|
190
|
+
readonly kind: 'declare';
|
|
191
|
+
/** Unique in the program. */
|
|
192
|
+
readonly id: number;
|
|
193
|
+
/** The procedure name, as declared. */
|
|
194
|
+
readonly name: string;
|
|
195
|
+
/** The module that declares it. */
|
|
196
|
+
readonly module: string;
|
|
197
|
+
/** Visible from other modules (not declared `Private`). */
|
|
198
|
+
readonly isPublic: boolean;
|
|
199
|
+
/** Its AST node. */
|
|
200
|
+
readonly declaration: DeclareStatement;
|
|
201
|
+
}
|
|
202
|
+
/** The scalar types a variable can be declared with. */
|
|
203
|
+
type ScalarTypeName = 'Boolean' | 'Byte' | 'Integer' | 'Long' | 'LongLong' | 'LongPtr' | 'Single' | 'Double' | 'Currency' | 'Decimal' | 'Date' | 'String';
|
|
204
|
+
/** `Variant`, and the type of anything the binder cannot type statically. */
|
|
205
|
+
interface VariantType {
|
|
206
|
+
/** Marks the Variant type. */
|
|
207
|
+
readonly kind: 'variant';
|
|
208
|
+
}
|
|
209
|
+
/** A scalar type: a number, `Boolean`, `Date` or `String` (also an `Enum`, stored as `Long`). */
|
|
210
|
+
interface ScalarType {
|
|
211
|
+
/** Marks a scalar type. */
|
|
212
|
+
readonly kind: 'scalar';
|
|
213
|
+
/** Which scalar type. */
|
|
214
|
+
readonly name: ScalarTypeName;
|
|
215
|
+
/** The `VarType` number ([MS-VBAL] 6.1.1.16), the runtime's `VT.*`. */
|
|
216
|
+
readonly vt: number;
|
|
217
|
+
/** `String * n`: the length expression (a constant expression). */
|
|
218
|
+
readonly fixedLength: Expression | null;
|
|
219
|
+
/** Set when the type is an Enum (stored as Long). */
|
|
220
|
+
readonly enumName: string | null;
|
|
221
|
+
}
|
|
222
|
+
/** `Object`, a class of the project, or a host type (`Range`, `Excel.Worksheet`). */
|
|
223
|
+
interface ObjectType {
|
|
224
|
+
/** Marks an object type. */
|
|
225
|
+
readonly kind: 'object';
|
|
226
|
+
/** The type as written; null for `Object`. */
|
|
227
|
+
readonly className: string | null;
|
|
228
|
+
/** The class module of the project it names, when it names one. */
|
|
229
|
+
readonly classModule: string | null;
|
|
230
|
+
}
|
|
231
|
+
/** A user-defined type (`Type ... End Type`). */
|
|
232
|
+
interface UdtType {
|
|
233
|
+
/** Marks a user-defined type. */
|
|
234
|
+
readonly kind: 'udt';
|
|
235
|
+
/** The type's declaration. */
|
|
236
|
+
readonly udt: UdtSymbol;
|
|
237
|
+
}
|
|
238
|
+
/** An array type. */
|
|
239
|
+
interface ArrayType {
|
|
240
|
+
/** Marks an array type. */
|
|
241
|
+
readonly kind: 'array';
|
|
242
|
+
/** The type of each element. */
|
|
243
|
+
readonly element: StaticType;
|
|
244
|
+
/** The number of dimensions when declared with bounds; null for a dynamic array. */
|
|
245
|
+
readonly rank: number | null;
|
|
246
|
+
/** Declared with bounds (`Dim a(3)`): cannot be ReDimmed. */
|
|
247
|
+
readonly fixed: boolean;
|
|
248
|
+
}
|
|
249
|
+
/** The type the binder knows for a symbol or expression before the program runs. */
|
|
250
|
+
type StaticType = VariantType | ScalarType | ObjectType | UdtType | ArrayType;
|
|
251
|
+
/** The Variant type. */
|
|
252
|
+
declare const VARIANT: VariantType;
|
|
253
|
+
/** The plain `Object` type: an object of no known class. */
|
|
254
|
+
declare const OBJECT: ObjectType;
|
|
255
|
+
/** The scalar type of a name (shared instances for the plain types). */
|
|
256
|
+
declare function scalarType(name: ScalarTypeName, fixedLength?: Expression | null, enumName?: string | null): ScalarType;
|
|
257
|
+
/** `VarType` number of a scalar type name. */
|
|
258
|
+
declare const vtOfScalar: (name: ScalarTypeName) => number;
|
|
259
|
+
/** True when the type is Variant: operators then use VBA's Variant rules (no strict overflow). */
|
|
260
|
+
declare const isVariant: (t: StaticType) => boolean;
|
|
261
|
+
/**
|
|
262
|
+
* The `VarType` an executor coerces stores to: a scalar's VT, 9 for objects, 36 for UDTs, 12
|
|
263
|
+
* (Variant) for Variants and arrays.
|
|
264
|
+
*/
|
|
265
|
+
declare function storageVt(t: StaticType): number;
|
|
266
|
+
/**
|
|
267
|
+
* How a runtime export is called: `env` (args, env), `conversion` (the one argument, env, typed:
|
|
268
|
+
* whether it is a literal or of a declared non-Variant type, see the invocation's `typedArgument`),
|
|
269
|
+
* `compare` (args, Option Compare mode, env), `session` (session, args), `pure` (args), `list`
|
|
270
|
+
* (args, ParamArray values, env), `special` (the executor implements it).
|
|
271
|
+
*/
|
|
272
|
+
type LibraryConvention = 'env' | 'conversion' | 'compare' | 'session' | 'pure' | 'list' | 'special';
|
|
273
|
+
/** A function or statement of VBA's library (`Left`, `MsgBox`, `Randomize`). */
|
|
274
|
+
interface LibraryFunction {
|
|
275
|
+
/** Marks a function entry. */
|
|
276
|
+
readonly kind: 'function';
|
|
277
|
+
/** The canonical VBA name, with `$` for the String forms. */
|
|
278
|
+
readonly name: string;
|
|
279
|
+
/** The runtime export (`leftS`), or null for `special` entries. */
|
|
280
|
+
readonly runtime: string | null;
|
|
281
|
+
/** How an executor calls the runtime export. */
|
|
282
|
+
readonly convention: LibraryConvention;
|
|
283
|
+
/** Parameter names in order, for named arguments (`InStr(Start:=2, ...)`). */
|
|
284
|
+
readonly params: readonly string[];
|
|
285
|
+
/** How many leading parameters are required. */
|
|
286
|
+
readonly required: number;
|
|
287
|
+
/** The last parameter is a ParamArray. */
|
|
288
|
+
readonly paramArray: boolean;
|
|
289
|
+
/**
|
|
290
|
+
* `InStr`/`InStrB`: the first parameter is optional although it comes first, so a call with
|
|
291
|
+
* `required` arguments leaves it out (`InStr(s, "x")` is `InStr(, s, "x")`).
|
|
292
|
+
*/
|
|
293
|
+
readonly leadingOptional: boolean;
|
|
294
|
+
/** The static type of the result: `String` for the `$` forms, Variant unless stated. */
|
|
295
|
+
readonly returns: StaticType;
|
|
296
|
+
/** May answer with a Promise (MsgBox, InputBox, DoEvents, CallByName on a host object). */
|
|
297
|
+
readonly async: boolean;
|
|
298
|
+
/** A statement-like procedure called without a result (Randomize). */
|
|
299
|
+
readonly statement: boolean;
|
|
300
|
+
/**
|
|
301
|
+
* May return an object (CallByName, Choose, CreateObject, GetObject, IIf, Switch): using the
|
|
302
|
+
* result as a value may read its default member.
|
|
303
|
+
*/
|
|
304
|
+
readonly mayReturnObject: boolean;
|
|
305
|
+
}
|
|
306
|
+
/** A built-in constant (`vbCrLf`, `vbTextCompare`). */
|
|
307
|
+
interface LibraryConstant {
|
|
308
|
+
/** Marks a constant entry. */
|
|
309
|
+
readonly kind: 'constant';
|
|
310
|
+
/** The constant's name, in its canonical spelling. */
|
|
311
|
+
readonly name: string;
|
|
312
|
+
/** Its value. */
|
|
313
|
+
readonly value: number | string;
|
|
314
|
+
/** `Long` for the numeric enum constants, `String` for vbCrLf and the like. */
|
|
315
|
+
readonly type: StaticType;
|
|
316
|
+
}
|
|
317
|
+
/** The objects VBA's library provides: `Err`, `Debug`, and the `VBA` qualifier itself. */
|
|
318
|
+
interface LibraryObject {
|
|
319
|
+
/** Marks an object entry. */
|
|
320
|
+
readonly kind: 'object';
|
|
321
|
+
/** Which object. */
|
|
322
|
+
readonly name: 'Err' | 'Debug' | 'VBA';
|
|
323
|
+
}
|
|
324
|
+
/** Any entry of VBA's library, told apart by `kind`. */
|
|
325
|
+
type LibraryEntry = LibraryFunction | LibraryConstant | LibraryObject;
|
|
326
|
+
/** The optional settings of a function entry built with `fn` or `twin`. */
|
|
327
|
+
interface FunctionOptions {
|
|
328
|
+
/** See {@link LibraryFunction.required}. Defaults to every parameter but a ParamArray. */
|
|
329
|
+
readonly required?: number;
|
|
330
|
+
/** The result type. Defaults to `String` for a name ending in `$`, else Variant. */
|
|
331
|
+
readonly returns?: ScalarTypeName | 'Variant';
|
|
332
|
+
/** See {@link LibraryFunction.async}. Defaults to false. */
|
|
333
|
+
readonly async?: boolean;
|
|
334
|
+
/** See {@link LibraryFunction.statement}. Defaults to false. */
|
|
335
|
+
readonly statement?: boolean;
|
|
336
|
+
/** See {@link LibraryFunction.leadingOptional}. Defaults to false. */
|
|
337
|
+
readonly leadingOptional?: boolean;
|
|
338
|
+
readonly mayReturnObject?: boolean;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* A function entry: `params` is a space-separated list; a trailing `...` marks the last one as a
|
|
342
|
+
* ParamArray. `required` defaults to every parameter but a ParamArray.
|
|
343
|
+
*/
|
|
344
|
+
declare function fn(name: string, runtime: string | null, convention: LibraryConvention, params: string, options?: FunctionOptions): LibraryFunction;
|
|
345
|
+
/** A function with a `$` twin that calls a separate runtime export (`Left`/`Left$`). */
|
|
346
|
+
declare function twin(name: string, runtime: string, runtimeS: string, convention: LibraryConvention, params: string, options?: FunctionOptions): LibraryFunction[];
|
|
347
|
+
/** Every built-in constant: the `vb` enumeration values as `Long`, the text ones as `String`. */
|
|
348
|
+
declare const LIBRARY_CONSTANTS: readonly LibraryConstant[];
|
|
349
|
+
/** Every library function, `$` forms included, as the binder and both executors see them. */
|
|
350
|
+
declare const LIBRARY_FUNCTIONS: readonly LibraryFunction[];
|
|
351
|
+
/** The library entry a name refers to (`Left`, `left$`, `vbCrLf`, `Err`), case-insensitively. */
|
|
352
|
+
declare const libraryEntry: (name: string) => LibraryEntry | undefined;
|
|
353
|
+
/** Every entry, for executors that build a dispatch table up front. */
|
|
354
|
+
declare const libraryEntries: () => IterableIterator<LibraryEntry>;
|
|
355
|
+
/** What a procedure body contains, for executors that pick a simpler path when they can. */
|
|
356
|
+
declare class ProcedureFacts {
|
|
357
|
+
/** Contains `GoTo`. */
|
|
358
|
+
hasGoTo: boolean;
|
|
359
|
+
/** Contains `GoSub`, or `On ... GoSub`. */
|
|
360
|
+
hasGoSub: boolean;
|
|
361
|
+
/** Contains `On ... GoTo` or `On ... GoSub`. */
|
|
362
|
+
hasOnGoTo: boolean;
|
|
363
|
+
/** Contains an `On Error` statement. */
|
|
364
|
+
hasOnError: boolean;
|
|
365
|
+
/** Contains a `Resume` statement. */
|
|
366
|
+
hasResume: boolean;
|
|
367
|
+
/** Has a line-number label (`10 x = 1`), which `Erl` reports. */
|
|
368
|
+
hasLineNumbers: boolean;
|
|
369
|
+
/** Contains `End` or `Stop`. */
|
|
370
|
+
hasEnd: boolean;
|
|
371
|
+
/** Calls a procedure of the project. */
|
|
372
|
+
readonly callees: Set<BoundProcedure>;
|
|
373
|
+
/** The library functions it calls. */
|
|
374
|
+
readonly library: Set<LibraryFunction>;
|
|
375
|
+
/**
|
|
376
|
+
* Touches something that may answer asynchronously: a host object, a run-time member, an
|
|
377
|
+
* asynchronous library function or an event. A procedure whose transitive callees are all free
|
|
378
|
+
* of it can run synchronously.
|
|
379
|
+
*/
|
|
380
|
+
dynamic: boolean;
|
|
381
|
+
/**
|
|
382
|
+
* Writes storage another activation can see: a module or class field, a ByRef parameter, an
|
|
383
|
+
* object's member, or a host name. Callees are not included (see `callees`). With
|
|
384
|
+
* `usage.written` of a parameter, this tells whether a ByRef argument can be read-only.
|
|
385
|
+
*/
|
|
386
|
+
writesShared: boolean;
|
|
387
|
+
/** Raises an event (`RaiseEvent`). */
|
|
388
|
+
raisesEvents: boolean;
|
|
389
|
+
/**
|
|
390
|
+
* Evaluates an expression that may run code implicitly (`BoundProgram.mayCallDefault`): an
|
|
391
|
+
* object's default member or enumerator. The default member of a class-typed operand is also
|
|
392
|
+
* in `callees`.
|
|
393
|
+
*/
|
|
394
|
+
implicitCalls: boolean;
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* One procedure of a bound module (each Property accessor is its own procedure), with its
|
|
398
|
+
* symbols, frame layout, labels and `With` blocks.
|
|
399
|
+
*/
|
|
400
|
+
declare class BoundProcedure {
|
|
401
|
+
/** A number unique among the program's symbols and procedures. */
|
|
402
|
+
readonly id: number;
|
|
403
|
+
/** The module that declares it. */
|
|
404
|
+
readonly module: BoundModule;
|
|
405
|
+
/** The procedure's AST node. */
|
|
406
|
+
readonly declaration: ProcedureDeclaration;
|
|
407
|
+
/** The declared return type of a Function or Property Get; null for Sub/Let/Set. */
|
|
408
|
+
readonly returnType: StaticType | null;
|
|
409
|
+
/** Parameters in order; parameter i is frame slot i. */
|
|
410
|
+
readonly params: ParamSymbol[];
|
|
411
|
+
/** The return value of a Function or Property Get (frame slot `params.length`), else null. */
|
|
412
|
+
result: VariableSymbol | null;
|
|
413
|
+
/** `Dim` and implicit locals: frame slots from `params.length + 1`. */
|
|
414
|
+
readonly locals: VariableSymbol[];
|
|
415
|
+
/** `Static` locals (and every local of a `Static Sub`): slots of the procedure's static store. */
|
|
416
|
+
readonly statics: VariableSymbol[];
|
|
417
|
+
/** Constants declared inside the procedure. */
|
|
418
|
+
readonly consts: ConstSymbol[];
|
|
419
|
+
/** The `Label` statement that defines each label or line number (lower case). */
|
|
420
|
+
readonly labels: Map<string, LabelStatement>;
|
|
421
|
+
/** `With` blocks by id (the index here). */
|
|
422
|
+
readonly withBlocks: WithBlock[];
|
|
423
|
+
/** What the body contains. */
|
|
424
|
+
readonly facts: ProcedureFacts;
|
|
425
|
+
constructor(
|
|
426
|
+
/** A number unique among the program's symbols and procedures. */
|
|
427
|
+
id: number,
|
|
428
|
+
/** The module that declares it. */
|
|
429
|
+
module: BoundModule,
|
|
430
|
+
/** The procedure's AST node. */
|
|
431
|
+
declaration: ProcedureDeclaration,
|
|
432
|
+
/** The declared return type of a Function or Property Get; null for Sub/Let/Set. */
|
|
433
|
+
returnType: StaticType | null);
|
|
434
|
+
/** The procedure name, as declared. */
|
|
435
|
+
get name(): string;
|
|
436
|
+
/** `Sub`, `Function`, `PropertyGet`, `PropertyLet` or `PropertySet`. */
|
|
437
|
+
get kind(): ProcedureKind;
|
|
438
|
+
/** Callable from other modules by early binding: Public or Friend. */
|
|
439
|
+
get isPublic(): boolean;
|
|
440
|
+
/**
|
|
441
|
+
* Who may call it: `public` everyone, `friend` early-bound callers in the project only (late
|
|
442
|
+
* binding through `As Object` raises 438), `private` its own module.
|
|
443
|
+
*/
|
|
444
|
+
get visibility(): 'public' | 'friend' | 'private';
|
|
445
|
+
/** `Module1.Foo`. */
|
|
446
|
+
get qualifiedName(): string;
|
|
447
|
+
/** Frame slots: parameters, the result slot, then locals. */
|
|
448
|
+
get frameSize(): number;
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Everything one name of a module stands for: a Sub or Function (`method`), or the Property
|
|
452
|
+
* Get/Let/Set procedures that share a name. Calls bind to the group; the executor picks the
|
|
453
|
+
* accessor from the context (read, Let assignment, Set assignment).
|
|
454
|
+
*/
|
|
455
|
+
declare class PropertyGroup {
|
|
456
|
+
/** The name, as first declared. */
|
|
457
|
+
readonly name: string;
|
|
458
|
+
/** The module that declares the group. */
|
|
459
|
+
readonly module: BoundModule;
|
|
460
|
+
/** The Sub or Function of this name, if the name is one. */
|
|
461
|
+
method: BoundProcedure | null;
|
|
462
|
+
/** The `Property Get` of this name. */
|
|
463
|
+
get: BoundProcedure | null;
|
|
464
|
+
/** The `Property Let` of this name. */
|
|
465
|
+
let: BoundProcedure | null;
|
|
466
|
+
/** The `Property Set` of this name. */
|
|
467
|
+
set: BoundProcedure | null;
|
|
468
|
+
constructor(
|
|
469
|
+
/** The name, as first declared. */
|
|
470
|
+
name: string,
|
|
471
|
+
/** The module that declares the group. */
|
|
472
|
+
module: BoundModule);
|
|
473
|
+
/** The procedure a read or call uses: the method, else Property Get. */
|
|
474
|
+
get reader(): BoundProcedure | null;
|
|
475
|
+
/** The procedure an access runs: Function or Get to read, Sub (else Get) to call, Let, Set. */
|
|
476
|
+
forAccess(access: 'get' | 'call' | 'let' | 'set'): BoundProcedure | null;
|
|
477
|
+
get any(): BoundProcedure;
|
|
478
|
+
/** True when any member of the group is public. */
|
|
479
|
+
get isPublic(): boolean;
|
|
480
|
+
/**
|
|
481
|
+
* Puts a procedure in its slot. Returns false, and changes nothing, when the slot is taken or
|
|
482
|
+
* the procedure would mix a Sub or Function with Property procedures (a duplicate declaration).
|
|
483
|
+
*/
|
|
484
|
+
add(procedure: BoundProcedure): boolean;
|
|
485
|
+
}
|
|
486
|
+
/** The `Option` statements of a module, with VBA's defaults for those not written. */
|
|
487
|
+
interface ModuleOptions {
|
|
488
|
+
/** `Option Base` (0 or 1): the default lower bound of arrays declared without one. */
|
|
489
|
+
readonly base: 0 | 1;
|
|
490
|
+
/** `Option Compare Text`. */
|
|
491
|
+
readonly compareText: boolean;
|
|
492
|
+
/** `Option Explicit`: every variable must be declared. */
|
|
493
|
+
readonly explicit: boolean;
|
|
494
|
+
/** `Option Private Module`: public members are not visible outside the project. */
|
|
495
|
+
readonly privateModule: boolean;
|
|
496
|
+
}
|
|
497
|
+
/** A module-level name: what `ModuleScope` finds for it. */
|
|
498
|
+
type ModuleMemberSymbol = VariableSymbol | ConstSymbol | EnumSymbol | EnumMemberSymbol | DeclareSymbol | PropertyGroup;
|
|
499
|
+
/**
|
|
500
|
+
* One module of a bound program: its options, module-level symbols and procedures, and for class
|
|
501
|
+
* and document modules the shape other code sees (default member, events, interfaces).
|
|
502
|
+
*/
|
|
503
|
+
declare class BoundModule {
|
|
504
|
+
/** The module name the host gave. */
|
|
505
|
+
readonly name: string;
|
|
506
|
+
/** Standard, class, document or form module. */
|
|
507
|
+
readonly kind: ModuleKind;
|
|
508
|
+
/** The parsed module. */
|
|
509
|
+
readonly ast: ModuleNode;
|
|
510
|
+
/** The module's `Option` statements. */
|
|
511
|
+
options: ModuleOptions;
|
|
512
|
+
/** Module variables (`scope` module) or class instance variables (`scope` instance), by slot. */
|
|
513
|
+
readonly variables: VariableSymbol[];
|
|
514
|
+
/** Module constants, in an order where each comes after the constants its value uses. */
|
|
515
|
+
readonly consts: ConstSymbol[];
|
|
516
|
+
/** `Enum` declarations, in source order. */
|
|
517
|
+
readonly enums: EnumSymbol[];
|
|
518
|
+
/** `Type` declarations (user-defined types), in source order. */
|
|
519
|
+
readonly udts: UdtSymbol[];
|
|
520
|
+
/** `Event` declarations of a class module, in source order. */
|
|
521
|
+
readonly events: EventSymbol[];
|
|
522
|
+
/** `Declare` statements (external procedures), in source order. */
|
|
523
|
+
readonly declares: DeclareSymbol[];
|
|
524
|
+
/** Every procedure (each Property accessor separately), in source order. */
|
|
525
|
+
readonly procedures: BoundProcedure[];
|
|
526
|
+
/** Procedures by lower-case name. */
|
|
527
|
+
readonly groups: Map<string, PropertyGroup>;
|
|
528
|
+
/** Every module-level name (lower case). */
|
|
529
|
+
readonly members: Map<string, ModuleMemberSymbol>;
|
|
530
|
+
/** `DefInt A-Z` and friends: the type of each letter (lower case). */
|
|
531
|
+
readonly defTypes: Map<string, ScalarTypeName>;
|
|
532
|
+
/** Class modules named by `Implements`. */
|
|
533
|
+
readonly implements: BoundModule[];
|
|
534
|
+
/** The member with `VB_UserMemId = 0` (class modules). */
|
|
535
|
+
defaultMember: PropertyGroup | null;
|
|
536
|
+
/** The member with `VB_UserMemId = -4` (`For Each` over an instance). */
|
|
537
|
+
newEnum: PropertyGroup | null;
|
|
538
|
+
/** `VB_PredeclaredId = True`: the class has a default instance named like the class. */
|
|
539
|
+
predeclared: boolean;
|
|
540
|
+
/** Handlers of `WithEvents` variables: the Sub for each variable and event (lower case). */
|
|
541
|
+
readonly eventHandlers: Map<string, Map<string, BoundProcedure>>;
|
|
542
|
+
/** True when a compile error was found in this module; it cannot run. */
|
|
543
|
+
hasErrors: boolean;
|
|
544
|
+
constructor(
|
|
545
|
+
/** The module name the host gave. */
|
|
546
|
+
name: string,
|
|
547
|
+
/** Standard, class, document or form module. */
|
|
548
|
+
kind: ModuleKind,
|
|
549
|
+
/** The parsed module. */
|
|
550
|
+
ast: ModuleNode);
|
|
551
|
+
/** The Sub that handles `<prefix>_<event>` (a document module's `Workbook_Open`). */
|
|
552
|
+
handler(prefix: string, event: string): BoundProcedure | null;
|
|
553
|
+
/** True for modules whose variables live per object (class and form modules). */
|
|
554
|
+
get perInstance(): boolean;
|
|
555
|
+
/** True for modules whose code runs with a `Me` (class, form and document modules). */
|
|
556
|
+
get hasMe(): boolean;
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* What a name, `Me`, member access, `!` access or call refers to. Every variant has a `kind`
|
|
560
|
+
* discriminant; `symbol`, `entry` and `module` name the declaration it resolved to.
|
|
561
|
+
*/
|
|
562
|
+
type Binding =
|
|
563
|
+
/** A local, Static local, module or class-instance variable (also another module's Public one). */
|
|
564
|
+
{
|
|
565
|
+
readonly kind: 'variable';
|
|
566
|
+
readonly symbol: VariableSymbol;
|
|
567
|
+
} | {
|
|
568
|
+
readonly kind: 'param';
|
|
569
|
+
readonly symbol: ParamSymbol;
|
|
570
|
+
} |
|
|
571
|
+
/** Inside a Function or Property Get, its own name without arguments: the return value. */
|
|
572
|
+
{
|
|
573
|
+
readonly kind: 'result';
|
|
574
|
+
readonly symbol: VariableSymbol;
|
|
575
|
+
readonly procedure: BoundProcedure;
|
|
576
|
+
} | {
|
|
577
|
+
readonly kind: 'const';
|
|
578
|
+
readonly symbol: ConstSymbol;
|
|
579
|
+
} | {
|
|
580
|
+
readonly kind: 'enumMember';
|
|
581
|
+
readonly symbol: EnumMemberSymbol;
|
|
582
|
+
} |
|
|
583
|
+
/** An Enum's name used as a qualifier (`Colors.Red` binds the member access). */
|
|
584
|
+
{
|
|
585
|
+
readonly kind: 'enum';
|
|
586
|
+
readonly symbol: EnumSymbol;
|
|
587
|
+
} |
|
|
588
|
+
/**
|
|
589
|
+
* A procedure of the project: a Sub or Function, or the Property Get/Let/Set group of a name.
|
|
590
|
+
* `receiver` says where `Me` comes from: `none` (standard module), `self` (the caller's own
|
|
591
|
+
* instance, an unqualified call inside a class or document module) or `object` (the member
|
|
592
|
+
* access's object).
|
|
593
|
+
*/
|
|
594
|
+
{
|
|
595
|
+
readonly kind: 'procedure';
|
|
596
|
+
/** The procedures of that name. */
|
|
597
|
+
readonly group: PropertyGroup;
|
|
598
|
+
/** Where `Me` comes from, as described above. */
|
|
599
|
+
readonly receiver: 'none' | 'self' | 'object';
|
|
600
|
+
} | {
|
|
601
|
+
readonly kind: 'declare';
|
|
602
|
+
readonly symbol: DeclareSymbol;
|
|
603
|
+
} | {
|
|
604
|
+
readonly kind: 'libraryFunction';
|
|
605
|
+
readonly entry: LibraryFunction;
|
|
606
|
+
} | {
|
|
607
|
+
readonly kind: 'libraryConstant';
|
|
608
|
+
readonly entry: LibraryConstant;
|
|
609
|
+
} |
|
|
610
|
+
/** `Err`, `Debug` or the `VBA` qualifier. */
|
|
611
|
+
{
|
|
612
|
+
readonly kind: 'libraryObject';
|
|
613
|
+
readonly entry: LibraryObject;
|
|
614
|
+
} |
|
|
615
|
+
/** A module name used as a qualifier (`Module2.Foo`). */
|
|
616
|
+
{
|
|
617
|
+
readonly kind: 'module';
|
|
618
|
+
readonly module: BoundModule;
|
|
619
|
+
} |
|
|
620
|
+
/** A class module's name in `New`, `TypeOf`, `As` (the class itself, not an instance). */
|
|
621
|
+
{
|
|
622
|
+
readonly kind: 'class';
|
|
623
|
+
readonly module: BoundModule;
|
|
624
|
+
} |
|
|
625
|
+
/** A host object from `options.globals` (`Application`, `ThisWorkbook`). */
|
|
626
|
+
{
|
|
627
|
+
readonly kind: 'hostGlobal';
|
|
628
|
+
readonly name: string;
|
|
629
|
+
} |
|
|
630
|
+
/** A document module's name: the host object it extends (`Sheet1.Range(...)`, `ThisWorkbook.Foo`). */
|
|
631
|
+
{
|
|
632
|
+
readonly kind: 'documentObject';
|
|
633
|
+
readonly module: BoundModule;
|
|
634
|
+
} |
|
|
635
|
+
/** `Me`: the class instance, or the host object of a document module. */
|
|
636
|
+
{
|
|
637
|
+
readonly kind: 'me';
|
|
638
|
+
readonly module: BoundModule;
|
|
639
|
+
} |
|
|
640
|
+
/**
|
|
641
|
+
* A name declared nowhere, resolved at run time: first a member of the document module's host
|
|
642
|
+
* object (in a document module), then a member of `options.globalObject`; a 438 from both means
|
|
643
|
+
* the implicit local `fallback` (Empty until assigned), or error "Variable not defined" when
|
|
644
|
+
* `fallback` is null (Option Explicit).
|
|
645
|
+
*/
|
|
646
|
+
{
|
|
647
|
+
readonly kind: 'dynamic';
|
|
648
|
+
/** The name as written. */
|
|
649
|
+
readonly name: string;
|
|
650
|
+
/** Whether the document module's host object is searched first. */
|
|
651
|
+
readonly document: boolean;
|
|
652
|
+
/** The implicit local used when no object has the name; null under Option Explicit. */
|
|
653
|
+
readonly fallback: VariableSymbol | null;
|
|
654
|
+
} |
|
|
655
|
+
/** An implicitly declared local (no Option Explicit, no dynamic scope). */
|
|
656
|
+
{
|
|
657
|
+
readonly kind: 'implicit';
|
|
658
|
+
readonly symbol: VariableSymbol;
|
|
659
|
+
} |
|
|
660
|
+
/** A member of an object only known at run time (`obj.Name`, `rng.Value`, `col!key`). */
|
|
661
|
+
{
|
|
662
|
+
readonly kind: 'member';
|
|
663
|
+
/** The member name as written. */
|
|
664
|
+
readonly name: string;
|
|
665
|
+
/** The static type of the object expression. */
|
|
666
|
+
readonly objectType: StaticType;
|
|
667
|
+
/** `obj!key`: the default member called with the key as a String. */
|
|
668
|
+
readonly dictionary: boolean;
|
|
669
|
+
} |
|
|
670
|
+
/** A field of a UDT value (`p.X`, `arr(1).Name`). */
|
|
671
|
+
{
|
|
672
|
+
readonly kind: 'udtField';
|
|
673
|
+
readonly field: UdtFieldSymbol;
|
|
674
|
+
readonly index: number;
|
|
675
|
+
} |
|
|
676
|
+
/** A member of the `Err` object (`Err.Number`, `Err.Raise`). */
|
|
677
|
+
{
|
|
678
|
+
readonly kind: 'errMember';
|
|
679
|
+
readonly name: string;
|
|
680
|
+
} |
|
|
681
|
+
/** `Debug.Assert`, `Debug.Print` called as a method. */
|
|
682
|
+
{
|
|
683
|
+
readonly kind: 'debugMember';
|
|
684
|
+
readonly name: string;
|
|
685
|
+
} |
|
|
686
|
+
/** Could not be bound; a diagnostic was reported. Executing it raises the diagnostic's error. */
|
|
687
|
+
{
|
|
688
|
+
readonly kind: 'unresolved';
|
|
689
|
+
readonly name: string;
|
|
690
|
+
readonly number: number;
|
|
691
|
+
};
|
|
692
|
+
/** How one argument reaches the parameter it is matched to. */
|
|
693
|
+
type ArgumentPassing =
|
|
694
|
+
/** A reference to the caller's variable, element or field: the callee's writes reach it. */
|
|
695
|
+
'ref' |
|
|
696
|
+
/** A ByRef parameter given an expression, a property or a parenthesised variable: a temporary. */
|
|
697
|
+
'temp' |
|
|
698
|
+
/** A ByVal parameter: the value. */
|
|
699
|
+
'value';
|
|
700
|
+
/** One argument of a call, matched to its parameter. */
|
|
701
|
+
interface BoundArgument {
|
|
702
|
+
/** The argument expression; null when the optional parameter was omitted. */
|
|
703
|
+
readonly expression: Expression | null;
|
|
704
|
+
/** How the argument reaches the parameter. */
|
|
705
|
+
readonly passing: ArgumentPassing;
|
|
706
|
+
}
|
|
707
|
+
/**
|
|
708
|
+
* Arguments matched to a compiled procedure's or library function's parameters: `params[i]` is
|
|
709
|
+
* the argument for parameter i (named arguments placed, omitted optionals null), `rest` the
|
|
710
|
+
* ParamArray tail.
|
|
711
|
+
*/
|
|
712
|
+
interface CallSite {
|
|
713
|
+
/** One entry per declared parameter (ParamArray excluded): the argument, or null if omitted. */
|
|
714
|
+
readonly params: readonly (BoundArgument | null)[];
|
|
715
|
+
/** The ParamArray tail; null where an argument was omitted (`F(1, , 3)`: Missing). */
|
|
716
|
+
readonly rest: readonly (Expression | null)[];
|
|
717
|
+
}
|
|
718
|
+
/**
|
|
719
|
+
* What a `CallOrIndex` node or a call statement does:
|
|
720
|
+
* - `call`: a compiled procedure (with `site`) or a `Declare` (refused at run time);
|
|
721
|
+
* - `library`: a library function (with `site`);
|
|
722
|
+
* - `index`: an element of an array known statically (`a(1)` where `a` is declared as an array);
|
|
723
|
+
* - `dynamic`: decided at run time: an array element when the value is an array, else the default
|
|
724
|
+
* member of the object called with the arguments (Variants, objects, the result of a call);
|
|
725
|
+
* - `member`: a method or indexed property of a run-time object (`obj.Item(1)`, `col.Add x`).
|
|
726
|
+
*/
|
|
727
|
+
type Invocation = {
|
|
728
|
+
readonly kind: 'call';
|
|
729
|
+
/** The procedures called. */
|
|
730
|
+
readonly group: PropertyGroup;
|
|
731
|
+
/** The arguments, matched to the parameters. */
|
|
732
|
+
readonly site: CallSite;
|
|
733
|
+
/**
|
|
734
|
+
* The procedure takes no arguments but was given some (`Items(1)` with `Property Get
|
|
735
|
+
* Items()`): call it with none, then index its result (an array element or the default
|
|
736
|
+
* member) with the arguments, which are bound as values.
|
|
737
|
+
*/
|
|
738
|
+
readonly indexResult?: boolean;
|
|
739
|
+
} | {
|
|
740
|
+
readonly kind: 'declare';
|
|
741
|
+
readonly symbol: DeclareSymbol;
|
|
742
|
+
} | {
|
|
743
|
+
readonly kind: 'library';
|
|
744
|
+
readonly entry: LibraryFunction;
|
|
745
|
+
readonly site: CallSite;
|
|
746
|
+
/**
|
|
747
|
+
* `Len`/`LenB` of a variable declared with a non-String scalar type: the VT whose size
|
|
748
|
+
* in bytes the call returns (`lenOfType` of the runtime) instead of the text's length.
|
|
749
|
+
*/
|
|
750
|
+
readonly typedLength?: number;
|
|
751
|
+
/**
|
|
752
|
+
* A `conversion` (CDate, CLng, ...) whose argument is a literal, a constant or of a declared
|
|
753
|
+
* non-Variant type: pass `typed` true to the runtime export (out of range raises 6, not 13).
|
|
754
|
+
*/
|
|
755
|
+
readonly typedArgument?: boolean;
|
|
756
|
+
} | {
|
|
757
|
+
readonly kind: 'index';
|
|
758
|
+
readonly elementType: StaticType;
|
|
759
|
+
} | {
|
|
760
|
+
readonly kind: 'dynamic';
|
|
761
|
+
} | {
|
|
762
|
+
readonly kind: 'member';
|
|
763
|
+
readonly name: string;
|
|
764
|
+
};
|
|
765
|
+
/** A `With` block: its id (unique in the procedure), depth and the static type of its subject. */
|
|
766
|
+
interface WithBlock {
|
|
767
|
+
/** Its index in the procedure's `withBlocks`. */
|
|
768
|
+
readonly id: number;
|
|
769
|
+
/** How many `With` blocks enclose it: 0 for an outermost one. */
|
|
770
|
+
readonly depth: number;
|
|
771
|
+
/** The `With` statement. */
|
|
772
|
+
readonly statement: WithStatement;
|
|
773
|
+
/** The static type of the `With` object. */
|
|
774
|
+
readonly subjectType: StaticType;
|
|
775
|
+
}
|
|
776
|
+
/** The compile errors the binder reports. `SEMANTIC_MESSAGES` gives each one's wording. */
|
|
777
|
+
type SemanticDiagnosticCode = 'variable-not-defined' | 'sub-or-function-not-defined' | 'duplicate-declaration' | 'ambiguous-name' | 'label-not-defined' | 'byref-argument-type-mismatch' | 'wrong-number-of-arguments' | 'argument-not-optional' | 'named-argument-not-found' | 'invalid-use-of-me' | 'user-defined-type-not-defined' | 'method-or-data-member-not-found' | 'expected-array' | 'invalid-qualifier' | 'constant-expression-required' | 'declare-not-supported' | 'exit-not-allowed' | 'exit-not-in-loop' | 'only-valid-in-object-module';
|
|
778
|
+
/** The message VBA's editor shows for each code. */
|
|
779
|
+
declare const SEMANTIC_MESSAGES: Readonly<Record<SemanticDiagnosticCode, string>>;
|
|
780
|
+
/** The runtime error an executor raises if it reaches code with this compile error. */
|
|
781
|
+
declare const SEMANTIC_ERROR_NUMBERS: Readonly<Partial<Record<SemanticDiagnosticCode, number>>>;
|
|
782
|
+
/** A diagnostic of the bound program: a parse diagnostic or a semantic one, with its module. */
|
|
783
|
+
interface BoundDiagnostic {
|
|
784
|
+
/** The name of the module it was found in. */
|
|
785
|
+
readonly module: string;
|
|
786
|
+
/** The parser's or the binder's code. */
|
|
787
|
+
readonly code: VbaDiagnostic['code'] | SemanticDiagnosticCode;
|
|
788
|
+
/** The message, in the VBA editor's wording for binder codes. */
|
|
789
|
+
readonly message: string;
|
|
790
|
+
/** An error stops the module from running; a warning does not. */
|
|
791
|
+
readonly severity: 'error' | 'warning';
|
|
792
|
+
/** The source the problem covers. */
|
|
793
|
+
readonly span: Span;
|
|
794
|
+
}
|
|
795
|
+
/** The side tables the binder fills; one per program. */
|
|
796
|
+
declare class BindingTable {
|
|
797
|
+
/** What each name, `Me`, member access, `!` access or call refers to. */
|
|
798
|
+
readonly bindings: Map<Expression, Binding>;
|
|
799
|
+
/** What each call, index or call statement does. */
|
|
800
|
+
readonly invocations: Map<Expression | Statement, Invocation>;
|
|
801
|
+
/** The `With` block of each `.member` or `!key` written without an object. */
|
|
802
|
+
readonly withRefs: Map<Expression, WithBlock>;
|
|
803
|
+
/** The static type of each expression the binder could type. */
|
|
804
|
+
readonly types: Map<Expression, StaticType>;
|
|
805
|
+
/** Values used as objects (Set, Is, a Variant or Object argument): no default member is read. */
|
|
806
|
+
readonly objectUses: Set<Expression>;
|
|
807
|
+
}
|
|
808
|
+
/**
|
|
809
|
+
* A bound project: what `bindProgram` returns. It holds the bound modules and the compile
|
|
810
|
+
* diagnostics, and answers, for any AST node of the project, what the binder decided about it.
|
|
811
|
+
*/
|
|
812
|
+
declare class BoundProgram {
|
|
813
|
+
/** The modules, in the order they were given to `bindProgram`. */
|
|
814
|
+
readonly modules: readonly BoundModule[];
|
|
815
|
+
/** Parse and compile diagnostics of every module. */
|
|
816
|
+
readonly diagnostics: readonly BoundDiagnostic[];
|
|
817
|
+
private readonly table;
|
|
818
|
+
private readonly byName;
|
|
819
|
+
constructor(
|
|
820
|
+
/** The modules, in the order they were given to `bindProgram`. */
|
|
821
|
+
modules: readonly BoundModule[],
|
|
822
|
+
/** Parse and compile diagnostics of every module. */
|
|
823
|
+
diagnostics: readonly BoundDiagnostic[], table: BindingTable);
|
|
824
|
+
/** The module with this name, compared case-insensitively. */
|
|
825
|
+
module(name: string): BoundModule | undefined;
|
|
826
|
+
/**
|
|
827
|
+
* Whether evaluating `e` for its value may run code implicitly: read an object's default member
|
|
828
|
+
* (a Variant, Object or class-typed operand of an operator, a Let, Print, a conversion, an
|
|
829
|
+
* index), or enumerate it (`For Each`). False for literals, typed scalars, and values passed on
|
|
830
|
+
* as objects (Set, Is, TypeOf, a Variant or Object argument). Conservative: true may still not
|
|
831
|
+
* call anything.
|
|
832
|
+
*/
|
|
833
|
+
mayCallDefault(e: Expression): boolean;
|
|
834
|
+
/** What a `Name`, `Me`, `MemberAccess`, `DictionaryAccess` or `CallOrIndex` refers to. */
|
|
835
|
+
binding(node: Expression): Binding | undefined;
|
|
836
|
+
/** What a `CallOrIndex` or call statement does. */
|
|
837
|
+
invocation(node: Expression | Statement): Invocation | undefined;
|
|
838
|
+
/** The `With` block a `.member` or `!key` with no object refers to. */
|
|
839
|
+
withBlock(node: Expression): WithBlock | undefined;
|
|
840
|
+
/** The static type of an expression (Variant when nothing is known). */
|
|
841
|
+
typeOf(node: Expression): StaticType;
|
|
842
|
+
/** Whether a comparison operand counts as declared (typed); see `isTypedOperand`. */
|
|
843
|
+
isTypedOperand(node: Expression): boolean;
|
|
844
|
+
/**
|
|
845
|
+
* Finds a procedure group by `Module.Name` or by an unambiguous `Name` among the standard
|
|
846
|
+
* modules (as `Application.Run` does). Private procedures are found when qualified.
|
|
847
|
+
*/
|
|
848
|
+
findGroup(name: string): PropertyGroup | 'ambiguous' | undefined;
|
|
849
|
+
/** Every bound procedure of every module. */
|
|
850
|
+
procedures(): IterableIterator<BoundProcedure>;
|
|
851
|
+
/** True when any module has a compile error. */
|
|
852
|
+
get hasErrors(): boolean;
|
|
853
|
+
}
|
|
854
|
+
/** One module of the project as source text. */
|
|
855
|
+
interface SourceModuleInput {
|
|
856
|
+
/** The module name. */
|
|
857
|
+
readonly name: string;
|
|
858
|
+
/** Standard, class, document or form module. */
|
|
859
|
+
readonly kind: ModuleKind;
|
|
860
|
+
/** The module's source text. */
|
|
861
|
+
readonly source: string;
|
|
862
|
+
}
|
|
863
|
+
/** What `bindProgram` needs to know about the host and the parser. */
|
|
864
|
+
interface BindOptions {
|
|
865
|
+
/** `#Const` values for conditional compilation. */
|
|
866
|
+
readonly constants?: ParseOptions['constants'];
|
|
867
|
+
/** Names of the host's global objects (`Application`, `ThisWorkbook`). */
|
|
868
|
+
readonly globals?: Iterable<string>;
|
|
869
|
+
/** True when the host gives a global object whose members resolve unqualified. */
|
|
870
|
+
readonly globalObject?: boolean;
|
|
871
|
+
/** Names of document modules that have a host object. */
|
|
872
|
+
readonly documentObjects?: Iterable<string>;
|
|
873
|
+
/** Parser limits and the current year for date literals without one. */
|
|
874
|
+
readonly parse?: Pick<ParseOptions, 'limits' | 'currentYear'>;
|
|
875
|
+
}
|
|
876
|
+
/** Binds a project: every module, every name, call and `With` member. Never throws on bad code. */
|
|
877
|
+
declare function bindProgram(inputs: readonly SourceModuleInput[], options?: BindOptions): BoundProgram;
|
|
878
|
+
/** The two lookups the facts read (a `BoundProgram`). */
|
|
879
|
+
interface BoundLookup {
|
|
880
|
+
binding(node: Expression): Binding | undefined;
|
|
881
|
+
typeOf(node: Expression): StaticType;
|
|
882
|
+
}
|
|
883
|
+
/**
|
|
884
|
+
* Whether an operand counts as declared (typed) for comparisons ([MS-VBAL] 5.6.9.8.1): a variable,
|
|
885
|
+
* parameter or function result declared with a type other than Variant. Literals and constants do
|
|
886
|
+
* not: Excel compares `v < "9a"` (v holding 9) as a number against a string, without converting.
|
|
887
|
+
* A Boolean literal does count: `"True" = True` converts the string and is True in Excel.
|
|
888
|
+
*/
|
|
889
|
+
declare function isTypedOperand(model: BoundLookup, e: Expression): boolean;
|
|
890
|
+
/**
|
|
891
|
+
* `Len(v)` / `LenB(v)` of a variable or parameter declared with a scalar type other than String:
|
|
892
|
+
* the VT whose byte size the call returns instead of the length of the text ([MS-VBAL]
|
|
893
|
+
* 6.1.2.11.1.15), else null.
|
|
894
|
+
*/
|
|
895
|
+
declare function typedLengthVt(model: BoundLookup, name: string, argument: Expression | undefined): number | null;
|
|
896
|
+
/** The statement lists nested in a statement (If branches, loop bodies, Case bodies). */
|
|
897
|
+
declare function nestedBodies(s: Statement): (readonly Statement[])[];
|
|
898
|
+
/** Visits every statement of a body, nested ones included, in source order. */
|
|
899
|
+
declare function forEachStatement(body: readonly Statement[], visit: (s: Statement) => void): void;
|
|
900
|
+
export { DeclareSymbol as $, LIBRARY_CONSTANTS as A, OBJECT as B, ModuleOptions as C, libraryEntries as D, PropertyGroup as E, LibraryFunction as F, UdtType as G, ScalarType as H, LibraryObject as I, isVariant as J, VARIANT as K, fn as L, LibraryConstant as M, LibraryConvention as N, libraryEntry as O, LibraryEntry as P, ConstSymbol as Q, twin as R, ModuleMemberSymbol as S, ProcedureFacts as T, ScalarTypeName as U, ObjectType as V, StaticType as W, storageVt as X, scalarType as Y, vtOfScalar as Z, BoundArgument as _, typedLengthVt as a, UdtSymbol as at, WithBlock as b, bindProgram as c, VariableSymbol as ct, BoundDiagnostic as d, EnumMemberSymbol as et, SEMANTIC_ERROR_NUMBERS as f, Binding as g, ArgumentPassing as h, isTypedOperand as i, UdtFieldSymbol as it, FunctionOptions as j, LIBRARY_FUNCTIONS as k, BindingTable as l, SemanticDiagnosticCode as m, nestedBodies as n, EventSymbol as nt, BindOptions as o, UsageFacts as ot, SEMANTIC_MESSAGES as p, VariantType as q, BoundLookup as r, ParamSymbol as rt, SourceModuleInput as s, VariableScope as st, forEachStatement as t, EnumSymbol as tt, BoundProgram as u, CallSite as v, BoundProcedure as w, BoundModule as x, Invocation as y, ArrayType as z };
|