www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - mixin()-ed code not treated the same as surrounding code

reply Roman Hargrave <roman hargrave.info> writes:
I have a mixin & generator I defined in order to mimic a 
corresponding CPP macro, DefineList(string name, string typename):

// See Torch - List.h, macro DEFINE_NEW_LIST(NAME, TYPE)
string DefineList(string name, string typename)
       "class " ~ name ~ " : TorchObject {"
       ~ "public: "
       ~ typename ~ "** nodes;"
       ~ "int n_nodes;"
       ~ " disable this();"
       ~ "final void add(" ~ name ~ "* list);"
       ~ "final void addNode(" ~ typename ~ "* node);"
       ~ "}";

When used in an extern block, the compiler does not use the 
requested linkage when generating symbols for the class.

Given the following:

extern(C++, Torch)
    private import CXXTorch.TorchObject;
    private import CXXTorch.List;
    private import CXXTorch.general;

    class Sequence : TorchObject
       // body

    mixin(DefineList("SequenceList", "Sequence"));

I would expect the following linker symbols:


But instead I get:


Which dont reflect any of the classifiers, nor the linkage 
specified for SequenceList by DefineList.

Firstly, add() and addNode() are potentially virtual (even though 
marked final), and a constructor is present (even though it has 
 disable, though I'm unfamiliar with the ABI semantics of 

Adding the linkage specifier to the return value of DefineList 
makes no difference.

The compiler does use the requested linkage for class Sequence, 
Aug 13 2017
next sibling parent Roman Hargrave <roman hargrave.info> writes:

Manually defining the class yields the same results (a class with 
D linkage).

What's going on here?
Aug 13 2017
prev sibling parent Adam D. Ruppe <destructionator gmail.com> writes:
On Sunday, 13 August 2017 at 19:50:57 UTC, Roman Hargrave wrote:
 But instead I get:

How are you getting that list? Those particular things are hidden D specific symbols so it might be generating those AND the ones you actually want. Of course, it is also possible that the extern(C++) just needs to be explicitly written on each class. I don't really know.
Aug 13 2017