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

Class _IncludeState

analytical_engine/misc/cpplint.py:1073–1246  ·  view source on GitHub ↗

Tracks line numbers for includes, and the order in which includes appear. include_list contains list of lists of (header, line number) pairs. It's a lists of lists rather than just one flat list to make it easier to update across preprocessor boundaries. Call CheckNextIncludeOrder() once f

Source from the content-addressed store, hash-verified

1071
1072
1073class _IncludeState(object):
1074 """Tracks line numbers for includes, and the order in which includes appear.
1075
1076 include_list contains list of lists of (header, line number) pairs.
1077 It's a lists of lists rather than just one flat list to make it
1078 easier to update across preprocessor boundaries.
1079
1080 Call CheckNextIncludeOrder() once for each header in the file, passing
1081 in the type constants defined above. Calls in an illegal order will
1082 raise an _IncludeError with an appropriate error message.
1083
1084 """
1085 # self._section will move monotonically through this set. If it ever
1086 # needs to move backwards, CheckNextIncludeOrder will raise an error.
1087 _INITIAL_SECTION = 0
1088 _MY_H_SECTION = 1
1089 _C_SECTION = 2
1090 _CPP_SECTION = 3
1091 _OTHER_SYS_SECTION = 4
1092 _OTHER_H_SECTION = 5
1093
1094 _TYPE_NAMES = {
1095 _C_SYS_HEADER: 'C system header',
1096 _CPP_SYS_HEADER: 'C++ system header',
1097 _OTHER_SYS_HEADER: 'other system header',
1098 _LIKELY_MY_HEADER: 'header this file implements',
1099 _POSSIBLE_MY_HEADER: 'header this file may implement',
1100 _OTHER_HEADER: 'other header',
1101 }
1102 _SECTION_NAMES = {
1103 _INITIAL_SECTION: "... nothing. (This can't be an error.)",
1104 _MY_H_SECTION: 'a header this file implements',
1105 _C_SECTION: 'C system header',
1106 _CPP_SECTION: 'C++ system header',
1107 _OTHER_SYS_SECTION: 'other system header',
1108 _OTHER_H_SECTION: 'other header',
1109 }
1110
1111 def __init__(self):
1112 self.include_list = [[]]
1113 self._section = None
1114 self._last_header = None
1115 self.ResetSection('')
1116
1117 def FindHeader(self, header):
1118 """Check if a header has already been included.
1119
1120 Args:
1121 header: header to check.
1122 Returns:
1123 Line number of previous occurrence, or -1 if the header has not
1124 been seen before.
1125 """
1126 for section_list in self.include_list:
1127 for f in section_list:
1128 if f[0] == header:
1129 return f[1]
1130 return -1

Callers 1

ProcessFileDataFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected