From 4098a01b68712400c025fa76b418c92e5c10d28a Mon Sep 17 00:00:00 2001 From: Ahmon Dancy Date: Wed, 9 Nov 2005 20:44:22 +0000 Subject: [PATCH] Huge update to the Allegrocl module. Better C support. C++ support added. Documentation! Makes use of typemaps for better interface tuning. Improved type support. Wrapping of foreign pointers in CLOS objects; hopefully a step toward being able to extend C++ classes from Lisp. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7828 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 30 + Doc/Manual/CSharp.html | 22 +- Doc/Manual/Chicken.html | 38 +- Doc/Manual/Contents.html | 137 +- Doc/Manual/Extending.html | 92 +- Doc/Manual/Guile.html | 42 +- Doc/Manual/Java.html | 188 +-- Doc/Manual/Lisp.html | 37 +- Doc/Manual/Lua.html | 50 +- Doc/Manual/Modula3.html | 46 +- Doc/Manual/Mzscheme.html | 4 +- Doc/Manual/Ocaml.html | 62 +- Doc/Manual/Perl5.html | 92 +- Doc/Manual/Php.html | 34 +- Doc/Manual/Pike.html | 24 +- Doc/Manual/Python.html | 146 +- Doc/Manual/Ruby.html | 108 +- Doc/Manual/Sections.html | 1 + Doc/Manual/Tcl.html | 90 +- Doc/Manual/chapters | 2 + Lib/allegrocl/allegrocl.swg | 454 +++++- Source/Modules/allegrocl.cxx | 2886 ++++++++++++++++++++++++++++++---- 22 files changed, 3703 insertions(+), 882 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 9acebee0e..f4351b928 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,36 @@ Version 1.3.28 (unreleased) =========================== +11/09/2005: dancy + + [Allegrocl] + Add C++ support to the Allegrocl module. Further + enhances the C support as well. Some of the + features: + + - MUCH better generation of foreign types based on + the C/C++ types for use in defining the FFI on + the lisp side. We don't pass everything as a (* :void) + any longer. + + - Uses typemaps for better control of type conversions + and code generation in the generated lisp and c++ wrapper + code. + + - CLOS wrapping of pointers returned from foreign space + makes it easier to differentiate pointers in user code. + The wrapping objects can be passed directly to FF calls. + + - Defun wrapping of FF calls, allowing for more lispy + interface. Conversion, GCing, of lisp objects to + foreign objects can be done in the wrapping defun via + the use of typemaps. + + - overload dispatching implemented on the lisp side + using generic functions. + + - Templates and synonymous types supported. + 11/07/2005: mmatus [Python] Adding proper support for multi-inheritance in diff --git a/Doc/Manual/CSharp.html b/Doc/Manual/CSharp.html index 1b77342a4..8ec7f8e84 100644 --- a/Doc/Manual/CSharp.html +++ b/Doc/Manual/CSharp.html @@ -5,7 +5,7 @@ -

16 SWIG and C#

+

18 SWIG and C#

-

16.3.3 C# exception example using exception specifications

+

18.3.3 C# exception example using exception specifications

