Conflicts:

.gitignore
	.project
	.travis.yml
	Examples/Makefile.in
	Examples/test-suite/director_nspace.i
This commit is contained in:
Oliver Buchtala 2013-09-27 02:29:02 +02:00
commit 6dcbbf07db
134 changed files with 10011 additions and 15 deletions

View file

@ -15,7 +15,9 @@ Active SWIG Developers:
Olly Betts (olly@survex.com) (PHP)
Joseph Wang (joequant@gmail.com) (R)
Xavier Delacour (xavier.delacour@gmail.com) (Octave)
David Nadlinger (code@klickverbot.at) (D)
David Nadlinger (code@klickverbot.at)
Oliver Buchtala (oliver.buchtala@gmail.com) (Javascript)
Neha Narang (narangneha03@gmail.com) (Javascript)
Past SWIG developers and major contributors include:
Dave Beazley (dave-swig@dabeaz.com) (SWIG core, Python, Tcl, Perl)

View file

@ -25,7 +25,7 @@ div.indent {
margin-right: 4em;
}
div.code {
div.code, div:not(.code) pre {
border-style: solid;
border-width: 1px;
padding: 2pt;
@ -82,3 +82,7 @@ div.indent p {
margin-right: 0;
}
h1 a, h2 a, h3 a, h4 a, h5 a, h6 a {
text-decoration:none;
color: #000000;
}

View file

@ -664,6 +664,82 @@ android_clean:
rm -f `find $(PACKAGEDIR) -name \*.java | grep -v $(PROJECTNAME).java`
rm -rf obj
##################################################################
##### JAVASCRIPT ######
##################################################################
ROOT_DIR = @ROOT_DIR@
JSCFLAGS = @JSCFLAGS@
JSCXXFLAGS = @JSCXXFLAGS@
JSINCLUDES = @JSCOREINC@ @JSV8INC@
JSDYNAMICLINKING = @JSCOREDYNAMICLINKING@ @JSV8DYNAMICLINKING@
JSLIBRARYPREFIX = @JSLIBRARYPREFIX@
JSSO =@JSSO@
JSLDSHARED = @JSLDSHARED@
JSCXXSHARED = @JSCXXSHARED@
# ----------------------------------------------------------------
# Compile a custom javascript interpreter
# ----------------------------------------------------------------
#
# Note:
# There is no common CLI Javascript interpreter.
# V8 comes with one 'd8' which however does not provide a means
# to load extensions. Therefore, by default we use nodejs as
# environment.
# For testing native v8 and jsc extensions we provide our own
# interpreter (see 'Tools/javascript').
# ----------------------------------------------------------------
JS_INTERPRETER_SRC_DIR = $(ROOT_DIR)/Tools/javascript
# These settings are provided by 'configure' (see '/configure.in')
ifeq (1, @JSV8ENABLED@)
JS_INTERPRETER_SRC_V8 = $(JS_INTERPRETER_SRC_DIR)/v8_shell.cxx
JS_INTERPRETER_CXXFLAGS_V8 = -DENABLE_V8
endif
ifeq (1, @JSCENABLED@)
JS_INTERPRETER_SRC_JSC = $(JS_INTERPRETER_SRC_DIR)/jsc_shell.cxx
JS_INTERPRETER_CXXFLAGS_JSC = -DENABLE_JSC
endif
JS_INTERPRETER_CXXFLAGS = $(JS_INTERPRETER_CXXFLAGS_JSC) $(JS_INTERPRETER_CXXFLAGS_V8)
JS_INTERPRETER_SRC = \
$(JS_INTERPRETER_SRC_DIR)/javascript.cxx $(JS_INTERPRETER_SRC_DIR)/js_shell.cxx $(JS_INTERPRETER_SRC_JSC) $(JS_INTERPRETER_SRC_V8)
# TODO: improve:
# - exe suffix
# - '-ldl' should come from configure
javascript_exe: $(SRCS)
$(CXX) $(CXXFLAGS) $(JS_INTERPRETER_CXXFLAGS) $(JSINCLUDES) $(JS_INTERPRETER_SRC) -ldl $(LIBS) $(JSDYNAMICLINKING) -o $(JS_INTERPRETER_SRC_DIR)/javascript
SWIGJS = $(SWIG) -javascript
# ----------------------------------------------------------------
# Run the javascript executable
# ----------------------------------------------------------------
javascript: $(SRCS)
$(SWIGJS) $(SWIGOPT) $(INTERFACEPATH)
$(CC) -c $(CCSHARED) $(CFLAGS) $(JSCFLAGS) $(ISRCS) $(SRCS) $(INCLUDES) $(JSINCLUDES)
$(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(JSDYNAMICLINKING) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO)
javascript_cpp: $(SRCS)
$(SWIGJS) -c++ $(SWIGOPT) $(INTERFACEPATH)
$(CXX) -c $(CCSHARED) $(CFLAGS) $(JSCFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) $(JSINCLUDES)
$(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(JSDYNAMICLINKING) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO)
# -----------------------------------------------------------------
# Cleaning the javascript examples
# -----------------------------------------------------------------
javascript_clean:
rm -rf build
rm -f *_wrap* runme
rm -f core @EXTRA_CLEAN@
rm -f *.@OBJEXT@ *@JSSO@
##################################################################
##### MODULA3 ######
##################################################################
@ -1539,7 +1615,7 @@ endif
r_cpp: $(CXXSRCS)
$(SWIG) -c++ -r $(SWIGOPT) -o $(RCXXSRCS) $(INTERFACEPATH)
ifneq ($(CXXSRCS),)
$(CXX) -g -c $(CFLAGS) $(R_CFLAGS) $(CXXSRCS) $(INCLUDES)
$(CXX) -g -c $(CFLAGS) $(R_CFLAGS) $(CXXSRCS) $(INCLUDES)
endif
+( PKG_CPPFLAGS="$(INCLUDES)" $(COMPILETOOL) $(R) CMD SHLIB -o $(LIBPREFIX)$(TARGET)$(SO) $(RCXXSRCS) $(OBJS) > /dev/null )

View file

@ -95,6 +95,7 @@ C_TEST_BROKEN += \
# C++ test cases. (Can be run individually using: make testcase.cpptest)
ifndef SKIP_CPP_CASES
CPP_TEST_CASES += \
abstract_access \
abstract_inherit \
@ -475,6 +476,7 @@ CPP_TEST_CASES += \
voidtest \
wallkw \
wrapmacro
endif
#
# Put all the heavy STD/STL cases here, where they can be skipped if needed
@ -507,6 +509,7 @@ endif
# C test cases. (Can be run individually using: make testcase.ctest)
ifndef SKIP_C_CASES
C_TEST_CASES += \
arrays \
bom_utf8 \
@ -554,9 +557,10 @@ C_TEST_CASES += \
typemap_subst \
union_parameter \
unions
endif
# Multi-module C++ test cases . (Can be run individually using make testcase.multicpptest)
ifndef SKIP_MULTI_CPP_CASES
MULTI_CPP_TEST_CASES += \
clientdata_prop \
imports \
@ -565,6 +569,7 @@ MULTI_CPP_TEST_CASES += \
mod \
template_typedef_import \
multi_import
endif
# Custom tests - tests with additional commandline options
wallkw.cpptest: SWIGOPT += -Wallkw

View file

@ -73,7 +73,7 @@ public:
%include "std_vector.i"
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGR) || defined(SWIGOCTAVE) || defined(SWIGRUBY)
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGR) || defined(SWIGOCTAVE) || defined(SWIGRUBY) || defined(SWIGJAVASCRIPT)
#define SWIG_GOOD_VECTOR
%ignore std::vector<Space::Flow>::vector(size_type);
%ignore std::vector<Space::Flow>::resize(size_type);

