MCPcopy Create free account
hub / github.com/BVLC/caffe / CheckEnd

Method CheckEnd

scripts/cpp_lint.py:1860–1903  ·  view source on GitHub ↗

Check end of namespace comments.

(self, filename, clean_lines, linenum, error)

Source from the content-addressed store, hash-verified

1858 self.starting_linenum = linenum
1859
1860 def CheckEnd(self, filename, clean_lines, linenum, error):
1861 """Check end of namespace comments."""
1862 line = clean_lines.raw_lines[linenum]
1863
1864 # Check how many lines is enclosed in this namespace. Don't issue
1865 # warning for missing namespace comments if there aren't enough
1866 # lines. However, do apply checks if there is already an end of
1867 # namespace comment and it's incorrect.
1868 #
1869 # TODO(unknown): We always want to check end of namespace comments
1870 # if a namespace is large, but sometimes we also want to apply the
1871 # check if a short namespace contained nontrivial things (something
1872 # other than forward declarations). There is currently no logic on
1873 # deciding what these nontrivial things are, so this check is
1874 # triggered by namespace size only, which works most of the time.
1875 if (linenum - self.starting_linenum < 10
1876 and not Match(r'};*\s*(//|/\*).*\bnamespace\b', line)):
1877 return
1878
1879 # Look for matching comment at end of namespace.
1880 #
1881 # Note that we accept C style "/* */" comments for terminating
1882 # namespaces, so that code that terminate namespaces inside
1883 # preprocessor macros can be cpplint clean.
1884 #
1885 # We also accept stuff like "// end of namespace <name>." with the
1886 # period at the end.
1887 #
1888 # Besides these, we don't accept anything else, otherwise we might
1889 # get false negatives when existing comment is a substring of the
1890 # expected namespace.
1891 if self.name:
1892 # Named namespace
1893 if not Match((r'};*\s*(//|/\*).*\bnamespace\s+' + re.escape(self.name) +
1894 r'[\*/\.\\\s]*$'),
1895 line):
1896 error(filename, linenum, 'readability/namespace', 5,
1897 'Namespace should be terminated with "// namespace %s"' %
1898 self.name)
1899 else:
1900 # Anonymous namespace
1901 if not Match(r'};*\s*(//|/\*).*\bnamespace[\*/\.\\\s]*$', line):
1902 error(filename, linenum, 'readability/namespace', 5,
1903 'Namespace should be terminated with "// namespace"')
1904
1905
1906class _PreprocessorInfo(object):

Callers

nothing calls this directly

Calls 1

MatchFunction · 0.85

Tested by

no test coverage detected