359
375
Printf(f_directors, "#include \"%s\"\n\n", Swig_file_filename(outfile_h));
362
String *wrapper_name = NewString("");
364
Printf(wrapper_name, "CSharp_%%f", imclass_name);
365
Swig_name_register((char *) "wrapper", Char(wrapper_name));
378
Swig_name_register((char *) "wrapper", (char *) "CSharp_%f");
366
379
if (old_variable_names) {
367
380
Swig_name_register((char *) "set", (char *) "set_%v");
368
381
Swig_name_register((char *) "get", (char *) "get_%v");
371
Delete(wrapper_name);
373
384
Printf(f_wrappers, "\n#ifdef __cplusplus\n");
374
385
Printf(f_wrappers, "extern \"C\" {\n");
375
386
Printf(f_wrappers, "#endif\n\n");
912
923
Replaceall(tm, "$source", "result"); /* deprecated */
913
924
Replaceall(tm, "$target", "jresult"); /* deprecated */
914
925
Replaceall(tm, "$result", "jresult");
927
if (GetFlag(n, "feature:new"))
928
Replaceall(tm, "$owner", "1");
930
Replaceall(tm, "$owner", "0");
915
932
Printf(f->code, "%s", tm);
916
933
null_attribute = Getattr(n, "tmap:out:null");
1456
1473
String *typemap_lookup_type = Getattr(n, "classtypeobj");
1457
1474
bool feature_director = Swig_directorclass(n) ? true : false;
1459
/* Deal with inheritance */
1460
List *baselist = Getattr(n, "bases");
1462
Iterator base = First(baselist);
1463
while (base.item && GetFlag(base.item, "feature:ignore")) {
1467
c_baseclassname = Getattr(base.item, "name");
1468
baseclass = Copy(getProxyName(c_baseclassname));
1470
c_baseclass = SwigType_namestr(Getattr(base.item, "name"));
1472
/* Warn about multiple inheritance for additional base class(es) */
1474
if (GetFlag(base.item, "feature:ignore")) {
1478
String *proxyclassname = SwigType_str(Getattr(n, "classtypeobj"), 0);
1479
String *baseclassname = SwigType_str(Getattr(base.item, "name"), 0);
1480
Swig_warning(WARN_CSHARP_MULTIPLE_INHERITANCE, input_file, line_number,
1481
"Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in C#.\n", proxyclassname, baseclassname);
1486
1476
// Inheritance from pure C# classes
1487
1477
Node *attributes = NewHash();
1488
1478
const String *pure_baseclass = typemapLookup("csbase", typemap_lookup_type, WARN_NONE, attributes);
1479
bool purebase_replace = GetFlag(attributes, "tmap:csbase:replace") ? true : false;
1483
if (!purebase_replace) {
1484
List *baselist = Getattr(n, "bases");
1486
Iterator base = First(baselist);
1487
while (base.item && GetFlag(base.item, "feature:ignore")) {
1491
c_baseclassname = Getattr(base.item, "name");
1492
baseclass = Copy(getProxyName(c_baseclassname));
1494
c_baseclass = SwigType_namestr(Getattr(base.item, "name"));
1496
/* Warn about multiple inheritance for additional base class(es) */
1498
if (GetFlag(base.item, "feature:ignore")) {
1502
String *proxyclassname = SwigType_str(Getattr(n, "classtypeobj"), 0);
1503
String *baseclassname = SwigType_str(Getattr(base.item, "name"), 0);
1504
Swig_warning(WARN_CSHARP_MULTIPLE_INHERITANCE, input_file, line_number,
1505
"Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in C#.\n", proxyclassname, baseclassname);
1489
1512
const String *wanted_base = baseclass ? baseclass : pure_baseclass;
1490
1513
bool derived = baseclass && getProxyName(c_baseclassname);
1492
if (GetFlag(attributes, "tmap:csbase:replace")) {
1515
if (purebase_replace) {
1493
1516
wanted_base = pure_baseclass;
1494
derived = *Char(wanted_base) ? true : false;
1495
1518
Delete(baseclass);
1496
1519
baseclass = NULL;
1497
1520
} else if (Len(pure_baseclass) > 0 && Len(baseclass) > 0) {
1498
1521
Swig_warning(WARN_CSHARP_MULTIPLE_INHERITANCE, input_file, line_number,
1499
"Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in C#.\n", typemap_lookup_type, pure_baseclass);
1522
"Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in C#. Perhaps you need the replace attribute in the csbase typemap?\n", typemap_lookup_type, pure_baseclass);
1501
1525
// Pure C# interfaces
1502
1526
const String *pure_interfaces = typemapLookup(derived ? "csinterfaces_derived" : "csinterfaces", typemap_lookup_type, WARN_NONE);
1503
1527
// Start writing the proxy class
1563
1587
// put this in classDirectorEnd ???
1564
1588
Printf(proxy_class_code, " private void SwigDirectorConnect() {\n");
1566
for (int i = first_class_dmethod; i < curr_class_dmethod; ++i) {
1591
for (i = first_class_dmethod; i < curr_class_dmethod; ++i) {
1567
1592
UpcallData *udata = Getitem(dmethods_seq, i);
1568
1593
String *method = Getattr(udata, "method");
1569
1594
String *methid = Getattr(udata, "class_methodidx");
1595
String *overname = Getattr(udata, "overname");
1570
1596
Printf(proxy_class_code, " if (SwigDerivedClassHasMethod(\"%s\", swigMethodTypes%s))\n", method, methid);
1571
Printf(proxy_class_code, " swigDelegate%s = new SwigDelegate%s_%s(SwigDirector%s);\n", methid, proxy_class_name, methid, method);
1597
Printf(proxy_class_code, " swigDelegate%s = new SwigDelegate%s_%s(SwigDirector%s);\n", methid, proxy_class_name, methid, overname);
1573
1599
Printf(proxy_class_code, " %s.%s_director_connect(swigCPtr", imclass_name, proxy_class_name);
1574
for (int i = first_class_dmethod; i < curr_class_dmethod; ++i) {
1600
for (i = first_class_dmethod; i < curr_class_dmethod; ++i) {
1575
1601
UpcallData *udata = Getitem(dmethods_seq, i);
1576
1602
String *methid = Getattr(udata, "class_methodidx");
1577
1603
Printf(proxy_class_code, ", swigDelegate%s", methid);
1929
1959
Printf(function_code, "static ");
1930
1960
Printf(function_code, "%s %s(", return_type, proxy_function_name);
1932
Printv(imcall, imclass_name, ".", intermediary_function_name, "(", NIL);
1962
Printv(imcall, imclass_name, ".$imfuncname(", NIL);
1933
1963
if (!static_flag)
1934
1964
Printf(imcall, "swigCPtr");
1976
2006
if ((tm = Getattr(p, "tmap:csin"))) {
1977
2007
substituteClassname(pt, tm);
1978
2008
Replaceall(tm, "$csinput", arg);
2009
String *pre = Getattr(p, "tmap:csin:pre");
2011
substituteClassname(pt, pre);
2012
Replaceall(pre, "$csinput", arg);
2013
if (Len(pre_code) > 0)
2014
Printf(pre_code, "\n");
2015
Printv(pre_code, pre, NIL);
2017
String *post = Getattr(p, "tmap:csin:post");
2019
substituteClassname(pt, post);
2020
Replaceall(post, "$csinput", arg);
2021
if (Len(post_code) > 0)
2022
Printf(post_code, "\n");
2023
Printv(post_code, post, NIL);
1979
2025
Printv(imcall, tm, NIL);
1981
2027
Swig_warning(WARN_CSHARP_TYPEMAP_CSIN_UNDEF, input_file, line_number, "No csin typemap defined for %s\n", SwigType_str(pt, 0));
1999
2045
// Transform return type used in PInvoke function (in intermediary class) to type used in C# wrapper function (in proxy class)
2000
2046
if ((tm = Swig_typemap_lookup_new("csout", n, "", 0))) {
2047
excodeSubstitute(n, tm, "csout", n);
2048
bool is_pre_code = Len(pre_code) > 0;
2049
bool is_post_code = Len(post_code) > 0;
2050
if (is_pre_code || is_post_code) {
2051
Replaceall(tm, "\n ", "\n "); // add extra indentation to code in typemap
2053
Insert(tm, 0, "\n try ");
2054
Printv(tm, " finally {\n", post_code, "\n }", NIL);
2056
Insert(tm, 0, "\n ");
2059
Insert(tm, 0, pre_code);
2060
Insert(tm, 0, "\n");
2001
2065
if (GetFlag(n, "feature:new"))
2002
2066
Replaceall(tm, "$owner", "true");
2012
2076
String *ex_intermediary_function_name = Swig_name_member(proxy_class_name, ex_overloaded_name);
2014
2078
String *ex_imcall = Copy(imcall);
2015
Replaceall(ex_imcall, intermediary_function_name, ex_intermediary_function_name);
2079
Replaceall(ex_imcall, "$imfuncname", ex_intermediary_function_name);
2080
Replaceall(imcall, "$imfuncname", intermediary_function_name);
2017
2082
String *excode = NewString("");
2018
2083
if (!Cmp(return_type, "void"))
2024
2089
Printv(imcall, excode, NIL);
2025
2090
Delete(ex_overloaded_name);
2026
2091
Delete(excode);
2093
Replaceall(imcall, "$imfuncname", intermediary_function_name);
2028
2095
Replaceall(tm, "$imcall", imcall);
2029
excodeSubstitute(n, tm, "csout", n);
2031
2097
Swig_warning(WARN_CSHARP_TYPEMAP_CSOUT_UNDEF, input_file, line_number, "No csout typemap defined for %s\n", SwigType_str(t, 0));
2041
2107
SwigType *pt = Getattr(p, "type");
2042
2108
if ((tm = Getattr(p, "tmap:cstype"))) {
2043
2109
substituteClassname(pt, tm);
2110
String *cstypeout = Getattr(p, "tmap:cstype:out"); // the type in the cstype typemap's out attribute overrides the type in the typemap
2111
variable_type = cstypeout ? cstypeout : tm;
2046
2113
Swig_warning(WARN_CSHARP_TYPEMAP_CSOUT_UNDEF, input_file, line_number, "No csvarin typemap defined for %s\n", SwigType_str(pt, 0));
2120
2193
String *imcall = NewString("");
2122
2195
const String *csattributes = Getattr(n, "feature:cs:attributes");
2124
2197
Printf(function_code, " %s\n", csattributes);
2198
Printf(helper_code, " %s\n", csattributes);
2125
2200
const String *methodmods = Getattr(n, "feature:cs:methodmodifiers");
2126
2201
methodmods = methodmods ? methodmods : (is_public(n) ? public_string : protected_string);
2203
tm = Getattr(n, "tmap:imtype"); // typemaps were attached earlier to the node
2204
String *imtypeout = Getattr(n, "tmap:imtype:out"); // the type in the imtype typemap's out attribute overrides the type in the typemap
2207
Printf(im_return_type, "%s", tm);
2127
2209
Printf(function_code, " %s %s(", methodmods, proxy_class_name);
2210
Printf(helper_code, " static private %s SwigConstruct%s(", im_return_type, proxy_class_name);
2128
2212
Printv(imcall, imclass_name, ".", mangled_overname, "(", NIL);
2130
2214
/* Attach the non-standard typemaps to the parameter list */
2167
2251
Printf(imcall, ", ");
2169
2253
String *arg = makeParameterName(n, p, i, false);
2171
2256
// Use typemaps to transform type used in C# wrapper function (in proxy class) to type used in PInvoke function (in intermediary class)
2172
2257
if ((tm = Getattr(p, "tmap:csin"))) {
2173
2258
substituteClassname(pt, tm);
2174
2259
Replaceall(tm, "$csinput", arg);
2260
String *pre = Getattr(p, "tmap:csin:pre");
2262
substituteClassname(pt, pre);
2263
Replaceall(pre, "$csinput", arg);
2264
if (Len(pre_code) > 0)
2265
Printf(pre_code, "\n");
2266
Printv(pre_code, pre, NIL);
2268
String *post = Getattr(p, "tmap:csin:post");
2270
substituteClassname(pt, post);
2271
Replaceall(post, "$csinput", arg);
2272
if (Len(post_code) > 0)
2273
Printf(post_code, "\n");
2274
Printv(post_code, post, NIL);
2276
cshin = Getattr(p, "tmap:csin:cshin");
2278
Replaceall(cshin, "$csinput", arg);
2175
2279
Printv(imcall, tm, NIL);
2177
2281
Swig_warning(WARN_CSHARP_TYPEMAP_CSIN_UNDEF, input_file, line_number, "No csin typemap defined for %s\n", SwigType_str(pt, 0));
2180
2284
/* Add parameter to proxy function */
2182
2286
Printf(function_code, ", ");
2287
Printf(helper_code, ", ");
2288
Printf(helper_args, ", ");
2183
2290
Printf(function_code, "%s %s", param_type, arg);
2291
Printf(helper_code, "%s %s", param_type, arg);
2292
Printf(helper_args, "%s", cshin ? cshin : arg);
2187
2297
Delete(param_type);
2188
2298
p = Getattr(p, "tmap:in:next");
2214
2325
Printv(function_code, " ", construct_tm, NIL);
2217
Replaceall(function_code, "$imcall", imcall);
2218
2328
excodeSubstitute(n, function_code, "csconstruct", attributes);
2330
bool is_pre_code = Len(pre_code) > 0;
2331
bool is_post_code = Len(post_code) > 0;
2332
if (is_pre_code || is_post_code) {
2333
Printf(helper_code, " {\n");
2335
Printv(helper_code, pre_code, "\n", NIL);
2338
Printf(helper_code, " try {\n");
2339
Printv(helper_code, " return ", imcall, ";\n", NIL);
2340
Printv(helper_code, " } finally {\n", post_code, "\n }", NIL);
2342
Printv(helper_code, " return ", imcall, ";", NIL);
2344
Printf(helper_code, "\n }\n");
2345
String *helper_name = NewStringf("%s.SwigConstruct%s(%s)", proxy_class_name, proxy_class_name, helper_args);
2346
String *im_outattribute = Getattr(n, "tmap:imtype:outattributes");
2347
if (im_outattribute)
2348
Printf(proxy_class_code, " %s\n", im_outattribute);
2349
Printv(proxy_class_code, helper_code, "\n", NIL);
2350
Replaceall(function_code, "$imcall", helper_name);
2351
Delete(helper_name);
2353
Replaceall(function_code, "$imcall", imcall);
2219
2356
Printv(proxy_class_code, function_code, "\n", NIL);
2358
Delete(helper_args);
2359
Delete(im_return_type);
2221
2362
Delete(construct_tm);
2222
2363
Delete(attributes);
2223
2364
Delete(overloaded_name);
2418
2563
if ((tm = Getattr(p, "tmap:csin"))) {
2419
2564
substituteClassname(pt, tm);
2420
2565
Replaceall(tm, "$csinput", arg);
2566
String *pre = Getattr(p, "tmap:csin:pre");
2568
substituteClassname(pt, pre);
2569
Replaceall(pre, "$csinput", arg);
2570
if (Len(pre_code) > 0)
2571
Printf(pre_code, "\n");
2572
Printv(pre_code, pre, NIL);
2574
String *post = Getattr(p, "tmap:csin:post");
2576
substituteClassname(pt, post);
2577
Replaceall(post, "$csinput", arg);
2578
if (Len(post_code) > 0)
2579
Printf(post_code, "\n");
2580
Printv(post_code, post, NIL);
2421
2582
Printv(imcall, tm, NIL);
2423
2584
Swig_warning(WARN_CSHARP_TYPEMAP_CSIN_UNDEF, input_file, line_number, "No csin typemap defined for %s\n", SwigType_str(pt, 0));
2440
2601
// Transform return type used in PInvoke function (in intermediary class) to type used in C# wrapper function (in module class)
2441
2602
if ((tm = Swig_typemap_lookup_new("csout", n, "", 0))) {
2603
excodeSubstitute(n, tm, "csout", n);
2604
bool is_pre_code = Len(pre_code) > 0;
2605
bool is_post_code = Len(post_code) > 0;
2606
if (is_pre_code || is_post_code) {
2607
Replaceall(tm, "\n ", "\n "); // add extra indentation to code in typemap
2609
Insert(tm, 0, "\n try ");
2610
Printv(tm, " finally {\n", post_code, "\n }", NIL);
2612
Insert(tm, 0, "\n ");
2615
Insert(tm, 0, pre_code);
2616
Insert(tm, 0, "\n");
2442
2621
if (GetFlag(n, "feature:new"))
2443
2622
Replaceall(tm, "$owner", "true");
2445
2624
Replaceall(tm, "$owner", "false");
2446
2625
substituteClassname(t, tm);
2447
2626
Replaceall(tm, "$imcall", imcall);
2448
excodeSubstitute(n, tm, "csout", n);
2450
2628
Swig_warning(WARN_CSHARP_TYPEMAP_CSOUT_UNDEF, input_file, line_number, "No csout typemap defined for %s\n", SwigType_str(t, 0));
2460
2638
SwigType *pt = Getattr(p, "type");
2461
2639
if ((tm = Getattr(p, "tmap:cstype"))) {
2462
2640
substituteClassname(pt, tm);
2641
String *cstypeout = Getattr(p, "tmap:cstype:out"); // the type in the cstype typemap's out attribute overrides the type in the typemap
2642
variable_type = cstypeout ? cstypeout : tm;
2465
2644
Swig_warning(WARN_CSHARP_TYPEMAP_CSOUT_UNDEF, input_file, line_number, "No csvarin typemap defined for %s\n", SwigType_str(pt, 0));
2478
2657
if (setter_flag) {
2479
2658
// Setter method
2480
Swig_typemap_attach_parms("csvarin", l, NULL);
2481
2659
p = last_parm; // (last parameter is the only parameter for properties)
2482
2660
SwigType *pt = Getattr(p, "type");
2483
2661
if ((tm = Getattr(p, "tmap:csvarin"))) {
2484
2662
substituteClassname(pt, tm);
2663
Replaceall(tm, "$csinput", "value");
2485
2664
Replaceall(tm, "$imcall", imcall);
2486
2665
excodeSubstitute(n, tm, "csvarin", p);
2487
2666
Printf(module_class_code, "%s", tm);
3004
3185
if (!is_void && !ignored_method) {
3005
3186
if (!SwigType_isclass(returntype)) {
3006
3187
if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) {
3007
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), NIL);
3188
String *construct_result = NewStringf("= SwigValueInit< %s >()", SwigType_lstr(returntype, 0));
3189
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), construct_result, NIL);
3190
Delete(construct_result);
3009
3192
String *base_typename = SwigType_base(returntype);
3010
3193
String *resolved_typename = SwigType_typedef_resolve_all(base_typename);
3611
3796
Printf(w->code, "}\n\n");
3613
3798
Printf(w->code, "void %s::swig_init_callbacks() {\n", director_classname);
3614
for (int i = first_class_dmethod; i < curr_class_dmethod; ++i) {
3799
for (i = first_class_dmethod; i < curr_class_dmethod; ++i) {
3615
3800
UpcallData *udata = Getitem(dmethods_seq, i);
3616
3801
String *overname = Getattr(udata, "overname");
3617
3802
Printf(w->code, "swig_callback%s = 0;\n", overname);