From 13d9e19cdbb9c3dc6d89fc0a44a97d66051d0068 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 11 Jan 2013 06:19:24 +0000 Subject: Fix spacing in generated code for csdirectorin 'pre', 'post' and 'terminator' attributes. Add some more tests for these attributes. --- Examples/test-suite/csharp/csharp_prepost_runme.cs | 16 +++++++ Examples/test-suite/csharp_prepost.i | 15 +++--- Source/Modules/csharp.cxx | 56 +++++++--------------- 3 files changed, 41 insertions(+), 46 deletions(-) diff --git a/Examples/test-suite/csharp/csharp_prepost_runme.cs b/Examples/test-suite/csharp/csharp_prepost_runme.cs index 8842a79b3..ca3979065 100644 --- a/Examples/test-suite/csharp/csharp_prepost_runme.cs +++ b/Examples/test-suite/csharp/csharp_prepost_runme.cs @@ -15,6 +15,11 @@ public class csharp_prepost_runme { Assert(vpost.Count, 2); vpost.Add(1.0); } + public override int methodint(ref double[] vpre, DoubleVector vpost) + { + method(ref vpre, vpost); + return vpost.Count; + } } public static void Main() { { @@ -58,6 +63,17 @@ public class csharp_prepost_runme { Assert(vpre[0], 2.0); Assert(vpost.Count, 3); } + { + PrePost3_Derived p = new PrePost3_Derived(); + double[] vpre = new double[] { 1.0 }; + DoubleVector vpost = new DoubleVector(); + vpost.Add(3.0); + vpost.Add(4.0); + int size = p.methodint(ref vpre, vpost); + Assert(vpre[0], 2.0); + Assert(vpost.Count, 3); + Assert(size, 3); + } // Check attributes are generated for the constructor helper function { diff --git a/Examples/test-suite/csharp_prepost.i b/Examples/test-suite/csharp_prepost.i index 4f5a49362..32ee10677 100644 --- a/Examples/test-suite/csharp_prepost.i +++ b/Examples/test-suite/csharp_prepost.i @@ -80,14 +80,14 @@ struct PrePost2 { // Check csdirectorin pre and post attributes // ref param %typemap(csdirectorin, - pre=" DoubleVector d$iminput = new DoubleVector($iminput, false);\n" - " int count$iminput = d$iminput.Count;\n" - " double[] v$iminput = new double[count$iminput];\n" - " for (int i=0; i &vpre "ref v$iminput" @@ -106,6 +106,7 @@ struct PrePost3 { } virtual ~PrePost3(){} virtual void method(std::vector & vpre, std::vector & vpost) {} + virtual int methodint(std::vector & vpre, std::vector & vpost) { return 0; } }; %} diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index f559d23aa..81b3b3f8b 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -3678,7 +3678,7 @@ public: substituteClassname(pt, din); Replaceall(din, "$iminput", ln); - // :pre and :post attribute support + // pre and post attribute support String *pre = Getattr(p, "tmap:csdirectorin:pre"); if (pre) { substituteClassname(pt, pre); @@ -3703,7 +3703,6 @@ public: Insert(terminator_code, 0, "\n"); Insert(terminator_code, 0, terminator); } - // end :pre and :post attribute support if (i > 0) { Printf(delegate_parms, ", "); @@ -3721,10 +3720,10 @@ public: if ((tm = Getattr(p, "tmap:cstype"))) { substituteClassname(pt, tm); if (Strncmp(tm, "ref ", 4) == 0) { - DohReplace(tm, "ref ", "", DOH_REPLACE_FIRST); + Replace(tm, "ref ", "", DOH_REPLACE_FIRST); Printf(proxy_method_types, "typeof(%s).MakeByRefType()", tm); } else if (Strncmp(tm, "out ", 4) == 0) { - DohReplace(tm, "out ", "", DOH_REPLACE_FIRST); + Replace(tm, "out ", "", DOH_REPLACE_FIRST); Printf(proxy_method_types, "typeof(%s).MakeByRefType()", tm); } else { Printf(proxy_method_types, "typeof(%s)", tm); @@ -3812,47 +3811,26 @@ public: String *upcall = NewStringf("%s(%s)", symname, imcall_args); - if (!is_void) { - if ((tm = Swig_typemap_lookup("csdirectorout", n, "", 0))) { - substituteClassname(returntype, tm); - Replaceall(tm, "$cscall", upcall); - // pre: and post: attribute support - bool is_pre_code = Len(pre_code) > 0; - bool is_post_code = Len(post_code) > 0; - bool is_terminator_code = Len(terminator_code) > 0; - if (is_pre_code || is_post_code || is_terminator_code) { - Insert(tm, 0, " return "); - Printf(tm, ";"); - if (is_post_code) { - Insert(tm, 0, "\n try {\n "); - Printv(tm, "\n }\n finally {\n", post_code, "\n }", NIL); - } else { - Insert(tm, 0, "\n "); - } - if (is_pre_code) { - Insert(tm, 0, pre_code); - Insert(tm, 0, "\n"); - } - if (is_terminator_code) - Printv(tm, "\n", terminator_code, NIL); - Printf(callback_code, " %s\n", tm); - } else { - Printf(callback_code, " return %s;\n", tm); - } - } - Delete(tm); - } else { + if ((tm = Swig_typemap_lookup("csdirectorout", n, "", 0))) { + substituteClassname(returntype, tm); + Replaceall(tm, "$cscall", upcall); + if (!is_void) + Insert(tm, 0, "return "); + Replaceall(tm, "\n ", "\n "); // add extra indentation to code in typemap + + // pre and post attribute support bool is_pre_code = Len(pre_code) > 0; bool is_post_code = Len(post_code) > 0; + bool is_terminator_code = Len(terminator_code) > 0; if (is_pre_code && is_post_code) - Printf(callback_code, " %s\n try {\n %s;\n }\n finally {\n %s\n }\n", pre_code, upcall, post_code); + Printf(callback_code, "%s\n try {\n %s;\n } finally {\n%s\n }\n", pre_code, tm, post_code); else if (is_pre_code) - Printf(callback_code, " %s\n %s;\n", pre_code, upcall); + Printf(callback_code, "%s\n %s;\n", pre_code, tm); else if (is_post_code) - Printf(callback_code, " try {\n %s;\n }\n finally {\n %s\n }\n", upcall, post_code); + Printf(callback_code, " try {\n %s;\n } finally {\n%s\n }\n", tm, post_code); else - Printf(callback_code, " %s;\n", upcall); - if (Len(terminator_code) > 0) + Printf(callback_code, " %s;\n", tm); + if (is_terminator_code) Printv(callback_code, "\n", terminator_code, NIL); } -- cgit v1.2.1