Skip to content

Commit e473740

Browse files
committed
* Let Parser output Info.javaText even for template declarations with no instances
* Prevent `Tokenizer` from using `long` literals for unsigned integers of 16 bits or less
1 parent 123ce0d commit e473740

File tree

5 files changed

+17
-6
lines changed

5 files changed

+17
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11

2+
* Let `Parser` output `Info.javaText` even for template declarations with no instances
3+
* Prevent `Tokenizer` from using `long` literals for unsigned integers of 16 bits or less
24
* Ensure `Parser` considers `>=` and `<=` as single tokens to prevent failures
35
* Make `Parser` use `Info.cppTypes` to override the type of `enum` values
46
* Fix `Parser` not using the correct `Info.pointerTypes` for `const&` declarations

src/main/java/org/bytedeco/javacpp/tools/Declaration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ class Declaration {
3030
Type type = null;
3131
Declarator declarator = null;
3232
boolean abstractMember = false, constMember = false, inaccessible = false,
33-
incomplete = false, function = false, variable = false, comment = false;
33+
incomplete = false, function = false, variable = false, comment = false, custom = false;
3434
String signature = "", text = "";
3535
}

src/main/java/org/bytedeco/javacpp/tools/DeclarationList.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ String rescan(String lines) {
6161

6262
@Override public boolean add(Declaration decl) {
6363
boolean add = true;
64-
if (templateMap != null && templateMap.empty() && (decl.type != null || decl.declarator != null)) {
64+
if (templateMap != null && templateMap.empty() && !decl.custom && (decl.type != null || decl.declarator != null)) {
6565
// method templates cannot be declared in Java, but make sure to make their
6666
// info available on request (when Info.javaNames is set) to be able to create instances
6767
if (infoIterator == null) {

src/main/java/org/bytedeco/javacpp/tools/Parser.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2312,6 +2312,7 @@ boolean function(Context context, DeclarationList declList) throws ParserExcepti
23122312
if (info != null && info.javaText != null) {
23132313
if (first) {
23142314
decl.signature = decl.text = info.javaText;
2315+
decl.custom = true;
23152316
} else {
23162317
break;
23172318
}
@@ -2489,6 +2490,7 @@ boolean variable(Context context, DeclarationList declList) throws ParserExcepti
24892490
if (info != null && info.javaText != null) {
24902491
decl.signature = decl.text = info.javaText;
24912492
decl.declarator = null;
2493+
decl.custom = true;
24922494
}
24932495
while (!tokens.get().match(Token.EOF, ';')) {
24942496
tokens.next();
@@ -2713,6 +2715,7 @@ boolean macro(Context context, DeclarationList declList) throws ParserException
27132715
}
27142716
if (info != null && info.javaText != null) {
27152717
decl.signature = decl.text = info.javaText;
2718+
decl.custom = true;
27162719
break;
27172720
}
27182721
}
@@ -2873,6 +2876,7 @@ boolean typedef(Context context, DeclarationList declList) throws ParserExceptio
28732876

28742877
if (info != null && info.javaText != null) {
28752878
decl.signature = decl.text = info.javaText;
2879+
decl.custom = true;
28762880
}
28772881
String comment = commentAfter();
28782882
decl.text = comment + decl.text;
@@ -2910,6 +2914,7 @@ boolean using(Context context, DeclarationList declList) throws ParserException
29102914
// inherit constructors
29112915
decl.signature = decl.text = info.javaText;
29122916
decl.declarator = dcl;
2917+
decl.custom = true;
29132918
}
29142919
String comment = commentAfter();
29152920
decl.text = comment + decl.text;
@@ -3296,6 +3301,7 @@ boolean group(Context context, DeclarationList declList) throws ParserException
32963301
}
32973302
int end = text.lastIndexOf('}');
32983303
decl.text += text.substring(start, end).replace(base2.javaName, type.javaName);
3304+
decl.custom = true;
32993305
}
33003306
}
33013307
for (Declaration d : declList2) {
@@ -3334,6 +3340,7 @@ boolean group(Context context, DeclarationList declList) throws ParserException
33343340
decl.type = type;
33353341
if (info != null && info.javaText != null) {
33363342
decl.signature = decl.text = info.javaText;
3343+
decl.custom = true;
33373344
} else if (info != null && info.flatten) {
33383345
info.javaText = decl.text;
33393346
}

src/main/java/org/bytedeco/javacpp/tools/Tokenizer.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2014-2017 Samuel Audet
2+
* Copyright (C) 2014-2020 Samuel Audet
33
*
44
* Licensed either under the Apache License, Version 2.0, or (at your option)
55
* under the terms of the GNU General Public License as published by
@@ -180,7 +180,7 @@ public Token nextToken() throws IOException {
180180
token.type = c == '.' ? Token.FLOAT : Token.INTEGER;
181181
buffer.append((char)c);
182182
int prevc = 0;
183-
boolean exp = false, large = false, unsigned = false, hex = false;
183+
boolean exp = false, large = false, unsigned = false, hex = false, small = false;
184184
while ((c = readChar()) != -1 && (Character.isDigit(c) || c == '.' || c == '-' || c == '+' ||
185185
(c >= 'a' && c <= 'f') || c == 'i' || c == 'l' || c == 'u' || c == 'x' ||
186186
(c >= 'A' && c <= 'F') || c == 'I' || c == 'L' || c == 'U' || c == 'X')) {
@@ -201,7 +201,9 @@ public Token nextToken() throws IOException {
201201
}
202202
if (token.type == Token.INTEGER && !large) {
203203
try {
204-
long high = Long.decode(buffer.toString()) >> 32;
204+
long high = Long.decode(buffer.toString()) >> 16L;
205+
small = high == 0 || high == -1;
206+
high >>= 16L;
205207
large = high != 0 && high != -1;
206208
} catch (NumberFormatException e) {
207209
// set as large, for things like 0x8000000000000000L
@@ -214,7 +216,7 @@ public Token nextToken() throws IOException {
214216
buffer.setLength(buffer.length() - 3);
215217
large = true;
216218
}
217-
if (token.type == Token.INTEGER && (large || (unsigned && !hex))) {
219+
if (token.type == Token.INTEGER && (large || (unsigned && !hex && !small))) {
218220
buffer.append('L');
219221
}
220222
token.value = buffer.toString();

0 commit comments

Comments
 (0)