[Issue 20081] New: Add pragma(identifier, StringExp)

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jul 25 04:30:00 UTC 2019


          Issue ID: 20081
           Summary: Add pragma(identifier, StringExp)
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: turkeyman at gmail.com

It's extremely common in reflection based code to generate declarations using
mixin, and possibly in order of 80% of the time, those declarations have
generated names.

Since string mixin's must contain whole declarations, it's impossible to supply
a generated function name without writing the entire body of the declaration
inside of a string. This is really ugly and difficult to maintain.

Function bodies written in strings lose:
 Syntax highlighting
 Step debugging
 Hover tooltip inspection

Text mixins are really unenjoyable and I'm very tired of it, particularly when
I have huge declaration that are only text because of the name.

I suggest to add `pragma(identifier, StringExp)` which may appear anywhere that
an identifier may appear.

In my code, I expect this will reduce instances of string mixin by something
close to 90%, and that creates much more reasonable, readable, and maintainable
code, and the IDE can keep working like it's meant to.

For example:

string makeIdent(size_t n) { return "name" ~ n.to!string; }

template T(size_t N)
  void pragma(identifier, makeIdent(N))(Args...)(Args args)

Also useful in places where an entire expression would have had to be enclosed
in text, like:

int pragma(identifier, getName()) = expression + 1 * myThing.members[n].x;


More information about the Digitalmars-d-bugs mailing list