Check function code for balanced parentheses, brackets, and braces

This commit is contained in:
Douglas Clowes
2014-09-29 11:52:29 +10:00
parent 94bd7f32eb
commit 334d9d0e0c

View File

@ -825,6 +825,30 @@ def adjust_group(MyGroup):
if Verbose: if Verbose:
print 'post adjust_group', MyGroup print 'post adjust_group', MyGroup
def check_func_code(MyDriver):
for name in MyDriver['Funcs']:
#print name
left_paren_count = 0
right_paren_count = 0
left_brack_count = 0
right_brack_count = 0
left_brace_count = 0
right_brace_count = 0
for idx, line in enumerate(MyDriver['Funcs'][name]['text']):
#print "%4d:" % (idx + 1), line
left_paren_count += line.count('(')
right_paren_count += line.count(')')
left_brack_count += line.count('[')
right_brack_count += line.count(']')
left_brace_count += line.count('{')
right_brace_count += line.count('}')
if left_paren_count != right_paren_count:
PrintPostError("Warning: Mismatched Parens in function %s (%d != %d)" % (name, left_paren_count, right_paren_count))
if left_brack_count != right_brack_count:
PrintPostError("Warning: Mismatched Brackets in function %s (%d != %d)" % (name, left_brack_count, right_brack_count))
if left_brace_count != right_brace_count:
PrintPostError("Warning: Mismatched Braces in function %s (%d != %d)" % (name, left_brace_count, right_brace_count))
def build_driver(MyDriver, TheTree): def build_driver(MyDriver, TheTree):
if Verbose: if Verbose:
print "TheTree:", TheTree print "TheTree:", TheTree
@ -1752,6 +1776,7 @@ def process_drivers(TheDrivers):
MyDriver['Permlink'] = {} MyDriver['Permlink'] = {}
MyDriver['Deferred'] = [] MyDriver['Deferred'] = []
build_driver(MyDriver, TheDrivers[driver]) build_driver(MyDriver, TheDrivers[driver])
check_func_code(MyDriver)
if Verbose: if Verbose:
print "MyDriver:", MyDriver['name'], '=', MyDriver print "MyDriver:", MyDriver['name'], '=', MyDriver
if DriverDump or Verbose: if DriverDump or Verbose: