Hierarchical enumeration #8

Open
opened 2026-05-01 23:16:12 -04:00 by yukirij · 0 comments
Owner

Hierarchical enumerations produce level-matched bit fields that can be used to check ancestry using bitwise operations.

  • Each level within a subtree occupies a bit field sized based on the number of elements.
    • The bit offset is the maximum total width of the descendant subtrees.
  • Hierarchical enumerations may not be used in the same enum block as value specification.
enum {
    A.a.i   # 0000
    A.a.ii  # 0001
    A.b     # 0010
    B.a     # 0100
    B.b     # 0101
    B.c     # 0110
    C.a     # 1000
}

# A   = 0000
# A.a = 0000
# A.b = 0010
# B   = 0100
# C   = 1000

assert!(B.c & B == B)
Hierarchical enumerations produce level-matched bit fields that can be used to check ancestry using bitwise operations. - Each level within a subtree occupies a bit field sized based on the number of elements. - The bit offset is the maximum total width of the descendant subtrees. - Hierarchical enumerations may not be used in the same enum block as value specification. ``` enum { A.a.i # 0000 A.a.ii # 0001 A.b # 0010 B.a # 0100 B.b # 0101 B.c # 0110 C.a # 1000 } # A = 0000 # A.a = 0000 # A.b = 0010 # B = 0100 # C = 1000 assert!(B.c & B == B) ```
yukirij added this to the Compiler project 2026-05-01 23:16:12 -04:00
Sign in to join this conversation.
No description provided.