Merged trunk through revision 12591

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12592 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Stefan Zager 2011-04-03 03:14:19 +00:00
commit f759999f40
38 changed files with 521 additions and 112 deletions

View file

@ -863,9 +863,10 @@ int CHICKEN::constantWrapper(Node *n) {
Delete(SwigType_pop(nctype));
}
bool is_enum_item = (Cmp(nodeType(n), "enumitem") == 0);
if (SwigType_type(nctype) == T_STRING) {
rvalue = NewStringf("\"%s\"", value);
} else if (SwigType_type(nctype) == T_CHAR) {
} else if (SwigType_type(nctype) == T_CHAR && !is_enum_item) {
rvalue = NewStringf("\'%s\'", value);
} else {
rvalue = NewString(value);

View file

@ -1274,11 +1274,15 @@ public:
// Note that this is used in enumValue() amongst other places
Setattr(n, "value", tmpValue);
// Deal with enum values that are bools
if (SwigType_type(Getattr(n, "type")) == T_BOOL) {
String *boolValue = NewStringf("%s ? 1 : 0", Getattr(n, "enumvalue"));
Setattr(n, "enumvalue", boolValue);
Delete(boolValue);
// Deal with enum values that are not int
int swigtype = SwigType_type(Getattr(n, "type"));
if (swigtype == T_BOOL) {
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"));
Setattr(n, "enumvalue", val);
Delete(val);
}
{
@ -1329,11 +1333,12 @@ public:
}
} else {
// Wrap C/C++ enums with constant integers or use the typesafe enum pattern
String *type = Getattr(n, "type"); /* should be int unless explicitly specified in a C++0x enum class */
SwigType *typemap_lookup_type = parent_name ? parent_name : type;
SwigType *typemap_lookup_type = parent_name ? parent_name : NewString("enum ");
Setattr(n, "type", typemap_lookup_type);
const String *tm = typemapLookup(n, "cstype", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CSTYPE_UNDEF);
String *return_type = Copy(tm);
substituteClassname(typemap_lookup_type, return_type);
const String *methodmods = Getattr(n, "feature:cs:methodmodifiers");
methodmods = methodmods ? methodmods : (is_public(n) ? public_string : protected_string);
@ -1362,6 +1367,7 @@ public:
Printf(enum_code, " %s %s %s %s = %s;\n", methodmods, const_readonly, return_type, symname, value);
Delete(value);
}
Delete(return_type);
}
// Add the enum value to the comma separated list being constructed in the enum declaration.
@ -1396,6 +1402,7 @@ public:
String *tm;
String *return_type = NewString("");
String *constants_code = NewString("");
Swig_save("constantWrapper", n, "value", NIL);
bool is_enum_item = (Cmp(nodeType(n), "enumitem") == 0);
@ -1444,7 +1451,6 @@ public:
// Add the stripped quotes back in
String *new_value = NewString("");
Swig_save("constantWrapper", n, "value", NIL);
if (SwigType_type(t) == T_STRING) {
Printf(new_value, "\"%s\"", Copy(Getattr(n, "value")));
Setattr(n, "value", new_value);

View file

@ -1393,9 +1393,10 @@ public:
}
// See if there's a typemap
bool is_enum_item = (Cmp(nodeType(n), "enumitem") == 0);
if (SwigType_type(nctype) == T_STRING) {
rvalue = NewStringf("\"%s\"", value);
} else if (SwigType_type(nctype) == T_CHAR) {
} else if (SwigType_type(nctype) == T_CHAR && !is_enum_item) {
rvalue = NewStringf("\'%s\'", value);
} else {
rvalue = NewString(value);

View file

@ -1349,11 +1349,15 @@ public:
// Note that this is used in enumValue() amongst other places
Setattr(n, "value", tmpValue);
// Deal with enum values that are bools
if (SwigType_type(Getattr(n, "type")) == T_BOOL) {
String *boolValue = NewStringf("%s ? 1 : 0", Getattr(n, "enumvalue"));
Setattr(n, "enumvalue", boolValue);
Delete(boolValue);
// Deal with enum values that are not int
int swigtype = SwigType_type(Getattr(n, "type"));
if (swigtype == T_BOOL) {
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"));
Setattr(n, "enumvalue", val);
Delete(val);
}
{
@ -1394,11 +1398,12 @@ public:
}
} else {
// Wrap C/C++ enums with constant integers or use the typesafe enum pattern
String *type = Getattr(n, "type"); /* should be int unless explicitly specified in a C++0x enum class */
SwigType *typemap_lookup_type = parent_name ? parent_name : type;
SwigType *typemap_lookup_type = parent_name ? parent_name : NewString("enum ");
Setattr(n, "type", typemap_lookup_type);
const String *tm = typemapLookup(n, "jstype", typemap_lookup_type, WARN_JAVA_TYPEMAP_JSTYPE_UNDEF);
String *return_type = Copy(tm);
substituteClassname(typemap_lookup_type, return_type);
const String *methodmods = Getattr(n, "feature:java:methodmodifiers");
methodmods = methodmods ? methodmods : (is_public(n) ? public_string : protected_string);
@ -1419,6 +1424,7 @@ public:
Printf(enum_code, " %s final static %s %s = %s;\n", methodmods, return_type, symname, value);
Delete(value);
}
Delete(return_type);
}
// Add the enum value to the comma separated list being constructed in the enum declaration.
@ -1453,6 +1459,7 @@ public:
String *tm;
String *return_type = NewString("");
String *constants_code = NewString("");
Swig_save("constantWrapper", n, "value", NIL);
bool is_enum_item = (Cmp(nodeType(n), "enumitem") == 0);
@ -1498,7 +1505,6 @@ public:
// Add the stripped quotes back in
String *new_value = NewString("");
Swig_save("constantWrapper", n, "value", NIL);
if (SwigType_type(t) == T_STRING) {
Printf(new_value, "\"%s\"", Copy(Getattr(n, "value")));
Setattr(n, "value", new_value);

View file

@ -1044,7 +1044,10 @@ int Language::functionHandler(Node *n) {
if (isstatic) {
staticmemberfunctionHandler(n);
} else if (isfriend) {
int oldInClass = InClass;
InClass = 0;
globalfunctionHandler(n);
InClass = oldInClass;
} else {
Node *explicit_n = 0;
if (directorsEnabled() && is_member_director(CurrentClass, n) && !extraDirectorProtectedCPPMethodsRequired()) {

View file

@ -637,9 +637,10 @@ public:
// Create variable and assign it a value
Printf(f_header, "static %s = ", SwigType_lstr(type, var_name));
bool is_enum_item = (Cmp(nodeType(n), "enumitem") == 0);
if ((SwigType_type(type) == T_STRING)) {
Printf(f_header, "\"%s\";\n", value);
} else if (SwigType_type(type) == T_CHAR) {
} else if (SwigType_type(type) == T_CHAR && !is_enum_item) {
Printf(f_header, "\'%s\';\n", value);
} else {
Printf(f_header, "%s;\n", value);

View file

@ -927,9 +927,10 @@ public:
// Create variable and assign it a value
Printf(f_header, "static %s = ", SwigType_lstr(type, name));
bool is_enum_item = (Cmp(nodeType(n), "enumitem") == 0);
if ((SwigType_type(type) == T_STRING)) {
Printf(f_header, "\"%s\";\n", value);
} else if (SwigType_type(type) == T_CHAR) {
} else if (SwigType_type(type) == T_CHAR && !is_enum_item) {
Printf(f_header, "\'%s\';\n", value);
} else {
Printf(f_header, "%s;\n", value);

View file

@ -578,12 +578,16 @@ public:
String *symname = Getattr(n, "sym:name");
SwigType *type = Getattr(n, "type");
String *value = Getattr(n, "value");
bool is_enum_item = (Cmp(nodeType(n), "enumitem") == 0);
/* Special hook for member pointer */
if (SwigType_type(type) == T_MPOINTER) {
/* Special hook for member pointer */
String *wname = Swig_name_wrapper(symname);
Printf(f_header, "static %s = %s;\n", SwigType_str(type, wname), value);
value = wname;
} else if (SwigType_type(type) == T_CHAR && is_enum_item) {
type = NewSwigType(T_INT);
Setattr(n, "type", type);
}
/* Perform constant typemap substitution */

View file

@ -531,7 +531,17 @@ public:
Printf(df->code, "Tcl_Obj *CONST *argv = objv+1;\n");
Printf(df->code, "int argc = objc-1;\n");
Printv(df->code, dispatch, "\n", NIL);
Printf(df->code, "Tcl_SetResult(interp,(char *) \"No matching function for overloaded '%s'\", TCL_STATIC);\n", iname);
Node *sibl = n;
while (Getattr(sibl, "sym:previousSibling"))
sibl = Getattr(sibl, "sym:previousSibling"); // go all the way up
String *protoTypes = NewString("");
do {
Printf(protoTypes, "\n\" %s(%s)\\n\"", SwigType_str(Getattr(sibl, "name"), 0), ParmList_protostr(Getattr(sibl, "wrap:parms")));
} while ((sibl = Getattr(sibl, "sym:nextSibling")));
Printf(df->code, "Tcl_SetResult(interp,(char *) "
"\"Wrong number or type of arguments for overloaded function '%s'.\\n\""
"\n\" Possible C/C++ prototypes are:\\n\"%s, TCL_STATIC);\n", iname, protoTypes);
Delete(protoTypes);
Printf(df->code, "return TCL_ERROR;\n");
Printv(df->code, "}\n", NIL);
Wrapper_print(df, f_wrappers);