< prev index next >

test/jdk/com/sun/tools/jextract/jclang-ffi/src/jdk/internal/clang/TranslationUnit.java

Print this page




  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.internal.clang;
  27 
  28 import java.foreign.NativeTypes;
  29 import java.foreign.Scope;
  30 import java.foreign.memory.LayoutType;
  31 import java.foreign.memory.Pointer;
  32 import java.io.IOException;
  33 import java.nio.file.Path;
  34 
  35 import clang.CXString.CXString;
  36 import clang.Index.CXDiagnostic;
  37 import clang.Index.CXToken;
  38 import clang.Index.CXTokenKind;
  39 import clang.Index.CXTranslationUnitImpl;
  40 
  41 public class TranslationUnit {
  42     private final Pointer<CXTranslationUnitImpl> tu;
  43     private final Scope scope = Scope.globalScope().fork();
  44 
  45     TranslationUnit(Pointer<CXTranslationUnitImpl> tu) {
  46         this.tu = tu;
  47     }
  48 
  49     public Cursor getCursor() {
  50         return new Cursor(LibClang.lib.clang_getTranslationUnitCursor(tu));
  51     }
  52 
  53     public Diagnostic[] getDiagnostics() {
  54         final clang.Index lclang = LibClang.lib;
  55 
  56         int cntDiags = lclang.clang_getNumDiagnostics(tu);
  57         if (cntDiags == 0) {
  58             return null;
  59         }
  60 
  61         Diagnostic[] rv = new Diagnostic[cntDiags];
  62         for (int i = 0; i < cntDiags; i++) {
  63             @CXDiagnostic Pointer<Void> diag = lclang.clang_getDiagnostic(tu, i);
  64             rv[i] = new Diagnostic(diag);
  65         }
  66 
  67         return rv;
  68     }
  69 
  70     public final void save(Path path) throws TranslationUnit.TranslationUnitSaveException {
  71         try (Scope sc = Scope.globalScope().fork()) {
  72             int res = LibClang.lib.clang_saveTranslationUnit(tu,
  73                     sc.allocateCString(path.toAbsolutePath().toString()), 0);
  74             if (res != 0) {




  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.internal.clang;
  27 
  28 import java.foreign.NativeTypes;
  29 import java.foreign.Scope;
  30 import java.foreign.memory.LayoutType;
  31 import java.foreign.memory.Pointer;
  32 import java.io.IOException;
  33 import java.nio.file.Path;
  34 
  35 import clang.CXString_h.CXString;
  36 import clang.Index_h.CXDiagnostic;
  37 import clang.Index_h.CXToken;
  38 import clang.Index_h.CXTokenKind;
  39 import clang.Index_h.CXTranslationUnitImpl;
  40 
  41 public class TranslationUnit {
  42     private final Pointer<CXTranslationUnitImpl> tu;
  43     private final Scope scope = Scope.globalScope().fork();
  44 
  45     TranslationUnit(Pointer<CXTranslationUnitImpl> tu) {
  46         this.tu = tu;
  47     }
  48 
  49     public Cursor getCursor() {
  50         return new Cursor(LibClang.lib.clang_getTranslationUnitCursor(tu));
  51     }
  52 
  53     public Diagnostic[] getDiagnostics() {
  54         final clang.Index_h lclang = LibClang.lib;
  55 
  56         int cntDiags = lclang.clang_getNumDiagnostics(tu);
  57         if (cntDiags == 0) {
  58             return null;
  59         }
  60 
  61         Diagnostic[] rv = new Diagnostic[cntDiags];
  62         for (int i = 0; i < cntDiags; i++) {
  63             @CXDiagnostic Pointer<Void> diag = lclang.clang_getDiagnostic(tu, i);
  64             rv[i] = new Diagnostic(diag);
  65         }
  66 
  67         return rv;
  68     }
  69 
  70     public final void save(Path path) throws TranslationUnit.TranslationUnitSaveException {
  71         try (Scope sc = Scope.globalScope().fork()) {
  72             int res = LibClang.lib.clang_saveTranslationUnit(tu,
  73                     sc.allocateCString(path.toAbsolutePath().toString()), 0);
  74             if (res != 0) {


< prev index next >