Skip to content

Commit

Permalink
* Allow Parser to use Info.javaNames for function names containi…
Browse files Browse the repository at this point in the history
…ng parameters as well (issue #492)

 * Fix `Parser` producing incorrect calls to function templates with non-type parameters (issue #491)
  • Loading branch information
saudet committed Jun 4, 2021
1 parent d943c8f commit b4cf59a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

* Allow `Parser` to use `Info.javaNames` for function names containing parameters as well ([issue #492](https://github.com/bytedeco/javacpp/issues/492))
* Fix `Parser` producing incorrect calls to function templates with non-type parameters ([issue #491](https://github.com/bytedeco/javacpp/issues/491))
* Add missing `presets/package-info.java` required for OSGi and add profile for M2Eclipse ([pull #490](https://github.com/bytedeco/javacpp/pull/490))
* Remove unnecessary mutex lock for pthreads on callbacks in `Generator` ([pull #489](https://github.com/bytedeco/javacpp/pull/489))
* Fix `@AsUtf16` handling for setter methods paired with getters in `Generator` ([pull #488](https://github.com/bytedeco/javacpp/pull/488))
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/bytedeco/javacpp/tools/Generator.java
Original file line number Diff line number Diff line change
Expand Up @@ -3723,7 +3723,7 @@ static Allocator allocator(Class<?> cls, Method method) {
}
org.bytedeco.javacpp.annotation.Properties classProperties =
cls.getAnnotation(org.bytedeco.javacpp.annotation.Properties.class);
if (classProperties != null) {
if (Pointer.class.isAssignableFrom(cls) && classProperties != null) {
for (Class c : classProperties.inherit()) {
if ((a = allocator(c, method)) != null) {
break;
Expand All @@ -3748,7 +3748,7 @@ static boolean criticalRegion(Class<?> cls, Method method) {
}
org.bytedeco.javacpp.annotation.Properties classProperties =
cls.getAnnotation(org.bytedeco.javacpp.annotation.Properties.class);
if (classProperties != null) {
if (Pointer.class.isAssignableFrom(cls) && classProperties != null) {
for (Class c : classProperties.inherit()) {
if (criticalRegion = criticalRegion(c, method)) {
break;
Expand All @@ -3773,7 +3773,7 @@ static boolean noException(Class<?> cls, Method method) {
}
org.bytedeco.javacpp.annotation.Properties classProperties =
cls.getAnnotation(org.bytedeco.javacpp.annotation.Properties.class);
if (classProperties != null) {
if (Pointer.class.isAssignableFrom(cls) && classProperties != null) {
for (Class c : classProperties.inherit()) {
if (noException = noException(c, method)) {
break;
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/org/bytedeco/javacpp/tools/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -1606,9 +1606,7 @@ Declarator declarator(Context context, String defaultName, int infoNumber, boole
if (context.namespace != null && localName.startsWith(context.namespace + "::")) {
localName = dcl.cppName.substring(context.namespace.length() + 2);
}
int template = localName.lastIndexOf('<');
String simpleName = template >= 0 ? localName.substring(0, template) : localName;
if (!simpleName.equals(dcl.javaName) && (!localName.contains("::") || context.javaName == null)) {
if (!localName.equals(dcl.javaName) && (!localName.contains("::") || context.javaName == null)) {
type.annotations += "@Name(\"" + localName + "\") ";
}
}
Expand Down Expand Up @@ -2213,7 +2211,7 @@ boolean function(Context context, DeclarationList declList) throws ParserExcepti
if (info == null) {
info = infoMap.getFirst(dcl.cppName);
}
if (!type.constructor && !type.destructor && !type.operator) {
if (!type.constructor && !type.destructor && !type.operator && (context.templateMap == null || context.templateMap.full())) {
infoMap.put(info != null ? new Info(info).cppNames(fullname) : new Info(fullname));
}
}
Expand Down Expand Up @@ -2342,6 +2340,15 @@ boolean function(Context context, DeclarationList declList) throws ParserExcepti
}
}

// use Java names that we may get here but that declarator() did not catch
if (fullInfo != null && fullInfo.javaNames != null && fullInfo.javaNames.length > 0 && !dcl.javaName.equals(fullInfo.javaNames[0])) {
dcl.javaName = fullInfo.javaNames[0];
dcl.signature = dcl.javaName + dcl.parameters.signature;
if (!localName.equals(dcl.javaName) && !type.annotations.contains("@Name(")) {
type.annotations += "@Name(\"" + localName + "\") ";
}
}

// check for const, other attributes, and pure virtual functions, ignoring the body if present
for (Token token = tokens.get(); !token.match(Token.EOF); token = tokens.get()) {
if (token.match(Token.CONST, Token.__CONST, Token.CONSTEXPR)) {
Expand Down

0 comments on commit b4cf59a

Please sign in to comment.