Meta information parser

Sjoerd van Leent svanleent at gmail.com
Mon May 29 12:08:07 PDT 2006


Hello,

I've been thinking about this, but if we want to use D for let's say 
webservices, Corba, Dynamic linking and so forth, we have to be able to 
store meta information.

Now, I don't like to have this around:

[WebMethod]
Foo();

nor do I like it the Javaish way, with @interface attributes.

So, rather than using that, wouldn't it be possible to, at compile time, 
be able to link another program to the parser, being able to generate 
additional code.

This way one doesn't have to deal with all kinds of fuzzy 
meta-declarations, but one can still have the possibility of accessing 
module/class/struct/enum/template/method information at compile time.

So I'd like to have the possibility:

foo.d
-----
module foo;
import std.stdio;

int main(char[][] args) {
	writefln("%s", "Hello World!");
	return 0;
}
-----

then:

dmd foo.d -offoo.exe -parsethrough daspect

daspect.exe, generated from daspect.d could for example look like:

daspect.d:
-----
module daspect;

import std.meta;

void main(char[][] args) {
     // From args or file location in args[1]
     Meta meta = Meta.deserialize(args);

     MetaModule module = meta.module;
     writefln("Injecting statements for: %s", module.name);

     foreach(Method method; module.methods) {
         // Perhaps using bare asm or some semi asm
         // or plain d code, parsed by dmd parser, perhaps
         // just parsing again the generated file
         method.start.inject(
             "writefln(\"%s\", \"Enter [" ~
             Meta.escape(module.name ~ "]" ~
             method.name) ~ "]\");");
         method.end.inject(
             "writefln(\"%s\", \"Leave [" ~
             Meta.escape(module.name ~ "]" ~
             method.name) ~ "]\");");
     }
     return 0;
}

any ideas on this?

Regards,
Sjoerd



More information about the Digitalmars-d mailing list