[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [53619] trunk/blender/source: style cleanup: '} else' and add this check to check_style_c.py

Campbell Barton ideasman42 at gmail.com
Mon Jan 7 03:33:04 CET 2013


Revision: 53619
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53619
Author:   campbellbarton
Date:     2013-01-07 02:32:57 +0000 (Mon, 07 Jan 2013)
Log Message:
-----------
style cleanup: '} else' and add this check to check_style_c.py

Modified Paths:
--------------
    trunk/blender/source/blender/editors/sculpt_paint/sculpt.c
    trunk/blender/source/blender/editors/space_view3d/view3d_draw.c
    trunk/blender/source/blender/editors/uvedit/uvedit_smart_stitch.c
    trunk/blender/source/tools/check_style_c.py

Modified: trunk/blender/source/blender/editors/sculpt_paint/sculpt.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/sculpt.c	2013-01-07 01:23:09 UTC (rev 53618)
+++ trunk/blender/source/blender/editors/sculpt_paint/sculpt.c	2013-01-07 02:32:57 UTC (rev 53619)
@@ -4590,7 +4590,8 @@
 						CD_DUPLICATE, unode->bm_enter_totpoly);
 
 		mesh_update_customdata_pointers(me, FALSE);
-	} else {
+	}
+	else {
 		sculptsession_bm_to_me(ob, TRUE);
 	}
 

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_draw.c	2013-01-07 01:23:09 UTC (rev 53618)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_draw.c	2013-01-07 02:32:57 UTC (rev 53619)
@@ -3138,7 +3138,8 @@
 
 			glMatrixMode(GL_MODELVIEW);
 			glPopMatrix();
-		} else {
+		}
+		else {
 			UI_ThemeClearColor(TH_BACK);
 			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 		}

Modified: trunk/blender/source/blender/editors/uvedit/uvedit_smart_stitch.c
===================================================================
--- trunk/blender/source/blender/editors/uvedit/uvedit_smart_stitch.c	2013-01-07 01:23:09 UTC (rev 53618)
+++ trunk/blender/source/blender/editors/uvedit/uvedit_smart_stitch.c	2013-01-07 02:32:57 UTC (rev 53619)
@@ -1273,7 +1273,8 @@
 			UvElement *element = state->selection_stack[i];
 
 			stitch_propagate_uv_final_position (element, i, preview_position, final_position, state, final, scene);
