replace bad parameter names when neccessary

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@7699 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2005-10-21 10:43:41 +00:00
commit 2ff3dd0d4e
10 changed files with 56 additions and 15 deletions

View file

@ -10,7 +10,7 @@
*/
/* activate all the name warnings */
%warnfilter(+315,+321,-403);
%warnfilter(+314,+321,-403);
%{
#ifdef max
@ -53,6 +53,15 @@
B() {}
};
}
%template(max_i) max<int>;
%inline {
/* silently rename the parameter names in csharp/java */
double foo(double in, double out) { return 1.0; }
double bar(double native, bool boolean) { return 1.0; }
}

View file

@ -46,6 +46,7 @@
// Functions
%inline %{
int foo(int a = 1, int b = 0) {return a + b; }
template<typename T> T templatedfunction(T a = 1, T b = 0) { return a + b; }
%}
@ -72,3 +73,12 @@
}
%}
// Functions with keywords
%warnfilter(-314);
%inline %{
/* silently rename the parameter names in python */
int foo_kw(int from = 1, int except = 2) {return from + except; }
%}

View file

@ -42,3 +42,8 @@ if foo(a=1,b=2) != 3:
if foo(b=2) != 3:
raise RuntimeError
#Funtions with keywords
if foo_kw(_from=2) != 4:
raise RuntimeError

View file

@ -640,8 +640,7 @@ using System.Runtime.InteropServices;
%apply unsigned long { size_t };
/* csharp keywords */
/* please test and activate */
//%include "csharpkw.swg"
%include "csharpkw.swg"
// Default enum handling
%include "enums.swg"

View file

@ -1192,8 +1192,7 @@ SWIG_PROXY_CONSTRUCTOR(true, true, SWIGTYPE)
%apply unsigned long { size_t };
/* java keywords */
/* please test and activate */
//%include "javakw.swg"
%include "javakw.swg"
// Default enum handling
%include "enumtypesafe.swg"

View file

@ -43,6 +43,7 @@ extern int yylex();
/* parser.y */
extern SwigType *Swig_cparse_type(String *);
extern Node *Swig_cparse(File *);
extern Hash *Swig_cparse_namewarn();
extern Hash *Swig_cparse_features();
extern void SWIG_cparse_set_compact_default_args(int defargs);
extern void SWIG_cparse_template_reduce(int treduce);

View file

@ -199,6 +199,11 @@ static Hash *features_hash = 0;
static String *resolve_node_scope(String *cname);
Hash *Swig_cparse_namewarn() {
if (!namewarn_hash) namewarn_hash = NewHash();
return namewarn_hash;
}
Hash *Swig_cparse_features() {
if (!features_hash) features_hash = NewHash();
return features_hash;
@ -271,21 +276,20 @@ static void rename_add(const char *name, SwigType *decl, const char *newname, Pa
static void namewarn_add(const char *name, SwigType *decl, const char *warning) {
String *nname;
if (!namewarn_hash) namewarn_hash = NewHash();
if (Namespaceprefix) {
nname = NewStringf("%s::%s",Namespaceprefix, name);
} else {
nname = NewString(name);
}
Swig_name_object_set(namewarn_hash,nname,decl,NewString(warning));
Swig_name_object_set(Swig_cparse_namewarn(),nname,decl,NewString(warning));
Delete(nname);
}
static void rename_inherit(String *base, String *derived) {
/* Printf(stdout,"base = '%s', derived = '%s'\n", base, derived); */
Swig_name_object_inherit(rename_hash,base,derived);
Swig_name_object_inherit(namewarn_hash,base,derived);
Swig_name_object_inherit(Swig_cparse_namewarn(),base,derived);
Swig_name_object_inherit(features_hash,base,derived);
}
@ -339,7 +343,7 @@ static String *make_unnamed() {
/* Return the node name when it requires to emit a name warning */
static String *name_warning(Node *n,String *name,SwigType *decl) {
/* Return in the obvious cases */
if (!namewarn_hash || !name || !need_name_warning(n)) {
if (!Swig_cparse_namewarn() || !name || !need_name_warning(n)) {
return 0;
} else {
String *access = Getattr(n,"access");
@ -350,7 +354,7 @@ static String *name_warning(Node *n,String *name,SwigType *decl) {
}
/* Check to see if the name is in the hash */
return Swig_name_object_get(namewarn_hash,Namespaceprefix,name,decl);
return Swig_name_object_get(Swig_cparse_namewarn(),Namespaceprefix,name,decl);
}
/* Return if the node is a friend declaration */

View file

@ -14,6 +14,7 @@ char cvsroot_csharp_cxx[] = "$Header$";
#include <limits.h> // for INT_MAX
#include "swigmod.h"
#include "cparse.h"
#include <ctype.h>
@ -2354,7 +2355,8 @@ class CSHARP : public Language {
count++;
plist = nextSibling(plist);
}
arg = (!pn || (count > 1)) ? NewStringf("arg%d",arg_num) : Copy(pn);
String *wrn = pn ? Swig_name_object_get(Swig_cparse_namewarn(),0,pn,0) : 0;
arg = (!pn || (count > 1) || wrn) ? NewStringf("arg%d",arg_num) : Copy(pn);
}
return arg;

View file

@ -14,6 +14,7 @@ char cvsroot_java_cxx[] = "$Header$";
#include <limits.h> // for INT_MAX
#include "swigmod.h"
#include "cparse.h"
#include <ctype.h>
/* Hash type used for JNI upcall data */
@ -2506,7 +2507,8 @@ class JAVA : public Language {
count++;
plist = nextSibling(plist);
}
arg = (!pn || (count > 1)) ? NewStringf("arg%d",arg_num) : Copy(pn);
String *wrn = pn ? Swig_name_object_get(Swig_cparse_namewarn(),0,pn,0) : 0;
arg = (!pn || (count > 1) || wrn) ? NewStringf("arg%d",arg_num) : Copy(pn);
}
return arg;

View file

@ -1270,10 +1270,20 @@ public:
if (i == num_required) Putc('|', parse_args); /* Optional argument separator */
/* Keyword argument handling */
if (Len(pn)) {
String *wrn = pn ? Swig_name_object_get(Swig_cparse_namewarn(),0,pn,0) : 0;
if (!wrn && Len(pn)) {
Printf(kwargs,"(char *) \"%s\",", pn);
} else {
Printf(kwargs,"\"arg%d\",", i+1);
if (wrn) {
/*
we change the parameter name just a little.
do we need to emit a warning?
*/
Printf(kwargs,"(char *) \"_%s\",", pn);
Swig_warning(0,Getfile(n),Getline(n), "%s, renaming parameter to _%s\n", wrn, pn);
} else {
Printf(kwargs,"(char *)\"arg%d\",", i+1);
}
}
/* Look for an input typemap */
@ -1317,7 +1327,7 @@ public:
/* finish argument marshalling */
Printf(kwargs," NULL }");
if (allow_kwargs) {
Printv(f->locals,tab4, "char *kwnames[] = ", kwargs, ";\n", NIL);
Printv(f->locals,tab4, "char * kwnames[] = ", kwargs, ";\n", NIL);
}
Printf(parse_args,":%s\"", iname);