swig/Source/Swig/cwrap.c
Jamie Kirkpatrick 825e67b2b0 Merged revisions 10487,10498-10499,10503-10504,10506,10508,10511,10515-10516,10518-10519,10527,10530-10531,10536-10537,10539-10552,10558-10568,10574-10580,10582,10584,10588-10589,10594,10607-10610,10616,10621,10624-10629,10633-10641,10643,10647,10649-10650,10662,10672,10676-10677,10682-10683,10714,10726-10727,10738,10743,10747,10749,10794,10801-10809,10827-10831,10834 via svnmerge from
https://swig.svn.sourceforge.net/svnroot/swig/trunk

................
  r10487 | wsfulton | 2008-05-21 23:15:52 +0100 (Wed, 21 May 2008) | 1 line
  
  Apply patch from Petr Viktorin to fix some recent regressions in CFFI/CLOS
................
  r10498 | talby | 2008-05-26 21:09:56 +0100 (Mon, 26 May 2008) | 2 lines
  
  run test cases in the Perl set by the --with-perl5 configure option.
................
  r10499 | talby | 2008-05-26 22:04:06 +0100 (Mon, 26 May 2008) | 3 lines
  
  The perl5 minherit runtime test will work better if the classes are 
  actually built under SWIGPERL.
................
  r10503 | wsfulton | 2008-05-28 10:44:37 +0100 (Wed, 28 May 2008) | 1 line
  
  Fix variable wrappers when using -proxy. Patch from Jan Jezabek
................
  r10504 | bhy | 2008-05-28 18:27:48 +0100 (Wed, 28 May 2008) | 2 lines
  
  Fixed SF #1971977:  typo in pycontainer.swg (related to -extranative option)
................
  r10506 | wsfulton | 2008-05-29 01:45:28 +0100 (Thu, 29 May 2008) | 1 line
  
  Fix variable wrappers when using -noproxy
................
  r10508 | bhy | 2008-05-30 14:53:33 +0100 (Fri, 30 May 2008) | 1 line
  
  Fixed SF #1976978, apply the macros for primitive types to std::wstring
