MCPcopy Index your code
hub / github.com/cpplint/cpplint / CheckLanguage

Function CheckLanguage

cpplint.py:5901–6113  ·  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_t inappropriately), but we do the best we can. Args: filename: The name of the current file. clean_lines: A CleansedLines instance c

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

Source from the content-addressed store, hash-verified

5899
5900
5901def CheckLanguage(
5902 filename, clean_lines, linenum, file_extension, include_state, nesting_state, error
5903):
5904 """Checks rules from the 'C++ language rules' section of cppguide.html.
5905
5906 Some of these rules are hard to test (function overloading, using
5907 uint32_t inappropriately), but we do the best we can.
5908
5909 Args:
5910 filename: The name of the current file.
5911 clean_lines: A CleansedLines instance containing the file.
5912 linenum: The number of the line to check.
5913 file_extension: The extension (without the dot) of the filename.
5914 include_state: An _IncludeState instance in which the headers are inserted.
5915 nesting_state: A NestingState instance which maintains information about
5916 the current stack of nested blocks being parsed.
5917 error: The function to call with any errors found.
5918 """
5919 # If the line is empty or consists of entirely a comment, no need to
5920 # check it.
5921 line = clean_lines.elided[linenum]
5922 if not line:
5923 return
5924
5925 match = _RE_PATTERN_INCLUDE.search(line)
5926 if match:
5927 CheckIncludeLine(filename, clean_lines, linenum, include_state, error)
5928 return
5929
5930 # Reset include state across preprocessor directives. This is meant
5931 # to silence warnings for conditional includes.
5932 match = re.match(r"^\s*#\s*(if|ifdef|ifndef|elif|else|endif)\b", line)
5933 if match:
5934 include_state.ResetSection(match.group(1))
5935
5936 # Perform other checks now that we are sure that this is not an include line
5937 CheckCasts(filename, clean_lines, linenum, error)
5938 CheckGlobalStatic(filename, clean_lines, linenum, error)
5939 CheckPrintf(filename, clean_lines, linenum, error)
5940
5941 if IsHeaderExtension(file_extension):
5942 # TODO(google): check that 1-arg constructors are explicit.
5943 # How to tell it's a constructor?
5944 # (handled in CheckForNonStandardConstructs for now)
5945 # TODO(google): check that classes declare or disable copy/assign
5946 # (level 1 error)
5947 pass
5948
5949 # Check if people are using the verboten C basic types. The only exception
5950 # we regularly allow is "unsigned short port" for port.
5951 if re.search(r"\bshort port\b", line):
5952 if not re.search(r"\bunsigned short port\b", line):
5953 error(
5954 filename, linenum, "runtime/int", 4, 'Use "unsigned short" for ports, not "short"'
5955 )
5956 else:
5957 match = re.search(r"\b(short|long(?! +double)|long long)\b", line)
5958 if match:

Callers 1

ProcessLineFunction · 0.85

Calls 7

CheckIncludeLineFunction · 0.85
CheckCastsFunction · 0.85
CheckGlobalStaticFunction · 0.85
CheckPrintfFunction · 0.85
IsHeaderExtensionFunction · 0.85
_GetTextInsideFunction · 0.85
ResetSectionMethod · 0.80

Tested by

no test coverage detected