digitalmars.D.learn - How can I express the type of a function in D?
- Sobaya (13/13) Jan 29 2019 I want to get a mangled name of a D function by
- FrankLike (16/29) Jan 29 2019 import std.stdio;
- FrankLike (9/29) Jan 29 2019 import std.stdio;
- Sobaya (2/15) Jan 29 2019 I want a mangled function name without "P", not one with "P".
- =?UTF-8?Q?Ali_=c3=87ehreli?= (9/25) Jan 30 2019 typeof works:
- Steven Schveighoffer (3/16) Jan 30 2019 Why not use add.mangleof?
- =?UTF-8?Q?Ali_=c3=87ehreli?= (17/34) Jan 30 2019 add.mangleof includes the module name as well (_D6deneme3addFiiZi) but
- H. S. Teoh (8/10) Jan 30 2019 [...]
- =?UTF-8?Q?Ali_=c3=87ehreli?= (3/15) Jan 30 2019 I remember names like _add. Is that a Windows thing?
- Neia Neutuladh (3/4) Jan 30 2019 A number of functions are implemented as manually-mangled names with
- Neia Neutuladh (5/19) Jan 30 2019 `add.mangleof` is correct. In fact, it's definitively correct.
- H. S. Teoh (5/26) Jan 30 2019 That would be a bug in core.demangle.
- Steven Schveighoffer (6/29) Jan 30 2019 But he says `The fuction name in a binary compiled this function is
- Atila Neves (11/15) Feb 01 2019 There's a way:
- dnsmt (2/6) Feb 04 2019 Did you consider `core.demangle.mangleFunc` instead?
I want to get a mangled name of a D function by `core.demangle.mangle`, but I'm in trouble because there are no ways to express a type of a function, which is used for a template argument of `mangle`. For example, it is wrong to use the type `int function(int,int)` to express the type of `int add(int,int)`. Because it expresses the type of a function POINTER, not just a function. The fuction name in a binary compiled this function is "_D3addFiiZi", but `mangle!(int function(int,int))("add")` returns "_D3addPFiiZi", which includes "P" meaning POINTER. How can I get the former one? Thanks.
Jan 29 2019
On Wednesday, 30 January 2019 at 05:14:20 UTC, Sobaya wrote:I want to get a mangled name of a D function by `core.demangle.mangle`, but I'm in trouble because there are no ways to express a type of a function, which is used for a template argument of `mangle`. For example, it is wrong to use the type `int function(int,int)` to express the type of `int add(int,int)`. Because it expresses the type of a function POINTER, not just a function. The fuction name in a binary compiled this function is "_D3addFiiZi", but `mangle!(int function(int,int))("add")` returns "_D3addPFiiZi", which includes "P" meaning POINTER. How can I get the former one? Thanks.import std.stdio; alias int* PINT; void main() { auto x= Add(1,2); writeln(x); writeln(&x); executeShell("pause"); } private PINT Add(int a,int b) { return cast(PINT)(a+b); } ////////////////CODE END////////// It works ok.
Jan 29 2019
On Wednesday, 30 January 2019 at 05:40:50 UTC, FrankLike wrote:On Wednesday, 30 January 2019 at 05:14:20 UTC, Sobaya wrote:import std.stdio; import std.process:executeShell; import core.demangle; void main() { assert(mangle!(int function(int))("a.b") == "_D1a1bPFiZi"); executeShell("pause"); }I want to get a mangled name of a D function by `core.demangle.mangle`, but I'm in trouble because there are no ways to express a type of a function, which is used for a template argument of `mangle`. For example, it is wrong to use the type `int function(int,int)` to express the type of `int add(int,int)`. Because it expresses the type of a function POINTER, not just a function. The fuction name in a binary compiled this function is "_D3addFiiZi", but `mangle!(int function(int,int))("add")` returns "_D3addPFiiZi", which includes "P" meaning POINTER. How can I get the former one? Thanks.////////////////CODE END////////// Yes,"_D1a1bPFiZi",which includes "P".
Jan 29 2019
On Wednesday, 30 January 2019 at 06:02:02 UTC, FrankLike wrote:On Wednesday, 30 January 2019 at 05:40:50 UTC, FrankLike wrote:I want a mangled function name without "P", not one with "P".On Wednesday, 30 January 2019 at 05:14:20 UTC, Sobaya wrote:import std.stdio; import std.process:executeShell; import core.demangle; void main() { assert(mangle!(int function(int))("a.b") == "_D1a1bPFiZi"); executeShell("pause"); }[...]////////////////CODE END////////// Yes,"_D1a1bPFiZi",which includes "P".
Jan 29 2019
On 01/29/2019 09:14 PM, Sobaya wrote:I want to get a mangled name of a D function by `core.demangle.mangle`, but I'm in trouble because there are no ways to express a type of a function, which is used for a template argument of `mangle`. For example, it is wrong to use the type `int function(int,int)` to express the type of `int add(int,int)`. Because it expresses the type of a function POINTER, not just a function. The fuction name in a binary compiled this function is "_D3addFiiZi", but `mangle!(int function(int,int))("add")` returns "_D3addPFiiZi", which includes "P" meaning POINTER. How can I get the former one? Thanks.typeof works: import core.demangle; int add(int, int); void main() { alias F = typeof(add); pragma(msg, mangle!F("add")); } Ali
Jan 30 2019
On 1/30/19 12:14 AM, Sobaya wrote:I want to get a mangled name of a D function by `core.demangle.mangle`, but I'm in trouble because there are no ways to express a type of a function, which is used for a template argument of `mangle`. For example, it is wrong to use the type `int function(int,int)` to express the type of `int add(int,int)`. Because it expresses the type of a function POINTER, not just a function. The fuction name in a binary compiled this function is "_D3addFiiZi", but `mangle!(int function(int,int))("add")` returns "_D3addPFiiZi", which includes "P" meaning POINTER. How can I get the former one?Why not use add.mangleof? -Steve
Jan 30 2019
On 01/30/2019 07:47 AM, Steven Schveighoffer wrote:On 1/30/19 12:14 AM, Sobaya wrote:function.I want to get a mangled name of a D function by `core.demangle.mangle`, but I'm in trouble because there are no ways to express a type of a function, which is used for a template argument of `mangle`. For example, it is wrong to use the type `int function(int,int)` to express the type of `int add(int,int)`. Because it expresses the type of a function POINTER, not just aadd.mangleof includes the module name as well (_D6deneme3addFiiZi) but the OP wanted without (_D3addFiiZi). I wonder why the inconsistency. On the other hand, .mangleof produces just "add" when the function is extern(C). (?) import core.demangle; extern(C) int add(int, int); void main() { alias F = typeof(add); pragma(msg, mangle!F("add")); pragma(msg, add.mangleof); } Output: _D3addUiiZi add <-- Is that correct? AliThe fuction name in a binary compiled this function is "_D3addFiiZi", but `mangle!(int function(int,int))("add")` returns "_D3addPFiiZi", which includes "P" meaning POINTER. How can I get the former one?Why not use add.mangleof? -Steve
Jan 30 2019
On Wed, Jan 30, 2019 at 10:39:21AM -0800, Ali Çehreli via Digitalmars-d-learn wrote: [...]I wonder why the inconsistency. On the other hand, .mangleof produces just "add" when the function is extern(C). (?)[...] For extern(C), this is correct behaviour, because that's how a C function would be mangled (i.e., not mangled at all). T -- In a world without fences, who needs Windows and Gates? -- Christian Surchi
Jan 30 2019
On 01/30/2019 11:42 AM, H. S. Teoh wrote:On Wed, Jan 30, 2019 at 10:39:21AM -0800, Ali Çehreli via Digitalmars-d-learn wrote: [...]I remember names like _add. Is that a Windows thing? AliI wonder why the inconsistency. On the other hand, .mangleof produces just "add" when the function is extern(C). (?)[...] For extern(C), this is correct behaviour, because that's how a C function would be mangled (i.e., not mangled at all). T
Jan 30 2019
On Wed, 30 Jan 2019 12:56:06 -0800, Ali Çehreli wrote:I remember names like _add. Is that a Windows thing?A number of functions are implemented as manually-mangled names with preprocessor macros that forward to them. It's weird, but it happens.
Jan 30 2019
On Wed, 30 Jan 2019 10:39:21 -0800, Ali Çehreli wrote:import core.demangle; extern(C) int add(int, int); void main() { alias F = typeof(add); pragma(msg, mangle!F("add")); pragma(msg, add.mangleof); } Output: _D3addUiiZi add <-- Is that correct?`add.mangleof` is correct. In fact, it's definitively correct. typeof(add) is extern(C) int function(int, int). Based on this output, core.demangle seems like it's not taking the extern(C) portion into account.
Jan 30 2019
On Wed, Jan 30, 2019 at 07:51:17PM +0000, Neia Neutuladh via Digitalmars-d-learn wrote:On Wed, 30 Jan 2019 10:39:21 -0800, Ali Çehreli wrote:That would be a bug in core.demangle. T -- "I suspect the best way to deal with procrastination is to put off the procrastination itself until later. I've been meaning to try this, but haven't gotten around to it yet. " -- swrimport core.demangle; extern(C) int add(int, int); void main() { alias F = typeof(add); pragma(msg, mangle!F("add")); pragma(msg, add.mangleof); } Output: _D3addUiiZi add <-- Is that correct?`add.mangleof` is correct. In fact, it's definitively correct. typeof(add) is extern(C) int function(int, int). Based on this output, core.demangle seems like it's not taking the extern(C) portion into account.
Jan 30 2019
On 1/30/19 1:39 PM, Ali Çehreli wrote:On 01/30/2019 07:47 AM, Steven Schveighoffer wrote: > On 1/30/19 12:14 AM, Sobaya wrote: >> I want to get a mangled name of a D function by >> `core.demangle.mangle`, but I'm in trouble because there are no ways >> to express a type of a function, which is used for a template argument >> of `mangle`. >> >> For example, it is wrong to use the type `int function(int,int)` to >> express the type of `int add(int,int)`. >> Because it expresses the type of a function POINTER, not just a function. >> >> The fuction name in a binary compiled this function is "_D3addFiiZi", >> but `mangle!(int function(int,int))("add")` returns "_D3addPFiiZi", >> which includes "P" meaning POINTER. >> >> How can I get the former one? > > Why not use add.mangleof? > add.mangleof includes the module name as well (_D6deneme3addFiiZi) but the OP wanted without (_D3addFiiZi).But he says `The fuction name in a binary compiled this function is "_D3addFiiZi"`. So whatever he compiles as must be what mangleof reports, as it's the same entity generating the mangle. I don't know what his source code is. -Steve
Jan 30 2019
On Wednesday, 30 January 2019 at 05:14:20 UTC, Sobaya wrote:I want to get a mangled name of a D function by `core.demangle.mangle`, but I'm in trouble because there are no ways to express a type of a function, which is used for a template argument of `mangle`.There's a way: int add(int i, int j); static assert(is(typeof(add) == typeof(*(int function(int, int)).init))); Unfortunately there's no dedicated syntax for it, unlike C++. Weirdly enough, if you pragma(msg) a function type it prints it out in C++ syntax (e.g. `int(int, int)`), but if you type it yourself it won't compile. Then there's this oddity: https://issues.dlang.org/show_bug.cgi?id=19270
Feb 01 2019
On Wednesday, 30 January 2019 at 05:14:20 UTC, Sobaya wrote:I want to get a mangled name of a D function by `core.demangle.mangle`, but I'm in trouble because there are no ways to express a type of a function, which is used for a template argument of `mangle`.Did you consider `core.demangle.mangleFunc` instead?
Feb 04 2019