View file

@ -40,7 +40,7 @@ namespace TopLevel
%include <std_string.i>
// nspace feature only supported by these languages
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD)
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD) || defined(SWIGJAVASCRIPT)
%nspace TopLevel::Bar::Foo;
%nspace TopLevel::Bar::FooBar;
#else

View file

@ -0,0 +1,48 @@
%module infinity
#include <math.h>
/* C99 defines INFINITY
Because INFINITY may be defined by compiler built-ins, we can't use #define.
Instead, expose the variable MYINFINITY and then use %rename to make it INFINITY in the scripting language.
*/
%rename(INFINITY) MYINFINITY;
%inline %{
#include <math.h>
/* C99 math.h defines INFINITY. If not available, this is the fallback. */
#ifndef INFINITY
#ifdef _MSC_VER
union MSVC_EVIL_FLOAT_HACK
{
unsigned __int8 Bytes[4];
float Value;
};
static union MSVC_EVIL_FLOAT_HACK INFINITY_HACK = {{0x00, 0x00, 0x80, 0x7F}};
#define INFINITY (INFINITY_HACK.Value)
#endif
#ifdef __GNUC__
#define INFINITY (__builtin_inf())
#elif defined(__clang__)
#if __has_builtin(__builtin_inf)
#define INFINITY (__builtin_inf())
#endif
#endif
#ifndef INFINITY
#define INFINITY (1e1000)
#endif
#endif
/* This will allow us to bind the real INFINITY value through SWIG via MYINFINITY. Use %rename to fix the name. */
const double MYINFINITY = INFINITY;
/* Use of float is intentional because the original bug was in the float conversion due to overflow checking. */
float use_infinity(float inf_val)
{
return inf_val;
}
%}

