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

Function scope_frame_find

internal/cbm/lsp/scope.c:135–158  ·  view source on GitHub ↗

The binding of name in one frame: hashed when the frame has an index, * otherwise the linear chunk scan (small frames, or no index memory). */

Source from the content-addressed store, hash-verified

133/* The binding of name in one frame: hashed when the frame has an index,
134 * otherwise the linear chunk scan (small frames, or no index memory). */
135static CBMVarBinding *scope_frame_find(const CBMScope *scope, const char *name) {
136 if (scope->index.cap > 0) {
137 uint32_t mask = (uint32_t)scope->index.cap - 1;
138 for (uint32_t i = scope_name_hash(name) & mask;; i = (i + 1) & mask) {
139 CBMVarBinding *b = scope->index.slots[i];
140 if (!b) {
141 return NULL;
142 }
143 CBM_LSP_WORK(1);
144 if (strcmp(b->name, name) == 0) {
145 return b;
146 }
147 }
148 }
149 for (CBMScopeChunk *c = scope->chunks; c != NULL; c = c->next) {
150 for (int i = 0; i < c->used; i++) {
151 CBM_LSP_WORK(1);
152 if (c->bindings[i].name && strcmp(c->bindings[i].name, name) == 0) {
153 return &c->bindings[i];
154 }
155 }
156 }
157 return NULL;
158}
159
160/* Returns false when the binding could NOT be recorded in THIS frame.
161 *

Callers 3

cbm_scope_bind_valueFunction · 0.85
cbm_scope_lookup_localFunction · 0.85

Calls 1

scope_name_hashFunction · 0.85

Tested by

no test coverage detected