diff --git a/utils/style_check.py b/utils/style_check.py new file mode 100644 index 0000000..718b635 --- /dev/null +++ b/utils/style_check.py @@ -0,0 +1,49 @@ +#===-- Style_check.py - Simple style checking for llvm *- Python -*- +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +#===---------------------------------------------------------------------- + +from optparse import OptionParser + +parser = OptionParser("usage: %prog arg1 arg2 ... argn [options]"); +parser.add_option("", "--no-check-for-tabs", action="store_false", + dest="doCheckForTabs", + default = True, help="don't check for tabs") +parser.add_option("", "--no-check-line-length", action="store_false", + dest="doCheckLineLength", + default = True, help="don't check line length") +parser.add_option("", "--max-line-length", dest="maxLineLength", + default=80, type="int", + help="specify maximum line length") +(options, args) = parser.parse_args() + +doCheckForTabs=options.doCheckForTabs +doCheckLineLength=options.doCheckLineLength +maxLineLength=options.maxLineLength + +def checkTabs(f, lineNum, line): + column = 0; + for c in line: + column = column + 1 + if c == '\t': + print "tab at line=", lineNum, "column=", column, f.name + +def checkLineLength(f, lineNum, line): + if len(line) > maxLineLength + 1: + print line, + print "line too long=", lineNum, "len=", len(line) - 1, f.name + +for x in args: + f = open(x, 'r') + lineNum = 0; + for line in f: + lineNum = lineNum + 1 + if doCheckLineLength: + checkLineLength(f, lineNum, line); + if doCheckForTabs: + checkTabs(f, lineNum, line); +