Java module enhancements/bug fixes since the C# module was derived off the Java one.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@4501 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
13682064c4
commit
c172b2e5e6
1 changed files with 156 additions and 133 deletions
|
|
@ -38,6 +38,7 @@ class CSHARP : public Language {
|
|||
bool variable_wrapper_flag; // Flag for when wrapping a nonstatic member variable
|
||||
bool wrapping_member_flag; // Flag for when wrapping a member variable/enum/const
|
||||
bool global_variable_flag; // Flag for when wrapping a global variable
|
||||
bool get_property_flag; //Get or set for property
|
||||
|
||||
String *jniclass_name; // JNI class name
|
||||
String *module_class_name; // module class name
|
||||
|
|
@ -62,9 +63,8 @@ class CSHARP : public Language {
|
|||
String *wrapper_conversion_code; //C++ casts for inheritance hierarchies JNI code
|
||||
String *jniclass_cppcasts_code; //C++ casts up inheritance hierarchies JNI class csharp code
|
||||
String *destructor_call; //Destructor (delete) call if any
|
||||
// String *outfile;
|
||||
String *outfile;
|
||||
String *last_property; //Last property name used for get & set
|
||||
bool get_property; //Get or set for property
|
||||
|
||||
enum type_additions {none, pointer, reference};
|
||||
|
||||
|
|
@ -91,6 +91,7 @@ class CSHARP : public Language {
|
|||
variable_wrapper_flag(false),
|
||||
wrapping_member_flag(false),
|
||||
global_variable_flag(false),
|
||||
get_property_flag(false),
|
||||
|
||||
jniclass_name(NULL),
|
||||
module_class_name(NULL),
|
||||
|
|
@ -114,7 +115,9 @@ class CSHARP : public Language {
|
|||
module_class_modifiers(NULL),
|
||||
wrapper_conversion_code(NULL),
|
||||
jniclass_cppcasts_code(NULL),
|
||||
destructor_call(NULL)
|
||||
destructor_call(NULL),
|
||||
outfile(NULL),
|
||||
last_property(NULL)
|
||||
|
||||
{
|
||||
}
|
||||
|
|
@ -196,7 +199,7 @@ class CSHARP : public Language {
|
|||
virtual int top(Node *n) {
|
||||
|
||||
/* Initialize all of the output files */
|
||||
String *outfile = Getattr(n,"outfile");
|
||||
outfile = Getattr(n,"outfile");
|
||||
|
||||
f_runtime = NewFile(outfile,"w");
|
||||
if (!f_runtime) {
|
||||
|
|
@ -283,7 +286,7 @@ class CSHARP : public Language {
|
|||
|
||||
// Generate the CSharp JNI class
|
||||
{
|
||||
String *filen = NewStringf("%s.cs", jniclass_name);
|
||||
String *filen = NewStringf("%s%s.cs", Swig_file_dirname(outfile), jniclass_name);
|
||||
File *f_java = NewFile(filen,"w");
|
||||
if(!f_java) {
|
||||
Printf(stderr,"Unable to open %s\n", filen);
|
||||
|
|
@ -322,7 +325,7 @@ class CSHARP : public Language {
|
|||
|
||||
// Generate the Java module class
|
||||
{
|
||||
String *filen = NewStringf("%s.cs", module_class_name);
|
||||
String *filen = NewStringf("%s%s.cs", Swig_file_dirname(outfile), module_class_name);
|
||||
File *f_module = NewFile(filen,"w");
|
||||
if(!f_module) {
|
||||
Printf(stderr,"Unable to open %s\n", filen);
|
||||
|
|
@ -478,12 +481,12 @@ class CSHARP : public Language {
|
|||
Not for enums and constants.
|
||||
*/
|
||||
if(proxy_flag && wrapping_member_flag && !enum_constant_flag) {
|
||||
get_property = Cmp(symname, Swig_name_set(Swig_name_member(shadow_classname, variable_name))) != 0;
|
||||
get_property_flag = Cmp(symname, Swig_name_set(Swig_name_member(shadow_classname, variable_name))) != 0;
|
||||
checkReserved(variable_name);
|
||||
|
||||
// Capitalize the first letter in the variable to create a JavaBean type getter/setter function name
|
||||
String *getter_setter_name = NewString("");
|
||||
if(!get_property)
|
||||
if(!get_property_flag)
|
||||
Printf(getter_setter_name,"set");
|
||||
else
|
||||
Printf(getter_setter_name,"get");
|
||||
|
|
@ -657,7 +660,8 @@ class CSHARP : public Language {
|
|||
}
|
||||
|
||||
// Get any Java exception classes in the throw typemap
|
||||
if (ParmList *throw_parm_list = Getattr(n,"throws")) {
|
||||
ParmList *throw_parm_list = NULL;
|
||||
if ((throw_parm_list = Getattr(n,"throws"))) {
|
||||
Swig_typemap_attach_parms("throws", throw_parm_list, f);
|
||||
for (p = throw_parm_list; p; p=nextSibling(p)) {
|
||||
if ((tm = Getattr(p,"tmap:throws"))) {
|
||||
|
|
@ -800,14 +804,25 @@ class CSHARP : public Language {
|
|||
String *tm;
|
||||
String *shadowrettype = NewString("");
|
||||
String *constants_code = NewString("");
|
||||
SwigType *original_type = t;
|
||||
|
||||
if (!addSymbol(symname,n)) return SWIG_ERROR;
|
||||
|
||||
bool is_enum_item = (Cmp(nodeType(n), "enumitem") == 0);
|
||||
|
||||
/* Adjust the enum type for the Swig_typemap_lookup. We want the same jstype typemap for all the enum items.
|
||||
* The type of each enum item depends on what value it is assigned, but is usually a C int. */
|
||||
if (is_enum_item) {
|
||||
t = NewStringf("enum %s", Getattr(parentNode(n), "sym:name"));
|
||||
Setattr(n,"type", t);
|
||||
}
|
||||
|
||||
/* Attach the non-standard typemaps to the parameter list. */
|
||||
Swig_typemap_attach_parms("jstype", l, NULL);
|
||||
|
||||
/* Get Java return types */
|
||||
bool is_return_type_java_class = false;
|
||||
|
||||
if ((tm = Swig_typemap_lookup_new("jstype",n,"",0))) {
|
||||
is_return_type_java_class = substituteJavaclassname(t, tm);
|
||||
Printf(shadowrettype, "%s", tm);
|
||||
|
|
@ -834,8 +849,9 @@ class CSHARP : public Language {
|
|||
|
||||
// The %javaconst directive determines how the constant value is obtained
|
||||
String *javaconst = Getattr(n,"feature:java:const");
|
||||
if (Cmp(nodeType(n), "enumitem") == 0 || !javaconst || Cmp(javaconst, "0") == 0) {
|
||||
// Enums and default constant handling will work with any type of C constant and initialises the Java variable from C through a JNI call.
|
||||
|
||||
if ((is_enum_item && Getattr(n,"enumvalue") == 0) || !javaconst || Cmp(javaconst, "0") == 0) {
|
||||
// Enums without value and default constant handling will work with any type of C constant and initialises the Java variable from C through a JNI call.
|
||||
|
||||
if(is_return_type_java_class) // This handles function pointers using the %constant directive
|
||||
Printf(constants_code, "new %s(%s.%s(), false);\n", shadowrettype, jniclass_name, Swig_name_get(symname));
|
||||
|
|
@ -846,6 +862,9 @@ class CSHARP : public Language {
|
|||
enum_constant_flag = true;
|
||||
variableWrapper(n);
|
||||
enum_constant_flag = false;
|
||||
} else if (is_enum_item) {
|
||||
// Alternative enum item handling will use the explicit value of the enum item and hope that it compiles as Java code
|
||||
Printf(constants_code, "%s;\n", Getattr(n,"enumvalue"));
|
||||
} else {
|
||||
// Alternative constant handling will use the C syntax to make a true Java constant and hope that it compiles as Java code
|
||||
Printf(constants_code, "%s;\n", Getattr(n,"value"));
|
||||
|
|
@ -857,6 +876,10 @@ class CSHARP : public Language {
|
|||
Printv(module_constants_code, constants_code, NIL);
|
||||
|
||||
Swig_restore(n);
|
||||
if (is_enum_item) {
|
||||
Delete(Getattr(n,"type"));
|
||||
Setattr(n,"type", original_type);
|
||||
}
|
||||
Delete(new_value);
|
||||
Delete(shadowrettype);
|
||||
Delete(constants_code);
|
||||
|
|
@ -1144,7 +1167,7 @@ class CSHARP : public Language {
|
|||
SWIG_exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
String *filen = NewStringf("%s.cs", shadow_classname);
|
||||
String *filen = NewStringf("%s%s.cs", Swig_file_dirname(outfile), shadow_classname);
|
||||
f_shadow = NewFile(filen,"w");
|
||||
if(!f_shadow) {
|
||||
Printf(stderr, "Unable to create proxy class file: %s\n", filen);
|
||||
|
|
@ -1302,7 +1325,7 @@ class CSHARP : public Language {
|
|||
Printf(shadow_code, " %s ", Getattr(n,"feature:java:methodmodifiers"));
|
||||
if (static_flag)
|
||||
Printf(shadow_code, "static ");
|
||||
Printf(shadow_code, "%s ", get_property?shadowrettype:propertytype);
|
||||
Printf(shadow_code, "%s ", get_property_flag?shadowrettype:propertytype);
|
||||
Printf(shadow_code, "%s {", variable_name);
|
||||
}
|
||||
|
||||
|
|
@ -1310,12 +1333,12 @@ class CSHARP : public Language {
|
|||
last_property = variable_name;
|
||||
|
||||
/* Start generating the shadow function */
|
||||
Printf(shadow_code, "\n %s", get_property?"get":"set");
|
||||
Printf(shadow_code, "\n %s", get_property_flag?"get":"set");
|
||||
|
||||
Printv(nativecall, " ", jniclass_name, ".", java_function_name, "(", NIL);
|
||||
if (!static_flag)
|
||||
Printv(nativecall, "swigCPtr", NIL);
|
||||
if (!get_property)
|
||||
if (!get_property_flag)
|
||||
Printv(nativecall, static_flag?"":", ", "value", NIL);
|
||||
else {
|
||||
int gencomma = !static_flag;
|
||||
|
|
@ -1378,7 +1401,7 @@ class CSHARP : public Language {
|
|||
substituteJavaclassname(t, tm);
|
||||
Replaceall(tm, "$jnicall", nativecall);
|
||||
Printf(shadow_code, " %s", tm);
|
||||
if (get_property) { //TODO: this is not the right way to do this
|
||||
if (get_property_flag) { //TODO: this is not the right way to do this
|
||||
Printf(shadow_code, "\n }\n\n");
|
||||
}
|
||||
} else {
|
||||
|
|
@ -1779,7 +1802,6 @@ class CSHARP : public Language {
|
|||
|
||||
String *arg = makeParameterName(n, p, i);
|
||||
|
||||
|
||||
// Use typemaps to transform type used in Java wrapper function (in proxy class) to type used in native function (in JNI class)
|
||||
if ((tm = Getattr(p,"tmap:javain"))) {
|
||||
substituteJavaclassname(pt, tm);
|
||||
|
|
@ -1906,7 +1928,7 @@ class CSHARP : public Language {
|
|||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void emitJavaClass(String *javaclassname, SwigType *type) {
|
||||
String *filen = NewStringf("%s.cs", javaclassname);
|
||||
String *filen = NewStringf("%s%s.cs", Swig_file_dirname(outfile), javaclassname);
|
||||
File *f_swigtype = NewFile(filen,"w");
|
||||
String *swigtype = NewString("");
|
||||
|
||||
|
|
@ -2069,4 +2091,5 @@ swig_csharp(void) {
|
|||
const char *CSHARP::usage = (char*)"\
|
||||
CSharp Options (available with -csharp)\n\
|
||||
-package <name> - set name of the assembly\n\
|
||||
-noproxy - Generate the low-level functional interface instead of proxy classes\n";
|
||||
-noproxy - Generate the low-level functional interface instead of proxy classes\n\
|
||||
\n";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue