MCPcopy Create free account
hub / github.com/BoomingTech/Piccolo / CheckLanguage

Function CheckLanguage

engine/3rdparty/tinyobjloader/deps/cpplint.py:4761–4916  ·  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

4759
4760
4761def CheckLanguage(filename, clean_lines, linenum, file_extension,
4762 include_state, nesting_state, error):
4763 """Checks rules from the 'C++ language rules' section of cppguide.html.
4764
4765 Some of these rules are hard to test (function overloading, using
4766 uint32 inappropriately), but we do the best we can.
4767
4768 Args:
4769 filename: The name of the current file.
4770 clean_lines: A CleansedLines instance containing the file.
4771 linenum: The number of the line to check.
4772 file_extension: The extension (without the dot) of the filename.
4773 include_state: An _IncludeState instance in which the headers are inserted.
4774 nesting_state: A NestingState instance which maintains information about
4775 the current stack of nested blocks being parsed.
4776 error: The function to call with any errors found.
4777 """
4778 # If the line is empty or consists of entirely a comment, no need to
4779 # check it.
4780 line = clean_lines.elided[linenum]
4781 if not line:
4782 return
4783
4784 match = _RE_PATTERN_INCLUDE.search(line)
4785 if match:
4786 CheckIncludeLine(filename, clean_lines, linenum, include_state, error)
4787 return
4788
4789 # Reset include state across preprocessor directives. This is meant
4790 # to silence warnings for conditional includes.
4791 match = Match(r'^\s*#\s*(if|ifdef|ifndef|elif|else|endif)\b', line)
4792 if match:
4793 include_state.ResetSection(match.group(1))
4794
4795 # Make Windows paths like Unix.
4796 fullname = os.path.abspath(filename).replace('\\', '/')
4797
4798 # Perform other checks now that we are sure that this is not an include line
4799 CheckCasts(filename, clean_lines, linenum, error)
4800 CheckGlobalStatic(filename, clean_lines, linenum, error)
4801 CheckPrintf(filename, clean_lines, linenum, error)
4802
4803 if file_extension == 'h':
4804 # TODO(unknown): check that 1-arg constructors are explicit.
4805 # How to tell it's a constructor?
4806 # (handled in CheckForNonStandardConstructs for now)
4807 # TODO(unknown): check that classes declare or disable copy/assign
4808 # (level 1 error)
4809 pass
4810
4811 # Check if people are using the verboten C basic types. The only exception
4812 # we regularly allow is "unsigned short port" for port.
4813 if Search(r'\bshort port\b', line):
4814 if not Search(r'\bunsigned short port\b', line):
4815 error(filename, linenum, 'runtime/int', 4,
4816 'Use "unsigned short" for ports, not "short"')
4817 else:
4818 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
SearchFunction · 0.85
_GetTextInsideFunction · 0.85
ResetSectionMethod · 0.80
splitMethod · 0.80
errorFunction · 0.50
findMethod · 0.45

Tested by

no test coverage detected