................
  r10511 | olly | 2008-05-30 17:11:27 +0100 (Fri, 30 May 2008) | 4 lines
  
  Fix typo in handling of /*@SWIG[...]*/ comments in the scanner.  This just
  meant we were only actually looking for /*@SWI at the start of the comment, so
  was pretty harmless in practice.
................
  r10515 | wsfulton | 2008-06-02 21:10:40 +0100 (Mon, 02 Jun 2008) | 1 line
  
  Fix samename testcase for c# and java
................
  r10516 | wsfulton | 2008-06-02 21:15:39 +0100 (Mon, 02 Jun 2008) | 1 line
  
  Fix enums when using -noproxy
................
  r10518 | bhy | 2008-06-07 12:20:07 +0100 (Sat, 07 Jun 2008) | 4 lines
  
  Added a test case for keyword renaming.
  Now it works for Python in SWIG's -c++ mode,
  but in C mode it doesn't work! (you can try with make keyword_rename.ctest)
................
  r10519 | bhy | 2008-06-07 14:40:51 +0100 (Sat, 07 Jun 2008) | 1 line
  
  fixed keyword_rename.ctest tese case, caused by a mistake in Swig/naming.c
................
  r10527 | mgossage | 2008-06-17 03:57:15 +0100 (Tue, 17 Jun 2008) | 1 line
  
  [lua] bugfix 1938142 (bool& and bool* support)
................
  r10530 | wsfulton | 2008-06-19 21:02:13 +0100 (Thu, 19 Jun 2008) | 1 line
  
  Add R keyword support. Rename keywords for successful compilation of Java and C# code. More consistent keyword warnings across the different languages.
................
  r10531 | wsfulton | 2008-06-19 22:15:48 +0100 (Thu, 19 Jun 2008) | 1 line
  
  add complete list of R reserved words
................
  r10536 | wsfulton | 2008-06-21 12:35:33 +0100 (Sat, 21 Jun 2008) | 1 line
  
  better terminology for static types
................
  r10537 | wsfulton | 2008-06-21 12:42:48 +0100 (Sat, 21 Jun 2008) | 1 line
  
  remove raise as keyword test- it conflicts with _raise in LIBCMT on windows
................
  r10539 | wsfulton | 2008-06-21 16:21:29 +0100 (Sat, 21 Jun 2008) | 1 line
  
  Lua example warning removal fixes for vc++
................
  r10540 | wsfulton | 2008-06-21 16:23:02 +0100 (Sat, 21 Jun 2008) | 1 line
  
  Remove some vc++ /W4 warnings
................
  r10541 | wsfulton | 2008-06-21 17:04:55 +0100 (Sat, 21 Jun 2008) | 1 line
  
  minor vc++ /W4 warning fixes
................
  r10542 | wsfulton | 2008-06-21 20:07:51 +0100 (Sat, 21 Jun 2008) | 1 line
  
  'byte' is already used in Ruby on windows, so use another keyword
................
  r10543 | wsfulton | 2008-06-21 21:45:32 +0100 (Sat, 21 Jun 2008) | 1 line
  
  Fix crashing in the Ruby reject method in the STL wrappers
................
  r10544 | wsfulton | 2008-06-21 21:48:28 +0100 (Sat, 21 Jun 2008) | 1 line
  
  Fix crashing in the Ruby reject method in the STL wrappers
................
  r10545 | wsfulton | 2008-06-21 21:49:10 +0100 (Sat, 21 Jun 2008) | 1 line
  
  remove unnecessary variable int the char **STRING_ARRAY out typemap
................
  r10546 | wsfulton | 2008-06-21 22:07:49 +0100 (Sat, 21 Jun 2008) | 1 line
  
  Fix Ruby C++ example dependencies in dsp files
................
  r10547 | wsfulton | 2008-06-21 23:25:36 +0100 (Sat, 21 Jun 2008) | 1 line
  
  Fix unused parameter warnings in python when using gcc's -W -Wall options
................
  r10548 | wsfulton | 2008-06-21 23:26:35 +0100 (Sat, 21 Jun 2008) | 1 line
  
  Fix virtual destructor
................
  r10549 | wsfulton | 2008-06-22 00:25:20 +0100 (Sun, 22 Jun 2008) | 1 line
  
  various warning fixes
................
  r10550 | wsfulton | 2008-06-22 01:09:11 +0100 (Sun, 22 Jun 2008) | 1 line
  
  Another fix for the JVM hanging on exit problem when using directors
................
  r10551 | wsfulton | 2008-06-22 01:09:51 +0100 (Sun, 22 Jun 2008) | 1 line
  
  documentation sections update
................
  r10552 | wsfulton | 2008-06-22 01:18:10 +0100 (Sun, 22 Jun 2008) | 1 line
  
  more docs on defining macros for the thread hanging problem
................
  r10558 | wsfulton | 2008-06-22 22:30:20 +0100 (Sun, 22 Jun 2008) | 1 line
  
  fix unused parms in last commit for C code
................
  r10559 | wsfulton | 2008-06-22 23:12:43 +0100 (Sun, 22 Jun 2008) | 1 line
  
  Suppress unused methods warning for VC++
................
  r10560 | wsfulton | 2008-06-23 21:26:07 +0100 (Mon, 23 Jun 2008) | 1 line
  
  fix partialcheck-test-suite and parallel make for r, chicken, tcl and php
................
  r10561 | wsfulton | 2008-06-23 21:39:41 +0100 (Mon, 23 Jun 2008) | 1 line
  
  correct message display when running the partialcheck-test-suite make target
................
  r10562 | wsfulton | 2008-06-23 22:14:53 +0100 (Mon, 23 Jun 2008) | 1 line
  
  fix typo
................
  r10563 | olly | 2008-06-23 22:23:54 +0100 (Mon, 23 Jun 2008) | 3 lines
  
  Fix bad use of Python API (untested, since I can't even compile this code on
  x86-64!)
................
  r10564 | olly | 2008-06-23 23:58:03 +0100 (Mon, 23 Jun 2008) | 3 lines
  
  [PHP] Fix segfault when wrapping a non-class function marked with
  %newobject (testcase char_strings).
................
  r10565 | olly | 2008-06-24 01:27:34 +0100 (Tue, 24 Jun 2008) | 3 lines
  
  [PHP] Fix assertion failure when handling %typemap(in,numinputs=0)
  (testcase ignore_parameter).
................
  r10566 | olly | 2008-06-24 01:33:08 +0100 (Tue, 24 Jun 2008) | 2 lines
  
  [PHP] Fix typemap_namespace.i to not try to copy a non-existent typemap.
................
  r10567 | olly | 2008-06-24 01:41:07 +0100 (Tue, 24 Jun 2008) | 3 lines
  
  Clean up dead and unused code in SwigToPhpType(), and rename to
  GetShadowReturnType().
................
  r10568 | olly | 2008-06-24 01:42:29 +0100 (Tue, 24 Jun 2008) | 2 lines
  
  Fix cosmetic typo in string constant.
................
  r10574 | wsfulton | 2008-06-24 21:10:28 +0100 (Tue, 24 Jun 2008) | 1 line
  
  zap last entry
................
  r10575 | wsfulton | 2008-06-24 21:11:46 +0100 (Tue, 24 Jun 2008) | 1 line
  
  variable name changes to remove php keywords
................
  r10576 | wsfulton | 2008-06-24 21:12:08 +0100 (Tue, 24 Jun 2008) | 1 line
  
  variable name hiding fix
................
  r10577 | wsfulton | 2008-06-24 21:12:43 +0100 (Tue, 24 Jun 2008) | 1 line
  
  More info about numobjects added
................
  r10578 | wsfulton | 2008-06-24 21:13:41 +0100 (Tue, 24 Jun 2008) | 1 line
  
  update for 1.3.36 release
................
  r10579 | wsfulton | 2008-06-24 22:48:46 +0100 (Tue, 24 Jun 2008) | 1 line
  
  remove deprecated -c commandline option (runtime library generation)
................
  r10580 | wsfulton | 2008-06-24 22:53:12 +0100 (Tue, 24 Jun 2008) | 1 line
  
  correct comment about deprecated option
................
  r10582 | wsfulton | 2008-06-25 00:00:27 +0100 (Wed, 25 Jun 2008) | 1 line
  
  use rsync and ssh to upload releases to SourceForge as ftp no longer works
................
  r10584 | wsfulton | 2008-06-25 00:24:48 +0100 (Wed, 25 Jun 2008) | 1 line
  
  correction for 1.3.36
................
  r10588 | wsfulton | 2008-06-25 01:16:04 +0100 (Wed, 25 Jun 2008) | 1 line
  
  section update
................
  r10589 | wsfulton | 2008-06-25 01:16:40 +0100 (Wed, 25 Jun 2008) | 1 line
  
  bump version to 1.3.37
................
  r10594 | wsfulton | 2008-06-26 19:33:06 +0100 (Thu, 26 Jun 2008) | 1 line
  
  correct typo in first entry about %fragment
................
  r10607 | wsfulton | 2008-06-29 01:19:05 +0100 (Sun, 29 Jun 2008) | 1 line
  
  fix some potential null pointer usage as reported by CoveriCoverity Prevent
................
  r10608 | wsfulton | 2008-06-29 01:50:27 +0100 (Sun, 29 Jun 2008) | 1 line
  
  fix potential null pointer usage as reported by Coverity Prevent
................
  r10609 | wsfulton | 2008-06-29 10:57:41 +0100 (Sun, 29 Jun 2008) | 1 line
  
  make life easier for svn status updates as everyone has different autotool versions installed - use svn:ignore on config.sub and config.guess
................
  r10610 | wsfulton | 2008-06-29 11:08:14 +0100 (Sun, 29 Jun 2008) | 1 line
  
  make life easier for svn status updates as everyone has different autotool versions installed - use svn:ignore on config.sub and config.guess
................
  r10616 | talby | 2008-07-01 00:41:27 +0100 (Tue, 01 Jul 2008) | 2 lines
  
  Hopefully this provides more portable values for Infinity and NaN in Perl.
................
  r10621 | wsfulton | 2008-07-01 23:02:14 +0100 (Tue, 01 Jul 2008) | 1 line
  
  update old commandline option
................
  r10624 | olly | 2008-07-02 04:17:46 +0100 (Wed, 02 Jul 2008) | 5 lines
  
  [Python] Import the C extension differently for Python 2.6 and
  later so that an implicit relative import doesn't produce a
  deprecation warning for 2.6 and a failure for 2.7 and later.
  Patch from Richard Boulton in SF#2008229.
................
  r10625 | bhy | 2008-07-02 05:56:11 +0100 (Wed, 02 Jul 2008) | 1 line
  
  fix the relative import patch by try both relative and absolute import
................
  r10626 | olly | 2008-07-02 06:55:18 +0100 (Wed, 02 Jul 2008) | 4 lines
  
  [PHP4] Support for PHP4 has been removed.  The PHP developers are
  no longer making new PHP4 releases, and won't even be patching
  critical security issues after 2008-08-08.
................
  r10627 | bhy | 2008-07-02 07:06:56 +0100 (Wed, 02 Jul 2008) | 1 line
  
  fix the previous commit -- new approach using imp module
................
  r10628 | bhy | 2008-07-02 07:29:15 +0100 (Wed, 02 Jul 2008) | 1 line
  
  minor fix on relative import: close fp if exception occured during imp.find_module
................
  r10629 | bhy | 2008-07-02 08:08:00 +0100 (Wed, 02 Jul 2008) | 1 line
  
  reconstruct the relative import, now the generated code looks better
................
  r10633 | olly | 2008-07-03 01:09:56 +0100 (Thu, 03 Jul 2008) | 9 lines
  
  WARN_* constants are user visible, so keep existing WARN_PHP4_* for
  backward compatibility, but add preferred forms WARN_PHP_* and use
  these ourselves.
  
  Rename Lib/php4 to Lib/php, Source/Modules/php4.cxx to Source/Modules/php.cxx.
   
  Add typemaps for const reference so Examples/test-suite/apply_signed_char.i
  works.
................
  r10634 | olly | 2008-07-03 01:12:58 +0100 (Thu, 03 Jul 2008) | 2 lines
  
  Remove file added in error.
................
  r10635 | olly | 2008-07-03 01:37:38 +0100 (Thu, 03 Jul 2008) | 2 lines
  
  Rename php4*.swg to php*.swg.
................
  r10636 | olly | 2008-07-03 02:13:51 +0100 (Thu, 03 Jul 2008) | 2 lines
  
  Update wrt PHP4.
................
  r10637 | olly | 2008-07-03 03:32:11 +0100 (Thu, 03 Jul 2008) | 4 lines
  
  [PHP] The deprecated command line option "-phpfull" has been
  removed.  We recommend building your extension as a dynamically
  loadable module.
................
  r10638 | olly | 2008-07-03 03:32:41 +0100 (Thu, 03 Jul 2008) | 2 lines
  
  Fix version number
................
  r10639 | olly | 2008-07-03 07:04:24 +0100 (Thu, 03 Jul 2008) | 2 lines
  
  Make t_output_helper() static.
................
  r10640 | olly | 2008-07-03 07:05:34 +0100 (Thu, 03 Jul 2008) | 2 lines
  
  Make testcase li_typemaps work for PHP.
................
  r10641 | olly | 2008-07-03 10:12:16 +0100 (Thu, 03 Jul 2008) | 2 lines
  
  Fix check::classname() to compare case-insensitively and not try to interpolate objects into strings.
................
  r10643 | olly | 2008-07-03 23:00:01 +0100 (Thu, 03 Jul 2008) | 4 lines
  
  The operator& trick in allowexcept.i doesn't work for SWIG/PHP because the
  generated code takes the address of the variable in the code in the "vinit"
  section.  So comment out the private operator& for PHP.
................
  r10647 | olly | 2008-07-04 00:55:33 +0100 (Fri, 04 Jul 2008) | 2 lines
  
  [PHP] The SWIG cdata.i library module is now supported.
................
  r10649 | olly | 2008-07-04 02:02:22 +0100 (Fri, 04 Jul 2008) | 4 lines
  
  [PHP] The deprecated command line option "-make" has been removed.  
  Searches on Google codesearch suggest that nobody is using it now
  anyway.
................
  r10650 | olly | 2008-07-04 02:22:11 +0100 (Fri, 04 Jul 2008) | 4 lines
  
  [PHP] For std_vector.i and std_map.i, rename empty() to is_empty()
  since "empty" is a PHP reserved word.  Based of patch from Mark Klein
  in SF#1943417.
................
  r10662 | wsfulton | 2008-07-14 22:09:23 +0100 (Mon, 14 Jul 2008) | 1 line
  
  Fix director typemaps for pointers so that NULL pointers are correctly marshalled to C#/Java null in director methods
................
  r10672 | olly | 2008-07-17 02:17:08 +0100 (Thu, 17 Jul 2008) | 2 lines
  
  Fix a typo; improve wording.
................
  r10676 | wsfulton | 2008-07-17 22:05:49 +0100 (Thu, 17 Jul 2008) | 1 line
  
  SF #2019156 Configuring with --without-octave or --without-alllang did not disable octave.
................
  r10677 | wsfulton | 2008-07-17 22:08:22 +0100 (Thu, 17 Jul 2008) | 1 line
  
  tidy output after detecting X11 headers
................
  r10682 | wsfulton | 2008-07-19 19:08:06 +0100 (Sat, 19 Jul 2008) | 1 line
  
  a bit more on pgcpp
................
  r10683 | wsfulton | 2008-07-19 23:45:54 +0100 (Sat, 19 Jul 2008) | 1 line
  
  Fix building of Tcl examples/test-suite on Mac OSX
................
  r10714 | olly | 2008-07-27 13:51:16 +0100 (Sun, 27 Jul 2008) | 2 lines
  
  Fix "can can" typo in docs (SF#2026756)
................
  r10726 | wuzzeb | 2008-08-02 09:28:02 +0100 (Sat, 02 Aug 2008) | 1 line
  
  Commit patch 2019314
................
  r10727 | wuzzeb | 2008-08-02 09:49:43 +0100 (Sat, 02 Aug 2008) | 1 line
  
  add assert.h to fix chicken build of external runtime (ext_test testsuite)
................
  r10738 | talby | 2008-08-07 07:28:13 +0100 (Thu, 07 Aug 2008) | 2 lines
  
  hoist globals to local scope where trival.
................
  r10743 | talby | 2008-08-08 04:10:55 +0100 (Fri, 08 Aug 2008) | 2 lines
  
  initial steps to clean up perl5 class methods (primarily constructors).
................
  r10747 | talby | 2008-08-09 05:08:26 +0100 (Sat, 09 Aug 2008) | 2 lines
  
  moves perl space constructor fixups into wrapper code.
................
  r10749 | talby | 2008-08-10 00:57:55 +0100 (Sun, 10 Aug 2008) | 2 lines
  
  usage_func() fix + CHANGES.current entry to explain my past few commits.
................
  r10794 | talby | 2008-08-19 08:09:29 +0100 (Tue, 19 Aug 2008) | 3 lines
  
  rollback 10737:10749, this work is better left on a branch until it is 
  in support a significant feature enhancement.
................
  r10801 | drjoe | 2008-08-31 17:07:43 +0100 (Sun, 31 Aug 2008) | 2 lines
  
  change Rf_warning to warning.  Looks like a typo
................
  r10802 | wsfulton | 2008-09-01 20:59:23 +0100 (Mon, 01 Sep 2008) | 1 line
  
  Fix ruby detection problem breaking configure
................
  r10803 | wsfulton | 2008-09-01 21:00:28 +0100 (Mon, 01 Sep 2008) | 1 line
  
  Fix another perl global namespace pollution
................
  r10804 | wsfulton | 2008-09-01 21:32:53 +0100 (Mon, 01 Sep 2008) | 1 line
  
  Fix array bounds checking in C# std::vector wrappers
................
  r10805 | wsfulton | 2008-09-01 21:34:49 +0100 (Mon, 01 Sep 2008) | 1 line
  
  fix runtime problem in Ruby std_vector example
................
  r10806 | wsfulton | 2008-09-01 21:42:40 +0100 (Mon, 01 Sep 2008) | 1 line
  
  Fix portability problem using /dev/null
................
  r10807 | wsfulton | 2008-09-01 22:46:41 +0100 (Mon, 01 Sep 2008) | 1 line
  
  patch #2079381 submitted by Boris Smilga - constant exprs put into no-eval context in DEFCENUM
................
  r10808 | wsfulton | 2008-09-02 21:56:52 +0100 (Tue, 02 Sep 2008) | 1 line
  
  Add new terminator attribute for the csin typemap for C#
................
  r10809 | wsfulton | 2008-09-03 00:01:37 +0100 (Wed, 03 Sep 2008) | 1 line
  
  Fix #1988296 - Multiple module director linking issue
................
  r10827 | richardb | 2008-09-10 11:08:21 +0100 (Wed, 10 Sep 2008) | 6 lines
  
  [Python] Commit patch #2089149: Director exception handling mangles
  returned exception.  Exceptions raised by Python code in directors
  are now passed through to the caller without change.  Also, remove
  the ": " prefix which used to be added to other director exceptions
  (eg, those due to incorrect return types).
................
  r10828 | bhy | 2008-09-10 11:45:33 +0100 (Wed, 10 Sep 2008) | 3 lines
  
  Initialized merge tracking via "svnmerge" with revisions "1-10827" from 
  https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-bhy
................
  r10829 | bhy | 2008-09-10 12:04:09 +0100 (Wed, 10 Sep 2008) | 4 lines
  
  Removed merge tracking for "svnmerge" for 
  https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-bhy
  (Undo the init due to user error)
................
  r10830 | bhy | 2008-09-10 12:08:16 +0100 (Wed, 10 Sep 2008) | 3 lines
  
  Initialized merge tracking via "svnmerge" with revisions "1-10403" from 
  https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-bhy
................
  r10831 | bhy | 2008-09-10 12:51:12 +0100 (Wed, 10 Sep 2008) | 11 lines
  
  (Still trying to set right properity to get svnmerge work...)
  Recorded merge of revisions 10404 via svnmerge from 
  https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-bhy
  
  ........
    r10404 | bhy | 2008-05-01 08:35:49 +0800 (Thu, 01 May 2008) | 5 lines
    
    Start of gsoc2008-bhy branch. This is a branch for Haoyu Bai's Python 3.0 backend project.
    Some file already modified since a little of work already done when starting the branch. 
  ........
................
  r10834 | bhy | 2008-09-11 18:18:07 +0100 (Thu, 11 Sep 2008) | 8 lines
  
  Merged the Python 3.0 support branch. The merging progress is not so smooth, so hope this commit won't make anything broken.
  
  This is the (incomplemete) log produced by svnmerge.py:
  
  Merged revisions 10405-10409,10420-10422,10426,10438,10445,10451,10454-10465,10467,10473-10475,10485,10488-10489,10493-10495,10497,10509-10510,10513-10514,10517,10520,10525,10528-10529,10533-10535,10554-10557,10570,10573,10593,10614,10666-10669,10673,10678,10687,10690,10704-10706,10731,10744,10750-10752,10755,10759,10770,10775-10776,10813,10819 via svnmerge from 
  https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-bhy
................


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-cherylfoil@10837 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2008-09-12 10:51:51 +00:00

1467 lines
43 KiB
C

/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* cwrap.c
*
* This file defines a variety of wrapping rules for C/C++ handling including
* the naming of local variables, calling conventions, and so forth.
* ----------------------------------------------------------------------------- */
char cvsroot_cwrap_c[] = "$Id$";
#include "swig.h"
extern int cparse_cplusplus;
static Parm *nonvoid_parms(Parm *p) {
if (p) {
SwigType *t = Getattr(p, "type");
if (SwigType_type(t) == T_VOID)
return 0;
}
return p;
}
/* -----------------------------------------------------------------------------
* Swig_parm_name()
*
* Generates a name for the ith argument in an argument list
* ----------------------------------------------------------------------------- */
String *Swig_cparm_name(Parm *p, int i) {
String *name = NewStringf("arg%d", i + 1);
if (p) {
Setattr(p, "lname", name);
}
return name;
}
/* -----------------------------------------------------------------------------
* Swig_clocal()
*
* Creates a string that declares a C local variable type. Converts references
* and user defined types to pointers.
* ----------------------------------------------------------------------------- */
static String *Swig_clocal(SwigType *t, const String_or_char *name, const String_or_char *value) {
String *decl;
decl = NewStringEmpty();
switch (SwigType_type(t)) {
case T_REFERENCE:
if (value) {
String *lstrname = SwigType_lstr(t, name);
String *lstr = SwigType_lstr(t, 0);
Printf(decl, "%s = (%s) &%s_defvalue", lstrname, lstr, name);
Delete(lstrname);
Delete(lstr);
} else {
String *lstrname = SwigType_lstr(t, name);
Printf(decl, "%s = 0", lstrname);
Delete(lstrname);
}
break;
case T_VOID:
break;
case T_VARARGS:
Printf(decl, "void *%s = 0", name);
break;
default:
if (value) {
String *lcaststr = SwigType_lcaststr(t, value);
String *lstr = SwigType_lstr(t, 0);
String *lstrn = SwigType_lstr(t, name);
Printf(decl, "%s = (%s) %s", lstrn, lstr, lcaststr);
Delete(lcaststr);
Delete(lstr);
Delete(lstrn);
} else {
String *lstrname = SwigType_lstr(t, name);
Append(decl, lstrname);
Delete(lstrname);
}
}
return decl;
}
/* -----------------------------------------------------------------------------
* Swig_wrapped_var_convert()
*
* Converts a member variable for use in the get and set wrapper methods.
* This function only converts user defined types to pointers.
* ----------------------------------------------------------------------------- */
String *Swig_wrapped_var_type(SwigType *t, int varcref) {
SwigType *ty;
if (!Strstr(t, "enum $unnamed")) {
ty = Copy(t);
} else {
/* Change the type for unnamed enum instance variables */
ty = NewString("int");
}
if (SwigType_isclass(t)) {
if (varcref) {
if (cparse_cplusplus) {
if (!SwigType_isconst(ty))
SwigType_add_qualifier(ty, "const");
SwigType_add_reference(ty);
} else {
return Copy(ty);
}
} else {
SwigType_add_pointer(ty);
}
}
return ty;
}
String *Swig_wrapped_member_var_type(SwigType *t, int varcref) {
SwigType *ty;
if (!Strstr(t, "enum $unnamed")) {
ty = Copy(t);
} else {
/* Change the type for unnamed enum instance variables */
ty = NewString("int");
}
if (SwigType_isclass(t)) {
if (varcref) {
if (cparse_cplusplus) {
if (!SwigType_isconst(ty))
SwigType_add_qualifier(ty, "const");
SwigType_add_reference(ty);
} else {
return Copy(ty);
}
} else {
SwigType_add_pointer(ty);
}
}
return ty;
}
static String *Swig_wrapped_var_deref(SwigType *t, String_or_char *name, int varcref) {
if (SwigType_isclass(t)) {
if (varcref) {
if (cparse_cplusplus) {
return NewStringf("*%s", name);
} else {
return NewStringf("%s", name);
}
} else {
return NewStringf("*%s", name);
}
} else {
return SwigType_rcaststr(t, name);
}
}
static String *Swig_wrapped_var_assign(SwigType *t, const String_or_char *name, int varcref) {
if (SwigType_isclass(t)) {
if (varcref) {
return NewStringf("%s", name);
} else {
return NewStringf("&%s", name);
}
} else {
return SwigType_lcaststr(t, name);
}
}
/* -----------------------------------------------------------------------------
* Swig_cargs()
*
* Emit all of the local variables for a list of parameters. Returns the
* number of parameters.
* Default values for the local variables are only emitted if the compact default
* argument behaviour is required.
* ----------------------------------------------------------------------------- */
int Swig_cargs(Wrapper *w, ParmList *p) {
int i = 0;
int compactdefargs = ParmList_is_compactdefargs(p);
while (p != 0) {
String *lname = Swig_cparm_name(p, i);
SwigType *pt = Getattr(p, "type");
if ((SwigType_type(pt) != T_VOID)) {
String *local = 0;
String *type = Getattr(p, "type");
/* default values only emitted if in compact default args mode */
String *pvalue = (compactdefargs) ? Getattr(p, "value") : 0;
SwigType *altty = SwigType_alttype(type, 0);
int tycode = SwigType_type(type);
if (tycode == T_REFERENCE) {
if (pvalue) {
SwigType *tvalue;
String *defname, *defvalue, *rvalue, *qvalue;
rvalue = SwigType_typedef_resolve_all(pvalue);
qvalue = SwigType_typedef_qualified(rvalue);
defname = NewStringf("%s_defvalue", lname);
tvalue = Copy(type);
SwigType_del_reference(tvalue);
tycode = SwigType_type(tvalue);
if (tycode != T_USER) {
/* plain primitive type, we copy the the def value */
String *lstr = SwigType_lstr(tvalue, defname);
defvalue = NewStringf("%s = %s", lstr, qvalue);
Delete(lstr);
} else {
/* user type, we copy the reference value */
String *str = SwigType_str(type, defname);
defvalue = NewStringf("%s = %s", str, qvalue);
Delete(str);
}
Wrapper_add_localv(w, defname, defvalue, NIL);
Delete(tvalue);
Delete(rvalue);
Delete(qvalue);
Delete(defname);
Delete(defvalue);
}
} else if (!pvalue && ((tycode == T_POINTER) || (tycode == T_STRING))) {
pvalue = (String *) "0";
}
if (!altty) {
local = Swig_clocal(pt, lname, pvalue);
} else {
local = Swig_clocal(altty, lname, pvalue);
Delete(altty);
}
Wrapper_add_localv(w, lname, local, NIL);
Delete(local);
i++;
}
Delete(lname);
p = nextSibling(p);
}
return (i);
}
/* -----------------------------------------------------------------------------
* Swig_cresult()
*
* This function generates the C code needed to set the result of a C
* function call.
* ----------------------------------------------------------------------------- */
String *Swig_cresult(SwigType *t, const String_or_char *name, const String_or_char *decl) {
String *fcall;
fcall = NewStringEmpty();
switch (SwigType_type(t)) {
case T_VOID:
break;
case T_REFERENCE:
{
String *str = SwigType_str(t, "_result_ref");
Printf(fcall, "{\n");
Printf(fcall, "%s = ", str);
Delete(str);
}
break;
case T_USER:
Printf(fcall, "%s = ", name);
break;
default:
/* Normal return value */
{
String *lstr = SwigType_lstr(t, 0);
Printf(fcall, "%s = (%s)", name, lstr);
Delete(lstr);
}
break;
}
/* Now print out function call */
Append(fcall, decl);
/* A sick hack */
{
char *c = Char(decl) + Len(decl) - 1;
if (!((*c == ';') || (*c == '}')))
Append(fcall, ";");
}
if (SwigType_type(t) == T_REFERENCE) {
String *lstr = SwigType_lstr(t, 0);
Printf(fcall, "\n%s = (%s) &_result_ref;\n", name, lstr);
Append(fcall, "}");
Delete(lstr);
}
return fcall;
}
/* -----------------------------------------------------------------------------
* Swig_cfunction_call()
*
* Creates a string that calls a C function using the local variable rules
* defined above.
*
* name(arg0, arg1, arg2, ... argn)
*
* ----------------------------------------------------------------------------- */
String *Swig_cfunction_call(String_or_char *name, ParmList *parms) {
String *func;
int i = 0;
int comma = 0;
Parm *p = parms;
String *nname;
func = NewStringEmpty();
nname = SwigType_namestr(name);
/*
SWIGTEMPLATEDISAMBIGUATOR is compiler dependent (swiglabels.swg),
- SUN Studio 9 requires 'template',
- gcc-3.4 forbids the use of 'template'.
the rest seems not caring very much,
*/
if (SwigType_istemplate(name)) {
String *prefix = Swig_scopename_prefix(nname);
if (!prefix || Len(prefix) == 0) {
Printf(func, "%s(", nname);
} else {
String *last = Swig_scopename_last(nname);
Printf(func, "%s::SWIGTEMPLATEDISAMBIGUATOR %s(", prefix, last);
Delete(last);
}
Delete(prefix);
} else {
Printf(func, "%s(", nname);
}
Delete(nname);
while (p) {
SwigType *pt = Getattr(p, "type");
if ((SwigType_type(pt) != T_VOID)) {
SwigType *rpt = SwigType_typedef_resolve_all(pt);
String *pname = Swig_cparm_name(p, i);
String *rcaststr = SwigType_rcaststr(rpt, pname);
if (comma) {
Printv(func, ",", rcaststr, NIL);
} else {
Append(func, rcaststr);
}
Delete(rpt);
Delete(pname);
Delete(rcaststr);
comma = 1;
i++;
}
p = nextSibling(p);
}
Append(func, ")");
return func;
}
/* -----------------------------------------------------------------------------
* Swig_cmethod_call()
*
* Generates a string that calls a C++ method from a list of parameters.
*
* arg0->name(arg1, arg2, arg3, ..., argn)
*
* self is an argument that defines how to handle the first argument. Normally,
* it should be set to "this->". With C++ proxy classes enabled, it could be
* set to "(*this)->" or some similar sequence.
* ----------------------------------------------------------------------------- */
static String *Swig_cmethod_call(String_or_char *name, ParmList *parms, String_or_char *self, String *explicit_qualifier, SwigType *director_type) {
String *func, *nname;
int i = 0;
Parm *p = parms;
SwigType *pt;
int comma = 0;
func = NewStringEmpty();
if (!p)
return func;
if (!self)
self = (char *) "(this)->";
Append(func, self);
if (SwigType_istemplate(name) && (strncmp(Char(name), "operator ", 9) == 0)) {
/* fix for template + operators and compilers like gcc 3.3.5 */
String *tprefix = SwigType_templateprefix(name);
nname = tprefix;
} else {
nname = SwigType_namestr(name);
}
if (director_type) {
const char *pname = "darg";
String *rcaststr = SwigType_rcaststr(director_type, pname);
Replaceall(func, "this", rcaststr);
Delete(rcaststr);
} else {
pt = Getattr(p, "type");
/* If the method is invoked through a dereferenced pointer, we don't add any casts
(needed for smart pointers). Otherwise, we cast to the appropriate type */
if (Strstr(func, "*this")) {
String *pname = Swig_cparm_name(p, 0);
Replaceall(func, "this", pname);
Delete(pname);
} else {
String *pname = Swig_cparm_name(p, 0);
String *rcaststr = SwigType_rcaststr(pt, pname);
Replaceall(func, "this", rcaststr);
Delete(rcaststr);
Delete(pname);
}
/*
SWIGTEMPLATEDESIMBUAGATOR is compiler dependent (swiglabels.swg),
- SUN Studio 9 requires 'template',
- gcc-3.4 forbids the use of 'template' (correctly implementing the ISO C++ standard)
the others don't seem to care,
*/
if (SwigType_istemplate(name))
Printf(func, "SWIGTEMPLATEDISAMBIGUATOR ");
if (explicit_qualifier) {
Printv(func, explicit_qualifier, "::", NIL);
}
}
Printf(func, "%s(", nname);
i++;
p = nextSibling(p);
while (p) {
pt = Getattr(p, "type");
if ((SwigType_type(pt) != T_VOID)) {
String *pname = Swig_cparm_name(p, i);
String *rcaststr = SwigType_rcaststr(pt, pname);
if (comma)
Append(func, ",");
Append(func, rcaststr);
Delete(rcaststr);
Delete(pname);
comma = 1;
i++;
}
p = nextSibling(p);
}
Append(func, ")");
Delete(nname);
return func;
}
/* -----------------------------------------------------------------------------
* Swig_cconstructor_call()
*
* Creates a string that calls a C constructor function.
*
* calloc(1,sizeof(name));
* ----------------------------------------------------------------------------- */
String *Swig_cconstructor_call(String_or_char *name) {
DOH *func;
func = NewStringEmpty();
Printf(func, "calloc(1, sizeof(%s))", name);
return func;
}
/* -----------------------------------------------------------------------------
* Swig_cppconstructor_call()
*
* Creates a string that calls a C function using the local variable rules
* defined above.
*
* name(arg0, arg1, arg2, ... argn)
*
* ----------------------------------------------------------------------------- */
String *Swig_cppconstructor_base_call(String_or_char *name, ParmList *parms, int skip_self) {
String *func;
String *nname;
int i = 0;
int comma = 0;
Parm *p = parms;
SwigType *pt;
if (skip_self) {
if (p)
p = nextSibling(p);
i++;
}
nname = SwigType_namestr(name);
func = NewStringEmpty();
Printf(func, "new %s(", nname);
while (p) {
pt = Getattr(p, "type");
if ((SwigType_type(pt) != T_VOID)) {
String *rcaststr = 0;
String *pname = 0;
if (comma)
Append(func, ",");
if (!Getattr(p, "arg:byname")) {
pname = Swig_cparm_name(p, i);
i++;
} else {
pname = Getattr(p, "value");
if (pname)
pname = Copy(pname);
else
pname = Copy(Getattr(p, "name"));
}
rcaststr = SwigType_rcaststr(pt, pname);
Append(func, rcaststr);
Delete(rcaststr);
comma = 1;
Delete(pname);
}
p = nextSibling(p);
}
Append(func, ")");
Delete(nname);
return func;
}
String *Swig_cppconstructor_call(String_or_char *name, ParmList *parms) {
return Swig_cppconstructor_base_call(name, parms, 0);
}
String *Swig_cppconstructor_nodirector_call(String_or_char *name, ParmList *parms) {
return Swig_cppconstructor_base_call(name, parms, 1);
}
String *Swig_cppconstructor_director_call(String_or_char *name, ParmList *parms) {
return Swig_cppconstructor_base_call(name, parms, 0);
}
/* -----------------------------------------------------------------------------
* Swig_rflag_search()
*
* This function searches for the class attribute 'attr' in the class
* 'n' or recursively in its bases.
*
* If you define SWIG_FAST_REC_SEARCH, the method will set the found
* 'attr' in the target class 'n'. If not, the method will set the
* 'noattr' one. This prevents of having to navigate the entire
* hierarchy tree everytime, so, it is an O(1) method... or something
* like that. However, it populates all the parsed classes with the
* 'attr' and/or 'noattr' attributes.
*
* If you undefine the SWIG_FAST_REC_SEARCH no attribute will be set
* while searching. This could be slower for large projects with very
* large hierarchy trees... or maybe not. But it will be cleaner.
*
* Maybe later a swig option can be added to switch at runtime.
*
* ----------------------------------------------------------------------------- */
/* #define SWIG_FAST_REC_SEARCH 1 */
String *Swig_rflag_search(Node *n, const String *attr, const String *noattr) {
String *f = 0;
n = Swig_methodclass(n);
if (GetFlag(n, noattr)) {
return 0;
}
f = GetFlagAttr(n, attr);
if (f) {
return f;
} else {
List *bl = Getattr(n, "bases");
if (bl) {
Iterator bi;
for (bi = First(bl); bi.item; bi = Next(bi)) {
f = Swig_rflag_search(bi.item, attr, noattr);
if (f) {
#ifdef SWIG_FAST_REC_SEARCH
SetFlagAttr(n, attr, f);
#endif
return f;
}
}
}
}
#ifdef SWIG_FAST_REC_SEARCH
SetFlag(n, noattr);
#endif
return 0;
}
/* -----------------------------------------------------------------------------
* Swig_unref_call()
*
* find the unref call, if any.
* ----------------------------------------------------------------------------- */
String *Swig_unref_call(Node *n) {
Node *cn = Swig_methodclass(n);
String *unref = Swig_rflag_search(cn, "feature:unref", "feature:nounref");
if (unref) {
String *pname = Swig_cparm_name(0, 0);
unref = NewString(unref);
Replaceall(unref, "$this", pname);
Replaceall(unref, "$self", pname);
Delete(pname);
}
return unref;
}
/* -----------------------------------------------------------------------------
* Swig_ref_call()
*
* find the ref call, if any.
* ----------------------------------------------------------------------------- */
String *Swig_ref_call(Node *n, const String *lname) {
Node *cn = Swig_methodclass(n);
String *ref = Swig_rflag_search(cn, "feature:ref", "feature:noref");
if (ref) {
ref = NewString(ref);
Replaceall(ref, "$this", lname);
Replaceall(ref, "$self", lname);
}
return ref;
}
/* -----------------------------------------------------------------------------
* Swig_cdestructor_call()
*
* Creates a string that calls a C destructor function.
*
* free((char *) arg0);
* ----------------------------------------------------------------------------- */
String *Swig_cdestructor_call(Node *n) {
String *unref = Swig_unref_call(n);
if (unref) {
return unref;
} else {
String *pname = Swig_cparm_name(0, 0);
String *call = NewStringf("free((char *) %s);", pname);
Delete(pname);
return call;
}
}
/* -----------------------------------------------------------------------------
* Swig_cppdestructor_call()
*
* Creates a string that calls a C destructor function.
*
* delete arg1;
* ----------------------------------------------------------------------------- */
String *Swig_cppdestructor_call(Node *n) {
String *unref = Swig_unref_call(n);
if (unref) {
return unref;
} else {
String *pname = Swig_cparm_name(0, 0);
String *call = NewStringf("delete %s;", pname);
Delete(pname);
return call;
}
}
/* -----------------------------------------------------------------------------
* Swig_cmemberset_call()
*
* Generates a string that sets the name of a member in a C++ class or C struct.
*
* arg0->name = arg1
*
* ----------------------------------------------------------------------------- */
String *Swig_cmemberset_call(String_or_char *name, SwigType *type, String_or_char *self, int varcref) {
String *func;
String *pname0 = Swig_cparm_name(0, 0);
String *pname1 = Swig_cparm_name(0, 1);
func = NewStringEmpty();
if (!self)
self = NewString("(this)->");
else
self = NewString(self);
Replaceall(self, "this", pname0);
if (SwigType_type(type) != T_ARRAY) {
if (!Strstr(type, "enum $unnamed")) {
String *dref = Swig_wrapped_var_deref(type, pname1, varcref);
Printf(func, "if (%s) %s%s = %s", pname0, self, name, dref);
Delete(dref);
} else {
Printf(func, "if (%s && sizeof(int) == sizeof(%s%s)) *(int*)(void*)&(%s%s) = %s", pname0, self, name, self, name, pname1);
}
}
Delete(self);
Delete(pname0);
Delete(pname1);
return (func);
}
/* -----------------------------------------------------------------------------
* Swig_cmemberget_call()
*
* Generates a string that sets the name of a member in a C++ class or C struct.
*
* arg0->name
*
* ----------------------------------------------------------------------------- */
String *Swig_cmemberget_call(const String_or_char *name, SwigType *t, String_or_char *self, int varcref) {
String *func;
String *call;
String *pname0 = Swig_cparm_name(0, 0);
if (!self)
self = NewString("(this)->");
else
self = NewString(self);
Replaceall(self, "this", pname0);
func = NewStringEmpty();
call = Swig_wrapped_var_assign(t, "", varcref);
Printf(func, "%s (%s%s)", call, self, name);
Delete(self);
Delete(call);
Delete(pname0);
return func;
}
/* -----------------------------------------------------------------------------
* extension_code()
*
* Generates an extension function (a function defined in %extend)
*
* return_type function_name(parms) code
*
* ----------------------------------------------------------------------------- */
static String *extension_code(const String *function_name, ParmList *parms, SwigType *return_type, const String *code, int cplusplus, const String *self) {
String *parms_str = cplusplus ? ParmList_str_defaultargs(parms) : ParmList_str(parms);
String *sig = NewStringf("%s(%s)", function_name, parms_str);
String *rt_sig = SwigType_str(return_type, sig);
String *body = NewStringf("SWIGINTERN %s", rt_sig);
Printv(body, code, "\n", NIL);
if (self)
Replaceall(body, "$self", self);
Delete(parms_str);
Delete(sig);
Delete(rt_sig);
return body;
}
/* -----------------------------------------------------------------------------
* Swig_add_extension_code()
*
* Generates an extension function (a function defined in %extend) and
* adds it to the "wrap:code" attribute of a node
*
* See also extension_code()
*
* ----------------------------------------------------------------------------- */
int Swig_add_extension_code(Node *n, const String *function_name, ParmList *parms, SwigType *return_type, const String *code, int cplusplus, const String *self) {
String *body = extension_code(function_name, parms, return_type, code, cplusplus, self);
Setattr(n, "wrap:code", body);
Delete(body);
return SWIG_OK;
}
/* -----------------------------------------------------------------------------
* Swig_MethodToFunction(Node *n)
*
* Converts a C++ method node to a function accessor function.
* ----------------------------------------------------------------------------- */
int Swig_MethodToFunction(Node *n, String *classname, int flags, SwigType *director_type, int is_director) {
String *name, *qualifier;
ParmList *parms;
SwigType *type;
Parm *p;
String *self = 0;
/* If smart pointer, change self dereferencing */
if (flags & CWRAP_SMART_POINTER) {
self = NewString("(*this)->");
}
/* If node is a member template expansion, we don't allow added code */
if (Getattr(n, "templatetype"))
flags &= ~(CWRAP_EXTEND);
name = Getattr(n, "name");
qualifier = Getattr(n, "qualifier");
parms = CopyParmList(nonvoid_parms(Getattr(n, "parms")));
type = NewString(classname);
if (qualifier) {
SwigType_push(type, qualifier);
}
SwigType_add_pointer(type);
p = NewParm(type, "self");
Setattr(p, "self", "1");
Setattr(p, "hidden","1");
/*
Disable the 'this' ownership in 'self' to manage inplace
operations like:
A& A::operator+=(int i) { ...; return *this;}
Here the 'self' parameter ownership needs to be disabled since
there could be two objects sharing the same 'this' pointer: the
input and the result one. And worse, the pointer could be deleted
in one of the objects (input), leaving the other (output) with
just a seg. fault to happen.
To avoid the previous problem, use
%feature("self:disown") *::operator+=;
%feature("new") *::operator+=;
These two lines just transfer the ownership of the 'this' pointer
from the input to the output wrapping object.
This happens in python, but may also happens in other target
languages.
*/
if (GetFlag(n, "feature:self:disown")) {
Setattr(p, "wrap:disown", "1");
}
set_nextSibling(p, parms);
Delete(type);
/* Generate action code for the access */
if (!(flags & CWRAP_EXTEND)) {
String *explicit_qualifier = 0;
String *call = 0;
String *cres = 0;
String *explicitcall_name = 0;
int pure_virtual = !(Cmp(Getattr(n, "storage"), "virtual")) && !(Cmp(Getattr(n, "value"), "0"));
/* Call the explicit method rather than allow for a polymorphic call */
if ((flags & CWRAP_DIRECTOR_TWO_CALLS) || (flags & CWRAP_DIRECTOR_ONE_CALL)) {
String *access = Getattr(n, "access");
if (access && (Cmp(access, "protected") == 0)) {
/* If protected access (can only be if a director method) then call the extra public accessor method (language module must provide this) */
String *explicit_qualifier_tmp = SwigType_namestr(Getattr(Getattr(parentNode(n), "typescope"), "qname"));
explicitcall_name = NewStringf("%sSwigPublic", name);
explicit_qualifier = NewStringf("SwigDirector_%s", explicit_qualifier_tmp);
Delete(explicit_qualifier_tmp);
} else {
explicit_qualifier = SwigType_namestr(Getattr(Getattr(parentNode(n), "typescope"), "qname"));
}
}
call = Swig_cmethod_call(explicitcall_name ? explicitcall_name : name, p, self, explicit_qualifier, director_type);
cres = Swig_cresult(Getattr(n, "type"), "result", call);
if (pure_virtual && is_director && (flags & CWRAP_DIRECTOR_TWO_CALLS)) {
String *qualifier = SwigType_namestr(Getattr(Getattr(parentNode(n), "typescope"), "qname"));
Delete(cres);
cres = NewStringf("Swig::DirectorPureVirtualException::raise(\"%s::%s\");", qualifier, name);
Delete(qualifier);
}
if (flags & CWRAP_DIRECTOR_TWO_CALLS) {
/* Create two method calls, one to call the explicit method, the other a normal polymorphic function call */
String *cres_both_calls = NewStringf("");
String *call_extra = Swig_cmethod_call(name, p, self, 0, director_type);
String *cres_extra = Swig_cresult(Getattr(n, "type"), "result", call_extra);
Printv(cres_both_calls, "if (upcall) {\n", cres, "\n", "} else {", cres_extra, "\n}", NIL);
Setattr(n, "wrap:action", cres_both_calls);
Delete(cres_extra);
Delete(call_extra);
Delete(cres_both_calls);
} else {
Setattr(n, "wrap:action", cres);
}
Delete(explicitcall_name);
Delete(call);
Delete(cres);
Delete(explicit_qualifier);
} else {
/* Methods with default arguments are wrapped with additional methods for each default argument,
* however, only one extra %extend method is generated. */
String *defaultargs = Getattr(n, "defaultargs");
String *code = Getattr(n, "code");
String *cname = Getattr(n, "classname") ? Getattr(n, "classname") : classname;
String *membername = Swig_name_member(cname, name);
String *mangled = Swig_name_mangle(membername);
int is_smart_pointer = flags & CWRAP_SMART_POINTER;
type = Getattr(n, "type");
/* Check if the method is overloaded. If so, and it has code attached, we append an extra suffix
to avoid a name-clash in the generated wrappers. This allows overloaded methods to be defined
in C. */
if (Getattr(n, "sym:overloaded") && code) {
Append(mangled, Getattr(defaultargs ? defaultargs : n, "sym:overname"));
}
/* See if there is any code that we need to emit */
if (!defaultargs && code && !is_smart_pointer) {
Swig_add_extension_code(n, mangled, p, type, code, cparse_cplusplus, "self");
}
if (is_smart_pointer) {
int i = 0;
Parm *pp = p;
String *func = NewStringf("%s(", mangled);
String *cres;
if (Cmp(Getattr(n, "storage"), "static") != 0) {
String *pname = Swig_cparm_name(pp, i);
String *ctname = SwigType_namestr(cname);
String *fadd = NewStringf("(%s*)(%s)->operator ->()", ctname, pname);
Append(func, fadd);
Delete(ctname);
Delete(fadd);
Delete(pname);
pp = nextSibling(pp);
if (pp)
Append(func, ",");
} else {
pp = nextSibling(pp);
}
++i;
while (pp) {
SwigType *pt = Getattr(pp, "type");
if ((SwigType_type(pt) != T_VOID)) {
String *pname = Swig_cparm_name(pp, i++);
String *rcaststr = SwigType_rcaststr(pt, pname);
Append(func, rcaststr);
Delete(rcaststr);
Delete(pname);
pp = nextSibling(pp);
if (pp)
Append(func, ",");
}
}
Append(func, ")");
cres = Swig_cresult(Getattr(n, "type"), "result", func);
Setattr(n, "wrap:action", cres);
Delete(cres);
} else {
String *call = Swig_cfunction_call(mangled, p);
String *cres = Swig_cresult(Getattr(n, "type"), "result", call);
Setattr(n, "wrap:action", cres);
Delete(call);
Delete(cres);
}
Delete(membername);
Delete(mangled);
}
Setattr(n, "parms", p);
Delete(p);
Delete(self);
Delete(parms);
return SWIG_OK;
}
/* -----------------------------------------------------------------------------
* Swig_methodclass()
*
* This function returns the class node for a given method or class.
* ----------------------------------------------------------------------------- */
Node *Swig_methodclass(Node *n) {
Node *nodetype = nodeType(n);
if (Cmp(nodetype, "class") == 0)
return n;
return GetFlag(n, "feature:extend") ? parentNode(parentNode(n)) : parentNode(n);
}
int Swig_directorclass(Node *n) {
Node *classNode = Swig_methodclass(n);
assert(classNode != 0);
return (Getattr(classNode, "vtable") != 0);
}
Node *Swig_directormap(Node *module, String *type) {
int is_void = !Cmp(type, "void");
if (!is_void && module) {
/* ?? follow the inheritance hierarchy? */
String *base = SwigType_base(type);
Node *directormap = Getattr(module, "wrap:directormap");
if (directormap)
return Getattr(directormap, base);
}
return 0;
}
/* -----------------------------------------------------------------------------
* Swig_ConstructorToFunction()
*
* This function creates a C wrapper for a C constructor function.
* ----------------------------------------------------------------------------- */
int Swig_ConstructorToFunction(Node *n, String *classname, String *none_comparison, String *director_ctor, int cplus, int flags) {
ParmList *parms;
Parm *prefix_args;
Parm *p;
ParmList *directorparms;
SwigType *type;
Node *classNode;
int use_director;
classNode = Swig_methodclass(n);
use_director = Swig_directorclass(n);
parms = CopyParmList(nonvoid_parms(Getattr(n, "parms")));
/* Prepend the list of prefix_args (if any) */
prefix_args = Getattr(n, "director:prefix_args");
if (prefix_args != NIL) {
Parm *p2, *p3;
directorparms = CopyParmList(prefix_args);
for (p = directorparms; nextSibling(p); p = nextSibling(p));
for (p2 = parms; p2; p2 = nextSibling(p2)) {
p3 = CopyParm(p2);
set_nextSibling(p, p3);
Delete(p3);
p = p3;
}
} else
directorparms = parms;
type = NewString(classname);
SwigType_add_pointer(type);
if (flags & CWRAP_EXTEND) {
/* Constructors with default arguments are wrapped with additional constructor methods for each default argument,
* however, only one extra %extend method is generated. */
String *call;
String *cres;
String *defaultargs = Getattr(n, "defaultargs");
String *code = Getattr(n, "code");
String *membername = Swig_name_construct(classname);
String *mangled = Swig_name_mangle(membername);
/* Check if the constructor is overloaded. If so, and it has code attached, we append an extra suffix
to avoid a name-clash in the generated wrappers. This allows overloaded constructors to be defined
in C. */
if (Getattr(n, "sym:overloaded") && code) {
Append(mangled, Getattr(defaultargs ? defaultargs : n, "sym:overname"));
}
/* See if there is any code that we need to emit */
if (!defaultargs && code) {
Swig_add_extension_code(n, mangled, parms, type, code, cparse_cplusplus, "self");
}
call = Swig_cfunction_call(mangled, parms);
cres = Swig_cresult(type, "result", call);
Setattr(n, "wrap:action", cres);
Delete(cres);
Delete(call);
Delete(membername);
Delete(mangled);
} else {
if (cplus) {
/* if a C++ director class exists, create it rather than the original class */
if (use_director) {
Node *parent = Swig_methodclass(n);
int abstract = Getattr(parent, "abstract") != 0;
String *name = Getattr(parent, "sym:name");
String *directorname = NewStringf("SwigDirector_%s", name);
String *action = NewStringEmpty();
String *tmp_none_comparison = Copy(none_comparison);
String *director_call;
String *nodirector_call;
Replaceall(tmp_none_comparison, "$arg", "arg1");
director_call = Swig_cppconstructor_director_call(directorname, directorparms);
nodirector_call = Swig_cppconstructor_nodirector_call(classname, parms);
if (abstract) {
/* whether or not the abstract class has been subclassed in python,
* create a director instance (there's no way to create a normal
* instance). if any of the pure virtual methods haven't been
* implemented in the target language, calls to those methods will
* generate Swig::DirectorPureVirtualException exceptions.
*/
String *cres = Swig_cresult(type, "result", director_call);
Append(action, cres);
Delete(cres);
} else {
/* (scottm): The code for creating a new director is now a string
template that gets passed in via the director_ctor argument.
$comparison : an 'if' comparison from none_comparison
$director_new: Call new for director class
$nondirector_new: Call new for non-director class
*/
String *cres;
Append(action, director_ctor);
Replaceall(action, "$comparison", tmp_none_comparison);
cres = Swig_cresult(type, "result", director_call);
Replaceall(action, "$director_new", cres);
Delete(cres);
cres = Swig_cresult(type, "result", nodirector_call);
Replaceall(action, "$nondirector_new", cres);
Delete(cres);
}
Setattr(n, "wrap:action", action);
Delete(tmp_none_comparison);
Delete(action);
Delete(directorname);
} else {
String *call = Swig_cppconstructor_call(classname, parms);
String *cres = Swig_cresult(type, "result", call);
Setattr(n, "wrap:action", cres);
Delete(cres);
Delete(call);
}
} else {
String *call = Swig_cconstructor_call(classname);
String *cres = Swig_cresult(type, "result", call);
Setattr(n, "wrap:action", cres);
Delete(cres);
Delete(call);
}
}
Setattr(n, "type", type);
Setattr(n, "parms", parms);
Delete(type);
if (directorparms != parms)
Delete(directorparms);
Delete(parms);
return SWIG_OK;
}
/* -----------------------------------------------------------------------------
* Swig_DestructorToFunction()
*
* This function creates a C wrapper for a destructor function.
* ----------------------------------------------------------------------------- */
int Swig_DestructorToFunction(Node *n, String *classname, int cplus, int flags) {
SwigType *type;
Parm *p;
type = NewString(classname);
SwigType_add_pointer(type);
p = NewParm(type, "self");
Setattr(p, "self", "1");
Setattr(p, "hidden", "1");
Setattr(p, "wrap:disown", "1");
Delete(type);
type = NewString("void");
if (flags & CWRAP_EXTEND) {
String *cres;
String *call;
String *membername, *mangled, *code;
membername = Swig_name_destroy(classname);
mangled = Swig_name_mangle(membername);
code = Getattr(n, "code");
if (code) {
Swig_add_extension_code(n, mangled, p, type, code, cparse_cplusplus, "self");
}
call = Swig_cfunction_call(mangled, p);
cres = NewStringf("%s;", call);
Setattr(n, "wrap:action", cres);
Delete(membername);
Delete(mangled);
Delete(call);
Delete(cres);
} else {
if (cplus) {
String *call = Swig_cppdestructor_call(n);
String *cres = NewStringf("%s", call);
Setattr(n, "wrap:action", cres);
Delete(call);
Delete(cres);
} else {
String *call = Swig_cdestructor_call(n);
String *cres = NewStringf("%s", call);
Setattr(n, "wrap:action", cres);
Delete(call);
Delete(cres);
}
}
Setattr(n, "type", type);
Setattr(n, "parms", p);
Delete(type);
Delete(p);
return SWIG_OK;
}
/* -----------------------------------------------------------------------------
* Swig_MembersetToFunction()
*
* This function creates a C wrapper for setting a structure member.
* ----------------------------------------------------------------------------- */
int Swig_MembersetToFunction(Node *n, String *classname, int flags) {
String *name;
ParmList *parms;
Parm *p;
SwigType *t;
SwigType *ty;
SwigType *type;
SwigType *void_type = NewString("void");
String *membername;
String *mangled;
String *self = 0;
String *sname;
int varcref = flags & CWRAP_NATURAL_VAR;
if (flags & CWRAP_SMART_POINTER) {
self = NewString("(*this)->");
}
if (flags & CWRAP_ALL_PROTECTED_ACCESS) {
self = NewStringf("darg->");
}
name = Getattr(n, "name");
type = Getattr(n, "type");
sname = Swig_name_set(name);
membername = Swig_name_member(classname, sname);
mangled = Swig_name_mangle(membername);
t = NewString(classname);
SwigType_add_pointer(t);
parms = NewParm(t, "self");
Setattr(parms, "self", "1");
Setattr(parms, "hidden","1");
Delete(t);
ty = Swig_wrapped_member_var_type(type, varcref);
p = NewParm(ty, name);
Setattr(parms, "hidden", "1");
set_nextSibling(parms, p);
/* If the type is a pointer or reference. We mark it with a special wrap:disown attribute */
if (SwigType_check_decl(type, "p.")) {
Setattr(p, "wrap:disown", "1");
}
Delete(p);
if (flags & CWRAP_EXTEND) {
String *call;
String *cres;
String *code = Getattr(n, "code");
if (code) {
/* I don't think this ever gets run - WSF */
Swig_add_extension_code(n, mangled, parms, void_type, code, cparse_cplusplus, "self");
}
call = Swig_cfunction_call(mangled, parms);
cres = NewStringf("%s;", call);
Setattr(n, "wrap:action", cres);
Delete(call);
Delete(cres);
} else {
String *call = Swig_cmemberset_call(name, type, self, varcref);
String *cres = NewStringf("%s;", call);
Setattr(n, "wrap:action", cres);
Delete(call);
Delete(cres);
}
Setattr(n, "type", void_type);
Setattr(n, "parms", parms);
Delete(parms);
Delete(ty);
Delete(void_type);
Delete(membername);
Delete(sname);
Delete(mangled);
Delete(self);
return SWIG_OK;
}
/* -----------------------------------------------------------------------------
* Swig_MembergetToFunction()
*
* This function creates a C wrapper for getting a structure member.
* ----------------------------------------------------------------------------- */
int Swig_MembergetToFunction(Node *n, String *classname, int flags) {
String *name;
ParmList *parms;
SwigType *t;
SwigType *ty;
SwigType *type;
String *membername;
String *mangled;
String *self = 0;
String *gname;
int varcref = flags & CWRAP_NATURAL_VAR;
if (flags & CWRAP_SMART_POINTER) {
if (checkAttribute(n, "storage", "static")) {
Node *sn = Getattr(n, "cplus:staticbase");
String *base = Getattr(sn, "name");
self = NewStringf("%s::", base);
} else {
self = NewString("(*this)->");
}
}
if (flags & CWRAP_ALL_PROTECTED_ACCESS) {
self = NewStringf("darg->");
}
name = Getattr(n, "name");
type = Getattr(n, "type");
gname = Swig_name_get(name);
membername = Swig_name_member(classname, gname);
mangled = Swig_name_mangle(membername);
t = NewString(classname);
SwigType_add_pointer(t);
parms = NewParm(t, "self");
Setattr(parms, "self", "1");
Setattr(parms, "hidden","1");
Delete(t);
ty = Swig_wrapped_member_var_type(type, varcref);
if (flags & CWRAP_EXTEND) {
String *call;
String *cres;
String *code = Getattr(n, "code");
if (code) {
/* I don't think this ever gets run - WSF */
Swig_add_extension_code(n, mangled, parms, ty, code, cparse_cplusplus, "self");
}
call = Swig_cfunction_call(mangled, parms);
cres = Swig_cresult(ty, "result", call);
Setattr(n, "wrap:action", cres);
Delete(cres);
Delete(call);
} else {
String *call = Swig_cmemberget_call(name, type, self, varcref);
String *cres = Swig_cresult(ty, "result", call);
Setattr(n, "wrap:action", cres);
Delete(call);
Delete(cres);
}
Setattr(n, "type", ty);
Setattr(n, "parms", parms);
Delete(parms);
Delete(ty);
Delete(membername);
Delete(gname);
Delete(mangled);
return SWIG_OK;
}
/* -----------------------------------------------------------------------------
* Swig_VarsetToFunction()
*
* This function creates a C wrapper for setting a global variable or static member
* variable.
* ----------------------------------------------------------------------------- */
int Swig_VarsetToFunction(Node *n, int flags) {
String *name, *nname;
ParmList *parms;
SwigType *type, *ty;
int varcref = flags & CWRAP_NATURAL_VAR;
name = Getattr(n, "name");
type = Getattr(n, "type");
nname = SwigType_namestr(name);
ty = Swig_wrapped_var_type(type, varcref);
parms = NewParm(ty, name);
if (flags & CWRAP_EXTEND) {
String *sname = Swig_name_set(name);
String *mangled = Swig_name_mangle(sname);
String *call = Swig_cfunction_call(mangled, parms);
String *cres = NewStringf("%s;", call);
Setattr(n, "wrap:action", cres);
Delete(cres);
Delete(call);
Delete(mangled);
Delete(sname);
} else {
if (!Strstr(type, "enum $unnamed")) {
String *pname = Swig_cparm_name(0, 0);
String *dref = Swig_wrapped_var_deref(type, pname, varcref);
String *call = NewStringf("%s = %s;", nname, dref);
Setattr(n, "wrap:action", call);
Delete(call);
Delete(dref);
Delete(pname);
} else {
String *pname = Swig_cparm_name(0, 0);
String *call = NewStringf("if (sizeof(int) == sizeof(%s)) *(int*)(void*)&(%s) = %s;", nname, nname, pname);
Setattr(n, "wrap:action", call);
Delete(pname);
Delete(call);
}
}
Setattr(n, "type", "void");
Setattr(n, "parms", parms);
Delete(parms);
Delete(ty);
Delete(nname);
return SWIG_OK;
}
/* -----------------------------------------------------------------------------
* Swig_VargetToFunction()
*
* This function creates a C wrapper for getting a global variable or static member
* variable.
* ----------------------------------------------------------------------------- */
int Swig_VargetToFunction(Node *n, int flags) {
String *cres, *call;
String *name;
SwigType *type;
SwigType *ty = 0;
int varcref = flags & CWRAP_NATURAL_VAR;
name = Getattr(n, "name");
type = Getattr(n, "type");
ty = Swig_wrapped_var_type(type, varcref);
if (flags & CWRAP_EXTEND) {
String *sname = Swig_name_get(name);
String *mangled = Swig_name_mangle(sname);
call = Swig_cfunction_call(mangled, 0);
cres = Swig_cresult(ty, "result", call);
Setattr(n, "wrap:action", cres);
Delete(mangled);
Delete(sname);
} else {
String *nname = SwigType_namestr(name);
call = Swig_wrapped_var_assign(type, nname, varcref);
cres = Swig_cresult(ty, "result", call);
Setattr(n, "wrap:action", cres);
Delete(nname);
}
Setattr(n, "type", ty);
Delattr(n, "parms");
Delete(cres);
Delete(call);
Delete(ty);
return SWIG_OK;
}