Advance past comments and string/char literals so only real code tokens consume the candidate budget (#1989 review). Handles line-spliced // comments (a backslash before the newline continues the comment — line splicing happens before comment recognition) and, via the identifier-scan hook in the callers, C++ raw string literals. A digit separator (1'000'000) can still over-skip — that fails safe,
| 160 | // hook in the callers, C++ raw string literals. A digit separator (1'000'000) |
| 161 | // can still over-skip — that fails safe, toward NOT collecting a candidate. |
| 162 | static int skip_non_code(const char *source, int source_len, int i) { |
| 163 | while (i < source_len) { |
| 164 | char c = source[i]; |
| 165 | if (c == '/' && i + 1 < source_len && source[i + 1] == '/') { |
| 166 | i += 2; |
| 167 | for (;;) { |
| 168 | while (i < source_len && source[i] != '\n') { |
| 169 | i++; |
| 170 | } |
| 171 | if (i >= source_len) { |
| 172 | break; |
| 173 | } |
| 174 | // Line splice: a backslash right before the newline (allowing |
| 175 | // \r\n) means the comment continues on the next line. |
| 176 | int back = i - 1; |
| 177 | if (back >= 0 && source[back] == '\r') { |
| 178 | back--; |
| 179 | } |
| 180 | if (back >= 0 && source[back] == '\\') { |
| 181 | i++; // spliced: keep consuming inside the comment |
| 182 | continue; |
| 183 | } |
| 184 | i++; // real end-of-comment newline |
| 185 | break; |
| 186 | } |
| 187 | } else if (c == '/' && i + 1 < source_len && source[i + 1] == '*') { |
| 188 | i += 2; |
| 189 | while (i + 1 < source_len && !(source[i] == '*' && source[i + 1] == '/')) { |
| 190 | i++; |
| 191 | } |
| 192 | if (i + 1 < source_len) { |
| 193 | i += 2; // past the closing "*/" |
| 194 | } else { |
| 195 | i = source_len; // unterminated comment runs to EOF |
| 196 | } |
| 197 | } else if (c == '"' || c == '\'') { |
| 198 | char quote = c; |
| 199 | i++; |
| 200 | while (i < source_len) { |
| 201 | if (source[i] == '\\') { |
| 202 | i += 2; |
| 203 | continue; |
| 204 | } |
| 205 | if (source[i] == quote) { |
| 206 | i++; |
| 207 | break; |
| 208 | } |
| 209 | i++; |
| 210 | } |
| 211 | } else { |
| 212 | return i; |
| 213 | } |
| 214 | } |
| 215 | return i; |
| 216 | } |
| 217 | |
| 218 | // Count-only scan used by the early gate (no storage). |
| 219 | static bool has_export_macro_candidates(const char *source, int source_len) { |
no outgoing calls
no test coverage detected