5
* richard@magicality.org
8
* Portions copyright Sun Microsystems (c) 2001
9
* Tim Hockin <thockin@sun.com>
12
static char cvsroot[] = "$Header: /cvs/projects/SWIG/Source/Modules1.1/Attic/php4.cxx,v 1.1.2.25 2002/01/31 00:47:18 beazley Exp $";
18
#include "swigconfig.h"
20
static char *usage = (char*)"\
21
PHP4 Options (available with -php4)\n\
22
-shadow - Create shadow classes.\n\
23
-dlname name - Set module prefix.\n\
24
-make - Create simple makefile.\n\
25
-phpfull - Create full make files.\n\
26
-nosync - No syncronisation of variables.\n\n";
28
#define PHP_READONLY 1<<0
30
static String *module = 0;
31
static String *cap_module = 0;
32
static String *dlname = 0;
34
static String *f_cinit = 0;
35
static String *f_oinit = 0;
36
static String *f_init = 0;
37
static String *f_entry = 0;
38
//static char *package = 0; // Name of the package
39
static char *c_pkgstr; // Name of the package
40
static char *php_pkgstr; // Name of the package
41
static char *shadow_classname;
44
static Wrapper *f_php;
45
static int gen_extra = 0;
46
static int gen_make = 0;
47
static int no_sync = 0;
49
static File *f_runtime = 0;
51
static File *f_header = 0;
52
static File *f_wrappers = 0;
53
static File *f_phpcode = 0;
55
static String *s_header;
56
static String *s_wrappers;
57
static String *s_init;
58
static String *s_vinit;
59
static String *s_cinit;
60
static String *s_oinit;
61
static String *s_entry;
62
static String *pragma_incl;
63
static String *pragma_code;
64
static String *pragma_phpinfo;
66
/* Variables for using PHP classes */
67
static String *php; /* Class initialization code */
68
static String *class_name = 0;
69
static String *base_class = 0;
70
static String *real_classname = 0;
71
static String *class_type = 0;
72
static String *realpackage = 0;
73
static String *package = 0;
75
static Hash *shadow_classes;
76
static Hash *shadow_php_vars;
77
static Hash *shadow_c_vars;
78
static String *shadow_classdef;
79
static String *shadow_code;
80
static char *shadow_variable_name = 0;
81
static int classdef_emitted = 0;
82
static int have_default_constructor = 0;
83
static int native_func = 0; // Set to 1 when wrapping a native function
84
static int enum_flag = 0; // Set to 1 when wrapping an enum
85
static int static_flag = 0; // Set to 1 when wrapping a static functions or member variables
86
static int const_flag = 0; // Set to 1 when wrapping a const member variables
87
static int variable_wrapper_flag = 0; // Set to 1 when wrapping a member variable/enum/const
88
static int wrapping_member = 0;
89
static int written_base_class = 0; // XX hack to prevent base class duplicated
91
static String *shadow_enum_code = 0;
92
static String *php_enum_code = 0;
93
static String *all_shadow_extra_code = 0;
94
//Extra code for all shadow classes from %pragma
95
static String *this_shadow_extra_code = 0;
96
//Extra Code for current single shadow class freom %pragma
97
static String *all_shadow_import = 0;
98
//import for all shadow classes from %pragma
99
static String *this_shadow_import = 0;
100
//import for current shadow classes from %pragma
101
static String *module_baseclass = 0;
102
//inheritance for module class from %pragma
103
static String *all_shadow_baseclass = 0;
104
//inheritence for all shadow classes from %pragma
105
static String *this_shadow_baseclass = 0;
106
//inheritance for shadow class from %pragma and cpp_inherit
107
static int class_renamed = 0;
108
static int shadow = 0;
110
/* Test to see if a type corresponds to something wrapped with a shadow class */
111
static String *is_shadow(SwigType *t) {
113
SwigType *lt = SwigType_ltype(t);
114
r = Getattr(shadow_classes,lt);
119
// Return the type of the c array
120
static SwigType *get_array_type(SwigType *t) {
122
if (SwigType_type(t) == T_ARRAY) {
125
aop = SwigType_pop(ta);
131
static void emit_banner(File *f) {
132
Printf(f, "/* ----------------------------------------------------------------------------\n");
133
Printf(f, " * This file was automatically generated by SWIG (http://www.swig.org).\n");
134
Printf(f, " * Version: %s\n", SWIG_VERSION);
136
Printf(f, " * Do not make changes to this file unless you know what you are doing--modify\n");
137
Printf(f, " * the SWIG interface file instead.\n");
138
Printf(f, " * ----------------------------------------------------------------------------- */\n\n");
141
/* -----------------------------------------------------------------------------
143
* ----------------------------------------------------------------------------- */
145
get_pointer(char *iname, char *srcname, char *src, char *dest,
146
SwigType *t, String *f, char *ret) {
148
SwigType_remember(t);
149
SwigType *lt = SwigType_ltype(t);
150
Printv(f, "if (SWIG_ConvertPtr(", src, ",(void **) ", dest, ",", 0);
152
/* If we're passing a void pointer, we give the pointer conversion a NULL
153
pointer, otherwise pass in the expected type. */
155
if (Cmp(lt,"p.void") == 0) {
156
Printf(f, " 0 ) < 0) {\n");
158
Printv(f, "SWIGTYPE", SwigType_manglestr(t), ") < 0) {\n",0);
162
"zend_error(E_ERROR, \"Type error in ", srcname, " of ", iname,
163
" Expected %s\", SWIGTYPE", SwigType_manglestr(t), "->name);\n", ret,
172
PHP4::main(int argc, char *argv[]) {
174
SWIG_library_directory("php4");
175
for(i = 1; i < argc; i++) {
177
if(strcmp(argv[i], "-phpfull") == 0) {
180
} else if(strcmp(argv[i], "-dlname") == 0) {
182
dlname = NewString(argv[i+1]);
189
} else if(strcmp(argv[i], "-shadow") == 0) {
192
} else if(strcmp(argv[i], "-make") == 0) {
195
} else if(strcmp(argv[i], "-nosync") == 0) {
198
} else if(strcmp(argv[i], "-help") == 0) {
199
fputs(usage, stderr);
204
Preprocessor_define((void *) "SWIGPHP 1", 0);
205
Preprocessor_define((void *) "SWIGPHP4 1", 0);
206
SWIG_typemap_lang("php4");
207
/* DB: Suggest using a language configuration file */
208
SWIG_config_file("php4.swg");
212
void create_simple_make(void) {
215
f_make = NewFile((void *)"makefile", "w");
217
Printf(f_make, "CC=g++\n");
219
Printf(f_make, "CC=gcc\n");
226
"PHP_INC=`php-config --includes`\n"
233
"\t$(CC) $(LDFLAGS) $(OBJS) -o $(PROG) $(EXTRA_LIB)\n\n"
235
"\t$(CC) $(EXTRA_INC) $(PHP_INC) $(CFLAGS) -c $<\n",
236
(CPlusPlus?"cxx":"c"));
242
void create_extra_files(void) {
246
/* Write out Makefile.in */
247
f_extra = NewFile((void *)"Makefile.in", "w");
249
Printf(stderr,"Unable to open Makefile.in\n");
250
SWIG_exit(EXIT_FAILURE);
254
"# $Id: php4.cxx,v 1.1.2.25 2002/01/31 00:47:18 beazley Exp $\n\n");
255
Printf(f_extra, "LTLIBRARY_NAME = lib%s.la\n", module);
256
Printf(f_extra, "LTLIBRARY_SOURCES = %s_wrap.c\n", module);
257
Printf(f_extra, "LTLIBRARY_SHARED_NAME = %s.la\n", module);
258
Printf(f_extra, "LTLIBRARY_SHARED_LIBADD = $(%s_SHARED_LIBADD)\n\n",
260
Printf(f_extra, "include $(top_srcdir)/build/dynlib.mk\n");
264
f_extra = NewFile((void *)"config.m4", "w");
266
Printf(stderr, "Unable to open config.m4\n");
267
SWIG_exit(EXIT_FAILURE);
271
"dnl $Id: php4.cxx,v 1.1.2.25 2002/01/31 00:47:18 beazley Exp $\n");
273
"dnl config.m4 for extension %s\n\n", module);
275
"dnl Comments in this file start with the string 'dnl'.\n");
277
"dnl Remove where necessary. This file will not work\n");
279
"dnl without editing.\n\n");
282
"dnl If your extension references somthing external, use:\n\n");
284
"dnl PHP_ARG_WITH(%s, for %s support,\n", module, module);
286
"dnl Make sure that the comment is aligned:\n");
288
"dnl [ --with-%s Include %s support])\n\n",
292
"dnl Otherwise use enable:\n\n");
294
"PHP_ARG_ENABLE(%s, whether to enable %s support,\n",
297
"dnl Make sure that the comment is aligned:\n");
299
"[ --enable-%s Enable %s support])\n\n", module, module);
302
"if test \"$PHP_%s\" != \"no\"; then\n", cap_module);
304
" dnl Write more examples of tests here\n\n");
306
" dnl # --with-%s -> check with-path\n", module);
308
" dnl # you might want to change this\n"
309
" dnl SEARCH_PATH=\"/usr/local /usr\"\n");
311
" dnl # you most likely want to change this\n"
312
" dnl SEARCH_FOR=\"/include/%s.h\"\n", module);
314
" dnl # path given as parameter\n"
315
" dnl if test -r $PHP_%s/; then\n", module);
317
" dnl %s_DIR=$PHP_%s\n", cap_module, cap_module);
319
" dnl else # search default path list\n");
321
" dnl AC_MSG_CHECKING(for %s files in default path)\n", module);
323
" dnl for i in $SEARCH_PATH; do\n");
325
" dnl if test -r $i/$SEARCH_FOR; then\n");
327
" dnl %s_DIR=$i\n", cap_module);
329
" dnl AC_MSG_RESULT(found in $i)\n");
339
" dnl if test -z \"$%s_DIR\"; then\n", cap_module);
341
" dnl AC_MSG_RESULT(not found)\n");
343
" dnl AC_MSG_ERROR(Please reinstall the %s distribution)\n",
348
" dnl # --with-%s -> add include path\n", module);
350
" dnl PHP_ADD_INCLUDE($%s_DIR/include)\n\n", cap_module);
352
" dnl #--with-%s -> check for lib and symbol presence\n", module);
354
" dnl LIBNAME=%s # you may want to change this\n", module);
356
" dnl LIBSYMBOL=%s # you most likely want to change this\n",
359
" dnl old_LIBS=$LIBS\n");
361
" dnl LIBS=\"$LIBS -L$%s_DIR/lib -lm -ldl\"\n", cap_module);
363
" dnl AC_CHECK_LIB($LIBNAME, $LIBSYMBOL, [AC_DEFINE(HAVE_%sLIB,1,[ ])],\n",
366
" dnl [AC_MSG_ERROR(wrong %s lib version or lib not found)])\n",
369
" dnl LIBS=$old_LIBS\n");
373
" dnl PHP_SUBST(%s_SHARED_LIBADD)\n", cap_module);
375
" dnl PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $%s_DIR/lib, SAPRFC_SHARED_LIBADD)\n\n",
378
" PHP_EXTENSION(%s, $ext_shared)\n", module);
379
Printf(f_extra,"fi\n");
383
f_extra = NewFile((void *)"CREDITS", "w");
385
Printf(stderr,"Unable to open CREDITS\n");
386
SWIG_exit(EXIT_FAILURE);
388
Printf(f_extra, "%s\n", module);
393
static const char *php_header =
395
"\n +----------------------------------------------------------------------+"
396
"\n | PHP version 4.0 |"
397
"\n +----------------------------------------------------------------------+"
398
"\n | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |"
399
"\n +----------------------------------------------------------------------+"
400
"\n | This source file is subject to version 2.02 of the PHP license, |"
401
"\n | that is bundled with this package in the file LICENSE, and is |"
402
"\n | available at through the world-wide-web at |"
403
"\n | http://www.php.net/license/2_02.txt. |"
404
"\n | If you did not receive a copy of the PHP license and are unable to |"
405
"\n | obtain it through the world-wide-web, please send a note to |"
406
"\n | license@php.net so we can mail you a copy immediately. |"
407
"\n +----------------------------------------------------------------------+"
410
"\n +----------------------------------------------------------------------+"
419
/* Initialize all of the output files */
420
outfile = Getattr(n,"outfile");
422
/* main output file */
423
f_runtime = NewFile(outfile,"w");
425
Printf(stderr,"*** Can't open '%s'\n", outfile);
426
SWIG_exit(EXIT_FAILURE);
429
Swig_banner(f_runtime);
431
/* sections of the output file */
432
s_init = NewString("/* init section */\n");
433
s_header = NewString("/* header section */\n");
434
s_wrappers = NewString("/* wrapper section */\n");
435
/* subsections of the init section */
436
s_vinit = NewString("/* vinit subsection */\n");
437
s_cinit = NewString("/* cinit subsection */\n");
438
s_oinit = NewString("/* oinit subsection */\n");
440
pragma_phpinfo = NewString("");
443
/* Register file targets with the SWIG file handler */
444
Swig_register_filebyname("runtime",f_runtime);
445
Swig_register_filebyname("init",s_init);
446
Swig_register_filebyname("header",s_header);
447
Swig_register_filebyname("wrapper",s_wrappers);
449
shadow_classes = NewHash();
450
shadow_classdef = NewString("");
451
shadow_code = NewString("");
452
php_enum_code = NewString("");
453
module_baseclass = NewString("");
454
all_shadow_extra_code = NewString("");
455
all_shadow_import = NewString("");
456
all_shadow_baseclass = NewString("");
458
/* Set the module name */
459
module = Copy(Getattr(n,"name"));
460
cap_module = NewStringf("%(upper)s",module);
463
realpackage = module;
464
package = NewStringf("%sc", module);
469
#if defined(_WIN32) || defined(__WIN32__)
470
dlname = NewStringf("%s.dll", module);
472
dlname = NewStringf("lib%s.so", module);
476
/* PHP module file */
477
filen = NewString(module);
478
Printf(filen, ".php");
479
f_phpcode = NewFile(filen, "w");
481
Printf(stderr, "*** Can't open '%s'\n", filen);
482
SWIG_exit(EXIT_FAILURE);
485
Printf(f_phpcode, "<?php\n\n");
487
emit_banner(f_phpcode);
490
"global $%s_LOADED__;\n"
491
"if ($%s_LOADED__) return;\n"
492
"$%s_LOADED__ = true;\n\n"
493
"/* if our extension has not been loaded, do what we can */\n"
494
"if (!extension_loaded(\"%s\")) {\n"
495
" if (!dl(\"%s\")) return;\n"
496
"}\n\n", cap_module, cap_module, cap_module, module, dlname);
499
/* sub-sections of the php file */
500
pragma_code = NewString("");
501
pragma_incl = NewString("");
503
/* Initialize the rest of the module */
506
f_php = NewWrapper();
507
Printf(f_c->def, "static void Swig_sync_c(void) {\n");
508
Printf(f_php->def, "static void Swig_sync_php(void) {\n");
510
/* start the header section */
511
Printf(s_header, php_header);
513
"#define SWIG_init init%s\n\n"
514
"#define SWIG_name \"%s\"\n"
515
"#ifdef HAVE_CONFIG_H\n"
516
"#include \"config.h\"\n"
518
"#ifdef __cplusplus\n"
521
"#include \"php.h\"\n"
522
"#include \"php_ini.h\"\n"
523
"#include \"php_%s.h\"\n"
524
"#ifdef __cplusplus\n"
527
module, module, module);
529
/* Create the .h file too */
530
filen = NewString("");
531
Printv(filen, Swig_file_dirname(outfile), "php_", module, ".h", 0);
532
f_h = NewFile(filen, "w");
534
Printf(stderr,"Unable to open %s\n", filen);
535
SWIG_exit(EXIT_FAILURE);
539
Printf(f_h, php_header);
543
"#define PHP_%s_H\n\n"
544
"extern zend_module_entry %s_module_entry;\n"
545
"#define phpext_%s_ptr &%s_module_entry\n\n"
547
"# define PHP_%s_API __declspec(dllexport)\n"
549
"# define PHP_%s_API\n"
551
"PHP_MINIT_FUNCTION(%s);\n"
552
"PHP_MSHUTDOWN_FUNCTION(%s);\n"
553
"PHP_RINIT_FUNCTION(%s);\n"
554
"PHP_RSHUTDOWN_FUNCTION(%s);\n"
555
"PHP_MINFO_FUNCTION(%s);\n\n",
556
cap_module, cap_module, module, module, module, cap_module, cap_module,
557
module, module, module, module, module);
559
/* start the function entry section */
560
s_entry = NewString("/* entry subsection */\n");
561
Printf(s_entry, "static void Swig_sync_c(void);\n");
562
Printf(s_entry, "static void Swig_sync_php(void);\n\n");
564
Printf(s_entry,"/* Every user visible function must have an entry */\n");
565
Printf(s_entry,"function_entry %s_functions[] = {\n", module);
567
/* Start variable init function (to be put in module init function) */
570
" for (i = 0; swig_types_initial[i]; i++) {\n"
571
" swig_types[i] = SWIG_TypeRegister(swig_types_initial[i]);\n"
574
/* start the init section */
576
Printf(s_init,"#ifdef COMPILE_DL_%s\n", cap_module);
578
"#ifdef __cplusplus\n"
581
"ZEND_GET_MODULE(%s)\n"
582
"#ifdef __cplusplus\n"
587
Printf(s_init,"#endif\n\n");
589
Printf(s_init,"PHP_MINIT_FUNCTION(%s)\n{\n", module);
590
Printf(s_init," return SUCCESS;\n");
591
Printf(s_init,"}\n");
593
Printf(s_init,"PHP_MSHUTDOWN_FUNCTION(%s)\n{\n", module);
594
Printf(s_init," return SUCCESS;\n");
595
Printf(s_init,"}\n");
598
/* finish our init section */
599
Printf(s_vinit, "/* end vinit subsection */\n");
601
/* We need this after all classes written out, not sure where to put it
604
Printf(s_oinit, "CG(active_class_entry) = NULL;\n");
606
Printf(s_oinit, "/* end oinit subsection */\n");
607
Printf(s_init,"PHP_RINIT_FUNCTION(%s)\n{\n", module);
609
/* Emit all of the code */
612
/* Constants generated during top call */
613
Printf(s_init, "%s\n", s_cinit);
614
Printf(s_cinit, "/* end cinit subsection */\n");
616
Printf(s_init, "%s\n%s\n", s_vinit, s_oinit);
620
Printf(s_init, " return SUCCESS;\n");
621
Printf(s_init,"}\n");
623
Printf(s_init,"PHP_RSHUTDOWN_FUNCTION(%s)\n{\n", module);
624
Printf(s_init," return SUCCESS;\n");
625
Printf(s_init,"}\n");
627
Printf(s_init,"PHP_MINFO_FUNCTION(%s)\n{\n", module);
628
Printf(s_init,"%s", pragma_phpinfo);
629
Printf(s_init,"}\n");
630
Printf(s_init, "/* end init section */\n");
632
/* Complete header file */
635
"/*If you declare any globals in php_%s.h uncomment this:\n", module);
636
Printf(f_h,"ZEND_BEGIN_MODULE_GLOBALS(%s)\n", module);
637
Printf(f_h,"ZEND_END_MODULE_GLOBALS(%s)\n", module);
640
Printf(f_h,"#ifdef ZTS\n");
641
Printf(f_h,"#define %s_D zend_%s_globals *%s_globals\n", cap_module,
643
Printf(f_h,"#define %s_DC , %s_D\n", cap_module, cap_module);
644
Printf(f_h,"#define %s_C %s_globals\n", cap_module, module);
645
Printf(f_h,"#define %s_CC , %s_C\n", cap_module, cap_module);
646
Printf(f_h,"#define %s_SG(v) (%s_globals->v)\n", cap_module, module);
647
Printf(f_h,"#define %s_FETCH() zend_%s_globals *%s_globals "
648
"= ts_resource(%s_globals_id)\n", cap_module, module, module, module);
649
Printf(f_h,"#else\n");
650
Printf(f_h,"#define %s_D\n", cap_module);
651
Printf(f_h,"#define %s_DC\n", cap_module);
652
Printf(f_h,"#define %s_C\n", cap_module);
653
Printf(f_h,"#define %s_CC\n", cap_module);
654
Printf(f_h,"#define %s_SG(v) (%s_globals.v)\n", cap_module, module);
655
Printf(f_h,"#define %s_FETCH()\n", cap_module);
656
Printf(f_h,"#endif\n\n");
657
Printf(f_h,"#endif /* PHP_%s_H */\n", cap_module);
661
Printf(s_header, "%s", s_entry);
663
Printf(s_header," {NULL, NULL, NULL}\n};\n\n");
664
Printf(s_header,"zend_module_entry %s_module_entry = {\n", module);
665
Printf(s_header,"#if ZEND_MODULE_API_NO > 20010900\n");
666
Printf(s_header," STANDARD_MODULE_HEADER,\n");
667
Printf(s_header,"#endif\n");
668
Printf(s_header," \"%s\",\n", module);
669
Printf(s_header," %s_functions,\n", module);
670
Printf(s_header," PHP_MINIT(%s),\n", module);
671
Printf(s_header," PHP_MSHUTDOWN(%s),\n", module);
672
Printf(s_header," PHP_RINIT(%s),\n", module);
673
Printf(s_header," PHP_RSHUTDOWN(%s),\n", module);
674
Printf(s_header," PHP_MINFO(%s),\n", module);
675
Printf(s_header,"#if ZEND_MODULE_API_NO > 20010900\n");
676
Printf(s_header," NO_VERSION_YET,\n");
677
Printf(s_header,"#endif\n");
678
Printf(s_header," STANDARD_MODULE_PROPERTIES\n");
679
Printf(s_header,"};\n\n");
681
Printv(f_runtime, s_header, 0);
683
String *type_table = NewString("");
684
SwigType_emit_type_table(f_runtime,type_table);
685
Printf(f_runtime,"%s",type_table);
688
Printf(f_c->code, "\n}\n");
689
Printf(f_php->code, "\n}\n");
691
Wrapper_print(f_c, s_wrappers);
692
Wrapper_print(f_php, s_wrappers);
694
Printf(s_header, "/* end header section */\n");
695
Printf(s_wrappers, "/* end wrapper section */\n");
697
Printv(f_runtime, s_wrappers, s_init, 0);
702
Printf(f_phpcode, "%s\n%s\n?>\n", pragma_incl, pragma_code);
705
create_extra_files();
707
if(!gen_extra && gen_make)
708
create_simple_make();
716
PHP4::set_module(char *mod_name) {
719
module = NewString(mod_name);
720
cap_module = Copy(module);
721
for(c = Char(cap_module); *c != '\0'; c++) {
722
if((*c >= 'a') && (*c <= 'z'))
731
PHP4::add_method(char *name, char *function, int kw) {
732
fprintf(stderr, "Would add method %s\n", name);
736
/* Just need to append function names to function table to register with
741
PHP4::create_command(char *cname, char *iname) {
742
char *lower_cname = strdup(cname);
745
for(c = lower_cname; *c != '\0'; c++) {
746
if(*c >= 'A' && *c <= 'Z')
751
" ZEND_NAMED_FE(%s,\n"
752
" %s, NULL)\n", lower_cname,iname);
753
Printf(f_h, "ZEND_NAMED_FUNCTION(%s);\n", iname);
759
PHP4::functionWrapper(Node *n) {
760
char *name = GetChar(n,"name");
761
char *iname = GetChar(n,"sym:name");
762
SwigType *d = Getattr(n,"type");
763
ParmList *l = Getattr(n,"parms");
765
char source[256],target[256],temp[256],argnum[32],args[32];
766
int pcount,i,j,numopt;
769
int need_save, num_saved = 0;
770
String *cleanup, *outarg;
772
if(shadow && wrapping_member && !enum_flag) {
773
String *member_function_name = NewString("");
774
String *php_function_name = NewString(iname);
775
if(strcmp(iname, Char(Swig_name_set(Swig_name_member(shadow_classname, shadow_variable_name)))) == 0) {
776
Printf(member_function_name, "set");
778
Setattr(shadow_c_vars, php_function_name, name);
781
Printf(member_function_name, "get");
783
Setattr(shadow_php_vars, php_function_name, name);
785
Putc(toupper((int )*shadow_variable_name), member_function_name);
786
Printf(member_function_name, "%s", shadow_variable_name+1);
788
cpp_func(Char(member_function_name), d, l, php_function_name);
790
Delete(php_function_name);
791
Delete(member_function_name);
795
create_command(iname, Char(Swig_name_wrapper(iname)));
797
outarg = cleanup = NULL;
801
outarg = NewString("");
803
Printv(f->def, "ZEND_NAMED_FUNCTION(" , Swig_name_wrapper(iname), ") {\n", 0);
806
/* Attach standard typemaps */
807
emit_attach_parmmaps(l,f);
809
int num_arguments = emit_num_arguments(l);
810
int num_required = emit_num_required(l);
811
numopt = num_arguments - num_required;
813
sprintf(args, "%s[%d]", "zval **args", num_arguments);
815
Wrapper_add_local(f, "args",args);
817
Printf(f->code, "Swig_sync_c();\n\n");/* Keep PHP4 / C vars in sync */
820
Wrapper_add_local(f, "arg_count", "int arg_count");
821
Printf(f->code,"arg_count = ZEND_NUM_ARGS();\n");
822
Printf(f->code,"if(arg_count<%d || arg_count>%d)\n",num_required,num_arguments);
823
Printf(f->code,"\tWRONG_PARAM_COUNT;\n\n");
825
/* Verified args, retrieve them... */
826
Printf(f->code,"if(zend_get_parameters_array_ex(arg_count,args)!=SUCCESS)");
827
Printf(f->code, "\n\t\tWRONG_PARAM_COUNT;\n\n");
830
Printf(f->code, "if((ZEND_NUM_ARGS() != %d) || (zend_get_parameters_array_ex(%d, args) != SUCCESS)) {\n", num_arguments, num_arguments);
831
Printf(f->code, "WRONG_PARAM_COUNT;\n}\n\n");
834
/* Now convert from php to C variables */
836
for (i = 0, p = l; i < num_arguments; i++) {
837
/* Skip ignored arguments */
838
while (Getattr(p,"tmap:ignore")) {
839
p = Getattr(p,"tmap:ignore:next");
841
SwigType *pt = Getattr(p,"type");
842
String *pn = Getattr(p,"name");
844
sprintf(source, "args[%d]", i);
845
sprintf(target, "%s", Char(Getattr(p,"lname")));
846
sprintf(argnum, "%d", i+1);
848
/* Check if optional */
850
if(i>= (num_required))
851
Printf(f->code,"\tif(arg_count > %d) {\n", i);
853
Setattr(p,"emit:input", source);
855
if ((tm = Getattr(p,"tmap:in"))) {
856
Replace(tm,"$target",target,DOH_REPLACE_ANY);
857
Replace(tm,"$source",source,DOH_REPLACE_ANY);
858
Replace(tm,"$input", source,DOH_REPLACE_ANY);
859
Printf(f->code,"%s\n",tm);
860
p = Getattr(p,"tmap:in:next");
861
if (i >= num_required) {
862
Printf(f->code,"}\n");
866
switch(SwigType_type(pt)) {
876
Printf(f->code,"convert_to_long_ex(args[%d]);\n", i);
877
Printf(f->code,"%s =(%s)Z_LVAL_PP(args[%d]);\n", target, SwigType_lstr(pt,0),i);
880
Printf(f->code,"convert_to_string_ex(args[%d]);\n", i);
881
Printf(f->code,"\t%s = (char) *Z_STRVAL_PP(args[%d]);\n", target, i);
885
Printf(f->code,"convert_to_double_ex(args[%d]);\n", i);
886
Printf(f->code,"\t%s = (%s)Z_DVAL_PP(args[%d]);\n", target, SwigType_lstr(pt,0), i);
891
SwigType_add_pointer(pt);
892
sprintf(temp,"argument %d", i+1);
893
Printf(f->code,"convert_to_string_ex(args[%d]);\n", i);
894
get_pointer(iname, temp, source, target, pt, f->code, (char *)"RETURN_FALSE");
895
SwigType_del_pointer(pt);
897
case T_POINTER: case T_ARRAY: case T_REFERENCE:
898
sprintf(temp,"argument %d", i+1);
899
Printf(f->code,"convert_to_string_ex(args[%d]);\n", i);
900
get_pointer(iname,temp,source,target, pt, f->code, (char *)"");
903
Printf(f->code,"convert_to_string_ex(args[%d]);\n", i);
904
Printf(f->code,"\t%s = (char *)Z_STRVAL_PP(args[%d]);\n", target, i);
907
Printf(stderr,"%s : Line %d, Unable to use type %s as a function argument.\n", input_file, line_number, SwigType_str(pt,0));
912
if (i>= num_required)
913
Printf(f->code,"\t}\n");
916
/* Insert constraint checking code */
918
if ((tm = Getattr(p,"tmap:check"))) {
919
Replace(tm,"$target",Getattr(p,"lname"),DOH_REPLACE_ANY);
920
Printv(f->code,tm,"\n",0);
921
p = Getattr(p,"tmap:check:next");
927
/* Insert cleanup code */
928
for (i = 0, p = l; p; i++) {
929
if ((tm = Getattr(p,"tmap:freearg"))) {
930
Replace(tm,"$source",Getattr(p,"lname"),DOH_REPLACE_ANY);
931
Printv(cleanup,tm,"\n",0);
932
p = Getattr(p,"tmap:freearg:next");
938
/* Insert argument output code */
940
for (i=0,p = l; p;i++) {
941
if ((tm = Getattr(p,"tmap:argout"))) {
942
Replace(tm,"$source",Getattr(p,"lname"),DOH_REPLACE_ANY);
943
Replace(tm,"$input",Getattr(p,"lname"),DOH_REPLACE_ANY);
944
Replace(tm,"$target","return_value",DOH_REPLACE_ANY);
945
Replace(tm,"$result","return_value",DOH_REPLACE_ANY);
946
String *in = Getattr(p,"emit:input");
948
sprintf(temp,"_saved[%d]", num_saved);
949
Replace(tm,"$arg",temp, DOH_REPLACE_ANY);
950
Printf(f->code,"_saved[%d] = %s;\n", num_saved, in);
953
Printv(outarg,tm,"\n",0);
954
p = Getattr(p,"tmap:argout:next");
961
sprintf(temp, "_saved[%d]",num_saved);
962
Wrapper_add_localv(f,"_saved","zval *",temp,0);
965
/* emit function call*/
969
if((tm = Swig_typemap_lookup((char*)"out",d,iname,(char*)"result",(char*)"result",(char*)"return_value",0))) {
970
Replaceall(tm, "$input", "result");
971
Replaceall(tm, "$source", "result");
972
Replaceall(tm, "$target", "return_value");
973
Printf(f->code, "%s\n", tm);
975
if(SwigType_type(d) != T_VOID) {
976
switch(SwigType_type(d)) {
986
Printf(f->code,"RETURN_LONG((long)result);\n");
990
Printf(f->code,"RETURN_DOUBLE((double)result);\n");
993
Wrapper_add_local(f,"_ctemp","char ctemp[2]");
995
tab4, "ctemp[0] = result;\n",
996
tab4, "ctemp[1] = 0;\n",
997
tab4, "RETURN_STRING(ctemp, 1);\n", 0);
1000
SwigType_add_pointer(d);
1001
SwigType_remember(d);
1002
Printv(f->code, "SWIG_SetPointerZval(return_value, (void *)result, SWIGTYPE", SwigType_manglestr(d), ");\n", 0);
1003
SwigType_del_pointer(d);
1006
Printf(f->code,"RETURN_STRING(result, 1);\n");
1010
SwigType_remember(d);
1011
Printv(f->code, tab4, "SWIG_SetPointerZval(return_value, (void *)result, SWIGTYPE", SwigType_manglestr(d), ");\n", 0);
1014
Printf(stderr,"%s: Line %d, Unable to use return type %s in function %s.\n", input_file, line_number, SwigType_str(d,0), name);
1022
Printv(f->code,outarg,0);
1025
Printv(f->code,cleanup,0);
1027
if((tm = Swig_typemap_lookup((char*)"ret",d,iname,(char *)"result", (char*)"result",(char*)"",0))) {
1028
Printf(f->code,"%s\n", tm);
1031
Replaceall(f->code,"$cleanup",cleanup);
1032
Replaceall(f->code,"$symname",iname);
1034
Printf(f->code, "\nSwig_sync_php();\n");
1035
Printf(f->code, "\n}");
1037
Wrapper_print(f,s_wrappers);
1042
PHP4::variableWrapper(Node *n) {
1043
char *name = GetChar(n,"name");
1044
char *iname = GetChar(n,"sym:name");
1045
SwigType *t = Getattr(n,"type");
1049
flags |= PHP_READONLY;
1053
SwigType_remember(t);
1055
/* Write out initilization code */
1057
switch(SwigType_type(t)) {
1070
" MAKE_STD_ZVAL(z_var);\n"
1071
" z_var->type = IS_LONG;\n"
1072
" z_var->value.lval = %s;\n"
1073
" zend_hash_add(&EG(symbol_table), \"%s\", %d,"
1074
" (void *)&z_var, sizeof(zval *), NULL);\n"
1075
"}\n", name, name, strlen(name)+1);
1083
" MAKE_STD_ZVAL(z_var);\n"
1084
" z_var->type = IS_DOUBLE;\n"
1085
" z_var->value.dval = %s;\n"
1086
" zend_hash_add(&EG(symbol_table), \"%s\", %d,"
1087
" (void *)&z_var, sizeof(zval *), NULL);\n"
1088
"}\n", name, name, strlen(name)+1);
1096
" MAKE_STD_ZVAL(z_var);\n"
1099
" z_var->type = IS_STRING;\n"
1100
" z_var->value.str.val = estrdup(c);\n"
1101
" z_var->value.str.len = 2;\n"
1102
" zend_hash_add(&EG(symbol_table), \"%s\", %d,"
1103
" (void *)&z_var, sizeof(zval *), NULL);\n"
1104
"}\n", name, name, strlen(name)+1);
1111
" MAKE_STD_ZVAL(z_var);\n"
1112
" z_var->type = IS_STRING;\n"
1114
" z_var->value.str.val = estrdup(%s);\n"
1115
" z_var->value.str.len = strlen(%s)+1;\n"
1117
" z_var->value.str.val = 0;\n"
1118
" z_var->value.str.len = 0;\n"
1120
" zend_hash_add(&EG(symbol_table), \"%s\", %d,"
1121
" (void *)&z_var, sizeof(zval *), NULL);\n"
1122
"}\n", name, name, name, name, strlen(name)+1);
1127
SwigType_add_pointer(t);
1131
" MAKE_STD_ZVAL(z_var);\n"
1132
" SWIG_SetPointerZval(z_var, (void*)&%s, SWIGTYPE%s);\n"
1133
" zend_hash_add(&EG(symbol_table), \"%s\", %d, "
1134
" (void *)&z_var, sizeof(zval *), NULL);\n"
1135
"}\n", name, SwigType_manglestr(t), name, strlen(name)+1);
1136
SwigType_del_pointer(t);
1142
SwigType *ta = Copy(t);
1143
aop = SwigType_pop(ta);
1144
if(SwigType_type(ta) == T_CHAR) {
1145
String *dim = SwigType_array_getdim(aop, 0);
1149
" MAKE_STD_ZVAL(z_var);\n"
1150
" z_var->type = IS_STRING;\n"
1152
" z_var->value.str.val = estrndup(%s, %s);\n"
1153
" z_var->value.str.len = strlen(%s)+1;\n"
1155
" zend_hash_add(&EG(symbol_table), \"%s\", %d,"
1156
" (void *)&z_var, sizeof(zval *), NULL);\n"
1157
"}\n", name, name, Char(dim), name, name, strlen(name)+1);
1162
" MAKE_STD_ZVAL(z_var);\n"
1163
" SWIG_SetPointerZval(z_var, (void *)%s, SWIGTYPE%s);\n"
1164
" zend_hash_add(&EG(symbol_table), \"%s\", %d,"
1165
" (void *)&z_var, sizeof(zval *), NULL);\n"
1166
"}\n", name, SwigType_manglestr(t), name, strlen(name)+1);
1174
Printf(s_vinit, "{\n\tzval *z_var;\n");
1175
Printf(s_vinit, "\tMAKE_STD_ZVAL(z_var);\n");
1176
Printf(s_vinit, "\tSWIG_SetPointerZval(z_var, (void*)%s, SWIGTYPE%s);\n", name,SwigType_manglestr(t));
1177
Printf(s_vinit, "\tzend_hash_add(&EG(symbol_table), \"%s\", %d, (void *)&z_var, sizeof(zval *), NULL);\n}\n", name, strlen(name)+1);
1181
" MAKE_STD_ZVAL(z_var);\n"
1182
" SWIG_SetPointerZval(z_var, (void*)%s, SWIGTYPE%s);\n"
1183
" zend_hash_add(&EG(symbol_table), \"%s\", %d,"
1184
" (void *)&z_var, sizeof(zval *), NULL);\n"
1185
"}\n", name, SwigType_manglestr(t), name, strlen(name)+1);
1194
/* Now code to set php values */
1196
switch(SwigType_type(t)) {
1206
Wrapper_add_local(f_php, "z_var", "zval **z_var");
1207
Printf(f_php->code, "zend_hash_find(&EG(symbol_table), \"%s\", %d, (void **)&z_var);\n", name, strlen(name)+1);
1208
Printf(f_php->code, "if(%s != (%s)((*z_var)->value.lval)) {\n", name, SwigType_lstr(t, 0));
1209
Printf(f_php->code, "(*z_var)->value.lval = (long)%s;\n", name);
1210
Printf(f_php->code, "}\n");
1215
Wrapper_add_local(f_php, "z_var", "zval **z_var");
1216
Printf(f_php->code, "zend_hash_find(&EG(symbol_table), \"%s\", %d, (void **)&z_var);\n", name, strlen(name)+1);
1217
Printf(f_php->code, "if(%s != (%s)((*z_var)->value.dval)) {\n", name, SwigType_lstr(t, 0));
1218
Printf(f_php->code, "(*z_var)->value.dval = (double)%s;\n", name);
1219
Printf(f_php->code, "}\n");
1222
Wrapper_add_local(f_php, "z_var", "zval **z_var");
1223
Printf(f_php->code, "zend_hash_find(&EG(symbol_table), \"%s\", %d, (void **)&z_var);\n", name, strlen(name)+1);
1224
Printf(f_php->code, "if(%s != *((*z_var)->value.str.val)) {\n", name);
1225
Printf(f_php->code, "char c[2];\n");
1226
Printf(f_php->code, "efree((*z_var)->value.str.val);\n");
1227
Printf(f_php->code, "c[0] = %s;\n", name);
1228
Printf(f_php->code, "c[1] = 0;\n");
1229
Printf(f_php->code, "(*z_var)->value.str.val = estrdup(c);\n");
1230
Printf(f_php->code, "}\n");
1233
Wrapper_add_local(f_php, "z_var", "zval **z_var");
1234
Wrapper_add_local(f_php, "s1", "char *s1");
1235
Printf(f_php->code, "zend_hash_find(&EG(symbol_table), \"%s\", %d, (void **)&z_var);\n", name, strlen(name)+1);
1236
Printf(f_php->code, "s1 = Z_STRVAL_PP(z_var);\n");
1237
Printf(f_php->code, "if((s1 == NULL) || (%s == NULL) || zend_binary_strcmp(s1, strlen(s1), %s, strlen(%s) )) {\n", name, name, name);
1238
Printf(f_php->code, "if(s1)\n");
1239
Printf(f_php->code, "efree(s1);\n");
1240
Printf(f_php->code, "if(%s) {\n", name);
1241
Printf(f_php->code, "(*z_var)->value.str.val = estrdup(%s);\n", name);
1242
Printf(f_php->code, "(*z_var)->value.str.len = strlen(%s)+1;\n", name);
1243
Printf(f_php->code, "} else {\n");
1244
Printf(f_php->code, "(*z_var)->value.str.val = 0;\n");
1245
Printf(f_php->code, "(*z_var)->value.str.len = 0;\n");
1246
Printf(f_php->code, "}\n}\n");
1249
SwigType_add_pointer(t);
1250
Wrapper_add_local(f_php, "z_var", "zval **z_var");
1251
Printf(f_php->code, "{\nzend_hash_find(&EG(symbol_table), \"%s\", %d, (void **)&z_var);\n", name, strlen(name)+1);
1252
Printf(f_php->code, "SWIG_SetPointerZval(*z_var, (void*)&%s, SWIGTYPE%s);\n", name, SwigType_manglestr(t));
1253
Printf(f_php->code, "}\n");
1254
SwigType_del_pointer(t);
1260
SwigType *ta = Copy(t);
1261
aop = SwigType_pop(ta);
1262
if(SwigType_type(ta) == T_CHAR) {
1263
String *dim = SwigType_array_getdim(aop, 0);
1264
Wrapper_add_local(f_php, "z_var", "zval **z_var");
1265
Wrapper_add_local(f_php, "s1", "char *s1");
1266
Printf(f_php->code, "zend_hash_find(&EG(symbol_table), \"%s\", %d, (void **)&z_var);\n", name, strlen(name)+1);
1267
Printf(f_php->code, "s1 = Z_STRVAL_PP(z_var);\n");
1268
Printf(f_php->code, "if((s1 == NULL) || zend_binary_strcmp(s1, strlen(s1), %s, strlen(%s) )) {\n", name, name);
1269
Printf(f_php->code, "if(%s) {\n", name);
1270
Printf(f_php->code, "(*z_var)->value.str.val = estrdup(%s);\n", name);
1271
Printf(f_php->code, "(*z_var)->value.str.len = strlen(%s)+1;\n", name);
1272
Printf(f_php->code, "} else {\n");
1273
Printf(f_php->code, "(*z_var)->value.str.val = 0;\n");
1274
Printf(f_php->code, "(*z_var)->value.str.len = 0;\n");
1275
Printf(f_php->code, "}\n}\n");
1277
Wrapper_add_local(f_php, "z_var", "zval **z_var");
1278
Printf(f_php->code, "zend_hash_find(&EG(symbol_table), \"%s\", %d, (void **)&z_var);\n", name, strlen(name)+1);
1279
Printf(f_php->code, "if(%s) {\n", name);
1280
Printf(f_php->code, "SWIG_SetPointerZval(*z_var, (void*)%s, SWIGTYPE);\n", name, SwigType_manglestr(t));
1281
/* Arrays are not modified directly by PHP vars */
1289
Wrapper_add_local(f_php, "z_var", "zval **z_var");
1290
Printf(f_php->code, "zend_hash_find(&EG(symbol_table), \"%s\", %d, (void **)&z_var);\n", name, strlen(name)+1);
1291
Printf(f_php->code, "SWIG_SetPointerZval(*z_var, (void *)%s, SWIGTYPE%s);\n", name, SwigType_manglestr(t));
1298
/* Now code to set c values */
1300
if(!(flags & PHP_READONLY)) {
1302
switch(SwigType_type(t)) {
1312
Wrapper_add_local(f_c, "z_var", "zval **z_var");
1313
Printf(f_c->code, "zend_hash_find(&EG(symbol_table), \"%s\", %d, (void **)&z_var);\n", name, strlen(name)+1);
1314
Printf(f_c->code, "if(%s != (%s)((*z_var)->value.lval)) {\n", name, SwigType_lstr(t, 0));
1315
Printf(f_c->code, "%s = Z_LVAL_PP(z_var);\n", name);
1316
Printf(f_c->code, "}\n");
1320
Wrapper_add_local(f_c, "z_var", "zval **z_var");
1321
Printf(f_c->code, "zend_hash_find(&EG(symbol_table), \"%s\", %d, (void **)&z_var);\n", name, strlen(name)+1);
1322
Printf(f_c->code, "if(%s != (%s)((*z_var)->value.dval)) {\n", name, SwigType_lstr(t, 0));
1323
Printf(f_c->code, "%s = Z_DVAL_PP(z_var);\n", name);
1324
Printf(f_c->code, "\n}\n");
1327
Wrapper_add_local(f_c, "z_var", "zval **z_var");
1328
Printf(f_c->code, "zend_hash_find(&EG(symbol_table), \"%s\", %d, (void **)&z_var);\n", name, strlen(name)+1);
1329
Printf(f_c->code, "if(%s != *((*z_var)->value.str.val)) {\n", name);
1330
Printf(f_c->code, "%s = *((*z_var)->value.str.val);\n", name);
1331
Printf(f_c->code, "\n}\n");
1335
Wrapper_add_local(f_c, "z_var", "zval **z_var");
1336
Wrapper_add_local(f_c, "s1", "char *s1");
1337
Printf(f_c->code, "zend_hash_find(&EG(symbol_table), \"%s\", %d, (void **)&z_var);\n", name, strlen(name)+1);
1338
Printf(f_c->code, "s1 = Z_STRVAL_PP(z_var);\n");
1339
Printf(f_c->code, "if((s1 == NULL) || (%s == NULL) || zend_binary_strcmp(s1, strlen(s1), %s, strlen(%s) )) {\n", name, name, name);
1340
Printf(f_c->code, "if(s1)\n");
1341
Printf(f_c->code, "%s = estrdup(s1);\n", name, name);
1342
Printf(f_c->code, "else\n");
1343
Printf(f_c->code, "%s = NULL;\n", name);
1344
Printf(f_c->code, "}\n");
1348
SwigType_add_pointer(t);
1349
Wrapper_add_local(f_c, "z_var", "zval **z_var");
1350
Printf(f_c->code, "{\n %s _temp;\n", SwigType_lstr(t,0));
1351
Printf(f_c->code, "zend_hash_find(&EG(symbol_table), \"%s\", %d, (void **)&z_var);\n", name, strlen(name)+1);
1352
get_pointer(name, (char*)"value", (char*)"*z_var", (char*)"&_temp", t, f_c->code,(char*)"return");
1353
Printv(f_c->code, tab4, name, " = *(", SwigType_str(t,0), ") _temp;\n", 0);
1354
Printf(f_c->code,"}\n");
1355
SwigType_del_pointer(t);
1361
SwigType *ta = Copy(t);
1362
aop = SwigType_pop(ta);
1363
if(SwigType_type(ta) == T_CHAR) {
1364
String *dim = SwigType_array_getdim(aop, 0);
1365
Wrapper_add_local(f_c, "z_var", "zval **z_var");
1366
Wrapper_add_local(f_c, "s1", "char *s1");
1367
Printf(f_c->code, "zend_hash_find(&EG(symbol_table), \"%s\", %d, (void **)&z_var);\n", name, strlen(name)+1);
1368
Printf(f_c->code, "s1 = Z_STRVAL_PP(z_var);\n");
1369
Printf(f_c->code, "if((s1 == NULL) || (%s == NULL) || zend_binary_strcmp(s1, strlen(s1), %s, strlen(%s) )) {\n", name, name, name);
1370
Printf(f_c->code, "if(s1) {\n");
1371
Printf(f_c->code, "strncpy(%s, s1, %s);\n", name, Char(dim));
1372
Printf(f_c->code, "}\n}\n");
1374
Wrapper_add_local(f_c, "z_var", "zval **z_var");
1375
Printf(f_c->code, "zend_hash_find(&EG(symbol_table), \"%s\", %d, (void **)&z_var);\n", name, strlen(name)+1);
1376
Printf(f_c->code, "if(%s) {\n", name);
1377
Printf(f_c->code, "SWIG_SetPointerZval(*z_var, (void*)%s, SWIGTYPE%s);\n", name, SwigType_manglestr(t));
1378
Printf(f_c->code, "}\n");
1379
/* Arrays are not modified directly by PHP vars */
1387
Printf(f_c->code, "{\n");
1388
Printf(f_c->code, "%s _temp;\n", SwigType_lstr(t,0));
1389
Wrapper_add_local(f_c, "z_var", "zval **z_var");
1390
Printf(f_c->code, "zend_hash_find(&EG(symbol_table), \"%s\", %d, (void **)&z_var);\n", name, strlen(name)+1);
1391
get_pointer(name, (char*)"value", (char*)"*(z_var)", (char*)"&_temp", t,f_c->code, (char*)"return");
1392
Printv(f_c->code, tab4, name, " = (", SwigType_str(t,0), ") _temp;\n", 0);
1393
Printf(f_c->code, "}\n");
1404
PHP4::constantWrapper(Node *n) {
1405
char *name = GetChar(n,"name");
1406
char *iname = GetChar(n,"sym:name");
1407
SwigType *type = Getattr(n,"type");
1408
char *value = GetChar(n,"value");
1412
SwigType_remember(type);
1414
switch(SwigType_type(type)) {
1416
rval = NewStringf("\"%s\"", value);
1419
rval = NewStringf("\'%s\'", value);
1422
rval = NewString(value);
1425
if((tm = Swig_typemap_lookup_new("consttab", n, name, 0))) {
1426
Replaceall(tm, "$source", value);
1427
Replaceall(tm, "$target", name);
1428
Replaceall(tm, "$value", value);
1429
Printf(s_cinit, "%s\n", tm);
1431
switch(SwigType_type(type)) {
1438
" REGISTER_LONG_CONSTANT(\"%s\", %s, CONST_CS);\n",
1444
" REGISTER_DOUBLE_CONSTANT(\"%s\", %s, CONST_CS);\n",
1453
" REGISTER_STRING_CONSTANT(\"%s\", estrdup(c),"
1454
" CONST_CS | CONST_PERSISTENT);\n"
1459
" REGISTER_STRING_CONSTANT(\"%s\", %s,"
1460
" CONST_CS | CONST_PERSISTENT);\n", name, rval);
1468
" SWIG_SetPointerChar(&cp, (void*)%s, SWIGTYPE%s);\n"
1469
" REGISTER_STRING_CONSTANT(\"%s\", cp,"
1470
" CONST_CS | CONST_PERSISTENT);\n"
1471
"}\n", value, SwigType_manglestr(type), name);
1485
* %pragma(php4) code="String" # Includes a string in the .php file
1486
* %pragma(php4) include="file.pl" # Includes a file in the .php file
1488
void PHP4::pragma(char *lang, char *type, char *value) {
1489
if (strcmp(lang,"php4") != 0) return;
1491
if (strcmp(type, "code") == 0) {
1493
Printf(pragma_code, "%s\n", value);
1494
} else if (strcmp(type, "include") == 0) {
1496
Printf(pragma_incl, "include \"%s\";\n", value);
1497
} else if (strcmp(type, "phpinfo") == 0) {
1499
Printf(pragma_phpinfo, "%s\n", value);
1501
Printf(stderr, "%s : Line %d. Unrecognized pragma.\n",
1502
input_file, line_number);
1508
PHP4::usage_func(char *iname, SwigType *, ParmList *l) {
1515
PHP4::add_native(char *name, char *funcname, SwigType *, ParmList *) {
1520
PHP4::emit_shadow_classdef() {
1521
String *baseclass = NULL;
1523
// Include Base class definition
1526
if(this_shadow_baseclass && *Char(this_shadow_baseclass))
1527
Printf(shadow_classdef,
1528
"include(\"%s.php\");\n",
1529
this_shadow_baseclass);
1532
// Import statements
1533
if(all_shadow_import)
1534
Printf(shadow_classdef, "%s", all_shadow_import);
1535
if(this_shadow_import)
1536
Printf(shadow_classdef, "%s", this_shadow_import);
1537
Printf(shadow_classdef, "\n");
1539
// Class modifiers XXX not in php
1541
Printf(shadow_classdef, "class $class ");
1543
// Inherited classes
1544
if(this_shadow_baseclass && *Char(this_shadow_baseclass)) {
1545
Printf(shadow_classdef, "extends %s ", this_shadow_baseclass);
1546
baseclass = this_shadow_baseclass;
1548
if(all_shadow_baseclass && *Char(all_shadow_baseclass)) {
1549
Printf(shadow_classdef, "extends %s ", all_shadow_baseclass);
1550
baseclass = all_shadow_baseclass;
1553
Printf(shadow_classdef, "{\n");
1555
// XXX No interfaces (?)
1557
// Display warning on attempt to use multiple inheritance
1559
char *search_str = Char(shadow_classdef);
1561
while((search_str = strstr(search_str, "extends"))) {
1562
search_str += strlen("extends");
1566
Printf(stderr, "Warning for shadow class %s: Multiple inheritance is not supported in PHP4.\n", shadow_classname);
1568
// Different code depending on whether or not the base class is a
1569
// SWIG shadow class.
1571
if(baseclass && is_shadow(baseclass)) {
1572
// Control which super constructor is called -
1573
// we don't want 2 malloc/new c/c++ calls
1577
Printv(shadow_classdef,
1579
" var $_cMemOwn;\n", 0);
1581
for(k = Firstkey(shadow_php_vars); k; k = Nextkey(shadow_php_vars)) {
1582
Printf(shadow_classdef, " var $%s;\n", Getattr(shadow_php_vars, k));
1585
Printv(shadow_classdef,
1587
" function getCPtr() {\n",
1588
" return $this->_cPtr;\n",
1591
" function setCPtr($cPtr, $own) {\n",
1592
" $this->_cPtr = $cPtr;\n",
1593
" $this->_cMemOwn = $own;\n",
1597
// No explicit super constructor call as this class does not
1598
// have a SWIG base class.
1601
Replace(shadow_classdef, "$class", shadow_classname, DOH_REPLACE_ANY);
1603
if(all_shadow_extra_code)
1604
Printv(shadow_classdef, all_shadow_extra_code, 0);
1606
if(this_shadow_extra_code)
1607
Printv(shadow_classdef, this_shadow_extra_code, 0);
1612
int PHP4::classHandler(Node *n) {
1616
if(class_name) free(class_name);
1617
class_name = Swig_copy_string(GetChar(n, "name"));
1620
char *classname = GetChar(n, "name");
1621
char *rename = GetChar(n, "sym:name");
1622
char *ctype = GetChar(n, "kind");
1624
shadow_classname = Swig_copy_string(rename);
1626
if(Strcmp(shadow_classname, module) == 0) {
1627
Printf(stderr, "class name cannot be equal to module name: %s\n", shadow_classname);
1631
Setattr(shadow_classes, classname, shadow_classname);
1633
if(ctype && strcmp(ctype, "struct") == 0) {
1634
sprintf(bigbuf, "struct %s", classname);
1635
Setattr(shadow_classes, bigbuf, shadow_classname);
1638
Clear(shadow_classdef);
1641
have_default_constructor = 0;
1642
shadow_enum_code = NewString("");
1643
this_shadow_baseclass = NewString("");
1644
this_shadow_extra_code = NewString("");
1645
this_shadow_import = NewString("");
1647
shadow_c_vars = NewHash();
1648
shadow_php_vars = NewHash();
1650
/* Deal with inheritance */
1651
List *baselist = Getattr(n, "bases");
1653
Node *base = Firstitem(baselist);
1655
if(is_shadow(Getattr(base, "name"))) {
1656
Printf(this_shadow_baseclass, "%s", Getattr(base, "name"));
1658
base = Nextitem(baselist);
1660
Printf(stderr, "Error: %s inherits from multiple base classes. Multiple inheritance is not supported by PHP4.\n", shadow_classname);
1662
} else { // XXX Must be base class ?
1663
/* Write out class init code */
1665
if(!written_base_class) {
1666
written_base_class = 1;
1667
Printf(s_oinit,"{\nzend_class_entry *ce;\n");
1668
Printf(s_oinit,"CG(class_entry).type = ZEND_USER_CLASS;\n");
1669
Printf(s_oinit, "CG(class_entry).name = estrdup(\"%s\");\n", package);
1670
Printf(s_oinit, "CG(class_entry).name_length = strlen(\"%s\");\n", package);
1671
Printf(s_oinit, "CG(class_entry).refcount = (int *) emalloc(sizeof(int));\n");
1672
Printf(s_oinit, "*CG(class_entry).refcount = 1;\n");
1673
Printf(s_oinit, "CG(class_entry).constants_updated = 0;\n");
1675
/* XXX do this ourselves */
1677
Printf(s_oinit, "zend_str_tolower(CG(class_entry).name, CG(class_entry).name_length);\n");
1679
/* Init class function hash */
1681
Printf(s_oinit, "zend_hash_init(&CG(class_entry).function_table, 10, NULL, ZEND_FUNCTION_DTOR, 0);\n");
1682
Printf(s_oinit, "zend_hash_init(&CG(class_entry).default_properties, 10, NULL, ZVAL_PTR_DTOR, 0);\n");
1684
/* XXX Handle inheritance ? */
1686
Printf(s_oinit, "CG(class_entry).handle_function_call = NULL;\n");
1687
Printf(s_oinit, "CG(class_entry).handle_property_set = NULL;\n");
1688
Printf(s_oinit, "CG(class_entry).handle_property_get = NULL;\n");
1690
/* Save class in class table */
1691
Printf(s_oinit, "zend_hash_update(CG(class_table), \"%s\", strlen(\"%s\")+1, &CG(class_entry), sizeof(zend_class_entry), (void **) &CG(active_class_entry));\n", package, package);
1693
Printf(s_oinit, "}\n");
1702
Language::classHandler(n);
1706
emit_shadow_classdef();
1708
Printv(f_phpcode, shadow_classdef, shadow_code, 0);
1710
// Write the enum initialisation code in a static block
1711
// These are all the enums defined withing the c++ class.
1713
// XXX Needed in PHP ?
1714
if(strlen(Char(shadow_enum_code)) != 0 )
1715
Printv(f_phpcode, "{\n // enum\n", shadow_enum_code, " }\n", 0);
1716
Printf(f_phpcode, "}\n");
1718
free(shadow_classname);
1719
shadow_classname = NULL;
1721
Delete(shadow_enum_code); shadow_enum_code = NULL;
1722
Delete(this_shadow_baseclass); this_shadow_baseclass = NULL;
1723
Delete(this_shadow_extra_code); this_shadow_extra_code = NULL;
1724
Delete(this_shadow_import); this_shadow_import = NULL;
1725
Delete(shadow_c_vars); shadow_c_vars = NULL;
1726
Delete(shadow_php_vars); shadow_php_vars = NULL;
1732
PHP4::memberfunctionHandler(Node *n) {
1733
char *name = GetChar(n, "name");
1734
char *iname = GetChar(n, "sym:name");
1735
SwigType *t = Getattr(n, "type");
1736
ParmList *l = Getattr(n, "parms");
1738
this->Language::memberfunctionHandler(n);
1741
char *realname = iname ? iname : name;
1742
String *php_function_name = Swig_name_member(shadow_classname, realname);
1744
cpp_func(iname, t, l, php_function_name);
1747
Printf(s_oinit, "{\nzend_function function;\n");
1748
Printf(s_oinit, "zend_internal_function *internal_function = (zend_internal_function *)&function;\n");
1749
Printf(s_oinit, "internal_function->type= ZEND_INTERNAL_FUNCTION;\n");
1750
Printf(s_oinit, "internal_function->handler = %s;\n", Swig_name_wrapper(iname));
1751
Printf(s_oinit, "internal_function->arg_types = NULL;\n");
1752
Printf(s_oinit, "internal_function->function_name = estrdup(\"%s\");\n", Swig_name_wrapper(iname));
1753
Printf(s_oinit, "zend_hash_add(&CG(active_class_entry)->function_table, \"%s\", %d, &function, sizeof(zend_function), NULL);\n}\n", Swig_name_wrapper(name), strlen(Char(Swig_name_wrapper(name)))+1);
1761
PHP4::membervariableHandler(Node *n) {
1762
char *name = GetChar(n,"name");
1763
char *iname = GetChar(n, "sym:name");
1764
SwigType *t = Getattr(n, "type");
1767
shadow_variable_name = Swig_copy_string((iname) ? iname : name);
1769
wrapping_member = 1;
1770
variable_wrapper_flag = 1;
1771
Language::membervariableHandler(n);
1772
wrapping_member = 0;
1773
variable_wrapper_flag = 0;
1778
int PHP4::staticmemberfunctionHandler(Node *n) {
1780
Language::staticmemberfunctionHandler(n);
1783
String *symname = Getattr(n, "sym:name");
1784
String *php_function_name = Swig_name_member(shadow_classname, symname);
1786
cpp_func(Char(symname), Getattr(n, "type"), Getattr(n, "parms"), php_function_name);
1793
int PHP4::staticmembervariableHandler(Node *n) {
1794
shadow_variable_name = GetChar(n, "sym:name");
1795
SwigType *d = Getattr(n, "type");
1796
ParmList *l = Getattr(n, "parms");
1797
char *iname = GetChar(n, "sym:name");
1798
String *static_name = NewStringf("%s::%s", class_name, iname);
1801
/* A temporary(!) hack for static member variables.
1802
* Php currently supports class functions, but not class variables.
1803
* Until it does, we convert a class variable to a class function
1804
* that returns the current value of the variable. E.g.
1808
* static int ncount;
1811
* would be available in php as Example::ncount()
1817
cpp_func(iname, d, 0, iname);
1820
create_command(iname, Char(Swig_name_wrapper(iname)));
1824
Printv(f->def, "ZEND_NAMED_FUNCTION(", Swig_name_wrapper(iname), ") {\n", 0);
1826
/* If a argument is given we set the variable. Then we return
1830
Printf(f->code, "zval **args[1];\n");
1831
Printf(f->code, "int argcount;\n\n");
1833
Printf(f->code, "argcount = ZEND_NUM_ARGS();\n");
1834
Printf(f->code, "if(argcount > %d) WRONG_PARAM_COUNT;\n\n", (const_flag? 0 : 1));
1836
Printf(f->code, "if(argcount) {\n");
1838
Printf(f->code, "if(zend_get_parameters_array_ex(argcount, args) != SUCCESS) WRONG_PARAM_COUNT;\n");
1840
switch(SwigType_type(d)) {
1850
Printf(f->code, "convert_to_long_ex(args[0]);\n");
1851
Printf(f->code, "%s::%s = Z_LVAL_PP(args[0]);\n", class_name, iname);
1854
Printf(f->code, "convert_to_string_ex(args[0]);\n");
1855
Printf(f->code, "%s::%s = estrdup(Z_STRVAL(args[0]));\n");
1859
Printf(f->code, "convert_to_double_ex(args[0]);\n");
1860
Printf(f->code, "%s::%s = Z_DVAL_PP(args[0]);\n", class_name, iname);
1865
Printf(f->code, "convert_to_string_ex(args[0]);\n");
1866
get_pointer(Char(iname), (char*)"variable", (char*)"args[0]", Char(static_name), d, f->code, (char *)"RETURN_FALSE");
1871
Printf(f->code, "convert_to_string_ex(args[0]);\n");
1872
get_pointer(Char(iname), (char*)"variable", (char*)"args[0]", Char(static_name), d, f->code, (char*)"RETURN_FALSE");
1875
Printf(stderr,"%s : Line %d, Unable to use type %s as a class variable.\n", input_file, line_number, SwigType_str(d,0));
1879
Printf(f->code, "}\n\n");
1881
} /* end of const_flag */
1883
switch(SwigType_type(d)) {
1893
Printf(f->code, "RETURN_LONG(%s::%s);\n", class_name, iname);
1897
Printf(f->code, "RETURN_DOUBLE(%s);\n", static_name);
1900
Printf(f->code, "{\nchar ctemp[2];\n");
1901
Printf(f->code, "ctemp[0] = %s;\n", static_name);
1902
Printf(f->code, "ctemp[1] = 0;\n");
1903
Printf(f->code, "RETURN_STRING(ctemp, 1);\n}\n");
1907
Printf(f->code, "SWIG_SetPointerZval(return_value, (void *)%s, SWIGTYPE%s);\n", static_name, SwigType_manglestr(d));
1910
Printf(f->code, "RETURN_STRING(%s, 1);\n", static_name);
1915
Printf(f->code, "}\n");
1919
Wrapper_print(f, s_wrappers);
1924
void PHP4::SwigToPhpType(SwigType *t, String_or_char *pname, String* php_type, int shadow_flag) {
1928
ptype = PhpTypeFromTypemap((char*)"pstype", t, pname,(char*)"");
1930
ptype = PhpTypeFromTypemap((char*)"ptype",t,pname,(char*)"");
1934
Printf(php_type, ptype);
1939
switch(SwigType_type(t)) {
1954
Printf(php_type, "");
1959
if(shadow_flag && is_shadow(t))
1960
Printf(php_type, Char(is_shadow(t)));
1962
Printf(php_type, "");
1968
Printf(stderr, "SwigToPhpType: unhandled data type: %s\n", SwigType_str(t,0));
1975
char *PHP4::PhpTypeFromTypemap(char *op, SwigType *t, String_or_char *pname, String_or_char *lname) {
1980
if(!(tms = Swig_typemap_lookup(op, t, pname, lname, (char*)"", (char*)"", NULL))) return NULL;
1983
while(*tm && (isspace(*tm) || *tm == '{')) tm++;
1984
while(*tm && *tm != '}') *c++ = *tm++;
1986
return Swig_copy_string(bigbuf);
1990
int PHP4::constructorHandler(Node *n) {
1992
char *iname = GetChar(n, "sym:name");
1993
ParmList *l = Getattr(n, "parms");
1995
Language::constructorHandler(n);
1998
String *nativecall = NewString("");
1999
String *php_function_name = NewString(iname);
2002
Printf(s_oinit, "{\nzend_function function;\n");
2003
Printf(s_oinit, "zend_internal_function *internal_function = (zend_internal_function *)&function;\n");
2004
Printf(s_oinit, "internal_function->type= ZEND_INTERNAL_FUNCTION;\n");
2005
Printf(s_oinit, "internal_function->handler = _wrap_new_%s;\n", iname);
2006
Printf(s_oinit, "internal_function->arg_types = NULL;\n");
2007
Printf(s_oinit, "internal_function->function_name = estrdup(\"new_%(lower)s\");\n", php_function_name);
2008
Printf(s_oinit, "zend_hash_add(&CG(active_class_entry)->function_table, \"new_%(lower)s\", %d, &function, sizeof(zend_function), NULL);\n}\n", php_function_name, strlen(Char(php_function_name))+5);
2009
Printf(shadow_code, " function %s(", shadow_classname);
2012
Printv(nativecall, tab4, "$this->_cPtr = ", package, "::", Swig_name_construct(iname), "(", 0);
2014
Printv(nativecall, tab4, "$this->_cPtr = ", module, "::", Swig_name_construct(shadow_classname), "(", 0);
2016
int pcount = ParmList_len(l);
2017
if(pcount == 0) // must have default constructor
2018
have_default_constructor = 1;
2020
/* Output each parameter */
2022
for (int i = 0; i < pcount ; i++, p = nextSibling(p)) {
2023
SwigType *pt = Getattr(p, "type");
2024
String *pn = Getattr(p, "name");
2026
/* Produce string representation of source and target arguments */
2028
if(pn && *(Char(pn)))
2029
strcpy(arg, Char(pn));
2031
sprintf(arg, "arg%d", i);
2035
Printv(nativecall, "$", arg, "->getCPtr()", 0);
2037
Printv(nativecall, "$", arg, 0);
2039
/* Add to php shadow function header */
2040
Printf(shadow_code, "$%s", arg);
2043
Printf(nativecall, ", ");
2044
Printf(shadow_code, ", ");
2048
Printf(shadow_code, ") {\n");
2049
Printv(nativecall, ");\n", tab4, "$this->_cMemOwn = true;\n", 0);
2050
/* register our shutdown function */
2052
Printv(nativecall, tab4,
2053
"register_shutdown_function(array(&$this,",
2054
"\"_destroy\"));\n", 0);
2056
/* Store new values in PHP */
2058
Printv(nativecall, tab4,
2059
"$this->_sync_php();\n", 0);
2062
Printf(shadow_code, "%s", nativecall);
2063
Printf(shadow_code, " }\n\n");
2069
int PHP4::destructorHandler(Node *n) {
2071
Language::destructorHandler(n);
2074
Printf(shadow_code, " function _destroy() {\n");
2075
Printf(shadow_code, " if($this->_cPtr && $this->_cMemOwn) {\n");
2076
Printf(shadow_code, " %s::%s($this->_cPtr);\n", package, Swig_name_destroy(shadow_classname));
2077
Printf(shadow_code, " $this->_cPtr = 0;\n");
2078
Printf(shadow_code, " }\n");
2079
Printf(shadow_code, " }\n\n");
2083
Printf(shadow_code," function _sync_c() {\n ");
2085
for(k = Firstkey(shadow_c_vars); k ; k = Nextkey(shadow_c_vars)) {
2086
Printf(shadow_code, "%s::%s($this->_cPtr, $this->%s);\n",
2088
Getattr(shadow_c_vars, k));
2091
Printf(shadow_code, "\n}\n");
2093
Printf(shadow_code," function _sync_php() {\n");
2095
for(k = Firstkey(shadow_php_vars);k;k = Nextkey(shadow_php_vars)) {
2096
Printf(shadow_code, "$this->%s = %s::%s($this->_cPtr);\n",
2097
Getattr(shadow_php_vars, k),
2101
Printf(shadow_code, "\n}\n");
2104
String *iname = Swig_name_destroy(GetChar(n, "sym:name"));
2106
Printf(s_oinit, "{\nzend_function function;\n");
2107
Printf(s_oinit, "zend_internal_function *internal_function = (zend_internal_function *)&function;\n");
2108
Printf(s_oinit, "internal_function->type= ZEND_INTERNAL_FUNCTION;\n");
2109
Printf(s_oinit, "internal_function->handler = %s;\n", Swig_name_wrapper(iname));
2110
Printf(s_oinit, "internal_function->arg_types = NULL;\n");
2111
Printf(s_oinit, "internal_function->function_name = estrdup(\"%(lower)s\");\n", iname);
2112
Printf(s_oinit, "zend_hash_add(&CG(active_class_entry)->function_table, \"%(lower)s\", %d, &function, sizeof(zend_function), NULL);\n}\n", iname, strlen(Char(iname))+1);
2118
PHP4::memberconstantHandler(Node *n) {
2119
shadow_variable_name = GetChar(n, "sym:name");
2120
wrapping_member = 1;
2121
Language::memberconstantHandler(n);
2122
wrapping_member = 0;
2127
PHP4::classforwardDeclaration(Node *n) {
2128
String *name = Getattr(n, "name");
2129
String *rename = Getattr(n, "sym:name");
2130
String *type = Getattr(n, "kind");
2134
stype = NewString(name);
2135
SwigType_add_pointer(stype);
2136
Setattr(shadow_classes, stype, rename);
2139
stype = NewStringf("%s %s", type, name);
2140
SwigType_add_pointer(stype);
2141
Setattr(shadow_classes, stype, rename);
2149
PHP4::typedefHandler(Node *n) {
2150
SwigType *t = Getattr(n, "type");
2151
String *name = Getattr(n, "name");
2152
if(!shadow) return SWIG_OK;
2154
Setattr(shadow_classes, name, is_shadow(t));
2160
PHP4::cpp_func(char *iname, SwigType *t, ParmList *l, String *php_function_name) {
2162
String *nativecall = NewString("");
2163
String *user_arrays = NewString("");
2170
if(SwigType_type(Getattr(l, "type")) == T_VOID) {
2176
Printf(s_oinit, "{\nzend_function function;\n");
2177
Printf(s_oinit, "zend_internal_function *internal_function = (zend_internal_function *)&function;\n");
2178
Printf(s_oinit, "internal_function->type= ZEND_INTERNAL_FUNCTION;\n");
2179
Printf(s_oinit, "internal_function->handler = %s;\n", Swig_name_wrapper(php_function_name));
2180
Printf(s_oinit, "internal_function->arg_types = NULL;\n");
2181
Printf(s_oinit, "internal_function->function_name = estrdup(\"%(lower)s\");\n", php_function_name);
2182
Printf(s_oinit, "zend_hash_add(&CG(active_class_entry)->function_table, \"%(lower)s\", %d, &function, sizeof(zend_function), NULL);\n}\n", php_function_name, strlen(Char(php_function_name))+1);
2184
Printf(shadow_code, "function %s(", iname);
2185
if(static_flag && !const_flag)
2186
Printf(shadow_code, "$val = 0");
2188
if(!no_sync && !static_flag)
2189
Printf(nativecall, "$this->_sync_c();\n\n");
2191
if((SwigType_type(t) != T_VOID) && !is_shadow(t)) {
2192
if(static_flag && !const_flag)
2193
Printf(nativecall, "if($val) {\n");
2194
Printf(nativecall, " return ");
2195
Printv(nativecall, package, "::", php_function_name, "(", 0);
2198
Printf(nativecall, "$val");
2200
Printv(nativecall, "$this->_cPtr", 0);
2202
} else if(SwigType_type(t) == T_VOID) {
2203
if(static_flag && !const_flag)
2204
Printf(nativecall, " if($val) {\n");
2205
Printv(nativecall," ", package, "::",php_function_name,"(",0);
2206
Printv(nativecall, "$this->_cPtr", 0);
2207
} else if(is_shadow(t)) {
2208
if(SwigType_type(t) == T_ARRAY) {
2209
Printf(nativecall, " return %s::%s($this->_cPtr",
2210
package, php_function_name);
2212
String *shadowrettype = NewString("");
2213
SwigToPhpType(t, iname, shadowrettype, shadow);
2214
Printf(nativecall, " $_sPtr = new %s();\n", shadowrettype);
2215
Printf(nativecall, " $_sPtr->_destroy();\n");
2216
Printf(nativecall, " $_iPtr = %s::%s($this->_cPtr",
2217
package, php_function_name);
2223
int pcount = ParmList_len(l);
2225
/* Output each parameter */
2229
/* Workaround to overcome Getignore(p) not working - p does not always
2230
* have the Getignore attribute set. Noticeable when cpp_func is called
2231
* from cpp_member_func()
2234
Wrapper *f = NewWrapper();
2235
emit_args(NULL, l, f);
2240
for(int i= 0; i < pcount; i++, p = nextSibling(p)) {
2241
if(Getattr(p, "ignore")) continue;
2243
if(!(variable_wrapper_flag && i==0))
2245
SwigType *pt = Getattr(p, "type");
2246
String *pn = Getattr(p, "name");
2248
/* Produce string repesentation of source and target arguments */
2250
if(pn && *(Char(pn)))
2251
strcpy(arg, Char(pn));
2253
sprintf(arg, "arg%d", i);
2256
Printf(nativecall, ", ");
2259
Printf(shadow_code, ",");
2264
Printv(nativecall, "$", arg, "->getCPtr()", 0);
2266
Printv(nativecall, "$", arg, 0);
2269
/* Add to php shadow function header */
2271
Printf(shadow_code, "$%s", arg);
2276
if(SwigType_type(t) == T_ARRAY && is_shadow(get_array_type(t))) {
2277
Printf(nativecall, ");\n");
2278
} else if(is_shadow(t)) {
2279
switch(SwigType_type(t)) {
2281
Printf(nativecall, ");\n");
2283
" $_sPtr->setCPtr($_iPtr, true);\n");
2284
Printf(nativecall, " return $_sPtr;\n");
2288
Printf(nativecall, ");\n");
2290
" $_sPtr->setCPtr($_iPtr, false);\n");
2291
Printf(nativecall, " return $_sPtr;\n");
2294
Printf(stderr, "Internal Error: unknown shadow_type: %\n", SwigType_str(t,0));
2298
Printf(nativecall,");\n");
2299
if(static_flag && !const_flag) {
2300
Printf(nativecall, " } else {\n");
2301
Printv(nativecall, " return ", package, "::",
2302
php_function_name, "();\n",0);
2306
if(static_flag &&!const_flag)
2307
Printf(nativecall, "}\n");
2309
Printf(shadow_code, ") {\n");
2310
Printf(shadow_code, " %s", nativecall);
2311
if(!no_sync && !static_flag)
2312
Printf(shadow_code, " $this->_sync_php();\n");
2313
Printf(shadow_code, " }\n\n");