static Set findFunctionDefs_keywords = new HashSet(splitAtSpace("static svoid ssvoid ssynchronized sbool sS sO sL")); static LS findFunctionDefs(S s) { ret findFunctionDefs(javaTok(s)); } static L findFunctionDefs(L tok) { new LS functions; /*if (tok instanceof IContentsIndexedList2) { for (S keyword : findFunctionDefs_keywords) { TreeSet indices = tok/IContentsIndexedList2.indicesOf_treeSetOfHasIndex(keyword); if (indices != null) for (HasIndex i : indices) findFunctionDefs_step(tok, i.idx, functions); } } else {*/ int n = l(tok); int curlyLevel = 0; for (int i = 1; i < n; i += 2) { S t = tok.get(i); curlyLevel += curlyLevel(t); if (curlyLevel == 0) if (findFunctionDefs_keywords.contains(t)) findFunctionDefs_step(tok, i, functions); } /*}*/ ret functions; } // we found one of the keywords listed above at token i // now scan forward for a function definition svoid findFunctionDefs_step(LS tok, int i, LS functions) { S t = tok.get(i); int j = i+2, n = l(tok); while (j < n && !findFunctionsDefs_checkToken(tok.get(j))) j += 2; if (isIdentifier(tok.get(j-2)) && eqGet(tok, j, "(") || eqGet(tok, j, "{") && eq(t, "svoid")) functions.add(tok.get(j-2)); } sbool findFunctionsDefs_checkToken(S t) { if (t.length() != 1) false; char c = t.charAt(0); ret c == ';' || c == '=' || c == '(' || c == '{' /*|| c == '#' XXX*/; }