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

Function CheckLanguage

scripts/cpp_lint.py:3838–4136  ·  view source on GitHub ↗

Checks rules from the 'C++ language rules' section of cppguide.html. Some of these rules are hard to test (function overloading, using uint32 inappropriately), but we do the best we can. Args: filename: The name of the current file. clean_lines: A CleansedLines instance containing th

(filename, clean_lines, linenum, file_extension,
                  include_state, nesting_state, error)

Source from the content-addressed store, hash-verified

3836
3837
3838def CheckLanguage(filename, clean_lines, linenum, file_extension,
3839 include_state, nesting_state, error):
3840 """Checks rules from the 'C++ language rules' section of cppguide.html.
3841
3842 Some of these rules are hard to test (function overloading, using
3843 uint32 inappropriately), but we do the best we can.
3844
3845 Args:
3846 filename: The name of the current file.
3847 clean_lines: A CleansedLines instance containing the file.
3848 linenum: The number of the line to check.
3849 file_extension: The extension (without the dot) of the filename.
3850 include_state: An _IncludeState instance in which the headers are inserted.
3851 nesting_state: A _NestingState instance which maintains information about
3852 the current stack of nested blocks being parsed.
3853 error: The function to call with any errors found.
3854 """
3855 # If the line is empty or consists of entirely a comment, no need to
3856 # check it.
3857 line = clean_lines.elided[linenum]
3858 if not line:
3859 return
3860
3861 match = _RE_PATTERN_INCLUDE.search(line)
3862 if match:
3863 CheckIncludeLine(filename, clean_lines, linenum, include_state, error)
3864 return
3865
3866 # Reset include state across preprocessor directives. This is meant
3867 # to silence warnings for conditional includes.
3868 if Match(r'^\s*#\s*(?:ifdef|elif|else|endif)\b', line):
3869 include_state.ResetSection()
3870
3871 # Make Windows paths like Unix.
3872 fullname = os.path.abspath(filename).replace('\\', '/')
3873
3874 # TODO(unknown): figure out if they're using default arguments in fn proto.
3875
3876 # Check to see if they're using an conversion function cast.
3877 # I just try to capture the most common basic types, though there are more.
3878 # Parameterless conversion functions, such as bool(), are allowed as they are
3879 # probably a member operator declaration or default constructor.
3880 match = Search(
3881 r'(\bnew\s+)?\b' # Grab 'new' operator, if it's there
3882 r'(int|float|double|bool|char|int32|uint32|int64|uint64)'
3883 r'(\([^)].*)', line)
3884 if match:
3885 matched_new = match.group(1)
3886 matched_type = match.group(2)
3887 matched_funcptr = match.group(3)
3888
3889 # gMock methods are defined using some variant of MOCK_METHODx(name, type)
3890 # where type may be float(), int(string), etc. Without context they are
3891 # virtually indistinguishable from int(x) casts. Likewise, gMock's
3892 # MockCallback takes a template parameter of the form return_type(arg_type),
3893 # which looks much like the cast we're trying to detect.
3894 #
3895 # std::function<> wrapper has a similar problem.

Callers 1

ProcessLineFunction · 0.85

Calls 7

CheckIncludeLineFunction · 0.85
MatchFunction · 0.85
SearchFunction · 0.85
CheckCStyleCastFunction · 0.85
_GetTextInsideFunction · 0.85
ResetSectionMethod · 0.80
NumLinesMethod · 0.80

Tested by

no test coverage detected