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,2877 @@
|
|
|
1
|
+
import { a as parseModule, t as forEachChild } from "./lang-Bo63dJb9.js";
|
|
2
|
+
// src/semantic/procedure.ts
|
|
3
|
+
/** What a procedure body contains, for executors that pick a simpler path when they can. */
|
|
4
|
+
var ProcedureFacts = class {
|
|
5
|
+
/** Contains `GoTo`. */
|
|
6
|
+
hasGoTo = false;
|
|
7
|
+
/** Contains `GoSub`, or `On ... GoSub`. */
|
|
8
|
+
hasGoSub = false;
|
|
9
|
+
/** Contains `On ... GoTo` or `On ... GoSub`. */
|
|
10
|
+
hasOnGoTo = false;
|
|
11
|
+
/** Contains an `On Error` statement. */
|
|
12
|
+
hasOnError = false;
|
|
13
|
+
/** Contains a `Resume` statement. */
|
|
14
|
+
hasResume = false;
|
|
15
|
+
/** Has a line-number label (`10 x = 1`), which `Erl` reports. */
|
|
16
|
+
hasLineNumbers = false;
|
|
17
|
+
/** Contains `End` or `Stop`. */
|
|
18
|
+
hasEnd = false;
|
|
19
|
+
/** Calls a procedure of the project. */
|
|
20
|
+
callees = /* @__PURE__ */ new Set();
|
|
21
|
+
/** The library functions it calls. */
|
|
22
|
+
library = /* @__PURE__ */ new Set();
|
|
23
|
+
/**
|
|
24
|
+
* Touches something that may answer asynchronously: a host object, a run-time member, an
|
|
25
|
+
* asynchronous library function or an event. A procedure whose transitive callees are all free
|
|
26
|
+
* of it can run synchronously.
|
|
27
|
+
*/
|
|
28
|
+
dynamic = false;
|
|
29
|
+
/**
|
|
30
|
+
* Writes storage another activation can see: a module or class field, a ByRef parameter, an
|
|
31
|
+
* object's member, or a host name. Callees are not included (see `callees`). With
|
|
32
|
+
* `usage.written` of a parameter, this tells whether a ByRef argument can be read-only.
|
|
33
|
+
*/
|
|
34
|
+
writesShared = false;
|
|
35
|
+
/** Raises an event (`RaiseEvent`). */
|
|
36
|
+
raisesEvents = false;
|
|
37
|
+
/**
|
|
38
|
+
* Evaluates an expression that may run code implicitly (`BoundProgram.mayCallDefault`): an
|
|
39
|
+
* object's default member or enumerator. The default member of a class-typed operand is also
|
|
40
|
+
* in `callees`.
|
|
41
|
+
*/
|
|
42
|
+
implicitCalls = false;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* One procedure of a bound module (each Property accessor is its own procedure), with its
|
|
46
|
+
* symbols, frame layout, labels and `With` blocks.
|
|
47
|
+
*/
|
|
48
|
+
var BoundProcedure = class {
|
|
49
|
+
id;
|
|
50
|
+
module;
|
|
51
|
+
declaration;
|
|
52
|
+
returnType;
|
|
53
|
+
/** Parameters in order; parameter i is frame slot i. */
|
|
54
|
+
params = [];
|
|
55
|
+
/** The return value of a Function or Property Get (frame slot `params.length`), else null. */
|
|
56
|
+
result = null;
|
|
57
|
+
/** `Dim` and implicit locals: frame slots from `params.length + 1`. */
|
|
58
|
+
locals = [];
|
|
59
|
+
/** `Static` locals (and every local of a `Static Sub`): slots of the procedure's static store. */
|
|
60
|
+
statics = [];
|
|
61
|
+
/** Constants declared inside the procedure. */
|
|
62
|
+
consts = [];
|
|
63
|
+
/** The `Label` statement that defines each label or line number (lower case). */
|
|
64
|
+
labels = /* @__PURE__ */ new Map();
|
|
65
|
+
/** `With` blocks by id (the index here). */
|
|
66
|
+
withBlocks = [];
|
|
67
|
+
/** What the body contains. */
|
|
68
|
+
facts = new ProcedureFacts();
|
|
69
|
+
constructor(id, module, declaration, returnType) {
|
|
70
|
+
this.id = id;
|
|
71
|
+
this.module = module;
|
|
72
|
+
this.declaration = declaration;
|
|
73
|
+
this.returnType = returnType;
|
|
74
|
+
}
|
|
75
|
+
/** The procedure name, as declared. */
|
|
76
|
+
get name() {
|
|
77
|
+
return this.declaration.name.name;
|
|
78
|
+
}
|
|
79
|
+
/** `Sub`, `Function`, `PropertyGet`, `PropertyLet` or `PropertySet`. */
|
|
80
|
+
get kind() {
|
|
81
|
+
return this.declaration.procedureKind;
|
|
82
|
+
}
|
|
83
|
+
/** Callable from other modules by early binding: Public or Friend. */
|
|
84
|
+
get isPublic() {
|
|
85
|
+
return this.declaration.scope !== "Private";
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Who may call it: `public` everyone, `friend` early-bound callers in the project only (late
|
|
89
|
+
* binding through `As Object` raises 438), `private` its own module.
|
|
90
|
+
*/
|
|
91
|
+
get visibility() {
|
|
92
|
+
const scope = this.declaration.scope;
|
|
93
|
+
return scope === "Private" ? "private" : scope === "Friend" ? "friend" : "public";
|
|
94
|
+
}
|
|
95
|
+
/** `Module1.Foo`. */
|
|
96
|
+
get qualifiedName() {
|
|
97
|
+
return `${this.module.name}.${this.name}`;
|
|
98
|
+
}
|
|
99
|
+
/** Frame slots: parameters, the result slot, then locals. */
|
|
100
|
+
get frameSize() {
|
|
101
|
+
return this.params.length + 1 + this.locals.length;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Everything one name of a module stands for: a Sub or Function (`method`), or the Property
|
|
106
|
+
* Get/Let/Set procedures that share a name. Calls bind to the group; the executor picks the
|
|
107
|
+
* accessor from the context (read, Let assignment, Set assignment).
|
|
108
|
+
*/
|
|
109
|
+
var PropertyGroup = class {
|
|
110
|
+
name;
|
|
111
|
+
module;
|
|
112
|
+
/** The Sub or Function of this name, if the name is one. */
|
|
113
|
+
method = null;
|
|
114
|
+
/** The `Property Get` of this name. */
|
|
115
|
+
get = null;
|
|
116
|
+
/** The `Property Let` of this name. */
|
|
117
|
+
let = null;
|
|
118
|
+
/** The `Property Set` of this name. */
|
|
119
|
+
set = null;
|
|
120
|
+
constructor(name, module) {
|
|
121
|
+
this.name = name;
|
|
122
|
+
this.module = module;
|
|
123
|
+
}
|
|
124
|
+
/** The procedure a read or call uses: the method, else Property Get. */
|
|
125
|
+
get reader() {
|
|
126
|
+
return this.method ?? this.get;
|
|
127
|
+
}
|
|
128
|
+
/** The procedure an access runs: Function or Get to read, Sub (else Get) to call, Let, Set. */
|
|
129
|
+
forAccess(access) {
|
|
130
|
+
switch (access) {
|
|
131
|
+
case "get": return this.reader;
|
|
132
|
+
case "call": return this.method ?? this.get;
|
|
133
|
+
case "let": return this.let;
|
|
134
|
+
case "set": return this.set;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
get any() {
|
|
138
|
+
const p = this.method ?? this.get ?? this.let ?? this.set;
|
|
139
|
+
if (!p) throw new Error(`empty procedure group ${this.name}`);
|
|
140
|
+
return p;
|
|
141
|
+
}
|
|
142
|
+
/** True when any member of the group is public. */
|
|
143
|
+
get isPublic() {
|
|
144
|
+
return [
|
|
145
|
+
this.method,
|
|
146
|
+
this.get,
|
|
147
|
+
this.let,
|
|
148
|
+
this.set
|
|
149
|
+
].some((p) => p !== null && p.isPublic);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Puts a procedure in its slot. Returns false, and changes nothing, when the slot is taken or
|
|
153
|
+
* the procedure would mix a Sub or Function with Property procedures (a duplicate declaration).
|
|
154
|
+
*/
|
|
155
|
+
add(procedure) {
|
|
156
|
+
const slot = procedure.kind === "PropertyGet" ? "get" : procedure.kind === "PropertyLet" ? "let" : procedure.kind === "PropertySet" ? "set" : "method";
|
|
157
|
+
if (this[slot] !== null) return false;
|
|
158
|
+
if (slot === "method" && (this.get || this.let || this.set)) return false;
|
|
159
|
+
if (slot !== "method" && this.method) return false;
|
|
160
|
+
this[slot] = procedure;
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
// src/semantic/symbols.ts
|
|
165
|
+
/** How a variable is used, collected while binding (both executors use it to optimise). */
|
|
166
|
+
var UsageFacts = class {
|
|
167
|
+
/** Read anywhere. */
|
|
168
|
+
read = false;
|
|
169
|
+
/** Assigned with Let (`x = ...`). */
|
|
170
|
+
letWritten = false;
|
|
171
|
+
/** Assigned with Set. */
|
|
172
|
+
setWritten = false;
|
|
173
|
+
/** A For or For Each counter. */
|
|
174
|
+
forCounter = false;
|
|
175
|
+
/** ReDim or Erase target. */
|
|
176
|
+
redimmed = false;
|
|
177
|
+
/** An element or field of it is written (`a(1) = ...`, `u.x = ...`). */
|
|
178
|
+
partWritten = false;
|
|
179
|
+
/** Target of `Mid(x, ...) =`, `LSet` or `RSet`. */
|
|
180
|
+
stringStatement = false;
|
|
181
|
+
/** Passed ByRef (as a variable reference) to a procedure that may write it. */
|
|
182
|
+
passedByRef = false;
|
|
183
|
+
/** True when any of the write facts above is set. */
|
|
184
|
+
get written() {
|
|
185
|
+
return this.letWritten || this.setWritten || this.forCounter || this.redimmed || this.partWritten || this.stringStatement || this.passedByRef;
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
/** Hands out program-wide unique ids. */
|
|
189
|
+
var IdSource = class {
|
|
190
|
+
next = 1;
|
|
191
|
+
take() {
|
|
192
|
+
return this.next++;
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
// src/semantic/types.ts
|
|
196
|
+
const VTS = {
|
|
197
|
+
Boolean: 11,
|
|
198
|
+
Byte: 17,
|
|
199
|
+
Integer: 2,
|
|
200
|
+
Long: 3,
|
|
201
|
+
LongLong: 20,
|
|
202
|
+
LongPtr: 20,
|
|
203
|
+
Single: 4,
|
|
204
|
+
Double: 5,
|
|
205
|
+
Currency: 6,
|
|
206
|
+
Decimal: 14,
|
|
207
|
+
Date: 7,
|
|
208
|
+
String: 8
|
|
209
|
+
};
|
|
210
|
+
/** The Variant type. */
|
|
211
|
+
const VARIANT = Object.freeze({ kind: "variant" });
|
|
212
|
+
/** The plain `Object` type: an object of no known class. */
|
|
213
|
+
const OBJECT = Object.freeze({
|
|
214
|
+
kind: "object",
|
|
215
|
+
className: null,
|
|
216
|
+
classModule: null
|
|
217
|
+
});
|
|
218
|
+
const scalars = /* @__PURE__ */ new Map();
|
|
219
|
+
/** The scalar type of a name (shared instances for the plain types). */
|
|
220
|
+
function scalarType(name, fixedLength = null, enumName = null) {
|
|
221
|
+
if (fixedLength === null && enumName === null) {
|
|
222
|
+
let t = scalars.get(name);
|
|
223
|
+
if (!t) {
|
|
224
|
+
t = Object.freeze({
|
|
225
|
+
kind: "scalar",
|
|
226
|
+
name,
|
|
227
|
+
vt: VTS[name],
|
|
228
|
+
fixedLength,
|
|
229
|
+
enumName
|
|
230
|
+
});
|
|
231
|
+
scalars.set(name, t);
|
|
232
|
+
}
|
|
233
|
+
return t;
|
|
234
|
+
}
|
|
235
|
+
return Object.freeze({
|
|
236
|
+
kind: "scalar",
|
|
237
|
+
name,
|
|
238
|
+
vt: VTS[name],
|
|
239
|
+
fixedLength,
|
|
240
|
+
enumName
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
/** `VarType` number of a scalar type name. */
|
|
244
|
+
const vtOfScalar = (name) => VTS[name];
|
|
245
|
+
/** True when the type is Variant: operators then use VBA's Variant rules (no strict overflow). */
|
|
246
|
+
const isVariant = (t) => t.kind === "variant";
|
|
247
|
+
/**
|
|
248
|
+
* The `VarType` an executor coerces stores to: a scalar's VT, 9 for objects, 36 for UDTs, 12
|
|
249
|
+
* (Variant) for Variants and arrays.
|
|
250
|
+
*/
|
|
251
|
+
function storageVt(t) {
|
|
252
|
+
switch (t.kind) {
|
|
253
|
+
case "scalar": return t.vt;
|
|
254
|
+
case "object": return 9;
|
|
255
|
+
case "udt": return 36;
|
|
256
|
+
default: return 12;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
/** The scalar type names a `DefType` statement or a type suffix maps to. */
|
|
260
|
+
const SUFFIX_TYPES = {
|
|
261
|
+
"%": "Integer",
|
|
262
|
+
"&": "Long",
|
|
263
|
+
"^": "LongLong",
|
|
264
|
+
"!": "Single",
|
|
265
|
+
"#": "Double",
|
|
266
|
+
"@": "Currency",
|
|
267
|
+
$: "String"
|
|
268
|
+
};
|
|
269
|
+
/** Ranks numeric types for the result type of an arithmetic operator ([MS-VBAL] 5.6.9.3). */
|
|
270
|
+
const NUMERIC_RANK = {
|
|
271
|
+
Byte: 1,
|
|
272
|
+
Boolean: 2,
|
|
273
|
+
Integer: 2,
|
|
274
|
+
Long: 3,
|
|
275
|
+
LongLong: 4,
|
|
276
|
+
LongPtr: 4,
|
|
277
|
+
Currency: 5,
|
|
278
|
+
Single: 6,
|
|
279
|
+
Double: 7,
|
|
280
|
+
Date: 8,
|
|
281
|
+
Decimal: 9
|
|
282
|
+
};
|
|
283
|
+
/** An approximate result type of `a op b` for two declared scalar operands. */
|
|
284
|
+
function widerScalar(a, b) {
|
|
285
|
+
const name = (NUMERIC_RANK[a.name] ?? 7) >= (NUMERIC_RANK[b.name] ?? 7) ? a.name : b.name;
|
|
286
|
+
return scalarType(name === "Boolean" ? "Integer" : name === "String" ? "Double" : name);
|
|
287
|
+
}
|
|
288
|
+
// src/semantic/declare.ts
|
|
289
|
+
const isPublicScope = (scope, standardDefault) => scope === null ? standardDefault : scope === "Public" || scope === "Global";
|
|
290
|
+
var ModuleDeclarer = class {
|
|
291
|
+
ids;
|
|
292
|
+
index;
|
|
293
|
+
types;
|
|
294
|
+
diagnostics;
|
|
295
|
+
constructor(ids, index, types, diagnostics) {
|
|
296
|
+
this.ids = ids;
|
|
297
|
+
this.index = index;
|
|
298
|
+
this.types = types;
|
|
299
|
+
this.diagnostics = diagnostics;
|
|
300
|
+
}
|
|
301
|
+
/** Pass 1: options, DefType, UDT and Enum names. */
|
|
302
|
+
collectTypes(m) {
|
|
303
|
+
this.index.addModule(m);
|
|
304
|
+
let base = 0;
|
|
305
|
+
let compareText = false;
|
|
306
|
+
let explicit = false;
|
|
307
|
+
let privateModule = false;
|
|
308
|
+
for (const member of m.ast.members) switch (member.kind) {
|
|
309
|
+
case "OptionBase":
|
|
310
|
+
base = member.base;
|
|
311
|
+
break;
|
|
312
|
+
case "OptionCompare":
|
|
313
|
+
compareText = member.mode === "Text";
|
|
314
|
+
break;
|
|
315
|
+
case "OptionExplicit":
|
|
316
|
+
explicit = true;
|
|
317
|
+
break;
|
|
318
|
+
case "OptionPrivateModule":
|
|
319
|
+
privateModule = true;
|
|
320
|
+
break;
|
|
321
|
+
case "DefTypeStatement":
|
|
322
|
+
for (const r of member.ranges) this.defType(m, member.type, r.from, r.to);
|
|
323
|
+
break;
|
|
324
|
+
case "TypeDeclaration": {
|
|
325
|
+
const udt = {
|
|
326
|
+
kind: "udt",
|
|
327
|
+
id: this.ids.take(),
|
|
328
|
+
name: member.name.name,
|
|
329
|
+
module: m.name,
|
|
330
|
+
isPublic: member.scope !== "Private",
|
|
331
|
+
fields: [],
|
|
332
|
+
declaration: member
|
|
333
|
+
};
|
|
334
|
+
m.udts.push(udt);
|
|
335
|
+
this.index.addUdt(udt);
|
|
336
|
+
break;
|
|
337
|
+
}
|
|
338
|
+
case "EnumDeclaration":
|
|
339
|
+
this.declareEnum(m, member);
|
|
340
|
+
break;
|
|
341
|
+
case "AttributeStatement": this.moduleAttribute(m, member);
|
|
342
|
+
}
|
|
343
|
+
m.options = {
|
|
344
|
+
base,
|
|
345
|
+
compareText,
|
|
346
|
+
explicit,
|
|
347
|
+
privateModule
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
defType(m, type, from, to) {
|
|
351
|
+
if (type === "Variant" || type === "Object") return;
|
|
352
|
+
const t = type === "LongPtr" ? "LongLong" : type;
|
|
353
|
+
const a = from.toLowerCase().charCodeAt(0);
|
|
354
|
+
const b = to.toLowerCase().charCodeAt(0);
|
|
355
|
+
for (let c = Math.min(a, b); c <= Math.max(a, b) && c - a < 26; c++) m.defTypes.set(String.fromCharCode(c), t);
|
|
356
|
+
}
|
|
357
|
+
moduleAttribute(m, a) {
|
|
358
|
+
if (a.name.toLowerCase() !== "vb_predeclaredid") return;
|
|
359
|
+
const v = a.values[0];
|
|
360
|
+
m.predeclared = v?.kind === "BooleanLiteral" && v.value;
|
|
361
|
+
}
|
|
362
|
+
declareEnum(m, decl) {
|
|
363
|
+
const members = [];
|
|
364
|
+
const isPublic = decl.scope !== "Private";
|
|
365
|
+
let previous = null;
|
|
366
|
+
for (const em of decl.members) {
|
|
367
|
+
const symbol = {
|
|
368
|
+
kind: "enumMember",
|
|
369
|
+
id: this.ids.take(),
|
|
370
|
+
name: em.name.name,
|
|
371
|
+
enumName: decl.name.name,
|
|
372
|
+
module: m.name,
|
|
373
|
+
value: em.value,
|
|
374
|
+
previous,
|
|
375
|
+
isPublic
|
|
376
|
+
};
|
|
377
|
+
members.push(symbol);
|
|
378
|
+
previous = symbol;
|
|
379
|
+
}
|
|
380
|
+
const symbol = {
|
|
381
|
+
kind: "enum",
|
|
382
|
+
id: this.ids.take(),
|
|
383
|
+
name: decl.name.name,
|
|
384
|
+
module: m.name,
|
|
385
|
+
isPublic,
|
|
386
|
+
members,
|
|
387
|
+
declaration: decl
|
|
388
|
+
};
|
|
389
|
+
m.enums.push(symbol);
|
|
390
|
+
this.index.addEnum(symbol);
|
|
391
|
+
this.addMember(m, decl.name, symbol);
|
|
392
|
+
for (const member of members) m.members.set(member.name.toLowerCase(), member);
|
|
393
|
+
}
|
|
394
|
+
/** Pass 2: UDT fields, variables, constants, events, Declares, procedures, Implements. */
|
|
395
|
+
declareMembers(m) {
|
|
396
|
+
const standard = m.kind === "standard";
|
|
397
|
+
for (const member of m.ast.members) switch (member.kind) {
|
|
398
|
+
case "TypeDeclaration":
|
|
399
|
+
this.udtFields(m, member);
|
|
400
|
+
break;
|
|
401
|
+
case "VariableDeclaration":
|
|
402
|
+
for (const d of member.declarators) {
|
|
403
|
+
const symbol = {
|
|
404
|
+
kind: "variable",
|
|
405
|
+
id: this.ids.take(),
|
|
406
|
+
name: d.name.name,
|
|
407
|
+
scope: m.perInstance ? "instance" : "module",
|
|
408
|
+
module: m.name,
|
|
409
|
+
isPublic: member.keyword === "Public" || member.keyword === "Global",
|
|
410
|
+
type: this.types.declared(d.name, d.asClause, d.dimensions?.bounds ?? null, m),
|
|
411
|
+
bounds: d.dimensions?.bounds ?? null,
|
|
412
|
+
isNew: d.asClause?.isNew ?? false,
|
|
413
|
+
withEvents: d.withEvents,
|
|
414
|
+
implicit: false,
|
|
415
|
+
slot: m.variables.length,
|
|
416
|
+
declaration: d,
|
|
417
|
+
usage: new UsageFacts()
|
|
418
|
+
};
|
|
419
|
+
m.variables.push(symbol);
|
|
420
|
+
this.addMember(m, d.name, symbol);
|
|
421
|
+
}
|
|
422
|
+
break;
|
|
423
|
+
case "ConstDeclaration":
|
|
424
|
+
for (const d of member.declarators) {
|
|
425
|
+
const symbol = {
|
|
426
|
+
kind: "const",
|
|
427
|
+
id: this.ids.take(),
|
|
428
|
+
name: d.name.name,
|
|
429
|
+
module: m.name,
|
|
430
|
+
procedure: null,
|
|
431
|
+
isPublic: isPublicScope(member.scope, false) && standard,
|
|
432
|
+
type: d.asClause ? this.types.named(d.asClause.type, m, d.asClause.fixedLength) : null,
|
|
433
|
+
value: d.value,
|
|
434
|
+
declaration: member,
|
|
435
|
+
nameRef: d.name
|
|
436
|
+
};
|
|
437
|
+
m.consts.push(symbol);
|
|
438
|
+
this.addMember(m, d.name, symbol);
|
|
439
|
+
}
|
|
440
|
+
break;
|
|
441
|
+
case "EventDeclaration":
|
|
442
|
+
m.events.push({
|
|
443
|
+
kind: "event",
|
|
444
|
+
id: this.ids.take(),
|
|
445
|
+
name: member.name.name,
|
|
446
|
+
module: m.name,
|
|
447
|
+
parameters: member.parameters,
|
|
448
|
+
declaration: member
|
|
449
|
+
});
|
|
450
|
+
break;
|
|
451
|
+
case "DeclareStatement": {
|
|
452
|
+
const symbol = {
|
|
453
|
+
kind: "declare",
|
|
454
|
+
id: this.ids.take(),
|
|
455
|
+
name: member.name.name,
|
|
456
|
+
module: m.name,
|
|
457
|
+
isPublic: isPublicScope(member.scope, true),
|
|
458
|
+
declaration: member
|
|
459
|
+
};
|
|
460
|
+
m.declares.push(symbol);
|
|
461
|
+
this.addMember(m, member.name, symbol);
|
|
462
|
+
this.diagnostics.add(m.name, "declare-not-supported", member.span, member.name.name);
|
|
463
|
+
break;
|
|
464
|
+
}
|
|
465
|
+
case "ProcedureDeclaration":
|
|
466
|
+
this.declareProcedure(m, member);
|
|
467
|
+
break;
|
|
468
|
+
case "ImplementsStatement": {
|
|
469
|
+
const name = member.type.parts.at(-1)?.name ?? member.type.name;
|
|
470
|
+
const target = this.index.classes.get(name.toLowerCase());
|
|
471
|
+
if (target) m.implements.push(target);
|
|
472
|
+
else this.diagnostics.add(m.name, "user-defined-type-not-defined", member.type.span, name);
|
|
473
|
+
break;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
udtFields(m, decl) {
|
|
478
|
+
const udt = m.udts.find((u) => u.declaration === decl);
|
|
479
|
+
if (!udt) return;
|
|
480
|
+
for (const f of decl.members) {
|
|
481
|
+
const bounds = f.dimensions?.bounds ?? null;
|
|
482
|
+
udt.fields.push({
|
|
483
|
+
name: f.name.name,
|
|
484
|
+
type: this.types.declared(f.name, f.asClause, bounds, m),
|
|
485
|
+
bounds
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
declareProcedure(m, decl) {
|
|
490
|
+
const returns = decl.procedureKind === "Function" || decl.procedureKind === "PropertyGet" ? this.types.declared(decl.name, decl.returnType, null, m) : null;
|
|
491
|
+
const p = new BoundProcedure(this.ids.take(), m, decl, returns);
|
|
492
|
+
decl.parameters.forEach((param, i) => p.params.push(this.param(m, param, i)));
|
|
493
|
+
if (returns) p.result = {
|
|
494
|
+
kind: "variable",
|
|
495
|
+
id: this.ids.take(),
|
|
496
|
+
name: decl.name.name,
|
|
497
|
+
scope: "result",
|
|
498
|
+
module: m.name,
|
|
499
|
+
isPublic: false,
|
|
500
|
+
type: returns,
|
|
501
|
+
bounds: null,
|
|
502
|
+
isNew: false,
|
|
503
|
+
withEvents: false,
|
|
504
|
+
implicit: false,
|
|
505
|
+
slot: p.params.length,
|
|
506
|
+
declaration: null,
|
|
507
|
+
usage: new UsageFacts()
|
|
508
|
+
};
|
|
509
|
+
m.procedures.push(p);
|
|
510
|
+
const key = decl.name.name.toLowerCase();
|
|
511
|
+
const existing = m.members.get(key);
|
|
512
|
+
let group = existing instanceof PropertyGroup ? existing : void 0;
|
|
513
|
+
if (!group) {
|
|
514
|
+
group = new PropertyGroup(decl.name.name, m);
|
|
515
|
+
if (existing) this.diagnostics.add(m.name, "duplicate-declaration", decl.name.span, decl.name.name);
|
|
516
|
+
else m.members.set(key, group);
|
|
517
|
+
m.groups.set(key, group);
|
|
518
|
+
}
|
|
519
|
+
if (!group.add(p)) this.diagnostics.add(m.name, "ambiguous-name", decl.name.span, decl.name.name);
|
|
520
|
+
for (const a of decl.attributes) this.memberAttribute(m, group, a);
|
|
521
|
+
}
|
|
522
|
+
param(m, param, index) {
|
|
523
|
+
const type = param.paramArray ? {
|
|
524
|
+
kind: "array",
|
|
525
|
+
element: VARIANT,
|
|
526
|
+
rank: null,
|
|
527
|
+
fixed: false
|
|
528
|
+
} : this.types.declared(param.name, param.asClause, null, m, param.isArray);
|
|
529
|
+
return {
|
|
530
|
+
kind: "param",
|
|
531
|
+
id: this.ids.take(),
|
|
532
|
+
name: param.name.name,
|
|
533
|
+
index,
|
|
534
|
+
slot: index,
|
|
535
|
+
passing: param.passing === "ByVal" ? "ByVal" : "ByRef",
|
|
536
|
+
optional: param.optional,
|
|
537
|
+
defaultValue: param.defaultValue,
|
|
538
|
+
paramArray: param.paramArray,
|
|
539
|
+
type,
|
|
540
|
+
declaration: param,
|
|
541
|
+
usage: new UsageFacts()
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
memberAttribute(m, group, a) {
|
|
545
|
+
if (!a.name.toLowerCase().endsWith(".vb_usermemid")) return;
|
|
546
|
+
const v = a.values[0];
|
|
547
|
+
const n = v?.kind === "NumberLiteral" ? v.value : v?.kind === "Unary" && v.operator === "-" && v.operand.kind === "NumberLiteral" ? -v.operand.value : void 0;
|
|
548
|
+
if (n === 0) m.defaultMember = group;
|
|
549
|
+
else if (n === -4) m.newEnum = group;
|
|
550
|
+
}
|
|
551
|
+
/** Records a module-level name, reporting a duplicate. */
|
|
552
|
+
addMember(m, name, symbol) {
|
|
553
|
+
const key = name.name.toLowerCase();
|
|
554
|
+
if (m.members.has(key)) this.reportDuplicate(m, name.span, name.name);
|
|
555
|
+
else m.members.set(key, symbol);
|
|
556
|
+
}
|
|
557
|
+
reportDuplicate(m, span, name) {
|
|
558
|
+
this.diagnostics.add(m.name, "duplicate-declaration", span, name);
|
|
559
|
+
}
|
|
560
|
+
};
|
|
561
|
+
scalarType("Long");
|
|
562
|
+
// src/semantic/diagnostics.ts
|
|
563
|
+
/** The message VBA's editor shows for each code. */
|
|
564
|
+
const SEMANTIC_MESSAGES = {
|
|
565
|
+
"variable-not-defined": "Variable not defined",
|
|
566
|
+
"sub-or-function-not-defined": "Sub or Function not defined",
|
|
567
|
+
"duplicate-declaration": "Duplicate declaration in current scope",
|
|
568
|
+
"ambiguous-name": "Ambiguous name detected",
|
|
569
|
+
"label-not-defined": "Label not defined",
|
|
570
|
+
"byref-argument-type-mismatch": "ByRef argument type mismatch",
|
|
571
|
+
"wrong-number-of-arguments": "Wrong number of arguments or invalid property assignment",
|
|
572
|
+
"argument-not-optional": "Argument not optional",
|
|
573
|
+
"named-argument-not-found": "Named argument not found",
|
|
574
|
+
"invalid-use-of-me": "Invalid use of Me keyword",
|
|
575
|
+
"user-defined-type-not-defined": "User-defined type not defined",
|
|
576
|
+
"method-or-data-member-not-found": "Method or data member not found",
|
|
577
|
+
"expected-array": "Expected array",
|
|
578
|
+
"invalid-qualifier": "Invalid qualifier",
|
|
579
|
+
"constant-expression-required": "Constant expression required",
|
|
580
|
+
"declare-not-supported": "Declare statements are not supported in this environment",
|
|
581
|
+
"exit-not-allowed": "Exit {target} not allowed in {others}",
|
|
582
|
+
"exit-not-in-loop": "Exit {target} not within {loop}",
|
|
583
|
+
"only-valid-in-object-module": "Only valid in object module"
|
|
584
|
+
};
|
|
585
|
+
/** The runtime error an executor raises if it reaches code with this compile error. */
|
|
586
|
+
const SEMANTIC_ERROR_NUMBERS = {
|
|
587
|
+
"sub-or-function-not-defined": 35,
|
|
588
|
+
"wrong-number-of-arguments": 450,
|
|
589
|
+
"argument-not-optional": 449,
|
|
590
|
+
"named-argument-not-found": 448,
|
|
591
|
+
"method-or-data-member-not-found": 438,
|
|
592
|
+
"expected-array": 13,
|
|
593
|
+
"declare-not-supported": 445
|
|
594
|
+
};
|
|
595
|
+
/** Collects diagnostics, capped so hostile input cannot grow the list without bound. */
|
|
596
|
+
var DiagnosticSink = class {
|
|
597
|
+
max;
|
|
598
|
+
items = [];
|
|
599
|
+
constructor(max = 1e3) {
|
|
600
|
+
this.max = max;
|
|
601
|
+
}
|
|
602
|
+
add(module, code, span, detail) {
|
|
603
|
+
if (this.items.length >= this.max) return;
|
|
604
|
+
const message = messageOf(code, detail);
|
|
605
|
+
const severity = code === "declare-not-supported" ? "warning" : "error";
|
|
606
|
+
this.items.push({
|
|
607
|
+
module,
|
|
608
|
+
code,
|
|
609
|
+
message,
|
|
610
|
+
severity,
|
|
611
|
+
span
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
addParsed(module, diagnostic) {
|
|
615
|
+
if (this.items.length >= this.max) return;
|
|
616
|
+
this.items.push({
|
|
617
|
+
...diagnostic,
|
|
618
|
+
module
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
};
|
|
622
|
+
const EXIT_OTHERS = {
|
|
623
|
+
Sub: "Function or Property",
|
|
624
|
+
Function: "Sub or Property",
|
|
625
|
+
Property: "Function or Sub"
|
|
626
|
+
};
|
|
627
|
+
/** The editor's message: the code's text, with its detail appended or filled in. */
|
|
628
|
+
function messageOf(code, detail) {
|
|
629
|
+
const text = SEMANTIC_MESSAGES[code];
|
|
630
|
+
if (code === "exit-not-in-loop" && detail) return text.replace("{target}", detail).replace("{loop}", detail === "Do" ? "Do...Loop" : "For...Next");
|
|
631
|
+
if (code === "exit-not-allowed" && detail) return text.replace("{target}", detail).replace("{others}", EXIT_OTHERS[detail] ?? "this procedure");
|
|
632
|
+
return text + (detail ? `: ${detail}` : "");
|
|
633
|
+
}
|
|
634
|
+
// src/semantic/module.ts
|
|
635
|
+
/**
|
|
636
|
+
* One module of a bound program: its options, module-level symbols and procedures, and for class
|
|
637
|
+
* and document modules the shape other code sees (default member, events, interfaces).
|
|
638
|
+
*/
|
|
639
|
+
var BoundModule = class {
|
|
640
|
+
name;
|
|
641
|
+
kind;
|
|
642
|
+
ast;
|
|
643
|
+
/** The module's `Option` statements. */
|
|
644
|
+
options = {
|
|
645
|
+
base: 0,
|
|
646
|
+
compareText: false,
|
|
647
|
+
explicit: false,
|
|
648
|
+
privateModule: false
|
|
649
|
+
};
|
|
650
|
+
/** Module variables (`scope` module) or class instance variables (`scope` instance), by slot. */
|
|
651
|
+
variables = [];
|
|
652
|
+
/** Module constants, in an order where each comes after the constants its value uses. */
|
|
653
|
+
consts = [];
|
|
654
|
+
/** `Enum` declarations, in source order. */
|
|
655
|
+
enums = [];
|
|
656
|
+
/** `Type` declarations (user-defined types), in source order. */
|
|
657
|
+
udts = [];
|
|
658
|
+
/** `Event` declarations of a class module, in source order. */
|
|
659
|
+
events = [];
|
|
660
|
+
/** `Declare` statements (external procedures), in source order. */
|
|
661
|
+
declares = [];
|
|
662
|
+
/** Every procedure (each Property accessor separately), in source order. */
|
|
663
|
+
procedures = [];
|
|
664
|
+
/** Procedures by lower-case name. */
|
|
665
|
+
groups = /* @__PURE__ */ new Map();
|
|
666
|
+
/** Every module-level name (lower case). */
|
|
667
|
+
members = /* @__PURE__ */ new Map();
|
|
668
|
+
/** `DefInt A-Z` and friends: the type of each letter (lower case). */
|
|
669
|
+
defTypes = /* @__PURE__ */ new Map();
|
|
670
|
+
/** Class modules named by `Implements`. */
|
|
671
|
+
implements = [];
|
|
672
|
+
/** The member with `VB_UserMemId = 0` (class modules). */
|
|
673
|
+
defaultMember = null;
|
|
674
|
+
/** The member with `VB_UserMemId = -4` (`For Each` over an instance). */
|
|
675
|
+
newEnum = null;
|
|
676
|
+
/** `VB_PredeclaredId = True`: the class has a default instance named like the class. */
|
|
677
|
+
predeclared = false;
|
|
678
|
+
/** Handlers of `WithEvents` variables: the Sub for each variable and event (lower case). */
|
|
679
|
+
eventHandlers = /* @__PURE__ */ new Map();
|
|
680
|
+
/** True when a compile error was found in this module; it cannot run. */
|
|
681
|
+
hasErrors = false;
|
|
682
|
+
constructor(name, kind, ast) {
|
|
683
|
+
this.name = name;
|
|
684
|
+
this.kind = kind;
|
|
685
|
+
this.ast = ast;
|
|
686
|
+
}
|
|
687
|
+
/** The Sub that handles `<prefix>_<event>` (a document module's `Workbook_Open`). */
|
|
688
|
+
handler(prefix, event) {
|
|
689
|
+
const group = this.groups.get(`${prefix}_${event}`.toLowerCase());
|
|
690
|
+
return group?.method?.kind === "Sub" ? group.method : null;
|
|
691
|
+
}
|
|
692
|
+
/** True for modules whose variables live per object (class and form modules). */
|
|
693
|
+
get perInstance() {
|
|
694
|
+
return this.kind === "class" || this.kind === "form";
|
|
695
|
+
}
|
|
696
|
+
/** True for modules whose code runs with a `Me` (class, form and document modules). */
|
|
697
|
+
get hasMe() {
|
|
698
|
+
return this.kind !== "standard";
|
|
699
|
+
}
|
|
700
|
+
};
|
|
701
|
+
// src/semantic/operands.ts
|
|
702
|
+
/**
|
|
703
|
+
* Whether an operand counts as declared (typed) for comparisons ([MS-VBAL] 5.6.9.8.1): a variable,
|
|
704
|
+
* parameter or function result declared with a type other than Variant. Literals and constants do
|
|
705
|
+
* not: Excel compares `v < "9a"` (v holding 9) as a number against a string, without converting.
|
|
706
|
+
* A Boolean literal does count: `"True" = True` converts the string and is True in Excel.
|
|
707
|
+
*/
|
|
708
|
+
function isTypedOperand(model, e) {
|
|
709
|
+
switch (e.kind) {
|
|
710
|
+
case "NumberLiteral":
|
|
711
|
+
case "StringLiteral":
|
|
712
|
+
case "DateLiteral":
|
|
713
|
+
case "EmptyLiteral":
|
|
714
|
+
case "NullLiteral":
|
|
715
|
+
case "NothingLiteral": return false;
|
|
716
|
+
case "Paren": return isTypedOperand(model, e.expression);
|
|
717
|
+
case "Unary": return isTypedOperand(model, e.operand);
|
|
718
|
+
case "Name": {
|
|
719
|
+
const k = model.binding(e)?.kind;
|
|
720
|
+
if (k === "const" || k === "enumMember" || k === "libraryConstant") return false;
|
|
721
|
+
return !isVariant(model.typeOf(e));
|
|
722
|
+
}
|
|
723
|
+
default: return !isVariant(model.typeOf(e));
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
/**
|
|
727
|
+
* `Len(v)` / `LenB(v)` of a variable or parameter declared with a scalar type other than String:
|
|
728
|
+
* the VT whose byte size the call returns instead of the length of the text ([MS-VBAL]
|
|
729
|
+
* 6.1.2.11.1.15), else null.
|
|
730
|
+
*/
|
|
731
|
+
function typedLengthVt(model, name, argument) {
|
|
732
|
+
const lower = name.toLowerCase();
|
|
733
|
+
if (lower !== "len" && lower !== "lenb" || !argument || argument.kind !== "Name") return null;
|
|
734
|
+
const k = model.binding(argument)?.kind;
|
|
735
|
+
if (k !== "variable" && k !== "param") return null;
|
|
736
|
+
const t = model.typeOf(argument);
|
|
737
|
+
return t.kind === "scalar" && t.vt !== 8 ? t.vt : null;
|
|
738
|
+
}
|
|
739
|
+
/**
|
|
740
|
+
* Whether a conversion's argument has a type known before it runs: a literal, a constant, or an
|
|
741
|
+
* expression of a declared non-Variant type. Office raises 6 for an out-of-range value of such an
|
|
742
|
+
* argument (`CDate(3000000)`), 13 for one held in a Variant.
|
|
743
|
+
*/
|
|
744
|
+
function isStaticallyTyped(model, e) {
|
|
745
|
+
switch (e.kind) {
|
|
746
|
+
case "NumberLiteral":
|
|
747
|
+
case "StringLiteral":
|
|
748
|
+
case "DateLiteral":
|
|
749
|
+
case "BooleanLiteral": return true;
|
|
750
|
+
case "Paren": return isStaticallyTyped(model, e.expression);
|
|
751
|
+
case "Unary": return isStaticallyTyped(model, e.operand);
|
|
752
|
+
case "Name": {
|
|
753
|
+
const k = model.binding(e)?.kind;
|
|
754
|
+
if (k === "const" || k === "enumMember" || k === "libraryConstant") return true;
|
|
755
|
+
return !isVariant(model.typeOf(e));
|
|
756
|
+
}
|
|
757
|
+
default: return !isVariant(model.typeOf(e));
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
// src/semantic/program.ts
|
|
761
|
+
/** The side tables the binder fills; one per program. */
|
|
762
|
+
var BindingTable = class {
|
|
763
|
+
/** What each name, `Me`, member access, `!` access or call refers to. */
|
|
764
|
+
bindings = /* @__PURE__ */ new Map();
|
|
765
|
+
/** What each call, index or call statement does. */
|
|
766
|
+
invocations = /* @__PURE__ */ new Map();
|
|
767
|
+
/** The `With` block of each `.member` or `!key` written without an object. */
|
|
768
|
+
withRefs = /* @__PURE__ */ new Map();
|
|
769
|
+
/** The static type of each expression the binder could type. */
|
|
770
|
+
types = /* @__PURE__ */ new Map();
|
|
771
|
+
/** Values used as objects (Set, Is, a Variant or Object argument): no default member is read. */
|
|
772
|
+
objectUses = /* @__PURE__ */ new Set();
|
|
773
|
+
};
|
|
774
|
+
/**
|
|
775
|
+
* `BoundProgram.mayCallDefault` over the side tables: a Variant or Object value read for its value,
|
|
776
|
+
* unless it is passed on as an object, is an operator's result, or is the result of a library
|
|
777
|
+
* function that never returns an object (`Len(s)`, `Mid(s, 2)`).
|
|
778
|
+
*/
|
|
779
|
+
function readMayCall(table, e) {
|
|
780
|
+
if (e.kind === "Binary" || e.kind === "Unary" || e.kind === "TypeOf") return false;
|
|
781
|
+
if (table.objectUses.has(e)) return false;
|
|
782
|
+
const t = table.types.get(e);
|
|
783
|
+
if (t !== void 0 && t.kind !== "variant" && t.kind !== "object") return false;
|
|
784
|
+
const inv = table.invocations.get(e);
|
|
785
|
+
return !(inv?.kind === "library" && !inv.entry.mayReturnObject);
|
|
786
|
+
}
|
|
787
|
+
/**
|
|
788
|
+
* A bound project: what `bindProgram` returns. It holds the bound modules and the compile
|
|
789
|
+
* diagnostics, and answers, for any AST node of the project, what the binder decided about it.
|
|
790
|
+
*/
|
|
791
|
+
var BoundProgram = class {
|
|
792
|
+
modules;
|
|
793
|
+
diagnostics;
|
|
794
|
+
table;
|
|
795
|
+
byName = /* @__PURE__ */ new Map();
|
|
796
|
+
constructor(modules, diagnostics, table) {
|
|
797
|
+
this.modules = modules;
|
|
798
|
+
this.diagnostics = diagnostics;
|
|
799
|
+
this.table = table;
|
|
800
|
+
for (const m of modules) this.byName.set(m.name.toLowerCase(), m);
|
|
801
|
+
}
|
|
802
|
+
/** The module with this name, compared case-insensitively. */
|
|
803
|
+
module(name) {
|
|
804
|
+
return this.byName.get(name.toLowerCase());
|
|
805
|
+
}
|
|
806
|
+
/**
|
|
807
|
+
* Whether evaluating `e` for its value may run code implicitly: read an object's default member
|
|
808
|
+
* (a Variant, Object or class-typed operand of an operator, a Let, Print, a conversion, an
|
|
809
|
+
* index), or enumerate it (`For Each`). False for literals, typed scalars, and values passed on
|
|
810
|
+
* as objects (Set, Is, TypeOf, a Variant or Object argument). Conservative: true may still not
|
|
811
|
+
* call anything.
|
|
812
|
+
*/
|
|
813
|
+
mayCallDefault(e) {
|
|
814
|
+
return readMayCall(this.table, e);
|
|
815
|
+
}
|
|
816
|
+
/** What a `Name`, `Me`, `MemberAccess`, `DictionaryAccess` or `CallOrIndex` refers to. */
|
|
817
|
+
binding(node) {
|
|
818
|
+
return this.table.bindings.get(node);
|
|
819
|
+
}
|
|
820
|
+
/** What a `CallOrIndex` or call statement does. */
|
|
821
|
+
invocation(node) {
|
|
822
|
+
return this.table.invocations.get(node);
|
|
823
|
+
}
|
|
824
|
+
/** The `With` block a `.member` or `!key` with no object refers to. */
|
|
825
|
+
withBlock(node) {
|
|
826
|
+
return this.table.withRefs.get(node);
|
|
827
|
+
}
|
|
828
|
+
/** The static type of an expression (Variant when nothing is known). */
|
|
829
|
+
typeOf(node) {
|
|
830
|
+
return this.table.types.get(node) ?? VARIANT;
|
|
831
|
+
}
|
|
832
|
+
/** Whether a comparison operand counts as declared (typed); see `isTypedOperand`. */
|
|
833
|
+
isTypedOperand(node) {
|
|
834
|
+
return isTypedOperand(this, node);
|
|
835
|
+
}
|
|
836
|
+
/**
|
|
837
|
+
* Finds a procedure group by `Module.Name` or by an unambiguous `Name` among the standard
|
|
838
|
+
* modules (as `Application.Run` does). Private procedures are found when qualified.
|
|
839
|
+
*/
|
|
840
|
+
findGroup(name) {
|
|
841
|
+
const dot = name.lastIndexOf(".");
|
|
842
|
+
if (dot > 0) return this.module(name.slice(0, dot))?.groups.get(name.slice(dot + 1).toLowerCase());
|
|
843
|
+
const found = [];
|
|
844
|
+
for (const m of this.modules) {
|
|
845
|
+
const g = m.groups.get(name.toLowerCase());
|
|
846
|
+
if (g && (m.kind === "standard" || m.kind === "document")) found.push(g);
|
|
847
|
+
}
|
|
848
|
+
if (found.length > 1) {
|
|
849
|
+
const standard = found.filter((g) => g.module.kind === "standard");
|
|
850
|
+
return standard.length === 1 ? standard[0] : "ambiguous";
|
|
851
|
+
}
|
|
852
|
+
return found[0];
|
|
853
|
+
}
|
|
854
|
+
/** Every bound procedure of every module. */
|
|
855
|
+
*procedures() {
|
|
856
|
+
for (const m of this.modules) yield* m.procedures;
|
|
857
|
+
}
|
|
858
|
+
/** True when any module has a compile error. */
|
|
859
|
+
get hasErrors() {
|
|
860
|
+
return this.modules.some((m) => m.hasErrors);
|
|
861
|
+
}
|
|
862
|
+
};
|
|
863
|
+
// src/semantic/library/constants.ts
|
|
864
|
+
const LONG = scalarType("Long");
|
|
865
|
+
const STRING = scalarType("String");
|
|
866
|
+
const NUMERIC = {
|
|
867
|
+
vbUseCompareOption: -1,
|
|
868
|
+
vbBinaryCompare: 0,
|
|
869
|
+
vbTextCompare: 1,
|
|
870
|
+
vbDatabaseCompare: 2,
|
|
871
|
+
vbTrue: -1,
|
|
872
|
+
vbFalse: 0,
|
|
873
|
+
vbUseDefault: -2,
|
|
874
|
+
vbEmpty: 0,
|
|
875
|
+
vbNull: 1,
|
|
876
|
+
vbInteger: 2,
|
|
877
|
+
vbLong: 3,
|
|
878
|
+
vbSingle: 4,
|
|
879
|
+
vbDouble: 5,
|
|
880
|
+
vbCurrency: 6,
|
|
881
|
+
vbDate: 7,
|
|
882
|
+
vbString: 8,
|
|
883
|
+
vbObject: 9,
|
|
884
|
+
vbError: 10,
|
|
885
|
+
vbBoolean: 11,
|
|
886
|
+
vbVariant: 12,
|
|
887
|
+
vbDataObject: 13,
|
|
888
|
+
vbDecimal: 14,
|
|
889
|
+
vbByte: 17,
|
|
890
|
+
vbLongLong: 20,
|
|
891
|
+
vbUserDefinedType: 36,
|
|
892
|
+
vbArray: 8192,
|
|
893
|
+
vbUseSystemDayOfWeek: 0,
|
|
894
|
+
vbSunday: 1,
|
|
895
|
+
vbMonday: 2,
|
|
896
|
+
vbTuesday: 3,
|
|
897
|
+
vbWednesday: 4,
|
|
898
|
+
vbThursday: 5,
|
|
899
|
+
vbFriday: 6,
|
|
900
|
+
vbSaturday: 7,
|
|
901
|
+
vbUseSystem: 0,
|
|
902
|
+
vbFirstJan1: 1,
|
|
903
|
+
vbFirstFourDays: 2,
|
|
904
|
+
vbFirstFullWeek: 3,
|
|
905
|
+
vbGeneralDate: 0,
|
|
906
|
+
vbLongDate: 1,
|
|
907
|
+
vbShortDate: 2,
|
|
908
|
+
vbLongTime: 3,
|
|
909
|
+
vbShortTime: 4,
|
|
910
|
+
vbUpperCase: 1,
|
|
911
|
+
vbLowerCase: 2,
|
|
912
|
+
vbProperCase: 3,
|
|
913
|
+
vbWide: 4,
|
|
914
|
+
vbNarrow: 8,
|
|
915
|
+
vbKatakana: 16,
|
|
916
|
+
vbHiragana: 32,
|
|
917
|
+
vbUnicode: 64,
|
|
918
|
+
vbFromUnicode: 128,
|
|
919
|
+
vbOKOnly: 0,
|
|
920
|
+
vbOKCancel: 1,
|
|
921
|
+
vbAbortRetryIgnore: 2,
|
|
922
|
+
vbYesNoCancel: 3,
|
|
923
|
+
vbYesNo: 4,
|
|
924
|
+
vbRetryCancel: 5,
|
|
925
|
+
vbCritical: 16,
|
|
926
|
+
vbQuestion: 32,
|
|
927
|
+
vbExclamation: 48,
|
|
928
|
+
vbInformation: 64,
|
|
929
|
+
vbDefaultButton1: 0,
|
|
930
|
+
vbDefaultButton2: 256,
|
|
931
|
+
vbDefaultButton3: 512,
|
|
932
|
+
vbDefaultButton4: 768,
|
|
933
|
+
vbApplicationModal: 0,
|
|
934
|
+
vbSystemModal: 4096,
|
|
935
|
+
vbMsgBoxHelpButton: 16384,
|
|
936
|
+
vbMsgBoxSetForeground: 65536,
|
|
937
|
+
vbMsgBoxRight: 524288,
|
|
938
|
+
vbMsgBoxRtlReading: 1048576,
|
|
939
|
+
vbOK: 1,
|
|
940
|
+
vbCancel: 2,
|
|
941
|
+
vbAbort: 3,
|
|
942
|
+
vbRetry: 4,
|
|
943
|
+
vbIgnore: 5,
|
|
944
|
+
vbYes: 6,
|
|
945
|
+
vbNo: 7,
|
|
946
|
+
vbMethod: 1,
|
|
947
|
+
vbGet: 2,
|
|
948
|
+
vbLet: 4,
|
|
949
|
+
vbSet: 8,
|
|
950
|
+
vbNormal: 0,
|
|
951
|
+
vbReadOnly: 1,
|
|
952
|
+
vbHidden: 2,
|
|
953
|
+
vbSystem: 4,
|
|
954
|
+
vbVolume: 8,
|
|
955
|
+
vbDirectory: 16,
|
|
956
|
+
vbArchive: 32,
|
|
957
|
+
vbAlias: 64,
|
|
958
|
+
vbHide: 0,
|
|
959
|
+
vbNormalFocus: 1,
|
|
960
|
+
vbMinimizedFocus: 2,
|
|
961
|
+
vbMaximizedFocus: 3,
|
|
962
|
+
vbNormalNoFocus: 4,
|
|
963
|
+
vbMinimizedNoFocus: 6,
|
|
964
|
+
vbBlack: 0,
|
|
965
|
+
vbRed: 255,
|
|
966
|
+
vbGreen: 65280,
|
|
967
|
+
vbYellow: 65535,
|
|
968
|
+
vbBlue: 0xff0000,
|
|
969
|
+
vbMagenta: 0xff00ff,
|
|
970
|
+
vbCyan: 0xffff00,
|
|
971
|
+
vbWhite: 0xffffff,
|
|
972
|
+
vbObjectError: -0x7ffc0000
|
|
973
|
+
};
|
|
974
|
+
const TEXT = {
|
|
975
|
+
vbCr: "\r",
|
|
976
|
+
vbLf: "\n",
|
|
977
|
+
vbCrLf: "\r\n",
|
|
978
|
+
vbNewLine: "\r\n",
|
|
979
|
+
vbNullChar: "\0",
|
|
980
|
+
vbNullString: "",
|
|
981
|
+
vbTab: " ",
|
|
982
|
+
vbBack: "\b",
|
|
983
|
+
vbFormFeed: "\f",
|
|
984
|
+
vbVerticalTab: "\v"
|
|
985
|
+
};
|
|
986
|
+
/** Every built-in constant: the `vb` enumeration values as `Long`, the text ones as `String`. */
|
|
987
|
+
const LIBRARY_CONSTANTS = [...Object.entries(NUMERIC).map(([name, value]) => ({
|
|
988
|
+
kind: "constant",
|
|
989
|
+
name,
|
|
990
|
+
value,
|
|
991
|
+
type: LONG
|
|
992
|
+
})), ...Object.entries(TEXT).map(([name, value]) => ({
|
|
993
|
+
kind: "constant",
|
|
994
|
+
name,
|
|
995
|
+
value,
|
|
996
|
+
type: STRING
|
|
997
|
+
}))];
|
|
998
|
+
// src/semantic/library/entry.ts
|
|
999
|
+
/**
|
|
1000
|
+
* A function entry: `params` is a space-separated list; a trailing `...` marks the last one as a
|
|
1001
|
+
* ParamArray. `required` defaults to every parameter but a ParamArray.
|
|
1002
|
+
*/
|
|
1003
|
+
function fn(name, runtime, convention, params, options = {}) {
|
|
1004
|
+
const list = params === "" ? [] : params.split(" ");
|
|
1005
|
+
const paramArray = list.at(-1)?.endsWith("...") ?? false;
|
|
1006
|
+
const names = list.map((p) => p.replace("...", ""));
|
|
1007
|
+
const returns = options.returns === void 0 || options.returns === "Variant" ? name.endsWith("$") ? scalarType("String") : VARIANT : scalarType(options.returns);
|
|
1008
|
+
return Object.freeze({
|
|
1009
|
+
kind: "function",
|
|
1010
|
+
name,
|
|
1011
|
+
runtime,
|
|
1012
|
+
convention,
|
|
1013
|
+
params: names,
|
|
1014
|
+
required: options.required ?? (paramArray ? names.length - 1 : names.length),
|
|
1015
|
+
paramArray,
|
|
1016
|
+
leadingOptional: options.leadingOptional ?? false,
|
|
1017
|
+
returns,
|
|
1018
|
+
async: options.async ?? false,
|
|
1019
|
+
mayReturnObject: options.mayReturnObject ?? false,
|
|
1020
|
+
statement: options.statement ?? false
|
|
1021
|
+
});
|
|
1022
|
+
}
|
|
1023
|
+
/** A function with a `$` twin that calls a separate runtime export (`Left`/`Left$`). */
|
|
1024
|
+
function twin(name, runtime, runtimeS, convention, params, options = {}) {
|
|
1025
|
+
return [fn(name, runtime, convention, params, options), fn(`${name}$`, runtimeS, convention, params, {
|
|
1026
|
+
...options,
|
|
1027
|
+
returns: "String"
|
|
1028
|
+
})];
|
|
1029
|
+
}
|
|
1030
|
+
// src/semantic/library/functions.ts
|
|
1031
|
+
const NUM_FORMAT = "Expression NumDigitsAfterDecimal IncludeLeadingDigit UseParensForNegativeNumbers GroupDigits";
|
|
1032
|
+
const STRINGS = [
|
|
1033
|
+
fn("Asc", "asc", "env", "String", { returns: "Integer" }),
|
|
1034
|
+
fn("AscB", "ascB", "env", "String", { returns: "Integer" }),
|
|
1035
|
+
fn("AscW", "ascW", "env", "String", { returns: "Integer" }),
|
|
1036
|
+
...twin("Chr", "chr", "chr", "env", "CharCode"),
|
|
1037
|
+
...twin("ChrB", "chrB", "chrB", "env", "CharCode"),
|
|
1038
|
+
...twin("ChrW", "chrW", "chrW", "env", "CharCode"),
|
|
1039
|
+
...twin("Format", "format", "formatS", "env", "Expression Format FirstDayOfWeek FirstWeekOfYear", { required: 1 }),
|
|
1040
|
+
fn("FormatCurrency", "formatCurrency", "env", NUM_FORMAT, { required: 1 }),
|
|
1041
|
+
fn("FormatNumber", "formatNumber", "env", NUM_FORMAT, { required: 1 }),
|
|
1042
|
+
fn("FormatPercent", "formatPercent", "env", NUM_FORMAT, { required: 1 }),
|
|
1043
|
+
fn("FormatDateTime", "formatDateTime", "env", "Expression NamedFormat", { required: 1 }),
|
|
1044
|
+
fn("InStr", "inStr", "compare", "Start String1 String2 Compare", {
|
|
1045
|
+
required: 2,
|
|
1046
|
+
leadingOptional: true
|
|
1047
|
+
}),
|
|
1048
|
+
fn("InStrB", "inStrB", "compare", "Start String1 String2 Compare", {
|
|
1049
|
+
required: 2,
|
|
1050
|
+
leadingOptional: true
|
|
1051
|
+
}),
|
|
1052
|
+
fn("InStrRev", "inStrRev", "compare", "StringCheck StringMatch Start Compare", { required: 2 }),
|
|
1053
|
+
fn("Join", "join", "env", "SourceArray Delimiter", { required: 1 }),
|
|
1054
|
+
...twin("LCase", "lCase", "lCaseS", "env", "String"),
|
|
1055
|
+
...twin("UCase", "uCase", "uCaseS", "env", "String"),
|
|
1056
|
+
...twin("Left", "left", "leftS", "env", "String Length"),
|
|
1057
|
+
...twin("LeftB", "leftB", "leftB", "env", "String Length"),
|
|
1058
|
+
...twin("Right", "right", "rightS", "env", "String Length"),
|
|
1059
|
+
...twin("RightB", "rightB", "rightB", "env", "String Length"),
|
|
1060
|
+
...twin("Mid", "mid", "midS", "env", "String Start Length", { required: 2 }),
|
|
1061
|
+
...twin("MidB", "midB", "midB", "env", "String Start Length", { required: 2 }),
|
|
1062
|
+
fn("Len", "len", "env", "Expression"),
|
|
1063
|
+
fn("LenB", "lenB", "env", "Expression"),
|
|
1064
|
+
...twin("LTrim", "lTrim", "lTrimS", "env", "String"),
|
|
1065
|
+
...twin("RTrim", "rTrim", "rTrimS", "env", "String"),
|
|
1066
|
+
...twin("Trim", "trim", "trimS", "env", "String"),
|
|
1067
|
+
fn("Replace", "replace", "compare", "Expression Find Replace Start Count Compare", {
|
|
1068
|
+
required: 3,
|
|
1069
|
+
returns: "String"
|
|
1070
|
+
}),
|
|
1071
|
+
...twin("Space", "space", "space", "env", "Number"),
|
|
1072
|
+
fn("Split", "split", "compare", "Expression Delimiter Limit Compare", { required: 1 }),
|
|
1073
|
+
fn("StrComp", "strComp", "compare", "String1 String2 Compare", { required: 2 }),
|
|
1074
|
+
fn("StrConv", "strConv", "env", "String Conversion"),
|
|
1075
|
+
...twin("String", "string", "stringS", "env", "Number Character"),
|
|
1076
|
+
fn("StrReverse", "strReverse", "env", "Expression", { returns: "String" }),
|
|
1077
|
+
fn("Filter", "filter", "compare", "SourceArray Match Include Compare", { required: 2 }),
|
|
1078
|
+
...twin("Str", "str", "strS", "env", "Number"),
|
|
1079
|
+
fn("Val", "val", "env", "String", { returns: "Double" }),
|
|
1080
|
+
...twin("Hex", "hex", "hexS", "env", "Number"),
|
|
1081
|
+
...twin("Oct", "oct", "octS", "env", "Number")
|
|
1082
|
+
];
|
|
1083
|
+
const CONVERSION = [
|
|
1084
|
+
fn("CBool", "cBool", "conversion", "Expression", { returns: "Boolean" }),
|
|
1085
|
+
fn("CByte", "cByte", "conversion", "Expression", { returns: "Byte" }),
|
|
1086
|
+
fn("CCur", "cCur", "conversion", "Expression", { returns: "Currency" }),
|
|
1087
|
+
fn("CDate", "cDate", "conversion", "Expression", { returns: "Date" }),
|
|
1088
|
+
fn("CVDate", "cDate", "conversion", "Expression"),
|
|
1089
|
+
fn("CDbl", "cDbl", "conversion", "Expression", { returns: "Double" }),
|
|
1090
|
+
fn("CDec", "cDec", "conversion", "Expression"),
|
|
1091
|
+
fn("CInt", "cInt", "conversion", "Expression", { returns: "Integer" }),
|
|
1092
|
+
fn("CLng", "cLng", "conversion", "Expression", { returns: "Long" }),
|
|
1093
|
+
fn("CLngLng", "cLngLng", "conversion", "Expression", { returns: "LongLong" }),
|
|
1094
|
+
fn("CLngPtr", "cLngPtr", "conversion", "Expression", { returns: "LongPtr" }),
|
|
1095
|
+
fn("CSng", "cSng", "conversion", "Expression", { returns: "Single" }),
|
|
1096
|
+
fn("CStr", "cStr", "conversion", "Expression", { returns: "String" }),
|
|
1097
|
+
fn("CVar", "cVar", "pure", "Expression"),
|
|
1098
|
+
fn("CVErr", "cVErr", "env", "Expression"),
|
|
1099
|
+
fn("Error", "error", "special", "ErrorNumber", { required: 0 }),
|
|
1100
|
+
fn("Error$", "error", "special", "ErrorNumber", {
|
|
1101
|
+
required: 0,
|
|
1102
|
+
returns: "String"
|
|
1103
|
+
})
|
|
1104
|
+
];
|
|
1105
|
+
const MATH = [
|
|
1106
|
+
fn("Abs", "abs", "env", "Number"),
|
|
1107
|
+
fn("Atn", "atn", "env", "Number", { returns: "Double" }),
|
|
1108
|
+
fn("Cos", "cos", "env", "Number", { returns: "Double" }),
|
|
1109
|
+
fn("Exp", "exp", "env", "Number", { returns: "Double" }),
|
|
1110
|
+
fn("Fix", "fix", "env", "Number"),
|
|
1111
|
+
fn("Int", "int", "env", "Number"),
|
|
1112
|
+
fn("Log", "log", "env", "Number", { returns: "Double" }),
|
|
1113
|
+
fn("Rnd", "rnd", "session", "Number", {
|
|
1114
|
+
required: 0,
|
|
1115
|
+
returns: "Single"
|
|
1116
|
+
}),
|
|
1117
|
+
fn("Randomize", "randomize", "session", "Number", {
|
|
1118
|
+
required: 0,
|
|
1119
|
+
statement: true
|
|
1120
|
+
}),
|
|
1121
|
+
fn("Round", "round", "env", "Number NumDigitsAfterDecimal", { required: 1 }),
|
|
1122
|
+
fn("Sgn", "sgn", "env", "Number", { returns: "Integer" }),
|
|
1123
|
+
fn("Sin", "sin", "env", "Number", { returns: "Double" }),
|
|
1124
|
+
fn("Sqr", "sqr", "env", "Number", { returns: "Double" }),
|
|
1125
|
+
fn("Tan", "tan", "env", "Number", { returns: "Double" })
|
|
1126
|
+
];
|
|
1127
|
+
const DATES = [
|
|
1128
|
+
fn("Date", "date", "session", ""),
|
|
1129
|
+
fn("Date$", "dateS", "session", ""),
|
|
1130
|
+
fn("Now", "now", "session", ""),
|
|
1131
|
+
fn("Time", "time", "session", ""),
|
|
1132
|
+
fn("Time$", "timeS", "session", ""),
|
|
1133
|
+
fn("Timer", "timer", "session", "", { returns: "Single" }),
|
|
1134
|
+
fn("DateAdd", "dateAdd", "env", "Interval Number Date"),
|
|
1135
|
+
fn("DateDiff", "dateDiff", "env", "Interval Date1 Date2 FirstDayOfWeek FirstWeekOfYear", { required: 3 }),
|
|
1136
|
+
fn("DatePart", "datePart", "env", "Interval Date FirstDayOfWeek FirstWeekOfYear", { required: 2 }),
|
|
1137
|
+
fn("DateSerial", "dateSerial", "env", "Year Month Day"),
|
|
1138
|
+
fn("DateValue", "dateValue", "env", "Date"),
|
|
1139
|
+
fn("TimeSerial", "timeSerial", "env", "Hour Minute Second"),
|
|
1140
|
+
fn("TimeValue", "timeValue", "env", "Time"),
|
|
1141
|
+
fn("Day", "day", "env", "Date"),
|
|
1142
|
+
fn("Month", "month", "env", "Date"),
|
|
1143
|
+
fn("Year", "year", "env", "Date"),
|
|
1144
|
+
fn("Hour", "hour", "env", "Time"),
|
|
1145
|
+
fn("Minute", "minute", "env", "Time"),
|
|
1146
|
+
fn("Second", "second", "env", "Time"),
|
|
1147
|
+
fn("Weekday", "weekday", "env", "Date FirstDayOfWeek", { required: 1 }),
|
|
1148
|
+
fn("WeekdayName", "weekdayName", "env", "Weekday Abbreviate FirstDayOfWeek", { required: 1 }),
|
|
1149
|
+
fn("MonthName", "monthName", "env", "Month Abbreviate", { required: 1 })
|
|
1150
|
+
];
|
|
1151
|
+
const INFORMATION = [
|
|
1152
|
+
fn("IsArray", "isArray", "pure", "VarName", { returns: "Boolean" }),
|
|
1153
|
+
fn("IsDate", "isDate", "env", "Expression", { returns: "Boolean" }),
|
|
1154
|
+
fn("IsEmpty", "isEmpty", "pure", "Expression", { returns: "Boolean" }),
|
|
1155
|
+
fn("IsError", "isError", "pure", "Expression", { returns: "Boolean" }),
|
|
1156
|
+
fn("IsMissing", "isMissing", "pure", "ArgName", { returns: "Boolean" }),
|
|
1157
|
+
fn("IsNull", "isNull", "pure", "Expression", { returns: "Boolean" }),
|
|
1158
|
+
fn("IsNumeric", "isNumeric", "env", "Expression", { returns: "Boolean" }),
|
|
1159
|
+
fn("IsObject", "isObject", "pure", "Expression", { returns: "Boolean" }),
|
|
1160
|
+
fn("TypeName", "typeName", "pure", "VarName", { returns: "String" }),
|
|
1161
|
+
fn("VarType", "varType", "pure", "VarName", { returns: "Integer" }),
|
|
1162
|
+
fn("QBColor", "qbColor", "pure", "Color", { returns: "Long" }),
|
|
1163
|
+
fn("RGB", "rgb", "pure", "Red Green Blue", { returns: "Long" }),
|
|
1164
|
+
fn("Array", null, "special", "ArgList..."),
|
|
1165
|
+
fn("LBound", null, "special", "ArrayName Dimension", {
|
|
1166
|
+
required: 1,
|
|
1167
|
+
returns: "Long"
|
|
1168
|
+
}),
|
|
1169
|
+
fn("UBound", null, "special", "ArrayName Dimension", {
|
|
1170
|
+
required: 1,
|
|
1171
|
+
returns: "Long"
|
|
1172
|
+
}),
|
|
1173
|
+
fn("Erl", null, "special", "", { returns: "Long" })
|
|
1174
|
+
];
|
|
1175
|
+
const INTERACTION = [
|
|
1176
|
+
fn("Choose", "choose", "list", "Index Choice...", { mayReturnObject: true }),
|
|
1177
|
+
fn("Switch", "switchOf", "list", "VarExpr...", { mayReturnObject: true }),
|
|
1178
|
+
fn("IIf", "iif", "env", "Expression TruePart FalsePart", { mayReturnObject: true }),
|
|
1179
|
+
fn("Partition", "partition", "env", "Number Start Stop Interval"),
|
|
1180
|
+
...twin("Environ", "environ", "environ", "session", "Expression"),
|
|
1181
|
+
fn("MsgBox", "msgBox", "session", "Prompt Buttons Title", {
|
|
1182
|
+
required: 1,
|
|
1183
|
+
async: true
|
|
1184
|
+
}),
|
|
1185
|
+
fn("InputBox", "inputBox", "session", "Prompt Title Default", {
|
|
1186
|
+
required: 1,
|
|
1187
|
+
async: true
|
|
1188
|
+
}),
|
|
1189
|
+
fn("DoEvents", "doEvents", "pure", "", {
|
|
1190
|
+
async: true,
|
|
1191
|
+
returns: "Integer"
|
|
1192
|
+
}),
|
|
1193
|
+
fn("CallByName", "callByName", "list", "Object ProcName CallType Args...", {
|
|
1194
|
+
async: true,
|
|
1195
|
+
mayReturnObject: true
|
|
1196
|
+
}),
|
|
1197
|
+
fn("Command", "command", "pure", ""),
|
|
1198
|
+
fn("Shell", "shell", "pure", "PathName WindowStyle", { required: 1 }),
|
|
1199
|
+
fn("SendKeys", "sendKeys", "pure", "String Wait", {
|
|
1200
|
+
required: 1,
|
|
1201
|
+
statement: true
|
|
1202
|
+
}),
|
|
1203
|
+
fn("AppActivate", "appActivate", "pure", "Title Wait", {
|
|
1204
|
+
required: 1,
|
|
1205
|
+
statement: true
|
|
1206
|
+
}),
|
|
1207
|
+
fn("CreateObject", "createObject", "env", "Class ServerName", {
|
|
1208
|
+
required: 1,
|
|
1209
|
+
mayReturnObject: true
|
|
1210
|
+
}),
|
|
1211
|
+
fn("GetObject", "getObject", "pure", "PathName Class", {
|
|
1212
|
+
required: 0,
|
|
1213
|
+
mayReturnObject: true
|
|
1214
|
+
}),
|
|
1215
|
+
fn("GetSetting", "getSetting", "pure", "AppName Section Key Default", { required: 3 }),
|
|
1216
|
+
fn("SaveSetting", "saveSetting", "pure", "AppName Section Key Setting", { statement: true }),
|
|
1217
|
+
fn("DeleteSetting", "deleteSetting", "pure", "AppName Section Key", {
|
|
1218
|
+
required: 1,
|
|
1219
|
+
statement: true
|
|
1220
|
+
}),
|
|
1221
|
+
fn("GetAllSettings", "getAllSettings", "pure", "AppName Section")
|
|
1222
|
+
];
|
|
1223
|
+
const FINANCIAL = [
|
|
1224
|
+
fn("FV", "fv", "env", "Rate NPer Pmt PV Type", {
|
|
1225
|
+
required: 3,
|
|
1226
|
+
returns: "Double"
|
|
1227
|
+
}),
|
|
1228
|
+
fn("PV", "pv", "env", "Rate NPer Pmt FV Type", {
|
|
1229
|
+
required: 3,
|
|
1230
|
+
returns: "Double"
|
|
1231
|
+
}),
|
|
1232
|
+
fn("Pmt", "pmt", "env", "Rate NPer PV FV Type", {
|
|
1233
|
+
required: 3,
|
|
1234
|
+
returns: "Double"
|
|
1235
|
+
}),
|
|
1236
|
+
fn("IPmt", "ipmt", "env", "Rate Per NPer PV FV Type", {
|
|
1237
|
+
required: 4,
|
|
1238
|
+
returns: "Double"
|
|
1239
|
+
}),
|
|
1240
|
+
fn("PPmt", "ppmt", "env", "Rate Per NPer PV FV Type", {
|
|
1241
|
+
required: 4,
|
|
1242
|
+
returns: "Double"
|
|
1243
|
+
}),
|
|
1244
|
+
fn("NPer", "nper", "env", "Rate Pmt PV FV Type", {
|
|
1245
|
+
required: 3,
|
|
1246
|
+
returns: "Double"
|
|
1247
|
+
}),
|
|
1248
|
+
fn("Rate", "rate", "env", "NPer Pmt PV FV Type Guess", {
|
|
1249
|
+
required: 3,
|
|
1250
|
+
returns: "Double"
|
|
1251
|
+
}),
|
|
1252
|
+
fn("NPV", "npv", "env", "Rate ValueArray", { returns: "Double" }),
|
|
1253
|
+
fn("IRR", "irr", "env", "ValueArray Guess", {
|
|
1254
|
+
required: 1,
|
|
1255
|
+
returns: "Double"
|
|
1256
|
+
}),
|
|
1257
|
+
fn("MIRR", "mirr", "env", "ValueArray FinanceRate ReinvestRate", { returns: "Double" }),
|
|
1258
|
+
fn("SLN", "sln", "env", "Cost Salvage Life", { returns: "Double" }),
|
|
1259
|
+
fn("SYD", "syd", "env", "Cost Salvage Life Period", { returns: "Double" }),
|
|
1260
|
+
fn("DDB", "ddb", "env", "Cost Salvage Life Period Factor", {
|
|
1261
|
+
required: 4,
|
|
1262
|
+
returns: "Double"
|
|
1263
|
+
})
|
|
1264
|
+
];
|
|
1265
|
+
/** File system functions: the sandbox has no disk, so each raises error 445 naming itself. */
|
|
1266
|
+
const FILES = [
|
|
1267
|
+
...["CurDir", "Dir"].flatMap((n) => twin(n, n === "Dir" ? "dir" : "curDir", n === "Dir" ? "dir" : "curDir", "pure", "Path Attributes", { required: 0 })),
|
|
1268
|
+
fn("EOF", "eof", "pure", "FileNumber"),
|
|
1269
|
+
fn("FileAttr", "fileAttr", "pure", "FileNumber ReturnType"),
|
|
1270
|
+
fn("FileDateTime", "fileDateTime", "pure", "PathName"),
|
|
1271
|
+
fn("FileLen", "fileLen", "pure", "PathName"),
|
|
1272
|
+
fn("FreeFile", "freeFile", "pure", "RangeNumber", { required: 0 }),
|
|
1273
|
+
fn("Loc", "loc", "pure", "FileNumber"),
|
|
1274
|
+
fn("LOF", "lof", "pure", "FileNumber"),
|
|
1275
|
+
fn("Seek", "seek", "pure", "FileNumber"),
|
|
1276
|
+
fn("GetAttr", "getAttr", "pure", "PathName"),
|
|
1277
|
+
fn("ChDir", "chDir", "pure", "Path", { statement: true }),
|
|
1278
|
+
fn("ChDrive", "chDrive", "pure", "Drive", { statement: true }),
|
|
1279
|
+
fn("FileCopy", "fileCopy", "pure", "Source Destination", { statement: true }),
|
|
1280
|
+
fn("Kill", "kill", "pure", "PathName", { statement: true }),
|
|
1281
|
+
fn("MkDir", "mkDir", "pure", "Path", { statement: true }),
|
|
1282
|
+
fn("RmDir", "rmDir", "pure", "Path", { statement: true }),
|
|
1283
|
+
fn("SetAttr", "setAttr", "pure", "PathName Attributes", { statement: true })
|
|
1284
|
+
];
|
|
1285
|
+
/** Every library function, `$` forms included, as the binder and both executors see them. */
|
|
1286
|
+
const LIBRARY_FUNCTIONS = [
|
|
1287
|
+
...STRINGS,
|
|
1288
|
+
...CONVERSION,
|
|
1289
|
+
...MATH,
|
|
1290
|
+
...DATES,
|
|
1291
|
+
...INFORMATION,
|
|
1292
|
+
...INTERACTION,
|
|
1293
|
+
...FINANCIAL,
|
|
1294
|
+
...FILES
|
|
1295
|
+
];
|
|
1296
|
+
// src/semantic/library/index.ts
|
|
1297
|
+
const OBJECTS = [
|
|
1298
|
+
{
|
|
1299
|
+
kind: "object",
|
|
1300
|
+
name: "Err"
|
|
1301
|
+
},
|
|
1302
|
+
{
|
|
1303
|
+
kind: "object",
|
|
1304
|
+
name: "Debug"
|
|
1305
|
+
},
|
|
1306
|
+
{
|
|
1307
|
+
kind: "object",
|
|
1308
|
+
name: "VBA"
|
|
1309
|
+
}
|
|
1310
|
+
];
|
|
1311
|
+
const TABLE = /* @__PURE__ */ new Map();
|
|
1312
|
+
for (const entry of [
|
|
1313
|
+
...LIBRARY_FUNCTIONS,
|
|
1314
|
+
...LIBRARY_CONSTANTS,
|
|
1315
|
+
...OBJECTS
|
|
1316
|
+
]) TABLE.set(entry.name.toLowerCase(), entry);
|
|
1317
|
+
/** The library entry a name refers to (`Left`, `left$`, `vbCrLf`, `Err`), case-insensitively. */
|
|
1318
|
+
const libraryEntry = (name) => TABLE.get(name.toLowerCase());
|
|
1319
|
+
/** Every entry, for executors that build a dispatch table up front. */
|
|
1320
|
+
const libraryEntries = () => TABLE.values();
|
|
1321
|
+
// src/semantic/scope.ts
|
|
1322
|
+
/** Converts a module-level symbol to the binding a reference to it gets. */
|
|
1323
|
+
function memberBinding(symbol, receiver) {
|
|
1324
|
+
if (symbol instanceof PropertyGroup) return {
|
|
1325
|
+
kind: "procedure",
|
|
1326
|
+
group: symbol,
|
|
1327
|
+
receiver
|
|
1328
|
+
};
|
|
1329
|
+
switch (symbol.kind) {
|
|
1330
|
+
case "variable": return {
|
|
1331
|
+
kind: "variable",
|
|
1332
|
+
symbol
|
|
1333
|
+
};
|
|
1334
|
+
case "const": return {
|
|
1335
|
+
kind: "const",
|
|
1336
|
+
symbol
|
|
1337
|
+
};
|
|
1338
|
+
case "enum": return {
|
|
1339
|
+
kind: "enum",
|
|
1340
|
+
symbol
|
|
1341
|
+
};
|
|
1342
|
+
case "enumMember": return {
|
|
1343
|
+
kind: "enumMember",
|
|
1344
|
+
symbol
|
|
1345
|
+
};
|
|
1346
|
+
case "declare": return {
|
|
1347
|
+
kind: "declare",
|
|
1348
|
+
symbol
|
|
1349
|
+
};
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
/** Whether a module-level symbol is visible outside its module (Public). */
|
|
1353
|
+
function isPublicSymbol(symbol) {
|
|
1354
|
+
return symbol instanceof PropertyGroup ? symbol.isPublic : symbol.isPublic;
|
|
1355
|
+
}
|
|
1356
|
+
/** Whether module `from` may see `symbol` of module `owner` through a qualifier. */
|
|
1357
|
+
const isVisible = (symbol, owner, from) => owner === from || isPublicSymbol(symbol);
|
|
1358
|
+
const isEnumSymbol = (symbol) => !(symbol instanceof PropertyGroup) && (symbol.kind === "enum" || symbol.kind === "enumMember");
|
|
1359
|
+
/** The project: module names, classes and the Public members of standard modules. */
|
|
1360
|
+
var ProjectScope = class {
|
|
1361
|
+
host;
|
|
1362
|
+
modules = /* @__PURE__ */ new Map();
|
|
1363
|
+
publics = /* @__PURE__ */ new Map();
|
|
1364
|
+
constructor(modules, host) {
|
|
1365
|
+
this.host = host;
|
|
1366
|
+
for (const m of modules) {
|
|
1367
|
+
this.modules.set(m.name.toLowerCase(), m);
|
|
1368
|
+
for (const [key, symbol] of m.members) {
|
|
1369
|
+
if (!isPublicSymbol(symbol) || m.kind !== "standard" && !isEnumSymbol(symbol)) continue;
|
|
1370
|
+
const list = this.publics.get(key);
|
|
1371
|
+
if (list) list.push({
|
|
1372
|
+
module: m,
|
|
1373
|
+
symbol
|
|
1374
|
+
});
|
|
1375
|
+
else this.publics.set(key, [{
|
|
1376
|
+
module: m,
|
|
1377
|
+
symbol
|
|
1378
|
+
}]);
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
module(name) {
|
|
1383
|
+
return this.modules.get(name.toLowerCase());
|
|
1384
|
+
}
|
|
1385
|
+
implemented;
|
|
1386
|
+
/**
|
|
1387
|
+
* True when some class `Implements` this one: an object declared as it may then be another
|
|
1388
|
+
* class seen through it, so its members cannot be bound early.
|
|
1389
|
+
*/
|
|
1390
|
+
isImplemented(m) {
|
|
1391
|
+
if (!this.implemented) {
|
|
1392
|
+
this.implemented = /* @__PURE__ */ new Set();
|
|
1393
|
+
for (const each of this.modules.values()) for (const i of each.implements) this.implemented.add(i);
|
|
1394
|
+
}
|
|
1395
|
+
return this.implemented.has(m);
|
|
1396
|
+
}
|
|
1397
|
+
/**
|
|
1398
|
+
* A project-level name: a module (as qualifier, class or document object), else a Public member
|
|
1399
|
+
* of another module. `'ambiguous'` when two modules export it.
|
|
1400
|
+
*/
|
|
1401
|
+
lookup(name, from) {
|
|
1402
|
+
const key = name.toLowerCase();
|
|
1403
|
+
const m = this.modules.get(key);
|
|
1404
|
+
if (m) {
|
|
1405
|
+
if (m.kind === "class" || m.kind === "form") return {
|
|
1406
|
+
kind: "class",
|
|
1407
|
+
module: m
|
|
1408
|
+
};
|
|
1409
|
+
if (m.kind === "document" && this.host.documents.has(key)) return {
|
|
1410
|
+
kind: "documentObject",
|
|
1411
|
+
module: m
|
|
1412
|
+
};
|
|
1413
|
+
return {
|
|
1414
|
+
kind: "module",
|
|
1415
|
+
module: m
|
|
1416
|
+
};
|
|
1417
|
+
}
|
|
1418
|
+
const found = this.publics.get(key)?.filter((e) => e.module !== from);
|
|
1419
|
+
if (!found || found.length === 0) return void 0;
|
|
1420
|
+
if (found.length > 1) return "ambiguous";
|
|
1421
|
+
return memberBinding(found[0].symbol, "none");
|
|
1422
|
+
}
|
|
1423
|
+
};
|
|
1424
|
+
/** The names a procedure declares: parameters, locals, Static locals and local constants. */
|
|
1425
|
+
var ProcedureScope = class {
|
|
1426
|
+
names = /* @__PURE__ */ new Map();
|
|
1427
|
+
declare(symbol) {
|
|
1428
|
+
const key = symbol.name.toLowerCase();
|
|
1429
|
+
if (this.names.has(key)) return false;
|
|
1430
|
+
this.names.set(key, symbol);
|
|
1431
|
+
return true;
|
|
1432
|
+
}
|
|
1433
|
+
lookup(name) {
|
|
1434
|
+
const s = this.names.get(name.toLowerCase());
|
|
1435
|
+
if (!s) return void 0;
|
|
1436
|
+
if (s.kind === "param") return {
|
|
1437
|
+
kind: "param",
|
|
1438
|
+
symbol: s
|
|
1439
|
+
};
|
|
1440
|
+
if (s.kind === "const") return {
|
|
1441
|
+
kind: "const",
|
|
1442
|
+
symbol: s
|
|
1443
|
+
};
|
|
1444
|
+
return s.implicit ? {
|
|
1445
|
+
kind: "implicit",
|
|
1446
|
+
symbol: s
|
|
1447
|
+
} : {
|
|
1448
|
+
kind: "variable",
|
|
1449
|
+
symbol: s
|
|
1450
|
+
};
|
|
1451
|
+
}
|
|
1452
|
+
};
|
|
1453
|
+
/**
|
|
1454
|
+
* The full lookup chain for one module (and, inside a procedure, its procedure scope). Returns
|
|
1455
|
+
* undefined for a name nothing declares.
|
|
1456
|
+
*/
|
|
1457
|
+
var ScopeChain = class {
|
|
1458
|
+
module;
|
|
1459
|
+
project;
|
|
1460
|
+
procedure;
|
|
1461
|
+
constructor(module, project, procedure) {
|
|
1462
|
+
this.module = module;
|
|
1463
|
+
this.project = project;
|
|
1464
|
+
this.procedure = procedure;
|
|
1465
|
+
}
|
|
1466
|
+
lookup(name) {
|
|
1467
|
+
const local = this.procedure?.lookup(name);
|
|
1468
|
+
if (local) return local;
|
|
1469
|
+
const own = this.module.members.get(name.toLowerCase());
|
|
1470
|
+
if (own) return memberBinding(own, this.module.perInstance ? "self" : "none");
|
|
1471
|
+
const project = this.project.lookup(name, this.module);
|
|
1472
|
+
if (project) return project;
|
|
1473
|
+
const entry = libraryEntry(name);
|
|
1474
|
+
if (entry) {
|
|
1475
|
+
if (entry.kind === "function") return {
|
|
1476
|
+
kind: "libraryFunction",
|
|
1477
|
+
entry
|
|
1478
|
+
};
|
|
1479
|
+
if (entry.kind === "constant") return {
|
|
1480
|
+
kind: "libraryConstant",
|
|
1481
|
+
entry
|
|
1482
|
+
};
|
|
1483
|
+
return {
|
|
1484
|
+
kind: "libraryObject",
|
|
1485
|
+
entry
|
|
1486
|
+
};
|
|
1487
|
+
}
|
|
1488
|
+
if (this.project.host.globals.has(name.toLowerCase())) return {
|
|
1489
|
+
kind: "hostGlobal",
|
|
1490
|
+
name
|
|
1491
|
+
};
|
|
1492
|
+
}
|
|
1493
|
+
/** True when an undeclared name may still be a member of a host object at run time. */
|
|
1494
|
+
get hasDynamicScope() {
|
|
1495
|
+
return this.project.host.globalObject || this.module.kind === "document" && this.project.host.documents.has(this.module.name.toLowerCase());
|
|
1496
|
+
}
|
|
1497
|
+
};
|
|
1498
|
+
// src/semantic/types-resolve.ts
|
|
1499
|
+
/** The type names of the project: classes, user-defined types and enums by lower-case name. */
|
|
1500
|
+
var TypeIndex = class {
|
|
1501
|
+
classes = /* @__PURE__ */ new Map();
|
|
1502
|
+
udts = /* @__PURE__ */ new Map();
|
|
1503
|
+
enums = /* @__PURE__ */ new Map();
|
|
1504
|
+
addModule(m) {
|
|
1505
|
+
if (m.kind === "class" || m.kind === "form") this.classes.set(m.name.toLowerCase(), m);
|
|
1506
|
+
}
|
|
1507
|
+
addUdt(u) {
|
|
1508
|
+
push(this.udts, u.name, u);
|
|
1509
|
+
}
|
|
1510
|
+
addEnum(e) {
|
|
1511
|
+
push(this.enums, e.name, e);
|
|
1512
|
+
}
|
|
1513
|
+
/** A UDT visible from `from`: its own module's first, then a Public one. */
|
|
1514
|
+
udt(name, from) {
|
|
1515
|
+
return visible(this.udts.get(name.toLowerCase()), from);
|
|
1516
|
+
}
|
|
1517
|
+
enum(name, from) {
|
|
1518
|
+
return visible(this.enums.get(name.toLowerCase()), from);
|
|
1519
|
+
}
|
|
1520
|
+
};
|
|
1521
|
+
function push(map, name, item) {
|
|
1522
|
+
const key = name.toLowerCase();
|
|
1523
|
+
const list = map.get(key);
|
|
1524
|
+
if (list) list.push(item);
|
|
1525
|
+
else map.set(key, [item]);
|
|
1526
|
+
}
|
|
1527
|
+
function visible(list, from) {
|
|
1528
|
+
if (!list) return void 0;
|
|
1529
|
+
return list.find((s) => s.module.toLowerCase() === from.name.toLowerCase()) ?? list.find((s) => s.isPublic);
|
|
1530
|
+
}
|
|
1531
|
+
const BUILTIN_SCALARS = /* @__PURE__ */ new Set([
|
|
1532
|
+
"Boolean",
|
|
1533
|
+
"Byte",
|
|
1534
|
+
"Integer",
|
|
1535
|
+
"Long",
|
|
1536
|
+
"LongLong",
|
|
1537
|
+
"LongPtr",
|
|
1538
|
+
"Single",
|
|
1539
|
+
"Double",
|
|
1540
|
+
"Currency",
|
|
1541
|
+
"Decimal",
|
|
1542
|
+
"Date",
|
|
1543
|
+
"String"
|
|
1544
|
+
]);
|
|
1545
|
+
var TypeResolver = class {
|
|
1546
|
+
index;
|
|
1547
|
+
constructor(index) {
|
|
1548
|
+
this.index = index;
|
|
1549
|
+
}
|
|
1550
|
+
/** The type a `TypeRef` names, seen from module `from`; undefined for an unknown UDT name. */
|
|
1551
|
+
named(type, from, fixedLength = null) {
|
|
1552
|
+
if (type.builtin) {
|
|
1553
|
+
if (type.builtin === "Variant" || type.builtin === "Any") return VARIANT;
|
|
1554
|
+
if (type.builtin === "Object") return OBJECT;
|
|
1555
|
+
return scalarType(type.builtin, fixedLength);
|
|
1556
|
+
}
|
|
1557
|
+
const last = type.parts.at(-1)?.name ?? type.name;
|
|
1558
|
+
const qualifier = type.parts.length > 1 ? type.parts[0]?.name.toLowerCase() : void 0;
|
|
1559
|
+
if (qualifier === void 0 || qualifier !== "vba") {
|
|
1560
|
+
const udt = this.index.udt(last, from);
|
|
1561
|
+
if (udt) return {
|
|
1562
|
+
kind: "udt",
|
|
1563
|
+
udt
|
|
1564
|
+
};
|
|
1565
|
+
const e = this.index.enum(last, from);
|
|
1566
|
+
if (e) return scalarType("Long", null, e.name);
|
|
1567
|
+
const cls = this.index.classes.get(last.toLowerCase());
|
|
1568
|
+
if (cls) return {
|
|
1569
|
+
kind: "object",
|
|
1570
|
+
className: cls.name,
|
|
1571
|
+
classModule: cls.name
|
|
1572
|
+
};
|
|
1573
|
+
}
|
|
1574
|
+
if (qualifier === "vba" && BUILTIN_SCALARS.has(last)) return scalarType(last);
|
|
1575
|
+
return {
|
|
1576
|
+
kind: "object",
|
|
1577
|
+
className: last,
|
|
1578
|
+
classModule: null
|
|
1579
|
+
};
|
|
1580
|
+
}
|
|
1581
|
+
/**
|
|
1582
|
+
* The type of a declared name: its `As` clause, else its type suffix, else the module's
|
|
1583
|
+
* DefType for its first letter, else Variant. `bounds` (non-null) makes it an array.
|
|
1584
|
+
*/
|
|
1585
|
+
declared(name, asClause, bounds, from, forceArray = false) {
|
|
1586
|
+
let element;
|
|
1587
|
+
if (asClause) element = this.named(asClause.type, from, asClause.fixedLength);
|
|
1588
|
+
else if (name.suffix) element = scalarType(SUFFIX_TYPES[name.suffix] ?? "Double");
|
|
1589
|
+
else {
|
|
1590
|
+
const def = from.defTypes.get(name.name.charAt(0).toLowerCase());
|
|
1591
|
+
element = def ? scalarType(def) : VARIANT;
|
|
1592
|
+
}
|
|
1593
|
+
if (bounds === null && !forceArray && !asClause?.isArray) return element;
|
|
1594
|
+
const rank = bounds && bounds.length > 0 ? bounds.length : null;
|
|
1595
|
+
return {
|
|
1596
|
+
kind: "array",
|
|
1597
|
+
element,
|
|
1598
|
+
rank,
|
|
1599
|
+
fixed: rank !== null
|
|
1600
|
+
};
|
|
1601
|
+
}
|
|
1602
|
+
};
|
|
1603
|
+
// src/semantic/bind/context.ts
|
|
1604
|
+
var BindContext = class {
|
|
1605
|
+
module;
|
|
1606
|
+
procedure;
|
|
1607
|
+
scope;
|
|
1608
|
+
procedureScope;
|
|
1609
|
+
table;
|
|
1610
|
+
diagnostics;
|
|
1611
|
+
ids;
|
|
1612
|
+
types;
|
|
1613
|
+
/** The open `With` blocks, innermost last. */
|
|
1614
|
+
withStack = [];
|
|
1615
|
+
/** Every expression bound for its value in this procedure (for the implicit-call summary). */
|
|
1616
|
+
reads = [];
|
|
1617
|
+
/** The loops around the statement being bound (Exit For and Exit Do need theirs). */
|
|
1618
|
+
loopStack = [];
|
|
1619
|
+
constructor(module, procedure, scope, procedureScope, table, diagnostics, ids, types) {
|
|
1620
|
+
this.module = module;
|
|
1621
|
+
this.procedure = procedure;
|
|
1622
|
+
this.scope = scope;
|
|
1623
|
+
this.procedureScope = procedureScope;
|
|
1624
|
+
this.table = table;
|
|
1625
|
+
this.diagnostics = diagnostics;
|
|
1626
|
+
this.ids = ids;
|
|
1627
|
+
this.types = types;
|
|
1628
|
+
}
|
|
1629
|
+
bind(node, binding) {
|
|
1630
|
+
this.table.bindings.set(node, binding);
|
|
1631
|
+
return binding;
|
|
1632
|
+
}
|
|
1633
|
+
invoke(node, invocation) {
|
|
1634
|
+
this.table.invocations.set(node, invocation);
|
|
1635
|
+
}
|
|
1636
|
+
type(node, type) {
|
|
1637
|
+
this.table.types.set(node, type);
|
|
1638
|
+
return type;
|
|
1639
|
+
}
|
|
1640
|
+
report(code, span, detail) {
|
|
1641
|
+
this.module.hasErrors ||= code !== "declare-not-supported";
|
|
1642
|
+
this.diagnostics.add(this.module.name, code, span, detail);
|
|
1643
|
+
}
|
|
1644
|
+
/** Marks that the procedure touches something that may answer asynchronously. */
|
|
1645
|
+
dynamic() {
|
|
1646
|
+
if (this.procedure) this.procedure.facts.dynamic = true;
|
|
1647
|
+
}
|
|
1648
|
+
/** Implicit locals that back undeclared names resolved at run time, by lower-case name. */
|
|
1649
|
+
fallbacks = /* @__PURE__ */ new Map();
|
|
1650
|
+
/**
|
|
1651
|
+
* The implicit local behind an undeclared name that may be a host member at run time. It is not
|
|
1652
|
+
* entered in the procedure scope, so every reference stays dynamic.
|
|
1653
|
+
*/
|
|
1654
|
+
fallbackLocal(name) {
|
|
1655
|
+
const key = name.name.toLowerCase();
|
|
1656
|
+
const known = this.fallbacks.get(key);
|
|
1657
|
+
if (known) return known;
|
|
1658
|
+
const symbol = this.implicitLocal(name, false);
|
|
1659
|
+
if (symbol) this.fallbacks.set(key, symbol);
|
|
1660
|
+
return symbol;
|
|
1661
|
+
}
|
|
1662
|
+
/** Declares an implicit local for an undeclared name (no `Option Explicit`). */
|
|
1663
|
+
implicitLocal(name, enterScope = true) {
|
|
1664
|
+
const p = this.procedure;
|
|
1665
|
+
if (!p || !this.procedureScope) return null;
|
|
1666
|
+
const symbol = {
|
|
1667
|
+
kind: "variable",
|
|
1668
|
+
id: this.ids.take(),
|
|
1669
|
+
name: name.name,
|
|
1670
|
+
scope: p.declaration.isStatic ? "static" : "local",
|
|
1671
|
+
module: this.module.name,
|
|
1672
|
+
isPublic: false,
|
|
1673
|
+
type: this.types.declared(name, null, null, this.module),
|
|
1674
|
+
bounds: null,
|
|
1675
|
+
isNew: false,
|
|
1676
|
+
withEvents: false,
|
|
1677
|
+
implicit: true,
|
|
1678
|
+
slot: p.declaration.isStatic ? p.statics.length : p.params.length + 1 + p.locals.length,
|
|
1679
|
+
declaration: null,
|
|
1680
|
+
usage: new UsageFacts()
|
|
1681
|
+
};
|
|
1682
|
+
(p.declaration.isStatic ? p.statics : p.locals).push(symbol);
|
|
1683
|
+
if (enterScope) this.procedureScope.declare(symbol);
|
|
1684
|
+
return symbol;
|
|
1685
|
+
}
|
|
1686
|
+
};
|
|
1687
|
+
// src/semantic/bind/names.ts
|
|
1688
|
+
/** The static type a binding gives its node. */
|
|
1689
|
+
function bindingType(b) {
|
|
1690
|
+
switch (b.kind) {
|
|
1691
|
+
case "variable":
|
|
1692
|
+
case "param":
|
|
1693
|
+
case "result":
|
|
1694
|
+
case "implicit": return b.symbol.type;
|
|
1695
|
+
case "const": return b.symbol.type ?? VARIANT;
|
|
1696
|
+
case "enumMember": return scalarType("Long");
|
|
1697
|
+
case "libraryConstant": return b.entry.type;
|
|
1698
|
+
case "libraryFunction": return b.entry.returns;
|
|
1699
|
+
case "procedure": return b.group.reader?.returnType ?? VARIANT;
|
|
1700
|
+
case "udtField": return b.field.type;
|
|
1701
|
+
case "me": return {
|
|
1702
|
+
kind: "object",
|
|
1703
|
+
className: b.module.name,
|
|
1704
|
+
classModule: b.module.perInstance ? b.module.name : null
|
|
1705
|
+
};
|
|
1706
|
+
case "module":
|
|
1707
|
+
case "class":
|
|
1708
|
+
case "documentObject":
|
|
1709
|
+
case "hostGlobal": return OBJECT;
|
|
1710
|
+
default: return VARIANT;
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
1713
|
+
/** Resolves a simple name; reports what cannot be resolved. */
|
|
1714
|
+
function bindName(ctx, node, use, hasArgs) {
|
|
1715
|
+
const ref = node.name;
|
|
1716
|
+
const p = ctx.procedure;
|
|
1717
|
+
if (p?.result && !hasArgs && use !== "call" && use !== "callee" && ref.name.toLowerCase() === p.name.toLowerCase()) return ctx.bind(node, {
|
|
1718
|
+
kind: "result",
|
|
1719
|
+
symbol: p.result,
|
|
1720
|
+
procedure: p
|
|
1721
|
+
});
|
|
1722
|
+
let found = ctx.scope.lookup(ref.name);
|
|
1723
|
+
if (found && typeof found === "object" && found.kind === "libraryFunction" && ref.suffix === "$") {
|
|
1724
|
+
const twin = libraryEntry(`${ref.name}$`);
|
|
1725
|
+
if (twin?.kind === "function") found = {
|
|
1726
|
+
kind: "libraryFunction",
|
|
1727
|
+
entry: twin
|
|
1728
|
+
};
|
|
1729
|
+
}
|
|
1730
|
+
if (found === "ambiguous") {
|
|
1731
|
+
ctx.report("ambiguous-name", ref.span, ref.name);
|
|
1732
|
+
return ctx.bind(node, {
|
|
1733
|
+
kind: "unresolved",
|
|
1734
|
+
name: ref.name,
|
|
1735
|
+
number: 35
|
|
1736
|
+
});
|
|
1737
|
+
}
|
|
1738
|
+
if (found) {
|
|
1739
|
+
if (found.kind === "procedure" || found.kind === "declare") addCallee(ctx, found);
|
|
1740
|
+
if (found.kind === "hostGlobal") ctx.dynamic();
|
|
1741
|
+
return ctx.bind(node, found);
|
|
1742
|
+
}
|
|
1743
|
+
return ctx.bind(node, undeclared(ctx, ref, use, hasArgs));
|
|
1744
|
+
}
|
|
1745
|
+
function addCallee(ctx, b) {
|
|
1746
|
+
if (b.kind !== "procedure" || !ctx.procedure) return;
|
|
1747
|
+
for (const proc of [
|
|
1748
|
+
b.group.method,
|
|
1749
|
+
b.group.get,
|
|
1750
|
+
b.group.let,
|
|
1751
|
+
b.group.set
|
|
1752
|
+
]) if (proc) ctx.procedure.facts.callees.add(proc);
|
|
1753
|
+
}
|
|
1754
|
+
/** A name nothing declares: a host member at run time, an implicit local, or a compile error. */
|
|
1755
|
+
function undeclared(ctx, ref, use, hasArgs) {
|
|
1756
|
+
const callLike = use === "call" || use === "callee" || hasArgs;
|
|
1757
|
+
const explicit = ctx.module.options.explicit;
|
|
1758
|
+
if (ctx.scope.hasDynamicScope) {
|
|
1759
|
+
ctx.dynamic();
|
|
1760
|
+
const fallback = !explicit ? ctx.fallbackLocal(ref) : null;
|
|
1761
|
+
return {
|
|
1762
|
+
kind: "dynamic",
|
|
1763
|
+
name: ref.name,
|
|
1764
|
+
document: ctx.module.kind === "document",
|
|
1765
|
+
fallback
|
|
1766
|
+
};
|
|
1767
|
+
}
|
|
1768
|
+
if (callLike) {
|
|
1769
|
+
ctx.report("sub-or-function-not-defined", ref.span, ref.name);
|
|
1770
|
+
return {
|
|
1771
|
+
kind: "unresolved",
|
|
1772
|
+
name: ref.name,
|
|
1773
|
+
number: 35
|
|
1774
|
+
};
|
|
1775
|
+
}
|
|
1776
|
+
if (explicit || !ctx.procedure) {
|
|
1777
|
+
ctx.report("variable-not-defined", ref.span, ref.name);
|
|
1778
|
+
return {
|
|
1779
|
+
kind: "unresolved",
|
|
1780
|
+
name: ref.name,
|
|
1781
|
+
number: 35
|
|
1782
|
+
};
|
|
1783
|
+
}
|
|
1784
|
+
const symbol = ctx.implicitLocal(ref);
|
|
1785
|
+
return symbol ? {
|
|
1786
|
+
kind: "implicit",
|
|
1787
|
+
symbol
|
|
1788
|
+
} : {
|
|
1789
|
+
kind: "unresolved",
|
|
1790
|
+
name: ref.name,
|
|
1791
|
+
number: 35
|
|
1792
|
+
};
|
|
1793
|
+
}
|
|
1794
|
+
/**
|
|
1795
|
+
* Binds `object.member` once the object is bound: a qualified project or library name, a UDT
|
|
1796
|
+
* field, or a run-time member.
|
|
1797
|
+
*/
|
|
1798
|
+
function bindMember(ctx, node, objectBinding, objectType, use) {
|
|
1799
|
+
const name = node.member.name;
|
|
1800
|
+
const qualified = objectBinding ? qualifiedMember(ctx, objectBinding, node.member, use) : void 0;
|
|
1801
|
+
if (qualified) return ctx.bind(node, qualified);
|
|
1802
|
+
if (objectType.kind === "object" && objectType.classModule) {
|
|
1803
|
+
const early = classMember(ctx, objectType.classModule, node.member);
|
|
1804
|
+
if (early) return ctx.bind(node, early);
|
|
1805
|
+
}
|
|
1806
|
+
if (objectType.kind === "udt") {
|
|
1807
|
+
const index = objectType.udt.fields.findIndex((f) => f.name.toLowerCase() === name.toLowerCase());
|
|
1808
|
+
const field = objectType.udt.fields[index];
|
|
1809
|
+
if (!field) {
|
|
1810
|
+
ctx.report("method-or-data-member-not-found", node.member.span, name);
|
|
1811
|
+
return ctx.bind(node, {
|
|
1812
|
+
kind: "unresolved",
|
|
1813
|
+
name,
|
|
1814
|
+
number: 438
|
|
1815
|
+
});
|
|
1816
|
+
}
|
|
1817
|
+
return ctx.bind(node, {
|
|
1818
|
+
kind: "udtField",
|
|
1819
|
+
field,
|
|
1820
|
+
index
|
|
1821
|
+
});
|
|
1822
|
+
}
|
|
1823
|
+
ctx.dynamic();
|
|
1824
|
+
return ctx.bind(node, {
|
|
1825
|
+
kind: "member",
|
|
1826
|
+
name,
|
|
1827
|
+
objectType,
|
|
1828
|
+
dictionary: false
|
|
1829
|
+
});
|
|
1830
|
+
}
|
|
1831
|
+
function qualifiedMember(ctx, object, member, use) {
|
|
1832
|
+
const key = member.name.toLowerCase();
|
|
1833
|
+
switch (object.kind) {
|
|
1834
|
+
case "module":
|
|
1835
|
+
case "documentObject": {
|
|
1836
|
+
const symbol = object.module.members.get(key);
|
|
1837
|
+
if (symbol && isVisible(symbol, object.module, ctx.module)) {
|
|
1838
|
+
const b = memberBinding(symbol, "none");
|
|
1839
|
+
addCallee(ctx, b);
|
|
1840
|
+
return b;
|
|
1841
|
+
}
|
|
1842
|
+
if (object.kind === "documentObject") return void 0;
|
|
1843
|
+
ctx.report("method-or-data-member-not-found", member.span, member.name);
|
|
1844
|
+
return {
|
|
1845
|
+
kind: "unresolved",
|
|
1846
|
+
name: member.name,
|
|
1847
|
+
number: 438
|
|
1848
|
+
};
|
|
1849
|
+
}
|
|
1850
|
+
case "me": {
|
|
1851
|
+
const symbol = object.module.members.get(key);
|
|
1852
|
+
if (symbol && !isPublicMember(symbol)) {
|
|
1853
|
+
ctx.report("method-or-data-member-not-found", member.span, member.name);
|
|
1854
|
+
return {
|
|
1855
|
+
kind: "unresolved",
|
|
1856
|
+
name: member.name,
|
|
1857
|
+
number: 438
|
|
1858
|
+
};
|
|
1859
|
+
}
|
|
1860
|
+
if (symbol) {
|
|
1861
|
+
const b = memberBinding(symbol, object.module.perInstance ? "self" : "none");
|
|
1862
|
+
addCallee(ctx, b);
|
|
1863
|
+
return b;
|
|
1864
|
+
}
|
|
1865
|
+
return;
|
|
1866
|
+
}
|
|
1867
|
+
case "enum": {
|
|
1868
|
+
const m = object.symbol.members.find((e) => e.name.toLowerCase() === key);
|
|
1869
|
+
if (m) return {
|
|
1870
|
+
kind: "enumMember",
|
|
1871
|
+
symbol: m
|
|
1872
|
+
};
|
|
1873
|
+
ctx.report("method-or-data-member-not-found", member.span, member.name);
|
|
1874
|
+
return {
|
|
1875
|
+
kind: "unresolved",
|
|
1876
|
+
name: member.name,
|
|
1877
|
+
number: 438
|
|
1878
|
+
};
|
|
1879
|
+
}
|
|
1880
|
+
case "libraryObject": {
|
|
1881
|
+
if (object.entry.name === "Err") return {
|
|
1882
|
+
kind: "errMember",
|
|
1883
|
+
name: member.name
|
|
1884
|
+
};
|
|
1885
|
+
if (object.entry.name === "Debug") return {
|
|
1886
|
+
kind: "debugMember",
|
|
1887
|
+
name: member.name
|
|
1888
|
+
};
|
|
1889
|
+
const entry = libraryEntry(member.name);
|
|
1890
|
+
if (entry?.kind === "function") return {
|
|
1891
|
+
kind: "libraryFunction",
|
|
1892
|
+
entry
|
|
1893
|
+
};
|
|
1894
|
+
if (entry?.kind === "constant") return {
|
|
1895
|
+
kind: "libraryConstant",
|
|
1896
|
+
entry
|
|
1897
|
+
};
|
|
1898
|
+
ctx.report("method-or-data-member-not-found", member.span, member.name);
|
|
1899
|
+
return {
|
|
1900
|
+
kind: "unresolved",
|
|
1901
|
+
name: member.name,
|
|
1902
|
+
number: 438
|
|
1903
|
+
};
|
|
1904
|
+
}
|
|
1905
|
+
default: return;
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
1908
|
+
/** `object!key` or `!key`: the default member with the key as a String. */
|
|
1909
|
+
function bindDictionary(ctx, node, objectType) {
|
|
1910
|
+
ctx.dynamic();
|
|
1911
|
+
return ctx.bind(node, {
|
|
1912
|
+
kind: "member",
|
|
1913
|
+
name: node.key.name,
|
|
1914
|
+
objectType,
|
|
1915
|
+
dictionary: true
|
|
1916
|
+
});
|
|
1917
|
+
}
|
|
1918
|
+
/**
|
|
1919
|
+
* `obj.Member` where `obj` is declared as a class of the project that no class implements: the
|
|
1920
|
+
* object can only be an instance of that class (or Nothing), so a public procedure binds early
|
|
1921
|
+
* (receiver `object`), and a public field is a member read that never waits. A name the class does
|
|
1922
|
+
* not have is the editor's compile error. Returns undefined to bind the member late.
|
|
1923
|
+
*/
|
|
1924
|
+
function classMember(ctx, className, member) {
|
|
1925
|
+
const project = ctx.scope.project;
|
|
1926
|
+
const m = project.module(className);
|
|
1927
|
+
if (!m || m.kind !== "class") return void 0;
|
|
1928
|
+
const symbol = m.members.get(member.name.toLowerCase());
|
|
1929
|
+
if (!symbol) {
|
|
1930
|
+
ctx.report("method-or-data-member-not-found", member.span, member.name);
|
|
1931
|
+
return {
|
|
1932
|
+
kind: "unresolved",
|
|
1933
|
+
name: member.name,
|
|
1934
|
+
number: 438
|
|
1935
|
+
};
|
|
1936
|
+
}
|
|
1937
|
+
if (!isPublicMember(symbol)) {
|
|
1938
|
+
ctx.report("method-or-data-member-not-found", member.span, member.name);
|
|
1939
|
+
return {
|
|
1940
|
+
kind: "unresolved",
|
|
1941
|
+
name: member.name,
|
|
1942
|
+
number: 438
|
|
1943
|
+
};
|
|
1944
|
+
}
|
|
1945
|
+
if (project.isImplemented(m)) return void 0;
|
|
1946
|
+
if (symbol instanceof PropertyGroup) {
|
|
1947
|
+
if (![
|
|
1948
|
+
symbol.method,
|
|
1949
|
+
symbol.get,
|
|
1950
|
+
symbol.let,
|
|
1951
|
+
symbol.set
|
|
1952
|
+
].filter((p) => p !== null).every((p) => p.isPublic)) return void 0;
|
|
1953
|
+
const b = {
|
|
1954
|
+
kind: "procedure",
|
|
1955
|
+
group: symbol,
|
|
1956
|
+
receiver: "object"
|
|
1957
|
+
};
|
|
1958
|
+
addCallee(ctx, b);
|
|
1959
|
+
return b;
|
|
1960
|
+
}
|
|
1961
|
+
if (symbol.kind === "variable" && symbol.isPublic) return {
|
|
1962
|
+
kind: "member",
|
|
1963
|
+
name: member.name,
|
|
1964
|
+
objectType: OBJECT,
|
|
1965
|
+
dictionary: false
|
|
1966
|
+
};
|
|
1967
|
+
}
|
|
1968
|
+
/** A member on the module's public interface: a non-Private procedure (any part of a property) or variable. */
|
|
1969
|
+
function isPublicMember(symbol) {
|
|
1970
|
+
return symbol instanceof PropertyGroup ? symbol.isPublic : symbol.isPublic;
|
|
1971
|
+
}
|
|
1972
|
+
// src/semantic/bind/calls.ts
|
|
1973
|
+
/**
|
|
1974
|
+
* Binds `target(args)` (a `CallOrIndex` node, a call statement, or a bare name or member that
|
|
1975
|
+
* calls a procedure) and records the invocation on `node`. Returns the result type.
|
|
1976
|
+
*/
|
|
1977
|
+
function bindInvocation(binder, node, target, args, isStatement) {
|
|
1978
|
+
const ctx = binder.ctx;
|
|
1979
|
+
let b;
|
|
1980
|
+
let targetType = VARIANT;
|
|
1981
|
+
if (target !== node) {
|
|
1982
|
+
if (target.kind === "Name") {
|
|
1983
|
+
b = bindName(ctx, target, isStatement ? "call" : "callee", node.kind === "CallOrIndex");
|
|
1984
|
+
targetType = ctx.type(target, bindingType(b));
|
|
1985
|
+
} else targetType = binder.bind(target, "callee");
|
|
1986
|
+
ctx.type(target, targetType);
|
|
1987
|
+
}
|
|
1988
|
+
b ??= ctx.table.bindings.get(target);
|
|
1989
|
+
const invocation = decide(binder, b, target, targetType, args, node.kind === "CallOrIndex");
|
|
1990
|
+
ctx.invoke(node, invocation);
|
|
1991
|
+
if (invocation.kind === "call" && invocation.indexResult) {
|
|
1992
|
+
for (const a of args) if (a.value) binder.value(a.value);
|
|
1993
|
+
return VARIANT;
|
|
1994
|
+
}
|
|
1995
|
+
if (invocation.kind === "call" || invocation.kind === "library") {
|
|
1996
|
+
bindSite(binder, invocation.site, args);
|
|
1997
|
+
if (invocation.kind === "call") return invocation.group.reader?.returnType ?? VARIANT;
|
|
1998
|
+
const facts = libraryFacts(ctx, invocation);
|
|
1999
|
+
if (facts) ctx.invoke(node, {
|
|
2000
|
+
...invocation,
|
|
2001
|
+
...facts
|
|
2002
|
+
});
|
|
2003
|
+
return invocation.entry.returns;
|
|
2004
|
+
}
|
|
2005
|
+
for (const a of args) if (a.value) {
|
|
2006
|
+
if (invocation.kind === "index") binder.value(a.value);
|
|
2007
|
+
else binder.objectValue(a.value);
|
|
2008
|
+
}
|
|
2009
|
+
if (invocation.kind === "index") return invocation.elementType;
|
|
2010
|
+
for (const a of args) if (a.value && isReference(binder, a.value)) binder.markWrite(a.value, "byref");
|
|
2011
|
+
return VARIANT;
|
|
2012
|
+
}
|
|
2013
|
+
function decide(binder, b, target, targetType, args, indexable) {
|
|
2014
|
+
const ctx = binder.ctx;
|
|
2015
|
+
switch (b?.kind) {
|
|
2016
|
+
case "procedure": {
|
|
2017
|
+
const proc = b.group.reader ?? b.group.any;
|
|
2018
|
+
if (indexable && b.group.reader && proc.params.length === 0 && args.length > 0) return {
|
|
2019
|
+
kind: "call",
|
|
2020
|
+
group: b.group,
|
|
2021
|
+
site: {
|
|
2022
|
+
params: [],
|
|
2023
|
+
rest: []
|
|
2024
|
+
},
|
|
2025
|
+
indexResult: true
|
|
2026
|
+
};
|
|
2027
|
+
return {
|
|
2028
|
+
kind: "call",
|
|
2029
|
+
group: b.group,
|
|
2030
|
+
site: matchArgs(binder, proc.params, args, target)
|
|
2031
|
+
};
|
|
2032
|
+
}
|
|
2033
|
+
case "declare": return {
|
|
2034
|
+
kind: "declare",
|
|
2035
|
+
symbol: b.symbol
|
|
2036
|
+
};
|
|
2037
|
+
case "libraryFunction":
|
|
2038
|
+
if (ctx.procedure) ctx.procedure.facts.library.add(b.entry);
|
|
2039
|
+
if (b.entry.async) ctx.dynamic();
|
|
2040
|
+
return {
|
|
2041
|
+
kind: "library",
|
|
2042
|
+
entry: b.entry,
|
|
2043
|
+
site: matchLibrary(binder, b.entry, args, target)
|
|
2044
|
+
};
|
|
2045
|
+
case "member": return {
|
|
2046
|
+
kind: "member",
|
|
2047
|
+
name: b.name
|
|
2048
|
+
};
|
|
2049
|
+
case "dynamic": return {
|
|
2050
|
+
kind: "member",
|
|
2051
|
+
name: b.name
|
|
2052
|
+
};
|
|
2053
|
+
case "errMember":
|
|
2054
|
+
case "debugMember": return {
|
|
2055
|
+
kind: "member",
|
|
2056
|
+
name: b.name
|
|
2057
|
+
};
|
|
2058
|
+
default:
|
|
2059
|
+
if (targetType.kind === "array" && args.length > 0) return {
|
|
2060
|
+
kind: "index",
|
|
2061
|
+
elementType: targetType.element
|
|
2062
|
+
};
|
|
2063
|
+
if (targetType.kind === "object" || targetType.kind === "variant") ctx.dynamic();
|
|
2064
|
+
return { kind: "dynamic" };
|
|
2065
|
+
}
|
|
2066
|
+
}
|
|
2067
|
+
const omitted = (a) => !a || a.value === null;
|
|
2068
|
+
/** Matches arguments to a compiled procedure's parameters, reporting VBA's compile errors. */
|
|
2069
|
+
function matchArgs(binder, params, args, at, dropLast = false) {
|
|
2070
|
+
const ctx = binder.ctx;
|
|
2071
|
+
const list = dropLast ? params.slice(0, -1) : params;
|
|
2072
|
+
const paramArray = list.at(-1)?.paramArray ? list.length - 1 : -1;
|
|
2073
|
+
const slots = (paramArray >= 0 ? list.slice(0, -1) : list).map(() => null);
|
|
2074
|
+
const rest = [];
|
|
2075
|
+
let position = 0;
|
|
2076
|
+
for (const a of args) {
|
|
2077
|
+
if (a.name) {
|
|
2078
|
+
const i = list.findIndex((p) => p.name.toLowerCase() === a.name?.name.toLowerCase());
|
|
2079
|
+
if (i < 0 || i === paramArray) {
|
|
2080
|
+
ctx.report("named-argument-not-found", a.name.span, a.name.name);
|
|
2081
|
+
continue;
|
|
2082
|
+
}
|
|
2083
|
+
slots[i] = bound(binder, list[i], a.value);
|
|
2084
|
+
continue;
|
|
2085
|
+
}
|
|
2086
|
+
if (paramArray >= 0 && position >= paramArray) {
|
|
2087
|
+
rest.push(a.value);
|
|
2088
|
+
position++;
|
|
2089
|
+
continue;
|
|
2090
|
+
}
|
|
2091
|
+
const p = list[position];
|
|
2092
|
+
if (!p) {
|
|
2093
|
+
ctx.report("wrong-number-of-arguments", a.span);
|
|
2094
|
+
break;
|
|
2095
|
+
}
|
|
2096
|
+
slots[position] = omitted(a) ? null : bound(binder, p, a.value);
|
|
2097
|
+
position++;
|
|
2098
|
+
}
|
|
2099
|
+
list.forEach((p, i) => {
|
|
2100
|
+
if (!p.optional && !p.paramArray && slots[i] === null && i < slots.length) ctx.report("argument-not-optional", at.span, p.name);
|
|
2101
|
+
});
|
|
2102
|
+
return {
|
|
2103
|
+
params: slots,
|
|
2104
|
+
rest
|
|
2105
|
+
};
|
|
2106
|
+
}
|
|
2107
|
+
/** The passing form of one argument, marking a variable passed ByRef. */
|
|
2108
|
+
function bound(binder, p, e) {
|
|
2109
|
+
if (!e) return null;
|
|
2110
|
+
if (p.type.kind === "variant" || p.type.kind === "object") binder.objectValue(e);
|
|
2111
|
+
else binder.value(e);
|
|
2112
|
+
let passing = "value";
|
|
2113
|
+
if (p.passing === "ByRef") passing = isReference(binder, e) ? "ref" : "temp";
|
|
2114
|
+
if (passing === "ref") {
|
|
2115
|
+
binder.markWrite(e, "byref");
|
|
2116
|
+
checkByRefType(binder, p, e);
|
|
2117
|
+
}
|
|
2118
|
+
return {
|
|
2119
|
+
expression: e,
|
|
2120
|
+
passing
|
|
2121
|
+
};
|
|
2122
|
+
}
|
|
2123
|
+
/** True when an argument names storage the callee can write through: a variable, element or field. */
|
|
2124
|
+
function isReference(binder, e) {
|
|
2125
|
+
const t = binder.ctx.table;
|
|
2126
|
+
const b = t.bindings.get(e);
|
|
2127
|
+
switch (e.kind) {
|
|
2128
|
+
case "Name": return b?.kind === "variable" || b?.kind === "param" || b?.kind === "implicit" || b?.kind === "result" || b?.kind === "dynamic" && b.fallback !== null;
|
|
2129
|
+
case "CallOrIndex": {
|
|
2130
|
+
const inv = t.invocations.get(e);
|
|
2131
|
+
return (inv?.kind === "index" || inv?.kind === "dynamic") && isReference(binder, e.target);
|
|
2132
|
+
}
|
|
2133
|
+
case "MemberAccess": return b?.kind === "udtField" && (e.object === null || isReference(binder, e.object));
|
|
2134
|
+
default: return false;
|
|
2135
|
+
}
|
|
2136
|
+
}
|
|
2137
|
+
function checkByRefType(binder, p, e) {
|
|
2138
|
+
if (e.kind !== "Name" || p.type.kind === "variant") return;
|
|
2139
|
+
const b = binder.ctx.table.bindings.get(e);
|
|
2140
|
+
if (b?.kind !== "variable" && b?.kind !== "param" && b?.kind !== "implicit") return;
|
|
2141
|
+
const a = b.symbol.type;
|
|
2142
|
+
if (p.type.kind === "scalar" && (a.kind !== "scalar" || a.vt !== p.type.vt) || p.type.kind === "udt" && (a.kind !== "udt" || a.udt !== p.type.udt) || p.type.kind === "array" && a.kind !== "array" && a.kind !== "variant") binder.ctx.report("byref-argument-type-mismatch", e.span, e.name.name);
|
|
2143
|
+
}
|
|
2144
|
+
/** Matches arguments to a library function; every argument is passed by value. */
|
|
2145
|
+
function matchLibrary(binder, entry, args, at) {
|
|
2146
|
+
const ctx = binder.ctx;
|
|
2147
|
+
const n = entry.params.length;
|
|
2148
|
+
const fixed = entry.paramArray ? n - 1 : n;
|
|
2149
|
+
const slots = entry.params.slice(0, fixed).map(() => null);
|
|
2150
|
+
const rest = [];
|
|
2151
|
+
const positional = args.filter((a) => !a.name);
|
|
2152
|
+
const shift = entry.leadingOptional && positional.length <= entry.required ? 1 : 0;
|
|
2153
|
+
let position = shift;
|
|
2154
|
+
for (const a of args) {
|
|
2155
|
+
if (a.name) {
|
|
2156
|
+
const i = entry.params.findIndex((p) => p.toLowerCase() === a.name?.name.toLowerCase());
|
|
2157
|
+
if (i < 0 || i >= fixed) ctx.report("named-argument-not-found", a.name.span, a.name.name);
|
|
2158
|
+
else slots[i] = arg(binder, a.value);
|
|
2159
|
+
continue;
|
|
2160
|
+
}
|
|
2161
|
+
if (position >= fixed) {
|
|
2162
|
+
if (entry.paramArray && a.value) rest.push(a.value);
|
|
2163
|
+
else if (!entry.paramArray) ctx.report("wrong-number-of-arguments", a.span, entry.name);
|
|
2164
|
+
if (a.value) binder.value(a.value);
|
|
2165
|
+
position++;
|
|
2166
|
+
continue;
|
|
2167
|
+
}
|
|
2168
|
+
slots[position] = omitted(a) ? null : arg(binder, a.value);
|
|
2169
|
+
position++;
|
|
2170
|
+
}
|
|
2171
|
+
const given = slots.filter((s) => s !== null).length + rest.length;
|
|
2172
|
+
const required = Math.min(entry.required, fixed);
|
|
2173
|
+
for (let i = shift; i < required; i++) if (slots[i] === null && given < entry.required) {
|
|
2174
|
+
ctx.report("argument-not-optional", at.span, entry.params[i]);
|
|
2175
|
+
break;
|
|
2176
|
+
}
|
|
2177
|
+
return {
|
|
2178
|
+
params: slots,
|
|
2179
|
+
rest
|
|
2180
|
+
};
|
|
2181
|
+
}
|
|
2182
|
+
const arg = (binder, e) => {
|
|
2183
|
+
if (!e) return null;
|
|
2184
|
+
binder.value(e);
|
|
2185
|
+
return {
|
|
2186
|
+
expression: e,
|
|
2187
|
+
passing: "value"
|
|
2188
|
+
};
|
|
2189
|
+
};
|
|
2190
|
+
/** Binds the arguments already matched into a site (their expressions were bound by `bound`). */
|
|
2191
|
+
function bindSite(binder, site, args) {
|
|
2192
|
+
for (const e of site.rest) if (e && !binder.ctx.table.types.has(e)) binder.objectValue(e);
|
|
2193
|
+
}
|
|
2194
|
+
/** Binds an assignment to a Property Let/Set with arguments (`Foo(1) = x`, `Module2.P(i) = x`). */
|
|
2195
|
+
function propertySite(binder, group, assignment, args, at) {
|
|
2196
|
+
const proc = assignment === "Set" ? group.set : group.let;
|
|
2197
|
+
if (!proc) return null;
|
|
2198
|
+
return matchArgs(binder, proc.params, args, at, true);
|
|
2199
|
+
}
|
|
2200
|
+
/** Facts of a library call that depend on its first argument's type (typed Len, conversions). */
|
|
2201
|
+
function libraryFacts(ctx, invocation) {
|
|
2202
|
+
const first = invocation.site.params[0]?.expression ?? void 0;
|
|
2203
|
+
if (!first) return null;
|
|
2204
|
+
const model = {
|
|
2205
|
+
binding: (e) => ctx.table.bindings.get(e),
|
|
2206
|
+
typeOf: (e) => ctx.table.types.get(e) ?? VARIANT
|
|
2207
|
+
};
|
|
2208
|
+
if (invocation.entry.convention === "conversion") return isStaticallyTyped(model, first) ? { typedArgument: true } : null;
|
|
2209
|
+
const sized = typedLengthVt(model, invocation.entry.name, first);
|
|
2210
|
+
return sized === null ? null : { typedLength: sized };
|
|
2211
|
+
}
|
|
2212
|
+
// src/semantic/bind/expressions.ts
|
|
2213
|
+
const LITERAL_TYPES = {
|
|
2214
|
+
Integer: scalarType("Integer"),
|
|
2215
|
+
Long: scalarType("Long"),
|
|
2216
|
+
LongLong: scalarType("LongLong"),
|
|
2217
|
+
Single: scalarType("Single"),
|
|
2218
|
+
Double: scalarType("Double"),
|
|
2219
|
+
Currency: scalarType("Currency")
|
|
2220
|
+
};
|
|
2221
|
+
const COMPARISONS = /* @__PURE__ */ new Set([
|
|
2222
|
+
"=",
|
|
2223
|
+
"<>",
|
|
2224
|
+
"<",
|
|
2225
|
+
">",
|
|
2226
|
+
"<=",
|
|
2227
|
+
">=",
|
|
2228
|
+
"Like",
|
|
2229
|
+
"Is"
|
|
2230
|
+
]);
|
|
2231
|
+
const LOGICAL = /* @__PURE__ */ new Set([
|
|
2232
|
+
"And",
|
|
2233
|
+
"Or",
|
|
2234
|
+
"Xor",
|
|
2235
|
+
"Eqv",
|
|
2236
|
+
"Imp"
|
|
2237
|
+
]);
|
|
2238
|
+
var ExpressionBinder = class {
|
|
2239
|
+
ctx;
|
|
2240
|
+
constructor(ctx) {
|
|
2241
|
+
this.ctx = ctx;
|
|
2242
|
+
}
|
|
2243
|
+
/** Binds an expression that is read for its value. */
|
|
2244
|
+
value(e) {
|
|
2245
|
+
this.ctx.reads.push(e);
|
|
2246
|
+
return this.ctx.type(e, this.bind(e, "value"));
|
|
2247
|
+
}
|
|
2248
|
+
/** Binds a value that is passed on as it is (an object stays an object). */
|
|
2249
|
+
objectValue(e) {
|
|
2250
|
+
const t = this.value(e);
|
|
2251
|
+
this.ctx.table.objectUses.add(e);
|
|
2252
|
+
return t;
|
|
2253
|
+
}
|
|
2254
|
+
/** Binds an expression written before `.member` (it may be a module, enum or library name). */
|
|
2255
|
+
qualifier(e) {
|
|
2256
|
+
const type = this.ctx.type(e, this.bind(e, "qualifier"));
|
|
2257
|
+
return {
|
|
2258
|
+
binding: this.ctx.table.bindings.get(e) ?? null,
|
|
2259
|
+
type
|
|
2260
|
+
};
|
|
2261
|
+
}
|
|
2262
|
+
/** Binds an assignment target and marks the variable it writes. */
|
|
2263
|
+
target(e, assignment) {
|
|
2264
|
+
const type = this.ctx.type(e, this.bind(e, "target"));
|
|
2265
|
+
this.markWrite(e, assignment === "Set" ? "set" : "let");
|
|
2266
|
+
return type;
|
|
2267
|
+
}
|
|
2268
|
+
/** Marks the variable an expression stores into (`x`, `a(1)`, `u.f`, `a(1).f`). */
|
|
2269
|
+
markWrite(e, how) {
|
|
2270
|
+
let node = e;
|
|
2271
|
+
let part = false;
|
|
2272
|
+
while (node.kind === "CallOrIndex" || node.kind === "MemberAccess" || node.kind === "Paren") {
|
|
2273
|
+
if (node.kind === "Paren") return;
|
|
2274
|
+
const b = this.ctx.table.bindings.get(node);
|
|
2275
|
+
if (node.kind === "MemberAccess" && b?.kind !== "udtField") return this.sharedWrite();
|
|
2276
|
+
const inv = this.ctx.table.invocations.get(node);
|
|
2277
|
+
if (node.kind === "CallOrIndex" && inv?.kind !== "index" && inv?.kind !== "dynamic") return this.sharedWrite();
|
|
2278
|
+
if (node.kind === "CallOrIndex" && inv?.kind === "dynamic") {
|
|
2279
|
+
this.sharedWrite();
|
|
2280
|
+
this.defaultLet(null);
|
|
2281
|
+
}
|
|
2282
|
+
if (node.kind === "MemberAccess" && node.object === null) return this.sharedWrite();
|
|
2283
|
+
node = node.kind === "CallOrIndex" ? node.target : node.object;
|
|
2284
|
+
part = true;
|
|
2285
|
+
}
|
|
2286
|
+
const b = this.ctx.table.bindings.get(node);
|
|
2287
|
+
if (!b || b.kind !== "variable" && b.kind !== "param" && b.kind !== "implicit" && b.kind !== "result") return this.sharedWrite();
|
|
2288
|
+
if (b.kind === "variable" && (b.symbol.scope === "module" || b.symbol.scope === "instance" || b.symbol.scope === "static") || b.kind === "param" && b.symbol.passing === "ByRef" || how === "let" && !part && b.symbol.type.kind === "object") this.sharedWrite();
|
|
2289
|
+
if (how === "let" && !part && b.symbol.type.kind === "object") this.defaultLet(b.symbol.type);
|
|
2290
|
+
const u = b.symbol.usage;
|
|
2291
|
+
if (part) u.partWritten = true;
|
|
2292
|
+
else if (how === "let") u.letWritten = true;
|
|
2293
|
+
else if (how === "set") u.setWritten = true;
|
|
2294
|
+
else if (how === "for") u.forCounter = true;
|
|
2295
|
+
else if (how === "redim") u.redimmed = true;
|
|
2296
|
+
else if (how === "string") u.stringStatement = true;
|
|
2297
|
+
else u.passedByRef = true;
|
|
2298
|
+
}
|
|
2299
|
+
/**
|
|
2300
|
+
* A Let that assigns an object's default member runs code implicitly: the procedure gets
|
|
2301
|
+
* `implicitCalls`, and a class's default Property Let joins its callees.
|
|
2302
|
+
*/
|
|
2303
|
+
defaultLet(type) {
|
|
2304
|
+
const p = this.ctx.procedure;
|
|
2305
|
+
if (!p) return;
|
|
2306
|
+
p.facts.implicitCalls = true;
|
|
2307
|
+
if (type?.kind !== "object" || !type.classModule) return;
|
|
2308
|
+
const d = this.ctx.scope.project.module(type.classModule)?.defaultMember;
|
|
2309
|
+
const proc = d ? d.let ?? d.set : null;
|
|
2310
|
+
if (proc) p.facts.callees.add(proc);
|
|
2311
|
+
}
|
|
2312
|
+
/** Records that the procedure writes storage another activation can see. */
|
|
2313
|
+
sharedWrite() {
|
|
2314
|
+
if (this.ctx.procedure) this.ctx.procedure.facts.writesShared = true;
|
|
2315
|
+
}
|
|
2316
|
+
/** Binds any expression; `use` says how a name at its root is used. */
|
|
2317
|
+
bind(e, use) {
|
|
2318
|
+
switch (e.kind) {
|
|
2319
|
+
case "NumberLiteral": return LITERAL_TYPES[e.literalType];
|
|
2320
|
+
case "StringLiteral": return scalarType("String");
|
|
2321
|
+
case "DateLiteral": return scalarType("Date");
|
|
2322
|
+
case "BooleanLiteral": return scalarType("Boolean");
|
|
2323
|
+
case "NothingLiteral": return OBJECT;
|
|
2324
|
+
case "EmptyLiteral":
|
|
2325
|
+
case "NullLiteral": return VARIANT;
|
|
2326
|
+
case "Name": {
|
|
2327
|
+
const b = bindName(this.ctx, e, use, false);
|
|
2328
|
+
this.markRead(b, use);
|
|
2329
|
+
if (use !== "qualifier" && use !== "target" && (b.kind === "procedure" || b.kind === "libraryFunction" || b.kind === "declare")) bindInvocation(this, e, e, [], use === "call");
|
|
2330
|
+
return bindingType(b);
|
|
2331
|
+
}
|
|
2332
|
+
case "Me":
|
|
2333
|
+
if (!this.ctx.module.hasMe) this.ctx.report("invalid-use-of-me", e.span);
|
|
2334
|
+
return bindingType(this.ctx.bind(e, {
|
|
2335
|
+
kind: "me",
|
|
2336
|
+
module: this.ctx.module
|
|
2337
|
+
}));
|
|
2338
|
+
case "MemberAccess": return this.member(e, use);
|
|
2339
|
+
case "DictionaryAccess": {
|
|
2340
|
+
const objectType = e.object ? this.objectValue(e.object) : this.withSubject(e);
|
|
2341
|
+
return bindingType(bindDictionary(this.ctx, e, objectType));
|
|
2342
|
+
}
|
|
2343
|
+
case "CallOrIndex": return bindInvocation(this, e, e.target, e.args, use === "call");
|
|
2344
|
+
case "Paren": return this.value(e.expression);
|
|
2345
|
+
case "Unary": {
|
|
2346
|
+
const t = this.value(e.operand);
|
|
2347
|
+
return e.operator === "Not" || isVariant(t) ? t : t;
|
|
2348
|
+
}
|
|
2349
|
+
case "Binary":
|
|
2350
|
+
if (e.operator === "Is") return this.binary(e.operator, this.objectValue(e.left), this.objectValue(e.right));
|
|
2351
|
+
return this.binary(e.operator, this.value(e.left), this.value(e.right));
|
|
2352
|
+
case "TypeOf":
|
|
2353
|
+
this.objectValue(e.expression);
|
|
2354
|
+
return scalarType("Boolean");
|
|
2355
|
+
case "New": {
|
|
2356
|
+
const t = this.ctx.types.named(e.type, this.ctx.module);
|
|
2357
|
+
if (t.kind !== "object") this.ctx.report("invalid-qualifier", e.type.span, e.type.name);
|
|
2358
|
+
return t;
|
|
2359
|
+
}
|
|
2360
|
+
case "AddressOf": return scalarType("LongLong");
|
|
2361
|
+
case "FileNumber": return this.value(e.expression);
|
|
2362
|
+
case "InvalidExpression": return VARIANT;
|
|
2363
|
+
}
|
|
2364
|
+
}
|
|
2365
|
+
markRead(b, use) {
|
|
2366
|
+
if (use === "target") return;
|
|
2367
|
+
if (b.kind === "variable" || b.kind === "param" || b.kind === "implicit") b.symbol.usage.read = true;
|
|
2368
|
+
}
|
|
2369
|
+
member(e, use) {
|
|
2370
|
+
let objectBinding = null;
|
|
2371
|
+
let objectType;
|
|
2372
|
+
if (e.object) {
|
|
2373
|
+
const q = this.qualifier(e.object);
|
|
2374
|
+
objectBinding = q.binding;
|
|
2375
|
+
objectType = q.type;
|
|
2376
|
+
} else objectType = this.withSubject(e);
|
|
2377
|
+
const b = bindMember(this.ctx, e, objectBinding, objectType, use);
|
|
2378
|
+
if (use !== "qualifier" && use !== "target" && use !== "callee" && (b.kind === "procedure" || b.kind === "libraryFunction")) bindInvocation(this, e, e, [], use === "call");
|
|
2379
|
+
return bindingType(b);
|
|
2380
|
+
}
|
|
2381
|
+
/** The static type of the innermost With subject, recording the `.member`'s block. */
|
|
2382
|
+
withSubject(e) {
|
|
2383
|
+
const block = this.ctx.withStack.at(-1);
|
|
2384
|
+
if (!block) {
|
|
2385
|
+
this.ctx.report("invalid-qualifier", e.span);
|
|
2386
|
+
return VARIANT;
|
|
2387
|
+
}
|
|
2388
|
+
this.ctx.table.withRefs.set(e, block);
|
|
2389
|
+
return block.subjectType;
|
|
2390
|
+
}
|
|
2391
|
+
binary(op, a, b) {
|
|
2392
|
+
if (op === "Is") return scalarType("Boolean");
|
|
2393
|
+
if (isVariant(a) || isVariant(b) || a.kind !== "scalar" || b.kind !== "scalar") return VARIANT;
|
|
2394
|
+
if (COMPARISONS.has(op)) return scalarType("Boolean");
|
|
2395
|
+
if (op === "&") return scalarType("String");
|
|
2396
|
+
if (op === "/" || op === "^") return scalarType("Double");
|
|
2397
|
+
if (LOGICAL.has(op) && a.name === "Boolean" && b.name === "Boolean") return a;
|
|
2398
|
+
return widerScalar(a, b);
|
|
2399
|
+
}
|
|
2400
|
+
};
|
|
2401
|
+
// src/semantic/bind/locals.ts
|
|
2402
|
+
/** The statement lists nested in a statement (If branches, loop bodies, Case bodies). */
|
|
2403
|
+
function nestedBodies(s) {
|
|
2404
|
+
switch (s.kind) {
|
|
2405
|
+
case "If": return [...s.branches.map((b) => b.body), ...s.elseBody ? [s.elseBody] : []];
|
|
2406
|
+
case "SelectCase": return [...s.cases.map((c) => c.body), ...s.elseBody ? [s.elseBody] : []];
|
|
2407
|
+
case "For":
|
|
2408
|
+
case "ForEach":
|
|
2409
|
+
case "DoLoop":
|
|
2410
|
+
case "While":
|
|
2411
|
+
case "With": return [s.body];
|
|
2412
|
+
default: return [];
|
|
2413
|
+
}
|
|
2414
|
+
}
|
|
2415
|
+
/** Visits every statement of a body, nested ones included, in source order. */
|
|
2416
|
+
function forEachStatement(body, visit) {
|
|
2417
|
+
for (const s of body) {
|
|
2418
|
+
visit(s);
|
|
2419
|
+
for (const inner of nestedBodies(s)) forEachStatement(inner, visit);
|
|
2420
|
+
}
|
|
2421
|
+
}
|
|
2422
|
+
/** Declares a local variable (or Static local), reporting a duplicate. */
|
|
2423
|
+
function declareLocal(ctx, name, declarator, asClause, bounds, isStatic) {
|
|
2424
|
+
const p = ctx.procedure;
|
|
2425
|
+
if (!p || !ctx.procedureScope) return null;
|
|
2426
|
+
const staticStore = isStatic || p.declaration.isStatic;
|
|
2427
|
+
const symbol = {
|
|
2428
|
+
kind: "variable",
|
|
2429
|
+
id: ctx.ids.take(),
|
|
2430
|
+
name: name.name,
|
|
2431
|
+
scope: staticStore ? "static" : "local",
|
|
2432
|
+
module: ctx.module.name,
|
|
2433
|
+
isPublic: false,
|
|
2434
|
+
type: ctx.types.declared(name, asClause, bounds, ctx.module),
|
|
2435
|
+
bounds,
|
|
2436
|
+
isNew: asClause?.isNew ?? false,
|
|
2437
|
+
withEvents: false,
|
|
2438
|
+
implicit: false,
|
|
2439
|
+
slot: staticStore ? p.statics.length : p.params.length + 1 + p.locals.length,
|
|
2440
|
+
declaration: declarator,
|
|
2441
|
+
usage: new UsageFacts()
|
|
2442
|
+
};
|
|
2443
|
+
if (!ctx.procedureScope.declare(symbol)) {
|
|
2444
|
+
ctx.report("duplicate-declaration", name.span, name.name);
|
|
2445
|
+
return null;
|
|
2446
|
+
}
|
|
2447
|
+
(staticStore ? p.statics : p.locals).push(symbol);
|
|
2448
|
+
return symbol;
|
|
2449
|
+
}
|
|
2450
|
+
function declareLocalConst(ctx, s, d) {
|
|
2451
|
+
const p = ctx.procedure;
|
|
2452
|
+
if (!p || !ctx.procedureScope) return null;
|
|
2453
|
+
const symbol = {
|
|
2454
|
+
kind: "const",
|
|
2455
|
+
id: ctx.ids.take(),
|
|
2456
|
+
name: d.name.name,
|
|
2457
|
+
module: ctx.module.name,
|
|
2458
|
+
procedure: p.name,
|
|
2459
|
+
isPublic: false,
|
|
2460
|
+
type: d.asClause ? ctx.types.named(d.asClause.type, ctx.module, d.asClause.fixedLength) : null,
|
|
2461
|
+
value: d.value,
|
|
2462
|
+
declaration: s,
|
|
2463
|
+
nameRef: d.name
|
|
2464
|
+
};
|
|
2465
|
+
if (!ctx.procedureScope.declare(symbol)) {
|
|
2466
|
+
ctx.report("duplicate-declaration", d.name.span, d.name.name);
|
|
2467
|
+
return null;
|
|
2468
|
+
}
|
|
2469
|
+
p.consts.push(symbol);
|
|
2470
|
+
return symbol;
|
|
2471
|
+
}
|
|
2472
|
+
/** Collects labels and `Dim`/`Static` locals of a body before it is bound. */
|
|
2473
|
+
function collectLocals(ctx, body) {
|
|
2474
|
+
const p = ctx.procedure;
|
|
2475
|
+
if (!p) return;
|
|
2476
|
+
forEachStatement(body, (s) => {
|
|
2477
|
+
if (s.kind === "Label") {
|
|
2478
|
+
const key = s.label.name.toLowerCase();
|
|
2479
|
+
if (p.labels.has(key)) ctx.report("duplicate-declaration", s.label.span, s.label.name);
|
|
2480
|
+
else p.labels.set(key, s);
|
|
2481
|
+
if (s.label.isLineNumber) p.facts.hasLineNumbers = true;
|
|
2482
|
+
} else if (s.kind === "VariableDeclaration") for (const d of s.declarators) declareLocal(ctx, d.name, d, d.asClause, d.dimensions?.bounds ?? null, s.keyword === "Static");
|
|
2483
|
+
});
|
|
2484
|
+
}
|
|
2485
|
+
// src/semantic/bind/statements.ts
|
|
2486
|
+
/** Expression-valued fields of the file statements (which raise error 445 when run). */
|
|
2487
|
+
const FILE_FIELDS = [
|
|
2488
|
+
"path",
|
|
2489
|
+
"fileNumber",
|
|
2490
|
+
"recordLength",
|
|
2491
|
+
"recordNumber",
|
|
2492
|
+
"target",
|
|
2493
|
+
"position",
|
|
2494
|
+
"from",
|
|
2495
|
+
"to",
|
|
2496
|
+
"width"
|
|
2497
|
+
];
|
|
2498
|
+
/** Binds a loop body with the loop on the stack Exit For and Exit Do check. */
|
|
2499
|
+
function loop(b, kind, body) {
|
|
2500
|
+
b.expr.ctx.loopStack.push(kind);
|
|
2501
|
+
b.block(body);
|
|
2502
|
+
b.expr.ctx.loopStack.pop();
|
|
2503
|
+
}
|
|
2504
|
+
const HANDLERS = {
|
|
2505
|
+
Label: () => void 0,
|
|
2506
|
+
AttributeStatement: () => void 0,
|
|
2507
|
+
InvalidStatement: () => void 0,
|
|
2508
|
+
Assignment: (b, s) => b.assignment(s.target, s.value, s.assignment),
|
|
2509
|
+
Call: (b, s) => {
|
|
2510
|
+
bindInvocation(b.expr, s, s.callee, s.args, true);
|
|
2511
|
+
},
|
|
2512
|
+
If: (b, s) => {
|
|
2513
|
+
for (const branch of s.branches) {
|
|
2514
|
+
b.expr.value(branch.condition);
|
|
2515
|
+
b.block(branch.body);
|
|
2516
|
+
}
|
|
2517
|
+
if (s.elseBody) b.block(s.elseBody);
|
|
2518
|
+
},
|
|
2519
|
+
SelectCase: (b, s) => {
|
|
2520
|
+
b.expr.value(s.subject);
|
|
2521
|
+
for (const c of s.cases) {
|
|
2522
|
+
for (const t of c.tests) if (t.kind === "CaseRange") {
|
|
2523
|
+
b.expr.value(t.from);
|
|
2524
|
+
b.expr.value(t.to);
|
|
2525
|
+
} else b.expr.value(t.value);
|
|
2526
|
+
b.block(c.body);
|
|
2527
|
+
}
|
|
2528
|
+
if (s.elseBody) b.block(s.elseBody);
|
|
2529
|
+
},
|
|
2530
|
+
For: (b, s) => {
|
|
2531
|
+
b.expr.target(s.counter, "Let");
|
|
2532
|
+
b.expr.markWrite(s.counter, "for");
|
|
2533
|
+
b.expr.value(s.start);
|
|
2534
|
+
b.expr.value(s.end);
|
|
2535
|
+
if (s.step) b.expr.value(s.step);
|
|
2536
|
+
loop(b, "For", s.body);
|
|
2537
|
+
},
|
|
2538
|
+
ForEach: (b, s) => {
|
|
2539
|
+
b.expr.target(s.element, "Let");
|
|
2540
|
+
b.expr.markWrite(s.element, "for");
|
|
2541
|
+
b.expr.value(s.collection);
|
|
2542
|
+
loop(b, "For", s.body);
|
|
2543
|
+
},
|
|
2544
|
+
DoLoop: (b, s) => {
|
|
2545
|
+
if (s.condition) b.expr.value(s.condition.expression);
|
|
2546
|
+
loop(b, "Do", s.body);
|
|
2547
|
+
},
|
|
2548
|
+
While: (b, s) => {
|
|
2549
|
+
b.expr.value(s.condition);
|
|
2550
|
+
b.block(s.body);
|
|
2551
|
+
},
|
|
2552
|
+
With: (b, s) => {
|
|
2553
|
+
const subjectType = b.expr.objectValue(s.object);
|
|
2554
|
+
const ctx = b.expr.ctx;
|
|
2555
|
+
const block = {
|
|
2556
|
+
id: ctx.procedure?.withBlocks.length ?? 0,
|
|
2557
|
+
depth: ctx.withStack.length,
|
|
2558
|
+
statement: s,
|
|
2559
|
+
subjectType
|
|
2560
|
+
};
|
|
2561
|
+
ctx.procedure?.withBlocks.push(block);
|
|
2562
|
+
ctx.withStack.push(block);
|
|
2563
|
+
b.block(s.body);
|
|
2564
|
+
ctx.withStack.pop();
|
|
2565
|
+
},
|
|
2566
|
+
Exit: (b, s) => {
|
|
2567
|
+
const p = b.expr.ctx.procedure;
|
|
2568
|
+
if (s.target === "Do" || s.target === "For") {
|
|
2569
|
+
if (!b.expr.ctx.loopStack.includes(s.target)) b.expr.ctx.report("exit-not-in-loop", s.span, s.target);
|
|
2570
|
+
return;
|
|
2571
|
+
}
|
|
2572
|
+
if (!p) return;
|
|
2573
|
+
const kind = p.declaration.procedureKind;
|
|
2574
|
+
if (!(s.target === "Sub" ? kind === "Sub" : s.target === "Function" ? kind === "Function" : kind.startsWith("Property"))) b.expr.ctx.report("exit-not-allowed", s.span, s.target);
|
|
2575
|
+
},
|
|
2576
|
+
GoTo: (b, s) => {
|
|
2577
|
+
const f = b.facts();
|
|
2578
|
+
if (f) {
|
|
2579
|
+
if (s.kind === "GoSub") f.hasGoSub = true;
|
|
2580
|
+
else f.hasGoTo = true;
|
|
2581
|
+
}
|
|
2582
|
+
b.label(s.label);
|
|
2583
|
+
},
|
|
2584
|
+
GoSub: (b, s) => HANDLERS.GoTo(b, s),
|
|
2585
|
+
Return: () => void 0,
|
|
2586
|
+
Stop: (b) => {
|
|
2587
|
+
const f = b.facts();
|
|
2588
|
+
if (f) f.hasEnd = true;
|
|
2589
|
+
},
|
|
2590
|
+
End: (b) => {
|
|
2591
|
+
const f = b.facts();
|
|
2592
|
+
if (f) f.hasEnd = true;
|
|
2593
|
+
},
|
|
2594
|
+
OnError: (b, s) => {
|
|
2595
|
+
const f = b.facts();
|
|
2596
|
+
if (f) f.hasOnError = true;
|
|
2597
|
+
if (s.action === "goto" && s.label) b.label(s.label);
|
|
2598
|
+
},
|
|
2599
|
+
Resume: (b, s) => {
|
|
2600
|
+
const f = b.facts();
|
|
2601
|
+
if (f) f.hasResume = true;
|
|
2602
|
+
if (s.action === "label" && s.label) b.label(s.label);
|
|
2603
|
+
},
|
|
2604
|
+
OnGoTo: (b, s) => {
|
|
2605
|
+
const f = b.facts();
|
|
2606
|
+
if (f) {
|
|
2607
|
+
f.hasOnGoTo = true;
|
|
2608
|
+
if (s.gosub) f.hasGoSub = true;
|
|
2609
|
+
}
|
|
2610
|
+
b.expr.value(s.selector);
|
|
2611
|
+
for (const l of s.labels) b.label(l);
|
|
2612
|
+
},
|
|
2613
|
+
ReDim: (b, s) => {
|
|
2614
|
+
for (const clause of s.clauses) {
|
|
2615
|
+
if (clause.target.kind === "Name" && !b.expr.ctx.scope.lookup(clause.target.name.name)) declareLocal(b.expr.ctx, clause.target.name, null, clause.asClause, [], false);
|
|
2616
|
+
b.expr.target(clause.target, "Let");
|
|
2617
|
+
b.expr.markWrite(clause.target, "redim");
|
|
2618
|
+
for (const bound of clause.bounds) {
|
|
2619
|
+
if (bound.lower) b.expr.value(bound.lower);
|
|
2620
|
+
b.expr.value(bound.upper);
|
|
2621
|
+
}
|
|
2622
|
+
}
|
|
2623
|
+
},
|
|
2624
|
+
Erase: (b, s) => {
|
|
2625
|
+
for (const t of s.targets) {
|
|
2626
|
+
b.expr.target(t, "Let");
|
|
2627
|
+
b.expr.markWrite(t, "redim");
|
|
2628
|
+
}
|
|
2629
|
+
},
|
|
2630
|
+
RaiseEvent: (b, s) => {
|
|
2631
|
+
const ctx = b.expr.ctx;
|
|
2632
|
+
if (!ctx.module.events.find((e) => e.name.toLowerCase() === s.name.name.toLowerCase())) ctx.report("method-or-data-member-not-found", s.name.span, s.name.name);
|
|
2633
|
+
const f = b.facts();
|
|
2634
|
+
if (f) f.raisesEvents = true;
|
|
2635
|
+
ctx.dynamic();
|
|
2636
|
+
for (const a of s.args) if (a.value) {
|
|
2637
|
+
b.expr.value(a.value);
|
|
2638
|
+
if (isReference(b.expr, a.value)) b.expr.markWrite(a.value, "byref");
|
|
2639
|
+
}
|
|
2640
|
+
},
|
|
2641
|
+
MidAssignment: (b, s) => {
|
|
2642
|
+
b.expr.target(s.target, "Let");
|
|
2643
|
+
b.expr.markWrite(s.target, "string");
|
|
2644
|
+
b.expr.value(s.start);
|
|
2645
|
+
if (s.length) b.expr.value(s.length);
|
|
2646
|
+
b.expr.value(s.value);
|
|
2647
|
+
},
|
|
2648
|
+
LSet: (b, s) => b.stringStatement(s.target, s.value),
|
|
2649
|
+
RSet: (b, s) => b.stringStatement(s.target, s.value),
|
|
2650
|
+
Name: (b, s) => {
|
|
2651
|
+
b.expr.value(s.oldPath);
|
|
2652
|
+
b.expr.value(s.newPath);
|
|
2653
|
+
},
|
|
2654
|
+
Error: (b, s) => {
|
|
2655
|
+
b.expr.value(s.number);
|
|
2656
|
+
},
|
|
2657
|
+
Print: (b, s) => {
|
|
2658
|
+
if (s.fileNumber) b.expr.value(s.fileNumber);
|
|
2659
|
+
for (const item of s.items) if (item.value) b.expr.value(item.value);
|
|
2660
|
+
},
|
|
2661
|
+
Open: (b, s) => b.fileStatement(s),
|
|
2662
|
+
Close: (b, s) => b.fileStatement(s),
|
|
2663
|
+
Input: (b, s) => b.fileStatement(s),
|
|
2664
|
+
LineInput: (b, s) => b.fileStatement(s),
|
|
2665
|
+
Write: (b, s) => b.fileStatement(s),
|
|
2666
|
+
Get: (b, s) => b.fileStatement(s),
|
|
2667
|
+
Put: (b, s) => b.fileStatement(s),
|
|
2668
|
+
Seek: (b, s) => b.fileStatement(s),
|
|
2669
|
+
Lock: (b, s) => b.fileStatement(s),
|
|
2670
|
+
Unlock: (b, s) => b.fileStatement(s),
|
|
2671
|
+
Width: (b, s) => b.fileStatement(s),
|
|
2672
|
+
VariableDeclaration: (b, s) => {
|
|
2673
|
+
for (const d of s.declarators) {
|
|
2674
|
+
for (const bound of d.dimensions?.bounds ?? []) {
|
|
2675
|
+
if (bound.lower) b.expr.value(bound.lower);
|
|
2676
|
+
b.expr.value(bound.upper);
|
|
2677
|
+
}
|
|
2678
|
+
if (d.asClause?.fixedLength) b.expr.value(d.asClause.fixedLength);
|
|
2679
|
+
}
|
|
2680
|
+
},
|
|
2681
|
+
ConstDeclaration: (b, s) => {
|
|
2682
|
+
for (const d of s.declarators) {
|
|
2683
|
+
b.expr.value(d.value);
|
|
2684
|
+
declareLocalConst(b.expr.ctx, s, d);
|
|
2685
|
+
}
|
|
2686
|
+
}
|
|
2687
|
+
};
|
|
2688
|
+
var StatementBinder = class {
|
|
2689
|
+
expr;
|
|
2690
|
+
constructor(expr) {
|
|
2691
|
+
this.expr = expr;
|
|
2692
|
+
}
|
|
2693
|
+
block(body) {
|
|
2694
|
+
for (const s of body) this.statement(s);
|
|
2695
|
+
}
|
|
2696
|
+
statement(s) {
|
|
2697
|
+
HANDLERS[s.kind](this, s);
|
|
2698
|
+
}
|
|
2699
|
+
facts() {
|
|
2700
|
+
return this.expr.ctx.procedure?.facts;
|
|
2701
|
+
}
|
|
2702
|
+
/** Reports a jump to a label the procedure does not define. */
|
|
2703
|
+
label(l) {
|
|
2704
|
+
const p = this.expr.ctx.procedure;
|
|
2705
|
+
if (!p) return;
|
|
2706
|
+
if (l.isLineNumber && (l.name === "0" || l.name === "-1")) return;
|
|
2707
|
+
if (!p.labels.has(l.name.toLowerCase())) this.expr.ctx.report("label-not-defined", l.span, l.name);
|
|
2708
|
+
}
|
|
2709
|
+
/** `target = value` / `Set target = value`, including Property Let/Set targets. */
|
|
2710
|
+
assignment(target, value, assignment) {
|
|
2711
|
+
if (assignment === "Set") this.expr.objectValue(value);
|
|
2712
|
+
else this.expr.value(value);
|
|
2713
|
+
const ctx = this.expr.ctx;
|
|
2714
|
+
const args = target.kind === "CallOrIndex" ? target.args : [];
|
|
2715
|
+
const head = target.kind === "CallOrIndex" ? target.target : target;
|
|
2716
|
+
this.expr.target(target, assignment);
|
|
2717
|
+
const b = ctx.table.bindings.get(head);
|
|
2718
|
+
if (b?.kind === "procedure" && (head.kind === "Name" || head.kind === "MemberAccess")) {
|
|
2719
|
+
const site = propertySite(this.expr, b.group, assignment, args, target);
|
|
2720
|
+
if (site) ctx.invoke(target, {
|
|
2721
|
+
kind: "call",
|
|
2722
|
+
group: b.group,
|
|
2723
|
+
site
|
|
2724
|
+
});
|
|
2725
|
+
else ctx.report("wrong-number-of-arguments", target.span, b.group.name);
|
|
2726
|
+
}
|
|
2727
|
+
}
|
|
2728
|
+
stringStatement(target, value) {
|
|
2729
|
+
this.expr.target(target, "Let");
|
|
2730
|
+
this.expr.markWrite(target, "string");
|
|
2731
|
+
this.expr.value(value);
|
|
2732
|
+
}
|
|
2733
|
+
fileStatement(s) {
|
|
2734
|
+
const record = s;
|
|
2735
|
+
for (const field of FILE_FIELDS) {
|
|
2736
|
+
const v = record[field];
|
|
2737
|
+
if (v && typeof v === "object" && "kind" in v) this.expr.value(v);
|
|
2738
|
+
}
|
|
2739
|
+
for (const field of ["fileNumbers", "targets"]) {
|
|
2740
|
+
const list = record[field];
|
|
2741
|
+
if (Array.isArray(list)) for (const e of list) this.expr.value(e);
|
|
2742
|
+
}
|
|
2743
|
+
const items = record.items;
|
|
2744
|
+
if (Array.isArray(items)) for (const item of items) {
|
|
2745
|
+
const v = item.value;
|
|
2746
|
+
if (v) this.expr.value(v);
|
|
2747
|
+
}
|
|
2748
|
+
}
|
|
2749
|
+
};
|
|
2750
|
+
// src/semantic/bind/program.ts
|
|
2751
|
+
/** Binds a project: every module, every name, call and `With` member. Never throws on bad code. */
|
|
2752
|
+
function bindProgram(inputs, options = {}) {
|
|
2753
|
+
const sink = new DiagnosticSink();
|
|
2754
|
+
const ids = new IdSource();
|
|
2755
|
+
const index = new TypeIndex();
|
|
2756
|
+
const types = new TypeResolver(index);
|
|
2757
|
+
const table = new BindingTable();
|
|
2758
|
+
const declarer = new ModuleDeclarer(ids, index, types, sink);
|
|
2759
|
+
const modules = inputs.map((input) => {
|
|
2760
|
+
const { module: ast, diagnostics } = parseModule(input.source, {
|
|
2761
|
+
...options.parse,
|
|
2762
|
+
moduleKind: input.kind,
|
|
2763
|
+
...options.constants ? { constants: options.constants } : {}
|
|
2764
|
+
});
|
|
2765
|
+
const m = new BoundModule(input.name, input.kind, ast);
|
|
2766
|
+
for (const d of diagnostics) {
|
|
2767
|
+
sink.addParsed(m.name, d);
|
|
2768
|
+
if (d.severity === "error") m.hasErrors = true;
|
|
2769
|
+
}
|
|
2770
|
+
return m;
|
|
2771
|
+
});
|
|
2772
|
+
for (const m of modules) declarer.collectTypes(m);
|
|
2773
|
+
for (const m of modules) declarer.declareMembers(m);
|
|
2774
|
+
const lower = (names) => new Set([...names ?? []].map((n) => n.toLowerCase()));
|
|
2775
|
+
const project = new ProjectScope(modules, {
|
|
2776
|
+
globals: lower(options.globals),
|
|
2777
|
+
globalObject: options.globalObject ?? false,
|
|
2778
|
+
documents: lower(options.documentObjects)
|
|
2779
|
+
});
|
|
2780
|
+
const make = (m, p, scope) => new BindContext(m, p, new ScopeChain(m, project, scope), scope, table, sink, ids, types);
|
|
2781
|
+
for (const m of modules) {
|
|
2782
|
+
bindModuleLevel(new ExpressionBinder(make(m, null, null)), m);
|
|
2783
|
+
for (const p of m.procedures) {
|
|
2784
|
+
const scope = new ProcedureScope();
|
|
2785
|
+
for (const param of p.params) scope.declare(param);
|
|
2786
|
+
const ctx = make(m, p, scope);
|
|
2787
|
+
collectLocals(ctx, p.declaration.body);
|
|
2788
|
+
new StatementBinder(new ExpressionBinder(ctx)).block(p.declaration.body);
|
|
2789
|
+
summarizeImplicitCalls(ctx, p);
|
|
2790
|
+
}
|
|
2791
|
+
orderConsts(m, table);
|
|
2792
|
+
connectHandlers(m, sink);
|
|
2793
|
+
}
|
|
2794
|
+
for (const d of sink.items) {
|
|
2795
|
+
if (d.severity !== "error") continue;
|
|
2796
|
+
const m = modules.find((x) => x.name === d.module);
|
|
2797
|
+
if (m) m.hasErrors = true;
|
|
2798
|
+
}
|
|
2799
|
+
return new BoundProgram(modules, sink.items, table);
|
|
2800
|
+
}
|
|
2801
|
+
/** Binds the constant expressions at module level: Const values, Enum values, bounds, defaults. */
|
|
2802
|
+
function bindModuleLevel(binder, m) {
|
|
2803
|
+
for (const c of m.consts) binder.value(c.value);
|
|
2804
|
+
for (const e of m.enums) for (const member of e.members) if (member.value) binder.value(member.value);
|
|
2805
|
+
for (const v of m.variables) {
|
|
2806
|
+
for (const b of v.bounds ?? []) {
|
|
2807
|
+
if (b.lower) binder.value(b.lower);
|
|
2808
|
+
binder.value(b.upper);
|
|
2809
|
+
}
|
|
2810
|
+
const fixed = v.declaration?.asClause?.fixedLength;
|
|
2811
|
+
if (fixed) binder.value(fixed);
|
|
2812
|
+
}
|
|
2813
|
+
for (const u of m.udts) for (const f of u.fields) {
|
|
2814
|
+
for (const b of f.bounds ?? []) {
|
|
2815
|
+
if (b.lower) binder.value(b.lower);
|
|
2816
|
+
binder.value(b.upper);
|
|
2817
|
+
}
|
|
2818
|
+
if (f.type.kind === "scalar" && f.type.fixedLength) binder.value(f.type.fixedLength);
|
|
2819
|
+
}
|
|
2820
|
+
for (const p of m.procedures) for (const param of p.params) if (param.defaultValue) binder.value(param.defaultValue);
|
|
2821
|
+
}
|
|
2822
|
+
/** Sorts the module's constants so each follows the constants of its own module it uses. */
|
|
2823
|
+
function orderConsts(m, table) {
|
|
2824
|
+
const done = /* @__PURE__ */ new Set();
|
|
2825
|
+
const sorted = [];
|
|
2826
|
+
const visiting = /* @__PURE__ */ new Set();
|
|
2827
|
+
const uses = (e, out) => {
|
|
2828
|
+
const b = table.bindings.get(e);
|
|
2829
|
+
if (b?.kind === "const" && b.symbol.module === m.name && b.symbol.procedure === null) out.push(b.symbol);
|
|
2830
|
+
forEachChild(e, (child) => uses(child, out));
|
|
2831
|
+
};
|
|
2832
|
+
const visit = (c) => {
|
|
2833
|
+
if (done.has(c) || visiting.has(c)) return;
|
|
2834
|
+
visiting.add(c);
|
|
2835
|
+
const deps = [];
|
|
2836
|
+
uses(c.value, deps);
|
|
2837
|
+
for (const d of deps) visit(d);
|
|
2838
|
+
visiting.delete(c);
|
|
2839
|
+
done.add(c);
|
|
2840
|
+
sorted.push(c);
|
|
2841
|
+
};
|
|
2842
|
+
for (const c of m.consts) visit(c);
|
|
2843
|
+
m.consts.splice(0, m.consts.length, ...sorted);
|
|
2844
|
+
}
|
|
2845
|
+
/** Finds the `<variable>_<event>` handlers of the module's `WithEvents` variables. */
|
|
2846
|
+
function connectHandlers(m, sink) {
|
|
2847
|
+
for (const v of m.variables) {
|
|
2848
|
+
if (!v.withEvents) continue;
|
|
2849
|
+
if (m.kind === "standard") {
|
|
2850
|
+
const span = v.declaration?.span;
|
|
2851
|
+
if (span) sink.add(m.name, "only-valid-in-object-module", span);
|
|
2852
|
+
continue;
|
|
2853
|
+
}
|
|
2854
|
+
const prefix = `${v.name.toLowerCase()}_`;
|
|
2855
|
+
const events = /* @__PURE__ */ new Map();
|
|
2856
|
+
for (const [key, group] of m.groups) if (key.startsWith(prefix) && group.method?.kind === "Sub") events.set(key.slice(prefix.length), group.method);
|
|
2857
|
+
m.eventHandlers.set(v.name.toLowerCase(), events);
|
|
2858
|
+
}
|
|
2859
|
+
}
|
|
2860
|
+
/**
|
|
2861
|
+
* `ProcedureFacts.implicitCalls`: the procedure reads a value that may run code implicitly, and the
|
|
2862
|
+
* default member of each class-typed operand it reads that way joins its callees.
|
|
2863
|
+
*/
|
|
2864
|
+
function summarizeImplicitCalls(ctx, p) {
|
|
2865
|
+
for (const e of ctx.reads) {
|
|
2866
|
+
if (!readMayCall(ctx.table, e)) continue;
|
|
2867
|
+
p.facts.implicitCalls = true;
|
|
2868
|
+
const t = ctx.table.types.get(e);
|
|
2869
|
+
if (t?.kind !== "object" || !t.classModule) continue;
|
|
2870
|
+
const d = ctx.scope.project.module(t.classModule)?.defaultMember;
|
|
2871
|
+
const proc = d ? d.reader ?? d.method ?? d.any : null;
|
|
2872
|
+
if (proc) p.facts.callees.add(proc);
|
|
2873
|
+
}
|
|
2874
|
+
}
|
|
2875
|
+
export { UsageFacts as C, PropertyGroup as E, vtOfScalar as S, ProcedureFacts as T, OBJECT as _, libraryEntry as a, scalarType as b, twin as c, BoundProgram as d, isTypedOperand as f, SEMANTIC_MESSAGES as g, SEMANTIC_ERROR_NUMBERS as h, libraryEntries as i, LIBRARY_CONSTANTS as l, BoundModule as m, forEachStatement as n, LIBRARY_FUNCTIONS as o, typedLengthVt as p, nestedBodies as r, fn as s, bindProgram as t, BindingTable as u, VARIANT as v, BoundProcedure as w, storageVt as x, isVariant as y };
|
|
2876
|
+
|
|
2877
|
+
//# sourceMappingURL=semantic-CAVxm72C.js.map
|