MCPcopy Create free account
hub / github.com/OpenPTrack/open_ptrack_v2 / CheckLanguage

Function CheckLanguage

rtpose_wrapper/scripts/cpp_lint.py:3834–4132  ·  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

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

Callers 1

ProcessLineFunction · 0.85

Calls 9

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

Tested by

no test coverage detected