[Issue 6946] Compile-time flags generator

2022-12-17 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=6946

Iain Buclaw  changed:

   What|Removed |Added

   Priority|P2  |P4

--


[Issue 6946] Compile-time flags generator

2016-10-15 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=6946

Andrei Alexandrescu  changed:

   What|Removed |Added

   Keywords||bootcamp
 CC||and...@erdani.com

--


[Issue 6946] Compile-time flags generator

2014-04-11 Thread d-bugmail
https://issues.dlang.org/show_bug.cgi?id=6946

--- Comment #12 from Nick Treleaven ntrel-pub...@yahoo.co.uk ---
(In reply to bearophile_hugs from comment #11)
 (In reply to comment #10)
  mixin BitFlags!q{A, B, C, D} MyFlags;

A better reason for this syntax is that is gives a name for ddoc to use for
documentation. Unfortunately the members can't be documented though.

 Is your version using a function like isReservedWord() I have shown in the
 first posts here?

I haven't actually implemented it, it could do.

--


Re: [Issue 6946] Compile-time flags generator

2014-04-11 Thread Orvid King
Actually, if we would already be doing partial tokenization, then I
would suspect it wouldn't be that hard to add support for extracting
documentation and putting them in the generated code for the mixin.
Also, to keep with standard D style, where the name of the type comes
before it's definition, perhaps the recommended syntax for the mixin
would be (provided it's currently possible):
mixin MyFlags = BitFlags!q{ A, B, C, D };

On 4/11/14, d-bugm...@puremagic.com d-bugm...@puremagic.com wrote:
 https://issues.dlang.org/show_bug.cgi?id=6946

 --- Comment #12 from Nick Treleaven ntrel-pub...@yahoo.co.uk ---
 (In reply to bearophile_hugs from comment #11)
 (In reply to comment #10)
  mixin BitFlags!q{A, B, C, D} MyFlags;

 A better reason for this syntax is that is gives a name for ddoc to use for
 documentation. Unfortunately the members can't be documented though.

 Is your version using a function like isReservedWord() I have shown in
 the
 first posts here?

 I haven't actually implemented it, it could do.

 --



[Issue 6946] Compile-time flags generator

2014-04-03 Thread d-bugmail
https://d.puremagic.com/issues/show_bug.cgi?id=6946



--- Comment #9 from Nick Treleaven ntrel-pub...@yahoo.co.uk 2014-04-03 
07:43:21 PDT ---
(In reply to comment #8)
 Is the name MyFlags not useful (as shown in the syntax you quote)?

It's fine, I just thought it might be good to take advantage of a mixin
identifier (I often forget about that feature). It seems a bit cleaner to me
than a string argument, although having mixin assignment syntax would make this
clearer. Nice idea BTW.

The cleanness is because I like to have identifiers highlighted in the same way
rather than have some as strings, so I would prefer to read something like:

mixin BitFlags!q{A, B, C, D} MyFlags;

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 6946] Compile-time flags generator

2014-04-03 Thread d-bugmail
https://d.puremagic.com/issues/show_bug.cgi?id=6946



--- Comment #10 from bearophile_h...@eml.cc 2014-04-03 09:07:50 PDT ---
(In reply to comment #9)

 although having mixin assignment syntax would make this
 clearer. Nice idea BTW.

The point of giving it a name in some way (with a string) is because later you
can use some trait to ask for its name. I am not suer how important this is.

The idea comes from Python namedtuples:

 from collections import namedtuple
 Three = namedtuple(Two, a b)
 Three(1, 2)
Two(a=1, b=2)

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 6946] Compile-time flags generator

2014-04-03 Thread d-bugmail
https://d.puremagic.com/issues/show_bug.cgi?id=6946



--- Comment #11 from bearophile_h...@eml.cc 2014-04-03 09:49:38 PDT ---
(In reply to comment #10)

 The cleanness is because I like to have identifiers highlighted in the same 
 way
 rather than have some as strings, so I would prefer to read something like:
 
 mixin BitFlags!q{A, B, C, D} MyFlags;

Is your version using a function like isReservedWord() I have shown in the
first posts here?

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 6946] Compile-time flags generator

2014-04-02 Thread d-bugmail
https://d.puremagic.com/issues/show_bug.cgi?id=6946


Nick Treleaven ntrel-pub...@yahoo.co.uk changed:

   What|Removed |Added

 CC||ntrel-pub...@yahoo.co.uk


--- Comment #7 from Nick Treleaven ntrel-pub...@yahoo.co.uk 2014-04-02 
09:14:47 PDT ---
A note about syntax:

 mixin(bitFlags!size_t(MyFlags, A B C D))

Wrapping enum code in a mixin template could allow:

mixin BitFlags!size_t(A B C D)) MyFlags;

Or if D mixin syntax was changed similar to alias assignment syntax:

mixin MyFlags = BitFlags!size_t(A B C D));

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 6946] Compile-time flags generator

2014-04-02 Thread d-bugmail
https://d.puremagic.com/issues/show_bug.cgi?id=6946



--- Comment #8 from bearophile_h...@eml.cc 2014-04-02 10:19:23 PDT ---
(In reply to comment #7)
 A note about syntax:
 
  mixin(bitFlags!size_t(MyFlags, A B C D))
 
 Wrapping enum code in a mixin template could allow:
 
 mixin BitFlags!size_t(A B C D)) MyFlags;
 
 Or if D mixin syntax was changed similar to alias assignment syntax:
 
 mixin MyFlags = BitFlags!size_t(A B C D));

Is the name MyFlags not useful (as shown in the syntax you quote)?

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 6946] Compile-time flags generator

