aboutsummaryrefslogtreecommitdiff
path: root/gen/prop/bool-props.awk
blob: d9c6299ce9539d2b5a7f58aeaf11f468f7808774 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
BEGIN {
	FS = "( *#.*| +; +)"

	print "/* This file is autogenerated by gen/prop/bool-props; DO NOT EDIT. */"
	print ""
	print "#include \"__bsearch.h\""
	print "#include \"bitset.h\""
	print "#include \"rune.h\""
	print "#include \"unicode/prop.h\""
	print ""
	print "/* clang-format off */"
	print ""
}

$2 == prop || (prop == "Indic_Conjunct_Break" && $2 ~ /InCB;/) {
	n = split($1, a, /\.\./)
	lo = strtonum("0x" a[1])
	hi = strtonum("0x" a[n])

	for (i = lo; i <= hi; i++)
		xs[i] = 1
}

END {
	for (i = 0; i <= 0xFF; i++) {
		if (xs[i])
			mask = or(mask, lshift(1, i))
	}

	if (mask > 0) {
		print "static constexpr bitset(bs, LATIN1_MAX) = {"
		for (i = 0; i < 32; i++) {
			if (i % 8 == 0)
				printf "\t"
			printf "0x%02X,", and(rshift(mask, 8 * i), 0xFF)
			printf((i % 8 == 7) ? "\n" : " ")
		}
		print "};"
		print  ""
	}

	for (i = 0x100; i <= 0x10FFFF; i++) {
		if (xs[i]) {
			need_big_lookup = 1
			break
		}
	}

	if (need_big_lookup) {
		print "static const struct {"
		print "\trune lo, hi;"
		print "} lookup[] = {"

		for (i = 0x100; i <= 0x10FFFF; i++) {
			if (!xs[i])
				continue
			lo = i
			while (xs[i + 1])
				i++
			printf "\t{RUNE_C(0x%06X), RUNE_C(0x%06X)},\n", lo, i
		}

		print  "};"
		print  ""
		print  "__MLIB_DEFINE_BSEARCH_CONTAINS(lookup)"
		print  ""
	}

	print  "bool"
	printf "uprop_is_%s(rune ch)\n", short
	print  "{"
	if (mask > 0 && need_big_lookup)
		print "\treturn ch <= LATIN1_MAX ? TESTBIT(bs, ch) : mlib_lookup_contains(ch);"
	else if (need_big_lookup)
		print "\treturn mlib_lookup_contains(ch);"
	else
		print "\treturn ch <= LATIN1_MAX && TESTBIT(bs, ch);"
	print  "}"
}