< prev index next >

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

Print this page

        

*** 30,39 **** --- 30,41 ---- import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.logging.Level; import java.util.logging.Logger; + import java.util.stream.Collectors; + import java.util.stream.Stream; import com.sun.tools.jextract.parser.Parser; import com.sun.tools.jextract.tree.HeaderTree; import com.sun.tools.jextract.tree.SimpleTreeVisitor; import com.sun.tools.jextract.tree.StructTree; import com.sun.tools.jextract.tree.Tree;
*** 76,93 **** ht.accept(this, null); // Replace trees from this.decls with Trees found in this.replacements. // We need this two step process so that named StructTree instances // will replace with original unnamed StructTree instances. ! List<Tree> newDecls = new ArrayList<>(); ! decls.stream().forEach(tx -> { if (replacements.containsKey(tx.cursor())) { ! newDecls.addAll(replacements.get(tx.cursor())); } else { ! newDecls.add(tx); } ! }); return treeMaker.createHeader(ht.cursor(), ht.path(), newDecls); } @Override --- 78,94 ---- ht.accept(this, null); // Replace trees from this.decls with Trees found in this.replacements. // We need this two step process so that named StructTree instances // will replace with original unnamed StructTree instances. ! List<Tree> newDecls = decls.stream().flatMap(tx -> { if (replacements.containsKey(tx.cursor())) { ! return replacements.get(tx.cursor()).stream(); } else { ! return Stream.of(tx); } ! }).collect(Collectors.toList()); return treeMaker.createHeader(ht.cursor(), ht.path(), newDecls); } @Override
*** 112,135 **** * typedef struct { int x; int y; } Point * * is mapped to two Cursors by clang. First one for anonymous struct decl. * and second one for typedef decl. We map it as a single named struct * declaration. ! */ ! Cursor dc = defTree.cursor(); ! ! /* * There may be more than one typedef on underlying anonymous struct/union. * Example: * * typedef struct { int x; int y; } Point; * typedef Point Vector; */ ! List<Tree> trees = replacements.containsKey(dc)? ! replacements.get(defTree.cursor()) : new ArrayList<>(); trees.add(((StructTree)defTree).withName(tt.name())); - replacements.put(dc, trees); log.print(Level.FINE, () -> "Typedef " + defTree.type().spelling() + " as " + tt.name()); return null; } else if (defTree.name().equals(tt.name())) { /* * Remove redundant typedef like: --- 113,133 ---- * typedef struct { int x; int y; } Point * * is mapped to two Cursors by clang. First one for anonymous struct decl. * and second one for typedef decl. We map it as a single named struct * declaration. ! * * There may be more than one typedef on underlying anonymous struct/union. * Example: * * typedef struct { int x; int y; } Point; * typedef Point Vector; */ ! ! Cursor dc = defTree.cursor(); ! List<Tree> trees = replacements.computeIfAbsent(dc, k -> new ArrayList<>()); trees.add(((StructTree)defTree).withName(tt.name())); log.print(Level.FINE, () -> "Typedef " + defTree.type().spelling() + " as " + tt.name()); return null; } else if (defTree.name().equals(tt.name())) { /* * Remove redundant typedef like:
< prev index next >