]> git.donarmstrong.com Git - lilypond.git/blob - scripts/auxiliar/smob-convert.sh
3915db009d7c72f2808077c7853075fc5ee64d76
[lilypond.git] / scripts / auxiliar / smob-convert.sh
1 #!/bin/sh
2 for i in $(git grep -l '^\s\+DECLARE_SIMPLE_SMOBS' lily)
3 do
4     sed -i -n '1h
5 1!H
6 ${g
7   s/^\(\(class\|struct\)\s\+\([A-Za-z_]\+\)\)\(\n\(.*\n\)\+\)\s*DECLARE_SIMPLE_SMOBS\s*(\3)\s*;\n/\1 : public Simple_smob<\3>\4/gm
8   s/^\(\(public:\|protected:\|private:\)\n\+\)\+\(public:\|protected:\|private:\|}\)/\3/gm
9   s/^\(\(public:\|protected:\|private:\)\n\(\([ \t].*\)\?\n\)\+\)\2\n/\1/gm
10   p
11   d}' "$i"
12 done
13
14 # Now the tough stuff: we need to add in-class declarations for the rest
15
16 add_public_def ()
17 {
18     # $1 is indented and line-delimited def, $2 is class, $3 is file
19     sed -i -n '1h
20 1!H
21 ${g
22   s/^\(class '$2'\b\([^{};]\|\n\)*{\n\)\n*public:\n/\1public:\n'"$1"'/gmp
23   t
24   s/^\(class '$2'\b\([^{};]\|\n\)*{\n\)\n*\(protected\|private\):\n/\1public:\n'"$1"'\3:\n/gmp
25   t
26   s/^\(class '$2'\b\([^{};]\|\n\)*{\n\)\n*/\1public:\n'"$1"'private:\n/gmp
27   t
28   s/^\(struct '$2'\b\([^{};]\|\n\)*{\n\)\n*\(public:\n\+\)\?/\1'"$1"'/gmp
29   t
30   s/^\(struct '$2'\b\([^{};]\|\n\)*{\n\)\n*\(protected\|private\):\n/\1public:\n'"$1"'\3:\n/gm
31   p
32   d}' "$3"
33 }
34
35 git grep '^\s\+DECLARE_SMOBS' lily|sed -n 's/^\([^:]\+\):\s*DECLARE_SMOBS\s*(\([^)]\+\));\?\s*$/\1 \2/p'|
36     while read file class
37     do
38         echo "Implement destructor for $class in $file" >&2
39         sed -i -n '1h
40 1!H
41 ${g
42   s/^\(\(class\|struct\)\s\+\([A-Za-z_]\+\)\)\(\n\(.*\n\)\+\)\s*DECLARE_SMOBS\s*(\3)\s*;\n/\1 : public Smob<\3>\4/gm
43   s/^\(\(class\|struct\)\s\+\([A-Za-z_]\+\)\s\+:\)\(.*\n\(.*\n\)\+\)\s*DECLARE_SMOBS\s*(\3)\s*;\n/\1 public Smob<\3>,\4/gm
44   s/^\(\(public:\|protected:\|private:\)\n\+\)\+\(public:\|protected:\|private:\|}\)/\3/gm
45   s/^\(\(public:\|protected:\|private:\)\n\(\([ \t].*\)\?\n\)\+\)\2\n/\1/gm
46   p
47   d}' "$file"
48         add_public_def "  virtual ~$class ();\\n" "$class" "$file"
49     done
50
51 for i in $(git grep -l '^IMPLEMENT\(_SIMPLE\)\?_SMOBS' lily)
52 do
53     sed -i '/^IMPLEMENT\(_SIMPLE\)\?_SMOBS\s*(.*);\s*$/d' $i
54 done
55
56 git grep '^IMPLEMENT_TYPE_P' lily|sed -n 's/^\([^:]\+\):IMPLEMENT_TYPE_P (\([^,]*\), \("[^"]*"\));\s*/\1 \2 \3/p'|
57     while read file class pred
58     do
59         echo "Implement predicate $pred for $class in $file" >&2
60         sed -i '/^IMPLEMENT_TYPE_P/c\
61 const char '"$class"'::type_p_name_[] = '"$pred"';' "$file"
62         for i in $(git grep -l '^\(class\|struct\)\s\+'"$class"'\s' lily)
63         do
64             add_public_def '  static const char type_p_name_[];\n' "$class" "$i"
65         done
66   done
67
68 for i in $(git grep -l '^IMPLEMENT_DEFAULT_EQUAL_P' lily)
69 do
70     sed -i '/^IMPLEMENT_DEFAULT_EQUAL_P/d' "$i"
71 done
72
73 # Get rid of stock mark_smob/print_smob/equal_p definitions: those are
74 # implemented by fallback in Smob_base
75
76 for i in $(git grep -l '^\([_a-zA-Z]\+::mark_smob\|print_smob\|equal_p\)\s*(SCM\s*\(\/\*[^*]*\*\/\s*\)\?[,)]' lily)
77 do
78     sed -i -n '1h
79 1!H
80 ${g
81   s/^\n\?\(\(SCM\|int\)\s\+\)\([_a-zA-Z]\+\)::\(mark_smob\|equal_p\|print_smob\)\s*(SCM\s*\(\/\*[^*]*\*\/\s*\)\?[,)]\(\n*[^}]\)*\n}//gm
82   p
83   d}' "$i"
84 done
85
86 git grep '^\([_a-zA-Z]\+\)::\(mark_smob\|print_smob\|equal_p\)\b' lily|sed -n 's/^\([^:]\+\):\([_a-zA-Z]\+\)::\([_a-zA-Z]\+\)\b.*$/\1 \2 \3/p'|
87     while read file class pred
88     do
89         echo "Declare $class::$pred in $file" >&2
90         for i in $(git grep -l '^\(struct\|class\) '$class'\s' lily)
91         do
92             case "$pred" in
93                 mark_smob)
94                     add_public_def "  static SCM mark_smob (SCM);\n" "$class" "$i"
95                     ;;
96                 print_smob)
97                     add_public_def "  static int print_smob (SCM, SCM, scm_print_state *);\n" "$class" "$i"
98                     ;;
99                 equal_p)
100                     add_public_def "  static SCM equal_p (SCM, SCM);\n" "$class" "$i"
101             esac
102         done
103     done
104
105 for i in $(git grep -l '^#include "ly-smobs.icc"$' lily)
106 do
107     sed -i '/^#include "ly-smobs.icc"$/d' "$i"
108 done
109
110 # Clean up trailing newlines
111 for i in $(git diff --name-only lily)
112 do
113     sed -i -n '1h
114 1!H
115 ${g
116   s/\n\+$//
117   p
118   d}' "$i"
119 done