(self, data)
| 3063 | self.reportError(token, 14, 1) |
| 3064 | |
| 3065 | def misra_14_2(self, data): |
| 3066 | for token in data.tokenlist: |
| 3067 | if token.str == 'for': |
| 3068 | expressions = getForLoopExpressions(token) |
| 3069 | if not expressions: |
| 3070 | continue |
| 3071 | if expressions[0] and not expressions[0].isAssignmentOp: |
| 3072 | if expressions[0].str != "(" or not expressions[0].previous.isName: |
| 3073 | self.reportError(token, 14, 2) |
| 3074 | if countSideEffectsRecursive(expressions[1]) > 0: |
| 3075 | self.reportError(token, 14, 2) |
| 3076 | if countSideEffectsRecursive(expressions[2]) > 1: |
| 3077 | self.reportError(token, 14, 2) |
| 3078 | |
| 3079 | counter_vars_first_clause, counter_vars_exit_modified = getForLoopCounterVariables(token, data) |
| 3080 | if len(counter_vars_exit_modified) == 0: |
| 3081 | # if it's not possible to identify a loop counter, all 3 clauses must be empty |
| 3082 | for idx in range(len(expressions)): |
| 3083 | if expressions[idx]: |
| 3084 | self.reportError(token, 14, 2) |
| 3085 | break |
| 3086 | elif len(counter_vars_exit_modified) > 1: |
| 3087 | # there shall be a single loop counter |
| 3088 | self.reportError(token, 14, 2) |
| 3089 | else: # len(counter_vars_exit_modified) == 1: |
| 3090 | loop_counter = counter_vars_exit_modified.pop() |
| 3091 | # if the first clause is not empty, then it shall (declare and) initialize the loop counter |
| 3092 | if expressions[0] is not None and loop_counter not in counter_vars_first_clause: |
| 3093 | self.reportError(token, 14, 2) |
| 3094 | |
| 3095 | # Inspect modification of loop counter in loop body |
| 3096 | body_scope = token.next.link.next.scope |
| 3097 | if not body_scope: |
| 3098 | continue |
| 3099 | tn = body_scope.bodyStart |
| 3100 | while tn and tn != body_scope.bodyEnd: |
| 3101 | if tn.variable == loop_counter: |
| 3102 | if tn.next: |
| 3103 | # TODO: Check modifications in function calls |
| 3104 | if countSideEffectsRecursive(tn.next) > 0: |
| 3105 | self.reportError(tn, 14, 2) |
| 3106 | tn = tn.next |
| 3107 | |
| 3108 | def misra_14_4(self, data): |
| 3109 | for token in data.tokenlist: |
nothing calls this directly
no test coverage detected