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:
parent
a2ee7e332d
commit
2ff3dd0d4e
10 changed files with 56 additions and 15 deletions
|
|
@ -10,7 +10,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* activate all the name warnings */
|
/* activate all the name warnings */
|
||||||
%warnfilter(+315,+321,-403);
|
%warnfilter(+314,+321,-403);
|
||||||
|
|
||||||
%{
|
%{
|
||||||
#ifdef max
|
#ifdef max
|
||||||
|
|
@ -53,6 +53,15 @@
|
||||||
B() {}
|
B() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
%template(max_i) max<int>;
|
%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; }
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,7 @@
|
||||||
%inline %{
|
%inline %{
|
||||||
int foo(int a = 1, int b = 0) {return a + b; }
|
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; }
|
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; }
|
||||||
|
|
||||||
|
%}
|
||||||
|
|
|
||||||
|
|
@ -42,3 +42,8 @@ if foo(a=1,b=2) != 3:
|
||||||
if foo(b=2) != 3:
|
if foo(b=2) != 3:
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
|
|
||||||
|
|
||||||
|
#Funtions with keywords
|
||||||
|
|
||||||
|
if foo_kw(_from=2) != 4:
|
||||||
|
raise RuntimeError
|
||||||
|
|
|
||||||
|
|
@ -640,8 +640,7 @@ using System.Runtime.InteropServices;
|
||||||
%apply unsigned long { size_t };
|
%apply unsigned long { size_t };
|
||||||
|
|
||||||
/* csharp keywords */
|
/* csharp keywords */
|
||||||
/* please test and activate */
|
%include "csharpkw.swg"
|
||||||
//%include "csharpkw.swg"
|
|
||||||
|
|
||||||
// Default enum handling
|
// Default enum handling
|
||||||
%include "enums.swg"
|
%include "enums.swg"
|
||||||
|
|
|
||||||
|
|
@ -1192,8 +1192,7 @@ SWIG_PROXY_CONSTRUCTOR(true, true, SWIGTYPE)
|
||||||
%apply unsigned long { size_t };
|
%apply unsigned long { size_t };
|
||||||
|
|
||||||
/* java keywords */
|
/* java keywords */
|
||||||
/* please test and activate */
|
%include "javakw.swg"
|
||||||
//%include "javakw.swg"
|
|
||||||
|
|
||||||
// Default enum handling
|
// Default enum handling
|
||||||
%include "enumtypesafe.swg"
|
%include "enumtypesafe.swg"
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ extern int yylex();
|
||||||
/* parser.y */
|
/* parser.y */
|
||||||
extern SwigType *Swig_cparse_type(String *);
|
extern SwigType *Swig_cparse_type(String *);
|
||||||
extern Node *Swig_cparse(File *);
|
extern Node *Swig_cparse(File *);
|
||||||
|
extern Hash *Swig_cparse_namewarn();
|
||||||
extern Hash *Swig_cparse_features();
|
extern Hash *Swig_cparse_features();
|
||||||
extern void SWIG_cparse_set_compact_default_args(int defargs);
|
extern void SWIG_cparse_set_compact_default_args(int defargs);
|
||||||
extern void SWIG_cparse_template_reduce(int treduce);
|
extern void SWIG_cparse_template_reduce(int treduce);
|
||||||
|
|
|
||||||
|
|
@ -199,6 +199,11 @@ static Hash *features_hash = 0;
|
||||||
|
|
||||||
static String *resolve_node_scope(String *cname);
|
static String *resolve_node_scope(String *cname);
|
||||||
|
|
||||||
|
Hash *Swig_cparse_namewarn() {
|
||||||
|
if (!namewarn_hash) namewarn_hash = NewHash();
|
||||||
|
return namewarn_hash;
|
||||||
|
}
|
||||||
|
|
||||||
Hash *Swig_cparse_features() {
|
Hash *Swig_cparse_features() {
|
||||||
if (!features_hash) features_hash = NewHash();
|
if (!features_hash) features_hash = NewHash();
|
||||||
return features_hash;
|
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) {
|
static void namewarn_add(const char *name, SwigType *decl, const char *warning) {
|
||||||
String *nname;
|
String *nname;
|
||||||
if (!namewarn_hash) namewarn_hash = NewHash();
|
|
||||||
if (Namespaceprefix) {
|
if (Namespaceprefix) {
|
||||||
nname = NewStringf("%s::%s",Namespaceprefix, name);
|
nname = NewStringf("%s::%s",Namespaceprefix, name);
|
||||||
} else {
|
} else {
|
||||||
nname = NewString(name);
|
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);
|
Delete(nname);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rename_inherit(String *base, String *derived) {
|
static void rename_inherit(String *base, String *derived) {
|
||||||
/* Printf(stdout,"base = '%s', derived = '%s'\n", base, derived); */
|
/* Printf(stdout,"base = '%s', derived = '%s'\n", base, derived); */
|
||||||
Swig_name_object_inherit(rename_hash,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);
|
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 */
|
/* Return the node name when it requires to emit a name warning */
|
||||||
static String *name_warning(Node *n,String *name,SwigType *decl) {
|
static String *name_warning(Node *n,String *name,SwigType *decl) {
|
||||||
/* Return in the obvious cases */
|
/* Return in the obvious cases */
|
||||||
if (!namewarn_hash || !name || !need_name_warning(n)) {
|
if (!Swig_cparse_namewarn() || !name || !need_name_warning(n)) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
String *access = Getattr(n,"access");
|
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 */
|
/* 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 */
|
/* Return if the node is a friend declaration */
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ char cvsroot_csharp_cxx[] = "$Header$";
|
||||||
|
|
||||||
#include <limits.h> // for INT_MAX
|
#include <limits.h> // for INT_MAX
|
||||||
#include "swigmod.h"
|
#include "swigmod.h"
|
||||||
|
#include "cparse.h"
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -2354,7 +2355,8 @@ class CSHARP : public Language {
|
||||||
count++;
|
count++;
|
||||||
plist = nextSibling(plist);
|
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;
|
return arg;
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ char cvsroot_java_cxx[] = "$Header$";
|
||||||
|
|
||||||
#include <limits.h> // for INT_MAX
|
#include <limits.h> // for INT_MAX
|
||||||
#include "swigmod.h"
|
#include "swigmod.h"
|
||||||
|
#include "cparse.h"
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
/* Hash type used for JNI upcall data */
|
/* Hash type used for JNI upcall data */
|
||||||
|
|
@ -2506,7 +2507,8 @@ class JAVA : public Language {
|
||||||
count++;
|
count++;
|
||||||
plist = nextSibling(plist);
|
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;
|
return arg;
|
||||||
|
|
|
||||||
|
|
@ -1270,10 +1270,20 @@ public:
|
||||||
if (i == num_required) Putc('|', parse_args); /* Optional argument separator */
|
if (i == num_required) Putc('|', parse_args); /* Optional argument separator */
|
||||||
|
|
||||||
/* Keyword argument handling */
|
/* 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);
|
Printf(kwargs,"(char *) \"%s\",", pn);
|
||||||
} else {
|
} 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 */
|
/* Look for an input typemap */
|
||||||
|
|
@ -1317,7 +1327,7 @@ public:
|
||||||
/* finish argument marshalling */
|
/* finish argument marshalling */
|
||||||
Printf(kwargs," NULL }");
|
Printf(kwargs," NULL }");
|
||||||
if (allow_kwargs) {
|
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);
|
Printf(parse_args,":%s\"", iname);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue