Remove SWIG_Get_Type function usage in class constants.
Add class constant typemaps. (classconsttab)
This commit is contained in:
parent
a71b349204
commit
b38e6d9584
2 changed files with 29 additions and 37 deletions
|
|
@ -3,6 +3,27 @@
|
||||||
*
|
*
|
||||||
* Typemaps for constants
|
* Typemaps for constants
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
%typemap(classconsttab) int,
|
||||||
|
unsigned int,
|
||||||
|
short,
|
||||||
|
unsigned short,
|
||||||
|
long,
|
||||||
|
unsigned long,
|
||||||
|
unsigned char,
|
||||||
|
signed char,
|
||||||
|
enum SWIGTYPE
|
||||||
|
"zend_declare_class_constant_long($class_ce, \"$const_name\", sizeof(\"$const_name\") - 1, $value);";
|
||||||
|
|
||||||
|
%typemap(classconsttab) bool
|
||||||
|
"zend_declare_class_constant_bool($class_ce, \"$const_name\", sizeof(\"$const_name\") - 1, $value);";
|
||||||
|
|
||||||
|
%typemap(classconsttab) float,
|
||||||
|
double
|
||||||
|
"zend_declare_class_constant_double($class_ce, \"$const_name\", sizeof(\"$const_name\") - 1, $value);";
|
||||||
|
|
||||||
|
%typemap(classconsttab) char,
|
||||||
|
string
|
||||||
|
"zend_declare_class_constant_string($class_ce, \"$const_name\", sizeof(\"$const_name\") - 1, \"$value\");";
|
||||||
|
|
||||||
%typemap(consttab) int,
|
%typemap(consttab) int,
|
||||||
unsigned int,
|
unsigned int,
|
||||||
|
|
|
||||||
|
|
@ -140,33 +140,6 @@ extern "C" {
|
||||||
static void (*r_prevtracefunc) (const SwigType *t, String *mangled, String *clientdata) = 0;
|
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() {
|
static void SwigPHP_emit_resource_registrations() {
|
||||||
Iterator ki;
|
Iterator ki;
|
||||||
bool emitted_default_dtor = false;
|
bool emitted_default_dtor = false;
|
||||||
|
|
@ -2489,11 +2462,13 @@ done:
|
||||||
String *tm;
|
String *tm;
|
||||||
|
|
||||||
bool isMemberConstant = false;
|
bool isMemberConstant = false;
|
||||||
|
String *constant_name = NULL;
|
||||||
|
|
||||||
if (Strchr(name,':') && class_name) {
|
if (Strchr(name,':') && class_name) {
|
||||||
isMemberConstant = true;
|
isMemberConstant = true;
|
||||||
char *ptr = Char(strrchr(GetChar(n, "name"),':')) + 1;
|
char *ptr = Char(strrchr(GetChar(n, "name"),':')) + 1;
|
||||||
name = (String*) ptr;
|
constant_name = NewStringEmpty();
|
||||||
|
constant_name = (String*) ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!addSymbol(iname, n))
|
if (!addSymbol(iname, n))
|
||||||
|
|
@ -2507,15 +2482,11 @@ done:
|
||||||
Replaceall(tm, "$value", value);
|
Replaceall(tm, "$value", value);
|
||||||
Printf(s_cinit, "%s\n", tm);
|
Printf(s_cinit, "%s\n", tm);
|
||||||
}
|
}
|
||||||
else {
|
else if (isMemberConstant && (tm = Swig_typemap_lookup("classconsttab", n, name, 0))) {
|
||||||
String *s_type = Swig_Get_type(Getattr(n, "type"));
|
Replaceall(tm, "$class", class_name);
|
||||||
if (s_type)
|
Replaceall(tm, "$const_name", constant_name);
|
||||||
if (Cmp(s_type,"string") == 0)
|
Replaceall(tm, "$value", value);
|
||||||
Printf(s_cinit, "zend_declare_class_constant_string(%s_ce, \"%s\", sizeof(\"%s\") - 1, \"%s\");\n\n", class_name, name, name, value);
|
Printf(s_cinit, "%s\n", tm);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shadow) {
|
if (shadow) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue