Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 57 additions & 56 deletions internal/cbm/extract_channels.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ static void scan_string_consts_js(CBMExtractCtx *ctx, chan_const_table_t *tbl) {

/* Python constant resolution: NAME = "value" (assignment node). */
static void scan_string_consts_python(CBMExtractCtx *ctx, chan_const_table_t *tbl) {
TSNode stack[CHAN_STACK_CAP];
int top = 0;
stack[top++] = ctx->root;
TSNodeStack stack;
ts_nstack_init(&stack, ctx->arena, CHAN_STACK_CAP);
ts_nstack_push(&stack, ctx->arena, ctx->root);

while (top > 0 && tbl->count < CHAN_CONST_CAP) {
TSNode node = stack[--top];
while (stack.count > 0 && tbl->count < CHAN_CONST_CAP) {
TSNode node = ts_nstack_pop(&stack);
const char *kind = ts_node_type(node);

if (strcmp(kind, "assignment") == 0) {
Expand All @@ -165,8 +165,8 @@ static void scan_string_consts_python(CBMExtractCtx *ctx, chan_const_table_t *tb
}

uint32_t count = ts_node_child_count(node);
for (int i = (int)count - SKIP_ONE; i >= 0 && top < CHAN_STACK_CAP; i--) {
stack[top++] = ts_node_child(node, (uint32_t)i);
for (int i = (int)count - SKIP_ONE; i >= 0; i--) {
ts_nstack_push(&stack, ctx->arena, ts_node_child(node, (uint32_t)i));
}
}
}
Expand Down Expand Up @@ -554,21 +554,21 @@ static void extract_channels_python(CBMExtractCtx *ctx) {
chan_const_table_t consts = {0};
scan_string_consts_python(ctx, &consts);

TSNode stack[CHAN_STACK_CAP];
int top = 0;
stack[top++] = ctx->root;
TSNodeStack stack;
ts_nstack_init(&stack, ctx->arena, CHAN_STACK_CAP);
ts_nstack_push(&stack, ctx->arena, ctx->root);

while (top > 0) {
TSNode node = stack[--top];
while (stack.count > 0) {
TSNode node = ts_nstack_pop(&stack);
const char *kind = ts_node_type(node);
if (strcmp(kind, "call") == 0) {
py_process_call(ctx, node, &consts);
} else if (strcmp(kind, "decorator") == 0) {
py_process_decorator(ctx, node, &consts);
}
uint32_t count = ts_node_child_count(node);
for (int i = (int)count - SKIP_ONE; i >= 0 && top < CHAN_STACK_CAP; i--) {
stack[top++] = ts_node_child(node, (uint32_t)i);
for (int i = (int)count - SKIP_ONE; i >= 0; i--) {
ts_nstack_push(&stack, ctx->arena, ts_node_child(node, (uint32_t)i));
}
}
}
Expand Down Expand Up @@ -632,18 +632,18 @@ static void go_process_call(CBMExtractCtx *ctx, TSNode call) {
}

static void extract_channels_go(CBMExtractCtx *ctx) {
TSNode stack[CHAN_STACK_CAP];
int top = 0;
stack[top++] = ctx->root;
TSNodeStack stack;
ts_nstack_init(&stack, ctx->arena, CHAN_STACK_CAP);
ts_nstack_push(&stack, ctx->arena, ctx->root);

while (top > 0) {
TSNode node = stack[--top];
while (stack.count > 0) {
TSNode node = ts_nstack_pop(&stack);
if (strcmp(ts_node_type(node), "call_expression") == 0) {
go_process_call(ctx, node);
}
uint32_t count = ts_node_child_count(node);
for (int i = (int)count - SKIP_ONE; i >= 0 && top < CHAN_STACK_CAP; i--) {
stack[top++] = ts_node_child(node, (uint32_t)i);
for (int i = (int)count - SKIP_ONE; i >= 0; i--) {
ts_nstack_push(&stack, ctx->arena, ts_node_child(node, (uint32_t)i));
}
}
}
Expand Down Expand Up @@ -729,21 +729,21 @@ static void java_process_annotation(CBMExtractCtx *ctx, TSNode annotation) {
}

static void extract_channels_java(CBMExtractCtx *ctx) {
TSNode stack[CHAN_STACK_CAP];
int top = 0;
stack[top++] = ctx->root;
TSNodeStack stack;
ts_nstack_init(&stack, ctx->arena, CHAN_STACK_CAP);
ts_nstack_push(&stack, ctx->arena, ctx->root);

while (top > 0) {
TSNode node = stack[--top];
while (stack.count > 0) {
TSNode node = ts_nstack_pop(&stack);
const char *kind = ts_node_type(node);
if (strcmp(kind, "method_invocation") == 0) {
java_process_call(ctx, node);
} else if (strcmp(kind, "marker_annotation") == 0 || strcmp(kind, "annotation") == 0) {
java_process_annotation(ctx, node);
}
uint32_t count = ts_node_child_count(node);
for (int i = (int)count - SKIP_ONE; i >= 0 && top < CHAN_STACK_CAP; i--) {
stack[top++] = ts_node_child(node, (uint32_t)i);
for (int i = (int)count - SKIP_ONE; i >= 0; i--) {
ts_nstack_push(&stack, ctx->arena, ts_node_child(node, (uint32_t)i));
}
}
}
Expand Down Expand Up @@ -798,18 +798,18 @@ static void csharp_process_call(CBMExtractCtx *ctx, TSNode call) {
}

static void extract_channels_csharp(CBMExtractCtx *ctx) {
TSNode stack[CHAN_STACK_CAP];
int top = 0;
stack[top++] = ctx->root;
TSNodeStack stack;
ts_nstack_init(&stack, ctx->arena, CHAN_STACK_CAP);
ts_nstack_push(&stack, ctx->arena, ctx->root);

while (top > 0) {
TSNode node = stack[--top];
while (stack.count > 0) {
TSNode node = ts_nstack_pop(&stack);
if (strcmp(ts_node_type(node), "invocation_expression") == 0) {
csharp_process_call(ctx, node);
}
uint32_t count = ts_node_child_count(node);
for (int i = (int)count - SKIP_ONE; i >= 0 && top < CHAN_STACK_CAP; i--) {
stack[top++] = ts_node_child(node, (uint32_t)i);
for (int i = (int)count - SKIP_ONE; i >= 0; i--) {
ts_nstack_push(&stack, ctx->arena, ts_node_child(node, (uint32_t)i));
}
}
}
Expand Down Expand Up @@ -861,18 +861,18 @@ static void ruby_process_call(CBMExtractCtx *ctx, TSNode call) {
}

static void extract_channels_ruby(CBMExtractCtx *ctx) {
TSNode stack[CHAN_STACK_CAP];
int top = 0;
stack[top++] = ctx->root;
TSNodeStack stack;
ts_nstack_init(&stack, ctx->arena, CHAN_STACK_CAP);
ts_nstack_push(&stack, ctx->arena, ctx->root);

while (top > 0) {
TSNode node = stack[--top];
while (stack.count > 0) {
TSNode node = ts_nstack_pop(&stack);
if (strcmp(ts_node_type(node), "call") == 0) {
ruby_process_call(ctx, node);
}
uint32_t count = ts_node_child_count(node);
for (int i = (int)count - SKIP_ONE; i >= 0 && top < CHAN_STACK_CAP; i--) {
stack[top++] = ts_node_child(node, (uint32_t)i);
for (int i = (int)count - SKIP_ONE; i >= 0; i--) {
ts_nstack_push(&stack, ctx->arena, ts_node_child(node, (uint32_t)i));
}
}
}
Expand Down Expand Up @@ -963,21 +963,21 @@ static void elixir_process_function_def(CBMExtractCtx *ctx, TSNode func_def) {
}

static void extract_channels_elixir(CBMExtractCtx *ctx) {
TSNode stack[CHAN_STACK_CAP];
int top = 0;
stack[top++] = ctx->root;
TSNodeStack stack;
ts_nstack_init(&stack, ctx->arena, CHAN_STACK_CAP);
ts_nstack_push(&stack, ctx->arena, ctx->root);

while (top > 0) {
TSNode node = stack[--top];
while (stack.count > 0) {
TSNode node = ts_nstack_pop(&stack);
const char *kind = ts_node_type(node);
if (strcmp(kind, "call") == 0) {
elixir_process_call(ctx, node);
} else if (strcmp(kind, "def") == 0) {
elixir_process_function_def(ctx, node);
}
uint32_t count = ts_node_child_count(node);
for (int i = (int)count - SKIP_ONE; i >= 0 && top < CHAN_STACK_CAP; i--) {
stack[top++] = ts_node_child(node, (uint32_t)i);
for (int i = (int)count - SKIP_ONE; i >= 0; i--) {
ts_nstack_push(&stack, ctx->arena, ts_node_child(node, (uint32_t)i));
}
}
}
Expand Down Expand Up @@ -1039,18 +1039,18 @@ static void rust_process_call(CBMExtractCtx *ctx, TSNode call) {
}

static void extract_channels_rust(CBMExtractCtx *ctx) {
TSNode stack[CHAN_STACK_CAP];
int top = 0;
stack[top++] = ctx->root;
TSNodeStack stack;
ts_nstack_init(&stack, ctx->arena, CHAN_STACK_CAP);
ts_nstack_push(&stack, ctx->arena, ctx->root);

while (top > 0) {
TSNode node = stack[--top];
while (stack.count > 0) {
TSNode node = ts_nstack_pop(&stack);
if (strcmp(ts_node_type(node), "call_expression") == 0) {
rust_process_call(ctx, node);
}
uint32_t count = ts_node_child_count(node);
for (int i = (int)count - SKIP_ONE; i >= 0 && top < CHAN_STACK_CAP; i--) {
stack[top++] = ts_node_child(node, (uint32_t)i);
for (int i = (int)count - SKIP_ONE; i >= 0; i--) {
ts_nstack_push(&stack, ctx->arena, ts_node_child(node, (uint32_t)i));
}
}
}
Expand Down Expand Up @@ -1092,3 +1092,4 @@ void cbm_extract_channels(CBMExtractCtx *ctx) {
break; /* no channel detection for this language */
}
}