| 1203 | } |
| 1204 | |
| 1205 | static bool tm_scan_source(cbm_test_model_t *m, const char *file, const char *text, size_t len, |
| 1206 | int language_kind) { |
| 1207 | if (!text) { |
| 1208 | text = ""; /* (NULL, 0) is empty input, never NULL pointer arithmetic */ |
| 1209 | } |
| 1210 | if (memchr(text, '\0', len)) { |
| 1211 | m->incomplete = true; |
| 1212 | } |
| 1213 | /* Translation-phase line splicing is followed where the lexer reads it |
| 1214 | * correctly (a directive's continuation lines, an escaped newline in a |
| 1215 | * literal); a splice it cannot follow (in plain code, or extending a line |
| 1216 | * comment) marks the file uncertain where it is met. */ |
| 1217 | tm_scan_t sc = {.m = m, .language_kind = language_kind, .ok = true}; |
| 1218 | int first_suite = m->suite_count; |
| 1219 | sc.file = cbm_arena_strdup(&m->arena, file); |
| 1220 | if (!sc.file) { |
| 1221 | m->incomplete = true; |
| 1222 | return false; |
| 1223 | } |
| 1224 | if (m->descriptor_mode) { |
| 1225 | tm_descriptor_preflight(&sc); |
| 1226 | if (!sc.ok) |
| 1227 | return false; |
| 1228 | if (!sc.language_kind) |
| 1229 | return true; /* preserve uncertainty; do not pretend to parse it */ |
| 1230 | } |
| 1231 | sc.lx = (tm_lex_t){ |
| 1232 | .p = text, .end = text + len, .line = 1, .line_start = true, .incomplete = &m->incomplete}; |
| 1233 | tm_tok_t tok; |
| 1234 | for (tm_next(&sc.lx, &tok); sc.ok && tok.kind != TM_TOK_EOF; tm_next(&sc.lx, &tok)) { |
| 1235 | if (sc.guard_closed) { |
| 1236 | m->incomplete = true; /* significant input after the supposed file guard */ |
| 1237 | } |
| 1238 | if (tok.kind == TM_TOK_DIRECTIVE) { |
| 1239 | tm_directive(&sc, &tok); |
| 1240 | } else if (tok.kind == TM_TOK_IDENT) { |
| 1241 | tm_ident(&sc, &tok); |
| 1242 | } else if (tok.ch == '{') { |
| 1243 | sc.depth++; |
| 1244 | } else if (tok.ch == '}') { |
| 1245 | tm_close_brace(&sc, tok.line); |
| 1246 | } |
| 1247 | sc.seen_token = true; |
| 1248 | } |
| 1249 | if (!sc.ok || sc.depth || sc.open != TM_OPEN_NONE || sc.cond_count) { |
| 1250 | m->incomplete = true; |
| 1251 | } |
| 1252 | if (sc.open == TM_OPEN_CASE) { |
| 1253 | m->cases[sc.open_index].end_line = sc.lx.line; /* body open at end of file */ |
| 1254 | } else if (sc.open == TM_OPEN_SUITE) { |
| 1255 | m->suites[sc.open_index].end_line = sc.lx.line; |
| 1256 | } |
| 1257 | for (int i = first_suite; sc.macro_registrations && i < m->suite_count; i++) { |
| 1258 | m->suites[i].macro_registrations = true; |
| 1259 | } |
| 1260 | return sc.ok; |
| 1261 | } |
| 1262 |
no test coverage detected