Add support for differentiating target language statuses

Three status: Disabled, Experimental and Supported.

Any target language classified as 'Experimental' will issue new warning
524 SWIGWARN_LANG_EXPERIMENTAL.
Any target language classified as 'Disabled' will error out.

Languages will be classified in forthcoming commits.

Issue #1437
This commit is contained in:
William S Fulton 2019-02-03 21:59:48 +00:00
commit 9defd8e033
9 changed files with 116 additions and 148 deletions

View file

@ -212,6 +212,10 @@ A target language is given the 'Experimental' status when
<p> <p>
Anyone using an experimental target language is strongly urged to assist with development of the target language module if they wish to use it. Anyone using an experimental target language is strongly urged to assist with development of the target language module if they wish to use it.
</p> </p>
<p>
SWIG displays a warning when an experimental target language is used in order to set expectations and emphasize the experimental status of the target language.
The usual <a href="Warnings.html#Warnings_suppression">warning suppression</a> techniques can be used if required.
</p>
<p> <p>
The above is a short summary and further details are outlined in the <a href="Extending.html#Extending_experimental_status">Experimental status</a> section in the Extending chapter. The above is a short summary and further details are outlined in the <a href="Extending.html#Extending_experimental_status">Experimental status</a> section in the Extending chapter.

View file

@ -534,6 +534,7 @@ example.i(4) : Syntax error in input(1).
<li>521. Illegal destructor name <em>name</em>. Ignored. <li>521. Illegal destructor name <em>name</em>. Ignored.
<li>522. Use of an illegal constructor name '<em>name</em>' in %extend is deprecated, the constructor name should be '<em>name</em>'. <li>522. Use of an illegal constructor name '<em>name</em>' in %extend is deprecated, the constructor name should be '<em>name</em>'.
<li>523. Use of an illegal destructor name '<em>name</em>' in %extend is deprecated, the destructor name should be '<em>name</em>'. <li>523. Use of an illegal destructor name '<em>name</em>' in %extend is deprecated, the destructor name should be '<em>name</em>'.
<li>524. Experimental target language. Target language <em>language</em> specified by <em>lang</em> is an experimental language. Please read about SWIG experimental languages, <em>htmllink</em>.
</ul> </ul>
<H3><a name="Warnings_doxygen">17.9.6 Doxygen comments (560-599)</a></H3> <H3><a name="Warnings_doxygen">17.9.6 Doxygen comments (560-599)</a></H3>

View file

@ -468,7 +468,7 @@ check-maintainer-clean: maintainer-clean
$(srcdir)/Lib/swigwarn.swg: $(srcdir)/Source/Include/swigwarn.h $(srcdir)/Lib/swigwarn.swg: $(srcdir)/Source/Include/swigwarn.h
mkdir -p Lib mkdir -p Lib
echo "/* SWIG warning codes */" > $@ echo "/* SWIG warning codes - generated from swigwarn.h - do not edit */" > $@
cat $? | grep "^#define WARN\|/\*.*\*/\|^[ \t]*$$" | sed 's/^#define \(WARN.*[0-9][0-9]*\)\(.*\)$$/%define SWIG\1 %enddef\2/' >> $@ cat $? | grep "^#define WARN\|/\*.*\*/\|^[ \t]*$$" | sed 's/^#define \(WARN.*[0-9][0-9]*\)\(.*\)$$/%define SWIG\1 %enddef\2/' >> $@
##################################################################### #####################################################################

View file

@ -18,6 +18,8 @@
* Even though symbolic constants are used in the SWIG source, this is * Even though symbolic constants are used in the SWIG source, this is
* not always the case in SWIG interface files. Do not change the * not always the case in SWIG interface files. Do not change the
* numbers in this file. * numbers in this file.
*
* This file is used as the input for generating Lib/swigwarn.swg.
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
#ifndef SWIGWARN_H_ #ifndef SWIGWARN_H_
@ -208,6 +210,7 @@
#define WARN_LANG_ILLEGAL_DESTRUCTOR 521 #define WARN_LANG_ILLEGAL_DESTRUCTOR 521
#define WARN_LANG_EXTEND_CONSTRUCTOR 522 #define WARN_LANG_EXTEND_CONSTRUCTOR 522
#define WARN_LANG_EXTEND_DESTRUCTOR 523 #define WARN_LANG_EXTEND_DESTRUCTOR 523
#define WARN_LANG_EXPERIMENTAL 524
/* -- Doxygen comments -- */ /* -- Doxygen comments -- */

