diff --git a/src/main/java/org/bytedeco/javacpp/tools/Context.java b/src/main/java/org/bytedeco/javacpp/tools/Context.java index e73914f4a..e08220274 100644 --- a/src/main/java/org/bytedeco/javacpp/tools/Context.java +++ b/src/main/java/org/bytedeco/javacpp/tools/Context.java @@ -72,6 +72,10 @@ class Context { /** Return all likely combinations of namespaces and template arguments for this C++ type */ String[] qualify(String cppName) { + return qualify(cppName, null); + } + /** or function, if parameters != null */ + String[] qualify(String cppName, String parameters) { if (cppName == null || cppName.length() == 0) { return new String[0]; } @@ -86,9 +90,16 @@ String[] qualify(String cppName) { String ns = namespace != null ? namespace : ""; while (ns != null) { String name = ns.length() > 0 ? ns + "::" + cppName : cppName; + if (parameters != null && name.endsWith(parameters)) { + name = name.substring(0, name.length() - parameters.length()); + } TemplateMap map = templateMap; while (map != null) { - if (name.equals(map.getName())) { + String name2 = map.getName(); + if (parameters != null && name2 != null && name2.endsWith(parameters)) { + name2 = name2.substring(0, name2.length() - parameters.length()); + } + if (name.equals(name2)) { String args = "<", separator = ""; for (Type t : map.values()) { // assume that missing arguments have default values @@ -97,7 +108,7 @@ String[] qualify(String cppName) { separator = ","; } } - names.add(name + args + (args.endsWith(">") ? " >" : ">")); + names.add(name + args + (args.endsWith(">") ? " >" : ">") + (parameters != null ? parameters : "")); break; } map = map.parent; diff --git a/src/main/java/org/bytedeco/javacpp/tools/DeclarationList.java b/src/main/java/org/bytedeco/javacpp/tools/DeclarationList.java index 04010f3d7..d110500ed 100644 --- a/src/main/java/org/bytedeco/javacpp/tools/DeclarationList.java +++ b/src/main/java/org/bytedeco/javacpp/tools/DeclarationList.java @@ -60,6 +60,9 @@ String rescan(String lines) { } @Override public boolean add(Declaration decl) { + return add(decl, null); + } + public boolean add(Declaration decl, String fullName) { boolean add = true; if (templateMap != null && templateMap.empty() && !decl.custom && (decl.type != null || decl.declarator != null)) { // method templates cannot be declared in Java, but make sure to make their @@ -67,13 +70,19 @@ String rescan(String lines) { if (infoIterator == null) { Type type = templateMap.type = decl.type; Declarator dcl = templateMap.declarator = decl.declarator; - List infoList = infoMap.get(dcl != null ? dcl.cppName : type.cppName); - boolean hasJavaName = false; - for (Info info : infoList) { - hasJavaName |= info.javaNames != null && info.javaNames.length > 0; - } - if (!decl.function || hasJavaName) { - infoIterator = infoList.size() > 0 ? infoList.listIterator() : null; + for (String name : new String[] {fullName, dcl != null ? dcl.cppName : type.cppName}) { + if (name == null) { + continue; + } + List infoList = infoMap.get(name); + boolean hasJavaName = false; + for (Info info : infoList) { + hasJavaName |= info.javaNames != null && info.javaNames.length > 0; + } + if (!decl.function || hasJavaName) { + infoIterator = infoList.size() > 0 ? infoList.listIterator() : null; + break; + } } } add = false; diff --git a/src/main/java/org/bytedeco/javacpp/tools/InfoMap.java b/src/main/java/org/bytedeco/javacpp/tools/InfoMap.java index 904c13051..d889a167a 100644 --- a/src/main/java/org/bytedeco/javacpp/tools/InfoMap.java +++ b/src/main/java/org/bytedeco/javacpp/tools/InfoMap.java @@ -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; + int count = 0, lastColon = -1, template = -1, parameters = -1; for (int i = 0; i < n; i++) { if (tokens[i].match('<')) { count++; @@ -228,8 +228,8 @@ String normalize(String name, boolean unconst, boolean untemplate) { count++; } else if (i > lastColon && tokens[i].match('>')) { count--; - if (count == 0 && i + 1 != n) { - template = -1; + if (count == 0) { + parameters = i + 1; } } } @@ -238,6 +238,9 @@ String normalize(String name, boolean unconst, boolean untemplate) { for (int i = 0; i < template; i++) { name += tokens[i]; } + for (int i = parameters; i < n; i++) { + name += tokens[i].spacing + tokens[i]; + } } } if (unconst && foundConst) { diff --git a/src/main/java/org/bytedeco/javacpp/tools/Parser.java b/src/main/java/org/bytedeco/javacpp/tools/Parser.java index 304a64b30..5b6c7abd5 100644 --- a/src/main/java/org/bytedeco/javacpp/tools/Parser.java +++ b/src/main/java/org/bytedeco/javacpp/tools/Parser.java @@ -2189,9 +2189,9 @@ boolean function(Context context, DeclarationList declList) throws ParserExcepti separator = ", "; } } - info = fullInfo = infoMap.getFirst(fullname += ")"); + info = fullInfo = infoMap.getFirst(fullname += ")", false); if (info == null) { - info = infoMap.getFirst(fullname2 += ")"); + info = infoMap.getFirst(fullname2 += ")", false); } } if (info == null) { @@ -2212,7 +2212,7 @@ boolean function(Context context, DeclarationList declList) throws ParserExcepti info = infoMap.getFirst(dcl.cppName); } 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)); + infoMap.put(info != null ? new Info(info).cppNames(fullname).javaNames(null) : new Info(fullname)); } } String localName = dcl.cppName; @@ -2341,11 +2341,28 @@ 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])) { + String parameters = fullname.substring(dcl.cppName.length()); + for (String name : context.qualify(dcl.cppName, parameters)) { + if ((infoMap.getFirst(name, false)) != null) { + dcl.cppName = name; + break; + } else if (infoMap.getFirst(name) != null) { + dcl.cppName = name; + } + } + String localName2 = dcl.cppName; + if (context.namespace != null && localName2.startsWith(context.namespace + "::")) { + localName2 = dcl.cppName.substring(context.namespace.length() + 2); + } + if (localName2.endsWith(parameters)) { + localName2 = localName2.substring(0, localName2.length() - parameters.length()); + } + if (fullInfo != null && fullInfo.javaNames != null && fullInfo.javaNames.length > 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 + "\") "; + if (!localName2.equals(dcl.javaName) && (!localName2.contains("::") || context.javaName == null)) { + type.annotations = type.annotations.replaceAll("@Name\\(.*\\) ", ""); + type.annotations += "@Name(\"" + localName2 + "\") "; } } @@ -2461,7 +2478,7 @@ boolean function(Context context, DeclarationList declList) throws ParserExcepti found |= dcl.signature.equals(d.signature); } if (dcl.javaName.length() > 0 && !found && (!type.destructor || (info != null && info.javaText != null))) { - if (declList.add(decl)) { + if (declList.add(decl, fullname)) { first = false; } if (type.virtual && context.virtualize) {