< prev index next >

src/jdk.jextract/share/classes/com/sun/tools/jextract/HeaderFile.java

Print this page




   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.nio.file.Path;
  26 import java.util.Collections;
  27 import java.util.List;
  28 import java.util.logging.Logger;
  29 
  30 import com.sun.tools.jextract.tree.StructTree;
  31 import com.sun.tools.jextract.tree.Tree;
  32 
  33 /**
  34  * This class represent a native code header file
  35  */
  36 public final class HeaderFile {
  37     private final Context ctx;
  38     final Path path;
  39     final String pkgName;
  40     final String clsName;
  41     private final TypeDictionary dict;
  42     // The top header file cause this file to be parsed
  43     private HeaderFile main;
  44     private AsmCodeFactory cf;
  45     List<String> libraries; // immutable
  46     List<String> libraryPaths; // immutable
  47 
  48     private final Logger logger = Logger.getLogger(getClass().getPackage().getName());
  49 
  50     HeaderFile(Context ctx, Path path, String pkgName, String clsName, HeaderFile main) {
  51         this.ctx = ctx;
  52         this.path = path;
  53         this.pkgName = pkgName;
  54         this.clsName = clsName;
  55         this.main = main == null ? this : main;
  56         this.dict = new TypeDictionary(ctx, this);
  57     }
  58 
  59     void useLibraries(List<String> libraries, List<String> libraryPaths) {
  60         this.libraries = Collections.unmodifiableList(libraries);
  61         this.libraryPaths = Collections.unmodifiableList(libraryPaths);
  62     }
  63 
  64     AsmCodeFactory getCodeFactory() {
  65         return cf;
  66     }
  67 
  68     TypeDictionary dictionary() {
  69         return dict;
  70     }
  71 
  72     /**
  73      * Call this function to enable code generation for this HeaderFile.
  74      * This function should only be called once to turn on code generation and before process any cursor.
  75      * @param cf The CodeFactory used to generate code
  76      */
  77     void useCodeFactory(AsmCodeFactory cf) {
  78         if (null != this.cf) {
  79             logger.config(() -> "CodeFactory had been initialized for " + path);
  80             // Diagnosis code
  81             if (Main.DEBUG) {
  82                 new Throwable().printStackTrace(ctx.err);
  83             }
  84         } else {
  85             this.cf = cf;
  86         }
  87     }
  88 
  89     @Override
  90     public String toString() {
  91         return "HeaderFile(path=" + path + ")";
  92     }
  93 
  94     void processTree(Tree tree, HeaderFile main, boolean isBuiltIn) {
  95         if (tree.isDeclaration()) {
  96             tree.accept(new TypeEnter(dictionary()), null);
  97             JType jt = dictionary().lookup(tree.type());
  98 
  99             if (tree instanceof StructTree) {
 100                 ((StructTree)tree).nestedTypes().forEach(nt -> processTree(nt, main, isBuiltIn));
 101             }
 102 
 103             // Only main file can define interface
 104             if (cf != null && this.main == main) {
 105                 cf.addType(jt, tree);
 106             }
 107         } else if (tree.isPreprocessing() && !isBuiltIn) {
 108             if (cf != null) {
 109                 tree.accept(cf, null);
 110             }
 111         }
 112     }
 113 }


   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.nio.file.Path;






  26 
  27 /**
  28  * This class represent a native code header file
  29  */
  30 public final class HeaderFile {

  31     final Path path;
  32     final String pkgName;
  33     final String clsName;
  34     private final TypeDictionary dict;







  35 
  36     HeaderFile(HeaderResolver resolver, Path path, String pkgName, String clsName) {

  37         this.path = path;
  38         this.pkgName = pkgName;
  39         this.clsName = clsName;
  40         this.dict = new TypeDictionary(resolver, this);










  41     }
  42 
  43     TypeDictionary dictionary() {
  44         return dict;
  45     }
  46 

















  47     @Override
  48     public String toString() {
  49         return "HeaderFile(path=" + path + ")";
  50     }




















  51 }
< prev index next >