[Pike] Remove code for Pike
We dropped support for it in SWIG 4.0.0 and nobody has stepped forward to revive it in over 2 years. See #2009.
This commit is contained in:
parent
12f3a85916
commit
11bb422bd3
37 changed files with 5 additions and 2534 deletions
|
|
@ -7,6 +7,11 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
|
|||
Version 4.1.0 (in progress)
|
||||
===========================
|
||||
|
||||
2021-05-13: olly
|
||||
[Pike] #2009 Remove code for Pike. We dropped support for it in
|
||||
SWIG 4.0.0 and nobody has stepped forward to revive it in over 2
|
||||
years.
|
||||
|
||||
2021-05-13: olly
|
||||
[Modula3] #2009 Remove code for Modula3. We dropped support for it
|
||||
in SWIG 4.0.0 and nobody has stepped forward to revive it in over 2
|
||||
|
|
|
|||
|
|
@ -1,246 +0,0 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>SWIG and Pike</title>
|
||||
<link rel="stylesheet" type="text/css" href="style.css">
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
</head>
|
||||
|
||||
<body bgcolor="#ffffff">
|
||||
<H1><a name="Pike">37 SWIG and Pike</a></H1>
|
||||
<!-- INDEX -->
|
||||
<div class="sectiontoc">
|
||||
<ul>
|
||||
<li><a href="#Pike_nn2">Preliminaries</a>
|
||||
<ul>
|
||||
<li><a href="#Pike_nn3">Running SWIG</a>
|
||||
<li><a href="#Pike_nn4">Getting the right header files</a>
|
||||
<li><a href="#Pike_nn5">Using your module</a>
|
||||
</ul>
|
||||
<li><a href="#Pike_nn6">Basic C/C++ Mapping</a>
|
||||
<ul>
|
||||
<li><a href="#Pike_nn7">Modules</a>
|
||||
<li><a href="#Pike_nn8">Functions</a>
|
||||
<li><a href="#Pike_nn9">Global variables</a>
|
||||
<li><a href="#Pike_nn10">Constants and enumerated types</a>
|
||||
<li><a href="#Pike_nn11">Constructors and Destructors</a>
|
||||
<li><a href="#Pike_nn12">Static Members</a>
|
||||
</ul>
|
||||
</ul>
|
||||
</div>
|
||||
<!-- INDEX -->
|
||||
|
||||
|
||||
|
||||
<p>
|
||||
This chapter describes SWIG support for Pike. As of this writing, the
|
||||
SWIG Pike module is still under development and is not considered
|
||||
ready for prime time. The Pike module is being developed against the
|
||||
Pike 7.4.10 release and may not be compatible with previous versions
|
||||
of Pike.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
This chapter covers most SWIG features, but certain low-level details
|
||||
are covered in less depth than in earlier chapters. At the very
|
||||
least, make sure you read the "<a href="SWIG.html#SWIG">SWIG Basics</a>"
|
||||
chapter.<br>
|
||||
</p>
|
||||
|
||||
<H2><a name="Pike_nn2">37.1 Preliminaries</a></H2>
|
||||
|
||||
|
||||
<H3><a name="Pike_nn3">37.1.1 Running SWIG</a></H3>
|
||||
|
||||
|
||||
<p>
|
||||
Suppose that you defined a SWIG module such as the following:
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
<pre>%module example<br><br>%{<br>#include "example.h"<br>%}<br><br>int fact(int n);<br></pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
To build a C extension module for Pike, run SWIG using the <tt>-pike</tt> option :
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
<pre>$ <b>swig -pike example.i</b><br></pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
If you're building a C++ extension, be sure to add the <tt>-c++</tt> option:
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
<pre>$ <b>swig -c++ -pike example.i</b><br></pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
This creates a single source file named <tt>example_wrap.c</tt> (or <tt>example_wrap.cxx</tt>, if you
|
||||
ran SWIG with the <tt>-c++</tt> option).
|
||||
The SWIG-generated source file contains the low-level wrappers that need
|
||||
to be compiled and linked with the rest of your C/C++ application to
|
||||
create an extension module.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The name of the wrapper file is derived from the name of the input
|
||||
file. For example, if the input file is <tt>example.i</tt>, the name
|
||||
of the wrapper file is <tt>example_wrap.c</tt>. To change this, you
|
||||
can use the <tt>-o</tt> option:
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
<pre>$ <b>swig -pike -o pseudonym.c example.i</b><br></pre>
|
||||
</div>
|
||||
<H3><a name="Pike_nn4">37.1.2 Getting the right header files</a></H3>
|
||||
|
||||
|
||||
<p>
|
||||
In order to compile the C/C++ wrappers, the compiler needs to know the
|
||||
path to the Pike header files. These files are usually contained in a
|
||||
directory such as
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
<pre>/usr/local/pike/7.4.10/include/pike<br></pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
There doesn't seem to be any way to get Pike itself to reveal the
|
||||
location of these files, so you may need to hunt around for them.
|
||||
You're looking for files with the names <tt>global.h</tt>, <tt>program.h</tt>
|
||||
and so on.
|
||||
</p>
|
||||
|
||||
<H3><a name="Pike_nn5">37.1.3 Using your module</a></H3>
|
||||
|
||||
|
||||
<p>
|
||||
To use your module, simply use Pike's <tt>import</tt> statement:
|
||||
</p>
|
||||
|
||||
<div class="code"><pre>
|
||||
$ <b>pike</b>
|
||||
Pike v7.4 release 10 running Hilfe v3.5 (Incremental Pike Frontend)
|
||||
> <b>import example;</b>
|
||||
> <b>fact(4);</b>
|
||||
(1) Result: 24
|
||||
</pre></div>
|
||||
|
||||
<H2><a name="Pike_nn6">37.2 Basic C/C++ Mapping</a></H2>
|
||||
|
||||
|
||||
<H3><a name="Pike_nn7">37.2.1 Modules</a></H3>
|
||||
|
||||
|
||||
<p>
|
||||
All of the code for a given SWIG module is wrapped into a single Pike
|
||||
module. Since the name of the shared library that implements your
|
||||
module ultimately determines the module's name (as far as Pike is
|
||||
concerned), SWIG's <tt>%module</tt> directive doesn't really have any
|
||||
significance.
|
||||
</p>
|
||||
|
||||
<H3><a name="Pike_nn8">37.2.2 Functions</a></H3>
|
||||
|
||||
|
||||
<p>
|
||||
Global functions are wrapped as new Pike built-in functions. For
|
||||
example,
|
||||
</p>
|
||||
|
||||
<div class="code"><pre>
|
||||
%module example
|
||||
|
||||
int fact(int n);
|
||||
</pre></div>
|
||||
|
||||
<p>
|
||||
creates a new built-in function <tt>example.fact(n)</tt> that works
|
||||
exactly as you'd expect it to:
|
||||
</p>
|
||||
|
||||
<div class="code"><pre>
|
||||
> <b>import example;</b>
|
||||
> <b>fact(4);</b>
|
||||
(1) Result: 24
|
||||
</pre></div>
|
||||
|
||||
<H3><a name="Pike_nn9">37.2.3 Global variables</a></H3>
|
||||
|
||||
|
||||
<p>
|
||||
Global variables are currently wrapped as a pair of functions, one to get
|
||||
the current value of the variable and another to set it. For example, the
|
||||
declaration
|
||||
</p>
|
||||
|
||||
<div class="code"><pre>
|
||||
%module example
|
||||
|
||||
double Foo;
|
||||
</pre></div>
|
||||
|
||||
<p>
|
||||
will result in two functions, <tt>Foo_get()</tt> and <tt>Foo_set()</tt>:
|
||||
</p>
|
||||
|
||||
<div class="code"><pre>
|
||||
> <b>import example;</b>
|
||||
> <b>Foo_get();</b>
|
||||
(1) Result: 3.000000
|
||||
> <b>Foo_set(3.14159);</b>
|
||||
(2) Result: 0
|
||||
> <b>Foo_get();</b>
|
||||
(3) Result: 3.141590
|
||||
</pre></div>
|
||||
|
||||
<H3><a name="Pike_nn10">37.2.4 Constants and enumerated types</a></H3>
|
||||
|
||||
|
||||
<p>
|
||||
Enumerated types in C/C++ declarations are wrapped as Pike constants,
|
||||
not as Pike enums.
|
||||
</p>
|
||||
|
||||
<H3><a name="Pike_nn11">37.2.5 Constructors and Destructors</a></H3>
|
||||
|
||||
|
||||
<p>
|
||||
Constructors are wrapped as <tt>create()</tt> methods, and destructors are
|
||||
wrapped as <tt>destroy()</tt> methods, for Pike classes.
|
||||
</p>
|
||||
|
||||
<H3><a name="Pike_nn12">37.2.6 Static Members</a></H3>
|
||||
|
||||
|
||||
<p>
|
||||
Since Pike doesn't support static methods or data for Pike classes, static
|
||||
member functions in your C++ classes are wrapped as regular functions and
|
||||
static member variables are wrapped as pairs of functions (one to get the
|
||||
value of the static member variable, and another to set it). The names of
|
||||
these functions are prepended with the name of the class.
|
||||
For example, given this C++ class declaration:
|
||||
</p>
|
||||
|
||||
<div class="code"><pre>
|
||||
class Shape
|
||||
{
|
||||
public:
|
||||
static void print();
|
||||
static int nshapes;
|
||||
};
|
||||
</pre></div>
|
||||
|
||||
<p>
|
||||
SWIG will generate a <tt>Shape_print()</tt> method that invokes the static
|
||||
<tt>Shape::print()</tt> member function, as well as a pair of methods,
|
||||
<tt>Shape_nshapes_get()</tt> and <tt>Shape_nshapes_set()</tt>, to get and set
|
||||
the value of <tt>Shape::nshapes</tt>.
|
||||
</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
# see top-level Makefile.in
|
||||
class
|
||||
constants
|
||||
enum
|
||||
overload
|
||||
simple
|
||||
template
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
TOP = ../..
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
CXXSRCS = example.cxx
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
LIBS = -lm
|
||||
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_run
|
||||
|
||||
build:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' pike_cpp
|
||||
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
TARGET='mypike' INTERFACE='$(INTERFACE)' pike_cpp_static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_clean
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
/* File : example.cxx */
|
||||
|
||||
#include "example.h"
|
||||
#define M_PI 3.14159265358979323846
|
||||
|
||||
/* Move the shape to a new location */
|
||||
void Shape::move(double dx, double dy) {
|
||||
x += dx;
|
||||
y += dy;
|
||||
}
|
||||
|
||||
int Shape::nshapes = 0;
|
||||
|
||||
double Circle::area() {
|
||||
return M_PI*radius*radius;
|
||||
}
|
||||
|
||||
double Circle::perimeter() {
|
||||
return 2*M_PI*radius;
|
||||
}
|
||||
|
||||
double Square::area() {
|
||||
return width*width;
|
||||
}
|
||||
|
||||
double Square::perimeter() {
|
||||
return 4*width;
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
/* File : example.h */
|
||||
|
||||
class Shape {
|
||||
public:
|
||||
Shape() {
|
||||
nshapes++;
|
||||
}
|
||||
virtual ~Shape() {
|
||||
nshapes--;
|
||||
}
|
||||
double x, y;
|
||||
void move(double dx, double dy);
|
||||
virtual double area() = 0;
|
||||
virtual double perimeter() = 0;
|
||||
static int nshapes;
|
||||
};
|
||||
|
||||
class Circle : public Shape {
|
||||
private:
|
||||
double radius;
|
||||
public:
|
||||
Circle(double r) : radius(r) { }
|
||||
virtual double area();
|
||||
virtual double perimeter();
|
||||
};
|
||||
|
||||
class Square : public Shape {
|
||||
private:
|
||||
double width;
|
||||
public:
|
||||
Square(double w) : width(w) { }
|
||||
virtual double area();
|
||||
virtual double perimeter();
|
||||
};
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
|
||||
%{
|
||||
#include "example.h"
|
||||
%}
|
||||
|
||||
/* Let's just grab the original header file here */
|
||||
%include "example.h"
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
import .example;
|
||||
|
||||
int main()
|
||||
{
|
||||
// ----- Object creation -----
|
||||
|
||||
write("Creating some objects:\n");
|
||||
Circle c = Circle(10.0);
|
||||
write(" Created circle.\n");
|
||||
Square s = Square(10.0);
|
||||
write(" Created square.\n");
|
||||
|
||||
// ----- Access a static member -----
|
||||
|
||||
write("\nA total of " + Shape_nshapes_get() + " shapes were created\n");
|
||||
|
||||
// ----- Member data access -----
|
||||
|
||||
// Set the location of the object
|
||||
|
||||
c->x_set(20.0);
|
||||
c->y_set(30.0);
|
||||
|
||||
s->x_set(-10.0);
|
||||
s->y_set(5.0);
|
||||
|
||||
write("\nHere is their current position:\n");
|
||||
write(" Circle = (%f, %f)\n", c->x_get(), c->y_get());
|
||||
write(" Square = (%f, %f)\n", s->x_get(), s->y_get());
|
||||
|
||||
// ----- Call some methods -----
|
||||
|
||||
write("\nHere are some properties of the shapes:\n");
|
||||
write(" The circle:\n");
|
||||
write(" area = %f.\n", c->area());
|
||||
write(" perimeter = %f.\n", c->perimeter());
|
||||
write(" The square:\n");
|
||||
write(" area = %f.\n", s->area());
|
||||
write(" perimeter = %f.\n", s->perimeter());
|
||||
|
||||
write("\nGuess I'll clean up now\n");
|
||||
|
||||
/* See if we can force 's' to be garbage-collected */
|
||||
s = 0;
|
||||
|
||||
/* Now we should be down to only 1 shape */
|
||||
write("%d shapes remain\n", Shape_nshapes_get());
|
||||
|
||||
/* Done */
|
||||
write("Goodbye\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
TOP = ../..
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
SRCS =
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_run
|
||||
|
||||
build:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' pike
|
||||
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
TARGET='mypike' INTERFACE='$(INTERFACE)' pike_static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_clean
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
|
||||
/* A few preprocessor macros */
|
||||
|
||||
#define ICONST 42
|
||||
#define FCONST 2.1828
|
||||
#define CCONST 'x'
|
||||
#define CCONST2 '\n'
|
||||
#define SCONST "Hello World"
|
||||
#define SCONST2 "\"Hello World\""
|
||||
|
||||
/* This should work just fine */
|
||||
#define EXPR ICONST + 3*(FCONST)
|
||||
|
||||
/* This shouldn't do anything */
|
||||
#define EXTERN extern
|
||||
|
||||
/* Neither should this (BAR isn't defined) */
|
||||
#define FOO (ICONST + BAR)
|
||||
|
||||
/* The following directives also produce constants */
|
||||
|
||||
%constant int iconst = 37;
|
||||
%constant double fconst = 3.14;
|
||||
|
||||
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
int main()
|
||||
{
|
||||
write("ICONST = %d (should be 42)\n", .example.ICONST);
|
||||
write("FCONST = %f (should be 2.1828)\n", .example.FCONST);
|
||||
write("CCONST = %c (should be 'x')\n", .example.CCONST);
|
||||
write("CCONST2 = %c (this should be on a new line)\n", .example.CCONST2);
|
||||
write("SCONST = %s (should be 'Hello World')\n", .example.SCONST);
|
||||
write("SCONST2 = %s (should be '\"Hello World\"')\n", .example.SCONST2);
|
||||
write("EXPR = %f (should be 48.5484)\n", .example.EXPR);
|
||||
write("iconst = %d (should be 37)\n", .example.iconst);
|
||||
write("fconst = %f (should be 3.14)\n", .example.fconst);
|
||||
|
||||
if (search(indices(.example), "EXTERN") == -1)
|
||||
write("EXTERN isn't defined (good)\n");
|
||||
else
|
||||
write("EXTERN is defined (bad)\n");
|
||||
|
||||
if (search(indices(.example), "FOO") == -1)
|
||||
write("FOO isn't defined (good)\n");
|
||||
else
|
||||
write("FOO is defined (bad)\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
TOP = ../..
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
CXXSRCS = example.cxx
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
LIBS = -lm
|
||||
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_run
|
||||
|
||||
build:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' pike_cpp
|
||||
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
TARGET='mypike' INTERFACE='$(INTERFACE)' pike_cpp_static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_clean
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
This example will not compile with Pike versions 7.4.20 unless you first
|
||||
patch the Pike sources. The problem is for line 91 of Pike's "stralloc.h"
|
||||
(usually installed as /usr/local/pike/7.4.10/include/pike/stralloc.h). That
|
||||
line reads:
|
||||
|
||||
tmp.ptr=ptr;
|
||||
|
||||
but should be patched to read:
|
||||
|
||||
tmp.ptr=(p_wchar0 *) ptr;
|
||||
|
||||
This bug has been reported to the Pike developers.
|
||||
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
/* File : example.c */
|
||||
|
||||
#include "example.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void Foo::enum_test(speed s) {
|
||||
if (s == IMPULSE) {
|
||||
printf("IMPULSE speed\n");
|
||||
} else if (s == WARP) {
|
||||
printf("WARP speed\n");
|
||||
} else if (s == LUDICROUS) {
|
||||
printf("LUDICROUS speed\n");
|
||||
} else {
|
||||
printf("Unknown speed\n");
|
||||
}
|
||||
}
|
||||
|
||||
void enum_test(color c, Foo::speed s) {
|
||||
if (c == RED) {
|
||||
printf("color = RED, ");
|
||||
} else if (c == BLUE) {
|
||||
printf("color = BLUE, ");
|
||||
} else if (c == GREEN) {
|
||||
printf("color = GREEN, ");
|
||||
} else {
|
||||
printf("color = Unknown color!, ");
|
||||
}
|
||||
if (s == Foo::IMPULSE) {
|
||||
printf("speed = IMPULSE speed\n");
|
||||
} else if (s == Foo::WARP) {
|
||||
printf("speed = WARP speed\n");
|
||||
} else if (s == Foo::LUDICROUS) {
|
||||
printf("speed = LUDICROUS speed\n");
|
||||
} else {
|
||||
printf("speed = Unknown speed!\n");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
/* File : example.h */
|
||||
|
||||
enum color { RED, BLUE, GREEN };
|
||||
|
||||
class Foo {
|
||||
public:
|
||||
Foo() { }
|
||||
enum speed { IMPULSE, WARP, LUDICROUS };
|
||||
void enum_test(speed s);
|
||||
};
|
||||
|
||||
void enum_test(color c, Foo::speed s);
|
||||
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
|
||||
%{
|
||||
#include "example.h"
|
||||
%}
|
||||
|
||||
/* Let's just grab the original header file here */
|
||||
|
||||
%include "example.h"
|
||||
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
int main()
|
||||
{
|
||||
write("*** color ***\n");
|
||||
write(" RED = " + .example.RED + "\n");
|
||||
write(" BLUE = " + .example.BLUE + "\n");
|
||||
write(" GREEN = " + .example.GREEN + "\n");
|
||||
|
||||
write("\n*** Foo::speed ***\n");
|
||||
write(" Foo_IMPULSE = " + .example.Foo.IMPULSE + "\n");
|
||||
write(" Foo_WARP = " + .example.Foo.WARP + "\n");
|
||||
write(" Foo_LUDICROUS = " + .example.Foo.LUDICROUS + "\n");
|
||||
|
||||
write("\nTesting use of enums with functions\n\n");
|
||||
|
||||
.example.enum_test(.example.RED, .example.Foo.IMPULSE);
|
||||
.example.enum_test(.example.BLUE, .example.Foo.WARP);
|
||||
.example.enum_test(.example.GREEN, .example.Foo.LUDICROUS);
|
||||
.example.enum_test(1234, 5678);
|
||||
|
||||
write("\nTesting use of enum with class method\n");
|
||||
.example.Foo f = .example.Foo();
|
||||
|
||||
f->enum_test(.example.Foo.IMPULSE);
|
||||
f->enum_test(.example.Foo.WARP);
|
||||
f->enum_test(.example.Foo.LUDICROUS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
TOP = ../..
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
CXXSRCS = example.cxx
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
LIBS = -lstdc++ -lm
|
||||
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_run
|
||||
|
||||
build:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' pike_cpp
|
||||
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
TARGET='mypike' INTERFACE='$(INTERFACE)' pike_cpp_static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_clean
|
||||
|
|
@ -1,115 +0,0 @@
|
|||
#include <iostream>
|
||||
|
||||
#include "example.h"
|
||||
|
||||
// Overloaded constructors for class Bar
|
||||
Bar::Bar() {
|
||||
std::cout << "Called Bar::Bar()" << std::endl;
|
||||
}
|
||||
|
||||
Bar::Bar(const Bar&) {
|
||||
std::cout << "Called Bar::Bar(const Bar&)" << std::endl;
|
||||
}
|
||||
|
||||
Bar::Bar(double x) {
|
||||
std::cout << "Called Bar::Bar(double) with x = " << x << std::endl;
|
||||
}
|
||||
|
||||
Bar::Bar(double x, char *y) {
|
||||
std::cout << "Called Bar::Bar(double, char *) with x, y = " << x << ", \"" << y << "\"" << std::endl;
|
||||
}
|
||||
|
||||
Bar::Bar(int x, int y) {
|
||||
std::cout << "Called Bar::Bar(int, int) with x, y = " << x << ", " << y << std::endl;
|
||||
}
|
||||
|
||||
Bar::Bar(char *x) {
|
||||
std::cout << "Called Bar::Bar(char *) with x = \"" << x << "\"" << std::endl;
|
||||
}
|
||||
|
||||
Bar::Bar(int x) {
|
||||
std::cout << "Called Bar::Bar(int) with x = " << x << std::endl;
|
||||
}
|
||||
|
||||
Bar::Bar(long x) {
|
||||
std::cout << "Called Bar::Bar(long) with x = " << x << std::endl;
|
||||
}
|
||||
|
||||
Bar::Bar(Bar *x) {
|
||||
std::cout << "Called Bar::Bar(Bar *) with x = " << x << std::endl;
|
||||
}
|
||||
|
||||
// Overloaded member functions
|
||||
void Bar::foo(const Bar& x) {
|
||||
std::cout << "Called Bar::foo(const Bar&) with &x = " << &x << std::endl;
|
||||
}
|
||||
|
||||
void Bar::foo(double x) {
|
||||
std::cout << "Called Bar::foo(double) with x = " << x << std::endl;
|
||||
}
|
||||
|
||||
void Bar::foo(double x, char *y) {
|
||||
std::cout << "Called Bar::foo(double, char *) with x, y = " << x << ", \"" << y << "\"" << std::endl;
|
||||
}
|
||||
|
||||
void Bar::foo(int x, int y) {
|
||||
std::cout << "Called Bar::foo(int, int) with x, y = " << x << ", " << y << std::endl;
|
||||
}
|
||||
|
||||
void Bar::foo(char *x) {
|
||||
std::cout << "Called Bar::foo(char *) with x = \"" << x << "\"" << std::endl;
|
||||
}
|
||||
|
||||
void Bar::foo(int x) {
|
||||
std::cout << "Called Bar::foo(int) with x = " << x << std::endl;
|
||||
}
|
||||
|
||||
void Bar::foo(long x) {
|
||||
std::cout << "Called Bar::foo(long) with x = " << x << std::endl;
|
||||
}
|
||||
|
||||
void Bar::foo(Bar *x) {
|
||||
std::cout << "Called Bar::foo(Bar *) with x = " << x << std::endl;
|
||||
}
|
||||
|
||||
void Bar::spam(int x, int y, int z) {
|
||||
std::cout << "Called Bar::spam(int, int, int) with x, y, z = " << x << ", " << y << ", " << z << std::endl;
|
||||
}
|
||||
|
||||
void Bar::spam(double x, int y, int z) {
|
||||
std::cout << "Called Bar::spam(double, int, int) with x, y, z = " << x << ", " << y << ", " << z << std::endl;
|
||||
}
|
||||
|
||||
// Overloaded global methods
|
||||
void foo(const Bar& x) {
|
||||
std::cout << "Called foo(const Bar& x) with &x = " << &x << std::endl;
|
||||
}
|
||||
|
||||
void foo(double x) {
|
||||
std::cout << "Called foo(double) with x = " << x << std::endl;
|
||||
}
|
||||
|
||||
void foo(double x, char *y) {
|
||||
std::cout << "Called foo(double, char *) with x, y = " << x << ", \"" << y << "\"" << std::endl;
|
||||
}
|
||||
|
||||
void foo(int x, int y) {
|
||||
std::cout << "Called foo(int, int) with x, y = " << x << ", " << y << std::endl;
|
||||
}
|
||||
|
||||
void foo(char *x) {
|
||||
std::cout << "Called foo(char *) with x = \"" << x << "\"" << std::endl;
|
||||
}
|
||||
|
||||
void foo(int x) {
|
||||
std::cout << "Called foo(int) with x = " << x << std::endl;
|
||||
}
|
||||
|
||||
void foo(long x) {
|
||||
std::cout << "Called foo(long) with x = " << x << std::endl;
|
||||
}
|
||||
|
||||
void foo(Bar *x) {
|
||||
std::cout << "Called foo(Bar *) with x = " << x << std::endl;
|
||||
}
|
||||
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
#ifndef EXAMPLE_H
|
||||
#define EXAMPLE_H
|
||||
|
||||
class Bar {
|
||||
public:
|
||||
Bar();
|
||||
Bar(const Bar&);
|
||||
Bar(double);
|
||||
Bar(double, char *);
|
||||
Bar(int, int);
|
||||
Bar(char *);
|
||||
Bar(long);
|
||||
Bar(int);
|
||||
Bar(Bar *);
|
||||
|
||||
void foo(const Bar&);
|
||||
void foo(double);
|
||||
void foo(double, char *);
|
||||
void foo(int, int);
|
||||
void foo(char *);
|
||||
void foo(long);
|
||||
void foo(int);
|
||||
void foo(Bar *);
|
||||
|
||||
void spam(int x, int y=2, int z=3);
|
||||
void spam(double x, int y=2, int z=3);
|
||||
};
|
||||
|
||||
void foo(const Bar&);
|
||||
void foo(double);
|
||||
void foo(double, char *);
|
||||
void foo(int, int);
|
||||
void foo(char *);
|
||||
void foo(int);
|
||||
void foo(long);
|
||||
void foo(Bar *);
|
||||
|
||||
void spam(int x, int y=2, int z=3);
|
||||
void spam(double x, int y=2, int z=3);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
|
||||
%{
|
||||
#include "example.h"
|
||||
%}
|
||||
|
||||
/**
|
||||
* These overloaded declarations conflict with other overloads (as far as
|
||||
* SWIG's Ruby module's implementation for overloaded methods is concerned).
|
||||
* One option is use the %rename directive to rename the conflicting methods;
|
||||
* here, we're just using %ignore to avoid wrapping some of the overloaded
|
||||
* functions altogether.
|
||||
*/
|
||||
|
||||
%ignore Bar;
|
||||
|
||||
%ignore Bar::Bar(Bar *);
|
||||
%ignore Bar::Bar(long);
|
||||
|
||||
%ignore Bar::foo(const Bar&);
|
||||
%ignore Bar::foo(long);
|
||||
|
||||
%ignore ::foo(const Bar&);
|
||||
%ignore ::foo(int);
|
||||
|
||||
/* Let's just grab the original header file here */
|
||||
%include "example.h"
|
||||
|
|
@ -1,83 +0,0 @@
|
|||
// import .example;
|
||||
|
||||
int main()
|
||||
{
|
||||
// This should invoke foo(double)
|
||||
.example.foo(3.14159);
|
||||
|
||||
// This should invoke foo(double, char *)
|
||||
.example.foo(3.14159, "Pi");
|
||||
|
||||
// This should invoke foo(int, int)
|
||||
.example.foo(3, 4);
|
||||
|
||||
// This should invoke foo(char *)
|
||||
.example.foo("This is a test");
|
||||
|
||||
// This should invoke foo(long)
|
||||
.example.foo(42);
|
||||
|
||||
/*
|
||||
// This should invoke Bar::Bar() followed by foo(Bar *)
|
||||
foo(Bar.new);
|
||||
|
||||
// Skip a line
|
||||
write("\n");
|
||||
|
||||
// This should invoke Bar::Bar(double)
|
||||
Bar.new(3.14159);
|
||||
|
||||
// This should invoke Bar::Bar(double, char *)
|
||||
Bar.new(3.14159, "Pi");
|
||||
|
||||
// This should invoke Bar::Bar(int, int)
|
||||
Bar.new(3, 4);
|
||||
|
||||
// This should invoke Bar::Bar(char *)
|
||||
Bar.new("This is a test");
|
||||
|
||||
// This should invoke Bar::Bar(int)
|
||||
Bar.new(42);
|
||||
|
||||
// This should invoke Bar::Bar() for the input argument,
|
||||
// followed by Bar::Bar(const Bar&).
|
||||
Bar.new(Bar.new);
|
||||
|
||||
// Skip a line
|
||||
write("\n");
|
||||
*/
|
||||
|
||||
// Construct a new Bar instance (invokes Bar::Bar())
|
||||
/*
|
||||
bar = Bar.new;
|
||||
|
||||
// This should invoke Bar::foo(double)
|
||||
bar.foo(3.14159);
|
||||
|
||||
// This should invoke Bar::foo(double, char *)
|
||||
bar.foo(3.14159, "Pi");
|
||||
|
||||
// This should invoke Bar::foo(int, int)
|
||||
bar.foo(3, 4);
|
||||
|
||||
// This should invoke Bar::foo(char *)
|
||||
bar.foo("This is a test");
|
||||
|
||||
// This should invoke Bar::foo(int)
|
||||
bar.foo(42);
|
||||
|
||||
// This should invoke Bar::Bar() to construct the input
|
||||
// argument, followed by Bar::foo(Bar *).
|
||||
bar.foo(Example::Bar.new);
|
||||
|
||||
// This should invoke Bar::spam(int x, int y, int z)
|
||||
bar.spam(1);
|
||||
|
||||
// This should invoke Bar::spam(double x, int y, int z)
|
||||
bar.spam(3.14159);
|
||||
*/
|
||||
|
||||
write("Goodbye\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
TOP = ../..
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
SRCS = example.c
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_run
|
||||
|
||||
build:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' pike
|
||||
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
TARGET='mypike' INTERFACE='$(INTERFACE)' pike_static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_clean
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
/* File : example.c */
|
||||
|
||||
/* A global variable */
|
||||
double Foo = 3.0;
|
||||
|
||||
/* Compute the greatest common divisor of positive integers */
|
||||
int gcd(int x, int y) {
|
||||
int g;
|
||||
g = y;
|
||||
while (x > 0) {
|
||||
g = x;
|
||||
x = y % x;
|
||||
y = g;
|
||||
}
|
||||
return g;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
|
||||
%inline %{
|
||||
extern int gcd(int x, int y);
|
||||
extern double Foo;
|
||||
%}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
int main()
|
||||
{
|
||||
/* Call our gcd() function */
|
||||
int x = 42;
|
||||
int y = 105;
|
||||
int g = .example.gcd(x, y);
|
||||
write("The gcd of %d and %d is %d\n", x, y, g);
|
||||
|
||||
/* Manipulate the Foo global variable */
|
||||
/* Output its current value */
|
||||
write("Foo = %f\n", .example->Foo_get());
|
||||
|
||||
/* Change its value */
|
||||
.example->Foo_set(3.1415926);
|
||||
|
||||
/* See if the change took effect */
|
||||
write("Foo = %f\n", .example->Foo_get());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
TOP = ../..
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
CXXSRCS =
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
LIBS = -lm
|
||||
SWIGOPT =
|
||||
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_run
|
||||
|
||||
build:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' pike_cpp
|
||||
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='mypike' INTERFACE='$(INTERFACE)' pike_cpp_static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_clean
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
/* File : example.h */
|
||||
|
||||
// Some template definitions
|
||||
|
||||
template<class T> T max(T a, T b) { return a>b ? a : b; }
|
||||
|
||||
template<class T> class vector {
|
||||
T *v;
|
||||
int sz;
|
||||
public:
|
||||
vector(int _sz) {
|
||||
v = new T[_sz];
|
||||
sz = _sz;
|
||||
}
|
||||
T &get(int index) {
|
||||
return v[index];
|
||||
}
|
||||
void set(int index, T &val) {
|
||||
v[index] = val;
|
||||
}
|
||||
#ifdef SWIG
|
||||
%extend {
|
||||
T getitem(int index) {
|
||||
return $self->get(index);
|
||||
}
|
||||
void setitem(int index, T val) {
|
||||
$self->set(index,val);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
|
||||
%{
|
||||
#include "example.h"
|
||||
%}
|
||||
|
||||
/* Let's just grab the original header file here */
|
||||
%include "example.h"
|
||||
|
||||
/* Now instantiate some specific template declarations */
|
||||
|
||||
%template(maxint) max<int>;
|
||||
%template(maxdouble) max<double>;
|
||||
%template(vecint) vector<int>;
|
||||
%template(vecdouble) vector<double>;
|
||||
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
int main()
|
||||
{
|
||||
// Call some templated functions
|
||||
write(sprintf("%d\n", .example.maxint(3, 7)));
|
||||
write(sprintf("%f\n", .example.maxdouble(3.14, 2.18)));
|
||||
|
||||
// Create some objects
|
||||
.example.vecint iv = .example.vecint(100);
|
||||
.example.vecdouble dv = .example.vecdouble(1000);
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
iv->setitem(i, 2*i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
dv->setitem(i, 1.0/(i+1));
|
||||
}
|
||||
|
||||
int isum = 0;
|
||||
for (int i = 0; i < 100; i++) {
|
||||
isum += iv->getitem(i);
|
||||
}
|
||||
|
||||
write(sprintf("%d\n", isum));
|
||||
|
||||
float fsum = 0.0;
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
fsum += dv->getitem(i);
|
||||
}
|
||||
write(sprintf("%f\n", fsum));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
#######################################################################
|
||||
# Makefile for Pike test-suite
|
||||
#######################################################################
|
||||
|
||||
LANGUAGE = pike
|
||||
PIKE = pike
|
||||
SCRIPTSUFFIX = _runme.pike
|
||||
|
||||
srcdir = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
top_builddir = @top_builddir@
|
||||
|
||||
include $(srcdir)/../common.mk
|
||||
|
||||
# Overridden variables here
|
||||
# none!
|
||||
|
||||
# Custom tests - tests with additional commandline options
|
||||
# none!
|
||||
|
||||
# Rules for the different types of tests
|
||||
%.cpptest:
|
||||
$(setup)
|
||||
+$(swig_and_compile_cpp)
|
||||
$(run_testcase)
|
||||
|
||||
%.ctest:
|
||||
$(setup)
|
||||
+$(swig_and_compile_c)
|
||||
$(run_testcase)
|
||||
|
||||
%.multicpptest:
|
||||
$(setup)
|
||||
+$(swig_and_compile_multi_cpp)
|
||||
$(run_testcase)
|
||||
|
||||
# Runs the testcase. A testcase is only run if
|
||||
# a file is found which has _runme.pike appended after the testcase name.
|
||||
run_testcase = \
|
||||
if [ -f $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \
|
||||
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) $(PIKE) $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); \
|
||||
fi
|
||||
|
||||
# Clean: remove the generated .pike file
|
||||
%.clean:
|
||||
@rm -f $*.pike;
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' pike_clean
|
||||
|
|
@ -1,326 +0,0 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* pike.swg
|
||||
*
|
||||
* Pike configuration module.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%insert(runtime) "swigrun.swg"; // Common C API type-checking code
|
||||
%insert(runtime) "pikerun.swg"; // Pike run-time code
|
||||
|
||||
%insert(runtime) %{
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include <pike/global.h>
|
||||
#include <pike/module.h>
|
||||
#include <pike/interpret.h>
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
%}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* standard typemaps
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
/* --- Input arguments --- */
|
||||
|
||||
/* Primitive datatypes. */
|
||||
|
||||
%typemap(in, pikedesc="tInt")
|
||||
int, unsigned int, short, unsigned short,
|
||||
long, unsigned long, char, signed char, unsigned char,
|
||||
bool, enum SWIGTYPE, long long, unsigned long long
|
||||
{
|
||||
if ($input.type != T_INT)
|
||||
Pike_error("Bad argument: Expected an integer.\n");
|
||||
$1 = ($1_ltype) $input.u.integer;
|
||||
}
|
||||
|
||||
%typemap(in, pikedesc="tFloat") float, double {
|
||||
if ($input.type != T_FLOAT)
|
||||
Pike_error("Bad argument: Expected a float.\n");
|
||||
$1 = ($1_ltype) $input.u.float_number;
|
||||
}
|
||||
|
||||
%typemap(in, pikedesc="tStr") char *, char [ANY] {
|
||||
if ($input.type != T_STRING)
|
||||
Pike_error("Bad argument: Expected a string.\n");
|
||||
$1 = ($1_ltype) STR0($input.u.string);
|
||||
}
|
||||
|
||||
/* Pointers, references and arrays */
|
||||
|
||||
%typemap(in) SWIGTYPE *,
|
||||
SWIGTYPE &,
|
||||
SWIGTYPE &&,
|
||||
SWIGTYPE []
|
||||
"SWIG_ConvertPtr($input.u.object, (void **) &$1, $1_descriptor, 1);"
|
||||
|
||||
/* Void pointer. Accepts any kind of pointer */
|
||||
%typemap(in) void * "/* FIXME */";
|
||||
|
||||
/* Object passed by value. Convert to a pointer */
|
||||
%typemap(in) SWIGTYPE ($&1_ltype argp) "/* FIXME */";
|
||||
|
||||
/* Pointer to a class member */
|
||||
%typemap(in) SWIGTYPE (CLASS::*) "/* FIXME */";
|
||||
|
||||
/* Const primitive references. Passed by value */
|
||||
|
||||
%typemap(in, pikedesc="tInt") const int & (int temp),
|
||||
const short & (short temp),
|
||||
const long & (long temp),
|
||||
const unsigned int & (unsigned int temp),
|
||||
const unsigned short & (unsigned short temp),
|
||||
const unsigned long & (unsigned long temp),
|
||||
const char & (char temp),
|
||||
const signed char & (signed char temp),
|
||||
const unsigned char & (unsigned char temp),
|
||||
const bool & (bool temp),
|
||||
const long long & ($*1_ltype temp),
|
||||
const unsigned long long & ($*1_ltype temp),
|
||||
const enum SWIGTYPE & ($*1_ltype temp),
|
||||
const enum SWIGTYPE && ($*1_ltype temp)
|
||||
{
|
||||
if ($input.type != T_INT)
|
||||
Pike_error("Bad argument: Expected an integer.\n");
|
||||
temp = ($*1_ltype) $input.u.integer;
|
||||
$1 = &temp;
|
||||
}
|
||||
|
||||
%typemap(in, pikedesc="tFloat") const float & (float temp),
|
||||
const double & (double temp)
|
||||
{
|
||||
if ($input.type != T_FLOAT)
|
||||
Pike_error("Bad argument: Expected a float.\n");
|
||||
temp = ($*1_ltype) $input.u.float_number;
|
||||
$1 = &temp;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Output Typemaps
|
||||
* ----------------------------------------------------------------------------- */
|
||||
%typemap(out, pikedesc="tInt")
|
||||
int, unsigned int,
|
||||
short, unsigned short,
|
||||
long, unsigned long,
|
||||
char, signed char, unsigned char,
|
||||
bool, enum SWIGTYPE
|
||||
"push_int($1);";
|
||||
|
||||
%typemap(out, pikedesc="tInt") long long "push_int64($1);";
|
||||
%typemap(out, pikedesc="tInt") unsigned long long "push_int64($1);";
|
||||
%typemap(out, pikedesc="tFloat") float, double "push_float($1);";
|
||||
%typemap(out, pikedesc="tStr") char * "push_text($1);";
|
||||
|
||||
/* Pointers, references, and arrays */
|
||||
%typemap(out, pikedesc="tObj") SWIGTYPE*, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] "push_object(SWIG_NewPointerObj((void *) $1, $1_descriptor, $owner));";
|
||||
|
||||
/* Void return value; don't push anything */
|
||||
%typemap(out, pikedesc="tVoid") void "";
|
||||
|
||||
/* Dynamic casts */
|
||||
|
||||
%typemap(out) SWIGTYPE *DYNAMIC, SWIGTYPE &DYNAMIC "/* FIXME */";
|
||||
|
||||
/* Member pointer */
|
||||
%typemap(out) SWIGTYPE (CLASS::*) "/* FIXME */";
|
||||
|
||||
/* Special typemap for character array return values */
|
||||
%typemap(out, pikedesc="tStr") char [ANY], const char [ANY] "push_text($1);";
|
||||
|
||||
/* Primitive types--return by value */
|
||||
%typemap(out, pikedesc="tObj") SWIGTYPE
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
$&1_ltype resultptr;
|
||||
resultptr = new $1_ltype((const $1_ltype &) $1);
|
||||
push_object(SWIG_NewPointerObj((void *) resultptr, $&1_descriptor, 1));
|
||||
}
|
||||
#else
|
||||
{
|
||||
$&1_ltype resultptr;
|
||||
resultptr = ($&1_ltype) malloc(sizeof($1_type));
|
||||
memmove(resultptr, &$1, sizeof($1_type));
|
||||
push_object(SWIG_NewPointerObj((void *) resultptr, $&1_descriptor, 1));
|
||||
}
|
||||
#endif
|
||||
|
||||
/* References to primitive types. Return by value */
|
||||
|
||||
%typemap(out, pikedesc="tInt") const int &, const unsigned int &,
|
||||
const short &, const unsigned short &,
|
||||
const long &, const unsigned long &,
|
||||
const char &, const signed char &, const unsigned char &,
|
||||
const bool &,
|
||||
const long long &, const unsigned long long &,
|
||||
const enum SWIGTYPE & ($*1_ltype temp),
|
||||
const enum SWIGTYPE && ($*1_ltype temp)
|
||||
"push_int(*($1));";
|
||||
|
||||
%typemap(out, pikedesc="tFloat") const float &, const double & "push_float(*($1));";
|
||||
|
||||
/************************ Constant Typemaps *****************************/
|
||||
|
||||
%typemap(constant)
|
||||
int, unsigned int,
|
||||
short, unsigned short,
|
||||
long, unsigned long,
|
||||
signed char, unsigned char,
|
||||
bool, enum SWIGTYPE,
|
||||
long long, unsigned long long
|
||||
"add_integer_constant(\"$symname\", $1, 0);";
|
||||
|
||||
%typemap(constant) char
|
||||
"add_integer_constant(\"$symname\", '$1', 0);";
|
||||
|
||||
%typemap(constant) long long, unsigned long long
|
||||
"add_integer_constant(\"$symname\", $1, 0);";
|
||||
|
||||
%typemap(constant) float, double
|
||||
"add_float_constant(\"$symname\", $1, 0);";
|
||||
|
||||
%typemap(constant) char *
|
||||
"add_string_constant(\"$symname\", \"$1\", 0);";
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* String & length
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%typemap(in) (char *STRING, int LENGTH), (char *STRING, size_t LENGTH) {
|
||||
if ($input.type != T_STRING)
|
||||
Pike_error("Bad argument: Expected a string.\n");
|
||||
$1 = ($1_ltype) STR0($input.u.string);
|
||||
$2 = ($2_ltype) $input.u.string->length;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* ANSI C typemaps
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%typemap(in, pikedesc="tInt") size_t {
|
||||
if ($input.type != T_INT)
|
||||
Pike_error("Bad argument: Expected an integer.\n");
|
||||
$1 = ($1_ltype) $input.u.integer;
|
||||
}
|
||||
|
||||
%typemap(out) size_t = long;
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Typechecking rules
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_INTEGER)
|
||||
int, short, long,
|
||||
unsigned int, unsigned short, unsigned long,
|
||||
signed char, unsigned char,
|
||||
long long, unsigned long long,
|
||||
const int &, const short &, const long &,
|
||||
const unsigned int &, const unsigned short &, const unsigned long &,
|
||||
const long long &, const unsigned long long &,
|
||||
enum SWIGTYPE, enum SWIGTYPE &, SWIGTYPE &&,
|
||||
bool, const bool &
|
||||
{
|
||||
$1 = ($input.type == T_INT) ? 1 : 0;
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_DOUBLE)
|
||||
float, double,
|
||||
const float &, const double &
|
||||
{
|
||||
$1 = (($input.type == T_FLOAT) || ($input.type == T_INT)) ? 1 : 0;
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_CHAR) char {
|
||||
$1 = ($input.type == T_INT) ? 1 : 0;
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_STRING) char * {
|
||||
$1 = ($input.type == T_STRING) ? 1 : 0;
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] {
|
||||
void *ptr;
|
||||
if (SWIG_ConvertPtr($input.u.object, (void **) &ptr, $1_descriptor, 0) == -1) {
|
||||
$1 = 0;
|
||||
} else {
|
||||
$1 = 1;
|
||||
}
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE {
|
||||
void *ptr;
|
||||
if (SWIG_ConvertPtr($input.u.object, (void **) &ptr, $&1_descriptor, 0) == -1) {
|
||||
$1 = 0;
|
||||
} else {
|
||||
$1 = 1;
|
||||
}
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_VOIDPTR) void * {
|
||||
void *ptr;
|
||||
if (SWIG_ConvertPtr($input.u.object, (void **) &ptr, 0, 0) == -1) {
|
||||
$1 = 0;
|
||||
} else {
|
||||
$1 = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Array reference typemaps */
|
||||
%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) }
|
||||
%apply SWIGTYPE && { SWIGTYPE ((&&)[ANY]) }
|
||||
|
||||
/* const pointers */
|
||||
%apply SWIGTYPE * { SWIGTYPE *const }
|
||||
%apply SWIGTYPE (CLASS::*) { SWIGTYPE (CLASS::*const) }
|
||||
%apply SWIGTYPE & { SWIGTYPE (CLASS::*const&) }
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Overloaded operator support
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
#ifdef __cplusplus
|
||||
%rename("`+") *::operator+;
|
||||
%rename("`-") *::operator-;
|
||||
%rename("`*") *::operator*;
|
||||
%rename("`/") *::operator/;
|
||||
%rename("`%") *::operator%;
|
||||
%rename("`<<") *::operator<<;
|
||||
%rename("`>>") *::operator>>;
|
||||
%rename("`&") *::operator&;
|
||||
%rename("`|") *::operator|;
|
||||
%rename("`^") *::operator^;
|
||||
%rename("`~") *::operator~;
|
||||
%rename("`<") *::operator<;
|
||||
%rename("`>") *::operator>;
|
||||
%rename("`==") *::operator==;
|
||||
|
||||
/* Special cases */
|
||||
%rename("`()") *::operator();
|
||||
|
||||
#endif
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* The start of the Pike initialization function
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%init "swiginit.swg"
|
||||
|
||||
%init %{
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
#endif
|
||||
PIKE_MODULE_EXIT {}
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
#endif
|
||||
PIKE_MODULE_INIT
|
||||
{
|
||||
struct program *pr;
|
||||
SWIG_InitializeModule(0);
|
||||
%}
|
||||
|
||||
/* pike keywords */
|
||||
%include <pikekw.swg>
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
#ifndef PIKE_PIKEKW_SWG_
|
||||
#define PIKE_PIKEKW_SWG_
|
||||
|
||||
/* Warnings for Pike keywords */
|
||||
#define PIKEKW(x) %namewarn("314: '" #x "' is a pike keyword") #x
|
||||
|
||||
/*
|
||||
from
|
||||
http://www.http://docs.linux.cz/pike/tutorial_C.html
|
||||
|
||||
*/
|
||||
|
||||
|
||||
PIKEKW(array);
|
||||
PIKEKW(break);
|
||||
PIKEKW(case);
|
||||
PIKEKW(catch);
|
||||
PIKEKW(continue);
|
||||
PIKEKW(default);
|
||||
PIKEKW(do);
|
||||
PIKEKW(else);
|
||||
PIKEKW(float);
|
||||
PIKEKW(for);
|
||||
PIKEKW(foreach);
|
||||
PIKEKW(function);
|
||||
PIKEKW(gauge);
|
||||
PIKEKW(if);
|
||||
PIKEKW(inherit);
|
||||
PIKEKW(inline);
|
||||
PIKEKW(int);
|
||||
PIKEKW(lambda);
|
||||
PIKEKW(mapping);
|
||||
PIKEKW(mixed);
|
||||
PIKEKW(multiset);
|
||||
PIKEKW(nomask);
|
||||
PIKEKW(object);
|
||||
PIKEKW(predef);
|
||||
PIKEKW(private);
|
||||
PIKEKW(program);
|
||||
PIKEKW(protected);
|
||||
PIKEKW(public);
|
||||
PIKEKW(return);
|
||||
PIKEKW(sscanf);
|
||||
PIKEKW(static);
|
||||
PIKEKW(string);
|
||||
PIKEKW(switch);
|
||||
PIKEKW(typeof);
|
||||
PIKEKW(varargs);
|
||||
PIKEKW(void);
|
||||
PIKEKW(while);
|
||||
|
||||
|
||||
#undef PIKEKW
|
||||
|
||||
#endif //PIKE_PIKEKW_SWG_
|
||||
|
|
@ -1,71 +0,0 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* pikerun.swg
|
||||
*
|
||||
* This file contains the runtime support for Pike modules
|
||||
* and includes code for managing global variables and pointer
|
||||
* type checking.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "pike/object.h"
|
||||
#include "pike/program.h"
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#include <assert.h>
|
||||
|
||||
/* Stores information about a wrapped object */
|
||||
typedef struct swig_object_wrapper {
|
||||
void *self;
|
||||
swig_type_info *type;
|
||||
} swig_object_wrapper;
|
||||
|
||||
#ifdef THIS
|
||||
#undef THIS
|
||||
#endif
|
||||
#define THIS (((swig_object_wrapper *) Pike_fp->current_storage)->self)
|
||||
|
||||
#define SWIG_ConvertPtr SWIG_Pike_ConvertPtr
|
||||
#define SWIG_NewPointerObj SWIG_Pike_NewPointerObj
|
||||
#define SWIG_GetModule(clientdata) SWIG_Pike_GetModule(clientdata)
|
||||
#define SWIG_SetModule(clientdata, pointer) SWIG_Pike_SetModule(pointer)
|
||||
|
||||
/* These need to be filled in before type sharing between modules will work */
|
||||
static swig_module_info *SWIG_Pike_GetModule(void *SWIGUNUSEDPARM(clientdata)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void SWIG_Pike_SetModule(swig_module_info *pointer) {
|
||||
|
||||
}
|
||||
|
||||
/* Convert a pointer value */
|
||||
static int
|
||||
SWIG_Pike_ConvertPtr(struct object *obj, void **ptr, swig_type_info *ty, int flags) {
|
||||
struct program *pr;
|
||||
swig_cast_info *tc;
|
||||
swig_object_wrapper *obj_wrapper;
|
||||
|
||||
if (ty) {
|
||||
pr = (struct program *) ty->clientdata;
|
||||
obj_wrapper = (swig_object_wrapper *) get_storage(obj, pr);
|
||||
if (obj_wrapper && obj_wrapper->type) {
|
||||
tc = SWIG_TypeCheckStruct(obj_wrapper->type, ty);
|
||||
if (tc) {
|
||||
int newmemory = 0;
|
||||
*ptr = SWIG_TypeCast(tc, obj_wrapper->self, &newmemory);
|
||||
assert(!newmemory); /* newmemory handling not yet implemented */
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Create a new pointer object */
|
||||
static struct object *
|
||||
SWIG_Pike_NewPointerObj(void *ptr, swig_type_info *type, int own) {
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* std_string.i
|
||||
*
|
||||
* SWIG typemaps for std::string
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%{
|
||||
#include <string>
|
||||
%}
|
||||
|
||||
namespace std {
|
||||
|
||||
%naturalvar string;
|
||||
|
||||
class string;
|
||||
|
||||
/* Overloading check */
|
||||
|
||||
%typemap(typecheck) string = char *;
|
||||
%typemap(typecheck) const string & = char *;
|
||||
|
||||
%typemap(in, pikedesc="tStr") string {
|
||||
if ($input.type != T_STRING)
|
||||
Pike_error("Bad argument: Expected a string.\n");
|
||||
$1.assign(STR0($input.u.string));
|
||||
}
|
||||
|
||||
%typemap(in, pikedesc="tStr") const string & ($*1_ltype temp) {
|
||||
if ($input.type != T_STRING)
|
||||
Pike_error("Bad argument: Expected a string.\n");
|
||||
temp.assign(STR0($input.u.string));
|
||||
$1 = &temp;
|
||||
}
|
||||
|
||||
%typemap(out, pikedesc="tStr") string "push_text($1.c_str());";
|
||||
|
||||
%typemap(out, pikedesc="tStr") const string & "push_text($1->c_str());";
|
||||
|
||||
%typemap(directorin) string, const string &, string & "$1.c_str()";
|
||||
|
||||
%typemap(directorin) string *, const string * "$1->c_str()";
|
||||
|
||||
%typemap(directorout) string {
|
||||
if ($input.type == T_STRING)
|
||||
$result.assign(STR0($input.u.string));
|
||||
else
|
||||
throw Swig::DirectorTypeMismatchException("string expected");
|
||||
}
|
||||
|
||||
%typemap(directorout) const string & ($*1_ltype temp) {
|
||||
if ($input.type == T_STRING) {
|
||||
temp.assign(STR0($input.u.string));
|
||||
$result = &temp;
|
||||
} else {
|
||||
throw Swig::DirectorTypeMismatchException("string expected");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1,892 +0,0 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* This file is part of SWIG, which is licensed as a whole under version 3
|
||||
* (or any later version) of the GNU General Public License. Some additional
|
||||
* terms also apply to certain portions of SWIG. The full details of the SWIG
|
||||
* license and copyrights can be found in the LICENSE and COPYRIGHT files
|
||||
* included with the SWIG source code as distributed by the SWIG developers
|
||||
* and at http://www.swig.org/legal.html.
|
||||
*
|
||||
* pike.cxx
|
||||
*
|
||||
* Pike language module for SWIG.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
/*
|
||||
* Notes:
|
||||
*
|
||||
* - The current approach used for "out" typemaps is inconsistent with
|
||||
* how "out" typemaps are handled by other language modules. Instead
|
||||
* of converting the C/C++ type ($1) to a Pike object type (e.g. a
|
||||
* struct svalue), we're just calling the appropriate push_XXX
|
||||
* (e.g. push_int) to push the return value onto the stack.
|
||||
*
|
||||
* - Pike classes can't have static member functions or data, so we need
|
||||
* to find some other appropriate mapping for C++ static member functions
|
||||
* and data.
|
||||
*
|
||||
* - Pike doesn't seem to provide any default way to print the memory
|
||||
* address, etc. for extension objects. Should we do something here?
|
||||
*
|
||||
*/
|
||||
|
||||
#include "swigmod.h"
|
||||
|
||||
#include <ctype.h> // for isalnum()
|
||||
|
||||
static const char *usage = "\
|
||||
Pike Options (available with -pike)\n\
|
||||
[no additional options]\n\
|
||||
\n";
|
||||
|
||||
class PIKE:public Language {
|
||||
private:
|
||||
|
||||
File *f_begin;
|
||||
File *f_runtime;
|
||||
File *f_header;
|
||||
File *f_wrappers;
|
||||
File *f_init;
|
||||
File *f_classInit;
|
||||
|
||||
String *PrefixPlusUnderscore;
|
||||
int current;
|
||||
|
||||
// Wrap modes
|
||||
enum {
|
||||
NO_CPP,
|
||||
MEMBER_FUNC,
|
||||
CONSTRUCTOR,
|
||||
DESTRUCTOR,
|
||||
MEMBER_VAR,
|
||||
CLASS_CONST,
|
||||
STATIC_FUNC,
|
||||
STATIC_VAR
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
* PIKE()
|
||||
*
|
||||
* Initialize member data
|
||||
* --------------------------------------------------------------------- */
|
||||
|
||||
PIKE() {
|
||||
f_begin = 0;
|
||||
f_runtime = 0;
|
||||
f_header = 0;
|
||||
f_wrappers = 0;
|
||||
f_init = 0;
|
||||
f_classInit = 0;
|
||||
PrefixPlusUnderscore = 0;
|
||||
current = NO_CPP;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
* main()
|
||||
*
|
||||
* Parse command line options and initializes variables.
|
||||
* --------------------------------------------------------------------- */
|
||||
|
||||
virtual void main(int argc, char *argv[]) {
|
||||
|
||||
/* Set location of SWIG library */
|
||||
SWIG_library_directory("pike");
|
||||
|
||||
/* Look for certain command line options */
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (argv[i]) {
|
||||
if (strcmp(argv[i], "-help") == 0) {
|
||||
fputs(usage, stdout);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Add a symbol to the parser for conditional compilation */
|
||||
Preprocessor_define("SWIGPIKE 1", 0);
|
||||
|
||||
/* Set language-specific configuration file */
|
||||
SWIG_config_file("pike.swg");
|
||||
|
||||
/* Set typemap language */
|
||||
SWIG_typemap_lang("pike");
|
||||
|
||||
/* Enable overloaded methods support */
|
||||
allow_overloading();
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
* top()
|
||||
* --------------------------------------------------------------------- */
|
||||
|
||||
virtual int top(Node *n) {
|
||||
/* Get the module name */
|
||||
String *module = Getattr(n, "name");
|
||||
|
||||
/* Get the output file name */
|
||||
String *outfile = Getattr(n, "outfile");
|
||||
|
||||
/* Open the output file */
|
||||
f_begin = NewFile(outfile, "w", SWIG_output_files());
|
||||
if (!f_begin) {
|
||||
FileErrorDisplay(outfile);
|
||||
SWIG_exit(EXIT_FAILURE);
|
||||
}
|
||||
f_runtime = NewString("");
|
||||
f_init = NewString("");
|
||||
f_classInit = NewString("");
|
||||
f_header = NewString("");
|
||||
f_wrappers = NewString("");
|
||||
|
||||
/* Register file targets with the SWIG file handler */
|
||||
Swig_register_filebyname("header", f_header);
|
||||
Swig_register_filebyname("wrapper", f_wrappers);
|
||||
Swig_register_filebyname("begin", f_begin);
|
||||
Swig_register_filebyname("runtime", f_runtime);
|
||||
Swig_register_filebyname("init", f_init);
|
||||
Swig_register_filebyname("classInit", f_classInit);
|
||||
|
||||
/* Standard stuff for the SWIG runtime section */
|
||||
Swig_banner(f_begin);
|
||||
|
||||
Printf(f_runtime, "\n\n#ifndef SWIGPIKE\n#define SWIGPIKE\n#endif\n\n");
|
||||
|
||||
Printf(f_header, "#define SWIG_init pike_module_init\n");
|
||||
Printf(f_header, "#define SWIG_name \"%s\"\n\n", module);
|
||||
|
||||
/* Change naming scheme for constructors and destructors */
|
||||
Swig_name_register("construct", "%n%c_create");
|
||||
Swig_name_register("destroy", "%n%c_destroy");
|
||||
|
||||
/* Current wrap type */
|
||||
current = NO_CPP;
|
||||
|
||||
/* Emit code for children */
|
||||
Language::top(n);
|
||||
|
||||
/* Close the initialization function */
|
||||
Printf(f_init, "}\n");
|
||||
SwigType_emit_type_table(f_runtime, f_wrappers);
|
||||
|
||||
/* Close all of the files */
|
||||
Dump(f_runtime, f_begin);
|
||||
Dump(f_header, f_begin);
|
||||
Dump(f_wrappers, f_begin);
|
||||
Wrapper_pretty_print(f_init, f_begin);
|
||||
|
||||
Delete(f_header);
|
||||
Delete(f_wrappers);
|
||||
Delete(f_init);
|
||||
Delete(f_classInit);
|
||||
Delete(f_runtime);
|
||||
Delete(f_begin);
|
||||
|
||||
/* Done */
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* validIdentifier()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int validIdentifier(String *s) {
|
||||
char *c = Char(s);
|
||||
const char *c0 = c;
|
||||
const char *c1 = c0 + 1;
|
||||
while (*c) {
|
||||
if (*c == '`' && c == c0) {
|
||||
c++;
|
||||
continue;
|
||||
}
|
||||
if ((*c == '+' || *c == '-' || *c == '*' || *c == '/') && c == c1) {
|
||||
c++;
|
||||
continue;
|
||||
}
|
||||
if (!(isalnum(*c) || (*c == '_')))
|
||||
return 0;
|
||||
c++;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* importDirective()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int importDirective(Node *n) {
|
||||
String *modname = Getattr(n, "module");
|
||||
if (modname) {
|
||||
Printf(f_init, "pike_require(\"%s\");\n", modname);
|
||||
}
|
||||
return Language::importDirective(n);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* strip()
|
||||
*
|
||||
* For names that begin with the current class prefix plus an
|
||||
* underscore (e.g. "Foo_enum_test"), return the base function
|
||||
* name (i.e. "enum_test").
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
String *strip(const DOHconst_String_or_char_ptr name) {
|
||||
String *s = Copy(name);
|
||||
if (Strncmp(name, PrefixPlusUnderscore, Len(PrefixPlusUnderscore)) != 0) {
|
||||
return s;
|
||||
}
|
||||
Replaceall(s, PrefixPlusUnderscore, "");
|
||||
return s;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* add_method()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
void add_method(const DOHconst_String_or_char_ptr name, const DOHconst_String_or_char_ptr function, const DOHconst_String_or_char_ptr description) {
|
||||
String *rename = NULL;
|
||||
switch (current) {
|
||||
case NO_CPP:
|
||||
rename = NewString(name);
|
||||
Printf(f_init, "ADD_FUNCTION(\"%s\", %s, tFunc(%s), 0);\n", rename, function, description);
|
||||
break;
|
||||
case STATIC_FUNC:
|
||||
case STATIC_VAR:
|
||||
rename = NewString(name);
|
||||
Printf(f_init, "ADD_FUNCTION(\"%s\", %s, tFunc(%s), 0);\n", rename, function, description);
|
||||
break;
|
||||
case CONSTRUCTOR:
|
||||
case DESTRUCTOR:
|
||||
case MEMBER_FUNC:
|
||||
case MEMBER_VAR:
|
||||
rename = strip(name);
|
||||
Printf(f_classInit, "ADD_FUNCTION(\"%s\", %s, tFunc(%s), 0);\n", rename, function, description);
|
||||
break;
|
||||
case CLASS_CONST: // shouldn't have gotten here for CLASS_CONST nodes
|
||||
default: // what is this?
|
||||
assert(false);
|
||||
}
|
||||
Delete(rename);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
* functionWrapper()
|
||||
*
|
||||
* Create a function declaration and register it with the interpreter.
|
||||
* --------------------------------------------------------------------- */
|
||||
|
||||
virtual int functionWrapper(Node *n) {
|
||||
|
||||
String *name = Getattr(n, "name");
|
||||
String *iname = Getattr(n, "sym:name");
|
||||
SwigType *d = Getattr(n, "type");
|
||||
ParmList *l = Getattr(n, "parms");
|
||||
|
||||
Parm *p;
|
||||
String *tm;
|
||||
int i;
|
||||
|
||||
String *overname = 0;
|
||||
if (Getattr(n, "sym:overloaded")) {
|
||||
overname = Getattr(n, "sym:overname");
|
||||
} else {
|
||||
if (!addSymbol(iname, n))
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
|
||||
Wrapper *f = NewWrapper();
|
||||
|
||||
// Emit all of the local variables for holding arguments.
|
||||
emit_parameter_variables(l, f);
|
||||
|
||||
/* Attach the standard typemaps */
|
||||
emit_attach_parmmaps(l, f);
|
||||
Setattr(n, "wrap:parms", l);
|
||||
|
||||
/* Get number of required and total arguments */
|
||||
int num_arguments = emit_num_arguments(l);
|
||||
int varargs = emit_isvarargs(l);
|
||||
|
||||
/* Which input argument to start with? */
|
||||
int start = (current == MEMBER_FUNC || current == MEMBER_VAR || current == DESTRUCTOR) ? 1 : 0;
|
||||
|
||||
/* Offset to skip over the attribute name */
|
||||
// int offset = (current == MEMBER_VAR) ? 1 : 0;
|
||||
int offset = 0;
|
||||
|
||||
String *wname = Swig_name_wrapper(iname);
|
||||
if (overname) {
|
||||
Append(wname, overname);
|
||||
}
|
||||
Setattr(n, "wrap:name", wname);
|
||||
|
||||
Printv(f->def, "static void ", wname, "(INT32 args) {", NIL);
|
||||
|
||||
/* Generate code for argument marshalling */
|
||||
String *description = NewString("");
|
||||
char source[64];
|
||||
for (i = 0, p = l; i < num_arguments; i++) {
|
||||
|
||||
while (checkAttribute(p, "tmap:in:numinputs", "0")) {
|
||||
p = Getattr(p, "tmap:in:next");
|
||||
}
|
||||
|
||||
SwigType *pt = Getattr(p, "type");
|
||||
String *ln = Getattr(p, "lname");
|
||||
|
||||
if (i < start) {
|
||||
String *lstr = SwigType_lstr(pt, 0);
|
||||
Printf(f->code, "%s = (%s) THIS;\n", ln, lstr);
|
||||
Delete(lstr);
|
||||
} else {
|
||||
/* Look for an input typemap */
|
||||
sprintf(source, "Pike_sp[%d-args]", i - start + offset);
|
||||
if ((tm = Getattr(p, "tmap:in"))) {
|
||||
Replaceall(tm, "$input", source);
|
||||
Setattr(p, "emit:input", source);
|
||||
Printf(f->code, "%s\n", tm);
|
||||
String *pikedesc = Getattr(p, "tmap:in:pikedesc");
|
||||
if (pikedesc) {
|
||||
Printv(description, pikedesc, " ", NIL);
|
||||
}
|
||||
p = Getattr(p, "tmap:in:next");
|
||||
continue;
|
||||
} else {
|
||||
Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "Unable to use type %s as a function argument.\n", SwigType_str(pt, 0));
|
||||
break;
|
||||
}
|
||||
}
|
||||
p = nextSibling(p);
|
||||
}
|
||||
|
||||
/* Check for trailing varargs */
|
||||
if (varargs) {
|
||||
if (p && (tm = Getattr(p, "tmap:in"))) {
|
||||
Replaceall(tm, "$input", "varargs");
|
||||
Printv(f->code, tm, "\n", NIL);
|
||||
}
|
||||
}
|
||||
|
||||
/* Insert constraint checking code */
|
||||
for (p = l; p;) {
|
||||
if ((tm = Getattr(p, "tmap:check"))) {
|
||||
Printv(f->code, tm, "\n", NIL);
|
||||
p = Getattr(p, "tmap:check:next");
|
||||
} else {
|
||||
p = nextSibling(p);
|
||||
}
|
||||
}
|
||||
|
||||
/* Insert cleanup code */
|
||||
String *cleanup = NewString("");
|
||||
for (p = l; p;) {
|
||||
if ((tm = Getattr(p, "tmap:freearg"))) {
|
||||
Printv(cleanup, tm, "\n", NIL);
|
||||
p = Getattr(p, "tmap:freearg:next");
|
||||
} else {
|
||||
p = nextSibling(p);
|
||||
}
|
||||
}
|
||||
|
||||
/* Insert argument output code */
|
||||
String *outarg = NewString("");
|
||||
for (p = l; p;) {
|
||||
if ((tm = Getattr(p, "tmap:argout"))) {
|
||||
Replaceall(tm, "$arg", Getattr(p, "emit:input"));
|
||||
Replaceall(tm, "$input", Getattr(p, "emit:input"));
|
||||
Printv(outarg, tm, "\n", NIL);
|
||||
p = Getattr(p, "tmap:argout:next");
|
||||
} else {
|
||||
p = nextSibling(p);
|
||||
}
|
||||
}
|
||||
|
||||
/* Emit the function call */
|
||||
String *actioncode = emit_action(n);
|
||||
|
||||
/* Clear the return stack */
|
||||
Printf(actioncode, "pop_n_elems(args);\n");
|
||||
|
||||
/* Return the function value */
|
||||
if (current == CONSTRUCTOR) {
|
||||
Printv(actioncode, "THIS = (void *) ", Swig_cresult_name(), ";\n", NIL);
|
||||
Printv(description, ", tVoid", NIL);
|
||||
} else if (current == DESTRUCTOR) {
|
||||
Printv(description, ", tVoid", NIL);
|
||||
} else {
|
||||
Printv(description, ", ", NIL);
|
||||
if ((tm = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode))) {
|
||||
actioncode = 0;
|
||||
Replaceall(tm, "$result", "resultobj");
|
||||
if (GetFlag(n, "feature:new")) {
|
||||
Replaceall(tm, "$owner", "1");
|
||||
} else {
|
||||
Replaceall(tm, "$owner", "0");
|
||||
}
|
||||
String *pikedesc = Getattr(n, "tmap:out:pikedesc");
|
||||
if (pikedesc) {
|
||||
Printv(description, pikedesc, NIL);
|
||||
}
|
||||
Printf(f->code, "%s\n", tm);
|
||||
} else {
|
||||
Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(d, 0), name);
|
||||
}
|
||||
}
|
||||
if (actioncode) {
|
||||
Append(f->code, actioncode);
|
||||
Delete(actioncode);
|
||||
}
|
||||
emit_return_variable(n, d, f);
|
||||
|
||||
/* Output argument output code */
|
||||
Printv(f->code, outarg, NIL);
|
||||
|
||||
/* Output cleanup code */
|
||||
Printv(f->code, cleanup, NIL);
|
||||
|
||||
/* Look to see if there is any newfree cleanup code */
|
||||
if (GetFlag(n, "feature:new")) {
|
||||
if ((tm = Swig_typemap_lookup("newfree", n, Swig_cresult_name(), 0))) {
|
||||
Printf(f->code, "%s\n", tm);
|
||||
}
|
||||
}
|
||||
|
||||
/* See if there is any return cleanup code */
|
||||
if ((tm = Swig_typemap_lookup("ret", n, Swig_cresult_name(), 0))) {
|
||||
Printf(f->code, "%s\n", tm);
|
||||
}
|
||||
|
||||
/* Close the function */
|
||||
Printf(f->code, "}\n");
|
||||
|
||||
/* Substitute the cleanup code */
|
||||
Replaceall(f->code, "$cleanup", cleanup);
|
||||
|
||||
/* Substitute the function name */
|
||||
Replaceall(f->code, "$symname", iname);
|
||||
Replaceall(f->code, "$result", "resultobj");
|
||||
|
||||
/* Dump the function out */
|
||||
Wrapper_print(f, f_wrappers);
|
||||
|
||||
/* Now register the function with the interpreter. */
|
||||
if (!Getattr(n, "sym:overloaded")) {
|
||||
add_method(iname, wname, description);
|
||||
} else {
|
||||
if (!Getattr(n, "sym:nextSibling")) {
|
||||
dispatchFunction(n);
|
||||
}
|
||||
}
|
||||
|
||||
Delete(cleanup);
|
||||
Delete(outarg);
|
||||
Delete(description);
|
||||
Delete(wname);
|
||||
DelWrapper(f);
|
||||
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* dispatchFunction()
|
||||
*
|
||||
* Emit overloading dispatch function
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
void dispatchFunction(Node *n) {
|
||||
/* Last node in overloaded chain */
|
||||
|
||||
int maxargs;
|
||||
String *tmp = NewString("");
|
||||
String *dispatch = Swig_overload_dispatch(n, "%s(args); return;", &maxargs);
|
||||
|
||||
/* Generate a dispatch wrapper for all overloaded functions */
|
||||
|
||||
Wrapper *f = NewWrapper();
|
||||
String *symname = Getattr(n, "sym:name");
|
||||
String *wname = Swig_name_wrapper(symname);
|
||||
|
||||
Printf(f->def, "static void %s(INT32 args) {", wname);
|
||||
|
||||
Wrapper_add_local(f, "argc", "INT32 argc");
|
||||
Printf(tmp, "struct svalue argv[%d]", maxargs);
|
||||
Wrapper_add_local(f, "argv", tmp);
|
||||
Wrapper_add_local(f, "ii", "INT32 ii");
|
||||
|
||||
Printf(f->code, "argc = args;\n");
|
||||
Printf(f->code, "for (ii = 0; (ii < argc) && (ii < %d); ii++) {\n", maxargs);
|
||||
Printf(f->code, "argv[ii] = Pike_sp[ii-args];\n");
|
||||
Printf(f->code, "}\n");
|
||||
|
||||
Replaceall(dispatch, "$args", "self, args");
|
||||
Printv(f->code, dispatch, "\n", NIL);
|
||||
Printf(f->code, "Pike_error(\"No matching function for overloaded '%s'.\");\n", symname);
|
||||
Printv(f->code, "}\n", NIL);
|
||||
|
||||
Wrapper_print(f, f_wrappers);
|
||||
|
||||
String *description = NewString("");
|
||||
Printf(description, "tAny,");
|
||||
if (current == CONSTRUCTOR || current == DESTRUCTOR) {
|
||||
Printf(description, " tVoid");
|
||||
} else {
|
||||
String *pd = Getattr(n, "tmap:out:pikedesc");
|
||||
if (pd)
|
||||
Printf(description, " %s", pd);
|
||||
}
|
||||
add_method(symname, wname, description);
|
||||
Delete(description);
|
||||
|
||||
DelWrapper(f);
|
||||
Delete(dispatch);
|
||||
Delete(tmp);
|
||||
Delete(wname);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* variableWrapper()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int variableWrapper(Node *n) {
|
||||
return Language::variableWrapper(n);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* constantWrapper()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int constantWrapper(Node *n) {
|
||||
|
||||
Swig_require("constantWrapper", n, "*sym:name", "type", "value", NIL);
|
||||
|
||||
String *symname = Getattr(n, "sym:name");
|
||||
SwigType *type = Getattr(n, "type");
|
||||
String *value = Getattr(n, "value");
|
||||
bool is_enum_item = (Cmp(nodeType(n), "enumitem") == 0);
|
||||
|
||||
if (SwigType_type(type) == T_MPOINTER) {
|
||||
/* Special hook for member pointer */
|
||||
String *wname = Swig_name_wrapper(symname);
|
||||
Printf(f_header, "static %s = %s;\n", SwigType_str(type, wname), value);
|
||||
value = wname;
|
||||
} else if (SwigType_type(type) == T_CHAR && is_enum_item) {
|
||||
type = NewSwigType(T_INT);
|
||||
Setattr(n, "type", type);
|
||||
}
|
||||
|
||||
/* Perform constant typemap substitution */
|
||||
String *tm = Swig_typemap_lookup("constant", n, value, 0);
|
||||
if (tm) {
|
||||
Replaceall(tm, "$symname", symname);
|
||||
Replaceall(tm, "$value", value);
|
||||
Printf(f_init, "%s\n", tm);
|
||||
} else {
|
||||
Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, "Unsupported constant value %s = %s\n", SwigType_str(type, 0), value);
|
||||
}
|
||||
|
||||
Swig_restore(n);
|
||||
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* nativeWrapper()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int nativeWrapper(Node *n) {
|
||||
// return Language::nativeWrapper(n);
|
||||
String *name = Getattr(n, "sym:name");
|
||||
String *wrapname = Getattr(n, "wrap:name");
|
||||
|
||||
if (!addSymbol(wrapname, n))
|
||||
return SWIG_ERROR;
|
||||
|
||||
add_method(name, wrapname, 0);
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* enumDeclaration()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int enumDeclaration(Node *n) {
|
||||
return Language::enumDeclaration(n);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* enumvalueDeclaration()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int enumvalueDeclaration(Node *n) {
|
||||
return Language::enumvalueDeclaration(n);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* classDeclaration()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int classDeclaration(Node *n) {
|
||||
return Language::classDeclaration(n);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* classHandler()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int classHandler(Node *n) {
|
||||
|
||||
String *symname = Getattr(n, "sym:name");
|
||||
if (!addSymbol(symname, n))
|
||||
return SWIG_ERROR;
|
||||
|
||||
PrefixPlusUnderscore = NewStringf("%s_", getClassPrefix());
|
||||
|
||||
Printf(f_classInit, "start_new_program();\n");
|
||||
|
||||
/* Handle inheritance */
|
||||
List *baselist = Getattr(n, "bases");
|
||||
if (baselist && Len(baselist) > 0) {
|
||||
Iterator base = First(baselist);
|
||||
while (base.item) {
|
||||
String *basename = Getattr(base.item, "name");
|
||||
SwigType *basetype = NewString(basename);
|
||||
SwigType_add_pointer(basetype);
|
||||
SwigType_remember(basetype);
|
||||
String *basemangle = SwigType_manglestr(basetype);
|
||||
Printf(f_classInit, "low_inherit((struct program *) SWIGTYPE%s->clientdata, 0, 0, 0, 0, 0);\n", basemangle);
|
||||
Delete(basemangle);
|
||||
Delete(basetype);
|
||||
base = Next(base);
|
||||
}
|
||||
} else {
|
||||
Printf(f_classInit, "ADD_STORAGE(swig_object_wrapper);\n");
|
||||
}
|
||||
|
||||
Language::classHandler(n);
|
||||
|
||||
/* Accessors for member variables */
|
||||
/*
|
||||
List *membervariables = Getattr(n,"membervariables");
|
||||
if (membervariables && Len(membervariables) > 0) {
|
||||
membervariableAccessors(membervariables);
|
||||
}
|
||||
*/
|
||||
|
||||
/* Done, close the class and dump its definition to the init function */
|
||||
Printf(f_classInit, "add_program_constant(\"%s\", pr = end_program(), 0);\n", symname);
|
||||
Dump(f_classInit, f_init);
|
||||
Clear(f_classInit);
|
||||
|
||||
SwigType *tt = NewString(symname);
|
||||
SwigType_add_pointer(tt);
|
||||
SwigType_remember(tt);
|
||||
String *tm = SwigType_manglestr(tt);
|
||||
Printf(f_init, "SWIG_TypeClientData(SWIGTYPE%s, (void *) pr);\n", tm);
|
||||
Delete(tm);
|
||||
Delete(tt);
|
||||
|
||||
Delete(PrefixPlusUnderscore);
|
||||
PrefixPlusUnderscore = 0;
|
||||
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* memberfunctionHandler()
|
||||
*
|
||||
* Method for adding C++ member function
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int memberfunctionHandler(Node *n) {
|
||||
current = MEMBER_FUNC;
|
||||
Language::memberfunctionHandler(n);
|
||||
current = NO_CPP;
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* constructorHandler()
|
||||
*
|
||||
* Method for adding C++ member constructor
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int constructorHandler(Node *n) {
|
||||
current = CONSTRUCTOR;
|
||||
Language::constructorHandler(n);
|
||||
current = NO_CPP;
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* destructorHandler()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int destructorHandler(Node *n) {
|
||||
current = DESTRUCTOR;
|
||||
Language::destructorHandler(n);
|
||||
current = NO_CPP;
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* membervariableAccessors()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
void membervariableAccessors(List *membervariables) {
|
||||
String *name;
|
||||
Iterator i;
|
||||
bool need_setter;
|
||||
String *funcname;
|
||||
|
||||
/* If at least one of them is mutable, we need a setter */
|
||||
need_setter = false;
|
||||
i = First(membervariables);
|
||||
while (i.item) {
|
||||
if (!GetFlag(i.item, "feature:immutable")) {
|
||||
need_setter = true;
|
||||
break;
|
||||
}
|
||||
i = Next(i);
|
||||
}
|
||||
|
||||
/* Create a function to set the values of the (mutable) variables */
|
||||
if (need_setter) {
|
||||
Wrapper *wrapper = NewWrapper();
|
||||
String *setter = Swig_name_member(NSPACE_TODO, getClassPrefix(), "`->=");
|
||||
String *wname = Swig_name_wrapper(setter);
|
||||
Printv(wrapper->def, "static void ", wname, "(INT32 args) {", NIL);
|
||||
Printf(wrapper->locals, "char *name = (char *) STR0(Pike_sp[0-args].u.string);\n");
|
||||
|
||||
i = First(membervariables);
|
||||
while (i.item) {
|
||||
if (!GetFlag(i.item, "feature:immutable")) {
|
||||
name = Getattr(i.item, "name");
|
||||
funcname = Swig_name_wrapper(Swig_name_set(NSPACE_TODO, Swig_name_member(NSPACE_TODO, getClassPrefix(), name)));
|
||||
Printf(wrapper->code, "if (!strcmp(name, \"%s\")) {\n", name);
|
||||
Printf(wrapper->code, "%s(args);\n", funcname);
|
||||
Printf(wrapper->code, "return;\n");
|
||||
Printf(wrapper->code, "}\n");
|
||||
Delete(funcname);
|
||||
}
|
||||
i = Next(i);
|
||||
}
|
||||
|
||||
/* Close the function */
|
||||
Printf(wrapper->code, "pop_n_elems(args);\n");
|
||||
Printf(wrapper->code, "}\n");
|
||||
|
||||
/* Dump wrapper code to the output file */
|
||||
Wrapper_print(wrapper, f_wrappers);
|
||||
|
||||
/* Register it with Pike */
|
||||
String *description = NewString("tStr tFloat, tVoid");
|
||||
add_method("`->=", wname, description);
|
||||
Delete(description);
|
||||
|
||||
/* Clean up */
|
||||
Delete(wname);
|
||||
Delete(setter);
|
||||
DelWrapper(wrapper);
|
||||
}
|
||||
|
||||
/* Create a function to get the values of the (mutable) variables */
|
||||
Wrapper *wrapper = NewWrapper();
|
||||
String *getter = Swig_name_member(NSPACE_TODO, getClassPrefix(), "`->");
|
||||
String *wname = Swig_name_wrapper(getter);
|
||||
Printv(wrapper->def, "static void ", wname, "(INT32 args) {", NIL);
|
||||
Printf(wrapper->locals, "char *name = (char *) STR0(Pike_sp[0-args].u.string);\n");
|
||||
|
||||
i = First(membervariables);
|
||||
while (i.item) {
|
||||
name = Getattr(i.item, "name");
|
||||
funcname = Swig_name_wrapper(Swig_name_get(NSPACE_TODO, Swig_name_member(NSPACE_TODO, getClassPrefix(), name)));
|
||||
Printf(wrapper->code, "if (!strcmp(name, \"%s\")) {\n", name);
|
||||
Printf(wrapper->code, "%s(args);\n", funcname);
|
||||
Printf(wrapper->code, "return;\n");
|
||||
Printf(wrapper->code, "}\n");
|
||||
Delete(funcname);
|
||||
i = Next(i);
|
||||
}
|
||||
|
||||
/* Close the function */
|
||||
Printf(wrapper->code, "pop_n_elems(args);\n");
|
||||
Printf(wrapper->code, "}\n");
|
||||
|
||||
/* Dump wrapper code to the output file */
|
||||
Wrapper_print(wrapper, f_wrappers);
|
||||
|
||||
/* Register it with Pike */
|
||||
String *description = NewString("tStr, tMix");
|
||||
add_method("`->", wname, description);
|
||||
Delete(description);
|
||||
|
||||
/* Clean up */
|
||||
Delete(wname);
|
||||
Delete(getter);
|
||||
DelWrapper(wrapper);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* membervariableHandler()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int membervariableHandler(Node *n) {
|
||||
List *membervariables = Getattr(getCurrentClass(), "membervariables");
|
||||
if (!membervariables) {
|
||||
membervariables = NewList();
|
||||
Setattr(getCurrentClass(), "membervariables", membervariables);
|
||||
}
|
||||
Append(membervariables, n);
|
||||
current = MEMBER_VAR;
|
||||
Language::membervariableHandler(n);
|
||||
current = NO_CPP;
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------
|
||||
* staticmemberfunctionHandler()
|
||||
*
|
||||
* Wrap a static C++ function
|
||||
* ---------------------------------------------------------------------- */
|
||||
|
||||
virtual int staticmemberfunctionHandler(Node *n) {
|
||||
current = STATIC_FUNC;
|
||||
Language::staticmemberfunctionHandler(n);
|
||||
current = NO_CPP;
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* memberconstantHandler()
|
||||
*
|
||||
* Create a C++ constant
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int memberconstantHandler(Node *n) {
|
||||
current = CLASS_CONST;
|
||||
constantWrapper(n);
|
||||
current = NO_CPP;
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
* staticmembervariableHandler()
|
||||
* --------------------------------------------------------------------- */
|
||||
|
||||
virtual int staticmembervariableHandler(Node *n) {
|
||||
current = STATIC_VAR;
|
||||
Language::staticmembervariableHandler(n);
|
||||
current = NO_CPP;
|
||||
return SWIG_OK;
|
||||
}
|
||||
};
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* swig_pike() - Instantiate module
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static Language *new_swig_pike() {
|
||||
return new PIKE();
|
||||
}
|
||||
extern "C" Language *swig_pike(void) {
|
||||
return new_swig_pike();
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/**
|
||||
* This is a helper script to identify the proper include path
|
||||
* for Pike header files. It should be run with the full path
|
||||
* to the Pike executable as its single argument, e.g.
|
||||
*
|
||||
* pike check-include-path.pike /usr/local/bin/pike
|
||||
*
|
||||
* and its output should be the correct path to the header
|
||||
* files, e.g.
|
||||
*
|
||||
* /usr/local/pike/7.2.239/include/pike
|
||||
*
|
||||
*/
|
||||
|
||||
int main(int argc, array(string) argv)
|
||||
{
|
||||
string prefix = replace(argv[1], "/bin/pike", "");
|
||||
write(prefix + "/pike/" + __MAJOR__ + "." + __MINOR__ + "." + __BUILD__ + "/include/pike");
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue