Browse Source

Add codepolicycheck for longlong consts

pull/1562/head
Sami Vaarala 8 years ago
parent
commit
2875c32b8f
  1. 1
      Makefile
  2. 15
      util/check_code_policy.py

1
Makefile

@ -986,6 +986,7 @@ codepolicycheck:
--check-nonleading-tab \
--check-cpp-comment \
--check-ifdef-ifndef \
--check-longlong-constants \
--dump-vim-commands \
src-input/*.c src-input/*.h src-input/*.h.in tests/api/*.c
@$(PYTHON) util/check_code_policy.py \

15
util/check_code_policy.py

@ -32,6 +32,8 @@ re_identifier = re.compile(r'[A-Za-z0-9_]+')
re_nonascii = re.compile(r'^.*?[\x80-\xff].*?$')
re_func_decl_or_def = re.compile(r'^(\w+)\s+(?:\w+\s+)*(\w+)\(.*?.*?$') # may not finish on same line
re_cpp_comment = re.compile(r'^.*?//.*?$')
re_longlong_constant_dec = re.compile(r'[0-9]+(LL|ULL)')
re_longlong_constant_hex = re.compile(r'0x[0-9a-fA-F]+(LL|ULL)')
fixmeString = 'FIX' + 'ME' # avoid triggering a code policy check warning :)
@ -351,6 +353,16 @@ def checkIfdefIfndef(lines, idx, filename):
if line.startswith('#ifndef'):
raise Exception('#ifndef found, #if !defined is preferred')
def checkLongLongConstants(lines, idx, filename):
line = lines[idx]
if not 'LL' in line:
return
for m in re.finditer(re_longlong_constant_hex, line):
raise Exception('plain longlong constant, use DUK_U64_CONSTANT or DUK_I64_CONSTANT: ' + str(m.group(0)))
for m in re.finditer(re_longlong_constant_dec, line):
raise Exception('plain longlong constant, use DUK_U64_CONSTANT or DUK_I64_CONSTANT: ' + str(m.group(0)))
def checkCppComment(lines, idx, filename):
line = lines[idx]
m = re_cpp_comment.match(line)
@ -419,6 +431,7 @@ def main():
parser.add_option('--check-nonleading-tab', dest='check_nonleading_tab', action='store_true', default=False, help='Check for non-leading tab characters')
parser.add_option('--check-cpp-comment', dest='check_cpp_comment', action='store_true', default=False, help='Check for c++ comments ("// ...")')
parser.add_option('--check-ifdef-ifndef', dest='check_ifdef_ifndef', action='store_true', default=False, help='Check for #ifdef and #ifndef (prefer #if defined and #if !defined)')
parser.add_option('--check-longlong-constants', dest='check_longlong_constants', action='store_true', default=False, help='Check for plain 123LL or 123ULL constants')
parser.add_option('--fail-on-errors', dest='fail_on_errors', action='store_true', default=False, help='Fail on errors (exit code != 0)')
(opts, args) = parser.parse_args()
@ -436,6 +449,8 @@ def main():
checkersRaw.append(checkNoSymbolVisibility)
if opts.check_ifdef_ifndef:
checkersRaw.append(checkIfdefIfndef)
if opts.check_longlong_constants:
checkersRaw.append(checkLongLongConstants)
checkersNoCCommentsOrLiterals = []
if opts.check_cpp_comment:

Loading…
Cancel
Save