Fix handling of const object parameters and return types

Simply ignore the const on them, to avoid ending up with an extra and
invalid "const" in the generated code.

This fixes director_pass_by_value and typemap_out_optimal unit tests
after the latest merge.
This commit is contained in:
Vadim Zeitlin 2022-09-17 15:30:31 +02:00
commit 049d3c309b

View file

@ -702,16 +702,34 @@ private:
} else {
String* classname;
if (Node* const class_node = Language::instance()->classLookup(type)) {
// Special case: if this is a pointer passed by (const) reference, we return just the pointer directly because we don't have any pointer-valued variable
// to give out a reference to.
if (typeKind == Type_Ptr && strncmp(Char(resolved_type), "r.q(const).", 11) == 0) {
scoped_dohptr deref_type(Copy(resolved_type));
Delslice(deref_type, 0, 11);
typestr = SwigType_str(deref_type, 0);
} else {
typestr = SwigType_str(resolved_type, 0);
// Deal with some special cases:
switch (typeKind) {
case Type_Ptr:
// If this is a pointer passed by const reference, we return just the pointer directly because we don't have any pointer-valued variable to give out
// a reference to.
if (strncmp(Char(resolved_type), "r.q(const).", 11) == 0) {
scoped_dohptr deref_type(Copy(resolved_type));
Delslice(deref_type, 0, 11);
typestr = SwigType_str(deref_type, 0);
}
break;
case Type_Obj:
// Const objects are just objects for our purposes here, remove the const from them to avoid having "const const" in the output.
if (SwigType_isconst(resolved_type))
SwigType_del_qualifier(resolved_type);
break;
case Type_Ref:
case Type_Enm:
case Type_Max:
// Nothing special to do.
break;
}
if (!typestr)
typestr = SwigType_str(resolved_type, 0);
classname = Getattr(class_node, "sym:name");
// We don't use namespaces, but the type may contain them, so get rid of them by replacing the base type name, which is fully qualified, with just the