diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 374976d2a..4bdf04a48 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,8 +49,6 @@ jobs: os: ubuntu-22.04 - SWIGLANG: "" compiler: clang - - SWIGLANG: c - CPPSTD: c++11 - SWIGLANG: csharp # D support can't be enabled because dmd 2.066 fails to build anything # under Ubuntu 18.04 due to its standard library (libphobos2.a) not diff --git a/COPYRIGHT b/COPYRIGHT index c9b8c1a47..e6df73ff8 100644 --- a/COPYRIGHT +++ b/COPYRIGHT @@ -1,7 +1,7 @@ SWIG Copyright and Authors -------------------------- -Copyright (c) 1995-2012 The SWIG Developers +Copyright (c) 1995-2011 The SWIG Developers Copyright (c) 2005-2006 Arizona Board of Regents (University of Arizona). Copyright (c) 1998-2005 University of Chicago. Copyright (c) 1995-1998 The University of Utah and the Regents of the University of California @@ -16,7 +16,6 @@ Active SWIG Developers: Joseph Wang (joequant@gmail.com) (R) Xavier Delacour (xavier.delacour@gmail.com) (Octave) David Nadlinger (code@klickverbot.at) (D) - Leif Middelschulte (leif.middelschulte@gmail.com) (C) Oliver Buchtala (oliver.buchtala@gmail.com) (Javascript) Neha Narang (narangneha03@gmail.com) (Javascript) Simon Marchetto (simon.marchetto@scilab-enterprises.com) (Scilab) diff --git a/Doc/Manual/C.html b/Doc/Manual/C.html deleted file mode 100644 index 2161d2739..000000000 --- a/Doc/Manual/C.html +++ /dev/null @@ -1,762 +0,0 @@ - - - -SWIG and C as the target language - - - -

36 SWIG and C as the target language

- -
- -
- - - - -

-This chapter describes SWIG's support for creating ANSI C wrappers. This module has a special purpose and thus is different from most other modules. -

- -

-NOTE: this module is still under development. -

- - -

36.1 Overview

- - -

-SWIG is normally used to provide access to C or C++ libraries from target languages such as scripting languages or languages running on a virtual machine. -SWIG performs analysis of the input C/C++ library header files from which it generates further code. For most target languages this code consists of two layers; namely an intermediary C code layer and a set of language specific proxy classes and functions on top of the C code layer. -We could also think of C as just another target language supported by SWIG. -The aim then is to generate a pure ANSI C interface to the input C or C++ library and hence the C target language module. -

- -

-With wrapper interfaces generated by SWIG, it is easy to use the functionality of C++ libraries inside application code written in C. This module may also be useful to generate custom APIs for a library, to suit particular needs, e.g. to supply function calls with error checking or to implement a "design by contract". -

- -

-Flattening C++ language constructs into a set of C-style functions obviously comes with many limitations and inconveniences, but this module is actually also capable of generating C++ wrappers defined completely inline using the C functions, thus wrapping the original C++ library API in another, similar C++ API. Contrary to the natural initial reaction, this is far from being completely pointless, as wrapping C++ API in this way avoids all problems due to C++ ABI issues, e.g. it is now possible to use the original C++ API using a different C++ compiler, or a different version of the same compiler, or even the same compiler, but with different compilation options affecting the ABI. The C++ wrapper API is not identical to the original one, but strives to be as close to it as possible. -

- -

Known C++ Shortcomings in Generated C API:

- -

36.2 Preliminaries

- - -

36.2.1 Running SWIG

- - -

-Consider the following simple example. Suppose we have an interface file like: -

- -
-
-/* File: example.i */
-%module test
-%{
-#include "stuff.h"
-%}
-int fact(int n);
-
-
- -

-To build a C module (C as the target language), run SWIG using the -c option :

- -
-$ swig -c example.i
-
- -

-The above assumes C as the input language. If the input language is C++ add the -c++ option: -

- -
-$ swig -c++ -c example.i
-
- -

-Note that -c is the option specifying the target language and -c++ controls what the input language is. -

- -

-This will generate an example_wrap.c file or, in the latter case, example_wrap.cxx file, along with example_wrap.h (the same extension is used in both C and C++ cases for the last one). The names of the files are derived from the name of the input file by default, but can be changed using the -o and -oh options common to all language modules. -

- -

-The xxx_wrap.c file contains the wrapper functions, which perform the main functionality of SWIG: each of the wrappers translates the input arguments from C to C++, makes calls to the original functions and marshals C++ output back to C data. The xxx_wrap.h header file contains the declarations of these functions as well as global variables. -

- -

36.2.2 Command line options

- - -

-The following table list the additional command line options available for the C module. They can also be seen by using: -

- -
-$ swig -c -help
-
- - - - - - - - - - - - - - - - - - - - - -
C specific options
-namespace <nspace>Generate wrappers with the prefix based on the provided namespace, e.g. if the option value is outer::inner, the prefix outer_inner_ will be used. Notice that this is different from using SWIG nspace feature, as it applies the the prefix to all the symbols, regardless of the namespace they were actually declared in. Notably, this allows to export instantiations of templates defined in the std namespace, such as std::vector, using a custom prefix rather than std_.
-nocxxDon't generate C++ wrappers, even when -c++ option is used. See C++ Wrappers section for more details.
-noexceptgenerate wrappers with no support of exception handling; see Exceptions chapter for more details
- -

36.2.3 Compiling a dynamic module

- - -

-The next step is to build a dynamically loadable module, which we can link to our application. This can be done easily, for example using the gcc compiler (Linux, MinGW, etc.): -

- -
-$ swig -c example.i
-$ gcc -c example_wrap.c
-$ gcc -shared example_wrap.o -o libexample.so
-
- -

-Or, for C++ input: -

- -
-$ swig -c++ -c example.i
-$ g++ -c example_wrap.cxx
-$ g++ -shared example_wrap.o -o libexample.so
-
- -

-Now the shared library module is ready to use. Note that the name of the generated module is important: is should be prefixed with lib on Unix, and have the specific extension, like .dll for Windows or .so for Unix systems. -

- -

36.2.4 Using the generated module

- - -

-The simplest way to use the generated shared module is to link it to the application code during the compilation stage. The process is usually similar to this: -

- -
-$ gcc runme.c -L. -lexample -o runme
-
- -

-This will compile the application code (runme.c) and link it against the generated shared module. Following the -L option is the path to the directory containing the shared module. The output executable is ready to use. The last thing to do is to supply to the operating system the information of location of our module. This is system dependant, for instance Unix systems look for shared modules in certain directories, like /usr/lib, and additionally we can set the environment variable LD_LIBRARY_PATH (Unix) or PATH (Windows) for other directories. -

- -

36.3 Basic C wrapping

- - -

-Wrapping C functions and variables is obviously performed in a straightforward way. There is no need to perform type conversions, and all language constructs can be preserved in their original form. However, SWIG allows you to enhance the code with some additional elements, for instance using check typemap or %extend directive. -

- -

-It is also possible to output arbitrary additional code into the generated header by using %insert directive with cheader section, e.g. -

-%insert("cheader") %{
-#include "another.h"
-%}
-
-

- -

36.3.1 Functions

- - -

-For each C function declared in the interface file a wrapper function with a prefix, required to make its name different from the original one, is created. The prefix for the global functions is module_, i.e. the name of the SWIG module followed by underscore, by default. If -namespace option is used, the prefix corresponding to the given fixed namespace is used instead. If nspace feature is used, the prefix corresponding to the namespace in which the function is defined is used -- note that, unlike with -namespace option, this prefix can be different for different functions. The wrapper function performs a call to the original function, and returns its result. -

- -

-For example, for function declaration in the module mymath: -

- -
-int gcd(int x, int y);
-
- -

-The output is simply: -

- -
-int mymath_gcd(int arg1, int arg2) {
-  int result;
-  result = gcd(arg1,arg2);
-  return result;
-}
-
- -

-Now one might think, what's the use of creating such functions in C? The answer is, you can apply special rules to the generated code. Take for example constraint checking. You can write a "check" typemap in your interface file: -

- -
-%typemap(check) int POSITIVE {
-  if ($1 <= 0)
-    fprintf(stderr, "Expected positive value in $name.\n");
-}
-
-int gcd(int POSITIVE, int POSITIVE);
-
- -

-And now the generated result looks like: -

- -
-int _wrap_gcd(int arg1, int arg2) {
-  {
-    if (arg1 <= 0)
-      fprintf(stderr, "Expected positive value in gcd.\n");
-  }
-  {
-    if (arg1 <= 0)
-      fprintf(stderr, "Expected positive value in gcd.\n");
-  }
-  int result;
-  result = gcd(arg1,arg2);
-  return result;
-}
-
- -

-This time calling gcd with negative value argument will trigger an error message. This can save you time writing all the constraint checking code by hand. -

- -

36.3.2 Variables

- - -

-Wrapping variables comes also without any special issues. All global variables are directly accessible from application code. There is a difference in the semantics of struct definition in C and C++. When handling C struct, SWIG simply rewrites its declaration. In C++ struct is handled as class declaration. -

- -

-You can still apply some of the SWIG features when handling structs, e.g. %extend directive. Suppose, you have a C struct declaration: -

- -
-typedef struct {
-  int x;
-  char *str;
-} my_struct;
-
- -

-You can redefine it to have an additional fields, like: -

- -
-%extend my_struct {
-  double d;
-};
-
- -

-In application code: -

- -
-struct my_struct ms;
-ms.x = 123;
-ms.d = 123.123;
-
- -

36.4 Basic C++ wrapping

- - -

-The main reason of having the C module in SWIG is to be able to access C++ from C. In this chapter we will take a look at the rules of wrapping elements of the C++ language. -

- -

-By default, SWIG attempts to build a natural C interface to your C/C++ code. - - - - - - - - - - - - - - - - - -
C++ TypeSWIG C Translation
Class ExampleEmpty structure Example
Public, mutable member variable Foo Example::foo - Example_foo_get(Example *e);
- Example_foo_set(Example *e, Foo *f); -
Public, immutable member variable Foo Example::bar - Example_foo_get(Example *e);
-
-This section briefly covers the essential aspects of this wrapping. -

- -

36.3.3 Enums

- -

-C enums and unscoped C++ enums are simply copied to the generated code and both the enum itself and its elements keep the same name as in the original code unless -namespace option is used or nspace feature is enabled, in which case the prefix corresponding to the specified namespace is used. -

-

-For scoped C++11 enums, the enum name itself is used as an additional prefix. -

- - -

36.4.1 Classes

- - -

-Consider the following example. We have a C++ class, and want to use it from C code. -

- -
-class Circle {
-public:
-  double radius;
-
-  Circle(double r) : radius(r) { };
-  double area(void);
-};
-
- -

-What we need to do is to create an object of the class, manipulate it, and finally, destroy it. SWIG generates C functions for this purpose each time a class declaration is encountered in the interface file. -

- -

-The first two generated functions are used to create and destroy instances of class Circle. Such instances are represented on the C side as pointers to special structs, called SwigObj. They are all "renamed" (via typedef) to the original class names, so that you can use the object instances on the C side using pointers like: -

- -
-Circle *circle;
-
- -

-The generated functions make calls to class' constructors and destructors, respectively. They also do all the necessary things required by the SWIG object management system in C. -

- -
-Circle * Circle_new(double r);
-void Circle_delete(Circle * self);
-
- -

-The class Circle has a public variable called radius. SWIG generates a pair of setters and getters for each such variable: -

- -
-void Circle_radius_set(Circle * self, double radius);
-double Circle_radius_get(Circle * self);
-
- -

-For each public method, an appropriate function is generated: -

- -
-double Circle_area(Circle * self);
-
- -

-You can see that in order to use the generated object we need to provide a pointer to the object instance (struct Circle in this case) as the first function argument. In fact, this struct is basically wrapping pointer to the "real" C++ object. -

- -

-Our application code could look like this: -

- -
-  Circle *c = Circle_new(1.5);
-  printf("radius: %f\narea: %f\n", Circle_radius_get(c), Circle_area(c));
-  Circle_delete(c);
-
- -

-After running this we'll get: -

- -
-radius: 1.500000
-area: 7.068583
-
- -

Backend Developer Documentation

- -

Typemaps

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TypemapUsed for
ctypeProvides types used for the C API and
- Typecasts wrapper functions return values in proxy functions
- - MyClass *MyClass_new(void) {
-  return (MyClass *)MyClass_new();
- } -
-
inMapping of wrapper functions parameters to local C++ variables
-
- - SwigObj* MyClass_do(SwigObj *carg1) {
-  SomeCPPClass *arg1 = 0;
-  if (carg1)
-   arg1 = (SomeCPPClass*)carg1->obj
-  else
-   arg1 = 0;
- } -
outAssigns wrapped function's return value to a dedicated return variable, packaging it into SwigObj if necessary
cppouttypeType of the result variable used for the return value if the wrapped function is a C++ function -
cxxintypeDefines the type for the parameters of C++ wrapper functions corresponding to this type. By default is the same as ctype, but may sometimes be different to make the functions more convenient to use. For example, ctype for std::string is const char*, but cxxintype typemap for it is std::string const&, i.e. even though the C++ string passed as a raw pointer via C API, the C++ wrapper still accepts a C++ string. If this typemap is defined, cxxin should normally be defined as well. If it is not defined, ctype is used. -
cxxouttypeSimilar to cxxintype, but is used for the function return values and together with cxxout typemap. Also defaults to ctype if not defined. -
cxxinDefines how to transform cxxintype value to ctype -
cxxoutDefines how to transform ctype value returned by a function to cxxouttype -
cxxcodeMay contain arbitrary code that will be injected in the declaration of the C++ wrapper class corresponding to the given type. Ignored for non-class types. The special variable $cxxclassname is replaced with the name of the class inside this typemap expansion and $cclassptrname is replaced with the name of the pointer type used to represent the class in C wrapper functions. -
- -

C Typemaps, a Code Generation Walkthrough

- -To get a better idea of which typemap is used for which generated code, have a look at the following 'walk through'.
-Let's assume we have the following C++ interface file, we'd like to generate code for: - -

The Interface

-
-%module example
-
-%inline
-%{
-  class SomeClass{};
-  template <typename T> class SomeTemplateClass{};
-  SomeClass someFunction(SomeTemplateClass<int> &someParameter, int simpleInt);
-%}
-
-%template (SomeIntTemplateClass) SomeTemplateClass<int>;
-
- - -What we would like to generate as a C interface of this function would be something like this: - -
-// wrapper header file
-typedef struct SwigObj_SomeClass SomeClass;
-
-SomeClass * SomeClass_new();
-
-void SomeClass_delete(SomeClass * carg1);
-        
-SomeClass* someFunction(SomeIntTemplateClass* carg1, int carg2);
-        
-        
-typedef struct SwigObj_SomeIntTemplateClass SomeIntTemplateClass;
-        
-SomeIntTemplateClass * SomeIntTemplateClass_new();
-        
-void SomeIntTemplateClass_delete(SomeIntTemplateClass * carg1);
-
- -

The Wrapper

-We'll examine the generation of the wrapper function first. - -
-SWIGEXPORTC SwigObj * module_someFunction(SwigObj * carg1, int carg2) {
-  SomeClass * cppresult;
-  SomeTemplateClass< int > *arg1 = 0 ;
-  int arg2 ;
-  SwigObj * result;
-  
-  {
-    if (carg1)
-    arg1 = (SomeTemplateClass< int > *) carg1->obj;
-    else
-    arg1 = (SomeTemplateClass< int > *) 0;
-  }
-  arg2 = (int) carg2;
-  {
-    const SomeClass &_result_ref =  someFunction(*arg1,arg2);cppresult = (SomeClass*) &_result_ref;
-  }
-  {
-    result = SWIG_create_object(cppresult, SWIG_STR(SomeClass));
-  }
-  return result;
-}
-
- -It might be helpful to think of the way function calls are generated as a composition of building blocks.
-A typical wrapper will be composited with these [optional] blocks: - -
    -
  1. Prototype
  2. -
  3. C return value variable
  4. -
  5. Local variables equal to the called C++ function's parameters
  6. -
  7. [C++ return value variable]
  8. -
  9. Assignment (extraction) of wrapper parameters to local parameter copies
  10. -
  11. [Contract (e.g. constraints) checking]
  12. -
  13. C++ function call
  14. -
  15. [Exception handling]
  16. -
  17. [Assignment to C++ return value]
  18. -
  19. Assignment to C return value
  20. -
- -Let's go through it step by step and start with the wrapper prototype - -
-ctype                        ctype            ctype
----------                    ---------        ---
-SwigObj * module_someFunction(SwigObj * carg1, int carg2);
-
- -As first unit of the wrapper code, a variable to hold the return value of the function is emitted to the wrapper's body - -
-ctype
----------
-SwigObj * result;
-
- -Now for each of the C++ function's arguments, a local variable with the very same type is emitted to the wrapper's body. - -
-SomeTemplateClass< int > *arg1 = 0 ;
-int arg2 ;
-
- -If it's a C++ function that is wrapped (in this case it is), another variable is emitted for the 'original' return value of the C++ function.
-At this point, we simply 'inject' behavior if it's a C++ function that is wrapped (in this case it obviously is). - -
-cppouttype
------------
-SomeClass * cppresult;
-
- -Next, the values of the input parameters are assigned to the local variables using the 'in' typemap. - -
-{
-  if (carg1)
-  arg1 = (SomeTemplateClass< int > *) carg1->obj;
-  else
-  arg1 = (SomeTemplateClass< int > *) 0;
-}
-arg2 = (int) carg2;
-
- -A reasonable question would be: "Why aren't the parameters assigned in the declaration of their local counterparts?"
-As seen above, for complex types pointers have to be verified before extracting and
-casting the actual data pointer from the provided SwigObj pointer.
-This could easily become messy if it was done in the same line with the local variable declaration.
-

-At this point we are ready to call the C++ function with our parameters.
-

-
-{
-  const SomeClass &_result_ref =  someFunction(*arg1,arg2);cppresult = (SomeClass*) &_result_ref;
-}
-
-Subsequently, the return value is assigned to the dedicated return value variable using the 'out' typemap -
-{
-  result = SWIG_create_object(cppresult, SWIG_STR(SomeClass));
-}
-
- -Finally, the return value variable is returned. -
-return result;
-
- -Note that typemaps may use $null special variable which will be -replaced with either 0 or nothing, depending on whether the function -has a non-void return value or not. - -

The Proxy

-Compared to the wrapper code generation, the header code is very simple.
-Basically it contains just the declarations corresponding to the definitions -above. - -
-// wrapper header file
-typedef struct SwigObj_SomeClass SomeClass;
-
-SomeClass * SomeClass_new();
-
-void SomeClass_delete(SomeClass * carg1);
-
-SomeClass* someFunction(SomeIntTemplateClass* carg1, int carg2);
-
-
-typedef struct SwigObj_SomeIntTemplateClass SomeIntTemplateClass;
-
-SomeIntTemplateClass * SomeIntTemplateClass_new();
-
-void SomeIntTemplateClass_delete(SomeIntTemplateClass * carg1);
-
- -

36.5 Exception handling

- -

-Any call to a C++ function may throw an exception, which cannot be caught by C code. Instead, the special SWIG_CException_get_pending() function must be called to check for this. If it returns a non-null pointer, SWIG_CException_msg_get() can be called to retrieve the error message associated with the exception. Finally, SWIG_CException_reset_pending() must be called to free the exception object and reset the current pending exception. Note that exception handling is much simpler when using C++, rather than C, wrappers, see sections 36.6.2. -

- -

36.6 C++ Wrappers

- -

-When -c++ command line option is used (and -nocxx one is not), the header file generated by SWIG will also contain the declarations of C++ wrapper functions and classes mirroring the original API. All C++ wrappers are fully inline, i.e. don't need to be compiled separately, and are always defined inside the namespace (or nested namespaces) specified by -namespace command-line option or the namespace with the same name as the SWIG module name if this option is not specified. -

- -

-C++ wrappers try to provide a similar API to the original C++ API being wrapped, notably any class Foo in the original API appears as a class with the same name in the wrappers namespace, and has the same, or similar, public methods. A class Bar deriving from Foo also derives from it in the wrappers and so on. There are some differences with the original API, however. Some of them are due to fundamental limitations of the approach used, e.g.: -

- -Other ones are due to things that could be supported but haven't been implemented yet: - -

- -

36.6.1 Additional customization possibilities

- -Generated C++ code can be customized by inserting custom code in the following sections: - - - -The following features are taken into account when generating C++ wrappers: - - -

36.6.2 Exception handling

- -

-Exception handling in C++ is more natural, as the exceptions are re-thrown when using C++ wrappers and so can be caught, as objects of the special SWIG_CException type, using the usual try/catch statement. The objects of SWIG_CException class have code() and msg() methods, with the latter returning the error message associated with the exception. -

- -

-If necessary, a custom exception type may be used instead of SWIG_CException. To do this, a custom implementation of swig_check() function, called to check for the pending exception and throw the corresponding C++ exception if necessary, must be provided and SWIG_swig_check_DEFINED preprocessor symbol must be defined to prevent the default implementation of this function from being compiled: -

