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(
| 1250 | |
| 1251 | |
| 1252 | class _IncludeState: |
| 1253 | """Tracks line numbers for includes, and the order in which includes appear. |
| 1254 | |
| 1255 | include_list contains list of lists of (header, line number) pairs. |
| 1256 | It's a lists of lists rather than just one flat list to make it |
| 1257 | easier to update across preprocessor boundaries. |
| 1258 | |
| 1259 | Call CheckNextIncludeOrder() once for each header in the file, passing |
| 1260 | in the type constants defined above. Calls in an illegal order will |
| 1261 | raise an _IncludeError with an appropriate error message. |
| 1262 | |
| 1263 | """ |
| 1264 | |
| 1265 | # self._section will move monotonically through this set. If it ever |
| 1266 | # needs to move backwards, CheckNextIncludeOrder will raise an error. |
| 1267 | _INITIAL_SECTION = 0 |
| 1268 | _MY_H_SECTION = 1 |
| 1269 | _OTHER_H_SECTION = 2 |
| 1270 | _C_SECTION = 3 |
| 1271 | _CPP_SECTION = 4 |
| 1272 | _OTHER_SYS_SECTION = 5 |
| 1273 | |
| 1274 | _TYPE_NAMES = { |
| 1275 | _C_SYS_HEADER: "C system header", |
| 1276 | _CPP_SYS_HEADER: "C++ system header", |
| 1277 | _OTHER_SYS_HEADER: "other system header", |
| 1278 | _LIKELY_MY_HEADER: "header this file implements", |
| 1279 | _POSSIBLE_MY_HEADER: "header this file may implement", |
| 1280 | _OTHER_HEADER: "other header", |
| 1281 | } |
| 1282 | _SECTION_NAMES = { |
| 1283 | _INITIAL_SECTION: "... nothing. (This can't be an error.)", |
| 1284 | _MY_H_SECTION: "a header this file implements", |
| 1285 | _OTHER_H_SECTION: "other header", |
| 1286 | _C_SECTION: "C system header", |
| 1287 | _CPP_SECTION: "C++ system header", |
| 1288 | _OTHER_SYS_SECTION: "other system header", |
| 1289 | } |
| 1290 | |
| 1291 | def __init__(self): |
| 1292 | self.include_list = [[]] |
| 1293 | self._section = None |
| 1294 | self._last_header = None |
| 1295 | self.ResetSection("") |
| 1296 | |
| 1297 | def FindHeader(self, header): |
| 1298 | """Check if a header has already been included. |
| 1299 | |
| 1300 | Args: |
| 1301 | header: header to check. |
| 1302 | Returns: |
| 1303 | Line number of previous occurrence, or -1 if the header has not |
| 1304 | been seen before. |
| 1305 | """ |
| 1306 | for section_list in self.include_list: |
| 1307 | for f in section_list: |
| 1308 | if f[0] == header: |
| 1309 | return f[1] |
no outgoing calls
no test coverage detected
searching dependent graphs…