Add $isvoid special variable

The $isvoid special variable expands to 1 if the
wrapped function has a void return, otherwise expands to 0.

In the implementation, use a consistent variable name, returntype,
for a node's "type" attribute.

Issue #2907
This commit is contained in:
William S Fulton 2024-06-15 19:53:05 +01:00
parent c9f5e1d48e
commit 2c70a912a6
23 changed files with 298 additions and 116 deletions

View File

@ -7,8 +7,12 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
Version 4.3.0 (in progress)
===========================
2024-06-15: wsfulton
#2907 Add $isvoid special variable which expands to 1 if the
wrapped function has a void return, otherwise expands to 0.
2024-06-14: jschueller
#2863 Support Python 3.13 (currently in prerealase).
#2863 Support Python 3.13 (currently in prerelease).
2024-06-13: erezgeva
#2609 Fix Java typemap (const char *STRING, size_t LENGTH) to

View File

@ -556,6 +556,10 @@
<li><a href="Typemaps.html#Typemaps_nn22">Scope</a>
<li><a href="Typemaps.html#Typemaps_nn23">Declaring new local variables</a>
<li><a href="Typemaps.html#Typemaps_special_variables">Special variables</a>
<ul>
<li><a href="Typemaps.html#Typemaps_type_special_variables">Type related special variables</a>
<li><a href="Typemaps.html#Typemaps_additional_special_variables">Non-type related special variables</a>
</ul>
<li><a href="Typemaps.html#Typemaps_special_variable_macros">Special variable macros</a>
<ul>
<li><a href="Typemaps.html#Typemaps_special_macro_descriptor">$descriptor(type)</a>
@ -825,7 +829,6 @@
<li><a href="CSharp.html#CSharp_primitive_types">Primitive types</a>
<li><a href="CSharp.html#CSharp_other_type_mappings">Other types</a>
<li><a href="CSharp.html#CSharp_void_pointers">Void pointers</a>
<li><a href="CSharp.html#CSharp_cdata_i">cdata.i</a>
</ul>
<li><a href="CSharp.html#CSharp_arrays">C# Arrays</a>
<ul>
@ -880,7 +883,6 @@
<li><a href="D.html#D_typecheck_typemaps">typecheck typemaps</a>
<li><a href="D.html#D_code_injection_typemaps">Code injection typemaps</a>
<li><a href="D.html#D_special_variables">Special variable macros</a>
<li><a href="D.html#D_cdata_i">cdata.i</a>
</ul>
<li><a href="D.html#D_other_code_control">Other D code control features</a>
<ul>
@ -944,9 +946,6 @@
<li><a href="Go.html#Go_output_arguments">Output arguments</a>
<li><a href="Go.html#Go_adding_additional_code">Adding additional go code</a>
<li><a href="Go.html#Go_typemaps">Go typemaps</a>
<ul>
<li><a href="Go.html#Go_cdata_i">cdata.i</a>
</ul>
</ul>
</ul>
</div>
@ -1097,7 +1096,7 @@
<li><a href="Java.html#Java_simple_pointers">Simple pointers</a>
<li><a href="Java.html#Java_c_arrays">Wrapping C arrays with Java arrays</a>
<li><a href="Java.html#Java_unbounded_c_arrays">Unbounded C Arrays</a>
<li><a href="Java.html#Java_binary_char">Binary data vs Strings</a>
<li><a href="Java.html#Java_string_length">Passing a string with length</a>
<li><a href="Java.html#Java_heap_allocations">Overriding new and delete to allocate from Java heap</a>
</ul>
<li><a href="Java.html#Java_typemaps">Java typemaps</a>
@ -1112,7 +1111,6 @@
<li><a href="Java.html#Java_typemaps_for_c_and_cpp">Typemaps for both C and C++ compilation</a>
<li><a href="Java.html#Java_code_typemaps">Java code typemaps</a>
<li><a href="Java.html#Java_directors_typemaps">Director specific typemaps</a>
<li><a href="Java.html#Java_cdata_i">cdata.i</a>
</ul>
<li><a href="Java.html#Java_typemap_examples">Typemap Examples</a>
<ul>

View File

@ -443,36 +443,32 @@ variables are replaced with.
<td>The actual operation to be performed (a function call, method invocation, variable access, etc.)</td>
</tr>
<tr>
<td>$decl</td>
<td>The fully qualified C/C++ declaration of the method being wrapped without the return type.</td>
</tr>
<tr>
<td>$fulldecl</td>
<td>The fully qualified C/C++ declaration of the method being wrapped including the return type.</td>
</tr>
<tr>
<td>$isvoid</td>
<td>Expands to 1 if the wrapped function has a void return, otherwise expands to 0.
Note that it expands to 1 in destructors and 0 in constructors.</td>
</tr>
<tr>
<td>$name</td>
<td>The C/C++ symbol name for the function.</td>
</tr>
<tr>
<td>$symname</td>
<td>The symbol name used internally by SWIG</td>
</tr>
<tr>
<td>$overname</td>
<td>The extra mangling used in the symbol name for overloaded method. Expands to nothing if the wrapped method is not overloaded.</td>
</tr>
<tr>
<td>$wrapname</td>
<td>The language specific wrapper name (usually a C function name exported from the shared object/dll)</td>
</tr>
<tr>
<td>$decl</td>
<td>The fully qualified C/C++ declaration of the method being wrapped without the return type</td>
</tr>
<tr>
<td>$fulldecl</td>
<td>The fully qualified C/C++ declaration of the method being wrapped including the return type</td>
</tr>
<tr>
<td>$parentclassname</td>
<td>The parent class name (if any) for a method.</td>
@ -483,6 +479,16 @@ variables are replaced with.
<td>The target language parent class name (if any) for a method.</td>
</tr>
<tr>
<td>$symname</td>
<td>The symbol name used internally by SWIG.</td>
</tr>
<tr>
<td>$wrapname</td>
<td>The language specific wrapper name (usually a C function name exported from the shared object/dll).</td>
</tr>
</table>
<p>

