Thread overview | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
July 18, 2014 Dump mixins (preprocessed/generated) code | ||||
---|---|---|---|---|
| ||||
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() { } ----- |
July 18, 2014 Re: Dump mixins (preprocessed/generated) code | ||||
---|---|---|---|---|
| ||||
Posted in reply to Domingo Alvarez Duarte | 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"));
|
July 18, 2014 Re: Dump mixins (preprocessed/generated) code | ||||
---|---|---|---|---|
| ||||
Posted in reply to Rikki Cattermole | 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); ---- |
July 18, 2014 Re: Dump mixins (preprocessed/generated) code | ||||
---|---|---|---|---|
| ||||
Posted in reply to Domingo Alvarez Duarte | 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.
|
July 18, 2014 Re: Dump mixins (preprocessed/generated) code | ||||
---|---|---|---|---|
| ||||
Posted in reply to Domingo Alvarez Duarte | 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. |
July 18, 2014 Re: Dump mixins (preprocessed/generated) code | ||||
---|---|---|---|---|
| ||||
Posted in reply to Rikki Cattermole | 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 ! |
July 18, 2014 Re: Dump mixins (preprocessed/generated) code | ||||
---|---|---|---|---|
| ||||
Posted in reply to Domingo Alvarez Duarte | 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.
|
July 18, 2014 Re: Dump mixins (preprocessed/generated) code | ||||
---|---|---|---|---|
| ||||
Posted in reply to Domingo Alvarez Duarte | 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. |
Copyright © 1999-2021 by the D Language Foundation