Wiki

Ticket #269 (new enhancement)

Opened 7 years ago

Add Enum handling features

Reported by: hopscc Owned by:
Priority: minor Milestone:
Component: Cobra Compiler Version: 0.8.0
Keywords: Cc:

Description

1) Add a capability to the declaration of a cobra enum to specify that they have the 'Flag' attribute and their members are automatically initialised to bitset values
Suggestion was an attribute 'BitSetFlag' or 'AutoBitSetFlag'

enum  Colors 
    has AutoBitSetFlag
    None, Red, Green, Blue, Yellow
# which would generate code equivalent to the explicitly detailed
enum Colors
    has Flag
    None = 0,
    Red = 1,
    Green = 2, 
    Blue = 4, 
    Yellow = 8 

( member values start from 0 and double (per a bitset setting) for each successive value)

2) Overload the processing for an 'in' expression so that 'in' on
an enum value and combined bitset gets converted to a valid set inclusion test optimised for whether the enum is a bitset or not
e.g.

primaries = Colors(Red,Green, Blue)
c = .getColor
if c in primaries

gets converted to the equivalent of

if primaries.hasFlags(c) # c & primaries == c

if Colors is declared as a bitset with Flags (either explicitly or as above)
and

if c in Set<of Colors>([Colors.Red, Colors.Green, Colors.Blue])

if not

See ticket:265

Note: See TracTickets for help on using tickets.