mirror of
https://github.com/DeusData/codebase-memory-mcp.git
synced 2026-12-04 04:37:20 +08:00
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>
70 lines
2.8 KiB
C
70 lines
2.8 KiB
C
#ifndef CBM_EXTRACT_UNIFIED_H
|
|
#define CBM_EXTRACT_UNIFIED_H
|
|
|
|
#include "cbm.h"
|
|
#include "lang_specs.h"
|
|
|
|
// Scope kinds for the walk state stack.
|
|
#define SCOPE_FUNC 1
|
|
#define SCOPE_CLASS 2
|
|
#define SCOPE_CALL 3
|
|
#define SCOPE_IMPORT 4
|
|
#define SCOPE_LOOP 5
|
|
#define SCOPE_BRANCH 6
|
|
|
|
#define MAX_SCOPES 64
|
|
|
|
// ObjectScript type map: variable name → class name (for instance_method_call
|
|
// resolution). Stack-allocated, per-method scope. Overflow is silent (no crash).
|
|
#define OS_TYPE_MAP_CAP 64
|
|
typedef struct {
|
|
const char *var_name;
|
|
const char *class_name;
|
|
} os_type_entry_t;
|
|
|
|
typedef struct {
|
|
os_type_entry_t entries[OS_TYPE_MAP_CAP];
|
|
int count;
|
|
int class_base_count; // entries [0,class_base_count) survive method-scope resets
|
|
} os_type_map_t;
|
|
|
|
// WalkState tracks scope context during the unified cursor walk.
|
|
// Replaces parent-chain walks for enclosing_func_qn, inside_call, etc.
|
|
typedef struct {
|
|
const char *enclosing_func_qn; // current function QN (module_qn at top level)
|
|
const char *enclosing_class_qn; // current class QN (NULL outside class)
|
|
bool inside_call; // within a call_node_types subtree
|
|
bool inside_import; // within an import_node_types subtree
|
|
int loop_depth; // count of enclosing loop scopes (for bottleneck metrics)
|
|
int branch_depth; // count of enclosing branch scopes
|
|
|
|
struct {
|
|
const char *qn;
|
|
uint32_t depth;
|
|
uint8_t kind;
|
|
} scopes[MAX_SCOPES];
|
|
int scope_top;
|
|
|
|
os_type_map_t os_type_map; // ObjectScript variable → type mapping
|
|
} WalkState;
|
|
|
|
// Per-node handler prototypes. Each is called once per node during the
|
|
// unified cursor walk, replacing the old recursive walk_* functions.
|
|
void handle_calls(CBMExtractCtx *ctx, TSNode node, const CBMLangSpec *spec, WalkState *state);
|
|
void handle_usages(CBMExtractCtx *ctx, TSNode node, const CBMLangSpec *spec, WalkState *state);
|
|
void handle_throws(CBMExtractCtx *ctx, TSNode node, const CBMLangSpec *spec, WalkState *state);
|
|
void handle_readwrites(CBMExtractCtx *ctx, TSNode node, const CBMLangSpec *spec, WalkState *state);
|
|
void handle_type_refs(CBMExtractCtx *ctx, TSNode node, const CBMLangSpec *spec, WalkState *state);
|
|
void handle_env_accesses(CBMExtractCtx *ctx, TSNode node, const CBMLangSpec *spec,
|
|
WalkState *state);
|
|
void handle_type_assigns(CBMExtractCtx *ctx, TSNode node, const CBMLangSpec *spec,
|
|
WalkState *state);
|
|
|
|
// Single-pass extraction using TSTreeCursor. Visits every node once,
|
|
// dispatching to all handlers per node. Replaces the 7 separate walk_*
|
|
// functions for calls/usages/throws/readwrites/type_refs/env_accesses/type_assigns.
|
|
// Definitions and imports stay as separate passes (different recursion patterns).
|
|
void cbm_extract_unified(CBMExtractCtx *ctx);
|
|
|
|
#endif // CBM_EXTRACT_UNIFIED_H
|