Transpiled version (10093L) is out of date.
1 | // TODO: Store Class AND Type |
2 | |
3 | // Describes a value during script optimization/type inference. |
4 | |
5 | // In the best case, the exact value is known. |
6 | // Next best case is we're knowing its precise type (value of object.getClass()). |
7 | // Third best case is we're knowing it's castable to a certain type. |
8 | // A completely unknown value is described simply by "new LASValueDescriptor". |
9 | |
10 | persistable sclass LASValueDescriptor {
|
11 | bool knownValue() { false; }
|
12 | O value() { null; }
|
13 | |
14 | Type type() { ret javaClass(); }
|
15 | |
16 | Class javaClass() { null; }
|
17 | bool javaClassIsExact() { false; }
|
18 | bool canBeNull() { true; }
|
19 | |
20 | bool canFail() { false; }
|
21 | bool willFail() { false; }
|
22 | |
23 | srecord Exact(Class c, bool canBeNull) > LASValueDescriptor {
|
24 | Class javaClass() { ret c; }
|
25 | bool javaClassIsExact() { true; }
|
26 | bool canBeNull() { ret canBeNull; }
|
27 | } |
28 | |
29 | srecord NonExact(Class c, bool canBeNull) > LASValueDescriptor {
|
30 | Class javaClass() { ret c; }
|
31 | bool javaClassIsExact() { false; }
|
32 | bool canBeNull() { ret canBeNull; }
|
33 | } |
34 | |
35 | // only returns a type(), not a javaClass() |
36 | // (e.g. for LAS classes still being defined) |
37 | srecord NonExactType(Type type, bool canBeNull) > LASValueDescriptor {
|
38 | Type type() { ret type; }
|
39 | bool javaClassIsExact() { false; }
|
40 | bool canBeNull() { ret canBeNull; }
|
41 | } |
42 | |
43 | static LASValueDescriptor nonExactCanBeNull(Type c) {
|
44 | ret new NonExact(typeToClass(c), true); |
45 | } |
46 | |
47 | srecord KnownValue(O value) > LASValueDescriptor {
|
48 | bool knownValue() { true; }
|
49 | O value() { ret value; }
|
50 | |
51 | Class javaClass() { ret value?.getClass(); }
|
52 | bool javaClassIsExact() { ret value != null; }
|
53 | bool canBeNull() { ret value == null; }
|
54 | } |
55 | |
56 | // Indicates an exception can be thrown instead of returning a value. |
57 | // Probably we don't need this. |
58 | sclass WillFail > LASValueDescriptor {
|
59 | bool canFail() { true; }
|
60 | bool willFail() { true; }
|
61 | } |
62 | |
63 | static LASValueDescriptor fromClass(Class c) {
|
64 | ret new NonExact(c, true); |
65 | } |
66 | |
67 | static LASValueDescriptor fromType(Type type) {
|
68 | ret new NonExact(typeToClass(type), true); |
69 | } |
70 | |
71 | toString {
|
72 | ret "LASValueDescriptor " + javaClass(); |
73 | } |
74 | } |
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
| Snippet ID: | #1034290 |
| Snippet name: | LASValueDescriptor |
| Eternal ID of this version: | #1034290/19 |
| Text MD5: | b88c281fd5eed2c177f01b2442f65e02 |
| Author: | stefan |
| Category: | javax / left arrow script |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2023-03-12 17:32:04 |
| Source code size: | 2233 bytes / 74 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 939 / 1201 |
| Version history: | 18 change(s) |
| Referenced in: | [show references] |