www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5309] New: Add language support for external D symbols refs


           Summary: Add language support for external D symbols refs
           Product: D
           Version: D2
          Platform: All
        OS/Version: Windows
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: ah08010-d yahoo.com

--- Comment #0 from Austin Hastings <ah08010-d yahoo.com> 2010-12-02 05:01:21
PST ---
Presently there is no way that I can find to declare a D symbol in another
module. That is, this doesn't work:

module m1;

import some.type; // defines SomeType

extern(D) SomeType m2.var;

void foo()


The reason I want this is that I am generating D source code programmatically -
a file full of tables. And I am using DMD's dependency reporting facility to
generate build rules for use in a Makefile.

Because of the build rules, all of the source code has to be valid enough to
satisfy DMD at all times. Including when the generated code files do not exist
(after a make clean, for example).

That means that I cannot have an import of a file which does not exist, so I
cannot simply do import generated.module; 

D *does* have support for extern (C), and I could certainly use that. But that
eliminates the benefit of namespacing in the first place. 

What I would like is a way to provide a module definition that includes the
declaration of an external D object. This way my code could import that module
definition, and the build system would be happy. And the generated code could
be generated, compiled, and added to the library later on, and the whole thing
would work together and sing Kumbaya and live in peace and harmony, modulo the
occasional lion attack.

Frustratingly, DMD already HAS this: the .di file. So that's what I'm using. It
works pretty much exactly the way I want, except of course that I'm not
generating the .di file from the .d source (which is itself a generated file).

Sadly, though, the spec says

D interface files bear some analogous similarities to C++ header files. But
they are not required in the way that C++ header files are, and they are not
part of the D language. They are a feature of the compiler, and serve only as
an optimization of the build process. 

The important part being "they are not part of the D language."

I'm sure that I'm not the first, or even the second, person to think of
generating data tables in source files. So I'm requesting either (1) what is
the part-of-the-D-language way to do this; or (2) please add the .di mechanism,
or something very much like it, to the D language proper.

Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 02 2010