View File

@ -44,6 +44,10 @@
<li><a href="#Typemaps_nn22">Scope</a>
<li><a href="#Typemaps_nn23">Declaring new local variables</a>
<li><a href="#Typemaps_special_variables">Special variables</a>
<ul>
<li><a href="#Typemaps_type_special_variables">Type related special variables</a>
<li><a href="#Typemaps_non_type_special_variables">Non-type related special variables</a>
</ul>
<li><a href="#Typemaps_special_variable_macros">Special variable macros</a>
<ul>
<li><a href="#Typemaps_special_macro_descriptor">$descriptor(type)</a>
@ -246,7 +250,7 @@ that is inserted directly into the SWIG generated wrapper functions.
The code is usually C or C++ code which will be generated into the C/C++ wrapper functions.
Note that this isn't always the case as some target language modules allow target language
code within the typemaps which gets generated into target language specific files.
Within this code, a number of special variables prefixed with a $ are expanded. These are
Within this code, a number of special variables prefixed with a <tt>$</tt> are expanded. These are
really just placeholders for C/C++ variables that are generated in the course
of creating the wrapper function. In this case, <tt>$input</tt> refers to an
input object that needs to be converted to C/C++ and <tt>$result</tt>
@ -2129,13 +2133,22 @@ each type must have its own local variable declaration.
<H3><a name="Typemaps_special_variables">14.4.3 Special variables</a></H3>
<p>
Special variables are prefixed with a <tt>$</tt> and are expanded by SWIG as part of the code generation process.
</p>
<H4><a name="Typemaps_type_special_variables">14.4.3.1 Type related special variables</a></H4>
<p>
Within all typemaps, the following special variables are expanded.
These are related in some way to a typemap's type.
This is by no means a complete list as some target languages have additional special variables which are documented in the language specific chapters.
</p>
<center>
<table border=1 summary="Typemap special variables">
<table border=1 summary="Typemap type related special variables">
<tr><th>Variable</th><th>Meaning</th></tr>
<tr>
@ -2378,6 +2391,38 @@ Another approach, which only works for arrays is to use the <tt>$1_basetype</tt>
</pre>
</div>
<H4><a name="Typemaps_non_type_special_variables">14.4.3.2 Non-type related special variables</a></H4>
<p>
The following are additional special variables.
These are not specifically related to a typemap's type.
</p>
<center>
<table border=1 summary="Non-type related special variables">
<tr><th>Variable</th><th>Meaning</th></tr>
<tr>
<td>$<em>isvoid</em></td>
<td>
Expands to 1 if the wrapped function has a void return, otherwise expands to 0.
Note that it expands to 1 in destructors and 0 in constructors.
</td>
</tr>
<tr>
<td>$<em>symname</em></td>
<td>
Name of function/method being wrapped.
</td>
</tr>
</table>
</center>
<H3><a name="Typemaps_special_variable_macros">14.4.4 Special variable macros</a></H3>
@ -2588,13 +2633,12 @@ to C. For example:
</div>
<p>
The following special variables are available:
The following additional special variables are available:
</p>
<div class="code">
<pre>
$input - Input object holding value to be converted.
$symname - Name of function/method being wrapped
</pre>
</div>
@ -2670,13 +2714,12 @@ into the target language. For example:
</div>
<p>
The following special variables are available.
The following additional special variables are available.
</p>
<div class="code">
<pre>
$result - Result object returned to target language.
$symname - Name of function/method being wrapped
</pre>
</div>
@ -2780,14 +2823,13 @@ with an "in" typemap---possibly to ignore the input value. For example:
</div>
<p>
The following special variables are available.
The following additional special variables are available.
</p>
<div class="diagram">
<pre>
$result - Result object returned to target language.
$input - The original input object passed.
$symname - Name of function/method being wrapped
</pre>
</div>

View File

@ -557,6 +557,7 @@ CPP_TEST_CASES += \
typemap_directorout \
typemap_documentation \
typemap_global_scope \
typemap_isvoid \
typemap_manyargs \
typemap_namespace \
typemap_ns_using \

View File

