1 | sclass LASScope {
|
2 | // do we use FixedVarContext instead of FlexibleVarContext |
3 | settable bool useFixedVars; |
4 | |
5 | // variables declared in this scope, with type/value description |
6 | gettable new Map<S, LASValueDescriptor> declaredVars; |
7 | |
8 | // optional parent scope |
9 | // (we can see the parent's variables in this scope too, unless they |
10 | // are redeclared) |
11 | settable LASScope parentScope; |
12 | |
13 | // true = we may outlive the parent scope |
14 | // (e.g. when we're a lambda) |
15 | settable bool parentIsDetached; |
16 | |
17 | // sorted names when scope is finalized (resolved) |
18 | S[] names; |
19 | |
20 | *() {}
|
21 | *(LASScope *parentScope) {}
|
22 | |
23 | bool resolved() { ret names != null; }
|
24 | |
25 | void addDeclaredVar(S name, LASValueDescriptor type) {
|
26 | if (resolved()) |
27 | fail("Can't add variables to resolved scope");
|
28 | declaredVars.put(name, type); |
29 | } |
30 | |
31 | int resolveVar(S name) {
|
32 | resolve(); |
33 | int idx = indexOfInSortedArray(names, name); |
34 | if (idx < 0) |
35 | fail("Variable not found in scope: " + name);
|
36 | ret idx; |
37 | } |
38 | |
39 | void resolve {
|
40 | if (names != null) ret; |
41 | names = empty(declaredVars) ? null |
42 | : toStringArray(sortedKeys(declaredVars)); |
43 | } |
44 | } |
Began life as a copy of #1035285
download show line numbers debug dex old transpilations
Travelled to 2 computer(s): mowyntqkapby, mqqgnosmbjvj
No comments. add comment
| Snippet ID: | #1036501 |
| Snippet name: | LASScope - a variable scope created during script parsing (old) |
| Eternal ID of this version: | #1036501/1 |
| Text MD5: | 3267c33e0dc514264395f2761f33ef9f |
| Author: | stefan |
| Category: | javax / parsing |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2023-01-01 19:36:19 |
| Source code size: | 1193 bytes / 44 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 439 / 459 |
| Referenced in: | [show references] |