digitalmars.D.learn - Dump mixins (preprocessed/generated) code
- Domingo Alvarez Duarte (32/32) Jul 18 2014 Hello !
- Rikki Cattermole (5/35) Jul 18 2014 You can use pragma(msg, ""); to output text at compile time if the value...
- Domingo Alvarez Duarte (17/17) Jul 18 2014 Thank you so much !
- Rikki Cattermole (4/20) Jul 18 2014 I can't really tell at this point.
- Domingo Alvarez Duarte (9/9) Jul 18 2014 Thanks for all you answers, I think I found the problem.
- Dicebot (5/14) Jul 18 2014 In general all identifiers starting with __ (double underscore)
- Domingo Alvarez Duarte (3/3) Jul 18 2014 It seems to be a bug somewhere because tired of getting errors
- Dicebot (5/5) Jul 18 2014 While `static if` false branch does not get compiled or
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() { } -----
Jul 18 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"));
Jul 18 2014
Thank you so much ! That did exactly what I was looking for, but now why I'm getting that error message ? Any help is welcome ! Cheers ! The generated code seems to fine: ---- debug assert(t.stackIndex > t.stackBase, (printStack(t), printCallStack(t), "fail.")); static if(!is(typeof(__FUNCTION__))) { struct __FUNCTION {} const char[] __FUNCTION__ = _getJustName(__FUNCTION.mangleof); } if((stackSize(t) - 1) < 1) throwStdException(t, "ApiError", __FUNCTION__ ~ " - not enough parameters (expected {}, only have {} stack slots)", 1, stackSize(t) - 1); ----
Jul 18 2014
On 19/07/2014 12:09 a.m., Domingo Alvarez Duarte wrote:Thank you so much ! That did exactly what I was looking for, but now why I'm getting that error message ? Any help is welcome ! Cheers ! The generated code seems to fine: ---- debug assert(t.stackIndex > t.stackBase, (printStack(t), printCallStack(t), "fail.")); static if(!is(typeof(__FUNCTION__))) { struct __FUNCTION {} const char[] __FUNCTION__ = _getJustName(__FUNCTION.mangleof); } if((stackSize(t) - 1) < 1) throwStdException(t, "ApiError", __FUNCTION__ ~ " - not enough parameters (expected {}, only have {} stack slots)", 1, stackSize(t) - 1); ----I can't really tell at this point. Try removing the code one line at a time (from the generation). You'll eventually work out what is killing it.
Jul 18 2014
Thanks for all you answers, I think I found the problem. The constant __FUNCTION__ was not a compiler reserved word at the time MiniD/Croc was created and it was introduced later on dmd2, it was clashing with it. I renamed it to __MFUNCTUION__ and it compiles now, I'm getting more errors of other kinds and trying to fix then. I plan to fork https://github.com/JarrettBillingsley/Croc and make it available. Cheers !
Jul 18 2014
On Friday, 18 July 2014 at 14:25:57 UTC, Domingo Alvarez Duarte wrote:Thanks for all you answers, I think I found the problem. The constant __FUNCTION__ was not a compiler reserved word at the time MiniD/Croc was created and it was introduced later on dmd2, it was clashing with it. I renamed it to __MFUNCTUION__ and it compiles now, I'm getting more errors of other kinds and trying to fix then. I plan to fork https://github.com/JarrettBillingsley/Croc and make it available. Cheers !In general all identifiers starting with __ (double underscore) are considered reserved by compiler / standard library and should never be used anywhere else.
Jul 18 2014
It seems to be a bug somewhere because tired of getting errors with dmd 2.065 I switched to dmd 2.066 trunk and the error vanished.
Jul 18 2014
While `static if` false branch does not get compiled or semantically evaluated it still should have a valid syntax. __FUNCTION__ gets replaced with a fully qualified name of a function which has dot inside - illegal identifier for a variable. This causes parser to freak out.
Jul 18 2014