< prev index next >
src/jdk.jextract/share/classes/com/sun/tools/jextract/TypedefHandler.java
Print this page
*** 57,86 ****
implements TreePhase {
private final TreeMaker treeMaker = new TreeMaker();
// Potential Tree instances that will go into transformed HeaderTree
// are collected in this list.
! private final List<Tree> decls = new ArrayList<>();
// Tree instances that are to be replaced from "decls" list are
// saved in the following Map.
private final Map<Cursor, Tree> replacements = new HashMap<>();
! private Path headerPath;
!
! private static boolean isFromPath(Tree tree, Path path) {
! SourceLocation loc = tree.location();
! return loc != null? Objects.equals(path, loc.getFileLocation().path()) : false;
! }
!
! private boolean isFromThisHeader(Tree tree) {
! return isFromPath(tree, headerPath);
}
@Override
public HeaderTree transform(HeaderTree ht) {
- this.headerPath = ht.path();
// Process all header declarations are collect potential
// declarations that will go into transformed HeaderTree
// into the this.decls field.
ht.accept(this, null);
--- 57,81 ----
implements TreePhase {
private final TreeMaker treeMaker = new TreeMaker();
// Potential Tree instances that will go into transformed HeaderTree
// are collected in this list.
! private List<Tree> decls = new ArrayList<>();
// Tree instances that are to be replaced from "decls" list are
// saved in the following Map.
private final Map<Cursor, Tree> replacements = new HashMap<>();
! private boolean isFromSameHeader(Tree def, Tree decl) {
! SourceLocation locDef = def.location();
! SourceLocation locDecl = decl.location();
! return locDef != null && locDecl != null &&
! Objects.equals(locDecl.getFileLocation().path(), locDef.getFileLocation().path());
}
@Override
public HeaderTree transform(HeaderTree ht) {
// Process all header declarations are collect potential
// declarations that will go into transformed HeaderTree
// into the this.decls field.
ht.accept(this, null);
*** 125,135 ****
// for which no definition is found elsewhere in this header.
if (e.isDefinition()) {
decls.add(e);
} else {
Optional<Tree> def = e.definition();
! if (!def.isPresent() || !isFromThisHeader(def.get())) {
decls.add(e);
}
}
return null;
}
--- 120,130 ----
// for which no definition is found elsewhere in this header.
if (e.isDefinition()) {
decls.add(e);
} else {
Optional<Tree> def = e.definition();
! if (!def.isPresent() || !isFromSameHeader(def.get(), e)) {
decls.add(e);
}
}
return null;
}
*** 140,149 ****
--- 135,153 ----
return null;
}
@Override
public Void visitStruct(StructTree s, Void v) {
+ List<Tree> oldDecls = decls;
+ List<Tree> structDecls = new ArrayList<>();
+ try {
+ decls = structDecls;
+ s.declarations().forEach(t -> t.accept(this, null));
+ } finally {
+ decls = oldDecls;
+ }
+
/*
* If we're seeing a forward/backward declaration of
* a struct which is definied elsewhere in this compilation
* unit, ignore it. If no definition is found, we want to
* leave the declaration so that dummy definition will be
*** 158,172 ****
*/
// include this only if this is a definition or a declaration
// for which no definition is found elsewhere in this header.
if (s.isDefinition()) {
! decls.add(s);
} else {
Optional<Tree> def = s.definition();
! if (!def.isPresent() || !isFromThisHeader(def.get())) {
! decls.add(s);
}
}
return null;
}
--- 162,176 ----
*/
// include this only if this is a definition or a declaration
// for which no definition is found elsewhere in this header.
if (s.isDefinition()) {
! decls.add(s.withNameAndDecls(s.name(), structDecls));
} else {
Optional<Tree> def = s.definition();
! if (!def.isPresent() || !isFromSameHeader(def.get(), s)) {
! decls.add(s.withNameAndDecls(s.name(), structDecls));
}
}
return null;
}
*** 206,216 ****
if (args.length == 0) {
System.err.println("Expected a header file");
return;
}
! Parser p = new Parser(true);
List<Path> paths = Arrays.stream(args).map(Paths::get).collect(Collectors.toList());
Path builtinInc = Paths.get(System.getProperty("java.home"), "conf", "jextract");
List<String> clangArgs = List.of("-I" + builtinInc);
List<HeaderTree> headers = p.parse(paths, clangArgs);
TreePrinter printer = new TreePrinter();
--- 210,221 ----
if (args.length == 0) {
System.err.println("Expected a header file");
return;
}
! Context context = new Context();
! Parser p = new Parser(context, true);
List<Path> paths = Arrays.stream(args).map(Paths::get).collect(Collectors.toList());
Path builtinInc = Paths.get(System.getProperty("java.home"), "conf", "jextract");
List<String> clangArgs = List.of("-I" + builtinInc);
List<HeaderTree> headers = p.parse(paths, clangArgs);
TreePrinter printer = new TreePrinter();
< prev index next >