clean up remaining fixmes for fma
[ieee754fpu.git] / expand-simd-map-input.sh
1 #!/bin/bash
2 # SPDX-License-Identifier: LGPL-3-or-later
3 # See Notices.txt for copyright information
4
5 # utility script for expanding input type annotations for SimdMap methods.
6 # not actually needed anymore, but I thought I'd commit it in case anyone
7 # finds it useful.
8
9 mapfile lines < src/ieee754/part/util.pyi
10
11 defs=()
12 def=""
13 LOOKING_FOR_DEF=0
14 PARSING_BODY=1
15 ((state = LOOKING_FOR_DEF))
16
17 # split into list of python method definitions
18 for line in "${lines[@]}"; do
19 if ((state == LOOKING_FOR_DEF)); then
20 if [[ "$line" =~ ^' '*'def ' ]]; then
21 ((state = PARSING_BODY))
22 fi
23 def+="$line"
24 elif [[ "$line" =~ ^' '*'@' ]]; then
25 defs+=("$def")
26 def="$line"
27 ((state = LOOKING_FOR_DEF))
28 elif [[ "$line" =~ ^' '*'def ' ]]; then
29 defs+=("$def")
30 def="$line"
31 else
32 def+="$line"
33 fi
34 done
35 if [[ "$def" != "" ]]; then
36 defs+=("$def")
37 fi
38
39 # expand all occurrences of _SimdMapInput[_T...]
40 ((working = 1))
41 while ((working)); do
42 ((working = 0))
43 old_defs=("${defs[@]}")
44 defs=()
45 for def in "${old_defs[@]}"; do
46 if [[ "$def" =~ ^(.*)'Optional[_SimdMapInput['(_T[0-9]*)']]'(.*)$ ]] ||
47 [[ "$a" =~ ^(.*)'_SimdMapInput['(_T[0-9]*)']'(.*)$ ]]; then
48 ((working = 1))
49 defs+=("${BASH_REMATCH[1]}SimdMap[${BASH_REMATCH[2]}]${BASH_REMATCH[3]}")
50 defs+=("${BASH_REMATCH[1]}Mapping[_ElWid, Optional[${BASH_REMATCH[2]}]]${BASH_REMATCH[3]}")
51 defs+=("${BASH_REMATCH[1]}Optional[${BASH_REMATCH[2]}]${BASH_REMATCH[3]}")
52 else
53 defs+=("$def")
54 fi
55 done
56 done
57
58 printf "%s" "${defs[@]}" > out.txt