View file

@ -65,9 +65,8 @@ eswig_SOURCES = CParse/cscanner.c \
Modules/lua.cxx \ Modules/lua.cxx \
Modules/main.cxx \ Modules/main.cxx \
Modules/modula3.cxx \ Modules/modula3.cxx \
Modules/module.cxx \
Modules/mzscheme.cxx \ Modules/mzscheme.cxx \
Modules/nested.cxx \ Modules/nested.cxx \
Modules/ocaml.cxx \ Modules/ocaml.cxx \
Modules/octave.cxx \ Modules/octave.cxx \
Modules/overload.cxx \ Modules/overload.cxx \
@ -132,7 +131,7 @@ distclean-local:
# swig executable as a way of checking before and after the 'beautifying'. # swig executable as a way of checking before and after the 'beautifying'.
# Single files can be beautified with the beautify-file target, eg: 'make beautify-file INDENTFILE=chosenfile.c' # Single files can be beautified with the beautify-file target, eg: 'make beautify-file INDENTFILE=chosenfile.c'
SWIGTYPEDEFS=-T bool -T File -T DohObjInfo -T Parm -T Language -T List -T Typetab -T ModuleFactory -T ErrorMessageFormat -T Symtab -T Hash -T Scanner -T String -T DohBase -T Node -T String_or_char -T SwigType -T Dispatcher -T Wrapper -T DohStringMethods -T DohFileMethods -T DohListMethods -T DohHashMethods -T DOH -T DohIterator -T ParmList -T FILE -T HashNode -T DOHObj_or_char -T DOHFile -T DOHString -T DOHString_or_char -T UpcallData SWIGTYPEDEFS=-T bool -T File -T DohObjInfo -T Parm -T Language -T List -T TargetLanguageModule -T Typetab -T ModuleFactory -T ErrorMessageFormat -T Symtab -T Hash -T Scanner -T String -T DohBase -T Node -T String_or_char -T SwigType -T Dispatcher -T Wrapper -T DohStringMethods -T DohFileMethods -T DohListMethods -T DohHashMethods -T DOH -T DohIterator -T ParmList -T FILE -T HashNode -T DOHObj_or_char -T DOHFile -T DOHString -T DOHString_or_char -T UpcallData
INDENTBAKSDIR=../IndentBaks INDENTBAKSDIR=../IndentBaks
beautify: beautify:

View file

