digitalmars.D.bugs - [Issue 2698] New: Parameterised identifier
- d-bugmail puremagic.com (50/50) Feb 28 2009 http://d.puremagic.com/issues/show_bug.cgi?id=2698
- d-bugmail puremagic.com (16/16) Mar 04 2009 http://d.puremagic.com/issues/show_bug.cgi?id=2698
- d-bugmail puremagic.com (14/14) May 12 2013 http://d.puremagic.com/issues/show_bug.cgi?id=2698
http://d.puremagic.com/issues/show_bug.cgi?id=2698 Summary: Parameterised identifier Product: D Version: 2.025 Platform: PC OS/Version: Windows Status: NEW Severity: enhancement Priority: P2 Component: DMD AssignedTo: bugzilla digitalmars.com ReportedBy: daniel.keep+d.puremagic.com gmail.com Proposal: add the following to the D grammar: Identifier: IdentiferStart IdentiferStart IdentifierChars ParameterisedIdentifier ParameterisedIdentifier: "__ident" "(" AssignExpression ")" This allows for two use-cases. Firstly, it allows the definition of symbols that do not have valid D identifiers. The pressing example from the efforts to port DMD to Mac OSX is the following [1]: _blah$UNIX2003 This is an issue with the pthread library in 10.5. D cannot link to these functions directly, and a C shim would have to be built. Instead, this proposal would allow for the following syntax: extern(C) void __ident("blah$UNIX2003")(int); thus removing the need for a shim. This need could also be filled by replacing "AssignExpression" with "StringLiteral", which I assume would be easier to implement. The second use-case is in compile-time generated code. An example might be generating a set of property accessors and storage, given a name and type. mixin Property!("foo", int); The problem here is that actually creating the functions and storage is fiddly. You have to do this within the template or CTFE: mixin(`int `~name~`() { return _`~name~`_storage; }`); Because of how mixin decls work, you have to quote out the entire function just to replace the identifiers. The proposal would allow for this: int __ident(name)() { return __ident("_"~name~"storage"); } Admittedly, this is actually longer than the above, but it has the distinct advantage of not requiring the programmer to stuff about with quoting and unquoting their code. In terms of mangling, I believe the symbol should be treated as not being mangled yet. If control over this is required (I can't imagine it being of use except in very extreme circumstances), another proposal could be made to extend the syntax to allow: __ident(name, cast(bool) should_name_be_mangled) [1] http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.announce&article_id=14958 --
Feb 28 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2698 You missed a third use-case: giving identifiers the names of keywords. This may be significant when interfacing with other languages. (Or even, earlier versions of D!). extern(C) { int __identifier("pure")(int); } __identifier is a keyword in MSVC for this reason. (BTW, if you _were_ going to support the name mangling case, a better syntax would probably be: __identifier("name", "mangle") One situation where this would be useful would be in direct linking to C++ compilers other than DMC/GCC. But I don't think that should be considered at all in this proposal). --
Mar 04 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2698 Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/5d2d09e6e4b7487ec5c7aea1349e1e2c09fe5bf8 Fix issue 2698 - Implement pragma(mangle, "...") allow all characters in mangle rename symbol_override to mangleOverride and remove ctype.h include Add eol at end of mangle.d https://github.com/D-Programming-Language/dmd/commit/656064c4651c87a41358b012ee6358c0c73d8d92 Fix issue 2698 - Implement pragma(mangle, "...") -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 12 2013