View file

@ -0,0 +1,181 @@
#######################################################################
# Makefile for javascript test-suite
#######################################################################
LANGUAGE = javascript
SCRIPTSUFFIX = _runme.js
srcdir = @srcdir@
top_srcdir = @top_srcdir@
top_builddir = @top_builddir@
SWIG = $(top_builddir)/preinst_swig
ifneq (, $(ENGINE))
JSENGINE=$(ENGINE)
else
JSENGINE=node
endif
# Note: the javascript generator is not ready yet for the real game.
# To be able keep the behavior continously tested that is expected to work already
# we have a 'light' version of the test-suite
# This will be removed and replaced by a list of 'BROKEN_TEST_CASES' when
# the number gets smaller (currently we have about 65 broken tests for JSC, and 85 for V8)
ifneq (,$(SMOKE))
C_TEST_CASES = \
preproc \
preproc_include
CPP_TEST_CASES = \
abstract_access \
abstract_typedef \
abstract_typedef2 \
abstract_virtual \
arrays_global \
array_member \
char_binary \
class_ignore \
class_scope_weird \
complextest \
constover \
constructor_copy \
cpp_enum \
cpp_namespace \
cpp_static \
enum_template \
namespace_virtual_method \
nspace \
nspace_extend \
overload_copy \
rename_simple \
rename_scope \
ret_by_value \
struct_value \
template_static \
typedef_class \
typedef_inherit \
typedef_scope \
typemap_arrays \
typemap_delete \
typemap_namespace \
typemap_ns_using \
using1 \
using2 \
javascript_unicode
SKIP_CPP_CASES = @SKIP_CPP_CASES@
SKIP_C_CASES = @SKIP_C_CASES@
SKIP_CPP_STD_CASES = @SKIP_CPP_STD_CASES@
SKIP_MULTI_CPP_CASES = @SKIP_MULTI_CPP_CASES@
endif
include $(srcdir)/../common.mk
_setup = \
if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \
echo "$(ACTION)ing testcase $* (with run test) under javascript ($(JSENGINE))" ; \
else \
echo "$(ACTION)ing testcase $* under javascript ($(JSENGINE))" ; \
fi;
ifneq (jsc,$(ENGINE))
# This test can not be run with v8 as it uses v8 API incompatible output typemaps
typemap_variables.cpptest:
echo "skipping testcase typemap_variables under javascript ($(JSENGINE))."
# with v8 we have to generate C++ wrappers only
# these tests did raise warnings which are ignored
nested.ctest: SWIGOPT += -w312,-325
nested_structs.ctest: SWIGOPT += -w312,-325
unions.ctest: SWIGOPT += -w312,-325
endif
ifeq (node,$(JSENGINE))
SWIGOPT += -v8 -DBUILDING_NODE_EXTENSION=1
# shut up some warnings
# contract macro has an empty 'else' at the end...
aggregate.cpptest: GYP_CFLAGS = \"-Wno-empty-body\"
contract.cpptest: GYP_CFLAGS = \"-Wno-empty-body\"
# dunno... ignoring generously
apply_signed_char.cpptest: GYP_CFLAGS = \"-Wno-ignored-qualifiers\"
constant_pointers.cpptest: GYP_CFLAGS = \"-Wno-ignored-qualifiers\"
enum_thorough.cpptest: GYP_CFLAGS = \"-Wno-ignored-qualifiers\"
__setup = \
sh ./setup_test.sh $* $(GYP_CFLAGS); \
$(SWIG) -c++ -javascript $(SWIGOPT) ../$*.i;
nodejs_swig_and_compile = \
node-gyp --loglevel=silent --directory $* configure build 1>>/dev/null
run_testcase = \
if [ -f $(srcdir)/$*$(SCRIPTSUFFIX) ]; then \
node $(srcdir)/$*$(SCRIPTSUFFIX); \
fi
%.cpptest:
$(_setup)
$(__setup)
$(nodejs_swig_and_compile)
$(run_testcase)
%.ctest:
$(_setup)
$(__setup)
$(nodejs_swig_and_compile)
$(run_testcase)
%.multicpptest:
$(_setup)
else
SWIGOPT += -$(JSENGINE)
run_testcase = \
if [ -f $(srcdir)/$*$(SCRIPTSUFFIX) ]; then \
$(top_srcdir)/Tools/javascript/javascript -$(JSENGINE) $(srcdir)/$*$(SCRIPTSUFFIX); \
fi
%.cpptest:
$(_setup)
+$(swig_and_compile_cpp)
$(run_testcase)
%.multicpptest:
$(_setup)
+$(swig_and_compile_multi_cpp)
$(run_testcase)
endif
ifeq (v8,$(ENGINE))
%.ctest:
$(_setup)
+$(swig_and_compile_cpp)
$(run_testcase)
endif
ifeq (jsc,$(ENGINE))
%.ctest:
$(_setup)
+$(swig_and_compile_c)
$(run_testcase)
endif
%.clean:
rm -rf $*
clean:
rm -f *_wrap.cxx
rm -f *_wrap.c
rm -f *.so
rm -f *.o