@ -0,0 +1,73 @@
%module typemap_isvoid
%{
void abc_1() {}
void def_0() {}
%}
// Use %exception to make sure $isvoid is expanded in the wrapper function
%exception void_function %{
$action
abc_$isvoid(); // must expand to abc_1
%}
%exception nonvoid_function %{
$action
def_$isvoid(); // must expand to def_0
%}
%exception void_function_static %{
$action
abc_$isvoid(); // must expand to abc_1
%}
%exception nonvoid_function_static %{
$action
def_$isvoid(); // must expand to def_0
%}
%exception AStruct::AStruct %{ $action
def_$isvoid(); // constructor must expand to def_0
%}
%exception AStruct::~AStruct %{
$action
abc_$isvoid(); // destructor must expand to abc_1
%}
%inline %{
void void_function() {}
int nonvoid_function() { return 0; }
void*nonvoid_function_voidptr() { return 0; }
struct AStruct {
void void_function() {}
int nonvoid_function() { return 0; }
void* nonvoid_function_voidptr() { return 0; }
static void void_function_static() {}
static int nonvoid_function_static() { return 0; }
static void* nonvoid_function_static_voidptr() { return 0; }
AStruct() {}
~AStruct() {}
};
%}
// Use the ret and check typemaps to make sure $isvoid is expanded in at least these typemaps
%typemap(check) int forvoid %{ abc_$isvoid(); /* must expand to abc_1() in a void return function (check typemap) */ %}
%typemap(check) int fornonvoid %{ def_$isvoid(); /* must expand to def_0() in a non void return function (check typemap) */ %}
%typemap(ret) void %{ abc_$isvoid(); /* must expand to abc_1() in a void return function (ret typemap $1_type) */ %}
%typemap(ret) long, void* %{ def_$isvoid(); /* must expand to def_0() in a non void return function (ret typemap $1_type) */ %}
%inline %{
void test_isvoid(int forvoid) {}
long test_nonvoid(int fornonvoid) { return 0; }
void* test_nonvoid_voidptr(int fornonvoid) { return 0; }
struct TestVoid {
void test_isvoid(int forvoid) {}
long test_nonvoid(int fornonvoid) { return 0; }
void* test_nonvoid_voidptr(int fornonvoid) { return 0; }
static void test_isvoid_static(int forvoid) {}
static long test_nonvoid_static(int fornonvoid) { return 0; }
static void* test_nonvoid_static_voidptr(int fornonvoid) { return 0; }
};
%}

View File

@ -771,7 +771,7 @@ public:
virtual int functionWrapper(Node *n) {
String *symname = Getattr(n, "sym:name");
SwigType *t = Getattr(n, "type");
SwigType *returntype = Getattr(n, "type");
ParmList *l = Getattr(n, "parms");
String *tm;
Parm *p;
@ -814,7 +814,7 @@ public:
tm = ctypeout;
Printf(c_return_type, "%s", tm);
} else {
Swig_warning(WARN_CSHARP_TYPEMAP_CTYPE_UNDEF, input_file, line_number, "No ctype typemap defined for %s\n", SwigType_str(t, 0));
Swig_warning(WARN_CSHARP_TYPEMAP_CTYPE_UNDEF, input_file, line_number, "No ctype typemap defined for %s\n", SwigType_str(returntype, 0));
}
if ((tm = Swig_typemap_lookup("imtype", n, "", 0))) {
@ -824,7 +824,7 @@ public:
Printf(im_return_type, "%s", tm);
im_outattributes = Getattr(n, "tmap:imtype:outattributes");
} else {
Swig_warning(WARN_CSHARP_TYPEMAP_CSTYPE_UNDEF, input_file, line_number, "No imtype typemap defined for %s\n", SwigType_str(t, 0));
Swig_warning(WARN_CSHARP_TYPEMAP_CSTYPE_UNDEF, input_file, line_number, "No imtype typemap defined for %s\n", SwigType_str(returntype, 0));
}
is_void_return = (Cmp(c_return_type, "void") == 0);
@ -995,9 +995,9 @@ public:
if (Len(tm))
Printf(f->code, "\n");
} else {
Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(t, 0), Getattr(n, "name"));
Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(returntype, 0), Getattr(n, "name"));
}
emit_return_variable(n, t, f);
emit_return_variable(n, returntype, f);
}
/* Output argument output code */
@ -1035,6 +1035,9 @@ public:
/* Substitute the cleanup code */
Replaceall(f->code, "$cleanup", cleanup);
bool isvoid = !Cmp(returntype, "void");
Replaceall(f->code, "$isvoid", isvoid ? "1" : "0");
/* Substitute the function name */
Replaceall(f->code, "$symname", symname);

View File

