Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion THIRD_PARTY.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ License summary:
- **License:** MIT
- **Copyright:** (c) 2025 InterSystems Corporation
- **Vendored at:** `internal/cbm/vendored/grammars/objectscript_udl/`, `internal/cbm/vendored/grammars/objectscript_routine/`
- **Pinned commit:** `a7ffcdf`
- **Pinned commit:** `48a06b6` (v1.9.19)
- **Notes:** InterSystems-maintained grammar for the ObjectScript language (InterSystems IRIS / Caché). Vendor-maintained; not in nvim-treesitter or Helix registries. Each `scanner.c`'s upstream `#include "../../common/scanner.h"` is repointed to a per-directory `objectscript_common.h` copied from upstream `common/scanner.h`; two loop counters in that copy are widened from `uint8_t` to `int` as documented in `internal/cbm/vendored/grammars/MANIFEST.md`.

## Vendored C/C++ Libraries
Expand Down
35 changes: 25 additions & 10 deletions internal/cbm/extract_calls.c
Original file line number Diff line number Diff line change
Expand Up @@ -1494,6 +1494,21 @@ static char *extract_puppet_callee(CBMArena *a, TSNode node, const char *source,
return NULL;
}

/* Callee container of a routine_tag_call / extrinsic_function. Older routine
* grammars always wrapped the target in line_ref. Newer ones emit a bare
* label as method_name (`Do accept`) and a bare routine as routine_ref
* (`$$^Other`). All three have the same source text. */
static TSNode objectscript_routine_callee_container(TSNode node) {
static const char *const kinds[] = {"line_ref", "method_name", "routine_ref", NULL};
for (int i = 0; kinds[i]; i++) {
TSNode child = cbm_find_child_by_kind(node, kinds[i]);
if (!ts_node_is_null(child)) {
return child;
}
}
return (TSNode){0};
}

