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

Function cpp_line_kind

internal/cbm/cpp_branch_views.c:23–50  ·  view source on GitHub ↗

Classify the line at src[pos..end): a conditional directive is a '#' in column 0, optional blanks, then the directive word — the same lines the Haskell scanner treats as conditionals.

Source from the content-addressed store, hash-verified

21// column 0, optional blanks, then the directive word — the same lines the
22// Haskell scanner treats as conditionals.
23static int cpp_line_kind(const char *src, int pos, int end) {
24 if (pos >= end || src[pos] != '#') {
25 return CPP_LINE_CODE;
26 }
27 int p = pos + 1;
28 while (p < end && (src[p] == ' ' || src[p] == '\t')) {
29 p++;
30 }
31 int w = p;
32 while (w < end && cpp_word_char(src[w])) {
33 w++;
34 }
35 static const struct {
36 const char *word;
37 int kind;
38 } words[] = {
39 {"if", CPP_LINE_START}, {"ifdef", CPP_LINE_START}, {"ifndef", CPP_LINE_START},
40 {"else", CPP_LINE_ELSE}, {"elif", CPP_LINE_ELSE}, {"elifdef", CPP_LINE_ELSE},
41 {"elifndef", CPP_LINE_ELSE}, {"endif", CPP_LINE_END},
42 };
43 size_t n = (size_t)(w - p);
44 for (size_t i = 0; i < sizeof(words) / sizeof(words[0]); i++) {
45 if (strlen(words[i].word) == n && memcmp(src + p, words[i].word, n) == 0) {
46 return words[i].kind;
47 }
48 }
49 return CPP_LINE_CODE;
50}
51
52static int cpp_line_end(const char *src, int pos, int len) {
53 const char *nl = memchr(src + pos, '\n', (size_t)(len - pos));

Callers 2

cpp_group_branchesFunction · 0.85
cbm_cpp_branch_viewFunction · 0.85

Calls 1

cpp_word_charFunction · 0.85

Tested by

no test coverage detected