13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 package com.sun.tools.jextract.parser;
25
26 import java.nio.file.Path;
27 import java.nio.file.Paths;
28 import java.util.Arrays;
29 import java.util.ArrayList;
30 import java.util.List;
31 import java.util.Collection;
32 import java.util.function.Predicate;
33 import com.sun.tools.jextract.tree.Tree;
34 import com.sun.tools.jextract.tree.HeaderTree;
35 import com.sun.tools.jextract.tree.Printer;
36
37 public class FindSymbol {
38 public static void main(String[] args) {
39 if (args.length == 0) {
40 System.err.println("Expected a header file");
41 return;
42 }
43
44 final List<Path> paths = List.of(Paths.get(args[0]));
45 final Path builtinInc = Paths.get(System.getProperty("java.home"), "conf", "jextract");
46 final List<String> clangArgs = List.of("-I" + builtinInc);
47
48 final Parser parser = new Parser(true);
49 final List<HeaderTree> headers = parser.parse(paths, clangArgs);
50 final Printer p = new Printer();
51 final HeaderTree tu = headers.get(0);
52
53 if (args.length == 1) {
54 p.printRecursive(tu, Integer.MAX_VALUE);
55 return;
56 }
57
58 final Collection<String> set = Arrays.asList(Arrays.copyOfRange(args, 1, args.length));
59 final Predicate<Tree> matchName = tree -> tree.isDeclaration() && set.contains(tree.name());
60 tu.declarations().stream()
61 .filter(matchName)
62 .forEach(declTree -> p.printRecursive(declTree, Integer.MAX_VALUE));
63 }
64 }
|
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 package com.sun.tools.jextract.parser;
25
26 import java.nio.file.Path;
27 import java.nio.file.Paths;
28 import java.util.Arrays;
29 import java.util.ArrayList;
30 import java.util.List;
31 import java.util.Collection;
32 import java.util.function.Predicate;
33
34 import com.sun.tools.jextract.Context;
35 import com.sun.tools.jextract.tree.Tree;
36 import com.sun.tools.jextract.tree.HeaderTree;
37 import com.sun.tools.jextract.tree.Printer;
38
39 public class FindSymbol {
40 public static void main(String[] args) {
41 if (args.length == 0) {
42 System.err.println("Expected a header file");
43 return;
44 }
45
46 final List<Path> paths = List.of(Paths.get(args[0]));
47 final Path builtinInc = Paths.get(System.getProperty("java.home"), "conf", "jextract");
48 final List<String> clangArgs = List.of("-I" + builtinInc);
49
50 Context context = new Context();
51 final Parser parser = new Parser(context, true);
52 final List<HeaderTree> headers = parser.parse(paths, clangArgs);
53 final Printer p = new Printer();
54 final HeaderTree tu = headers.get(0);
55
56 if (args.length == 1) {
57 p.printRecursive(tu, Integer.MAX_VALUE);
58 return;
59 }
60
61 final Collection<String> set = Arrays.asList(Arrays.copyOfRange(args, 1, args.length));
62 final Predicate<Tree> matchName = tree -> tree.isDeclaration() && set.contains(tree.name());
63 tu.declarations().stream()
64 .filter(matchName)
65 .forEach(declTree -> p.printRecursive(declTree, Integer.MAX_VALUE));
66 }
67 }
|