static char *extract_callee_lang_specific(CBMArena *a, TSNode node, const char *source,
CBMLanguage lang) {
const char *nk = ts_node_type(node);
Expand Down Expand Up @@ -1699,13 +1714,13 @@ static char *extract_callee_lang_specific(CBMArena *a, TSNode node, const char *
}
return NULL;
}
// $$label^routine extrinsic / routine tag call -> the line_ref text.
// The routine grammar keeps the leading `$$` as an unnamed token, so
// both call forms have the same exact named callee container.
// $$label^routine extrinsic / routine tag call -> the callee container
// text. The routine grammar keeps the leading `$$` as an unnamed token,
// so both call forms have the same exact named callee container.
if (strcmp(nk, "extrinsic_function") == 0 || strcmp(nk, "routine_tag_call") == 0) {
TSNode line_ref = cbm_find_child_by_kind(node, "line_ref");
if (!ts_node_is_null(line_ref)) {
return cbm_node_text(a, line_ref, source);
TSNode callee = objectscript_routine_callee_container(node);
if (!ts_node_is_null(callee)) {
return cbm_node_text(a, callee, source);
}
return NULL;
}
Expand Down Expand Up @@ -3825,7 +3840,7 @@ static const char *resolve_objectscript_callee(CBMExtractCtx *ctx, TSNode node,
}

const char *kind = ts_node_type(node);
if ((!callee || !callee[0]) && strcmp(kind, "method_call") == 0) {
if ((!callee || !callee[0]) && cbm_objectscript_is_instance_call(node)) {
callee =
resolve_objectscript_instance_call(ctx->arena, node, ctx->source, &state->os_type_map);
}
Expand Down Expand Up @@ -4092,12 +4107,12 @@ static TSNode objectscript_callee_expr(TSNode node) {
if (strcmp(kind, "class_method_call") == 0) {
return cbm_find_child_by_kind(node, "method_name");
}
if (strcmp(kind, "method_call") == 0 || strcmp(kind, "relative_dot_method") == 0) {
if (cbm_objectscript_is_instance_call(node) || strcmp(kind, "relative_dot_method") == 0) {
TSNode oref = cbm_find_child_by_kind(node, "oref_method");
return ts_node_is_null(oref) ? (TSNode){0} : cbm_find_child_by_kind(oref, "method_name");
}
if (strcmp(kind, "extrinsic_function") == 0 || strcmp(kind, "routine_tag_call") == 0) {
return cbm_find_child_by_kind(node, "line_ref");
return objectscript_routine_callee_container(node);
}
return (TSNode){0};
}
Expand Down Expand Up @@ -4427,7 +4442,7 @@ CBMInvocationDescriptor handle_calls(CBMExtractCtx *ctx, TSNode node, const CBML
}

if (!callable_reference && spec->call_node_types && spec->call_node_types[0] &&
cbm_kind_in_set(node, spec->call_node_types)) {
cbm_is_call_site(ctx->language, node, spec->call_node_types)) {
CBMPrimaryCalleeSelection callee = select_primary_callee(ctx, node, state);
// Keyword-filter callees, but keep builtins we mint a node for (len, str,
// ...) so the LSP-resolved builtin call still forms a CALLS edge.
Expand Down
30 changes: 28 additions & 2 deletions internal/cbm/extract_defs.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@ static bool try_append_ident(const char *source, uint32_t s, int len, uint32_t *
* contract; the pending stack is not — BT_STACK is only the on-stack first
* chunk and spills to the heap, because a full fixed stack dropped a wide
* body's FIRST children and sampled a mid-body window instead.
* Subtrees ending at or before from_byte are skipped (0 = whole body).
* Returns arena-allocated string, or NULL when there are no identifiers or the
* stack could not be grown (logged; no truncated sample is ever returned). */
static char *extract_body_ident_tokens(CBMExtractCtx *ctx, TSNode body) {
static char *extract_ident_tokens_from(CBMExtractCtx *ctx, TSNode body, uint32_t from_byte) {
enum { BT_STACK = 512, BT_BUF = 2048, BT_MAX_IDENTS = 128, BT_SEEN = 256, BT_SEEN_MASK = 255 };
TSNode bt_inline[BT_STACK];
TSNode *bt_stack = bt_inline;
Expand All @@ -116,6 +117,9 @@ static char *extract_body_ident_tokens(CBMExtractCtx *ctx, TSNode body) {

while (bt_top > 0 && bt_count < BT_MAX_IDENTS) {
TSNode nd = bt_stack[--bt_top];
if (ts_node_end_byte(nd) <= from_byte) {
continue;
}
uint32_t nc = ts_node_child_count(nd);
if (nc == 0) {
const char *k = ts_node_type(nd);
Expand Down Expand Up @@ -153,6 +157,10 @@ static char *extract_body_ident_tokens(CBMExtractCtx *ctx, TSNode body) {
return NULL;
}

static char *extract_body_ident_tokens(CBMExtractCtx *ctx, TSNode body) {
return extract_ident_tokens_from(ctx, body, 0);
}

/* Compute MinHash fingerprint for a function body node and store in def.
* Sets def->fingerprint (arena-allocated) and def->fingerprint_k on success,
* leaves them NULL/0 if the body is too short. */
Expand Down Expand Up @@ -11194,6 +11202,10 @@ static void extract_class_fields(CBMExtractCtx *ctx, TSNode class_node, const ch

if (strcmp(member_label, "Storage") == 0) {
TSNode sbody = cbm_find_child_by_kind(child, "storage_body");
if (ts_node_is_null(sbody)) {
sbody =
cbm_find_child_by_kind(child, "external_method_body_content");
}
if (!ts_node_is_null(sbody)) {
char *xml = cbm_node_text(a, sbody, ctx->source);
if (xml) {
Expand Down Expand Up @@ -11295,13 +11307,27 @@ static void extract_class_fields(CBMExtractCtx *ctx, TSNode class_node, const ch
}

if (strcmp(member_label, "Trigger") == 0) {
/* Grammar v1.9.15+ hides the core_trigger /
* external_trigger wrapper; the body is then
* everything after trigger_name. */
TSNode tbody = cbm_find_child_by_kind(child, "core_trigger");
if (ts_node_is_null(tbody)) {
tbody = cbm_find_child_by_kind(child, "external_trigger");
}
uint32_t body_from = 0;
if (ts_node_is_null(tbody)) {
tbody = child;
body_from = ts_node_end_byte(nname);
}
if (!ts_node_is_null(tbody)) {
mdef.body_tokens = extract_body_ident_tokens(ctx, tbody);
mdef.body_tokens = extract_ident_tokens_from(ctx, tbody, body_from);
char *raw = cbm_node_text(a, tbody, ctx->source);
if (raw && body_from > ts_node_start_byte(tbody)) {
raw += body_from - ts_node_start_byte(tbody);
while (*raw == ' ' || *raw == '\t') {
raw++;
}
}
if (raw && raw[0]) {
char esc[CBM_SZ_512];
int ei = 0;
Expand Down
2 changes: 1 addition & 1 deletion internal/cbm/extract_usages.c
Original file line number Diff line number Diff line change
Expand Up @@ -2597,7 +2597,7 @@ static void walk_usages(CBMExtractCtx *ctx, TSNode root, const CBMLangSpec *spec
UsageFrame *f = &frames[top - 1];
if (entering) {
try_emit_usage(ctx, f->node, spec, call_depth > 0, import_depth > 0);
f->counts_call = cbm_kind_in_set(f->node, spec->call_node_types);
f->counts_call = cbm_is_call_site(ctx->language, f->node, spec->call_node_types);
f->counts_import =
(has_imports && cbm_kind_in_set(f->node, spec->import_node_types)) ||
(has_from_imports && cbm_kind_in_set(f->node, spec->import_from_types));
Expand Down
18 changes: 18 additions & 0 deletions internal/cbm/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,24 @@ TSNode cbm_find_child_by_kind(TSNode parent, const char *kind) {
return null_node;
}

bool cbm_objectscript_is_instance_call(TSNode node) {
const char *kind = ts_node_type(node);
if (strcmp(kind, "method_call") == 0) {
return true;
}
if (strcmp(kind, "do_parameter") != 0 && strcmp(kind, "job_argument") != 0) {
return false;
}
return !ts_node_is_null(cbm_find_child_by_kind(node, "oref_method"));
}

bool cbm_is_call_site(CBMLanguage lang, TSNode node, const char **call_types) {
if (cbm_kind_in_set(node, call_types)) {
return true;
}
return lang == CBM_LANG_OBJECTSCRIPT_UDL && cbm_objectscript_is_instance_call(node);
}

int cbm_find_children_by_kind(TSNode parent, const char *kind, TSNode *out, int max) {
int n = 0;
uint32_t count = ts_node_child_count(parent);
Expand Down
11 changes: 11 additions & 0 deletions internal/cbm/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ char *cbm_go_receiver_type_name(CBMArena *a, TSNode recv, const char *source);
// Find a child node by kind string.
TSNode cbm_find_child_by_kind(TSNode parent, const char *kind);

// ObjectScript `Do obj.M()` / `Job obj.M()`: grammar v1.9.15+ hides the old
// `method_call` wrapper, so its receiver and `oref_method` sit directly under
// `do_parameter` / `job_argument`. True for `method_call` itself or for one of
// those parents carrying a direct `oref_method` child.
bool cbm_objectscript_is_instance_call(TSNode node);

// Find every child node matching `kind` (unlike cbm_find_child_by_kind,
// which stops at the first match). Writes up to `max` nodes into `out`;
// returns how many were found. Repeated sibling nodes of the same kind are
Expand Down Expand Up @@ -222,6 +228,11 @@ bool cbm_chialisp_is_def_head(const char *t);
// Check if node kind matches a set of types (NULL-terminated array of strings).
bool cbm_kind_in_set(TSNode node, const char **types);

// cbm_kind_in_set over a language's call_node_types, plus the ObjectScript UDL
// `Do obj.M()` sites that no longer have a dedicated node kind (see
// cbm_objectscript_is_instance_call).
bool cbm_is_call_site(CBMLanguage lang, TSNode node, const char **call_types);

/* Namespace/module declarations that extend a qualified-name scope without
* turning their children into class methods. Shared by definition and unified
* walks so TS/TSX scope attribution cannot drift. */
Expand Down
7 changes: 5 additions & 2 deletions internal/cbm/lang_specs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1695,8 +1695,11 @@ static const char *objectscript_udl_func_types[] = {"method", "classmethod", "qu
static const char *objectscript_udl_class_types[] = {"class_definition", NULL};
static const char *objectscript_udl_field_types[] = {
"property", "parameter", "index", "trigger", "xdata", "storage", "foreignkey", NULL};
static const char *objectscript_udl_call_types[] = {"class_method_call", "method_call",
"relative_dot_method", "macro", NULL};
/* Instance calls (`Do obj.M()`) have no call node of their own: the grammar
* hides method_call, leaving do_parameter/job_argument with an oref_method
* child. cbm_is_call_site() matches those via cbm_objectscript_is_instance_call. */
static const char *objectscript_udl_call_types[] = {"class_method_call", "relative_dot_method",
"macro", NULL};
static const char *objectscript_udl_module_types[] = {"source_file", NULL};
/* Branching nodes for cyclomatic complexity (verified against grammar node-types) */
static const char *objectscript_udl_branch_types[] = {
Expand Down
Loading
Loading