| 4089 | /** simplify labels and case|default in the code: add a ";" if not already in.*/ |
| 4090 | |
| 4091 | void Tokenizer::simplifyLabelsCaseDefault() |
| 4092 | { |
| 4093 | const bool cpp = isCPP(); |
| 4094 | bool executablescope = false; |
| 4095 | int indentLevel = 0; |
| 4096 | for (Token *tok = list.front(); tok; tok = tok->next()) { |
| 4097 | // Simplify labels in the executable scope.. |
| 4098 | auto *start = const_cast<Token *>(startOfExecutableScope(tok)); |
| 4099 | if (start) { |
| 4100 | tok = start; |
| 4101 | executablescope = true; |
| 4102 | } |
| 4103 | |
| 4104 | if (!executablescope) |
| 4105 | continue; |
| 4106 | |
| 4107 | if (tok->str() == "{") { |
| 4108 | if (tok->strAt(-1) == "=") |
| 4109 | tok = tok->link(); |
| 4110 | else |
| 4111 | ++indentLevel; |
| 4112 | } else if (tok->str() == "}") { |
| 4113 | --indentLevel; |
| 4114 | if (indentLevel == 0) { |
| 4115 | executablescope = false; |
| 4116 | continue; |
| 4117 | } |
| 4118 | } else if (Token::Match(tok, "(|[")) |
| 4119 | tok = tok->link(); |
| 4120 | |
| 4121 | if (Token::Match(tok, "[;{}:] case")) { |
| 4122 | tok = skipCaseLabel(tok->next()); |
| 4123 | if (!tok) |
| 4124 | break; |
| 4125 | if (tok->str() != ":" || tok->strAt(-1) == "case" || !tok->next()) |
| 4126 | syntaxError(tok); |
| 4127 | if (tok->strAt(1) != ";" && tok->strAt(1) != "case") |
| 4128 | tok->insertToken(";"); |
| 4129 | else |
| 4130 | tok = tok->previous(); |
| 4131 | } else if (Token::Match(tok, "[;{}] %name% : !!;")) { |
| 4132 | if (!cpp || !Token::Match(tok->next(), "class|struct|enum")) { |
| 4133 | tok = tok->tokAt(2); |
| 4134 | tok->insertToken(";"); |
| 4135 | } |
| 4136 | } |
| 4137 | } |
| 4138 | } |
| 4139 | |
| 4140 | |
| 4141 | void Tokenizer::simplifyCaseRange() |
nothing calls this directly
no test coverage detected