Skip to content

Commit e122353

Browse files
authored
Merge pull request #3921 from WalterBright/getBitfieldInfo
add __traits getBitfieldOffset and getBitfieldWidth
2 parents a5089fe + 6574a07 commit e122353

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

spec/traits.dd

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ $(GNAME TraitsKeyword):
5656
$(RELATIVE_LINK2 fullyQualifiedName, $(D fullyQualifiedName))
5757
$(RELATIVE_LINK2 getAliasThis, $(D getAliasThis))
5858
$(RELATIVE_LINK2 getAttributes, $(D getAttributes))
59+
$(RELATIVE_LINK2 getBitfieldOffset, $(D getBitfieldOffset))
60+
$(RELATIVE_LINK2 getBitfieldWidth, $(D getBitfieldWidth))
5961
$(RELATIVE_LINK2 getFunctionAttributes, $(D getFunctionAttributes))
6062
$(RELATIVE_LINK2 getFunctionVariadicStyle, $(D getFunctionVariadicStyle))
6163
$(RELATIVE_LINK2 getLinkage, $(D getLinkage))
@@ -1351,6 +1353,55 @@ tuple((Foo))
13511353
)
13521354
)
13531355

1356+
$(SECTION3 $(GNAME getBitfieldOffset),
1357+
$(P Takes one argument, a qualified name that resolve to a field in a struct or class.
1358+
)
1359+
$(P If the field is a bitfield, it returns as a `uint` the bit number of the least significant
1360+
bit in the field. The rightmost bit is at offset 0, the leftmost bit is at offset 31 (for
1361+
32 bit int fields).
1362+
)
1363+
$(P If the field is a not bitfield, it returns as a `uint` the number 0.
1364+
)
1365+
1366+
$(SPEC_RUNNABLE_EXAMPLE_FAIL
1367+
---
1368+
// OK with -preview=bitfields
1369+
struct S
1370+
{
1371+
int a,b;
1372+
int :2, c:3;
1373+
}
1374+
1375+
static assert(__traits(getBitfieldOffset, S.b) == 0);
1376+
static assert(__traits(getBitfieldOffset, S.c) == 2);
1377+
---
1378+
)
1379+
1380+
)
1381+
1382+
$(SECTION3 $(GNAME getBitfieldWidth),
1383+
$(P Takes one argument, a qualified name that resolve to a field in a struct or class.
1384+
)
1385+
$(P If the field is a bitfield, it returns as a `uint` the width of the bit field as
1386+
a number of bits.
1387+
)
1388+
$(P If the field is a not bitfield, it returns the number of bits in the type.
1389+
)
1390+
$(SPEC_RUNNABLE_EXAMPLE_FAIL
1391+
---
1392+
// OK with -preview=bitfields
1393+
struct S
1394+
{
1395+
int a,b;
1396+
int :2, c:3;
1397+
}
1398+
1399+
static assert(__traits(getBitfieldWidth, S.b) == 32);
1400+
static assert(__traits(getBitfieldWidth, S.c) == 3);
1401+
---
1402+
)
1403+
)
1404+
13541405
$(H3 $(GNAME getLinkage))
13551406

13561407
$(P Takes one argument, which is a declaration symbol, or the type of a function, delegate,

0 commit comments

Comments
 (0)