View file

@ -0,0 +1,6 @@
var abstract_access = require("./abstract_access");
var d = new abstract_access.D()
if (d.do_x() != 1) {
throw "Error";
}

View file

@ -0,0 +1,40 @@
var abstract_inherit = require("./abstract_inherit");
// Shouldn't be able to instantiate any of these classes
// since none of them implements the pure virtual function
// declared in the base class (Foo).
var Foo = abstract_inherit.Foo;
var Bar = abstract_inherit.Bar;
var Spam = abstract_inherit.Spam;
var caughtException = false;
try {
new Foo();
} catch (err) {
caughtException = true;
}
if (!caughtException) {
throw new Error("Foo should be instantiated as it is abstract");
}
caughtException = false;
try {
new Bar();
} catch (err) {
caughtException = true;
}
if (!caughtException) {
throw new Error("Bar should be instantiated as it is abstract");
}
caughtException = false;
try {
new Spam();
} catch (err) {
caughtException = true;
}
if (!caughtException) {
throw new Error("Spam should be instantiated as it is abstract");
}

View file

@ -0,0 +1,6 @@
var abstract_typedef2 = require("./abstract_typedef2");
var a = new abstract_typedef2.A_UF();
if (a == undefined)
throw "Error";

View file

@ -0,0 +1,8 @@
var abstract_typedef = require("./abstract_typedef");
var e = new abstract_typedef.Engine();
var a = new abstract_typedef.A()
if (a.write(e) != 1) {
throw "Error";
}

View file

@ -0,0 +1,11 @@
var abstract_virtual = require("./abstract_virtual");
d = new abstract_virtual.D()
if (d == undefined)
throw "Error";
e = new abstract_virtual.E()
if (e == undefined)
throw "Error";

View file

@ -0,0 +1,22 @@
var array_member = require("./array_member");
var f = new array_member.Foo();
f.data = array_member.global_data;
for (var i=0; i<8; i++) {
if (array_member.get_value(f.data,i) != array_member.get_value(array_member.global_data,i)) {
throw "Bad array assignment (1)";
}
}
for (var i=0; i<8; i++) {
array_member.set_value(f.data,i,-i);
}
array_member.global_data = f.data;
for (var i=0; i<8; i++){
if (array_member.get_value(f.data,i) != array_member.get_value(array_member.global_data,i)) {
throw "Bad array assignment (2)";
}
}

