changeset 57967:dca9af00aeac nicl

8202099: variables with an elaborated type are not mapped properly Reviewed-by: henryjen
author sundar
date Fri, 20 Apr 2018 14:50:57 -0700
parents 86baa689ef43
children 78a4afbb218d
files src/jdk.jextract/share/classes/com/sun/tools/jextract/HeaderFile.java test/jdk/com/sun/tools/jextract/JextractToolProviderTest.java test/jdk/com/sun/tools/jextract/elaboratedtype.h
diffstat 3 files changed, 55 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.jextract/share/classes/com/sun/tools/jextract/HeaderFile.java	Thu Apr 19 15:03:39 2018 -0700
+++ b/src/jdk.jextract/share/classes/com/sun/tools/jextract/HeaderFile.java	Fri Apr 20 14:50:57 2018 -0700
@@ -220,6 +220,7 @@
         logger.fine("Define " + t.kind() + ":" + t.spelling() + " for TD " + pkgName);
         switch (t.kind()) {
             case Unexposed:
+            case Elaborated:
                 jt = define(t.canonicalType());
                 break;
             case ConstantArray:
--- a/test/jdk/com/sun/tools/jextract/JextractToolProviderTest.java	Thu Apr 19 15:03:39 2018 -0700
+++ b/test/jdk/com/sun/tools/jextract/JextractToolProviderTest.java	Fri Apr 20 14:50:57 2018 -0700
@@ -30,6 +30,7 @@
 import java.net.URLClassLoader;
 import java.nicl.metadata.Header;
 import java.nicl.metadata.LibraryDependencies;
+import java.nicl.types.Pointer;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.nio.file.Files;
@@ -144,6 +145,10 @@
         return findMethod(cls, name + "$get");
     }
 
+    private static Method findGlobalVariableGet(Class<?> cls, String name) {
+        return findMethod(cls, name + "$get");
+    }
+
     private static Method findFirstMethod(Class<?> cls, String name) {
         try {
             for (Method m : cls.getMethods()) {
@@ -558,4 +563,20 @@
             deleteFile(nestedJar);
         }
     }
+
+    @Test
+    public void testAnonymousStructTypeGlobalVar() {
+        Path elaboratedTypeJar = getOutputFilePath("elaboratedtype.jar");
+        deleteFile(elaboratedTypeJar);
+        Path elaboratedTypeH = getInputFilePath("elaboratedtype.h");
+        try {
+            checkSuccess(null, "-o", elaboratedTypeJar.toString(), elaboratedTypeH.toString());
+            Class<?> headerCls = loadClass("elaboratedtype", elaboratedTypeJar);
+            assertNotNull(findGlobalVariableGet(headerCls, "point"));
+            assertNotNull(findGlobalVariableGet(headerCls, "long_or_int"));
+            assertNotNull(findMethod(headerCls, "func", Pointer.class));
+        } finally {
+            deleteFile(elaboratedTypeJar);
+        }
+    }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/tools/jextract/elaboratedtype.h	Fri Apr 20 14:50:57 2018 -0700
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+struct {
+    int x, y;
+} point;
+
+union {
+    long l;
+    int i;
+} long_or_int;
+
+void func(struct { int x, y; }* ptr);