MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / build_line_map

Function build_line_map

internal/cbm/preprocessor.cpp:434–471  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

432}
433
434static bool build_line_map(const std::string &expanded, const std::string &main_file,
435 uint32_t *original_line_by_expanded_line,
436 uint8_t *belongs_to_main_file) {
437 std::string current_file = main_file;
438 uint32_t current_line = 1;
439 int expanded_line = 1;
440 size_t line_start = 0;
441
442 while (line_start <= expanded.size()) {
443 size_t line_end = expanded.find('\n', line_start);
444 if (line_end == std::string::npos) {
445 line_end = expanded.size();
446 }
447
448 uint32_t directive_line = 0;
449 std::string directive_file;
450 if (parse_line_directive(expanded.c_str() + line_start, line_end - line_start,
451 &directive_line, &directive_file)) {
452 current_file = directive_file;
453 current_line = directive_line;
454 original_line_by_expanded_line[expanded_line] = 0;
455 belongs_to_main_file[expanded_line] = 0;
456 } else {
457 original_line_by_expanded_line[expanded_line] = current_line;
458 belongs_to_main_file[expanded_line] = current_file == main_file ? 1 : 0;
459 if (current_line < UINT32_MAX) {
460 current_line++;
461 }
462 }
463
464 if (line_end == expanded.size()) {
465 break;
466 }
467 line_start = line_end + 1;
468 expanded_line++;
469 }
470 return true;
471}
472
473CBMPreprocessedSource *cbm_preprocess_with_map(const char *source, int source_len,
474 const char *filename, const char **extra_defines,

Callers 1

cbm_preprocess_with_mapFunction · 0.85

Calls 2

parse_line_directiveFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected