@@ -429,75 +429,6 @@ static int result_find_same_def_identity(const CBMFileResult *result, const CBMD
429429 return -1 ;
430430}
431431
432- static bool cbm_pp_directive_matches (const char * p , int len , const char * word ) {
433- int word_len = (int )strlen (word );
434- return len >= word_len && strncmp (p , word , (size_t )word_len ) == 0 &&
435- (len == word_len || !cbm_ident_char (p [word_len ]));
436- }
437-
438- static bool cbm_line_is_preprocessor_branch_directive (const char * line , int len ) {
439- int p = 0 ;
440- while (p < len && isspace ((unsigned char )line [p ])) {
441- p ++ ;
442- }
443- if (p >= len || line [p ++ ] != '#' ) {
444- return false;
445- }
446- while (p < len && isspace ((unsigned char )line [p ])) {
447- p ++ ;
448- }
449- int word_len = len - p ;
450- return cbm_pp_directive_matches (line + p , word_len , "if" ) ||
451- cbm_pp_directive_matches (line + p , word_len , "ifdef" ) ||
452- cbm_pp_directive_matches (line + p , word_len , "ifndef" ) ||
453- cbm_pp_directive_matches (line + p , word_len , "elif" ) ||
454- cbm_pp_directive_matches (line + p , word_len , "else" ) ||
455- cbm_pp_directive_matches (line + p , word_len , "endif" );
456- }
457-
458- static bool cbm_span_contains_preprocessor_branch (const char * source , int source_len ,
459- uint32_t start_line , uint32_t end_line ) {
460- int span_start = 0 ;
461- int span_end = 0 ;
462- if (!cbm_source_line_bounds (source , source_len , start_line , end_line , & span_start , & span_end )) {
463- return false;
464- }
465- int line_start = span_start ;
466- while (line_start <= span_end ) {
467- int line_end = line_start ;
468- while (line_end < span_end && source [line_end ] != '\n' ) {
469- line_end ++ ;
470- }
471- if (cbm_line_is_preprocessor_branch_directive (source + line_start , line_end - line_start )) {
472- return true;
473- }
474- if (line_end >= span_end ) {
475- break ;
476- }
477- line_start = line_end + 1 ;
478- }
479- return false;
480- }
481-
482- static bool cbm_should_replace_preprocessed_duplicate (const CBMDefinition * existing ,
483- const CBMDefinition * remapped ,
484- const char * source , int source_len ) {
485- if (!existing || !remapped || existing -> start_line == 0 || remapped -> start_line == 0 ) {
486- return false;
487- }
488- if (existing -> start_line == remapped -> start_line && existing -> end_line == remapped -> end_line ) {
489- return false;
490- }
491- uint32_t start =
492- existing -> start_line < remapped -> start_line ? existing -> start_line : remapped -> start_line ;
493- uint32_t existing_end =
494- existing -> end_line < existing -> start_line ? existing -> start_line : existing -> end_line ;
495- uint32_t remapped_end =
496- remapped -> end_line < remapped -> start_line ? remapped -> start_line : remapped -> end_line ;
497- uint32_t end = existing_end > remapped_end ? existing_end : remapped_end ;
498- return cbm_span_contains_preprocessor_branch (source , source_len , start , end );
499- }
500-
501432static void merge_missing_preprocessed_callables (CBMFileResult * dst , const CBMFileResult * src ,
502433 CBMArena * arena ,
503434 const CBMPreprocessedSource * preprocessed ,
@@ -520,16 +451,13 @@ static void merge_missing_preprocessed_callables(CBMFileResult *dst, const CBMFi
520451 original_source_len )) {
521452 continue ;
522453 }
454+ /* Successful expanded-source remaps are parse-coverage evidence. Raw
455+ * definitions remain primary; the final defs array is fill-only below. */
523456 if (!cbm_recovered_callables_push (arena , recovered , & remapped )) {
524457 continue ;
525458 }
526- int existing_idx = result_find_same_def_identity (dst , & remapped );
527- if (existing_idx < 0 ) {
459+ if (result_find_same_def_identity (dst , & remapped ) < 0 ) {
528460 cbm_defs_push (& dst -> defs , arena , remapped );
529- } else if (cbm_should_replace_preprocessed_duplicate (& dst -> defs .items [existing_idx ],
530- & remapped , original_source ,
531- original_source_len )) {
532- dst -> defs .items [existing_idx ] = remapped ;
533461 }
534462 }
535463}
0 commit comments