summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam S Fulton <wsf@fultondesigns.co.uk>2016-01-27 08:54:44 +0000
committerWilliam S Fulton <wsf@fultondesigns.co.uk>2016-01-27 09:01:00 +0000
commit7339de974dde92dbc9bb912e4f94091aee82f0ec (patch)
tree35246643f57f2d470cd85fb5a40f1df7a2a3505e
parent95eb6649ead4cb593e5e2c11f0899ac3b48c624d (diff)
downloadswig-7339de974dde92dbc9bb912e4f94091aee82f0ec.tar.gz
Fix static const char member variables wrappers with %javaconst(1).
This fixes the case when an integer is used as the initializer, such as: struct W { static const char w = 100; }; The "valuetype" attribute has been added to the "cdecl" Node which enables us to distinguish the declared type from the type of the initializer.
-rw-r--r--CHANGES.current8
-rw-r--r--Examples/test-suite/chartest.i38
-rw-r--r--Source/CParse/parser.y8
-rw-r--r--Source/Modules/java.cxx3
4 files changed, 55 insertions, 2 deletions
diff --git a/CHANGES.current b/CHANGES.current
index 4406f1225..2091d89a2 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -5,9 +5,15 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 3.0.9 (in progress)
===========================
+2016-01-27: wsfulton
+ [Java] Fix static const char member variables wrappers with %javaconst(1).
+ This fixes the case when an integer is used as the initializer, such as:
+
+ struct W { static const char w = 100; };
+
2016-01-26: wsfulton
[Java] Fix generated code parsing enum values using char escape sequences
- when these values appear in the Java code (usually when using %javaconst)
+ when these values appear in the Java code (usually when using %javaconst(1))
such as:
enum X { x1 = '\n', x2 = '\1' };
diff --git a/Examples/test-suite/chartest.i b/Examples/test-suite/chartest.i
index cc30b51bc..e9b25f782 100644
--- a/Examples/test-suite/chartest.i
+++ b/Examples/test-suite/chartest.i
@@ -20,6 +20,9 @@ static const char globcharB = '\102'; // B
static const char globcharC = '\x43'; // C
static const char globcharD = 0x44; // D
static const char globcharE = 69; // E
+static const char globcharAE1 = 'Æ'; // AE (latin1 encoded)
+static const char globcharAE2 = '\306'; // AE (latin1 encoded)
+static const char globcharAE3 = '\xC6'; // AE (latin1 encoded)
struct CharTestClass {
static const char memberchar0 = '\0';
@@ -30,5 +33,40 @@ struct CharTestClass {
static const char membercharC = '\x43'; // C
static const char membercharD = 0x44; // D
static const char membercharE = 69; // E
+ static const char membercharAE1 = 'Æ'; // AE (latin1 encoded)
+ static const char membercharAE2 = '\306'; // AE (latin1 encoded)
+ static const char membercharAE3 = '\xC6'; // AE (latin1 encoded)
+};
+%}
+
+#if defined(SWIGJAVA)
+%javaconst(1);
+#endif
+
+%inline %{
+static const char x_globchar0 = '\0';
+static const char x_globchar1 = '\1';
+static const char x_globchar2 = '\n';
+static const char x_globcharA = 'A';
+static const char x_globcharB = '\102'; // B
+static const char x_globcharC = '\x43'; // C
+static const char x_globcharD = 0x44; // D
+static const char x_globcharE = 69; // E
+static const char x_globcharAE1 = 'Æ'; // AE (latin1 encoded)
+static const char x_globcharAE2 = '\306'; // AE (latin1 encoded)
+static const char x_globcharAE3 = '\xC6'; // AE (latin1 encoded)
+
+struct X_CharTestClass {
+ static const char memberchar0 = '\0';
+ static const char memberchar1 = '\1';
+ static const char memberchar2 = '\n';
+ static const char membercharA = 'A';
+ static const char membercharB = '\102'; // B
+ static const char membercharC = '\x43'; // C
+ static const char membercharD = 0x44; // D
+ static const char membercharE = 69; // E
+ static const char membercharAE1 = 'Æ'; // AE (latin1 encoded)
+ static const char membercharAE2 = '\306'; // AE (latin1 encoded)
+ static const char membercharAE3 = '\xC6'; // AE (latin1 encoded)
};
%}
diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y
index 621d43421..a38edbc36 100644
--- a/Source/CParse/parser.y
+++ b/Source/CParse/parser.y
@@ -2926,6 +2926,14 @@ c_decl : storage_class type declarator initializer c_decl_tail {
Setattr($$,"throws",$4.throws);
Setattr($$,"throw",$4.throwf);
Setattr($$,"noexcept",$4.nexcept);
+ if ($4.val && $4.type) {
+ /* store initializer type as it might be different to the declared type */
+ SwigType *valuetype = NewSwigType($4.type);
+ if (Len(valuetype) > 0)
+ Setattr($$,"valuetype",valuetype);
+ else
+ Delete(valuetype);
+ }
if (!$5) {
if (Len(scanner_ccode)) {
String *code = Copy(scanner_ccode);
diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx
index c8655a017..01370a725 100644
--- a/Source/Modules/java.cxx
+++ b/Source/Modules/java.cxx
@@ -1481,6 +1481,7 @@ public:
virtual int constantWrapper(Node *n) {
String *symname = Getattr(n, "sym:name");
SwigType *t = Getattr(n, "type");
+ SwigType *valuetype = Getattr(n, "valuetype");
ParmList *l = Getattr(n, "parms");
String *tm;
String *return_type = NewString("");
@@ -1572,7 +1573,7 @@ public:
} else {
// Alternative constant handling will use the C syntax to make a true Java constant and hope that it compiles as Java code
if (Getattr(n, "wrappedasconstant")) {
- if (SwigType_type(t) == T_CHAR)
+ if (SwigType_type(valuetype) == T_CHAR)
Printf(constants_code, "\'%(escape)s\';\n", Getattr(n, "staticmembervariableHandler:value"));
else
Printf(constants_code, "%s;\n", Getattr(n, "staticmembervariableHandler:value"));