Skip to content

Commit

Permalink
* Fix Parser with Info.enumerate failing to translate enum val…
Browse files Browse the repository at this point in the history
…ues based on other `enum` values
  • Loading branch information
saudet committed May 9, 2023
1 parent be4df66 commit b0a8e89
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

* Fix `Parser` with `Info.enumerate` failing to translate `enum` values based on other `enum` values
* Fix `Parser` prematurely expanding macros defined in `class`, `struct` or `union` ([issue #674](https://github.com/bytedeco/javacpp/issues/674))
* Add `Info.upcast` to support class hierarchies with virtual inheritance ([pull #671](https://github.com/bytedeco/javacpp/pull/671))
* Pick up `@Adapter`, `@SharedPtr`, etc annotations on `allocate()` as well ([pull #668](https://github.com/bytedeco/javacpp/pull/668))
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/org/bytedeco/javacpp/tools/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ Type type(Context context, boolean definition) throws ParserException {
}
type.cppName += separator;
Info info = infoMap.getFirst(t.cppName);
String s = info != null && info.cppTypes != null ? info.cppTypes[0] : t.cppName;
String s = info != null && info.cppTypes != null && info.cppTypes.length > 0 ? info.cppTypes[0] : t.cppName;
if (t.constValue && !s.startsWith("const ")) {
s = "const " + s;
}
Expand Down Expand Up @@ -3952,10 +3952,11 @@ boolean enumeration(Context context, DeclarationList declList) throws ParserExce
}
String cast = javaType.equals("byte") || javaType.equals("short") ? "(" + javaType + ")(" : "";
text += spacing + javaName + spacing2 + " = " + cast + countPrefix;
text2 += spacing + javaName + spacing2 + "(" + cast + countPrefix;
if (enumeratorMap.containsKey(countPrefix.trim())) {
text2 += ".value";
String countPrefix2 = countPrefix;
for (String key : enumeratorMap.keySet()) {
countPrefix2 = countPrefix2.replaceAll("\\b" + key + "\\b", key + ".value");
}
text2 += spacing + javaName + spacing2 + "(" + cast + countPrefix2;
if (countPrefix.trim().length() > 0) {
if (count > 0) {
text += " + " + count;
Expand Down

0 comments on commit b0a8e89

Please sign in to comment.