HaxeFoundation / haxe

Haxe - The Cross-Platform Toolkit
https://haxe.org
6.03k stars 648 forks source link

[cpp] Extend Map and IMap interface #7592

Open azrafe7 opened 5 years ago

azrafe7 commented 5 years ago

This is a bit lengthy, and probably pretty hairy! :grimacing:

I'm trying to extend the standard Map (and IMap), so that I could add a couple of methods to it. But am encountering some issues with cpp (other targets seem to be OK).

My best effort on trying to reduce the issue so far is here (for now): https://github.com/azrafe7/hxtend_map/blob/c778207b6a11d457be5374b53f5a4cc7c3d99058/Issue.hx

The cpp compiler complains with something like:

Error: In file included from ./src/XStringMap.cpp:8:0:
include/XStringMap.h:58:8: error: ‘void XStringMap_obj::set_41d0cb46(Dynamic, Dynamic)’ cannot be overloaded
   void set_41d0cb46( ::Dynamic k, ::Dynamic v);
        ^
include/XStringMap.h:50:8: error: with ‘void XStringMap_obj::set_41d0cb46(Dynamic, Dynamic)’
   void set_41d0cb46( ::Dynamic k, ::Dynamic v);
        ^
./src/XStringMap.cpp:91:6: error: redefinition of ‘void XStringMap_obj::set_41d0cb46(Dynamic, Dynamic)’
 void XStringMap_obj::set_41d0cb46( ::Dynamic k, ::Dynamic v) {
      ^
./src/XStringMap.cpp:75:6: error: ‘void XStringMap_obj::set_41d0cb46(Dynamic, Dynamic)’ previously defined here
 void XStringMap_obj::set_41d0cb46( ::Dynamic k, ::Dynamic v) {
      ^

(travis log: https://travis-ci.org/azrafe7/hxtend_map/builds/450644462)

Other targets seem to be OK with it.

PS: I've also tried a bottom-up approach (https://gist.github.com/azrafe7/9740c24595247f25bcf497c93835094c) to better identify the issue, but hxcpp is ok with that gist. So I've taken my codebase and tried to remove all unnecessary things.

If you want me to test something on my end I've no problem doing it.

Thanks

azrafe7 commented 5 years ago

Update: hxcpp seems to generate two identical definitions and implementations (same mangled name) for the set() method (but only for that, why not for get() too for example?).

Anyway removing them (the duplicates) manually from the generated cpp output, and manually compiling the Build.xml makes things work as other targets.

@hughsando, I'd appreciate if you could take a quick look at it. :stuck_out_tongue_winking_eye:

hughsando commented 5 years ago

I have great problems with the IMap interface, since it make it extremely difficult to write fast code for the Map class, which should be the main priority. AFAIK, it should not ever show up: https://github.com/HaxeFoundation/haxe/issues/6394 The multi-type logic is a bit beyond me, so I don't really know what to do.