www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - file and debug info all in one place?

reply Amex <Amex gmail.com> writes:
__FILE__, __LINE__, etc...

we have to use these as template parameters

Why not just make every function have this info available in a 
"hidden" struct? No need to mess around with any extra bloating 
of the function signature.
May 25
next sibling parent reply user1234 <user1234 12.de> writes:
On Saturday, 25 May 2019 at 19:29:25 UTC, Amex wrote:
 __FILE__, __LINE__, etc...

 we have to use these as template parameters

 Why not just make every function have this info available in a 
 "hidden" struct? No need to mess around with any extra bloating 
 of the function signature.
rather log when you enter a function, this will be more simple in your case enum lg = `writeln(__FILE_FULL_PATH, "(", __LINE__, "): enter", __PRETTY_FUNCTION__);`; and put mixin(lg); in your functions. or use std.experimental.logger which does more or less the same when you just log() without supplemental args.
May 25
parent Amex <Amex gmail.com> writes:
On Saturday, 25 May 2019 at 19:54:28 UTC, user1234 wrote:
 On Saturday, 25 May 2019 at 19:29:25 UTC, Amex wrote:
 __FILE__, __LINE__, etc...

 we have to use these as template parameters

 Why not just make every function have this info available in a 
 "hidden" struct? No need to mess around with any extra 
 bloating of the function signature.
rather log when you enter a function, this will be more simple in your case enum lg = `writeln(__FILE_FULL_PATH, "(", __LINE__, "): enter", __PRETTY_FUNCTION__);`; and put mixin(lg); in your functions. or use std.experimental.logger which does more or less the same when you just log() without supplemental args.
No, this won't get the the callee's info....
May 26
prev sibling parent reply Exil <Exil gmall.com> writes:
On Saturday, 25 May 2019 at 19:29:25 UTC, Amex wrote:
 __FILE__, __LINE__, etc...

 we have to use these as template parameters

 Why not just make every function have this info available in a 
 "hidden" struct? No need to mess around with any extra bloating 
 of the function signature.
Not really sure what you mean, but you don't need to use templates for this. You can just pass the parameters in through the function parameters instead. No template bloat. Assuming you want to know the values of those variables at the call site then that would be bad anyways. As now every function would have to pass this extra meta data. The function name, line of code, name of the module, basically all of it will need to be stored in this hidden struct and passed even when it might never even be used. Otherwise it would just complicate when you do or don't need to pass the struct. It's better as it is now, you only pay for it when you need it.
May 25
parent reply Amex <Amex gmail.com> writes:
On Sunday, 26 May 2019 at 02:06:21 UTC, Exil wrote:
 On Saturday, 25 May 2019 at 19:29:25 UTC, Amex wrote:
 __FILE__, __LINE__, etc...

 we have to use these as template parameters

 Why not just make every function have this info available in a 
 "hidden" struct? No need to mess around with any extra 
 bloating of the function signature.
Not really sure what you mean, but you don't need to use templates for this. You can just pass the parameters in through the function parameters instead. No template bloat. Assuming you want to know the values of those variables at the call site then that would be bad anyways. As now every function would have to pass this extra meta data. The function name, line of code, name of the module, basically all of it will need to be stored in this hidden struct and passed even when it might never even be used. Otherwise it would just complicate when you do or don't need to pass the struct. It's better as it is now, you only pay for it when you need it.
No, it wouldn't... you don't have to do this now. You are simply adding template parameters to your functions only to get compiler information. There is no point in doing that. The compiler can easily fill out all that information silently and do... And you don't have to pay for it when not using it... if you don't reference the struct then it doesn't need to be generated.
May 26
parent Exil <Exil gmall.com> writes:
On Sunday, 26 May 2019 at 17:46:07 UTC, Amex wrote:
 On Sunday, 26 May 2019 at 02:06:21 UTC, Exil wrote:
 On Saturday, 25 May 2019 at 19:29:25 UTC, Amex wrote:
 __FILE__, __LINE__, etc...

 we have to use these as template parameters

 Why not just make every function have this info available in 
 a "hidden" struct? No need to mess around with any extra 
 bloating of the function signature.
Not really sure what you mean, but you don't need to use templates for this. You can just pass the parameters in through the function parameters instead. No template bloat. Assuming you want to know the values of those variables at the call site then that would be bad anyways. As now every function would have to pass this extra meta data. The function name, line of code, name of the module, basically all of it will need to be stored in this hidden struct and passed even when it might never even be used. Otherwise it would just complicate when you do or don't need to pass the struct. It's better as it is now, you only pay for it when you need it.
No, it wouldn't... you don't have to do this now. You are simply adding template parameters to your functions only to get compiler information. There is no point in doing that. The compiler can easily fill out all that information silently and do...
I feel there is a misunderstanding here. import std.stdio; void test(int ln = __LINE__, string fn = __FUNCTION__ ) { writeln( ln, "\t", fn, " / ", __FUNCTION__ ); } void subtest() { test(); } void main() { test(); subtest(); } https://run.dlang.io/is/RsSbMa This will print: 13 onlineapp.main / onlineapp.test 8 onlineapp.subtest / onlineapp.test When passing through as a parameter (as you said) it is using the information from the caller. This information is changed and the compiler doesn't know which one is which until it is called. Now you should see the problem here, if the compiler just silently fills out this information for a template. struct S { enum int line = __hidden_struct.__LINE__; // proposed hidden struct } S a; S b; // will fail since on different lines, but would expect to pass static assert(a.line == b.line); a and b won't be equal even though they are the exact same type. This is why it needs to be a template, because they aren't actually the same type if you are using different information.
 And you don't have to pay for it when not using it... if you 
 don't reference the struct then it doesn't need to be generated.
You would be paying for everything, even if you only needed say __LINE__. It would still need to fill in the entire struct. Storing things like the file name even though it isn't used. If you don't do it this way, then it becomes way more complicated and the function signature will reflect that.
May 26