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.
This commit is contained in:
parent
95eb6649ea
commit
7339de974d
4 changed files with 55 additions and 2 deletions
|
|
@ -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' };
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
};
|
||||
%}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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"));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue