[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [53589] trunk/blender/source: style cleanup: also add checker for function brace placement.

Campbell Barton ideasman42 at gmail.com
Sat Jan 5 16:36:04 CET 2013


Revision: 53589
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53589
Author:   campbellbarton
Date:     2013-01-05 15:36:03 +0000 (Sat, 05 Jan 2013)
Log Message:
-----------
style cleanup: also add checker for function brace placement.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c
    trunk/blender/source/blender/makesrna/intern/rna_particle.c
    trunk/blender/source/blender/makesrna/intern/rna_sculpt_paint.c
    trunk/blender/source/tools/check_style_c.py

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c	2013-01-05 15:33:18 UTC (rev 53588)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c	2013-01-05 15:36:03 UTC (rev 53589)
@@ -657,8 +657,7 @@
 	 * grid rather than brush alpha */
 	kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", DKEY, KM_PRESS, KM_SHIFT, 0);
 	set_brush_rc_props(kmi->ptr, "sculpt", "detail_size", NULL, 0);
-	RNA_string_set(kmi->ptr, "data_path_primary",
-				   "tool_settings.sculpt.detail_size");
+	RNA_string_set(kmi->ptr, "data_path_primary", "tool_settings.sculpt.detail_size");
 
 	/* multires switch */
 	kmi = WM_keymap_add_item(keymap, "OBJECT_OT_subdivision_set", PAGEUPKEY, KM_PRESS, 0, 0);

Modified: trunk/blender/source/blender/makesrna/intern/rna_particle.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_particle.c	2013-01-05 15:33:18 UTC (rev 53588)
+++ trunk/blender/source/blender/makesrna/intern/rna_particle.c	2013-01-05 15:36:03 UTC (rev 53589)
@@ -492,7 +492,7 @@
 		if (n_mcol && ELEM(part->from, PART_FROM_FACE, PART_FROM_VOLUME)) {
 			if (num != DMCACHE_NOTFOUND) {
 				MFace *mface = modifier->dm->getTessFaceData(modifier->dm, num, CD_MFACE);
-				MCol *mc = (MCol*)CustomData_get_layer_n(&modifier->dm->faceData, CD_MCOL, vcol_no);
+				MCol *mc = (MCol *)CustomData_get_layer_n(&modifier->dm->faceData, CD_MCOL, vcol_no);
 				mc += num * 4;
 
 				psys_interpolate_mcol(mc, mface->v4, particle->fuv, &mcol);
@@ -517,7 +517,7 @@
 			if (n_mcol && ELEM(PART_FROM_FACE, PART_FROM_FACE, PART_FROM_VOLUME)) {
 				if (cpa->num != DMCACHE_NOTFOUND) {
 					MFace *mface = modifier->dm->getTessFaceData(modifier->dm, cpa->num, CD_MFACE);
-					MCol *mc = (MCol*)CustomData_get_layer_n(&modifier->dm->faceData, CD_MCOL, 0);
+					MCol *mc = (MCol *)CustomData_get_layer_n(&modifier->dm->faceData, CD_MCOL, 0);
 					mc += cpa->num * 4;
 
 					psys_interpolate_mcol(mc, mface->v4, cpa->fuv, &mcol);
@@ -543,7 +543,7 @@
 			if (n_mcol && ELEM(part->from, PART_FROM_FACE, PART_FROM_VOLUME)) {
 				if (num != DMCACHE_NOTFOUND) {
 					MFace *mface = modifier->dm->getTessFaceData(modifier->dm, num, CD_MFACE);
-					MCol *mc = (MCol*)CustomData_get_layer_n(&modifier->dm->faceData, CD_MCOL, 0);
+					MCol *mc = (MCol *)CustomData_get_layer_n(&modifier->dm->faceData, CD_MCOL, 0);
 					mc += num * 4;
 
 					psys_interpolate_mcol(mc, mface->v4, parent->fuv, &mcol);

Modified: trunk/blender/source/blender/makesrna/intern/rna_sculpt_paint.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_sculpt_paint.c	2013-01-05 15:33:18 UTC (rev 53588)
+++ trunk/blender/source/blender/makesrna/intern/rna_sculpt_paint.c	2013-01-05 15:36:03 UTC (rev 53589)
@@ -222,7 +222,7 @@
 
 		if (ob->sculpt) {
 			ob->sculpt->bm_smooth_shading = (scene->toolsettings->sculpt->flags &
-											 SCULPT_DYNTOPO_SMOOTH_SHADING);
+			                                 SCULPT_DYNTOPO_SMOOTH_SHADING);
 		}
 	}
 }

Modified: trunk/blender/source/tools/check_style_c.py
===================================================================
--- trunk/blender/source/tools/check_style_c.py	2013-01-05 15:33:18 UTC (rev 53588)
+++ trunk/blender/source/tools/check_style_c.py	2013-01-05 15:36:03 UTC (rev 53589)
@@ -91,16 +91,18 @@
 
 
 def tk_item_is_newline(tok):
-    return tok.type == Token.Text and tok.text == "\n"
+    return tok.type == Token.Text and tok.text.strip("\t ") == "\n"
 
 
 def tk_item_is_ws_newline(tok):
-    return (tok.type == Token.Text and tok.text.isspace()) or \
+    return (tok.text == "") or \
+           (tok.type == Token.Text and tok.text.isspace()) or \
            (tok.type in Token.Comment)
 
 
 def tk_item_is_ws(tok):
-    return (tok.type == Token.Text and tok.text != "\n" and tok.text.isspace()) or \
+    return (tok.text == "") or \
+           (tok.type == Token.Text and tok.text.strip("\t ") != "\n" and tok.text.isspace()) or \
            (tok.type in Token.Comment)
 
 
@@ -110,6 +112,11 @@
         index += direction
     return index
 
+def tk_advance_no_ws(index, direction):
+    index += direction
+    while tk_item_is_ws(tokens[index]) and index > 0:
+        index += direction
+    return index
 
 def tk_advance_ws_newline(index, direction):
     while tk_item_is_ws_newline(tokens[index + direction]) and index > 0:
@@ -223,7 +230,7 @@
             return None
     tokens_cast_strip = []
     for t in tokens_cast:
-        if t.type == Token.Comment:
+        if t.type in Token.Comment:
             pass
         elif t.type == Token.Text and t.text.isspace():
             pass
@@ -615,7 +622,68 @@
                 item_range = extract_cast(i)
                 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.
 
+                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