]> git.donarmstrong.com Git - lilypond.git/blobdiff - scripts/auxiliar/fixcc.py
Imported Upstream version 2.14.2
[lilypond.git] / scripts / auxiliar / fixcc.py
index 34e9a89e55d132cf5762e893edc66b1e897e6595..845e97672fe782acdae18b98bf3a1dd1621b6a10 100755 (executable)
@@ -2,6 +2,21 @@
 
 # fixcc -- nitpick lily's c++ code
 
+# This file is part of LilyPond, the GNU music typesetter.
+#
+# LilyPond is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# LilyPond is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
+
 # TODO
 #  * maintainable rules: regexp's using whitespace (?x) and match names
 #    <identifier>)
@@ -31,9 +46,9 @@ indent_p = 0
 rules = {
     GLOBAL_CXX:
     [
-    # delete gratuitous block
-    ('''\n(    |\t)\s*{\n\s*(.*?)(?![{}]|\b(do|for|else|if|switch|while)\b);\n\s*}''',
-    '\n\\2;'),
+    # delete gratuitous block -- disabled because it breaks .h files
+#    ('''\n(    |\t)\s*{\n\s*(.*?)(?![{}]|\b(do|for|else|if|switch|while)\b);\n\s*}''',
+#    '\n\\2;'),
     ],
     CXX:
     [
@@ -41,9 +56,9 @@ rules = {
     ('([^\( \]])[ \t]*\(', '\\1 ('),
     # space after comma
     ("\([^'],\)[ \t]*", '\1 '),
-    # delete gratuitous block
-    ('''\n(    |\t)\s*{\n\s*(.*?)(?![{}]|\b(do|for|else|if|switch|while)\b);\n\s*}''',
-    '\n\\2;'),
+    # delete gratuitous block -- disabled because it breaks .h files
+#    ('''\n(    |\t)\s*{\n\s*(.*?)(?![{}]|\b(do|for|else|if|switch|while)\b);\n\s*}''',
+#    '\n\\2;'),
     # delete inline tabs
     ('(\w)\t+', '\\1 '),
     # delete inline double spaces
@@ -76,17 +91,17 @@ rules = {
     # space around +/-; exponent
     ('([\w\)\]])(\+|-)([_A-Za-z\(])', '\\1 \\2 \\3'),
     ('([_\dA-Za-df-z\)\]])(\+|-)([\w\(])', '\\1 \\2 \\3'),
-    # trailing operator
-    (' (::|&&|\|\||<=|>=|!=|\|=|==|\+=|-=|\*=|/=|\?|<|>|\+|-|=|/|:|&XXX|\||\*XXX)[ \t]*\n([ \t]*)',         '\n\\2\\1 '),
+    # trailing operator, but don't un-trail #include
+    (' (::|&&|\|\||<=|>=|!=|\|=|==|\+=|-=|\*=|/=|\?|<|>|\+|-|=|/|:|&XXX|\||\*XXX)[ \t]*\n([ \t]*)(?!#include)', '\n\\2\\1 '),
     # pointer
     ##('(bool|char|const|delete|int|stream|unsigned|void|size_t|struct \w+|[A-Z]\w*|,|;|&&|<|[^-]>|\|\||-|\+)[ \t]*(\*|&)[ \t]*', '\\1 \\2'),
-    ('(bool|char|const|delete|int|stream|unsigned|void|size_t|struct \w+|[A-Z]\w*|,|;|:|=|\?\)|&&|<|[^-]>|\|\||-|\+)[ \t]*(\*|&)[ \t]*', '\\1 \\2'),
+    ('(bool|char|const|delete|int|stream|unsigned|void|vsize|size_t|struct \w+|[A-Z]\w*|,|;|:|=|\?\)|&&|<|[^-]>|\|\||-|\+)[ \t]*(\*|&)[ \t]*', '\\1 \\2'),
     #to#('(bool|char|const|delete|int|stream|unsigned|void|([A-Z]\w*)|[,])[ \n\t]*(\*|&)[ \t]*', '\\1 \\3'),
     # pointer with template
-    ('(( *((bool|char|const|delete|int|stream|unsigned|void|size_t|class[ \t]+\w*|[A-Z]\w*|\w+::\w+|[,])\*&],*)+)>) *(\*|&) *', '\\1 \\5'),
+    ('(( *((bool|char|const|delete|int|stream|unsigned|void|size_t|class[ \t]+\w*|[A-Z]\w*|\w+::\w+|[,])\s*[\*&],*)+)>) *(\*|&) *', '\\1 \\5'),
     #to#('(( *((bool|char|delete|int|stream|unsigned|void|(class[ \t]+\w*)|([A-Z]\w*)|[,])[ \*&],*)+)>)[ \t\n]*(\*|&) *', '\\1 \\7'),
     # unary pointer, minus, not
-    ('(return|=) (\*|&|-|!) ([\w\(])', '\\1 \\2\\3'),
+    ('(return|=|&&|\|\|) (\*|&|-|!) ([\w\(])', '\\1 \\2\\3'),
     # space after `operator'
     ('(\Woperator) *([^\w\s])', '\\1 \\2'),
     # dangling brace close
@@ -100,10 +115,10 @@ rules = {
     ('\n[ \t]*\)', ')'),
     # dangling comma
     ('\n[ \t]*,', ','),
-    # dangling semicolon
-    ('\n[ \t]*;', ';'),
-    # brace open
-    ('(\w)[ \t]*([^\s]*){([ \t]*\n)', '\\1\\2\n{\n'),
+    # dangling semicolon, but don't un-dangle it onto #include
+    ('(\n.*\n[ \t]*;)(?!\n#include)', '\\1'),
+    # brace open, but not changing a #define... line
+    ('(\w)[ \t]*([^\s]*){([ \t]*\n)(?!#define)', '\\1\\2\n{\n'),
     # brace open backslash
     ('(\w[^\n]*){[ \t]*\\\\\n', '\\1\\\n{\\\n'),
     # brace close
@@ -128,7 +143,7 @@ rules = {
     ('(typedef struct\s+([\w]*\s){([^}]|{[^}]*})*})\s*\n\s*(\w[\w\d]*;)', '\\1 \\4'),
     # delete spaces around template brackets
     #('(dynamic_cast|template|([A-Z]\w*))[ \t]*<[ \t]*(( *(bool|char|int|unsigned|void|(class[ \t]+\w*)|([A-Z]\w*)),?)+)[ \t]?(| [\*&])[ \t]*>', '\\1<\\3\\8>'),
-    ('(dynamic_cast|template|typedef|\w+::\w+|[A-Z]\w*)[ \t]*<[ \t]*(( *(bool|char|const|int|unsigned|void|size_t|class[ \t]+\w*|[A-Z]\w*)( *[\*&]?,|[\*&])*)+)[ \t]?(| [\*&])[ \t]*>', '\\1<\\2\\6>'),
+    ('(dynamic_cast|less|list|map|set|template|typedef|vector|\w+::\w+|[A-Z]\w*)[ \t]*<[ \t]*(( *(bool|char|const|string|int|unsigned|void|vsize|size_t|class[ \t]+\w*|[A-Z]\w*)( *[\*&]?,|[\*&])*)+)[ \t]?(| [\*&])[ \t]*>', '\\1<\\2\\6>'),
     ('(\w+::\w+|[A-Z]\w*) < ((\w+::\w+|[A-Z]\w*)<[A-Z]\w*>) >', '\\1<\\2 >'),
     ('((if|while)\s+\(([^\)]|\([^\)]*\))*\))\s*;', '\\1\n;'),
     ('(for\s+\(([^;]*;[^;]*;([^\)]|\([^\)]*\))*)\))\s*;', '\\1\n;'),
@@ -435,7 +450,6 @@ Typical use with LilyPond:
 
  fixcc $(find flower kpath-guile lily -name '*cc' -o -name '*hh' | grep -v /out)
 
-This script is licensed under the GNU GPL
 ''')
 
 def do_options ():
@@ -532,7 +546,7 @@ typedef struct _t_ligature
 typedef std::map < AFM_Ligature const *, int > Bar;
 
  /**
(c) 1997--2009 Han-Wen Nienhuys <hanwen@cs.uu.nl>
Copyright (C) 1997--2011 Han-Wen Nienhuys <hanwen@cs.uu.nl>
  */
  
 /*      ||