Dump mixins (preprocessed/generated) code

Rikki Cattermole via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jul 18 04:41:46 PDT 2014


On 18/07/2014 11:39 p.m., Domingo Alvarez Duarte wrote:
> Hello !
>
> I'm trying to make MiniD/Croc work with dmd2 and I'm having a problem
> with this code and I want to know how to dump the generated code to
> understand what's happening.
>
> How that can be done ?
>
> debugmixin.d-mixin-15(15): Error: no identifier for declarator char[]
>
> -----debugmixin.d
> /// Eheheh, I has a __FUNCTION__.
> const char[] FuncNameMix = "static if(!is(typeof(__FUNCTION__))) {
> struct __FUNCTION {} const char[] __FUNCTION__ =
> _getJustName(__FUNCTION.mangleof); }";
>
> template apiCheckNumParams(const char[] numParams, const char[] t = "t")
> {
>      const char[] apiCheckNumParams =
>      "debug assert(" ~ t ~ ".stackIndex > " ~ t ~ ".stackBase,
> (printStack(" ~ t ~ "), printCallStack(" ~ t ~ "), \"fail.\"));" ~
>      FuncNameMix ~
>      "if((stackSize(" ~ t ~ ") - 1) < " ~ numParams ~ ")"
>          "throwStdException(" ~ t ~ ", \"ApiError\", __FUNCTION__ ~ \" -
> not enough parameters (expected {}, only have {} stack slots)\", " ~
> numParams ~ ", stackSize(" ~ t ~ ") - 1);";
> }
>
> void setHookFunc(void* t, ubyte mask, uint hookDelay)
> {
>      mixin(apiCheckNumParams!("1"));
> }
>
> void main()
> {
> }
> -----

You can use pragma(msg, ""); to output text at compile time if the value 
is known during compilation (aka can go into a string mixin).

e.g.
pragma(msg, apiCheckNumParams!("1"));


More information about the Digitalmars-d-learn mailing list