Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename function parameters using a reserved keyword #757

Merged
merged 6 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

* Let `Parser` annotate Java constructors with `@Deprecated` when appropriate ([pull #757](https://github.com/bytedeco/javacpp/pull/757))
* Add to `InfoMap.defaults` more names that are reserved in Java, but not in C++ ([pull #757](https://github.com/bytedeco/javacpp/pull/757))
* Bundle `libomp` from Visual Studio to fix presets using OpenMP on Windows ([pull #755](https://github.com/bytedeco/javacpp/pull/755))
* Fix inconsistencies when using `@Platform(inherit=..., library=...)` together ([pull #747](https://github.com/bytedeco/javacpp/pull/747))
* Let `Parser` support templates with unnamed type parameters ([pull #742](https://github.com/bytedeco/javacpp/pull/742))
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/bytedeco/javacpp/tools/InfoMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,23 @@ public class InfoMap extends HashMap<String,List<Info>> {
.put(new Info("std::vector").annotations("@StdVector"))

.put(new Info("abstract").javaNames("_abstract"))
.put(new Info("assert").javaNames("_assert"))
.put(new Info("boolean").javaNames("_boolean"))
.put(new Info("byte").javaNames("_byte"))
.put(new Info("extends").javaNames("_extends"))
.put(new Info("final").javaNames("_final"))
.put(new Info("finally").javaNames("_finally"))
.put(new Info("implements").javaNames("_implements"))
.put(new Info("import").javaNames("_import"))
.put(new Info("instanceof").javaNames("_instanceof"))
.put(new Info("interface").javaNames("_interface"))
.put(new Info("native").javaNames("_native"))
.put(new Info("null").javaNames("_null"))
.put(new Info("package").javaNames("_package"))
.put(new Info("strictfp").javaNames("_strictfp"))
.put(new Info("super").javaNames("_super"))
.put(new Info("synchronized").javaNames("_synchronized"))
.put(new Info("throws").javaNames("_throws"))
.put(new Info("transient").javaNames("_transient"))

.put(new Info("operator ->").javaNames("access"))
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/org/bytedeco/javacpp/tools/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ static String desugarVarargs(String s) {
return s.trim().endsWith("...") ? s.trim().substring(0, s.length() - 3) + "[]" : s;
}

static String filterJavaAnnotations(String s) {
return s.contains("@Deprecated") ? "@Deprecated " : "";
}

static String upcastMethodName(String javaName) {
String shortName = javaName.substring(javaName.lastIndexOf('.') + 1);
return "as" + Character.toUpperCase(shortName.charAt(0)) + shortName.substring(1);
Expand Down Expand Up @@ -357,7 +361,7 @@ void containers(Context context, DeclarationList declList) throws ParserExceptio
if (dim < 2 && !javaName.equals("int") && !javaName.equals("long")) {
decl.text += " public " + containerType.javaName + "(" + javaName + " value) { this(1); put(0, value); }\n";
}
decl.text += " public " + containerType.javaName + "(" + javaName + arrayBrackets + " ... array) { this(array.length); put(array); }\n";
decl.text += " public " + containerType.javaName + "(" + desugarVarargs(javaName) + arrayBrackets + " ... array) { this(array.length); put(array); }\n";
}
} else if (indexType == null && dim == 0 && !constant && !purify) {
int n = 0;
Expand Down Expand Up @@ -597,7 +601,7 @@ void containers(Context context, DeclarationList declList) throws ParserExceptio
+ " return put(0, value);\n"
+ " }\n";
}
decl.text += " public " + containerType.javaName + " put(" + javaName + arrayBrackets + " ... array) {\n";
decl.text += " public " + containerType.javaName + " put(" + desugarVarargs(javaName) + arrayBrackets + " ... array) {\n";
String indent = " ", indices = "", args = "";
separator = "";
for (int i = 0; i < dim; i++) {
Expand Down Expand Up @@ -2740,7 +2744,7 @@ boolean function(Context context, DeclarationList declList) throws ParserExcepti
}
}
if (type.constructor && params != null) {
decl.text += "public " + context.shorten(context.javaName) + dcl.parameters.list + " { super((Pointer)null); allocate" + params.names + "; }\n" +
decl.text += filterJavaAnnotations(type.annotations) + "public " + context.shorten(context.javaName) + dcl.parameters.list + " { super((Pointer)null); allocate" + params.names + "; }\n" +
type.annotations + "private native void allocate" + dcl.parameters.list + ";\n";
} else {
String modifiers2 = modifiers;
Expand Down Expand Up @@ -3494,7 +3498,7 @@ String downcast(Type derived, Type base, boolean virtual) {
}
String shortName = derived.javaName.substring(derived.javaName.lastIndexOf('.') + 1);
String res = " /** Downcast constructor. */\n"
+ " public " + shortName + "(" + base.javaName + " pointer) { super((Pointer)null); allocate(pointer); }\n";
+ " " + filterJavaAnnotations(annotations) + "public " + shortName + "(" + base.javaName + " pointer) { super((Pointer)null); allocate(pointer); }\n";
if (annotations.isEmpty()) {
res += " @Namespace private native @Name(\"" + downcastType + "_cast<" + derived.cppName + "*>\") void allocate(" + base.javaName + " pointer);\n";
} else {
Expand Down Expand Up @@ -3931,7 +3935,7 @@ boolean group(Context context, DeclarationList declList) throws ParserException

if (implicitConstructor && (info == null || !info.purify) && (!abstractClass || ctx.virtualize)) {
constructors += " /** Default native constructor. */\n" +
" public " + shortName + "() { super((Pointer)null); allocate(); }\n";
" " + filterJavaAnnotations(constructorAnnotations) + "public " + shortName + "() { super((Pointer)null); allocate(); }\n";
if (constructorAnnotations.isEmpty()) {
constructors += " /** Native array allocator. Access with {@link Pointer#position(long)}. */\n" +
" public " + shortName + "(long size) { super((Pointer)null); allocateArray(size); }\n";
Expand Down