@ -1544,7 +1544,7 @@ public:
* --------------------------------------------------------------------------- */
virtual int functionWrapper(Node *n) {
String *symname = Getattr(n, "sym:name");
SwigType *t = Getattr(n, "type");
SwigType *returntype = Getattr(n, "type");
ParmList *l = Getattr(n, "parms");
String *tm;
Parm *p;
@ -1583,7 +1583,7 @@ public:
Printf(c_return_type, "%s", tm);
} else {
Swig_warning(WARN_D_TYPEMAP_CTYPE_UNDEF, input_file, line_number,
"No ctype typemap defined for %s\n", SwigType_str(t, 0));
"No ctype typemap defined for %s\n", SwigType_str(returntype, 0));
}
if ((tm = lookupDTypemap(n, "imtype"))) {
@ -1595,7 +1595,7 @@ public:
}
Printf(im_return_type, "%s", tm);
} else {
Swig_warning(WARN_D_TYPEMAP_IMTYPE_UNDEF, input_file, line_number, "No imtype typemap defined for %s\n", SwigType_str(t, 0));
Swig_warning(WARN_D_TYPEMAP_IMTYPE_UNDEF, input_file, line_number, "No imtype typemap defined for %s\n", SwigType_str(returntype, 0));
}
is_void_return = (Cmp(c_return_type, "void") == 0);
@ -1758,9 +1758,9 @@ public:
if (Len(tm))
Printf(f->code, "\n");
} else {
Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(t, 0), Getattr(n, "name"));
Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(returntype, 0), Getattr(n, "name"));
}
emit_return_variable(n, t, f);
emit_return_variable(n, returntype, f);
}
/* Output argument output code */
@ -1801,6 +1801,9 @@ public:
/* Substitute the cleanup code */
Replaceall(f->code, "$cleanup", cleanup);
bool isvoid = !Cmp(returntype, "void");
Replaceall(f->code, "$isvoid", isvoid ? "1" : "0");
/* Substitute the function name */
Replaceall(f->code, "$symname", symname);

View File

@ -1753,6 +1753,7 @@ private:
* ----------------------------------------------------------------------- */
void cleanupFunction(Node *n, Wrapper *f, ParmList *parms) {
SwigType *returntype = Getattr(n, "type");
String *cleanup = freearg(parms);
Printv(f->code, cleanup, NULL);
@ -1774,6 +1775,9 @@ private:
Delete(tm);
}
bool isvoid = !Cmp(returntype, "void");
Replaceall(f->code, "$isvoid", isvoid ? "1" : "0");
Replaceall(f->code, "$symname", Getattr(n, "sym:name"));
}

View File

@ -608,7 +608,7 @@ public:
virtual int functionWrapper(Node *n) {
String *iname = Getattr(n, "sym:name");
SwigType *d = Getattr(n, "type");
SwigType *returntype = Getattr(n, "type");
ParmList *l = Getattr(n, "parms");
Parm *p;
String *proc_name = 0;
@ -831,9 +831,9 @@ public:
Replaceall(tm, "$owner", "0");
Printv(f->code, tm, "\n", NIL);
} else {
throw_unhandled_guile_type_error(d);
throw_unhandled_guile_type_error(returntype);
}
emit_return_variable(n, d, f);
emit_return_variable(n, returntype, f);
// Documentation
if ((tm = Getattr(n, "tmap:out:doc"))) {
@ -843,7 +843,7 @@ public:
else
num_results = 0;
} else {
String *s = SwigType_str(d, 0);
String *s = SwigType_str(returntype, 0);
Chop(s);
Printf(returns, "<%s>", s);
Delete(s);
@ -875,10 +875,13 @@ public:
Printv(f->code, beforereturn, "\n", NIL);
Printv(f->code, "return gswig_result;\n", NIL);
bool isvoid = !Cmp(returntype, "void");
Replaceall(f->code, "$isvoid", isvoid ? "1" : "0");
/* Substitute the function name */
Replaceall(f->code, "$symname", iname);
// Undefine the scheme name
// Undefine the scheme name
Printf(f->code, "#undef FUNC_NAME\n");
Printf(f->code, "}\n");

View File

@ -853,7 +853,7 @@ public:
virtual int functionWrapper(Node *n) {
String *symname = Getattr(n, "sym:name");
SwigType *t = Getattr(n, "type");
SwigType *returntype = Getattr(n, "type");
ParmList *l = Getattr(n, "parms");
String *tm;
Parm *p;
@ -899,13 +899,13 @@ public:
if ((tm = Swig_typemap_lookup("jni", n, "", 0))) {
Printf(c_return_type, "%s", tm);
} else {
Swig_warning(WARN_JAVA_TYPEMAP_JNI_UNDEF, input_file, line_number, "No jni typemap defined for %s\n", SwigType_str(t, 0));
Swig_warning(WARN_JAVA_TYPEMAP_JNI_UNDEF, input_file, line_number, "No jni typemap defined for %s\n", SwigType_str(returntype, 0));
}
if ((tm = Swig_typemap_lookup("jtype", n, "", 0))) {
Printf(im_return_type, "%s", tm);
} else {
Swig_warning(WARN_JAVA_TYPEMAP_JTYPE_UNDEF, input_file, line_number, "No jtype typemap defined for %s\n", SwigType_str(t, 0));
Swig_warning(WARN_JAVA_TYPEMAP_JTYPE_UNDEF, input_file, line_number, "No jtype typemap defined for %s\n", SwigType_str(returntype, 0));
}
is_void_return = (Cmp(c_return_type, "void") == 0);
@ -1089,9 +1089,9 @@ public:
if (Len(tm))
Printf(f->code, "\n");
} else {
Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(t, 0), Getattr(n, "name"));
Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(returntype, 0), Getattr(n, "name"));
}
emit_return_variable(n, t, f);
emit_return_variable(n, returntype, f);
}
/* Output argument output code */
@ -1130,6 +1130,9 @@ public:
/* Substitute the cleanup code */
Replaceall(f->code, "$cleanup", cleanup);
bool isvoid = !Cmp(returntype, "void");
Replaceall(f->code, "$isvoid", isvoid ? "1" : "0");
/* Substitute the function name */
Replaceall(f->code, "$symname", symname);

