Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions cpp/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

from . import keywords
from . import tokenize
from . import utils


try:
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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())
Expand Down
6 changes: 3 additions & 3 deletions cpp/find_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions cpp/static_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,15 @@ 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:
if node.name == 'static':
# 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):
Expand Down
4 changes: 0 additions & 4 deletions cpp/tokenize.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

import sys

from . import utils

__author__ = 'nnorwitz@google.com (Neal Norwitz)'


Expand Down Expand Up @@ -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__
Expand Down
4 changes: 0 additions & 4 deletions cpp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 11 additions & 11 deletions test/expected.txt
Original file line number Diff line number Diff line change
@@ -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;'
Expand Down