MCPcopy Create free account
hub / github.com/apache/mesos / CheckLanguage

Function CheckLanguage

support/cpplint.py:4685–4840  ·  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

4683
4684
4685def CheckLanguage(filename, clean_lines, linenum, file_extension,
4686 include_state, nesting_state, error):
4687 """Checks rules from the 'C++ language rules' section of cppguide.html.
4688
4689 Some of these rules are hard to test (function overloading, using
4690 uint32 inappropriately), but we do the best we can.
4691
4692 Args:
4693 filename: The name of the current file.
4694 clean_lines: A CleansedLines instance containing the file.
4695 linenum: The number of the line to check.
4696 file_extension: The extension (without the dot) of the filename.
4697 include_state: An _IncludeState instance in which the headers are inserted.
4698 nesting_state: A NestingState instance which maintains information about
4699 the current stack of nested blocks being parsed.
4700 error: The function to call with any errors found.
4701 """
4702 # If the line is empty or consists of entirely a comment, no need to
4703 # check it.
4704 line = clean_lines.elided[linenum]
4705 if not line:
4706 return
4707
4708 match = _RE_PATTERN_INCLUDE.search(line)
4709 if match:
4710 CheckIncludeLine(filename, clean_lines, linenum, include_state, error)
4711 return
4712
4713 # Reset include state across preprocessor directives. This is meant
4714 # to silence warnings for conditional includes.
4715 match = Match(r'^\s*#\s*(if|ifdef|ifndef|elif|else|endif)\b', line)
4716 if match:
4717 include_state.ResetSection(match.group(1))
4718
4719 # Make Windows paths like Unix.
4720 fullname = os.path.abspath(filename).replace('\\', '/')
4721
4722 # Perform other checks now that we are sure that this is not an include line
4723 CheckCasts(filename, clean_lines, linenum, error)
4724 CheckGlobalStatic(filename, clean_lines, linenum, error)
4725 CheckPrintf(filename, clean_lines, linenum, error)
4726
4727 if IsHeaderExtension(file_extension):
4728 # TODO(unknown): check that 1-arg constructors are explicit.
4729 # How to tell it's a constructor?
4730 # (handled in CheckForNonStandardConstructs for now)
4731 # TODO(unknown): check that classes declare or disable copy/assign
4732 # (level 1 error)
4733 pass
4734
4735 # Check if people are using the verboten C basic types. The only exception
4736 # we regularly allow is "unsigned short port" for port.
4737 if Search(r'\bshort port\b', line):
4738 if not Search(r'\bunsigned short port\b', line):
4739 error(filename, linenum, 'runtime/int', 4,
4740 'Use "unsigned short" for ports, not "short"')
4741 else:
4742 match = Search(r'\b(short|long(?! +double)|long long)\b', line)

Callers 1

ProcessLineFunction · 0.85

Calls 11

CheckIncludeLineFunction · 0.85
MatchFunction · 0.85
CheckCastsFunction · 0.85
CheckGlobalStaticFunction · 0.85
CheckPrintfFunction · 0.85
IsHeaderExtensionFunction · 0.85
SearchFunction · 0.85
errorFunction · 0.85
_GetTextInsideFunction · 0.85
ResetSectionMethod · 0.80
findMethod · 0.45

Tested by

no test coverage detected