www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - alias symbol name

reply Radu <void null.pt> writes:
Consider this https://run.dlang.io/is/HyY2qG

---
void main()
{
     import std.traits;
     size_t s;

     pragma(msg, typeof(s).stringof);
     pragma(msg, mangledName!(typeof(s)));
     pragma(msg, mangledName!s);
}
---

It outputs:
---
ulong
m
_D9onlineapp4mainFZ1sm
---

I'm looking for a way to get the `s` type symbol name (size_t) 
not whatever the alias is pointing to (ulong in this case).

Is there a way to obtain the alias symbol name?
Jun 26 2018
parent reply Stefan Koch <uplink.coder googlemail.com> writes:
On Tuesday, 26 June 2018 at 09:14:11 UTC, Radu wrote:
 Consider this https://run.dlang.io/is/HyY2qG

 ---
 void main()
 {
     import std.traits;
     size_t s;

     pragma(msg, typeof(s).stringof);
     pragma(msg, mangledName!(typeof(s)));
     pragma(msg, mangledName!s);
 }
 ---

 It outputs:
 ---
 ulong
 m
 _D9onlineapp4mainFZ1sm
 ---

 I'm looking for a way to get the `s` type symbol name (size_t) 
 not whatever the alias is pointing to (ulong in this case).

 Is there a way to obtain the alias symbol name?
__traits(identifier, sym);
Jun 26 2018
parent reply Radu <void null.pt> writes:
On Tuesday, 26 June 2018 at 09:24:15 UTC, Stefan Koch wrote:
 On Tuesday, 26 June 2018 at 09:14:11 UTC, Radu wrote:
 Consider this https://run.dlang.io/is/HyY2qG

 ---
 void main()
 {
     import std.traits;
     size_t s;

     pragma(msg, typeof(s).stringof);
     pragma(msg, mangledName!(typeof(s)));
     pragma(msg, mangledName!s);
 }
 ---

 It outputs:
 ---
 ulong
 m
 _D9onlineapp4mainFZ1sm
 ---

 I'm looking for a way to get the `s` type symbol name (size_t) 
 not whatever the alias is pointing to (ulong in this case).

 Is there a way to obtain the alias symbol name?
__traits(identifier, sym);
Him, that will print the symbol name, in my case `s`. To cut to chase - I'm looking something that will print `size_t` for the symbol `s`.
Jun 26 2018
parent reply Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
On Tuesday, June 26, 2018 09:47:44 Radu via Digitalmars-d-learn wrote:
 On Tuesday, 26 June 2018 at 09:24:15 UTC, Stefan Koch wrote:
 On Tuesday, 26 June 2018 at 09:14:11 UTC, Radu wrote:
 Consider this https://run.dlang.io/is/HyY2qG

 ---
 void main()
 {

     import std.traits;
     size_t s;

     pragma(msg, typeof(s).stringof);
     pragma(msg, mangledName!(typeof(s)));
     pragma(msg, mangledName!s);

 }
 ---

 It outputs:
 ---
 ulong
 m
 _D9onlineapp4mainFZ1sm
 ---

 I'm looking for a way to get the `s` type symbol name (size_t)
 not whatever the alias is pointing to (ulong in this case).

 Is there a way to obtain the alias symbol name?
__traits(identifier, sym);
Him, that will print the symbol name, in my case `s`. To cut to chase - I'm looking something that will print `size_t` for the symbol `s`.
I'm pretty sure that that's impossible. As I understand it, the compiler basically just replaces aliases with what they refer to and doesn't care what the original type was. And they _definitely_ don't affect mangling. If you're looking to treat an alias as anything different from what it refers to, you're going to be disappointed. - Jonathan M Davis
Jun 26 2018
parent reply Radu <void null.pt> writes:
On Tuesday, 26 June 2018 at 10:19:44 UTC, Jonathan M Davis wrote:
 On Tuesday, June 26, 2018 09:47:44 Radu via Digitalmars-d-learn 
 wrote:
 On Tuesday, 26 June 2018 at 09:24:15 UTC, Stefan Koch wrote:
 On Tuesday, 26 June 2018 at 09:14:11 UTC, Radu wrote:
 Consider this https://run.dlang.io/is/HyY2qG

 ---
 void main()
 {

     import std.traits;
     size_t s;

     pragma(msg, typeof(s).stringof);
     pragma(msg, mangledName!(typeof(s)));
     pragma(msg, mangledName!s);

 }
 ---

 It outputs:
 ---
 ulong
 m
 _D9onlineapp4mainFZ1sm
 ---

 I'm looking for a way to get the `s` type symbol name 
 (size_t)
 not whatever the alias is pointing to (ulong in this case).

 Is there a way to obtain the alias symbol name?
__traits(identifier, sym);
Him, that will print the symbol name, in my case `s`. To cut to chase - I'm looking something that will print `size_t` for the symbol `s`.
I'm pretty sure that that's impossible. As I understand it, the compiler basically just replaces aliases with what they refer to and doesn't care what the original type was. And they _definitely_ don't affect mangling. If you're looking to treat an alias as anything different from what it refers to, you're going to be disappointed. - Jonathan M Davis
Ha! :) yeah I was pretty sure this will not work. I'm looking to generate some custom wrappers and knowing when something is really `size_t` is important, I have a backup plan, but having a compiler trait to get an alias symbol name would be great. Maybe this is worthy an enhancement request?
Jun 26 2018
parent reply Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
On Tuesday, June 26, 2018 11:28:11 Radu via Digitalmars-d-learn wrote:
 I'm pretty sure that that's impossible. As I understand it, the
 compiler basically just replaces aliases with what they refer
 to and doesn't care what the original type was. And they
 _definitely_ don't affect mangling. If you're looking to treat
 an alias as anything different from what it refers to, you're
 going to be disappointed.

 - Jonathan M Davis
Ha! :) yeah I was pretty sure this will not work. I'm looking to generate some custom wrappers and knowing when something is really `size_t` is important, I have a backup plan, but having a compiler trait to get an alias symbol name would be great. Maybe this is worthy an enhancement request?
Feel free. I have no idea how likely it is to ever be implemented. However, if your custom wrappers are generated at compilation time rather than generated as files to be compiled later, then it's unnecessary to know whether an alias was used, since then you'd just use the exact type being used for that particular compilation. - Jonathan M Davis
Jun 26 2018
parent Radu <void null.pt> writes:
On Tuesday, 26 June 2018 at 12:19:16 UTC, Jonathan M Davis wrote:
 On Tuesday, June 26, 2018 11:28:11 Radu via Digitalmars-d-learn 
 wrote:
 [...]
Ha! :) yeah I was pretty sure this will not work. I'm looking to generate some custom wrappers and knowing when something is really `size_t` is important, I have a backup plan, but having a compiler trait to get an alias symbol name would be great. Maybe this is worthy an enhancement request?
Feel free. I have no idea how likely it is to ever be implemented. However, if your custom wrappers are generated at compilation time rather than generated as files to be compiled later, then it's unnecessary to know whether an alias was used, since then you'd just use the exact type being used for that particular compilation. - Jonathan M Davis
Code generation is at compile time and the target is C code, so it is important to keep the type `size_t` rather than `uint` or `ulong` for obvious reasons. I will submit and issue for a new trait.
Jun 26 2018