From dd145115fdd1ccf68c16c3acf99c700ea3a46ec3 Mon Sep 17 00:00:00 2001 From: Samuel Audet Date: Sat, 28 Jun 2014 12:11:02 +0900 Subject: [PATCH] * Fix issues in the `Parser` with access specifiers and casting of const values by reference --- CHANGELOG.md | 2 +- .../java/org/bytedeco/javacpp/tools/Parser.java | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 50d284d1a..2480b44c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ - * Fix a few other minor issues in the `Parser` + * Fix a few other minor issues in the `Parser` with the `long double` type, floating-point numbers, macro redefinitions, access specifiers, casting of const values by reference * Allow users to instruct the `Parser` to skip the expansion of specific macro invocations * Let `Parser` concatenate tokens when expanding macros containing the `##` operator * Add some documentation for `Info`, `InfoMap`, `InfoMapper`, and `Parser` diff --git a/src/main/java/org/bytedeco/javacpp/tools/Parser.java b/src/main/java/org/bytedeco/javacpp/tools/Parser.java index d9b13e9b3..ac6fd4280 100644 --- a/src/main/java/org/bytedeco/javacpp/tools/Parser.java +++ b/src/main/java/org/bytedeco/javacpp/tools/Parser.java @@ -442,9 +442,6 @@ Declarator declarator(Context context, String defaultName, int infoNumber, boole } cast += token; } - if (dcl.indirections == 0 && dcl.reference) { - cast = cast.replace('&', '*'); - } ArrayList attributes = new ArrayList(); if (type.attributes != null) { @@ -662,6 +659,14 @@ Declarator declarator(Context context, String defaultName, int infoNumber, boole } } if (needCast) { + if (dcl.indirections == 0 && dcl.reference) { + // consider as pointer type + cast = cast.replace('&', '*'); + } + if (valueType && type.constValue && dcl.reference) { + // consider as value type + cast = cast.substring(0, cast.length() - 1); + } if (type.constValue) { cast = "const " + cast; } @@ -1881,9 +1886,10 @@ boolean extern(Context context, DeclarationList declList) throws ParserException void declarations(Context context, DeclarationList declList) throws ParserException { for (Token token = tokens.get(); !token.match(Token.EOF, '}'); token = tokens.get()) { - if (token.match(Token.PRIVATE, Token.PROTECTED, Token.PUBLIC) && tokens.next().match(':')) { + while (token.match(Token.PRIVATE, Token.PROTECTED, Token.PUBLIC) && tokens.get(1).match(':')) { context.inaccessible = !token.match(Token.PUBLIC); tokens.next(); + tokens.next(); } Context ctx = context; String comment = commentBefore();