43
47
* set by the %module directive, e.g. "Xerces". It will determine
44
* the name of the .pm file, and the dynamic library.
48
* the name of the .pm file, and the dynamic library, and the name
49
* used by any module wanting to %import the module.
46
51
static String *module = 0;
50
* the fully namespace qualified name of the module, e.g. "XML::Xerces"
51
* it will be used to set the package namespace in the .pm file, as
52
* well as the name of the initialization methods in the glue library
55
* the fully namespace qualified name of the module. It will be used
56
* to set the package namespace in the .pm file, as well as the name
57
* of the initialization methods in the glue library. This will be
58
* the same as module, above, unless the %module directive is given
59
* the 'package' option, e.g. %module(package="Foo::Bar") "baz"
54
static String *fullmodule = 0;
61
static String *namespace_module = 0;
57
65
* the namespace of the internal glue code, set to the value of
237
258
Printf(f_runtime, "#define SWIG_CASTRANK_MODE\n");
240
module = Copy(Getattr(n, "name"));
261
// Is the imported module in another package? (IOW, does it use the
262
// %module(package="name") option and it's different than the package
264
Node *mod = Getattr(n, "module");
265
Node *options = Getattr(mod, "options");
266
module = Copy(Getattr(n,"name"));
269
fprintf(stdout, "top: using module: %s\n", Char(module));
272
dest_package = options ? Getattr(options, "package") : 0;
274
namespace_module = Copy(dest_package);
276
fprintf(stdout, "top: Found package: %s\n",Char(dest_package));
279
namespace_module = Copy(module);
281
fprintf(stdout, "top: No package found\n");
284
String *underscore_module = Copy(module);
285
Replaceall(underscore_module,":","_");
288
fprintf(stdout, "top: using namespace_module: %s\n", Char(namespace_module));
242
291
/* If we're in blessed mode, change the package name to "packagec" */
245
cmodule = NewStringf("%sc", module);
294
cmodule = NewStringf("%sc",namespace_module);
247
cmodule = NewString(module);
296
cmodule = NewString(namespace_module);
249
fullmodule = NewString(module);
251
299
/* Create a .pm file
252
300
* Need to strip off any prefixes that might be found in
375
428
Printf(f_pm, "package %s;\n", cmodule);
378
Printf(f_pm, "bootstrap %s;\n", fullmodule);
431
Printf(f_pm,"bootstrap %s;\n", module);
380
String *tmp = NewString(fullmodule);
381
Replaceall(tmp, ":", "_");
382
Printf(f_pm, "boot_%s();\n", tmp);
385
Printf(f_pm, "package %s;\n", fullmodule);
386
Printf(f_pm, "@EXPORT = qw( %s);\n", exported);
433
Printf(f_pm,"package %s;\n", cmodule);
434
Printf(f_pm,"boot_%s();\n", underscore_module);
437
Printf(f_pm, "package %s;\n", module);
439
* If the package option has been given we are placing our
440
* symbols into some other packages namespace, so we do not
444
Printf(f_pm,"@EXPORT = qw(%s);\n", exported);
387
447
Printf(f_pm, "%s", pragma_include);
391
Printv(base, "\n# ---------- BASE METHODS -------------\n\n", "package ", fullmodule, ";\n\n", NIL);
393
/* Write out the TIE method */
395
Printv(base, "sub TIEHASH {\n", tab4, "my ($classname,$obj) = @_;\n", tab4, "return bless $obj, $classname;\n", "}\n\n", NIL);
397
/* Output a CLEAR method. This is just a place-holder, but by providing it we
398
* can make declarations such as
399
* %$u = ( x => 2, y=>3, z =>4 );
401
* Where x,y,z are the members of some C/C++ object. */
403
Printf(base, "sub CLEAR { }\n\n");
405
/* Output default firstkey/nextkey methods */
407
Printf(base, "sub FIRSTKEY { }\n\n");
408
Printf(base, "sub NEXTKEY { }\n\n");
410
/* Output a FETCH method. This is actually common to all classes */
413
tab4, "my ($self,$field) = @_;\n", tab4, "my $member_func = \"swig_${field}_get\";\n", tab4, "$self->$member_func();\n", "}\n\n", NIL);
415
/* Output a STORE method. This is also common to all classes (might move to base class) */
419
tab4, "my ($self,$field,$newval) = @_;\n",
420
tab4, "my $member_func = \"swig_${field}_set\";\n", tab4, "$self->$member_func($newval);\n", "}\n\n", NIL);
422
/* Output a 'this' method */
424
Printv(base, "sub this {\n", tab4, "my $ptr = shift;\n", tab4, "return tied(%$ptr);\n", "}\n\n", NIL);
426
Printf(f_pm, "%s", base);
452
* These methods will be duplicated if package
453
* has been specified, so we do not output them
456
Printv(base, "\n# ---------- BASE METHODS -------------\n\n", "package ", namespace_module, ";\n\n", NIL);
458
/* Write out the TIE method */
460
Printv(base, "sub TIEHASH {\n", tab4, "my ($classname,$obj) = @_;\n", tab4, "return bless $obj, $classname;\n", "}\n\n", NIL);
462
/* Output a CLEAR method. This is just a place-holder, but by providing it we
463
* can make declarations such as
464
* %$u = ( x => 2, y=>3, z =>4 );
466
* Where x,y,z are the members of some C/C++ object. */
468
Printf(base, "sub CLEAR { }\n\n");
470
/* Output default firstkey/nextkey methods */
472
Printf(base, "sub FIRSTKEY { }\n\n");
473
Printf(base, "sub NEXTKEY { }\n\n");
475
/* Output a FETCH method. This is actually common to all classes */
478
tab4, "my ($self,$field) = @_;\n", tab4, "my $member_func = \"swig_${field}_get\";\n", tab4, "$self->$member_func();\n", "}\n\n", NIL);
480
/* Output a STORE method. This is also common to all classes (might move to base class) */
484
tab4, "my ($self,$field,$newval) = @_;\n",
485
tab4, "my $member_func = \"swig_${field}_set\";\n", tab4, "$self->$member_func($newval);\n", "}\n\n", NIL);
487
/* Output a 'this' method */
489
Printv(base, "sub this {\n", tab4, "my $ptr = shift;\n", tab4, "return tied(%$ptr);\n", "}\n\n", NIL);
491
Printf(f_pm, "%s", base);
428
494
/* Emit function stubs for stand-alone functions */
430
495
Printf(f_pm, "\n# ------- FUNCTION WRAPPERS --------\n\n");
431
Printf(f_pm, "package %s;\n\n", fullmodule);
496
Printf(f_pm, "package %s;\n\n", namespace_module);
432
497
Printf(f_pm, "%s", func_stubs);
434
499
/* Emit package code for different classes */
787
856
Printv(setf->code, tab4, "MAGIC_PPERL\n", NIL);
789
858
/* Check for a few typemaps */
790
tm = Swig_typemap_lookup_new("varin", n, name, 0);
859
tm = Swig_typemap_lookup("varin", n, name, 0);
792
861
Replaceall(tm, "$source", "sv");
793
862
Replaceall(tm, "$target", name);
794
863
Replaceall(tm, "$input", "sv");
795
864
/* Printf(setf->code,"%s\n", tm); */
796
emit_action_code(n, setf, tm);
865
emit_action_code(n, setf->code, tm);
798
867
Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number, "Unable to set variable of type %s.\n", SwigType_str(t, 0));
799
868
return SWIG_NOWRAP;
1073
1142
/* Do some work on the class name */
1074
actualpackage = Getattr(clsmodule, "name");
1075
if ((!compat) && (!Strchr(symname, ':'))) {
1076
fullname = NewStringf("%s::%s", actualpackage, symname);
1144
fprintf(stdout, "setclassname: Found sym:name: %s\n", Char(symname));
1145
fprintf(stdout, "setclassname: Found module: %s\n", Char(clsmodule));
1146
fprintf(stdout, "setclassname: No package found\n");
1150
fullname = NewStringf("%s::%s", namespace_module, symname);
1078
fullname = NewString(symname);
1152
actualpackage = Getattr(clsmodule,"name");
1155
fprintf(stdout, "setclassname: Found actualpackage: %s\n", Char(actualpackage));
1157
if ((!compat) && (!Strchr(symname,':'))) {
1158
fullname = NewStringf("%s::%s",actualpackage,symname);
1160
fullname = NewString(symname);
1164
fprintf(stdout, "setclassname: setting proxy: %s\n", Char(fullname));
1080
1166
Setattr(n, "perl5:proxy", fullname);