View File

@ -927,7 +927,10 @@ int JSEmitter::emitCtor(Node *n) {
Template t_ctor(getTemplate("js_ctor"));
String *wrap_name = Swig_name_wrapper(Getattr(n, "sym:name"));
// prepare the function wrapper name
String *iname = Getattr(n, "sym:name");
SwigType *returntype = Getattr(n, "type");
String *wrap_name = Swig_name_wrapper(iname);
if (is_overloaded) {
t_ctor = getTemplate("js_overloaded_ctor");
Append(wrap_name, Getattr(n, "sym:overname"));
@ -949,6 +952,11 @@ int JSEmitter::emitCtor(Node *n) {
emitCleanupCode(n, wrapper, params);
bool isvoid = !Cmp(returntype, "void");
Replaceall(wrapper->code, "$isvoid", isvoid ? "1" : "0");
Replaceall(wrapper->code, "$symname", iname);
t_ctor.replace("$jsmangledname", state.clazz(NAME_MANGLED))
.replace("$jswrapper", wrap_name)
.replace("$jsmangledtype", state.clazz(TYPE_MANGLED))
@ -1257,6 +1265,7 @@ int JSEmitter::emitFunction(Node *n, bool is_member, bool is_static) {
// prepare the function wrapper name
String *iname = Getattr(n, "sym:name");
SwigType *returntype = Getattr(n, "type");
String *wrap_name = Swig_name_wrapper(iname);
if (is_overloaded) {
t_function = getTemplate(getOverloadedFunctionTemplate(is_member));
@ -1274,6 +1283,10 @@ int JSEmitter::emitFunction(Node *n, bool is_member, bool is_static) {
String *action = emit_action(n);
marshalOutput(n, params, wrapper, action);
emitCleanupCode(n, wrapper, params);
bool isvoid = !Cmp(returntype, "void");
Replaceall(wrapper->code, "$isvoid", isvoid ? "1" : "0");
Replaceall(wrapper->code, "$symname", iname);
t_function.replace("$jsmangledname", state.clazz(NAME_MANGLED))

View File

@ -516,7 +516,7 @@ public:
String *iname = Getattr(n, "sym:name");
String *lua_name = Getattr(n, "lua:name");
assert(lua_name);
SwigType *d = Getattr(n, "type");
SwigType *returntype = Getattr(n, "type");
ParmList *l = Getattr(n, "parms");
Parm *p;
String *tm;
@ -746,9 +746,9 @@ public:
Printf(f->code, "%s\n", tm);
// returnval++;
} else {
Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(d, 0), name);
Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(returntype, 0), name);
}
emit_return_variable(n, d, f);
emit_return_variable(n, returntype, f);
/* Output argument output code */
Printv(f->code, outarg, NIL);
@ -783,6 +783,9 @@ public:
/* Substitute the cleanup code */
Replaceall(f->code, "$cleanup", cleanup);
bool isvoid = !Cmp(returntype, "void");
Replaceall(f->code, "$isvoid", isvoid ? "1" : "0");
/* Substitute the function name */
Replaceall(f->code, "$symname", iname);
Replaceall(f->code, "$result", Swig_cresult_name());

View File

@ -214,7 +214,7 @@ public:
virtual int functionWrapper(Node *n) {
char *iname = GetChar(n, "sym:name");
SwigType *d = Getattr(n, "type");
SwigType *returntype = Getattr(n, "type");
ParmList *l = Getattr(n, "parms");
Parm *p;
@ -283,7 +283,7 @@ public:
{
String *parms = ParmList_protostr(l);
String *func = NewStringf("(*caller)(%s)", parms);
Wrapper_add_local(f, "caller", SwigType_lstr(d, func)); /*"(*caller)()")); */
Wrapper_add_local(f, "caller", SwigType_lstr(returntype, func));
}
}
@ -385,9 +385,9 @@ public:
Replaceall(tm, "$owner", "0");
Printv(f->code, tm, "\n", NIL);
} else {
throw_unhandled_mzscheme_type_error(d);
throw_unhandled_mzscheme_type_error(returntype);
}
emit_return_variable(n, d, f);
emit_return_variable(n, returntype, f);
// Dump the argument output code
Printv(f->code, Char(outarg), NIL);
@ -413,6 +413,9 @@ public:
Printf(f->code, "#undef FUNC_NAME\n");
Printv(f->code, "}\n", NIL);
bool isvoid = !Cmp(returntype, "void");
Replaceall(f->code, "$isvoid", isvoid ? "1" : "0");
/* Substitute the function name */
Replaceall(f->code, "$symname", iname);

View File

@ -446,8 +446,8 @@ public:
virtual int functionWrapper(Node *n) {
char *iname = GetChar(n, "sym:name");
SwigType *d = Getattr(n, "type");
String *return_type_normalized = normalizeTemplatedClassName(d);
SwigType *returntype = Getattr(n, "type");
String *return_type_normalized = normalizeTemplatedClassName(returntype);
ParmList *l = Getattr(n, "parms");
int director_method = 0;
Parm *p;
@ -524,7 +524,7 @@ public:
// adds local variables
Wrapper_add_local(f, "args", "CAMLparam1(args)");
Wrapper_add_local(f, "ret", "CAMLlocal2(swig_result,rv)");
d = SwigType_typedef_qualified(d);
returntype = SwigType_typedef_qualified(returntype);
emit_parameter_variables(l, f);
/* Attach the standard typemaps */
@ -660,9 +660,9 @@ public:
Replaceall(tm, "$ntype", return_type_normalized);
Printv(f->code, tm, "\n", NIL);
} else {
throw_unhandled_ocaml_type_error(d, "out");
throw_unhandled_ocaml_type_error(returntype, "out");
}
emit_return_variable(n, d, f);
emit_return_variable(n, returntype, f);
// Dump the argument output code
Printv(f->code, Char(outarg), NIL);
@ -695,6 +695,9 @@ public:
Printv(f->code, tab4, "CAMLreturn(swig_result);\n", NIL);
Printv(f->code, "}\n", NIL);
bool isvoid = !Cmp(returntype, "void");
Replaceall(f->code, "$isvoid", isvoid ? "1" : "0");
/* Substitute the function name */
Replaceall(f->code, "$symname", iname);
@ -1361,7 +1364,7 @@ public:
String *storage = Getattr(n, "storage");
String *value = Getattr(n, "value");
String *decl = Getattr(n, "decl");
String *returntype = Getattr(n, "type");
SwigType *returntype = Getattr(n, "type");
String *name = Getattr(n, "name");
String *classname = Getattr(parent, "sym:name");
String *c_classname = Getattr(parent, "name");

View File

@ -552,7 +552,7 @@ public:
String *iname = Getattr(n, "sym:name");
String *wname = Swig_name_wrapper(iname);
String *overname = Copy(wname);
SwigType *d = Getattr(n, "type");
SwigType *returntype = Getattr(n, "type");
ParmList *l = Getattr(n, "parms");
if (!overloaded && !addSymbol(iname, n))
@ -728,9 +728,9 @@ public:
Printf(f->code, "if (_outv.is_defined()) _outp = " "SWIG_Octave_AppendOutput(_outp, _outv);\n");
Delete(tm);
} else {
Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(d, 0), iname);
Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(returntype, 0), iname);
}
emit_return_variable(n, d, f);
emit_return_variable(n, returntype, f);
Printv(f->code, outarg, NIL);
Printv(f->code, cleanup, NIL);
@ -767,6 +767,9 @@ public:
/* Substitute the cleanup code */
Replaceall(f->code, "$cleanup", cleanup);
bool isvoid = !Cmp(returntype, "void");
Replaceall(f->code, "$isvoid", isvoid ? "1" : "0");
Replaceall(f->code, "$symname", iname);
Wrapper_print(f, f_wrappers);
DelWrapper(f);
@ -1274,7 +1277,7 @@ public:
int is_void = 0;
int is_pointer = 0;
String *decl = Getattr(n, "decl");
String *returntype = Getattr(n, "type");
SwigType *returntype = Getattr(n, "type");
String *name = Getattr(n, "name");
String *classname = Getattr(parent, "sym:name");
String *c_classname = Getattr(parent, "name");

