From 9c323f4a70d687ceda3700e8e193263be04f04f3 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 19 Jun 2008 20:02:13 +0000 Subject: [PATCH] Add R keyword support. Rename keywords for successful compilation of Java and C# code. More consistent keyword warnings across the different languages. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10530 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 9 +++++++++ Examples/test-suite/keyword_rename.i | 8 +++++++- Lib/chicken/chickenkw.swg | 2 +- Lib/csharp/csharpkw.swg | 2 +- Lib/java/javakw.swg | 2 +- Lib/ocaml/ocamlkw.swg | 2 +- Lib/perl5/perlkw.swg | 4 ++-- Lib/php4/php4kw.swg | 10 +++++----- Lib/pike/pikekw.swg | 2 +- Lib/python/pythonkw.swg | 4 ++-- Lib/r/r.swg | 2 ++ Lib/r/rkw.swg | 17 +++++++++++++++++ Lib/ruby/rubykw.swg | 2 +- Source/Modules/r.cxx | 3 +++ 14 files changed, 53 insertions(+), 16 deletions(-) create mode 100644 Lib/r/rkw.swg diff --git a/CHANGES.current b/CHANGES.current index ed1b7d2d0..5df243eca 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,15 @@ Version 1.3.36 (in progress) ============================= +06/19/2008: wsfulton + [Java, C#] C# and Java keywords will be renamed instead of just issuing a warning + and then generating uncompileable code. Warning 314 gives the new name when a + keyword is found. + +06/19/2008: wsfulton + [R] Keyword handling added. R Keywords will be renamed as necessary. + Warning 314 gives the new name when a keyword is found. + 06/17/2008: mgossage [Lua] Added missing support for bool& and bool*. Added runtest for li_typemaps testcase. (Bug #1938142) diff --git a/Examples/test-suite/keyword_rename.i b/Examples/test-suite/keyword_rename.i index 4323304cf..28d813499 100644 --- a/Examples/test-suite/keyword_rename.i +++ b/Examples/test-suite/keyword_rename.i @@ -3,7 +3,9 @@ */ %module keyword_rename -%warnfilter(SWIGWARN_PARSE_KEYWORD); + +#pragma SWIG nowarn=SWIGWARN_PARSE_KEYWORD + %inline %{ #define KW(x, y) int x (int y) { return y;} @@ -21,6 +23,10 @@ KW(use, next) KW(implements, native) KW(byte, final) +/* C# Keywords */ +KW(string, out) +struct sealed {}; + %} diff --git a/Lib/chicken/chickenkw.swg b/Lib/chicken/chickenkw.swg index f01faf14f..d2c26c74c 100644 --- a/Lib/chicken/chickenkw.swg +++ b/Lib/chicken/chickenkw.swg @@ -3,7 +3,7 @@ /* Warnings for certain CHICKEN keywords. From Section 7.1.1 of Revised^5 Report on the Algorithmic Language Scheme */ -#define CHICKENKW(x) %namewarn("314:" #x " is a R^5RS syntatic keyword") #x +#define CHICKENKW(x) %namewarn("314: '" #x "' is a R^5RS syntatic keyword") #x CHICKENKW(else); CHICKENKW(=>); diff --git a/Lib/csharp/csharpkw.swg b/Lib/csharp/csharpkw.swg index c96042d2d..9a6d979f1 100644 --- a/Lib/csharp/csharpkw.swg +++ b/Lib/csharp/csharpkw.swg @@ -2,7 +2,7 @@ #define CSHARP_CSHARPKW_SWG_ /* Warnings for C# keywords */ -#define CSHARPKW(x) %namewarn("314:" #x " is a csharp keyword") #x +#define CSHARPKW(x) %keywordwarn("'" `x` "' is a C# keyword, renaming to '_" `x` "'",rename="_%s") `x` /* from diff --git a/Lib/java/javakw.swg b/Lib/java/javakw.swg index 9dcd97062..99cd54770 100644 --- a/Lib/java/javakw.swg +++ b/Lib/java/javakw.swg @@ -2,7 +2,7 @@ #define JAVA_JAVAKW_SWG_ /* Warnings for Java keywords */ -#define JAVAKW(x) %namewarn("314:" #x " is a java keyword") #x +#define JAVAKW(x) %keywordwarn("'" `x` "' is a java keyword, renaming to '_"`x`"'",rename="_%s") `x` /* from diff --git a/Lib/ocaml/ocamlkw.swg b/Lib/ocaml/ocamlkw.swg index ba06f238e..9b9096e2b 100644 --- a/Lib/ocaml/ocamlkw.swg +++ b/Lib/ocaml/ocamlkw.swg @@ -2,7 +2,7 @@ #define OCAML_OCAMLKW_SWG_ /* Warnings for Ocaml keywords */ -#define OCAMLKW(x) %namewarn("314:" #x " is a ocaml keyword and it will properly renamed") #x +#define OCAMLKW(x) %namewarn("314: '" #x "' is a ocaml keyword and it will properly renamed") #x /* from diff --git a/Lib/perl5/perlkw.swg b/Lib/perl5/perlkw.swg index 71a229c66..00648e0bf 100644 --- a/Lib/perl5/perlkw.swg +++ b/Lib/perl5/perlkw.swg @@ -1,6 +1,6 @@ /* Warnings for Perl keywords */ -#define PERLKW(x) %keywordwarn(`x` " is a perl keyword") `x` -#define PERLBN(x) %builtinwarn(`x` " conflicts with a built-in name in perl") "::" `x` +#define PERLKW(x) %keywordwarn("'" `x` "' is a perl keyword") `x` +#define PERLBN(x) %builtinwarn("'" `x` "' conflicts with a built-in name in perl") "::" `x` /* diff --git a/Lib/php4/php4kw.swg b/Lib/php4/php4kw.swg index 0d28994c5..a6b519445 100644 --- a/Lib/php4/php4kw.swg +++ b/Lib/php4/php4kw.swg @@ -8,15 +8,15 @@ * when used as class methods. * ----------------------------------------------------------------------------- */ -#define PHPKW(x) %keywordwarn(`x` " is a php keyword, renamed as c_"`x`,sourcefmt="%(lower)s", rename="c_%s",fullname=1) `x` +#define PHPKW(x) %keywordwarn("'" `x` "' is a php keyword, renamed as 'c_" `x` "'",sourcefmt="%(lower)s", rename="c_%s",fullname=1) `x` %define PHPCN(x) -%keywordwarn(`x` " is a php reserved class name, class renamed as c_"`x`,%$isclass,rename="c_%s") `x`; -%keywordwarn(`x` " is a php reserved class name, constructor renamed as c_"`x`,%$isconstructor,rename="c_%s") `x`; +%keywordwarn("'" `x` "' is a php reserved class name, class renamed as 'c_" `x` "'",%$isclass,rename="c_%s") `x`; +%keywordwarn("'" `x` "' is a php reserved class name, constructor renamed as 'c_" `x` "'",%$isconstructor,rename="c_%s") `x`; %enddef -#define PHPBN1(x) %builtinwarn(`x` " conflicts with a built-in name in php",sourcefmt="%(lower)s",fullname=1) `x` -#define PHPBN2(x) %builtinwarn(`x` " conflicts with a built-in name in php") "::" `x` +#define PHPBN1(x) %builtinwarn("'" `x` "' conflicts with a built-in name in php",sourcefmt="%(lower)s",fullname=1) `x` +#define PHPBN2(x) %builtinwarn("'" `x` "' conflicts with a built-in name in php") "::" `x` /* diff --git a/Lib/pike/pikekw.swg b/Lib/pike/pikekw.swg index 85fd091a8..844b1f189 100644 --- a/Lib/pike/pikekw.swg +++ b/Lib/pike/pikekw.swg @@ -2,7 +2,7 @@ #define PIKE_PIKEKW_SWG_ /* Warnings for Pike keywords */ -#define PIKEKW(x) %namewarn("314:" #x " is a pike keyword") #x +#define PIKEKW(x) %namewarn("314: '" #x "' is a pike keyword") #x /* from diff --git a/Lib/python/pythonkw.swg b/Lib/python/pythonkw.swg index f57d34ce4..2ee233516 100644 --- a/Lib/python/pythonkw.swg +++ b/Lib/python/pythonkw.swg @@ -2,8 +2,8 @@ Warnings for Python keywords, built-in names and bad names. */ -#define PYTHONKW(x) %keywordwarn(`x` " is a python keyword, symbol will be renamed as '_" `x`"'", rename="_%s") `x` -#define PYTHONBN(x) %builtinwarn(`x` " conflicts with a built-in name in python") "::"`x` +#define PYTHONKW(x) %keywordwarn("'" `x` "' is a python keyword, renaming to '_" `x` "'", rename="_%s") `x` +#define PYTHONBN(x) %builtinwarn("'" `x` "' conflicts with a built-in name in python") "::"`x` /* diff --git a/Lib/r/r.swg b/Lib/r/r.swg index 3095529a0..0ab7e11a0 100644 --- a/Lib/r/r.swg +++ b/Lib/r/r.swg @@ -12,6 +12,8 @@ SWIGEXPORT void SWIG_init(void) { %} +%include + #define %Rruntime %insert("s") #define SWIG_Object SEXP diff --git a/Lib/r/rkw.swg b/Lib/r/rkw.swg new file mode 100644 index 000000000..24bb5d83c --- /dev/null +++ b/Lib/r/rkw.swg @@ -0,0 +1,17 @@ +/* + Warnings for R keywords, built-in names and bad names. +*/ + +#define RKW(x) %keywordwarn("'" `x` "' is a R keyword, renaming to '_" `x`"'", rename="_%s") `x` + + +/* + Warnings for R keywords + REFERENCE ???? +*/ + +RKW(except); +RKW(in); +RKW(next); + +#undef RKW diff --git a/Lib/ruby/rubykw.swg b/Lib/ruby/rubykw.swg index fec47baff..194687b95 100644 --- a/Lib/ruby/rubykw.swg +++ b/Lib/ruby/rubykw.swg @@ -2,7 +2,7 @@ #define RUBY_RUBYKW_SWG_ /* Warnings for Ruby keywords */ -#define RUBYKW(x) %keywordwarn("'" `x` "' is a ruby keyword, and it will renamed as 'C_"`x`"'",rename="C_%s",fullname=1) `x` +#define RUBYKW(x) %keywordwarn("'" `x` "' is a ruby keyword, renaming to 'C_" `x` "'",rename="C_%s",fullname=1) `x` /* diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index 989136a9d..32c7a3925 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -1841,6 +1841,9 @@ int R::functionWrapper(Node *n) { String *name = Getattr(p,"name"); String *lname = Getattr(p,"lname"); + // R keyword renaming + if (name && Swig_name_warning(p, 0, name, 0)) + name = 0; /* If we have a :: in the parameter name because we are accessing a static member of a class, say, then we need to remove that prefix. */