Re: $typemap and variable names

Lindley French <[email protected]> Mon, 21 Jun 2021 19:34:38 -0700
Newsgroups gmane.comp.programming.swig
Message-ID <CALwtg06+HrppwKROiksxq7zJVoFu5TC2z4YB72Gm1ZFj3Ax1fQ@mail.gmail.com>
I was eventually able to solve this by using an anonymous class so that the
variable name could be reused with a different type without trouble.

On Sun, Jun 20, 2021 at 3:26 AM William S Fulton <[email protected]>
wrote:

> Hi Lindley
>
> This is quite hard to follow what you are doing. From what I can make out
> the expansion of $javainput in 'javain' is okay. It should work the same as
> $input in the 'in' typemap and I can't see a difference in behaviour.
>
> The techniques to handle template types in map<K, V> can be seen in
> Lib/java/std_map.i. Perhaps that will help you. If not, perhaps give a full
> example of std:map that you want to customise.
>
> William
>
> On Tue, 27 Apr 2021 at 18:40, Lindley French <[email protected]> wrote:
>
>> Im trying to write a typemap involving subtypes. Specifically, for
>> map<K,V>.
>>
>> The problem is that when I reference $typemap(javain, K) within
>> %typemap(javain) map<K,V>, the value of $javainput is the same variable
>> name in the inner and outer typemaps, even though it has different types.
>>
>> In the 'in' typemap I was able to handle this with scoping to create a
>> shadow. I can do the same in Java with an anonymous class. But that’s
>> super-verbose, and since the javain typemap is an expression rather than a
>> block, I'm not sure how to format it so it's readable. A Java lambda
>> would be much cleaner, but they don't allow shadowing.
>>
>> According to
>> http://www.swig.org/Doc3.0/SWIGDocumentation.html#Typemaps_special_macro_typemap,
>> "The special variables within the matched typemap are expanded into those
>> for the matched typemap type, not the typemap within which the macro is
>> called." But this doesn't appear to apply to $javainput. I thought
>> that $typemap(javain, KeyType& key) might set $javainput to "key", but it
>> doesn't, unfortunately.
>>
>> Is it possible to reassign the javainput variable temporarily, or use a
>> special syntax that tells swig to rename it for me in $typemap lookups?
>>
> _______________________________________________
>> Swig-user mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/swig-user
>>
>

_______________________________________________
Swig-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/swig-user