View file

@ -0,0 +1,18 @@
var arrays_global = require("./arrays_global");
arrays_global.array_i = arrays_global.array_const_i;
arrays_global.BeginString_FIX44a;
arrays_global.BeginString_FIX44b;
arrays_global.BeginString_FIX44c;
arrays_global.BeginString_FIX44d;
arrays_global.BeginString_FIX44d;
arrays_global.BeginString_FIX44b = "12"+'\0'+"45";
arrays_global.BeginString_FIX44b;
arrays_global.BeginString_FIX44d;
arrays_global.BeginString_FIX44e;
arrays_global.BeginString_FIX44f;
arrays_global.test_a("hello","hi","chello","chi");
arrays_global.test_b("1234567","hi");

View file

@ -0,0 +1,30 @@
var callback = require("./callback");
if (callback.foo(2) !== 2) {
throw new Error("Failed.");
}
if (callback.A_bar(2) !== 4) {
throw new Error("Failed.");
}
if (callback.foobar(3, callback.foo) != callback.foo(3)) {
throw new Error("Failed.");
}
if (callback.foobar(3, foo) != callback.foo(3)) {
throw new Error("Failed.");
}
if (callback.foobar(3, callback.A_bar) != callback.A_bar(3)) {
throw new Error("Failed.");
}
if (callback.foobar(3, callback.foof) != callback.foof(3)) {
throw new Error("Failed.");
}
if (callback.foobar_i(3, callback.foo_i) != callback.foo_i(3)) {
throw new Error("Failed.");
}
if (callback.foobar_d(3.5, callback.foo_d) != callback.foo_d(3.5)) {
throw new Error("Failed.");
}
var a = new callback.A();
if (callback.foobarm(3, a, callback.A.foom_cb_ptr) != a.foom(3)) {
throw new Error("Failed.");
}

View file

@ -0,0 +1,38 @@
var char_binary = require("./char_binary");
var t = new char_binary.Test();
if (t.strlen('hile') != 4) {
print(t.strlen('hile'));
throw("bad multi-arg typemap 1");
}
if (t.strlen('hil\0') != 4) {
throw("bad multi-arg typemap 2");
}
/*
* creating a raw char*
*/
var pc = char_binary.new_pchar(5);
char_binary.pchar_setitem(pc, 0, 'h');
char_binary.pchar_setitem(pc, 1, 'o');
char_binary.pchar_setitem(pc, 2, 'l');
char_binary.pchar_setitem(pc, 3, 'a');
char_binary.pchar_setitem(pc, 4, 0);
if (t.strlen(pc) != 4) {
throw("bad multi-arg typemap (3)");
}
char_binary.var_pchar = pc;
if (char_binary.var_pchar != "hola") {
print(char_binary.var_pchar);
throw("bad pointer case (1)");
}
char_binary.var_namet = pc;
if (char_binary.var_namet != "hola") {
throw("bad pointer case (2)");
}
char_binary.delete_pchar(pc);

View file

@ -0,0 +1,11 @@
var char_strings = require("./char_strings");
var assertIsEqual = function(expected, actual) {
if (expected !== actual) {
throw new Error("Expected "+expected+", was "+actual);
}
};
assertIsEqual("hi there", char_strings.CharPingPong("hi there"));
assertIsEqual("hi there", char_strings.CharArrayPingPong("hi there"));
assertIsEqual("hi there", char_strings.CharArrayDimsPingPong("hi there"));

View file

@ -0,0 +1,6 @@
var class_ignore = require("./class_ignore");
a = new class_ignore.Bar();
if (class_ignore.do_blah(a) != "Bar::blah")
throw "Error";

View file

@ -0,0 +1,6 @@
var class_scope_weird = require("./class_scope_weird");
f = new class_scope_weird.Foo();
g = new class_scope_weird.Foo(3);
if (f.bar(3) != 3)
throw RuntimeError;

Some files were not shown because too many files have changed in this diff Show more