diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2016-03-12 11:26:17 +0000 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2016-03-12 11:26:17 +0000 |
commit | 6840996dba76794f3538ea51e068b09fe73be220 (patch) | |
tree | 95b2688ea096e4a0717aec31d5047df7d39fe4e0 | |
parent | 539aca58a5ae10c26332190911919cf87796ebcd (diff) | |
download | swig-6840996dba76794f3538ea51e068b09fe73be220.tar.gz |
Fix wrapping D constants using %dmanifestconst
-rw-r--r-- | Examples/test-suite/chartest.i | 4 | ||||
-rw-r--r-- | Source/Modules/d.cxx | 26 |
2 files changed, 20 insertions, 10 deletions
diff --git a/Examples/test-suite/chartest.i b/Examples/test-suite/chartest.i index e9b25f782..b86bfdc91 100644 --- a/Examples/test-suite/chartest.i +++ b/Examples/test-suite/chartest.i @@ -41,6 +41,10 @@ struct CharTestClass { #if defined(SWIGJAVA) %javaconst(1); +//#elif SWIGCSHARP +//%csconst(1); +#elif SWIGD +%dmanifestconst; #endif %inline %{ diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx index 5fc21ad18..cf859993a 100644 --- a/Source/Modules/d.cxx +++ b/Source/Modules/d.cxx @@ -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); + } } } |