changeset 01b16bab6675 in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=01b16bab6675
description:
util: added line length and boolean comparison style checkers
Added checkers for line length and boolean comparisons
(== true/== false) to the style script.
diffstat:
util/style.py | 48 ++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 42 insertions(+), 6 deletions(-)
diffs (65 lines):
diff -r 02e930db812d -r 01b16bab6675 util/style.py
--- a/util/style.py Sat Feb 06 17:21:19 2016 -0800
+++ b/util/style.py Sat Feb 06 17:21:20 2016 -0800
@@ -404,12 +404,6 @@
f.write('\n')
f.close()
-# list of all verifier classes
-all_verifiers = [
- Whitespace,
- ControlSpace,
- SortedIncludes
-]
def linelen(line):
tabs = line.count('\t')
@@ -425,6 +419,48 @@
return count
+class LineLength(Verifier):
+ languages = set(('C', 'C++', 'swig', 'python', 'asm', 'isa', 'scons'))
+ test_name = 'line length'
+ opt_name = 'length'
+
+ def check_line(self, line):
+ return linelen(line) <= 78
+
+ def fix(self, filename, regions=all_regions):
+ self.write("Warning: cannot automatically fix overly long lines.\n")
+
+
+class BoolCompare(Verifier):
+ languages = set(('C', 'C++', 'python'))
+ test_name = 'boolean comparison'
+ opt_name = 'boolcomp'
+
+ regex = re.compile(r'\s*==\s*([Tt]rue|[Ff]alse)\b')
+
+ def check_line(self, line):
+ return self.regex.search(line) == None
+
+ def fix_line(self, line):
+ match = self.regex.search(line)
+ if match:
+ if match.group(1) in ('true', 'True'):
+ line = self.regex.sub('', line)
+ else:
+ self.write("Warning: cannot automatically fix "
+ "comparisons with false/False.\n")
+ return line
+
+
+# list of all verifier classes
+all_verifiers = [
+ Whitespace,
+ ControlSpace,
+ LineLength,
+ BoolCompare,
+ SortedIncludes
+]
+
class ValidationStats(object):
def __init__(self):
self.toolong = 0
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev