Transpiled version (6163L) is out of date.
1 | sbool findFunctionInvocations_v2_debug; |
2 | |
3 | // tok: the code |
4 | // sf: map of functions (keys) to look for - null to record every function call |
5 | // hardReferences (out parameter): records every "please include" statement if not null |
6 | // haveFunctions: functions to skip (or null) |
7 | // includePossiblyMapLikes: include calls with pre-brackets argument (e.g. map l(...)) |
8 | // mainClassName: name of program's main class (calls to this class will be skipped) |
9 | static Set<S> findFunctionInvocations_v2(LS tok, SS sf, Cl<S> hardReferences, Set<S> haveFunctions, bool includePossiblyMapLikes, S mainClassName, IPred<S> isKnownClassName) {
|
10 | new LinkedHashSet<S> l; |
11 | for (int i : jfindAll(tok, "please include functions")) {
|
12 | int j = i + 6; |
13 | while licensed {
|
14 | String fname = tok.get(j); |
15 | assertIdentifier("in please include functions section", get(tok, j));
|
16 | l.add(fname); |
17 | add(hardReferences, fname); |
18 | j += 2; |
19 | if (eqGet(tok, j, ".")) break; |
20 | while (eqGetOneOf(tok, j, ",", "and")) j += 2; |
21 | } |
22 | clearAllTokens(tok.subList(i, j+2)); |
23 | } |
24 | |
25 | for (int i : jfindAll(tok, "please include function *.")) {
|
26 | String fname = tok.get(i+6); |
27 | l.add(fname); |
28 | add(hardReferences, fname); |
29 | clearAllTokens(tok.subList(i, i+10)); |
30 | } |
31 | |
32 | int i, n = tok.size(); |
33 | boolean result = false; |
34 | for (i = 1; i+2 < n; i += 2) {
|
35 | S f = tok.get(i); |
36 | if (!isIdentifier_quick(f)) continue; |
37 | |
38 | // main.<A>bla() |
39 | if (eq(mainClassName, f) && eq(tok.get(i+2), ".") && eqGet(tok, i+4, "<")) {
|
40 | i = findEndOfTypeArgs(tok, i+4)+1; |
41 | f = tok.get(i); |
42 | if (!isIdentifier(f)) continue; |
43 | } |
44 | |
45 | // e.g. ... html_findLIs(LS [auto htmlTok] tok) { ... }
|
46 | if (eqGet(tok, i-4, "[") && eqGet(tok, i-2, "auto")) {
|
47 | // ok |
48 | } else if (eqGet(tok, i-2, ":") && eqGet(tok, i-4, ":") && eqGet(tok, i-6, mainClassName)) {
|
49 | // ok, function reference (main::bla) |
50 | } else if (eqGet(tok, i+2, "(")) {
|
51 | // ok, normal function invocation |
52 | } else if (includePossiblyMapLikes && eqGet(tok, i+4, "(") && isIdentifier(get(tok, i+2))) {
|
53 | // ok, mapLike invocation (bla blubb(...)) |
54 | } else |
55 | // not an invocation |
56 | continue; |
57 | |
58 | if (!tok_isMethodDeclarationNotSFInvocation(tok, i, mainClassName, isKnownClassName)) {
|
59 | bool inSF = sf == null || sf.containsKey(f); |
60 | if (findFunctionInvocations_v2_debug) |
61 | print("Possible invocation: " + f + ", inSF: " + inSF);
|
62 | if (inSF && !contains(haveFunctions, f) && l.add(f)) |
63 | if (findFunctionInvocations_v2_debug) |
64 | print("Found reference to standard function " + f + ": " + lineAroundToken(tok, i));
|
65 | } |
66 | } |
67 | |
68 | ret l; |
69 | } |
Began life as a copy of #1003268
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
| Snippet ID: | #1034873 |
| Snippet name: | findFunctionInvocations_v2 - parse Java source for function invocations - removes "please include function" lines - TODO: type arguments |
| Eternal ID of this version: | #1034873/5 |
| Text MD5: | 70eb94ecde9da78591ed68e9906b0425 |
| Author: | stefan |
| Category: | javax / transpiling |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2022-03-12 22:32:47 |
| Source code size: | 2721 bytes / 69 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 353 / 478 |
| Version history: | 4 change(s) |
| Referenced in: | [show references] |