Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add diagnostics for bit field ranges (#140)
Validates the bit ranges passed to bit field macros do not overlap nor do they extend past the register bounds. In either case, diagnostics are emitted indicating the offending attribute and offending range[s]. Given the example bit field: ```swift @bitfield(bits: 0..<24, 8..<32, 16..<48, 36..<44) var field: Field ``` The ranges visually look like: ``` 0 8 16 24 32 36 44 48 ╎ ╎ ╎ ╎ ╎ ╎ ╎ ╎ •───────────────────────◦ ╎ ╎ ╎ ╎ ╎ •───────────────────────◦ ╎ ╎ ╎ ╎ ╎ •───────────────────────────────◦ ╎ ╎ ╎ ╎ ╎ •───────◦ ╎ ╎ ╎ ╎ ╎ ╎ ╎ ╎ ╎ 0 8 16 24 32 36 44 48 ``` The following diagnostics will be emitted: ``` <location> error: overlapping bit ranges in '@bitfield(bits: 0..<24, 8..<40, 16..<48, 36..<44)' @bitfield(bits: 0..<24, 8..<40, 16..<48, 36..<44) ^~~~~~~~ <location> note: bit range '0..<24' overlaps bit ranges '8..<32' and '16..<48' over subrange '8..<24' @bitfield(bits: 0..<24, 8..<40, 16..<48, 36..<44) ^~~~~~ <location> note: bit range '8..<32' overlaps bit ranges '0..<24' and '16..<48' @bitfield(bits: 0..<24, 8..<32, 16..<48, 36..<44) ^~~~~~ <location> note: bit range '16..<48' overlaps bit ranges '0..<24', '8..<32', and '36..<44' over anges '16..<32' and '36..<44' @bitfield(bits: 0..<24, 8..<40, 16..<48, 36..<44) ^~~~~~~ <location> note: bit range '36..<44' overlaps bit range '16..<48' @bitfield(bits: 0..<24, 8..<40, 16..<48, 36..<44) ^~~~~~~ ```
- Loading branch information