diff --git a/cpp/ast.py b/cpp/ast.py index 5aae7c0..4d0f07b 100644 --- a/cpp/ast.py +++ b/cpp/ast.py @@ -23,7 +23,6 @@ from . import keywords from . import tokenize -from . import utils try: @@ -94,8 +93,6 @@ def requires(self, node): return False def _string_helper(self, name, suffix): - if not utils.DEBUG: - return '%s(%s)' % (name, suffix) return '%s(%d, %d, %s)' % (name, self.start, self.end, suffix) def __repr__(self): @@ -1579,9 +1576,6 @@ def _get_class(self, class_type, visibility, templated_types): body = None if token.token_type == tokenize.SYNTAX and token.name == '{': - assert token.token_type == tokenize.SYNTAX, token - assert token.name == '{', token - ast = AstBuilder(self.get_scope(), self.filename, class_name, visibility, self.namespace_stack) body = list(ast.generate()) diff --git a/cpp/find_warnings.py b/cpp/find_warnings.py index 84ad403..614cd1b 100644 --- a/cpp/find_warnings.py +++ b/cpp/find_warnings.py @@ -191,7 +191,7 @@ def _verify_includes(self, included_files): for filename, (node, module) in included_files.items(): normalized_filename = module.normalized_filename if is_cpp_file(filename): - msg = 'should not #include C++ source file: %s' % filename + msg = 'Should not #include C++ source file: %s' % filename self._add_warning(msg, node) if normalized_filename == self.normalized_filename: self._add_warning('%s #includes itself' % filename, node) @@ -209,7 +209,7 @@ def _verify_include_files_used(self, file_uses, included_files): if not use & USES_DECLARATION: node, module = included_files[include_file] if module.ast_list is not None: - msg = module.filename + ' does not need to be #included' + msg = node.filename + ' does not need to be #included' if use & USES_REFERENCE: msg += '. Use a forward declaration instead' self._add_warning(msg, node) @@ -478,7 +478,7 @@ def _find_source_warnings(self): # be something to warn against. I expect this will either # be configurable or removed in the future. But it's easy # to check for now. - msg = 'forward declarations not expected in source file' + msg = 'Forward declarations not expected in source file' self._add_warning(msg, list(forward_declarations.values())[0]) # A primary header is optional. However, when looking up diff --git a/cpp/static_data.py b/cpp/static_data.py index a4a2cfe..829ea34 100644 --- a/cpp/static_data.py +++ b/cpp/static_data.py @@ -28,7 +28,7 @@ def _find_warnings(filename, source, ast_list, static_is_optional): def print_warning(node, name): lines = metrics.Metrics(source) print('%s:%d' % (filename, lines.get_line_number(node.start)), end=' ') - print('static data:', name) + print("static data: '{}'".format(name)) def find_static(function_node): for node in function_node.body: @@ -36,9 +36,7 @@ def find_static(function_node): # TODO(nnorwitz): should ignore const. Is static const common # here? lines = metrics.Metrics(source) - print_warning( - node, - "'{}'".format(lines.get_line(node.start).strip())) + print_warning(node, lines.get_line(node.start).strip()) for node in ast_list: if isinstance(node, ast.VariableDeclaration): diff --git a/cpp/tokenize.py b/cpp/tokenize.py index 2c5c783..892eaa0 100644 --- a/cpp/tokenize.py +++ b/cpp/tokenize.py @@ -21,8 +21,6 @@ import sys -from . import utils - __author__ = 'nnorwitz@google.com (Neal Norwitz)' @@ -76,8 +74,6 @@ def __init__(self, token_type, name, start, end): self.whence = WHENCE_STREAM def __str__(self): - if not utils.DEBUG: - return 'Token(%r)' % self.name return 'Token(%r, %s, %s)' % (self.name, self.start, self.end) __repr__ = __str__ diff --git a/cpp/utils.py b/cpp/utils.py index 29c4bae..b208b65 100644 --- a/cpp/utils.py +++ b/cpp/utils.py @@ -26,10 +26,6 @@ __author__ = 'nnorwitz@google.com (Neal Norwitz)' -# Set to True to see the start/end token indices. -DEBUG = True - - def read_file(filename, print_error=True): """Returns the contents of a file.""" try: diff --git a/test/expected.txt b/test/expected.txt index 5d7fa2e..b9ed707 100644 --- a/test/expected.txt +++ b/test/expected.txt @@ -1,22 +1,22 @@ -test/baz.h:1: test/bar.h does not need to be #included. Use a forward declaration instead +test/baz.h:1: bar.h does not need to be #included. Use a forward declaration instead test/cxx.cxx: Unable to find header file with matching name test/cxx.cxx:1: cxx not found in any directly #included header test/empty.cc: Unable to find header file with matching name test/foo.h:14: 'Unused' not used test/foo.h:61: 'ProtoArray' not used -test/foo.h:113: test/not-used.h does not need to be #included +test/foo.h:113: not-used.h does not need to be #included test/foo.h:150: 'AR' not used test/foo.h:221: Unable to find dir//bar.h test/foo.h:234 Colon has virtual methods without a virtual dtor -test/foo.h:20 static data: d -test/foo.h:101 static data: ptof -test/foo.h:106 static data: data -test/foo.h:208 static data: garbage_state -test/foo.h:225 static data: flags_ -test/foo.h:239 static data: foo -test/foo.h:241 static data: GlobalKey -test/foo.h:268 static data: instance_ -test/foo.h:274 static data: string_list +test/foo.h:20 static data: 'd' +test/foo.h:101 static data: 'ptof' +test/foo.h:106 static data: 'data' +test/foo.h:208 static data: 'garbage_state' +test/foo.h:225 static data: 'flags_' +test/foo.h:239 static data: 'foo' +test/foo.h:241 static data: 'GlobalKey' +test/foo.h:268 static data: 'instance_' +test/foo.h:274 static data: 'string_list' test/latin1.cc: Unable to find header file with matching name test/latin1.cc:2: latin1 not found in any directly #included header test/latin1.cc:4 static data: 'static int x;'