Libraryless. Click here for Pure Java version (10529L/59K).
1 | // only one multi-type argument per declaration for now |
2 | // also allows only one combo right now (File/S with newFile) |
3 | // example: |
4 | // sS loadTextFile(File/S file) { ... } |
5 | svoid tok_expandMultiTypeArgument(LS tok, |
6 | int iArgStart, int iArgEnd, // start and end of argument |
7 | S argName, S mainType, S altType, S conversionExpr) { |
8 | |
9 | iArgEnd |= 1; |
10 | |
11 | int iOpening = lastIndexOf(tok, iArgStart, "("); // TODO: brackets |
12 | int iClosing = findEndOfBracketPart2(tok, iOpening)-1; |
13 | |
14 | // function name |
15 | int iName = iOpening-2; |
16 | S name = assertIdentifier(get(tok, iName)); |
17 | |
18 | int iType = tok_leftScanType(tok, iName); |
19 | int iStart = tok_leftScanTypeArgsOpt(tok, iType); |
20 | iStart = leftScanModifiers(tok, iStart); |
21 | //print("Found method head: " + joinSubList(tok, iStart, iClosing+1)); |
22 | LS _args1 = subList(tok, iOpening+1, iArgStart); |
23 | LS _args2 = subList(tok, iArgEnd&~1, iClosing); |
24 | LS args1 = tok_parseArgsDeclList2(_args1); |
25 | LS args2 = tok_parseArgsDeclList2(_args2); |
26 | LS type = subList(tok, iType-1, iName); |
27 | bool isVoid = containsOneOf(codeTokens(type), javaxVoidAliases()); |
28 | //printVars(+expr, +_args1, +_args2, +args1, +args2, +type, +isVoid); |
29 | |
30 | S altHead = joinSubList(tok, iStart, iOpening+1) |
31 | + joinWithComma(concatLists( |
32 | args1, |
33 | ll(altType + " " + argName), |
34 | args2)) + ")"; |
35 | |
36 | if (tok_isSingleIdentifier(conversionExpr)) |
37 | conversionExpr += "(\*argName*/)"; |
38 | |
39 | replaceTokens_reTok(tok, iArgStart|1, iArgEnd, mainType + " " + argName); |
40 | tokPrepend_reTok(tok, iStart, altHead + " { " |
41 | + (isVoid ? "" : "return ") + name + "(" + |
42 | joinWithComma(concatLists( |
43 | map tok_lastIdentifier(args1), |
44 | ll(conversionExpr), |
45 | map tok_lastIdentifier(args2))) + "); }\n"); |
46 | } |
Began life as a copy of #1031905
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx
No comments. add comment
Snippet ID: | #1032172 |
Snippet name: | tok_expandMultiTypeArgument |
Eternal ID of this version: | #1032172/7 |
Text MD5: | f6f223e6b9e768d0f7a89efc53e0ab82 |
Transpilation MD5: | b8fb73954a3a5bd9582b058909883767 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-06-27 10:26:44 |
Source code size: | 1792 bytes / 46 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 231 / 329 |
Version history: | 6 change(s) |
Referenced in: | [show references] |