Transpiled version (5830L) is out of date.
1 | static void tok_simplyCachedFunctions(L<S> tok) { pcall { |
2 | int i = -1; |
3 | while ((i = jfind(tok, i+1, "simplyCached <id>")) >= 0) { |
4 | Cl<S> modifiers = tok_modifiersLeftOf(tok, i); |
5 | int iMod = tok_leftScanModifiers(tok, i); |
6 | int bracket = indexOf(tok, "(", i); |
7 | S fName; |
8 | try { |
9 | fName = assertIdentifier(tok.get(bracket-2)); |
10 | } on fail { |
11 | printTokenContext(tok, iMod, bracket-2); |
12 | } |
13 | int iMod2 = tok_rightScanModifiers(tok, i+2); |
14 | modifiers.addAll(codeTokensFromSubList(tok, i+2, iMod2)); |
15 | S type = joinSubList(tok, iMod2, bracket-3); |
16 | S boxedType = tok_toNonPrimitiveTypes(type); |
17 | S fieldMods = joinWithSpace(listMinus(modifiers, "final", "abstract")); |
18 | S functionMods = joinWithSpace(listMinus(modifiers, "transient", "abstract")); |
19 | S loadFunctionMods = joinWithSpace(listMinus(modifiers, "transient")); |
20 | bool isVoid = eq(type, "void"); |
21 | |
22 | S var = isVoid ? "ran_" + fName : fName + "_cache"; |
23 | S implFunc = isVoid ? fName + "_impl" : fName + "_load"; |
24 | S varType = isVoid ? "bool" : boxedType; |
25 | |
26 | S replacement = |
27 | // variable declaration |
28 | "\*fieldMods*/ \*varType*/ \*var*/;\n" |
29 | |
30 | + "\*functionMods*/ \*type*/ \*fName*/() { " |
31 | |
32 | // function body |
33 | + (isVoid |
34 | ? "if (\*var*/) ret; set \*var*/; \*implFunc*/();" |
35 | : "if (\*var*/ == null) \*var*/ = \*fName*/_load(); ret \*var*/;") |
36 | |
37 | + "}\n\n" |
38 | |
39 | // beginning of impl function |
40 | + "\*loadFunctionMods*/ \*type*/ \*implFunc*/"; |
41 | |
42 | replaceTokens_reTok(tok, iMod, bracket-1, replacement); |
43 | } |
44 | }} |
Began life as a copy of #1010513
download show line numbers debug dex old transpilations
Travelled to 9 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1020989 |
Snippet name: | tok_simplyCachedFunctions |
Eternal ID of this version: | #1020989/26 |
Text MD5: | af51afa8096c64a94f01c3c6e73f5110 |
Author: | stefan |
Category: | javax / transpiling |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-08-05 16:49:10 |
Source code size: | 1632 bytes / 44 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 459 / 670 |
Version history: | 25 change(s) |
Referenced in: | [show references] |