Merge branch 'char-escaping'
* char-escaping: Add missing string_constant.i testcase changes file update for char wrappers C# char wrappers fixes for enum values, static const member char values and %csconst D testing added for %dmanifestconst and char constants Fix wrapping D constants using %dmanifestconst Php fix for enum value of '\0' Fix static const char member variables wrappers with %javaconst(1). Expand char testing in enums and %constant Java char changes file update Java enum and static member variable escaping fix for chars Add tests for enum values and static const member variables chars containing escape sequences Minor documentation tweak Conflicts: CHANGES.current
This commit is contained in:
commit
ac495d5c66
15 changed files with 355 additions and 23 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -1320,7 +1320,7 @@ public:
|
|||
const char *val = Equal(Getattr(n, "enumvalue"), "true") ? "1" : "0";
|
||||
Setattr(n, "enumvalue", val);
|
||||
} else if (swigtype == T_CHAR) {
|
||||
String *val = NewStringf("'%s'", Getattr(n, "enumvalue"));
|
||||
String *val = NewStringf("'%(hexescape)s'", Getattr(n, "enumvalue"));
|
||||
Setattr(n, "enumvalue", val);
|
||||
Delete(val);
|
||||
}
|
||||
|
|
@ -1444,6 +1444,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("");
|
||||
|
|
@ -1496,13 +1497,15 @@ public:
|
|||
Swig_warning(WARN_CSHARP_TYPEMAP_CSWTYPE_UNDEF, input_file, line_number, "No cstype typemap defined for %s\n", SwigType_str(t, 0));
|
||||
}
|
||||
|
||||
// Default (octal) escaping is no good - change to hex escaped value
|
||||
String *hexescaped_value = Getattr(n, "rawvalue") ? NewStringf("%(hexescape)s", Getattr(n, "rawvalue")) : 0;
|
||||
// Add the stripped quotes back in
|
||||
String *new_value = NewString("");
|
||||
if (SwigType_type(t) == T_STRING) {
|
||||
Printf(new_value, "\"%s\"", Copy(Getattr(n, "value")));
|
||||
Printf(new_value, "\"%s\"", hexescaped_value ? hexescaped_value : Copy(Getattr(n, "value")));
|
||||
Setattr(n, "value", new_value);
|
||||
} else if (SwigType_type(t) == T_CHAR) {
|
||||
Printf(new_value, "\'%s\'", Copy(Getattr(n, "value")));
|
||||
Printf(new_value, "\'%s\'", hexescaped_value ? hexescaped_value : Copy(Getattr(n, "value")));
|
||||
Setattr(n, "value", new_value);
|
||||
}
|
||||
|
||||
|
|
@ -1543,10 +1546,14 @@ public:
|
|||
} else {
|
||||
// Alternative constant handling will use the C syntax to make a true C# constant and hope that it compiles as C# code
|
||||
if (Getattr(n, "wrappedasconstant")) {
|
||||
if (SwigType_type(t) == T_CHAR)
|
||||
Printf(constants_code, "\'%s\';\n", Getattr(n, "staticmembervariableHandler:value"));
|
||||
else
|
||||
if (SwigType_type(t) == T_CHAR) {
|
||||
if (SwigType_type(valuetype) == T_CHAR)
|
||||
Printf(constants_code, "\'%(hexescape)s\';\n", Getattr(n, "staticmembervariableHandler:value"));
|
||||
else
|
||||
Printf(constants_code, "(char)%s;\n", Getattr(n, "staticmembervariableHandler:value"));
|
||||
} else {
|
||||
Printf(constants_code, "%s;\n", Getattr(n, "staticmembervariableHandler:value"));
|
||||
}
|
||||
} else {
|
||||
Printf(constants_code, "%s;\n", Getattr(n, "value"));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -910,7 +910,7 @@ public:
|
|||
const char *val = Equal(Getattr(n, "enumvalue"), "true") ? "1" : "0";
|
||||
Setattr(n, "enumvalue", val);
|
||||
} else if (swigtype == T_CHAR) {
|
||||
String *val = NewStringf("'%s'", Getattr(n, "enumvalue"));
|
||||
String *val = NewStringf("'%(escape)s'", Getattr(n, "enumvalue"));
|
||||
Setattr(n, "enumvalue", val);
|
||||
Delete(val);
|
||||
}
|
||||
|
|
@ -1423,6 +1423,7 @@ public:
|
|||
|
||||
String *constants_code = NewString("");
|
||||
SwigType *t = Getattr(n, "type");
|
||||
SwigType *valuetype = Getattr(n, "valuetype");
|
||||
ParmList *l = Getattr(n, "parms");
|
||||
|
||||
// Attach the non-standard typemaps to the parameter list.
|
||||
|
|
@ -1470,16 +1471,21 @@ public:
|
|||
Printf(constants_code, "%s;\n", override_value);
|
||||
} else {
|
||||
// Just take the value from the C definition and hope it compiles in D.
|
||||
String* value = Getattr(n, "wrappedasconstant") ?
|
||||
Getattr(n, "staticmembervariableHandler:value") : Getattr(n, "value");
|
||||
|
||||
// Add the stripped quotes back in.
|
||||
if (SwigType_type(t) == T_STRING) {
|
||||
Printf(constants_code, "\"%s\";\n", value);
|
||||
} else if (SwigType_type(t) == T_CHAR) {
|
||||
Printf(constants_code, "\'%s\';\n", value);
|
||||
if (Getattr(n, "wrappedasconstant")) {
|
||||
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"));
|
||||
} else {
|
||||
Printf(constants_code, "%s;\n", value);
|
||||
// Add the stripped quotes back in.
|
||||
String* value = Getattr(n, "value");
|
||||
if (SwigType_type(t) == T_STRING) {
|
||||
Printf(constants_code, "\"%s\";\n", value);
|
||||
} else if (SwigType_type(t) == T_CHAR) {
|
||||
Printf(constants_code, "\'%s\';\n", value);
|
||||
} else {
|
||||
Printf(constants_code, "%s;\n", value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1380,7 +1380,7 @@ public:
|
|||
const char *val = Equal(Getattr(n, "enumvalue"), "true") ? "1" : "0";
|
||||
Setattr(n, "enumvalue", val);
|
||||
} else if (swigtype == T_CHAR) {
|
||||
String *val = NewStringf("'%s'", Getattr(n, "enumvalue"));
|
||||
String *val = NewStringf("'%(escape)s'", Getattr(n, "enumvalue"));
|
||||
Setattr(n, "enumvalue", val);
|
||||
Delete(val);
|
||||
}
|
||||
|
|
@ -1486,6 +1486,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("");
|
||||
|
|
@ -1577,8 +1578,8 @@ 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)
|
||||
Printf(constants_code, "\'%s\';\n", Getattr(n, "staticmembervariableHandler:value"));
|
||||
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"));
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1904,7 +1904,7 @@ done:
|
|||
enumvalue = GetChar(n, "enumvalueex");
|
||||
}
|
||||
|
||||
if (enumvalue) {
|
||||
if (enumvalue && *Char(enumvalue)) {
|
||||
// Check for a simple constant expression which is valid in PHP.
|
||||
// If we find one, initialise the const member with it; otherwise
|
||||
// we initialise it using the C/C++ wrapped constant.
|
||||
|
|
@ -1916,7 +1916,8 @@ done:
|
|||
break;
|
||||
}
|
||||
}
|
||||
if (!*p) set_to = enumvalue;
|
||||
if (!*p)
|
||||
set_to = enumvalue;
|
||||
}
|
||||
|
||||
if (wrapping_member_constant) {
|
||||
|
|
|
|||
|
|
@ -309,6 +309,7 @@ int Swig_storage_isstatic(Node *n) {
|
|||
* Swig_string_escape()
|
||||
*
|
||||
* Takes a string object and produces a string with escape codes added to it.
|
||||
* Octal escaping is used.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
String *Swig_string_escape(String *s) {
|
||||
|
|
@ -342,6 +343,43 @@ String *Swig_string_escape(String *s) {
|
|||
return ns;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_string_hexescape()
|
||||
*
|
||||
* Takes a string object and produces a string with escape codes added to it.
|
||||
* Hex escaping is used.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
String *Swig_string_hexescape(String *s) {
|
||||
String *ns;
|
||||
int c;
|
||||
ns = NewStringEmpty();
|
||||
|
||||
while ((c = Getc(s)) != EOF) {
|
||||
if (c == '\n') {
|
||||
Printf(ns, "\\n");
|
||||
} else if (c == '\r') {
|
||||
Printf(ns, "\\r");
|
||||
} else if (c == '\t') {
|
||||
Printf(ns, "\\t");
|
||||
} else if (c == '\\') {
|
||||
Printf(ns, "\\\\");
|
||||
} else if (c == '\'') {
|
||||
Printf(ns, "\\'");
|
||||
} else if (c == '\"') {
|
||||
Printf(ns, "\\\"");
|
||||
} else if (c == ' ') {
|
||||
Putc(c, ns);
|
||||
} else if (!isgraph(c)) {
|
||||
if (c < 0)
|
||||
c += UCHAR_MAX + 1;
|
||||
Printf(ns, "\\x%X", c);
|
||||
} else {
|
||||
Putc(c, ns);
|
||||
}
|
||||
}
|
||||
return ns;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_string_upper()
|
||||
|
|
@ -1425,6 +1463,7 @@ String *Swig_pcre_version(void) {
|
|||
void Swig_init() {
|
||||
/* Set some useful string encoding methods */
|
||||
DohEncoding("escape", Swig_string_escape);
|
||||
DohEncoding("hexescape", Swig_string_hexescape);
|
||||
DohEncoding("upper", Swig_string_upper);
|
||||
DohEncoding("lower", Swig_string_lower);
|
||||
DohEncoding("title", Swig_string_title);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue