csgetcptr and csptrconstructormodifiers typemap replaced by the csbody/csbody_derived typemap
csclassmodifiers typemap now contains the class type imclassclassmodifiers and moduleclassmodifiers pragmas now contain the class type $module special variable support git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5969 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
83f70b7d17
commit
ad46ed2214
1 changed files with 46 additions and 66 deletions
|
|
@ -185,6 +185,14 @@ class CSHARP : public Language {
|
||||||
|
|
||||||
virtual int top(Node *n) {
|
virtual int top(Node *n) {
|
||||||
|
|
||||||
|
// Get any options set in the module directive
|
||||||
|
Node* optionsnode = Getattr( Getattr(n,"module"), "options");
|
||||||
|
|
||||||
|
if (optionsnode) {
|
||||||
|
if (Getattr(optionsnode,"imclassname"))
|
||||||
|
imclass_name = Copy(Getattr(optionsnode,"imclassname"));
|
||||||
|
}
|
||||||
|
|
||||||
/* Initialize all of the output files */
|
/* Initialize all of the output files */
|
||||||
String *outfile = Getattr(n,"outfile");
|
String *outfile = Getattr(n,"outfile");
|
||||||
|
|
||||||
|
|
@ -202,13 +210,10 @@ class CSHARP : public Language {
|
||||||
Swig_register_filebyname("wrapper",f_wrappers);
|
Swig_register_filebyname("wrapper",f_wrappers);
|
||||||
Swig_register_filebyname("runtime",f_runtime);
|
Swig_register_filebyname("runtime",f_runtime);
|
||||||
Swig_register_filebyname("init",f_init);
|
Swig_register_filebyname("init",f_init);
|
||||||
|
|
||||||
swig_types_hash = NewHash();
|
swig_types_hash = NewHash();
|
||||||
|
|
||||||
// Make the intermediary class and module class names. The intermediary class name can be set in the module directive.
|
// Make the intermediary class and module class names. The intermediary class name can be set in the module directive.
|
||||||
Node* optionsnode = Getattr( Getattr(n,"module") ,"options");
|
|
||||||
if (optionsnode)
|
|
||||||
if (Getattr(optionsnode,"imclassname"))
|
|
||||||
imclass_name = Copy(Getattr(optionsnode,"imclassname"));
|
|
||||||
if (!imclass_name) {
|
if (!imclass_name) {
|
||||||
imclass_name = NewStringf("%sPINVOKE", Getattr(n,"name"));
|
imclass_name = NewStringf("%sPINVOKE", Getattr(n,"name"));
|
||||||
module_class_name = Copy(Getattr(n,"name"));
|
module_class_name = Copy(Getattr(n,"name"));
|
||||||
|
|
@ -220,7 +225,6 @@ class CSHARP : public Language {
|
||||||
module_class_name = Copy(Getattr(n,"name"));
|
module_class_name = Copy(Getattr(n,"name"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
imclass_class_code = NewString("");
|
imclass_class_code = NewString("");
|
||||||
proxy_class_def = NewString("");
|
proxy_class_def = NewString("");
|
||||||
proxy_class_code = NewString("");
|
proxy_class_code = NewString("");
|
||||||
|
|
@ -232,7 +236,7 @@ class CSHARP : public Language {
|
||||||
module_baseclass = NewString("");
|
module_baseclass = NewString("");
|
||||||
module_interfaces = NewString("");
|
module_interfaces = NewString("");
|
||||||
module_imports = NewString("");
|
module_imports = NewString("");
|
||||||
module_class_modifiers = NewString("public");
|
module_class_modifiers = NewString("");
|
||||||
imclass_imports = NewString("");
|
imclass_imports = NewString("");
|
||||||
imclass_cppcasts_code = NewString("");
|
imclass_cppcasts_code = NewString("");
|
||||||
upcasts_code = NewString("");
|
upcasts_code = NewString("");
|
||||||
|
|
@ -282,7 +286,7 @@ class CSHARP : public Language {
|
||||||
|
|
||||||
if (Len(imclass_class_modifiers) > 0)
|
if (Len(imclass_class_modifiers) > 0)
|
||||||
Printf(f_im, "%s ", imclass_class_modifiers);
|
Printf(f_im, "%s ", imclass_class_modifiers);
|
||||||
Printf(f_im, "class %s ", imclass_name);
|
Printf(f_im, "%s ", imclass_name);
|
||||||
|
|
||||||
if (imclass_baseclass && *Char(imclass_baseclass))
|
if (imclass_baseclass && *Char(imclass_baseclass))
|
||||||
Printf(f_im, ": %s ", imclass_baseclass);
|
Printf(f_im, ": %s ", imclass_baseclass);
|
||||||
|
|
@ -322,7 +326,7 @@ class CSHARP : public Language {
|
||||||
|
|
||||||
if (Len(module_class_modifiers) > 0)
|
if (Len(module_class_modifiers) > 0)
|
||||||
Printf(f_module, "%s ", module_class_modifiers);
|
Printf(f_module, "%s ", module_class_modifiers);
|
||||||
Printf(f_module, "class %s ", module_class_name);
|
Printf(f_module, "%s ", module_class_name);
|
||||||
|
|
||||||
if (module_baseclass && *Char(module_baseclass))
|
if (module_baseclass && *Char(module_baseclass))
|
||||||
Printf(f_module, ": %s ", module_baseclass);
|
Printf(f_module, ": %s ", module_baseclass);
|
||||||
|
|
@ -337,8 +341,7 @@ class CSHARP : public Language {
|
||||||
Printv(f_module, module_class_code, NIL);
|
Printv(f_module, module_class_code, NIL);
|
||||||
|
|
||||||
// Write out all the global constants
|
// Write out all the global constants
|
||||||
if (Len(module_class_constants_code) != 0 )
|
Printv(f_module, module_class_constants_code, NIL);
|
||||||
Printv(f_module, module_class_constants_code, NIL);
|
|
||||||
|
|
||||||
// Finish off the class
|
// Finish off the class
|
||||||
Printf(f_module, "}\n");
|
Printf(f_module, "}\n");
|
||||||
|
|
@ -716,6 +719,7 @@ class CSHARP : public Language {
|
||||||
Printf(imclass_class_code, ")");
|
Printf(imclass_class_code, ")");
|
||||||
generateThrowsClause(n, imclass_class_code);
|
generateThrowsClause(n, imclass_class_code);
|
||||||
Printf(imclass_class_code, ";\n");
|
Printf(imclass_class_code, ";\n");
|
||||||
|
|
||||||
Printf(f->def,") {");
|
Printf(f->def,") {");
|
||||||
|
|
||||||
if(!is_void_return)
|
if(!is_void_return)
|
||||||
|
|
@ -850,7 +854,7 @@ class CSHARP : public Language {
|
||||||
Printv(enum_code,
|
Printv(enum_code,
|
||||||
(enum_feature == ProperEnum) ?
|
(enum_feature == ProperEnum) ?
|
||||||
"\n" :
|
"\n" :
|
||||||
typemapLookup("csgetcptr", typemap_lookup_type, WARN_NONE), // getCPtr method (will probably never be used, but what the heck)
|
typemapLookup("csbody", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CSBODY_UNDEF), // main body of class
|
||||||
typemapLookup("cscode", typemap_lookup_type, WARN_NONE), // extra C# code
|
typemapLookup("cscode", typemap_lookup_type, WARN_NONE), // extra C# code
|
||||||
"}\n",
|
"}\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
|
@ -1094,6 +1098,10 @@ class CSHARP : public Language {
|
||||||
return SWIG_OK;
|
return SWIG_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* insertDirective()
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
virtual int insertDirective(Node *n) {
|
virtual int insertDirective(Node *n) {
|
||||||
String *code = Getattr(n,"code");
|
String *code = Getattr(n,"code");
|
||||||
Replaceall(code, "$module", module_class_name);
|
Replaceall(code, "$module", module_class_name);
|
||||||
|
|
@ -1222,7 +1230,7 @@ class CSHARP : public Language {
|
||||||
typemapLookup("csimports", typemap_lookup_type, WARN_NONE), // Import statements
|
typemapLookup("csimports", typemap_lookup_type, WARN_NONE), // Import statements
|
||||||
"\n",
|
"\n",
|
||||||
typemapLookup("csclassmodifiers", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers
|
typemapLookup("csclassmodifiers", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers
|
||||||
" class $csclassname", // Class name and base class
|
" $csclassname", // Class name and base class
|
||||||
(derived || *Char(pure_baseclass) || *Char(pure_interfaces)) ?
|
(derived || *Char(pure_baseclass) || *Char(pure_interfaces)) ?
|
||||||
" : " :
|
" : " :
|
||||||
"",
|
"",
|
||||||
|
|
@ -1232,20 +1240,10 @@ class CSHARP : public Language {
|
||||||
", " :
|
", " :
|
||||||
"",
|
"",
|
||||||
pure_interfaces,
|
pure_interfaces,
|
||||||
" {\n",
|
" {",
|
||||||
" private IntPtr swigCPtr;\n", // Member variables for memory handling
|
derived ?
|
||||||
derived ?
|
typemapLookup("csbody_derived", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CSBODY_UNDEF) : // main body of class
|
||||||
"" :
|
typemapLookup("csbody", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CSBODY_UNDEF), // main body of class
|
||||||
" protected bool swigCMemOwn;\n",
|
|
||||||
"\n",
|
|
||||||
" ",
|
|
||||||
typemapLookup("csptrconstructormodifiers", typemap_lookup_type, WARN_CSHARP_TYPEMAP_PTRCONSTMOD_UNDEF), // pointer constructor modifiers
|
|
||||||
" $csclassname(IntPtr cPtr, bool cMemoryOwn) ", // Constructor used for wrapping pointers
|
|
||||||
derived ?
|
|
||||||
": base($imclassname.$csclassnameTo$baseclass(cPtr), cMemoryOwn) {\n" :
|
|
||||||
"{\n swigCMemOwn = cMemoryOwn;\n",
|
|
||||||
" swigCPtr = cPtr;\n",
|
|
||||||
" }\n",
|
|
||||||
NIL);
|
NIL);
|
||||||
|
|
||||||
if(!have_default_constructor_flag) { // All proxy classes need a constructor
|
if(!have_default_constructor_flag) { // All proxy classes need a constructor
|
||||||
|
|
@ -1294,9 +1292,8 @@ class CSHARP : public Language {
|
||||||
Delete(attributes);
|
Delete(attributes);
|
||||||
Delete(destruct);
|
Delete(destruct);
|
||||||
|
|
||||||
// Emit various other methods
|
// Emit extra user code
|
||||||
Printv(proxy_class_def,
|
Printv(proxy_class_def,
|
||||||
typemapLookup("csgetcptr", typemap_lookup_type, WARN_CSHARP_TYPEMAP_GETCPTR_UNDEF), // getCPtr method
|
|
||||||
typemapLookup("cscode", typemap_lookup_type, WARN_NONE), // extra C# code
|
typemapLookup("cscode", typemap_lookup_type, WARN_NONE), // extra C# code
|
||||||
"\n",
|
"\n",
|
||||||
NIL);
|
NIL);
|
||||||
|
|
@ -1305,31 +1302,24 @@ class CSHARP : public Language {
|
||||||
Replaceall(proxy_class_code, "$csclassname", proxy_class_name);
|
Replaceall(proxy_class_code, "$csclassname", proxy_class_name);
|
||||||
Replaceall(proxy_class_def, "$csclassname", proxy_class_name);
|
Replaceall(proxy_class_def, "$csclassname", proxy_class_name);
|
||||||
|
|
||||||
Replaceall(proxy_class_def, "$baseclass", baseclass);
|
Replaceall(proxy_class_def, "$module", module_class_name);
|
||||||
Replaceall(proxy_class_code, "$baseclass", baseclass);
|
Replaceall(proxy_class_code, "$module", module_class_name);
|
||||||
|
|
||||||
Replaceall(proxy_class_def, "$imclassname", imclass_name);
|
|
||||||
Replaceall(proxy_class_code, "$imclassname", imclass_name);
|
|
||||||
|
|
||||||
// Add code to do C++ casting to base class (only for classes in an inheritance hierarchy)
|
// Add code to do C++ casting to base class (only for classes in an inheritance hierarchy)
|
||||||
if(derived){
|
if(derived){
|
||||||
Printv(imclass_cppcasts_code,"\n [DllImport(\"", module_class_name, "\", EntryPoint=\"CSharp_", proxy_class_name ,"To", baseclass ,"\")]\n", NIL);
|
Printv(imclass_cppcasts_code,"\n [DllImport(\"", module_class_name, "\", EntryPoint=\"CSharp_", proxy_class_name ,"Upcast", "\")]\n", NIL);
|
||||||
Printv(imclass_cppcasts_code," public static extern IntPtr ",
|
Printf(imclass_cppcasts_code," public static extern IntPtr $csclassnameUpcast(IntPtr objectRef);\n");
|
||||||
"$csclassnameTo$baseclass(IntPtr objectRef);\n",
|
|
||||||
NIL);
|
|
||||||
|
|
||||||
Replaceall(imclass_cppcasts_code, "$csclassname", proxy_class_name);
|
Replaceall(imclass_cppcasts_code, "$csclassname", proxy_class_name);
|
||||||
Replaceall(imclass_cppcasts_code, "$baseclass", baseclass);
|
|
||||||
|
|
||||||
Printv(upcasts_code,
|
Printv(upcasts_code,
|
||||||
"DllExport $cbaseclass * SWIGSTDCALL CSharp_$imclazznameTo$imbaseclass",
|
"DllExport $cbaseclass * SWIGSTDCALL CSharp_$imclazznameUpcast",
|
||||||
"($cclass *objectRef) {\n",
|
"($cclass *objectRef) {\n",
|
||||||
" return ($cbaseclass *)objectRef;\n"
|
" return ($cbaseclass *)objectRef;\n"
|
||||||
"}\n",
|
"}\n",
|
||||||
"\n",
|
"\n",
|
||||||
NIL);
|
NIL);
|
||||||
|
|
||||||
Replaceall(upcasts_code, "$imbaseclass", baseclass);
|
|
||||||
Replaceall(upcasts_code, "$cbaseclass", c_baseclass);
|
Replaceall(upcasts_code, "$cbaseclass", c_baseclass);
|
||||||
Replaceall(upcasts_code, "$imclazzname", proxy_class_name);
|
Replaceall(upcasts_code, "$imclazzname", proxy_class_name);
|
||||||
Replaceall(upcasts_code, "$cclass", c_classname);
|
Replaceall(upcasts_code, "$cclass", c_classname);
|
||||||
|
|
@ -1380,6 +1370,7 @@ class CSHARP : public Language {
|
||||||
destructor_call = NewString("");
|
destructor_call = NewString("");
|
||||||
proxy_class_constants_code = NewString("");
|
proxy_class_constants_code = NewString("");
|
||||||
}
|
}
|
||||||
|
|
||||||
Language::classHandler(n);
|
Language::classHandler(n);
|
||||||
|
|
||||||
if (proxy_flag) {
|
if (proxy_flag) {
|
||||||
|
|
@ -1509,7 +1500,7 @@ class CSHARP : public Language {
|
||||||
|
|
||||||
/* Start generating the proxy function */
|
/* Start generating the proxy function */
|
||||||
const String *methodmods = Getattr(n,"feature:cs:methodmodifiers");
|
const String *methodmods = Getattr(n,"feature:cs:methodmodifiers");
|
||||||
methodmods = methodmods ? methodmods : (is_protected(n) ? protected_string : public_string);
|
methodmods = methodmods ? methodmods : (!is_public(n) ? protected_string : public_string);
|
||||||
Printf(function_code, " %s ", methodmods);
|
Printf(function_code, " %s ", methodmods);
|
||||||
if (static_flag)
|
if (static_flag)
|
||||||
Printf(function_code, "static ");
|
Printf(function_code, "static ");
|
||||||
|
|
@ -1522,7 +1513,7 @@ class CSHARP : public Language {
|
||||||
|
|
||||||
Printv(imcall, imclass_name, ".", intermediary_function_name, "(", NIL);
|
Printv(imcall, imclass_name, ".", intermediary_function_name, "(", NIL);
|
||||||
if (!static_flag)
|
if (!static_flag)
|
||||||
Printv(imcall, "swigCPtr", NIL);
|
Printf(imcall, "swigCPtr");
|
||||||
|
|
||||||
emit_mark_varargs(l);
|
emit_mark_varargs(l);
|
||||||
|
|
||||||
|
|
@ -1669,7 +1660,7 @@ class CSHARP : public Language {
|
||||||
String *imcall = NewString("");
|
String *imcall = NewString("");
|
||||||
|
|
||||||
const String *methodmods = Getattr(n,"feature:cs:methodmodifiers");
|
const String *methodmods = Getattr(n,"feature:cs:methodmodifiers");
|
||||||
methodmods = methodmods ? methodmods : (is_protected(n) ? protected_string : public_string);
|
methodmods = methodmods ? methodmods : (!is_public(n) ? protected_string : public_string);
|
||||||
methodmods = methodmods ? methodmods : public_string;
|
methodmods = methodmods ? methodmods : public_string;
|
||||||
Printf(proxy_class_code, " %s %s(", methodmods, proxy_class_name);
|
Printf(proxy_class_code, " %s %s(", methodmods, proxy_class_name);
|
||||||
Printv(imcall, " : this(", imclass_name, ".", Swig_name_construct(overloaded_name), "(", NIL);
|
Printv(imcall, " : this(", imclass_name, ".", Swig_name_construct(overloaded_name), "(", NIL);
|
||||||
|
|
@ -1922,7 +1913,7 @@ class CSHARP : public Language {
|
||||||
|
|
||||||
/* Start generating the function */
|
/* Start generating the function */
|
||||||
const String *methodmods = Getattr(n,"feature:cs:methodmodifiers");
|
const String *methodmods = Getattr(n,"feature:cs:methodmodifiers");
|
||||||
methodmods = methodmods ? methodmods : (is_protected(n) ? protected_string : public_string);
|
methodmods = methodmods ? methodmods : (!is_public(n) ? protected_string : public_string);
|
||||||
Printf(function_code, " %s static %s %s(", methodmods, return_type, func_name);
|
Printf(function_code, " %s static %s %s(", methodmods, return_type, func_name);
|
||||||
Printv(imcall, imclass_name, ".", overloaded_name, "(", NIL);
|
Printv(imcall, imclass_name, ".", overloaded_name, "(", NIL);
|
||||||
|
|
||||||
|
|
@ -2242,7 +2233,7 @@ class CSHARP : public Language {
|
||||||
typemapLookup("csimports", type, WARN_NONE), // Import statements
|
typemapLookup("csimports", type, WARN_NONE), // Import statements
|
||||||
"\n",
|
"\n",
|
||||||
typemapLookup("csclassmodifiers", type, WARN_CSHARP_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers
|
typemapLookup("csclassmodifiers", type, WARN_CSHARP_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers
|
||||||
" class $csclassname", // Class name and base class
|
" $csclassname", // Class name and base class
|
||||||
(*Char(pure_baseclass) || *Char(pure_interfaces)) ?
|
(*Char(pure_baseclass) || *Char(pure_interfaces)) ?
|
||||||
" : " :
|
" : " :
|
||||||
"",
|
"",
|
||||||
|
|
@ -2251,32 +2242,21 @@ class CSHARP : public Language {
|
||||||
", " :
|
", " :
|
||||||
"",
|
"",
|
||||||
pure_interfaces,
|
pure_interfaces,
|
||||||
" {\n",
|
" {",
|
||||||
" private IntPtr swigCPtr;\n",
|
typemapLookup("csbody", type, WARN_CSHARP_TYPEMAP_CSBODY_UNDEF), // main body of class
|
||||||
"\n",
|
|
||||||
" ",
|
|
||||||
typemapLookup("csptrconstructormodifiers", type, WARN_CSHARP_TYPEMAP_PTRCONSTMOD_UNDEF), // pointer constructor modifiers
|
|
||||||
" $csclassname(IntPtr cPtr, bool bFutureUse) {\n", // Constructor used for wrapping pointers
|
|
||||||
" swigCPtr = cPtr;\n",
|
|
||||||
" }\n",
|
|
||||||
"\n",
|
|
||||||
" protected $csclassname() {\n", // Default constructor
|
|
||||||
" swigCPtr = IntPtr.Zero;\n",
|
|
||||||
" }\n",
|
|
||||||
typemapLookup("csgetcptr", type, WARN_CSHARP_TYPEMAP_GETCPTR_UNDEF), // getCPtr method
|
|
||||||
typemapLookup("cscode", type, WARN_NONE), // extra C# code
|
typemapLookup("cscode", type, WARN_NONE), // extra C# code
|
||||||
"}\n",
|
"}\n",
|
||||||
Len(namespce) > 0 ?
|
Len(namespce) > 0 ?
|
||||||
"\n}\n" :
|
"\n}\n" :
|
||||||
"",
|
"",
|
||||||
NIL);
|
NIL);
|
||||||
|
|
||||||
Replaceall(swigtype, "$csclassname", classname);
|
Replaceall(swigtype, "$csclassname", classname);
|
||||||
Replaceall(swigtype, "$module", module_class_name);
|
Replaceall(swigtype, "$module", module_class_name);
|
||||||
Printv(f_swigtype, swigtype, NIL);
|
Printv(f_swigtype, swigtype, NIL);
|
||||||
|
|
||||||
Close(f_swigtype);
|
Close(f_swigtype);
|
||||||
Delete(swigtype);
|
Delete(swigtype);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue