Skip to content

Commit

Permalink
* Let Parser support arrays of anonymous struct or union conta…
Browse files Browse the repository at this point in the history
…ining another one (discussion #528)
  • Loading branch information
saudet committed Dec 15, 2021
1 parent b9e7080 commit 1c72e35
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,4 +1,5 @@

* Let `Parser` support arrays of anonymous `struct` or `union` containing another one ([discussion #528](https://github.com/bytedeco/javacpp/discussions/528))
* Prevent `Parser` from outputting duplicate `Pointer` constructors for basic containers
* Fix `Generator` compiler errors on callback functions returning objects without default constructors
* Ensure `Builder` copies resources only from the first directories found in the paths
Expand Down
25 changes: 17 additions & 8 deletions src/main/java/org/bytedeco/javacpp/tools/Parser.java
Expand Up @@ -2648,9 +2648,9 @@ boolean variable(Context context, DeclarationList declList) throws ParserExcepti
String nameAnnotation = "";
if (metadcl != null && metadcl.cppName != null && metadcl.cppName.length() > 0) {
nameAnnotation = metadcl.indices == 0
? "@Name(\"" + metadcl.cppName + "." + shortName + "\") "
: "@Name({\"" + metadcl.cppName + "\", \"." + shortName + "\"}) ";
javaName = metadcl.javaName + "_" + shortName;
? "@Name(\"" + metadcl.cppName + "." + metadcl.type.cppName + shortName + "\") "
: "@Name({\"" + metadcl.cppName + "\", \"." + metadcl.type.cppName + shortName + "\"}) ";
javaName = metadcl.javaName + "_" + metadcl.type.javaName + shortName;
}
final boolean beanify = context.beanify && indices.isEmpty();
String capitalizedJavaName = null;
Expand Down Expand Up @@ -2709,10 +2709,10 @@ boolean variable(Context context, DeclarationList declList) throws ParserExcepti
}
if (metadcl != null && metadcl.cppName.length() > 0) {
decl.text += metadcl.indices == 0
? "@Name(\"" + metadcl.cppName + "." + shortName + "\") "
: "@Name({\"" + metadcl.cppName + "\", \"." + shortName + "\"}) ";
? "@Name(\"" + metadcl.cppName + "." + metadcl.type.cppName + shortName + "\") "
: "@Name({\"" + metadcl.cppName + "\", \"." + metadcl.type.cppName + shortName + "\"}) ";
dcl.type.annotations = dcl.type.annotations.replaceAll("@Name\\(.*\\) ", "");
javaName = metadcl.javaName + "_" + shortName;
javaName = metadcl.javaName + "_" + metadcl.type.javaName + shortName;
}
tokens.index = backIndex;
Declarator dcl2 = declarator(context, null, -1, false, n, false, false);
Expand Down Expand Up @@ -3428,8 +3428,17 @@ boolean group(Context context, DeclarationList declList) throws ParserException
declarations(ctx, declList2);
} else for (Declarator var : variables) {
if (context.variable != null) {
var.cppName = context.variable.cppName + "." + var.cppName;
var.javaName = context.variable.javaName + "_" + var.javaName;
if (context.variable.indices > 0 && var.indices == 0) {
// allow arrays on metadcl when there are none on dcl
var.indices = context.variable.indices;
var.type.cppName = var.cppName + ".";
var.type.javaName = var.javaName + "_";
var.cppName = context.variable.cppName;
var.javaName = context.variable.javaName;
} else {
var.cppName = context.variable.cppName + "." + var.cppName;
var.javaName = context.variable.javaName + "_" + var.javaName;
}
}
ctx.variable = var;
declarations(ctx, declList2);
Expand Down

0 comments on commit 1c72e35

Please sign in to comment.