(self, data, rule, rawTokens = None)
| 394 | break |
| 395 | |
| 396 | def misra_9_x(self, data, rule, rawTokens = None): |
| 397 | |
| 398 | parser = InitializerParser() |
| 399 | |
| 400 | for variable in data.variables: |
| 401 | if variable.nameToken is None: |
| 402 | continue |
| 403 | |
| 404 | nameToken = variable.nameToken |
| 405 | |
| 406 | # Check if declaration and initialization is |
| 407 | # split into two separate statements in ast. |
| 408 | if nameToken.next and nameToken.next.isSplittedVarDeclEq: |
| 409 | nameToken = nameToken.next.next |
| 410 | |
| 411 | # Find declarations with initializer assignment |
| 412 | eq = nameToken |
| 413 | while not eq.isAssignmentOp and eq.astParent: |
| 414 | eq = eq.astParent |
| 415 | |
| 416 | # We are only looking for initializers |
| 417 | if not eq.isAssignmentOp or eq.astOperand2.isName: |
| 418 | continue |
| 419 | |
| 420 | if variable.isArray or variable.isClass: |
| 421 | ed = getElementDef(nameToken, rawTokens) |
| 422 | # No need to check non-arrays if valueType is missing, |
| 423 | # since we can't say anything useful about the structure |
| 424 | # without it. |
| 425 | if ed.valueType is None and not variable.isArray: |
| 426 | continue |
| 427 | parser.parseInitializer(ed, eq.astOperand2) |
| 428 | # print(rule, nameToken.str + '=', ed.getInitDump()) |
| 429 | if rule == 902 and not ed.isMisra92Compliant(): |
| 430 | self.reportError(nameToken, 9, 2) |
| 431 | if rule == 903 and not ed.isMisra93Compliant(): |
| 432 | # Do not check when variable is pointer type |
| 433 | type_token = variable.nameToken |
| 434 | while type_token and type_token.isName: |
| 435 | type_token = type_token.previous |
| 436 | if type_token and type_token.str == '*': |
| 437 | continue |
| 438 | |
| 439 | self.reportError(nameToken, 9, 3) |
| 440 | if rule == 904 and not ed.isMisra94Compliant(): |
| 441 | self.reportError(nameToken, 9, 4) |
| 442 | if rule == 905 and not ed.isMisra95Compliant(): |
| 443 | self.reportError(nameToken, 9, 5) |
| 444 | |
| 445 | def getElementDef(nameToken, rawTokens = None): |
| 446 | if nameToken.variable.isArray: |
nothing calls this directly
no test coverage detected