View File

@ -652,7 +652,7 @@ public:
virtual int functionWrapper(Node *n) {
String *name = Getattr(n, "name");
String *iname = Getattr(n, "sym:name");
SwigType *d = Getattr(n, "type");
SwigType *returntype = Getattr(n, "type");
ParmList *l = Getattr(n, "parms");
String *overname = 0;
int director_method = 0;
@ -702,7 +702,7 @@ public:
} else {
Printf(f->code, " if (items < %d) {\n", num_required);
}
Printf(f->code, " SWIG_croak(\"Usage: %s\");\n", usage_func(Char(iname), d, l));
Printf(f->code, " SWIG_croak(\"Usage: %s\");\n", usage_func(Char(iname), returntype, l));
Printf(f->code, "}\n");
/* Write code to extract parameters. */
@ -854,9 +854,9 @@ public:
}
Printf(f->code, "%s\n", tm);
} else {
Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(d, 0), name);
Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(returntype, 0), name);
}
emit_return_variable(n, d, f);
emit_return_variable(n, returntype, f);
/* If there were any output args, take care of them. */
@ -893,6 +893,10 @@ public:
/* Substitute the cleanup code */
Replaceall(f->code, "$cleanup", cleanup);
bool isvoid = !Cmp(returntype, "void");
Replaceall(f->code, "$isvoid", isvoid ? "1" : "0");
Replaceall(f->code, "$symname", iname);
/* Dump the wrapper function */
@ -2035,7 +2039,7 @@ public:
Wrapper *w = NewWrapper();
String *tm;
String *wrap_args = NewString("");
String *returntype = Getattr(n, "type");
SwigType *returntype = Getattr(n, "type");
String *value = Getattr(n, "value");
String *storage = Getattr(n, "storage");
bool pure_virtual = false;

View File

