File: prefer_constexpr_for_const_literals.sh

package info (click to toggle)
insighttoolkit5 5.4.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 704,404 kB
  • sloc: cpp: 783,697; ansic: 628,724; xml: 44,704; fortran: 34,250; python: 22,874; sh: 4,078; pascal: 2,636; lisp: 2,158; makefile: 461; yacc: 328; asm: 205; perl: 203; lex: 146; tcl: 132; javascript: 98; csh: 81
file content (29 lines) | stat: -rwxr-xr-x 1,718 bytes parent folder | download | duplicates (3)
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
#!/bin/bash


for ff in $( git grep -l "\(\s*\)const  *\([^=]*\)= *\([0-9\.][0-9\.]*\) *;" |fgrep -v ThirdParty ); do
  cat $ff | \
  sed -e  's/^\( *\)const  *size_t  *\([^ ]*\) *= *\([0-9\.][0-9\.]*\) *;/\1constexpr size_t \2 = \3;/g' | \
  sed -e  's/^\( *\)const  *unsigned  *int  *\([^ ]*\) *= *\([0-9\.][0-9\.]*\) *;/\1constexpr unsigned int \2 = \3;/g' | \
  sed -e  's/^\( *\)const  *unsigned  *short  *\([^ ]*\) *= *\([0-9\.][0-9\.]*\) *;/\1constexpr unsigned short \2 = \3;/g' | \
  sed -e  's/^\( *\)const  *unsigned  *char  *\([^ ]*\) *= *\([0-9\.][0-9\.]*\) *;/\1constexpr unsigned char \2 = \3;/g' | \
  sed -e  's/^\( *\)const  *int  *\([^ ]*\) *= *\([0-9\.][0-9\.]*\) *;/\1constexpr int \2 = \3;/g' | \
  sed -e  's/^\( *\)const  *short  *\([^ ]*\) *= *\([0-9\.][0-9\.]*\) *;/\1constexpr short \2 = \3;/g' | \
  sed -e  's/^\( *\)const  *char  *\([^ ]*\) *= *\([0-9\.][0-9\.]*\) *;/\1constexpr char \2 = \3;/g' | \
  sed -e  's/^\( *\)const  *float  *\([^ ]*\) *= *\([0-9\.][0-9\.]*\) *;/\1constexpr float \2 = \3;/g' | \
  sed -e  's/^\( *\)const  *double  *\([^ ]*\) *= *\([0-9\.][0-9\.]*\) *;/\1constexpr double \2 = \3;/g' | \
  sed -e  's/^\( *\)const  *\([^=]*\)= *\([0-9\.][0-9\.]*\) *;/\1constexpr \2 = \3;/g' | \
  sed -e  's/constexpr *\([^)]*\)) *= *0 *;/const \1) = 0;/g' | \
  sed -e  's/constexpr *\([^)]*\)) *const *= *0 *;/const \1) const = 0;/g' | \
  sed -e  's/constexpr *\([^)]*\)) *const *override *= *0 *;/const \1) const override = 0;/g' | \
  sed -e  's/constexpr \(.*\)   *=/\1 =/g'  > /tmp/temp_file
  mv  /tmp/temp_file $ff
done

cat > /tmp/cmt_msg << EOF
STYLE: Prefer constexpr for const numeric literals

Use constexpr for constant numeric literals.
EOF

cat /tmp/cmt_msg