From 70cc4186c3c3e0e3404ac286a3e92ef77d74c4ab Mon Sep 17 00:00:00 2001 From: Jiulong Wang Date: Wed, 7 Sep 2016 15:46:16 -0700 Subject: [PATCH 1/9] Fix enum error when value contains char in compound expression Problem: When enum value contains compound expression with a char constant, the quotes around char constant is missing in the generated expression. Example: enum media_type { YUY2 = ((('2' << 24) | ('Y' << 16)) | ('U' << 8)) | 'Y' }; The generated C# enum becomes: public enum media_type { YUY2 = (((2 << 24)|(Y << 16))|(U << 8))|Y } While the correct representation (after this fix) should be: public enum media_type { YUY2 = ((('2' << 24)|('Y' << 16))|('U' << 8))|'Y' } Causes: the exprcompound promotes the expression type from char to int and uses $1.val in the generated expression. However $1.val does not contain the quotes. Since the type is promoted to int, there's no way to know there's char component in the compound expression. Solution: in exprcomound, use $1.rawval if $1.type is T_CHAR or T_WCHAR. The rawval contains quotes which yield correct expression. --- Source/CParse/cparse.h | 3 +++ Source/CParse/parser.y | 40 ++++++++++++++++++++-------------------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/Source/CParse/cparse.h b/Source/CParse/cparse.h index ab5f74b1908..8079805e466 100644 --- a/Source/CParse/cparse.h +++ b/Source/CParse/cparse.h @@ -78,4 +78,7 @@ extern "C" { #define SWIG_WARN_NODE_END(Node) \ if (wrnfilter) Swig_warnfilter(wrnfilter,0); \ } + +#define COMPOUND_EXPR_VAL(dtype) \ + ((dtype).type == T_CHAR || (dtype).type == T_WCHAR ? (dtype).rawval : (dtype).val) #endif diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 784187c28ff..f6af4680167 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -6095,81 +6095,81 @@ exprnum : NUM_INT { $$ = $1; } ; exprcompound : expr PLUS expr { - $$.val = NewStringf("%s+%s",$1.val,$3.val); + $$.val = NewStringf("%s+%s", COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3)); $$.type = promote($1.type,$3.type); } | expr MINUS expr { - $$.val = NewStringf("%s-%s",$1.val,$3.val); + $$.val = NewStringf("%s-%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3)); $$.type = promote($1.type,$3.type); } | expr STAR expr { - $$.val = NewStringf("%s*%s",$1.val,$3.val); + $$.val = NewStringf("%s*%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3)); $$.type = promote($1.type,$3.type); } | expr SLASH expr { - $$.val = NewStringf("%s/%s",$1.val,$3.val); + $$.val = NewStringf("%s/%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3)); $$.type = promote($1.type,$3.type); } | expr MODULO expr { - $$.val = NewStringf("%s%%%s",$1.val,$3.val); + $$.val = NewStringf("%s%%%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3)); $$.type = promote($1.type,$3.type); } | expr AND expr { - $$.val = NewStringf("%s&%s",$1.val,$3.val); + $$.val = NewStringf("%s&%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3)); $$.type = promote($1.type,$3.type); } | expr OR expr { - $$.val = NewStringf("%s|%s",$1.val,$3.val); + $$.val = NewStringf("%s|%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3)); $$.type = promote($1.type,$3.type); } | expr XOR expr { - $$.val = NewStringf("%s^%s",$1.val,$3.val); + $$.val = NewStringf("%s^%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3)); $$.type = promote($1.type,$3.type); } | expr LSHIFT expr { - $$.val = NewStringf("%s << %s",$1.val,$3.val); + $$.val = NewStringf("%s << %s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3)); $$.type = promote_type($1.type); } | expr RSHIFT expr { - $$.val = NewStringf("%s >> %s",$1.val,$3.val); + $$.val = NewStringf("%s >> %s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3)); $$.type = promote_type($1.type); } | expr LAND expr { - $$.val = NewStringf("%s&&%s",$1.val,$3.val); + $$.val = NewStringf("%s&&%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3)); $$.type = cparse_cplusplus ? T_BOOL : T_INT; } | expr LOR expr { - $$.val = NewStringf("%s||%s",$1.val,$3.val); + $$.val = NewStringf("%s||%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3)); $$.type = cparse_cplusplus ? T_BOOL : T_INT; } | expr EQUALTO expr { - $$.val = NewStringf("%s==%s",$1.val,$3.val); + $$.val = NewStringf("%s==%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3)); $$.type = cparse_cplusplus ? T_BOOL : T_INT; } | expr NOTEQUALTO expr { - $$.val = NewStringf("%s!=%s",$1.val,$3.val); + $$.val = NewStringf("%s!=%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3)); $$.type = cparse_cplusplus ? T_BOOL : T_INT; } /* Sadly this causes 2 reduce-reduce conflicts with templates. FIXME resolve these. | expr GREATERTHAN expr { - $$.val = NewStringf("%s > %s", $1.val, $3.val); + $$.val = NewStringf("%s > %s", COMPOUND_EXPR_VAL($1), COMPOUND_EXPR_VAL($3)); $$.type = cparse_cplusplus ? T_BOOL : T_INT; } | expr LESSTHAN expr { - $$.val = NewStringf("%s < %s", $1.val, $3.val); + $$.val = NewStringf("%s < %s", COMPOUND_EXPR_VAL($1), COMPOUND_EXPR_VAL($3)); $$.type = cparse_cplusplus ? T_BOOL : T_INT; } */ | expr GREATERTHANOREQUALTO expr { - $$.val = NewStringf("%s >= %s", $1.val, $3.val); + $$.val = NewStringf("%s >= %s", COMPOUND_EXPR_VAL($1), COMPOUND_EXPR_VAL($3)); $$.type = cparse_cplusplus ? T_BOOL : T_INT; } | expr LESSTHANOREQUALTO expr { - $$.val = NewStringf("%s <= %s", $1.val, $3.val); + $$.val = NewStringf("%s <= %s", COMPOUND_EXPR_VAL($1), COMPOUND_EXPR_VAL($3)); $$.type = cparse_cplusplus ? T_BOOL : T_INT; } | expr QUESTIONMARK expr COLON expr %prec QUESTIONMARK { - $$.val = NewStringf("%s?%s:%s", $1.val, $3.val, $5.val); + $$.val = NewStringf("%s?%s:%s", COMPOUND_EXPR_VAL($1), COMPOUND_EXPR_VAL($3), COMPOUND_EXPR_VAL($5)); /* This may not be exactly right, but is probably good enough * for the purposes of parsing constant expressions. */ $$.type = promote($3.type, $5.type); @@ -6187,7 +6187,7 @@ exprcompound : expr PLUS expr { $$.type = $2.type; } | LNOT expr { - $$.val = NewStringf("!%s",$2.val); + $$.val = NewStringf("!%s",COMPOUND_EXPR_VAL($2)); $$.type = T_INT; } | type LPAREN { From 1a3aa9a07f4a316098428a7f403e290d03c73720 Mon Sep 17 00:00:00 2001 From: Jiulong Wang Date: Thu, 8 Sep 2016 17:27:12 -0700 Subject: [PATCH 2/9] Add enum test cases with const char in compound expression --- Examples/test-suite/enum_thorough.i | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Examples/test-suite/enum_thorough.i b/Examples/test-suite/enum_thorough.i index f17a7ee966b..b3ec7f39d69 100644 --- a/Examples/test-suite/enum_thorough.i +++ b/Examples/test-suite/enum_thorough.i @@ -611,7 +611,8 @@ enum { globalenumcharE = 69, // E globalenumcharAE1 = 'Æ', // AE (latin1 encoded) globalenumcharAE2 = '\306', // AE (latin1 encoded) - globalenumcharAE3 = '\xC6' // AE (latin1 encoded) + globalenumcharAE3 = '\xC6', // AE (latin1 encoded) + globalenumYuy2 = ((('2'<<24) | ('Y' << 16)) | ('U' << 8)) | 'Y' }; enum EnumChar { enumchar0 = '\0', @@ -624,7 +625,8 @@ enum EnumChar { enumcharE = 69, // E enumcharAE1 = 'Æ', // AE (latin1 encoded) enumcharAE2 = '\306', // AE (latin1 encoded) - enumcharAE3 = '\xC6' // AE (latin1 encoded) + enumcharAE3 = '\xC6', // AE (latin1 encoded) + enumYuy2 = ((('2'<<24) | ('Y' << 16)) | ('U' << 8)) | 'Y' }; struct EnumCharStruct { enum EnumChar { @@ -638,7 +640,8 @@ struct EnumCharStruct { enumcharE = 69, // E enumcharAE1 = 'Æ', // AE (latin1 encoded) enumcharAE2 = '\306', // AE (latin1 encoded) - enumcharAE3 = '\xC6' // AE (latin1 encoded) + enumcharAE3 = '\xC6', // AE (latin1 encoded) + enumYuy2 = ((('2'<<24) | ('Y' << 16)) | ('U' << 8)) | 'Y' }; }; %} @@ -661,7 +664,8 @@ enum { x_globalenumcharE = 69, // E x_globalenumcharAE1 = 'Æ', // AE (latin1 encoded) x_globalenumcharAE2 = '\306', // AE (latin1 encoded) - x_globalenumcharAE3 = '\xC6' // AE (latin1 encoded) + x_globalenumcharAE3 = '\xC6', // AE (latin1 encoded) + x_globalenumYuy2 = ((('2'<<24) | ('Y' << 16)) | ('U' << 8)) | 'Y' }; enum X_EnumChar { x_enumchar0 = '\0', @@ -674,7 +678,8 @@ enum X_EnumChar { x_enumcharE = 69, // E x_enumcharAE1 = 'Æ', // AE (latin1 encoded) x_enumcharAE2 = '\306', // AE (latin1 encoded) - x_enumcharAE3 = '\xC6' // AE (latin1 encoded) + x_enumcharAE3 = '\xC6', // AE (latin1 encoded) + x_enumYuy2 = ((('2'<<24) | ('Y' << 16)) | ('U' << 8)) | 'Y' }; struct X_EnumCharStruct { enum X_EnumChar { @@ -688,7 +693,8 @@ struct X_EnumCharStruct { enumcharE = 69, // E enumcharAE1 = 'Æ', // AE (latin1 encoded) enumcharAE2 = '\306', // AE (latin1 encoded) - enumcharAE3 = '\xC6' // AE (latin1 encoded) + enumcharAE3 = '\xC6', // AE (latin1 encoded) + enumYuy2 = ((('2'<<24) | ('Y' << 16)) | ('U' << 8)) | 'Y' }; }; #if defined(__clang__) From b4d434114d7af687e656e8be5f7a384c2fdde5c9 Mon Sep 17 00:00:00 2001 From: Jiulong Wang Date: Thu, 8 Sep 2016 17:59:22 -0700 Subject: [PATCH 3/9] Add runtime tests for char in compound expression patch --- .../test-suite/csharp/enum_thorough_typesafe_runme.cs | 6 ++++++ Examples/test-suite/enum_thorough.i | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Examples/test-suite/csharp/enum_thorough_typesafe_runme.cs b/Examples/test-suite/csharp/enum_thorough_typesafe_runme.cs index 86179dcf4c2..a23d3b370df 100644 --- a/Examples/test-suite/csharp/enum_thorough_typesafe_runme.cs +++ b/Examples/test-suite/csharp/enum_thorough_typesafe_runme.cs @@ -413,6 +413,8 @@ static void Main() { if (enum_thorough_typesafe.differentTypesTest(DifferentTypes.typeboolfalse).swigValue != 0) throw new Exception("differentTypes 4 failed"); if (enum_thorough_typesafe.differentTypesTest(DifferentTypes.typechar).swigValue != (int)'C') throw new Exception("differentTypes 5 failed"); if (enum_thorough_typesafe.differentTypesTest(DifferentTypes.typedefaultint).swigValue != (int)'D') throw new Exception("differentTypes 6 failed"); + if (enum_thorough_typesafe.differentTypesTest(DifferentTypes.typecharcompound).swigValue != (int)'A' + 1) throw new Exception("differentTypes 7 failed"); + if (enum_thorough_typesafe.differentTypesTest(DifferentTypes.typecharcompound2).swigValue != (int)'B' << 2) throw new Exception("differentTypes 8 failed"); int global_enum = enum_thorough_typesafe.global_typeint; if (enum_thorough_typesafe.globalDifferentTypesTest(global_enum) != 10) throw new Exception("global differentTypes 1 failed"); @@ -426,6 +428,10 @@ static void Main() { if (enum_thorough_typesafe.globalDifferentTypesTest(global_enum) != 'C') throw new Exception("global differentTypes 5 failed"); global_enum = enum_thorough_typesafe.global_typedefaultint; if (enum_thorough_typesafe.globalDifferentTypesTest(global_enum) != 'D') throw new Exception("global differentTypes 6 failed"); + global_enum = enum_thorough_typesafe.global_typecharcompound; + if (enum_thorough_typesafe.globalDifferentTypesTest(global_enum) != (int)'A' + 1) throw new Exception("global differentTypes 7 failed"); + global_enum = enum_thorough_typesafe.global_typecharcompound2; + if (enum_thorough_typesafe.globalDifferentTypesTest(global_enum) != (int)'B' << 2) throw new Exception("global differentTypes 8 failed"); } } } diff --git a/Examples/test-suite/enum_thorough.i b/Examples/test-suite/enum_thorough.i index b3ec7f39d69..dce875ab9a5 100644 --- a/Examples/test-suite/enum_thorough.i +++ b/Examples/test-suite/enum_thorough.i @@ -571,7 +571,9 @@ enum DifferentTypes { typebooltrue = true, typebooltwo, typechar = 'C', - typedefaultint + typedefaultint, + typecharcompound='A'+1, + typecharcompound2='B' << 2 }; DifferentTypes differentTypesTest(DifferentTypes n) { return n; } @@ -581,7 +583,9 @@ enum { global_typebooltrue = true, global_typebooltwo, global_typechar = 'C', - global_typedefaultint + global_typedefaultint, + global_typecharcompound='A'+1, + global_typecharcompound2='B' << 2 }; int globalDifferentTypesTest(int n) { return n; } } From de3620640ab9d8cf6173f40049a1e60f3f00a74e Mon Sep 17 00:00:00 2001 From: Jiulong Wang Date: Fri, 9 Sep 2016 09:19:05 -0700 Subject: [PATCH 4/9] Revert "Add enum test cases with const char in compound expression" This reverts commit b2bf0b3ef79b96ff6bfb81e51d7e9a6a913d773f. --- Examples/test-suite/enum_thorough.i | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/Examples/test-suite/enum_thorough.i b/Examples/test-suite/enum_thorough.i index dce875ab9a5..78e976b0e6f 100644 --- a/Examples/test-suite/enum_thorough.i +++ b/Examples/test-suite/enum_thorough.i @@ -615,8 +615,7 @@ enum { globalenumcharE = 69, // E globalenumcharAE1 = 'Æ', // AE (latin1 encoded) globalenumcharAE2 = '\306', // AE (latin1 encoded) - globalenumcharAE3 = '\xC6', // AE (latin1 encoded) - globalenumYuy2 = ((('2'<<24) | ('Y' << 16)) | ('U' << 8)) | 'Y' + globalenumcharAE3 = '\xC6' // AE (latin1 encoded) }; enum EnumChar { enumchar0 = '\0', @@ -629,8 +628,7 @@ enum EnumChar { enumcharE = 69, // E enumcharAE1 = 'Æ', // AE (latin1 encoded) enumcharAE2 = '\306', // AE (latin1 encoded) - enumcharAE3 = '\xC6', // AE (latin1 encoded) - enumYuy2 = ((('2'<<24) | ('Y' << 16)) | ('U' << 8)) | 'Y' + enumcharAE3 = '\xC6' // AE (latin1 encoded) }; struct EnumCharStruct { enum EnumChar { @@ -644,8 +642,7 @@ struct EnumCharStruct { enumcharE = 69, // E enumcharAE1 = 'Æ', // AE (latin1 encoded) enumcharAE2 = '\306', // AE (latin1 encoded) - enumcharAE3 = '\xC6', // AE (latin1 encoded) - enumYuy2 = ((('2'<<24) | ('Y' << 16)) | ('U' << 8)) | 'Y' + enumcharAE3 = '\xC6' // AE (latin1 encoded) }; }; %} @@ -668,8 +665,7 @@ enum { x_globalenumcharE = 69, // E x_globalenumcharAE1 = 'Æ', // AE (latin1 encoded) x_globalenumcharAE2 = '\306', // AE (latin1 encoded) - x_globalenumcharAE3 = '\xC6', // AE (latin1 encoded) - x_globalenumYuy2 = ((('2'<<24) | ('Y' << 16)) | ('U' << 8)) | 'Y' + x_globalenumcharAE3 = '\xC6' // AE (latin1 encoded) }; enum X_EnumChar { x_enumchar0 = '\0', @@ -682,8 +678,7 @@ enum X_EnumChar { x_enumcharE = 69, // E x_enumcharAE1 = 'Æ', // AE (latin1 encoded) x_enumcharAE2 = '\306', // AE (latin1 encoded) - x_enumcharAE3 = '\xC6', // AE (latin1 encoded) - x_enumYuy2 = ((('2'<<24) | ('Y' << 16)) | ('U' << 8)) | 'Y' + x_enumcharAE3 = '\xC6' // AE (latin1 encoded) }; struct X_EnumCharStruct { enum X_EnumChar { @@ -697,8 +692,7 @@ struct X_EnumCharStruct { enumcharE = 69, // E enumcharAE1 = 'Æ', // AE (latin1 encoded) enumcharAE2 = '\306', // AE (latin1 encoded) - enumcharAE3 = '\xC6', // AE (latin1 encoded) - enumYuy2 = ((('2'<<24) | ('Y' << 16)) | ('U' << 8)) | 'Y' + enumcharAE3 = '\xC6' // AE (latin1 encoded) }; }; #if defined(__clang__) From cac20d691571edcbef9971c2e940f3ae4225d4f1 Mon Sep 17 00:00:00 2001 From: Jiulong Wang Date: Wed, 14 Sep 2016 22:41:02 -0700 Subject: [PATCH 5/9] Add more test case for char const expression in enum --- .../test-suite/csharp/enum_thorough_typesafe_runme.cs | 4 ++++ Examples/test-suite/enum_thorough.i | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/Examples/test-suite/csharp/enum_thorough_typesafe_runme.cs b/Examples/test-suite/csharp/enum_thorough_typesafe_runme.cs index a23d3b370df..82c52a31f64 100644 --- a/Examples/test-suite/csharp/enum_thorough_typesafe_runme.cs +++ b/Examples/test-suite/csharp/enum_thorough_typesafe_runme.cs @@ -405,6 +405,10 @@ static void Main() { if (enum_thorough_typesafe.repeatTest(repeat.llast).swigValue != 3) throw new Exception("repeatTest 5 failed"); if (enum_thorough_typesafe.repeatTest(repeat.end).swigValue != 3) throw new Exception("repeatTest 6 failed"); } + { + if (enum_thorough_typesafe.enumWithMacroTest(enumWithMacro.ABCD).swigValue != (('A' << 24) | ('B' << 16) | ('C' << 8) | 'D')) throw new Exception("enumWithMacroTest 1 failed"); + if (enum_thorough_typesafe.enumWithMacroTest(enumWithMacro.ABCD2).swigValue != enum_thorough_typesafe.enumWithMacroTest(enumWithMacro.ABCD).swigValue) throw new Exception("enumWithMacroTest 2 failed"); + } // different types { if (enum_thorough_typesafe.differentTypesTest(DifferentTypes.typeint).swigValue != 10) throw new Exception("differentTypes 1 failed"); diff --git a/Examples/test-suite/enum_thorough.i b/Examples/test-suite/enum_thorough.i index 78e976b0e6f..e54c03a85cd 100644 --- a/Examples/test-suite/enum_thorough.i +++ b/Examples/test-suite/enum_thorough.i @@ -563,6 +563,17 @@ repeat repeatTest(repeat e) { return e; } } %} +%inline %{ +namespace EnumWithMacro { +#define PACK(C1,C2,C3,C4) ((C1<<24)|(C2<<16)|(C3<<8)|C4) +typedef enum { + ABCD = PACK('A','B','C','D'), + ABCD2 = ABCD +} enumWithMacro; +enumWithMacro enumWithMacroTest(enumWithMacro e) { return e; } +} +%} + %inline %{ namespace DifferentSpace { enum DifferentTypes { From eecc011570c34cc915abb9bcd364b38eb984543a Mon Sep 17 00:00:00 2001 From: Jiulong Wang Date: Wed, 14 Sep 2016 22:51:40 -0700 Subject: [PATCH 6/9] Fix #define error when value contains char in compound expression --- Examples/test-suite/preproc_constants.i | 8 +++++--- Source/CParse/parser.y | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Examples/test-suite/preproc_constants.i b/Examples/test-suite/preproc_constants.i index db71bd2d7cc..3a999ada367 100644 --- a/Examples/test-suite/preproc_constants.i +++ b/Examples/test-suite/preproc_constants.i @@ -51,7 +51,7 @@ // Expressions - runtime tests check the type for any necessary type promotions of the expressions #define INT_AND_BOOL 0xFF & true -//#define INT_AND_CHAR 0xFF & 'A' /* FIXME compile error */ +#define INT_AND_CHAR 0xFF & 'A' #define INT_AND_INT 0xFF & 2 #define INT_AND_UINT 0xFF & 2u #define INT_AND_LONG 0xFF & 2l @@ -60,8 +60,7 @@ #define INT_AND_ULLONG 0xFF & 2ull #define BOOL_AND_BOOL true & true // Note integral promotion to type int -//#define CHAR_AND_CHAR 'A' & 'B' // Note integral promotion to type int -/* FIXME ABOVE */ +#define CHAR_AND_CHAR 'A' & 'B' // Note integral promotion to type int #define EXPR_MULTIPLY 0xFF * 2 @@ -88,6 +87,9 @@ #define EXPR_LOR 0xFF || 1 #define EXPR_CONDITIONAL true ? 2 : 2.2 +#define EXPR_CHAR_COMPOUND_ADD 'A' + 12 +#define EXPR_CHAR_COMPOUND_LSHIFT 'B' << 6 +#define H_SUPPRESS_SCALING_MAGIC (('s'<<24) | ('u'<<16) | ('p'<<8) | 'p') /// constant assignment in enum #if defined(SWIGCSHARP) diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index f6af4680167..82608053ec5 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -5828,7 +5828,7 @@ definetype : { /* scanner_check_typedef(); */ } expr { if ($$.type == T_STRING) { $$.rawval = NewStringf("\"%(escape)s\"",$$.val); } else if ($$.type != T_CHAR && $$.type != T_WSTRING && $$.type != T_WCHAR) { - $$.rawval = 0; + $$.rawval = NewStringf("%s", $$.val); } $$.qualifier = 0; $$.bitfield = 0; From 0db2a32190b133824e9f7c7a27f65e9be795ab1f Mon Sep 17 00:00:00 2001 From: Jiulong Wang Date: Mon, 10 Oct 2016 21:34:19 -0700 Subject: [PATCH 7/9] Fix extra quote escape in golang --- Source/Modules/go.cxx | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index 7fa9b26705f..aaf338ca585 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -2800,29 +2800,35 @@ class GO:public Language { String *get = NewString(""); Printv(get, Swig_cresult_name(), " = ", NULL); - char quote; - if (Getattr(n, "wrappedasconstant")) { - quote = '\0'; - } else if (SwigType_type(type) == T_CHAR) { - quote = '\''; - } else if (SwigType_type(type) == T_STRING) { - Printv(get, "(char *)", NULL); - quote = '"'; + String *rawval = Getattr(n, "rawval"); + if (rawval && Len(rawval)) { + Printv(get, rawval, NULL); } else { - quote = '\0'; - } + char quote; + if (Getattr(n, "wrappedasconstant")) { + quote = '\0'; + } else if (SwigType_type(type) == T_CHAR) { + quote = '\''; + } else if (SwigType_type(type) == T_STRING) { + Printv(get, "(char *)", NULL); + quote = '"'; + } else { + quote = '\0'; + } - if (quote != '\0') { - Printf(get, "%c", quote); - } + if (quote != '\0') { + Printf(get, "%c", quote); + } - Printv(get, Getattr(n, "value"), NULL); + Printv(get, Getattr(n, "value"), NULL); + + if (quote != '\0') { + Printf(get, "%c", quote); + } - if (quote != '\0') { - Printf(get, "%c", quote); + Printv(get, ";\n", NULL); } - Printv(get, ";\n", NULL); Setattr(n, "wrap:action", get); String *sname = Copy(symname); From 4aae757c4323fddb541fe700dc0f9dcba7ca65f6 Mon Sep 17 00:00:00 2001 From: Jiulong Wang Date: Mon, 10 Oct 2016 22:42:30 -0700 Subject: [PATCH 8/9] Fix missing semicolon in golang wrapper --- Source/Modules/go.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index aaf338ca585..325cf0f31ab 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -2825,10 +2825,10 @@ class GO:public Language { if (quote != '\0') { Printf(get, "%c", quote); } - - Printv(get, ";\n", NULL); } + Printv(get, ";\n", NULL); + Setattr(n, "wrap:action", get); String *sname = Copy(symname); From fa966460015bc95dc52167074a6568ff80db3f7d Mon Sep 17 00:00:00 2001 From: Jiulong Wang Date: Tue, 11 Oct 2016 10:49:43 -0700 Subject: [PATCH 9/9] Fix go wrapper compilation error --- Source/Modules/go.cxx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index 325cf0f31ab..e505d4ddccc 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -2802,6 +2802,10 @@ class GO:public Language { String *rawval = Getattr(n, "rawval"); if (rawval && Len(rawval)) { + if (SwigType_type(type) == T_STRING) { + Printv(get, "(char *)", NULL); + } + Printv(get, rawval, NULL); } else { char quote;