< prev index next >

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

Print this page




  51 
  52     public JextractTool(Context ctx) {
  53         this.headerResolver = new HeaderResolver(ctx);
  54         this.parser = new Parser(ctx, Options.INCLUDE_MACROS);
  55         this.codeFactory = ctx.options.genStaticForwarder ?
  56                 hf -> new AsmCodeFactoryExt(ctx, hf) :
  57                 hf -> new AsmCodeFactory(ctx, hf);
  58         this.clangArgs = ctx.options.clangArgs;
  59         this.sources = ctx.sources;
  60         this.ctx = ctx;
  61         assert sources.size() > 0;
  62     }
  63 
  64     /** This is the main jextract entry point */
  65     public Writer processHeaders() {
  66         Path source = sources.size() > 1? generateTmpSource() : sources.iterator().next();
  67         Map<HeaderFile, List<Tree>> headerMap = Stream.of(parser.parse(source, clangArgs))
  68                 .map(new SymbolFilter(ctx))
  69                 .map(new LibraryLookupFilter(ctx))
  70                 .map(new DependencyFilter(ctx))

  71                 .map(new TypedefHandler(ctx))
  72                 .map(new EmptyNameHandler())
  73                 .map(new DuplicateDeclarationHandler())
  74                 .flatMap(h -> h.declarations().stream())
  75                 .peek(new FlexibleArrayWarningVisitor(ctx))
  76                 .collect(Collectors.groupingBy(this::headerFromDecl));
  77 
  78         //generate classes
  79         Map<String, byte[]> results = new LinkedHashMap<>();
  80         headerMap.forEach((hf, decls) -> generateHeader(hf, decls, results));
  81         return new Writer(ctx, results);
  82     }
  83 
  84     private void generateHeader(HeaderFile hf, List<Tree> decls, Map<String, byte[]> results) {
  85         TypeEnter enter = new TypeEnter(hf.dictionary());
  86         decls.forEach(t -> t.accept(enter, null));
  87         if (ctx.options.srcDumpDir != null) {
  88             JavaSourceFactory jsb = ctx.options.genStaticForwarder ?
  89                 new JavaSourceFactoryExt(ctx, hf) : new JavaSourceFactory(ctx, hf);
  90             jsb.generate(decls);




  51 
  52     public JextractTool(Context ctx) {
  53         this.headerResolver = new HeaderResolver(ctx);
  54         this.parser = new Parser(ctx, Options.INCLUDE_MACROS);
  55         this.codeFactory = ctx.options.genStaticForwarder ?
  56                 hf -> new AsmCodeFactoryExt(ctx, hf) :
  57                 hf -> new AsmCodeFactory(ctx, hf);
  58         this.clangArgs = ctx.options.clangArgs;
  59         this.sources = ctx.sources;
  60         this.ctx = ctx;
  61         assert sources.size() > 0;
  62     }
  63 
  64     /** This is the main jextract entry point */
  65     public Writer processHeaders() {
  66         Path source = sources.size() > 1? generateTmpSource() : sources.iterator().next();
  67         Map<HeaderFile, List<Tree>> headerMap = Stream.of(parser.parse(source, clangArgs))
  68                 .map(new SymbolFilter(ctx))
  69                 .map(new LibraryLookupFilter(ctx))
  70                 .map(new DependencyFilter(ctx))
  71                 .map(new BuiltinTypesHandler(ctx))
  72                 .map(new TypedefHandler(ctx))
  73                 .map(new EmptyNameHandler())
  74                 .map(new DuplicateDeclarationHandler())
  75                 .flatMap(h -> h.declarations().stream())
  76                 .peek(new FlexibleArrayWarningVisitor(ctx))
  77                 .collect(Collectors.groupingBy(this::headerFromDecl));
  78 
  79         //generate classes
  80         Map<String, byte[]> results = new LinkedHashMap<>();
  81         headerMap.forEach((hf, decls) -> generateHeader(hf, decls, results));
  82         return new Writer(ctx, results);
  83     }
  84 
  85     private void generateHeader(HeaderFile hf, List<Tree> decls, Map<String, byte[]> results) {
  86         TypeEnter enter = new TypeEnter(hf.dictionary());
  87         decls.forEach(t -> t.accept(enter, null));
  88         if (ctx.options.srcDumpDir != null) {
  89             JavaSourceFactory jsb = ctx.options.genStaticForwarder ?
  90                 new JavaSourceFactoryExt(ctx, hf) : new JavaSourceFactory(ctx, hf);
  91             jsb.generate(decls);


< prev index next >