MCPcopy Create free account
hub / github.com/alibaba/GraphScope / CheckIncludeLine

Function CheckIncludeLine

analytical_engine/misc/cpplint.py:5050–5137  ·  view source on GitHub ↗

Check rules that are applicable to #include lines. Strings on #include lines are NOT removed from elided line, to make certain tasks easier. However, to prevent false positives, checks applicable to #include lines in CheckLanguage must be put here. Args: filename: The name of the curre

(filename, clean_lines, linenum, include_state, error)

Source from the content-addressed store, hash-verified

5048
5049
5050def CheckIncludeLine(filename, clean_lines, linenum, include_state, error):
5051 """Check rules that are applicable to #include lines.
5052
5053 Strings on #include lines are NOT removed from elided line, to make
5054 certain tasks easier. However, to prevent false positives, checks
5055 applicable to #include lines in CheckLanguage must be put here.
5056
5057 Args:
5058 filename: The name of the current file.
5059 clean_lines: A CleansedLines instance containing the file.
5060 linenum: The number of the line to check.
5061 include_state: An _IncludeState instance in which the headers are inserted.
5062 error: The function to call with any errors found.
5063 """
5064 fileinfo = FileInfo(filename)
5065 line = clean_lines.lines[linenum]
5066
5067 # "include" should use the new style "foo/bar.h" instead of just "bar.h"
5068 # Only do this check if the included header follows google naming
5069 # conventions. If not, assume that it's a 3rd party API that
5070 # requires special include conventions.
5071 #
5072 # We also make an exception for Lua headers, which follow google
5073 # naming convention but not the include convention.
5074 match = Match(r'#include\s*"([^/]+\.h)"', line)
5075 if match and not _THIRD_PARTY_HEADERS_PATTERN.match(match.group(1)):
5076 error(filename, linenum, 'build/include_subdir', 4,
5077 'Include the directory when naming .h files')
5078
5079 # we shouldn't include a file more than once. actually, there are a
5080 # handful of instances where doing so is okay, but in general it's
5081 # not.
5082 match = _RE_PATTERN_INCLUDE.search(line)
5083 if match:
5084 include = match.group(2)
5085 used_angle_brackets = (match.group(1) == '<')
5086 duplicate_line = include_state.FindHeader(include)
5087 if duplicate_line >= 0:
5088 error(filename, linenum, 'build/include', 4,
5089 '"%s" already included at %s:%s' %
5090 (include, filename, duplicate_line))
5091 return
5092
5093 for extension in GetNonHeaderExtensions():
5094 if (include.endswith('.' + extension) and
5095 os.path.dirname(fileinfo.RepositoryName()) != os.path.dirname(include)):
5096 error(filename, linenum, 'build/include', 4,
5097 'Do not include .' + extension + ' files from other packages')
5098 return
5099
5100 # We DO want to include a 3rd party looking header if it matches the
5101 # filename. Otherwise we get an erroneous error "...should include its
5102 # header" error later.
5103 third_src_header = False
5104 for ext in GetHeaderExtensions():
5105 basefilename = filename[0:len(filename) - len(fileinfo.Extension())]
5106 headerfile = basefilename + '.' + ext
5107 headername = FileInfo(headerfile).RepositoryName()

Callers 1

CheckLanguageFunction · 0.85

Calls 15

RepositoryNameMethod · 0.95
ExtensionMethod · 0.95
BaseNameMethod · 0.95
FileInfoClass · 0.85
GetNonHeaderExtensionsFunction · 0.85
GetHeaderExtensionsFunction · 0.85
_ClassifyIncludeFunction · 0.85
FindHeaderMethod · 0.80
CheckNextIncludeOrderMethod · 0.80
IsInAlphabeticalOrderMethod · 0.80
SetLastHeaderMethod · 0.80

Tested by

no test coverage detected