Skip to content

Commit

Permalink
Fix Parser not picking up Info.javaNames with function parameters…
Browse files Browse the repository at this point in the history
… containing '::' (issue #491)
  • Loading branch information
saudet committed Jun 9, 2021
1 parent b7dbf1c commit 82b8bde
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
11 changes: 7 additions & 4 deletions src/main/java/org/bytedeco/javacpp/tools/InfoMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ String normalize(String name, boolean unconst, boolean untemplate) {
name += " " + tokens[i].value;
}
} else if (untemplate) {
int count = 0, lastColon = -1, template = -1, parameters = -1;
int count = 0, lastColon = -1, template = -1, parameters = n;
for (int i = 0; i < n; i++) {
if (tokens[i].match('<')) {
count++;
Expand All @@ -218,18 +218,21 @@ String normalize(String name, boolean unconst, boolean untemplate) {
}
if (count == 0 && tokens[i].match("::")) {
lastColon = i;
} else if (count == 0 && tokens[i].match('(')) {
parameters = i;
break;
}
}
for (int i = 0; i < n; i++) {
for (int i = 0; i < parameters; i++) {
if (i > lastColon && tokens[i].match('<')) {
if (count == 0) {
template = i;
}
count++;
} else if (i > lastColon && tokens[i].match('>')) {
count--;
if (count == 0) {
parameters = i + 1;
if (count == 0 && i + 1 != parameters) {
template = -1;
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/org/bytedeco/javacpp/tools/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -1606,7 +1606,9 @@ 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);
}
if (!localName.equals(dcl.javaName) && (!localName.contains("::") || context.javaName == null)) {
int template = localName.lastIndexOf('<');
String simpleName = template >= 0 ? localName.substring(0, template) : localName;
if (!localName.equals(dcl.javaName) && (!simpleName.contains("::") || context.javaName == null)) {
type.annotations += "@Name(\"" + localName + "\") ";
}
}
Expand Down Expand Up @@ -2360,7 +2362,9 @@ boolean function(Context context, DeclarationList declList) throws ParserExcepti
if (fullInfo != null && fullInfo.javaNames != null && fullInfo.javaNames.length > 0) {
dcl.javaName = fullInfo.javaNames[0];
dcl.signature = dcl.javaName + dcl.parameters.signature;
if (!localName2.equals(dcl.javaName) && (!localName2.contains("::") || context.javaName == null)) {
int template = localName2.lastIndexOf('<');
String simpleName = template >= 0 ? localName2.substring(0, template) : localName2;
if (!localName2.equals(dcl.javaName) && (!simpleName.contains("::") || context.javaName == null)) {
type.annotations = type.annotations.replaceAll("@Name\\(.*\\) ", "");
type.annotations += "@Name(\"" + localName2 + "\") ";
}
Expand Down

0 comments on commit 82b8bde

Please sign in to comment.