summaryrefslogtreecommitdiffstats
path: root/llvm/utils/lint/common_lint.py
diff options
context:
space:
mode:
authorMisha Brukman <brukman+llvm@gmail.com>2009-01-02 21:15:30 +0000
committerMisha Brukman <brukman+llvm@gmail.com>2009-01-02 21:15:30 +0000
commit9d7b49bfd151717898e7886acb7a4000bbc16472 (patch)
treec71ff42f189447bb8f520abc053a80719ad13c6d /llvm/utils/lint/common_lint.py
parent6d24def98afe645cc7ec8744637f7e7aae0737dc (diff)
downloadbcm5719-llvm-9d7b49bfd151717898e7886acb7a4000bbc16472.tar.gz
bcm5719-llvm-9d7b49bfd151717898e7886acb7a4000bbc16472.zip
Added some basic lint tools for C++ and generic lint tool applicable to all
types of files (TableGen, LLVM assembly, HTML files, etc.) llvm-svn: 61592
Diffstat (limited to 'llvm/utils/lint/common_lint.py')
-rw-r--r--llvm/utils/lint/common_lint.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/llvm/utils/lint/common_lint.py b/llvm/utils/lint/common_lint.py
new file mode 100644
index 00000000000..95670316654
--- /dev/null
+++ b/llvm/utils/lint/common_lint.py
@@ -0,0 +1,58 @@
+#!/usr/bin/python
+#
+# Common lint functions applicable to multiple types of files.
+
+import re
+
+def VerifyLineLength(filename, lines, max_length):
+ """Checkes to make sure the file has no lines with lines exceeding the length
+ limit.
+
+ Args:
+ filename: the file under consideration as string
+ lines: contents of the file as string array
+ max_length: maximum acceptable line length as number
+ """
+ line_num = 1
+ for line in lines:
+ length = len(line.rstrip()) # strip off EOL char(s)
+ if length > max_length:
+ print '%s:%d:Line exceeds %d chars (%d)' % (filename, line_num,
+ max_length, length)
+ line_num += 1
+
+
+def VerifyTrailingWhitespace(filename, lines):
+ """Checkes to make sure the file has no lines with trailing whitespace.
+
+ Args:
+ filename: the file under consideration as string
+ lines: contents of the file as string array
+ """
+ trailing_whitespace_re = re.compile(r'\s+$')
+ line_num = 1
+ for line in lines:
+ if trailing_whitespace_re.match(line):
+ print '%s:%d:Trailing whitespace' % (filename, line_num)
+ line_num += 1
+
+
+class BaseLint:
+ def RunOnFile(filename, lines):
+ raise Exception('RunOnFile() unimplemented')
+
+
+def RunLintOverAllFiles(lint, filenames):
+ """Runs linter over the contents of all files.
+
+ Args:
+ lint: subclass of BaseLint, implementing RunOnFile()
+ filenames: list of all files whose contents will be linted
+ """
+ for filename in filenames:
+ file = open(filename, 'r')
+ if not file:
+ print 'Cound not open %s' % filename
+ continue
+ lines = file.readlines()
+ lint.RunOnFile(filename, lines)
OpenPOWER on IntegriCloud