@ -459,7 +459,7 @@ static void SWIG_dump_runtime() {
SWIG_exit(EXIT_SUCCESS); SWIG_exit(EXIT_SUCCESS);
} }
void SWIG_getoptions(int argc, char *argv[]) { static void getoptions(int argc, char *argv[]) {
int i; int i;
// Get options // Get options
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
@ -878,7 +878,7 @@ void SWIG_getoptions(int argc, char *argv[]) {
} }
} }
int SWIG_main(int argc, char *argv[], Language *l) { int SWIG_main(int argc, char *argv[], const TargetLanguageModule *tlm) {
char *c; char *c;
/* Initialize the SWIG core */ /* Initialize the SWIG core */
@ -892,7 +892,7 @@ int SWIG_main(int argc, char *argv[], Language *l) {
// Set lang to a dummy value if no target language was specified so we // Set lang to a dummy value if no target language was specified so we
// can process options enough to handle -version, etc. // can process options enough to handle -version, etc.
lang = l ? l : new Language; lang = tlm ? tlm->fac() : new Language;
// Set up some default symbols (available in both SWIG interface files // Set up some default symbols (available in both SWIG interface files
// and C files) // and C files)
@ -956,13 +956,13 @@ int SWIG_main(int argc, char *argv[], Language *l) {
/* Check for SWIG_FEATURES environment variable */ /* Check for SWIG_FEATURES environment variable */
SWIG_getoptions(argc, argv); getoptions(argc, argv);
// Define the __cplusplus symbol // Define the __cplusplus symbol
if (CPlusPlus) if (CPlusPlus)
Preprocessor_define((DOH *) "__cplusplus __cplusplus", 0); Preprocessor_define((DOH *) "__cplusplus __cplusplus", 0);
if (!l) { if (!tlm) {
Printf(stderr, "No target language specified\n"); Printf(stderr, "No target language specified\n");
return 1; return 1;
} }
@ -1312,6 +1312,13 @@ int SWIG_main(int argc, char *argv[], Language *l) {
// Check the extension for a c/c++ file. If so, we're going to declare everything we see as "extern" // Check the extension for a c/c++ file. If so, we're going to declare everything we see as "extern"
ForceExtern = check_extension(input_file); ForceExtern = check_extension(input_file);
if (tlm->status == Experimental) {
Swig_warning(WARN_LANG_EXPERIMENTAL, "SWIG", 1, "Experimental target language. "
"Target language %s specified by %s is an experimental language. "
"Please read about SWIG experimental languages, http://swig.org/Doc4.0/Introduction.html#Introduction_experimental_status.\n",
tlm->help ? tlm->help : "", tlm->name);
}
lang->top(top); lang->top(top);
if (browse) { if (browse) {

View file

@ -1,59 +0,0 @@
/* -----------------------------------------------------------------------------
* This file is part of SWIG, which is licensed as a whole under version 3
* (or any later version) of the GNU General Public License. Some additional
* terms also apply to certain portions of SWIG. The full details of the SWIG
* license and copyrights can be found in the LICENSE and COPYRIGHT files
* included with the SWIG source code as distributed by the SWIG developers
* and at http://www.swig.org/legal.html.
*
* module.cxx
*
* This file is responsible for the module system.
* ----------------------------------------------------------------------------- */
#include "swigmod.h"
struct Module {
ModuleFactory fac;
char *name;
Module *next;
Module(const char *n, ModuleFactory f) {
fac = f;
name = new char[strlen(n) + 1];
strcpy(name, n);
next = 0;
} ~Module() {
delete[]name;
}
};
static Module *modules = 0;
/* -----------------------------------------------------------------------------
* void Swig_register_module()
*
* Register a module.
* ----------------------------------------------------------------------------- */
void Swig_register_module(const char *n, ModuleFactory f) {
Module *m = new Module(n, f);
m->next = modules;
modules = m;
}
/* -----------------------------------------------------------------------------
* Language *Swig_find_module()
*
* Given a command line option, locates the factory function.
* ----------------------------------------------------------------------------- */
ModuleFactory Swig_find_module(const char *name) {
Module *m = modules;
while (m) {
if (strcmp(m->name, name) == 0) {
return m->fac;
}
m = m->next;
}
return 0;
}

View file

@ -26,79 +26,73 @@
can be dynamically loaded in future versions. */ can be dynamically loaded in future versions. */
extern "C" { extern "C" {
Language *swig_tcl(void); Language *swig_allegrocl(void);
Language *swig_python(void); Language *swig_cffi(void);
Language *swig_perl5(void); Language *swig_chicken(void);
Language *swig_ruby(void); Language *swig_clisp(void);
Language *swig_csharp(void);
Language *swig_d(void);
Language *swig_go(void);
Language *swig_guile(void); Language *swig_guile(void);
Language *swig_java(void);
Language *swig_javascript(void);
Language *swig_lua(void);
Language *swig_modula3(void); Language *swig_modula3(void);
Language *swig_mzscheme(void); Language *swig_mzscheme(void);
Language *swig_java(void); Language *swig_ocaml(void);
Language *swig_octave(void);
Language *swig_perl5(void);
Language *swig_php(void); Language *swig_php(void);
Language *swig_php4(void); Language *swig_php4(void);
Language *swig_php5(void); Language *swig_php5(void);
Language *swig_ocaml(void);
Language *swig_octave(void);
Language *swig_pike(void); Language *swig_pike(void);
Language *swig_sexp(void); Language *swig_python(void);
Language *swig_xml(void);
Language *swig_chicken(void);
Language *swig_csharp(void);
Language *swig_allegrocl(void);
Language *swig_lua(void);
Language *swig_clisp(void);
Language *swig_cffi(void);
Language *swig_uffi(void);
Language *swig_r(void); Language *swig_r(void);
Language *swig_ruby(void);
Language *swig_scilab(void); Language *swig_scilab(void);
Language *swig_go(void); Language *swig_sexp(void);
Language *swig_d(void); Language *swig_tcl(void);
Language *swig_javascript(void); Language *swig_uffi(void);
Language *swig_xml(void);
} }
struct swig_module {
const char *name;
ModuleFactory fac;
const char *help;
};
/* Association of command line options to language modules. /* Association of command line options to language modules.
Place an entry for new language modules here, keeping the Place an entry for new language modules here, keeping the
list sorted alphabetically. */ list sorted alphabetically. */
static swig_module modules[] = { static TargetLanguageModule modules[] = {
{"-allegrocl", swig_allegrocl, "ALLEGROCL"}, {"-allegrocl", swig_allegrocl, "ALLEGROCL", Supported},
{"-chicken", swig_chicken, "CHICKEN"}, {"-chicken", swig_chicken, "CHICKEN", Supported},
{"-clisp", swig_clisp, "CLISP"}, {"-clisp", swig_clisp, "CLISP", Supported},
{"-cffi", swig_cffi, "CFFI"}, {"-cffi", swig_cffi, "CFFI", Supported},
{"-csharp", swig_csharp, "C#"}, {"-csharp", swig_csharp, "C#", Supported},
{"-d", swig_d, "D"}, {"-d", swig_d, "D", Supported},
{"-go", swig_go, "Go"}, {"-go", swig_go, "Go", Supported},
{"-guile", swig_guile, "Guile"}, {"-guile", swig_guile, "Guile", Supported},
{"-java", swig_java, "Java"}, {"-java", swig_java, "Java", Supported},
{"-javascript", swig_javascript, "Javascript"}, {"-javascript", swig_javascript, "Javascript", Supported},
{"-lua", swig_lua, "Lua"}, {"-lua", swig_lua, "Lua", Supported},
{"-modula3", swig_modula3, "Modula 3"}, {"-modula3", swig_modula3, "Modula 3", Supported},
{"-mzscheme", swig_mzscheme, "Mzscheme"}, {"-mzscheme", swig_mzscheme, "Mzscheme", Supported},
{"-ocaml", swig_ocaml, "Ocaml"}, {"-ocaml", swig_ocaml, "Ocaml", Supported},
{"-octave", swig_octave, "Octave"}, {"-octave", swig_octave, "Octave", Supported},
{"-perl", swig_perl5, "Perl"}, {"-perl", swig_perl5, "Perl", Supported},
{"-perl5", swig_perl5, 0}, {"-perl5", swig_perl5, NULL, Supported},
{"-php", swig_php, 0}, {"-php", swig_php, NULL, Supported},
{"-php4", swig_php4, 0}, {"-php4", swig_php4, NULL, Supported},
{"-php5", swig_php5, 0}, {"-php5", swig_php5, NULL, Supported},
{"-php7", swig_php, "PHP7"}, {"-php7", swig_php, "PHP7", Supported},
{"-pike", swig_pike, "Pike"}, {"-pike", swig_pike, "Pike", Supported},
{"-python", swig_python, "Python"}, {"-python", swig_python, "Python", Supported},
{"-r", swig_r, "R (aka GNU S)"}, {"-r", swig_r, "R (aka GNU S)", Supported},
{"-ruby", swig_ruby, "Ruby"}, {"-ruby", swig_ruby, "Ruby", Supported},
{"-scilab", swig_scilab, "Scilab"}, {"-scilab", swig_scilab, "Scilab", Supported},
{"-sexp", swig_sexp, "Lisp S-Expressions"}, {"-sexp", swig_sexp, "Lisp S-Expressions", Supported},
{"-tcl", swig_tcl, "Tcl"}, {"-tcl", swig_tcl, "Tcl", Supported},
{"-tcl8", swig_tcl, 0}, {"-tcl8", swig_tcl, NULL, Supported},
{"-uffi", swig_uffi, "Common Lisp / UFFI"}, {"-uffi", swig_uffi, "Common Lisp / UFFI", Supported},
{"-xml", swig_xml, "XML"}, {"-xml", swig_xml, "XML", Supported},
{NULL, NULL, NULL} {NULL, NULL, NULL, Disabled}
}; };
#ifdef MACSWIG #ifdef MACSWIG
@ -230,8 +224,7 @@ static void merge_options_files(int *argc, char ***argv) {
int main(int margc, char **margv) { int main(int margc, char **margv) {
int i; int i;
Language *dl = 0; const TargetLanguageModule *language_module = 0;
ModuleFactory fac = 0;
int argc; int argc;
char **argv; char **argv;
@ -244,26 +237,40 @@ int main(int margc, char **margv) {
argc = ccommand(&argv); argc = ccommand(&argv);
#endif #endif
/* Register built-in modules */
for (i = 0; modules[i].name; i++) {
Swig_register_module(modules[i].name, modules[i].fac);
}
Swig_init_args(argc, argv); Swig_init_args(argc, argv);
/* Get options */ /* Get options */
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
if (argv[i]) { if (argv[i]) {
fac = Swig_find_module(argv[i]); bool is_target_language_module = false;
if (fac) { for (int j = 0; modules[j].name; j++) {
dl = (fac) (); if (strcmp(modules[j].name, argv[i]) == 0) {
language_module = &modules[j];
is_target_language_module = true;
break;
}
}
if (is_target_language_module) {
Swig_mark_arg(i); Swig_mark_arg(i);
if (language_module->status == Disabled) {
if (language_module->help)
Printf(stderr, "Target language option %s (%s) is no longer supported.\n", language_module->name, language_module->help);
else
Printf(stderr, "Target language option %s is no longer supported.\n", language_module->name);
SWIG_exit(EXIT_FAILURE);
}
} else if ((strcmp(argv[i], "-help") == 0) || (strcmp(argv[i], "--help") == 0)) { } else if ((strcmp(argv[i], "-help") == 0) || (strcmp(argv[i], "--help") == 0)) {
if (strcmp(argv[i], "--help") == 0) if (strcmp(argv[i], "--help") == 0)
strcpy(argv[i], "-help"); strcpy(argv[i], "-help");
Printf(stdout, "Target Language Options\n"); Printf(stdout, "Supported Target Language Options\n");
for (int j = 0; modules[j].name; j++) { for (int j = 0; modules[j].name; j++) {
if (modules[j].help) { if (modules[j].help && modules[j].status == Supported) {
Printf(stdout, " %-15s - Generate %s wrappers\n", modules[j].name, modules[j].help);
}
}
Printf(stdout, "\nExperimental Target Language Options\n");
for (int j = 0; modules[j].name; j++) {
if (modules[j].help && modules[j].status == Experimental) {
Printf(stdout, " %-15s - Generate %s wrappers\n", modules[j].name, modules[j].help); Printf(stdout, " %-15s - Generate %s wrappers\n", modules[j].name, modules[j].help);
} }
} }
@ -272,7 +279,7 @@ int main(int margc, char **margv) {
} }
} }
int res = SWIG_main(argc, argv, dl); int res = SWIG_main(argc, argv, language_module);
return res; return res;
} }

View file

@ -354,7 +354,21 @@ private:
static Language *this_; static Language *this_;
}; };
int SWIG_main(int, char **, Language *); extern "C" {
void SWIG_typemap_lang(const char *);
typedef Language *(*ModuleFactory) (void);
}
enum Status {Disabled, Experimental, Supported};
struct TargetLanguageModule {
const char *name;
ModuleFactory fac;
const char *help;
Status status;
};
int SWIG_main(int argc, char *argv[], const TargetLanguageModule *tlm);
void emit_parameter_variables(ParmList *l, Wrapper *f); void emit_parameter_variables(ParmList *l, Wrapper *f);
void emit_return_variable(Node *n, SwigType *rt, Wrapper *f); void emit_return_variable(Node *n, SwigType *rt, Wrapper *f);
void SWIG_exit(int); /* use EXIT_{SUCCESS,FAILURE} */ void SWIG_exit(int); /* use EXIT_{SUCCESS,FAILURE} */
@ -391,14 +405,6 @@ void Swig_director_emit_dynamic_cast(Node *n, Wrapper *f);
void Swig_director_parms_fixup(ParmList *parms); void Swig_director_parms_fixup(ParmList *parms);
/* directors.cxx end */ /* directors.cxx end */
extern "C" {
void SWIG_typemap_lang(const char *);
typedef Language *(*ModuleFactory) (void);
}
void Swig_register_module(const char *name, ModuleFactory fac);
ModuleFactory Swig_find_module(const char *name);
/* Utilities */ /* Utilities */
int is_public(Node *n); int is_public(Node *n);