Skip to content

Commit

Permalink
Fix various small issues with Parser
Browse files Browse the repository at this point in the history
  • Loading branch information
saudet committed Feb 28, 2018
1 parent 0822f0c commit 65c41d9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Let `Generator` pick up `@NoException` annotations from super classes as well
* Add `-stdlib=libc++` option to iOS properties, required by `clang++` to support C++11 ([pull #221](https://github.com/bytedeco/javacpp/pull/221))
* Make it possible to define read-only containers with `Parser` by prepending `const ` ([issue #223](https://github.com/bytedeco/javacpp/issues/223))
* Fix `Parser` failure of variable or function declarations on names starting with `::`
* Fix `Parser` failure of variable or function declarations on names starting with `::`, among other various small issues
* Access elements of basic containers defined in `Parser` with `at()` instead of `operator[]` ([issue #223](https://github.com/bytedeco/javacpp/issues/223))
* Add third element to `@Const` annotation to support `virtual const` functions ([pull #224](https://github.com/bytedeco/javacpp/pull/224))
* Create more symbolic links to libraries preloaded by `Loader` to satisfy libraries like MKL
Expand Down
25 changes: 19 additions & 6 deletions src/main/java/org/bytedeco/javacpp/tools/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ void containers(Context context, DeclarationList declList) throws ParserExceptio
for (int i = 0; i < valueType.indirections; i++) {
cast += "*";
}
} else if (!valueType.value) {
cast += "*";
}
if (valueType.reference) {
cast += "&";
Expand Down Expand Up @@ -291,6 +293,9 @@ void containers(Context context, DeclarationList declList) throws ParserExceptio
if (indexType != null && !indexType.annotations.contains("@Const") && !indexType.annotations.contains("@Cast") && !indexType.value) {
indexType.annotations += "@Const ";
}
if (!valueType.annotations.contains("@Const") && !valueType.value) {
valueType.annotations += "@Const ";
}
decl.text += "\n"
+ " public native @ByVal Iterator begin();\n"
+ " public native @ByVal Iterator end();\n"
Expand Down Expand Up @@ -1619,11 +1624,11 @@ Parameters parameters(Context context, int infoNumber, boolean useDefaults) thro
defaultToken = tokens.get();
int count2 = 0;
for (token = tokens.next(), token.spacing = ""; !token.match(Token.EOF); token = tokens.next()) {
if (count2 == 0 && token.match(',', ')')) {
if (count2 == 0 && token.match(',', ')', '}')) {
break;
} else if (token.match('(')) {
} else if (token.match('(', '{')) {
count2++;
} else if (token.match(')')) {
} else if (token.match(')', '}')) {
count2--;
}

Expand Down Expand Up @@ -1802,7 +1807,7 @@ boolean function(Context context, DeclarationList declList) throws ParserExcepti
if (context.namespace != null && namespace < 0) {
dcl.cppName = context.namespace + "::" + dcl.cppName;
}
Info info = null;
Info info = null, fullInfo = null;
String fullname = dcl.cppName, fullname2 = dcl.cppName;
if (dcl.parameters != null) {
fullname += "(";
Expand Down Expand Up @@ -1833,7 +1838,7 @@ boolean function(Context context, DeclarationList declList) throws ParserExcepti
separator = ", ";
}
}
info = infoMap.getFirst(fullname += ")");
info = fullInfo = infoMap.getFirst(fullname += ")");
if (info == null) {
info = infoMap.getFirst(fullname2 += ")");
}
Expand Down Expand Up @@ -1878,7 +1883,9 @@ boolean function(Context context, DeclarationList declList) throws ParserExcepti
if (tokens.get().match('{')) {
body();
} else {
tokens.next();
while (!tokens.get().match(';', Token.EOF)) {
tokens.next();
}
}
decl.text = spacing;
decl.function = true;
Expand Down Expand Up @@ -1970,6 +1977,12 @@ boolean function(Context context, DeclarationList declList) throws ParserExcepti
if (context.namespace != null && context.javaName == null) {
decl.text += "@Namespace(\"" + context.namespace + "\") ";
}
// append annotations specified for a full function declaration only to avoid overlap with type.annotations
if (fullInfo != null && fullInfo.annotations != null) {
for (String s : fullInfo.annotations) {
decl.text += s + " ";
}
}
if (type.constructor && params != null) {
decl.text += "public " + context.shorten(context.javaName) + dcl.parameters.list + " { super((Pointer)null); allocate" + params.names + "; }\n" +
"private native " + type.annotations + "void allocate" + dcl.parameters.list + ";\n";
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/org/bytedeco/javacpp/tools/TokenIndexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,16 @@ Token[] expand(Token[] array, int index) {
boolean foundArg = false;
for (int i = 0; i < params.size(); i++) {
if (params.get(i).equals(token.value)) {
tokens.addAll(args[i]);
String s = token.spacing;
for (Token arg : args[i]) {
// clone tokens here to avoid potential problems with concatenation below
Token t = new Token(arg);
if (s != null) {
t.spacing += s;
}
tokens.add(t);
s = null;
}
foundArg = true;
break;
}
Expand Down

0 comments on commit 65c41d9

Please sign in to comment.