MCPcopy Create free account
hub / github.com/dmtcp/dmtcp / CheckLanguage

Function CheckLanguage

util/cpplint.py:4607–4762  ·  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

4605
4606
4607def CheckLanguage(filename, clean_lines, linenum, file_extension,
4608 include_state, nesting_state, error):
4609 """Checks rules from the 'C++ language rules' section of cppguide.html.
4610
4611 Some of these rules are hard to test (function overloading, using
4612 uint32 inappropriately), but we do the best we can.
4613
4614 Args:
4615 filename: The name of the current file.
4616 clean_lines: A CleansedLines instance containing the file.
4617 linenum: The number of the line to check.
4618 file_extension: The extension (without the dot) of the filename.
4619 include_state: An _IncludeState instance in which the headers are inserted.
4620 nesting_state: A NestingState instance which maintains information about
4621 the current stack of nested blocks being parsed.
4622 error: The function to call with any errors found.
4623 """
4624 # If the line is empty or consists of entirely a comment, no need to
4625 # check it.
4626 line = clean_lines.elided[linenum]
4627 if not line:
4628 return
4629
4630 match = _RE_PATTERN_INCLUDE.search(line)
4631 if match:
4632 CheckIncludeLine(filename, clean_lines, linenum, include_state, error)
4633 return
4634
4635 # Reset include state across preprocessor directives. This is meant
4636 # to silence warnings for conditional includes.
4637 match = Match(r'^\s*#\s*(if|ifdef|ifndef|elif|else|endif)\b', line)
4638 if match:
4639 include_state.ResetSection(match.group(1))
4640
4641 # Make Windows paths like Unix.
4642 fullname = os.path.abspath(filename).replace('\\', '/')
4643
4644 # Perform other checks now that we are sure that this is not an include line
4645 CheckCasts(filename, clean_lines, linenum, error)
4646 CheckGlobalStatic(filename, clean_lines, linenum, error)
4647 CheckPrintf(filename, clean_lines, linenum, error)
4648
4649 if IsHeaderExtension(file_extension):
4650 # TODO(unknown): check that 1-arg constructors are explicit.
4651 # How to tell it's a constructor?
4652 # (handled in CheckForNonStandardConstructs for now)
4653 # TODO(unknown): check that classes declare or disable copy/assign
4654 # (level 1 error)
4655 pass
4656
4657 # Check if people are using the verboten C basic types. The only exception
4658 # we regularly allow is "unsigned short port" for port.
4659 if Search(r'\bshort port\b', line):
4660 if not Search(r'\bunsigned short port\b', line):
4661 error(filename, linenum, 'runtime/int', 4,
4662 'Use "unsigned short" for ports, not "short"')
4663 else:
4664 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
replaceMethod · 0.80

Tested by

no test coverage detected