gnu/gcc/5dc2754c0945d076a7482d6468d3de4ba550fd89
analyzer: add unit-safe integer classes
This patch introduces a template class ana::integer_with_unit<Unit>
wrapping the arbitrary-precision ana::integer introduced in the previous
patch, capturing the units of the integer in the type system: bits vs
bytes vs unitless. The idea is that if we mess up bits vs bytes in the
analyzer implementation, we get a compile-time type error. The class
also supports user-defined literals, so we can write e.g.
8_bits
in the code, rather than
integer_with_unit<units::bit> (8)
As in the previous patch, nothing uses this yet, but it is fundamental
to my upcoming rewrite of the analyzer's state-tracking.
gcc/ChangeLog:
* Makefile.in (ANALYZER_OBJS): Add analyzer/integer-with-unit.o.
gcc/analyzer/ChangeLog:
* analyzer-selftests.cc (run_analyzer_selftests): Call
analyzer_integer_with_unit_cc_tests.
* analyzer-selftests.h (analyzer_integer_with_unit_cc_tests): New
decl.
* integer-with-unit.cc: New file.
* integer-with-unit.h: New file.
* units.h: New file.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
6 files changed