@@ -734,7 +734,7 @@ SWIGEXPORT void SWIGSTDCALL CSharp_evensonly(int jarg1) { Multiple catch handlers are generated should there be more than one exception specifications declared.

-

16.3.4 Custom C# ApplicationException example

+

18.3.4 Custom C# ApplicationException example

@@ -868,7 +868,7 @@ try { -

16.4 C# Typemap examples

+

18.4 C# Typemap examples

This section includes a few examples of typemaps. For more examples, you @@ -876,7 +876,7 @@ might look at the files "csharp.swg" and "typemaps.i" in the SWIG library. -

16.4.1 Memory management when returning references to member variables

+

18.4.1 Memory management when returning references to member variables

@@ -1000,7 +1000,7 @@ public class Bike : IDisposable { Note the addReference call.

-

16.4.2 Memory management for objects passed to the C++ layer

+

18.4.2 Memory management for objects passed to the C++ layer

diff --git a/Doc/Manual/Chicken.html b/Doc/Manual/Chicken.html index 8668fa3e4..ed7bdb033 100644 --- a/Doc/Manual/Chicken.html +++ b/Doc/Manual/Chicken.html @@ -8,7 +8,7 @@ -

17 SWIG and Chicken

+

19 SWIG and Chicken

-

17.3 TinyCLOS

+

19.3 TinyCLOS

@@ -321,7 +321,7 @@

-

17.4 Linkage

+

19.4 Linkage

@@ -342,7 +342,7 @@

-

17.4.1 Static binary or shared library linked at compile time

+

19.4.1 Static binary or shared library linked at compile time

We can easily use csc to build a static binary.

@@ -383,7 +383,7 @@ in which case the test script does not need to be linked with example.so. The t be run with csi.

-

17.4.2 Building chicken extension libraries

+

19.4.2 Building chicken extension libraries

Building a shared library like in the above section only works if the library @@ -441,7 +441,7 @@ distributed and used by anyone, even if SWIG is not installed.

See the Examples/chicken/egg directory in the SWIG source for an example that builds two eggs, one using the first method and one using the second method.

-

17.4.3 Linking multiple SWIG modules with TinyCLOS

+

19.4.3 Linking multiple SWIG modules with TinyCLOS

Linking together multiple modules that share type information using the %import @@ -465,7 +465,7 @@ with (declare (uses ...)). To create an extension library or an egg, just create a module_load.scm file that (declare (uses ...)) all the modules.

-

17.5 Typemaps

+

19.5 Typemaps

@@ -474,7 +474,7 @@ all the modules.

Lib/chicken/chicken.swg.

-

17.6 Pointers

+

19.6 Pointers

@@ -507,7 +507,7 @@ all the modules.

type. flags is either zero or SWIG_POINTER_DISOWN (see below).

-

17.6.1 Garbage collection

+

19.6.1 Garbage collection

If the owner flag passed to SWIG_NewPointerObj is 1, NewPointerObj will add a @@ -538,7 +538,7 @@ all the modules.

must be called manually.

-

17.7 Unsupported features and known problems

+

19.7 Unsupported features and known problems

+
  • C# Typemap examples + -

    17 SWIG and Chicken

    +

    19 SWIG and Chicken

    @@ -538,7 +643,7 @@
    -

    18 SWIG and Guile

    +

    20 SWIG and Guile

    @@ -573,7 +678,7 @@
    -

    19 SWIG and Java

    +

    21 SWIG and Java

    @@ -691,6 +796,8 @@
  • Adding an equals method to the Java classes
  • Void pointers and a common Java base class
  • Struct pointer to pointer +
  • Memory management when returning references to member variables +
  • Memory management for objects passed to the C++ layer
  • Living with Java Directors
  • Odds and ends @@ -705,7 +812,7 @@ -

    20 SWIG and Modula-3

    +

    22 SWIG and Modula-3

    @@ -746,7 +853,7 @@
    -

    21 SWIG and MzScheme

    +

    23 SWIG and MzScheme

    @@ -756,7 +863,7 @@
    -

    22 SWIG and Ocaml

    +

    24 SWIG and Ocaml

    @@ -807,7 +914,7 @@
    -

    23 SWIG and Perl5

    +

    25 SWIG and Perl5

    @@ -873,7 +980,7 @@
    -

    24 SWIG and PHP4

    +

    26 SWIG and PHP4

    @@ -904,7 +1011,7 @@
    -

    25 SWIG and Pike

    +

    27 SWIG and Pike

    @@ -928,7 +1035,7 @@
    -

    26 SWIG and Python

    +

    28 SWIG and Python

    @@ -1029,7 +1136,7 @@
    -

    27 SWIG and Ruby

    +

    29 SWIG and Ruby

    @@ -1111,7 +1218,7 @@
    -

    28 SWIG and Tcl

    +

    30 SWIG and Tcl

    @@ -1176,7 +1283,7 @@
    -

    29 SWIG and Lua

    +

    31 SWIG and Lua

    @@ -1215,7 +1322,7 @@
    -

    30 Extending SWIG

    +

    32 Extending SWIG

    diff --git a/Doc/Manual/Extending.html b/Doc/Manual/Extending.html index e7a7bc21d..da1657787 100644 --- a/Doc/Manual/Extending.html +++ b/Doc/Manual/Extending.html @@ -6,7 +6,7 @@ -

    30 Extending SWIG

    +

    32 Extending SWIG

      @@ -75,7 +75,7 @@ Caution: This chapter is being rewritten! (11/25/01)

      -

      30.1 Introduction

      +

      32.1 Introduction

      @@ -91,7 +91,7 @@ Also, this chapter is not meant to be a hand-holding tutorial. As a starting po you should probably look at one of SWIG's existing modules.

      -

      30.2 Prerequisites

      +

      32.2 Prerequisites

      @@ -121,7 +121,7 @@ obvious, but almost all SWIG directives as well as the low-level generation of wrapper code are driven by C++ datatypes.

      -

      30.3 The Big Picture

      +

      32.3 The Big Picture

      @@ -158,7 +158,7 @@ role in making the system work. For example, both typemaps and declaration anno based on pattern matching and interact heavily with the underlying type system.

      -

      30.4 Execution Model

      +

      32.4 Execution Model

      @@ -203,7 +203,7 @@ stage of compilation. The next few sections briefly describe some of these stages.

      -

      30.4.1 Preprocessing

      +

      32.4.1 Preprocessing

      @@ -283,7 +283,7 @@ been expanded as well as everything else that goes into the low-level construction of the wrapper code.

      -

      30.4.2 Parsing

      +

      32.4.2 Parsing

      @@ -384,7 +384,7 @@ returning a foo and taking types a and b as arguments).

      -

      30.4.3 Parse Trees

      +

      32.4.3 Parse Trees

      @@ -636,7 +636,7 @@ $ swig -c++ -python -dump_tree example.i

    -

    30.4.4 Attribute namespaces

    +

    32.4.4 Attribute namespaces

    @@ -655,7 +655,7 @@ that matches the name of the target language. For example, python:foo perl:foo.

    -

    30.4.5 Symbol Tables

    +

    32.4.5 Symbol Tables

    @@ -743,7 +743,7 @@ example.i:5. Previous declaration is foo_i(int )

    -

    30.4.6 The %feature directive

    +

    32.4.6 The %feature directive

    @@ -799,7 +799,7 @@ For example, the exception code above is simply stored without any modifications.

    -

    30.4.7 Code Generation

    +

    32.4.7 Code Generation

    @@ -921,7 +921,7 @@ public : The role of these functions is described shortly.

    -

    30.4.8 SWIG and XML

    +

    32.4.8 SWIG and XML

    @@ -934,7 +934,7 @@ internal data structures, it may be useful keep XML in the back of your mind as a model.

    -

    30.5 Primitive Data Structures

    +

    32.5 Primitive Data Structures

    @@ -980,7 +980,7 @@ typedef Hash Typetab; -

    30.5.1 Strings

    +

    32.5.1 Strings

    @@ -1121,7 +1121,7 @@ Returns the number of replacements made (if any). -

    30.5.2 Hashes

    +

    32.5.2 Hashes

    @@ -1198,7 +1198,7 @@ Returns the list of hash table keys. -

    30.5.3 Lists

    +

    32.5.3 Lists

    @@ -1287,7 +1287,7 @@ If t is not a standard object, it is assumed to be a char * and is used to create a String object. -

    30.5.4 Common operations

    +

    32.5.4 Common operations

    The following operations are applicable to all datatypes. @@ -1342,7 +1342,7 @@ objects and report errors. Gets the line number associated with x. -

    30.5.5 Iterating over Lists and Hashes

    +

    32.5.5 Iterating over Lists and Hashes

    To iterate over the elements of a list or a hash table, the following functions are used: @@ -1387,7 +1387,7 @@ for (j = First(j); j.item; j= Next(j)) { -

    30.5.6 I/O

    +

    32.5.6 I/O

    Special I/O functions are used for all internal I/O. These operations @@ -1523,7 +1523,7 @@ Similarly, the preprocessor and parser all operate on string-files. -

    30.6 Navigating and manipulating parse trees

    +

    32.6 Navigating and manipulating parse trees

    Parse trees are built as collections of hash tables. Each node is a hash table in which @@ -1657,7 +1657,7 @@ Deletes a node from the parse tree. Deletion reconnects siblings and properly u the parent so that sibling nodes are unaffected. -

    30.7 Working with attributes

    +

    32.7 Working with attributes

    @@ -1774,7 +1774,7 @@ the attribute is optional. Swig_restore() must always be called after function. -

    30.8 Type system

    +

    32.8 Type system

    @@ -1783,7 +1783,7 @@ pointers, references, and pointers to members. A detailed discussion of type theory is impossible here. However, let's cover the highlights.

    -

    30.8.1 String encoding of types

    +

    32.8.1 String encoding of types

    @@ -1884,7 +1884,7 @@ make the final type, the two parts are just joined together using string concatenation.

    -

    30.8.2 Type construction

    +

    32.8.2 Type construction

    @@ -2053,7 +2053,7 @@ Returns the prefix of a type. For example, if ty is ty is unmodified. -

    30.8.3 Type tests

    +

    32.8.3 Type tests

    @@ -2140,7 +2140,7 @@ Checks if ty is a varargs type. Checks if ty is a templatized type. -

    30.8.4 Typedef and inheritance

    +

    32.8.4 Typedef and inheritance

    @@ -2242,7 +2242,7 @@ Fully reduces ty according to typedef rules. Resulting datatype will consist only of primitive typenames. -

    30.8.5 Lvalues

    +

    32.8.5 Lvalues

    @@ -2279,7 +2279,7 @@ Literal y; // type = 'Literal', ltype='p.char' -

    30.8.6 Output functions

    +

    32.8.6 Output functions

    @@ -2341,7 +2341,7 @@ SWIG, but is most commonly associated with type-descriptor objects that appear in wrappers (e.g., SWIGTYPE_p_double). -

    30.9 Parameters

    +

    32.9 Parameters

    @@ -2440,7 +2440,7 @@ included. Used to emit prototypes. Returns the number of required (non-optional) arguments in p. -

    30.10 Writing a Language Module

    +

    32.10 Writing a Language Module

    @@ -2451,7 +2451,7 @@ describes the creation of a minimal Python module. You should be able to extra this to other languages.

    -

    30.10.1 Execution model

    +

    32.10.1 Execution model

    @@ -2461,7 +2461,7 @@ the parsing of command line options, all aspects of code generation are controll different methods of the Language that must be defined by your module.

    -

    30.10.2 Starting out

    +

    32.10.2 Starting out

    @@ -2574,7 +2574,7 @@ that activates your module. For example, swig -python foo.i. The messages from your new module should appear.

    -

    30.10.3 Command line options

    +

    32.10.3 Command line options

    @@ -2633,7 +2633,7 @@ to mark the option as valid. If you forget to do this, SWIG will terminate wit unrecognized command line option error.

    -

    30.10.4 Configuration and preprocessing

    +

    32.10.4 Configuration and preprocessing

    @@ -2682,7 +2682,7 @@ an implementation file python.cxx and a configuration file python.swg.

    -

    30.10.5 Entry point to code generation

    +

    32.10.5 Entry point to code generation

    @@ -2740,13 +2740,13 @@ int Python::top(Node *n) { -

    30.10.6 Module I/O and wrapper skeleton

    +

    32.10.6 Module I/O and wrapper skeleton

    -

    30.10.7 Low-level code generators

    +

    32.10.7 Low-level code generators

    -

    30.10.8 Configuration files

    +

    32.10.8 Configuration files

    @@ -2901,7 +2901,7 @@ to handle some of these configuration tasks, but that point is now long past. If you are interested in working on that, feel free to raise the issue in the context of a next-generation clean-slate SWIG. -

    30.10.9 Runtime support

    +

    32.10.9 Runtime support

    @@ -2910,7 +2910,7 @@ Discuss the kinds of functions typically needed for SWIG runtime support (e.g. the SWIG files that implement those functions.

    -

    30.10.10 Standard library files

    +

    32.10.10 Standard library files

    @@ -2924,7 +2924,7 @@ Discuss the standard library files that most language modules provide, e.g.

  • stl.i
  • -

    30.10.11 Examples and test cases

    +

    32.10.11 Examples and test cases

    @@ -2951,7 +2951,7 @@ during this process, see the section on configuration files.

    -

    30.10.12 Documentation

    +

    32.10.12 Documentation

    @@ -2983,13 +2983,13 @@ Some topics that you'll want to be sure to address include: if available. -

    30.11 Typemaps

    +

    32.11 Typemaps

    -

    30.11.1 Proxy classes

    +

    32.11.1 Proxy classes

    -

    30.12 Guide to parse tree nodes

    +

    32.12 Guide to parse tree nodes

    diff --git a/Doc/Manual/Guile.html b/Doc/Manual/Guile.html index ff8275342..7368d6c8e 100644 --- a/Doc/Manual/Guile.html +++ b/Doc/Manual/Guile.html @@ -8,7 +8,7 @@ -

    18 SWIG and Guile

    +

    20 SWIG and Guile

    -

    18.3.4 Old Auto-Loading Guile Module Linkage

    +

    20.3.4 Old Auto-Loading Guile Module Linkage

    Guile used to support an autoloading facility for object-code @@ -283,7 +283,7 @@ option, SWIG generates an exported module initialization function with an appropriate name. -

    18.3.5 Hobbit4D Linkage

    +

    20.3.5 Hobbit4D Linkage

    @@ -308,7 +308,7 @@ my/lib/libfoo.so.X.Y.Z and friends. This scheme is still very experimental; the (hobbit4d link) conventions are not well understood.

    -

    18.4 Underscore Folding

    +

    20.4 Underscore Folding

    @@ -320,7 +320,7 @@ complained so far. %rename to specify the Guile name of the wrapped functions and variables (see CHANGES). -

    18.5 Typemaps

    +

    20.5 Typemaps

    @@ -405,7 +405,7 @@ In body, the first result of See also the "multivalue" example.

    -

    18.6 Representation of pointers as smobs

    +

    20.6 Representation of pointers as smobs

    @@ -426,7 +426,7 @@ representing the expected pointer type. See also If the Scheme object passed was not a SWIG smob representing a compatible pointer, a wrong-type-arg exception is raised. -

    18.6.1 GH Smobs

    +

    20.6.1 GH Smobs

    @@ -455,7 +455,7 @@ that created them, so the first module we check will most likely be correct. Once we have a swig_type_info structure, we loop through the linked list of casts, using pointer comparisons.

    -

    18.6.2 SCM Smobs

    +

    20.6.2 SCM Smobs

    The SCM interface (using the "-scm" argument to swig) uses swigrun.swg. @@ -470,7 +470,7 @@ in the smob tag. If a generated GOOPS module has been loaded, smobs will be wra GOOPS class.

    -

    18.6.3 Garbage Collection

    +

    20.6.3 Garbage Collection

    Garbage collection is a feature of the new SCM interface, and it is automatically included @@ -484,7 +484,7 @@ is exactly like described in Object ownership and %newobject in the SWIG manual. All typemaps use an $owner var, and the guile module replaces $owner with 0 or 1 depending on feature:new.

    -

    18.7 Exception Handling

    +

    20.7 Exception Handling

    @@ -510,7 +510,7 @@ mapping: The default when not specified here is to use "swig-error". See Lib/exception.i for details. -

    18.8 Procedure documentation

    +

    20.8 Procedure documentation

    If invoked with the command-line option -procdoc @@ -546,7 +546,7 @@ like this: typemap argument doc. See Lib/guile/typemaps.i for details. -

    18.9 Procedures with setters

    +

    20.9 Procedures with setters

    For global variables, SWIG creates a single wrapper procedure @@ -574,7 +574,7 @@ struct members, the procedures (struct-member-get pointer) and (struct-member-set pointer value) are not generated. -

    18.10 GOOPS Proxy Classes

    +

    20.10 GOOPS Proxy Classes

    SWIG can also generate classes and generic functions for use with @@ -723,7 +723,7 @@ Notice that <Foo> is used before it is defined. The fix is to just put th %import "foo.h" before the %inline block.

    -

    18.10.1 Naming Issues

    +

    20.10.1 Naming Issues

    As you can see in the example above, there are potential naming conflicts. The default exported @@ -762,7 +762,7 @@ guile-modules. For example,

    TODO: Renaming class name prefixes?

    -

    18.10.2 Linking

    +

    20.10.2 Linking

    The guile-modules generated above all need to be linked together. GOOPS support requires diff --git a/Doc/Manual/Java.html b/Doc/Manual/Java.html index ceb806bcf..477a14ce9 100644 --- a/Doc/Manual/Java.html +++ b/Doc/Manual/Java.html @@ -5,7 +5,7 @@ -

    19 SWIG and Java

    +

    21 SWIG and Java

      @@ -146,7 +146,7 @@ It covers most SWIG features, but certain low-level details are covered in less

      -

      19.1 Overview

      +

      21.1 Overview

      @@ -181,7 +181,7 @@ Various customisation tips and techniques using SWIG directives are covered. The latter sections cover the advanced techniques of using typemaps for complete control of the wrapping process.

      -

      19.2 Preliminaries

      +

      21.2 Preliminaries

      @@ -197,7 +197,7 @@ Run make -k check from the SWIG root directory after installing SWIG on The Java module requires your system to support shared libraries and dynamic loading. This is the commonly used method to load JNI code so your system will more than likely support this.

      -

      19.2.1 Running SWIG

      +

      21.2.1 Running SWIG

      @@ -244,7 +244,7 @@ To change this, you can use the -o option. It is also possible to change the output directory that the Java files are generated into using -outdir.

      -

      19.2.2 Additional Commandline Options

      +

      21.2.2 Additional Commandline Options

      @@ -276,7 +276,7 @@ swig -java -help Their use will become clearer by the time you have finished reading this section on SWIG and Java.

      -

      19.2.3 Getting the right header files

      +

      21.2.3 Getting the right header files

      @@ -291,7 +291,7 @@ They are usually in directories like this:

      The exact location may vary on your machine, but the above locations are typical.

      -

      19.2.4 Compiling a dynamic module

      +

      21.2.4 Compiling a dynamic module

      @@ -319,7 +319,7 @@ The name of the shared library output file is important. If the name of your SWIG module is "example", the name of the corresponding shared library file should be "libexample.so" (or equivalent depending on your machine, see Dynamic linking problems for more information). The name of the module is specified using the %module directive or -module command line option.

      -

      19.2.5 Using your module

      +

      21.2.5 Using your module

      @@ -354,7 +354,7 @@ $ If it doesn't work have a look at the following section which discusses problems loading the shared library.

      -

      19.2.6 Dynamic linking problems

      +

      21.2.6 Dynamic linking problems

      @@ -428,7 +428,7 @@ The following section also contains some C++ specific linking problems and solut

      -

      19.2.7 Compilation problems and compiling with C++

      +

      21.2.7 Compilation problems and compiling with C++

      @@ -481,7 +481,7 @@ Finally make sure the version of JDK header files matches the version of Java th

      -

      19.2.8 Building on Windows

      +

      21.2.8 Building on Windows

      @@ -490,7 +490,7 @@ You will want to produce a DLL that can be loaded by the Java Virtual Machine. This section covers the process of using SWIG with Microsoft Visual C++ 6 although the procedure may be similar with other compilers. In order for everything to work, you will need to have a JDK installed on your machine in order to read the JNI header files.

      -

      19.2.8.1 Running SWIG from Visual Studio

      +

      21.2.8.1 Running SWIG from Visual Studio

      @@ -529,7 +529,7 @@ To run the native code in the DLL (example.dll), make sure that it is in your pa If the library fails to load have a look at Dynamic linking problems.

      -

      19.2.8.2 Using NMAKE

      +

      21.2.8.2 Using NMAKE

      @@ -588,7 +588,7 @@ Of course you may want to make changes for it to work for C++ by adding in the -

      -

      19.3 A tour of basic C/C++ wrapping

      +

      21.3 A tour of basic C/C++ wrapping

      @@ -598,7 +598,7 @@ variables are wrapped with JavaBean type getters and setters and so forth. This section briefly covers the essential aspects of this wrapping.

      -

      19.3.1 Modules, packages and generated Java classes

      +

      21.3.1 Modules, packages and generated Java classes

      @@ -632,7 +632,7 @@ swig -java -package com.bloggs.swig -outdir com/bloggs/swig example.i SWIG won't create the directory, so make sure it exists beforehand. -

      19.3.2 Functions

      +

      21.3.2 Functions

      @@ -666,7 +666,7 @@ System.out.println(example.fact(4));

    -

    19.3.3 Global variables

    +

    21.3.3 Global variables

    @@ -753,7 +753,7 @@ extern char *path; // Read-only (due to %immutable) -

    19.3.4 Constants

    +

    21.3.4 Constants

    @@ -885,7 +885,7 @@ Or if you decide this practice isn't so bad and your own class implements ex

    -

    19.3.5 Enumerations

    +

    21.3.5 Enumerations

    @@ -899,7 +899,7 @@ The final two approaches use simple integers for each enum item. Before looking at the various approaches for wrapping named C/C++ enums, anonymous enums are considered.

    -

    19.3.5.1 Anonymous enums

    +

    21.3.5.1 Anonymous enums

    @@ -960,7 +960,7 @@ As in the case of constants, you can access them through either the module class

    -

    19.3.5.2 Typesafe enums

    +

    21.3.5.2 Typesafe enums

    @@ -1051,7 +1051,7 @@ When upgrading to J2SDK 1.5 or later, proper Java enums could be used instead, w The following section details proper Java enum generation.

    -

    19.3.5.3 Proper Java enums

    +

    21.3.5.3 Proper Java enums

    @@ -1103,7 +1103,7 @@ The additional support methods need not be generated if none of the enum items h Simpler Java enums for enums without initializers section.

    -

    19.3.5.4 Type unsafe enums

    +

    21.3.5.4 Type unsafe enums

    @@ -1150,7 +1150,7 @@ Note that unlike typesafe enums, this approach requires users to mostly use diff Thus the upgrade path to proper enums provided in J2SDK 1.5 is more painful.

    -

    19.3.5.5 Simple enums

    +

    21.3.5.5 Simple enums

    @@ -1169,7 +1169,7 @@ SWIG-1.3.21 and earlier versions wrapped all enums using this approach. The type unsafe approach is preferable to this one and this simple approach is only included for backwards compatibility with these earlier versions of SWIG.

    -

    19.3.6 Pointers

    +

    21.3.6 Pointers

    @@ -1257,7 +1257,7 @@ C-style cast may return a bogus result whereas as the C++-style cast will return a NULL pointer if the conversion can't be performed.

    -

    19.3.7 Structures

    +

    21.3.7 Structures

    @@ -1425,7 +1425,7 @@ x.setA(3); // Modify x.a - this is the same as b.f.a -

    19.3.8 C++ classes

    +

    21.3.8 C++ classes

    @@ -1488,7 +1488,7 @@ int bar = Spam.getBar(); -

    19.3.9 C++ inheritance

    +

    21.3.9 C++ inheritance

    @@ -1549,7 +1549,7 @@ Note that Java does not support multiple inheritance so any multiple inheritance A warning is given when multiple inheritance is detected and only the first base class is used.

    -

    19.3.10 Pointers, references, arrays and pass by value

    +

    21.3.10 Pointers, references, arrays and pass by value

    @@ -1604,7 +1604,7 @@ to hold the result and a pointer is returned (Java will release this memory when the returned object's finalizer is run by the garbage collector).

    -

    19.3.10.1 Null pointers

    +

    21.3.10.1 Null pointers

    @@ -1628,7 +1628,7 @@ For spam1 and spam4 above the Java null gets translat The converse also occurs, that is, NULL pointers are translated into null Java objects when returned from a C/C++ function.

    -

    19.3.11 C++ overloaded functions

    +

    21.3.11 C++ overloaded functions

    @@ -1743,7 +1743,7 @@ void spam(short); // Ignored -

    19.3.12 C++ default arguments

    +

    21.3.12 C++ default arguments

    @@ -1786,7 +1786,7 @@ Further details on default arguments and how to restore this approach are given

    -

    19.3.13 C++ namespaces

    +

    21.3.13 C++ namespaces

    @@ -1846,7 +1846,7 @@ symbols separate, consider wrapping them as separate SWIG modules. Each SWIG module can be placed into a separate package.

    -

    19.3.14 C++ templates

    +

    21.3.14 C++ templates

    @@ -1895,7 +1895,7 @@ Obviously, there is more to template wrapping than shown in this example. More details can be found in the SWIG and C++ chapter.

    -

    19.3.15 C++ Smart Pointers

    +

    21.3.15 C++ Smart Pointers

    @@ -1979,7 +1979,7 @@ Foo f = p.__deref__(); // Returns underlying Foo * -

    19.4 Further details on the generated Java classes

    +

    21.4 Further details on the generated Java classes

    @@ -1994,7 +1994,7 @@ Finally enum classes are covered. First, the crucial intermediary JNI class is considered.

    -

    19.4.1 The intermediary JNI class

    +

    21.4.1 The intermediary JNI class

    @@ -2107,7 +2107,7 @@ If name is the same as modulename then the module class name g from modulename to modulenameModule.

    -

    19.4.1.1 The intermediary JNI class pragmas

    +

    21.4.1.1 The intermediary JNI class pragmas

    @@ -2186,7 +2186,7 @@ For example, let's change the intermediary JNI class access to public. All the methods in the intermediary JNI class will then be callable outside of the package as the method modifiers are public by default.

    -

    19.4.2 The Java module class

    +

    21.4.2 The Java module class

    @@ -2217,7 +2217,7 @@ example.egg(new Foo()); The primary reason for having the module class wrapping the calls in the intermediary JNI class is to implement static type checking. In this case only a Foo can be passed to the egg function, whereas any long can be passed to the egg function in the intermediary JNI class.

    -

    19.4.2.1 The Java module class pragmas

    +

    21.4.2.1 The Java module class pragmas

    @@ -2268,7 +2268,7 @@ See The intermediary JNI class pragmas section fo

    -

    19.4.3 Java proxy classes

    +

    21.4.3 Java proxy classes

    @@ -2342,7 +2342,7 @@ int y = f.spam(5, new Foo()); -

    19.4.3.1 Memory management

    +

    21.4.3.1 Memory management

    @@ -2504,7 +2504,7 @@ and

    -

    19.4.3.2 Inheritance

    +

    21.4.3.2 Inheritance

    @@ -2618,7 +2618,7 @@ However, true cross language polymorphism can be achieved using the 19.4.3.3 Proxy classes and garbage collection +

    21.4.3.3 Proxy classes and garbage collection

    @@ -2695,7 +2695,7 @@ The section on Java typemaps details how to specify -

    19.4.4 Type wrapper classes

    +

    21.4.4 Type wrapper classes

    @@ -2782,7 +2782,7 @@ public static void spam(SWIGTYPE_p_int x, SWIGTYPE_p_int y, int z) { ... } -

    19.4.5 Enum classes

    +

    21.4.5 Enum classes

    @@ -2791,7 +2791,7 @@ The Enumerations section discussed these but omitted The following sub-sections detail the various types of enum classes that can be generated.

    -

    19.4.5.1 Typesafe enum classes

    +

    21.4.5.1 Typesafe enum classes

    @@ -2867,7 +2867,7 @@ The swigValue method is used for marshalling in the other direction. The toString method is overridden so that the enum name is available.

    -

    19.4.5.2 Proper Java enum classes

    +

    21.4.5.2 Proper Java enum classes

    @@ -2939,7 +2939,7 @@ These needn't be generated if the enum being wrapped does not have any initializ Simpler Java enums for enums without initializers section describes how typemaps can be used to achieve this.

    -

    19.4.5.3 Type unsafe enum classes

    +

    21.4.5.3 Type unsafe enum classes

    @@ -2969,7 +2969,7 @@ public final class Beverage { -

    19.5 Cross language polymorphism using directors (experimental)

    +

    21.5 Cross language polymorphism using directors (experimental)

    @@ -2991,7 +2991,7 @@ The upshot is that C++ classes can be extended in Java and from C++ these extens Neither C++ code nor Java code needs to know where a particular method is implemented: the combination of proxy classes, director classes, and C wrapper functions transparently takes care of all the cross-language method routing.

    -

    19.5.1 Enabling directors

    +

    21.5.1 Enabling directors

    @@ -3062,7 +3062,7 @@ public: -

    19.5.2 Director classes

    +

    21.5.2 Director classes

    @@ -3089,7 +3089,7 @@ If the correct implementation is in Java, the Java API is used to call the metho

    -

    19.5.3 Overhead and code bloat

    +

    21.5.3 Overhead and code bloat

    @@ -3107,7 +3107,7 @@ This situation can be optimized by selectively enabling director methods (using

    -

    19.5.4 Simple directors example

    +

    21.5.4 Simple directors example

    @@ -3172,7 +3172,7 @@ directorDerived::upcall_method() invoked. -

    19.6 Common customization features

    +

    21.6 Common customization features

    @@ -3184,7 +3184,7 @@ be awkward. This section describes some common SWIG features that are used to improve the interface to existing C/C++ code.

    -

    19.6.1 C/C++ helper functions

    +

    21.6.1 C/C++ helper functions

    @@ -3250,7 +3250,7 @@ hard to implement. It is possible to improve on this using Java code, typemaps, customization features as covered in later sections, but sometimes helper functions are a quick and easy solution to difficult cases.

    -

    19.6.2 Class extension with %extend

    +

    21.6.2 Class extension with %extend

    @@ -3313,7 +3313,7 @@ Vector(2,3,4) in any way---the extensions only show up in the Java interface.

    -

    19.6.3 Exception handling with %exception and %javaexception

    +

    21.6.3 Exception handling with %exception and %javaexception

    @@ -3470,7 +3470,7 @@ to raise exceptions. See the SWIG Library ch The typemap example Handling C++ exception specifications as Java exceptions provides further exception handling capabilities.

    -

    19.6.4 Method access with %javamethodmodifiers

    +

    21.6.4 Method access with %javamethodmodifiers

    @@ -3496,7 +3496,7 @@ protected static void protect_me() { -

    19.7 Tips and techniques

    +

    21.7 Tips and techniques

    @@ -3506,7 +3506,7 @@ strings and arrays. This chapter discusses the common techniques for solving these problems.

    -

    19.7.1 Input and output parameters using primitive pointers and references

    +

    21.7.1 Input and output parameters using primitive pointers and references

    @@ -3680,7 +3680,7 @@ void foo(Bar *OUTPUT); will not have the intended effect since typemaps.i does not define an OUTPUT rule for Bar.

    -

    19.7.2 Simple pointers

    +

    21.7.2 Simple pointers

    @@ -3746,7 +3746,7 @@ System.out.println("3 + 4 = " + result); See the SWIG Library chapter for further details.

    -

    19.7.3 Wrapping C arrays with Java arrays

    +

    21.7.3 Wrapping C arrays with Java arrays

    @@ -3813,7 +3813,7 @@ Please be aware that the typemaps in this library are not efficient as all the e There is an alternative approach using the SWIG array library and this is covered in the next section.

    -

    19.7.4 Unbounded C Arrays

    +

    21.7.4 Unbounded C Arrays

    @@ -3958,7 +3958,7 @@ well suited for applications in which you need to create buffers, package binary data, etc.

    -

    19.8 Java typemaps

    +

    21.8 Java typemaps

    @@ -3979,7 +3979,7 @@ Before proceeding, it should be stressed that typemaps are not a required part of using SWIG---the default wrapping behavior is enough in most cases. Typemaps are only used if you want to change some aspect of the generated code. -

    19.8.1 Default primitive type mappings

    +

    21.8.1 Default primitive type mappings

    @@ -4130,7 +4130,7 @@ There is no perfect mapping between Java and C as Java doesn't support all the u However, the mappings allow the full range of values for each C type from Java.

    -

    19.8.2 Sixty four bit JVMs

    +

    21.8.2 Sixty four bit JVMs

    @@ -4143,7 +4143,7 @@ Unfortunately it won't of course hold true for JNI code.

    -

    19.8.3 What is a typemap?

    +

    21.8.3 What is a typemap?

    @@ -4266,7 +4266,7 @@ int c = example.count('e',"Hello World"); -

    19.8.4 Typemaps for mapping C/C++ types to Java types

    +

    21.8.4 Typemaps for mapping C/C++ types to Java types

    @@ -4456,7 +4456,7 @@ These are listed below: -

    19.8.5 Java typemap attributes

    +

    21.8.5 Java typemap attributes

    @@ -4486,7 +4486,7 @@ the union of the exception classes is added to the throws clause ensuring there See the NaN exception example for further usage.

    -

    19.8.6 Java special variables

    +

    21.8.6 Java special variables

    @@ -4621,7 +4621,7 @@ This special variable expands to the module name, as specified by %module$moduleJNI.

    -

    19.8.7 Typemaps for both C and C++ compilation

    +

    21.8.7 Typemaps for both C and C++ compilation

    @@ -4658,7 +4658,7 @@ If you do not intend your code to be targeting both C and C++ then your typemaps

    -

    19.8.8 Java code typemaps

    +

    21.8.8 Java code typemaps

    @@ -4848,7 +4848,7 @@ For the typemap to be used in all type wrapper classes, all the different types Again this is the same that is in "java.swg", barring the method modifier for getCPtr.

    -

    19.8.9 Director specific typemaps

    +

    21.8.9 Director specific typemaps

    @@ -5038,7 +5038,7 @@ The basic strategy here is to provide a default package typemap for the majority -

    19.9 Typemap Examples

    +

    21.9 Typemap Examples

    @@ -5048,7 +5048,7 @@ the SWIG library.

    -

    19.9.1 Simpler Java enums for enums without initializers

    +

    21.9.1 Simpler Java enums for enums without initializers

    @@ -5127,7 +5127,7 @@ This would be done by using the original versions of these typemaps in "enums.sw

    -

    19.9.2 Handling C++ exception specifications as Java exceptions

    +

    21.9.2 Handling C++ exception specifications as Java exceptions

    @@ -5252,7 +5252,7 @@ We could alternatively have used %rename to rename what() into

    -

    19.9.3 NaN Exception - exception handling for a particular type

    +

    21.9.3 NaN Exception - exception handling for a particular type

    @@ -5370,7 +5370,7 @@ If we were a martyr to the JNI cause, we could replace the succinct code within If we had, we would have put it in the "in" typemap which, like all JNI and Java typemaps, also supports the 'throws' attribute.

    -

    19.9.4 Converting Java String arrays to char **

    +

    21.9.4 Converting Java String arrays to char **

    @@ -5514,7 +5514,7 @@ Lastly the "jni", "jtype" and "jstype" typemaps are also required to specify what Java types to use.

    -

    19.9.5 Expanding a Java object to multiple arguments

    +

    21.9.5 Expanding a Java object to multiple arguments

    @@ -5596,7 +5596,7 @@ example.foo(new String[]{"red", "green", "blue", "white"}); -

    19.9.6 Using typemaps to return arguments

    +

    21.9.6 Using typemaps to return arguments

    @@ -5714,7 +5714,7 @@ $ java main 1 12.0 340.0 -

    19.9.7 Adding Java downcasts to polymorphic return types

    +

    21.9.7 Adding Java downcasts to polymorphic return types

    @@ -5920,7 +5920,7 @@ SWIG usually generates code which constructs the proxy classes using Java code a Note that the JNI code above uses a number of string lookups to call a constructor, whereas this would not occur using byte compiled Java code.

    -

    19.9.8 Adding an equals method to the Java classes

    +

    21.9.8 Adding an equals method to the Java classes

    @@ -5959,7 +5959,7 @@ System.out.println("foo1? " + foo1.equals(foo2)); -

    19.9.9 Void pointers and a common Java base class

    +

    21.9.9 Void pointers and a common Java base class

    @@ -6018,7 +6018,7 @@ This example contains some useful functionality which you may want in your code.

  • It also has a function which effectively implements a cast from the type of the proxy/type wrapper class to a void pointer. This is necessary for passing a proxy class or a type wrapper class to a function that takes a void pointer. -

    19.9.10 Struct pointer to pointer

    +

    21.9.10 Struct pointer to pointer

    @@ -6190,7 +6190,7 @@ The C functional interface has been completely morphed into an object-oriented i the Butler class would behave much like any pure Java class and feel more natural to Java users.

    -

    19.9.11 Memory management when returning references to member variables

    +

    21.9.11 Memory management when returning references to member variables

    @@ -6313,7 +6313,7 @@ public class Bike { Note the addReference call.

    -

    19.9.12 Memory management for objects passed to the C++ layer

    +

    21.9.12 Memory management for objects passed to the C++ layer

    @@ -6430,7 +6430,7 @@ The 'javacode' typemap simply adds in the specified code into the Java proxy cla -

    19.10 Living with Java Directors

    +

    21.10 Living with Java Directors

    @@ -6611,10 +6611,10 @@ public abstract class UserVisibleFoo extends Foo {

  • -

    19.11 Odds and ends

    +

    21.11 Odds and ends

    -

    19.11.1 JavaDoc comments

    +

    21.11.1 JavaDoc comments

    @@ -6670,7 +6670,7 @@ public class Barmy { -

    19.11.2 Functional interface without proxy classes

    +

    21.11.2 Functional interface without proxy classes

    @@ -6731,7 +6731,7 @@ All destructors have to be called manually for example the delete_Foo(foo) -

    19.11.3 Using your own JNI functions

    +

    21.11.3 Using your own JNI functions

    @@ -6781,7 +6781,7 @@ This directive is only really useful if you want to mix your own hand crafted JN

    -

    19.11.4 Performance concerns and hints

    +

    21.11.4 Performance concerns and hints

    @@ -6803,7 +6803,7 @@ This method normally calls the C++ destructor or free() for C code.

    -

    19.12 Examples

    +

    21.12 Examples

    diff --git a/Doc/Manual/Lisp.html b/Doc/Manual/Lisp.html index 38b899a36..440f83f9b 100644 --- a/Doc/Manual/Lisp.html +++ b/Doc/Manual/Lisp.html @@ -6,17 +6,23 @@ -

    30 SWIG and Common Lisp

    +

    16 SWIG and Common Lisp

    + +

    Common Lisp is a high-level, all-purpose, object-oriented, dynamic, functional programming language with long history. @@ -27,10 +33,19 @@ interfaces. SWIG currently supports only the Allegro Common Lisp, CLisp and UFFI foreign function interfaces.

    -

    30.1 Allegro Common Lisp

    +

    16.1 Allegro Common Lisp

    + +

    + Allegro Common Lisp support in SWIG has been updated to include + support for both C and C++. You can read about the interface + here

    -

    30.2 CLISP

    + + +

    16.2 CLISP

    + +

    CLISP is a feature-loaded implementation of common lisp which is portable across most of the @@ -56,7 +71,8 @@ swig -clispcl -module module-name file-name interface file for the CLISP module. The CLISP module tries to produce code which is both human readable and easily modifyable.

    -

    30.2.1 Additional Commandline Options

    +

    16.2.1 Additional Commandline Options

    +

    The following table list the additional commandline options available for the CLISP module. They can also be seen by using: @@ -88,7 +104,8 @@ and global variables will be created otherwise only definitions for
    -

    30.2.2 Details on CLISP bindings

    +

    16.2.2 Details on CLISP bindings

    +

    As mentioned earlier the CLISP bindings generated by SWIG may need @@ -211,7 +228,9 @@ struct bar { -

    30.3 UFFI

    +

    16.3 UFFI

    + +

    diff --git a/Doc/Manual/Lua.html b/Doc/Manual/Lua.html index b83cb69e1..90fafe664 100644 --- a/Doc/Manual/Lua.html +++ b/Doc/Manual/Lua.html @@ -6,7 +6,7 @@ -

    29 SWIG and Lua

    +

    31 SWIG and Lua

      @@ -49,7 +49,7 @@

      Lua is an extension programming language designed to support general procedural programming with data description facilities. It also offers good support for object-oriented programming, functional programming, and data-driven programming. Lua is intended to be used as a powerful, light-weight configuration language for any program that needs one. Lua is implemented as a library, written in clean C (that is, in the common subset of ANSI C and C++). Its also a really tiny language, less than 6000 lines of code, which compiles to <100 kilobytes of binary code. It can be found at http://www.lua.org

      -

      29.1 Preliminaries

      +

      31.1 Preliminaries

      @@ -58,7 +58,7 @@ The current SWIG implementation is designed to work with Lua 5.0. It should work

      Note: Lua 5.1 (alpha) has just (as of September 05) been released. The current version of SWIG will produce wrappers which are compatible with Lua 5.1, though the dynamic loading mechanism has changed (see below). The configure script and makefiles should work correctly with with Lua 5.1, though some small tweaks may be needed.

      -

      29.2 Running SWIG

      +

      31.2 Running SWIG

      @@ -90,7 +90,7 @@ This creates a C/C++ source file example_wrap.c or example_wrap.cxx

      The name of the wrapper file is derived from the name of the input file. For example, if the input file is example.i, the name of the wrapper file is example_wrap.c. To change this, you can use the -o option. The wrappered module will export one function "int Example_Init(LuaState* L)" which must be called to register the module with the Lua interpreter. The name "Example_Init" depends upon the name of the module. Note: SWIG will automatically capitalise the module name, so "module example;" becomes "Example_Init".

      -

      29.2.1 Compiling and Linking and Interpreter

      +

      31.2.1 Compiling and Linking and Interpreter

      @@ -137,7 +137,7 @@ $ gcc -c example.c -o example.o $ gcc -I/usr/include/lua -L/usr/lib/lua min.o example_wrap.o example.o -o my_lua

    -

    29.2.2 Compiling a dynamic module

    +

    31.2.2 Compiling a dynamic module

    @@ -173,7 +173,7 @@ The wrappers produced by SWIG can be compiled and linked with Lua 5.1. The loadi require("example") -

    29.2.3 Using your module

    +

    31.2.3 Using your module

    @@ -191,19 +191,19 @@ $ ./my_lua > -

    29.3 A tour of basic C/C++ wrapping

    +

    31.3 A tour of basic C/C++ wrapping

    By default, SWIG tries to build a very natural Lua interface to your C/C++ code. This section briefly covers the essential aspects of this wrapping.

    -

    29.3.1 Modules

    +

    31.3.1 Modules

    The SWIG module directive specifies the name of the Lua module. If you specify `module example', then everything is wrapped into a Lua table 'example' containing all the functions and variables. When choosing a module name, make sure you don't use the same name as a built-in Lua command or standard module name.

    -

    29.3.2 Functions

    +

    31.3.2 Functions

    @@ -241,7 +241,7 @@ It is also possible to rename the module with an assignment. 24 -

    29.3.3 Global variables

    +

    31.3.3 Global variables

    @@ -296,7 +296,7 @@ nil 3.142 -

    29.3.4 Constants and enums

    +

    31.3.4 Constants and enums

    @@ -319,7 +319,7 @@ example.SUNDAY=0

    Constants are not guaranteed to remain constant in Lua. The name of the constant could be accidentally reassigned to refer to some other object. Unfortunately, there is no easy way for SWIG to generate code that prevents this. You will just have to be careful.

    -

    29.3.5 Pointers

    +

    31.3.5 Pointers

    @@ -357,7 +357,7 @@ Lua enforces the integrity of its userdata, so it is virtually impossible to cor nil -

    29.3.6 Structures

    +

    31.3.6 Structures

    @@ -443,7 +443,7 @@ Because the pointer points inside the structure, you can modify the contents and > x.a = 3 -- Modifies the same structure -

    29.3.7 C++ classes

    +

    31.3.7 C++ classes

    @@ -503,7 +503,7 @@ It is not (currently) possible to access static members of an instance: -- does NOT work -

    29.3.8 C++ inheritance

    +

    31.3.8 C++ inheritance

    @@ -528,7 +528,7 @@ then the function spam() accepts a Foo pointer or a pointer to any clas

    It is safe to use multiple inheritance with SWIG.

    -

    29.3.9 Pointers, references, values, and arrays

    +

    31.3.9 Pointers, references, values, and arrays

    @@ -559,7 +559,7 @@ Foo spam7();

    then all three functions will return a pointer to some Foo object. Since the third function (spam7) returns a value, newly allocated memory is used to hold the result and a pointer is returned (Lua will release this memory when the return value is garbage collected). The other two are pointers which are assumed to be managed by the C code and so will not be garbage collected.

    -

    29.3.10 C++ overloaded functions

    +

    31.3.10 C++ overloaded functions

    @@ -645,7 +645,7 @@ Please refer to the "SWIG and C++" chapter for more information about overloadin

    Dealing with the Lua coercion mechanism, the priority is roughly (integers, floats, strings, userdata). But it is better to rename the functions rather than rely upon the ordering.

    -

    29.3.11 C++ operators

    +

    31.3.11 C++ operators

    @@ -760,7 +760,7 @@ It is also possible to overload the operator[], but currently this cann }; -

    29.3.12 Class extension with %extend

    +

    31.3.12 Class extension with %extend

    @@ -815,7 +815,7 @@ true

    Extend works with both C and C++ code, on classes and structs. It does not modify the underlying object in any way---the extensions only show up in the Lua interface. The only item to take note of is the code has to use the 'self' instead of 'this', and that you cannot access protected/private members of the code (as you are not officially part of the class).

    -

    29.3.13 C++ templates

    +

    31.3.13 C++ templates

    @@ -850,7 +850,7 @@ In Lua:

    Obviously, there is more to template wrapping than shown in this example. More details can be found in the SWIG and C++ chapter. Some more complicated examples will appear later.

    -

    29.3.14 C++ Smart Pointers

    +

    31.3.14 C++ Smart Pointers

    @@ -902,7 +902,7 @@ If you ever need to access the underlying pointer returned by operator->( > f = p:__deref__() -- Returns underlying Foo * -

    29.4 Details on the Lua binding

    +

    31.4 Details on the Lua binding

    @@ -913,7 +913,7 @@ If you ever need to access the underlying pointer returned by operator->(

    -

    29.4.1 Binding global data into the module.

    +

    31.4.1 Binding global data into the module.

    @@ -972,7 +972,7 @@ end

    That way when you call 'a=example.Foo', the interpreter looks at the table 'example' sees that there is no field 'Foo' and calls __index. This will in turn check in '.get' table and find the existence of 'Foo' and then return the value of the C function call 'Foo_get()'. Similarly for the code 'example.Foo=10', the interpreter will check the table, then call the __newindex which will then check the '.set' table and call the C function 'Foo_set(10)'.

    -

    29.4.2 Userdata and Metatables

    +

    31.4.2 Userdata and Metatables

    @@ -1052,7 +1052,7 @@ Note: Both the opaque structures (like the FILE*) and normal wrappered classes/s

    Note: Operator overloads are basically done in the same way, by adding functions such as '__add' & '__call' to the classes metatable. The current implementation is a bit rough as it will add any member function beginning with '__' into the metatable too, assuming its an operator overload.

    -

    29.4.3 Memory management

    +

    31.4.3 Memory management

    diff --git a/Doc/Manual/Modula3.html b/Doc/Manual/Modula3.html index 1a0b67e4a..06094b33d 100644 --- a/Doc/Manual/Modula3.html +++ b/Doc/Manual/Modula3.html @@ -5,7 +5,7 @@ -

    20 SWIG and Modula-3

    +

    22 SWIG and Modula-3

      @@ -57,7 +57,7 @@ especially typemaps.

      -

      20.1 Overview

      +

      22.1 Overview

      @@ -90,7 +90,7 @@ So the introduction got a bit longer than it should ... ;-)

      -

      20.1.1 Why not scripting ?

      +

      22.1.1 Why not scripting ?

      @@ -126,7 +126,7 @@ are not advantages of the language itself but can be provided by function libraries.

      -

      20.1.2 Why Modula-3 ?

      +

      22.1.2 Why Modula-3 ?

      @@ -166,7 +166,7 @@ it's statically typed, too.

      -

      20.1.3 Why C / C++ ?

      +

      22.1.3 Why C / C++ ?

      @@ -179,7 +179,7 @@ Even more fortunately even non-C libraries may provide C header files. This is where SWIG becomes helpful.

      -

      20.1.4 Why SWIG ?

      +

      22.1.4 Why SWIG ?

      @@ -252,10 +252,10 @@ integrate Modula-3 code into a C / C++ project.

      -

      20.2 Conception

      +

      22.2 Conception

      -

      20.2.1 Interfaces to C libraries

      +

      22.2.1 Interfaces to C libraries

      @@ -404,7 +404,7 @@ and the principal type must be renamed (%typemap).

      -

      20.2.2 Interfaces to C++ libraries

      +

      22.2.2 Interfaces to C++ libraries

      @@ -505,10 +505,10 @@ There is no C++ library I wrote a SWIG interface for, so I'm not sure if this is possible or sensible, yet.

      -

      20.3 Preliminaries

      +

      22.3 Preliminaries

      -

      20.3.1 Compilers

      +

      22.3.1 Compilers

      @@ -522,7 +522,7 @@ For testing examples I use Critical Mass cm3.

      -

      20.3.2 Additional Commandline Options

      +

      22.3.2 Additional Commandline Options

      @@ -599,10 +599,10 @@ Instead generate templates for some basic typemaps. -

      20.4 Modula-3 typemaps

      +

      22.4 Modula-3 typemaps

      -

      20.4.1 Inputs and outputs

      +

      22.4.1 Inputs and outputs

      @@ -818,7 +818,7 @@ consist of the following parts: -

      20.4.2 Subranges, Enumerations, Sets

      +

      22.4.2 Subranges, Enumerations, Sets

      @@ -870,7 +870,7 @@ that I'd like to automate.

      -

      20.4.3 Objects

      +

      22.4.3 Objects

      @@ -883,7 +883,7 @@ is not really useful, yet.

      -

      20.4.4 Imports

      +

      22.4.4 Imports

      @@ -918,7 +918,7 @@ IMPORT M3toC;

    -

    20.4.5 Exceptions

    +

    22.4.5 Exceptions

    @@ -942,7 +942,7 @@ you should declare %typemap("m3wrapinconv:throws") blah * %{OSError.E%}.

    -

    20.4.6 Example

    +

    22.4.6 Example

    @@ -989,10 +989,10 @@ where almost everything is generated by a typemap: -

    20.5 More hints to the generator

    +

    22.5 More hints to the generator

    -

    20.5.1 Features

    +

    22.5.1 Features

    @@ -1029,7 +1029,7 @@ where almost everything is generated by a typemap:
    -

    20.5.2 Pragmas

    +

    22.5.2 Pragmas

    @@ -1052,7 +1052,7 @@ where almost everything is generated by a typemap:
    -

    20.6 Remarks

    +

    22.6 Remarks

      diff --git a/Doc/Manual/Mzscheme.html b/Doc/Manual/Mzscheme.html index fb29ab887..191ef6f94 100644 --- a/Doc/Manual/Mzscheme.html +++ b/Doc/Manual/Mzscheme.html @@ -8,7 +8,7 @@ -

      21 SWIG and MzScheme

      +

      23 SWIG and MzScheme

        @@ -22,7 +22,7 @@

        This section contains information on SWIG's support of MzScheme. -

        21.1 Creating native MzScheme structures

        +

        23.1 Creating native MzScheme structures

        diff --git a/Doc/Manual/Ocaml.html b/Doc/Manual/Ocaml.html index 5938e1216..f0a1f4375 100644 --- a/Doc/Manual/Ocaml.html +++ b/Doc/Manual/Ocaml.html @@ -6,7 +6,7 @@ -

        22 SWIG and Ocaml

        +

        24 SWIG and Ocaml

          @@ -80,7 +80,7 @@ If you're not familiar with the Objective Caml language, you can visit The Ocaml Website.

          -

          22.1 Preliminaries

          +

          24.1 Preliminaries

          @@ -99,7 +99,7 @@ file Examples/Makefile illustrate how to compile and link SWIG modules that will be loaded dynamically. This has only been tested on Linux so far.

          -

          22.1.1 Running SWIG

          +

          24.1.1 Running SWIG

          @@ -122,7 +122,7 @@ you will compile the file example_wrap.c with ocamlc or the resulting .ml and .mli files as well, and do the final link with -custom (not needed for native link).

          -

          22.1.2 Compiling the code

          +

          24.1.2 Compiling the code

          @@ -158,7 +158,7 @@ the user more freedom with respect to custom typing.

        -

        22.1.3 The camlp4 module

        +

        24.1.3 The camlp4 module

        @@ -234,7 +234,7 @@ let b = C_string (getenv "PATH") -

        22.1.4 Using your module

        +

        24.1.4 Using your module

        @@ -248,7 +248,7 @@ When linking any ocaml bytecode with your module, use the -custom option is not needed when you build native code.

        -

        22.1.5 Compilation problems and compiling with C++

        +

        24.1.5 Compilation problems and compiling with C++

        @@ -259,7 +259,7 @@ liberal with pointer types may not compile under the C++ compiler. Most code meant to be compiled as C++ will not have problems.

        -

        22.2 The low-level Ocaml/C interface

        +

        24.2 The low-level Ocaml/C interface

        @@ -360,7 +360,7 @@ is that you must append them to the return list with swig_result = caml_list_a signature for a function that uses value in this way.

        -

        22.2.1 The generated module

        +

        24.2.1 The generated module

        @@ -394,7 +394,7 @@ it describes the output SWIG will generate for class definitions. -

        22.2.2 Enums

        +

        24.2.2 Enums

        @@ -457,7 +457,7 @@ val x : Enum_test.c_obj = C_enum `a

      -

      22.2.2.1 Enum typing in Ocaml

      +

      24.2.2.1 Enum typing in Ocaml

      @@ -470,10 +470,10 @@ functions imported from different modules. You must convert values to master values using the swig_val function before sharing them with another module.

      -

      22.2.3 Arrays

      +

      24.2.3 Arrays

      -

      22.2.3.1 Simple types of bounded arrays

      +

      24.2.3.1 Simple types of bounded arrays

      @@ -494,7 +494,7 @@ arrays of simple types with known bounds in your code, but this only works for arrays whose bounds are completely specified.

      -

      22.2.3.2 Complex and unbounded arrays

      +

      24.2.3.2 Complex and unbounded arrays

      @@ -507,7 +507,7 @@ SWIG can't predict which of these methods will be used in the array, so you have to specify it for yourself in the form of a typemap.

      -

      22.2.3.3 Using an object

      +

      24.2.3.3 Using an object

      @@ -521,7 +521,7 @@ Consider writing an object when the ending condition of your array is complex, such as using a required centinel, etc.

      -

      22.2.3.4 Example typemap for a function taking float * and int

      +

      24.2.3.4 Example typemap for a function taking float * and int

      @@ -572,7 +572,7 @@ void printfloats( float *tab, int len ); -

      22.2.4 C++ Classes

      +

      24.2.4 C++ Classes

      @@ -615,7 +615,7 @@ the underlying pointer, so using create_[x]_from_ptr alters the returned value for the same object.

      -

      22.2.4.1 STL vector and string Example

      +

      24.2.4.1 STL vector and string Example

      @@ -695,7 +695,7 @@ baz # -

      22.2.4.2 C++ Class Example

      +

      24.2.4.2 C++ Class Example

      @@ -725,7 +725,7 @@ public: }; -

      22.2.4.3 Compiling the example

      +

      24.2.4.3 Compiling the example

      @@ -743,7 +743,7 @@ bash-2.05a$ ocamlmktop -custom swig.cmo -I `camlp4 -where` \
         -L$QTPATH/lib -cclib -lqt
       
      -

      22.2.4.4 Sample Session

      +

      24.2.4.4 Sample Session

      @@ -770,10 +770,10 @@ Assuming you have a working installation of QT, you will see a window
       containing the string "hi" in a button.  
       

      -

      22.2.5 Director Classes

      +

      24.2.5 Director Classes

      -

      22.2.5.1 Director Introduction

      +

      24.2.5.1 Director Introduction

      @@ -800,7 +800,7 @@ class foo { };

      -

      22.2.5.2 Overriding Methods in Ocaml

      +

      24.2.5.2 Overriding Methods in Ocaml

      @@ -828,7 +828,7 @@ In this example, I'll examine the objective caml code involved in providing an overloaded class. This example is contained in Examples/ocaml/shapes.

      -

      22.2.5.3 Director Usage Example

      +

      24.2.5.3 Director Usage Example

      @@ -887,7 +887,7 @@ in a more effortless style in ocaml, while leaving the "engine" part of the program in C++.

      -

      22.2.5.4 Creating director objects

      +

      24.2.5.4 Creating director objects

      @@ -928,7 +928,7 @@ object from causing a core dump, as long as the object is destroyed properly.

      -

      22.2.5.5 Typemaps for directors, directorin, directorout, directorargout

      +

      24.2.5.5 Typemaps for directors, directorin, directorout, directorargout

      @@ -939,7 +939,7 @@ well as a function return value in the same way you provide function arguments, and to receive arguments the same way you normally receive function returns.

      -

      22.2.5.6 directorin typemap

      +

      24.2.5.6 directorin typemap

      @@ -950,7 +950,7 @@ code receives when you are called. In general, a simple directorin typ can use the same body as a simple out typemap.

      -

      22.2.5.7 directorout typemap

      +

      24.2.5.7 directorout typemap

      @@ -961,7 +961,7 @@ for the same type, except when there are special requirements for object ownership, etc.

      -

      22.2.5.8 directorargout typemap

      +

      24.2.5.8 directorargout typemap

      @@ -978,7 +978,7 @@ In the event that you don't specify all of the necessary values, integral values will read zero, and struct or object returns have undefined results.

      -

      22.2.6 Exceptions

      +

      24.2.6 Exceptions

      diff --git a/Doc/Manual/Perl5.html b/Doc/Manual/Perl5.html index dbb8883e3..a44fba7d9 100644 --- a/Doc/Manual/Perl5.html +++ b/Doc/Manual/Perl5.html @@ -6,7 +6,7 @@ -

      23 SWIG and Perl5

      +

      25 SWIG and Perl5

        @@ -86,7 +86,7 @@ later. Earlier versions are problematic and SWIG generated extensions may not compile or run correctly.

        -

        23.1 Overview

        +

        25.1 Overview

        @@ -107,7 +107,7 @@ described. Advanced customization features, typemaps, and other options are found near the end of the chapter.

        -

        23.2 Preliminaries

        +

        25.2 Preliminaries

        @@ -132,7 +132,7 @@ To build the module, you will need to compile the file example_wrap.c and link it with the rest of your program.

        -

        23.2.1 Getting the right header files

        +

        25.2.1 Getting the right header files

        @@ -164,7 +164,7 @@ loaded, an easy way to find out is to run Perl itself.

      -

      23.2.2 Compiling a dynamic module

      +

      25.2.2 Compiling a dynamic module

      @@ -197,7 +197,7 @@ the target should be named `example.so', `example.sl', or the appropriate dynamic module name on your system.

      -

      23.2.3 Building a dynamic module with MakeMaker

      +

      25.2.3 Building a dynamic module with MakeMaker

      @@ -231,7 +231,7 @@ the preferred approach to compilation. More information about MakeMaker can be found in "Programming Perl, 2nd ed." by Larry Wall, Tom Christiansen, and Randal Schwartz.

      -

      23.2.4 Building a static version of Perl

      +

      25.2.4 Building a static version of Perl

      @@ -300,7 +300,7 @@ added to it. Depending on your machine, you may need to link with additional libraries such as -lsocket, -lnsl, -ldl, etc.

      -

      23.2.5 Using the module

      +

      25.2.5 Using the module

      @@ -455,7 +455,7 @@ system configuration (this requires root access and you will need to read the man pages).

      -

      23.2.6 Compilation problems and compiling with C++

      +

      25.2.6 Compilation problems and compiling with C++

      @@ -598,7 +598,7 @@ have to find the macro that conflicts and add an #undef into the .i file. Pleas any conflicting macros you find to swig mailing list.

      -

      23.2.7 Compiling for 64-bit platforms

      +

      25.2.7 Compiling for 64-bit platforms

      @@ -625,7 +625,7 @@ also introduce problems on platforms that support more than one linking standard (e.g., -o32 and -n32 on Irix).

      -

      23.3 Building Perl Extensions under Windows

      +

      25.3 Building Perl Extensions under Windows

      @@ -636,7 +636,7 @@ section assumes you are using SWIG with Microsoft Visual C++ although the procedure may be similar with other compilers.

      -

      23.3.1 Running SWIG from Developer Studio

      +

      25.3.1 Running SWIG from Developer Studio

      @@ -699,7 +699,7 @@ print "$a\n"; -

      23.3.2 Using other compilers

      +

      25.3.2 Using other compilers

      @@ -707,7 +707,7 @@ SWIG is known to work with Cygwin and may work with other compilers on Windows. For general hints and suggestions refer to the Windows chapter.

      -

      23.4 The low-level interface

      +

      25.4 The low-level interface

      @@ -717,7 +717,7 @@ can be used to control your application. However, it is also used to construct more user-friendly proxy classes as described in the next section.

      -

      23.4.1 Functions

      +

      25.4.1 Functions

      @@ -740,7 +740,7 @@ use example; $a = &example::fact(2); -

      23.4.2 Global variables

      +

      25.4.2 Global variables

      @@ -810,7 +810,7 @@ extern char *path; // Declared later in the input -

      23.4.3 Constants

      +

      25.4.3 Constants

      @@ -837,7 +837,7 @@ $example::FOO = 2; # Error -

      23.4.4 Pointers

      +

      25.4.4 Pointers

      @@ -946,7 +946,7 @@ as XS and xsubpp. Given the advancement of the SWIG typesystem and the SWIG and XS, this is no longer supported.

      -

      23.4.5 Structures

      +

      25.4.5 Structures

      @@ -1080,7 +1080,7 @@ void Bar_f_set(Bar *b, Foo *val) { -

      23.4.6 C++ classes

      +

      25.4.6 C++ classes

      @@ -1145,7 +1145,7 @@ provides direct access to C++ objects. A higher level interface using Perl prox can be built using these low-level accessors. This is described shortly.

      -

      23.4.7 C++ classes and type-checking

      +

      25.4.7 C++ classes and type-checking

      @@ -1181,7 +1181,7 @@ If necesssary, the type-checker also adjusts the value of the pointer (as is nec multiple inheritance is used).

      -

      23.4.8 C++ overloaded functions

      +

      25.4.8 C++ overloaded functions

      @@ -1225,7 +1225,7 @@ example::Spam_foo_d($s,3.14); Please refer to the "SWIG Basics" chapter for more information.

      -

      23.4.9 Operators

      +

      25.4.9 Operators

      @@ -1258,7 +1258,7 @@ $c = example::add_complex($a,$b); Some preliminary work on mapping C++ operators into Perl operators has been completed. This is covered later.

      -

      23.4.10 Modules and packages

      +

      25.4.10 Modules and packages

      @@ -1325,7 +1325,7 @@ print Foo::fact(4),"\n"; # Call a function in package FooBar --> -

      23.5 Input and output parameters

      +

      25.5 Input and output parameters

      @@ -1544,7 +1544,7 @@ print "$c\n"; Note: The REFERENCE feature is only currently supported for numeric types (integers and floating point).

      -

      23.6 Exception handling

      +

      25.6 Exception handling

      @@ -1709,7 +1709,7 @@ This is still supported, but it is deprecated. The newer %exception di functionality, but it has additional capabilities that make it more powerful.

      -

      23.7 Remapping datatypes with typemaps

      +

      25.7 Remapping datatypes with typemaps

      @@ -1726,7 +1726,7 @@ Typemaps are only used if you want to change some aspect of the primitive C-Perl interface.

      -

      23.7.1 A simple typemap example

      +

      25.7.1 A simple typemap example

      @@ -1830,7 +1830,7 @@ example::count("e","Hello World"); -

      23.7.2 Perl5 typemaps

      +

      25.7.2 Perl5 typemaps

      @@ -1935,7 +1935,7 @@ Return of C++ member data (all languages). Check value of input parameter. -

      23.7.3 Typemap variables

      +

      25.7.3 Typemap variables

      @@ -2006,7 +2006,7 @@ properly assigned. The Perl name of the wrapper function being created. -

      23.7.4 Useful functions

      +

      25.7.4 Useful functions

      @@ -2075,7 +2075,7 @@ int sv_isa(SV *, char *0; -

      23.8 Typemap Examples

      +

      25.8 Typemap Examples

      @@ -2084,7 +2084,7 @@ might look at the files "perl5.swg" and "typemaps.i" in the SWIG library.

      -

      23.8.1 Converting a Perl5 array to a char **

      +

      25.8.1 Converting a Perl5 array to a char **

      @@ -2176,7 +2176,7 @@ print @$b,"\n"; # Print it out -

      23.8.2 Return values

      +

      25.8.2 Return values

      @@ -2205,7 +2205,7 @@ can be done using the EXTEND() macro as in : } -

      23.8.3 Returning values from arguments

      +

      25.8.3 Returning values from arguments

      @@ -2259,7 +2259,7 @@ print "multout(7,13) = @r\n"; ($x,$y) = multout(7,13); -

      23.8.4 Accessing array structure members

      +

      25.8.4 Accessing array structure members

      @@ -2322,7 +2322,7 @@ the "in" typemap in the previous section would be used to convert an to copy the converted array into a C data structure.

      -

      23.8.5 Turning Perl references into C pointers

      +

      25.8.5 Turning Perl references into C pointers

      @@ -2387,7 +2387,7 @@ print "$c\n"; -

      23.8.6 Pointer handling

      +

      25.8.6 Pointer handling

      @@ -2466,7 +2466,7 @@ For example: -

      23.9 Proxy classes

      +

      25.9 Proxy classes

      @@ -2482,7 +2482,7 @@ to the underlying code. This section describes the implementation details of the proxy interface.

      -

      23.9.1 Preliminaries

      +

      25.9.1 Preliminaries

      @@ -2504,7 +2504,7 @@ SWIG creates a collection of high-level Perl wrappers. In your scripts, you wil high level wrappers. The wrappers, in turn, interact with the low-level procedural module.

      -

      23.9.2 Structure and class wrappers

      +

      25.9.2 Structure and class wrappers

      @@ -2630,7 +2630,7 @@ $v->DESTROY(); -

      23.9.3 Object Ownership

      +

      25.9.3 Object Ownership

      @@ -2717,7 +2717,7 @@ counting, garbage collection, or advanced features one might find in sophisticated languages.

      -

      23.9.4 Nested Objects

      +

      25.9.4 Nested Objects

      @@ -2770,7 +2770,7 @@ $p->{f}->{x} = 0.0; %${$p->{v}} = ( x=>0, y=>0, z=>0); -

      23.9.5 Proxy Functions

      +

      25.9.5 Proxy Functions

      @@ -2804,7 +2804,7 @@ This function replaces the original function, but operates in an identical manner.

      -

      23.9.6 Inheritance

      +

      25.9.6 Inheritance

      @@ -2880,7 +2880,7 @@ particular, inheritance of data members is extremely tricky (and I'm not even sure if it really works).

      -

      23.9.7 Modifying the proxy methods

      +

      25.9.7 Modifying the proxy methods

      diff --git a/Doc/Manual/Php.html b/Doc/Manual/Php.html index 40f8bbf0d..e417a34e7 100644 --- a/Doc/Manual/Php.html +++ b/Doc/Manual/Php.html @@ -7,7 +7,7 @@ -

      24 SWIG and PHP4

      +

      26 SWIG and PHP4

        @@ -66,7 +66,7 @@ extension into php directly (without having the overhead of loading it into each script), you will need the complete PHP source tree available.

        -

        24.1 Generating PHP4 Extensions

        +

        26.1 Generating PHP4 Extensions

        @@ -104,7 +104,7 @@ script. The first choice is the default, however it can be changed by passing the '-phpfull' command line switch to select the second build method.

        -

        24.1.1 Building a loadable extension

        +

        26.1.1 Building a loadable extension

        @@ -194,7 +194,7 @@ additional optional arguments:

      • -dlname "<name>" Changes the name of the generated shared object.
      -

      24.1.2 Building extensions into PHP

      +

      26.1.2 Building extensions into PHP

      @@ -252,7 +252,7 @@ which contains your new module. You can test it with a php script which does not have the 'dl' command as used above.

      -

      24.1.3 Using PHP4 Extensions

      +

      26.1.3 Using PHP4 Extensions

      @@ -275,7 +275,7 @@ attempts to do the dl() call for you: -

      24.2 Basic PHP4 interface

      +

      26.2 Basic PHP4 interface

      @@ -285,7 +285,7 @@ possible for names of symbols in one extension module to clash with other symbols unless care is taken to %rename them.

      -

      24.2.1 Constants

      +

      26.2.1 Constants

      @@ -410,7 +410,7 @@ both point to the same value, without the case test taking place. ( Apologies, this paragraph needs rewriting to make some sense. )

      -

      24.2.2 Global Variables

      +

      26.2.2 Global Variables

      @@ -459,7 +459,7 @@ undefined. At this time SWIG does not support custom accessor methods.

      -

      24.2.3 Functions

      +

      26.2.3 Functions

      @@ -510,7 +510,7 @@ print $s; # The value of $s was not changed.

      -

      24.2.4 Overloading

      +

      26.2.4 Overloading

      @@ -564,7 +564,7 @@ Cause less confusion and doit("2"); will invoke the function taking the integer argument.

      -

      24.2.5 Pointers and References

      +

      26.2.5 Pointers and References

      @@ -696,7 +696,7 @@ PHP in a number of ways: by using unset on an existing variable, or assigning NULL to a variable.

      -

      24.2.6 Structures and C++ classes

      +

      26.2.6 Structures and C++ classes

      @@ -755,7 +755,7 @@ Would be used in the following way: Member variables and methods are accessed using the -> operator.

      -

      24.2.6.1 Using -noproxy

      +

      26.2.6.1 Using -noproxy

      @@ -780,7 +780,7 @@ Complex_im_set($obj,$d); Complex_im_get($obj); -

      24.2.6.2 Constructors and Destructors

      +

      26.2.6.2 Constructors and Destructors

      @@ -821,7 +821,7 @@ the programmer can either reassign the variable or call unset($v)

      -

      24.2.6.3 Static Member Variables

      +

      26.2.6.3 Static Member Variables

      @@ -861,7 +861,7 @@ Ko::threats(10); echo "There has now been " . Ko::threats() . " threats\n"; -

      24.2.6.4 Static Member Functions

      +

      26.2.6.4 Static Member Functions

      @@ -883,7 +883,7 @@ Ko::threats(); -

      24.2.7 PHP4 Pragmas, Startup and Shutdown code

      +

      26.2.7 PHP4 Pragmas, Startup and Shutdown code

      diff --git a/Doc/Manual/Pike.html b/Doc/Manual/Pike.html index c38e97fdf..cc9d8fd28 100644 --- a/Doc/Manual/Pike.html +++ b/Doc/Manual/Pike.html @@ -6,7 +6,7 @@ -

      25 SWIG and Pike

      +

      27 SWIG and Pike

        @@ -46,10 +46,10 @@ least, make sure you read the "SWIG Basics" chapter.

        -

        25.1 Preliminaries

        +

        27.1 Preliminaries

        -

        25.1.1 Running SWIG

        +

        27.1.1 Running SWIG

        @@ -94,7 +94,7 @@ can use the -o option:

        $ swig -pike -o pseudonym.c example.i
        -

        25.1.2 Getting the right header files

        +

        27.1.2 Getting the right header files

        @@ -114,7 +114,7 @@ You're looking for files with the names global.h, program.h and so on.

        -

        25.1.3 Using your module

        +

        27.1.3 Using your module

        @@ -129,10 +129,10 @@ Pike v7.4 release 10 running Hilfe v3.5 (Incremental Pike Frontend) (1) Result: 24

      -

      25.2 Basic C/C++ Mapping

      +

      27.2 Basic C/C++ Mapping

      -

      25.2.1 Modules

      +

      27.2.1 Modules

      @@ -143,7 +143,7 @@ concerned), SWIG's %module directive doesn't really have any significance.

      -

      25.2.2 Functions

      +

      27.2.2 Functions

      @@ -168,7 +168,7 @@ exactly as you'd expect it to: (1) Result: 24 -

      25.2.3 Global variables

      +

      27.2.3 Global variables

      @@ -197,7 +197,7 @@ will result in two functions, Foo_get() and Foo_set(): (3) Result: 3.141590 -

      25.2.4 Constants and enumerated types

      +

      27.2.4 Constants and enumerated types

      @@ -205,7 +205,7 @@ Enumerated types in C/C++ declarations are wrapped as Pike constants, not as Pike enums.

      -

      25.2.5 Constructors and Destructors

      +

      27.2.5 Constructors and Destructors

      @@ -213,7 +213,7 @@ Constructors are wrapped as create() methods, and destructors are wrapped as destroy() methods, for Pike classes.

      -

      25.2.6 Static Members

      +

      27.2.6 Static Members

      diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index 9a6eac530..3021d2b45 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -6,7 +6,7 @@ -

      26 SWIG and Python

      +

      28 SWIG and Python

        @@ -126,7 +126,7 @@ very least, make sure you read the "SWIG Basics" chapter.

        -

        26.1 Overview

        +

        28.1 Overview

        @@ -153,10 +153,10 @@ described followed by a discussion of low-level implementation details.

        -

        26.2 Preliminaries

        +

        28.2 Preliminaries

        -

        26.2.1 Running SWIG

        +

        28.2.1 Running SWIG

        @@ -205,7 +205,7 @@ from the module name specified with %module. If the module name is example.py is created.

        -

        26.2.2 Getting the right header files

        +

        28.2.2 Getting the right header files

        @@ -236,7 +236,7 @@ Type "copyright", "credits" or "license" for more information.

      -

      26.2.3 Compiling a dynamic module

      +

      28.2.3 Compiling a dynamic module

      @@ -282,10 +282,10 @@ module actually consists of two files; socket.py and _socket.so. Many other built-in Python modules follow a similar convention.

      -

      26.2.4 Using distutils

      +

      28.2.4 Using distutils

      -

      26.2.5 Static linking

      +

      28.2.5 Static linking

      @@ -364,7 +364,7 @@ If using static linking, you might want to rely on a different approach (perhaps using distutils).

      -

      26.2.6 Using your module

      +

      28.2.6 Using your module

      @@ -521,7 +521,7 @@ system configuration (this requires root access and you will need to read the man pages).

      -

      26.2.7 Compilation of C++ extensions

      +

      28.2.7 Compilation of C++ extensions

      @@ -618,7 +618,7 @@ erratic program behavior. If working with lots of software components, you might want to investigate using a more formal standard such as COM.

      -

      26.2.8 Compiling for 64-bit platforms

      +

      28.2.8 Compiling for 64-bit platforms

      @@ -655,7 +655,7 @@ and -m64 allow you to choose the desired binary format for your python extension.

      -

      26.2.9 Building Python Extensions under Windows

      +

      28.2.9 Building Python Extensions under Windows

      @@ -744,7 +744,7 @@ you may want to consult the 26.3 A tour of basic C/C++ wrapping +

      28.3 A tour of basic C/C++ wrapping

      @@ -753,7 +753,7 @@ to your C/C++ code. Functions are wrapped as functions, classes are wrapped as This section briefly covers the essential aspects of this wrapping.

      -

      26.3.1 Modules

      +

      28.3.1 Modules

      @@ -766,7 +766,7 @@ module name, make sure you don't use the same name as a built-in Python command or standard module name.

      -

      26.3.2 Functions

      +

      28.3.2 Functions

      @@ -790,7 +790,7 @@ like you think it does: >>> -

      26.3.3 Global variables

      +

      28.3.3 Global variables

      @@ -928,7 +928,7 @@ that starts with a leading underscore. SWIG does not create cvar if there are no global variables in a module.

      -

      26.3.4 Constants and enums

      +

      28.3.4 Constants and enums

      @@ -968,7 +968,7 @@ other object. Unfortunately, there is no easy way for SWIG to generate code that prevents this. You will just have to be careful.

      -

      26.3.5 Pointers

      +

      28.3.5 Pointers

      @@ -1109,7 +1109,7 @@ C-style cast may return a bogus result whereas as the C++-style cast will return None if the conversion can't be performed.

      -

      26.3.6 Structures

      +

      28.3.6 Structures

      @@ -1298,7 +1298,7 @@ everything works just like you would expect. For example: -

      26.3.7 C++ classes

      +

      28.3.7 C++ classes

      @@ -1387,7 +1387,7 @@ they are accessed through cvar like this: -

      26.3.8 C++ inheritance

      +

      28.3.8 C++ inheritance

      @@ -1442,7 +1442,7 @@ then the function spam() accepts Foo * or a pointer to any cla It is safe to use multiple inheritance with SWIG.

      -

      26.3.9 Pointers, references, values, and arrays

      +

      28.3.9 Pointers, references, values, and arrays

      @@ -1503,7 +1503,7 @@ treated as a returning value, and it will follow the same allocation/deallocation process.

      -

      26.3.10 C++ overloaded functions

      +

      28.3.10 C++ overloaded functions

      @@ -1626,7 +1626,7 @@ first declaration takes precedence. Please refer to the "SWIG and C++" chapter for more information about overloading.

      -

      26.3.11 C++ operators

      +

      28.3.11 C++ operators

      @@ -1715,7 +1715,7 @@ Also, be aware that certain operators don't map cleanly to Python. For instance overloaded assignment operators don't map to Python semantics and will be ignored.

      -

      26.3.12 C++ namespaces

      +

      28.3.12 C++ namespaces

      @@ -1782,7 +1782,7 @@ utilizes thousands of small deeply nested namespaces each with identical symbol names, well, then you get what you deserve.

      -

      26.3.13 C++ templates

      +

      28.3.13 C++ templates

      @@ -1835,7 +1835,7 @@ More details can be found in the SWIG and C++ -

      26.3.14 C++ Smart Pointers

      +

      28.3.14 C++ Smart Pointers

      @@ -1920,7 +1920,7 @@ simply use the __deref__() method. For example: -

      26.3.15 C++ Reference Counted Objects (ref/unref)

      +

      28.3.15 C++ Reference Counted Objects (ref/unref)

      @@ -2062,7 +2062,7 @@ python releases the shadow instance.

      -

      26.4 Further details on the Python class interface

      +

      28.4 Further details on the Python class interface

      @@ -2075,7 +2075,7 @@ of low-level details were omitted. This section provides a brief overview of how the proxy classes work.

      -

      26.4.1 Proxy classes

      +

      28.4.1 Proxy classes

      @@ -2164,7 +2164,7 @@ you can attach new Python methods to the class and you can even inherit from it by Python built-in types until Python 2.2).

      -

      26.4.2 Memory management

      +

      28.4.2 Memory management

      @@ -2351,7 +2351,7 @@ It is also possible to deal with situations like this using typemaps--an advanced topic discussed later.

      -

      26.4.3 Python 2.2 and classic classes

      +

      28.4.3 Python 2.2 and classic classes

      @@ -2388,7 +2388,7 @@ class itself. In Python-2.1 and earlier, they have to be accessed as a global function or through an instance (see the earlier section).

      -

      26.5 Cross language polymorphism

      +

      28.5 Cross language polymorphism

      @@ -2422,7 +2422,7 @@ proxy classes, director classes, and C wrapper functions takes care of all the cross-language method routing transparently.

      -

      26.5.1 Enabling directors

      +

      28.5.1 Enabling directors

      @@ -2515,7 +2515,7 @@ class MyFoo(mymodule.Foo): -

      26.5.2 Director classes

      +

      28.5.2 Director classes

      @@ -2597,7 +2597,7 @@ so there is no need for the extra overhead involved with routing the calls through Python.

      -

      26.5.3 Ownership and object destruction

      +

      28.5.3 Ownership and object destruction

      @@ -2664,7 +2664,7 @@ deleting all the Foo pointers it contains at some point. Note that no hard references to the Foo objects remain in Python.

      -

      26.5.4 Exception unrolling

      +

      28.5.4 Exception unrolling

      @@ -2723,7 +2723,7 @@ Swig::DirectorMethodException is thrown, Python will register the exception as soon as the C wrapper function returns.

      -

      26.5.5 Overhead and code bloat

      +

      28.5.5 Overhead and code bloat

      @@ -2757,7 +2757,7 @@ directive) for only those methods that are likely to be extended in Python.

      -

      26.5.6 Typemaps

      +

      28.5.6 Typemaps

      @@ -2771,7 +2771,7 @@ need to be supported.

      -

      26.5.7 Miscellaneous

      +

      28.5.7 Miscellaneous

      @@ -2818,7 +2818,7 @@ methods that return const references.

      -

      26.6 Common customization features

      +

      28.6 Common customization features

      @@ -2831,7 +2831,7 @@ This section describes some common SWIG features that are used to improve your the interface to an extension module.

      -

      26.6.1 C/C++ helper functions

      +

      28.6.1 C/C++ helper functions

      @@ -2912,7 +2912,7 @@ hard to implement. It is possible to clean this up using Python code, typemaps, customization features as covered in later sections.

      -

      26.6.2 Adding additional Python code

      +

      28.6.2 Adding additional Python code

      @@ -2966,7 +2966,7 @@ what can be done without having to rely on any of the more advanced customization features.

      -

      26.6.3 Class extension with %extend

      +

      28.6.3 Class extension with %extend

      @@ -3055,7 +3055,7 @@ Vector(12,14,16) in any way---the extensions only show up in the Python interface.

      -

      26.6.4 Exception handling with %exception

      +

      28.6.4 Exception handling with %exception

      @@ -3181,7 +3181,7 @@ The language-independent exception.i library file can also be used to raise exceptions. See the SWIG Library chapter.

      -

      26.7 Tips and techniques

      +

      28.7 Tips and techniques

      @@ -3191,7 +3191,7 @@ strings, binary data, and arrays. This chapter discusses the common techniques solving these problems.

      -

      26.7.1 Input and output parameters

      +

      28.7.1 Input and output parameters

      @@ -3404,7 +3404,7 @@ void foo(Bar *OUTPUT); may not have the intended effect since typemaps.i does not define an OUTPUT rule for Bar.

      -

      26.7.2 Simple pointers

      +

      28.7.2 Simple pointers

      @@ -3473,7 +3473,7 @@ If you replace %pointer_functions() by %pointer_class(type,name)SWIG Library chapter for further details.

      -

      26.7.3 Unbounded C Arrays

      +

      28.7.3 Unbounded C Arrays

      @@ -3535,7 +3535,7 @@ well suited for applications in which you need to create buffers, package binary data, etc.

      -

      26.7.4 String handling

      +

      28.7.4 String handling

      @@ -3604,16 +3604,16 @@ If you need to return binary data, you might use the also be used to extra binary data from arbitrary pointers.

      -

      26.7.5 Arrays

      +

      28.7.5 Arrays

      -

      26.7.6 String arrays

      +

      28.7.6 String arrays

      -

      26.7.7 STL wrappers

      +

      28.7.7 STL wrappers

      -

      26.8 Typemaps

      +

      28.8 Typemaps

      @@ -3630,7 +3630,7 @@ Typemaps are only used if you want to change some aspect of the primitive C-Python interface or if you want to elevate your guru status.

      -

      26.8.1 What is a typemap?

      +

      28.8.1 What is a typemap?

      @@ -3746,7 +3746,7 @@ parameter is omitted): -

      26.8.2 Python typemaps

      +

      28.8.2 Python typemaps

      @@ -3787,7 +3787,7 @@ a look at the SWIG library version 1.3.20 or so.

      -

      26.8.3 Typemap variables

      +

      28.8.3 Typemap variables

      @@ -3858,7 +3858,7 @@ properly assigned. The Python name of the wrapper function being created. -

      26.8.4 Useful Python Functions

      +

      28.8.4 Useful Python Functions

      @@ -3972,7 +3972,7 @@ write me -

      26.9 Typemap Examples

      +

      28.9 Typemap Examples

      @@ -3981,7 +3981,7 @@ might look at the files "python.swg" and "typemaps.i" in the SWIG library.

      -

      26.9.1 Converting Python list to a char **

      +

      28.9.1 Converting Python list to a char **

      @@ -4061,7 +4061,7 @@ memory allocation is used to allocate memory for the array, the the C function.

      -

      26.9.2 Expanding a Python object into multiple arguments

      +

      28.9.2 Expanding a Python object into multiple arguments

      @@ -4140,7 +4140,7 @@ to supply the argument count. This is automatically set by the typemap code. F -

      26.9.3 Using typemaps to return arguments

      +

      28.9.3 Using typemaps to return arguments

      @@ -4229,7 +4229,7 @@ function can now be used as follows: >>> -

      26.9.4 Mapping Python tuples into small arrays

      +

      28.9.4 Mapping Python tuples into small arrays

      @@ -4278,7 +4278,7 @@ array, such an approach would not be recommended for huge arrays, but for small structures, this approach works fine.

      -

      26.9.5 Mapping sequences to C arrays

      +

      28.9.5 Mapping sequences to C arrays

      @@ -4363,7 +4363,7 @@ static int convert_darray(PyObject *input, double *ptr, int size) { -

      26.9.6 Pointer handling

      +

      28.9.6 Pointer handling

      @@ -4458,7 +4458,7 @@ class object (if applicable). -

      26.10 Docstring Features

      +

      28.10 Docstring Features

      @@ -4486,7 +4486,7 @@ of your users much simpler.

      -

      26.10.1 Module docstring

      +

      28.10.1 Module docstring

      @@ -4520,7 +4520,7 @@ layout of controls on a panel, etc. to be loaded from an XML file." -

      26.10.2 %feature("autodoc")

      +

      28.10.2 %feature("autodoc")

      @@ -4547,7 +4547,7 @@ names, default values if any, and return type if any. There are also three options for autodoc controlled by the value given to the feature, described below. -

      26.10.2.1 %feature("autodoc", "0")

      +

      28.10.2.1 %feature("autodoc", "0")

      @@ -4576,7 +4576,7 @@ def function_name(*args, **kwargs): -

      26.10.2.2 %feature("autodoc", "1")

      +

      28.10.2.2 %feature("autodoc", "1")

      @@ -4601,7 +4601,7 @@ def function_name(*args, **kwargs): -

      26.10.2.3 %feature("autodoc", "docstring")

      +

      28.10.2.3 %feature("autodoc", "docstring")

      @@ -4620,7 +4620,7 @@ void GetPosition(int* OUTPUT, int* OUTPUT); -

      26.10.3 %feature("docstring")

      +

      28.10.3 %feature("docstring")

      @@ -4652,7 +4652,7 @@ with more than one line. -

      26.11 Python Packages

      +

      28.11 Python Packages

      diff --git a/Doc/Manual/Ruby.html b/Doc/Manual/Ruby.html index e46a6fb97..bbf9826ab 100644 --- a/Doc/Manual/Ruby.html +++ b/Doc/Manual/Ruby.html @@ -5,7 +5,7 @@ -

      27 SWIG and Ruby

      +

      29 SWIG and Ruby

        @@ -223,7 +223,7 @@

      This chapter describes SWIG's support of Ruby.

      -

      27.1 Preliminaries

      +

      29.1 Preliminaries

      @@ -237,7 +237,7 @@ Basics" chapter. It is also assumed that the reader has a basic understanding of Ruby.

      -

      27.1.1 Running SWIG

      +

      29.1.1 Running SWIG

      @@ -259,7 +259,7 @@ extension module. To finish building the module, you need to compile this file and link it with the rest of your program.

      -

      27.1.2 Getting the right header files

      +

      29.1.2 Getting the right header files

      @@ -280,7 +280,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/ /usr/local/lib/ruby/site_ruby /usr/local/lib/ruby/1.6 /usr/local/lib/ruby/1.6/i686-linux . -

      27.1.3 Compiling a dynamic module

      +

      29.1.3 Compiling a dynamic module

      @@ -332,7 +332,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/

      -

      27.1.4 Using your module

      +

      29.1.4 Using your module

      @@ -356,7 +356,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/ will result in an extension module using the feature name "example" and Ruby module name "Example".

      -

      27.1.5 Static linking

      +

      29.1.5 Static linking

      @@ -372,7 +372,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/ to the list of extensions in the file, and finally rebuilding Ruby.

      -

      27.1.6 Compilation of C++ extensions

      +

      29.1.6 Compilation of C++ extensions

      @@ -396,7 +396,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/

      require 'mkmf'
      $libs = append_library($libs, "supc++")
      create_makefile('example')
      -

      27.2 Building Ruby Extensions under Windows 95/NT

      +

      29.2 Building Ruby Extensions under Windows 95/NT

      @@ -419,7 +419,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/ will need the Ruby header files.

      -

      27.2.1 Running SWIG from Developer Studio

      +

      29.2.1 Running SWIG from Developer Studio

      @@ -487,14 +487,14 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/

      C:\swigtest> ruby run.rb
      Foo = 3.0
      -

      27.3 The Ruby-to-C/C++ Mapping

      +

      29.3 The Ruby-to-C/C++ Mapping

      This section describes the basics of how SWIG maps C or C++ declarations in your SWIG interface files to Ruby constructs.

      -

      27.3.1 Modules

      +

      29.3.1 Modules

      @@ -561,7 +561,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/ global module, take care that the names of your constants, classes and methods don't conflict with any of Ruby's built-in names.

      -

      27.3.2 Functions

      +

      29.3.2 Functions

      @@ -584,7 +584,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/

      $ irb
      irb(main):001:0> require 'example'
      true
      irb(main):002:0> Example.fact(4)
      24
      -

      27.3.3 Variable Linking

      +

      29.3.3 Variable Linking

      @@ -621,7 +621,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/ The %immutable directive stays in effect until it is explicitly disabled using %mutable.

      -

      27.3.4 Constants

      +

      29.3.4 Constants

      @@ -638,7 +638,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/

      $ irb
      irb(main):001:0> require 'Example'
      true
      irb(main):002:0> Example::PI
      3.14159
      -

      27.3.5 Pointers

      +

      29.3.5 Pointers

      @@ -659,7 +659,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/

      A NULL pointer is always represented by the Ruby nil object.

      -

      27.3.6 Structures

      +

      29.3.6 Structures

      @@ -724,7 +724,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/

      Foo *Bar_f_get(Bar *b) {
      return &b->f;
      }

      void Bar_f_set(Bar *b, Foo *val) {
      b->f = *val;
      }
      -

      27.3.7 C++ classes

      +

      29.3.7 C++ classes

      @@ -758,7 +758,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/

      require 'Example'

      l = Example::List.new

      l.insert("Ale")
      l.insert("Stout")
      l.insert("Lager")
      Example.print(l)
      l.length()
      ----- produces the following output
      Lager
      Stout
      Ale
      3
      -

      27.3.8 C++ Inheritance

      +

      29.3.8 C++ Inheritance

      @@ -851,7 +851,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/ will otherwise behave as though they inherit from both Base1 and Base2 (i.e. they exhibit "Duck Typing").

      -

      27.3.9 C++ Overloaded Functions

      +

      29.3.9 C++ Overloaded Functions

      @@ -913,7 +913,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/

      Please refer to the "SWIG and C++" chapter for more information about overloading.

      -

      27.3.10 C++ Operators

      +

      29.3.10 C++ Operators

      @@ -943,7 +943,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/ More details about wrapping C++ operators into Ruby operators is discussed in the section on operator overloading.

      -

      27.3.11 C++ namespaces

      +

      29.3.11 C++ namespaces

      @@ -973,7 +973,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/ namespaces each with identical symbol names, well, then you get what you deserve.

      -

      27.3.12 C++ templates

      +

      29.3.12 C++ templates

      @@ -1014,7 +1014,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/ examples. More details can be found in the SWIG and C++ chapter.

      -

      27.3.13 C++ Smart Pointers

      +

      29.3.13 C++ Smart Pointers

      @@ -1052,7 +1052,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/

      irb(main):004:0> f = p.__deref__() # Returns underlying Foo *
      -

      27.3.14 Cross-Language Polymorphism

      +

      29.3.14 Cross-Language Polymorphism

      @@ -1062,7 +1062,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/ this section just notes the differences that you need to be aware of when using this feature with Ruby.

      -

      27.3.14.1 Exception Unrolling

      +

      29.3.14.1 Exception Unrolling

      @@ -1083,7 +1083,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/ Ruby exception is raised, it will be caught here and a C++ exception is raised in its place.

      -

      27.4 Input and output parameters

      +

      29.4 Input and output parameters

      @@ -1209,7 +1209,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/ the standard Ruby exception classes, consult a Ruby reference such as Programming Ruby.

      -

      27.5 Typemaps

      +

      29.5 Typemaps

      @@ -1222,7 +1222,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/ of using SWIG---the default wrapping behavior is enough in most cases. Typemaps are only used if you want to change some aspect of the primitive C-Ruby interface.

      -

      27.5.1 What is a typemap?

      +

      29.5.1 What is a typemap?

      @@ -1289,7 +1289,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/

      puts Example.count('o','Hello World')
      2
      -

      27.5.2 Ruby typemaps

      +

      29.5.2 Ruby typemaps

      @@ -1346,7 +1346,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/ Examples of these typemaps appears in the section on typemap examples

      -

      27.5.3 Typemap variables

      +

      29.5.3 Typemap variables

      Within a typemap, a number of special variables prefaced with a $ may @@ -1382,7 +1382,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/

      $symname

      The Ruby name of the wrapper function being created.
      -

      27.5.4 Useful Functions

      +

      29.5.4 Useful Functions

      @@ -1392,19 +1392,19 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/ by David Thomas and Andrew Hunt.)

      -

      27.5.4.1 C Datatypes to Ruby Objects

      +

      29.5.4.1 C Datatypes to Ruby Objects

      INT2NUM(long or int) - int to Fixnum or Bignum
      INT2FIX(long or int) - int to Fixnum (faster than INT2NUM)
      CHR2FIX(char) - char to Fixnum
      rb_str_new2(char*) - char* to String
      rb_float_new(double) - double to Float
      -

      27.5.4.2 Ruby Objects to C Datatypes

      +

      29.5.4.2 Ruby Objects to C Datatypes

       int NUM2INT(Numeric)
      int FIX2INT(Numeric)
      unsigned int NUM2UINT(Numeric)
      unsigned int FIX2UINT(Numeric)
      long NUM2LONG(Numeric)
      long FIX2LONG(Numeric)
      unsigned long FIX2ULONG(Numeric)
      char NUM2CHR(Numeric or String)
      char * STR2CSTR(String)
      char * rb_str2cstr(String, int*length)
      double NUM2DBL(Numeric)

      -

      27.5.4.3 Macros for VALUE

      +

      29.5.4.3 Macros for VALUE

      @@ -1419,7 +1419,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/

      capacity of the Ruby array

      RARRAY(arr)->ptr

      pointer to array storage
      -

      27.5.4.4 Exceptions

      +

      29.5.4.4 Exceptions

      @@ -1486,7 +1486,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/ with the -w flag. The given format string fmt and remaining arguments are interpreted as with printf(). -

      27.5.4.5 Iterators

      +

      29.5.4.5 Iterators

      @@ -1525,14 +1525,14 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/

      Equivalent to Ruby's throw.
      -

      27.5.5 Typemap Examples

      +

      29.5.5 Typemap Examples

      This section includes a few examples of typemaps. For more examples, you might look at the examples in the Example/ruby directory.

      -

      27.5.6 Converting a Ruby array to a char **

      +

      29.5.6 Converting a Ruby array to a char **

      @@ -1556,7 +1556,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/ allocation is used to allocate memory for the array, the "freearg" typemap is used to later release this memory after the execution of the C function.

      -

      27.5.7 Collecting arguments in a hash

      +

      29.5.7 Collecting arguments in a hash

      @@ -1669,7 +1669,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/ the extension, can be found in the Examples/ruby/hashargs directory of the SWIG distribution.

      -

      27.5.8 Pointer handling

      +

      29.5.8 Pointer handling

      @@ -1716,7 +1716,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/

      %typemap(in) Foo * {
      SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor, 1);
      }
      -

      27.5.8.1 Ruby Datatype Wrapping

      +

      29.5.8.1 Ruby Datatype Wrapping

      @@ -1737,7 +1737,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/

      Retrieves the original C pointer of type c-type from the data object obj and assigns that pointer to ptr.
      -

      27.6 Operator overloading

      +

      29.6 Operator overloading

      @@ -1752,7 +1752,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/ defining an equivalence operator, there is no separate method for handling inequality since Ruby parses the expression a != b as !(a == b).

      -

      27.6.1 Example: STL Vector to Ruby Array

      +

      29.6.1 Example: STL Vector to Ruby Array

      @@ -1789,10 +1789,10 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/

      %define VECTOR_TO_RUBY_ARRAY(vectorclassname, classname)
      %typemap(ruby, out) vectorclassname &, const vectorclassname & {
      VALUE arr = rb_ary_new2($1->size());
      vectorclassname::iterator i = $1->begin(), iend = $1->end();
      for ( ; i!=iend; i++ )
      rb_ary_push(arr, Data_Wrap_Struct(c ## classname.klass, 0, 0, &(*i)));
      $result = arr;
      }
      %typemap(ruby, out) vectorclassname, const vectorclassname {
      VALUE arr = rb_ary_new2($1.size());
      vectorclassname::iterator i = $1.begin(), iend = $1.end();
      for ( ; i!=iend; i++ )
      rb_ary_push(arr, Data_Wrap_Struct(c ## classname.klass, 0, 0, &(*i)));
      $result = arr;
      }
      %enddef
      -

      27.7 Advanced Topics

      +

      29.7 Advanced Topics

      -

      27.7.1 Creating Multi-Module Packages

      +

      29.7.1 Creating Multi-Module Packages

      @@ -1863,7 +1863,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/

      $ irb
      irb(main):001:0> require 'shape'
      true
      irb(main):002:0> require 'circle'
      true
      irb(main):003:0> c = Circle::Circle.new(5, 5, 20)
      #<Circle::Circle:0xa097208>
      irb(main):004:0> c.kind_of? Shape::Shape
      true
      irb(main):005:0> c.getX()
      5.0
      -

      27.7.2 Defining Aliases

      +

      29.7.2 Defining Aliases

      @@ -1902,7 +1902,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/ mechanism and so the same name matching rules used for other kinds of features apply (see the chapter on "Customization Features") for more details).

      -

      27.7.3 Predicate Methods

      +

      29.7.3 Predicate Methods

      @@ -1939,7 +1939,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/ of features apply (see the chapter on "Customization Features") for more details).

      -

      27.7.4 Specifying Mixin Modules

      +

      29.7.4 Specifying Mixin Modules

      @@ -1980,7 +1980,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/ apply (see the chapter on "Customization Features") for more details).

      -

      27.8 Memory Management

      +

      29.8 Memory Management

      One of the most common issues in generating SWIG bindings for Ruby is proper @@ -2024,7 +2024,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/ allocated in creating the underlying C struct or C++ struct, then a "free" function must be defined that deallocates this memory.

      -

      27.8.1 Object Ownership

      +

      29.8.1 Object Ownership

      As described above, memory management depends on clearly defining who is @@ -2099,7 +2099,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/

      This code can be seen in swig/examples/ruby/tracking.


      -

      27.8.2 Object Tracking

      +

      29.8.2 Object Tracking

      The remaining parts of this section will use the class library shown below to @@ -2168,7 +2168,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/ implement your own free functions (see below) you may also have to call theSWIG_RubyRemoveTracking and RubyUnlinkObjects methods.

      -

      27.8.3 Mark Functions

      +

      29.8.3 Mark Functions

      With a bit more testing, we see that our class library still has problems. For @@ -2210,7 +2210,7 @@ $ ruby -e 'puts $:.join("\n")'
      /usr/local/lib/ruby/site_ruby/1.6 /usr/

      This code can be seen in swig/examples/ruby/mark_function.

      -

      27.8.4 Free Functions

      +

      29.8.4 Free Functions

      By default, SWIG creates a "free" function that is called when a Ruby object is diff --git a/Doc/Manual/Sections.html b/Doc/Manual/Sections.html index 23389c6f0..7c40b4c5f 100644 --- a/Doc/Manual/Sections.html +++ b/Doc/Manual/Sections.html @@ -41,6 +41,7 @@ to help!).

      • Common Lisp support
      • +
      • Allegro CL support
      • C# support
      • Chicken support
      • Guile support
      • diff --git a/Doc/Manual/Tcl.html b/Doc/Manual/Tcl.html index 3ad696f1b..27c35c6eb 100644 --- a/Doc/Manual/Tcl.html +++ b/Doc/Manual/Tcl.html @@ -6,7 +6,7 @@ -

        28 SWIG and Tcl

        +

        30 SWIG and Tcl

          @@ -82,7 +82,7 @@ Tcl 8.0 or a later release. Earlier releases of SWIG supported Tcl 7.x, but this is no longer supported.

          -

          28.1 Preliminaries

          +

          30.1 Preliminaries

          @@ -108,7 +108,7 @@ build a Tcl extension module. To finish building the module, you need to compile this file and link it with the rest of your program.

          -

          28.1.1 Getting the right header files

          +

          30.1.1 Getting the right header files

          @@ -126,7 +126,7 @@ this is the case, you should probably make a symbolic link so that tcl.h -

          28.1.2 Compiling a dynamic module

          +

          30.1.2 Compiling a dynamic module

          @@ -161,7 +161,7 @@ The name of the module is specified using the %module directive or the -module command line option.

          -

          28.1.3 Static linking

          +

          30.1.3 Static linking

          @@ -227,7 +227,7 @@ minimal in most situations (and quite frankly not worth the extra hassle in the opinion of this author).

          -

          28.1.4 Using your module

          +

          30.1.4 Using your module

          @@ -355,7 +355,7 @@ to the default system configuration (this requires root access and you will need the man pages).

          -

          28.1.5 Compilation of C++ extensions

          +

          30.1.5 Compilation of C++ extensions

          @@ -438,7 +438,7 @@ erratic program behavior. If working with lots of software components, you might want to investigate using a more formal standard such as COM.

          -

          28.1.6 Compiling for 64-bit platforms

          +

          30.1.6 Compiling for 64-bit platforms

          @@ -465,7 +465,7 @@ also introduce problems on platforms that support more than one linking standard (e.g., -o32 and -n32 on Irix).

          -

          28.1.7 Setting a package prefix

          +

          30.1.7 Setting a package prefix

          @@ -484,7 +484,7 @@ option will append the prefix to the name when creating a command and call it "Foo_bar".

          -

          28.1.8 Using namespaces

          +

          30.1.8 Using namespaces

          @@ -506,7 +506,7 @@ When the -namespace option is used, objects in the module are always accessed with the namespace name such as Foo::bar.

          -

          28.2 Building Tcl/Tk Extensions under Windows 95/NT

          +

          30.2 Building Tcl/Tk Extensions under Windows 95/NT

          @@ -517,7 +517,7 @@ covers the process of using SWIG with Microsoft Visual C++. although the procedure may be similar with other compilers.

          -

          28.2.1 Running SWIG from Developer Studio

          +

          30.2.1 Running SWIG from Developer Studio

          @@ -575,7 +575,7 @@ MSDOS > tclsh80 %

        -

        28.2.2 Using NMAKE

        +

        30.2.2 Using NMAKE

        @@ -638,7 +638,7 @@ to get you started. With a little practice, you'll be making lots of Tcl extensions.

        -

        28.3 A tour of basic C/C++ wrapping

        +

        30.3 A tour of basic C/C++ wrapping

        @@ -649,7 +649,7 @@ classes. This section briefly covers the essential aspects of this wrapping.

        -

        28.3.1 Modules

        +

        30.3.1 Modules

        @@ -683,7 +683,7 @@ To fix this, supply an extra argument to load like this: -

        28.3.2 Functions

        +

        30.3.2 Functions

        @@ -708,7 +708,7 @@ like you think it does: % -

        28.3.3 Global variables

        +

        30.3.3 Global variables

        @@ -788,7 +788,7 @@ extern char *path; // Read-only (due to %immutable) -

        28.3.4 Constants and enums

        +

        30.3.4 Constants and enums

        @@ -872,7 +872,7 @@ When an identifier name is given, it is used to perform an implicit hash-table l conversion. This allows the global statement to be ommitted.

        -

        28.3.5 Pointers

        +

        30.3.5 Pointers

        @@ -968,7 +968,7 @@ C-style cast may return a bogus result whereas as the C++-style cast will return None if the conversion can't be performed.

        -

        28.3.6 Structures

        +

        30.3.6 Structures

        @@ -1250,7 +1250,7 @@ Note: Tcl only destroys the underlying object if it has ownership. See the memory management section that appears shortly.

        -

        28.3.7 C++ classes

        +

        30.3.7 C++ classes

        @@ -1317,7 +1317,7 @@ In Tcl, the static member is accessed as follows: -

        28.3.8 C++ inheritance

        +

        30.3.8 C++ inheritance

        @@ -1366,7 +1366,7 @@ For instance: It is safe to use multiple inheritance with SWIG.

        -

        28.3.9 Pointers, references, values, and arrays

        +

        30.3.9 Pointers, references, values, and arrays

        @@ -1420,7 +1420,7 @@ to hold the result and a pointer is returned (Tcl will release this memory when the return value is garbage collected).

        -

        28.3.10 C++ overloaded functions

        +

        30.3.10 C++ overloaded functions

        @@ -1543,7 +1543,7 @@ first declaration takes precedence. Please refer to the "SWIG and C++" chapter for more information about overloading.

        -

        28.3.11 C++ operators

        +

        30.3.11 C++ operators

        @@ -1645,7 +1645,7 @@ There are ways to make this operator appear as part of the class using the % Keep reading.

        -

        28.3.12 C++ namespaces

        +

        30.3.12 C++ namespaces

        @@ -1709,7 +1709,7 @@ utilizes thousands of small deeply nested namespaces each with identical symbol names, well, then you get what you deserve.

        -

        28.3.13 C++ templates

        +

        30.3.13 C++ templates

        @@ -1761,7 +1761,7 @@ More details can be found in the SWIG and C++ -

        28.3.14 C++ Smart Pointers

        +

        30.3.14 C++ Smart Pointers

        @@ -1845,7 +1845,7 @@ simply use the __deref__() method. For example: -

        28.4 Further details on the Tcl class interface

        +

        30.4 Further details on the Tcl class interface

        @@ -1858,7 +1858,7 @@ of low-level details were omitted. This section provides a brief overview of how the proxy classes work.

        -

        28.4.1 Proxy classes

        +

        30.4.1 Proxy classes

        @@ -1923,7 +1923,7 @@ function. This allows objects to be encapsulated objects that look a lot like as shown in the last section.

        -

        28.4.2 Memory management

        +

        30.4.2 Memory management

        @@ -2111,7 +2111,7 @@ typemaps--an advanced topic discussed later.

        -

        28.5 Input and output parameters

        +

        30.5 Input and output parameters

        @@ -2299,7 +2299,7 @@ set c [lindex $dim 1] -

        28.6 Exception handling

        +

        30.6 Exception handling

        @@ -2433,7 +2433,7 @@ Since SWIG's exception handling is user-definable, you are not limited to C++ ex See the chapter on "Customization Features" for more examples.

        -

        28.7 Typemaps

        +

        30.7 Typemaps

        @@ -2450,7 +2450,7 @@ Typemaps are only used if you want to change some aspect of the primitive C-Tcl interface.

        -

        28.7.1 What is a typemap?

        +

        30.7.1 What is a typemap?

        @@ -2567,7 +2567,7 @@ parameter is ommitted): -

        28.7.2 Tcl typemaps

        +

        30.7.2 Tcl typemaps

        @@ -2705,7 +2705,7 @@ Initialize an argument to a value before any conversions occur. Examples of these methods will appear shortly.

        -

        28.7.3 Typemap variables

        +

        30.7.3 Typemap variables

        @@ -2776,7 +2776,7 @@ properly assigned. The Tcl name of the wrapper function being created. -

        28.7.4 Converting a Tcl list to a char **

        +

        30.7.4 Converting a Tcl list to a char **

        @@ -2838,7 +2838,7 @@ argv[2] = Larry 3 -

        28.7.5 Returning values in arguments

        +

        30.7.5 Returning values in arguments

        @@ -2880,7 +2880,7 @@ result, a Tcl function using these typemaps will work like this : % -

        28.7.6 Useful functions

        +

        30.7.6 Useful functions

        @@ -2957,7 +2957,7 @@ int Tcl_IsShared(Tcl_Obj *obj); -

        28.7.7 Standard typemaps

        +

        30.7.7 Standard typemaps

        @@ -3041,7 +3041,7 @@ work) -

        28.7.8 Pointer handling

        +

        30.7.8 Pointer handling

        @@ -3117,7 +3117,7 @@ For example: -

        28.8 Turning a SWIG module into a Tcl Package.

        +

        30.8 Turning a SWIG module into a Tcl Package.

        @@ -3189,7 +3189,7 @@ As a final note, most SWIG examples do not yet use the to use the load command instead.

        -

        28.9 Building new kinds of Tcl interfaces (in Tcl)

        +

        30.9 Building new kinds of Tcl interfaces (in Tcl)

        @@ -3288,7 +3288,7 @@ danger of blowing something up (although it is easily accomplished with an out of bounds array access).

        -

        28.9.1 Proxy classes

        +

        30.9.1 Proxy classes

        diff --git a/Doc/Manual/chapters b/Doc/Manual/chapters index 93a7fa5af..f7bf49d19 100644 --- a/Doc/Manual/chapters +++ b/Doc/Manual/chapters @@ -13,6 +13,8 @@ Contract.html Varargs.html Warnings.html Modules.html +Lisp.html +Allegrocl.html CSharp.html Chicken.html Guile.html diff --git a/Lib/allegrocl/allegrocl.swg b/Lib/allegrocl/allegrocl.swg index f468edb4c..190a92f83 100644 --- a/Lib/allegrocl/allegrocl.swg +++ b/Lib/allegrocl/allegrocl.swg @@ -3,44 +3,275 @@ #define SWIG_ALLEGRO_CL -/* Typespecs for basic types. */ +#define %ffargs(...) %feature("ffargs", "1", ##__VA_ARGS__) +%ffargs(strings_convert="t"); -%typemap(ffitype) char ":char"; +/* typemaps for argument and result type conversions. */ +%typemap(lin) SWIGTYPE "(let (($out $in))\n $body)"; + +%typemap(lout) bool, char, unsigned char, signed char, + short, signed short, unsigned short, + int, signed int, unsigned int, + long, signed long, unsigned long, + float, double, long double, char *, void *, void, + enum SWIGTYPE "$body"; +%typemap(lout) SWIGTYPE[ANY], SWIGTYPE *, + SWIGTYPE & "(make-instance '$lclass :foreign-address $body)"; +%typemap(lout) SWIGTYPE "(let* ((address $body)\n (ACL_result (make-instance '$lclass :foreign-address address)))\n (unless (zerop address)\n (excl:schedule-finalization ACL_result #'$ldestructor))\n ACL_result)"; + +%typemap(lisptype) bool "boolean"; %typemap(lisptype) char "character"; -%typemap(ffitype) unsigned char ":unsigned-char"; %typemap(lisptype) unsigned char "integer"; -%typemap(ffitype) signed char ":char"; %typemap(lisptype) signed char "integer"; -%typemap(ffitype) short ":short"; -%typemap(ffitype) signed short ":short"; + +%typemap(ffitype) bool ":int"; +%typemap(ffitype) char ":char"; +%typemap(ffitype) unsigned char ":unsigned-char"; +%typemap(ffitype) signed char ":char"; +%typemap(ffitype) short, signed short ":short"; %typemap(ffitype) unsigned short ":unsigned-short"; -%typemap(ffitype) int ":int"; -%typemap(ffitype) signed int ":int"; +%typemap(ffitype) int, signed int ":int"; %typemap(ffitype) unsigned int ":unsigned-int"; -%typemap(ffitype) long ":long"; -%typemap(ffitype) signed long ":long"; +%typemap(ffitype) long, signed long ":long"; %typemap(ffitype) unsigned long ":unsigned-long"; %typemap(ffitype) float ":float"; %typemap(ffitype) double ":double"; %typemap(ffitype) char * "(* :char)"; %typemap(ffitype) void * "(* :void)"; %typemap(ffitype) void ":void"; +%typemap(ffitype) enum SWIGTYPE ":int"; +%typemap(ffitype) SWIGTYPE & "(* :void)"; -%wrapper %{ +%typemap(ctype) bool "int"; +%typemap(ctype) char, unsigned char, signed char, + short, signed short, unsigned short, + int, signed int, unsigned int, + long, signed long, unsigned long, + float, double, long double, char *, void *, void, + enum SWIGTYPE, SWIGTYPE *, + SWIGTYPE[ANY], SWIGTYPE & "$1_ltype"; +%typemap(ctype) SWIGTYPE "$&1_type"; + +%typemap(in) bool "$1 = (bool)$input;"; +%typemap(in) char, unsigned char, signed char, + short, signed short, unsigned short, + int, signed int, unsigned int, + long, signed long, unsigned long, + float, double, long double, char *, void *, void, + enum SWIGTYPE, SWIGTYPE *, + SWIGTYPE[ANY], SWIGTYPE & "$1 = $input;"; +%typemap(in) SWIGTYPE "$1 = *$input;"; + +/* We don't need to do any actual C-side typechecking, but need to + use the precedence values to choose which overloaded function + interfaces to generate when conflicts arise. */ + +/* predefined precedence values + +Symbolic Name Precedence Value +------------------------------ ------------------ +SWIG_TYPECHECK_POINTER 0 +SWIG_TYPECHECK_VOIDPTR 10 +SWIG_TYPECHECK_BOOL 15 +SWIG_TYPECHECK_UINT8 20 +SWIG_TYPECHECK_INT8 25 +SWIG_TYPECHECK_UINT16 30 +SWIG_TYPECHECK_INT16 35 +SWIG_TYPECHECK_UINT32 40 +SWIG_TYPECHECK_INT32 45 +SWIG_TYPECHECK_UINT64 50 +SWIG_TYPECHECK_INT64 55 +SWIG_TYPECHECK_UINT128 60 +SWIG_TYPECHECK_INT128 65 +SWIG_TYPECHECK_INTEGER 70 +SWIG_TYPECHECK_FLOAT 80 +SWIG_TYPECHECK_DOUBLE 90 +SWIG_TYPECHECK_COMPLEX 100 +SWIG_TYPECHECK_UNICHAR 110 +SWIG_TYPECHECK_UNISTRING 120 +SWIG_TYPECHECK_CHAR 130 +SWIG_TYPECHECK_STRING 140 +SWIG_TYPECHECK_BOOL_ARRAY 1015 +SWIG_TYPECHECK_INT8_ARRAY 1025 +SWIG_TYPECHECK_INT16_ARRAY 1035 +SWIG_TYPECHECK_INT32_ARRAY 1045 +SWIG_TYPECHECK_INT64_ARRAY 1055 +SWIG_TYPECHECK_INT128_ARRAY 1065 +SWIG_TYPECHECK_FLOAT_ARRAY 1080 +SWIG_TYPECHECK_DOUBLE_ARRAY 1090 +SWIG_TYPECHECK_CHAR_ARRAY 1130 +SWIG_TYPECHECK_STRING_ARRAY 1140 +*/ + +%typecheck(SWIG_TYPECHECK_BOOL) bool { $1 = 1; }; +%typecheck(SWIG_TYPECHECK_CHAR) char { $1 = 1; }; +%typecheck(SWIG_TYPECHECK_FLOAT) float { $1 = 1; }; +%typecheck(SWIG_TYPECHECK_DOUBLE) double { $1 = 1; }; +%typecheck(SWIG_TYPECHECK_STRING) char * { $1 = 1; }; +%typecheck(SWIG_TYPECHECK_INTEGER) + unsigned char, signed char, + short, signed short, unsigned short, + int, signed int, unsigned int, + long, signed long, unsigned long, + enum SWIGTYPE { $1 = 1; }; +%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, + SWIGTYPE[ANY], SWIGTYPE { $1 = 1; }; + +/* This maps C/C++ types to Lisp classes for overload dispatch */ + +%typemap(lispclass) bool "t"; +%typemap(lispclass) char "character"; +%typemap(lispclass) unsigned char, signed char, + short, signed short, unsigned short, + int, signed int, unsigned int, + long, signed long, unsigned long, + enum SWIGTYPE "integer"; +%typemap(lispclass) float "single-float"; +%typemap(lispclass) double "double-float"; +%typemap(lispclass) char * "string"; + +%typemap(out) bool "$result = (int)$1;"; +%typemap(out) char, unsigned char, signed char, + short, signed short, unsigned short, + int, signed int, unsigned int, + long, signed long, unsigned long, + float, double, long double, char *, void *, void, + enum SWIGTYPE, SWIGTYPE *, + SWIGTYPE[ANY], SWIGTYPE & "$result = $1;"; +%typemap(out) SWIGTYPE "$result = new $1_type($1);"; + +////////////////////////////////////////////////////////////// +// UCS-2 string conversion + +// should this be SWIG_TYPECHECK_CHAR? +%typecheck(SWIG_TYPECHECK_UNICHAR) wchar_t { $1 = 1; }; + +%typemap(in) wchar_t "$1 = $input;"; +%typemap(lin) wchar_t "(let (($out (char-code $in)))\n $body)"; +%typemap(lin) wchar_t* "(excl:with-native-string ($out $in +:external-format #+little-endian :fat-le #-little-endian :fat)\n +$body)" + +%typemap(out) wchar_t "$result = $1;"; +%typemap(lout) wchar_t "(code-char $body)"; +%typemap(lout) wchar_t* "(excl:native-to-string $body +:external-format #+little-endian :fat-le #-little-endian :fat)"; + +%typemap(ffitype) wchar_t ":unsigned-short"; +%typemap(lisptype) wchar_t ""; +%typemap(ctype) wchar_t "wchar_t"; +%typemap(lispclass) wchar_t "character"; +%typemap(lispclass) wchar_t* "string"; +////////////////////////////////////////////////////////////// + +/* name conversion for overloaded operators. */ +#ifdef __cplusplus +%rename(__add__) *::operator+; +%rename(__pos__) *::operator+(); +%rename(__pos__) *::operator+() const; + +%rename(__sub__) *::operator-; +%rename(__neg__) *::operator-() const; +%rename(__neg__) *::operator-(); + +%rename(__mul__) *::operator*; +%rename(__deref__) *::operator*(); +%rename(__deref__) *::operator*() const; + +%rename(__div__) *::operator/; +%rename(__mod__) *::operator%; +%rename(__logxor__) *::operator^; +%rename(__logand__) *::operator&; +%rename(__logior__) *::operator|; +%rename(__lognot__) *::operator~(); +%rename(__lognot__) *::operator~() const; + +%rename(__not__) *::operator!(); +%rename(__not__) *::operator!() const; + +%rename(__assign__) *::operator=; + +%rename(__add_assign__) *::operator+=; +%rename(__sub_assign__) *::operator-=; +%rename(__mul_assign__) *::operator*=; +%rename(__div_assign__) *::operator/=; +%rename(__mod_assign__) *::operator%=; +%rename(__logxor_assign__) *::operator^=; +%rename(__logand_assign__) *::operator&=; +%rename(__logior_assign__) *::operator|=; + +%rename(__lshift__) *::operator<<; +%rename(__lshift_assign__) *::operator<<=; +%rename(__rshift__) *::operator>>; +%rename(__rshift_assign__) *::operator>>=; + +%rename(__eq__) *::operator==; +%rename(__ne__) *::operator!=; +%rename(__lt__) *::operator<; +%rename(__gt__) *::operator>; +%rename(__lte__) *::operator<=; +%rename(__gte__) *::operator>=; + +%rename(__and__) *::operator&&; +%rename(__or__) *::operator||; + +%rename(__preincr__) *::operator++(); +%rename(__postincr__) *::operator++(int); +%rename(__predecr__) *::operator--(); +%rename(__postdecr__) *::operator--(int); + +%rename(__comma__) *::operator,(); +%rename(__comma__) *::operator,() const; + +%rename(__member_ref__) *::operator->; +%rename(__member_func_ref__) *::operator->*; + +%rename(__funcall__) *::operator(); +%rename(__aref__) *::operator[]; +#endif + +%insert("lisphead") %{ ;; $Id$ (eval-when (compile eval) ;;; You can define your own identifier converter if you want. ;;; Use the -identifier-converter command line argument to -;;; specify its name. - -(defun identifier-convert-null (id &key type) - (declare (ignore type)) - (read-from-string id)) +;;; specify its name. -(defun identifier-convert-lispify (cname &key type) +(eval-when (:compile-toplevel :load-toplevel :execute) + (defparameter *swig-export-list* nil)) + +(defun read-symbol-from-string (string) + (multiple-value-bind (result position) + (read-from-string string nil "eof" :preserve-whitespace t) + (if (and (symbolp result) (eql position (length string))) + result + (intern string)))) + +(defun full-name (id type arity class) + (case type + (:getter (format nil "~@[~A_~]~A" class id)) + (:constructor (format nil "new_~A~@[~A~]" id arity)) + (:destructor (format nil "delete_~A" id)) + (:type (format nil "ff_~A" id)) + (:ff-operator (format nil "ffi_~A" id)) + (otherwise (format nil "~@[~A_~]~A~@[~A~]" + class id arity)))) + +(defun identifier-convert-null (id &key type class arity) + (if (eq type :setter) + `(setf ,(identifier-convert-null + id :type :getter :class class :arity arity)) + (read-symbol-from-string (full-name id type arity class)))) + +(defun identifier-convert-lispify (cname &key type class arity) (assert (stringp cname)) + (when (eq type :setter) + (return-from identifier-convert-lispify + `(setf ,(identifier-convert-lispify + cname :type :getter :class class :arity arity)))) + (setq cname (full-name cname type arity class)) (if (eq type :constant) (setf cname (format nil "*~A*" cname))) (setf cname (replace-regexp cname "_" "-")) @@ -54,7 +285,7 @@ (when (or (and (eq lastcase :upper) (eq newcase :lower)) (and (eq lastcase :lower) (eq newcase :upper))) - ;; case change... add a dash + ;; case change... add a dash (push #\- res) (setf newcase :other)) @@ -65,26 +296,191 @@ else (push char res) (setf lastcase :other))) - (read-from-string (coerce (nreverse res) 'string)))) + (read-symbol-from-string (coerce (nreverse res) 'string)))) + +(defun id-convert-and-export (name &rest kwargs) + (multiple-value-bind (symbol package) + (apply *swig-identifier-converter* name kwargs) + (let ((args (list (if (consp symbol) (cadr symbol) symbol) + (or package *package*)))) + (apply #'export args) + (pushnew args swig::*swig-export-list*)) + symbol)) + +(defmacro swig-insert-id (name namespace &key (type :type) class) + `(let ((*package* (find-package ,(package-name-for-namespace namespace)))) + (id-convert-and-export ,name :type ,type :class ,class))) (defmacro swig-defconstant (string value) - (let ((symbol (funcall *swig-identifier-converter* string :type :constant))) + (let ((symbol (id-convert-and-export string :type :constant))) `(eval-when (compile load eval) - (defconstant ,symbol ,value) - (export (quote ,symbol))))) + (defconstant ,symbol ,value)))) -(defmacro swig-defun (name &rest rest) - (let ((symbol (funcall *swig-identifier-converter* name :type :operator))) +(defun maybe-reorder-args (funcname arglist) + ;; in the foreign setter function the new value will be the last argument + ;; in Lisp it needs to be the first + (if (consp funcname) + (append (last arglist) (butlast arglist)) + arglist)) + +(defun maybe-return-value (funcname arglist) + ;; setf functions should return the new value + (when (consp funcname) + `(,(if (consp (car arglist)) + (caar arglist) + (car arglist))))) + +(defun swig-anyvarargs-p (arglist) + (member :SWIG__varargs_ arglist)) + +(defmacro swig-defun ((name &optional (mangled-name name) + &key (type :operator) class arity) + ffargs kwargs + &body body) + (let* ((symbol (id-convert-and-export name :type type + :arity arity :class class)) + (mangle (if* (eq name mangled-name) + then (id-convert-and-export + (cond ((eq type :setter) (format nil "~A-set" name)) + ((eq type :getter) (format nil "~A-get" name)) + (t name)) + :type :ff-operator :arity arity :class class) + else (intern mangled-name))) + (defun-args (maybe-reorder-args + symbol + (mapcar #'car (and (not (equal ffargs '(:void))) + ffargs)) + )) + ) + (when (swig-anyvarargs-p ffargs) + (setq ffargs '())) `(eval-when (compile load eval) (excl::compiler-let ((*record-xref-info* nil)) - (ff:def-foreign-call (,symbol ,name) ,@rest) - (export (quote ,symbol)))))) + (ff:def-foreign-call (,mangle ,mangled-name) ,ffargs ,@kwargs)) + (macrolet ((swig-ff-call (&rest args) + (cons ',mangle args))) + (defun ,symbol ,defun-args + ,@body + ,@(maybe-return-value symbol defun-args)))))) -(defmacro swig-def-foreign-type (name &rest rest) - (let ((symbol (funcall *swig-identifier-converter* name :type :type))) +(defmacro swig-defmethod ((name &optional (mangled-name name) + &key (type :operator) class arity) + ffargs kwargs + &body body) + (let* ((symbol (id-convert-and-export name :type type + :arity arity :class class)) + (mangle (intern mangled-name)) + (defmethod-args (maybe-reorder-args + symbol + (unless (equal ffargs '(:void)) + (loop for (name dispatch) in ffargs + collect `(,name ,dispatch))))) + (ffargs (if (equal ffargs '(:void)) + ffargs + (loop for (name nil . ffi) in ffargs + collect `(,name ,@ffi))))) + `(eval-when (compile load eval) + (excl::compiler-let ((*record-xref-info* nil)) + (ff:def-foreign-call (,mangle ,mangled-name) ,ffargs ,@kwargs)) + (macrolet ((swig-ff-call (&rest args) + (cons ',mangle args))) + (defmethod ,symbol ,defmethod-args + ,@body + ,@(maybe-return-value symbol defmethod-args)))))) + +(defmacro swig-dispatcher ((name &key (type :operator) class arities)) + (let ((symbol (id-convert-and-export name + :type type :class class))) + `(eval-when (compile load eval) + (defun ,symbol (&rest args) + (case (length args) + ,@(loop for arity in arities + for symbol-n = (id-convert-and-export name + :type type :class class :arity arity) + collect `(,arity (apply #',symbol-n args))) + (t (error "No applicable wrapper-methods for foreign call ~a with args ~a of classes ~a" ',symbol args (mapcar #'(lambda (x) (class-name (class-of x))) args))) + ))))) + +(defmacro swig-def-foreign-stub (name) + (let ((lsymbol (id-convert-and-export name :type :class)) + (symbol (id-convert-and-export name :type :type))) + `(eval-when (compile load eval) + (ff:def-foreign-type ,symbol (:class )) + (defclass ,lsymbol (ff:foreign-pointer) ())))) + +(defmacro swig-def-foreign-class (name supers &rest rest) + (let ((lsymbol (id-convert-and-export name :type :class)) + (symbol (id-convert-and-export name :type :type))) `(eval-when (compile load eval) (ff:def-foreign-type ,symbol ,@rest) - (export (quote ,symbol))))) + (defclass ,lsymbol ,supers + ((foreign-type :initform ',symbol :initarg :foreign-type + :accessor foreign-pointer-type)))))) + +(defmacro swig-def-foreign-type (name &rest rest) + (let ((symbol (id-convert-and-export name :type :type))) + `(eval-when (compile load eval) + (ff:def-foreign-type ,symbol ,@rest)))) + +(defmacro swig-def-synonym-type (synonym of ff-synonym) + `(eval-when (compile load eval) + (setf (find-class ',synonym) (find-class ',of)) + (ff:def-foreign-type ,ff-synonym (:struct )))) + +(defun package-name-for-namespace (namespace) + (list-to-delimited-string + (cons *swig-module-name* + (mapcar #'(lambda (name) + (string + (funcall *swig-identifier-converter* + name + :type :namespace))) + namespace)) + ".")) + +(defmacro swig-defpackage (namespace) + (let* ((parent-namespaces (maplist #'reverse (cdr (reverse namespace)))) + (parent-strings (mapcar #'package-name-for-namespace + parent-namespaces)) + (string (package-name-for-namespace namespace))) + `(eval-when (compile load eval) + (defpackage ,string + (:use :common-lisp :ff :swig :excl + ,@parent-strings ,*swig-module-name*))))) + +(defmacro swig-in-package (namespace) + `(eval-when (compile load eval) + (in-package ,(package-name-for-namespace namespace)))) + +(defmacro swig-defvar (name mangled-name &key type) + (let ((symbol (id-convert-and-export name :type type))) + `(eval-when (compile load eval) + (ff:def-foreign-variable (,symbol ,mangled-name))))) ) ;; eval-when + +(eval-when (compile eval) + (flet ((starts-with-p (str prefix) + (and (>= (length str) (length prefix)) + (string= str prefix :end1 (length prefix))))) + (export (loop for sym being each present-symbol of *package* + when (or (starts-with-p (symbol-name sym) (symbol-name :swig-)) + (starts-with-p (symbol-name sym) (symbol-name :identifier-convert-))) + collect sym)))) + +(in-package #.*swig-module-name*) +%} + + + +%{ + +#ifdef __cplusplus +# define EXTERN extern "C" +#else +# define EXTERN extern +#endif + +#define EXPORT EXTERN SWIGEXPORT + %} diff --git a/Source/Modules/allegrocl.cxx b/Source/Modules/allegrocl.cxx index c68a44049..32e2657a3 100644 --- a/Source/Modules/allegrocl.cxx +++ b/Source/Modules/allegrocl.cxx @@ -1,29 +1,1547 @@ char cvsroot_allegrocl_cxx[] = "$Header$"; +#include #include "swigmod.h" +#include "cparse.h" + +// #define ALLEGROCL_DEBUG +// #define ALLEGROCL_WRAP_DEBUG +// #define ALLEGROCL_TYPE_DEBUG +// #define ALLEGROCL_CLASS_DEBUG + +static File *f_cl=0; +String *f_clhead = NewString(""); +String *f_clwrap = NewString("(swig-in-package ())\n\n"); +static File *f_cxx=0; +static File *f_cxx_header=0; +static File *f_cxx_wrapper=0; + +const char *identifier_converter="identifier-convert-null"; + +static String *current_namespace=NewString(""); +static String *current_package=NewString(""); +static Hash *defined_namespace_packages=NewHash(); +static Node *in_class = 0; + +static Node *first_linked_type=0; +static Hash *defined_foreign_types=NewHash(); +static Hash *defined_foreign_ltypes=NewHash(); + +// stub +String * convert_literal(String *num_param, String *type); class ALLEGROCL : public Language { public: - virtual void main(int argc, char *argv[]); virtual int top(Node *n); virtual int functionWrapper(Node *n); + virtual int namespaceDeclaration(Node *n); + virtual int constructorHandler(Node *n); + virtual int destructorHandler(Node *n); + virtual int globalvariableHandler(Node *n); + virtual int variableWrapper(Node *n); virtual int constantWrapper(Node *n); - virtual int classDeclaration(Node *n); + virtual int memberfunctionHandler(Node *n); + virtual int membervariableHandler(Node *n); + virtual int classHandler(Node *n); + virtual int emit_one(Node *n); + virtual int enumDeclaration(Node *n); + virtual int enumvalueDeclaration(Node *n); + virtual int typedefHandler(Node *n); + virtual int classforwardDeclaration(Node *n); + virtual int templateDeclaration(Node *n); + virtual int validIdentifier(String *s); +private: + int emit_defun(Node *n, File* f_cl); + int emit_dispatch_defun(Node *n); + int emit_buffered_defuns(Node *n); + int cClassHandler(Node *n); + int cppClassHandler(Node *n); +}; +static ALLEGROCL* allegrocl = 0; +static String *trim(String *str) { + char *c = Char(str); + while (*c != '\0' && isspace((int)*c)) + ++c; + String *result = NewString(c); + Chop(result); + return result; +} + +int is_integer(String *s) { + char *c = Char(s); + if(c[0] == '#' && (c[1] == 'x' || c[1] == 'o')) c+= 2; + + while(*c) { + if(!isdigit(*c)) return 0; + c++; + } + return 1; +} + +String *class_from_class_or_class_ref(String *type) { + SwigType *stripped = SwigType_strip_qualifiers(type); + if(SwigType_isclass(stripped)) return stripped; + + if(SwigType_ispointer(stripped) || SwigType_isreference(stripped)) { + // Printf(stderr,"It is a pointer/reference. Is it a class?\n"); + SwigType_pop(stripped); + if(SwigType_isclass(stripped)) { + return stripped; + } + } + return 0; +} + +String *lookup_defined_foreign_type(String *k) { + +#ifdef ALLEGROCL_TYPE_DEBUG + Printf(stderr, "Looking up defined type '%s'.\n Found: '%s'\n", + k, Getattr(defined_foreign_types, k)); +#endif + + return Getattr(defined_foreign_types, k); +} + +String *listify_namespace(String *namespaze) +{ + if (Len(namespaze) == 0) + return NewString("()"); + String *result = NewStringf("(\"%s\")", namespaze); + Replaceall(result, "::", "\" \""); + return result; +} + +String *namespaced_name(Node *n, String *ns = current_namespace) { + + return NewStringf("%s%s%s", + ns, (Len(ns) != 0) ? "::" : "", + Getattr(n,"sym:name")); +} + +// "Namespace::Nested::Class2::Baz" -> "Baz" +static String *strip_namespaces(String *str) +{ + char *result = Char(str); + String *stripped_one; + while ((stripped_one = Strstr(result, "::"))) + result = Char(stripped_one)+2; + return NewString(result); +} + +static String *namespace_of(String *str) { + char *p = Char(str); + char *start = Char(str); + char *result = 0; + String *stripped_one; + while ((stripped_one = Strstr(p, "::"))) + p = Char(stripped_one)+2; + + if(p > str) { + int len = p - start - 1; + result = (char *)malloc(len); + strncpy(result, start, len-1); + result[len-1] = 0; + } + return Char(result); +} + +void add_linked_type(Node *n) { +#ifdef ALLEGROCL_CLASS_DEBUG + Printf(stderr,"Adding linked node of type: %s(%s) %s(%x)\n\n", nodeType(n), + Getattr(n,"storage"), Getattr(n,"name"),n); +#endif + if(!first_linked_type) { + first_linked_type = n; + Setattr(n,"allegrocl:last_linked_type",n); + } else { + Node *t = Getattr(first_linked_type,"allegrocl:last_linked_type"); + Setattr(t,"allegrocl:next_linked_type",n); + Setattr(first_linked_type,"allegrocl:last_linked_type",n); + } +} + +void replace_linked_type(Node *old, Node *new_node) { + Node *prev = Getattr(old,"allegrocl:prev_linked_type"); + + Setattr(new_node,"allegrocl:next_linked_type", + Getattr(old,"allegrocl:next_linked_type")); + if(prev) Setattr(prev,"allegrocl:next_linked_type",new_node); + Delattr(old,"allegrocl:next_linked_type"); + Delattr(old,"allegrocl:prev_linked_type"); + + // check if we're replacing the first link. + if(first_linked_type == old) { + first_linked_type = new_node; + Setattr(first_linked_type,"allegrocl:last_linked_type", + Getattr(old,"allegrocl:last_linked_type")); + } + + // check if we're replacing the last link. + if(Getattr(first_linked_type,"allegrocl:last_linked_type") == old) + Setattr(first_linked_type,"allegrocl:last_linked_type",new_node); +} + +void insert_linked_type_at(Node *old, Node *new_node, int before = 1) { + Node *p = 0; + + if(!first_linked_type) { + add_linked_type(new_node); + return; + } + + if(!before) { + Setattr(new_node,"allegrocl:next_linked_type", + Getattr(old,"allegrocl:next_linked_type")); + Setattr(old,"allegrocl:next_linked_type",new_node); + if(Getattr(first_linked_type,"allegrocl:last_linked_type") == old) + Setattr(first_linked_type,"allegrocl:last_linked_type",new_node); + } else { + Node *c = first_linked_type; + while(c) { + if(c == old) { + break; + } else { + p = c; + c = Getattr(c,"allegrocl:next_linked_type"); + } + } + if(c == old) { + Setattr(new_node,"allegrocl:next_linked_type",c); + if(first_linked_type == c) { + first_linked_type = new_node; + Setattr(first_linked_type,"allegrocl:last_linked_type", + Getattr(c,"allegrocl:last_linked_type")); + Delattr(c,"allegrocl:last_linked_type"); + } + if(p) Setattr(p,"allegrocl:next_linked_type",new_node); + } + } +} + +Node *find_linked_type_by_name(String *name) { + Node *p = 0; + Node *c = first_linked_type; + + // Printf(stderr,"in find_linked_type_by_name '%s'...", name); + while(c) { + // String *cdeclname = Getattr(c,"allegrocl:classDeclarationName"); + // String *key = cdeclname ? NewStringf("struct %s",cdeclname) : + // Getattr(c,"name"); + String *key = Getattr(c,"name"); + // Printf(stderr," X '%s' '%s'", key, name); + // if(!Strcmp(Getattr(c,"name"),name)) { + if(!Strcmp(key,name)) { + break; + } else { + p = c; + c = Getattr(c,"allegrocl:next_linked_type"); + } + } + // Printf(stderr,"exit find_linked_type_by_name.\n"); + + if(p && c) Setattr(c,"allegrocl:prev_linked_type",p); + // Printf(stderr,"DONE\n"); + return c; +} + +Node *get_primary_synonym_of(Node *n) { + Node *p = Getattr(n,"allegrocl:synonym-of"); + Node *prim = n; + + // Printf(stderr, "getting primary synonym of %x\n", n); + while(p) { + // Printf(stderr, " found one! %x\n", p); + prim = p; + p = Getattr(p,"allegrocl:synonym-of"); + } + // Printf(stderr,"DONE. returning %s(%x)\n", Getattr(prim,"name"),prim); + return prim; +} + +void add_defined_foreign_type(Node *n, + int overwrite=0, + String *k=0, + String *name=0, + String *ns=current_namespace) { + + String *val; + String *ns_list = listify_namespace(ns); + String *templated = n ? Getattr(n,"template") : 0; + String *cDeclName = n ? Getattr(n,"classDeclaration:name") : 0; + +#ifdef ALLEGROCL_TYPE_DEBUG + Printf(stderr,"IN A-D-F-T\n"); +#endif + if(n) { + name=Getattr(n,"sym:name"); + if(!name) name = Getattr(n,"name"); + if(templated) { + k = namespaced_name(n); + } else { + String *kind_of_type = Getattr(n,"kind"); + + /* + For typedefs of the form: + + typedef __xxx { ... } xxx; + + add_defined_foreign_type will be called once via classHandler + to define the type for 'struct __xxx', and once via typedefHandler + to associate xxx with 'struct __xxx'. + + We create the following type to identifier mappings: + + struct __xxx -> (swig-insert-id "xxx") via classHand + xxx -> (swig-insert-id "xxx") via typedefHand + + and all references to this typedef'd struct will appear in + generated code as 'xxx'. For non-typedef'd structs, the + classHand mapping will be + + struct __xxx -> (swig-insert-id "__xxx") + */ + if(kind_of_type && !Strcmp(kind_of_type,"struct") && cDeclName) { + k = NewStringf("struct %s", cDeclName); + } else { + k = Getattr(n,"name"); + // if (cDeclName) Setattr(n,"allegrocl:classDeclarationName",cDeclName); + } + } + // Swig_print_node(n); + } + + if(SwigType_istemplate(name)) { + String *temp = strip_namespaces(SwigType_templateprefix(name)); + name = NewStringf("%s%s%s", temp, SwigType_templateargs(name), SwigType_templatesuffix(name)); + } + + val = lookup_defined_foreign_type(k); + + int is_fwd_ref = 0; + if(val) is_fwd_ref = !Strcmp(val,"forward-reference"); + + if(!val || overwrite || is_fwd_ref) { +#ifdef ALLEGROCL_TYPE_DEBUG + Printf(stderr, "Adding defined type '%s' = '%s' '%s' (overwrite=%d)\n", + k, ns, name, overwrite); +#endif + String *mangled_name_gen = + NewStringf("#.(swig-insert-id \"%s\" %s)", name, ns_list); + String *mangled_lname_gen = + NewStringf("#.(swig-insert-id \"%s\" %s :type :class)", name, ns_list); + + Setattr(defined_foreign_types,Copy(k),Copy(mangled_name_gen)); + Setattr(defined_foreign_ltypes,Copy(k),Copy(mangled_lname_gen)); + +#ifdef ALLEGROCL_TYPE_DEBUG + Printf(stderr,"looking to add %s/%s(%x) to linked_type_list...\n", k, name, n); +#endif + if(is_fwd_ref) { + // Printf(stderr,"*** 1\n"); + add_linked_type(n); + } else { + // Printf(stderr,"*** 1-a\n"); + if(SwigType_istemplate(k)) { + SwigType *resolved = SwigType_typedef_resolve_all(k); + // Printf(stderr,"*** 1-b\n"); + Node *match = find_linked_type_by_name(resolved); + Node *new_node = 0; + // Printf(stderr, "*** temp-1\n"); + if (n) { + new_node = n; + } else { +#ifdef ALLEGROCL_CLASS_DEBUG + Printf(stderr,"Creating a new templateInst:\n"); + Printf(stderr," name = %s\n", resolved); + Printf(stderr," sym:name = %s\n", name); + Printf(stderr," real-name = %s\n", k); + Printf(stderr," type = %s\n", resolved); + Printf(stderr," ns = %s\n\n", ns); +#endif + new_node = NewHash(); + Setattr(new_node,"nodeType","templateInst"); + Setattr(new_node,"name",Copy(resolved)); + Setattr(new_node,"sym:name",Copy(name)); + Setattr(new_node,"real-name",Copy(k)); + Setattr(new_node,"type",Copy(resolved)); + Setattr(new_node,"allegrocl:namespace",ns); + Setattr(new_node,"allegrocl:package",ns); + } + + if(!match) { + if(!Strcmp(nodeType(new_node),"templateInst") && in_class) { + /* this is an implicit template instantiation found while + walking a class. need to insert this into the + linked_type list before the current class definition */ +#ifdef ALLEGROCL_CLASS_DEBUG + Printf(stderr,"trying to insert a templateInst before a class\n"); +#endif + insert_linked_type_at(in_class,new_node); +#ifdef ALLEGROCL_CLASS_DEBUG + Printf(stderr,"DID IT!\n"); +#endif + } else { + // Printf(stderr,"*** 3\n"); + add_linked_type(new_node); + } + Setattr(new_node,"allegrocl:synonym:is-primary","1"); + } else { + // a synonym type was found (held in variable 'match') + // Printf(stderr, "setting primary synonym of %x to %x\n", new_node, match); + if(new_node == match) Printf(stderr,"Hey-4 * - '%s' is a synonym of iteself!\n", Getattr(new_node,"name")); + Setattr(new_node,"allegrocl:synonym-of",match); + // Printf(stderr,"*** 4\n"); + add_linked_type(new_node); + } + } else { + Node *match; + + if(!Strcmp(nodeType(n),"cdecl") && + !Strcmp(Getattr(n,"storage"),"typedef")) { + SwigType *type = SwigType_strip_qualifiers(Getattr(n,"type")); +#ifdef ALLEGROCL_TYPE_DEBUG + Printf(stderr,"Examining typedef '%s' for class references.\n", type); + // Printf(stderr," k='%s' v='%s'\n k='%s' v='%s'\n", + // type, Getattr(defined_foreign_types,type), + // k, Getattr(defined_foreign_types,k)); + Printf(stderr," the strstr() = %d, strcmp() = %d", Strstr(type,"struct "), !Strcmp(Getattr(defined_foreign_types,type),Getattr(defined_foreign_types,k))); + bool a = Strstr(type,"struct ") && !Strcmp(Getattr(defined_foreign_types,type),Getattr(defined_foreign_types,k)); + bool b = !a; + Printf(stderr,", and'd=%d, not-and'd=%d\n", a, b); +#endif + if(SwigType_isclass(type)) { +#ifdef ALLEGROCL_CLASS_DEBUG + Printf(stderr,"Found typedef of a class '%s'\n", type); +#endif + /* + For the following parsed expression: + + typedef struct __xxx { ... } xxx; + + if n is of kind "class" (defining the class 'struct __xxx' + then we add n to the linked type list. + + if n is "cdecl" node of storage "typedef" (to note + that xxx is equivalent to 'struct __xxx' then we don't + want to add this node to the linked type list. + */ + if(Strstr(type,"struct ") && + !Strcmp(lookup_defined_foreign_type(type), + lookup_defined_foreign_type(k))) { + // mark as a synonym but don't add to linked_type list + Setattr(n,"allegrocl:synonym","1"); + } else { + SwigType *lookup_type = SwigType_istemplate(type) ? + SwigType_typedef_resolve_all(type) : Copy(type); + match = find_linked_type_by_name(lookup_type); + if(match) { + Setattr(n,"allegrocl:synonym","1"); + Setattr(n,"allegrocl:synonym-of",match); + // if(n == match) Printf(stderr, "Hey-5 * setting synonym of %x to %x\n", n, match); + // Printf(stderr,"*** 5\n"); + add_linked_type(n); + } else { + // Printf(stderr,"Weird! Can't find the type!\n"); + } + Delete(lookup_type); + } + } else { + // check if it's a pointer or reference to a class. + // Printf(stderr,"Checking if '%s' is a p. or r. to a class\n", type); + String *class_ref = class_from_class_or_class_ref(type); + if(class_ref) { + match = find_linked_type_by_name(class_ref); + Setattr(n,"allegrocl:synonym","1"); + Setattr(n,"allegrocl:synonym-of",match); + add_linked_type(n); + } + } + Delete(type); + // synonym types have already been added. + // Printf(stderr,"*** 10\n"); + if(!Getattr(n,"allegrocl:synonym")) add_linked_type(n); + } else if(Getattr(n,"template")) { + // Printf(stderr, "this is a class template node(%s)\n", nodeType(n)); + String *resolved = SwigType_typedef_resolve_all(Getattr(n,"name")); + +#ifdef ALLEGROCL_CLASS_DEBUG + Printf(stderr, " looking up %s for linked type match with %s...\n", Getattr(n,"sym:name"), resolved); +#endif + match = find_linked_type_by_name(resolved); + if (!match) { +#ifdef ALLEGROCL_CLASS_DEBUG + Printf(stderr, "found no implicit instantiation of %%template node %s(%x)\n", Getattr(n,"name"),n); +#endif + add_linked_type(n); + } else { + Node *primary = get_primary_synonym_of(match); + + Setattr(n,"allegrocl:synonym:is-primary","1"); + Delattr(primary,"allegrocl:synonym:is-primary"); + if(n == match) Printf(stderr, "Hey-7 * setting synonym of %x to %x\n (match = %x)", primary, n, match); + Setattr(primary,"allegrocl:synonym-of",n); + // Printf(stderr,"*** 7\n"); + add_linked_type(n); + } + } else { +#ifdef ALLEGROCL_CLASS_DEBUG + Printf(stderr, "linking type %s(%x)\n", k, n); +#endif + // Printf(stderr,"*** 8\n"); + add_linked_type(n); + } + } + } + Delete(mangled_name_gen); + Delete(mangled_lname_gen); + } else { + Swig_warning(WARN_TYPE_REDEFINED, Getfile(n), Getline(n), + "Attempting to store a foreign type that exists: %s\n", k); + } + + Delete(ns_list); + +#ifdef ALLEGROCL_TYPE_DEBUG + Printf(stderr,"OUT A-D-F-T\n"); +#endif +} + +void note_implicit_template_instantiation(SwigType *t) { + // the namespace of the implicit instantiation is not necessarily + // current_namespace. Attempt to cull this from the type. +#ifdef ALLEGROCL_CLASS_DEBUG + Printf(stderr,"culling namespace of '%s' from '%s'\n", t, SwigType_templateprefix(t)); +#endif + String *implicit_ns = namespace_of(SwigType_templateprefix(t)); + add_defined_foreign_type(0, 0, t, t, implicit_ns ? implicit_ns : current_namespace); +} + +String *get_ffi_type(SwigType *ty, const String_or_char *name) { + /* lookup defined foreign type. + if it exists, it will return a form suitable for placing + into lisp code to generate the def-foreign-type name */ + +#ifdef ALLEGROCL_TYPE_DEBUG + Printf(stderr, "inside g_f_t: looking up %s\n", ty); +#endif + + String *found_type = lookup_defined_foreign_type(ty); + + if (found_type) { + return (Strcmp(found_type,"forward-reference") ? + Copy(found_type) : NewString(":void")); + } else { + Hash *typemap = Swig_typemap_search("ffitype", ty, name, 0); + + if (typemap) { + String *typespec = Getattr(typemap, "code"); + + return NewString(typespec); + } + + if(SwigType_istemplate(ty)) { + note_implicit_template_instantiation(ty); + return Copy(lookup_defined_foreign_type(ty)); + } + } + return 0; +} + +String *lookup_defined_foreign_ltype(String *l) { + +#ifdef ALLEGROCL_TYPE_DEBUG + Printf(stderr, "Looking up defined ltype '%s'.\n Found: '%s'\n", + l, Getattr(defined_foreign_ltypes, l)); +#endif + return Getattr(defined_foreign_ltypes, l); +} + +/* walk type and return string containing lisp version. + recursive. */ +String *internal_compose_foreign_type(SwigType *ty) { + + SwigType *tok; + String *ffiType = NewString(""); + + // for a function type, need to walk the parm list. + while(Len(ty) != 0) { + tok = SwigType_pop(ty); + + if(SwigType_isfunction(tok)) { + // Generate Function wrapper + Printf(ffiType, "(:function "); + // walk parm list + List *pl = SwigType_parmlist(tok); + + Printf(ffiType, "("); // start parm list + for (Iterator i=First(pl); i.item; i = Next(i)) { + SwigType *f_arg = SwigType_strip_qualifiers(i.item); + Printf(ffiType, "%s ", internal_compose_foreign_type(f_arg)); + Delete(f_arg); + } + Printf(ffiType, ")"); // end parm list. + + // do function return type. + Printf(ffiType, " %s)", internal_compose_foreign_type(ty)); + break; + } else if (SwigType_ispointer(tok) || SwigType_isreference(tok)) { + Printf(ffiType, "(* %s)", internal_compose_foreign_type(ty)); + } else if (SwigType_isarray(tok)) { + Printf(ffiType, "(:array %s", internal_compose_foreign_type(ty)); + String *atype = NewString("int"); + String *dim = convert_literal(SwigType_array_getdim(tok, 0),atype); + Delete(atype); + if(is_integer(dim)) { + Printf(ffiType, " %s)", dim); + } else { + Printf(ffiType, " #| %s |#)", SwigType_array_getdim(tok,0)); + } + } else if (SwigType_ismemberpointer(tok)) { + // temp + Printf(ffiType, "(* %s)", internal_compose_foreign_type(ty)); + } else { + String *res; + if ((res = get_ffi_type(tok, ""))) { + Printf(ffiType, "%s", res); + } else { + SwigType *resolved_type = SwigType_typedef_resolve(tok); + while(resolved_type) { + res = get_ffi_type(resolved_type, ""); + if (res) { + Printf(ffiType, "%s", res); + break; + } else { + resolved_type = SwigType_typedef_resolve(tok); + } + } + if(!resolved_type) { + Printf(stderr,"Unknown datatype: %s\n", tok); + Printf(ffiType, "(* :void)"); + } + } + } + } + return ffiType; +} + +String *compose_foreign_type(SwigType *ty) { + + /* should we allow named lookups in the typemap here? */ + SwigType *temp = SwigType_strip_qualifiers(ty); + String *res = internal_compose_foreign_type(temp); + Delete(temp); + + return res; +} + +void update_package_if_needed(Node *n, File *f = f_clwrap) { +#ifdef ALLEGROCL_DEBUG + Printf(stderr, "update_package: ENTER... "); + Printf(stderr, " current_package = '%s'\n", current_package); + Printf(stderr, " node_package = '%s'\n", Getattr(n,"allegrocl:package")); + Printf(stderr, " node(%x) = '%s'\n", n, Getattr(n,"name")); +#endif + String *node_package = Getattr(n,"allegrocl:package"); + if(Strcmp(current_package,node_package)) { + String *lispy_package = listify_namespace(node_package); + + Delete(current_package); + current_package = Copy(node_package); + Printf(f,"\n(swig-in-package %s)\n", lispy_package); + Delete(lispy_package); + } +#ifdef ALLEGROCL_DEBUG + Printf(stderr,"EXIT\n"); +#endif +} + +static String *mangle_name(Node *n, char const *prefix = "ACL", + String *ns = current_namespace) +{ + String* suffix = Getattr(n, "sym:overname"); + String *pre_mangled_name = + NewStringf("%s_%s__%s%s", prefix, ns, Getattr(n, "sym:name"), suffix); + String *mangled_name = Swig_name_mangle(pre_mangled_name); + Delete(pre_mangled_name); + return mangled_name; +} + +/* utilities */ +/* returns new string w/ parens stripped */ +String *strip_parens(String *string) { + string = Copy(string); + Replaceall(string, "(", ""); + Replaceall(string, ")", ""); + return string; + /* + char *s=Char(string), *p; + int len=Len(string); + String *res; + + if (len==0 || s[0] != '(' || s[len-1] != ')') { + return NewString(string); + } + + p=(char *)malloc(len-2+1); + if (!p) { + Printf(stderr, "Malloc failed\n"); + SWIG_exit(EXIT_FAILURE); + } + + strncpy(p, s+1, len-1); + p[len-2]=0; // null terminate + + res=NewString(p); + free(p); + + return res; +*/ +} + +int ALLEGROCL :: validIdentifier(String *s) { + char *c = Char(s); + if (*c && !isalpha(*c) && *c != '_') return 0; + while (*c) { + if (!isalnum(*c) && *c != '_') return 0; + c++; + } + return 1; +} + +String *infix_to_prefix(String *val, char split_op, const String *op, String *type) { + List *ored = Split(val, split_op, -1); + if (Len(ored) > 1) { + String *result = NewStringf("(%s", op); + for (Iterator i = First(ored); i.item; i = Next(i)) { + String *converted = convert_literal(i.item, type); + Printf(result, " %s", converted); + Delete(converted); + } + Printf(result, ")"); + Delete(ored); + return result; + } + else { + Delete(ored); + } + return 0; +} + +/* to be called by code generating the lisp interface */ +String * convert_literal(String *num_param, String *type) { + String *trimmed = trim(num_param); + String *num=strip_parens(trimmed), *res=0; + char *s=Char(num); + + // very basic parsing of infix expressions. + if(res = infix_to_prefix(num, '|', "logior", type)) return res; + if(res = infix_to_prefix(num, '&', "logand", type)) return res; + if(res = infix_to_prefix(num, '*', "*", type)) return res; + if(res = infix_to_prefix(num, '/', "/", type)) return res; + if(res = infix_to_prefix(num, '+', "+", type)) return res; + if(res = infix_to_prefix(num, '-', "-", type)) return res; + + if (SwigType_type(type) == T_FLOAT || + SwigType_type(type) == T_DOUBLE || + SwigType_type(type) == T_LONGDOUBLE) { + // Use CL syntax for float literals + String *oldnum = Copy(num); + int fsuffixes = Replaceall(num, "f", "") + Replaceall(num, "F", ""); + int lsuffixes = Replaceall(num, "l", "") + Replaceall(num, "L", ""); + char const *lisp_exp = fsuffixes ? "f" : (lsuffixes ? "l" : "d"); + int exponents = Replaceall(num, "e", lisp_exp) + + Replaceall(num, "E", lisp_exp); + if ((fsuffixes + lsuffixes) > 1 || exponents > 1) { + Printf(stderr, "Weird!! number %s looks invalid.\n", oldnum); + SWIG_exit(EXIT_FAILURE); + } + if (!exponents) + Printf(num, "%s0", lisp_exp); + Delete(oldnum); Delete(trimmed); + return num; + } + else if (SwigType_type(type) == T_CHAR) { + /* Use CL syntax for character literals */ + Delete(num); Delete(trimmed); + return NewStringf("#\\%s", num_param); + } + else if (SwigType_type(type) == T_STRING) { + /* Use CL syntax for string literals */ + Delete(num); Delete(trimmed); + return NewStringf("\"%s\"", num_param); + } + else if (allegrocl->validIdentifier(num)) { + /* convert C/C++ identifiers to CL symbols */ + String *ns = listify_namespace(current_namespace); + res = NewStringf("#.(swig-insert-id \"%s\" %s :type :constant)", num, ns); + Delete(num); Delete(trimmed); Delete(ns); + return res; + } + else if (Len(num) >= 1 && isdigit(s[0])) { + /* use CL syntax for numbers */ + String *oldnum = Copy(num); + int usuffixes = Replaceall(num, "u", "") + Replaceall(num, "U", ""); + int lsuffixes = Replaceall(num, "l", "") + Replaceall(num, "L", ""); + if (usuffixes > 1 || lsuffixes > 1) { + Printf(stderr, "Weird!! number %s looks invalid.\n", oldnum); + SWIG_exit(EXIT_FAILURE); + } + s = Char(num); + if (s[0] == '0' && Len(num) >= 2) { + /*octal or hex */ + res=NewStringf("#%c%s", + tolower(s[1]) == 'x' ? 'x' : 'o', + s+2); + Delete(num); + } + else + { + res=num; + } + Delete(oldnum); Delete(trimmed); + return res; + } else { + Delete(trimmed); + return num; + } +} + + +void emit_stub_class(Node *n) { + String *name = Getattr(n,"sym:name"); + + if(Getattr(n,"allegrocl:synonym:already-been-stubbed")) return; + + if(SwigType_istemplate(name)) { + String *temp = strip_namespaces(SwigType_templateprefix(name)); + name = NewStringf("%s%s%s", temp, + SwigType_templateargs(name), + SwigType_templatesuffix(name)); + + Delete(temp); + } else { + name = strip_namespaces(name); + } + + // Printf(f_clhead, ";; from emit-stub-class\n"); + update_package_if_needed(n,f_clhead); + Printf(f_clhead, ";; class template stub.\n"); + Printf(f_clhead,"(swig-def-foreign-stub \"%s\")\n", name); + + Setattr(n,"allegrocl:synonym:already-been-stubbed","1"); +} + +void emit_synonym(Node *synonym) { + + // Printf(stderr,"in emit_synonym for %s(%x)\n", Getattr(synonym,"name"),synonym); + int is_tempInst = !Strcmp(nodeType(synonym),"templateInst"); + String *synonym_type; + + Node *of = get_primary_synonym_of(synonym); + + if(is_tempInst) { + synonym_type = Getattr(synonym,"real-name"); + } else { + synonym_type = Getattr(synonym,"name"); + } + + String *synonym_ns = listify_namespace(Getattr(synonym,"allegrocl:namespace")); + // String *of_cdeclname = Getattr(of,"allegrocl:classDeclarationName"); + String *of_ns = Getattr(of,"allegrocl:namespace"); + String *of_ns_list = listify_namespace(of_ns); + // String *of_name = of_cdeclname ? NewStringf("struct %s", Getattr(of,"name")) : NewStringf("%s::%s", of_ns, Getattr(of,"sym:name")); + // String *of_name = NewStringf("%s::%s", of_ns, Getattr(of,"sym:name")); + String *of_name = namespaced_name(of, of_ns); + String *syn_ltype = lookup_defined_foreign_ltype(synonym_type); + String *syn_type = lookup_defined_foreign_type(synonym_type); + String *of_ltype = lookup_defined_foreign_ltype(of_name); + + // Printf(f_clhead,";; from emit-synonym\n"); + Printf(f_clhead,"(swig-def-synonym-type %s\n %s\n %s)\n", syn_ltype, of_ltype, syn_type); + + Delete(synonym_ns); + Delete(of_ns_list); + Delete(of_name); +} + +void emit_full_class(Node *n) { + String *name=Getattr(n, "sym:name"); + String *kind = Getattr(n,"kind"); + + // Printf(stderr,"in emit_full_class: '%s'(%x).", Getattr(n,"name"),n); + if(Getattr(n,"allegrocl:synonym-of")) { + // Printf(stderr,"but it's a synonym of something.\n"); + update_package_if_needed(n,f_clhead); + emit_synonym(n); + return; + } + + // collect superclasses + String *bases = Getattr(n,"bases"); + String *supers = NewString("("); + if(bases) { + int first=1; + for (Iterator i=First(bases); i.item; i = Next(i)) { + if (!first) Printf(supers," "); + String *s = lookup_defined_foreign_ltype(Getattr(i.item,"name")); + // String *name = Getattr(i.item,"name"); + if(s) { + Printf(supers,"%s",s); + } else { +#ifdef ALLEGROCL_TYPE_DEBUG + Printf(stderr,"emit_templ_inst: did not find ltype for base class %s (%s)", Getattr(i.item,"name"), Getattr(n,"allegrocl:namespace")); +#endif + } + } + } else { + Printf(supers,"ff:foreign-pointer"); + } + + Printf(supers,")"); + + // Walk children to generate type definition. + String *slotdefs = NewString(" "); + + Node *c; + for (c=firstChild(n); c; c=nextSibling(c)) { + String *storage_type = Getattr(c,"storage"); + if((!Strcmp(nodeType(c),"cdecl") && + (!storage_type || Strcmp(storage_type,"typedef")))) { + String *access = Getattr(c,"access"); + SwigType *childType=NewStringf("%s%s", Getattr(c,"decl"), + Getattr(c,"type")); + String *cname = (access && Strcmp(access,"public")) ? + NewString("nil") : Copy(Getattr(c,"name")); + + if(!SwigType_isfunction(childType)) { + // Printf(slotdefs, ";;; member functions don't appear as slots.\n "); + // Printf(slotdefs, ";; "); + String *ns = listify_namespace(Getattr(n, "allegrocl:package")); + Printf(slotdefs, "(#.(swig-insert-id \"%s\" %s :type :slot :class \"%s\") %s)", + cname, ns, name, compose_foreign_type(childType)); + Delete(ns); + if(access && Strcmp(access,"public")) + Printf(slotdefs, " ;; %s member", access); + + Printf(slotdefs, "\n "); + } + Delete(childType); + Delete(cname); + } + } + + String *ns_list = listify_namespace(Getattr(n,"allegrocl:namespace")); + update_package_if_needed(n,f_clhead); + Printf(f_clhead, + "(swig-def-foreign-class \"%s\"\n %s\n (:%s\n%s))\n\n", + name, supers, kind, slotdefs); + + Delete(supers); + Delete(ns_list); +} + +void emit_class(Node *n) { + int is_tempInst = !Strcmp(nodeType(n),"templateInst"); + + String *ns_list = listify_namespace(Getattr(n,"allegrocl:namespace")); + String *name = Getattr(n,is_tempInst ? "real-name" : "name"); + + if(SwigType_istemplate(name)) { + String *temp = strip_namespaces(SwigType_templateprefix(name)); + name = NewStringf("%s%s%s", temp, + SwigType_templateargs(name), + SwigType_templatesuffix(name)); + + Delete(temp); + } else { + name = strip_namespaces(name); + } + + // Printf(stderr,"in emit-class: %s(%x)\n", name, n); + if(Getattr(n,"allegrocl:synonym:is-primary")) { + // Printf(stderr," is primary... "); + if(is_tempInst) { + emit_stub_class(n); + } else { + emit_full_class(n); + } + } else { + // Node *primary = Getattr(n,"allegrocl:synonym-of"); + Node *primary = get_primary_synonym_of(n); + if(primary && (primary != n)) { + // Printf(stderr," emitting synonym... "); + emit_stub_class(primary); + update_package_if_needed(n,f_clhead); + emit_synonym(n); + } else { + emit_full_class(n); + } + } + // Printf(stderr,"DONE\n"); + Delete(name); + Delete(ns_list); +} + +void emit_typedef(Node *n) { + String *name; + + String *sym_name = Getattr(n,"sym:name"); + String *type = NewStringf("%s%s", Getattr(n,"decl"), Getattr(n,"type")); + String *lisp_type = compose_foreign_type(type); + Delete(type); + Node *in_class = Getattr(n,"allegrocl:typedef:in-class"); + + // Printf(stderr,"in emit_typedef: '%s'(%x).",Getattr(n,"name"),n); + if(Getattr(n,"allegrocl:synonym-of")) { + // Printf(stderr," but it's a synonym of something.\n"); + emit_synonym(n); + return; + } + + if(in_class) { + String *class_name = Getattr(in_class,"name"); + if(SwigType_istemplate(class_name)) { + String *temp = strip_namespaces(SwigType_templateprefix(class_name)); + class_name = NewStringf("%s%s%s", temp, + SwigType_templateargs(class_name), + SwigType_templatesuffix(class_name)); + Delete(temp); + } + + name = NewStringf("%s__%s",class_name,sym_name); + Setattr(n,"allegrocl:in-class",in_class); + } else { + name = Copy(sym_name); + } + + // leave these in for now. might want to change these to def-foreign-class at some point. +// Printf(f_clhead, ";; %s\n", SwigType_typedef_resolve_all(lisp_type)); + Printf(f_clhead, "(swig-def-foreign-type \"%s\"\n %s)\n", name, lisp_type); + + Delete(name); +} + +void emit_enum_type_no_wrap(Node *n) { + if(String *name=Getattr(n,"sym:name")) { + String *ns = listify_namespace(current_namespace); + SwigType *enumtype = compose_foreign_type(Getattr(n,"type")); + + Printf(f_clhead,"(swig-def-foreign-type \"%s\" %s)\n", name, enumtype); + Delete(ns); + + // walk children. + Node *c; + for(c = firstChild(n); c; c=nextSibling(c)) { + if(!Getattr(c,"error")) { + String *val = Getattr(c,"enumvalue"); + if(!val) val = Getattr(c,"enumvalueex"); + + val = convert_literal(val,Getattr(c,"type")); + + String *valname = Getattr(c,"sym:name"); + Printf(f_clhead,"(swig-defconstant \"%s\" %s)\n", valname, val); + } + } + } + Printf(f_clhead,"\n"); +} + +void emit_enum_type(Node *n) { + if(!CPlusPlus) { + emit_enum_type_no_wrap(n); + return; + } + + if(String *name=Getattr(n,"sym:name")) { + String *ns = listify_namespace(current_namespace); + SwigType *enumtype = compose_foreign_type(Getattr(n,"type")); + + Printf(f_clhead,"(swig-def-foreign-type \"%s\" %s)\n", name, enumtype); + Delete(ns); + + // walk children. + Node *c; + for(c = firstChild(n); c; c=nextSibling(c)) { + String *mangled_name = mangle_name(c, "ACL_ENUM", Getattr(c,"allegrocl:package")); + Printf(f_clhead, "(swig-defvar \"%s\" \"%s\" :type :constant)\n", + Getattr(c, "sym:name"), mangled_name); + Delete(mangled_name); + } + } +} + +void emit_default_linked_type(Node *n) { + + // catchall for non class types. + if(!Strcmp(nodeType(n),"classforward")) { + Printf(f_clhead,";; forward referenced stub.\n"); + Printf(f_clhead,"(swig-def-foreign-type \"%s\" (:class ))\n\n", + Getattr(n,"sym:name")); + } else if(!Strcmp(nodeType(n),"enum")) { + emit_enum_type(n); + } else { + Printf(stderr,"Don't know how to emit node type '%s' named '%s'\n", + nodeType(n), Getattr(n,"name")); + } +} + +void dump_linked_types(File *f) { + Node *n = first_linked_type; + int i = 0; + while(n) { + Printf(f,"%d: (%x) node '%s' name '%s'\n", i++, n, nodeType(n), Getattr(n,"sym:name")); + + Node *t; + if(t = Getattr(n,"allegrocl:synonym-of")) + Printf(f," synonym-of %s(%x)\n",Getattr(t,"name"),t); + n = Getattr(n,"allegrocl:next_linked_type"); + } +} + +void emit_linked_types() { + Node *n = first_linked_type; + + while(n) { + String *node_type = nodeType(n); + + // Printf(stderr,"emitting node %s(%x) of type %s.", Getattr(n,"name"),n, nodeType(n)); + if(!Strcmp(node_type,"class") || !Strcmp(node_type,"templateInst")) { + // may need to emit a stub, so it will update the package itself. + // Printf(stderr," Passing to emit_class."); + emit_class(n); + } else if(!Strcmp(nodeType(n),"cdecl")) { + // Printf(stderr," Passing to emit_typedef."); + update_package_if_needed(n,f_clhead); + emit_typedef(n); + } else { + // Printf(stderr," Passing to default_emitter."); + update_package_if_needed(n,f_clhead); + emit_default_linked_type(n); + } + + n = Getattr(n,"allegrocl:next_linked_type"); + // Printf(stderr,"returned.\n"); + } +} + +extern "C" Language *swig_allegrocl(void) { + return (allegrocl = new ALLEGROCL()); +} + +void ALLEGROCL :: main(int argc, char *argv[]) { + int i; + + SWIG_library_directory("allegrocl"); + SWIG_config_file("allegrocl.swg"); + + for(i=1; i\n" + "\tSpecifies the type of conversion to do on C identifiers to convert\n" + "\tthem to symbols. There are two built-in converters: 'null' and\n" + "\t 'lispify'. The default is 'null'. If you supply a name other\n" + "\tthan one of the built-ins, then a function by that name will be\n" + "\tcalled to convert identifiers to symbols.\n"); + + } + + } + + allow_overloading(); +} + +int ALLEGROCL :: top(Node *n) { + String *module=Getattr(n, "name"); + String *cxx_filename=Getattr(n, "outfile"); + String *cl_filename=NewString(""); + + Printf(cl_filename, "%s%s.cl", SWIG_output_directory(), module); + + f_cl=NewFile(cl_filename, "w"); + if (!f_cl) { + Printf(stderr, "Unable to open %s for writing\n", cl_filename); + SWIG_exit(EXIT_FAILURE); + } + + if (CPlusPlus) + { + f_cxx=NewFile(cxx_filename, "w"); + if (!f_cxx) { + Close(f_cl); Delete(f_cl); + Printf(stderr, "Unable to open %s for writing\n", cxx_filename); + SWIG_exit(EXIT_FAILURE); + } + } + else f_cxx=NewString(""); + + f_cxx_header = f_cxx; + f_cxx_wrapper=NewString(""); + + Swig_register_filebyname("header",f_cxx_header); + Swig_register_filebyname("wrapper",f_cxx_wrapper); + Swig_register_filebyname("runtime",f_cxx); + Swig_register_filebyname("lisp", f_clwrap); + Swig_register_filebyname("lisphead", f_cl); + + Printf(f_cl, ";; This is an automatically generated file. Make changes in\n" + ";; the definition file, not here.\n\n" + "(defpackage :swig\n" + " (:use :common-lisp :ff :excl)\n" + " (:export #:*swig-identifier-converter* #:*swig-module-name*))\n" + "(in-package :swig)\n\n" + "(eval-when (compile load eval)\n" + " (defparameter *swig-identifier-converter* '%s)\n" + " (defparameter *swig-module-name* :%s))\n\n", + identifier_converter, module); + Printf(f_cl, "(defpackage :%s\n" + " (:use :common-lisp :swig :ff :excl))\n\n", + module); + + Language::top(n); + +// SwigType_emit_type_table(f_cxx,f_cxx_wrapper); + + // Swig_print_tree(n); +#ifdef ALLEGROCL_TYPE_DEBUG + dump_linked_types(stderr); +#endif + emit_linked_types(); + + Printf(f_clwrap, "\n(in-package :swig)\n"); + Printf(f_clwrap, "\n(macrolet ((swig-do-export ()\n"); + Printf(f_clwrap, " `(dolist (s ',*swig-export-list*)\n"); + Printf(f_clwrap, " (apply #'export s))))\n"); + Printf(f_clwrap, " (swig-do-export))\n"); + Printf(f_clwrap, "\n(setq *swig-export-list* nil)\n"); + + Printf(f_cl, "%s\n", f_clhead); + Printf(f_cl, "%s\n", f_clwrap); + + Printf(stderr, "All done now!\n"); + + Close(f_cl); + Delete(f_cl); // Delete the handle, not the file + Delete(f_clhead); + Delete(f_clwrap); + /*if (CPlusPlus)*/ Close(f_cxx); + Delete(f_cxx); + Delete(f_cxx_wrapper); + + // Swig_print_tree(n); + + return SWIG_OK; +} + +/* very shamelessly 'borrowed' from overload.cxx, which + keeps the below Swig_overload_rank() code to itself. + We don't need a dispatch function in the C++ wrapper + code; we want it over on the lisp side. */ + +#define MAX_OVERLOAD 256 + +/* Overload "argc" and "argv" */ +// String *argv_template_string; +// String *argc_template_string; + +struct Overloaded { + Node *n; /* Node */ + int argc; /* Argument count */ + ParmList *parms; /* Parameters used for overload check */ + int error; /* Ambiguity error */ }; -static File *f_cl=0; -static File *f_null=0; +/* ----------------------------------------------------------------------------- + * Swig_overload_rank() + * + * This function takes an overloaded declaration and creates a list that ranks + * all overloaded methods in an order that can be used to generate a dispatch + * function. + * Slight difference in the way this function is used by scripting languages and + * statically typed languages. The script languages call this method via + * Swig_overload_dispatch() - where wrappers for all overloaded methods are generated, + * however sometimes the code can never be executed. The non-scripting languages + * call this method via Swig_overload_check() for each overloaded method in order + * to determine whether or not the method should be wrapped. Note the slight + * difference when overloading methods that differ by const only. The + * scripting languages will ignore the const method, whereas the non-scripting + * languages ignore the first method parsed. + * ----------------------------------------------------------------------------- */ -static struct { - int count; - String **entries; -} defined_foreign_types; +static List * +Swig_overload_rank(Node *n, bool script_lang_wrapping) { + Overloaded nodes[MAX_OVERLOAD]; + int nnodes = 0; + Node *o = Getattr(n,"sym:overloaded"); + Node *c; -static const char *identifier_converter="identifier-convert-null"; + if (!o) return 0; -static int any_varargs(ParmList *pl) { + c = o; + while (c) { + if (Getattr(c,"error")) { + c = Getattr(c,"sym:nextSibling"); + continue; + } + /* if (SmartPointer && Getattr(c,"cplus:staticbase")) { + c = Getattr(c,"sym:nextSibling"); + continue; + } */ + + /* Make a list of all the declarations (methods) that are overloaded with + * this one particular method name */ + if (Getattr(c,"wrap:name")) { + nodes[nnodes].n = c; + nodes[nnodes].parms = Getattr(c,"wrap:parms"); + nodes[nnodes].argc = emit_num_required(nodes[nnodes].parms); + nodes[nnodes].error = 0; + nnodes++; + } + c = Getattr(c,"sym:nextSibling"); + } + + /* Sort the declarations by required argument count */ + { + int i,j; + for (i = 0; i < nnodes; i++) { + for (j = i+1; j < nnodes; j++) { + if (nodes[i].argc > nodes[j].argc) { + Overloaded t = nodes[i]; + nodes[i] = nodes[j]; + nodes[j] = t; + } + } + } + } + + /* Sort the declarations by argument types */ + { + int i,j; + for (i = 0; i < nnodes-1; i++) { + if (nodes[i].argc == nodes[i+1].argc) { + for (j = i+1; (j < nnodes) && (nodes[j].argc == nodes[i].argc); j++) { + Parm *p1 = nodes[i].parms; + Parm *p2 = nodes[j].parms; + int differ = 0; + int num_checked = 0; + while (p1 && p2 && (num_checked < nodes[i].argc)) { + // Printf(stdout,"p1 = '%s', p2 = '%s'\n", Getattr(p1,"type"), Getattr(p2,"type")); + if (checkAttribute(p1,"tmap:in:numinputs","0")) { + p1 = Getattr(p1,"tmap:in:next"); + continue; + } + if (checkAttribute(p2,"tmap:in:numinputs","0")) { + p2 = Getattr(p2,"tmap:in:next"); + continue; + } + String *t1 = Getattr(p1,"tmap:typecheck:precedence"); + String *t2 = Getattr(p2,"tmap:typecheck:precedence"); + if ((!t1) && (!nodes[i].error)) { + Swig_warning(WARN_TYPEMAP_TYPECHECK, Getfile(nodes[i].n), Getline(nodes[i].n), + "Overloaded %s(%s) not supported (no type checking rule for '%s').\n", + Getattr(nodes[i].n,"name"),ParmList_str_defaultargs(Getattr(nodes[i].n,"parms")), + SwigType_str(Getattr(p1,"type"),0)); + nodes[i].error = 1; + } else if ((!t2) && (!nodes[j].error)) { + Swig_warning(WARN_TYPEMAP_TYPECHECK, Getfile(nodes[j].n), Getline(nodes[j].n), + "Overloaded %s(%s) not supported (no type checking rule for '%s').\n", + Getattr(nodes[j].n,"name"),ParmList_str_defaultargs(Getattr(nodes[j].n,"parms")), + SwigType_str(Getattr(p2,"type"),0)); + nodes[j].error = 1; + } + if (t1 && t2) { + int t1v, t2v; + t1v = atoi(Char(t1)); + t2v = atoi(Char(t2)); + differ = t1v-t2v; + } + else if (!t1 && t2) differ = 1; + else if (t2 && !t1) differ = -1; + else if (!t1 && !t2) differ = -1; + num_checked++; + if (differ > 0) { + Overloaded t = nodes[i]; + nodes[i] = nodes[j]; + nodes[j] = t; + break; + } else if ((differ == 0) && (Strcmp(t1,"0") == 0)) { + t1 = Getattr(p1,"ltype"); + if (!t1) { + t1 = SwigType_ltype(Getattr(p1,"type")); + if (Getattr(p1,"tmap:typecheck:SWIGTYPE")) { + SwigType_add_pointer(t1); + } + Setattr(p1,"ltype",t1); + } + t2 = Getattr(p2,"ltype"); + if (!t2) { + t2 = SwigType_ltype(Getattr(p2,"type")); + if (Getattr(p2,"tmap:typecheck:SWIGTYPE")) { + SwigType_add_pointer(t2); + } + Setattr(p2,"ltype",t2); + } + + /* Need subtype check here. If t2 is a subtype of t1, then we need to change the + order */ + + if (SwigType_issubtype(t2,t1)) { + Overloaded t = nodes[i]; + nodes[i] = nodes[j]; + nodes[j] = t; + } + + if (Strcmp(t1,t2) != 0) { + differ = 1; + break; + } + } else if (differ) { + break; + } + if (Getattr(p1,"tmap:in:next")) { + p1 = Getattr(p1,"tmap:in:next"); + } else { + p1 = nextSibling(p1); + } + if (Getattr(p2,"tmap:in:next")) { + p2 = Getattr(p2,"tmap:in:next"); + } else { + p2 = nextSibling(p2); + } + } + if (!differ) { + /* See if declarations differ by const only */ + String *d1 = Getattr(nodes[i].n,"decl"); + String *d2 = Getattr(nodes[j].n,"decl"); + if (d1 && d2) { + String *dq1 = Copy(d1); + String *dq2 = Copy(d2); + if (SwigType_isconst(d1)) { + Delete(SwigType_pop(dq1)); + } + if (SwigType_isconst(d2)) { + Delete(SwigType_pop(dq2)); + } + if (Strcmp(dq1,dq2) == 0) { + + if (SwigType_isconst(d1) && !SwigType_isconst(d2)) { + if (script_lang_wrapping) { + // Swap nodes so that the const method gets ignored (shadowed by the non-const method) + Overloaded t = nodes[i]; + nodes[i] = nodes[j]; + nodes[j] = t; + } + differ = 1; + if (!nodes[j].error) { + if (script_lang_wrapping) { + Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[j].n), Getline(nodes[j].n), + "Overloaded %s(%s) const ignored. Non-const method at %s:%d used.\n", + Getattr(nodes[j].n,"name"), ParmList_protostr(nodes[j].parms), + Getfile(nodes[i].n), Getline(nodes[i].n)); + } else { + if (!Getattr(nodes[j].n, "overload:ignore")) + Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n), + "Overloaded method %s(%s) ignored. Method %s(%s) const at %s:%d used.\n", + Getattr(nodes[j].n,"name"), ParmList_protostr(nodes[j].parms), + Getattr(nodes[i].n,"name"), ParmList_protostr(nodes[i].parms), + Getfile(nodes[i].n), Getline(nodes[i].n)); + } + } + nodes[j].error = 1; + } else if (!SwigType_isconst(d1) && SwigType_isconst(d2)) { + differ = 1; + if (!nodes[j].error) { + if (script_lang_wrapping) { + Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[j].n), Getline(nodes[j].n), + "Overloaded %s(%s) const ignored. Non-const method at %s:%d used.\n", + Getattr(nodes[j].n,"name"), ParmList_protostr(nodes[j].parms), + Getfile(nodes[i].n), Getline(nodes[i].n)); + } else { + if (!Getattr(nodes[j].n, "overload:ignore")) + Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n), + "Overloaded method %s(%s) const ignored. Method %s(%s) at %s:%d used.\n", + Getattr(nodes[j].n,"name"), ParmList_protostr(nodes[j].parms), + Getattr(nodes[i].n,"name"), ParmList_protostr(nodes[i].parms), + Getfile(nodes[i].n), Getline(nodes[i].n)); + } + } + nodes[j].error = 1; + } + } + Delete(dq1); + Delete(dq2); + } + } + if (!differ) { + if (!nodes[j].error) { + if (script_lang_wrapping) { + Swig_warning(WARN_LANG_OVERLOAD_SHADOW, Getfile(nodes[j].n), Getline(nodes[j].n), + "Overloaded %s(%s)%s is shadowed by %s(%s)%s at %s:%d.\n", + Getattr(nodes[j].n,"name"), ParmList_protostr(nodes[j].parms), + SwigType_isconst(Getattr(nodes[j].n,"decl")) ? " const" : "", + Getattr(nodes[i].n,"name"), ParmList_protostr(nodes[i].parms), + SwigType_isconst(Getattr(nodes[i].n,"decl")) ? " const" : "", + Getfile(nodes[i].n),Getline(nodes[i].n)); + } else { + if (!Getattr(nodes[j].n, "overload:ignore")) + Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n), + "Overloaded method %s(%s)%s ignored. Method %s(%s)%s at %s:%d used.\n", + Getattr(nodes[j].n,"name"), ParmList_protostr(nodes[j].parms), + SwigType_isconst(Getattr(nodes[j].n,"decl")) ? " const" : "", + Getattr(nodes[i].n,"name"), ParmList_protostr(nodes[i].parms), + SwigType_isconst(Getattr(nodes[i].n,"decl")) ? " const" : "", + Getfile(nodes[i].n),Getline(nodes[i].n)); + } + nodes[j].error = 1; + } + } + } + } + } + } + List *result = NewList(); + { + int i; + for (i = 0; i < nnodes; i++) { + if (nodes[i].error) + Setattr(nodes[i].n, "overload:ignore", "1"); + Append(result,nodes[i].n); + // Printf(stdout,"[ %d ] %s\n", i, ParmList_protostr(nodes[i].parms)); + // Swig_print_node(nodes[i].n); + } + } + return result; +} + +/* end shameless borrowing */ + +int any_varargs(ParmList *pl) { Parm *p; for(p=pl; p; p=nextSibling(p)) { @@ -34,161 +1552,37 @@ static int any_varargs(ParmList *pl) { return 0; } - -/* utilities */ -/* returns new string w/ parens stripped */ -static String *strip_parens(String *string) { - char *s=Char(string), *p; - int len=Len(string); - String *res; - - if (len==0 || s[0] != '(' || s[len-1] != ')') { - return NewString(string); - } - - p=(char *)malloc(len-2+1); - if (!p) { - Printf(stderr, "Malloc failed\n"); - SWIG_exit(EXIT_FAILURE); - } - - strncpy(p, s+1, len-1); - p[len-2]=0; /* null terminate */ - - res=NewString(p); - free(p); - - return res; -} +void add_forward_referenced_type(Node *n, int overwrite = 0) +{ + String *k = Getattr(n,"name"); + String *name = Getattr(n, "sym:name"); + String *ns = listify_namespace(current_namespace); + String *val = Getattr(defined_foreign_types, k); -static String *convert_literal(String *num_param, String *type) { - String *num=strip_parens(num_param), *res; - char *s=Char(num); - - /* Make sure doubles use 'd' instead of 'e' */ - if (!Strcmp(type, "double")) { - String *updated=Copy(num); - if (Replace(updated, "e", "d", DOH_REPLACE_ANY) > 1) { - Printf(stderr, "Weird!! number %s looks invalid.\n", num); - SWIG_exit(EXIT_FAILURE); - } - Delete(num); - return updated; - } + if(!val || overwrite) { +#ifdef ALLEGROCL_TYPE_DEBUG + Printf(stderr,"Adding forward reference for %s (overwrite=%d)\n", + k, overwrite); +#endif + Setattr(defined_foreign_types,Copy(k),NewString("forward-reference")); - if (SwigType_type(type) == T_CHAR) { - /* Use CL syntax for character literals */ - return NewStringf("#\\%s", num_param); - } - else if (SwigType_type(type) == T_STRING) { - /* Use CL syntax for string literals */ - return NewStringf("\"%s\"", num_param); - } - - if (Len(num) < 2 || s[0] != '0') { - return num; - } - - /* octal or hex */ - - res=NewStringf("#%c%s", - s[1] == 'x' ? 'x' : 'o', - s+2); - Delete(num); + String *mangled_lname_gen = + NewStringf("#.(swig-insert-id \"%s\" %s :type :class)", name, ns); - return res; -} + Setattr(defined_foreign_ltypes,Copy(k),mangled_lname_gen); + // Printf(f_cl, ";; forward reference stub\n" + // "(swig-def-foreign-class \"%s\" (ff:foreign-pointer) (:class ))\n\n" + // , name); -static void add_defined_foreign_type(String *type) { - if (!defined_foreign_types.count) { - /* Make fresh */ - defined_foreign_types.count=1; - defined_foreign_types.entries=(String **)malloc(sizeof(String *)); - } else { - /* make room */ - defined_foreign_types.count++; - defined_foreign_types.entries=(String **) - realloc(defined_foreign_types.entries, - defined_foreign_types.count*sizeof(String *)); - } - - if (!defined_foreign_types.entries) { - Printf(stderr, "Out of memory\n"); - SWIG_exit(EXIT_FAILURE); - } - - /* Fill in the new data */ - defined_foreign_types.entries[defined_foreign_types.count-1]= - Copy(type); - -} - - -static String *get_ffi_type(SwigType *ty, const String_or_char *name) { - Hash *typemap = Swig_typemap_search("ffitype", ty, name, 0); - if (typemap) { - String *typespec = Getattr(typemap, "code"); - return NewString(typespec); - } - else { - List *elements; - int nelements, i; - String *head = NewString(""); - String *tail = NewString(""); - String *base_type; - do { - elements = SwigType_split(ty); - nelements = Len(elements); - for (i = 0; i\n" - "\tSpecifies the type of conversion to do on C identifiers to convert\n" - "\tthem to symbols. There are two built-in converters: 'null' and\n" - "\t 'lispify'. The default is 'null'. If you supply a name other\n" - "\tthan one of the built-ins, then a function by that name will be\n" - "\tcalled to convert identifiers to symbols.\n"); - - } - +Node *parent_node_skipping_extends(Node* n) +{ + Node* result = n; + do { + result = parentNode(result); } - - + while (Cmp("extend", nodeType(result)) == 0); + return result; } -int ALLEGROCL :: top(Node *n) { - String *module=Getattr(n, "name"); - String *output_filename=NewString(""); - String *devnull=NewString("/dev/null"); - - f_null=NewFile(devnull, "w+"); - if (!f_null) { - FileErrorDisplay(devnull); - SWIG_exit(EXIT_FAILURE); +String *id_converter_type(SwigType const *type) +{ + SwigType *t = Copy(type); + String *result = 0; + + if (SwigType_ispointer(t)) + { + SwigType_pop(t); + String *pointee = id_converter_type(t); + result = NewStringf("(:* %s)", pointee); + Delete(pointee); } - Delete(devnull); + else if (SwigType_ismemberpointer(t)) + { + String *klass = SwigType_parm(t); + SwigType_pop(t); + String *member = id_converter_type(t); + result = NewStringf("(:member \"%s\" %s)", klass, member); + Delete(klass); + Delete(member); + } + else if (SwigType_isreference(t)) + { + SwigType_pop(t); + String *referencee = id_converter_type(t); + result = NewStringf("(:& %s)", referencee); + Delete(referencee); + } + else if (SwigType_isarray(t)) + { + String *size = SwigType_parm(t); + SwigType_pop(t); + String *element_type = id_converter_type(t); + result = NewStringf("(:array %s \"%s\")", element_type, size); + Delete(size); + Delete(element_type); + } + else if (SwigType_isfunction(t)) + { + result = NewString("(:function ("); + String *parmlist_str = SwigType_parm(t); + List *parms = SwigType_parmlist(parmlist_str); + + for (Iterator i = First(parms); i.item; ) + { + String *parm = id_converter_type((SwigType *)i.item); + Printf(result, "%s", parm); + i = Next(i); + if (i.item) Printf(result, " "); + Delete(parm); + } + SwigType_pop(t); + String *ret = id_converter_type(t); + Printf(result, ") %s)", ret); + + Delete(parmlist_str); + Delete(parms); + Delete(ret); + } + else if (SwigType_isqualifier(t)) + { + result = NewString("(:qualified ("); + String *qualifiers_str = Copy(SwigType_parm(t)); // ?! + // Replaceall below SEGVs if we don't put the Copy here... + SwigType_pop(t); + String *qualifiee = id_converter_type(t); + Replaceall(qualifiers_str, " ", " :"); + if (Len(qualifiers_str) > 0) Printf(result, ":"); + Printf(result, "%s) %s)", qualifiers_str, qualifiee); + + Delete(qualifiers_str); + Delete(qualifiee); + } + else if (SwigType_istemplate(t)) + { + result = NewStringf("(:template \"%s\")", t); + } + else /* if (SwigType_issimple(t)) */ + { + if (Strstr(Char(t), "::")) + { + result = listify_namespace(t); + } + else + { + result = NewStringf("\"%s\"", t); + } + } + + Delete(t); + return result; +} - Printf(output_filename, "%s%s.cl", SWIG_output_directory(), module); +static ParmList *parmlist_with_names(ParmList *pl) +{ + ParmList* pl2 = CopyParmList(pl); + for (Parm *p = pl, *p2 = pl2; p2; + p=nextSibling(p), p2=nextSibling(p2)) + { + if (!Getattr(p2, "name")) + Setattr(p2, "name", Getattr(p2, "lname")); + Setattr(p2, "name", strip_namespaces(Getattr(p2, "name"))); + Setattr(p2, "tmap:ctype", Getattr(p, "tmap:ctype")); + } + return pl2; +} +static String *parmlist_str_id_converter(ParmList *pl) +{ + String *result = NewString(""); + for (Parm *p = pl; p; ) + { + String *lispy_type = id_converter_type(Getattr(p, "type")); + Printf(result, "(\"%s\" %s)", Getattr(p, "name"), lispy_type); + Delete(lispy_type); + if ((p=nextSibling(p))) Printf(result, " "); + } + return result; +} - f_cl=NewFile(output_filename, "w"); - if (!f_cl) { - FileErrorDisplay(output_filename); - SWIG_exit(EXIT_FAILURE); +String *collect_others_args(Node *overload) { + String *overloaded_from = Getattr(overload,"sym:overloaded"); + String *others_args = NewString(""); + int first_overload = 1; + + for (Node *overload2 = overloaded_from; + overload2; + overload2 = Getattr(overload2,"sym:nextSibling")) + { + if (overload2 == overload || + GetInt(overload2, "overload:ignore")) + continue; + + ParmList *opl = parmlist_with_names(Getattr(overload2, "wrap:parms")); + String *args = parmlist_str_id_converter(opl); + if (!first_overload) + Printf(others_args, "\n "); + Printf(others_args, "(%s)", args); + Delete(args); + Delete(opl); + first_overload = 0; + } + return others_args; +} + +struct IDargs { + String* name; + String* type; + String* klass; + String* arity; + + IDargs() : name(0), type(0), klass(0), arity(0) {} + + String* full_quoted_str() { + String *result = no_others_quoted_str(); + if (arity) Printf(result, " :arity %s", arity); + return result; } - Swig_register_filebyname("header",f_null); - Swig_register_filebyname("runtime",f_null); - Swig_register_filebyname("wrapper", f_cl); + String* no_others_quoted_str() { + String *result = NewString(""); + Printf(result, "\"%s\" :type :%s", name, type); + if (klass) Printf(result, " :class \"%s\"", klass); + return result; + } - Printf(f_cl, ";; This is an automatically generated file. Make changes in\n;; the definition file, not here.\n\n(defpackage :%s\n (:use :common-lisp :ff :excl))\n\n(in-package :%s)\n", module, module); - Printf(f_cl, "(eval-when (compile load eval)\n (defparameter *swig-identifier-converter* '%s))\n", identifier_converter); - - Language::top(n); + String* noname_str() { + String *result = NewString(""); + Printf(result, " :type :%s", type); + if (klass) Printf(result, " :class \"%s\"", klass); + if (arity) Printf(result, " :arity %s", arity); + return result; + } +}; +IDargs* id_converter_arguments(Node *n) +{ + IDargs* result = (IDargs*)GetVoid(n, "allegrocl:id-converter-args"); + if (!result) result = new IDargs; - Close(f_cl); - Delete(f_cl); // Delete the handle, not the file - Close(f_null); - Delete(f_null); + // Base name + if (!result->name) { + result->name = Getattr(n, "allegrocl:old-sym:name"); + if (!result->name) result->name = Getattr(n, "sym:name"); + result->name = Copy(result->name); + } + // :type + if (result->type) Delete(result->type); + if (!Getattr(n, "allegrocl:kind")) + Setattr(n, "allegrocl:kind", "function"); + if (Strstr(Getattr(n, "name"), "operator ")) + Replaceall(Getattr(n, "allegrocl:kind"), "function", "operator"); + if (Strstr(Getattr(n, "allegrocl:kind"), "variable")) + { + int name_end = Len(Getattr(n, "sym:name")) - 4; + char *str = Char(Getattr(n, "sym:name")); + String *get_set = NewString(str+name_end+1); + result->type = Copy(Getattr(n, "allegrocl:kind")); + Replaceall(result->type, "variable", ""); + Printf(result->type, "%ster", get_set); + Delete(get_set); + } + else + { + result->type = Copy(Getattr(n, "allegrocl:kind")); + } + + // :class + if (Strstr(result->type, "member ")) + { + Replaceall(result->type, "member ", ""); + if (!result->klass) + result->klass = Copy(Getattr(parent_node_skipping_extends(n), + "sym:name")); + } + + // :arity + if (Getattr(n, "sym:overloaded")) { + if(result->arity) Delete(result->arity); + result->arity = NewStringf("%d", + emit_num_arguments(Getattr(n, "wrap:parms"))); + } + + SetVoid(n, "allegrocl:id-converter-args", result); + return result; +} + +int ALLEGROCL :: emit_buffered_defuns(Node *n) { + + Node *overloaded_from = Getattr(n,"sym:overloaded"); + + String *wrap; + + if (!overloaded_from) { + wrap = Getattr(n,"allegrocl:lisp-wrap"); + + Printf(f_clwrap,"%s\n",wrap); + Delattr(n,"allegrocl:lisp-wrap"); + Delete(wrap); + } else { + for (Node *overload = overloaded_from; + overload; + overload = Getattr(overload,"sym:nextSibling")) + { + String *others_args = collect_others_args(overload); + wrap = Getattr(overload, "allegrocl:lisp-wrap"); + + Replaceall(wrap, "@@OTHERS-ARGS-GO-HERE@@", others_args); +// IDargs* id_args = id_converter_arguments(overload); +// Replaceall(id_args->others_args, "@@OTHERS-ARGS-GO-HERE@@", others_args); + + if (!GetInt(overload, "overload:ignore")) + Printf(f_clwrap, "%s", wrap); + + Delattr(overload, "allegrocl:lisp-wrap"); + Delete(wrap); + } + } return SWIG_OK; } -int ALLEGROCL :: functionWrapper(Node *n) { - String *funcname=Getattr(n, "sym:name"); - ParmList *pl=Getattr(n, "parms"); - Parm *p; - int argnum=0, first=1, varargs=0; - - //Language::functionWrapper(n); +String *dispatching_type(Parm* p) { + String *result = 0; - Printf(f_cl, "(swig-defun \"%s\"\n", funcname); + String *parsed = Getattr(p, "type"); //Swig_cparse_type(Getattr(p,"tmap:ctype")); + String *cl_t = SwigType_typedef_resolve_all(parsed); + + Hash *typemap = Swig_typemap_search("lispclass", parsed, Getattr(p, "name"), 0); + // Printf(stderr,"inspecting type '%s' for class\n", parsed); + // Printf(stderr," cfcocr = '%s' res_all = '%s'\n", + // class_from_class_or_class_ref(parsed), cl_t); + if (typemap) { + result = Copy(Getattr(typemap, "code")); + } else { + String *lookup_type = class_from_class_or_class_ref(parsed); + if(lookup_type) result = lookup_defined_foreign_ltype(lookup_type); + } + + // if (!result && SwigType_ispointer(cl_t)) { + // SwigType_pop(cl_t); + // result = lookup_defined_foreign_ltype(cl_t); + // } + + if (!result) + result = NewStringf("ff:foreign-pointer"); + + Delete(parsed); + Delete(cl_t); + return result; +} + +String *defmethod_lambda_list(Node* overload) { + String *result = NewString(""); + + ParmList *parms = Getattr(overload, "wrap:parms"); + Parm *p; + int a; + + for (a=0, p=parms; p; p=nextSibling(p),++a) { + if (a!=0) Printf(result, " "); + Printf(result, "(arg%d ", a); + Printf(result, "%s", dispatching_type(p)); + Printf(result, ")"); + } + + return result; +} + +int ALLEGROCL :: emit_dispatch_defun(Node *n) { + + List *overloads = Swig_overload_rank(n,true); + + String *id_args = id_converter_arguments(n)->no_others_quoted_str(); + Printf(f_clwrap, "(swig-dispatcher (%s :arities (", id_args); + + int last_arity = -1; + for (Iterator i = First(overloads); i.item; i = Next(i)) { + int arity = emit_num_arguments(Getattr(i.item, "wrap:parms")); + if (arity == last_arity) continue; + + Printf(f_clwrap, "%s%d", last_arity == -1 ? "" : " ", arity); + + last_arity = arity; + } + Printf(f_clwrap, ")))\n"); + + Delete(id_args); + Delete(overloads); + + return SWIG_OK; +} + +int ALLEGROCL :: emit_defun(Node *n, File *f_cl) { +#ifdef ALLEGROCL_DEBUG + int auto_generated = Cmp(Getattr(n, "view"), "globalfunctionHandler"); + Printf(stderr, "%s%sfunction %s%s%s\n", + auto_generated ? "> " : "", Getattr(n, "sym:overloaded") + ? "overloaded " : "", current_namespace, + (current_namespace) > 0 ? "::" : "", Getattr(n, "sym:name")); + Printf(stderr, " (view: %s)\n", Getattr(n, "view")); +#endif + + String *funcname = Getattr(n, "allegrocl:old-sym:name"); + if (!funcname) funcname = Getattr(n, "sym:name"); + String *mangled_name=mangle_name(n, "ACL", Getattr(n,"allegrocl:package")); + // SwigType *type=Copy(Getattr(n, "type")); + ParmList *pl = parmlist_with_names(Getattr(n, "wrap:parms")); + + // attach typemap info. + Wrapper *wrap = NewWrapper(); + Swig_typemap_attach_parms("lin", pl, wrap); + Swig_typemap_lookup_new("lout",n,"result",0); + + // prime the pump. + Printf(wrap->code,"$body"); + + Parm *p; + int largnum = 0, argnum=0, first=1; + // int varargs=0; + SwigType *result_type = Swig_cparse_type(Getattr(n,"tmap:ctype")); + + if (CPlusPlus) + { + String *extra_parms = id_converter_arguments(n)->noname_str(); + if (Getattr(n, "sym:overloaded")) + Printf(f_cl, "(swig-defmethod (\"%s\" \"%s\"%s)\n", + funcname, mangled_name, extra_parms); + else + Printf(f_cl, "(swig-defun (\"%s\" \"%s\"%s)\n", + funcname, mangled_name, extra_parms); + Delete(extra_parms); + } + // Just C + else + { + Printf(f_cl, "(swig-defun (\"%s\")\n", funcname); + } + + ////////////////////////////////////// + // Lisp foreign call parameter list // + ////////////////////////////////////// Printf(f_cl, " ("); /* Special cases */ if (ParmList_len(pl) == 0) { Printf(f_cl, ":void"); - } else if (any_varargs(pl)) { +/* } else if (any_varargs(pl)) { Printf(f_cl, "#| varargs |#"); - varargs=1; + varargs=1; */ } else { - for (p=pl; p; p=nextSibling(p), argnum++) { - String *argname=Getattr(p, "name"); + String *largs = NewString(""); + + for (p=pl; p; p=nextSibling(p), argnum++, largnum++) { SwigType *argtype=Getattr(p, "type"); - String *ffitype=get_ffi_type(argtype, argname); - String *lisptype=get_lisp_type(argtype, argname); - int tempargname=0; - - if (!argname) { - argname=NewStringf("arg%d", argnum); - tempargname=1; - } - + if (!first) { Printf(f_cl, "\n "); } - Printf(f_cl, "(%s %s %s)", argname, ffitype, lisptype); - first=0; - - Delete(ffitype); - Delete(lisptype); - if (tempargname) - Delete(argname); - - } - } - Printf(f_cl, ")\n"); /* finish arg list */ - Printf(f_cl, " :returning (%s %s)\n :strings-convert t\n :call-direct %s\n :optimize-for-space t)\n", - get_ffi_type(Getattr(n, "type"), "result"), - get_lisp_type(Getattr(n, "type"), "result"), - varargs ? "nil" : "t"); + if(SwigType_isvarargs(argtype)) { + Printf(stderr, "Function %s (line %d) contains varargs, which is not directly supported. Use %varargs instead.\n", Getattr(n,"name"), Getline(n)); + } else { + String *argname=NewStringf("PARM%d_%s", largnum, Getattr(p, "name")); + + // String *ffitype=get_ffi_type(argtype, argname); + String *ffitype=compose_foreign_type(argtype); + String *lisptype=get_lisp_type(argtype, argname); + + // while we're walking the parameters, generating LIN + // wrapper code... + Setattr(p,"lname",NewStringf("SWIG_arg%d", largnum)); + + String *parm_code = Getattr(p,"tmap:lin"); + if (parm_code) { + String *lname = Getattr(p,"lname"); + + Printf(largs," %s",lname); + Replaceall(parm_code,"$in", argname); + Replaceall(parm_code,"$out", lname); + + Replaceall(wrap->code,"$body", parm_code); + } + + String *dispatchtype=Getattr(n, "sym:overloaded") ? + dispatching_type(p) : + NewString(""); + + Printf(f_cl, "(%s %s %s %s)", argname, dispatchtype, ffitype, lisptype); + first=0; + + Delete(ffitype); + Delete(lisptype); + } + } + + Printf(wrap->locals,"%s",largs); + } + + String *lout = Getattr(n,"tmap:lout"); + Replaceall(wrap->code,"$body", lout); + // $lclass handling. + String *lclass = (String *)0; + SwigType *parsed = Swig_cparse_type(Getattr(n,"tmap:ctype")); + // SwigType *cl_t = SwigType_typedef_resolve_all(parsed); + SwigType *cl_t = class_from_class_or_class_ref(parsed); + Delete(parsed); + int isPtrReturn = 0; + + if(cl_t) { + lclass = lookup_defined_foreign_ltype(cl_t); + isPtrReturn = 1; + } + + // if (SwigType_ispointer(cl_t)) { + // isPtrReturn = 1; + // SwigType_pop(cl_t); + // lclass = lookup_defined_foreign_ltype(cl_t); + // } + + int ff_foreign_ptr = 0; + if(!lclass) { + ff_foreign_ptr = 1; + lclass = NewStringf("ff:foreign-pointer"); + } + +#ifdef ALLEGROCL_WRAP_DEBUG + Printf(stderr,"for output wrapping %s: type=%s, ctype=%s\n", + Getattr(n,"name"), Getattr(n,"type"), + Swig_cparse_type(Getattr(n,"tmap:ctype"))); +#endif + + if(lclass) Replaceall(wrap->code,"$lclass", lclass); + + // if(Replaceall(wrap->code,"$lclass", lclass) && !isPtrReturn) { + // Swig_warning(WARN_LANG_RETURN_TYPE,Getfile(n), Getline(n), + // "While Wrapping %s, replaced a $lclass reference when return type is non-pointer %s!\n", + // Getattr(n,"name"), cl_t); + // } + + Replaceall(wrap->code,"$body", NewStringf("(swig-ff-call%s)", + wrap->locals)); + String* ldestructor = Copy(lclass); + if (ff_foreign_ptr) + Replaceall(ldestructor, ldestructor, "identity"); + else + Replaceall(ldestructor, ":type :class", ":type :destructor"); + if (Replaceall(wrap->code,"$ldestructor", ldestructor) > 0 && + ff_foreign_ptr) { + Swig_warning(WARN_LANG_RETURN_TYPE, Getfile(n), Getline(n), + "While wrapping %s, replaced an $ldestructor reference " + "when there was no Lisp class.\n", + Getattr(n,"name")); + } + Delete(ldestructor); + Printf(f_cl, ")\n"); /* finish arg list */ + + ///////////////////////////////////////////////////// + // Lisp foreign call return type and optimizations // + ///////////////////////////////////////////////////// + Printf(f_cl, " (:returning (%s %s)", + compose_foreign_type(result_type), + get_lisp_type(Getattr(n, "type"), "result")); + + for (Iterator option = First(n); option.item; option = Next(option)) { + if (Strncmp("feature:ffargs:", option.key, 15)) continue; + String *option_val = option.item; + String *option_name = NewString(Char(option.key) + 14); + Replaceall(option_name, "_", "-"); + + // TODO: varargs vs call-direct ? + Printf(f_cl, "\n %s %s", option_name, option_val); + + Delete(option_name); + } + + Printf(f_cl,")\n %s)\n\n", wrap->code); + // Wrapper_print(wrap, stderr); + + Delete(result_type); + Delete(mangled_name); + Delete(pl); return SWIG_OK; } +int ALLEGROCL :: functionWrapper(Node *n) { + + ParmList *parms = CopyParmList(Getattr(n,"parms")); + Wrapper *wrap = NewWrapper(); + + String *raw_return_type = Swig_typemap_lookup_new("ctype",n,"",0); + SwigType *return_type = Swig_cparse_type(raw_return_type); + SwigType *resolved = SwigType_typedef_resolve_all(return_type); + int is_void_return = (Cmp(resolved, "void") == 0); + Delete(resolved); + if (!is_void_return) + { + String *lresult_init = NewStringf("lresult = (%s)0", raw_return_type); + Wrapper_add_localv(wrap,"lresult", raw_return_type, lresult_init, NIL); + Delete(lresult_init); + } + + // Emit all of the local variables for holding arguments. + emit_args(Getattr(n, "type"), parms, wrap); + + // Attach the standard typemaps + Swig_typemap_attach_parms("ctype", parms, wrap); + emit_attach_parmmaps(parms, wrap); + + String *mangled = mangle_name(n); + Node *overloaded = Getattr(n,"sym:overloaded"); + + // Parameter overloading + Setattr(n,"wrap:parms", parms); + Setattr(n,"wrap:name", mangled); + + if (overloaded) { + // emit warnings when overloading is impossible on the lisp side. + // basically Swig_overload_check(n), but with script_lang_wrapping + // set to true. + Delete(Swig_overload_rank(n, true)); + if (Getattr(n, "overload:ignore")) { + // if we're the last overload, make sure to force the emit + // of the rest of the overloads before we leave. + Printf(stderr, "ignored overload %s(%x)\n", Getattr(n,"name"), + Getattr(n,"sym:nextSibling")); + if(!Getattr(n,"sym:nextSibling")) { + update_package_if_needed(n); + emit_buffered_defuns(n); + emit_dispatch_defun(n); + } + return SWIG_OK; + } + } + + // Get number of required and total arguments + int num_arguments = emit_num_arguments(parms); + int gencomma = 0; + +#ifdef ALLEGROCL_DEBUG + Printf(stderr,"Walking parameters for %s '%s'\n", Getattr(n,"allegrocl:kind"), Getattr(n,"name")); +#endif + // Now walk the function parameter list and generate code to get arguments + String *name_and_parms = NewStringf("%s (", mangled); + int i; Parm *p; + for (i = 0, p=parms; i < num_arguments; i++) { + + while (checkAttribute(p,"tmap:in:numinputs","0")) { + p = Getattr(p,"tmap:in:next"); + } + + SwigType *c_parm_type = Swig_cparse_type(Getattr(p, "tmap:ctype")); + String *arg = NewStringf("l%s", Getattr(p,"lname")); + + // Emit parameter declaration + if (gencomma) Printf(name_and_parms, ", "); + String *parm_decl = SwigType_str(c_parm_type, arg); + Printf(name_and_parms, "%s", parm_decl); +#ifdef ALLEGROCL_DEBUG + Printf(stderr," param: %s\n", parm_decl); +#endif + Delete(parm_decl); + gencomma = 1; + + // Emit parameter conversion code + String *parm_code = Getattr(p,"tmap:in"); + //if (!parm_code) { + // Swig_warning(...); + // p = nextSibling(p); + /*} else*/ { + // canThrow(n, "in", p); + Replaceall(parm_code,"$input", arg); + Setattr(p,"emit:input", arg); + Printf(wrap->code,"%s\n", parm_code); + p = Getattr(p,"tmap:in:next"); + } + + Delete(arg); + } + Printf(name_and_parms, ")"); + + // Emit the function definition + String *signature = SwigType_str(return_type, name_and_parms); + Printf(wrap->def, "EXPORT %s {", signature); + Printf(wrap->code," try {\n"); + emit_action(n, wrap); + if (!is_void_return) + { + String *result_convert = Swig_typemap_lookup_new("out",n,"result",0); + Replaceall(result_convert, "$result", "lresult"); + Printf(wrap->code, "%s\n", result_convert); + Printf(wrap->code, " return lresult;\n"); + Delete(result_convert); + } + Printf(wrap->code," } catch (...) {\n"); + if (!is_void_return) + Printf(wrap->code," return (%s)0;\n", raw_return_type); + Printf(wrap->code," }\n"); + Printf(wrap->code,"}\n"); + + if (CPlusPlus) + Wrapper_print(wrap, f_cxx); + + String *f_buffer = NewString(""); + + emit_defun(n,f_buffer); + Setattr(n,"allegrocl:lisp-wrap",f_buffer); + + if (!overloaded || !Getattr(n, "sym:nextSibling")) { + update_package_if_needed(n); + emit_buffered_defuns(n); + // this is the last overload. + if (overloaded) { + emit_dispatch_defun(n); + } + } + + return SWIG_OK; +} + +int ALLEGROCL :: namespaceDeclaration(Node *n) { + // Empty namespaces are not worth DEFPACKAGEing. + if (!firstChild(n)) return SWIG_OK; + + String *name=Getattr(n, "sym:name"); + + String *old_namespace = current_namespace; + if (Cmp(current_namespace, "") == 0) + current_namespace = NewStringf("%s", name); + else + current_namespace = NewStringf("%s::%s", current_namespace, name); + + if (!GetInt(defined_namespace_packages, current_namespace)) + { + SetInt(defined_namespace_packages, current_namespace, 1); + String *lispy_namespace = listify_namespace(current_namespace); + Printf(f_clhead, "(swig-defpackage %s)\n", lispy_namespace); + Delete(lispy_namespace); + } + + emit_children(n); + + Delete(current_namespace); + current_namespace = old_namespace; + return SWIG_OK; +} + +int ALLEGROCL :: constructorHandler(Node *n) +{ +#ifdef ALLEGROCL_DEBUG + Printf(stderr, "constructor %s\n", Getattr(n, "name")); +#endif + + Setattr(n, "allegrocl:kind", "constructor"); + Setattr(n, "allegrocl:old-sym:name", Getattr(n, "sym:name")); + + // Let SWIG generate a global forwarding function. + return Language::constructorHandler(n); +} + +int ALLEGROCL :: destructorHandler(Node *n) +{ +#ifdef ALLEGROCL_DEBUG + Printf(stderr, "destructor %s\n", Getattr(n, "name")); +#endif + + Setattr(n, "allegrocl:kind", "destructor"); + Setattr(n, "allegrocl:old-sym:name", Getattr(n, "sym:name")); + + // Let SWIG generate a global forwarding function. + return Language::destructorHandler(n); +} + int ALLEGROCL :: constantWrapper(Node *n) { +#ifdef ALLEGROCL_DEBUG + Printf(stderr, "constant %s\n", Getattr(n, "name")); +#endif String *type=Getattr(n, "type"); String *converted_value=convert_literal(Getattr(n, "value"), type); String *name=Getattr(n, "sym:name"); + Setattr(n, "allegrocl:kind", "constant"); + Setattr(n, "allegrocl:old-sym:name", Getattr(n, "sym:name")); + #if 0 Printf(stdout, "constant %s is of type %s. value: %s\n", - name, type, converted_value); + name, type, converted_value); #endif - Printf(f_cl, "(swig-defconstant \"%s\" %s)\n", - name, converted_value); + Printf(f_clwrap, "(swig-defconstant \"%s\" %s)\n", + name, converted_value); Delete(converted_value); return SWIG_OK; } -// Includes structs -int ALLEGROCL :: classDeclaration(Node *n) { - String *name=Getattr(n, "sym:name"); +int ALLEGROCL :: globalvariableHandler(Node *n) { + if(CPlusPlus) return Language::globalvariableHandler(n); + + // String *name = Getattr(n, "name"); + SwigType *type = Getattr(n,"type"); + SwigType *ctype; + SwigType *rtype = SwigType_typedef_resolve_all(type); + + int pointer_added = 0; + + if(SwigType_isclass(rtype)) { + SwigType_add_pointer(type); + SwigType_add_pointer(rtype); + pointer_added = 1; + } + + ctype = SwigType_str(type,0); + // EXPORT ; + // = ; + // Printf(f_cxx, "EXPORT %s %s;\n%s %s = %s%s;\n", ctype, mangled_name, + // ctype, mangled_name, (pointer_added ? "&" : ""), name); + + Printf(f_clwrap, "(swig-defvar \"%s\" \"%s\" :type %s)\n", + Getattr(n,"sym:name"), Getattr(n,"sym:name"), + ((SwigType_isconst(type)) ? ":constant" : ":variable")); + + return SWIG_OK; +} + +int ALLEGROCL :: variableWrapper(Node *n) { +#ifdef ALLEGROCL_DEBUG + Printf(stderr, "variable %s\n", Getattr(n, "name")); +#endif + Setattr(n, "allegrocl:kind", "variable"); + Setattr(n, "allegrocl:old-sym:name", Getattr(n, "sym:name")); + + // Let SWIG generate a get/set function pair. + if(CPlusPlus) return Language::variableWrapper(n); + + /* + String *name = Getattr(n, "name"); + SwigType *type = Getattr(n,"type"); + SwigType *ctype; + SwigType *rtype = SwigType_typedef_resolve_all(type); + + int pointer_added = 0; + + if(SwigType_isclass(rtype)) { + SwigType_add_pointer(type); + SwigType_add_pointer(rtype); + pointer_added = 1; + } + + ctype = SwigType_str(type,0); + // EXPORT ; + // = ; + // Printf(f_cxx, "EXPORT %s %s;\n%s %s = %s%s;\n", ctype, mangled_name, + // ctype, mangled_name, (pointer_added ? "&" : ""), name); + + Printf(f_cl, "(swig-defvar \"%s\" :type %s)\n", + Getattr(n,"sym:name"), + ((SwigType_isconst(type)) ? ":constant" : ":variable")); + */ + + /* + Printf(f_cxx, "// swigtype: %s\n", SwigType_typedef_resolve_all(Getattr(n,"type"))); + Printf(f_cxx, "// vwrap: %s\n", compose_foreign_type(SwigType_strip_qualifiers(Copy(rtype)))); + */ + + // Delete(mangled_name); + + return SWIG_OK; +} + +int ALLEGROCL :: memberfunctionHandler(Node *n) { +#ifdef ALLEGROCL_DEBUG + Printf(stderr, "member function %s::%s\n", + Getattr(parent_node_skipping_extends(n), "name"), Getattr(n, "name")); +#endif + Setattr(n, "allegrocl:kind", "member function"); + Setattr(n, "allegrocl:old-sym:name", Getattr(n, "sym:name")); + + // Let SWIG generate a global forwarding function. + return Language::memberfunctionHandler(n); +} + +int ALLEGROCL :: membervariableHandler(Node *n) { +#ifdef ALLEGROCL_DEBUG + Printf(stderr, "member variable %s::%s\n", + Getattr(parent_node_skipping_extends(n), "name"), Getattr(n, "name")); +#endif + Setattr(n, "allegrocl:kind", "member variable"); + Setattr(n, "allegrocl:old-sym:name", Getattr(n, "sym:name")); + + // Let SWIG generate a get/set function pair. + return Language::membervariableHandler(n); +} + +int ALLEGROCL :: typedefHandler(Node *n) { + +#ifdef ALLEGROCL_TYPE_DEBUG + Printf(stderr,"In typedefHAND\n"); +#endif + + // has the side-effect of noting any implicit + // template instantiations in type. + Delete(compose_foreign_type(Getattr(n,"type"))); + + String *sym_name = Getattr(n,"sym:name"); + + String *name; + String *type_ref; + + if(in_class) { + Setattr(n,"allegrocl:typedef:in-class",in_class); + } + + if(in_class) { + String *class_name = Getattr(in_class,"name"); + name = NewStringf("%s__%s",class_name,sym_name); + type_ref = NewStringf("%s::%s", class_name, sym_name); + Setattr(n,"allegrocl:in-class",in_class); + } else { + name = Copy(sym_name); + type_ref = Copy(Getattr(n,"name")); + } + + Setattr(n,"allegrocl:namespace",current_namespace); + add_defined_foreign_type(n, 0, type_ref, name); + +#ifdef ALLEGROCL_TYPE_DEBUG + Printf(stderr,"Out typedefHAND\n"); +#endif + + return SWIG_OK; +} + +// forward referenced classes are added specially to defined_foreign_types +int ALLEGROCL :: classforwardDeclaration(Node *n) { + add_forward_referenced_type(n); + return SWIG_OK; +} + +int ALLEGROCL :: classHandler(Node *n) { +#ifdef ALLEGROCL_DEBUG + Printf(stderr, "class %s::%s\n", current_namespace, + Getattr(n, "sym:name")); +#endif + String *name=Getattr(n, "sym:name"); String *kind = Getattr(n,"kind"); - Node *c; - if (Strcmp(kind, "struct")) { + // maybe just remove this check and get rid of the else clause below. + if (Strcmp(kind, "struct") == 0 || + Strcmp(kind, "class") == 0 || + Strcmp(kind, "union") == 0) + { + if (CPlusPlus) + return cppClassHandler(n); + else + return cClassHandler(n); + } + // else if (Strcmp(kind, "union") == 0) + // { + // Printf(f_cl, ";; There should be a union type named \"%s\" here.\n", + // name); + // return SWIG_OK; + // } + else + { Printf(stderr, "Don't know how to deal with %s kind of class yet.\n", - kind); + kind); Printf(stderr, " (name: %s)\n", name); SWIG_exit(EXIT_FAILURE); + return SWIG_OK; } - - Printf(f_cl, - "(swig-def-foreign-type \"%s\"\n (:struct\n", - name); - - for (c=firstChild(n); c; c=nextSibling(c)) { - SwigType *type=Getattr(c, "type"); - String *lisp_type; - - if (Strcmp(nodeType(c), "cdecl")) { - Printf(stderr, "Structure %s has a slot that we can't deal with.\n", - name); - Printf(stderr, "nodeType: %s, name: %s, type: %s\n", - nodeType(c), - Getattr(c, "name"), - Getattr(c, "type")); - SWIG_exit(EXIT_FAILURE); - } - - - /* Printf(stdout, "Converting %s in %s\n", type, name); */ - lisp_type=get_ffi_type(type, Getattr(c, "sym:name")); - - Printf(f_cl, - " (#.(funcall *swig-identifier-converter* \"%s\" :type :slot) %s)\n", - Getattr(c, "sym:name"), - lisp_type); - - Delete(lisp_type); - } - - Printf(f_cl, " ))\n"); - - /* Add this structure to the known lisp types */ - //Printf(stdout, "Adding %s foreign type\n", name); - add_defined_foreign_type(name); return SWIG_OK; } -extern "C" Language *swig_allegrocl(void) { - return new ALLEGROCL(); +int ALLEGROCL :: cClassHandler(Node *n) { + // String *cDeclName = Getattr(n,"classDeclaration:name"); + // String *name= Getattr(n, "sym:name"); + // String *kind = Getattr(n,"kind"); + // Node *c; + + /* Add this structure to the known lisp types */ + // Printf(stderr, "Adding %s foreign type\n", name); + String *ns = listify_namespace(current_namespace); + +#ifdef ALLEGROCL_TYPE_DEBUG + Printf(stderr,"In cClassHAND\n"); +#endif + + add_defined_foreign_type(n); + + Delete(ns); + +#ifdef ALLEGROCL_TYPE_DEBUG + Printf(stderr,"Out cClassHAND\n"); +#endif + + return SWIG_OK; } +int ALLEGROCL :: cppClassHandler(Node *n) { + // String *name=Getattr(n, "sym:name"); + // String *kind = Getattr(n,"kind"); + /* Template instantiation. + Careful. + SWIG does not create instantiations of templated classes whenever + it sees a templated class reference (say, as a return type, or + in a parameter list). + + The %template directive results in a templated class instantiation + that will actually be seen by :: classHandler(). + + In this case, we don't want to error if the type already exists; + the point is to force the creation of wrappers for the templated + class. + */ + String *templated = Getattr(n,"template"); + String *t_name; + // String *ns = listify_namespace(current_namespace); + + if(templated) { + t_name = namespaced_name(n); + // t_name = Getattr(n,"name"); + } else { + t_name = Getattr(n,"name"); + } + + Setattr(n,"allegrocl:namespace",current_namespace); + + /* Add this structure to the known lisp types. + Class may contain references to the type currently being + defined */ + if(!templated || !lookup_defined_foreign_type(t_name)) { +#ifdef ALLEGROCL_DEBUG + Printf(stderr, "Adding %s foreign type\n", Getattr(n,"sym:name")); +#endif + add_defined_foreign_type(n); + } else { +#ifdef ALLEGROCL_DEBUG + Printf(stderr, "cppClassHand: type %s already exists. Assuming %%template instantiation for wrapping purposes.\n", Getattr(n,"sym:name")); +#endif + add_defined_foreign_type(n,1); + } + + // mjb - for real fun, generate wrappers for class slot access. + + // Generate slot accessors, constructor, and destructor. + Node *prev_class = in_class; + in_class = n; + + Node *c; + // walk all member variables. + for(c=firstChild(n); c; c=nextSibling(c)) { + // ping the types of all children--even protected and private + // so their types can be added to the linked_type_list. + SwigType *childType = NewStringf("%s%s", Getattr(c,"decl"), + Getattr(c,"type")); + if(!SwigType_isfunction(childType)) + Delete(compose_foreign_type(childType)); + } + + // this will walk all necessary methods. + Language::classHandler(n); + in_class = prev_class; + + return SWIG_OK; +} + +int ALLEGROCL :: emit_one(Node *n) +{ + // When the current package does not correspond with the current + // namespace we need to generate an IN-PACKAGE form, unless the + // current node is another namespace node. + if (Cmp(nodeType(n), "namespace") != 0 && + Cmp(current_package, current_namespace) != 0) + { + String *lispy_namespace = listify_namespace(current_namespace); + Printf(f_clwrap, "(swig-in-package %s)\n", lispy_namespace); + Delete(lispy_namespace); + Delete(current_package); + current_package = NewStringf("%s", current_namespace); + } + + Setattr(n,"allegrocl:package",current_package); + + return Language::emit_one(n); +} + +int ALLEGROCL :: enumDeclaration(Node *n) { + + if(Getattr(n,"sym:name")) { + add_defined_foreign_type(n); + } + Node *c; + for(c = firstChild(n); c; c=nextSibling(c)) { + ALLEGROCL::enumvalueDeclaration(c); + // since we walk our own children, we need to add + // the current package ourselves. + Setattr(c,"allegrocl:package",current_package); + } + return SWIG_OK; +} + +int ALLEGROCL :: enumvalueDeclaration(Node *n) { + + if(CPlusPlus) { + String *mangled_name = mangle_name(n, "ACL_ENUM"); + + Printf(f_cxx, "EXPORT const %s %s = %s;\n", Getattr(n, "type"), + mangled_name, Getattr(n, "value")); + + Delete(mangled_name); + } + + return SWIG_OK; +} + +int ALLEGROCL :: templateDeclaration(Node *n) { + + String *type = Getattr(n,"templatetype"); + + // Printf(stderr, "tempDecl: %s %s\n", Getattr(n,"name"), + // type); + // Swig_print_node(n); + + if(!Strcmp(type,"cdecl")) { + SwigType *ty = NewStringf("%s%s",Getattr(n,"decl"), + Getattr(n,"type")); + Delete(ty); + } + Delete(type); + + return SWIG_OK; +}