1 /* 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 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 package com.sun.tools.jextract; 24 25 import java.io.PrintWriter; 26 import java.nio.file.Files; 27 import java.nio.file.Path; 28 import java.util.*; 29 import java.util.logging.Logger; 30 import java.util.regex.Pattern; 31 import java.util.stream.Collectors; 32 import com.sun.tools.jextract.parser.Parser; 33 import com.sun.tools.jextract.tree.Tree; 34 35 /** 36 * The setup for the tool execution 37 */ 38 public final class Context { 39 // The args for parsing C 40 public final List<String> clangArgs; 41 // The set of source header files 42 public final Set<Path> sources; 43 // The list of library names 44 public final List<String> libraryNames; 45 // The list of library paths 46 public final List<String> libraryPaths; 47 // The list of library paths for link checks 48 public final List<String> linkCheckPaths; 49 // Symbol patterns to be included 50 public final List<Pattern> includeSymbols; 51 // Symbol patterns to be excluded 52 public final List<Pattern> excludeSymbols; 53 // no NativeLocation info 54 public boolean noNativeLocations; 55 // generate static forwarder class or not? 56 public boolean genStaticForwarder; 57 // target package 58 public String targetPackage; 59 // package mappings 60 public final Map<Path, String> pkgMappings = new LinkedHashMap<>(); 61 62 public final PrintWriter out; 63 public final PrintWriter err; 64 65 final Logger logger = Logger.getLogger(getClass().getPackage().getName()); 66 67 public Context(PrintWriter out, PrintWriter err) { 68 this.clangArgs = new ArrayList<>(); 69 this.sources = new TreeSet<>(); 70 this.libraryNames = new ArrayList<>(); 71 this.libraryPaths = new ArrayList<>(); 72 this.linkCheckPaths = new ArrayList<>(); 73 this.includeSymbols = new ArrayList<>(); 74 this.excludeSymbols = new ArrayList<>(); 75 this.out = out; 76 this.err = err; 77 } 78 79 public Context() { 80 this(new PrintWriter(System.out, true), new PrintWriter(System.err, true)); 81 } 82 83 public void addClangArg(String arg) { 84 clangArgs.add(arg); 85 } 86 87 public void addSource(Path path) { 88 sources.add(path); 89 } 90 91 public void addLibraryName(String name) { 92 libraryNames.add(name); 93 } 94 95 public void addLibraryPath(String path) { 96 libraryPaths.add(path); 97 } 98 99 public void addLinkCheckPath(String path) { 100 linkCheckPaths.add(path); 101 } 102 103 public void setNoNativeLocations() { 104 noNativeLocations = true; 105 } 106 107 public void addIncludeSymbols(String pattern) { 108 includeSymbols.add(Pattern.compile(pattern)); 109 } 110 111 public void addExcludeSymbols(String pattern) { 112 excludeSymbols.add(Pattern.compile(pattern)); 113 } 114 115 public void setGenStaticForwarder(boolean flag) { 116 this.genStaticForwarder = flag; 117 } 118 119 public void setTargetPackage(String pkg) { 120 this.targetPackage = pkg; 121 } 122 123 public void addPackageMapping(Path path, String pkg) { 124 pkgMappings.put(path, pkg); 125 } 126 } --- EOF ---