Skip to content

Commit

Permalink
* Let Parser create mutable instances of map containers without `c…
Browse files Browse the repository at this point in the history
…onst ` prefix (issue bytedeco/javacpp-presets#595)

 * Fix `Parser` sometimes ignoring `define` of `const ` containers (pull bytedeco/javacpp-presets#547)
  • Loading branch information
saudet committed Aug 3, 2018
1 parent 7cfd1bf commit 391002c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

* Let `Parser` create mutable instances of map containers without `const ` prefix ([issue bytedeco/javacpp-presets#595](https://github.com/bytedeco/javacpp-presets/issues/595))
* Fix `Parser` sometimes ignoring `define` of `const ` containers ([pull bytedeco/javacpp-presets#547](https://github.com/bytedeco/javacpp-presets/pull/547))
* Explain the purpose of the `intern()` methods generated for Java enums
* Clarify that `Loader.load()` can throw `UnsatisfiedLinkError` when interrupted
* Synchronize `Loader.loadLibrary()` to fix potential race condition ([pull #246](https://github.com/bytedeco/javacpp/pull/246))
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/org/bytedeco/javacpp/tools/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ void containers(Context context, DeclarationList declList) throws ParserExceptio
} else if (containerName.endsWith("list") || containerName.endsWith("set")) {
indexType = null;
resizable = false;
} else if (!constant && !resizable) {
indexFunction = ""; // maps need operator[] to be writable
}
while (valueType.cppName.startsWith(containerName)
&& leafInfoMap.get(valueType.cppName, false).size() == 0) {
Expand Down Expand Up @@ -1117,9 +1119,12 @@ Declarator declarator(Context context, String defaultName, int infoNumber, boole

int infoLength = 1;
boolean valueType = false, needCast = arrayAsPointer && dcl.indices > 1, implicitConst = false;
String prefix = type.constValue && dcl.indirections < 2 && !dcl.reference ? "const " : "";
Info info = infoMap.getFirst(prefix + type.cppName, false);
if ((!typedef || dcl.parameters != null) && (info == null || (info.cppTypes != null && info.cppTypes.length > 0))) {
Info constInfo = infoMap.getFirst("const " + type.cppName, false);
Info info = type.constValue && dcl.indirections < 2 && !dcl.reference ? constInfo
: infoMap.getFirst(type.cppName, false);
if ((!typedef || dcl.parameters != null)
&& (constInfo == null || (constInfo.cppTypes != null && constInfo.cppTypes.length > 0))
&& (info == null || (info.cppTypes != null && info.cppTypes.length > 0))) {
// substitute template types that have no info with appropriate adapter annotation
Type type2 = type;
if (info != null) {
Expand Down Expand Up @@ -1173,7 +1178,7 @@ Declarator declarator(Context context, String defaultName, int infoNumber, boole
&& ((type.constValue && dcl.indirections == 0 && dcl.reference)
|| (dcl.indirections == 0 && !dcl.reference)
|| info.pointerTypes == null);
implicitConst = info.cppNames[0].startsWith("const ");
implicitConst = info.cppNames[0].startsWith("const ") && !info.define;
infoLength = valueType ? (info.valueTypes != null ? info.valueTypes.length : 1)
: (info.pointerTypes != null ? info.pointerTypes.length : 1);
dcl.infoNumber = infoNumber < 0 ? 0 : infoNumber % infoLength;
Expand Down

0 comments on commit 391002c

Please sign in to comment.