1 | static Set<S> findFunctionDefs_keywords = new HashSet(splitAtSpace("static svoid ssvoid ssynchronized sbool sS sO sL")); |
2 | |
3 | static LS findFunctionDefs(S s) { |
4 | ret findFunctionDefs(javaTok(s)); |
5 | } |
6 | |
7 | static L<S> findFunctionDefs(L<S> tok) { |
8 | new LS functions; |
9 | |
10 | if (tok instanceof IContentsIndexedList2) { |
11 | for (S keyword : findFunctionDefs_keywords) { |
12 | TreeSet<HasIndex> indices = tok/IContentsIndexedList2.indicesOf_treeSetOfHasIndex(keyword); |
13 | if (indices != null) |
14 | for (HasIndex i : indices) |
15 | findFunctionDefs_step(tok, i.idx, functions); |
16 | } |
17 | } else { |
18 | int n = l(tok); |
19 | for (int i = 1; i < n; i += 2) |
20 | if (findFunctionDefs_keywords.contains(tok.get(i))) |
21 | findFunctionDefs_step(tok, i, functions); |
22 | } |
23 | ret functions; |
24 | } |
25 | |
26 | // we found one of the keywords listed above at token i |
27 | // now scan forward for a function definition |
28 | svoid findFunctionDefs_step(LS tok, int i, LS functions) { |
29 | S t = tok.get(i); |
30 | int j = i+2, n = l(tok); |
31 | while (j < n && !findFunctionsDefs_checkToken(tok.get(j))) |
32 | j += 2; |
33 | if (isIdentifier(tok.get(j-2)) && |
34 | eqGet(tok, j, "(") || eqGet(tok, j, "{") && eq(t, "svoid")) |
35 | functions.add(tok.get(j-2)); |
36 | } |
37 | |
38 | sbool findFunctionsDefs_checkToken(S t) { |
39 | if (t.length() != 1) false; |
40 | char c = t.charAt(0); |
41 | ret c == ';' || c == '=' || c == '(' || c == '{' /*|| c == '#' XXX*/; |
42 | } |
Began life as a copy of #1004051
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1034495 |
Snippet name: | findFunctionDefs (finds static functions, backup) |
Eternal ID of this version: | #1034495/1 |
Text MD5: | f508aa26dc1a988d8990d66c679f1a7a |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-02-09 23:55:41 |
Source code size: | 1402 bytes / 42 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 143 / 162 |
Referenced in: | [show references] |