hppa: xfail scan-assembler-not check in g++.dg/cpp0x/initlist-const1.C
[official-gcc.git] / contrib / unicode / gen-combining-chars.py
blobfb5ef50ba4cad5ef46d101d08d7a6daa5736d5d9
1 #!/usr/bin/env python3
3 # Script to generate libcpp/combining-chars.inc
5 # This file is part of GCC.
7 # GCC is free software; you can redistribute it and/or modify it under
8 # the terms of the GNU General Public License as published by the Free
9 # Software Foundation; either version 3, or (at your option) any later
10 # version.
12 # GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 # for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with GCC; see the file COPYING3. If not see
19 # <http://www.gnu.org/licenses/>. */
21 from pprint import pprint
22 import unicodedata
24 def is_combining_char(code_point) -> bool:
25 return unicodedata.combining(chr(code_point)) != 0
27 class Range:
28 def __init__(self, start, end, value):
29 self.start = start
30 self.end = end
31 self.value = value
33 def __repr__(self):
34 return f'Range({self.start:x}, {self.end:x}, {self.value})'
36 def make_ranges(value_callback):
37 ranges = []
38 for code_point in range(0x10FFFF):
39 value = is_combining_char(code_point)
40 if 0:
41 print(f'{code_point=:x} {value=}')
42 if ranges and ranges[-1].value == value:
43 # Extend current range
44 ranges[-1].end = code_point
45 else:
46 # Start a new range
47 ranges.append(Range(code_point, code_point, value))
48 return ranges
50 ranges = make_ranges(is_combining_char)
51 if 0:
52 pprint(ranges)
54 print(f"/* Generated by contrib/unicode/gen-combining-chars.py")
55 print(f" using version {unicodedata.unidata_version}"
56 " of the Unicode standard. */")
57 print("\nstatic const cppchar_t combining_range_ends[] = {", end="")
58 for i, r in enumerate(ranges):
59 if i % 8:
60 print(" ", end="")
61 else:
62 print("\n ", end="")
63 print("0x%x," % r.end, end="")
64 print("\n};\n")
65 print("static const bool is_combining[] = {", end="")
66 for i, r in enumerate(ranges):
67 if i % 24:
68 print(" ", end="")
69 else:
70 print("\n ", end="")
71 if r.value:
72 print("1,", end="")
73 else:
74 print("0,", end="")
75 print("\n};")