< prev index next >

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

Print this page




 123                  * typedef Point Vector;
 124                  */
 125 
 126                 Cursor dc = defTree.cursor();
 127                 List<Tree> trees = replacements.computeIfAbsent(dc, k -> new ArrayList<>());
 128                 trees.add(((StructTree)defTree).withName(tt.name()));
 129                 log.print(Level.FINE, () -> "Typedef " + defTree.type().spelling() + " as " + tt.name());
 130                 return null;
 131             } else if (defTree.name().equals(tt.name())) {
 132                 /*
 133                  * Remove redundant typedef like:
 134                  *
 135                  * typedef struct Point { int x; int y; } Point
 136                  * typedef enum Color { R, G, B} Color
 137                  * typedef struct Undef Undef
 138                  */
 139                 return null;
 140             }
 141         }
 142 










 143         decls.add(tt);
 144         return null;
 145     }
 146 
 147     // test main to manually check this visitor
 148     public static void main(String[] args) {
 149         if (args.length == 0) {
 150             System.err.println("Expected a header file");
 151             return;
 152         }
 153 
 154         Context context = Context.createDefault();
 155         Parser p = new Parser(context, true);
 156         Path builtinInc = Paths.get(System.getProperty("java.home"), "conf", "jextract");
 157         List<String> clangArgs = List.of("-I" + builtinInc);
 158         HeaderTree header = p.parse(Paths.get(args[0]), clangArgs);
 159         TreePrinter printer = new TreePrinter();
 160         TypedefHandler handler = new TypedefHandler(context);
 161         handler.transform(header).accept(printer, null);
 162     }


 123                  * typedef Point Vector;
 124                  */
 125 
 126                 Cursor dc = defTree.cursor();
 127                 List<Tree> trees = replacements.computeIfAbsent(dc, k -> new ArrayList<>());
 128                 trees.add(((StructTree)defTree).withName(tt.name()));
 129                 log.print(Level.FINE, () -> "Typedef " + defTree.type().spelling() + " as " + tt.name());    
 130                 return null;
 131             } else if (defTree.name().equals(tt.name())) {
 132                 /*
 133                  * Remove redundant typedef like:
 134                  *
 135                  * typedef struct Point { int x; int y; } Point
 136                  * typedef enum Color { R, G, B} Color
 137                  * typedef struct Undef Undef
 138                  */
 139                 return null;
 140             }
 141         }
 142 
 143         /*
 144          * There are typedefs on built-in types like struct __va_list_tag. These
 145          * are not exposed as declaration cursor for any headers, but are available
 146          * from Type objects. We've to walk and check null file path to detect these
 147          * Cursors and create Trees.
 148          */
 149         Utils.getBuiltinRecordTypes(tt.type()).forEach(c -> {
 150             decls.add(treeMaker.createTree(c));
 151         });
 152 
 153         decls.add(tt);
 154         return null;
 155     }
 156 
 157     // test main to manually check this visitor
 158     public static void main(String[] args) {
 159         if (args.length == 0) {
 160             System.err.println("Expected a header file");
 161             return;
 162         }
 163 
 164         Context context = Context.createDefault();
 165         Parser p = new Parser(context, true);
 166         Path builtinInc = Paths.get(System.getProperty("java.home"), "conf", "jextract");
 167         List<String> clangArgs = List.of("-I" + builtinInc);
 168         HeaderTree header = p.parse(Paths.get(args[0]), clangArgs);
 169         TreePrinter printer = new TreePrinter();
 170         TypedefHandler handler = new TypedefHandler(context);
 171         handler.transform(header).accept(printer, null);
 172     }
< prev index next >