-		}  else {
+		}
+		else {
 			UvEdge *edge = state->selection_stack[i];
 
 			stitch_propagate_uv_final_position (state->uvs[edge->uv1], edge->uv1, preview_position, final_position, state, final, scene);

Modified: trunk/blender/source/tools/check_style_c.py
===================================================================
--- trunk/blender/source/tools/check_style_c.py	2013-01-07 01:23:09 UTC (rev 53618)
+++ trunk/blender/source/tools/check_style_c.py	2013-01-07 02:32:57 UTC (rev 53619)
@@ -353,7 +353,15 @@
         if tokens[index_kw].line < tokens[i_next].line:
             warning("else if is split by a new line 'else\\nif'", index_kw, i_next)
 
+    # check
+    # } else
+    # ... which is never OK
+    i_prev = tk_advance_no_ws(index_kw, -1)
+    if tokens[i_prev].type == Token.Punctuation and tokens[i_prev].text == "}":
+        if tokens[index_kw].line == tokens[i_prev].line:
+            warning("else has no newline before the brace '} else'", i_prev, index_kw)
 
+
 def blender_check_cast(index_kw_start, index_kw_end):
     # detect: '( float...'
     if tokens[index_kw_start + 1].text.isspace():
@@ -515,6 +523,74 @@
                 warning("line length %d > %d" % (len(l), LIN_SIZE), index_start, index_end)
 
 
+def blender_check_function_definition(i):
+    # Warning, this is a fairly slow check and guesses
+    # based on some fuzzy rules
+
+    # assert(tokens[index] == "{")
+    
+    # check function declaraction is not:
+    #  'void myfunc() {'
+    # ... other uses are handled by checks for statements
+    # this check is rather simplistic but tends to work well enough.
+
+    i_prev = i - 1
+    while tokens[i_prev].text == "":
+        i_prev -= 1
+
+    # ensure this isnt '{' in its own line
+    if tokens[i_prev].line == tokens[i].line:
+
+        # check we '}' isnt on same line...
+        i_next = i + 1
+        found = False
+        while tokens[i_next].line == tokens[i].line:
+            if tokens[i_next].text == "}":
+                found = True
+                break
+            i_next += 1
+        del i_next
+
+        if found is False:
+
+            # First check this isnt an assignment
+            i_prev = tk_advance_no_ws(i, -1)
+            # avoid '= {'
+            #if tokens(index_prev).text != "="
+            # print(tokens[i_prev].text)
+            # allow:
+            # - 'func()[] {'
+            # - 'func() {'
+
+            if tokens[i_prev].text in {")", "]"}:
+                i_prev = i - 1
+                while tokens[i_prev].line == tokens[i].line:
+                    i_prev -= 1
+                split = tokens[i_prev].text.rsplit("\n", 1)
+                if len(split) > 1 and split[-1] != "":
+                    split_line = split[-1]
+                else:
+                    split_line = tokens[i_prev + 1].text
+
+                if split_line and split_line[0].isspace():
+                    pass
+                else:
+                    # no whitespace!
+                    i_begin = i_prev + 1
+
+                    # skip blank
+                    if tokens[i_begin].text == "":
+                        i_begin += 1
+                    # skip static
+                    if tokens[i_begin].text == "static":
+                        i_begin += 1
+                    while tokens[i_begin].text.isspace():
+                        i_begin += 1
+                    # now we are done skipping stuff
+
+                    warning("function's '{' must be on a newline", i_begin, i)
+
+
 def quick_check_indentation(code):
     """
     Quick check for multiple tab indents.
@@ -623,67 +699,8 @@
                 if item_range is not None:
                     blender_check_cast(item_range[0], item_range[1])
             elif tok.text == "{":
-                # check function declaraction is not:
-                #  'void myfunc() {'
-                # ... other uses are handled by checks for statements
-                # this check is rather simplistic but tends to work well enough.
+                blender_check_function_definition(i);
 
-                i_prev = i - 1
-                while tokens[i_prev].text == "":
-                    i_prev -= 1
-
-                # ensure this isnt '{' in its own line
-                if tokens[i_prev].line == tok.line:
-
-                    # check we '}' isnt on same line...
-                    i_next = i + 1
-                    found = False
-                    while tokens[i_next].line == tok.line:
-                        if tokens[i_next].text == "}":
-                            found = True
-                            break
-                        i_next += 1
-                    del i_next
-
-                    if found is False:
-
-                        # First check this isnt an assignment
-                        i_prev = tk_advance_no_ws(i, -1)
-                        # avoid '= {'
-                        #if tokens(index_prev).text != "="
-                        # print(tokens[i_prev].text)
-                        # allow:
-                        # - 'func()[] {'
-                        # - 'func() {'
-
-                        if tokens[i_prev].text in {")", "]"}:
-                            i_prev = i - 1
-                            while tokens[i_prev].line == tokens[i].line:
-                                i_prev -= 1
-                            split = tokens[i_prev].text.rsplit("\n", 1)
-                            if len(split) > 1 and split[-1] != "":
-                                split_line = split[-1]
-                            else:
-                                split_line = tokens[i_prev + 1].text
-
-                            if split_line and split_line[0].isspace():
-                                pass
-                            else:
-                                # no whitespace!
-                                i_begin = i_prev + 1
-
-                                # skip blank
-                                if tokens[i_begin].text == "":
-                                    i_begin += 1
-                                # skip static
-                                if tokens[i_begin].text == "static":
-                                    i_begin += 1
-                                while tokens[i_begin].text.isspace():
-                                    i_begin += 1
-                                # now we are done skipping stuff
-
-                                warning("function's '{' must be on a newline '%s', '%s' %d %d" % (tokens[i_begin].text, tokens[i].text, i_begin, i), i_begin, i)
-
         elif tok.type == Token.Operator:
             # we check these in pairs, only want first
             if tokens[i - 1].type != Token.Operator:




More information about the Bf-blender-cvs mailing list