Tidy up descriptions of destructors.
Fix comments for handles for simple types. Omit superfluous "else" when generating property getter and setter handling code, which produces smaller generated source code, and simplifies the generating code. With -php5, if -prefix isn't specified, don't prefix classes. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@9389 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
04b6cd7f92
commit
25636f132f
1 changed files with 27 additions and 48 deletions
|
|
@ -87,7 +87,7 @@ static String *withincs = 0;
|
||||||
static String *withc = 0;
|
static String *withc = 0;
|
||||||
static String *withcxx = 0;
|
static String *withcxx = 0;
|
||||||
|
|
||||||
static char *shadow_classname;
|
static String *shadow_classname = 0;
|
||||||
|
|
||||||
static int gen_extra = 0;
|
static int gen_extra = 0;
|
||||||
static int gen_make = 0;
|
static int gen_make = 0;
|
||||||
|
|
@ -170,9 +170,6 @@ static const char *php_header =
|
||||||
void
|
void
|
||||||
SwigPHP_emit_resource_registrations() {
|
SwigPHP_emit_resource_registrations() {
|
||||||
Iterator ki;
|
Iterator ki;
|
||||||
String *destructor=0;
|
|
||||||
String *classname=0;
|
|
||||||
String *shadow_classname=0;
|
|
||||||
|
|
||||||
if (!zend_types) return;
|
if (!zend_types) return;
|
||||||
|
|
||||||
|
|
@ -181,32 +178,31 @@ SwigPHP_emit_resource_registrations() {
|
||||||
while (ki.key) if (1 /* is pointer type*/) {
|
while (ki.key) if (1 /* is pointer type*/) {
|
||||||
DOH *key = ki.key;
|
DOH *key = ki.key;
|
||||||
Node *class_node = ki.item;
|
Node *class_node = ki.item;
|
||||||
|
String *human_name = key;
|
||||||
|
|
||||||
// Write out destructor function header
|
// Write out destructor function header
|
||||||
Printf(s_wrappers,"/* NEW Destructor style */\nstatic ZEND_RSRC_DTOR_FUNC(_wrap_destroy%s) {\n",key);
|
Printf(s_wrappers,"/* NEW Destructor style */\nstatic ZEND_RSRC_DTOR_FUNC(_wrap_destroy%s) {\n",key);
|
||||||
|
|
||||||
// write out body
|
// write out body
|
||||||
if ((class_node!=NOTCLASS)) {
|
if ((class_node!=NOTCLASS)) {
|
||||||
classname = Getattr(class_node,"name");
|
String *destructor = Getattr(class_node, "destructor");
|
||||||
if (! (shadow_classname = Getattr(class_node,"sym:name"))) {
|
human_name = Getattr(class_node,"sym:name");
|
||||||
shadow_classname=classname;
|
if (!human_name) human_name = Getattr(class_node,"name");
|
||||||
}
|
|
||||||
// Do we have a known destructor for this type?
|
// Do we have a known destructor for this type?
|
||||||
if ((destructor = Getattr(class_node,"destructor"))) {
|
if (destructor) {
|
||||||
Printf(s_wrappers," /* has destructor: %s */\n",destructor);
|
|
||||||
Printf(s_wrappers," %s(rsrc, SWIGTYPE%s->name TSRMLS_CC);\n",destructor,key);
|
Printf(s_wrappers," %s(rsrc, SWIGTYPE%s->name TSRMLS_CC);\n",destructor,key);
|
||||||
} else {
|
} else {
|
||||||
Printf(s_wrappers," /* bah! No destructor for this wrapped class!! */\n");
|
Printf(s_wrappers," /* No destructor for class %s */\n", human_name);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Printf(s_wrappers," /* bah! No destructor for this simple type!! */\n");
|
Printf(s_wrappers," /* No destructor for simple type %s */\n", key);
|
||||||
}
|
}
|
||||||
|
|
||||||
// close function
|
// close function
|
||||||
Printf(s_wrappers,"}\n");
|
Printf(s_wrappers,"}\n");
|
||||||
|
|
||||||
// declare le_swig_<mangled> to store php registration
|
// declare le_swig_<mangled> to store php registration
|
||||||
Printf(s_vdecl,"static int le_swig_%s=0; /* handle for %s */\n", key, shadow_classname);
|
Printf(s_vdecl,"static int le_swig_%s=0; /* handle for %s */\n", key, human_name);
|
||||||
|
|
||||||
// register with php
|
// register with php
|
||||||
Printf(s_oinit,"le_swig_%s=zend_register_list_destructors_ex"
|
Printf(s_oinit,"le_swig_%s=zend_register_list_destructors_ex"
|
||||||
|
|
@ -618,7 +614,7 @@ public:
|
||||||
/* Set the module name */
|
/* Set the module name */
|
||||||
module = Copy(Getattr(n,"name"));
|
module = Copy(Getattr(n,"name"));
|
||||||
cap_module = NewStringf("%(upper)s",module);
|
cap_module = NewStringf("%(upper)s",module);
|
||||||
if (!prefix) prefix = Copy(module);
|
if (!prefix) prefix = NewStringEmpty();
|
||||||
|
|
||||||
/* PHP module file */
|
/* PHP module file */
|
||||||
filen = NewStringEmpty();
|
filen = NewStringEmpty();
|
||||||
|
|
@ -863,9 +859,9 @@ public:
|
||||||
|
|
||||||
Printf(f_phpcode, "%s\n%s\n", pragma_incl, pragma_code);
|
Printf(f_phpcode, "%s\n%s\n", pragma_incl, pragma_code);
|
||||||
if (s_fakeoowrappers) {
|
if (s_fakeoowrappers) {
|
||||||
Printf(f_phpcode, "abstract class %s {", prefix);
|
Printf(f_phpcode, "abstract class %s {", Len(prefix) ? prefix : module);
|
||||||
Printf(f_phpcode, "%s", s_fakeoowrappers);
|
Printf(f_phpcode, "%s", s_fakeoowrappers);
|
||||||
Printf(f_phpcode, "}\n\n", prefix);
|
Printf(f_phpcode, "}\n\n");
|
||||||
Delete(s_fakeoowrappers);
|
Delete(s_fakeoowrappers);
|
||||||
s_fakeoowrappers = NULL;
|
s_fakeoowrappers = NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -1016,13 +1012,13 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// if PHP4, shadow and variable wrapper we want to snag the main contents
|
// if PHP4, shadow and variable wrapper we want to snag the main contents
|
||||||
// of this function to stick in to the property handler....
|
// of this function to stick in to the property handler...
|
||||||
if (mvr) {
|
if (mvr) {
|
||||||
String *php_function_name = NewString(iname);
|
String *php_function_name = NewString(iname);
|
||||||
if( Strcmp( iname, Swig_name_set(Swig_name_member(shadow_classname, name)))== 0) {
|
if (Strcmp(iname, Swig_name_set(Swig_name_member(shadow_classname, name)))== 0) {
|
||||||
Setattr(shadow_set_vars, php_function_name, name);
|
Setattr(shadow_set_vars, php_function_name, name);
|
||||||
}
|
}
|
||||||
if( Strcmp(iname, Swig_name_get(Swig_name_member(shadow_classname, name))) == 0) {
|
if (Strcmp(iname, Swig_name_get(Swig_name_member(shadow_classname, name))) == 0) {
|
||||||
Setattr(shadow_get_vars, php_function_name, name);
|
Setattr(shadow_get_vars, php_function_name, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1993,14 +1989,14 @@ public:
|
||||||
char *rename = GetChar(n, "sym:name");
|
char *rename = GetChar(n, "sym:name");
|
||||||
|
|
||||||
if (!addSymbol(rename,n)) return SWIG_ERROR;
|
if (!addSymbol(rename,n)) return SWIG_ERROR;
|
||||||
shadow_classname = Swig_copy_string(rename);
|
shadow_classname = NewStringf("%s", rename);
|
||||||
cs_entry = NewStringEmpty();
|
cs_entry = NewStringEmpty();
|
||||||
Printf(cs_entry,"/* Function entries for %s */\n",shadow_classname);
|
Printf(cs_entry, "/* Function entries for %s */\n", shadow_classname);
|
||||||
Printf(cs_entry,"static zend_function_entry %s_functions[] = {\n", shadow_classname);
|
Printf(cs_entry, "static zend_function_entry %s_functions[] = {\n", shadow_classname);
|
||||||
|
|
||||||
if(Strcmp(shadow_classname, module) == 0) {
|
if (Strcmp(shadow_classname, module) == 0) {
|
||||||
Printf(stderr, "class name cannot be equal to module name: %s\n", shadow_classname);
|
Printf(stderr, "class name cannot be equal to module name: %s\n", module);
|
||||||
SWIG_exit(1);
|
SWIG_exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
shadow_get_vars = NewHash();
|
shadow_get_vars = NewHash();
|
||||||
|
|
@ -2073,7 +2069,6 @@ public:
|
||||||
|
|
||||||
if (shadow && php_version == 4) {
|
if (shadow && php_version == 4) {
|
||||||
DOH *key;
|
DOH *key;
|
||||||
int gcount, scount;
|
|
||||||
String *s_propget = NewStringEmpty();
|
String *s_propget = NewStringEmpty();
|
||||||
String *s_propset = NewStringEmpty();
|
String *s_propset = NewStringEmpty();
|
||||||
List *baselist = Getattr(n, "bases");
|
List *baselist = Getattr(n, "bases");
|
||||||
|
|
@ -2144,23 +2139,15 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
scount=0;
|
|
||||||
while (ki.key) {
|
while (ki.key) {
|
||||||
key = ki.key;
|
key = ki.key;
|
||||||
if (scount++) {
|
|
||||||
Printf(s_propset," else");
|
|
||||||
}
|
|
||||||
Printf(s_propset," if (strcmp(propname,\"%s\")==0) {\n", ki.item);
|
Printf(s_propset," if (strcmp(propname,\"%s\")==0) {\n", ki.item);
|
||||||
Printf(s_propset," return _wrap_%s(property_reference, value);\n",key);
|
Printf(s_propset," return _wrap_%s(property_reference, value);\n",key);
|
||||||
Printf(s_propset," }");
|
Printf(s_propset," }\n");
|
||||||
|
|
||||||
ki=Next(ki);
|
ki=Next(ki);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scount) {
|
|
||||||
Printf(s_propset," else");
|
|
||||||
}
|
|
||||||
|
|
||||||
// If there is a base class then chain its handler else set directly
|
// If there is a base class then chain its handler else set directly
|
||||||
// try each base class handler, else set directly...
|
// try each base class handler, else set directly...
|
||||||
if (base.item) {
|
if (base.item) {
|
||||||
|
|
@ -2234,24 +2221,16 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gcount=0;
|
|
||||||
while (ki.key) {
|
while (ki.key) {
|
||||||
key = ki.key;
|
key = ki.key;
|
||||||
if (gcount++) {
|
|
||||||
Printf(s_propget," else");
|
|
||||||
}
|
|
||||||
Printf(s_propget," if (strcmp(propname,\"%s\")==0) {\n", ki.item);
|
Printf(s_propget," if (strcmp(propname,\"%s\")==0) {\n", ki.item);
|
||||||
Printf(s_propget," *value=_wrap_%s(property_reference);\n",key);
|
Printf(s_propget," *value=_wrap_%s(property_reference);\n",key);
|
||||||
Printf(s_propget," return SUCCESS;\n");
|
Printf(s_propget," return SUCCESS;\n");
|
||||||
Printf(s_propget," }");
|
Printf(s_propget," }\n");
|
||||||
|
|
||||||
ki=Next(ki);
|
ki=Next(ki);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gcount) {
|
|
||||||
Printf(s_propget," else");
|
|
||||||
}
|
|
||||||
|
|
||||||
// If there is a base class then chain its handler else return FAILURE.
|
// If there is a base class then chain its handler else return FAILURE.
|
||||||
if (base.item) {
|
if (base.item) {
|
||||||
Printf(s_propget, " {\n /* chain to base class */\n");
|
Printf(s_propget, " {\n /* chain to base class */\n");
|
||||||
|
|
@ -2297,7 +2276,7 @@ public:
|
||||||
// Write the enum initialisation code in a static block
|
// Write the enum initialisation code in a static block
|
||||||
// These are all the enums defined within the C++ class.
|
// These are all the enums defined within the C++ class.
|
||||||
|
|
||||||
free(shadow_classname);
|
Delete(shadow_classname);
|
||||||
shadow_classname = NULL;
|
shadow_classname = NULL;
|
||||||
|
|
||||||
Delete(shadow_set_vars); shadow_set_vars = NULL;
|
Delete(shadow_set_vars); shadow_set_vars = NULL;
|
||||||
|
|
@ -2399,7 +2378,7 @@ public:
|
||||||
|
|
||||||
Printf(s_phpclasses, "}\n\n");
|
Printf(s_phpclasses, "}\n\n");
|
||||||
|
|
||||||
free(shadow_classname);
|
Delete(shadow_classname);
|
||||||
shadow_classname = NULL;
|
shadow_classname = NULL;
|
||||||
|
|
||||||
Delete(shadow_set_vars); shadow_set_vars = NULL;
|
Delete(shadow_set_vars); shadow_set_vars = NULL;
|
||||||
|
|
@ -2633,13 +2612,13 @@ public:
|
||||||
/* ------------------------------------------------------------
|
/* ------------------------------------------------------------
|
||||||
* constructorHandler()
|
* constructorHandler()
|
||||||
* ------------------------------------------------------------ */
|
* ------------------------------------------------------------ */
|
||||||
|
|
||||||
virtual int constructorHandler(Node *n) {
|
virtual int constructorHandler(Node *n) {
|
||||||
char *name = GetChar(n, "name");
|
char *name = GetChar(n, "name");
|
||||||
char *iname = GetChar(n, "sym:name");
|
char *iname = GetChar(n, "sym:name");
|
||||||
|
|
||||||
if (shadow && php_version == 4) {
|
if (shadow && php_version == 4) {
|
||||||
if (strcmp(iname, shadow_classname) == 0) {
|
if (strcmp(iname, Char(shadow_classname)) == 0) {
|
||||||
native_constructor = NATIVE_CONSTRUCTOR;
|
native_constructor = NATIVE_CONSTRUCTOR;
|
||||||
} else {
|
} else {
|
||||||
native_constructor = ALTERNATIVE_CONSTRUCTOR;
|
native_constructor = ALTERNATIVE_CONSTRUCTOR;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue