< prev index next >

src/jdk.jextract/share/classes/com/sun/tools/jextract/tree/LayoutUtils.java

Print this page

        

*** 47,73 **** * General Layout utility functions */ public final class LayoutUtils { private LayoutUtils() {} ! public static String getIdentifier(Type type) { Cursor c = type.getDeclarationCursor(); if (c.isInvalid()) { return type.spelling(); } ! return getIdentifier(c); } ! static String getIdentifier(Cursor cursor) { // Use cursor name instead of type name, this way we don't have struct // or enum prefix String nativeName = cursor.spelling(); if (nativeName.isEmpty()) { - // This happens when a typedef an anonymous struct, i.e., typedef struct {} type; Type t = cursor.type(); nativeName = t.spelling(); ! if (nativeName.contains("::")) { SourceLocation.Location loc = cursor.getSourceLocation().getFileLocation(); return "anon$" + loc.path().getFileName().toString().replaceAll("\\.", "_") + "$" + loc.offset(); } --- 47,77 ---- * General Layout utility functions */ public final class LayoutUtils { private LayoutUtils() {} ! public static String getName(Type type) { Cursor c = type.getDeclarationCursor(); if (c.isInvalid()) { return type.spelling(); } ! return getName(c); } ! public static String getName(Tree tree) { ! String name = tree.name(); ! return name.isEmpty()? getName(tree.cursor()) : name; ! } ! ! private static String getName(Cursor cursor) { // Use cursor name instead of type name, this way we don't have struct // or enum prefix String nativeName = cursor.spelling(); if (nativeName.isEmpty()) { Type t = cursor.type(); nativeName = t.spelling(); ! if (nativeName.contains("::") || nativeName.contains(" ")) { SourceLocation.Location loc = cursor.getSourceLocation().getFileLocation(); return "anon$" + loc.path().getFileName().toString().replaceAll("\\.", "_") + "$" + loc.offset(); }
*** 194,204 **** } private static Layout getRecordReferenceLayout(Type t) { //symbolic reference return Unresolved.of() ! .withAnnotation(Layout.NAME, getIdentifier(t.canonicalType())); } static Layout getRecordLayout(Type t, BiFunction<Cursor, Layout, Layout> fieldMapper) { return getRecordLayoutInternal(0, t, t, fieldMapper); } --- 198,208 ---- } private static Layout getRecordReferenceLayout(Type t) { //symbolic reference return Unresolved.of() ! .withAnnotation(Layout.NAME, getName(t.canonicalType())); } static Layout getRecordLayout(Type t, BiFunction<Cursor, Layout, Layout> fieldMapper) { return getRecordLayoutInternal(0, t, t, fieldMapper); }
*** 255,265 **** replaceBitfields(fieldLayouts, pendingBitfieldStart); } Layout[] fields = fieldLayouts.toArray(new Layout[0]); Group g = isUnion ? Group.union(fields) : Group.struct(fields); ! return g.withAnnotation(Layout.NAME, getIdentifier(cu)); } private static Layout fieldLayout(boolean isUnion, Cursor c, BiFunction<Cursor, Layout, Layout> fieldMapper) { Layout layout = getLayout(c.type()); if (c.isBitField()) { --- 259,269 ---- replaceBitfields(fieldLayouts, pendingBitfieldStart); } Layout[] fields = fieldLayouts.toArray(new Layout[0]); Group g = isUnion ? Group.union(fields) : Group.struct(fields); ! return g.withAnnotation(Layout.NAME, getName(cu)); } private static Layout fieldLayout(boolean isUnion, Cursor c, BiFunction<Cursor, Layout, Layout> fieldMapper) { Layout layout = getLayout(c.type()); if (c.isBitField()) {
< prev index next >