bind: sanitize parameter names
Package names, type names and method names are already sanitized.
Extend that to parameter names as well.
Change-Id: I408024c5e2f9561c37e8059a2b53199ee1afaef6
Reviewed-on: https://go-review.googlesource.com/31519
Reviewed-by: David Crawshaw <crawshaw@golang.org>
diff --git a/bind/genjava.go b/bind/genjava.go
index 1989210..6ef0a30 100644
--- a/bind/genjava.go
+++ b/bind/genjava.go
@@ -634,7 +634,7 @@
if !javaLetterDigitRE.MatchString(name) {
name = fmt.Sprintf("p%d", pos)
}
- return name
+ return javaNameReplacer(name)
}
func (g *JavaGen) genFuncSignature(o *types.Func, jm *java.Func, hasThis bool) {
diff --git a/bind/genobjc.go b/bind/genobjc.go
index 67918c3..c758242 100644
--- a/bind/genobjc.go
+++ b/bind/genobjc.go
@@ -573,7 +573,8 @@
}
func (g *ObjcGen) paramName(params *types.Tuple, pos int) string {
- return basicParamName(params, pos)
+ name := basicParamName(params, pos)
+ return objcNameReplacer(name)
}
func (g *ObjcGen) genFuncH(obj *types.Func) {
diff --git a/bind/testdata/classes.java.c.golden b/bind/testdata/classes.java.c.golden
index fd89a34..6b90e75 100644
--- a/bind/testdata/classes.java.c.golden
+++ b/bind/testdata/classes.java.c.golden
@@ -240,8 +240,8 @@
JNIEXPORT void JNICALL
Java_go_java_Runnable_run(JNIEnv* env, jobject __this__) {
int32_t o = go_seq_to_refnum_go(env, __this__);
- int32_t _this = go_seq_to_refnum(env, __this__);
- proxyjava_Runnable_Run(o, _this);
+ int32_t _this_ = go_seq_to_refnum(env, __this__);
+ proxyjava_Runnable_Run(o, _this_);
}
JNIEXPORT void JNICALL
diff --git a/bind/testdata/keywords.go b/bind/testdata/keywords.go
index 46ecb52..d5a7733 100644
--- a/bind/testdata/keywords.go
+++ b/bind/testdata/keywords.go
@@ -59,3 +59,6 @@
Null()
True()
}
+
+func Const(id string) {}
+func Static(strictfp string) {}
diff --git a/bind/testdata/keywords.go.golden b/bind/testdata/keywords.go.golden
index 58a7c3d..d9fba9b 100644
--- a/bind/testdata/keywords.go.golden
+++ b/bind/testdata/keywords.go.golden
@@ -607,3 +607,15 @@
func (p *proxykeywords_KeywordCaller) While() {
C.cproxykeywords_KeywordCaller_While(C.int32_t(p.Bind_proxy_refnum__()))
}
+
+//export proxykeywords__Const
+func proxykeywords__Const(param_id C.nstring) {
+ _param_id := decodeString(param_id)
+ keywords.Const(_param_id)
+}
+
+//export proxykeywords__Static
+func proxykeywords__Static(param_strictfp C.nstring) {
+ _param_strictfp := decodeString(param_strictfp)
+ keywords.Static(_param_strictfp)
+}
diff --git a/bind/testdata/keywords.java.c.golden b/bind/testdata/keywords.java.c.golden
index a84742d..9dd20f6 100644
--- a/bind/testdata/keywords.java.c.golden
+++ b/bind/testdata/keywords.java.c.golden
@@ -129,6 +129,18 @@
}
JNIEXPORT void JNICALL
+Java_go_keywords_Keywords_const_1(JNIEnv* env, jclass _clazz, jstring id) {
+ nstring _id = go_seq_from_java_string(env, id);
+ proxykeywords__Const(_id);
+}
+
+JNIEXPORT void JNICALL
+Java_go_keywords_Keywords_static_1(JNIEnv* env, jclass _clazz, jstring strictfp_) {
+ nstring _strictfp_ = go_seq_from_java_string(env, strictfp_);
+ proxykeywords__Static(_strictfp_);
+}
+
+JNIEXPORT void JNICALL
Java_go_keywords_Keywords_00024proxyKeywordCaller_abstract_1(JNIEnv* env, jobject __this__) {
int32_t o = go_seq_to_refnum_go(env, __this__);
proxykeywords_KeywordCaller_Abstract(o);
diff --git a/bind/testdata/keywords.java.golden b/bind/testdata/keywords.java.golden
index 04e7cb4..4334f81 100644
--- a/bind/testdata/keywords.java.golden
+++ b/bind/testdata/keywords.java.golden
@@ -151,4 +151,6 @@
}
+ public static native void const_(String id);
+ public static native void static_(String strictfp_);
}
diff --git a/bind/testdata/keywords.objc.h.golden b/bind/testdata/keywords.objc.h.golden
index d8ba6f5..11b6f95 100644
--- a/bind/testdata/keywords.objc.h.golden
+++ b/bind/testdata/keywords.objc.h.golden
@@ -69,6 +69,10 @@
- (void)while;
@end
+FOUNDATION_EXPORT void GoKeywordsConst(NSString* id_);
+
+FOUNDATION_EXPORT void GoKeywordsStatic(NSString* strictfp);
+
@class GoKeywordsKeywordCaller;
@interface GoKeywordsKeywordCaller : NSObject <goSeqRefInterface, GoKeywordsKeywordCaller> {
diff --git a/bind/testdata/keywords.objc.m.golden b/bind/testdata/keywords.objc.m.golden
index 837ce6d..2454880 100644
--- a/bind/testdata/keywords.objc.m.golden
+++ b/bind/testdata/keywords.objc.m.golden
@@ -286,6 +286,16 @@
+void GoKeywordsConst(NSString* id_) {
+ nstring _id_ = go_seq_from_objc_string(id_);
+ proxykeywords__Const(_id_);
+}
+
+void GoKeywordsStatic(NSString* strictfp) {
+ nstring _strictfp = go_seq_from_objc_string(strictfp);
+ proxykeywords__Static(_strictfp);
+}
+
void cproxykeywords_KeywordCaller_Abstract(int32_t refnum) {
@autoreleasepool {
GoKeywordsKeywordCaller* o = go_seq_objc_from_refnum(refnum);