-
-%insert(cxxheader) %{
-#ifndef SWIG_swig_check_DEFINED
-#define SWIG_swig_check_DEFINED 1
-
-#include 
-
-class Exception : public std::runtime_error {
-public:
-    explicit Exception(const char* msg) : std::runtime_error{msg} {}
-};
-
-inline void swig_check() {
-  if (auto* swig_ex = SWIG_CException_get_pending()) {
-    Exception const e{SWIG_CException_msg_get(swig_ex)};
-    SWIG_CException_reset_pending();
-    throw e;
-  }
-}
-
-template  T swig_check(T x) {
-  swig_check();
-  return x;
-}
-
-#endif // SWIG_swig_check_DEFINED
-%}
-
- - - diff --git a/Doc/Manual/chapters b/Doc/Manual/chapters index f888848d5..994b28851 100644 --- a/Doc/Manual/chapters +++ b/Doc/Manual/chapters @@ -20,7 +20,6 @@ Warnings.html Modules.html CCache.html Android.html -C.html CSharp.html D.html Go.html diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 7b40ba653..46193348d 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -1472,377 +1472,6 @@ ruby_clean: rm -f core @EXTRA_CLEAN@ rm -f *.@OBJEXT@ *$(RUBY_SO) -################################################################## -##### PHP ###### -################################################################## - -PHP = @PHP@ -PHP_INCLUDE = @PHPINC@ -PHP_SO = @PHP_SO@ -PHP_SCRIPT = $(SRCDIR)$(RUNME).php -PHP_EXTENSION = example$(PHP_SO) - -# ------------------------------------------------------------------- -# Build a PHP dynamically loadable module (C) -# ------------------------------------------------------------------- - -php: $(SRCDIR_SRCS) - $(SWIG) -php $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) - $(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(SRCDIR_SRCS) $(ISRCS) $(INCLUDES) $(PHP_INCLUDE) - $(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(PHP_SO) - -# -------------------------------------------------------------------- -# Build a PHP dynamically loadable module (C++) -# -------------------------------------------------------------------- - -php_cpp: $(SRCDIR_SRCS) - $(SWIG) -php -c++ $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(PHP_INCLUDE) - $(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(PHP_SO) - -# ----------------------------------------------------------------- -# Running a PHP example -# ----------------------------------------------------------------- - -php_run: - $(RUNTOOL) $(PHP) -n -d extension_dir=. -d extension=$(PHP_EXTENSION) -d display_errors=stderr -r 'set_error_handler(function($$n,$$s,$$f,$$l){if($$f!==Null){print$$f;if($$l!==Null)print":$$l";print": ";}print"$$s\n";exit(1);});if(strlen($$argv[1]))include($$argv[1]);' '$(PHP_SCRIPT)' $(RUNPIPE) - -# ----------------------------------------------------------------- -# Version display -# ----------------------------------------------------------------- - -php_version: - $(PHP) -v | head -n 1 - -# ----------------------------------------------------------------- -# Cleaning the PHP examples -# ----------------------------------------------------------------- - -php_clean: - rm -f *_wrap* *~ .~* example.php php_example.h - rm -f core @EXTRA_CLEAN@ - rm -f *.@OBJEXT@ *$(PHP_SO) - -################################################################## -##### CSHARP ###### -################################################################## - -# Extra CSharp specific dynamic linking options -CSHARP_DLNK = @CSHARPDYNAMICLINKING@ -CSHARP_LIBPREFIX = @CSHARPLIBRARYPREFIX@ -CSHARPCOMPILER = @CSHARPCOMPILER@ -CSHARPCILINTERPRETER = @CSHARPCILINTERPRETER@ -CSHARPCILINTERPRETER_FLAGS = @CSHARPCILINTERPRETER_FLAGS@ -CSHARPCFLAGS = @CSHARPCFLAGS@ -CSHARPFLAGS = -CSHARPOPTIONS = -CSHARPSO = @CSHARPSO@ -CSHARP_RUNME = ./$(RUNME).exe - -# ---------------------------------------------------------------- -# Build a CSharp dynamically loadable module (C) -# ---------------------------------------------------------------- - -csharp: $(SRCDIR_SRCS) - $(SWIG) -csharp $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) - $(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(CSHARPCFLAGS) $(SRCDIR_SRCS) $(ISRCS) $(INCLUDES) - $(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(CSHARP_DLNK) $(LIBS) -o $(CSHARP_LIBPREFIX)$(TARGET)$(CSHARPSO) - -# ---------------------------------------------------------------- -# Build a CSharp dynamically loadable module (C++) -# ---------------------------------------------------------------- - -csharp_cpp: $(SRCDIR_SRCS) - $(SWIG) -csharp -c++ $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(CSHARPCFLAGS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(ICXXSRCS) $(INCLUDES) - $(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(CSHARP_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(CSHARP_LIBPREFIX)$(TARGET)$(CSHARPSO) - -# ---------------------------------------------------------------- -# Compile CSharp files -# ---------------------------------------------------------------- - -ifneq (,$(SRCDIR)) -SRCDIR_CSHARPSRCS = $(addprefix $(SRCDIR),$(CSHARPSRCS)) -else -SRCDIR_CSHARPSRCS = -endif - -csharp_compile: $(SRCDIR_SRCS) - $(COMPILETOOL) $(CSHARPCOMPILER) $(CSHARPFLAGS) $(CSHARPOPTIONS) $(CSHARPSRCS) $(SRCDIR_CSHARPSRCS) - -# ----------------------------------------------------------------- -# Run CSharp example -# ----------------------------------------------------------------- - -csharp_run: - env LD_LIBRARY_PATH=$$PWD $(RUNTOOL) $(CSHARPCILINTERPRETER) $(CSHARPCILINTERPRETER_FLAGS) $(CSHARP_RUNME) $(RUNPIPE) - -# ----------------------------------------------------------------- -# Version display -# ----------------------------------------------------------------- - -# Version check below also works with MS csc.exe which does not understand --version -csharp_version: - $(CSHARPCOMPILER) --version | head -n 1 - if test -n "$(CSHARPCILINTERPRETER)" ; then "$(CSHARPCILINTERPRETER)" --version ; fi - -# ----------------------------------------------------------------- -# Cleaning the CSharp examples -# ----------------------------------------------------------------- - -csharp_clean: - rm -f *_wrap* *~ .~* $(RUNME) $(RUNME).exe *.exe.mdb gc.log `find . -name \*.cs | grep -v $(RUNME).cs` - rm -f core @EXTRA_CLEAN@ - rm -f *.@OBJEXT@ *@CSHARPSO@ - -################################################################## -##### LUA ###### -################################################################## - -# lua flags -LUA_INCLUDE= @LUAFLAGS@ -LUA_LIB = @LUALINK@ - -# Extra specific dynamic linking options -LUA_DLNK = @LUADYNAMICLINKING@ -LUA_SO = @LUA_SO@ - -LUA = @LUABIN@ -LUA_SCRIPT = $(SRCDIR)$(RUNME).lua - -# Extra code for lua static link -LUA_INTERP = ../lua.c - -# ---------------------------------------------------------------- -# Build a C dynamically loadable module -# ---------------------------------------------------------------- - -lua: $(SRCDIR_SRCS) - $(SWIG) -lua $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) - $(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(ISRCS) $(SRCDIR_SRCS) $(INCLUDES) $(LUA_INCLUDE) - $(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(LUA_LIB) -o $(LIBPREFIX)$(TARGET)$(LUA_SO) - -# ----------------------------------------------------------------- -# Build a C++ dynamically loadable module -# ----------------------------------------------------------------- - -lua_cpp: $(SRCDIR_SRCS) $(GENCXXSRCS) - $(SWIG) -c++ -lua $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(GENCXXSRCS) $(INCLUDES) $(LUA_INCLUDE) - $(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(LUA_LIB) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(LUA_SO) - -lua_externalhdr: - $(SWIG) -lua -external-runtime $(TARGET) - -lua_swig_cpp: - $(SWIG) -c++ -lua $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) - -# ----------------------------------------------------------------- -# Build statically linked Lua interpreter -# ----------------------------------------------------------------- - -lua_static: $(SRCDIR_SRCS) - $(SWIG) -lua -module example $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) - $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(ISRCS) $(SRCDIR_SRCS) $(SRCDIR)$(LUA_INTERP) $(INCLUDES) \ - $(LUA_INCLUDE) $(LIBS) $(LUA_LIB) -o $(TARGET) - -lua_static_cpp: $(SRCDIR_SRCS) $(GENCXXSRCS) - $(SWIG) -c++ -lua -module example $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) - $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(GENCXXSRCS) $(SRCDIR)$(LUA_INTERP) $(INCLUDES) \ - $(LUA_INCLUDE) $(LIBS) $(LUA_LIB) -o $(TARGET) - -# ----------------------------------------------------------------- -# Run Lua example -# ----------------------------------------------------------------- - -lua_run: - $(RUNTOOL) $(LUA) $(LUA_SCRIPT) $(RUNPIPE) - -lua_embed_run: - $(RUNTOOL) ./$(TARGET) $(LUA_SCRIPT) $(RUNPIPE) - -# ----------------------------------------------------------------- -# Version display -# ----------------------------------------------------------------- - -lua_version: - $(LUA) -v | head -n 1 - -# ----------------------------------------------------------------- -# Cleaning the lua examples -# ----------------------------------------------------------------- - -lua_clean: - rm -f *_wrap* *~ .~* mylua@EXEEXT@ - rm -f core @EXTRA_CLEAN@ - rm -f *.@OBJEXT@ *$(LUA_SO) - -################################################################## -##### CFFI ###### -################################################################## - -CFFI = @CFFIBIN@ -CFFI_SCRIPT=$(RUNME).lisp - -cffi: $(SRCDIR_SRCS) - $(SWIG) -cffi $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) -# $(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(ISRCS) $(INCLUDES) $(SRCDIR_SRCS) -# $(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO) - -cffi_cpp: $(SRCDIR_SRCS) - $(SWIG) -c++ -cffi $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(INCLUDES) - $(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) - -# ----------------------------------------------------------------- -# Run CFFI example -# ----------------------------------------------------------------- - -cffi_run: - $(RUNTOOL) $(CFFI) -batch -s $(CFFI_SCRIPT) $(RUNPIPE) - -# ----------------------------------------------------------------- -# Version display -# ----------------------------------------------------------------- - -cffi_version: - $(CFFI) --version - -# ----------------------------------------------------------------- -# Cleaning the CFFI examples -# ----------------------------------------------------------------- - -cffi_clean: - rm -f *_wrap* *~ .~* - rm -f core @EXTRA_CLEAN@ - rm -f *.@OBJEXT@ *@SO@ - -################################################################## -##### R ###### -################################################################## - -R = R -RCXXSRCS = $(INTERFACE:.i=_wrap.cpp) #Need to use _wrap.cpp for R build system as it does not understand _wrap.cxx -RRSRC = $(INTERFACE:.i=.R) -R_CFLAGS=-fPIC -R_OPT = --slave --quiet --no-save --no-restore -R_SCRIPT=$(SRCDIR)$(RUNME).R - -# need to compile .cxx files outside of R build system to make sure that -# we get -fPIC -# CMD SHLIB stdout is piped to /dev/null to prevent echo of compiler command - -# ---------------------------------------------------------------- -# Build a R dynamically loadable module (C) -# ---------------------------------------------------------------- - -r: $(SRCDIR_SRCS) - $(SWIG) -r $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) -ifneq ($(SRCDIR_SRCS),) - $(CC) -g -c $(CPPFLAGS) $(CFLAGS) $(R_CFLAGS) $(SRCDIR_SRCS) $(INCLUDES) -endif - +( PKG_CPPFLAGS="$(CPPFLAGS) $(INCLUDES)" PKG_CFLAGS="$(CFLAGS)" $(COMPILETOOL) $(R) CMD SHLIB -o $(LIBPREFIX)$(TARGET)$(SO) $(ISRCS) $(OBJS) > /dev/null ) - -# ---------------------------------------------------------------- -# Build a R dynamically loadable module (C++) -# ---------------------------------------------------------------- -r_cpp: $(SRCDIR_CXXSRCS) - $(SWIG) -c++ -r $(SWIGOPT) -o $(RCXXSRCS) $(INTERFACEPATH) -ifneq ($(SRCDIR_CXXSRCS),) - $(CXX) -g -c $(CPPFLAGS) $(CXXFLAGS) $(R_CFLAGS) $(SRCDIR_CXXSRCS) $(INCLUDES) -endif - +( PKG_CPPFLAGS="$(CPPFLAGS) $(INCLUDES)" PKG_CXXFLAGS="$(CXXFLAGS)" $(COMPILETOOL) $(R) CMD SHLIB -o $(LIBPREFIX)$(TARGET)$(SO) $(RCXXSRCS) $(OBJS) > /dev/null ) - -# ----------------------------------------------------------------- -# Run R example -# ----------------------------------------------------------------- - -r_run: - $(RUNTOOL) $(R) $(R_OPT) -f $(R_SCRIPT) $(RUNPIPE) - -# ----------------------------------------------------------------- -# Version display -# ----------------------------------------------------------------- - -r_version: - $(R) --version | head -n 1 - -# ----------------------------------------------------------------- -# Cleaning the R examples -# ----------------------------------------------------------------- - -r_clean: - rm -f *_wrap* *~ .~* - rm -f core @EXTRA_CLEAN@ - rm -f *.@OBJEXT@ *@SO@ NAMESPACE - rm -f $(RRSRC) $(RUNME).Rout .RData - -################################################################## -##### C ###### -################################################################## - -# ---------------------------------------------------------------- -# Build a C dynamically loadable module -# ---------------------------------------------------------------- - -CLIBPREFIX = lib -C_LDSHARED = @C_LDSHARED@ -CXX_LDSHARED = @CXX_LDSHARED@ -C_SO = @C_SO@ - -c: $(SRCDIR_SRCS) - $(SWIG) -c $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) - $(CC) -c $(CCSHARED) -I$(SRCDIR) $(CFLAGS) $(ISRCS) $(SRCDIR_SRCS) $(INCLUDES) - $(COMPILETOOL) $(C_LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(CLIBPREFIX)$(TARGET)$(C_SO) - -c_cpp: $(SRCDIR_SRCS) - $(SWIG) -c++ -c $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) -I$(SRCDIR) $(CXXFLAGS) $(ICXXSRCS) $(SRCDIR_CXXSRCS) $(INCLUDES) - $(COMPILETOOL) $(CXX_LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(CLIBPREFIX)$(TARGET)$(C_SO) - -c_compile_c: $(SRCDIR)$(RUNME).c - $(COMPILETOOL) $(CC) $(CFLAGS) -o $(RUNME)_$(RUNME_EXT) -I. -I.. $< -L. -l$(TARGET) - -c_compile_cxx: $(SRCDIR)$(RUNME).cxx - $(COMPILETOOL) $(CXX) $(CXXFLAGS) -o $(RUNME)_$(RUNME_EXT) -I. -I.. $< -L. -l$(TARGET) - -$(eval c_compile: c_compile_$(RUNME_EXT)) - -# This target is used for the unit tests: if we don't have any test code to -# run, we at least can check that the generated header can be included without -# giving any syntax errors, both when compiling it as C and C++ code. -c_syntax_check: c_syntax_check_c c_syntax_check_cxx - -c_syntax_check_c: - $(CC) -fsyntax-only -x c -I$(SRCDIR)$(INTERFACEDIR) $(C_HEADER) - -c_syntax_check_cxx: - $(CXX) -fsyntax-only -x c++ -I$(SRCDIR)$(INTERFACEDIR) $(C_HEADER) - -# ----------------------------------------------------------------- -# Run C example -# ----------------------------------------------------------------- - -c_run: c_compile - env LD_LIBRARY_PATH=$$PWD $(RUNTOOL) ./$(RUNME)_$(RUNME_EXT) $(RUNPIPE) - -# ----------------------------------------------------------------- -# Version display -# ----------------------------------------------------------------- - -c_version: - $(CC) --version | head -n 1 - -# ----------------------------------------------------------------- -# Cleaning the C examples -# ----------------------------------------------------------------- - -c_clean: - rm -f *_wrap.[ch] *_wrap.cxx - rm -f core @EXTRA_CLEAN@ - rm -f *.@OBJEXT@ *@SO@ - rm -f $(RUNME)_c $(RUNME)_cxx - ################################################################## ##### SCILAB ###### ################################################################## diff --git a/Examples/c/check.list b/Examples/c/check.list deleted file mode 100644 index 16a00accf..000000000 --- a/Examples/c/check.list +++ /dev/null @@ -1,5 +0,0 @@ -# see top-level Makefile.in -simple -class -std_vector -exception diff --git a/Examples/c/class/Makefile b/Examples/c/class/Makefile deleted file mode 100644 index b031415ad..000000000 --- a/Examples/c/class/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -TOP = ../.. -SWIGEXE = $(TOP)/../swig -SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib -CXXSRCS = example.cxx -TARGET = example -INTERFACE = example.i - -check_c: build - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' RUNME_EXT=c c_run - -check_cxx: build - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' RUNME_EXT=cxx c_run - -check: check_c check_cxx - -build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ - SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ - SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' c_cpp - -clean: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' c_clean diff --git a/Examples/c/class/example.cxx b/Examples/c/class/example.cxx deleted file mode 100644 index 046304519..000000000 --- a/Examples/c/class/example.cxx +++ /dev/null @@ -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; -} diff --git a/Examples/c/class/example.h b/Examples/c/class/example.h deleted file mode 100644 index 0dff185b2..000000000 --- a/Examples/c/class/example.h +++ /dev/null @@ -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(); -}; diff --git a/Examples/c/class/example.i b/Examples/c/class/example.i deleted file mode 100644 index fbdf7249f..000000000 --- a/Examples/c/class/example.i +++ /dev/null @@ -1,9 +0,0 @@ -/* File : example.i */ -%module example - -%{ -#include "example.h" -%} - -/* Let's just grab the original header file here */ -%include "example.h" diff --git a/Examples/c/class/runme.c b/Examples/c/class/runme.c deleted file mode 100644 index f7f463031..000000000 --- a/Examples/c/class/runme.c +++ /dev/null @@ -1,44 +0,0 @@ -#include - -#include "example_wrap.h" - -int main(int argc, char **argv) { - printf("Creating some objects from C:\n"); - Circle* c = Circle_new(10); - printf(" Created circle\n"); - Square* s = Square_new(10); - printf(" Created square\n"); - - printf("\nA total of %d shapes were created\n", Shape_nshapes_get()); - - Circle_x_set(c, 20); - Circle_y_set(c, 30); - - Shape* shape = (Shape*) s; - Shape_x_set(shape, -10); - Shape_y_set(shape, 5); - - printf("\nHere is their current positions:\n"); - printf(" Circle = (%f %f)\n", Circle_x_get(c), Circle_y_get(c)); - printf(" Square = (%f %f)\n", Square_x_get(s), Square_y_get(s)); - - printf("\nHere are some properties of the shapes:\n"); - Shape* shapes[] = {(Shape*) c, (Shape*) s}; - int i; - for (i = 0; i < 2; i++) { - printf(" %s\n", i ? "Square" : "Circle"); - printf(" area = %f\n", Shape_area(shapes[i])); - printf(" perimeter = %f\n", Shape_perimeter(shapes[i])); - } - - printf("\nGuess I'll clean up now\n"); - - Square_delete(s); - Circle_delete(c); - - printf("%d shapes remain\n", Shape_nshapes_get()); - printf("Goodbye from C\n"); - - return 0; -} - diff --git a/Examples/c/class/runme.cxx b/Examples/c/class/runme.cxx deleted file mode 100644 index c7994c7ff..000000000 --- a/Examples/c/class/runme.cxx +++ /dev/null @@ -1,41 +0,0 @@ -#include - -#include "example_wrap.h" - -int main(int argc, char **argv) { - { // Block containing the Circle and Square objects. - std::cout << "Creating some objects from C++:\n"; - example::Circle c(10); - std::cout << " Created circle\n"; - example::Square s(10); - std::cout << " Created square\n"; - - std::cout << "\nA total of " << example::Shape::nshapes() << " shapes were created\n"; - - c.x(20); - c.y(30); - - example::Shape& shape = s; - shape.x(-10); - shape.y(5); - - std::cout << "\nHere is their current positions:\n"; - std::cout << " Circle = (" << c.x() << " " << c.y() << ")\n"; - std::cout << " Square = (" << s.x() << " " << s.y() << ")\n"; - - std::cout << "\nHere are some properties of the shapes:\n"; - example::Shape* shapes[] = {&c, &s}; - for (int i = 0; i < 2; i++) { - std::cout << " " << (i ? "Square" : "Circle") << "\n"; - std::cout << " area = " << shapes[i]->area() << "\n"; - std::cout << " perimeter = " << shapes[i]->perimeter() << "\n"; - } - - std::cout << "\nGuess I'll clean up now\n"; - } - - std::cout << example::Shape::nshapes() << " shapes remain\n"; - std::cout << "Goodbye from C++\n"; - - return 0; -} diff --git a/Examples/c/exception/Makefile b/Examples/c/exception/Makefile deleted file mode 100644 index b031415ad..000000000 --- a/Examples/c/exception/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -TOP = ../.. -SWIGEXE = $(TOP)/../swig -SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib -CXXSRCS = example.cxx -TARGET = example -INTERFACE = example.i - -check_c: build - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' RUNME_EXT=c c_run - -check_cxx: build - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' RUNME_EXT=cxx c_run - -check: check_c check_cxx - -build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ - SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ - SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' c_cpp - -clean: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' c_clean diff --git a/Examples/c/exception/example.cxx b/Examples/c/exception/example.cxx deleted file mode 100644 index e69de29bb..000000000 diff --git a/Examples/c/exception/example.h b/Examples/c/exception/example.h deleted file mode 100644 index 7e8361e4a..000000000 --- a/Examples/c/exception/example.h +++ /dev/null @@ -1,45 +0,0 @@ -/* File : example.h */ - -#include -#ifndef SWIG -struct A { -}; -#define SWIG_THROW(...) -#endif - -class Exc { -public: - Exc(int c, const char *m) { - code = c; - strncpy(msg,m,255); - } - int code; - char msg[256]; -}; - -class Test { -public: - int simple() SWIG_THROW(int&) { - throw(37); - return 1; - } - int message() SWIG_THROW(const char *) { - throw("I died."); - return 1; - } - int hosed() SWIG_THROW(Exc) { - throw(Exc(42,"Hosed")); - return 1; - } - int unknown() SWIG_THROW(A*) { - static A a; - throw &a; - return 1; - } - int multi(int x) SWIG_THROW(int, const char *, Exc) { - if (x == 1) throw(37); - if (x == 2) throw("Bleah!"); - if (x == 3) throw(Exc(42,"No-go-diggy-die")); - return 1; - } -}; diff --git a/Examples/c/exception/example.i b/Examples/c/exception/example.i deleted file mode 100644 index d0404b93d..000000000 --- a/Examples/c/exception/example.i +++ /dev/null @@ -1,17 +0,0 @@ -/* File : example.i */ -%module example - -%{ -#include "example.h" -%} - -%typemap(throws, noblock="1") Exc { - SWIG_exception(SWIG_RuntimeError, $1.msg); -} - -/* This needs to be defined for SWIG, even though it can't be used in C++ any more. */ -#define SWIG_THROW(...) throw(__VA_ARGS__) - -/* Let's just grab the original header file here */ -%include "example.h" - diff --git a/Examples/c/exception/runme.c b/Examples/c/exception/runme.c deleted file mode 100644 index 3cc64b620..000000000 --- a/Examples/c/exception/runme.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * NOTE: this won't run with -noexcept flag - */ - -#include -#include - -#include "example_wrap.h" - -static void show_exception(const char* prefix) { - SWIG_CException* ex = SWIG_CException_get_pending(); - assert(ex); - printf("%s exception: %s (%d)\n", prefix, SWIG_CException_msg_get(ex), SWIG_CException_code_get(ex)); - SWIG_CException_reset_pending(); -} - -int main() { - Test *t = Test_new(); - - Test_unknown(t); - show_exception("Unknown"); - - Test_simple(t); - show_exception("Int"); - - Test_message(t); - show_exception("String"); - - Test_hosed(t); - show_exception("Custom"); - - int i; - for (i = 0; i < 4; ++i) { - Test_multi(t, i); - if (!SWIG_CException_get_pending()) { - printf("Success for i=%d\n", i); - } else { - printf("For i=%d", i); - show_exception(""); - } - } - - Test_delete(t); - - return 0; -} - diff --git a/Examples/c/exception/runme.cxx b/Examples/c/exception/runme.cxx deleted file mode 100644 index 1f4ce38a7..000000000 --- a/Examples/c/exception/runme.cxx +++ /dev/null @@ -1,69 +0,0 @@ -/* - * NOTE: this won't run with -noexcept flag - */ - -#include -#include - -#include "example_wrap.h" - -using Exception = example::SWIG_CException; - -static int exit_code = 0; - -static void show_exception(const char* prefix, Exception const& ex) { - printf("%s exception: %s (%d)\n", prefix, ex.msg(), ex.code()); -} - -static void missing_exception(const char* prefix) { - printf("*** ERROR: %s: expected exception not thrown.\n", prefix); - exit_code++; -} - -int main() { - example::Test t; - - try { - t.unknown(); - missing_exception("Unknown"); - } catch (Exception const& e) { - show_exception("Unknown", e); - } - - try { - t.simple(); - missing_exception("Int"); - } catch (Exception const& e) { - show_exception("Int", e); - } - - try { - t.message(); - missing_exception("String"); - } catch (Exception const& e) { - show_exception("String", e); - } - - try { - t.hosed(); - missing_exception("Custom"); - } catch (Exception const& e) { - show_exception("Custom", e); - } - - for (int i = 0; i < 4; ++i) { - try { - t.multi(i); - if (i == 0) { - printf("Success for i=%d\n", i); - } else { - missing_exception("Multi"); - } - } catch (Exception const& e) { - printf("For i=%d", i); - show_exception("", e); - } - } - - return exit_code; -} diff --git a/Examples/c/simple/Makefile b/Examples/c/simple/Makefile deleted file mode 100644 index 908203a85..000000000 --- a/Examples/c/simple/Makefile +++ /dev/null @@ -1,18 +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)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' RUNME_EXT=c c_run - -build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ - SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ - SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' c - -clean: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' c_clean diff --git a/Examples/c/simple/example.c b/Examples/c/simple/example.c deleted file mode 100644 index 1c2af789c..000000000 --- a/Examples/c/simple/example.c +++ /dev/null @@ -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; -} - - diff --git a/Examples/c/simple/example.i b/Examples/c/simple/example.i deleted file mode 100644 index 24093b9bf..000000000 --- a/Examples/c/simple/example.i +++ /dev/null @@ -1,7 +0,0 @@ -/* File : example.i */ -%module example - -%inline %{ -extern int gcd(int x, int y); -extern double Foo; -%} diff --git a/Examples/c/simple/runme.c b/Examples/c/simple/runme.c deleted file mode 100644 index b75f951cc..000000000 --- a/Examples/c/simple/runme.c +++ /dev/null @@ -1,15 +0,0 @@ -#include - -#include "example_wrap.h" - -int main(int argc, char **argv) { - int a = 42; - int b = 105; - int g = example_gcd(a, b); - printf("The gcd of %d and %d is %d\n", a, b, g); - printf("Foo = %f\n", Foo); - Foo = 3.1415926; - printf("Foo = %f\n", Foo); - return 0; -} - diff --git a/Examples/c/std_vector/Makefile b/Examples/c/std_vector/Makefile deleted file mode 100644 index 7104242cc..000000000 --- a/Examples/c/std_vector/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -TOP = ../.. -SWIGEXE = $(TOP)/../swig -SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib -CXXSRCS = example.cxx -TARGET = example -INTERFACE = example.i - -check: build - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' RUNME_EXT=c c_run - -build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ - SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ - SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' c_cpp - -clean: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' c_clean diff --git a/Examples/c/std_vector/example.cxx b/Examples/c/std_vector/example.cxx deleted file mode 100644 index cd6c9d173..000000000 --- a/Examples/c/std_vector/example.cxx +++ /dev/null @@ -1,2 +0,0 @@ -/* File : example.c */ - diff --git a/Examples/c/std_vector/example.h b/Examples/c/std_vector/example.h deleted file mode 100644 index ca8ba9dbe..000000000 --- a/Examples/c/std_vector/example.h +++ /dev/null @@ -1,18 +0,0 @@ -/* File : example.h */ - -#include -#include - -class A { -public: - A() : name(""), value(0) {} - A(std::string str, int i) : name(str), value(i) {} - std::string name; - int value; -}; - -class Klass { -public: - std::vector vi; - std::vector va; -}; diff --git a/Examples/c/std_vector/example.i b/Examples/c/std_vector/example.i deleted file mode 100644 index 36ff4e243..000000000 --- a/Examples/c/std_vector/example.i +++ /dev/null @@ -1,14 +0,0 @@ -/* File : example.i */ -%module example -%include -%include - -%{ -#include "example.h" -%} - -/* Let's just grab the original header file here */ -%include "example.h" - -%template(Vint) std::vector; -%template(VA) std::vector; diff --git a/Examples/c/std_vector/runme.c b/Examples/c/std_vector/runme.c deleted file mode 100644 index 32c905a78..000000000 --- a/Examples/c/std_vector/runme.c +++ /dev/null @@ -1,42 +0,0 @@ -#include - -#include "example_wrap.h" - -int main() { - Klass *klass = Klass_new(); - Vint *vint = Klass_vi_get(klass); - VA *va = Klass_va_get(klass); - - printf("Vector of ints:\n"); - printf("size=%zd\ncapacity=%zd\n\n", Vint_size(vint), Vint_capacity(vint)); - - int i; - for (i = 0; i < 10; i++) - Vint_push_back(vint, i*i); - - printf("size=%zd\ncapacity=%zd\n\n", Vint_size(vint), Vint_capacity(vint)); - - for (i = 0; i < Vint_size(vint); i++) - printf("%d%c", Vint_get(vint, i), i+1 == Vint_size(vint) ? '\n' : ','); - - Vint_clear(vint); - Vint_reserve(vint, 100); - printf("\nsize=%zd\ncapacity=%zd\n", Vint_size(vint), Vint_capacity(vint)); - - printf("\nVector of objects:\n"); - - for (i = 0; i < 10; i++) { - A *a = A_new_std_string_i("hello", i); - VA_push_back(va, a); - A_delete(a); - } - - for (i = 0; i < VA_size(va); i++) { - A *a = VA_get(va, i); - printf("%s %d\n", A_name_get(a), A_value_get(a)); - } - - Klass_delete(klass); - - return 0; -} diff --git a/Examples/test-suite/argcargvtest.i b/Examples/test-suite/argcargvtest.i index 6ce5e68fd..5711441d9 100644 --- a/Examples/test-suite/argcargvtest.i +++ b/Examples/test-suite/argcargvtest.i @@ -1,6 +1,6 @@ %module argcargvtest -#if !defined(SWIGC) && !defined(SWIGCSHARP) && !defined(SWIGD) && !defined(SWIGGO) && !defined(SWIGGUILE) && !defined(SWIGJAVA) && !defined(SWIGJAVASCRIPT) && !defined(SWIGMZSCHEME) && !defined(SWIGOCAML) && !defined(SWIGR) && !defined(SWIGSCILAB) +#if !defined(SWIGCSHARP) && !defined(SWIGD) && !defined(SWIGGO) && !defined(SWIGGUILE) && !defined(SWIGJAVA) && !defined(SWIGJAVASCRIPT) && !defined(SWIGMZSCHEME) && !defined(SWIGOCAML) && !defined(SWIGR) && !defined(SWIGSCILAB) %include %apply (int ARGC, char **ARGV) { (size_t argc, const char **argv) } diff --git a/Examples/test-suite/c/Makefile.in b/Examples/test-suite/c/Makefile.in deleted file mode 100644 index f5b88b4f8..000000000 --- a/Examples/test-suite/c/Makefile.in +++ /dev/null @@ -1,239 +0,0 @@ -####################################################################### -# Makefile for C test-suite -####################################################################### - -LANGUAGE = c -C = gcc -CXX = g++ -RUNMESUFFIX = _runme -srcdir = @srcdir@ -top_srcdir = ../@top_srcdir@ -top_builddir = ../@top_builddir@ - -# This can be set to ":" to avoid progress messages. -ECHO_PROGRESS := echo - -CPP_TEST_CASES := \ - c_backend_cpp_natural_std_string \ - c_backend_cpp_exception - -CPP11_TEST_CASES := \ - cpp11_shared_ptr_const \ - cpp11_shared_ptr_nullptr_in_containers \ - cpp11_shared_ptr_overload \ - cpp11_shared_ptr_upcast \ - -# The following tests are currently broken and need to be fixed. -FAILING_C_TESTS := \ - arrays \ - funcptr \ - function_typedef \ - lextype \ - li_carrays \ - nested \ - nested_extend_c \ - nested_structs \ - typedef_struct \ - union_parameter \ - unions \ - -FAILING_CPP_TESTS := \ - apply_signed_char \ - array_member \ - array_typedef_memberin \ - arrayref \ - arrays_dimensionless \ - arrays_global \ - arrays_global_twodim \ - constant_pointers \ - enum_thorough \ - extend \ - extend_default \ - extern_c \ - extern_template_method \ - funcptr_cpp \ - global_scope_types \ - grouping \ - import_nomodule \ - li_attribute \ - li_attribute_template \ - li_boost_shared_ptr_attribute \ - li_std_auto_ptr \ - li_std_deque \ - li_std_wstring \ - li_windows \ - member_funcptr_galore \ - member_pointer \ - member_pointer_const \ - mixed_types \ - nested_class \ - template_basic \ - template_default \ - template_enum \ - template_explicit \ - template_typedef_fnc \ - typedef_array_member \ - typedef_funcptr \ - typedef_struct_cpp \ - typemap_namespace \ - typemap_various \ - using_extend \ - varargs \ - varargs_overload \ - virtual_poly \ - cpp11_ref_qualifiers \ - cpp11_ref_qualifiers_typemaps \ - cpp11_result_of \ - cpp11_rvalue_reference \ - cpp11_rvalue_reference2 \ - cpp11_rvalue_reference3 \ - cpp11_type_aliasing \ - -# Ignore warnings about failing to apply typemaps because none are defined: -# usually there is no need for special typemaps in C. -char_binary.cpptest director_binary_string.cpptest li_typemaps.cpptest li_typemaps_apply.cpptest long_long_apply.cpptest: SWIGOPT += -w453 - -include $(srcdir)/../common.mk - -# Overridden variables here - -# Suppress warnings about experimental status and unsupported features -- there are just too many of those for now for these warnings to be useful. -SWIGOPT += -w524 -w779 - -%.ctest: SWIGOPT += -nocxx - -# Tests for which C++ wrappers currently don't compile. -contract.cpptest: SWIG_NOCXX = -nocxx # Class derived from a base class with multiple base classes and hence ignored. -conversion.cpptest: SWIG_NOCXX = -nocxx # Conversion operator return type not handled specially. -conversion_namespace.cpptest: SWIG_NOCXX = -nocxx # Conversion operator name not handled correctly. -conversion_ns_template.cpptest: SWIG_NOCXX = -nocxx # Conversion operator return not handled specially. -cpp11_default_delete.cpptest: SWIG_NOCXX = -nocxx # Assignment operator and r-value references not handled. -cpp11_explicit_conversion_operators.cpptest: SWIG_NOCXX = -nocxx # Conversion operator return type. -cpp11_noexcept.cpptest: SWIG_NOCXX = -nocxx # Assignment operator. -default_constructor.cpptest: SWIG_NOCXX = -nocxx # Something weird with OSRSpatialReferenceShadow. -director_conversion_operators.cpptest: SWIG_NOCXX = -nocxx # Conversion operator return type. -director_frob.cpptest: SWIG_NOCXX = -nocxx # Conversion operator return type. -extend_template_method.cpptest: SWIG_NOCXX = -nocxx # Wrong form of template function name. -features.cpptest: SWIG_NOCXX = -nocxx # Conversion operator return type not handled specially. -global_namespace.cpptest: SWIG_NOCXX = -nocxx # Const const reference type. -li_carrays_cpp.cpptest: SWIG_NOCXX = -nocxx # Arrays not really supported currently. -li_cdata_cpp.cpptest: SWIG_NOCXX = -nocxx # No support for multiarg typemaps required here. -member_template.cpptest: SWIG_NOCXX = -nocxx # Wrong form of template function name. -multiple_inheritance_abstract.cpptest: SWIG_NOCXX = -nocxx # Multiple inheritance not supported. -multiple_inheritance_interfaces.cpptest: SWIG_NOCXX = -nocxx -multiple_inheritance_nspace.cpptest: SWIG_NOCXX = -nocxx -multiple_inheritance_shared_ptr.cpptest: SWIG_NOCXX = -nocxx -namespace_class.cpptest: SWIG_NOCXX = -nocxx # Many broken type names. -operator_pointer_ref.cpptest: SWIG_NOCXX = -nocxx -operbool.cpptest: SWIG_NOCXX = -nocxx -overload_null.cpptest: SWIG_NOCXX = -nocxx -overload_template.cpptest: SWIG_NOCXX = -nocxx -overload_template_fast.cpptest: SWIG_NOCXX = -nocxx -pure_virtual.cpptest: SWIG_NOCXX = -nocxx -rename1.cpptest: SWIG_NOCXX = -nocxx -rename2.cpptest: SWIG_NOCXX = -nocxx -rename3.cpptest: SWIG_NOCXX = -nocxx -rename4.cpptest: SWIG_NOCXX = -nocxx -rename_wildcard.cpptest: SWIG_NOCXX = -nocxx -return_const_value.cpptest: SWIG_NOCXX = -nocxx -smart_pointer_member.cpptest: SWIG_NOCXX = -nocxx -smart_pointer_template_const_overload.cpptest: SWIG_NOCXX = -nocxx -smart_pointer_templatemethods.cpptest: SWIG_NOCXX = -nocxx # Wrong form of template function name. -struct_initialization_cpp.cpptest: SWIG_NOCXX = -nocxx # Arrays in initialization not supported. -template_const_ref.cpptest: SWIG_NOCXX = -nocxx -template_default_arg_overloaded.cpptest: SWIG_NOCXX = -nocxx -template_inherit_abstract.cpptest: SWIG_NOCXX = -nocxx -template_methods.cpptest: SWIG_NOCXX = -nocxx -template_nested.cpptest: SWIG_NOCXX = -nocxx -template_nested_flat.cpptest: SWIG_NOCXX = -nocxx -template_qualifier.cpptest: SWIG_NOCXX = -nocxx -template_static.cpptest: SWIG_NOCXX = -nocxx -typemap_array_qualifiers.cpptest: SWIG_NOCXX = -nocxx # Arrays not supported. -valuewrapper_const.cpptest: SWIG_NOCXX = -nocxx # Misplaced const. - -# Avoid conflict with the C++ keyword for some tests. -SWIG_NS = $* - -dynamic_cast.cpptest: SWIG_NS = dyn_cast -typename.cpptest: SWIG_NS = type_name - -%.multicpptest: SWIGOPT += -namespace $* - -%.cpptest: SWIGOPT += -namespace $(SWIG_NS) $(SWIG_NOCXX) - -SRCDIR = ../$(srcdir)/ - -# Make function to check if we have an executable test for the given test base name. -define has_runme --f $(srcdir)/$1$(RUNMESUFFIX).c -o -f $(srcdir)/$1$(RUNMESUFFIX).cxx -endef - -# Rules for the different types of tests -%.cpptest: - $(setup) - +(cd $* && $(swig_and_compile_cpp)) - +if [ $(call has_runme,$*) ]; then \ - $(do_run_testcase); \ - else \ - cd $* && $(call syntax_check_testcase,$*); \ - fi - -%.ctest: - $(setup) - +(cd $* && $(swig_and_compile_c)) - +if [ $(call has_runme,$*) ]; then \ - $(do_run_testcase); \ - else \ - cd $* && $(call syntax_check_testcase,$*,_c); \ - fi - -%.multicpptest: - $(setup) - +(cd $* && $(swig_and_compile_multi_cpp)) - +if [ $(call has_runme,$*) ]; then \ - $(do_run_testcase); \ - else \ - cd $* && for f in `cat $(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/$*.list`; do \ - $(call syntax_check_testcase,$${f}) || exit 1; \ - done; \ - fi - -# Makes a directory for the testcase if it does not exist -setup = \ - if [ $(call has_runme,$*) ]; then \ - $(ECHO_PROGRESS) "$(ACTION)ing testcase $* (with run test) under $(LANGUAGE)" ; \ - else \ - $(ECHO_PROGRESS) "$(ACTION)ing testcase $* under $(LANGUAGE)" ; \ - fi; \ - if [ ! -d $* ]; then \ - mkdir $*; \ - fi; - -# Checks the header syntax if there is no runnable testcase for it. -# -# The optional second argument can be "_c" to check syntax using C compiler only -# (by default both C and C++ compilers are used). -syntax_check_testcase = \ - $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile \ - SRCDIR='$(SRCDIR)' \ - INTERFACEDIR='$(INTERFACEDIR)' \ - C_HEADER=$1_wrap.h \ - c_syntax_check$2 - -# Compiles C files then runs the testcase unconditionally. -do_run_testcase = \ - cd $* && $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile \ - SRCDIR='$(SRCDIR)' \ - RUNME=$*$(RUNMESUFFIX) \ - RUNME_EXT=$(patsubst .%,%,$(suffix $(wildcard $(srcdir)/$*$(RUNMESUFFIX).c*))) \ - TARGET='$*' \ - c_run - -# Clean: remove testcase directories -%.clean: - @if [ -d $* ]; then \ - rm -rf $*; \ - fi; - -clean: - @rm -f *_wrap.* *~ *.exe *.dll *.so *.out *runme diff --git a/Examples/test-suite/c/abstract_access_runme.c b/Examples/test-suite/c/abstract_access_runme.c deleted file mode 100644 index 02d99511f..000000000 --- a/Examples/test-suite/c/abstract_access_runme.c +++ /dev/null @@ -1,12 +0,0 @@ -#include "abstract_access/abstract_access_wrap.h" -#include - -int main(int argc, const char *argv[]) { - abstract_access_D *d = abstract_access_D_new(); - - assert(abstract_access_D_do_x(d) == 1); - - abstract_access_D_delete(d); - - return 0; -} diff --git a/Examples/test-suite/c/abstract_inherit_ok_runme.cxx b/Examples/test-suite/c/abstract_inherit_ok_runme.cxx deleted file mode 100644 index 147c549dc..000000000 --- a/Examples/test-suite/c/abstract_inherit_ok_runme.cxx +++ /dev/null @@ -1,12 +0,0 @@ -#include "abstract_inherit_ok_wrap.h" -#include - -int main(int argc, const char *argv[]) { - abstract_inherit_ok_Foo* const spam = (abstract_inherit_ok_Foo*)abstract_inherit_ok_Spam_new(); - - assert(abstract_inherit_ok_Foo_blah(spam) == 0); - - abstract_inherit_ok_Foo_delete(spam); - - return 0; -} diff --git a/Examples/test-suite/c/abstract_typedef_runme.c b/Examples/test-suite/c/abstract_typedef_runme.c deleted file mode 100644 index 5e90c1676..000000000 --- a/Examples/test-suite/c/abstract_typedef_runme.c +++ /dev/null @@ -1,15 +0,0 @@ -#include "abstract_typedef/abstract_typedef_wrap.h" -#include -#include - -int main(int argc, const char *argv[]) { - abstract_typedef_Engine *e = abstract_typedef_Engine_new(); - abstract_typedef_A *a = abstract_typedef_A_new(); - - assert(abstract_typedef_AbstractBaseClass_write((abstract_typedef_AbstractBaseClass*)a, e) == true); - - abstract_typedef_A_delete(a); - abstract_typedef_Engine_delete(e); - - return 0; -} diff --git a/Examples/test-suite/c/abstract_virtual_runme.c b/Examples/test-suite/c/abstract_virtual_runme.c deleted file mode 100644 index 7c8c1be37..000000000 --- a/Examples/test-suite/c/abstract_virtual_runme.c +++ /dev/null @@ -1,18 +0,0 @@ -#include "abstract_virtual/abstract_virtual_wrap.h" -#include - -int main(int argc, const char *argv[]) { - abstract_virtual_B *b = abstract_virtual_B_new(); - abstract_virtual_D *d = abstract_virtual_D_new(); - abstract_virtual_E *e = abstract_virtual_E_new(); - - assert(abstract_virtual_B_foo(b) == 0); - assert(abstract_virtual_D_foo(d) == 0); - assert(abstract_virtual_E_foo(e) == 0); - - abstract_virtual_B_delete(b); - abstract_virtual_D_delete(d); - abstract_virtual_E_delete(e); - - return 0; -} diff --git a/Examples/test-suite/c/access_change_runme.c b/Examples/test-suite/c/access_change_runme.c deleted file mode 100644 index c17af6bc4..000000000 --- a/Examples/test-suite/c/access_change_runme.c +++ /dev/null @@ -1,34 +0,0 @@ -#include "access_change_wrap.h" -#include - -int main(int argc, const char *argv[]) { - access_change_BaseInt *ba = access_change_BaseInt_new(); - access_change_DerivedInt *d = access_change_DerivedInt_new(); - access_change_BottomInt *bo = access_change_BottomInt_new(); - - assert(access_change_BaseInt_PublicProtectedPublic1(ba) == 0); - assert(access_change_BaseInt_PublicProtectedPublic2(ba) == 0); - assert(access_change_BaseInt_PublicProtectedPublic3(ba) == 0); - assert(access_change_BaseInt_PublicProtectedPublic4(ba) == 0); - - assert(access_change_DerivedInt_WasProtected1((access_change_DerivedInt*)ba) == 0); - assert(access_change_DerivedInt_WasProtected2((access_change_DerivedInt*)ba) == 0); - assert(access_change_DerivedInt_WasProtected3((access_change_DerivedInt*)ba) == 0); - assert(access_change_DerivedInt_WasProtected4((access_change_DerivedInt*)ba) == 0); - - assert(access_change_BottomInt_PublicProtectedPublic1((access_change_BottomInt*)ba) == 0); - assert(access_change_BottomInt_PublicProtectedPublic2((access_change_BottomInt*)ba) == 0); - assert(access_change_BottomInt_PublicProtectedPublic3((access_change_BottomInt*)ba) == 0); - assert(access_change_BottomInt_PublicProtectedPublic4((access_change_BottomInt*)ba) == 0); - - assert(access_change_BottomInt_WasProtected1((access_change_BottomInt*)ba) == 0); - assert(access_change_BottomInt_WasProtected2((access_change_BottomInt*)ba) == 0); - assert(access_change_BottomInt_WasProtected3((access_change_BottomInt*)ba) == 0); - assert(access_change_BottomInt_WasProtected4((access_change_BottomInt*)ba) == 0); - - access_change_BaseInt_delete(ba); - access_change_DerivedInt_delete(d); - access_change_BottomInt_delete(bo); - - return 0; -} diff --git a/Examples/test-suite/c/add_link_runme.c b/Examples/test-suite/c/add_link_runme.c deleted file mode 100644 index 8ebdf485a..000000000 --- a/Examples/test-suite/c/add_link_runme.c +++ /dev/null @@ -1,14 +0,0 @@ -#include "add_link/add_link_wrap.h" -#include - -int main(int argc, const char *argv[]) { - add_link_Foo *f = add_link_Foo_new(); - add_link_Foo *f2 = add_link_Foo_blah(f); - - assert(f2 != 0); - - add_link_Foo_delete(f); - add_link_Foo_delete(f2); - - return 0; -} diff --git a/Examples/test-suite/c/anonymous_bitfield_runme.c b/Examples/test-suite/c/anonymous_bitfield_runme.c deleted file mode 100644 index 55937585e..000000000 --- a/Examples/test-suite/c/anonymous_bitfield_runme.c +++ /dev/null @@ -1,29 +0,0 @@ -#include "anonymous_bitfield/anonymous_bitfield_wrap.h" -#include - -int main(int argc, const char *argv[]) { - anonymous_bitfield_Foo *f = anonymous_bitfield_Foo_new(); - - assert(f != 0); - - anonymous_bitfield_Foo_x_set(f, 1); - assert(anonymous_bitfield_Foo_x_get(f) == 1); - assert(anonymous_bitfield_Foo_y_get(f) == 0); - - anonymous_bitfield_Foo_y_set(f, 0); - assert(anonymous_bitfield_Foo_x_get(f) == 1); - assert(anonymous_bitfield_Foo_y_get(f) == 0); - - anonymous_bitfield_Foo_f_set(f, 1); - assert(anonymous_bitfield_Foo_f_get(f) == 1); - - anonymous_bitfield_Foo_z_set(f, 1); - assert(anonymous_bitfield_Foo_z_get(f) == 1); - - anonymous_bitfield_Foo_seq_set(f, 1); - assert(anonymous_bitfield_Foo_seq_get(f) == 1); - - anonymous_bitfield_Foo_delete(f); - - return 0; -} diff --git a/Examples/test-suite/c/c_backend_cpp_exception_runme.c b/Examples/test-suite/c/c_backend_cpp_exception_runme.c deleted file mode 100644 index 206bedbbc..000000000 --- a/Examples/test-suite/c/c_backend_cpp_exception_runme.c +++ /dev/null @@ -1,14 +0,0 @@ -#include - -#include "c_backend_cpp_exception/c_backend_cpp_exception_wrap.h" - -int main() -{ - assert(c_backend_cpp_exception_checkVal_get() == 0); - c_backend_cpp_exception_throwSomeKnownException(); - assert(c_backend_cpp_exception_checkVal_get() == 1); - c_backend_cpp_exception_throwSomeUnknownException(); - assert(c_backend_cpp_exception_checkVal_get() == 2); - - return 0; -} \ No newline at end of file diff --git a/Examples/test-suite/c/c_backend_cpp_natural_std_string_runme.c b/Examples/test-suite/c/c_backend_cpp_natural_std_string_runme.c deleted file mode 100644 index cb605e00e..000000000 --- a/Examples/test-suite/c/c_backend_cpp_natural_std_string_runme.c +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include -#include - -#include "c_backend_cpp_natural_std_string/c_backend_cpp_natural_std_string_wrap.h" - -int main() -{ - char buf[] = "World, "; - char *myComposedString = c_backend_cpp_natural_std_string_myStringAppend(buf, "Hello!"); - - assert(myComposedString); - assert(strcmp(myComposedString, "World, Hello!") == 0); - - free(myComposedString); - - return 0; -} \ No newline at end of file diff --git a/Examples/test-suite/c/cast_operator_runme.c b/Examples/test-suite/c/cast_operator_runme.c deleted file mode 100644 index e6099672d..000000000 --- a/Examples/test-suite/c/cast_operator_runme.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include -#include - -#include "cast_operator/cast_operator_wrap.h" - -int main() { - cast_operator_A *a = cast_operator_A_new(); - if (strcmp(cast_operator_A_tochar(a), "hi")) - fprintf(stderr, "cast failed\n"); - cast_operator_A_delete(a); - exit(0); -} - diff --git a/Examples/test-suite/c/char_strings_runme.c b/Examples/test-suite/c/char_strings_runme.c deleted file mode 100644 index 65ef205ec..000000000 --- a/Examples/test-suite/c/char_strings_runme.c +++ /dev/null @@ -1,200 +0,0 @@ -#include -#include -#include - -#include "char_strings/char_strings_wrap.h" - -int main() { - char *CPLUSPLUS_MSG = "A message from the deep dark world of C++, where anything is possible."; - char *OTHERLAND_MSG = "Little message from the safe world."; - - int count = 10000; - int i = 0; - - // get functions - for (i=0; i - -int main(int argc, const char *argv[]) { - cpp11_shared_ptr_const_Foo* f; - cpp11_shared_ptr_const_Foo* f2; - - f = cpp11_shared_ptr_const_Foo_new(17); - assert(cpp11_shared_ptr_const_Foo_get_m(f) == 17); - f2 = cpp11_shared_ptr_const_foo(f); - assert(cpp11_shared_ptr_const_Foo_get_m(f2) == 17); - cpp11_shared_ptr_const_Foo_delete(f2); - cpp11_shared_ptr_const_Foo_delete(f); - - return 0; -} diff --git a/Examples/test-suite/c/cpp11_shared_ptr_upcast_runme.c b/Examples/test-suite/c/cpp11_shared_ptr_upcast_runme.c deleted file mode 100644 index 493ddf617..000000000 --- a/Examples/test-suite/c/cpp11_shared_ptr_upcast_runme.c +++ /dev/null @@ -1,26 +0,0 @@ -#include "cpp11_shared_ptr_upcast_wrap.h" -#include - -int main(int argc, const char *argv[]) { - { - cpp11_shared_ptr_upcast_Derived* d; - - d = cpp11_shared_ptr_upcast_Derived_new_i(17); - assert( cpp11_shared_ptr_upcast_base_num1((cpp11_shared_ptr_upcast_Base *)d) == -1 ); - assert( cpp11_shared_ptr_upcast_derived_num1(d) == 17 ); - - cpp11_shared_ptr_upcast_Derived_delete(d); - } - - { - cpp11_shared_ptr_upcast_Derived2* d2; - - d2 = cpp11_shared_ptr_upcast_Derived2_new_i(289); - assert( cpp11_shared_ptr_upcast_base2_num1((cpp11_shared_ptr_upcast_Base2 *)d2) == -1 ); - assert( cpp11_shared_ptr_upcast_derived2_num1(d2) == 289 ); - - cpp11_shared_ptr_upcast_Derived2_delete(d2); - } - - return 0; -} diff --git a/Examples/test-suite/c/cpp_basic_runme.c b/Examples/test-suite/c/cpp_basic_runme.c deleted file mode 100644 index 164142d9f..000000000 --- a/Examples/test-suite/c/cpp_basic_runme.c +++ /dev/null @@ -1,109 +0,0 @@ -#include "cpp_basic/cpp_basic_wrap.h" -#include -#include - -int main(int argc, const char *argv[]) { - cpp_basic_Foo *f = cpp_basic_Foo_new(5); - - // test global static variables - // TODO: Implement or document as not available - /* - assert(init_ref != 0); - - global_fptr_set(f); - assert(cpp_basic_Foo_num_get(global_fptr_get()) == 5); - - assert(cpp_basic_Foo_num_get(global_fref_get()) == -4); - cpp_basic_Foo_num_set(f, 6); - global_fref_set(f); - assert(cpp_basic_Foo_num_get(global_fref_get()) == 6); - - cpp_basic_Foo_num_set(f, 7); - global_fval_set(f); - assert(cpp_basic_Foo_num_get(global_fval_get()) == 7); - */ - - cpp_basic_Foo_num_set(f, 5); - assert(cpp_basic_Foo_num_get(f) == 5); - assert(cpp_basic_Foo_func1(f, 2) == 20); - assert(cpp_basic_Foo_func2(f, 2) == -10); - - // function pointer set/get tests are missing - // because of unclear implementation details - //foo_func_ptr_set(f, &cpp_basic_Foo_func1); - - // test of global static variable is missing - // because of unclear implementation details - //assert(c_init_ref != 0); - - cpp_basic_Bar *b = cpp_basic_Bar_new(); - - // check default value set by constructor - assert(cpp_basic_Bar_cint_get(b) == 3); - - // check default value set by cpp_basic_Bar initializer - assert(cpp_basic_Foo_num_get(cpp_basic_Bar_fval_get(b)) == 15); - // change, recheck - cpp_basic_Foo_num_set(cpp_basic_Bar_fval_get(b), 2); - assert(cpp_basic_Foo_num_get(cpp_basic_Bar_fval_get(b)) == 2); - - // check references - assert(cpp_basic_Bar_fref_get(b) != 0); - - // check global static value and references - assert(cpp_basic_Foo_num_get(cpp_basic_Bar_fref_get(b)) == -4); - cpp_basic_Foo_num_set(cpp_basic_Bar_fref_get(b), 1); - assert(cpp_basic_Foo_num_get(cpp_basic_Bar_fref_get(b)) == 1); - // create new cpp_basic_Bar instance and check static member value - cpp_basic_Bar *b2 = cpp_basic_Bar_new(); - assert(cpp_basic_Foo_num_get(cpp_basic_Bar_fref_get(b2)) == 1); - cpp_basic_Bar_delete(b2); - b2 = 0; - - // Try to set a pointer - cpp_basic_Bar_fptr_set(b, f); - - assert(cpp_basic_Bar_test(b, 2, f) == 9); - assert(cpp_basic_Bar_test(b, 2, 0) == 4); - - cpp_basic_Foo *f2 = cpp_basic_Bar_testFoo(b, 2, f); - assert(cpp_basic_Foo_num_get(f2) == 11); - cpp_basic_Foo_delete(f2); - f2 = 0; - - // test static variables - cpp_basic_Bar_global_fptr_set(f); - assert(cpp_basic_Foo_num_get(cpp_basic_Bar_global_fptr_get()) == 5); - - cpp_basic_Foo_num_set(f, 6); - cpp_basic_Bar_global_fref_set(f); - assert(cpp_basic_Foo_num_get(cpp_basic_Bar_global_fref_get()) == 6); - - cpp_basic_Foo_num_set(f, 7); - cpp_basic_Bar_global_fval_set(f); - assert(cpp_basic_Foo_num_get(cpp_basic_Bar_global_fval_get()) == 7); - - // getting, setting and calling function pointers isn't supported yet -#if 0 - SomeTypeForMemFnPtr func1 = get_func1_ptr(); - cpp_basic_Foo_func_ptr_set(f, func1); - assert(test_func_ptr(f, 2) == 28); - SomeTypeForMemFnPtr func2 = get_func2_ptr(); - cpp_basic_Foo_func_ptr_set(f, func2); - assert(test_func_ptr(f, 2) == -14); -#endif - - cpp_basic_Bar_delete(b); - cpp_basic_Foo_delete(f); - - cpp_basic_Fl_Window *w = cpp_basic_Fl_Window_new(); - // Test whether macro worked for code extension - // and test optional function parameters - cpp_basic_Fl_Window_show(w); - cpp_basic_Fl_Window_show_pv(w, 0); - cpp_basic_Fl_Window_show_pv_pv(w, 0, 0); - cpp_basic_Fl_Window_delete(w); - w = 0; - - return 0; -} diff --git a/Examples/test-suite/c/cpp_enum_runme.cxx b/Examples/test-suite/c/cpp_enum_runme.cxx deleted file mode 100644 index 060c127df..000000000 --- a/Examples/test-suite/c/cpp_enum_runme.cxx +++ /dev/null @@ -1,71 +0,0 @@ -#include "cpp_enum/cpp_enum_wrap.h" -#include -#include - -int main(int argc, const char *argv[]) { - - enum cpp_enum_SOME_ENUM e = cpp_enum_ENUM_ONE, *p; - - // check the constructor's default value - cpp_enum_StructWithEnums *s = cpp_enum_StructWithEnums_new(); - assert(cpp_enum_StructWithEnums_some_enum_get(s) == cpp_enum_ENUM_ONE); - - // check setter - cpp_enum_StructWithEnums_some_enum_set(s, cpp_enum_ENUM_TWO); - assert(cpp_enum_StructWithEnums_some_enum_get(s) == cpp_enum_ENUM_TWO); - - // check function call - cpp_enum_StructWithEnums_enum_test1(s, e, &e, &e); - - // check function call - cpp_enum_StructWithEnums_enum_test2(s, e, &e, &e); - - // check function call - assert(cpp_enum_StructWithEnums_enum_test3(s) == cpp_enum_ENUM_ONE); - - // check function call - assert(cpp_enum_StructWithEnums_enum_test4(s) == cpp_enum_ENUM_TWO); - - // check function call - p = cpp_enum_StructWithEnums_enum_test5(s); - assert(*p == cpp_enum_ENUM_TWO); - - // check function call - p = cpp_enum_StructWithEnums_enum_test6(s); - assert(*p == cpp_enum_ENUM_TWO); - - // check function call - p = cpp_enum_StructWithEnums_enum_test7(s); - assert(*p == cpp_enum_ENUM_TWO); - - // check function call - p = cpp_enum_StructWithEnums_enum_test8(s); - assert(*p == cpp_enum_ENUM_TWO); - - cpp_enum_StructWithEnums_delete(s); - - cpp_enum_Foo *f = cpp_enum_Foo_new(); - - // check the constructor's default value - assert(cpp_enum_Foo_hola_get(f) == cpp_enum_Foo_Hello); - - cpp_enum_Foo_hola_set(f, cpp_enum_Foo_Hi); - assert(cpp_enum_Foo_hola_get(f) == cpp_enum_Foo_Hi); - - cpp_enum_Foo_delete(f); - - //check C enum - cpp_enum_hi_set(cpp_enum_Hi); - cpp_enum_hi_set(cpp_enum_Hello); - - // check typedef enum - cpp_enum_play_state t; - - t = cpp_enum_PLAY; - assert(t == 1); - - t = cpp_enum_STOP; - assert(t == 0); - - return 0; -} diff --git a/Examples/test-suite/c/enum_rename_runme.c b/Examples/test-suite/c/enum_rename_runme.c deleted file mode 100644 index ccc016816..000000000 --- a/Examples/test-suite/c/enum_rename_runme.c +++ /dev/null @@ -1,12 +0,0 @@ -#include - -#include "enum_rename/enum_rename_wrap.h" - -int main() { - assert(enum_rename_M_Jan == 0); - assert(enum_rename_May == 1); - assert(enum_rename_M_Dec == 2); - - assert(enum_rename_S_Can == 1); - assert(enum_rename_S_Must == 2); -} diff --git a/Examples/test-suite/c/enums_runme.c b/Examples/test-suite/c/enums_runme.c deleted file mode 100644 index 24a811766..000000000 --- a/Examples/test-suite/c/enums_runme.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include - -#include "enums/enums_wrap.h" - -int main() { - assert(GlobalInstance == globalinstance1); - assert(iFoo_Char == 'a'); - enums_bar2(1); - enums_bar3(1); - enums_bar1(1); - exit(0); -} - diff --git a/Examples/test-suite/c/exception_order_runme.c b/Examples/test-suite/c/exception_order_runme.c deleted file mode 100644 index a4ca46522..000000000 --- a/Examples/test-suite/c/exception_order_runme.c +++ /dev/null @@ -1,46 +0,0 @@ -#include -#include - -#include "exception_order/exception_order_wrap.h" - -int main() { - exception_order_A* a = exception_order_A_new(); - - exception_order_A_foo(a); - if (!exception_order_SWIG_CException_get_pending()) { - fprintf(stderr, "foo: bad exception order\n"); - } else { - exception_order_SWIG_CException_reset_pending(); - } - - exception_order_A_bar(a); - if (!exception_order_SWIG_CException_get_pending()) { - fprintf(stderr, "bar: bad exception order\n"); - } else { - exception_order_SWIG_CException_reset_pending(); - } - - exception_order_A_foobar(a); - if (!exception_order_SWIG_CException_get_pending()) { - fprintf(stderr, "foobar: bad exception order\n"); - } else { - exception_order_SWIG_CException_reset_pending(); - } - - exception_order_A_barfoo(a, 1); - if (!exception_order_SWIG_CException_get_pending()) { - fprintf(stderr, "barfoo(1): bad exception order\n"); - } else { - exception_order_SWIG_CException_reset_pending(); - } - - exception_order_A_barfoo(a, 2); - if (!exception_order_SWIG_CException_get_pending()) { - fprintf(stderr, "barfoo(2): bad exception order\n"); - } else { - exception_order_SWIG_CException_reset_pending(); - } - - exit(0); -} - diff --git a/Examples/test-suite/c/global_vars_runme.c b/Examples/test-suite/c/global_vars_runme.c deleted file mode 100644 index 1226152bb..000000000 --- a/Examples/test-suite/c/global_vars_runme.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include -#include "global_vars/global_vars_wrap.h" - -int main(int argc, const char *argv[]) -{ - global_vars_init(); - - assert(strcmp(global_vars_b_get(), "string b") == 0); - assert(global_vars_x_get() == 1234); - - return 0; -} diff --git a/Examples/test-suite/c/li_boost_shared_ptr_runme.cxx b/Examples/test-suite/c/li_boost_shared_ptr_runme.cxx deleted file mode 100644 index 8d5149f71..000000000 --- a/Examples/test-suite/c/li_boost_shared_ptr_runme.cxx +++ /dev/null @@ -1,15 +0,0 @@ -#include "li_boost_shared_ptr_wrap.h" -#include -#include - -int main(int argc, const char *argv[]) { - { - li_boost_shared_ptr::Klass k("me oh my"); - assert( k.getValue() == "me oh my" ); - } - - { - li_boost_shared_ptr::Klass k{li_boost_shared_ptr_factorycreate()}; - assert( k.getValue() == "factorycreate" ); - } -} diff --git a/Examples/test-suite/c/li_std_map_runme.c b/Examples/test-suite/c/li_std_map_runme.c deleted file mode 100644 index dd9292f87..000000000 --- a/Examples/test-suite/c/li_std_map_runme.c +++ /dev/null @@ -1,26 +0,0 @@ -#include "li_std_map/li_std_map_wrap.h" -#include - -int main() { - li_std_map_A* a1 = li_std_map_A_new_i(3); - li_std_map_A* a2 = li_std_map_A_new_i(7); - - li_std_map_mapA* mA = li_std_map_mapA_new(); - li_std_map_mapA_set(mA, 1, a1); - li_std_map_mapA_set(mA, 2, a2); - - assert( li_std_map_mapA_size(mA) == 2 ); - - { - li_std_map_A* a = li_std_map_mapA_get(mA, 1); - assert( li_std_map_A_val_get(a) == 3 ); - } - - assert( !li_std_map_mapA_has_key(mA, 3) ); - - li_std_map_mapA_delete(mA); - li_std_map_A_delete(a2); - li_std_map_A_delete(a1); - - return 0; -} diff --git a/Examples/test-suite/c/li_std_pair_runme.c b/Examples/test-suite/c/li_std_pair_runme.c deleted file mode 100644 index 793b160ab..000000000 --- a/Examples/test-suite/c/li_std_pair_runme.c +++ /dev/null @@ -1,42 +0,0 @@ -#include "li_std_pair/li_std_pair_wrap.h" -#include - -int main() { - { - li_std_pair_IntPair* intPair = li_std_pair_makeIntPair(7, 6); - assert(li_std_pair_IntPair_first_get(intPair)==7 && li_std_pair_IntPair_second_get(intPair)==6); - - assert(li_std_pair_product1(intPair) == 42); - assert(li_std_pair_product2(intPair) == 42); - assert(li_std_pair_product3(intPair) == 42); - - li_std_pair_IntPair_delete(intPair); - } - - { - li_std_pair_IntPair* intPairPtr = li_std_pair_makeIntPairPtr(7, 6); - assert(li_std_pair_IntPair_first_get(intPairPtr)==7 && li_std_pair_IntPair_second_get(intPairPtr)==6); - - assert(li_std_pair_product1(intPairPtr) == 42); - assert(li_std_pair_product2(intPairPtr) == 42); - assert(li_std_pair_product3(intPairPtr) == 42); - } - - { - li_std_pair_IntPair* intPairRef = li_std_pair_makeIntPairRef(7, 6); - assert(li_std_pair_IntPair_first_get(intPairRef)==7 && li_std_pair_IntPair_second_get(intPairRef)==6); - - assert(li_std_pair_product1(intPairRef) == 42); - assert(li_std_pair_product2(intPairRef) == 42); - assert(li_std_pair_product3(intPairRef) == 42); - } - - { - li_std_pair_IntPair* intPairConstRef = li_std_pair_makeIntPairConstRef(7, 6); - assert(li_std_pair_IntPair_first_get(intPairConstRef)==7 && li_std_pair_IntPair_second_get(intPairConstRef)==6); - - assert(li_std_pair_product1(intPairConstRef) == 42); - assert(li_std_pair_product2(intPairConstRef) == 42); - assert(li_std_pair_product3(intPairConstRef) == 42); - } -} diff --git a/Examples/test-suite/c/li_std_set_runme.c b/Examples/test-suite/c/li_std_set_runme.c deleted file mode 100644 index e3a7781fd..000000000 --- a/Examples/test-suite/c/li_std_set_runme.c +++ /dev/null @@ -1,33 +0,0 @@ -#include "li_std_set/li_std_set_wrap.h" -#include - -int main() { - { - li_std_set_IntSet* is = li_std_set_IntSet_new(); - - li_std_set_IntSet_add(is, 1); - li_std_set_IntSet_add(is, 4); - li_std_set_IntSet_add(is, 9); - - assert( li_std_set_IntSet_size(is) == 3 ); - assert( li_std_set_IntSet_has(is, 4) ); - assert( !li_std_set_IntSet_has(is, 16) ); - - li_std_set_IntSet_delete(is); - } - - { - li_std_set_StringSet* ss = li_std_set_StringSet_new(); - - li_std_set_StringSet_add(ss, "foo"); - li_std_set_StringSet_add(ss, "bar"); - - assert( li_std_set_StringSet_size(ss) == 2 ); - assert( li_std_set_StringSet_has(ss, "bar") ); - assert( !li_std_set_StringSet_has(ss, "baz") ); - - li_std_set_StringSet_delete(ss); - } - - return 0; -} diff --git a/Examples/test-suite/c/li_std_string_runme.cxx b/Examples/test-suite/c/li_std_string_runme.cxx deleted file mode 100644 index 05714fc59..000000000 --- a/Examples/test-suite/c/li_std_string_runme.cxx +++ /dev/null @@ -1,26 +0,0 @@ -#include "li_std_string_wrap.h" - -#include - -using namespace li_std_string; - -int main(int argc, const char *argv[]) { - Structure st; - assert( st.MemberString().empty() ); - - st.MemberString("bloordyblop"); - assert( st.MemberString() == "bloordyblop" ); - - assert( st.MemberString2() == "member string 2" ); - - assert( st.ConstMemberString() == "const member string" ); - - st.StaticMemberString(std::string("static bloordyblop")); - assert( st.StaticMemberString() == "static bloordyblop" ); - - assert( Structure::StaticMemberString2() == "static member string 2" ); - assert( Structure::ConstStaticMemberString() == "const static member string" ); - - Foo f; - assert( f.test("1+") == "1+1" ); -} diff --git a/Examples/test-suite/c/li_std_vector_runme.c b/Examples/test-suite/c/li_std_vector_runme.c deleted file mode 100644 index 2e8a36360..000000000 --- a/Examples/test-suite/c/li_std_vector_runme.c +++ /dev/null @@ -1,22 +0,0 @@ -#include "li_std_vector/li_std_vector_wrap.h" -#include - -int main() { - size_t i; - - li_std_vector_IntVector* iv = li_std_vector_IntVector_new(); - assert( li_std_vector_IntVector_size(iv) == 0 ); - - li_std_vector_IntVector_push_back(iv, 1); - li_std_vector_IntVector_push_back(iv, 4); - li_std_vector_IntVector_push_back(iv, 9); - assert( li_std_vector_IntVector_size(iv) == 3 ); - - for ( i = 0; i < 3; i++ ) { - assert( li_std_vector_IntVector_get(iv, i) == (i + 1)*(i + 1) ); - } - - li_std_vector_IntVector_delete(iv); - - return 0; -} diff --git a/Examples/test-suite/c/operator_overload_runme.c b/Examples/test-suite/c/operator_overload_runme.c deleted file mode 100644 index 1dde8ae8f..000000000 --- a/Examples/test-suite/c/operator_overload_runme.c +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include -#include - -#include "operator_overload/operator_overload_wrap.h" - -int main() { - operator_overload_Op_sanity_check(); - - operator_overload_Op *op1 = operator_overload_Op_new_i(1), *op2 = operator_overload_Op_new_i(2), *op3 = operator_overload_Op_copy(op1); - - assert(operator_overload_Op_NotEqual(op1, op2)); - operator_overload_Op_PlusPlusPrefix(op3); - assert(operator_overload_Op_EqualEqual(op2, op3)); - assert(operator_overload_Op_GreaterThanEqual(op2, op1)); - operator_overload_Op_PlusEqual(op3, op1); - assert(operator_overload_Op_LessThan(op1, op2) && operator_overload_Op_LessThan(op2, op3)); - assert(3 == *operator_overload_Op_IndexInto(op3, operator_overload_Op_IndexIntoConst(op2, operator_overload_Op_Functor(op1)))); - assert(5 == operator_overload_Op_Functor_i(op3, 2)); - - operator_overload_Op_delete(op1); - operator_overload_Op_delete(op2); - operator_overload_Op_delete(op3); - exit(0); -} diff --git a/Examples/test-suite/c_backend_cpp_exception.i b/Examples/test-suite/c_backend_cpp_exception.i deleted file mode 100644 index 3b56d91d7..000000000 --- a/Examples/test-suite/c_backend_cpp_exception.i +++ /dev/null @@ -1,25 +0,0 @@ -%module c_backend_cpp_exception - -%exception { - try { - $action - } catch(SomeKnownException) { - checkVal = 1; - } catch(...) { - checkVal = 2; - } -} - -%inline %{ - class SomeKnownException{}; - class SomeUnkownException{}; - int checkVal = 0; - - void throwSomeKnownException(void) { - throw SomeKnownException(); - } - - void throwSomeUnknownException(void) { - throw SomeUnkownException(); - } -%} \ No newline at end of file diff --git a/Examples/test-suite/c_backend_cpp_natural_std_string.i b/Examples/test-suite/c_backend_cpp_natural_std_string.i deleted file mode 100644 index 6bf8e6bd2..000000000 --- a/Examples/test-suite/c_backend_cpp_natural_std_string.i +++ /dev/null @@ -1,13 +0,0 @@ -%module c_backend_cpp_natural_std_string - -%feature ("nspace", "1"); - -%include std_string.i - -%inline %{ - static std::string& myStringAppend(std::string &someString, const std::string &appendedString) - { - someString += appendedString; - return someString; - } -%} \ No newline at end of file diff --git a/Examples/test-suite/cpp11_alternate_function_syntax.i b/Examples/test-suite/cpp11_alternate_function_syntax.i index 5c4e83468..2f5aaa41a 100644 --- a/Examples/test-suite/cpp11_alternate_function_syntax.i +++ b/Examples/test-suite/cpp11_alternate_function_syntax.i @@ -11,10 +11,8 @@ struct SomeStruct { auto addAlternateConst(int x, int y) const -> int; auto addAlternateNoExcept(int x, int y) noexcept -> int; auto addAlternateConstNoExcept(int x, int y) const noexcept -> int; -#ifndef SWIGC auto addAlternateMemberPtrParm(int x, int (SomeStruct::*mp)(int, int)) -> int; auto addAlternateMemberPtrConstParm(int x, int (SomeStruct::*mp)(int, int) const) const -> int; -#endif // !SWIGC // Returning a reference didn't parse in SWIG < 4.1.0 (#231) auto output() -> Hello&; @@ -28,7 +26,6 @@ auto SomeStruct::addAlternate(int x, int y) -> int { return x + y; } auto SomeStruct::addAlternateConst(int x, int y) const -> int { return x + y; } auto SomeStruct::addAlternateNoExcept(int x, int y) noexcept -> int { return x + y; } auto SomeStruct::addAlternateConstNoExcept(int x, int y) const noexcept -> int { return x + y; } -#ifndef SWIGC auto SomeStruct::addAlternateMemberPtrParm(int x, int (SomeStruct::*mp)(int, int)) -> int { return 100*x + (this->*mp)(x, x); } @@ -36,6 +33,5 @@ auto SomeStruct::addAlternateMemberPtrConstParm(int x, int (SomeStruct::*mp)(int return 1000*x + (this->*mp)(x, x); } auto SomeStruct::output() -> Hello& { static Hello h; return h; } -#endif // !SWIGC %} diff --git a/Examples/test-suite/cpp_basic.i b/Examples/test-suite/cpp_basic.i index 9302cfb43..8c31a9cf0 100644 --- a/Examples/test-suite/cpp_basic.i +++ b/Examples/test-suite/cpp_basic.i @@ -31,9 +31,7 @@ class Foo { return -a*num; } -#ifndef SWIGC int (Foo::*func_ptr)(int); -#endif // SWIGC const char* __str__() const { return "Foo"; } }; @@ -102,7 +100,6 @@ Foo Bar::global_fval = Foo(3); %} /* member function tests */ -#ifndef SWIGC %inline %{ int (Foo::*get_func1_ptr())(int) { return &Foo::func1; @@ -117,7 +114,6 @@ int test_func_ptr(Foo *f, int a) { } %} -#endif // SWIGC #ifdef __cplusplus diff --git a/Examples/test-suite/director_smartptr.i b/Examples/test-suite/director_smartptr.i index c6bd9b054..d016af17e 100644 --- a/Examples/test-suite/director_smartptr.i +++ b/Examples/test-suite/director_smartptr.i @@ -34,7 +34,7 @@ public: %} -#if defined(SWIGC) || defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY) +#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY) #define SHARED_PTR_WRAPPERS_IMPLEMENTED #endif diff --git a/Examples/test-suite/dynamic_cast.i b/Examples/test-suite/dynamic_cast.i index e8c39931d..392b3bfd1 100644 --- a/Examples/test-suite/dynamic_cast.i +++ b/Examples/test-suite/dynamic_cast.i @@ -1,7 +1,7 @@ /* File : example.i */ %module dynamic_cast -#if !defined(SWIGJAVA) && !defined(SWIGCSHARP) && !defined(SWIGGO) && !defined(SWIGD) && !defined(SWIGC) +#if !defined(SWIGJAVA) && !defined(SWIGCSHARP) && !defined(SWIGGO) && !defined(SWIGD) %apply SWIGTYPE *DYNAMIC { Foo * }; #endif @@ -17,7 +17,7 @@ public: }; %} -#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGGO) || defined(SWIGD) || defined(SWIGC) +#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGGO) || defined(SWIGD) %typemap(out) Foo *blah { Bar *downcast = dynamic_cast($1); *(Bar **)&$result = downcast; @@ -69,7 +69,7 @@ char *do_test(Bar *b) { } %} -#if !defined(SWIGJAVA) && !defined(SWIGCSHARP) && !defined(SWIGGO) && !defined(SWIGD) && !defined(SWIGC) +#if !defined(SWIGJAVA) && !defined(SWIGCSHARP) && !defined(SWIGGO) && !defined(SWIGD) // A general purpose function for dynamic casting of a Foo * %{ static swig_type_info * diff --git a/Examples/test-suite/functors.i b/Examples/test-suite/functors.i index 39e3078af..363123000 100644 --- a/Examples/test-suite/functors.i +++ b/Examples/test-suite/functors.i @@ -1,7 +1,7 @@ %module functors // Rename operator() only if the language does not already do this by default -#if defined(SWIGC) || defined(SWIGCSHARP) || defined(SWIGGO) || defined(SWIGGUILE) || defined(SWIGJAVA) || defined(SWIGJAVASCRIPT) || defined(SWIGPHP) || defined(SWIGSCILAB) || defined(SWIGTCL) +#if defined(SWIGCSHARP) || defined(SWIGGO) || defined(SWIGGUILE) || defined(SWIGJAVA) || defined(SWIGJAVASCRIPT) || defined(SWIGPHP) || defined(SWIGSCILAB) || defined(SWIGTCL) %rename(Funktor) operator(); #endif diff --git a/Examples/test-suite/import_fragments_a.i b/Examples/test-suite/import_fragments_a.i index 01167baec..1babea95f 100644 --- a/Examples/test-suite/import_fragments_a.i +++ b/Examples/test-suite/import_fragments_a.i @@ -1,5 +1,5 @@ -#if !defined(SWIGC) && !defined(SWIGGO) -// Prevent C/Go from generating a C include/Go module import - this test is not set up as true multiple modules +#if !defined(SWIGGO) +// Prevent Go from generating a Go module import - this test is not set up as true multiple modules %module import_fragments_a #endif diff --git a/Examples/test-suite/kwargs_feature.i b/Examples/test-suite/kwargs_feature.i index b4e7c4d47..5b9418129 100644 --- a/Examples/test-suite/kwargs_feature.i +++ b/Examples/test-suite/kwargs_feature.i @@ -128,8 +128,6 @@ struct ExtendingOptArgs1 {}; struct ExtendingOptArgs2 {}; %} -#ifndef SWIGC - // For strlen/strcpy %{ #include @@ -152,5 +150,3 @@ struct VarargConstructor { } }; %} - -#endif // !SWIGC diff --git a/Examples/test-suite/li_boost_shared_ptr.i b/Examples/test-suite/li_boost_shared_ptr.i index 4e6fbfe06..48d5fc2f1 100644 --- a/Examples/test-suite/li_boost_shared_ptr.i +++ b/Examples/test-suite/li_boost_shared_ptr.i @@ -44,7 +44,7 @@ # define SWIG_SHARED_PTR_NAMESPACE SwigBoost #endif -#if defined(SWIGC) || defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY) || defined(SWIGR) +#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY) || defined(SWIGR) #define SHARED_PTR_WRAPPERS_IMPLEMENTED #endif diff --git a/Examples/test-suite/li_boost_shared_ptr_attribute.i b/Examples/test-suite/li_boost_shared_ptr_attribute.i index c06515359..f15baa693 100644 --- a/Examples/test-suite/li_boost_shared_ptr_attribute.i +++ b/Examples/test-suite/li_boost_shared_ptr_attribute.i @@ -1,6 +1,6 @@ %module li_boost_shared_ptr_attribute -#if defined(SWIGC) || defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY) +#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY) #define SHARED_PTR_WRAPPERS_IMPLEMENTED #endif diff --git a/Examples/test-suite/li_boost_shared_ptr_bits.i b/Examples/test-suite/li_boost_shared_ptr_bits.i index d18b838e4..7cf84010e 100644 --- a/Examples/test-suite/li_boost_shared_ptr_bits.i +++ b/Examples/test-suite/li_boost_shared_ptr_bits.i @@ -1,6 +1,6 @@ %module li_boost_shared_ptr_bits -#if defined(SWIGC) || defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY) +#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY) #define SHARED_PTR_WRAPPERS_IMPLEMENTED #endif diff --git a/Examples/test-suite/li_boost_shared_ptr_director.i b/Examples/test-suite/li_boost_shared_ptr_director.i index 6d1d32708..b2d9fc131 100644 --- a/Examples/test-suite/li_boost_shared_ptr_director.i +++ b/Examples/test-suite/li_boost_shared_ptr_director.i @@ -4,7 +4,7 @@ #include %} -#if defined(SWIGC) || defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY) || defined(SWIGR) +#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY) || defined(SWIGR) #define SHARED_PTR_WRAPPERS_IMPLEMENTED #endif diff --git a/Examples/test-suite/li_boost_shared_ptr_template.i b/Examples/test-suite/li_boost_shared_ptr_template.i index 3e9312877..3965a976e 100644 --- a/Examples/test-suite/li_boost_shared_ptr_template.i +++ b/Examples/test-suite/li_boost_shared_ptr_template.i @@ -30,7 +30,7 @@ %} -#if defined(SWIGC) || defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY) +#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) || defined(SWIGOCTAVE) || defined(SWIGRUBY) #define SHARED_PTR_WRAPPERS_IMPLEMENTED #endif diff --git a/Examples/test-suite/li_std_set.i b/Examples/test-suite/li_std_set.i index a4d2b4b17..507272d8d 100644 --- a/Examples/test-suite/li_std_set.i +++ b/Examples/test-suite/li_std_set.i @@ -22,7 +22,7 @@ %template(set_int) std::multiset; %template(v_int) std::vector; %template(set_string) std::set; -#elif defined(SWIGC) || defined(SWIGJAVA) || defined(SWIGCSHARP) +#elif defined(SWIGJAVA) || defined(SWIGCSHARP) // This operator is only defined because it's needed to store objects of // type Foo in std::set in C++, we don't need to wrap it. %ignore operator<; diff --git a/Examples/test-suite/memberin_extend.i b/Examples/test-suite/memberin_extend.i index 2c051ad3b..43251973f 100644 --- a/Examples/test-suite/memberin_extend.i +++ b/Examples/test-suite/memberin_extend.i @@ -9,20 +9,11 @@ struct ExtendMe { }; %} -// Use different names for the C backend to be consistent with the global prefix used. -%inline { -#ifdef SWIGC -%#define ADD_PREFIX(name) memberin_extend_ ## name -#else -%#define ADD_PREFIX(name) name -#endif -} - %{ #include #include std::map ExtendMeStringMap; -void ADD_PREFIX(ExtendMe_thing_set)(ExtendMe *self, const char *val) { +void ExtendMe_thing_set(ExtendMe *self, const char *val) { char *old_val = ExtendMeStringMap[self]; delete [] old_val; if (val) { @@ -32,7 +23,7 @@ void ADD_PREFIX(ExtendMe_thing_set)(ExtendMe *self, const char *val) { ExtendMeStringMap[self] = 0; } } -char * ADD_PREFIX(ExtendMe_thing_get)(ExtendMe *self) { +char * ExtendMe_thing_get(ExtendMe *self) { return ExtendMeStringMap[self]; } %} diff --git a/Examples/test-suite/namespace_extend.i b/Examples/test-suite/namespace_extend.i index 3f672abee..3c414d1af 100644 --- a/Examples/test-suite/namespace_extend.i +++ b/Examples/test-suite/namespace_extend.i @@ -8,37 +8,16 @@ namespace foo { public: }; } -%} - -// C uses different naming convention, with all functions starting with the class prefix -// and using the global namespace prefix too, if specified (which is the case for the tests). -#ifdef SWIGC -%{ -foo::bar *namespace_extend_foo_bar_new() { - return new foo::bar; -} -void namespace_extend_foo_bar_delete(foo::bar *self) { - delete self; -} - -int namespace_extend_foo_bar_blah(foo::bar *self, int x) { - return x; -} -%} -#else -%{ foo::bar *new_foo_bar() { return new foo::bar; } void delete_foo_bar(foo::bar *self) { delete self; } - int foo_bar_blah(foo::bar *self, int x) { return x; } %} -#endif namespace foo { class bar { diff --git a/Examples/test-suite/namespace_spaces.i b/Examples/test-suite/namespace_spaces.i index a880d7ce7..86b21e221 100644 --- a/Examples/test-suite/namespace_spaces.i +++ b/Examples/test-suite/namespace_spaces.i @@ -16,9 +16,7 @@ public: int blah(int x); int spam(int x); Integer bar(Integer x); -#ifndef SWIGC void (Foo:: *func_ptr) (int); -#endif }; inline Foo :: Foo () {} diff --git a/Examples/test-suite/operator_overload.i b/Examples/test-suite/operator_overload.i index 2ada209c8..ce3454fd9 100644 --- a/Examples/test-suite/operator_overload.i +++ b/Examples/test-suite/operator_overload.i @@ -15,11 +15,6 @@ see bottom for a set of possible tests SWIGWARN_IGNORE_OPERATOR_LOR); #endif -#if defined(SWIGC) -%warnfilter(SWIGWARN_IGNORE_OPERATOR_EQ, - SWIGWARN_IGNORE_OPERATOR_PLUSPLUS); -#endif - #if !defined(SWIGLUA) && !defined(SWIGR) %rename(Equal) operator =; %rename(PlusEqual) operator +=; diff --git a/Examples/test-suite/special_variables.i b/Examples/test-suite/special_variables.i index a95e288d8..aa1db0461 100644 --- a/Examples/test-suite/special_variables.i +++ b/Examples/test-suite/special_variables.i @@ -27,19 +27,6 @@ std::string ExceptionVars(double i, double j) { %} %rename(ExceptionVars) Space::exceptionvars; - -#ifdef SWIGC - -%exception Space::exceptionvars %{ - $action - result = (char*)$symname(1.0,2.0).c_str(); // Should expand to ExceptionVars - result = (char*)$name(3.0,4.0).c_str(); // Should expand to Space::exceptionvars - // above will not compile if the variables are not expanded properly - result = (char*)"$action $name $symname $overname $wrapname"; -%} - -#else - %exception Space::exceptionvars %{ $action result = $symname(1.0,2.0); // Should expand to ExceptionVars @@ -47,9 +34,6 @@ std::string ExceptionVars(double i, double j) { // above will not compile if the variables are not expanded properly result = "$action $name $symname $overname $wrapname $parentclassname $parentclasssymname"; %} - -#endif - %inline %{ namespace Space { std::string exceptionvars(double i, double j) { @@ -59,20 +43,6 @@ std::string exceptionvars(double i, double j) { %} -#ifdef SWIGC - -%exception Space::overloadedmethod %{ - $action - result = (char*)Space::$symname(1.0).c_str(); - result = (char*)$name().c_str(); - result = (char*)$name(2.0).c_str(); - // above will not compile if the variables are not expanded properly - result = (char*)"$action $name $symname $overname $wrapname"; - // $decl -%} - -#else - %exception Space::overloadedmethod %{ $action result = Space::$symname(1.0); @@ -83,8 +53,6 @@ std::string exceptionvars(double i, double j) { // $decl %} -#endif - %inline %{ namespace Space { std::string overloadedmethod(double j) { diff --git a/Examples/test-suite/stl_no_default_constructor.i b/Examples/test-suite/stl_no_default_constructor.i index e2d475b34..32aff2b46 100644 --- a/Examples/test-suite/stl_no_default_constructor.i +++ b/Examples/test-suite/stl_no_default_constructor.i @@ -9,7 +9,7 @@ struct NoDefaultCtor { }; %} -#if defined(SWIGC) || defined(SWIGCSHARP) || defined(SWIGJAVA) || defined(SWIGD) +#if defined(SWIGCSHARP) || defined(SWIGJAVA) || defined(SWIGD) %template(VectorNoDefaultCtor) std::vector; #endif diff --git a/Lib/c/boost_shared_ptr.i b/Lib/c/boost_shared_ptr.i deleted file mode 100644 index bf4e0959c..000000000 --- a/Lib/c/boost_shared_ptr.i +++ /dev/null @@ -1,5 +0,0 @@ -#ifndef SWIG_SHARED_PTR_NAMESPACE -#define SWIG_SHARED_PTR_NAMESPACE boost -#endif - -%include diff --git a/Lib/c/c.swg b/Lib/c/c.swg deleted file mode 100644 index 806ca5f11..000000000 --- a/Lib/c/c.swg +++ /dev/null @@ -1,359 +0,0 @@ -/* ----------------------------------------------------------------------------- - * See the LICENSE file for information on copyright, usage and redistribution - * of SWIG, and the README file for authors - http://www.swig.org/release.html. - * - * c.swg - * ----------------------------------------------------------------------------- */ - -%include - -%insert("runtime") "clabels.swg" - -%insert("runtime") %{ -#include -#include -#include -#include - -#define SWIG_contract_assert(expr, msg) if(!(expr)) { printf("%s\n", msg); SWIG_exit(0); } else -%} - -%fragment("stdbool_inc", "cheader") {#include } - -%define same_macro_all_primitive_types_but_void(macro_name, TM) -macro_name(TM, short); -macro_name(TM, unsigned short); -macro_name(TM, int); -macro_name(TM, unsigned int); -macro_name(TM, long); -macro_name(TM, unsigned long); -macro_name(TM, long long); -macro_name(TM, unsigned long long); -macro_name(TM, char); -macro_name(TM, signed char); -macro_name(TM, unsigned char); -macro_name(TM, float); -macro_name(TM, double); -macro_name(TM, size_t); -%enddef - -// This is used to handle all primitive types as just themselves. -// This macro doesn't cover const references, use either cref_as_value or -// cref_as_ptr below in addition to it. -// Notice that const pointers are mapped to non-const ones as we need to -// declare variables of this type when it's used as a return type, and top -// level const doesn't matter anyhow in the function declarations. -%define same_type(TM, T) -%typemap(TM) T, const T "T" -%typemap(TM) T*, T&, T[ANY], T[] "T *" -%typemap(TM) const T*, const T[ANY], const T[] "const T *" -%typemap(TM) T**, T*&, T*[ANY], T[ANY][ANY] "T **" -%typemap(TM) const T**, const T*&, T *const &, const T*[ANY], const T[ANY][ANY] "const T **" -// constant pointers -%typemap(TM) T * const "T *" -%typemap(TM) T* * const "T* *" -%typemap(TM) const T* * const "const T* *" -%enddef - -%define cref_as_value(TM, T) -%typemap(TM) const T& "T" -%enddef - -%define cref_as_ptr(TM, T) -%typemap(TM) const T& "T *" -%enddef - -%define same_type_all_primitive_types_but_void(TM) -%enddef - -//Used by 'in' and 'out' typemaps -%define same_action(TM, T, ACTION, ACTION_CREF) -%typemap(TM) T, const T ACTION -%typemap(TM) const T& ACTION_CREF -%typemap(TM) T*, T&, T[ANY], T[] ACTION -%typemap(TM) const T*, const T[ANY], const T[] ACTION -%typemap(TM) T**, T*&, T*[ANY], T[ANY][ANY] ACTION -%typemap(TM) const T**, const T*&, const T*[ANY], const T[ANY][ANY] ACTION -// constant pointers -%typemap(TM) T * const ACTION -%typemap(TM) T* * const ACTION -%typemap(TM) const T* * const ACTION -%enddef - -%define same_action_all_primitive_types(TM, ACTION, ACTION_CREF) -same_action(TM, short, ACTION, ACTION_CREF); -same_action(TM, unsigned short, ACTION, ACTION_CREF); -same_action(TM, int, ACTION, ACTION_CREF); -same_action(TM, unsigned int, ACTION, ACTION_CREF); -same_action(TM, long, ACTION, ACTION_CREF); -same_action(TM, unsigned long, ACTION, ACTION_CREF); -same_action(TM, long long, ACTION, ACTION_CREF); -same_action(TM, unsigned long long, ACTION, ACTION_CREF); -same_action(TM, char, ACTION, ACTION_CREF); -same_action(TM, signed char, ACTION, ACTION_CREF); -same_action(TM, unsigned char, ACTION, ACTION_CREF); -//unsigned only -same_action(TM, float, ACTION, ACTION_CREF); -same_action(TM, double, ACTION, ACTION_CREF); -same_action(TM, size_t, ACTION, ACTION_CREF); -%typemap(TM) void*, void const* ACTION -%enddef - -// "ctype" is the type used with C wrapper functions. -// void -%typemap(ctype) void "void" -%typemap(ctype) void*, void& "void *" -%typemap(ctype) const void&, const void* "const void *" -%typemap(ctype) void**, void*& "void **" -%typemap(ctype) const void**, const void*& "const void **" -// constant pointers -%typemap(ctype) void* * const "void* * const" -%typemap(ctype) const void* * const "const void* * const" - -same_macro_all_primitive_types_but_void(same_type,ctype); -same_macro_all_primitive_types_but_void(cref_as_value,ctype); - -// trivial typemap for arrays of void pointers to avoid applying the object typemaps to them -%typemap(ctype) void*[ANY] "void **" - -// objects -%typemap(ctype) SWIGTYPE "$&resolved_type*" -%typemap(ctype) SWIGTYPE * "$resolved_type*" -%typemap(ctype) SWIGTYPE * const & "$resolved_type*" -%typemap(ctype) SWIGTYPE & "$*resolved_type*" -%typemap(ctype) SWIGTYPE [ANY] "$resolved_type*" -%typemap(ctype) SWIGTYPE * [ANY] "$resolved_type**" - -// enums -%typemap(ctype) enum SWIGTYPE "$resolved_type" -%typemap(ctype) enum SWIGTYPE * "$resolved_type*" -%typemap(ctype) enum SWIGTYPE & "$*resolved_type*" -%typemap(ctype) enum SWIGTYPE [ANY] "$resolved_type*" - -%typemap(ctype, fragment="stdbool_inc") bool, const bool, const bool & "bool" -%typemap(ctype, fragment="stdbool_inc") bool *, const bool *, bool & "bool *" - -// Typemaps for assigning wrapper parameters to local variables -same_action_all_primitive_types(in, "$1 = ($1_ltype) $input;", "$1 = &$input;") - -%typemap(in) short [ANY], int [ANY], long [ANY], long long [ANY], char [ANY], float [ANY], double [ANY], unsigned char [ANY] "$1 = ($1_basetype *) $input;" -%typemap(in) short * [ANY], int * [ANY], long * [ANY], long long * [ANY], char * [ANY], float * [ANY], double * [ANY] "$1 = ($1_basetype *) $input;" - -%typemap(in, fragment="stdbool_inc") bool, bool *, bool **, const bool, const bool * "$1 = ($1_ltype) $input;" -%typemap(in, fragment="stdbool_inc") bool & "$1 = ($1_basetype *) $input;" -%typemap(in, fragment="stdbool_inc") const bool &, const bool * "$1 = ($1_basetype *) $input;" - -%typemap(in) enum SWIGTYPE "$1 = ($1_ltype) $input;" -%typemap(in) enum SWIGTYPE &,enum SWIGTYPE * "$1 = ($1_ltype) $input;" - -%typemap(in) SWIGTYPE [] "$1 = ($1_ltype) $input;" -%typemap(in) SWIGTYPE ((&)[ANY]) "$1 = ($1_ltype) $input;" - -%typemap(in) SWIGTYPE (CLASS::*) { - if ($input) - $1 = *($&1_ltype) &$input; -} - -%typemap(in) SWIGTYPE "$1 = *($1_ltype *)$input;" - -%typemap(in) SWIGTYPE * "$1 = ($1_ltype) $input;" - -%typemap(in) SWIGTYPE *[ANY] { - if ($input) { - $1 = ($1_ltype) malloc($1_dim0 * sizeof($1_basetype)); - size_t i = 0; - for ( ; i < $1_dim0; ++i) - if ($input[i]) - $1[i] = ($*1_ltype) $input[i]; - else - $1[i] = ($*1_ltype) 0; - } - else - $1 = ($1_ltype) 0; -} - -%typemap(in) SWIGTYPE [ANY][ANY] { - if ($input) { - $1 = ($1_ltype) malloc($1_dim0 * $1_dim1 * sizeof($1_basetype)); - size_t i = 0, j = 0; - for ( ; i < $1_dim0; ++i) { - for ( ; j < $1_dim1; ++j) { - if ($input[i][j]) - $1[i][j] = * ($*1_ltype) $input[i][j]; - else - $1[i][j] = * ($*1_ltype) 0; - } - } - } - else - $1 = ($1_ltype) 0; -} - -%typemap(freearg) SWIGTYPE * [ANY], SWIGTYPE * [ANY][ANY] { - if ($input) - free($input); -} - -%typemap(in) SWIGTYPE & %{ - $1 = ($1_ltype) $input; -%} - -// Typemaps for assigning result values to a special return variable -same_action_all_primitive_types(out, "$result = $1;", "$result = *$1;") - -%typemap(out) void "" - -%typemap(out, fragment="stdbool_inc") bool, bool *, const bool, const bool * "$result = ($1_ltype) $1;" -%typemap(out, fragment="stdbool_inc") bool &, const bool & "$result = $1;" - -%typemap(out) enum SWIGTYPE "$result = (int) $1;" -%typemap(out) enum SWIGTYPE &, enum SWIGTYPE * "$result = $1;" - -%typemap(out) SWIGTYPE (CLASS::*) { - *($&1_ltype) &$result = $1; -} - -%typemap(out) SWIGTYPE "$result = (SwigObj*)new $1_ltype($1);" - -%typemap(out) SWIGTYPE *, SWIGTYPE & "$result = (SwigObj*) $1;" - -%typemap(out) SWIGTYPE * [ANY], SWIGTYPE [ANY][ANY] { - static SwigObj **_temp = 0; - if ($1) { - size_t i = 0; - if (_temp) { - for ( ; i < $1_dim0; ++i) - delete ($1_ltype *)_temp[i]; - free(_temp); - } - _temp = (SwigObj**) malloc($1_dim0 * sizeof(SwigObj*)); - for (i = 0 ; i < $1_dim0; ++i) { - if ($1[i]) { - _temp[i] = $1[i]; - } - else - _temp[i] = (SwigObj*) 0; - } - $result = ($1_ltype) _temp; - } - else - $result = ($1_ltype) 0; -} - -/* Typecheck typemaps - The purpose of these is merely to issue a warning for overloaded C++ functions - * that cannot be overloaded in the wrappers as more than one C++ type maps to a single C type */ - -%typecheck(SWIG_TYPECHECK_BOOL) - bool, - const bool & - "" - -%typecheck(SWIG_TYPECHECK_CHAR) - char, - const char & - "" - -%typecheck(SWIG_TYPECHECK_INT8) - signed char, - const signed char & - "" - -%typecheck(SWIG_TYPECHECK_UINT8) - unsigned char, - const unsigned char & - "" - -%typecheck(SWIG_TYPECHECK_INT16) - short, - const short & - "" - -%typecheck(SWIG_TYPECHECK_UINT16) - unsigned short, - const unsigned short & - "" - -%typecheck(SWIG_TYPECHECK_INT32) - int, - long, - const int &, - const long & - "" - -%typecheck(SWIG_TYPECHECK_UINT32) - unsigned int, - unsigned long, - const unsigned int &, - const unsigned long & - "" - -%typecheck(SWIG_TYPECHECK_INT64) - long long, - const long long & - "" - -%typecheck(SWIG_TYPECHECK_UINT64) - unsigned long long, - const unsigned long long & - "" - -%typecheck(SWIG_TYPECHECK_FLOAT) - float, - const float & - "" - -%typecheck(SWIG_TYPECHECK_DOUBLE) - double, - const double & - "" - -%typecheck(SWIG_TYPECHECK_STRING) - char *, - char *&, - char[ANY], - char[] - "" - -%typecheck(SWIG_TYPECHECK_POINTER) - SWIGTYPE, - SWIGTYPE *, - SWIGTYPE &, - SWIGTYPE &&, - SWIGTYPE *const&, - SWIGTYPE [], - SWIGTYPE (CLASS::*) - "" - -#ifdef SWIG_CPPMODE - -%insert("runtime") %{ -typedef struct SwigObj SwigObj; -%} - -%insert("cheader") %{ -typedef struct SwigObj SwigObj; -%} - -#endif // SWIG_CPPMODE - -#ifdef SWIG_C_EXCEPT -%include "cexcept.swg" -#else // !SWIG_C_EXCEPT -// Still define the macro used in some standard typemaps, but we can't -// implement it in C, so just allow the user predefining their own version. -%insert("runtime") %{ -#ifndef SWIG_exception -#define SWIG_exception(code, msg) -#endif -%} -#endif // SWIG_C_EXCEPT/!SWIG_C_EXCEPT - -%insert("runtime") %{ -#ifdef __cplusplus -extern "C" { -#endif -SWIGEXPORTC int SWIG_exit(int code) { exit(code); } -#ifdef __cplusplus -} -#endif -%} diff --git a/Lib/c/cexcept.swg b/Lib/c/cexcept.swg deleted file mode 100644 index 57171273d..000000000 --- a/Lib/c/cexcept.swg +++ /dev/null @@ -1,109 +0,0 @@ -/* ----------------------------------------------------------------------------- - * clabels.swg - * - * Exception handling code and typemaps for C module. - * ----------------------------------------------------------------------------- */ - -// This function is special: it's used by various typemaps (via SWIG_exception -// macro below) and needs to be defined, but we don't want to export it. -%ignore SWIG_CException_Raise; -%{ -extern "C" void SWIG_CException_Raise(int code, const char* msg); -%} - -// This class is special too because its name is used in c.cxx source. It is -// only defined if the code there didn't predefine SWIG_CException_DEFINED -// because the class is already defined in another module. -// -// It has to be seen by SWIG because we want to generate wrappers for its -// public functions to be able to use it from the application code. -%inline %{ -#ifndef SWIG_CException_DEFINED -class SWIG_CException { -public: - SWIG_CException(const SWIG_CException& ex) throw() : code(ex.code), msg(strdup(ex.msg)) { } - ~SWIG_CException() { free(const_cast(msg)); } - - const int code; - const char* const msg; - - static SWIG_CException* get_pending() throw() { - return PendingException; - } - - static void reset_pending() throw() { - if (PendingException) { - delete PendingException; - PendingException = 0; - } - } - -private: - friend void SWIG_CException_Raise(int code, const char* msg); - - static thread_local SWIG_CException* PendingException; - - SWIG_CException(int code, const char* msg) : code(code), msg(strdup(msg)) { } - - SWIG_CException& operator=(const SWIG_CException& ex); -}; -#endif // SWIG_CException_DEFINED -%} - -// This part is implementation only and doesn't need to be seen by SWIG. -%{ -#ifndef SWIG_CException_DEFINED -thread_local SWIG_CException *SWIG_CException::PendingException = 0; - -SWIGEXPORTC void SWIG_CException_Raise(int code, const char* msg) { - delete SWIG_CException::PendingException; - SWIG_CException::PendingException = new SWIG_CException(code, msg); -} -#endif // SWIG_CException_DEFINED -%} - -#ifdef SWIG_CXX_WRAPPERS - -// This is somewhat of a hack, but our generated header may include another -// generated header, when using multiple modules, and defining swig_check() in -// all of them would result in errors, so we use SWIG_swig_check_DEFINED to -// prevent this from happening. -// -// This also has a nice side effect of allowing the user code to predefine this -// symbol and provide their own SWIG_swig_check_DEFINED implementation to -// customize exception handling. -%insert("cxxcode") %{ -#ifndef SWIG_swig_check_DEFINED -#define SWIG_swig_check_DEFINED 1 - -inline void swig_check() { - if (SWIG_CException* swig_ex = SWIG_CException::get_pending()) { - SWIG_CException swig_ex_copy{*swig_ex}; - delete swig_ex; - SWIG_CException::reset_pending(); - throw swig_ex_copy; - } -} - -template T swig_check(T x) { - swig_check(); - return x; -} - -#endif // SWIG_swig_check_DEFINED -%} - -#endif // SWIG_CXX_WRAPPERS - -%insert("runtime") "swigerrors.swg" - -#define SWIG_exception(code, msg)\ - SWIG_CException_Raise(code, msg) - -%typemap(throws, noblock="1") char *, const char * { - SWIG_exception(SWIG_RuntimeError, $1); -} - -%typemap(throws, noblock="1") SWIGTYPE { - SWIG_exception(SWIG_UnknownError, "exception of type $1_type"); -} diff --git a/Lib/c/cheader.swg b/Lib/c/cheader.swg deleted file mode 100644 index c162a8260..000000000 --- a/Lib/c/cheader.swg +++ /dev/null @@ -1,20 +0,0 @@ -/* ----------------------------------------------------------------------------- - * cheader.swg - * ----------------------------------------------------------------------------- */ - -%insert("cheader") %{ -#ifndef SWIGIMPORT -# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) -# if defined(STATIC_LINKED) -# define SWIGDLLIMPORT -# else -# define SWIGDLLIMPORT __declspec(dllimport) -# endif -# else -# define SWIGDLLIMPORT -# endif -# define SWIGIMPORT extern SWIGDLLIMPORT -#endif - -#include -%} diff --git a/Lib/c/clabels.swg b/Lib/c/clabels.swg deleted file mode 100644 index ce4bcd02d..000000000 --- a/Lib/c/clabels.swg +++ /dev/null @@ -1,19 +0,0 @@ -/* ----------------------------------------------------------------------------- - * clabels.swg - * - * Definitions of C specific preprocessor symbols. - * ----------------------------------------------------------------------------- */ - -// this is used instead of default SWIGEXPORT symbol - -#ifndef SWIGEXPORTC -# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) || defined(__APPLE__) -# define SWIGEXPORTC -# else -# if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY) -# define SWIGEXPORTC __attribute__ ((visibility("default"))) -# else -# define SWIGEXPORTC -# endif -# endif -#endif diff --git a/Lib/c/std_common.i b/Lib/c/std_common.i deleted file mode 100644 index c21a2e564..000000000 --- a/Lib/c/std_common.i +++ /dev/null @@ -1,4 +0,0 @@ -%include - -%apply size_t { std::size_t }; -%apply const size_t& { const std::size_t & }; diff --git a/Lib/c/std_except.i b/Lib/c/std_except.i deleted file mode 100644 index cc5a7fca2..000000000 --- a/Lib/c/std_except.i +++ /dev/null @@ -1,20 +0,0 @@ -/* ----------------------------------------------------------------------------- - * See the LICENSE file for information on copyright, usage and redistribution - * of SWIG, and the README file for authors - http://www.swig.org/release.html. - * - * std_except.i - * - * Typemaps used by the STL wrappers that throw exceptions. - * These typemaps are used when methods are declared with an STL exception specification, such as - * size_t at() const throw (std::out_of_range); - * ----------------------------------------------------------------------------- */ - -%{ -#include -%} - -namespace std -{ - %ignore exception; - struct exception {}; -} diff --git a/Lib/c/std_map.i b/Lib/c/std_map.i deleted file mode 100644 index 42d620827..000000000 --- a/Lib/c/std_map.i +++ /dev/null @@ -1,61 +0,0 @@ -/* ----------------------------------------------------------------------------- - * std_map.i - * - * SWIG typemaps for std::map - * ----------------------------------------------------------------------------- */ - -%include - -// ------------------------------------------------------------------------ -// std::map -// ------------------------------------------------------------------------ - -%{ -#include -#include -%} - -namespace std { - template > class map { - public: - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef K key_type; - typedef T mapped_type; - typedef std::pair< const K, T > value_type; - typedef value_type* pointer; - typedef const value_type* const_pointer; - typedef value_type& reference; - typedef const value_type& const_reference; - - map(); - map(const map& other); - - size_t size() const; - bool empty() const; - void clear(); - %extend { - const T& get(const K& key) throw (std::out_of_range) { - std::map< K, T, C >::iterator i = self->find(key); - if (i != self->end()) - return i->second; - else - throw std::out_of_range("key not found"); - } - void set(const K& key, const T& x) { - (*self)[key] = x; - } - void del(const K& key) throw (std::out_of_range) { - std::map< K, T, C >::iterator i = self->find(key); - if (i != self->end()) - self->erase(i); - else - throw std::out_of_range("key not found"); - } - bool has_key(const K& key) const { - std::map< K, T, C >::const_iterator i = self->find(key); - return i != self->end(); - } - } - }; -} diff --git a/Lib/c/std_pair.i b/Lib/c/std_pair.i deleted file mode 100644 index f6e1c7c81..000000000 --- a/Lib/c/std_pair.i +++ /dev/null @@ -1,24 +0,0 @@ -%{ -#include -%} - -// Ideal, especially for the simple/primitive types, would be to represent -// pair as a C struct with the 2 fields, but for now we use the simplest -// possible implementation, with the accessor functions required to work with -// the fields. - -namespace std { - template struct pair { - typedef T first_type; - typedef U second_type; - - pair(); - pair(T first, U second); - pair(const pair& other); - - template pair(const pair &other); - - T first; - U second; - }; -} diff --git a/Lib/c/std_set.i b/Lib/c/std_set.i deleted file mode 100644 index 1127a0a50..000000000 --- a/Lib/c/std_set.i +++ /dev/null @@ -1,48 +0,0 @@ -/* ----------------------------------------------------------------------------- - * std_set.i - * - * SWIG typesets for std::set - * ----------------------------------------------------------------------------- */ - -%include - -// ------------------------------------------------------------------------ -// std::set -// ------------------------------------------------------------------------ - -%{ -#include -#include -%} - -namespace std { - template class set { - public: - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef T key_type; - typedef T value_type; - typedef value_type* pointer; - typedef const value_type* const_pointer; - typedef value_type& reference; - typedef const value_type& const_reference; - - set(); - set(const set& other); - - size_t size() const; - bool empty() const; - void clear(); - %extend { - bool add(const T& item) { - return self->insert(item).second; - } - bool del(const T& item) { - return self->erase(item) != 0; - } - bool has(const T& item) const { - return self->count(item) != 0; - } - } - }; -} diff --git a/Lib/c/std_shared_ptr.i b/Lib/c/std_shared_ptr.i deleted file mode 100644 index d2049f5f9..000000000 --- a/Lib/c/std_shared_ptr.i +++ /dev/null @@ -1,84 +0,0 @@ -// This could be predefined in e.g. our own boost_shared_ptr.i -#ifndef SWIG_SHARED_PTR_NAMESPACE -#define SWIG_SHARED_PTR_NAMESPACE std -#endif - -%define SWIG_SHARED_PTR_TYPEMAPS(CONST, TYPE...) - -%naturalvar TYPE; -%naturalvar SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >; - -// Replace the default "delete arg1" with the code destroying the smart pointer itself instead. -%feature("unref") TYPE "(void)arg1; delete smartarg1;" - -// All smart pointers look like normal objects to the code using the interface. -%typemap(ctype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >, - SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >&, - SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >* - "$typemap(ctype, TYPE)"; - -// Typemap for smart pointer type itself: these are somewhat special because we represent empty shared pointers as null pointers at C level because there is -// no advantage in using a non-null pointer in this case, while testing for NULL is much simpler than testing whether a shared pointer is empty. -%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > empty) %{ - $1 = $input ? *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr*)$input : empty; %} - -%typemap(in) const SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >& (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > empty) %{ - $1 = $input ? (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr*)$input : ∅ %} - -// Note that "&" here is required because "$1" ends up being SwigValueWrapper and not the shared pointer itself. This is wrong and should be fixed by disabling -// the use of SwigValueWrapper for shared pointers entirely, as it's never needed for them. -%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > %{ $result = (&$1 ? new $1_ltype($1) : 0); %} - -// Use of "*" here is due to the fact that "$1" is a pointer, but we want to test the smart pointer itself. -%typemap(out) const SWIG_SHARED_PTR_QNAMESPACE::shared_ptr& %{ $result = (*$1 ? $1 : 0); %} - -// And for the plain type. -%typemap(in) CONST TYPE (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{ - smartarg = (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr *)$input; - if (!smartarg || !smartarg->get()) { - SWIG_exception(SWIG_RuntimeError, "$1_type value is null"); - return $null; - } - $1 = **smartarg;%} -%typemap(out) CONST TYPE %{ - $result = (SwigObj*) new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr(new $1_ltype($1));%} - -// Plain type pointer. -%typemap(in) CONST TYPE * (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{ - smartarg = (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr *)$input; - $1 = (TYPE *)(smartarg ? smartarg->get() : 0);%} -%typemap(out, fragment="SWIG_null_deleter") CONST TYPE * %{ - $result = $1 ? (SwigObj*) new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr($1 SWIG_NO_NULL_DELETER_$owner) : 0;%} - -// Plain type references. -%typemap(in) CONST TYPE & (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{ - smartarg = (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr *)$input; - if (!smartarg || !smartarg->get()) { - SWIG_exception(SWIG_RuntimeError, "$1_type reference is null"); - return $null; - } - $1 = (TYPE *)smartarg->get();%} -%typemap(out, fragment="SWIG_null_deleter") CONST TYPE & %{ - $result = (SwigObj*) new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr($1 SWIG_NO_NULL_DELETER_$owner);%} - -// Allow creating null shared pointers and testing them for validity. -%typemap(cxxcode) TYPE %{ - static $cxxclassname null() { return $cxxclassname{($cclassptrname)nullptr, false}; } - explicit operator bool() const { return swig_self_ != nullptr; } -%} - -// This is required to handle overloads on shared_ptr/normal type correctly. -%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER, equivalent="TYPE *") - TYPE CONST, - TYPE CONST &, - TYPE CONST *, - TYPE *CONST&, - SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >, - SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &, - SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *, - SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& - "" - -%enddef - -%include diff --git a/Lib/c/std_string.i b/Lib/c/std_string.i deleted file mode 100644 index e97cad5f3..000000000 --- a/Lib/c/std_string.i +++ /dev/null @@ -1,90 +0,0 @@ -%{ -#include -%} - -%fragment("SwigStrInOut", "header") { -class SwigStrInOut { - std::string str_; - char* ptr_; - size_t len_; -public: - void init(char* ptr) { - ptr_ = ptr; - if (ptr_) { - str_ = ptr_; - len_ = str_.length(); - } - } - - std::string* str() { return &str_; } - - ~SwigStrInOut() { - if (ptr_) { - memcpy(ptr_, str_.c_str(), len_); - ptr_[len_] = '\0'; - } - } -}; -} - -%fragment("include_string", "cxxheader") %{ -#include -%} - -namespace std { - -// use "const string &" typemaps for wrapping member strings -%naturalvar string; - -class string; - -%typemap(ctype) string, const string & "const char *" -%typemap(ctype) string * "char *" -%typemap(ctype) string & "char *" - -%typemap(in) string %{ - if ($input) - $1 = $input; -%} - -%typemap(in) const string & (std::string temp) %{ - if ($input) - temp = $input; - $1 = &temp; -%} - -%typemap(in, fragment="SwigStrInOut") string * (SwigStrInOut temp), string & (SwigStrInOut temp) %{ - temp.init($input); - $1 = temp.str(); -%} - -// Note that we don't support strings with embedded NULs, as there is no way to -// return their length to C code anyhow. -%typemap(out) string %{ - $result = strdup(cppresult.c_str()); -%} - -%typemap(out) const string &, string *, string & %{ - $result = strdup(cppresult->c_str()); -%} - -// This is required to warn about clashes between the overloaded functions -// taking strings and raw pointers in the generated wrappers. -%typemap(typecheck) string, const string &, string *, string & = char *; - - -// Define typemaps for wrapping strings back into std::string in C++ wrappers -// and accepting strings directly. - -%typemap(cxxintype, fragment="include_string") string, const string & "std::string const&" - -%typemap(cxxin) string, const string & "$1.c_str()" - -%typemap(cxxouttype, fragment="include_string") string, const string & "std::string" - -%typemap(cxxout, noblock="1") string, const string & %{ - $result = std::string($cresult); - free(const_cast($cresult)); -%} - -} diff --git a/Lib/c/std_vector.i b/Lib/c/std_vector.i deleted file mode 100644 index 070814a15..000000000 --- a/Lib/c/std_vector.i +++ /dev/null @@ -1,91 +0,0 @@ -/* ----------------------------------------------------------------------------- - * std_vector.i - * - * SWIG typemaps for std::vector - * ----------------------------------------------------------------------------- */ - -%include - -%{ -#include -#include -%} - -namespace std { - - template class vector { - public: - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef T value_type; - typedef value_type* pointer; - typedef const value_type* const_pointer; - typedef value_type& reference; - typedef const value_type& const_reference; - - vector(); - vector(const vector& other); - - size_type size() const; - size_type capacity() const; - void reserve(size_type n); - bool empty() const; - void clear(); - void push_back(const value_type& x); - %extend { - const_reference get(int i) throw (std::out_of_range) { - int size = int(self->size()); - if (i>=0 && isize()); - if (i>=0 && i class vector { - public: - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef bool value_type; - typedef value_type* pointer; - typedef const value_type* const_pointer; - typedef value_type& reference; - typedef bool const_reference; - - vector(); - vector(size_type n); - vector(const vector& other); - - size_type size() const; - size_type capacity() const; - void reserve(size_type n); - bool empty() const; - void clear(); - void push_back(bool x); - %extend { - bool get(int i) throw (std::out_of_range) { - int size = int(self->size()); - if (i>=0 && isize()); - if (i>=0 && i -%include -%include -%include -%include diff --git a/Lib/c/typemaps.i b/Lib/c/typemaps.i deleted file mode 100644 index 10407cd21..000000000 --- a/Lib/c/typemaps.i +++ /dev/null @@ -1,12 +0,0 @@ -/* ----------------------------------------------------------------------------- - * See the LICENSE file for information on copyright, usage and redistribution - * of SWIG, and the README file for authors - http://www.swig.org/release.html. - * - * typemaps.i - * - * Pointer handling - * These mappings provide support for input/output arguments and common - * uses for C/C++ pointers. - * ----------------------------------------------------------------------------- */ - -%include diff --git a/Lib/cdata.i b/Lib/cdata.i index ffd712d34..8736de1c2 100644 --- a/Lib/cdata.i +++ b/Lib/cdata.i @@ -23,28 +23,6 @@ typedef struct SWIGCDATA { } %typemap(in) (const void *indata, int inlen) = (char *STRING, int LENGTH); -#elif SWIGC - -%insert("cheader") { -typedef struct SWIGCDATA { - char *data; - int len; -} SWIGCDATA; -} - -%typemap(ctype) SWIGCDATA "SWIGCDATA" -%typemap(cppouttype) SWIGCDATA "SWIGCDATA" - -%typemap(out) SWIGCDATA { - $result = $1; -} - -%typemap(ctype) (const void *indata, int inlen) "const SWIGCDATA*" -%typemap(in) (const void *indata, int inlen) { - $1 = $input->data; - $2 = $input->len; -} - #elif SWIGPHP %typemap(out) SWIGCDATA { diff --git a/Makefile.in b/Makefile.in index 3e7232b25..3e8f93d19 100644 --- a/Makefile.in +++ b/Makefile.in @@ -72,7 +72,6 @@ skip-perl5 = test -n "@SKIP_PERL5@" skip-php = test -n "@SKIP_PHP@" skip-python = test -n "@SKIP_PYTHON@" skip-r = test -n "@SKIP_R@" -skip-c = test -n "@SKIP_C@" skip-ruby = test -n "@SKIP_RUBY@" skip-scilab = test -n "@SKIP_SCILAB@" skip-tcl = test -n "@SKIP_TCL@" @@ -114,7 +113,6 @@ check-aliveness: @$(skip-php) || ./$(TARGET) -php7 -help @$(skip-python) || ./$(TARGET) -python -help @$(skip-r) || ./$(TARGET) -r -help - @$(skip-c) || ./$(TARGET) -c -help @$(skip-ruby) || ./$(TARGET) -ruby -help @$(skip-scilab) || ./$(TARGET) -scilab -help @$(skip-tcl) || ./$(TARGET) -tcl -help @@ -173,7 +171,6 @@ check-examples: \ check-php-examples \ check-python-examples \ check-r-examples \ - check-c-examples \ check-ruby-examples \ check-scilab-examples \ check-tcl-examples \ @@ -193,7 +190,6 @@ perl5_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/perl5/check.list) php_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/php/check.list) python_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/python/check.list) r_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/r/check.list) -c_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/c/check.list) ruby_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/ruby/check.list) scilab_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/scilab/check.list) tcl_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/tcl/check.list) @@ -235,7 +231,6 @@ check-test-suite: \ check-php-test-suite \ check-python-test-suite \ check-r-test-suite \ - check-c-test-suite \ check-ruby-test-suite \ check-scilab-test-suite \ check-tcl-test-suite \ @@ -283,7 +278,6 @@ all-test-suite: \ all-php-test-suite \ all-python-test-suite \ all-r-test-suite \ - all-c-test-suite \ all-ruby-test-suite \ all-scilab-test-suite \ all-tcl-test-suite \ @@ -307,12 +301,8 @@ broken-test-suite: \ broken-php-test-suite \ broken-python-test-suite \ broken-r-test-suite \ - broken-c-test-suite \ - broken-scilab-test-suite \ - broken-go-test-suite \ - broken-d-test-suite \ - broken-javascript-test-suite broken-ruby-test-suite \ + broken-scilab-test-suite \ broken-tcl-test-suite \ broken-%-test-suite: @@ -445,7 +435,7 @@ install-main: @$(INSTALL_PROGRAM) $(TARGET) $(DESTDIR)$(BIN_DIR)/`echo $(TARGET_NOEXE) | sed '$(transform)'`@EXEEXT@ lib-languages = typemaps tcl perl5 python guile java mzscheme ruby php ocaml octave \ - csharp lua r c go d javascript javascript/jsc \ + csharp lua r go d javascript javascript/jsc \ javascript/v8 scilab xml lib-modules = std diff --git a/Source/Include/swigwarn.h b/Source/Include/swigwarn.h index f9eca2813..f9be0b669 100644 --- a/Source/Include/swigwarn.h +++ b/Source/Include/swigwarn.h @@ -264,11 +264,6 @@ /* please leave 750-759 free for R */ -#define WARN_C_TYPEMAP_CTYPE_UNDEF 760 -#define WARN_C_UNSUPPORTTED 761 - -/* please leave 760-779 free for C */ - #define WARN_RUBY_WRONG_NAME 801 #define WARN_RUBY_MULTIPLE_INHERITANCE 802 diff --git a/Source/Makefile.am b/Source/Makefile.am index c4e4c4521..095c5d4ea 100644 --- a/Source/Makefile.am +++ b/Source/Makefile.am @@ -45,7 +45,6 @@ eswig_SOURCES = CParse/cscanner.c \ Doxygen/pydoc.h \ Modules/allocate.cxx \ Modules/contract.cxx \ - Modules/c.cxx \ Modules/csharp.cxx \ Modules/d.cxx \ Modules/directors.cxx \ diff --git a/Source/Modules/c.cxx b/Source/Modules/c.cxx deleted file mode 100644 index d50d3475a..000000000 --- a/Source/Modules/c.cxx +++ /dev/null @@ -1,3177 +0,0 @@ -/* ----------------------------------------------------------------------------- - * See the LICENSE file for information on copyright, usage and redistribution - * of SWIG, and the README file for authors - http://www.swig.org/release.html. - * - * c.cxx - * - * C language module for SWIG. - * ----------------------------------------------------------------------------- */ - -#include -#include -#include "swigmod.h" - -extern int UseWrapperSuffix; // from main.cxx - -int SwigType_isbuiltin(SwigType *t) { - const char* builtins[] = { "void", "short", "int", "long", "char", "float", "double", "bool", 0 }; - int i = 0; - char *c = Char(t); - if (!t) - return 0; - while (builtins[i]) { - if (strcmp(c, builtins[i]) == 0) - return 1; - i++; - } - return 0; -} - - -// Private helpers, could be made public and reused from other language modules in the future. -namespace -{ - -enum exceptions_support { - exceptions_support_enabled, // Default value in C++ mode. - exceptions_support_disabled, // Not needed at all. - exceptions_support_imported // Needed, but already defined in an imported module. -}; - -// When using scoped_dohptr, it's very simple to accidentally pass it to a vararg function, such as Printv() or Printf(), resulting in catastrophic results -// during run-time (crash or, worse, junk in the generated output), so make sure gcc warning about this, which is not enabled by default for some reason (see -// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64867 for more information), is enabled. -#ifdef __GNUC__ - #pragma GCC diagnostic error "-Wconditionally-supported" -#endif // __GNUC__ - -// Delete a DOH object on scope exit. -class scoped_dohptr -{ -public: - scoped_dohptr() : obj_(NULL) {} - explicit scoped_dohptr(DOH* obj) : obj_(obj) {} - ~scoped_dohptr() { Delete(obj_); } - - // This is an std::auto_ptr<>-like "destructive" copy ctor which allows to return objects of this type from functions. - scoped_dohptr(scoped_dohptr const& other) : obj_(other.release()) {} - - // Same for the assignment operator. - scoped_dohptr& operator=(scoped_dohptr const& other) { - reset(other.release()); - - return *this; - } - - // Assignment operator takes ownership of the pointer, just as the ctor does. - scoped_dohptr& operator=(DOH* obj) { - reset(obj); - - return *this; - } - - DOH* get() const { return obj_; } - - DOH* release() const /* not really */ { - DOH* obj = obj_; - const_cast(const_cast(this)->obj_) = NULL; - return obj; - } - - void reset(DOH* obj = NULL) { - if (obj != obj_) { - Delete(obj_); - obj_ = obj; - } - } - - operator DOH*() const { return obj_; } - -protected: - DOH* obj_; -}; - -// Wrapper for a DOH object which can be owned or not. -class maybe_owned_dohptr : public scoped_dohptr -{ -public: - explicit maybe_owned_dohptr(DOH* obj = NULL) : scoped_dohptr(obj), owned_(true) {} - - maybe_owned_dohptr(maybe_owned_dohptr const& other) : scoped_dohptr(other) { - owned_ = other.owned_; - - // We can live other.owned_ unchanged, as its pointer is null now anyhow. - } - - maybe_owned_dohptr& operator=(maybe_owned_dohptr const& other) { - reset(other.release()); - owned_ = other.owned_; - - return *this; - } - - ~maybe_owned_dohptr() { - if (!owned_) - obj_ = NULL; // Prevent it from being deleted by the base class dtor. - } - - void assign_owned(DOH* obj) { - reset(obj); - } - - void assign_non_owned(DOH* obj) { - reset(obj); - owned_ = false; - } - -private: - bool owned_; -}; - - -// Helper class setting the given pointer to the given value in its ctor and resetting it in the dtor. -// -// Used to non-intrusively set a pointer to some object only during this object life-time. -template -class temp_ptr_setter -{ -public: - // Pointer must be non-null, its current value is restored when this object is destroyed. - temp_ptr_setter(T* ptr, T value) : ptr_(ptr), value_orig_(*ptr) { - *ptr_ = value; - } - - ~temp_ptr_setter() { - *ptr_ = value_orig_; - } - -private: - T* const ptr_; - T const value_orig_; - - // Non copyable. - temp_ptr_setter(const temp_ptr_setter&); - temp_ptr_setter& operator=(const temp_ptr_setter&); -}; - - -// Helper class to output "begin" fragment in the ctor and "end" in the dtor. -class begin_end_output_guard -{ -public: - begin_end_output_guard(File* f, const_String_or_char_ptr begin, const_String_or_char_ptr end) - : f_(f), - end_(NewString(end)) - { - String* const s = NewString(begin); - Dump(s, f_); - Delete(s); - } - - ~begin_end_output_guard() - { - Dump(end_, f_); - Delete(end_); - } - -private: - // Non copyable. - begin_end_output_guard(const begin_end_output_guard&); - begin_end_output_guard& operator=(const begin_end_output_guard&); - - File* const f_; - String* const end_; -}; - -// Subclass to output extern "C" guards when compiling as C++. -class cplusplus_output_guard : private begin_end_output_guard -{ -public: - explicit cplusplus_output_guard(File* f) - : begin_end_output_guard( - f, - "#ifdef __cplusplus\n" - "extern \"C\" {\n" - "#endif\n\n", - "#ifdef __cplusplus\n" - "}\n" - "#endif\n\n" - ) - { - } -}; - -// String containing one indentation level for the generated code. -const char* const cindent = " "; - -// Returns the non-owned string to the name of the class or enum to use in C wrappers. -String* get_c_proxy_name(Node* n) { - String *proxyname = Getattr(n, "proxyname"); - if (!proxyname) { - String *symname = Getattr(n, "sym:name"); - String *nspace = Getattr(n, "sym:nspace"); - - if (nspace) { - scoped_dohptr nspace_mangled(Swig_name_mangle_string(nspace)); - proxyname = NewStringf("%s_%s", (DOH*)nspace_mangled, symname); - } else { - proxyname = Swig_name_type(symname); - } - Setattr(n, "proxyname", proxyname); - - Delete(proxyname); // It stays alive because it's referenced by the hash. - } - - return proxyname; -} - -// Returns the first named "import" node under the given one (which must be non-NULL). May return NULL. -Node* find_first_named_import(Node* parent) { - for (Node* n = firstChild(parent); n; n = nextSibling(n)) { - if (Cmp(nodeType(n), "import") == 0) { - // We've almost succeeded, but there are sometimes some weird unnamed import modules that don't really count for our purposes, so skip them. - if (Getattr(n, "module")) - return n; - } else if (Cmp(nodeType(n), "include") == 0) { - // Recurse into this node as included files may contain imports too. - if (Node* const import = find_first_named_import(n)) - return import; - } else { - // We consider that import nodes can only occur in the global scope, some don't bother recursing here. If this turns out to be false, we'd just need to - // start doing it. - } - } - - return NULL; -} - - -/* - Information about the function return type. - */ -class cxx_rtype_desc -{ -public: - // Default ctor creates a "void" return type. - cxx_rtype_desc() {} - - // If this returns true, get_return_code() can't be called. - bool is_void() const { - return !type_; - } - - // This function must be called before calling get_return_code(). - void set_type(String* type) { - type_ = Copy(type); - } - - // This function must also be called before calling get_return_code(). - // - // NB: It takes ownership of the string, the intended use is to pass it NewStringf(...). - void set_return_value(String* new_string) { - value_ = new_string; - } - - // This function applies the given typemap, which must set $result variable from $cresult containing the result of C wrapper function call. - // - // If it is not called, the trivial "$result = $cresult" typemap is used and, in fact, the extra variables are optimized away and just "return $cresult" is - // generated directly for brevity. - // - // If the string doesn't start with "$result = ", it is prepended to it implicitly, for convenience. - // - // NB: It takes ownership of the string, which is typically returned from Swig_typemap_lookup(). - void apply_out_typemap(String* new_out_tm_string) { - out_tm_ = new_out_tm_string; - } - - // Return the function return type: can always be called, even for void functions (for which it just returns "void"). - String* type() const { - return type_ ? type_ : get_void_type(); - } - - // Return the string containing the code for returning the value, previously set by set_return_value(). - // - // The returned string ends with a semicolon, i.e. is a complete statement (or possibly more than one). - // - // Asserts unless both set_type() and set_return_value() had been called. - scoped_dohptr get_return_code() const { - assert(type_); - assert(value_); - - if (!out_tm_) { - // Trivial case when we return the same value, just do it. - // - // Add extra spaces after/before opening/closing braces because we keep everything on the same line in this case. - return scoped_dohptr(NewStringf(" return %s; ", value_.get())); - } - - // We need to start by introducing a temporary variable for the C call result because if $cresult is used twice by the typemap, we don't want to call the - // function twice. Note that just "auto" is enough because C functions can't return references, but we need "auto&&" for C++ result which can be anything - // (defined by the user in their typemaps). - scoped_dohptr code(NewStringf( - "\n" - "%sauto swig_cres = %s;\n", - cindent, value_.get() - )); - - // We support 2 cases: either typemap is a statement, or multiple statements, containing assignment to $result, in which case this assignment must occur at - // its beginning. - bool const has_result = strstr(Char(out_tm_), "$result = ") != NULL; - if (has_result) { - Printv(code, cindent, "auto&& ", NIL); - } else { - // Or the typemap is just an expression, which can be returned directly, without defining $result at all. Note that this is more than an optimization as - // it allows the generated code to work even with non-copyable classes. - Printv(code, cindent, "return ", NIL); - } - - // Skip leading whitespace and chop the trailing whitespace from the typemap to keep indentation consistent. - const char* tm = Char(out_tm_); - while (isspace(*tm)) - ++tm; - Append(code, tm); - Chop(code); - - if ((Char(code))[Len(code) - 1] != ';') - Append(code, ";"); - - Replaceall(code, "$cresult", "swig_cres"); - - if (has_result) { - Printf(code, "\n%sreturn $result;\n", cindent); - Replaceall(code, "$result", "swig_cxxres"); - } else { - Append(code, "\n"); - } - - return code; - } - -private: - static String* get_void_type() { - static String* const void_type = NewString("void"); - return void_type; - } - - scoped_dohptr type_; - scoped_dohptr value_; - scoped_dohptr out_tm_; -}; - -/* - Information about a function parameter. - - This is similar to cxx_rtype_desc, but is used for the parameters and not the return type. - */ -class cxx_ptype_desc -{ -public: - // Ctor initializes the object to an empty/unknown state, call set_type() later to finish initialization. - cxx_ptype_desc() {} - - // This function must be called (with a non-null string) before calling get_param_code(). - void set_type(String* type) { type_ = Copy(type); } - - // If this one returns NULL, it means that we don't have any type information at all. - String* type() const { return type_; } - - // This may be called before calling get_param_code() if a translation from C++ to C type is necessary. By default the parameter is passed "as is". - void apply_in_typemap(String* new_in_tm_string) { - in_tm_ = new_in_tm_string; - } - - // Return the full expression needed to pass the given value as parameter to C wrapper function. - scoped_dohptr get_param_code(String* value) const { - assert(type_); - - if (!in_tm_) { - return scoped_dohptr(Copy(value)); - } - - // There doesn't seem to be any simple way to use the full SWIG typemap expansion machinery here, so just do it manually. - scoped_dohptr code(Copy(in_tm_)); - Replace(code, "$1", value, DOH_REPLACE_NUMBER_END); - return code; - } - -private: - scoped_dohptr type_; - scoped_dohptr in_tm_; -}; - - -/* - Struct containing information needed only for generating C++ wrappers. -*/ -struct cxx_wrappers -{ - // Default ctor doesn't do anything, use initialize() if C++ wrappers really need to be generated. - cxx_wrappers() : - except_check_start(NULL), except_check_end(NULL), - sect_cxx_h(NULL), sect_types(NULL), sect_decls(NULL), sect_impls(NULL) { - node_func_ = NULL; - rtype_desc_ = NULL; - ptype_desc_ = NULL; - } - - void initialize() { - sect_cxx_h = NewStringEmpty(); - sect_types = NewStringEmpty(); - sect_decls = NewStringEmpty(); - sect_impls = NewStringEmpty(); - - // Allow using SWIG directive to inject code here. - Swig_register_filebyname("cxxheader", sect_cxx_h); - Swig_register_filebyname("cxxcode", sect_impls); - } - - // This function must be called after initialize(). The two can't be combined because we don't yet know if we're going to use exceptions or not when we - // initialize the object of this class in C::main(), so this one is called later from C::top(). - void initialize_exceptions(exceptions_support support) { - switch (support) { - case exceptions_support_enabled: - case exceptions_support_imported: - except_check_start = "swig_check("; - except_check_end = ")"; - break; - - case exceptions_support_disabled: - except_check_start = - except_check_end = ""; - break; - } - } - - bool is_initialized() const { return sect_types != NULL; } - - bool is_exception_support_enabled() const { return *except_check_start != '\0'; } - - - // All the functions below are only used when is_initialized() returns true. - - // Fill the provided rtype_desc with the type information for the given function node. - // - // Returns false in case of error, i.e. if function wrapper can't be generated at all. - bool lookup_cxx_ret_type(cxx_rtype_desc& rtype_desc, Node* n) { - String* const func_type = Getattr(n, "type"); - if (SwigType_type(func_type) == T_VOID) { - // Nothing to do, rtype_desc is void by default. - return true; - } - - // As above, ensure our replaceSpecialVariables() is used. - temp_ptr_setter set(&rtype_desc_, &rtype_desc); - - bool use_cxxout = true; - String* type(Swig_typemap_lookup("cxxouttype", n, "", NULL)); - if (!type) { - use_cxxout = false; - type = Swig_typemap_lookup("ctype", n, "", NULL); - } - - if (!type) { - Swig_warning(WARN_C_TYPEMAP_CTYPE_UNDEF, Getfile(n), Getline(n), - "No ctype typemap defined for the return type \"%s\" of %s\n", - SwigType_str(func_type, NULL), - Getattr(n, "sym:name") - ); - return false; - } - - if (!do_resolve_type(n, func_type, type, NULL, &rtype_desc)) - return false; - - if (use_cxxout) { - if (String* out_tm = Swig_typemap_lookup("cxxout", n, "", NULL)) - rtype_desc.apply_out_typemap(out_tm); - } - - return true; - } - - // Return the type description for the given parameter of the function. - bool lookup_cxx_parm_type(cxx_ptype_desc& ptype_desc, Node* n, Parm* p) { - // Ensure our own replaceSpecialVariables() is used for $typemap() expansion. - temp_ptr_setter set(&ptype_desc_, &ptype_desc); - - bool use_cxxin = true; - String* type = Swig_typemap_lookup("cxxintype", p, "", NULL); - if (!type) { - use_cxxin = false; - type = Swig_typemap_lookup("ctype", p, "", NULL); - } - - if (!type) { - Swig_warning(WARN_C_TYPEMAP_CTYPE_UNDEF, Getfile(p), Getline(p), - "No ctype typemap defined for the parameter \"%s\" of %s\n", - Getattr(p, "name"), - Getattr(n, "sym:name") - ); - return false; - } - - if (!do_resolve_type(n, Getattr(p, "type"), type, &ptype_desc, NULL)) - return false; - - if (use_cxxin) { - if (String* in_tm = Getattr(p, "tmap:cxxin")) - ptype_desc.apply_in_typemap(Copy(in_tm)); - } - - return true; - } - - - // This function is called from C::replaceSpecialVariables() but only does something non-trivial when it's called by our own lookup_cxx_xxx_type() functions. - bool replaceSpecialVariables(String *method, String *tm, Parm *parm) { - if (!ptype_desc_ && !rtype_desc_) - return false; - - if (Cmp(method, "ctype") != 0) { - Swig_warning(WARN_C_UNSUPPORTTED, input_file, line_number, "Unsupported %s typemap %s\n", method, tm); - return false; - } - - if (SwigType *type = Getattr(parm, "type")) { - if (ptype_desc_) - ptype_desc_->set_type(type); - if (rtype_desc_) - rtype_desc_->set_type(type); - - if (!do_resolve_type(node_func_, type, tm, ptype_desc_, rtype_desc_)) - return false; - } - - return true; - } - - - - // Used for generating exception checks around the calls, see initialize_exceptions(). - const char* except_check_start; - const char* except_check_end; - - - // The order of the members here is the same as the order in which they appear in the output file. - - // This section doesn't contain anything by default but can be used by typemaps etc. It is the only section outside of the namespace in which all the other - // declaration live. - String* sect_cxx_h; - - // This section contains forward declarations of the classes. - String* sect_types; - - // Full declarations of the classes. - String* sect_decls; - - // Implementation of the classes. - String* sect_impls; - - -private: - // Replace "resolved_type" occurrences in the string with the value corresponding to the given type. - // - // Note that the node here is the function itself, but type may be either its return type or the type of one of its parameters, so it's passed as a different - // parameter. - // - // Also fills in the start/end wrapper parts of the provided type descriptions if they're not null, with the casts needed to translate from C type to C++ type - // (this is used for the parameters of C++ functions, hence the name) and from C types to C++ types (which is used for the function return values). - static bool do_resolve_type(Node* n, String* type, String* s, cxx_ptype_desc* ptype_desc, cxx_rtype_desc* rtype_desc) { - enum TypeKind - { - Type_Ptr, - Type_Ref, - Type_Obj, - Type_Enm, - Type_Max - } typeKind = Type_Max; - - // These correspond to the typemaps for SWIGTYPE*, SWIGTYPE&, SWIGTYPE and enum SWIGTYPE, respectively, defined in c.swg. - static const char* typemaps[Type_Max] = { - "$resolved_type*", - "$*resolved_type*", - "$&resolved_type*", - "$resolved_type", - }; - - for (int i = 0; i < Type_Max; ++i) { - if (Strstr(s, typemaps[i])) { - typeKind = static_cast(i); - break; - } - } - - if (typeKind == Type_Max) { - if (Strstr(s, "resolved_type")) { - Swig_warning(WARN_C_UNSUPPORTTED, input_file, line_number, - "Unsupported typemap \"%s\" used for type \"%s\" of \"%s\"\n", - s, type, Getattr(n, "name") - ); - - return false; - } - - // Nothing else needed. - if (rtype_desc) - rtype_desc->set_type(s); - if (ptype_desc) - ptype_desc->set_type(s); - - return true; - } - - // The logic here is somewhat messy because we use the same "$resolved_type*" typemap for pointers/references to both enums and classes, but we actually - // need to do quite different things for them. It could probably be simplified by changing the typemaps to be distinct, but this would require also updating - // the code for C wrappers generation in substituteResolvedTypeSpecialVariable(). - // - // An even better idea might be to try to define this using cxx{in,out} typemaps for the various types and let the generic SWIG machinery do all the - // matching instead of doing it in the code here. - scoped_dohptr resolved_type(SwigType_typedef_resolve_all(type)); - scoped_dohptr base_resolved_type(SwigType_base(resolved_type)); - - scoped_dohptr typestr; - if (SwigType_isenum(base_resolved_type)) { - String* enumname = NULL; - if (Node* const enum_node = Language::instance()->enumLookup(base_resolved_type)) { - // This is the name of the enum in C wrappers, it should be already set by getEnumName(). - enumname = Getattr(enum_node, "enumname"); - - if (enumname) { - String* const enum_symname = Getattr(enum_node, "sym:name"); - - if (Checkattr(enum_node, "ismember", "1")) { - Node* const parent_class = parentNode(enum_node); - typestr = NewStringf("%s::%s", Getattr(parent_class, "sym:name"), enum_symname); - } else { - typestr = Copy(enum_symname); - } - } - } - - if (!enumname) { - // Unknown enums are mapped to int and no casts are necessary in this case. - typestr = NewString("int"); - } - - if (SwigType_ispointer(type)) - Append(typestr, " *"); - else if (SwigType_isreference(type)) - Append(typestr, " &"); - - if (enumname) { - switch (typeKind) { - case Type_Ptr: - if (rtype_desc) { - rtype_desc->apply_out_typemap(NewStringf("(%s)$cresult", typestr.get())); - } - - if (ptype_desc) { - ptype_desc->apply_in_typemap(NewStringf("(%s*)$1", enumname)); - } - break; - - case Type_Ref: - if (rtype_desc) { - rtype_desc->apply_out_typemap(NewStringf("(%s)(*($cresult))", typestr.get())); - } - - if (ptype_desc) { - ptype_desc->apply_in_typemap(NewStringf("(%s*)&($1)", enumname)); - } - break; - - case Type_Enm: - if (rtype_desc) { - rtype_desc->apply_out_typemap(NewStringf("(%s)$cresult", typestr.get())); - } - - if (ptype_desc) { - ptype_desc->apply_in_typemap(NewStringf("(%s)$1", enumname)); - } - break; - - case Type_Obj: - case Type_Max: - // Unreachable, but keep here to avoid -Wswitch warnings. - assert(0); - } - } else { - // This is the only thing we need to do even when we don't have the enum name. - if (typeKind == Type_Ref && ptype_desc) - ptype_desc->apply_in_typemap(NewString("&($1)")); - } - } else { - String* classname; - if (Node* const class_node = Language::instance()->classLookup(type)) { - // Deal with some special cases: - switch (typeKind) { - case Type_Ptr: - // If this is a pointer passed by const reference, we return just the pointer directly because we don't have any pointer-valued variable to give out - // a reference to. - if (strncmp(Char(resolved_type), "r.q(const).", 11) == 0) { - scoped_dohptr deref_type(Copy(resolved_type)); - Delslice(deref_type, 0, 11); - typestr = SwigType_str(deref_type, 0); - } - break; - - case Type_Obj: - // Const objects are just objects for our purposes here, remove the const from them to avoid having "const const" in the output. - if (SwigType_isconst(resolved_type)) - SwigType_del_qualifier(resolved_type); - break; - - case Type_Ref: - case Type_Enm: - case Type_Max: - // Nothing special to do. - break; - } - - if (!typestr) - typestr = SwigType_str(resolved_type, 0); - - classname = Getattr(class_node, "sym:name"); - - // We don't use namespaces, but the type may contain them, so get rid of them by replacing the base type name, which is fully qualified, with just the - // class name, which is not. - scoped_dohptr basetype(SwigType_base(resolved_type)); - scoped_dohptr basetypestr(SwigType_str(basetype, 0)); - if (Cmp(basetypestr, classname) != 0) { - Replaceall(typestr, basetypestr, classname); - } - } else { - classname = NULL; - } - - if (!classname) { - Swig_warning(WARN_C_UNSUPPORTTED, input_file, line_number, - "Unsupported C++ wrapper function %s type \"%s\"\n", - ptype_desc ? "parameter" : "return", SwigType_str(type, 0) - ); - return false; - } - - const char* const owns = GetFlag(n, "feature:new") ? "true" : "false"; - switch (typeKind) { - case Type_Ptr: - if (ptype_desc) { - ptype_desc->apply_in_typemap(NewString("$1->swig_self()")); - } - - if (rtype_desc) { - rtype_desc->apply_out_typemap(NewStringf( - "$cresult ? new %s($cresult, %s) : nullptr;", - classname, owns - )); - } - break; - - case Type_Ref: - if (rtype_desc) { - // We can't return a reference, as this requires an existing object and we don't have any, so we have to return an object instead, and this object - // must be constructed using the special ctor not taking the pointer ownership. - typestr = Copy(classname); - - rtype_desc->apply_out_typemap(NewStringf("%s{$cresult, false}", classname)); - } - - if (ptype_desc) { - ptype_desc->apply_in_typemap(NewString("$1.swig_self()")); - } - break; - - case Type_Obj: - if (rtype_desc) { - // The pointer returned by C function wrapping a function returning an object should never be null unless an exception happened, so we don't test - // for it here, unlike in Type_Ptr case. - // - // Also, normally all returned objects should be owned by their wrappers, but there is a special case of objects not being returned by value: this - // seems not to make sense, but can actually happen when typemaps map references or pointers to objects, like they do for e.g. shared_ptr<>. - // - // Note that we must use the type of the function, retrieved from its node, here and not the type passed to us which is the result of typemap - // expansion and so may not be a reference any more. - rtype_desc->apply_out_typemap(NewStringf("%s{$cresult, %s}", - typestr.get(), - SwigType_isreference(Getattr(n, "type")) ? owns : "true" - )); - } - - if (ptype_desc) { - // It doesn't seem like it can ever be useful to pass an object by value to a wrapper function and it can fail if it doesn't have a copy ctor (see - // code related to has_copy_ctor_ in our dtor above), so always pass it by const reference instead. - Append(typestr, " const&"); - - ptype_desc->apply_in_typemap(NewString("$1.swig_self()")); - } - break; - - case Type_Enm: - case Type_Max: - // Unreachable, but keep here to avoid -Wswitch warnings. - assert(0); - } - } - - Replaceall(s, typemaps[typeKind], typestr); - - if (rtype_desc) - rtype_desc->set_type(s); - if (ptype_desc) - ptype_desc->set_type(s); - - return true; - } - - - // These pointers are temporarily set to non-null value only while expanding a typemap for C++ wrappers, see replaceSpecialVariables(). - cxx_ptype_desc* ptype_desc_; - cxx_rtype_desc* rtype_desc_; - - // This one is set from the outside, so make it public for simplicity. -public: - Node* node_func_; -}; - -/* - cxx_function_wrapper - - Outputs the C++ wrapper function. It's different from the C function because it is declared inside the namespace and so doesn't need the usual prefix and may - also have different parameter and return types when objects and/or cxx{in,out}type typemaps are involved. - */ -class cxx_function_wrapper -{ -public: - // Call can_wrap() to check if this wrapper can be emitted later. - explicit cxx_function_wrapper(cxx_wrappers& cxx_wrappers, Node* n, Parm* parms) : cxx_wrappers_(cxx_wrappers) { - func_node = NULL; - - except_check_start = - except_check_end = ""; - - if (Checkattr(n, "feature:cxxignore", "1")) - return; - - // Usually generating wrappers for overloaded methods is fine, but sometimes their types can clash after applying typemaps and in this case we have no - // choice but to avoid generating them, as otherwise we'd just generate uncompilable code. - if (Getattr(n, "sym:overloaded")) { - Swig_overload_check(n); - if (Getattr(n, "overload:ignore")) - return; - } - - if (!cxx_wrappers_.lookup_cxx_ret_type(rtype_desc, n)) - return; - - parms_cxx = NewStringEmpty(); - parms_call = NewStringEmpty(); - - if (parms) { - // We want to use readable parameter names in our wrappers instead of the autogenerated arg$N if possible, so do it, and do it before calling - // Swig_typemap_attach_parms(), as this uses the parameter names for typemap expansion. - - Parm *p; - int index = 1; - String *lname = 0; - std::map strmap; - - for (p = (Parm*)parms, index = 1; p; (p = nextSibling(p)), index++) { - String* name = Getattr(p, "name"); - if (!name) { - // Can't do anything for unnamed parameters. - continue; - } - - // Static variables use fully qualified names, so we need to strip the scope from them. - scoped_dohptr name_ptr; - if (Strstr(name, "::")) { - name_ptr = Swig_scopename_last(name); - name = name_ptr.get(); - } - if (strmap.count(Hashval(name))) { - strmap[Hashval(name)]++; - String* nname = NewStringf("%s%d", name, strmap[Hashval(name)]); - Setattr(p, "lname", nname); - } - else { - Setattr(p, "lname", name); - strmap[Hashval(name)] = 1; - } - } - - Swig_typemap_attach_parms("cxxin", p, NULL); - - for (p = parms; p; p = Getattr(p, "tmap:in:next")) { - if (Checkattr(p, "tmap:in:numinputs", "0")) - continue; - - String* const name = Getattr(p, "lname"); - - cxx_ptype_desc ptype_desc; - if (!cxx_wrappers_.lookup_cxx_parm_type(ptype_desc, n, p)) - return; - - if (Len(parms_cxx)) - Append(parms_cxx, ", "); - Printv(parms_cxx, ptype_desc.type(), " ", name, NIL); - - if (Len(parms_call)) - Append(parms_call, ", "); - Append(parms_call, ptype_desc.get_param_code(name)); - } - } - - - // Avoid checking for exceptions unnecessarily. Note that this is more than an optimization: we'd get into infinite recursion if we checked for exceptions - // thrown by members of SWIG_CException itself if we didn't do it. - if (cxx_wrappers_.is_exception_support_enabled() && - !Checkattr(n, "noexcept", "true") && - (!Checkattr(n, "throw", "1") || Getattr(n, "throws"))) { - except_check_start = cxx_wrappers_.except_check_start; - except_check_end = cxx_wrappers_.except_check_end; - } - - // Everything is fine, so set func_node to indicate success. - func_node = n; - } - - bool can_wrap() const { return func_node != NULL; } - - // Emit just the function body, including the braces around it. - // - // This helper is used both by our emit() and emit_member_function(). - void emit_body(String* wparms) { - String* const wname = Getattr(func_node, "wrap:name"); - - Append(cxx_wrappers_.sect_impls, "{"); - - if (rtype_desc.is_void()) { - Printv(cxx_wrappers_.sect_impls, - " ", wname, "(", wparms, "); ", - NIL - ); - - if (*except_check_start != '\0') { - Printv(cxx_wrappers_.sect_impls, - except_check_start, - except_check_end, - "; ", - NIL - ); - } - } else { - rtype_desc.set_return_value(NewStringf("%s%s(%s)%s", except_check_start, wname, wparms, except_check_end)); - Append(cxx_wrappers_.sect_impls, rtype_desc.get_return_code()); - } - - Append(cxx_wrappers_.sect_impls, "}\n"); - } - - // Do emit the function wrapper. - void emit() { - // The wrapper function name should be sym:name, but we change it to include the namespace prefix in our own globalvariableHandler(), so now we have to undo - // this by using the value saved there, if available. This is definitely clumsy and it would be better to avoid it, but this would probably need to be done - // by separating C and C++ wrapper generation in two different passes and so would require significantly more changes than this hack. - String* name = Getattr(func_node, "c:globalvariableHandler:sym:name"); - if (!name) - name = Getattr(func_node, "sym:name"); - - Printv(cxx_wrappers_.sect_impls, - "inline ", rtype_desc.type(), " ", name, "(", parms_cxx.get(), ") ", - NIL - ); - - emit_body(parms_call); - } - - - cxx_wrappers& cxx_wrappers_; - Node* func_node; - cxx_rtype_desc rtype_desc; - scoped_dohptr parms_cxx; - scoped_dohptr parms_call; - const char* except_check_start; - const char* except_check_end; - -private: - // Non copyable. - cxx_function_wrapper(const cxx_function_wrapper&); - cxx_function_wrapper& operator=(const cxx_function_wrapper&); -}; - - -/* - Return true if the class, or one of its base classes, uses multiple inheritance, i.e. has more than one base class. - - The output first_base parameter is optional and is filled with the first base class (if any). -*/ -bool uses_multiple_inheritance(Node* n, scoped_dohptr* first_base_out = NULL) { - if (first_base_out) - first_base_out->reset(); - - List* const baselist = Getattr(n, "bases"); - if (!baselist) - return false; - - scoped_dohptr first_base; - for (Iterator i = First(baselist); i.item; i = Next(i)) { - if (Checkattr(i.item, "feature:ignore", "1")) - continue; - - if (first_base) - return true; - - if (uses_multiple_inheritance(i.item)) - return true; - - first_base = Copy(i.item); - } - - if (first_base_out) - *first_base_out = first_base; - - return false; -} - -/* - cxx_class_wrapper - - Outputs the declaration of the class wrapping the given one if we're generating C++ wrappers, i.e. if the provided cxx_wrappers object is initialized. -*/ -class cxx_class_wrapper -{ -public: - // If the provided cxx_wrappers object is not initialized, this class doesn't do anything. - // - // The node pointer must be valid, point to a class and remain valid for the lifetime of this object. - cxx_class_wrapper(cxx_wrappers& cxx_wrappers, Node* n) : cxx_wrappers_(cxx_wrappers) { - class_node_ = NULL; - - if (!cxx_wrappers_.is_initialized()) - return; - - if (Checkattr(n, "feature:cxxignore", "1")) - return; - - String* const classname = Getattr(n, "sym:name"); - - scoped_dohptr base_classes(NewStringEmpty()); - if (uses_multiple_inheritance(n, &first_base_)) { - Swig_warning(WARN_C_UNSUPPORTTED, Getfile(n), Getline(n), - "Multiple inheritance not supported yet, skipping C++ wrapper generation for %s\n", - classname - ); - - // Return before initializing class_node_, so that the dtor won't output anything neither. - return; - } - - if (first_base_) - Printv(base_classes, " : public ", Getattr(first_base_, "sym:name"), NIL); - - Printv(cxx_wrappers_.sect_types, - "class ", classname, ";\n", - NIL - ); - - Printv(cxx_wrappers_.sect_decls, - "class ", classname, base_classes.get(), " {\n" - "public:", - NIL - ); - - // If we have any extra code, inject it. Note that we need a hack with an artificial extra node to use Swig_typemap_lookup(), as it needs a "type" attribute - // which the class node doesn't have. - scoped_dohptr dummy(NewHash()); - Setattr(dummy, "type", Getattr(n, "name")); - Setfile(dummy, Getfile(n)); - Setline(dummy, Getline(n)); - scoped_dohptr cxxcode(Swig_typemap_lookup("cxxcode", dummy, "", NULL)); - if (!cxxcode || *Char(cxxcode) != '\n') - Append(cxx_wrappers_.sect_decls, "\n"); - if (cxxcode) { - Replaceall(cxxcode, "$cxxclassname", classname); - Replaceall(cxxcode, "$cclassptrname", get_c_class_ptr(n)); - Append(cxx_wrappers_.sect_decls, cxxcode); - } - - class_node_ = n; - dtor_wname_ = NULL; - has_copy_ctor_ = false; - } - - // Get indentation used inside this class declaration. - const char* get_indent() const { - // Currently we always use a single level of indent, but this would need to change if/when nested classes are supported. - // - // As the first step, we should probably change all occurrences of "cindent" in this class itself to use get_indent() instead. - return cindent; - } - - // Emit wrapper of a member function. - void emit_member_function(Node* n) { - if (!class_node_) - return; - - // We don't need to redeclare functions inherited from the base class, as we use real inheritance. - if (Getattr(n, "c:inherited_from")) - return; - - // And we even don't need to redeclare virtual functions actually overridden in the derived class, as their implementation is the same as in the base class - // anyhow, so don't bother generating needless extra code. - if (Getattr(n, "override")) - return; - - // Also ignore friend function declarations: they appear inside the class, but we shouldn't generate any wrappers for them. - if (Checkattr(n, "storage", "friend")) - return; - - // As mentioned elsewhere, we can't use Swig_storage_isstatic() here because the "storage" attribute is temporarily saved in another view when this - // function is being executed, so rely on another attribute to determine if it's a static function instead. - const bool is_member = Checkattr(n, "ismember", "1"); - const bool is_static = is_member && Getattr(n, "cplus:staticbase"); - const bool is_ctor = Checkattr(n, "nodeType", "constructor"); - - Parm* p = Getattr(n, "parms"); - if (p && is_member && !is_ctor && !is_static) { - // We should have "this" as the first parameter and we need to just skip it, as we handle it specially in C++ wrappers. - if (Checkattr(p, "name", "self")) { - p = nextSibling(p); - } else { - // This is not supposed to happen, so warn if it does. - Swig_warning(WARN_C_UNSUPPORTTED, Getfile(n), Getline(n), - "Unexpected first parameter \"%s\" in %s\n", - Getattr(p, "name"), - Getattr(n, "sym:name")); - } - } - - cxx_function_wrapper func_wrapper(cxx_wrappers_, n, p); - if (!func_wrapper.can_wrap()) - return; - - // Define aliases for the stuff actually stored in the function wrapper object. - cxx_rtype_desc& rtype_desc = func_wrapper.rtype_desc; - String* const parms_cxx = func_wrapper.parms_cxx; - String* const parms_call = func_wrapper.parms_call; - - // For some reason overloaded functions use fully-qualified name, so we can't just use the name directly. - scoped_dohptr name_ptr(Swig_scopename_last(Getattr(n, "name"))); - String* const name = name_ptr; - String* const wname = Getattr(n, "wrap:name"); - - String* const classname = Getattr(class_node_, "sym:name"); - - if (Checkattr(n, "kind", "variable")) { - if (Checkattr(n, "memberget", "1")) { - Printv(cxx_wrappers_.sect_decls, - cindent, rtype_desc.type(), " ", name, "() const;\n", - NIL - ); - - rtype_desc.set_return_value(NewStringf("%s(swig_self())", Getattr(n, "sym:name"))); - Printv(cxx_wrappers_.sect_impls, - "inline ", rtype_desc.type(), " ", classname, "::", name, "() const " - "{", rtype_desc.get_return_code().get(), "}\n", - NIL - ); - } else if (Checkattr(n, "memberset", "1")) { - Printv(cxx_wrappers_.sect_decls, - cindent, "void ", name, "(", parms_cxx, ");\n", - NIL - ); - - Printv(cxx_wrappers_.sect_impls, - "inline void ", classname, "::", name, "(", parms_cxx, ") " - "{ ", Getattr(n, "sym:name"), "(swig_self(), ", parms_call, "); }\n", - NIL - ); - } else if (Checkattr(n, "varget", "1")) { - Printv(cxx_wrappers_.sect_decls, - cindent, "static ", rtype_desc.type(), " ", name, "();\n", - NIL - ); - - rtype_desc.set_return_value(NewStringf("%s()", Getattr(n, "sym:name"))); - Printv(cxx_wrappers_.sect_impls, - "inline ", rtype_desc.type(), " ", classname, "::", name, "() " - "{", rtype_desc.get_return_code().get(), "}\n", - NIL - ); - } else if (Checkattr(n, "varset", "1")) { - Printv(cxx_wrappers_.sect_decls, - cindent, "static void ", name, "(", parms_cxx, ");\n", - NIL - ); - - Printv(cxx_wrappers_.sect_impls, - "inline void ", classname, "::", name, "(", parms_cxx, ") " - "{ ", Getattr(n, "sym:name"), "(", parms_call, "); }\n", - NIL - ); - } else { - Swig_warning(WARN_C_UNSUPPORTTED, Getfile(n), Getline(n), - "Not generating C++ wrappers for variable %s\n", - Getattr(n, "sym:name") - ); - } - } else if (is_ctor) { - // Delegate to the ctor from opaque C pointer taking ownership of the object. - Printv(cxx_wrappers_.sect_decls, - cindent, classname, "(", parms_cxx, ");\n", - NIL - ); - - Printv(cxx_wrappers_.sect_impls, - "inline ", classname, "::", classname, "(", parms_cxx, ") : ", - classname, "{", - func_wrapper.except_check_start, - wname, "(", parms_call, ")", - func_wrapper.except_check_end, - "} {}\n", - NIL - ); - - // Remember that we had a copy ctor. - if (Checkattr(n, "copy_constructor", "1")) - has_copy_ctor_ = true; - } else if (Checkattr(n, "nodeType", "destructor")) { - if (first_base_) { - // Delete the pointer and reset the ownership flag to ensure that the base class doesn't do it again. - Printv(cxx_wrappers_.sect_decls, - cindent, get_virtual_prefix(n), "~", classname, "() {\n", - cindent, cindent, "if (swig_owns_self_) {\n", - cindent, cindent, cindent, wname, "(swig_self());\n", - cindent, cindent, cindent, "swig_owns_self_ = false;\n", - cindent, cindent, "}\n", - cindent, "}\n", - NIL - ); - } else { - // Slightly simplified version for classes without base classes, as we don't need to reset swig_self_ then. - Printv(cxx_wrappers_.sect_decls, - cindent, get_virtual_prefix(n), "~", classname, "() {\n", - cindent, cindent, "if (swig_owns_self_)\n", - cindent, cindent, cindent, wname, "(swig_self_);\n", - cindent, "}\n", - NIL - ); - - // We're also going to need this in move assignment operator. - dtor_wname_ = wname; - } - } else if (is_member) { - // Wrapper parameters list may or not include "this" pointer and may or not have other parameters, so construct it piecewise for simplicity. - scoped_dohptr wparms(NewStringEmpty()); - if (!is_static) - Append(wparms, "swig_self()"); - if (Len(parms_call)) { - if (Len(wparms)) - Append(wparms, ", "); - Append(wparms, parms_call); - } - - Printv(cxx_wrappers_.sect_decls, - cindent, - is_static ? "static " : get_virtual_prefix(n), rtype_desc.type(), " ", - name, "(", parms_cxx, ")", - get_const_suffix(n), ";\n", - NIL - ); - - Printv(cxx_wrappers_.sect_impls, - "inline ", rtype_desc.type(), " ", - classname, "::", name, "(", parms_cxx, ")", - get_const_suffix(n), - " ", - NIL - ); - - func_wrapper.emit_body(wparms); - } else { - // This is something we don't know about - Swig_warning(WARN_C_UNSUPPORTTED, Getfile(n), Getline(n), - "Not generating C++ wrappers for %s\n", - Getattr(n, "sym:name") - ); - } - } - - ~cxx_class_wrapper() { - // Don't do anything if generation of the wrapper for this class was disabled in ctor. - if (!class_node_) - return; - - // This is the name used for the class pointers in C wrappers. - scoped_dohptr c_class_ptr = get_c_class_ptr(class_node_); - - String* const classname = Getattr(class_node_, "sym:name"); - - // We need to generate a ctor from the C object pointer, which is required to be able to create objects of this class from pointers created by C wrappers - // and also by any derived classes. - Printv(cxx_wrappers_.sect_decls, - "\n", - cindent, "explicit ", classname, "(", c_class_ptr.get(), " swig_self, " - "bool swig_owns_self = true) noexcept : ", - NIL - ); - - if (first_base_) { - // In this case we delegate to the base class ctor, but need a cast because it expects a different pointer type (as these types are opaque, there is no - // relationship between them). - Printv(cxx_wrappers_.sect_decls, - Getattr(first_base_, "sym:name"), - "{(", get_c_class_ptr(first_base_).get(), ")swig_self, swig_owns_self}", - NIL - ); - } else { - // Just initialize our own field. - Printv(cxx_wrappers_.sect_decls, - "swig_self_{swig_self}, swig_owns_self_{swig_owns_self}", - NIL - ); - } - - Append(cxx_wrappers_.sect_decls, " {}\n"); - - // If the class doesn't have a copy ctor, forbid copying it: we currently must do it even if the original class has a perfectly cromulent implicit copy ctor - // because we don't wrap it and copying would use the trivial ctor that would just copy the swig_self_ pointer resulting in double destruction of it later. - // To fix this, we would need to always provide our own C wrapper for the copy ctor, which is not something we do currently. - if (!has_copy_ctor_) { - Printv(cxx_wrappers_.sect_decls, - cindent, classname, "(", classname, " const&) = delete;\n", - NIL - ); - } - - // We currently never wrap the assignment operator, so we have to always disable it for the same reason we disable the copy ctor above. - // It would definitely be nice to provide the assignment, if possible. - Printv(cxx_wrappers_.sect_decls, - cindent, classname, "& operator=(", classname, " const&) = delete;\n", - NIL - ); - - // OTOH we may always provide move ctor and assignment, as we can always implement them trivially ourselves. - if (first_base_) { - Printv(cxx_wrappers_.sect_decls, - cindent, classname, "(", classname, "&& obj) = default;\n", - cindent, classname, "& operator=(", classname, "&& obj) = default;\n", - NIL - ); - } else { - Printv(cxx_wrappers_.sect_decls, - cindent, classname, "(", classname, "&& obj) noexcept : " - "swig_self_{obj.swig_self_}, swig_owns_self_{obj.swig_owns_self_} { " - "obj.swig_owns_self_ = false; " - "}\n", - cindent, classname, "& operator=(", classname, "&& obj) noexcept {\n", - NIL - ); - - if (dtor_wname_) { - Printv(cxx_wrappers_.sect_decls, - cindent, cindent, "if (swig_owns_self_)\n", - cindent, cindent, cindent, dtor_wname_, "(swig_self_);\n", - NIL - ); - } - - Printv(cxx_wrappers_.sect_decls, - cindent, cindent, "swig_self_ = obj.swig_self_;\n", - cindent, cindent, "swig_owns_self_ = obj.swig_owns_self_;\n", - cindent, cindent, "obj.swig_owns_self_ = false;\n", - cindent, cindent, "return *this;\n", - cindent, "}\n", - NIL - ); - } - - // We also need a swig_self() method for accessing the C object pointer. - Printv(cxx_wrappers_.sect_decls, - cindent, c_class_ptr.get(), " swig_self() const noexcept ", - NIL - ); - - if (first_base_) { - // If we have a base class, we reuse its existing "self" pointer. - Printv(cxx_wrappers_.sect_decls, - "{ return (", c_class_ptr.get(), ")", Getattr(first_base_, "sym:name"), "::swig_self(); }\n", - NIL - ); - } else { - // We use our own pointer, which we also have to declare, together with the ownership flag. - // - // Perhaps we could avoid having a separate bool flag by reusing the low-order bit of the pointer itself as the indicator of ownership and masking it when - // retrieving it here in the future. If we decide to implement this optimization, the code generated here should be the only thing that would need to - // change. - Printv(cxx_wrappers_.sect_decls, - "{ return swig_self_; }\n", - cindent, c_class_ptr.get(), " swig_self_;\n", - cindent, "bool swig_owns_self_;\n", - NIL - ); - } - - Printv(cxx_wrappers_.sect_decls, - "};\n" - "\n", - NIL - ); - } - -private: - // Various helpers. - - // Return the string containing the pointer type used for representing the objects of the given class in the C wrappers. - // - // Returned value includes "*" at the end. - static scoped_dohptr get_c_class_ptr(Node* class_node) { - return scoped_dohptr(NewStringf("SwigObj_%s*", get_c_proxy_name(class_node))); - } - - // Return "virtual " if this is a virtual function, empty string otherwise. - static const char* get_virtual_prefix(Node* n) { - return Checkattr(n, "storage", "virtual") ? "virtual " : ""; - } - - // Return " const" if this is a const function, empty string otherwise. - static const char* get_const_suffix(Node* n) { - String* const qualifier = Getattr(n, "qualifier"); - return qualifier && strncmp(Char(qualifier), "q(const)", 8) == 0 ? " const" : ""; - } - - - cxx_wrappers& cxx_wrappers_; - - // The class node itself, left null only if we skip generating wrappers for it for whatever reason. - Node* class_node_; - - // We currently don't support generating C++ wrappers for classes using multiple inheritance. This could be implemented, with some tweaks to allow - // initializing the other base classes after creating the most-derived object, but hasn't been done yet. Until then we store just the first base class (if - // any, this member can also be null). - scoped_dohptr first_base_; - - // Name of the C function used for deleting the owned object, if any. - String* dtor_wname_; - - // True if the class defines an explicit copy ctor. - bool has_copy_ctor_; - - - // Non copyable. - cxx_class_wrapper(const cxx_class_wrapper&); - cxx_class_wrapper& operator=(const cxx_class_wrapper&); -}; - -} // anonymous namespace - -class C:public Language { - static const char *usage; - - // These files contain types used by the wrappers declarations and the declarations themselves and end up in the output header file. - String *sect_wrappers_types; - String *sect_wrappers_decl; - - // This one contains wrapper functions definitions and end up in the output C++ file. - String *sect_wrappers; - - String *empty_string; - - // Namespace used for the C++ wrappers, set from -namespace command-line option if specified or from the module name otherwise. - String *ns_cxx; - - // Prefix used for all symbols, if non-null. If ns_cxx was specified, it is a mangled version of it. - String *ns_prefix; - - // Name of the module, used as a prefix for module-level symbols if ns_prefix is null. - String *module_name; - - // Name of the output header, set in top(). - String *outfile_h; - - // Used only while generating wrappers for an enum and contains the prefix, ending with underscore, to use for enum elements or is empty. - scoped_dohptr enum_prefix_; - - // Used only while generating wrappers for an enum, as we don't know if enum will have any elements or not in advance and we must not generate an empty enum, - // so we accumulate the full declaration here and then write it to sect_wrappers_types at once only if there are any elements. - String *enum_decl; - - // Selects between the wrappers (public) declarations and (private) definitions. - enum { - output_wrapper_decl, - output_wrapper_def - } current_output; - - // Selects between various kinds of needed support for exception-related code. - exceptions_support exceptions_support_; - - // This object contains information necessary only for C++ wrappers generation, use its is_initialized() to check if this is being done. - cxx_wrappers cxx_wrappers_; - - // Non-owning pointer to the current C++ class wrapper if we're currently generating one or NULL. - cxx_class_wrapper* cxx_class_wrapper_; - - // This is parallel to enum_prefix_ but for C++ enum elements. - scoped_dohptr cxx_enum_prefix_; - - // This is parallel to enum_decl but for C++ enum declaration. - String *cxx_enum_decl; - - // An extra indent level needed for nested C++ enums. - const char* cxx_enum_indent; - -public: - - /* ----------------------------------------------------------------------------- - * C() - * ----------------------------------------------------------------------------- */ - - C() : - empty_string(NewString("")), - ns_cxx(NULL), - ns_prefix(NULL), - module_name(NULL), - outfile_h(NULL), - cxx_class_wrapper_(NULL) - { - UseWrapperSuffix = 1; - } - - ~C() - { - Delete(ns_cxx); - Delete(ns_prefix); - } - - // Construct the name to be used for a function with the given name in C wrappers. - // - // The returned string must be freed by caller. - maybe_owned_dohptr getFunctionWrapperName(Node *n, String *name) const - { - maybe_owned_dohptr wname; - - // The basic idea here is that for class members we don't need to use any prefix at all, as they're already prefixed by the class name, which has the - // appropriate prefix, but we need to use a prefix for the other symbols. - // - // However there are a couple of special cases complicating this: - // - // - Friend functions are declared inside the class, but are not member functions, so we have to check for both the current class and "ismember" property. - // - Destructors and implicitly generated constructors don't have "ismember" for some reason, so we need to check for them specifically. - // - Variable getters and setters don't need to use the prefix as they don't clash with anything. - if ((getCurrentClass() && - (Checkattr(n, "ismember", "1") || - Checkattr(n, "nodeType", "constructor") || - Checkattr(n, "nodeType", "destructor"))) || -- Checkattr(n, "varget", "1") || Checkattr(n, "varset", "1")) { - wname.assign_non_owned(name); - return wname; - } - - // Use namespace as the prefix if feature:nspace is in use. - scoped_dohptr scopename_prefix; - if (GetFlag(parentNode(n), "feature:nspace")) { - scopename_prefix = Swig_scopename_prefix(Getattr(n, "name")); - if (scopename_prefix) { - scoped_dohptr mangled_prefix(Swig_name_mangle_string(scopename_prefix)); - scopename_prefix = mangled_prefix; - } - } - - // Fall back to the module name if we don't use feature:nspace and don't have the global prefix neither. - // - // Note that we really, really need to use some prefix, as wrapper function can't have the same name as the original function being wrapped. - String* const prefix = scopename_prefix - ? scopename_prefix - : ns_prefix - ? ns_prefix - : module_name; - - wname.assign_owned(NewStringf("%s_%s", prefix, name)); - return wname; - } - - /* ----------------------------------------------------------------------------- - * getClassProxyName() - * - * Test to see if a type corresponds to something wrapped with a proxy class. - * Return NULL if not, otherwise the proxy class name to be freed by the caller. - * ----------------------------------------------------------------------------- */ - - String *getClassProxyName(SwigType *t) { - Node *n = classLookup(t); - - return n ? Copy(get_c_proxy_name(n)) : NULL; - - } - - /* ----------------------------------------------------------------------------- - * getEnumName() - * - * Return the name to use for the enum in the generated code. - * Also caches it in the node for subsequent access. - * Returns NULL if the node doesn't correspond to an enum. - * ----------------------------------------------------------------------------- */ - - String *getEnumName(Node *n) { - String *enumname = Getattr(n, "enumname"); - if (!enumname) { - // We can't use forward-declared enums because we can't define them for C wrappers (we could forward declare them in C++ if their underlying type, - // available as "inherit" node attribute, is specified, but not in C), so we have no choice but to use "int" for them. - if (Checkattr(n, "sym:weak", "1")) - return NULL; - - String *symname = Getattr(n, "sym:name"); - if (symname) { - // Add in class scope when referencing enum if not a global enum - String *proxyname = 0; - if (String *name = Getattr(n, "name")) { - if (String *scopename_prefix = Swig_scopename_prefix(name)) { - proxyname = getClassProxyName(scopename_prefix); - Delete(scopename_prefix); - } - } - if (proxyname) { - enumname = NewStringf("%s_%s", proxyname, symname); - Delete(proxyname); - } else { - // global enum or enum in a namespace - enumname = Copy(get_c_proxy_name(n)); - } - Setattr(n, "enumname", enumname); - Delete(enumname); - } - } - - return enumname; - } - - - /* ----------------------------------------------------------------------------- - * substituteResolvedTypeSpecialVariable() - * ----------------------------------------------------------------------------- */ - - void substituteResolvedTypeSpecialVariable(SwigType *classnametype, String *tm, const char *classnamespecialvariable) { - scoped_dohptr btype(SwigType_base(classnametype)); - if (SwigType_isenum(btype)) { - Node* const enum_node = enumLookup(btype); - String* const enumname = enum_node ? getEnumName(enum_node) : NULL; - - // We use the enum name in the wrapper declaration if it's available, as this makes it more type safe, but we always use just int for the function - // definition because we don't have the enum declaration in scope there. This obviously only actually works if the actual enum underlying type is int (or - // smaller). - maybe_owned_dohptr c_enumname; - if (current_output == output_wrapper_decl && enumname) { - // We need to add "enum" iff this is not already a typedef for the enum. - if (Checkattr(enum_node, "allows_typedef", "1")) - c_enumname.assign_non_owned(enumname); - else - c_enumname.assign_owned(NewStringf("enum %s", enumname)); - } else { - c_enumname.assign_owned(NewString("int")); - } - - Replaceall(tm, classnamespecialvariable, c_enumname); - } else { - if (!CPlusPlus) { - // Just use the original C type when not using C++, we know that this type can be used in the wrappers. - Clear(tm); - String* const s = SwigType_str(classnametype, 0); - Append(tm, s); - Delete(s); - return; - } - - String* typestr = NIL; - if (current_output == output_wrapper_def || Cmp(btype, "SwigObj") == 0) { - // Special case, just leave it unchanged. - typestr = NewString("SwigObj"); - } else { - typestr = getClassProxyName(btype); - if (!typestr) { - if (SwigType_isbuiltin(btype)) { - // This should work just as well in C without any changes. - typestr = SwigType_str(classnametype, 0); - } else { - // Swig doesn't know anything about this type, use descriptor for it. - typestr = NewStringf("SWIGTYPE%s", SwigType_manglestr(classnametype)); - - // And make sure it is declared before it is used. - Printf(sect_wrappers_types, "typedef struct %s %s;\n\n", typestr, typestr); - } - } - } - - Replaceall(tm, classnamespecialvariable, typestr); - Delete(typestr); - } - } - - /* ----------------------------------------------------------------------------- - * substituteResolvedType() - * - * Substitute the special variable $csclassname with the proxy class name for classes/structs/unions - * that SWIG knows about. Also substitutes enums with enum name. - * Otherwise use the $descriptor name for the C# class name. Note that the $&csclassname substitution - * is the same as a $&descriptor substitution, ie one pointer added to descriptor name. - * Inputs: - * pt - parameter type - * tm - typemap contents that might contain the special variable to be replaced - * Outputs: - * tm - typemap contents complete with the special variable substitution - * ----------------------------------------------------------------------------- */ - - void substituteResolvedType(SwigType *pt, String *tm) { - SwigType *type = SwigType_typedef_resolve_all(pt); - SwigType *strippedtype = SwigType_strip_qualifiers(type); - - if (Strstr(tm, "$resolved_type")) { - SwigType *classnametype = Copy(strippedtype); - substituteResolvedTypeSpecialVariable(classnametype, tm, "$resolved_type"); - Delete(classnametype); - } - if (Strstr(tm, "$*resolved_type")) { - SwigType *classnametype = Copy(strippedtype); - Delete(SwigType_pop(classnametype)); - if (Len(classnametype) > 0) { - substituteResolvedTypeSpecialVariable(classnametype, tm, "$*resolved_type"); - } - Delete(classnametype); - } - if (Strstr(tm, "$&resolved_type")) { - SwigType *classnametype = Copy(strippedtype); - SwigType_add_pointer(classnametype); - substituteResolvedTypeSpecialVariable(classnametype, tm, "$&resolved_type"); - Delete(classnametype); - } - - Delete(strippedtype); - Delete(type); - } - - /*---------------------------------------------------------------------- - * replaceSpecialVariables() - * - * Override the base class method to ensure that $resolved_type is expanded correctly inside $typemap(). - *--------------------------------------------------------------------*/ - - virtual void replaceSpecialVariables(String *method, String *tm, Parm *parm) { - // This function is called by Swig_typemap_lookup(), which may be called when generating C or C++ wrappers, so delegate to the latter one if necessary. - if (cxx_wrappers_.is_initialized() && cxx_wrappers_.replaceSpecialVariables(method, tm, parm)) - return; - - SwigType *type = Getattr(parm, "type"); - substituteResolvedType(type, tm); - } - - /* ------------------------------------------------------------ - * main() - * ------------------------------------------------------------ */ - - virtual void main(int argc, char *argv[]) { - bool except_flag = CPlusPlus; - bool use_cxx_wrappers = CPlusPlus; - - // look for certain command line options - for (int i = 1; i < argc; i++) { - if (argv[i]) { - if (strcmp(argv[i], "-help") == 0) { - Printf(stdout, "%s\n", usage); - } else if (strcmp(argv[i], "-namespace") == 0) { - if (argv[i + 1]) { - ns_cxx = NewString(argv[i + 1]); - ns_prefix = Swig_name_mangle_string(ns_cxx); - Swig_mark_arg(i); - Swig_mark_arg(i + 1); - i++; - } else { - Swig_arg_error(); - } - } else if (strcmp(argv[i], "-nocxx") == 0) { - use_cxx_wrappers = false; - Swig_mark_arg(i); - } else if (strcmp(argv[i], "-noexcept") == 0) { - except_flag = false; - Swig_mark_arg(i); - } - } - } - - // add a symbol to the parser for conditional compilation - Preprocessor_define("SWIGC 1", 0); - if (except_flag) - Preprocessor_define("SWIG_C_EXCEPT 1", 0); - if (CPlusPlus) - Preprocessor_define("SWIG_CPPMODE 1", 0); - if (use_cxx_wrappers) - Preprocessor_define("SWIG_CXX_WRAPPERS 1", 0); - - SWIG_library_directory("c"); - - // add typemap definitions - SWIG_typemap_lang("c"); - SWIG_config_file("c.swg"); - - String* const ns_prefix_ = ns_prefix ? NewStringf("%s_", ns_prefix) : NewString(""); - - // The default naming convention is to use new_Foo(), copy_Foo() and delete_Foo() for the default/copy ctor and dtor of the class Foo, but we prefer to - // start all Foo methods with the same prefix, so change this. Notice that new/delete are chosen to ensure that we avoid conflicts with the existing class - // methods, more natural create/destroy, for example, could result in errors if the class already had a method with the same name, but this is impossible - // for the chosen names as they're keywords in C++ ("copy" is still a problem but we'll just have to live with it). - Swig_name_register("construct", NewStringf("%s%%n%%c_new", ns_prefix_)); - Swig_name_register("copy", NewStringf("%s%%n%%c_copy", ns_prefix_)); - Swig_name_register("destroy", NewStringf("%s%%n%%c_delete", ns_prefix_)); - - // These ones are only needed when using a global prefix, as otherwise the defaults are fine. - if (ns_prefix) { - Swig_name_register("member", NewStringf("%s%%n%%c_%%m", ns_prefix_)); - Swig_name_register("type", NewStringf("%s%%c", ns_prefix_)); - } - - Delete(ns_prefix_); - - exceptions_support_ = except_flag ? exceptions_support_enabled : exceptions_support_disabled; - - if (use_cxx_wrappers) - cxx_wrappers_.initialize(); - - allow_overloading(); - } - - /* --------------------------------------------------------------------- - * top() - * --------------------------------------------------------------------- */ - - virtual int top(Node *n) { - module_name = Getattr(n, "name"); - String *outfile = Getattr(n, "outfile"); - - // initialize I/O - const scoped_dohptr f_wrappers_cxx(NewFile(outfile, "w", SWIG_output_files())); - if (!f_wrappers_cxx) { - FileErrorDisplay(outfile); - Exit(EXIT_FAILURE); - } - - Swig_banner(f_wrappers_cxx); - - // Open the file where all wrapper declarations will be written to in the end. - outfile_h = Getattr(n, "outfile_h"); - const scoped_dohptr f_wrappers_h(NewFile(outfile_h, "w", SWIG_output_files())); - if (!f_wrappers_h) { - FileErrorDisplay(outfile_h); - Exit(EXIT_FAILURE); - } - - Swig_banner(f_wrappers_h); - - // Associate file with the SWIG sections with the same name, so that e.g. "%header" contents end up in sect_header etc. - const scoped_dohptr sect_begin(NewStringEmpty()); - const scoped_dohptr sect_header(NewStringEmpty()); - const scoped_dohptr sect_runtime(NewStringEmpty()); - const scoped_dohptr sect_init(NewStringEmpty()); - - // This one is used outside of this function, so it's a member variable rather than a local one. - sect_wrappers = NewStringEmpty(); - - Swig_register_filebyname("begin", sect_begin); - Swig_register_filebyname("header", sect_header); - Swig_register_filebyname("wrapper", sect_wrappers); - Swig_register_filebyname("runtime", sect_runtime); - Swig_register_filebyname("init", sect_init); - - // This one is C-specific and goes directly to the output header file. - Swig_register_filebyname("cheader", f_wrappers_h); - - // Deal with exceptions support. - if (exceptions_support_ == exceptions_support_enabled) { - // Redefine SWIG_CException_Raise() to have a unique prefix in the shared library built from SWIG-generated sources to allow using more than one extension - // in the same process without conflicts. This has to be done in this hackish way because we really need to change the name of the function itself, not - // its wrapper (which is not even generated). - Printv(sect_runtime, - "#define SWIG_CException_Raise ", (ns_prefix ? ns_prefix : module_name), "_SWIG_CException_Raise\n", - NIL - ); - - // We need to check if we have any %imported modules, as they would already define the exception support code and we want to have exactly one copy of it - // in the generated shared library, so check for "import" nodes. - if (find_first_named_import(n)) { - // We import another module, which will have already defined SWIG_CException, so set the flag indicating that we shouldn't do it again in this one and - // define the symbol to skip compiling its implementation. - Printv(sect_runtime, "#define SWIG_CException_DEFINED 1\n", NIL); - - // Also set a flag telling classDeclaration() to skip creating SWIG_CException wrappers. - exceptions_support_ = exceptions_support_imported; - } - } - - if (cxx_wrappers_.is_initialized()) - cxx_wrappers_.initialize_exceptions(exceptions_support_); - - { - String* const include_guard_name = NewStringf("SWIG_%s_WRAP_H_", module_name); - String* const include_guard_begin = NewStringf( - "#ifndef %s\n" - "#define %s\n\n", - include_guard_name, - include_guard_name - ); - String* const include_guard_end = NewStringf( - "\n" - "#endif /* %s */\n", - include_guard_name - ); - - begin_end_output_guard - include_guard_wrappers_h(f_wrappers_h, include_guard_begin, include_guard_end); - - // All the struct types used by the functions go to f_wrappers_types so that they're certain to be defined before they're used by any functions. All the - // functions declarations go directly to f_wrappers_decl we write both of them to f_wrappers_h at the end. - sect_wrappers_types = NewString(""); - sect_wrappers_decl = NewString(""); - - { - cplusplus_output_guard - cplusplus_guard_wrappers(sect_wrappers), - cplusplus_guard_wrappers_h(sect_wrappers_decl); - - // emit code for children - Language::top(n); - } // close extern "C" guards - - Dump(sect_wrappers_types, f_wrappers_h); - Delete(sect_wrappers_types); - - Dump(sect_wrappers_decl, f_wrappers_h); - Delete(sect_wrappers_decl); - - if (cxx_wrappers_.is_initialized()) { - if (!ns_cxx) { - // We need some namespace for the C++ wrappers as otherwise their names could conflict with the C functions, so use the module name if nothing was - // explicitly specified. - ns_cxx = Copy(module_name); - } - - Printv(f_wrappers_h, "#ifdef __cplusplus\n\n", NIL); - Dump(cxx_wrappers_.sect_cxx_h, f_wrappers_h); - - // Generate possibly nested namespace declarations, as unfortunately we can't rely on C++17 nested namespace definitions being always available. - scoped_dohptr cxx_ns_end(NewStringEmpty()); - for (const char* c = Char(ns_cxx);;) { - const char* const next = strstr(c, "::"); - - maybe_owned_dohptr ns_component; - if (next) { - ns_component.assign_owned(NewStringWithSize(c, next - c)); - } else { - ns_component.assign_non_owned((DOH*)c); - } - - Printf(f_wrappers_h, "namespace %s {\n", ns_component.get()); - Printf(cxx_ns_end, "}\n"); - - if (!next) - break; - - c = next + 2; - } - - Printv(f_wrappers_h, "\n", NIL); - Dump(cxx_wrappers_.sect_types, f_wrappers_h); - - Printv(f_wrappers_h, "\n", NIL); - Dump(cxx_wrappers_.sect_decls, f_wrappers_h); - - Printv(f_wrappers_h, "\n", NIL); - Dump(cxx_wrappers_.sect_impls, f_wrappers_h); - - Printv(f_wrappers_h, "\n", cxx_ns_end.get(), "\n#endif /* __cplusplus */\n", NIL); - } - } // close wrapper header guard - - // write all to the file - Dump(sect_begin, f_wrappers_cxx); - Dump(sect_runtime, f_wrappers_cxx); - Dump(sect_header, f_wrappers_cxx); - Dump(sect_wrappers, f_wrappers_cxx); - Dump(sect_init, f_wrappers_cxx); - - return SWIG_OK; - } - - /* ----------------------------------------------------------------------- - * importDirective() - * ------------------------------------------------------------------------ */ - - virtual int importDirective(Node *n) { - // When we import another module, we need access to its declarations in our header, so we must include the header generated for that module. Unfortunately - // there doesn't seem to be any good way to get the name of that header, so we try to guess it from the header name of this module. This is obviously not - // completely reliable, but works reasonably well in practice and it's not clear what else could we do, short of requiring some C-specific %import attribute - // specifying the name of the header explicitly. - - // We can only do something if we have a module name. - if (String* const imported_module_name = Getattr(n, "module")) { - // Start with our header name. - scoped_dohptr header_name(Copy(outfile_h)); - - // Strip the output directory from the file name, as it should be common to all generated headers. - Replace(header_name, SWIG_output_directory(), "", DOH_REPLACE_FIRST); - - // And replace our module name with the name of the one being imported. - Replace(header_name, module_name, imported_module_name, DOH_REPLACE_FIRST); - - // Finally inject inclusion of this header. - Printv(Swig_filebyname("cheader"), "#include \"", header_name.get(), "\"\n", NIL); - } - - return Language::importDirective(n); - } - - /* ----------------------------------------------------------------------- - * globalvariableHandler() - * ------------------------------------------------------------------------ */ - - virtual int globalvariableHandler(Node *n) { - // Don't export static globals, they won't be accessible when using a shared library, for example. - if (Checkattr(n, "storage", "static")) - return SWIG_NOWRAP; - - // We can't export variables defined inside namespaces to C directly, whatever their type, and we can only export them under their original name, so we - // can't do it when using a global namespace prefix neither. - if (!ns_prefix && !scoped_dohptr(Swig_scopename_prefix(Getattr(n, "name")))) { - // If we can export the variable directly, do it, this will be more convenient to use from C code than accessor functions. - if (String* const var_decl = make_c_var_decl(n)) { - Printv(sect_wrappers_decl, "SWIGIMPORT ", var_decl, ";\n\n", NIL); - Delete(var_decl); - return SWIG_OK; - } - } - - // We have to prepend the global prefix to the names of the accessors for this variable, if we use one. - // - // Note that we can't just register the name format using the prefix for "get" and "set", as we do it for "member", and using it for both would result in - // the prefix being used twice for the member variables getters and setters, so we have to work around it here instead. - if (ns_prefix && !getCurrentClass()) { - Swig_require("c:globalvariableHandler", n, "*sym:name", NIL); - Setattr(n, "sym:name", NewStringf("%s_%s", ns_prefix, Getattr(n, "sym:name"))); - } - - // Otherwise, e.g. if it's of a C++-only type, or a reference, generate accessor functions for it. - int const rc = Language::globalvariableHandler(n); - - if (Getattr(n, "view")) - Swig_restore(n); - - return rc; - } - - /* ---------------------------------------------------------------------- - * prepend_feature() - * ---------------------------------------------------------------------- */ - - String* prepend_feature(Node *n) { - String *prepend_str = Getattr(n, "feature:prepend"); - if (prepend_str) { - char *t = Char(prepend_str); - if (*t == '{') { - Delitem(prepend_str, 0); - Delitem(prepend_str, DOH_END); - } - } - return (prepend_str ? prepend_str : empty_string); - } - - /* ---------------------------------------------------------------------- - * append_feature() - * ---------------------------------------------------------------------- */ - - String* append_feature(Node *n) { - String *append_str = Getattr(n, "feature:append"); - if (append_str) { - char *t = Char(append_str); - if (*t == '{') { - Delitem(append_str, 0); - Delitem(append_str, DOH_END); - } - } - return (append_str ? append_str : empty_string); - } - - /* ---------------------------------------------------------------------- - * get_mangled_type() - * ---------------------------------------------------------------------- */ - - String *get_mangled_type(SwigType *type_arg) { - String *result = NewString(""); - SwigType *type = 0; - SwigType *tdtype = SwigType_typedef_resolve_all(type_arg); - if (tdtype) - type = tdtype; - else - type = Copy(type_arg); - - // special cases for ptr to function as an argument - if (SwigType_ismemberpointer(type)) { - SwigType_del_memberpointer(type); - SwigType_add_pointer(type); - } - if (SwigType_ispointer(type)) { - SwigType_del_pointer(type); - if (SwigType_isfunction(type)) { - Printf(result, "f"); - Delete(type); - return result; - } - Delete(type); - type = Copy(type_arg); - } - - SwigType *prefix = SwigType_prefix(type); - if (Len(prefix)) { - Replaceall(prefix, ".", ""); - Replaceall(prefix, "const", "c"); - Replaceall(prefix, "volatile", "v"); - Replaceall(prefix, "a(", "a"); - Replaceall(prefix, "m(", "m"); - Replaceall(prefix, "q(", ""); - Replaceall(prefix, ")", ""); - Replaceall(prefix, " ", ""); - Printf(result, "%s", prefix); - } - - type = SwigType_base(type); - if (SwigType_isbuiltin(type)) { - Printf(result, "%c", *Char(SwigType_base(type))); - } else if (SwigType_isenum(type)) { - String* enumname = Swig_scopename_last(type); - const char* s = Char(enumname); - static const int len_enum_prefix = strlen("enum "); - if (strncmp(s, "enum ", len_enum_prefix) == 0) - s += len_enum_prefix; - Printf(result, "e%s", s); - } else { - Printf(result, "%s", Char(Swig_name_mangle_string(SwigType_base(type)))); - } - - Delete(prefix); - Delete(type); - - return result; - } - - void functionWrapperCSpecific(Node *n) - { - // this is C function, we don't apply typemaps to it - String *name = Getattr(n, "sym:name"); - maybe_owned_dohptr wname = getFunctionWrapperName(n, name); - SwigType *type = Getattr(n, "type"); - SwigType *return_type = NULL; - String *arg_names = NULL; - ParmList *parms = Getattr(n, "parms"); - Parm *p; - String *proto = NewString(""); - int gencomma = 0; - bool is_void_return = (SwigType_type(type) == T_VOID); - - // create new function wrapper object - Wrapper *wrapper = NewWrapper(); - - // create new wrapper name - Setattr(n, "wrap:name", wname); //Necessary to set this attribute? Apparently, it's never read! - - // create function call - arg_names = Swig_cfunction_call(empty_string, parms); - if (arg_names) { - Delitem(arg_names, 0); - Delitem(arg_names, DOH_END); - } - return_type = SwigType_str(type, 0); - - // emit wrapper prototype and code - for (p = parms, gencomma = 0; p; p = nextSibling(p)) { - Printv(proto, gencomma ? ", " : "", SwigType_str(Getattr(p, "type"), 0), " ", Getattr(p, "lname"), NIL); - gencomma = 1; - } - Printv(wrapper->def, return_type, " ", wname.get(), "(", proto, ") {\n", NIL); - - // attach 'check' typemaps - Swig_typemap_attach_parms("check", parms, wrapper); - - // insert constraint checking - for (p = parms; p; ) { - String *tm; - if ((tm = Getattr(p, "tmap:check"))) { - Replaceall(tm, "$target", Getattr(p, "lname")); - Replaceall(tm, "$name", name); - Printv(wrapper->code, tm, "\n", NIL); - p = Getattr(p, "tmap:check:next"); - } else { - p = nextSibling(p); - } - } - - Append(wrapper->code, prepend_feature(n)); - if (!is_void_return) { - Printv(wrapper->code, return_type, " result;\n", NIL); - Printf(wrapper->code, "result = "); - } - Printv(wrapper->code, Getattr(n, "name"), "(", arg_names, ");\n", NIL); - Append(wrapper->code, append_feature(n)); - if (!is_void_return) - Printf(wrapper->code, "return result;\n"); - Printf(wrapper->code, "}"); - - Wrapper_print(wrapper, sect_wrappers); - - emit_wrapper_func_decl(n, wname); - - // cleanup - Delete(proto); - Delete(arg_names); - Delete(return_type); - DelWrapper(wrapper); - } - - void functionWrapperAppendOverloaded(String *name, Parm* first_param) - { - String *over_suffix = NewString(""); - Parm *p; - String *mangled; - - for (p = first_param; p; p = nextSibling(p)) { - mangled = get_mangled_type(Getattr(p, "type")); - Printv(over_suffix, "_", mangled, NIL); - } - Append(name, over_suffix); - Delete(over_suffix); - } - - scoped_dohptr get_wrapper_func_return_type(Node *n) - { - SwigType *type = Getattr(n, "type"); - String *return_type; - - if ((return_type = Swig_typemap_lookup("ctype", n, "", 0))) { - substituteResolvedType(type, return_type); - } else { - Swig_warning(WARN_C_TYPEMAP_CTYPE_UNDEF, input_file, line_number, "No ctype typemap defined for %s\n", SwigType_str(type, 0)); - return_type = NewString(""); - } - - Replaceall(return_type, "::", "_"); - - return scoped_dohptr(return_type); - } - - /* ---------------------------------------------------------------------- - * get_wrapper_func_proto() - * - * Return the function signature, i.e. the comma-separated list of argument types and names surrounded by parentheses. - * If a non-null wrapper is specified, it is used to emit typemap-defined code in it and it also determines whether we're generating the prototype for the - * declarations or the definitions, which changes the type used for the C++ objects. - * ---------------------------------------------------------------------- */ - scoped_dohptr get_wrapper_func_proto(Node *n, Wrapper* wrapper = NULL) - { - ParmList *parms = Getattr(n, "parms"); - - Parm *p; - String *proto = NewString("("); - int gencomma = 0; - - // attach the standard typemaps - if (wrapper) { - emit_attach_parmmaps(parms, wrapper); - } else { - // We can't call emit_attach_parmmaps() without a wrapper, it would just crash. - // Attach "in" manually, we need it for tmap:in:numinputs below. - Swig_typemap_attach_parms("in", parms, 0); - } - Setattr(n, "wrap:parms", parms); //never read again?! - - // attach 'ctype' typemaps - Swig_typemap_attach_parms("ctype", parms, 0); - - - // prepare function definition - for (p = parms, gencomma = 0; p; ) { - String *tm; - SwigType *type = NULL; - - while (p && checkAttribute(p, "tmap:in:numinputs", "0")) { - p = Getattr(p, "tmap:in:next"); - } - if (!p) break; - - type = Getattr(p, "type"); - if (SwigType_type(type) == T_VOID) { - p = nextSibling(p); - continue; - } - - if (SwigType_type(type) == T_VARARGS) { - Swig_error(Getfile(n), Getline(n), "Vararg function %s not supported.\n", Getattr(n, "name")); - return scoped_dohptr(NULL); - } - - String *lname = Getattr(p, "lname"); - String *c_parm_type = 0; - String *arg_name = NewString(""); - - Printf(arg_name, "c%s", lname); - - if ((tm = Getattr(p, "tmap:ctype"))) { // set the appropriate type for parameter - c_parm_type = Copy(tm); - substituteResolvedType(type, c_parm_type); - - // We prefer to keep typedefs in the wrapper functions signatures as it makes them more readable, but we can't do it for nested typedefs as - // they're not valid in C, so resolve them in this case. - if (strstr(Char(c_parm_type), "::")) { - SwigType* const tdtype = SwigType_typedef_resolve_all(c_parm_type); - Delete(c_parm_type); - c_parm_type = tdtype; - } - - // template handling - Replaceall(c_parm_type, "$tt", SwigType_lstr(type, 0)); - } else { - Swig_warning(WARN_C_TYPEMAP_CTYPE_UNDEF, input_file, line_number, "No ctype typemap defined for %s\n", SwigType_str(type, 0)); - } - - Printv(proto, gencomma ? ", " : "", c_parm_type, " ", arg_name, NIL); - gencomma = 1; - - // apply typemaps for input parameter - if ((tm = Getattr(p, "tmap:in"))) { - Replaceall(tm, "$input", arg_name); - if (wrapper) { - Setattr(p, "emit:input", arg_name); - Printf(wrapper->code, "%s\n", tm); - } - p = Getattr(p, "tmap:in:next"); - } else { - Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "Unable to use type %s as a function argument.\n", SwigType_str(type, 0)); - p = nextSibling(p); - } - - Delete(arg_name); - Delete(c_parm_type); - } - - Printv(proto, ")", NIL); - return scoped_dohptr(proto); - } - - /* ---------------------------------------------------------------------- - * emit_wrapper_func_decl() - * - * Declares the wrapper function, using the C types used for it, in the header. - * The node here is a function declaration. - * ---------------------------------------------------------------------- */ - void emit_wrapper_func_decl(Node *n, String *wname) - { - current_output = output_wrapper_decl; - - // add function declaration to the proxy header file - Printv(sect_wrappers_decl, "SWIGIMPORT ", get_wrapper_func_return_type(n).get(), " ", wname, get_wrapper_func_proto(n).get(), ";\n\n", NIL); - } - - - void functionWrapperCPPSpecific(Node *n) - { - ParmList *parms = Getattr(n, "parms"); - String *name = Copy(Getattr(n, "sym:name")); - - // mangle name if function is overloaded - if (Getattr(n, "sym:overloaded")) { - if (!Getattr(n, "copy_constructor")) { - Parm* first_param = (Parm*)parms; - if (first_param) { - // Skip the first "this" parameter of the wrapped methods, it doesn't participate in overload resolution and would just result in extra long - // and ugly names. - // - // We need to avoid dropping the first argument of static methods which don't have "this" pointer, in spite of being members (and we have to - // use "cplus:staticbase" for this instead of just using Swig_storage_isstatic() because "storage" is reset in staticmemberfunctionHandler() - // and so is not available here. - // - // Of course, the constructors don't have the extra first parameter neither. - if (!Checkattr(n, "nodeType", "constructor") && - Checkattr(n, "ismember", "1") && - !Getattr(n, "cplus:staticbase")) { - first_param = nextSibling(first_param); - - // A special case of overloading on const/non-const "this" pointer only, we still need to distinguish between those. - if (SwigType_isconst(Getattr(n, "decl"))) { - const char * const nonconst = Char(Getattr(n, "decl")) + 9 /* strlen("q(const).") */; - for (Node* nover = Getattr(n, "sym:overloaded"); nover; nover = Getattr(nover, "sym:nextSibling")) { - if (nover == n) - continue; - - if (Cmp(Getattr(nover, "decl"), nonconst) == 0) { - // We have an overload differing by const only, disambiguate. - Append(name, "_const"); - break; - } - } - } - } - - functionWrapperAppendOverloaded(name, first_param); - } - } - } - - // make sure lnames are set - Parm *p; - int index = 1; - String *lname = 0; - std::map strmap; - - for (p = (Parm*)parms, index = 1; p; (p = nextSibling(p)), index++) { - String* name = Getattr(p, "name"); - if (!name) { - // Can't do anything for unnamed parameters. - if(!(lname = Getattr(p, "lname"))) { - lname = NewStringf("arg%d", index); - Setattr(p, "lname", lname); - } - continue; - } - scoped_dohptr name_ptr; - if (Strstr(name, "::")) { - name_ptr = Swig_scopename_last(name); - name = name_ptr.get(); - } - if (strmap.count(Hashval(name))) { - strmap[Hashval(name)]++; - String* nname = NewStringf("%s%d", name, strmap[Hashval(name)]); - Setattr(p, "lname", nname); - } - else { - Setattr(p, "lname", name); - strmap[Hashval(name)] = 1; - } - } - - // C++ function wrapper - current_output = output_wrapper_def; - - SwigType *type = Getattr(n, "type"); - scoped_dohptr return_type = get_wrapper_func_return_type(n); - maybe_owned_dohptr wname = getFunctionWrapperName(n, name); - bool is_void_return = (SwigType_type(type) == T_VOID); - // create new function wrapper object - Wrapper *wrapper = NewWrapper(); - - // create new wrapper name - Setattr(n, "wrap:name", wname); - - // add variable for holding result of original function 'cppresult' - if (!is_void_return) { - SwigType *value_type = cplus_value_type(type); - SwigType* cppresult_type = value_type ? value_type : type; - SwigType* ltype = SwigType_ltype(cppresult_type); - Wrapper_add_local(wrapper, "cppresult", SwigType_str(ltype, "cppresult")); - Delete(ltype); - Delete(value_type); - } - - // create wrapper function prototype - Printv(wrapper->def, "SWIGEXPORTC ", return_type.get(), " ", wname.get(), NIL); - - Printv(wrapper->def, get_wrapper_func_proto(n, wrapper).get(), NIL); - Printv(wrapper->def, " {", NIL); - - // emit variables for holding parameters - emit_parameter_variables(parms, wrapper); - - // emit variable for holding function return value - emit_return_variable(n, return_type, wrapper); - - // insert constraint checking - for (p = parms; p; ) { - String *tm; - if ((tm = Getattr(p, "tmap:check"))) { - Replaceall(tm, "$target", Getattr(p, "lname")); - Replaceall(tm, "$name", name); - Printv(wrapper->code, tm, "\n", NIL); - p = Getattr(p, "tmap:check:next"); - } else { - p = nextSibling(p); - } - } - - // create action code - String *action = Getattr(n, "wrap:action"); - if (!action) - action = NewString(""); - - String *cbase_name = Getattr(n, "c:base_name"); - if (cbase_name) { - Replaceall(action, "arg1)->", NewStringf("(%s*)arg1)->", Getattr(n, "c:inherited_from"))); - Replaceall(action, Getattr(n, "name"), cbase_name); - } - - Replaceall(action, "result =", "cppresult ="); - - // prepare action code to use, e.g. insert try-catch blocks - action = emit_action(n); - - // emit output typemap if needed - if (!is_void_return) { - String *tm; - if ((tm = Swig_typemap_lookup_out("out", n, "cppresult", wrapper, action))) { - // This is ugly, but the type of our result variable is not always the same as the actual return type currently because - // get_wrapper_func_return_type() applies ctype typemap to it. These types are more or less compatible though, so we should be able to cast - // between them explicitly. - const char* start = Char(tm); - const char* p = strstr(start, "$result = "); - if (p == start || (p && p[-1] == ' ')) { - p += strlen("$result = "); - scoped_dohptr result_cast(NewStringf("(%s)", return_type.get())); - - // However don't add a cast which is already there. - if (strncmp(p, Char(result_cast), strlen(Char(result_cast))) != 0) - Insert(tm, p - start, result_cast); - } - Replaceall(tm, "$result", "result"); - Replaceall(tm, "$owner", GetFlag(n, "feature:new") ? "1" : "0"); - Printf(wrapper->code, "%s", tm); - if (Len(tm)) - Printf(wrapper->code, "\n"); - } else { - Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(type, 0), Getattr(n, "name")); - } - } else { - Append(wrapper->code, action); - } - - // insert cleanup code - for (p = parms; p; ) { - String *tm; - if ((tm = Getattr(p, "tmap:freearg"))) { - if (tm && (Len(tm) != 0)) { - String *input = NewStringf("c%s", Getattr(p, "lname")); - Replaceall(tm, "$source", Getattr(p, "lname")); - Replaceall(tm, "$input", input); - Delete(input); - Printv(wrapper->code, tm, "\n", NIL); - } - p = Getattr(p, "tmap:freearg:next"); - } else { - p = nextSibling(p); - } - } - - if (is_void_return) { - Replaceall(wrapper->code, "$null", ""); - } else { - Replaceall(wrapper->code, "$null", "0"); - - Append(wrapper->code, "return result;\n"); - } - - Append(wrapper->code, "}\n"); - - Wrapper_print(wrapper, sect_wrappers); - - // cleanup - DelWrapper(wrapper); - - emit_wrapper_func_decl(n, wname); - - if (cxx_wrappers_.is_initialized()) { - temp_ptr_setter set(&cxx_wrappers_.node_func_, n); - - if (cxx_class_wrapper_) { - cxx_class_wrapper_->emit_member_function(n); - } else { - cxx_function_wrapper w(cxx_wrappers_, n, Getattr(n, "parms")); - if (w.can_wrap()) - w.emit(); - } - } - - Delete(name); - } - - /* ---------------------------------------------------------------------- - * functionWrapper() - * ---------------------------------------------------------------------- */ - - virtual int functionWrapper(Node *n) { - if (!Getattr(n, "sym:overloaded")) { - if (!addSymbol(Getattr(n, "sym:name"), n)) - return SWIG_ERROR; - } - - if (CPlusPlus) { - functionWrapperCPPSpecific(n); - } else { - functionWrapperCSpecific(n); - } - - return SWIG_OK; - } - - /* --------------------------------------------------------------------- - * copy_node() - * - * This is not a general-purpose node copying function, but just a helper of classHandler(). - * --------------------------------------------------------------------- */ - - Node *copy_node(Node *node) { - Node *new_node = NewHash(); - Setattr(new_node, "name", Copy(Getattr(node, "name"))); - Setattr(new_node, "ismember", Copy(Getattr(node, "ismember"))); - Setattr(new_node, "view", Copy(Getattr(node, "view"))); - Setattr(new_node, "kind", Copy(Getattr(node, "kind"))); - Setattr(new_node, "access", Copy(Getattr(node, "access"))); - Setattr(new_node, "parms", Copy(Getattr(node, "parms"))); - Setattr(new_node, "type", Copy(Getattr(node, "type"))); - Setattr(new_node, "decl", Copy(Getattr(node, "decl"))); - - Node* const parent = parentNode(node); - Setattr(new_node, "c:inherited_from", Getattr(parent, "name")); - Setattr(new_node, "sym:name", Getattr(node, "sym:name")); - Setattr(new_node, "sym:symtab", Getattr(parent, "symtab")); - set_nodeType(new_node, "cdecl"); - - return new_node; - } - - /* --------------------------------------------------------------------- - * is_in() - * - * tests if given name already exists in one of child nodes of n - * --------------------------------------------------------------------- */ - - Hash *is_in(String *name, Node *n) { - Hash *h; - for (h = firstChild(n); h; h = nextSibling(h)) { - if (Cmp(name, Getattr(h, "name")) == 0) - return h; - } - return 0; - } - - /* --------------------------------------------------------------------- - * make_c_var_decl() - * - * Return the C declaration for the given node of "variable" kind. - * - * If the variable has a type not representable in C, returns NULL, the caller must check for this! - * - * This function accounts for two special cases: - * 1. If the type is an anonymous enum, "int" is used instead. - * 2. If the type is an array, its bounds are stripped. - * --------------------------------------------------------------------- */ - String *make_c_var_decl(Node *n) { - String *name = Getattr(n, "name"); - SwigType *type = Getattr(n, "type"); - String *type_str = SwigType_str(type, 0); - - if (Getattr(n, "unnamedinstance")) { - // If this is an anonymous enum, we can declare the variable as int even though we can't reference this type. - if (Strncmp(type_str, "enum $", 6) != 0) { - // Otherwise we're out of luck, with the current approach of exposing the variables directly we simply can't do it, we would need to use accessor - // functions instead to support this. - Swig_error(Getfile(n), Getline(n), "Variables of anonymous non-enum types are not supported.\n"); - return SWIG_ERROR; - } - - const char * const unnamed_end = strchr(Char(type_str) + 6, '$'); - if (!unnamed_end) { - Swig_error(Getfile(n), Getline(n), "Unsupported anonymous enum type \"%s\".\n", type_str); - return SWIG_ERROR; - } - - String* const int_type_str = NewStringf("int%s", unnamed_end + 1); - Delete(type_str); - type_str = int_type_str; - } else { - scoped_dohptr btype(SwigType_base(type)); - if (SwigType_isenum(btype)) { - // Enums are special as they can be unknown, i.e. not wrapped by SWIG. In this case we just use int instead. - if (!enumLookup(btype)) { - Replaceall(type_str, btype, "int"); - } - } else { - // Don't bother with checking if type is representable in C if we're wrapping C and not C++ anyhow: of course it is. - if (CPlusPlus) { - if (SwigType_isreference(type)) - return NIL; - - if (!SwigType_isbuiltin(btype)) - return NIL; - - // Final complication: define bool if it is used here. - if (Cmp(btype, "bool") == 0) { - Printv(sect_wrappers_types, "#include \n\n", NIL); - } - } - } - } - - String* const var_decl = NewStringEmpty(); - if (SwigType_isarray(type)) { - String *dims = Strchr(type_str, '['); - char *c = Char(type_str); - c[Len(type_str) - Len(dims) - 1] = '\0'; - Printv(var_decl, c, " ", name, "[]", NIL); - } else { - Printv(var_decl, type_str, " ", name, NIL); - } - - Delete(type_str); - - return var_decl; - } - - /* --------------------------------------------------------------------- - * emit_c_struct_def() - * - * Append the declarations of C struct members to the given string. - * Notice that this function has a side effect of outputting all enum declarations inside the struct into sect_wrappers_types directly. - * This is done to avoid gcc warnings "declaration does not declare anything" given for the anonymous enums inside the structs. - * --------------------------------------------------------------------- */ - - void emit_c_struct_def(String* out, Node *n) { - for ( Node* node = firstChild(n); node; node = nextSibling(node)) { - String* const ntype = nodeType(node); - if (Cmp(ntype, "cdecl") == 0) { - SwigType* t = NewString(Getattr(node, "type")); - SwigType_push(t, Getattr(node, "decl")); - t = SwigType_typedef_resolve_all(t); - if (SwigType_isfunction(t)) { - Swig_warning(WARN_C_UNSUPPORTTED, input_file, line_number, "Extending C struct with %s is not currently supported, ignored.\n", SwigType_str(t, 0)); - } else { - String* const var_decl = make_c_var_decl(node); - Printv(out, cindent, var_decl, ";\n", NIL); - Delete(var_decl); - } - } else if (Cmp(ntype, "enum") == 0) { - // This goes directly into sect_wrappers_types, before this struct declaration. - emit_one(node); - } else { - // WARNING: proxy declaration can be different than original code - if (Cmp(nodeType(node), "extend") == 0) - emit_c_struct_def(out, node); - } - } - } - - /* --------------------------------------------------------------------- - * classDeclaration() - * --------------------------------------------------------------------- */ - - virtual int classDeclaration(Node *n) { - if (Cmp(Getattr(n, "name"), "SWIG_CException") == 0) { - // Ignore this class only if it was already wrapped in another module, imported from this one (if exceptions are disabled, we shouldn't be even parsing - // SWIG_CException in the first place and if they're enabled, we handle it normally). - if (exceptions_support_ == exceptions_support_imported) - return SWIG_NOWRAP; - } - - return Language::classDeclaration(n); - } - - /* --------------------------------------------------------------------- - * classHandler() - * --------------------------------------------------------------------- */ - - virtual int classHandler(Node *n) { - String* const name = get_c_proxy_name(n); - - if (CPlusPlus) { - cxx_class_wrapper cxx_class_wrapper_obj(cxx_wrappers_, n); - temp_ptr_setter set_cxx_class_wrapper(&cxx_class_wrapper_, &cxx_class_wrapper_obj); - - // inheritance support: attach all members from base classes to this class - if (List *baselist = Getattr(n, "bases")) { - Iterator i; - for (i = First(baselist); i.item; i = Next(i)) { - // look for member variables and functions - Node *node; - for (node = firstChild(i.item); node; node = nextSibling(node)) { - if ((Cmp(Getattr(node, "kind"), "variable") == 0) - || (Cmp(Getattr(node, "kind"), "function") == 0)) { - if ((Cmp(Getattr(node, "access"), "public") == 0) - && (Cmp(Getattr(node, "storage"), "static") != 0)) { - // Assignment operators are not inherited in C++ and symbols without sym:name should be ignored, not copied into the derived class. - if (Getattr(node, "sym:name") && Cmp(Getattr(node, "name"), "operator =") != 0) { - String *parent_name = Getattr(parentNode(node), "name"); - Hash *dupl_name_node = is_in(Getattr(node, "name"), n); - // if there's a duplicate inherited name, due to the C++ multiple - // inheritance, change both names to avoid ambiguity - if (dupl_name_node) { - String *cif = Getattr(dupl_name_node, "c:inherited_from"); - String *old_name = Getattr(dupl_name_node, "sym:name"); - if (cif && parent_name && (Cmp(cif, parent_name) != 0)) { - Setattr(dupl_name_node, "sym:name", NewStringf("%s%s", cif ? cif : "", old_name)); - Setattr(dupl_name_node, "c:base_name", old_name); - Node *new_node = copy_node(node); - Setattr(new_node, "name", NewStringf("%s%s", parent_name, old_name)); - Setattr(new_node, "c:base_name", old_name); - appendChild(n, new_node); - } - } else { - appendChild(n, copy_node(node)); - } - } - } - } - } - } - } - - // declare type for specific class in the proxy header - Printv(sect_wrappers_types, "typedef struct SwigObj_", name, " ", name, ";\n\n", NIL); - - return Language::classHandler(n); - } else { - // this is C struct, just declare it in the proxy - String* struct_def = NewStringEmpty(); - String* const tdname = Getattr(n, "tdname"); - if (tdname) - Append(struct_def, "typedef struct {\n"); - else - Printv(struct_def, "struct ", name, " {\n", NIL); - emit_c_struct_def(struct_def, n); - if (tdname) - Printv(struct_def, "} ", tdname, ";\n\n", NIL); - else - Append(struct_def, "};\n\n"); - - Printv(sect_wrappers_types, struct_def, NIL); - Delete(struct_def); - } - return SWIG_OK; - } - - /* --------------------------------------------------------------------- - * staticmembervariableHandler() - * --------------------------------------------------------------------- */ - - virtual int staticmembervariableHandler(Node *n) { - SwigType *type = Getattr(n, "type"); - SwigType *tdtype = SwigType_typedef_resolve_all(type); - if (tdtype) { - type = tdtype; - Setattr(n, "type", type); - } - SwigType *btype = SwigType_base(type); - if (SwigType_isarray(type) && !SwigType_isbuiltin(btype)) { - // this hack applies to member objects array (not ptrs.) - SwigType_add_pointer(btype); - SwigType_add_array(btype, NewStringf("%s", SwigType_array_getdim(type, 0))); - Setattr(n, "type", btype); - } - Delete(type); - Delete(btype); - return Language::staticmembervariableHandler(n); - } - - /* --------------------------------------------------------------------- - * membervariableHandler() - * --------------------------------------------------------------------- */ - - virtual int membervariableHandler(Node *n) { - SwigType *type = Getattr(n, "type"); - SwigType *tdtype = SwigType_typedef_resolve_all(type); - if (tdtype) { - type = tdtype; - Setattr(n, "type", type); - } - SwigType *btype = SwigType_base(type); - if (SwigType_isarray(type) && !SwigType_isbuiltin(btype)) { - // this hack applies to member objects array (not ptrs.) - SwigType_add_pointer(btype); - SwigType_add_array(btype, NewStringf("%s", SwigType_array_getdim(type, 0))); - Setattr(n, "type", btype); - } - Delete(type); - Delete(btype); - return Language::membervariableHandler(n); - } - - /* --------------------------------------------------------------------- - * constructorHandler() - * --------------------------------------------------------------------- */ - - virtual int constructorHandler(Node *n) { - // For some reason, the base class implementation of constructorDeclaration() only takes care of the copy ctor automatically for the languages not - // supporting overloading (i.e. not calling allow_overloading(), as we do). So duplicate the relevant part of its code here, - if (!Abstract && Getattr(n, "copy_constructor")) { - return Language::copyconstructorHandler(n); - } - - if (GetFlag(n, "feature:extend")) { - // Pretend that all ctors added via %extend are overloaded to avoid clash between the functions created for them and the actual exported function, that - // could have the same "Foo_new" name otherwise. - SetFlag(n, "sym:overloaded"); - } - - return Language::constructorHandler(n); - } - - /* ---------------------------------------------------------------------- - * Language::enumforwardDeclaration() - * ---------------------------------------------------------------------- */ - - virtual int enumforwardDeclaration(Node *n) { - // Base implementation of this function calls enumDeclaration() for "missing" enums, i.e. those without any definition at all. This results in invalid (at - // least in C++) enum declarations in the output, so simply don't do this here. - (void) n; - return SWIG_OK; - } - - /* --------------------------------------------------------------------- - * enumDeclaration() - * --------------------------------------------------------------------- */ - - virtual int enumDeclaration(Node *n) { - if (ImportMode) - return SWIG_OK; - - if (getCurrentClass() && (cplus_mode != PUBLIC)) - return SWIG_NOWRAP; - - // We don't know here if we're going to have any non-ignored enum elements, so generate enum declaration in a temporary string. - enum_decl = NewStringEmpty(); - - // Another string for C++ enum declaration, which differs from the C one because it never uses the prefix, as C++ enums are declared in the correct scope. - cxx_enum_decl = cxx_wrappers_.is_initialized() ? NewStringEmpty() : NULL; - - // If we're currently generating a wrapper class, we need an extra level of indent. - if (cxx_enum_decl) { - if (cxx_class_wrapper_) { - cxx_enum_indent = cxx_class_wrapper_->get_indent(); - Append(cxx_enum_decl, cxx_enum_indent); - } else { - cxx_enum_indent = ""; - } - } - - String* const symname = Getattr(n, "sym:name"); - - // Preserve the typedef if we have it in the input. - bool const is_typedef = Checkattr(n, "allows_typedef", "1"); - if (is_typedef) { - Printv(enum_decl, "typedef ", NIL); - if (cxx_enum_decl) - Printv(cxx_enum_decl, "typedef ", NIL); - } - Printv(enum_decl, "enum", NIL); - if (cxx_enum_decl) - Printv(cxx_enum_decl, "enum", NIL); - - String* enum_prefix; - if (Node* const klass = getCurrentClass()) { - enum_prefix = get_c_proxy_name(klass); - } else { - enum_prefix = ns_prefix; // Possibly NULL, but that's fine. - } - - // C++ enum names don't use the prefix, as they're defined in namespace or class scope. - String* cxx_enum_prefix = NULL; - - scoped_dohptr enumname; - scoped_dohptr cxx_enumname; - - // Unnamed enums may just have no name at all or have a synthesized invalid name of the form "$unnamedN$ which is indicated by "unnamed" attribute. - if (String* const name = Getattr(n, "unnamed") ? NULL : symname) { - // If it's a typedef, its sym:name is the typedef name, but we don't want to use it here (we already use it for the typedef we generate), so use the - // actual C++ name instead. - if (is_typedef) { - // But the name may include the containing class, so get rid of it. - enumname = Swig_scopename_last(Getattr(n, "name")); - } else { - enumname = Copy(name); - } - - const bool scoped_enum = Checkattr(n, "scopedenum", "1"); - - if (cxx_enum_decl) { - // In C++ we can use actual scoped enums instead of emulating them with element prefixes. - if (scoped_enum) - Printv(cxx_enum_decl, " class", NIL); - - // And enum name itself shouldn't include the prefix neither, as this enum is either inside a namespace or inside a class, so use enumname before it - // gets updated below. - Printv(cxx_enum_decl, " ", enumname.get(), NIL); - } - - if (enum_prefix) { - enumname = NewStringf("%s_%s", enum_prefix, enumname.get()); - } - - Printv(enum_decl, " ", enumname.get(), NIL); - if (cxx_enum_decl) - Printv(cxx_enum_decl, " ", cxx_enumname.get(), NIL); - - // For scoped enums, their name should be prefixed to their elements in addition to any other prefix we use. - if (scoped_enum) { - enum_prefix = enumname.get(); - cxx_enum_prefix = cxx_enumname.get(); - } - } - - enum_prefix_ = enum_prefix ? NewStringf("%s_", enum_prefix) : NewStringEmpty(); - cxx_enum_prefix_ = cxx_enum_prefix ? NewStringf("%s_", cxx_enum_prefix) : NewStringEmpty(); - - Printv(enum_decl, " {\n", NIL); - if (cxx_enum_decl) - Printv(cxx_enum_decl, " {\n", NIL); - - int const len_orig = Len(enum_decl); - - // Emit each enum item. - Language::enumDeclaration(n); - - // Only emit the enum declaration if there were actually any items. - if (Len(enum_decl) > len_orig) { - Printv(enum_decl, "\n}", NIL); - if (cxx_enum_decl) - Printv(cxx_enum_decl, "\n", cxx_enum_indent, "}", NIL); - - if (is_typedef) { - Printv(enum_decl, " ", enum_prefix_.get(), symname, NIL); - if (cxx_enum_decl) - Printv(cxx_enum_decl, " ", symname, NIL); - } - Printv(enum_decl, ";\n\n", NIL); - if (cxx_enum_decl) - Printv(cxx_enum_decl, ";\n\n", NIL); - - Append(sect_wrappers_types, enum_decl); - if (cxx_enum_decl) { - // Enums declared in global scopes can be just defined before everything else, but nested enums have to be defined inside the declaration of the class, - // which we must be in process of creating, so output them in the appropriate section. - Append(cxx_class_wrapper_ ? cxx_wrappers_.sect_decls : cxx_wrappers_.sect_types, cxx_enum_decl); - } - } - - Delete(enum_decl); - if (cxx_enum_decl) - Delete(cxx_enum_decl); - - return SWIG_OK; - } - - /* --------------------------------------------------------------------- - * enumvalueDeclaration() - * --------------------------------------------------------------------- */ - - virtual int enumvalueDeclaration(Node *n) { - if (Cmp(Getattr(n, "ismember"), "1") == 0 && Cmp(Getattr(n, "access"), "public") != 0) - return SWIG_NOWRAP; - Swig_require("enumvalueDeclaration", n, "?enumvalueex", "?enumvalue", NIL); - - if (!GetFlag(n, "firstenumitem")) { - Printv(enum_decl, ",\n", NIL); - if (cxx_enum_decl) - Printv(cxx_enum_decl, ",\n", NIL); - } - - String* const symname = Getattr(n, "sym:name"); - Printv(enum_decl, cindent, enum_prefix_.get(), symname, NIL); - if (cxx_enum_decl) - Printv(cxx_enum_decl, cxx_enum_indent, cindent, cxx_enum_prefix_.get(), symname, NIL); - - // We only use "enumvalue", which comes from the input, and not "enumvalueex" synthesized by SWIG itself because C should use the correct value for the enum - // items without an explicit one anyhow (and "enumvalueex" can't be always used as is in C code for enum elements inside a class or even a namespace). - String *value = Getattr(n, "enumvalue"); - if (value) { - // We can't always use the raw value, check its type to see if we need to transform it. - maybe_owned_dohptr cvalue; - switch (SwigType_type(Getattr(n, "type"))) { - case T_BOOL: - // Boolean constants can't appear in C code, so replace them with their values in the simplest possible case. This is not exhaustive, of course, - // but better than nothing and doing the right thing is not simple at all as we'd need to really parse the expression, just textual substitution wouldn't - // be enough (consider e.g. an enum element called "very_true" and another one using it as its value). - if (Cmp(value, "true") == 0) { - cvalue.assign_owned(NewString("1")); - } else if (Cmp(value, "false") == 0) { - cvalue.assign_owned(NewString("0")); - } else { - Swig_error(Getfile(n), Getline(n), "Unsupported boolean enum value \"%s\".\n", value); - } - break; - - case T_CHAR: - // SWIG parser doesn't put single quotes around char values, for some reason, so add them here. - cvalue.assign_owned(NewStringf("'%(escape)s'", value)); - break; - - default: - cvalue.assign_non_owned(value); - } - - Printv(enum_decl, " = ", cvalue.get(), NIL); - if (cxx_enum_decl) - Printv(cxx_enum_decl, " = ", cvalue.get(), NIL); - } - - Swig_restore(n); - return SWIG_OK; - } - - /* --------------------------------------------------------------------- - * constantWrapper() - * --------------------------------------------------------------------- */ - - virtual int constantWrapper(Node *n) { - String *name = Getattr(n, "sym:name"); - // If it's a #define or a %constant, use raw value and hope that it will work in C as well as in C++. This is not ideal, but using "value" is even worse, as - // it doesn't even work for simple char constants such as "#define MY_X 'x'", that would end up unquoted in the generated code. - String *value = Getattr(n, "rawval"); - - if (!value) { - // Check if it's not a static member variable because its "value" is a reference to a C++ variable and won't translate to C correctly. - // - // Arguably, those should be handled in overridden memberconstantHandler() and not here. - value = Getattr(n, "staticmembervariableHandler:value"); - if (value && Equal(Getattr(n, "valuetype"), "char")) { - // We need to quote this value. - const unsigned char c = *Char(value); - Clear(value); - if (isalnum(c)) { - Printf(value, "'%c'", c); - } else { - Printf(value, "'\\x%x%x'", c / 0x10, c % 0x10); - } - } - } - - if (!value) { - // Fall back on whatever SWIG parsed the value as for all the rest. - value = Getattr(n, "value"); - } - - Printv(sect_wrappers_decl, "#define ", name, " ", value, "\n", NIL); - return SWIG_OK; - } -}; /* class C */ - -/* ----------------------------------------------------------------------------- - * swig_c() - Instantiate module - * ----------------------------------------------------------------------------- */ - -static Language *new_swig_c() { - return new C(); -} - -extern "C" Language *swig_c(void) { - return new_swig_c(); -} - -/* ----------------------------------------------------------------------------- - * Static member variables - * ----------------------------------------------------------------------------- */ - -const char *C::usage = (char *) "\ -C Options (available with -c)\n\ - -namespace ns - use prefix based on the provided namespace\n\ - -nocxx - do not generate C++ wrappers\n\ - -noexcept - do not generate exception handling code\n\ -\n"; - diff --git a/Source/Modules/swigmain.cxx b/Source/Modules/swigmain.cxx index c027f6324..d553fe893 100644 --- a/Source/Modules/swigmain.cxx +++ b/Source/Modules/swigmain.cxx @@ -26,7 +26,6 @@ can be dynamically loaded in future versions. */ extern "C" { - Language *swig_c(void); Language *swig_csharp(void); Language *swig_d(void); Language *swig_go(void); @@ -53,7 +52,6 @@ extern "C" { static TargetLanguageModule modules[] = { {"-allegrocl", NULL, "ALLEGROCL", Disabled}, - {"-c", swig_c, "C", Experimental}, {"-chicken", NULL, "CHICKEN", Disabled}, {"-clisp", NULL, "CLISP", Disabled}, {"-cffi", NULL, "CFFI", Disabled}, diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c index 075ce9097..b4be5d728 100644 --- a/Source/Swig/cwrap.c +++ b/Source/Swig/cwrap.c @@ -15,7 +15,7 @@ #include "swig.h" #include "cparse.h" -extern int UseWrapperSuffix; // from main.cxx +extern int UseWrapperSuffix; static const char *cresult_variable_name = "result"; @@ -58,8 +58,7 @@ const char *Swig_cresult_name(void) { String *Swig_cparm_name(Parm *p, int i) { String *name = NewStringf("arg%d", i + 1); if (p) { - String *lname = Getattr(p, "lname"); - if (!lname) Setattr(p, "lname", name); + Setattr(p, "lname", name); } return name; diff --git a/Source/Swig/naming.c b/Source/Swig/naming.c index 5b2692a96..517b056a7 100644 --- a/Source/Swig/naming.c +++ b/Source/Swig/naming.c @@ -181,32 +181,6 @@ String *Swig_name_mangle_type(const SwigType *s) { return mangled; } -/* ----------------------------------------------------------------------------- - * Swig_name_type() - * - * Returns the name of a type. - * ----------------------------------------------------------------------------- */ - -String *Swig_name_type(const_String_or_char_ptr tname) { - String *r, *s; - String* f = naming_hash ? Getattr(naming_hash, "type") : NULL; - - /* Don't bother doing anything else if there is no special naming format. */ - if (f) { - s = Copy(f); - Replace(s, "%c", tname, DOH_REPLACE_ANY); - } else { - s = (String*)tname; - } - - r = Swig_name_mangle_string(s); - - if (s != tname) - Delete(s); - - return r; -} - /* ----------------------------------------------------------------------------- * Swig_name_mangle_string() * diff --git a/Source/Swig/swig.h b/Source/Swig/swig.h index a5cda80cb..4b02a8101 100644 --- a/Source/Swig/swig.h +++ b/Source/Swig/swig.h @@ -276,7 +276,6 @@ extern int ParmList_is_compactdefargs(ParmList *p); extern void Swig_name_register(const_String_or_char_ptr method, const_String_or_char_ptr format); extern void Swig_name_unregister(const_String_or_char_ptr method); - extern String *Swig_name_type(const_String_or_char_ptr tname); extern String *Swig_name_mangle_string(const String *s); extern String *Swig_name_mangle_type(const SwigType *s); extern String *Swig_name_wrapper(const_String_or_char_ptr fname); diff --git a/Source/Swig/typemap.c b/Source/Swig/typemap.c index ddc60a8cf..8eabc1474 100644 --- a/Source/Swig/typemap.c +++ b/Source/Swig/typemap.c @@ -1837,7 +1837,7 @@ void Swig_typemap_attach_parms(const_String_or_char_ptr tmap_method, ParmList *p for (i = 0; i < nmatch; i++) { SwigType *type = Getattr(p, "type"); String *pname = Getattr(p, "name"); - String *lname = Swig_cparm_name(p, argnum-1); + String *lname = Getattr(p, "lname"); SwigType *mtype = Getattr(p, "tmap:match"); SwigType *matchtype = mtype ? mtype : type; diff --git a/Tools/testflags.py b/Tools/testflags.py index 24cd80469..16e4d8aee 100755 --- a/Tools/testflags.py +++ b/Tools/testflags.py @@ -9,7 +9,6 @@ def get_cflags(language, std, compiler): # use c99 or gnu99 if feature is necessary for using target language c_common = c_common + " -Wdeclaration-after-statement" cflags = { - "c":"-Werror " + c_common, "csharp":"-Werror " + c_common, "d":"-Werror " + c_common, "go":"-Werror " + c_common, @@ -41,7 +40,6 @@ def get_cxxflags(language, std, compiler): std = "c++98" cxx_common = "-fdiagnostics-show-option -std=" + std + " -Wno-long-long -Wreturn-type -Wmissing-field-initializers" cxxflags = { - "c":"-Werror " + cxx_common, "csharp":"-Werror " + cxx_common, "d":"-Werror " + cxx_common, "go":"-Werror " + cxx_common, diff --git a/configure.ac b/configure.ac index b0b9fff05..830214a74 100644 --- a/configure.ac +++ b/configure.ac @@ -2244,35 +2244,6 @@ fi AC_SUBST(RBIN) -#---------------------------------------------------------------- -# Nothing to look for in C case, just define some variables -#---------------------------------------------------------------- - -# Some tweaks for creating shared modules. -C_SO='$(SO)' - -case $host in -*-*-darwin*) - C_LDFLAGS='-dynamiclib' - C_SO=".dylib" - ;; -*-*-cygwin* | *-*-mingw*) - # Nothing special to do. - ;; -*) - # This is needed for linking with Boost which uses mutexes and does no - # harm in all the other cases. - C_LDFLAGS='-pthread' - ;; -esac - -C_LDSHARED="\$(LDSHARED) $C_LDFLAGS" -CXX_LDSHARED="\$(CXXSHARED) $C_LDFLAGS" - -AC_SUBST(C_LDSHARED) -AC_SUBST(CXX_LDSHARED) -AC_SUBST(C_SO) - #---------------------------------------------------------------- # Look for Ruby #---------------------------------------------------------------- @@ -2668,17 +2639,6 @@ if test -z "$DDEFAULTVERSION" ; then fi AC_SUBST(SKIP_D) -SKIP_C= -if test -x "$CC" || test -z "$CXX" ; then - SKIP_C="1" -fi -AC_SUBST(SKIP_C) - -SKIP_SCILAB= -if test -z "$SCILAB"; then - SKIP_SCILAB="1" -fi -AC_SUBST(SKIP_SCILAB) SKIP_GO= if test -z "$GO" ; then @@ -2898,7 +2858,6 @@ AC_CONFIG_FILES([ Examples/test-suite/ruby/Makefile Examples/test-suite/scilab/Makefile Examples/test-suite/tcl/Makefile - Examples/test-suite/c/Makefile Source/Makefile Tools/javascript/Makefile ]) @@ -2944,7 +2903,6 @@ EOF AC_OUTPUT langs="" -test -n "$SKIP_C" || langs="${langs}c " test -n "$SKIP_CSHARP" || langs="${langs}csharp " test -n "$SKIP_D" || langs="${langs}d " test -n "$SKIP_GO" || langs="${langs}go "