Fix spacing in generated code for csdirectorin 'pre', 'post' and 'terminator' attributes. Add some more tests for these attributes.
This commit is contained in:
parent
2b407f4b27
commit
13d9e19cdb
3 changed files with 41 additions and 46 deletions
|
|
@ -15,6 +15,11 @@ public class csharp_prepost_runme {
|
||||||
Assert(vpost.Count, 2);
|
Assert(vpost.Count, 2);
|
||||||
vpost.Add(1.0);
|
vpost.Add(1.0);
|
||||||
}
|
}
|
||||||
|
public override int methodint(ref double[] vpre, DoubleVector vpost)
|
||||||
|
{
|
||||||
|
method(ref vpre, vpost);
|
||||||
|
return vpost.Count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public static void Main() {
|
public static void Main() {
|
||||||
{
|
{
|
||||||
|
|
@ -58,6 +63,17 @@ public class csharp_prepost_runme {
|
||||||
Assert(vpre[0], 2.0);
|
Assert(vpre[0], 2.0);
|
||||||
Assert(vpost.Count, 3);
|
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
|
// Check attributes are generated for the constructor helper function
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -80,14 +80,14 @@ struct PrePost2 {
|
||||||
// Check csdirectorin pre and post attributes
|
// Check csdirectorin pre and post attributes
|
||||||
// ref param
|
// ref param
|
||||||
%typemap(csdirectorin,
|
%typemap(csdirectorin,
|
||||||
pre=" DoubleVector d$iminput = new DoubleVector($iminput, false);\n"
|
pre=" DoubleVector d$iminput = new DoubleVector($iminput, false);\n"
|
||||||
" int count$iminput = d$iminput.Count;\n"
|
" int count$iminput = d$iminput.Count;\n"
|
||||||
" double[] v$iminput = new double[count$iminput];\n"
|
" double[] v$iminput = new double[count$iminput];\n"
|
||||||
" for (int i=0; i<count$iminput; ++i) {\n"
|
" for (int i=0; i<count$iminput; ++i) {\n"
|
||||||
" v$iminput[i] = d$iminput[i];\n"
|
" v$iminput[i] = d$iminput[i];\n"
|
||||||
" }\n",
|
" }\n",
|
||||||
post=" foreach (double d in v$iminput) {\n"
|
post=" foreach (double d in v$iminput) {\n"
|
||||||
" d$iminput.Add(d);\n"
|
" d$iminput.Add(d);\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
) std::vector<double> &vpre
|
) std::vector<double> &vpre
|
||||||
"ref v$iminput"
|
"ref v$iminput"
|
||||||
|
|
@ -106,6 +106,7 @@ struct PrePost3 {
|
||||||
}
|
}
|
||||||
virtual ~PrePost3(){}
|
virtual ~PrePost3(){}
|
||||||
virtual void method(std::vector<double> & vpre, std::vector<double> & vpost) {}
|
virtual void method(std::vector<double> & vpre, std::vector<double> & vpost) {}
|
||||||
|
virtual int methodint(std::vector<double> & vpre, std::vector<double> & vpost) { return 0; }
|
||||||
};
|
};
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3678,7 +3678,7 @@ public:
|
||||||
substituteClassname(pt, din);
|
substituteClassname(pt, din);
|
||||||
Replaceall(din, "$iminput", ln);
|
Replaceall(din, "$iminput", ln);
|
||||||
|
|
||||||
// :pre and :post attribute support
|
// pre and post attribute support
|
||||||
String *pre = Getattr(p, "tmap:csdirectorin:pre");
|
String *pre = Getattr(p, "tmap:csdirectorin:pre");
|
||||||
if (pre) {
|
if (pre) {
|
||||||
substituteClassname(pt, pre);
|
substituteClassname(pt, pre);
|
||||||
|
|
@ -3703,7 +3703,6 @@ public:
|
||||||
Insert(terminator_code, 0, "\n");
|
Insert(terminator_code, 0, "\n");
|
||||||
Insert(terminator_code, 0, terminator);
|
Insert(terminator_code, 0, terminator);
|
||||||
}
|
}
|
||||||
// end :pre and :post attribute support
|
|
||||||
|
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
Printf(delegate_parms, ", ");
|
Printf(delegate_parms, ", ");
|
||||||
|
|
@ -3721,10 +3720,10 @@ public:
|
||||||
if ((tm = Getattr(p, "tmap:cstype"))) {
|
if ((tm = Getattr(p, "tmap:cstype"))) {
|
||||||
substituteClassname(pt, tm);
|
substituteClassname(pt, tm);
|
||||||
if (Strncmp(tm, "ref ", 4) == 0) {
|
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);
|
Printf(proxy_method_types, "typeof(%s).MakeByRefType()", tm);
|
||||||
} else if (Strncmp(tm, "out ", 4) == 0) {
|
} 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);
|
Printf(proxy_method_types, "typeof(%s).MakeByRefType()", tm);
|
||||||
} else {
|
} else {
|
||||||
Printf(proxy_method_types, "typeof(%s)", tm);
|
Printf(proxy_method_types, "typeof(%s)", tm);
|
||||||
|
|
@ -3812,47 +3811,26 @@ public:
|
||||||
|
|
||||||
String *upcall = NewStringf("%s(%s)", symname, imcall_args);
|
String *upcall = NewStringf("%s(%s)", symname, imcall_args);
|
||||||
|
|
||||||
if (!is_void) {
|
if ((tm = Swig_typemap_lookup("csdirectorout", n, "", 0))) {
|
||||||
if ((tm = Swig_typemap_lookup("csdirectorout", n, "", 0))) {
|
substituteClassname(returntype, tm);
|
||||||
substituteClassname(returntype, tm);
|
Replaceall(tm, "$cscall", upcall);
|
||||||
Replaceall(tm, "$cscall", upcall);
|
if (!is_void)
|
||||||
// pre: and post: attribute support
|
Insert(tm, 0, "return ");
|
||||||
bool is_pre_code = Len(pre_code) > 0;
|
Replaceall(tm, "\n ", "\n "); // add extra indentation to code in typemap
|
||||||
bool is_post_code = Len(post_code) > 0;
|
|
||||||
bool is_terminator_code = Len(terminator_code) > 0;
|
// pre and post attribute support
|
||||||
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 {
|
|
||||||
bool is_pre_code = Len(pre_code) > 0;
|
bool is_pre_code = Len(pre_code) > 0;
|
||||||
bool is_post_code = Len(post_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)
|
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)
|
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)
|
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
|
else
|
||||||
Printf(callback_code, " %s;\n", upcall);
|
Printf(callback_code, " %s;\n", tm);
|
||||||
if (Len(terminator_code) > 0)
|
if (is_terminator_code)
|
||||||
Printv(callback_code, "\n", terminator_code, NIL);
|
Printv(callback_code, "\n", terminator_code, NIL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue