Files
Thomas Dyar 4d6f2dd34a feat(objectscript): add InterSystems IRIS ObjectScript language support
Add ObjectScript (InterSystems IRIS / Caché) as a supported language,
covering the UDL class format (.cls), MAC/INT routines (.mac/.int/.rtn),
include/macro files (.inc), and IRIS Studio Export XML.

Definition extraction (extract_defs.c): Class, Method, ClassMethod,
Property, Parameter, Index, Trigger (with body text), XData, Storage,
and Query members as graph nodes; base classes from the Extends clause.

Call dispatch resolution (extract_calls.c) — four ObjectScript patterns
that are structurally invisible to text search:
  1. ##class(Pkg.Class).Method()    explicit cross-class call
  2. ..Method()                     relative-dot self-call (the dominant
                                    intra-class form; large impact on
                                    CALLS completeness)
  3. $$$Macro                       macro expansion via a per-project
                                    table built from .inc files
  4. type inference from %New/%OpenId + declared return types

Ensemble production topology (pass_ensemble_routing.c): EnsembleItem
nodes per production component and ROUTES_TO edges resolved from
ProductionDefinition XData, plus WorkMgr .Queue("##class(X).method")
dispatch — all parsed statically at index time, no live IRIS required.

Language detection (language.c): .mac/.int/.rtn map to ObjectScript
routine directly; .cls (shared with Apex) and .inc (shared with BitBake)
are disambiguated by content, defaulting to the existing language on any
doubt so neither Apex nor BitBake detection regresses.

The two new per-project tables (macros, return types) are threaded
through a new internal cbm_extract_file_ex() so the public
cbm_extract_file() signature is unchanged.

The tree-sitter grammars for ObjectScript UDL and routine are vendored
in internal/cbm/vendored/grammars/objectscript_{udl,routine}/ from
https://github.com/intersystems/tree-sitter-objectscript (MIT, ABI 15).

Refs #462

Signed-off-by: Thomas Dyar <tdyar@intersystems.com>
2026-07-11 19:09:43 -04:00

48 lines
1.7 KiB
C

#pragma once
#include <stddef.h>
#include "arena.h"
#define CBM_MACRO_MAX_PARAMS 4
#define CBM_MACRO_TABLE_CAP 4096
typedef struct {
const char *name;
int param_count;
const char *param_names[CBM_MACRO_MAX_PARAMS];
const char *expansion;
const char *resolved_callee;
} CBMMacroEntry;
typedef struct CBMMacroTable {
CBMMacroEntry entries[CBM_MACRO_TABLE_CAP];
int count;
CBMArena arena;
} CBMMacroTable;
// Add an entry. Silently drops on overflow.
void cbm_macro_table_add(CBMMacroTable *t, CBMArena *arena, const char *name, int param_count,
const char **param_names, const char *expansion,
const char *resolved_callee);
// Look up by name. Returns NULL if not found.
const CBMMacroEntry *cbm_macro_table_find(const CBMMacroTable *t, const char *name);
// Parse a single .inc file content into the table (arena-allocated strings).
void cbm_parse_inc_file(CBMMacroTable *t, CBMArena *arena, const char *content);
// Expand a macro call: substitute args into expansion text.
// Returns arena-allocated expanded text, or NULL if no expansion.
char *cbm_macro_expand(CBMArena *arena, const CBMMacroEntry *entry, const char **args,
int arg_count);
// Extract a callee name from expanded text (looks for ##class(X).Method or $$Label^Routine).
// Returns arena-allocated "X.Method" or "Label^Routine", or NULL.
char *cbm_macro_extract_callee(CBMArena *arena, const char *expansion);
// Allocate and populate a new table with the hardcoded system macros.
// Caller owns the table (stack or heap).
void cbm_macro_table_init_system(CBMMacroTable *t);
// Destroy the arena inside t and free t itself. NULL-safe.
void cbm_macro_table_free(CBMMacroTable *t);