@ -1265,7 +1265,7 @@ public:
}
String *name = GetChar(n, "name");
String *iname = GetChar(n, "sym:name");
SwigType *d = Getattr(n, "type");
SwigType *returntype = Getattr(n, "type");
ParmList *l = Getattr(n, "parms");
String *nodeType = Getattr(n, "nodeType");
int newobject = GetFlag(n, "feature:new");
@ -1583,9 +1583,9 @@ public:
Replaceall(tm, "$owner", newobject ? "1" : "0");
Printf(f->code, "%s\n", tm);
} else {
Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(d, 0), name);
Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(returntype, 0), name);
}
emit_return_variable(n, d, f);
emit_return_variable(n, returntype, f);
List *return_types = phptypes->process_phptype(n, 0, "tmap:out:phptype");
@ -1653,6 +1653,10 @@ public:
}
Replaceall(f->code, "$cleanup", cleanup);
bool isvoid = !Cmp(returntype, "void");
Replaceall(f->code, "$isvoid", isvoid ? "1" : "0");
Replaceall(f->code, "$symname", iname);
Wrapper_print(f, s_wrappers);
@ -2232,7 +2236,7 @@ public:
int is_void = 0;
int is_pointer = 0;
String *decl = Getattr(n, "decl");
String *returntype = Getattr(n, "type");
SwigType *returntype = Getattr(n, "type");
String *name = Getattr(n, "name");
String *classname = Getattr(parent, "sym:name");
String *c_classname = Getattr(parent, "name");

View File

