Remove SWIG_Get_Type function usage in class constants.

Add class constant typemaps. (classconsttab)
This commit is contained in:
Nihal 2017-07-12 08:29:27 +05:30
commit b38e6d9584
2 changed files with 29 additions and 37 deletions

View file

@ -140,33 +140,6 @@ extern "C" {
static void (*r_prevtracefunc) (const SwigType *t, String *mangled, String *clientdata) = 0;
}
/* Function used to get the return type mapped to PHP return type.
* Used for defining class constants or class properties.
*/
static String *Swig_Get_type(String *type) {
String *return_value = NULL;
if ( Cmp(type,"int") == 0 ||
Cmp(type,"unsigned int") == 0 ||
Cmp(type,"signed int") == 0 ||
Cmp(type,"short") == 0 ||
Cmp(type,"unsigned short int") == 0 ||
Cmp(type,"signed short int") == 0 ||
Cmp(type,"long int") == 0 ||
Cmp(type,"unsigned long int") == 0 ||
Cmp(type,"signed long int") == 0)
return_value = NewString("long");
else if (Cmp(type,"float") == 0 ||
Cmp(type,"double") == 0 ||
Cmp(type,"long double") == 0)
return_value = NewString("double");
else if (Cmp(type,"bool") == 0)
return_value = NewString("bool");
else if (Cmp(type,"char") == 0 ||
Cmp(type,"String") == 0)
return_value = NewString("string");
return return_value;
}
static void SwigPHP_emit_resource_registrations() {
Iterator ki;
bool emitted_default_dtor = false;
@ -2489,11 +2462,13 @@ done:
String *tm;
bool isMemberConstant = false;
String *constant_name = NULL;
if (Strchr(name,':') && class_name) {
isMemberConstant = true;
char *ptr = Char(strrchr(GetChar(n, "name"),':')) + 1;
name = (String*) ptr;
constant_name = NewStringEmpty();
constant_name = (String*) ptr;
}
if (!addSymbol(iname, n))
@ -2507,15 +2482,11 @@ done:
Replaceall(tm, "$value", value);
Printf(s_cinit, "%s\n", tm);
}
else {
String *s_type = Swig_Get_type(Getattr(n, "type"));
if (s_type)
if (Cmp(s_type,"string") == 0)
Printf(s_cinit, "zend_declare_class_constant_string(%s_ce, \"%s\", sizeof(\"%s\") - 1, \"%s\");\n\n", class_name, name, name, value);
else
Printf(s_cinit, "zend_declare_class_constant_%s(%s_ce, \"%s\", sizeof(\"%s\") - 1, %s);\n\n", s_type, class_name, name, name, value);
else
Printf(s_cinit, "zend_declare_class_constant_null(%s_ce, \"%s\", sizeof(\"%s\") - 1);\n\n", class_name, name, name);
else if (isMemberConstant && (tm = Swig_typemap_lookup("classconsttab", n, name, 0))) {
Replaceall(tm, "$class", class_name);
Replaceall(tm, "$const_name", constant_name);
Replaceall(tm, "$value", value);
Printf(s_cinit, "%s\n", tm);
}
if (shadow) {