diff --git a/CHANGELOG.md b/CHANGELOG.md index b16481f9..f8cbea17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ + * Fix `Parser` failing on nested initializer lists and on attributes found inside `enum` declarations * Fix `Parser` for basic containers like `std::optional >` ([issue #718](https://github.com/bytedeco/javacpp/issues/718)) * Add support for `std::basic_string` basic container ([issue bytedeco/javacpp-presets#1311](https://github.com/bytedeco/javacpp-presets/issues/1311)) * Enhance `Parser` by adding downcast constructors for polymorphic classes ([pull #700](https://github.com/bytedeco/javacpp/pull/700)) diff --git a/src/main/java/org/bytedeco/javacpp/tools/InfoMap.java b/src/main/java/org/bytedeco/javacpp/tools/InfoMap.java index f776b4ca..ba6ee471 100644 --- a/src/main/java/org/bytedeco/javacpp/tools/InfoMap.java +++ b/src/main/java/org/bytedeco/javacpp/tools/InfoMap.java @@ -47,6 +47,7 @@ public class InfoMap extends HashMap> { "std::function", "std::basic_string")) .put(new Info("basic/types").cppTypes("signed", "unsigned", "char", "short", "int", "long", "bool", "float", "double", "__int8", "__int16", "__int32", "__int64", "_Bool", "_Complex", "_Imaginary", "complex", "imaginary")) + .put(new Info("deprecated").annotations("@Deprecated")) .put(new Info("noexcept").annotations("@NoException(true)")) .put(new Info("__COUNTER__").cppText("#define __COUNTER__ 0")) diff --git a/src/main/java/org/bytedeco/javacpp/tools/Parser.java b/src/main/java/org/bytedeco/javacpp/tools/Parser.java index 77056e4d..ca9c3c45 100644 --- a/src/main/java/org/bytedeco/javacpp/tools/Parser.java +++ b/src/main/java/org/bytedeco/javacpp/tools/Parser.java @@ -2294,8 +2294,8 @@ boolean function(Context context, DeclarationList declList) throws ParserExcepti count--; } - // consider { ... } preceded by an identifier or `>` as an initializer list - if (count == 0 && !token.match(Token.IDENTIFIER, '>') && tokens.get(1).match('{')) { + // consider { ... } preceded by an identifier, a comma, or `>` as an initializer list + if (count == 0 && !token.match(Token.IDENTIFIER, ',', '>') && tokens.get(1).match('{')) { tokens.next(); break; } @@ -2426,8 +2426,8 @@ boolean function(Context context, DeclarationList declList) throws ParserExcepti count--; } - // consider { ... } preceded by an identifier or `>` as an initializer list - if (count == 0 && !token.match(Token.IDENTIFIER, '>') && tokens.get(1).match('{')) { + // consider { ... } preceded by an identifier, a comma, or `>` as an initializer list + if (count == 0 && !token.match(Token.IDENTIFIER, ',', '>') && tokens.get(1).match('{')) { tokens.next(); break; } @@ -2506,8 +2506,8 @@ boolean function(Context context, DeclarationList declList) throws ParserExcepti count--; } - // consider { ... } preceded by an identifier or `>` as an initializer list - if (count == 0 && !token.match(Token.IDENTIFIER, '>') && tokens.get(1).match('{')) { + // consider { ... } preceded by an identifier, a comma, or `>` as an initializer list + if (count == 0 && !token.match(Token.IDENTIFIER, ',', '>') && tokens.get(1).match('{')) { tokens.next(); break; } @@ -4065,8 +4065,15 @@ boolean enumeration(Context context, DeclarationList declList) throws ParserExce } else if (info == null) { infoMap.put(info = new Info(cppName).cppText("").translate()); } + tokens.next(); + String annotations = ""; + Attribute attr = attribute(true); + while (attr != null && attr.annotation) { + annotations += attr.javaName; + attr = attribute(true); + } String spacing2 = ""; - if (tokens.next().match('=')) { + if (tokens.get().match('=')) { spacing2 = tokens.get().spacing; if (spacing2.length() > 0 && spacing2.charAt(0) == ' ') { spacing2 = spacing2.substring(1); @@ -4104,7 +4111,6 @@ boolean enumeration(Context context, DeclarationList declList) throws ParserExce if (separator.equals(",")) { separator = ";"; } - String annotations = ""; if (!javaName.equals(cppName)){ annotations += "@Name(\"" + cppName + "\") "; } else if (context.namespace != null && context.javaName == null) { @@ -4142,12 +4148,12 @@ boolean enumeration(Context context, DeclarationList declList) throws ParserExce spacing = " "; } String cast = javaType.equals("byte") || javaType.equals("short") ? "(" + javaType + ")(" : ""; - text += spacing + javaName + spacing2 + " = " + cast + countPrefix; + text += spacing + annotations + javaName + spacing2 + " = " + cast + countPrefix; String countPrefix2 = countPrefix; for (String key : enumeratorMap.keySet()) { countPrefix2 = countPrefix2.replaceAll("\\b" + key + "\\b", key + ".value"); } - text2 += spacing + javaName + spacing2 + "(" + cast + countPrefix2; + text2 += spacing + annotations + javaName + spacing2 + "(" + cast + countPrefix2; if (countPrefix.trim().length() > 0) { if (count > 0) { text += " + " + count;