@ -2686,7 +2686,7 @@ public:
String *name = Getattr(n, "name");
String *iname = Getattr(n, "sym:name");
SwigType *d = Getattr(n, "type");
SwigType *returntype = Getattr(n, "type");
ParmList *l = Getattr(n, "parms");
Node *parent = Swig_methodclass(n);
@ -3172,16 +3172,13 @@ public:
Delete(tm);
} else {
Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(d, 0), name);
Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(returntype, 0), name);
}
emit_return_variable(n, d, f);
emit_return_variable(n, returntype, f);
/* Output argument output code */
Printv(f->code, outarg, NIL);
bool isvoid = d && (SwigType_type(d) == T_VOID);
Replaceall(f->code, "$isvoid", isvoid ? "1" : "0");
/* Output cleanup code */
int need_cleanup = Len(cleanup) != 0;
if (need_cleanup) {
@ -3242,6 +3239,9 @@ public:
/* Substitute the cleanup code */
Replaceall(f->code, "$cleanup", cleanup);
bool isvoid = !Cmp(returntype, "void");
Replaceall(f->code, "$isvoid", isvoid ? "1" : "0");
/* Substitute the function name */
Replaceall(f->code, "$symname", iname);
Replaceall(f->code, "$result", "resultobj");
@ -5312,7 +5312,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
Wrapper *w = NewWrapper();
String *tm;
String *wrap_args = NewString("");
String *returntype = Getattr(n, "type");
SwigType *returntype = Getattr(n, "type");
String *value = Getattr(n, "value");
String *storage = Getattr(n, "storage");
bool pure_virtual = false;

View File

@ -1656,11 +1656,11 @@ void R::dispatchFunction(Node *n) {
int R::functionWrapper(Node *n) {
String *fname = Getattr(n, "name");
String *iname = Getattr(n, "sym:name");
String *type = Getattr(n, "type");
String *returntype = Getattr(n, "type");
if (debugMode) {
Printf(stdout,
"<functionWrapper> %s %s %s\n", fname, iname, type);
"<functionWrapper> %s %s %s\n", fname, iname, returntype);
}
String *overname = 0;
String *nodeType = Getattr(n, "nodeType");
@ -1703,17 +1703,14 @@ int R::functionWrapper(Node *n) {
p = nextSibling(p);
}
String *unresolved_return_type =
Copy(type);
if (expandTypedef(type) &&
SwigType_istypedef(type)) {
SwigType *resolved =
SwigType_typedef_resolve_all(type);
String *unresolved_return_type = Copy(returntype);
if (expandTypedef(returntype) && SwigType_istypedef(returntype)) {
SwigType *resolved = SwigType_typedef_resolve_all(returntype);
if (debugMode)
Printf(stdout, "<functionWrapper> resolved %s\n", Copy(unresolved_return_type));
if (expandTypedef(resolved)) {
type = Copy(resolved);
Setattr(n, "type", type);
returntype = Copy(resolved);
Setattr(n, "type", returntype);
}
}
if (debugMode)
@ -1756,8 +1753,8 @@ int R::functionWrapper(Node *n) {
Wrapper *f = NewWrapper();
Wrapper *sfun = NewWrapper();
int isVoidReturnType = (Strcmp(type, "void") == 0);
// Need to use the unresolved return type since
int isVoidReturnType = (Strcmp(returntype, "void") == 0);
// Need to use the unresolved returntype since
// typedef resolution removes the const which causes a
// mismatch with the function action
emit_return_variable(n, unresolved_return_type, f);
@ -1769,8 +1766,7 @@ int R::functionWrapper(Node *n) {
addCopyParam = addCopyParameter(rtype);
if (debugMode)
Printf(stdout, "Adding a .copy argument to %s for %s = %s\n",
iname, type, addCopyParam ? "yes" : "no");
Printf(stdout, "Adding a .copy argument to %s for %s = %s\n", iname, returntype, addCopyParam ? "yes" : "no");
Printv(f->def, "SWIGEXPORT SEXP\n", wname, " ( ", NIL);
@ -2017,7 +2013,7 @@ int R::functionWrapper(Node *n) {
} else {
Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number,
"Unable to use return type %s in function %s.\n", SwigType_str(type, 0), fname);
"Unable to use return type %s in function %s.\n", SwigType_str(returntype, 0), fname);
}
@ -2110,6 +2106,9 @@ int R::functionWrapper(Node *n) {
Printv(f->code, "}\n", NIL);
Printv(sfun->code, "\n}", NIL);
bool isvoid = !Cmp(returntype, "void");
Replaceall(f->code, "$isvoid", isvoid ? "1" : "0");
/* Substitute the function name */
Replaceall(f->code,"$symname",iname);

View File

@ -1644,7 +1644,7 @@ public:
bool destructor;
String *symname = Copy(Getattr(n, "sym:name"));
SwigType *t = Getattr(n, "type");
SwigType *returntype = Getattr(n, "type");
ParmList *l = Getattr(n, "parms");
int director_method = 0;
String *tm;
@ -1842,7 +1842,7 @@ public:
}
/* Return value if necessary */
if (SwigType_type(t) != T_VOID && current != CONSTRUCTOR_INITIALIZE) {
if (SwigType_type(returntype) != T_VOID && current != CONSTRUCTOR_INITIALIZE) {
need_result = 1;
if (GetFlag(n, "feature:predicate")) {
Printv(actioncode, tab4, "vresult = (", Swig_cresult_name(), " ? Qtrue : Qfalse);\n", NIL);
@ -1873,7 +1873,7 @@ public:
Delete(tm);
} else {
Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s.\n", SwigType_str(t, 0));
Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s.\n", SwigType_str(returntype, 0));
}
}
}
@ -1881,7 +1881,7 @@ public:
Append(f->code, actioncode);
Delete(actioncode);
}
emit_return_variable(n, t, f);
emit_return_variable(n, returntype, f);
}
/* Extra code needed for new and initialize methods */
@ -1891,7 +1891,7 @@ public:
SwigType *psmart = smart ? Copy(smart) : 0;
if (psmart)
SwigType_add_pointer(psmart);
SwigType *classtype = psmart ? psmart : t;
SwigType *classtype = psmart ? psmart : returntype;
need_result = 1;
Printf(f->code, "VALUE vresult = SWIG_NewClassInstance(self, SWIGTYPE%s);\n", Char(SwigType_manglestr(classtype)));
Printf(f->code, "#ifndef HAVE_RB_DEFINE_ALLOC_FUNC\n");
@ -1904,7 +1904,7 @@ public:
else
{
if ( need_result > 1 ) {
if ( SwigType_type(t) == T_VOID )
if ( SwigType_type(returntype) == T_VOID )
Printf(f->code, "vresult = rb_ary_new();\n");
else
{
@ -1984,6 +1984,9 @@ public:
/* Substitute the cleanup code */
Replaceall(f->code, "$cleanup", cleanup);
bool isvoid = !Cmp(returntype, "void");
Replaceall(f->code, "$isvoid", isvoid ? "1" : "0");
/* Substitute the function name */
Replaceall(f->code, "$symname", symname);
@ -3020,7 +3023,7 @@ public:
Wrapper *w = NewWrapper();
String *tm;
String *wrap_args = NewString("");
String *returntype = Getattr(n, "type");
SwigType *returntype = Getattr(n, "type");
Parm *p;
String *value = Getattr(n, "value");
String *storage = Getattr(n, "storage");

View File

@ -515,6 +515,9 @@ public:
/* TODO */
/* Final substitutions if applicable */
bool isvoid = !Cmp(functionReturnType, "void");
Replaceall(wrapper->code, "$isvoid", isvoid ? "1" : "0");
Replaceall(wrapper->code, "$symname", functionName);
/* Set CheckInputArgument and CheckOutputArgument input arguments */

View File

@ -261,7 +261,7 @@ public:
virtual int functionWrapper(Node *n) {
String *name = Getattr(n, "name"); /* Like to get rid of this */
String *iname = Getattr(n, "sym:name");
SwigType *type = Getattr(n, "type");
SwigType *returntype = Getattr(n, "type");
ParmList *parms = Getattr(n, "parms");
String *overname = 0;
@ -390,7 +390,7 @@ public:
}
}
Printf(argstr, "%s\"", usage_string(Char(iname), type, parms));
Printf(argstr, "%s\"", usage_string(Char(iname), returntype, parms));
Printv(f->code, "if (SWIG_GetArgs(interp, objc, objv,", argstr, args, ") == TCL_ERROR) SWIG_fail;\n", NIL);
@ -455,9 +455,9 @@ public:
}
Printf(f->code, "%s\n", tm);
} else {
Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(type, 0), name);
Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(returntype, 0), name);
}
emit_return_variable(n, type, f);
emit_return_variable(n, returntype, f);
/* Dump output argument code */
Printv(f->code, outarg, NIL);
@ -484,6 +484,10 @@ public:
/* Substitute the cleanup code */
Replaceall(f->code, "$cleanup", cleanup);
bool isvoid = !Cmp(returntype, "void");
Replaceall(f->code, "$isvoid", isvoid ? "1" : "0");
Replaceall(f->code, "$symname", iname);
/* Dump out the function */