2012-09-26 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=6946



--- Comment #6 from bearophile_h...@eml.cc 2012-09-26 07:28:19 PDT ---
See also Issue 8727

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 6946] Compile-time flags generator

2012-09-25 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=6946


Denis Shelomovskij verylonglogin@gmail.com changed:

   What|Removed |Added

 CC||verylonglogin@gmail.com


--- Comment #5 from Denis Shelomovskij verylonglogin@gmail.com 2012-09-25 
23:47:56 MSD ---
Related NG thread:
http://forum.dlang.org/thread/k3soo8$2ast$1...@digitalmars.com

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 6946] Compile-time flags generator

2012-08-15 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=6946


Marco Leise marco.le...@gmx.de changed:

   What|Removed |Added

 CC||marco.le...@gmx.de


--- Comment #4 from Marco Leise marco.le...@gmx.de 2012-08-15 06:22:24 PDT ---
I think Delphi has the most convenient implementation of sets.

  type
 TWorkDay = (Monday, Tuesday, Wednesday, Thursday, Friday) ;
 TDaySet = set of TWorkDay;
  var
 days : TDaySet;
  begin
 days := [Monday, Friday];

 days := days + [Tuesday, Thursday] - [Friday];

 if Wednesday IN days then ShowMessage('I love Wednesday!') ;

It also uses the 2^n binary notation internally. Any proposed solution should
add safety as well as the basic set operators. As long as it is still easier to
write set = ~flag to remove a flag from a set, it failed its mission.
It would be even better if a set type would be allowed in bindings to C code or
painlessly converted to it's integer representation with set.val or similar.
:)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 6946] Compile-time flags generator

2011-12-12 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=6946


yebblies yebbl...@gmail.com changed:

   What|Removed |Added

 CC||yebbl...@gmail.com


--- Comment #3 from yebblies yebbl...@gmail.com 2011-12-13 17:49:43 EST ---
You probably need to turn this into a pull request if you want it reviewed for
inclusion in phobos.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 6946] Compile-time flags generator

2011-11-14 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=6946



--- Comment #1 from bearophile_h...@eml.cc 2011-11-14 15:21:15 PST ---
For the C# [Flags] attribute see:
http://msdn.microsoft.com/en-us/library/cc138362.aspx
http://msdn.microsoft.com/en-us/library/system.flagsattribute.aspx


In D enums EnumBaseType defaults to int:
http://www.d-programming-language.org/enum.html
but for powers of two bit flags I think using an unsigned type is saner, so for
bitFlags I have used uint as default type.

Follows a bit improved version, it always contains a None member too,
represented with 0:


import std.traits: isUnsigned;
import std.string: split;
import std.conv: text;
import std.algorithm: canFind;

bool isReservedWord(in string w) {
string[] reservedWords = abstract alias align asm
assert auto body bool break byte case cast catch cdouble cent cfloat
char class const continue creal dchar debug default delegate delete
deprecated do double else enum export extern false final finally
float for foreach foreach_reverse function goto idouble if ifloat
immutable import in inout int interface invariant ireal is lazy long
macro mixin module new nothrow null out override package pragma
private protected public pure real ref return scope shared short
static struct super switch synchronized template this throw true try
typedef typeid typeof ubyte ucent uint ulong union unittest ushort
version void volatile wchar while with __FILE__ __LINE__ __gshared
__thread __traits.split();
return canFind(reservedWords, w);
}

string bitFlags(BaseType=uint)(string enumName, string enumItems)
if (isUnsigned!BaseType) {
assert ((enumItems.split().length + 1)  (BaseType.sizeof * 8),
text(BaseType (, BaseType.stringof,
 ) doesn't have enough bits to represent all the enumItems
plus None.));
string result = text(enum , enumName,  : , BaseType.stringof,  {\n);
result ~= text(None = 0,\n);
foreach (i, flag; enumItems.split()) {
assert(!isReservedWord(flag), text(bitFlags: enum member ', flag, '
is a D keyword.));
result ~= text(, flag,  = (1  , i, ),\n);
}
return result ~ };
}

// example usages 
mixin(bitFlags!size_t(MyFlags, A B C D));
//mixin(bitFlags!ulong(MyFlags, A B C D)); // writeln bug 6892

mixin(bitFlags(Days, Sunday Monday Tuesday Wednesday Thursday Friday
Saturday));

void main() {
import std.stdio;
writeln(MyFlags.C);
import std.traits, std.algorithm;
assert(equal(map!text([EnumMembers!MyFlags]),
 [None, A, B, C, D]));
Days meetingDays = Days.Tuesday | Days.Thursday;
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 6946] Compile-time flags generator

2011-11-14 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=6946


Alex R�nne Petersen xtzgzo...@gmail.com changed:

   What|Removed |Added

 CC||xtzgzo...@gmail.com


--- Comment #2 from Alex R�nne Petersen xtzgzo...@gmail.com 2011-11-14 
15:42:16 PST ---
Please use 'none' instead of 'None' (and so on) to follow Phobos naming
conventions.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---