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

Function CheckCStyleCast

rtpose_wrapper/scripts/cpp_lint.py:4247–4338  ·  view source on GitHub ↗

Checks for a C-style cast by looking for the pattern. Args: filename: The name of the current file. linenum: The number of the line to check. line: The line of code to check. raw_line: The raw line of code to check, with comments. cast_type: The string for the C++ cast to reco

(filename, linenum, line, raw_line, cast_type, pattern,
                    error)

Source from the content-addressed store, hash-verified

4245
4246
4247def CheckCStyleCast(filename, linenum, line, raw_line, cast_type, pattern,
4248 error):
4249 """Checks for a C-style cast by looking for the pattern.
4250
4251 Args:
4252 filename: The name of the current file.
4253 linenum: The number of the line to check.
4254 line: The line of code to check.
4255 raw_line: The raw line of code to check, with comments.
4256 cast_type: The string for the C++ cast to recommend. This is either
4257 reinterpret_cast, static_cast, or const_cast, depending.
4258 pattern: The regular expression used to find C-style casts.
4259 error: The function to call with any errors found.
4260
4261 Returns:
4262 True if an error was emitted.
4263 False otherwise.
4264 """
4265 match = Search(pattern, line)
4266 if not match:
4267 return False
4268
4269 # Exclude lines with sizeof, since sizeof looks like a cast.
4270 sizeof_match = Match(r'.*sizeof\s*$', line[0:match.start(1) - 1])
4271 if sizeof_match:
4272 return False
4273
4274 # operator++(int) and operator--(int)
4275 if (line[0:match.start(1) - 1].endswith(' operator++') or
4276 line[0:match.start(1) - 1].endswith(' operator--')):
4277 return False
4278
4279 # A single unnamed argument for a function tends to look like old
4280 # style cast. If we see those, don't issue warnings for deprecated
4281 # casts, instead issue warnings for unnamed arguments where
4282 # appropriate.
4283 #
4284 # These are things that we want warnings for, since the style guide
4285 # explicitly require all parameters to be named:
4286 # Function(int);
4287 # Function(int) {
4288 # ConstMember(int) const;
4289 # ConstMember(int) const {
4290 # ExceptionMember(int) throw (...);
4291 # ExceptionMember(int) throw (...) {
4292 # PureVirtual(int) = 0;
4293 #
4294 # These are functions of some sort, where the compiler would be fine
4295 # if they had named parameters, but people often omit those
4296 # identifiers to reduce clutter:
4297 # (FunctionPointer)(int);
4298 # (FunctionPointer)(int) = value;
4299 # Function((function_pointer_arg)(int))
4300 # <TemplateArgument(int)>;
4301 # <(FunctionPointerTemplateArgument)(int)>;
4302 remainder = line[match.end(0):]
4303 if Match(r'^\s*(?:;|const\b|throw\b|=|>|\{|\))', remainder):
4304 # Looks like an unnamed parameter.

Callers 1

CheckLanguageFunction · 0.85

Calls 4

SearchFunction · 0.85
MatchFunction · 0.85
errorFunction · 0.85
endMethod · 0.45

Tested by

no test coverage detected