diff --git a/README.md b/README.md index fbe8dff699..47f1abc0eb 100644 --- a/README.md +++ b/README.md @@ -1139,7 +1139,7 @@ The result is a knowledge graph accurate enough to drive `trace_path` across pac | **Good** (75-89%) | | Python, TypeScript, TSX, Go, Rust, Java, R, Dart, JavaScript, Erlang, Elixir, Scala, Ruby, PHP, C#, SQL | | **Functional** (< 75%) | | OCaml, Haskell | -Also supported (not yet benchmarked): Ada, Agda, Apex, ArkTS, Assembly (NASM), Astro, AWK, Beancount, BibTeX, Bicep, Bitbake, Blade, Cairo, Cap'n Proto, CFML, CFScript, Chialisp, Clojure, CMake, COBOL, Common Lisp, Crystal, CSV, CUDA, D, Devicetree, Diff, .env, Elm, Emacs Lisp, F#, Fennel, Fish, FORM, Fortran, FunC, GDScript, .gitattributes, .gitignore, Gleam, GLSL, GN, Go module, Go template, GraphQL, Hare, HLSL, Hyprlang, INI, ISPC, Janet, Jinja2, JSDoc, JSON, JSON5, Jsonnet, Julia, Just, Kconfig, KDL, Lean 4, Linker Script, Liquid, LLVM IR, Luau, Magma, Makefile, Markdown, MATLAB, Mermaid, Meson, Mojo, Move, Nickel, Nix, ObjectScript (UDL and routines), Odin, Pascal, Pine Script, Pkl, PL/SQL, PO (gettext), Pony, PowerShell, Prisma, .properties, Protobuf, Puppet, PureScript, QML, Racket, Regex, requirements.txt, ReScript, RON, reStructuredText, Scheme, Slang, Smali, Smithy, Solidity, SOQL, SOSL, Squirrel, SSH config, Starlark, Svelte, Sway, SystemVerilog, TableGen, Tcl, Teal, Templ, Thrift, TLA+, Typst, Verilog, VHDL, Vim script, Vue, WGSL, WIT, Wolfram, XML, Zsh. +Also supported (not yet benchmarked): Ada, Agda, Apex, ArkTS, Assembly (NASM), Astro, AWK, Beancount, BibTeX, Bicep, Bitbake, Blade, Cairo, Cap'n Proto, CFML, CFScript, Chialisp, Clojure, CMake, COBOL, Common Lisp, Crystal, CSV, CUDA, D, Devicetree, Diff, .env, Elm, Emacs Lisp, F#, Fennel, Fish, FORM, Fortran, FunC, GDScript, .gitattributes, .gitignore, Gleam, GLSL, GN, Go module, Go template, GraphQL, Hare, HLSL, Hyprlang, INI, ISPC, Janet, Jinja2, JSDoc, JSON, JSON5, Jsonnet, Julia, Just, Kconfig, KDL, Lean 4, Linker Script, Liquid, LLVM IR, Luau, Magma, Makefile, Markdown, MATLAB, Mermaid, Meson, Mojo, Move, Nickel, Nix, ObjectScript (UDL and routines), Odin, Pascal, Pine Script, Pkl, PL/SQL, PO (gettext), Pony, PowerShell, Prisma, .properties, Protobuf, Puppet, PureScript, QML, Racket, Regex, requirements.txt, ReScript, RON, reStructuredText, Scheme, Slang, Smali, Smithy, Solidity, SOQL, SOSL, Squirrel, SSH config, Starlark, Svelte, Sway, SystemVerilog, TableGen, Tcl, Teal, Templ, Thrift, TLA+, Typst, VB.NET, Verilog, VHDL, Vim script, Vue, WGSL, WIT, Wolfram, XML, Zsh. ## Architecture diff --git a/internal/cbm/cbm.h b/internal/cbm/cbm.h index de1cc03f92..b4f7431560 100644 --- a/internal/cbm/cbm.h +++ b/internal/cbm/cbm.h @@ -206,15 +206,16 @@ typedef enum { CBM_LANG_OBJECTSCRIPT_UDL, // InterSystems ObjectScript UDL (.cls class files) CBM_LANG_OBJECTSCRIPT_ROUTINE, // InterSystems ObjectScript routine (.mac/.int/.rtn/.inc) CBM_LANG_OBJECTSCRIPT_EXPORT, // InterSystems Studio Export XML () - CBM_LANG_ARKTS, // ArkTS (HarmonyOS/OpenHarmony .ets — TypeScript superset + ArkUI) - CBM_LANG_PLSQL, // Oracle PL/SQL - CBM_LANG_CHIALISP, // Chialisp (.clsp/.clib/.clinc — Chia smart-coin s-expression language) - CBM_LANG_PDF, // PDF documents: the text layer, read without a grammar (doc_pdf.c) - CBM_LANG_ASCIIDOC, // AsciiDoc documents, read without a grammar (doc_adoc.c) - CBM_LANG_OPENAPI, // openapi.json / swagger.json: the JSON grammar, no node per key; their - // operations are Routes (openapi.c) - CBM_LANG_DIAGRAM, // diagram files (PlantUML, DOT, D2, draw.io, Excalidraw), read - // without a grammar (diagram.c) + CBM_LANG_ARKTS, // ArkTS (HarmonyOS/OpenHarmony .ets — TypeScript superset + ArkUI) + CBM_LANG_PLSQL, // Oracle PL/SQL + CBM_LANG_CHIALISP, // Chialisp (.clsp/.clib/.clinc — Chia smart-coin s-expression language) + CBM_LANG_PDF, // PDF documents: the text layer, read without a grammar (doc_pdf.c) + CBM_LANG_ASCIIDOC, // AsciiDoc documents, read without a grammar (doc_adoc.c) + CBM_LANG_OPENAPI, // openapi.json / swagger.json: the JSON grammar, no node per key; their + // operations are Routes (openapi.c) + CBM_LANG_DIAGRAM, // diagram files (PlantUML, DOT, D2, draw.io, Excalidraw), read + // without a grammar (diagram.c) + CBM_LANG_VISUALBASIC, // VB.NET (.vb — WinForms, class libraries) CBM_LANG_COUNT } CBMLanguage; diff --git a/internal/cbm/extract_calls.c b/internal/cbm/extract_calls.c index ad73a764d0..a5e20daa82 100644 --- a/internal/cbm/extract_calls.c +++ b/internal/cbm/extract_calls.c @@ -1603,6 +1603,127 @@ static char *extract_puppet_callee(CBMArena *a, TSNode node, const char *source, return NULL; } +/* VB.NET `New A.B.C(...)`: the grammar parses `New A` as a complete + * object_creation_expression (no argument list, no initializer) and `.B.C` as + * member accesses on it, so the enclosing invocation or indexing node is the + * real constructor call. True for that incomplete `New A` when a member access + * follows it; `New Foo().Bar()` creates a Foo and calls Bar, and `As New Foo` + * without parentheses constructs a Foo. + * + * The member access is recognised by the '.' after the node (blanks aside), + * not by ts_node_parent: that descends from the root, scanning siblings at + * every level, once per `New` in a WinForms InitializeComponent that holds + * thousands of them. Bytes are read only below the parsed tree's end minus + * one, which stays inside the source even when the parser was served an + * absent final newline (#2078). */ +static bool vb_new_is_chain_prefix(TSNode creation, const char *source) { + TSNode ty = ts_node_child_by_field_name(creation, TS_FIELD("type")); + if (ts_node_is_null(ty) || strcmp(ts_node_type(ty), "array_type") == 0 || + !ts_node_is_null(ts_node_child_by_field_name(creation, TS_FIELD("arguments"))) || + !ts_node_is_null(ts_node_child_by_field_name(creation, TS_FIELD("initializer")))) { + return false; + } + uint32_t limit = ts_node_end_byte(ts_tree_root_node(creation.tree)); + for (uint32_t i = ts_node_end_byte(creation); i + SKIP_ONE < limit; i++) { + if (source[i] != ' ' && source[i] != '\t') { + return source[i] == '.'; + } + } + return false; +} + +/* The constructed type of a `New A.B.C` chain prefix (vb_new_is_chain_prefix) + * that no call encloses: `sb = New Text.StringBuilder` has no argument list, + * so no invocation or indexing node names the type. NULL when the dotted run + * is followed by '(' -- the enclosing call names it then (vb_callee). */ +static char *vb_new_chain_without_call(CBMArena *a, TSNode creation, const char *source) { + TSNode ty = ts_node_child_by_field_name(creation, TS_FIELD("type")); + uint32_t start = ts_node_start_byte(ty); + uint32_t limit = ts_node_end_byte(ts_tree_root_node(creation.tree)); + uint32_t end = start; + while (end + SKIP_ONE < limit) { + unsigned char c = (unsigned char)source[end]; + bool name_char = c == '_' || c == '.' || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || + (c >= '0' && c <= '9'); + if (!name_char) { + break; + } + end++; + } + if (end == start || (end + SKIP_ONE < limit && source[end] == '(')) { + return NULL; + } + return cbm_arena_strndup(a, source + start, (size_t)(end - start)); +} + +/* Type name text with generic and array suffixes cut (`List(Of T)` -> "List"). */ +static char *vb_strip_type_suffix(char *text) { + if (!text) { + return NULL; + } + char *paren = strchr(text, '('); + if (paren) { + *paren = '\0'; + } + return text[0] ? text : NULL; +} + +/* VB.NET callee text for a call node (vb_call_types in lang_specs.c), NULL + * when the node names no callee. + * - invocation_expression `F()` names it in `function`, and + * array_access_expression `F(x)` in `array`: VB writes calls and indexing + * alike, and the grammar reads a call with arguments as indexing. + * - `Me.X()` / `MyClass.X()` are self-calls: the member name resolves like a + * bare same-class call. The receiver is matched by node kind, so its + * spelling (`me.`, `ME.`) does not matter in a case-insensitive language. + * - object_creation_expression names the constructed type; an empty argument + * list reads as an array rank (`New Customer()`), so an array_type there is + * the type's element_type. See vb_new_is_chain_prefix for `New A.B.C()`. */ +static char *vb_callee(CBMArena *a, TSNode node, const char *source, const char *nk) { + if (strcmp(nk, "object_creation_expression") == 0) { + if (vb_new_is_chain_prefix(node, source)) { + return vb_new_chain_without_call(a, node, source); + } + TSNode ty = ts_node_child_by_field_name(node, TS_FIELD("type")); + if (!ts_node_is_null(ty) && strcmp(ts_node_type(ty), "array_type") == 0) { + ty = ts_node_child_by_field_name(ty, TS_FIELD("element_type")); + } + return ts_node_is_null(ty) ? NULL : vb_strip_type_suffix(cbm_node_text(a, ty, source)); + } + TSNode callee = strcmp(nk, "invocation_expression") == 0 + ? ts_node_child_by_field_name(node, TS_FIELD("function")) + : ts_node_child_by_field_name(node, TS_FIELD("array")); + if (ts_node_is_null(callee)) { + return NULL; + } + if (strcmp(ts_node_type(callee), "member_access_expression") == 0) { + TSNode obj = ts_node_child_by_field_name(callee, TS_FIELD("object")); + const char *ok = ts_node_is_null(obj) ? "" : ts_node_type(obj); + if (strcmp(ok, "me_expression") == 0 || strcmp(ok, "myclass_expression") == 0) { + TSNode member = ts_node_child_by_field_name(callee, TS_FIELD("member")); + return ts_node_is_null(member) ? NULL : cbm_node_text(a, member, source); + } + /* Walk the access chain to its root; `New A` there makes this call + * the constructor of A.B.C, spelled from the type to the chain end. */ + TSNode root = obj; + while (!ts_node_is_null(root) && + strcmp(ts_node_type(root), "member_access_expression") == 0) { + root = ts_node_child_by_field_name(root, TS_FIELD("object")); + } + if (!ts_node_is_null(root) && + strcmp(ts_node_type(root), "object_creation_expression") == 0 && + vb_new_is_chain_prefix(root, source)) { + TSNode ty = ts_node_child_by_field_name(root, TS_FIELD("type")); + uint32_t start = ts_node_start_byte(ty); + uint32_t end = ts_node_end_byte(callee); + return end > start ? vb_strip_type_suffix( + cbm_arena_strndup(a, source + start, (size_t)(end - start))) + : NULL; + } + } + return cbm_node_text(a, callee, source); +} + static char *extract_callee_lang_specific(CBMArena *a, TSNode node, const char *source, CBMLanguage lang) { const char *nk = ts_node_type(node); @@ -2550,6 +2671,14 @@ static char *extract_callee_name(CBMArena *a, TSNode node, const char *source, C return extract_pkl_callee(a, node, source, ts_node_type(node)); } + /* VB.NET: resolve here and return unconditionally, like Pkl. The generic + * constructor path would name `New System.Windows.Forms.Button()` after + * its misparsed `New System` prefix, and the first-identifier fallback + * would turn indexing into calls of anything. NULL means "not a call". */ + if (lang == CBM_LANG_VISUALBASIC) { + return vb_callee(a, node, source, ts_node_type(node)); + } + // Helm / Go templates: resolve `include "x"` / `template "x"` to the // referenced named template so it links to the define'd Function (#338). if (lang == CBM_LANG_GOTEMPLATE) { diff --git a/internal/cbm/extract_defs.c b/internal/cbm/extract_defs.c index 85e159d971..a68c31f56b 100644 --- a/internal/cbm/extract_defs.c +++ b/internal/cbm/extract_defs.c @@ -4756,6 +4756,52 @@ static const char **extract_base_classes(CBMArena *a, TSNode node, const char *s } return NULL; } + // VB.NET: `Inherits A` / `Implements I1, I2` statements are children of the + // class/interface/structure declaration, next to its members (the grammar + // has no body wrapper), and each statement's named children are the base + // type names (simple_name / qualified_name / generic_name). Generic + // `(Of T)` suffixes are stripped like the '<' strip elsewhere. A cursor + // walks the declaration's children: a WinForms class holds thousands of + // members, and indexed child access is O(i) per call. + if (lang == CBM_LANG_VISUALBASIC) { + const char *bases[MAX_BASES]; + int base_count = 0; + TSTreeCursor cur = ts_tree_cursor_new(node); + bool more = ts_tree_cursor_goto_first_child(&cur); + while (more && base_count < MAX_BASES_MINUS_1) { + TSNode clause = ts_tree_cursor_current_node(&cur); + more = ts_tree_cursor_goto_next_sibling(&cur); + const char *ck = ts_node_type(clause); + if (strcmp(ck, "inherits_statement") != 0 && strcmp(ck, "implements_statement") != 0) { + continue; + } + uint32_t tc = ts_node_named_child_count(clause); + for (uint32_t j = 0; j < tc && base_count < MAX_BASES_MINUS_1; j++) { + TSNode ty = ts_node_named_child(clause, j); + char *base = cbm_node_text(a, ty, source); + if (base && base[0]) { + char *paren = strchr(base, '('); + if (paren) { + *paren = '\0'; + } + bases[base_count++] = base; + } + } + } + ts_tree_cursor_delete(&cur); + if (base_count > 0) { + const char **result = + (const char **)cbm_arena_alloc(a, (base_count + NULL_TERM) * sizeof(const char *)); + if (result) { + for (int i = 0; i < base_count; i++) { + result[i] = bases[i]; + } + result[base_count] = NULL; + return result; + } + } + return NULL; + } // Languages whose heritage is not exposed via a tree-sitter field need // dedicated walkers; the generic field/keyword path mis-captures them. if (lang == CBM_LANG_TYPESCRIPT || lang == CBM_LANG_TSX || lang == CBM_LANG_ARKTS) { @@ -9185,6 +9231,13 @@ static void drop_c_typedefs_shadowed_by_tags(CBMExtractCtx *ctx, int first) { // Find the body/members node inside a class node static TSNode find_class_body(TSNode class_node, CBMLanguage lang) { + // VB.NET: class/module/structure/interface/enum declarations have no body + // wrapper — member declarations are direct children of the declaration. + // The grammar tags every member with a `body` field, so the field lookup + // below would return the first member as the body: decide this first. + if (lang == CBM_LANG_VISUALBASIC) { + return class_node; + } // Try field names first static const char *body_fields[] = {"body", "members", "class_body", "declaration_list", NULL}; for (const char **f = body_fields; *f; f++) { @@ -9411,6 +9464,11 @@ static TSNode resolve_method_name(TSNode child, CBMLanguage lang) { return null_node; } +// Push a single method definition with a pre-resolved name (for members whose +// name is not a tree node, e.g. VB.NET `Sub New` constructors). +static void push_method_def_named(CBMExtractCtx *ctx, TSNode child, TSNode class_node, + const char *class_qn, const CBMLangSpec *spec, char *name); + // Push a single method definition static void push_method_def(CBMExtractCtx *ctx, TSNode child, TSNode class_node, const char *class_qn, const CBMLangSpec *spec, TSNode name_node) { @@ -9420,6 +9478,12 @@ static void push_method_def(CBMExtractCtx *ctx, TSNode child, TSNode class_node, if (!name || !name[0]) { return; } + push_method_def_named(ctx, child, class_node, class_qn, spec, name); +} + +static void push_method_def_named(CBMExtractCtx *ctx, TSNode child, TSNode class_node, + const char *class_qn, const CBMLangSpec *spec, char *name) { + CBMArena *a = ctx->arena; const char *method_qn = cbm_arena_sprintf(a, "%s.%s", class_qn, name); @@ -9795,6 +9859,15 @@ static void extract_class_methods(CBMExtractCtx *ctx, TSNode class_node, const c continue; } + // VB.NET: `Sub New` constructors carry no name node (the New keyword is + // an anonymous token) — emit as Method "New" under the class QN. + if (ctx->language == CBM_LANG_VISUALBASIC && + strcmp(ts_node_type(method_node), "constructor_declaration") == 0) { + char *ctor_name = cbm_arena_sprintf(ctx->arena, "New"); + push_method_def_named(ctx, method_node, class_node, class_qn, spec, ctor_name); + continue; + } + TSNode name_node = resolve_method_name(method_node, ctx->language); if (ts_node_is_null(name_node)) { continue; @@ -12309,6 +12382,115 @@ static bool extract_schema_field(CBMExtractCtx *ctx, TSNode child, const char *c return true; } +/* VB.NET: the type an `As` clause declares, as text without generic or array + * suffixes (`List(Of String)` -> "List", `Integer()` -> "Integer"); NULL when + * the clause names none. `As T` carries it in declared_type. `As New T(...)` + * holds an object_creation_expression instead, and the grammar reads an empty + * argument list after the type (`New List(Of String)()`) as an array rank, so + * an array_type there is the constructed type's element_type. */ +static char *vb_as_clause_type(CBMArena *a, TSNode as_clause, const char *source) { + TSNode ty = ts_node_child_by_field_name(as_clause, TS_FIELD("declared_type")); + if (ts_node_is_null(ty)) { + TSNode created = cbm_find_child_by_kind(as_clause, "object_creation_expression"); + if (ts_node_is_null(created)) { + return NULL; + } + ty = ts_node_child_by_field_name(created, TS_FIELD("type")); + if (!ts_node_is_null(ty) && strcmp(ts_node_type(ty), "array_type") == 0) { + ty = ts_node_child_by_field_name(ty, TS_FIELD("element_type")); + } + if (ts_node_is_null(ty)) { + return NULL; + } + } + char *text = cbm_node_text(a, ty, source); + if (!text || !text[0]) { + return NULL; + } + char *paren = strchr(text, '('); + if (paren == text) { + return NULL; + } + if (paren) { + *paren = '\0'; + } + return text; +} + +/* One VB.NET Field def: `name_node` names it, `decl` is the declaration that + * holds it (its line span), `type` the As-clause type or NULL. */ +static void vb_push_field(CBMExtractCtx *ctx, TSNode decl, TSNode name_node, const char *type, + const char *class_qn) { + CBMArena *a = ctx->arena; + if (ts_node_is_null(name_node)) { + return; + } + char *name = cbm_node_text(a, name_node, ctx->source); + if (!name || !name[0]) { + return; + } + CBMDefinition def; + memset(&def, 0, sizeof(def)); + def.name = name; + def.qualified_name = cbm_arena_sprintf(a, "%s.%s", class_qn, name); + def.label = "Field"; + def.file_path = ctx->rel_path; + def.parent_class = class_qn; + def.return_type = type; + def.start_line = ts_node_start_point(decl).row + TS_LINE_OFFSET; + def.end_line = ts_node_end_point(decl).row + TS_LINE_OFFSET; + def.is_exported = cbm_is_exported(name, ctx->language); + cbm_defs_push(&ctx->result->defs, a, def); +} + +enum { VB_PENDING_DECLARATORS = 16 }; + +/* VB.NET member fields. A property_declaration carries its name and As clause + * itself. A field_declaration holds variable_declarators, and in + * `Dim a, b As Integer` every name before an As clause takes that clause's + * type, so untyped names wait (up to VB_PENDING_DECLARATORS) for the next + * clause; a declarator with an initializer and no clause ends the group. + * WithEvents controls in a WinForms .Designer.vb are fields of this shape. */ +static void extract_vb_member_fields(CBMExtractCtx *ctx, TSNode child, const char *class_qn) { + CBMArena *a = ctx->arena; + if (strcmp(ts_node_type(child), "property_declaration") == 0) { + TSNode asc = cbm_find_child_by_kind(child, "as_clause"); + vb_push_field(ctx, child, ts_node_child_by_field_name(child, TS_FIELD("name")), + ts_node_is_null(asc) ? NULL : vb_as_clause_type(a, asc, ctx->source), + class_qn); + return; + } + TSNode pending[VB_PENDING_DECLARATORS]; + int npending = 0; + TSTreeCursor cur = ts_tree_cursor_new(child); + bool more = ts_tree_cursor_goto_first_child(&cur); + while (more) { + TSNode part = ts_tree_cursor_current_node(&cur); + more = ts_tree_cursor_goto_next_sibling(&cur); + if (strcmp(ts_node_type(part), "variable_declarator") != 0) { + continue; + } + TSNode name_node = ts_node_child_by_field_name(part, TS_FIELD("name")); + TSNode asc = cbm_find_child_by_kind(part, "as_clause"); + bool initialized = + !ts_node_is_null(ts_node_child_by_field_name(part, TS_FIELD("initializer"))); + if (ts_node_is_null(asc) && !initialized && npending < VB_PENDING_DECLARATORS) { + pending[npending++] = name_node; + continue; + } + char *type = ts_node_is_null(asc) ? NULL : vb_as_clause_type(a, asc, ctx->source); + for (int i = 0; i < npending; i++) { + vb_push_field(ctx, child, pending[i], type, class_qn); + } + npending = 0; + vb_push_field(ctx, child, name_node, type, class_qn); + } + ts_tree_cursor_delete(&cur); + for (int i = 0; i < npending; i++) { + vb_push_field(ctx, child, pending[i], NULL, class_qn); + } +} + static void extract_class_fields(CBMExtractCtx *ctx, TSNode class_node, const char *class_qn, const CBMLangSpec *spec) { if (!spec->field_node_types || !spec->field_node_types[0]) { @@ -12560,6 +12742,14 @@ static void extract_class_fields(CBMExtractCtx *ctx, TSNode class_node, const ch } } + /* VB.NET: the declared type lives inside an `As` clause, not in a + * "type" field on the declaration, so the generic paths below never + * match (extract_vb_member_fields). */ + if (ctx->language == CBM_LANG_VISUALBASIC) { + extract_vb_member_fields(ctx, child, class_qn); + continue; + } + /* Locate the field's "type" + name node. Two shapes: * - direct (Java/Go/Rust/C/C++): * field_declaration .type=identifier .declarator=variable_declarator(.name) @@ -13091,9 +13281,13 @@ static void push_nested_class_nodes(TSNode body, const CBMLangSpec *spec, wd_sta /* A nested class inside #if/#else is still nested here, and so is * a decorated one (Python `@dataclass class Meta:` in a class * body): the decorated_definition wraps the class_definition. */ + /* VB.NET wraps a type declared inside a type in a + * type_declaration_in_type node. */ if (strcmp(ck, "field_declaration") == 0 || strcmp(ck, "template_declaration") == 0 || strcmp(ck, "declaration") == 0 || (ctx->language == CBM_LANG_PYTHON && strcmp(ck, "decorated_definition") == 0) || + (ctx->language == CBM_LANG_VISUALBASIC && + strcmp(ck, "type_declaration_in_type") == 0) || cbm_kind_in_set(child, cbm_conditional_block_types(spec->language))) { ts_nstack_push(&nc_stack, child); } @@ -13248,7 +13442,12 @@ static void push_class_body_children(TSNode node, const CBMLangSpec *spec, wd_st * independent spelling list omitted valid containers such as Scala's * `template_body` and Solidity's contract body. Methods were extracted * once by extract_class_methods(), then the generic walk descended through - * the unrecognized body and extracted them again as free functions. */ + * the unrecognized body and extracted them again as free functions. + * VB.NET's class/module/structure declarations have no body wrapper — this + * already routes through find_class_body's CBM_LANG_VISUALBASIC branch, + * which returns the class node itself, so push_nested_class_nodes below + * runs on `node` directly and members are not re-walked (and + * double-extracted) as top-level functions by the fallback below. */ /* Smali's class node is itself the member container. Method extraction * currently preserves Smali's established file-level Function contract, * so the generic walk must still visit those direct method_definition diff --git a/internal/cbm/extract_imports.c b/internal/cbm/extract_imports.c index 62985df7c7..37fa9d873c 100644 --- a/internal/cbm/extract_imports.c +++ b/internal/cbm/extract_imports.c @@ -40,6 +40,7 @@ static void parse_generic_imports(CBMExtractCtx *ctx, const char *node_type); static void parse_wolfram_imports(CBMExtractCtx *ctx); static void parse_php_imports(CBMExtractCtx *ctx); static void parse_csharp_imports(CBMExtractCtx *ctx); +static void parse_visual_basic_imports(CBMExtractCtx *ctx); static void parse_spec_imports(CBMExtractCtx *ctx); static void parse_hare_imports(CBMExtractCtx *ctx); static void parse_pascal_imports(CBMExtractCtx *ctx); @@ -2850,6 +2851,37 @@ static void parse_csharp_imports(CBMExtractCtx *ctx) { ts_tree_cursor_delete(&cursor); } +// --- VB.NET imports --- +// `Imports System.Text` and `Imports Col = System.Collections.Generic` are +// top-level imports_statement nodes with the path in the `namespace` field and +// the alias, if any, in `alias`. A cursor walks the file's top-level nodes. +static void parse_visual_basic_imports(CBMExtractCtx *ctx) { + CBMArena *a = ctx->arena; + TSTreeCursor cursor = ts_tree_cursor_new(ctx->root); + bool more = ts_tree_cursor_goto_first_child(&cursor); + while (more) { + TSNode node = ts_tree_cursor_current_node(&cursor); + more = ts_tree_cursor_goto_next_sibling(&cursor); + if (strcmp(ts_node_type(node), "imports_statement") != 0) { + continue; + } + TSNode path_node = ts_node_child_by_field_name(node, TS_FIELD("namespace")); + if (ts_node_is_null(path_node)) { + continue; + } + char *path = cbm_node_text(a, path_node, ctx->source); + if (!path || !path[0]) { + continue; + } + TSNode alias = ts_node_child_by_field_name(node, TS_FIELD("alias")); + const char *local = + ts_node_is_null(alias) ? path_last(a, path) : cbm_node_text(a, alias, ctx->source); + CBMImport imp = {.local_name = local, .module_path = path}; + cbm_imports_push(&ctx->result->imports, a, imp); + } + ts_tree_cursor_delete(&cursor); +} + // --- Generic spec-driven imports --- // For grammar-only languages that have no dedicated parser above, consume the // `import_node_types` declared in the language's CBMLangSpec. Each root-level @@ -4493,6 +4525,7 @@ void cbm_extract_imports(CBMExtractCtx *ctx) { case CBM_LANG_JAVA: case CBM_LANG_KOTLIN: case CBM_LANG_CSHARP: + case CBM_LANG_VISUALBASIC: case CBM_LANG_PHP: capture_namespace_decl(ctx); break; @@ -4524,6 +4557,9 @@ void cbm_extract_imports(CBMExtractCtx *ctx) { case CBM_LANG_CSHARP: parse_csharp_imports(ctx); break; + case CBM_LANG_VISUALBASIC: + parse_visual_basic_imports(ctx); + break; case CBM_LANG_RUST: parse_rust_imports(ctx); break; diff --git a/internal/cbm/helpers.c b/internal/cbm/helpers.c index 21b72def73..d2d5f4615a 100644 --- a/internal/cbm/helpers.c +++ b/internal/cbm/helpers.c @@ -454,6 +454,8 @@ bool cbm_is_test_file(const char *rel_path, CBMLanguage lang) { return has_suffix(base, "Test.php"); case CBM_LANG_CSHARP: return has_suffix(base, "Tests.cs") || has_suffix(base, "Test.cs"); + case CBM_LANG_VISUALBASIC: + return has_suffix(base, "Tests.vb") || has_suffix(base, "Test.vb"); case CBM_LANG_CPP: case CBM_LANG_C: return has_suffix(base, "_test.c") || has_suffix(base, "_test.cc") || diff --git a/internal/cbm/lang_specs.c b/internal/cbm/lang_specs.c index cc117859ec..fcff6f67c8 100644 --- a/internal/cbm/lang_specs.c +++ b/internal/cbm/lang_specs.c @@ -13,6 +13,7 @@ extern const TSLanguage *tree_sitter_rust(void); extern const TSLanguage *tree_sitter_java(void); extern const TSLanguage *tree_sitter_cpp(void); extern const TSLanguage *tree_sitter_c_sharp(void); +extern const TSLanguage *tree_sitter_vbnet(void); extern const TSLanguage *tree_sitter_php_only(void); extern const TSLanguage *tree_sitter_lua(void); extern const TSLanguage *tree_sitter_scala(void); @@ -399,6 +400,36 @@ static const char *cs_assign_types[] = {"assignment_expression", "postfix_unary_ static const char *cs_throw_types[] = {"throw_statement", "throw_expression", NULL}; static const char *cs_decorator_types[] = {"attribute", NULL}; +// ==================== VB.NET ==================== +// Node kinds from the vendored vbnet grammar (govindbanura/tree-sitter-vbnet +// with CodeGraph's patch; see vendored grammar MANIFEST.md). Sub and Function +// both parse as method_declaration, MustOverride members as +// abstract_method_declaration and Declare members as +// external_method_declaration. A VB Module is a static-class-like container +// so it rides in class_types; class_label_for_kind's default labels it, and a +// Structure, "Class", while interface_declaration/enum_declaration get +// "Interface"/"Enum" like C#'s. VB uses one parenthesised form for calls and +// indexing: `F()` parses as invocation_expression, `F(x)` as +// array_access_expression, so both are call nodes. +static const char *vb_func_types[] = {"method_declaration", "constructor_declaration", + "interface_method_declaration", "abstract_method_declaration", + "external_method_declaration", NULL}; +static const char *vb_class_types[] = {"class_declaration", "module_declaration", + "structure_declaration", "interface_declaration", + "enum_declaration", NULL}; +static const char *vb_module_types[] = {"source_file", NULL}; +static const char *vb_call_types[] = {"invocation_expression", "array_access_expression", + "object_creation_expression", NULL}; +static const char *vb_import_types[] = {"imports_statement", NULL}; +static const char *vb_branch_types[] = { + "if_statement", "for_statement", "for_each_statement", "while_statement", + "do_statement", "select_statement", "try_statement", NULL}; +static const char *vb_var_types[] = {"field_declaration", "declaration_statement", NULL}; +static const char *vb_field_types[] = {"field_declaration", "property_declaration", NULL}; +static const char *vb_assign_types[] = {"assignment_statement", NULL}; +static const char *vb_throw_types[] = {"throw_statement", NULL}; +static const char *vb_decorator_types[] = {"attribute", NULL}; + // ==================== PHP ==================== static const char *php_func_types[] = {"function_static_declaration", "anonymous_function", "function_definition", "arrow_function", @@ -2756,6 +2787,11 @@ static const CBMLangSpec lang_specs[CBM_LANG_COUNT] = { plsql_module_types, plsql_call_types, empty_types, empty_types, plsql_branch_types, empty_types, plsql_assign_types, plsql_throw_types, NULL, empty_types, NULL, NULL, tree_sitter_plsql, NULL}, + // CBM_LANG_VISUALBASIC — VB.NET (.vb) + [CBM_LANG_VISUALBASIC] = {CBM_LANG_VISUALBASIC, vb_func_types, vb_class_types, vb_field_types, + vb_module_types, vb_call_types, vb_import_types, vb_import_types, + vb_branch_types, vb_var_types, vb_assign_types, vb_throw_types, NULL, + vb_decorator_types, cs_env_funcs, NULL, tree_sitter_vbnet, NULL}, }; diff --git a/internal/cbm/vendored/grammars/MANIFEST.md b/internal/cbm/vendored/grammars/MANIFEST.md index e1e907f5e8..593e2d41b9 100644 --- a/internal/cbm/vendored/grammars/MANIFEST.md +++ b/internal/cbm/vendored/grammars/MANIFEST.md @@ -57,7 +57,7 @@ The grammars were originally vendored as bare `parser.c`+`scanner.c` with **no r - **arkts** (added 2026-08-26): **first-party derivative** — a fork of [tree-sitter/tree-sitter-typescript](https://github.com/tree-sitter/tree-sitter-typescript)'s `typescript` dialect pinned @ `75b3874edb2d` (v0.23.2, the same commit our vendored typescript/tsx come from), on the tree-sitter-javascript base @ `3a837b6f3658` (v0.23.1, the version upstream's own package-lock pins), extended with ArkTS/ArkUI syntax (`@Component struct` declarations, UI-DSL trailing-closure calls with post-block attribute chains, decorated function declarations, `import lazy`, `@Extend`/`@Styles` leading-dot attribute chains, anonymous `stateStyles` style blocks). Grammar source + corpus tests live in `tools/tree-sitter-arkts/`; regenerate with `npx tree-sitter-cli@0.25.10 generate` (ABI 15). **External scanner:** `scanner.c` is a symbol-rename trampoline; `_common_scanner.h` is byte-identical (same SHA-256) to the reviewed `typescript/_common_scanner.h` already shipped. **LICENSE:** tree-sitter-typescript's MIT text **verbatim and byte-identical** (© 2017 Max Brunsfeld) — which is what MIT requires of a derivative work, and what lets the provenance audit byte-verify it against upstream rather than take a note on trust. The fork is registered in the audit's `FORKS` map. Our own copyright for the ArkTS additions, and the tree-sitter-javascript attribution (© 2014 Max Brunsfeld), live with the SOURCE in `tools/tree-sitter-arkts/grammar.js` and in `THIRD_PARTY.md`, which is what ships in the release archives. - **javascript + tsx** (forked 2026-09-25, #1736): **self-maintained forks** of the pins we already vendored — [tree-sitter/tree-sitter-javascript](https://github.com/tree-sitter/tree-sitter-javascript) @ `58404d8cf191` and [tree-sitter/tree-sitter-typescript](https://github.com/tree-sitter/tree-sitter-typescript)'s `tsx` dialect @ `75b3874edb2d` (javascript base @ `3a837b6f3658`, the version upstream's package-lock pins, as for arkts). **Why:** upstream accepts a `&` inside a JSX string only before a space/digit or as a complete character reference, and never inside JSX text, so a plain URL query (`href="…?a=1&b=2"`, Google Fonts `&display=swap`) or `

Tom & Jerry

` produced an ERROR node — a `parse_partial` flag, plus false USAGE edges from identifiers the error recovery pulled out of the URL (on vercel/next.js `examples/`: 45 of 92 flagged files, 115 false cross-example USAGE edges). **The change** is one patch, `tools/tree-sitter-javascript/patches/jsx-lone-ampersand.patch`, applied to both javascript bases: a lone `&` that does not begin a complete `html_character_reference` is a one-character token (lexical precedence -1, so `&`/`&` still lex as references) aliased to the EXISTING `string_fragment` / `jsx_text` nodes, and the string-fragment regexes stop before a `&` that directly precedes the closing quote. Node types are unchanged (same type/named set; `node-types.json` only gains an empty `fields` map on those two entries). Without the patch both directories regenerate upstream exactly (javascript: byte-identical `parser.c` apart from the generator-version comment; tsx: identical state/symbol counts, ABI 14 → 15 from the newer CLI). **External scanners** are unchanged: `javascript/scanner.c` and `tsx/scanner.c` + `_common_scanner.h` stay the reviewed upstream bytes. Regenerate with `npx tree-sitter-cli@0.25.10 generate` in `tools/tree-sitter-{javascript,tsx}/` (ABI 15) and copy `src/parser.c` (tsx: also `src/tree_sitter/*.h`) here. **On an upstream bump:** re-fetch the new pins, re-apply the patch, regenerate, re-run `test/corpus/jsx_ampersand.txt` — and drop the fork if upstream fixes it. **LICENSE:** upstream's MIT text byte-identical (registered in the audit's `FORKS` map); our copyright for the patch lives in the fork `grammar.js` headers and `THIRD_PARTY.md`. - **pascal** (forked 2026-09-25, #2211): **self-maintained fork** of the pin we already vendored — [Isopod/tree-sitter-pascal](https://github.com/Isopod/tree-sitter-pascal) @ `042119eca2e1` (full: `042119eca2e18a60e56317fb06ee3ba5c32cb447`, v0.10.2, upstream `master` HEAD at fork time). **Why:** upstream's `identifier` token is ASCII-only (`/[&]?[a-zA-Z_]+[0-9_a-zA-Z]*/`), so a Delphi identifier with non-ASCII letters — e.g. the Cyrillic member names of 1C's OLE API called through late-bound Variants — produced ERROR nodes and a `parse_partial` flag. **The change** is one patch, `tools/tree-sitter-pascal/patches/unicode-identifiers.patch`, touching only that token: `/[&]?[\p{L}_][\p{L}\p{M}\p{Nd}_]*/` (a Unicode letter or `_` first, then letters, combining marks, decimal digits or `_`). Keywords are still extracted from this `word` token, so `begin`/`end`/`procedure` lex as before (and `begin` glued to Cyrillic letters is one identifier). Node types are unchanged: `node-types.json` is identical to the unpatched regeneration, and versus upstream's 0.24-generated file it only gains the 0.25 generator's `"extra": true` markers. The `\p{}` classes compile to numeric code-point ranges, so the vendored `parser.c` stays **0 non-ASCII bytes**. **Fidelity:** upstream's `parser.c` carries no generator stamp (its package.json pins tree-sitter-cli ^0.24.5). Regenerating the UNPATCHED grammar with 0.25.10 gives the same symbol/token/field/production counts (only state minimisation differs, 4299 vs 2715 states) and parse trees byte-identical to upstream's shipped parser on upstream's 88 corpus cases and its three `examples/*.pas` (37,773 tree lines for `codetoolmanager.pas`); the patched parser (2715 states) gives the same identical trees on all of those inputs. Regenerate with `npx tree-sitter-cli@0.25.10 generate --abi 14` in `tools/tree-sitter-pascal/` (ABI 14, as the upstream pin, so the ABI tally is unchanged) and copy `src/parser.c` + `src/tree_sitter/parser.h` here (`parser.h` is byte-identical to the reviewed chialisp copy); no external scanner. **On an upstream bump:** re-fetch the pinned `grammar.js`, re-apply the patch, regenerate, re-run `test/corpus/unicode_identifiers.txt` plus upstream's corpus — and drop the fork if upstream accepts Unicode identifiers. **LICENSE:** upstream's MIT text byte-identical (registered in the audit's `FORKS` map); our copyright for the patch lives in the fork `grammar.js` header and `THIRD_PARTY.md`. -- **vbnet** (added 2026-11-10; refs #1178, #1179): **self-maintained fork** of [govindbanura/tree-sitter-vbnet](https://github.com/govindbanura/tree-sitter-vbnet) @ `538b7087bf80` (full: `538b7087bf80e86004531b392fe1186379c0a2b5`, tag `v0.1-beta`, upstream `main` HEAD; no upstream commit since 2025-07-30) — MIT, (c) 2025 Govind Banura — with CodeGraph's real-world VB.NET patch, `docs/grammars/tree-sitter-vbnet.patch` from [colbymchenry/codegraph](https://github.com/colbymchenry/codegraph) @ `fe7542b6f6a4` (full: `fe7542b6f6a4939b89964affeea74f78a1c78b96`, the latest revision of that file, 2026-10-06) — MIT, (c) 2026 Colby Mchenry. **Why this grammar:** it is the licensed VB.NET grammar; `CodeAnt-AI/tree-sitter-vb-dotnet` carries no license (GitHub reports none; no LICENSE file), so it cannot be vendored. **Why the patch:** upstream checks in only `grammar.js` (no generated `src/`, no scanner) and parses textbook VB.NET but not real code: unpatched, the Single literals every WinForms `.Designer.vb` carries (`New System.Drawing.SizeF(6.0!, 13.0!)`) and body-less `MustOverride` members are ERROR nodes, and names that begin with a keyword are split (`Public SharedCache` lexes as `Shared` + `Cache`). The patch, `tools/tree-sitter-vbnet/patches/tree-sitter-vbnet.patch` (byte-identical to CodeGraph's, git blob `37918d81ed4e`), edits `grammar.js` and adds `src/scanner.c`, an external scanner for two tokens (`EXTERNAL_TOKEN_COUNT 2`: multi-line LINQ clause continuation and opaque XML literals; stateless, no allocation, no I/O; its comments carry typographic non-ASCII characters, its code none). CodeGraph's `docs/grammars/tree-sitter-vbnet.md` at the same commit lists every construct the patch adds and the parse-health census behind it. Its 2026-10-06 revision is the one pinned because it fixes the keyword-prefix split; the earlier revision (`e871c49a`, the one PR #2885 carried) still turns `Sub NewItem()` into an ERROR and `Public SharedCache As Integer` into a `Shared` field named `Cache`. **Provenance by hash:** upstream `grammar.js` at the pin is blob `21c8523b88f3`, the patch's pre-image; `tools/tree-sitter-vbnet/grammar.js` minus its 41-line provenance header is blob `c9c1d85f91ae`, the patch's post-image, and CodeGraph's `scanner.c` is blob `8334fdb92fd7`, both exactly as the patch's `index` lines record. The vendored `scanner.c` then carries one local patch of ours, `tools/tree-sitter-vbnet/patches/xml-literal-tag-syntax.patch` (blob `8334fdb` → `b3473d17d8de`; see "Local source patches" below), which stops a quadratic rescan at attribute lines. **Generated here** with tree-sitter-cli 0.25.10 (`da6fe9beb4f7`) from that `grammar.js`: ABI 15, 14,842 states, 976,623 lines, 0 non-ASCII bytes, no string literal containing a space, one comment (the generator stamp), no call outside the tree-sitter macros and the scanner hooks; two independent generations are byte-identical (`parser.c` SHA-256 `d0c29e9a7741…`, pinned in `scripts/vendored-checksums.txt`). Upstream's other files were not run or vendored (it also checks in a Windows `parser.obj`/`parser.lib`/`parser.exp` and a `build.py`). Upstream's `test/corpus` predates its own `grammar.js` (CodeGraph reports every case failing at the pin), so it is not carried; regression coverage is `vbnet_vendored_grammar_parses_real_vb_clean` in `tests/test_parse_coverage.c`. **Known gaps** (CodeGraph's notes, reproduced here): a GoTo label at column 0 leaves a localized ERROR, and a file whose last line has no trailing newline ends in a MISSING newline (upstream's `_eof` rule); VB.NET extraction must account for both. Also not parsed: XML namespace imports (`Imports `) and an embedded expression as an element name (`<<%= n %>>...`). One lexing cost remains after the local scanner patch: an attribute WITHOUT an argument list (``) is a well-formed XML start tag, so the XML-literal scan from it still reads on until something that cannot be XML (a `&` concatenation, a comparison `<`, an attribute with arguments) or the end of the file; a file of nothing but such attributes over code with neither character stays quadratic (2,000 `` methods, 120 KB: 0.56 s). **Registration:** grammar only. `internal/cbm/grammar_vbnet.c` compiles and links `tree_sitter_vbnet`, but no `CBMLanguage`, file extension or name alias routes to it yet; VB.NET extraction (#1179, with #2885 folded in) adds them, with `vb` and `visualbasic` meaning VB.NET (VB6 keeps its own name). Regenerate with `npx tree-sitter-cli@0.25.10 generate` in `tools/tree-sitter-vbnet/` and copy `src/parser.c`, `src/scanner.c` and `src/tree_sitter/*.h` here. **On an upstream bump:** re-fetch both pins, re-apply the patch, regenerate, re-run the test, and drop the fork if upstream absorbs the patch. **LICENSE:** `LICENSE` is upstream's MIT text byte-identical (SHA-256 `fa7ab39bcf92…`; registered in the audit's `FORKS` map); `LICENSE-codegraph` is CodeGraph's MIT text byte-identical to `colbymchenry/codegraph`'s `LICENSE` at the patch commit (SHA-256 `e6d98f98c666…`), shipped next to the code because the scanner and the patched rules are CodeGraph's work. +- **vbnet** (added 2026-11-10; refs #1178, #1179): **self-maintained fork** of [govindbanura/tree-sitter-vbnet](https://github.com/govindbanura/tree-sitter-vbnet) @ `538b7087bf80` (full: `538b7087bf80e86004531b392fe1186379c0a2b5`, tag `v0.1-beta`, upstream `main` HEAD; no upstream commit since 2025-07-30) — MIT, (c) 2025 Govind Banura — with CodeGraph's real-world VB.NET patch, `docs/grammars/tree-sitter-vbnet.patch` from [colbymchenry/codegraph](https://github.com/colbymchenry/codegraph) @ `fe7542b6f6a4` (full: `fe7542b6f6a4939b89964affeea74f78a1c78b96`, the latest revision of that file, 2026-10-06) — MIT, (c) 2026 Colby Mchenry. **Why this grammar:** it is the licensed VB.NET grammar; `CodeAnt-AI/tree-sitter-vb-dotnet` carries no license (GitHub reports none; no LICENSE file), so it cannot be vendored. **Why the patch:** upstream checks in only `grammar.js` (no generated `src/`, no scanner) and parses textbook VB.NET but not real code: unpatched, the Single literals every WinForms `.Designer.vb` carries (`New System.Drawing.SizeF(6.0!, 13.0!)`) and body-less `MustOverride` members are ERROR nodes, and names that begin with a keyword are split (`Public SharedCache` lexes as `Shared` + `Cache`). The patch, `tools/tree-sitter-vbnet/patches/tree-sitter-vbnet.patch` (byte-identical to CodeGraph's, git blob `37918d81ed4e`), edits `grammar.js` and adds `src/scanner.c`, an external scanner for two tokens (`EXTERNAL_TOKEN_COUNT 2`: multi-line LINQ clause continuation and opaque XML literals; stateless, no allocation, no I/O; its comments carry typographic non-ASCII characters, its code none). CodeGraph's `docs/grammars/tree-sitter-vbnet.md` at the same commit lists every construct the patch adds and the parse-health census behind it. Its 2026-10-06 revision is the one pinned because it fixes the keyword-prefix split; the earlier revision (`e871c49a`, the one PR #2885 carried) still turns `Sub NewItem()` into an ERROR and `Public SharedCache As Integer` into a `Shared` field named `Cache`. **Provenance by hash:** upstream `grammar.js` at the pin is blob `21c8523b88f3`, the patch's pre-image; `tools/tree-sitter-vbnet/grammar.js` minus its 41-line provenance header is blob `c9c1d85f91ae`, the patch's post-image, and CodeGraph's `scanner.c` is blob `8334fdb92fd7`, both exactly as the patch's `index` lines record. The vendored `scanner.c` then carries one local patch of ours, `tools/tree-sitter-vbnet/patches/xml-literal-tag-syntax.patch` (blob `8334fdb` → `b3473d17d8de`; see "Local source patches" below), which stops a quadratic rescan at attribute lines. **Generated here** with tree-sitter-cli 0.25.10 (`da6fe9beb4f7`) from that `grammar.js`: ABI 15, 14,842 states, 976,623 lines, 0 non-ASCII bytes, no string literal containing a space, one comment (the generator stamp), no call outside the tree-sitter macros and the scanner hooks; two independent generations are byte-identical (`parser.c` SHA-256 `d0c29e9a7741…`, pinned in `scripts/vendored-checksums.txt`). Upstream's other files were not run or vendored (it also checks in a Windows `parser.obj`/`parser.lib`/`parser.exp` and a `build.py`). Upstream's `test/corpus` predates its own `grammar.js` (CodeGraph reports every case failing at the pin), so it is not carried; regression coverage is `vbnet_vendored_grammar_parses_real_vb_clean` in `tests/test_parse_coverage.c`. **Known gaps** (CodeGraph's notes, reproduced here): a GoTo label at column 0 leaves a localized ERROR, and a file whose last line has no trailing newline ends in a MISSING newline (upstream's `_eof` rule); VB.NET extraction must account for both. Also not parsed: XML namespace imports (`Imports `) and an embedded expression as an element name (`<<%= n %>>...`). One lexing cost remains after the local scanner patch: an attribute WITHOUT an argument list (``) is a well-formed XML start tag, so the XML-literal scan from it still reads on until something that cannot be XML (a `&` concatenation, a comparison `<`, an attribute with arguments) or the end of the file; a file of nothing but such attributes over code with neither character stays quadratic (2,000 `` methods, 120 KB: 0.56 s). **Registration:** `internal/cbm/grammar_vbnet.c` compiles and links `tree_sitter_vbnet`; `CBM_LANG_VISUALBASIC` ("VB.NET", `.vb`) routes to it, and the name aliases `vb.net`, `vbnet`, `visualbasic` and `vb` mean VB.NET (VB6 keeps its own name). Extraction (#1179, with #2885 folded in) is described in the custom-handling table below; VB.NET names resolve case-insensitively (`src/pipeline/registry.c`, `vb_canonical_callee`). Regenerate with `npx tree-sitter-cli@0.25.10 generate` in `tools/tree-sitter-vbnet/` and copy `src/parser.c`, `src/scanner.c` and `src/tree_sitter/*.h` here. **On an upstream bump:** re-fetch both pins, re-apply the patch, regenerate, re-run the test, and drop the fork if upstream absorbs the patch. **LICENSE:** `LICENSE` is upstream's MIT text byte-identical (SHA-256 `fa7ab39bcf92…`; registered in the audit's `FORKS` map); `LICENSE-codegraph` is CodeGraph's MIT text byte-identical to `colbymchenry/codegraph`'s `LICENSE` at the patch commit (SHA-256 `e6d98f98c666…`), shipped next to the code because the scanner and the patched rules are CodeGraph's work. - **sql** (forked 2026-11-11, #2246): **self-maintained fork** of the pin we already vendored — [DerekStride/tree-sitter-sql](https://github.com/DerekStride/tree-sitter-sql) @ `851e9cb257ba` (full: `851e9cb257ba7c66cc8c14214a31c44d2f1e954e`, v0.3.11; upstream's gh-pages "deploy: 3c99273f9b32" commit, whose `grammar.js` + `grammar/` are blob-identical to main @ `3c99273f9b32`, where upstream's test corpus lives). **Why:** upstream rejected SQLite syntax that valid migration files use, so each use became an ERROR node and the file was flagged `parse_partial` (15 valid SQLite files in dani-garcia/vaultwarden `migrations/sqlite` and atuinsh/atuin `*.sql`). **The change** is one patch, `tools/tree-sitter-sql/patches/sqlite-dialect.patch` (git-style; its `index` pre-image hashes are upstream's blobs), touching `grammar/` only: `PRAGMA [schema.]name [= value | (value)]` (new `pragma_statement`); `AUTOINCREMENT` as `keyword_auto_increment` (upstream's own change, `c042cde1e2a6` of 2026-11-08, after our pin — drop that hunk on a refresh past it); a column named `key` after the first column (it lexed as the keyword of MySQL's `KEY name (cols)` index); `WITHOUT ROWID`; a trigger's `BEGIN ... END` body (the existing `block` node) after an optional unparenthesized `WHEN`; `INSERT OR {ABORT | FAIL | IGNORE | REPLACE | ROLLBACK}`; and `CREATE VIRTUAL TABLE [IF NOT EXISTS] name USING module(args)`, aliased to `create_table` (new `module_argument` node) so the table is extracted like any other. Every upstream node keeps its type and shape: upstream's 511 corpus cases pass unchanged, and `test/corpus/sqlite.txt` adds 11 (the 9 SQLite cases fail on the unpatched grammar; 2 controls pass on both). **Trade-off:** after `, KEY` a type keyword now lexes as that type, so the patch also accepts the type keywords that take no arguments (`name`, `date`, `text`, `uuid`, `json`, …) as a MySQL index name; an unquoted index named after a type that takes arguments (`KEY timestamp (ts)`, `KEY int (n)`) is now an ERROR (backtick-quoted names, which mysqldump writes, are unaffected). **Provenance:** without the patch the fork regenerates upstream's shipped `parser.c` byte-for-byte apart from line 1 (upstream's generator stamp carries no version), and `grammar.json`, `node-types.json` and `tree_sitter/*.h` byte-identical; the previously vendored files were exactly upstream's minus the final newline. **Generated here** with tree-sitter-cli 0.25.10 (`da6fe9beb4f7`): ABI 15, 31,081 states (was 30,622), 782 symbols (was 770), 434 tokens (was 429), 54 fields (was 53), 0 non-ASCII bytes, no string literal containing a space, one comment (the generator stamp), the same identifiers in call position as before; three generations are byte-identical (`parser.c` SHA-256 `3c64e5c415d0…`, pinned in `scripts/vendored-checksums.txt`). **External scanner:** `scanner.c` is upstream's plus our start_tag leak fix (see "Local source patches"); `tree_sitter/*.h` are unchanged. Regenerate with `npx tree-sitter-cli@0.25.10 generate` in `tools/tree-sitter-sql/` and copy `src/parser.c` here. **On an upstream bump:** re-fetch `grammar.js` + `grammar/`, re-apply the patch, regenerate, re-run `test/corpus/sqlite.txt` plus upstream's corpus — and drop each hunk upstream absorbs. Originally reported with a regenerated parser and tests in PR #2246 by Kerf (@kerfern); the tests are carried in `tests/test_parse_coverage.c`. **LICENSE:** upstream's MIT text byte-identical (blob `b976c9b4c70b`, also upstream main's today; registered in the audit's `FORKS` map); our copyright for the patch lives in the fork `grammar.js` header and `THIRD_PARTY.md`. - **vba** (added 2026-11-12; refs #721, #2564): **self-maintained fork** of [harumiWeb/tree-sitter-vba](https://github.com/harumiWeb/tree-sitter-vba) @ `83c5c3c3c721` (full: `83c5c3c3c7210468fb6745b585b5fb6532aa2376`, tag `v0.14.5`, upstream `main` HEAD, 2026-09-27), its `vba` dialect — MIT, (c) 2026 harumiWeb (the shared core's vb6 layer came upstream through harumiWeb/tree-sitter-vba#56 under the same license). **Why generated here:** upstream does not track its generated parser (its ADR 0002: it checks in `node-types.json` and a Go-binding copy generated by tree-sitter-cli 0.26.9), so the grammar source lives in `tools/tree-sitter-vba/` in upstream's layout, with **no local patch**: `common/define-grammar.js` is upstream's file byte-identical (blob `5e1f7d758ce1`), and `vba/grammar.js` minus its 40-line provenance header is upstream's (blob `9247dbbfe166`). **Generated here** with tree-sitter-cli 0.25.10 (`da6fe9beb4f7`), `generate --abi 15 --output vba/src vba/grammar.js` (upstream's own command): ABI 15, 16,029 states, 1,119,783 lines, 48,349,333 bytes, **no external scanner** (`EXTERNAL_TOKEN_COUNT 0`). Two independent generations are byte-identical, and identical to a generation from upstream's own layout and `tree-sitter.json` (`parser.c` SHA-256 `bd2a7ecde688…`, pinned in `scripts/vendored-checksums.txt`). Cross-checks against upstream's own artifacts: the generated `node-types.json` is upstream's checked-in `vba/src/node-types.json` byte-identical (blob `500e63561011`), and the state / large-state / symbol / token / field / production counts (16029 / 7511 / 417 / 180 / 65 / 362) equal those of upstream's 0.26.9 `bindings/go/parser.c`. Review: 0 non-ASCII and 0 control bytes, full tokenization with 0 unmatched characters, one comment (the generator stamp), no string literal containing a space, 729 hex literals that are all lexer code-point comparisons against `lookahead`, no call outside the tree-sitter macros; `tree_sitter/*.h` are byte-identical to copies already vendored here. Nothing else from upstream was run or vendored (npm/Go bindings, scripts, workflows, Wasm/playground tooling, agent instruction files, test fixtures); upstream's `THIRD_PARTY_LICENSE.md` covers only its `examples/third_party` fixtures, none of which is carried. **Why this pin:** v0.13.0 (`63b2f8d0`, the pin PR #2564 carried, likewise regenerated with 0.25.10) exposes the same procedures but misreads statements without an ERROR node: on the three corpora below it yields 1,276 `expression_statement` nodes where v0.14.5 yields 56 (e.g. `Err.Raise a, b, c` after a label loses its callee; upstream fixed these in v0.14.0-v0.14.3), and it leaves an ERROR at `Case obj Is Nothing` (fixed in v0.14.1). **Why the vba dialect, not upstream's vb6 one:** measured with the CLI on kellyethridge/VBCorLib @ `100acbbae0c0` (MIT, 655 VB6 files), Kr00l/VBCCR @ `4b86c5c2c075` (MIT, 161 VB6 files incl. 70 `.ctl`) and upstream's 481 VBA example files, vba vs vb6: files without ERROR/MISSING 643/653, 114/61 and 481/413; procedures outside ERROR nodes 14,084/14,084, 12,385/1,552 and 8,104/6,573. The vb6 dialect rejects the VBA7 forms (`PtrSafe`, `LongPtr`) that dual-target VB6 keeps inside `#If VBA7` blocks, and its error recovery then covers 83 of the 161 VBCCR files almost entirely; in no file of any corpus does vba see fewer procedures than vb6. vb6's advantage is limited to the component lines below, and its parser is 75,798,550 bytes (22,572 states), above the 50 MB line. **Known gaps** of the vba dialect on real VB6, for the extraction PR: a `.frm`/`.ctl` component reference `Object = "{GUID}#1.2#0"; "COMDLG32.OCX"` leaves a 16-character ERROR on that line (vb6 has a `frm_object_reference` node); a designer resource offset ending in a hex letter (`ToolboxBitmap = "X.ctx":003B`) leaves a 1-character ERROR; and a procedure whose header is duplicated across `#If VBA7` / `#Else` with an `Attribute Name.VB_Description` line inside each branch sends error recovery to the end of the file (2 of the 161 VBCCR files are >90% ERROR). Regression coverage: `vba_vendored_grammar_*` in `tests/test_parse_coverage.c`. **Registration:** grammar only. `internal/cbm/grammar_vba.c` compiles and links `tree_sitter_vba`, but no `CBMLanguage`, file extension or name alias routes to it yet; VB6/VBA extraction (#2564, ported after #1179) adds them under the `vb6`/`vba` names (`vb` and `visualbasic` mean VB.NET). Regenerate with the command above in `tools/tree-sitter-vba/` and copy `vba/src/parser.c` and `vba/src/tree_sitter/*.h` here. **On an upstream bump:** re-fetch both grammar files at the new tag, regenerate twice (byte-identical), and re-run the tests. **LICENSE:** upstream's MIT text byte-identical (SHA-256 `f58a3dc0eafd…`; registered in the audit's `FORKS` map). - **plsql** (added 2026-08-27): vendored from [AndreasMaierDe/tree-sitter-plsql](https://github.com/AndreasMaierDe/tree-sitter-plsql) @ `28aebef209be` (full: `28aebef209be57169600e1aa41ca1431cc6c916f`, upstream tip; repo dormant since 2023-02) — MIT, ABI 14, **no external scanner** (`EXTERNAL_TOKEN_COUNT 0`). Not listed in nvim-treesitter/Helix (`community-niche`, an individual-maintained grammar); provenance verified directly against upstream (pin = `git ls-remote` HEAD; vendored `parser.c` byte-identical to the pinned clone apart from the include-quote local patch below; 0 non-ASCII bytes; 0 dangerous calls). Security review covered only the vendored C surface (`parser.c`, `tree_sitter/parser.h`) plus upstream license/provenance metadata; no package manager hooks, workflow files, prompt/agent instruction files, or generated lockfiles were vendored. Known upstream limitation: `CREATE TYPE ... AS OBJECT` currently yields ERROR nodes (pinned by `plsql_create_type_as_object_limitation` in `tests/test_extraction.c` + `tests/fixtures/plsql/create_type_as_object_limitation.tps`). Originally contributed as PR #1033 by Oğuz (@ouzsrcm); re-vendored from upstream per vendoring policy with the PR's language wiring distilled on top. @@ -100,6 +100,7 @@ Guarded by the `contract_all_grammars_in_graph` graph-breadth test in | scheme | `extract_lisp_def`: `(define …)` head-symbol forms in `list` | | slang | added to the C-family declarator-name gate (tree-sitter-cpp/hlsl fork) | | squirrel | `resolve_func_name`: `function_declaration` → `identifier` child | +| vbnet | `find_class_body`: a type declaration is its own member container (no body wrapper); `Sub New` (`constructor_declaration`, no name) → Method `New`; bases from `inherits_statement`/`implements_statement`; fields from `variable_declarator` + `as_clause` (`declared_type`, or the `As New` object creation); callees in `extract_calls.c` `vb_callee`: `F()` is `invocation_expression`, `F(x)` is `array_access_expression`, and `New A.B.C()` (read as `New A` plus member accesses) names `A.B.C`; nested types under `type_declaration_in_type` | ## Local source patches (applied atop pinned upstream) diff --git a/scripts/vendored-checksums.txt b/scripts/vendored-checksums.txt index 9993f0d6f0..d277c7ce07 100644 --- a/scripts/vendored-checksums.txt +++ b/scripts/vendored-checksums.txt @@ -5,7 +5,7 @@ c5cfb43042b6b72045f4ba997834d0a7786d2793d91680868b5815b39f14fc78 internal/cbm/v b29c1c9fb7cc82f58c84b376df1297d6e2737a1d655fd356db0859e3c29c2fea internal/cbm/vendored/common/tree_sitter/alloc.h 31e60a1bff6f715afacce03b5b70efe42b58371b4f9595dd4af52a577ff9608c internal/cbm/vendored/common/tree_sitter/array.h 180b893c8734778fd32f372dfbc27bd6ad1cd2221f26150b31256ff6716320d2 internal/cbm/vendored/common/tree_sitter/parser.h -c89ec56087da3b2b0ad8dcad34cd7bb92e10ea7c72ae86f69d9f59daba6cdb3d internal/cbm/vendored/grammars/MANIFEST.md +4c24b50d9e30edc40ccf3a32591b93b4381864908bf1c9e81f000e6d6f6953e4 internal/cbm/vendored/grammars/MANIFEST.md ad8425038de519f8c4e3e9339feebf99dfad8a6002dcf79227d91402780a32cc internal/cbm/vendored/grammars/ada/LICENSE 02805ec13939b749c891567be36bf024b09034e04c80683a1ae667272458d549 internal/cbm/vendored/grammars/ada/parser.c 115a75d000bef9c70c4de7dfbb7f2a80b90cbb14ba265056dc7abb1ef3b9b6db internal/cbm/vendored/grammars/ada/tree_sitter/alloc.h diff --git a/src/discover/language.c b/src/discover/language.c index bfd76a0703..ab1fa26e15 100644 --- a/src/discover/language.c +++ b/src/discover/language.c @@ -64,6 +64,9 @@ static const ext_entry_t EXT_TABLE[] = { * markup lands in ERROR regions and is reported via parse_partial. */ {".cshtml", CBM_LANG_CSHARP}, + /* VB.NET */ + {".vb", CBM_LANG_VISUALBASIC}, + /* Clojure */ {".clj", CBM_LANG_CLOJURE}, {".cljc", CBM_LANG_CLOJURE}, @@ -948,6 +951,7 @@ static const char *LANG_NAMES[CBM_LANG_COUNT] = { [CBM_LANG_OBJECTSCRIPT_EXPORT] = "ObjectScript Export XML", [CBM_LANG_ARKTS] = "ArkTS", [CBM_LANG_PLSQL] = "PL/SQL", + [CBM_LANG_VISUALBASIC] = "VB.NET", }; diff --git a/src/discover/userconfig.c b/src/discover/userconfig.c index 905209a0b6..728fc72118 100644 --- a/src/discover/userconfig.c +++ b/src/discover/userconfig.c @@ -99,6 +99,11 @@ static const lang_name_entry_t LANG_NAME_TABLE[] = { {"cpp", CBM_LANG_CPP}, {"c#", CBM_LANG_CSHARP}, {"csharp", CBM_LANG_CSHARP}, + /* `vb` and `visualbasic` mean VB.NET; VB6 keeps a name of its own. */ + {"vb.net", CBM_LANG_VISUALBASIC}, + {"vbnet", CBM_LANG_VISUALBASIC}, + {"visualbasic", CBM_LANG_VISUALBASIC}, + {"vb", CBM_LANG_VISUALBASIC}, {"php", CBM_LANG_PHP}, {"lua", CBM_LANG_LUA}, {"scala", CBM_LANG_SCALA}, diff --git a/src/pipeline/pass_calls.c b/src/pipeline/pass_calls.c index 4430e9d440..9bcab562d1 100644 --- a/src/pipeline/pass_calls.c +++ b/src/pipeline/pass_calls.c @@ -983,6 +983,15 @@ static int calls_emit_unresolved_service(cbm_pipeline_ctx_t *ctx, const CBMCall return calls_emit_service_call(ctx, call, source_node, svc, NULL, evidence); } +void cbm_pipeline_emit_field_call_usage(cbm_gbuf_t *gbuf, const cbm_gbuf_node_t *source, + const cbm_gbuf_node_t *field, const CBMCall *call) { + char esc_ref[CBM_SZ_256]; + cbm_json_escape(esc_ref, sizeof(esc_ref), call->callee_name); + char props[CBM_SZ_512]; + snprintf(props, sizeof(props), "{\"callee\":\"%s\"}", esc_ref); + cbm_gbuf_insert_edge(gbuf, source->id, field->id, "USAGE", props); +} + /* Apply the field-call policy after a registry target has been found. */ static const cbm_gbuf_node_t *calls_field_target(cbm_pipeline_ctx_t *ctx, const CBMCall *call, const CBMResolvedCallArray *lsp_calls, @@ -994,6 +1003,9 @@ static const cbm_gbuf_node_t *calls_field_target(cbm_pipeline_ctx_t *ctx, const target_node->file_path)) { case CBM_FIELD_CALL_DROP: return NULL; + case CBM_FIELD_CALL_AS_USAGE: + cbm_pipeline_emit_field_call_usage(ctx->gbuf, source_node, target_node, call); + return NULL; case CBM_FIELD_CALL_BY_OWNER: /* An arrow call was already bound this way by registry resolution. */ if (!arrow_bound) { @@ -1036,7 +1048,8 @@ static bool calls_emit_lsp_target(cbm_pipeline_ctx_t *ctx, const CBMCall *call, } /* LSP textual fallbacks can also name data, as with static imports. The * call is handled: no edge, and no registry fallback after it. */ - if (cbm_java_suppress_call_to_data_member(lang == CBM_LANG_JAVA, target_node->label)) { + if (cbm_java_suppress_call_to_data_member(cbm_call_never_names_data(lang), + target_node->label)) { return true; } cbm_resolution_t res = {0}; @@ -1433,10 +1446,12 @@ static int resolve_single_call(cbm_pipeline_ctx_t *ctx, CBMCall *call, const CBM return calls_emit_route_call(ctx, call, source_node, module_qn, imp_keys, imp_vals, imp_count, route_mount, lang, evidence); } - /* A Java call never targets data — see cbm_java_suppress_call_to_data_member. - * The language gate lives here, as with the guards above, and MUST match - * pass_parallel.c exactly or the two resolvers diverge. */ - if (cbm_java_suppress_call_to_data_member(lang == CBM_LANG_JAVA, target_node->label)) { + /* A Java or VB.NET call never targets data — see + * cbm_java_suppress_call_to_data_member. The language gate is + * cbm_call_never_names_data, shared with pass_parallel.c so the two + * resolvers cannot diverge. */ + if (cbm_java_suppress_call_to_data_member(cbm_call_never_names_data(lang), + target_node->label)) { return 0; } /* A bare Go `init(...)` calls a local closure or parameter: never a diff --git a/src/pipeline/pass_parallel.c b/src/pipeline/pass_parallel.c index 71b5b684ff..aa612d7c1b 100644 --- a/src/pipeline/pass_parallel.c +++ b/src/pipeline/pass_parallel.c @@ -3754,6 +3754,11 @@ static void resolve_file_calls(resolve_ctx_t *rc, resolve_worker_state_t *ws, CB if (field_policy == CBM_FIELD_CALL_DROP) { continue; } + if (field_policy == CBM_FIELD_CALL_AS_USAGE) { + cbm_pipeline_emit_field_call_usage(ws->local_edge_buf, source_node, target_node, + call); + continue; + } if (field_policy == CBM_FIELD_CALL_BY_OWNER && !arrow_bound) { if (!field_index_built) { field_index_ready = @@ -3780,9 +3785,10 @@ static void resolve_file_calls(resolve_ctx_t *rc, resolve_worker_state_t *ws, CB continue; } if (target_node && source_node->id != target_node->id && - cbm_java_suppress_call_to_data_member(lang == CBM_LANG_JAVA, target_node->label)) { + cbm_java_suppress_call_to_data_member(cbm_call_never_names_data(lang), + target_node->label)) { /* Same guard as pass_calls.c — a Java call never targets a - * Variable or a Field. */ + * Variable or a Field, a VB.NET call never an enum member. */ continue; } if (target_node && source_node->id != target_node->id && diff --git a/src/pipeline/pipeline.h b/src/pipeline/pipeline.h index 26bf59c0bf..2dba413897 100644 --- a/src/pipeline/pipeline.h +++ b/src/pipeline/pipeline.h @@ -572,6 +572,7 @@ typedef enum { CBM_FIELD_CALL_KEEP = 0, /* not a Field target, or a language this rule leaves alone */ CBM_FIELD_CALL_DROP, /* a Field can never be this call's target */ CBM_FIELD_CALL_BY_OWNER, /* C/C++ member call: the object's type names the Field */ + CBM_FIELD_CALL_AS_USAGE, /* VB.NET indexing written like a call: a USAGE of the Field */ } cbm_field_call_policy_t; cbm_field_call_policy_t cbm_call_onto_field_policy(CBMLanguage caller_lang, const char *callee_text, const char *target_label, @@ -609,6 +610,12 @@ const char *cbm_registry_unique_field_qn(const cbm_registry_t *r, const char *me * test_registry.c. */ bool cbm_java_suppress_call_to_data_member(bool is_java, const char *target_label); +/* The `is_java` gate of cbm_java_suppress_call_to_data_member for a caller + * language: Java, and VB.NET, whose Variables are enum members. One gate for + * pass_calls.c and pass_parallel.c, so the two resolvers cannot diverge. + * Pure; unit-tested in test_registry.c. */ +bool cbm_call_never_names_data(CBMLanguage lang); + /* Get the label of a qualified name, or NULL if not found. */ const char *cbm_registry_label_of(const cbm_registry_t *r, const char *qn); diff --git a/src/pipeline/pipeline_internal.h b/src/pipeline/pipeline_internal.h index 75a3c5d772..7d694b1837 100644 --- a/src/pipeline/pipeline_internal.h +++ b/src/pipeline/pipeline_internal.h @@ -902,6 +902,12 @@ bool cbm_pipeline_spawn_site(const cbm_gbuf_t *gbuf, CBMLanguage lang, const CBM void cbm_pipeline_emit_spawn(cbm_gbuf_t *gbuf, const cbm_gbuf_node_t *source, const CBMCall *call, const cbm_pipeline_spawn_t *spawn); +/* CBM_FIELD_CALL_AS_USAGE: the USAGE edge from `source` to the Field a call + * landed on, with the properties the usage pass writes. Shared by + * pass_calls.c and pass_parallel.c. */ +void cbm_pipeline_emit_field_call_usage(cbm_gbuf_t *gbuf, const cbm_gbuf_node_t *source, + const cbm_gbuf_node_t *field, const CBMCall *call); + /* Resolve an import to its in-graph target node, or NULL if unresolvable. * * Resolution order (first hit wins): diff --git a/src/pipeline/registry.c b/src/pipeline/registry.c index 73c2a41481..d2cade6462 100644 --- a/src/pipeline/registry.c +++ b/src/pipeline/registry.c @@ -150,6 +150,11 @@ struct cbm_registry { CBMHashTable *swift_signatures; /* borrowed exact-map keys; owned values */ CBMHashTable *swift_overloads; /* base callable QN -> overloads */ swift_owners_t *swift_owners; + /* VB.NET: ASCII-folded name -> the by_name spelling it was registered + * under (key and value owned). Filled only by VB.NET definitions and read + * only by a VB.NET lookup that found nothing under its own spelling, so + * no other language sees it (vb_canonical_callee). */ + CBMHashTable *vb_folded; }; /* ── Helpers ─────────────────────────────────────────────────────── */ @@ -1338,6 +1343,7 @@ static int xl_family(CBMLanguage lang) { return XL_FAM_JVM; case CBM_LANG_CSHARP: case CBM_LANG_FSHARP: + case CBM_LANG_VISUALBASIC: return XL_FAM_DOTNET; case CBM_LANG_PHP: case CBM_LANG_BLADE: @@ -1553,6 +1559,12 @@ cbm_field_call_policy_t cbm_call_onto_field_policy(CBMLanguage caller_lang, cons if (cbm_suppress_cross_language_ref(caller_lang, target_file_path)) { return CBM_FIELD_CALL_DROP; } + /* VB.NET writes indexing like a call (`items(0)`, `Me.Cache(key)`), so a + * parenthesised name that lands on a Field indexes it or reads a property: + * it calls nothing, and it references the Field as C#'s `items[0]` does. */ + if (caller_lang == CBM_LANG_VISUALBASIC) { + return CBM_FIELD_CALL_AS_USAGE; + } if (caller_lang != CBM_LANG_C && caller_lang != CBM_LANG_CPP) { return CBM_FIELD_CALL_KEEP; } @@ -1620,6 +1632,17 @@ bool cbm_java_suppress_call_to_data_member(bool is_java, const char *target_labe return strcmp(target_label, "Variable") == 0 || strcmp(target_label, "Field") == 0; } +bool cbm_call_never_names_data(CBMLanguage lang) { + /* VB.NET's Variables are enum members, and an enum member is never + * called: `Refresh()` in a Form calls Form.Refresh, not the `Refresh` + * member of some enum the short-name registry finds. Measured on + * staxrip/staxrip: 249 of 6,455 VB.NET CALLS edges landed on an enum + * member that way. A VB.NET call that lands on a Field never gets here: + * cbm_call_onto_field_policy has already made it a USAGE of the Field + * (indexing, or a delegate field invoked like a call). */ + return lang == CBM_LANG_JAVA || lang == CBM_LANG_VISUALBASIC; +} + /* ── Lifecycle ──────────────────────────────────────────────────── */ cbm_registry_t *cbm_registry_new(void) { @@ -1665,6 +1688,12 @@ static void free_swift_overloads(const char *key, void *value, void *ud) { cbm_free(CBM_MEM_CLASS_OTHER, (void *)key); } +static void free_vb_folded(const char *key, void *value, void *ud) { + (void)ud; + cbm_free(CBM_MEM_CLASS_OTHER, value); + cbm_free(CBM_MEM_CLASS_OTHER, (void *)key); +} + static void swift_owners_free(swift_owners_t *index) { if (!index) { return; @@ -1697,6 +1726,10 @@ void cbm_registry_free(cbm_registry_t *r) { cbm_ht_free(r->swift_overloads); } swift_owners_free(r->swift_owners); + if (r->vb_folded) { + cbm_ht_foreach(r->vb_folded, free_vb_folded, NULL); + cbm_ht_free(r->vb_folded); + } cbm_ht_foreach(r->exact, free_label, NULL); cbm_ht_free(r->exact); for (int i = 0; i < r->label_pool_n; i++) { @@ -1838,6 +1871,99 @@ static const char *registry_add_exact(cbm_registry_t *r, const char *qualified_n return cbm_ht_get_key(r->exact, qualified_name); } +/* ── VB.NET case-insensitive names ───────────────────────────────── */ + +/* ASCII-fold the `len` bytes of `name` into `out` (`cap` bytes). False when + * they do not fit. VB.NET identifiers are case-insensitive: `Calculate`, + * `CALCULATE` and `calculate` name one symbol. */ +static bool vb_fold(const char *name, size_t len, char *out, size_t cap) { + if (!name || len + SKIP_ONE > cap) { + return false; + } + for (size_t i = 0; i < len; i++) { + unsigned char c = (unsigned char)name[i]; + out[i] = (char)(c >= 'A' && c <= 'Z' ? c - 'A' + 'a' : c); + } + out[len] = '\0'; + return true; +} + +/* Record the by_name spelling of a VB.NET definition under its folded form. + * Two spellings that fold alike (`Run`, `RUN`) keep the strcmp-smaller one, + * so the table does not depend on registration order; folding keeps the + * length, so the kept spelling is overwritten in place. */ +static void vb_index_folded(cbm_registry_t *r, const char *spelling) { + char folded[CBM_SZ_512]; + size_t len = strlen(spelling); + if (!vb_fold(spelling, len, folded, sizeof(folded))) { + return; + } + if (!r->vb_folded) { + r->vb_folded = cbm_ht_create(CBM_SZ_512); + if (!r->vb_folded) { + return; + } + } + char *have = cbm_ht_get(r->vb_folded, folded); + if (have) { + if (strcmp(spelling, have) < 0) { + memcpy(have, spelling, len); + } + return; + } + char *key = cbm_mem_strdup(CBM_MEM_CLASS_OTHER, folded); + char *value = cbm_mem_strdup(CBM_MEM_CLASS_OTHER, spelling); + if (!key || !value) { + if (key) { + cbm_free(CBM_MEM_CLASS_OTHER, key); + } + if (value) { + cbm_free(CBM_MEM_CLASS_OTHER, value); + } + return; + } + cbm_ht_set(r->vb_folded, key, value); +} + +/* Respell each dot segment of a VB.NET `callee` the way a VB.NET definition + * spells it (`helpers.format` -> `Helpers.Format`) into `out`; a segment no + * definition folds to (a local variable) stays as written. False when nothing + * changes or the result does not fit. */ +static bool vb_canonical_callee(const cbm_registry_t *r, const char *callee, char *out, + size_t cap) { + if (!r->vb_folded || !callee) { + return false; + } + size_t o = 0; + bool changed = false; + const char *seg = callee; + for (;;) { + size_t len = strcspn(seg, "."); + const char *dot = seg[len] == '.' ? seg + len : NULL; + char folded[CBM_SZ_512]; + const char *canon = vb_fold(seg, len, folded, sizeof(folded)) + ? (const char *)cbm_ht_get(r->vb_folded, folded) + : NULL; + /* o < cap holds here, so cap - o - SKIP_ONE cannot wrap: room for the + * segment plus its '.' or the terminating NUL. */ + if (len >= cap - o - SKIP_ONE) { + return false; + } + if (canon && strncmp(canon, seg, len) != 0) { + changed = true; + } + memcpy(out + o, canon ? canon : seg, len); + o += len; + if (!dot) { + break; + } + out[o++] = '.'; + seg = dot + SKIP_ONE; + } + out[o] = '\0'; + return changed; +} + void cbm_registry_add(cbm_registry_t *r, const char *name, const char *qualified_name, const char *label, bool is_test) { cbm_registry_add_lang_in_module(r, name, qualified_name, label, CBM_LANG_COUNT, 0, is_test); @@ -1909,6 +2035,9 @@ void cbm_registry_add_lang_in_module(cbm_registry_t *r, const char *name, const char *primary = name && cbm_qn_callable_base_len_named(owned_qn, name) < strlen(owned_qn) ? name : derived; index_under_name(r, primary, owned_qn, is_test, lang); + if (lang == CBM_LANG_VISUALBASIC) { + vb_index_folded(r, primary); + } /* '#' is a QN fence; no extractor mints one for a REGISTERED definition * today (Rust cfg twins are variants of one plain QN; a C macro's QN ends in * "#macro", but Macro is no registry label, so it never gets here). A @@ -5030,22 +5159,58 @@ static size_t lang_scope_len(const char *module_qn, CBMLanguage lang) { : (module_qn ? strlen(module_qn) : 0); } +/* VB.NET names are case-insensitive. A lookup that found nothing under the + * name as written retries once with every segment respelled the way a VB.NET + * definition spells it (vb_canonical_callee); one that did find something + * keeps it, so an exact spelling always wins. `call_lang` and `caller_test` + * are passed through as the first lookup received them + * (registry_resolve_scoped). */ +static cbm_resolution_t vb_resolve_folded(const cbm_registry_t *r, cbm_resolution_t res, + const char *callee_name, const char *module_qn, + const char **import_map_keys, + const char **import_map_vals, int import_map_count, + size_t scope_len, bool skip_members, + CBMLanguage call_lang, bool caller_test) { + if (res.qualified_name && res.qualified_name[0]) { + return res; + } + char canon[CBM_SZ_512]; + if (!vb_canonical_callee(r, callee_name, canon, sizeof(canon))) { + return res; + } + return registry_resolve_scoped(r, canon, module_qn, import_map_keys, import_map_vals, + import_map_count, scope_len, skip_members, call_lang, + caller_test); +} + cbm_resolution_t cbm_registry_resolve_lang(const cbm_registry_t *r, const char *callee_name, const char *module_qn, const char **import_map_keys, const char **import_map_vals, int import_map_count, CBMLanguage lang) { - return registry_resolve_scoped(r, callee_name, module_qn, import_map_keys, import_map_vals, - import_map_count, lang_scope_len(module_qn, lang), false, - CBM_LANG_COUNT, false); + size_t scope_len = lang_scope_len(module_qn, lang); + cbm_resolution_t res = + registry_resolve_scoped(r, callee_name, module_qn, import_map_keys, import_map_vals, + import_map_count, scope_len, false, CBM_LANG_COUNT, false); + if (lang == CBM_LANG_VISUALBASIC) { + res = vb_resolve_folded(r, res, callee_name, module_qn, import_map_keys, import_map_vals, + import_map_count, scope_len, false, CBM_LANG_COUNT, false); + } + return res; } cbm_resolution_t cbm_registry_resolve_ref(const cbm_registry_t *r, const char *ref_name, const char *module_qn, const char **import_map_keys, const char **import_map_vals, int import_map_count, CBMLanguage lang, bool caller_test) { - return registry_resolve_scoped(r, ref_name, module_qn, import_map_keys, import_map_vals, - import_map_count, lang_scope_len(module_qn, lang), false, - CBM_LANG_COUNT, caller_test); + size_t scope_len = lang_scope_len(module_qn, lang); + cbm_resolution_t res = + registry_resolve_scoped(r, ref_name, module_qn, import_map_keys, import_map_vals, + import_map_count, scope_len, false, CBM_LANG_COUNT, caller_test); + if (lang == CBM_LANG_VISUALBASIC) { + res = vb_resolve_folded(r, res, ref_name, module_qn, import_map_keys, import_map_vals, + import_map_count, scope_len, false, CBM_LANG_COUNT, caller_test); + } + return res; } static cbm_resolution_t resolve_call_lang(const cbm_registry_t *r, const char *callee_name, @@ -5058,9 +5223,15 @@ static cbm_resolution_t resolve_call_lang(const cbm_registry_t *r, const char *c * for the name; a C member call and every other language keep them. */ bool skip_members = lang == CBM_LANG_C && callee_name && !strchr(callee_name, '.') && !strstr(callee_name, "->"); - return registry_resolve_scoped(r, callee_name, module_qn, import_map_keys, import_map_vals, - import_map_count, lang_scope_len(module_qn, lang), skip_members, - lang, caller_test); + size_t scope_len = lang_scope_len(module_qn, lang); + cbm_resolution_t res = + registry_resolve_scoped(r, callee_name, module_qn, import_map_keys, import_map_vals, + import_map_count, scope_len, skip_members, lang, caller_test); + if (lang == CBM_LANG_VISUALBASIC) { + res = vb_resolve_folded(r, res, callee_name, module_qn, import_map_keys, import_map_vals, + import_map_count, scope_len, skip_members, lang, caller_test); + } + return res; } cbm_resolution_t cbm_registry_resolve_call_lang(const cbm_registry_t *r, const char *callee_name, diff --git a/tests/fixtures/complexity/VB.NET/CustomerService.vb b/tests/fixtures/complexity/VB.NET/CustomerService.vb new file mode 100644 index 0000000000..fc6426f126 --- /dev/null +++ b/tests/fixtures/complexity/VB.NET/CustomerService.vb @@ -0,0 +1,28 @@ +Public Interface ICustomerStore + Sub Save(name As String) +End Interface + +Public Class CustomerService + Implements ICustomerStore + + Private lastName As String + + Public Sub Save(name As String) Implements ICustomerStore.Save + If Validate(name) Then + lastName = name + End If + End Sub + + Public Function Describe() As String + Return "Customer: " & lastName + End Function + + Private Function Validate(name As String) As Boolean + Return Not String.IsNullOrEmpty(name) + End Function + + Public Class Snapshot + Public Sub Capture() + End Sub + End Class +End Class diff --git a/tests/fixtures/complexity/VB.NET/Form1.Designer.vb b/tests/fixtures/complexity/VB.NET/Form1.Designer.vb new file mode 100644 index 0000000000..fb051d530e --- /dev/null +++ b/tests/fixtures/complexity/VB.NET/Form1.Designer.vb @@ -0,0 +1,19 @@ + _ +Partial Class Form1 + Inherits System.Windows.Forms.Form + + Private components As System.ComponentModel.IContainer + Friend WithEvents SaveButton As System.Windows.Forms.Button + Friend WithEvents NameBox As System.Windows.Forms.TextBox + + Private Sub InitializeComponent() + Me.SaveButton = New System.Windows.Forms.Button() + Me.NameBox = New System.Windows.Forms.TextBox() + Me.SuspendLayout() + Me.SaveButton.Text = "Save" + Me.ClientSize = New System.Drawing.Size(284, 261) + Me.Controls.Add(Me.SaveButton) + Me.Controls.Add(Me.NameBox) + Me.ResumeLayout(False) + End Sub +End Class diff --git a/tests/fixtures/complexity/VB.NET/Form1.vb b/tests/fixtures/complexity/VB.NET/Form1.vb new file mode 100644 index 0000000000..eb070ff2bd --- /dev/null +++ b/tests/fixtures/complexity/VB.NET/Form1.vb @@ -0,0 +1,27 @@ +Imports System.Windows.Forms + +Public Class Form1 + Implements IDisposable + + Private ReadOnly service As New CustomerService() + + Public Sub New() + InitializeComponent() + AddHandler NameBox.TextChanged, AddressOf OnNameChanged + End Sub + +#Region "Handlers" + Private Sub SaveButton_Click(sender As Object, e As EventArgs) Handles SaveButton.Click + service.Save(NameBox.Text) + UpdateTitle() + End Sub + + Private Sub OnNameChanged(sender As Object, e As EventArgs) + UPDATETITLE() + End Sub +#End Region + + Private Sub UpdateTitle() + Me.Text = service.Describe() + End Sub +End Class diff --git a/tests/repro/repro_call_argument_matrix_b.c b/tests/repro/repro_call_argument_matrix_b.c index ccac7a32e6..6a27186ce9 100644 --- a/tests/repro/repro_call_argument_matrix_b.c +++ b/tests/repro/repro_call_argument_matrix_b.c @@ -1,5 +1,5 @@ /* - * Exhaustive call-argument reproduction matrix, CBMLanguage 80..164. + * Exhaustive call-argument reproduction matrix, CBMLanguage 80..170. * * Every language in this numeric range whose live spec has call-node metadata * owns one TEST row below. Semantic applications are exercised twice: once as @@ -879,6 +879,21 @@ static const char PLSQL_BARE[] = "CREATE OR REPLACE PACKAGE BODY sample_pkg AS\n " END;\n" "END sample_pkg;\n" "/\n"; +static const char VISUALBASIC_INSIDE[] = "Module Sample\n" + " Function Accept(value As Object) As Object\n" + " Return value\n" + " End Function\n" + "\n" + " Function Run(watched As Object) As Object\n" + " Dim result = Accept(watched)\n" + " Return result\n" + " End Function\n" + "End Module\n"; +static const char VISUALBASIC_BARE[] = "Module Sample\n" + " Function Run(watched As Object) As Object\n" + " Return watched\n" + " End Function\n" + "End Module\n"; #define ROUTINE_ARGUMENT_CASE(tag_value, language_value, filename_value, inside_value, bare_value, \ kind_value, caller_value, callee_value, argument_value, defs_value, \ @@ -1030,6 +1045,10 @@ static const RoutineArgumentCase PLSQL_CASE = ROUTINE_ARGUMENT_CASE( static const RoutineArgumentCase CHIALISP_CASE = ROUTINE_ARGUMENT_CASE( "CHIALISP", CBM_LANG_CHIALISP, "sample.clib", CHIALISP_INSIDE, CHIALISP_BARE, "list", "run", "accept", "watched", 1, 1, 0, "Chialisp list application and symbol-reference vocabulary"); +static const RoutineArgumentCase VISUALBASIC_CASE = ROUTINE_ARGUMENT_CASE( + "VISUALBASIC", CBM_LANG_VISUALBASIC, "Sample.vb", VISUALBASIC_INSIDE, VISUALBASIC_BARE, + "array_access_expression", "Run", "Accept", "watched", 1, 1, 0, + "VB.NET Module function application with a value argument"); static const ModuleArgumentCase JUST_CASE = MODULE_ARGUMENT_CASE( "JUST", CBM_LANG_JUST, "justfile", JUST_INSIDE, JUST_BARE, "function_call", "uppercase", @@ -1223,6 +1242,7 @@ DEFINE_ROUTINE_ARGUMENT_TEST(objectscript_udl, OBJECTSCRIPT_UDL_CASE) DEFINE_ROUTINE_ARGUMENT_TEST(objectscript_routine, OBJECTSCRIPT_ROUTINE_CASE) DEFINE_ROUTINE_ARGUMENT_TEST(plsql, PLSQL_CASE) DEFINE_ROUTINE_ARGUMENT_TEST(chialisp, CHIALISP_CASE) +DEFINE_ROUTINE_ARGUMENT_TEST(visualbasic, VISUALBASIC_CASE) #undef DEFINE_ROUTINE_ARGUMENT_TEST @@ -1292,15 +1312,15 @@ TEST(repro_call_argument_matrix_b_domain_bitbake) { } enum { - ROUTINE_ARGUMENT_LANGUAGE_COUNT = 39, + ROUTINE_ARGUMENT_LANGUAGE_COUNT = 40, MODULE_ARGUMENT_LANGUAGE_COUNT = 4, DOMAIN_CONTROL_LANGUAGE_COUNT = 6, MATRIX_LANGUAGE_COUNT = ROUTINE_ARGUMENT_LANGUAGE_COUNT + MODULE_ARGUMENT_LANGUAGE_COUNT + DOMAIN_CONTROL_LANGUAGE_COUNT, }; -_Static_assert(MATRIX_LANGUAGE_COUNT == 49, - "RACKET..CHIALISP call-capable matrix must contain exactly 49 " +_Static_assert(MATRIX_LANGUAGE_COUNT == 50, + "RACKET..VISUALBASIC call-capable matrix must contain exactly 50 " "language rows"); #define MATRIX_B_LANGUAGE_ROWS(X) \ @@ -1345,6 +1365,7 @@ _Static_assert(MATRIX_LANGUAGE_COUNT == 49, OBJECTSCRIPT_ROUTINE_CASE.identity.language) \ X(repro_call_argument_matrix_b_routine_plsql, PLSQL_CASE.identity.language) \ X(repro_call_argument_matrix_b_routine_chialisp, CHIALISP_CASE.identity.language) \ + X(repro_call_argument_matrix_b_routine_visualbasic, VISUALBASIC_CASE.identity.language) \ X(repro_call_argument_matrix_b_module_just, JUST_CASE.identity.language) \ X(repro_call_argument_matrix_b_module_gotemplate, GOTEMPLATE_CASE.identity.language) \ X(repro_call_argument_matrix_b_module_linkerscript, LINKERSCRIPT_CASE.identity.language) \ diff --git a/tests/repro/repro_call_node_manifest.c b/tests/repro/repro_call_node_manifest.c index fc2a8b14c5..e11120f9c4 100644 --- a/tests/repro/repro_call_node_manifest.c +++ b/tests/repro/repro_call_node_manifest.c @@ -59,10 +59,10 @@ typedef struct { } CallNodeManifestEntry; enum { - EXPECTED_HISTORICAL_CALL_NODE_TOTAL = 226, - EXPECTED_ACTIVE_PRIMARY_TOTAL = 196, - EXPECTED_DIRECT_CALLS = 160, - EXPECTED_CONSTRUCTOR_CALLS = 22, + EXPECTED_HISTORICAL_CALL_NODE_TOTAL = 229, + EXPECTED_ACTIVE_PRIMARY_TOTAL = 199, + EXPECTED_DIRECT_CALLS = 162, + EXPECTED_CONSTRUCTOR_CALLS = 23, EXPECTED_OPERATOR_CALLS = 12, EXPECTED_IMPLICIT_CALLS = 2, EXPECTED_DSL_INVOCATIONS = 14, @@ -70,7 +70,7 @@ enum { EXPECTED_CALLEE_WRAPPERS = 8, EXPECTED_ARGUMENT_WRAPPERS = 1, EXPECTED_CONTROL_OR_DOCUMENT_NONCALLS = 6, - EXPECTED_PRIMARY_OWNERS = 196, + EXPECTED_PRIMARY_OWNERS = 199, EXPECTED_SYNTHETIC_OWNERS = 10, EXPECTED_NO_CALL_EDGE_OWNERS = 20, EXPECTED_PRIMARY_OPERATOR_CALLS = 4, @@ -321,6 +321,14 @@ static const CallNodeManifestEntry CALL_NODE_MANIFEST[] = { ENTRY(CBM_LANG_ARKTS, "call_expression", DIRECT_CALL, PRIMARY_EXTRACTOR, true, true), ENTRY(CBM_LANG_ARKTS, "new_expression", CONSTRUCTOR_CALL, PRIMARY_EXTRACTOR, true, true), ENTRY(CBM_LANG_PLSQL, "ref_call", DIRECT_CALL, PRIMARY_EXTRACTOR, true, true), + /* VB.NET writes calls and indexing alike: `F()` parses as + * invocation_expression, `F(x)` as array_access_expression. */ + ENTRY(CBM_LANG_VISUALBASIC, "invocation_expression", DIRECT_CALL, PRIMARY_EXTRACTOR, true, + true), + ENTRY(CBM_LANG_VISUALBASIC, "array_access_expression", DIRECT_CALL, PRIMARY_EXTRACTOR, true, + true), + ENTRY(CBM_LANG_VISUALBASIC, "object_creation_expression", CONSTRUCTOR_CALL, PRIMARY_EXTRACTOR, + true, true), }; #undef ENTRY @@ -328,7 +336,7 @@ static const CallNodeManifestEntry CALL_NODE_MANIFEST[] = { #define MANIFEST_COUNT (sizeof(CALL_NODE_MANIFEST) / sizeof(CALL_NODE_MANIFEST[0])) _Static_assert(MANIFEST_COUNT == EXPECTED_HISTORICAL_CALL_NODE_TOTAL, - "call-node manifest must contain exactly 222 entries"); + "call-node manifest must contain exactly 229 entries"); _Static_assert(EXPECTED_DIRECT_CALLS + EXPECTED_CONSTRUCTOR_CALLS + EXPECTED_OPERATOR_CALLS + EXPECTED_IMPLICIT_CALLS + EXPECTED_DSL_INVOCATIONS + EXPECTED_BUILD_DEPENDENCIES + EXPECTED_CALLEE_WRAPPERS + diff --git a/tests/repro/repro_language_registry.c b/tests/repro/repro_language_registry.c index 668f9fa616..68cd340fbb 100644 --- a/tests/repro/repro_language_registry.c +++ b/tests/repro/repro_language_registry.c @@ -221,6 +221,10 @@ static const LanguageCapabilityEntry LANGUAGE_CAPABILITIES[CBM_LANG_COUNT] = { DOCUMENT(ASCIIDOC), NO_CALL(OPENAPI), /* the JSON grammar; its operations are Routes, no calls */ DOCUMENT(DIAGRAM), + /* VB.NET's `identifier` rule (grammar.js) emits plain "identifier" nodes + * for names, matching extract_usages.c's generic identifier-kind check + * (no VB-specific case needed there), the same shape as CSHARP above. */ + CALL_WITH_REFERENCE_VOCAB(VISUALBASIC), }; #undef CALL_WITH_REFERENCE_VOCAB @@ -311,7 +315,7 @@ TEST(repro_language_capability_ledger_covers_every_enum) { } } - if (counts[CAP_CALL_WITH_REFERENCE_VOCAB] != 88 || + if (counts[CAP_CALL_WITH_REFERENCE_VOCAB] != 89 || counts[CAP_CALL_WITHOUT_REFERENCE_VOCAB] != 27 || counts[CAP_NO_CALL] != 50 || counts[CAP_TRANSFORM_ONLY] != 1 || counts[CAP_UNSUPPORTED] != 1 || counts[CAP_DOCUMENT] != 3) { @@ -331,8 +335,8 @@ TEST(repro_language_capability_ledger_covers_every_enum) { TEST(repro_call_argument_matrices_equal_call_capability_ledger) { enum { EXPECTED_MATRIX_A_ROWS = 68, - EXPECTED_MATRIX_B_ROWS = 49, - EXPECTED_CALL_CAPABLE_LANGUAGES = 115, + EXPECTED_MATRIX_B_ROWS = 50, + EXPECTED_CALL_CAPABLE_LANGUAGES = 116, EXPECTED_NON_CALL_LANGUAGES = 55, /* 50 no-call + transform-only + unsupported + PDF, AsciiDoc, Diagram */ EXPECTED_NON_CALL_DOMAIN_CONTROLS = 2, diff --git a/tests/test_extraction.c b/tests/test_extraction.c index 041c6db513..384ad9798c 100644 --- a/tests/test_extraction.c +++ b/tests/test_extraction.c @@ -15647,6 +15647,420 @@ TEST(extraction_marker_round_trips_non_ascii_environment_path) { } #endif +/* =================================================================== + * Group I: VB.NET structural extraction + * =================================================================== */ + +TEST(vb_basic_declarations) { + CBMFileResult *r = extract("Namespace DemoApp\n" + " Module MathHelpers\n" + " Function AddOne(x As Integer) As Integer\n" + " Return x + 1\n" + " End Function\n" + " End Module\n" + "\n" + " Class Customer\n" + " Public Property Name As String\n" + " Public Sub Save()\n" + " End Sub\n" + " End Class\n" + "\n" + " Interface IRunnable\n" + " Sub Run()\n" + " End Interface\n" + "\n" + " Enum Status\n" + " Active\n" + " Disabled\n" + " End Enum\n" + "End Namespace\n", + CBM_LANG_VISUALBASIC, "t", "Demo.vb"); + ASSERT_NOT_NULL(r); + ASSERT_FALSE(r->has_error); + ASSERT(has_def(r, "Class", "MathHelpers")); + ASSERT(has_def(r, "Method", "AddOne")); + ASSERT(has_def(r, "Class", "Customer")); + ASSERT(has_def(r, "Field", "Name")); + ASSERT(has_def(r, "Method", "Save")); + ASSERT(has_def(r, "Interface", "IRunnable")); + ASSERT(has_def(r, "Method", "Run")); + ASSERT(has_def(r, "Enum", "Status")); + ASSERT(has_def(r, "Variable", "Active")); + ASSERT(has_def(r, "Variable", "Disabled")); + cbm_free_result(r); + PASS(); +} + +TEST(vb_method_qn_scoped_to_class) { + CBMFileResult *r = extract("Class Customer\n" + " Public Sub Save()\n" + " End Sub\n" + "End Class\n", + CBM_LANG_VISUALBASIC, "t", "Customer.vb"); + ASSERT_NOT_NULL(r); + ASSERT_FALSE(r->has_error); + int found = 0; + for (int i = 0; i < r->defs.count; i++) { + if (strcmp(r->defs.items[i].name, "Save") == 0) { + found = 1; + ASSERT_STR_EQ(r->defs.items[i].label, "Method"); + ASSERT_STR_EQ(r->defs.items[i].qualified_name, "t.Customer.Customer.Save"); + } + } + ASSERT_TRUE(found); + cbm_free_result(r); + PASS(); +} + +TEST(vb_inherits_implements_next_line) { + /* The standard VB.NET form: clauses on their own lines after the header. */ + CBMFileResult *r = extract("Class Manager\n" + " Inherits Employee\n" + " Implements IRunnable, IDisposable\n" + "End Class\n", + CBM_LANG_VISUALBASIC, "t", "Manager.vb"); + ASSERT_NOT_NULL(r); + ASSERT_FALSE(r->has_error); + int found = 0; + for (int i = 0; i < r->defs.count; i++) { + if (strcmp(r->defs.items[i].name, "Manager") == 0) { + found = 1; + ASSERT_NOT_NULL(r->defs.items[i].base_classes); + ASSERT_NOT_NULL(r->defs.items[i].base_classes[0]); + ASSERT_STR_EQ(r->defs.items[i].base_classes[0], "Employee"); + ASSERT_NOT_NULL(r->defs.items[i].base_classes[1]); + ASSERT_STR_EQ(r->defs.items[i].base_classes[1], "IRunnable"); + ASSERT_NOT_NULL(r->defs.items[i].base_classes[2]); + ASSERT_STR_EQ(r->defs.items[i].base_classes[2], "IDisposable"); + } + } + ASSERT_TRUE(found); + cbm_free_result(r); + PASS(); +} + +TEST(vb_qualified_base_dotted_name) { + CBMFileResult *r = extract("Partial Class Form1\n" + " Inherits System.Windows.Forms.Form\n" + "End Class\n", + CBM_LANG_VISUALBASIC, "t", "Form1.Designer.vb"); + ASSERT_NOT_NULL(r); + ASSERT_FALSE(r->has_error); + int found = 0; + for (int i = 0; i < r->defs.count; i++) { + if (strcmp(r->defs.items[i].name, "Form1") == 0) { + found = 1; + ASSERT_NOT_NULL(r->defs.items[i].base_classes); + ASSERT_NOT_NULL(r->defs.items[i].base_classes[0]); + ASSERT_STR_EQ(r->defs.items[i].base_classes[0], "System.Windows.Forms.Form"); + } + } + ASSERT_TRUE(found); + cbm_free_result(r); + PASS(); +} + +TEST(vb_constructor_extracted_as_new) { + CBMFileResult *r = extract("Class Customer\n" + " Public Sub New(name As String)\n" + " End Sub\n" + "End Class\n", + CBM_LANG_VISUALBASIC, "t", "Customer.vb"); + ASSERT_NOT_NULL(r); + ASSERT_FALSE(r->has_error); + ASSERT(has_def(r, "Method", "New")); + cbm_free_result(r); + PASS(); +} + +TEST(vb_calls_bare_member_and_new) { + CBMFileResult *r = extract("Class Svc\n" + " Public Sub Run()\n" + " Validate()\n" + " Dim c As New Customer()\n" + " c.Save(1)\n" + " Me.Helper()\n" + " End Sub\n" + "End Class\n", + CBM_LANG_VISUALBASIC, "t", "Svc.vb"); + ASSERT_NOT_NULL(r); + ASSERT_FALSE(r->has_error); + ASSERT(has_call(r, "Validate")); + ASSERT(has_call(r, "Customer")); /* As New Customer() constructor call */ + ASSERT(has_call(r, "c.Save")); + ASSERT(has_call(r, "Helper")); /* Me.Helper() self-call, receiver stripped */ + cbm_free_result(r); + PASS(); +} + +TEST(vb_region_does_not_break_extraction) { + CBMFileResult *r = extract("Module Helpers\n" + "#Region \"Utils\"\n" + " Sub DoWork()\n" + " End Sub\n" + "#End Region\n" + " Sub After()\n" + " End Sub\n" + "End Module\n", + CBM_LANG_VISUALBASIC, "t", "Helpers.vb"); + ASSERT_NOT_NULL(r); + ASSERT_FALSE(r->has_error); + ASSERT(has_def(r, "Class", "Helpers")); + ASSERT(has_def(r, "Method", "DoWork")); + ASSERT(has_def(r, "Method", "After")); + cbm_free_result(r); + PASS(); +} + +TEST(vb_winforms_designer_shapes) { + /* Designer-generated file shapes: attribute with `_` continuation before + * the class, Partial modifier, WithEvents fields, As New initializers. */ + CBMFileResult *r = extract(" _\n" + "Partial Class Form1\n" + " Inherits System.Windows.Forms.Form\n" + " Private components As System.ComponentModel.IContainer\n" + " Friend WithEvents Button1 As System.Windows.Forms.Button\n" + " Private Sub InitializeComponent()\n" + " Me.Button1 = New System.Windows.Forms.Button()\n" + " Me.SuspendLayout()\n" + " End Sub\n" + "End Class\n", + CBM_LANG_VISUALBASIC, "t", "Form1.Designer.vb"); + ASSERT_NOT_NULL(r); + ASSERT_FALSE(r->has_error); + ASSERT(has_def(r, "Class", "Form1")); + ASSERT(has_def(r, "Method", "InitializeComponent")); + ASSERT(has_def(r, "Field", "components")); + ASSERT(has_def(r, "Field", "Button1")); + cbm_free_result(r); + PASS(); +} + +TEST(vb_handles_and_addhandler_parse) { + /* Handles clause + AddHandler/AddressOf statement must not break parsing; + * the method defs and the AddressOf handler reference must survive. */ + CBMFileResult *r = extract("Class Form1\n" + " Private Sub OnClick(sender As Object, e As EventArgs) Handles Button1.Click\n" + " End Sub\n" + " Private Sub Wire()\n" + " AddHandler Button1.Click, AddressOf OnClick\n" + " End Sub\n" + "End Class\n", + CBM_LANG_VISUALBASIC, "t", "Form1.vb"); + ASSERT_NOT_NULL(r); + ASSERT_FALSE(r->has_error); + ASSERT(has_def(r, "Method", "OnClick")); + ASSERT(has_def(r, "Method", "Wire")); + int handler_usage = 0; + for (int i = 0; i < r->usages.count; i++) { + if (strcmp(r->usages.items[i].ref_name, "OnClick") == 0) { + handler_usage = 1; + } + } + ASSERT_TRUE(handler_usage); + cbm_free_result(r); + PASS(); +} + +TEST(vb_imports_extracted) { + CBMFileResult *r = extract("Imports System.Text\n" + "Imports System.Collections.Generic\n" + "Module M\n" + "End Module\n", + CBM_LANG_VISUALBASIC, "t", "M.vb"); + ASSERT_NOT_NULL(r); + ASSERT_FALSE(r->has_error); + ASSERT(r->imports.count >= 2); + cbm_free_result(r); + PASS(); +} + +TEST(vb_nested_class_extracted) { + CBMFileResult *r = extract("Class Outer\n" + " Class Inner\n" + " Public Sub Go()\n" + " End Sub\n" + " End Class\n" + "End Class\n", + CBM_LANG_VISUALBASIC, "t", "Outer.vb"); + ASSERT_NOT_NULL(r); + ASSERT_FALSE(r->has_error); + ASSERT(has_def(r, "Class", "Outer")); + ASSERT(has_def(r, "Class", "Inner")); + ASSERT(has_def(r, "Method", "Go")); + cbm_free_result(r); + PASS(); +} + +/* Number of calls whose callee is exactly `callee` (has_call matches a + * substring, which cannot tell "System" from "System.Windows.Forms.Button"). */ +static int vb_call_count_exact(CBMFileResult *r, const char *callee) { + int n = 0; + for (int i = 0; i < r->calls.count; i++) { + if (r->calls.items[i].callee_name && strcmp(r->calls.items[i].callee_name, callee) == 0) { + n++; + } + } + return n; +} + +/* The grammar reads `New A.B.C()` as `New A` plus member accesses; the call + * names the whole type, and the `New A` prefix is no call of its own. Without + * an argument list no call encloses the chain, so the prefix names it. */ +TEST(vb_new_dotted_type_is_one_constructor_call) { + CBMFileResult *r = extract("Class Form1\n" + " Private Sub InitializeComponent()\n" + " Me.Button1 = New System.Windows.Forms.Button()\n" + " Me.ClientSize = New System.Drawing.Size(284, 261)\n" + " components = New System.ComponentModel.Container\n" + " End Sub\n" + "End Class\n", + CBM_LANG_VISUALBASIC, "t", "Form1.Designer.vb"); + ASSERT_NOT_NULL(r); + ASSERT_FALSE(r->has_error); + ASSERT_EQ(vb_call_count_exact(r, "System.Windows.Forms.Button"), 1); + ASSERT_EQ(vb_call_count_exact(r, "System.Drawing.Size"), 1); + ASSERT_EQ(vb_call_count_exact(r, "System.ComponentModel.Container"), 1); + ASSERT_EQ(vb_call_count_exact(r, "System"), 0); + cbm_free_result(r); + PASS(); +} + +/* A call with arguments parses as array_access_expression (VB writes calls + * and indexing alike; coverage from #2885), and the Me/MyClass receiver is + * matched by node kind, so its spelling does not matter. */ +TEST(vb_calls_with_arguments_and_any_case_receiver) { + CBMFileResult *r = extract("Class Svc\n" + " Public Sub Run()\n" + " Dim x = Compute(1, 2)\n" + " me.Helper()\n" + " MYCLASS.Other(x)\n" + " End Sub\n" + "End Class\n", + CBM_LANG_VISUALBASIC, "t", "Svc.vb"); + ASSERT_NOT_NULL(r); + ASSERT_FALSE(r->has_error); + ASSERT_EQ(vb_call_count_exact(r, "Compute"), 1); + ASSERT_EQ(vb_call_count_exact(r, "Helper"), 1); + ASSERT_EQ(vb_call_count_exact(r, "Other"), 1); + cbm_free_result(r); + PASS(); +} + +/* `Dim a, b As Integer`: every name before an As clause takes its type, and + * `As New List(Of String)()` names the constructed type. */ +TEST(vb_field_types_from_as_clauses) { + CBMFileResult *r = extract("Class Holder\n" + " Dim a, b As Integer\n" + " Private items As New List(Of String)()\n" + "End Class\n", + CBM_LANG_VISUALBASIC, "t", "Holder.vb"); + ASSERT_NOT_NULL(r); + ASSERT_FALSE(r->has_error); + int typed = 0; + for (int i = 0; i < r->defs.count; i++) { + const CBMDefinition *d = &r->defs.items[i]; + if (strcmp(d->label, "Field") != 0 || !d->return_type) { + continue; + } + if ((strcmp(d->name, "a") == 0 || strcmp(d->name, "b") == 0) && + strcmp(d->return_type, "Integer") == 0) { + typed++; + } + if (strcmp(d->name, "items") == 0 && strcmp(d->return_type, "List") == 0) { + typed++; + } + } + ASSERT_EQ(typed, 3); + cbm_free_result(r); + PASS(); +} + +/* Imports with and without an alias (coverage from #2885). */ +TEST(vb_imports_alias_and_path) { + CBMFileResult *r = extract("Imports System.Text\n" + "Imports Col = System.Collections.Generic\n" + "Module M\n" + "End Module\n", + CBM_LANG_VISUALBASIC, "t", "M.vb"); + ASSERT_NOT_NULL(r); + ASSERT_FALSE(r->has_error); + int text = 0; + int aliased = 0; + for (int i = 0; i < r->imports.count; i++) { + const CBMImport *imp = &r->imports.items[i]; + if (strcmp(imp->module_path, "System.Text") == 0 && strcmp(imp->local_name, "Text") == 0) { + text++; + } + if (strcmp(imp->module_path, "System.Collections.Generic") == 0 && + strcmp(imp->local_name, "Col") == 0) { + aliased++; + } + } + ASSERT_EQ(text, 1); + ASSERT_EQ(aliased, 1); + cbm_free_result(r); + PASS(); +} + +/* Interface members, MustOverride members and a type nested in a type. */ +TEST(vb_interface_abstract_and_nested_members) { + CBMFileResult *r = extract("Public Interface IShape\n" + " Function Area() As Double\n" + "End Interface\n" + "Public MustInherit Class Shape\n" + " Implements IShape\n" + " Public MustOverride Function Area() As Double Implements " + "IShape.Area\n" + " Public Class Unit\n" + " Public Sub Scale()\n" + " End Sub\n" + " End Class\n" + "End Class\n", + CBM_LANG_VISUALBASIC, "t", "Shape.vb"); + ASSERT_NOT_NULL(r); + ASSERT_FALSE(r->has_error); + ASSERT(has_def(r, "Interface", "IShape")); + ASSERT(has_def_qn(r, "t.Shape.IShape.Area")); + ASSERT(has_def_qn(r, "t.Shape.Shape.Area")); + ASSERT(has_def(r, "Class", "Unit")); + ASSERT(has_def(r, "Method", "Scale")); + cbm_free_result(r); + PASS(); +} + +/* is_test of the Method `Run` the source below defines, extracted as `path`; + * -1 when no such Method was extracted. */ +static int vb_run_method_is_test(const char *path) { + CBMFileResult *r = extract("Public Class OrderTests\n" + " Public Sub Run()\n" + " End Sub\n" + "End Class\n", + CBM_LANG_VISUALBASIC, "t", path); + int verdict = -1; + for (int i = 0; r && i < r->defs.count; i++) { + const CBMDefinition *d = &r->defs.items[i]; + if (strcmp(d->label, "Method") == 0 && strcmp(d->name, "Run") == 0) { + verdict = d->is_test ? 1 : 0; + } + } + if (r) { + cbm_free_result(r); + } + return verdict; +} + +/* *Test.vb / *Tests.vb are test files (from #2885), and that verdict reaches + * the methods they define: the registry ranks on it (#2427). */ +TEST(vb_test_file_names) { + ASSERT_TRUE(cbm_is_test_file("src/OrderTests.vb", CBM_LANG_VISUALBASIC)); + ASSERT_TRUE(cbm_is_test_file("src/OrderTest.vb", CBM_LANG_VISUALBASIC)); + ASSERT_FALSE(cbm_is_test_file("src/Order.vb", CBM_LANG_VISUALBASIC)); + ASSERT_EQ(vb_run_method_is_test("src/OrderTests.vb"), 1); + ASSERT_EQ(vb_run_method_is_test("src/Order.vb"), 0); + PASS(); +} + SUITE(extraction) { #ifdef _WIN32 RUN_TEST(extraction_marker_round_trips_non_ascii_environment_path); @@ -15728,6 +16142,25 @@ SUITE(extraction) { RUN_TEST(call_args_skip_comments_between_arguments); RUN_TEST(objectscript_data_flows_class_method_args); RUN_TEST(objectscript_data_flows_instance_method_args); + + /* Group I: VB.NET structural extraction */ + RUN_TEST(vb_basic_declarations); + RUN_TEST(vb_method_qn_scoped_to_class); + RUN_TEST(vb_inherits_implements_next_line); + RUN_TEST(vb_qualified_base_dotted_name); + RUN_TEST(vb_constructor_extracted_as_new); + RUN_TEST(vb_calls_bare_member_and_new); + RUN_TEST(vb_region_does_not_break_extraction); + RUN_TEST(vb_winforms_designer_shapes); + RUN_TEST(vb_handles_and_addhandler_parse); + RUN_TEST(vb_imports_extracted); + RUN_TEST(vb_nested_class_extracted); + RUN_TEST(vb_new_dotted_type_is_one_constructor_call); + RUN_TEST(vb_calls_with_arguments_and_any_case_receiver); + RUN_TEST(vb_field_types_from_as_clauses); + RUN_TEST(vb_imports_alias_and_path); + RUN_TEST(vb_interface_abstract_and_nested_members); + RUN_TEST(vb_test_file_names); RUN_TEST(iris_export_xml_simple_class); RUN_TEST(iris_export_xml_classmethod); RUN_TEST(iris_export_xml_property_parameter_index); diff --git a/tests/test_grammar_labels.c b/tests/test_grammar_labels.c index be28a0687d..0dfb060523 100644 --- a/tests/test_grammar_labels.c +++ b/tests/test_grammar_labels.c @@ -94,6 +94,7 @@ static const LabelGolden LABEL_GOLDENS[] = { {"php", "Class:1,Function:1,Module:1"}, {"c_sharp", "Class:1,Method:1,Module:1"}, {"csharp_extension_declaration", "Class:1,Method:1,Module:1"}, + {"visualbasic", "Class:1,Method:1,Module:1"}, {"bash", "Function:2,Module:1"}, {"zsh", "Function:2,Module:1"}, {"lua", "Function:2,Module:1"}, diff --git a/tests/test_grammar_regression.c b/tests/test_grammar_regression.c index 7a02468a60..06929e72d5 100644 --- a/tests/test_grammar_regression.c +++ b/tests/test_grammar_regression.c @@ -162,6 +162,12 @@ const GrammarCase CBM_GRAMMAR_CASES[] = { "}\n", 2, {"NumberExtensions", "SumPositive", NULL}}, + {"visualbasic", + CBM_LANG_VISUALBASIC, + "A.vb", + "Class A\n Public Sub Foo()\n End Sub\nEnd Class\n", + 2, + {"A", "Foo", NULL}}, {"bash", CBM_LANG_BASH, "a.sh", diff --git a/tests/test_lang_contract.c b/tests/test_lang_contract.c index ff333410b0..d98c71435f 100644 --- a/tests/test_lang_contract.c +++ b/tests/test_lang_contract.c @@ -743,6 +743,157 @@ TEST(contract_chialisp_constant_resolves_across_files) { PASS(); } +/* Edges of `type` from any node named `src_name` to a node named `dst_name`. */ +static int edges_between_names(cbm_store_t *store, const char *project, const char *src_name, + const char *type, const char *dst_name) { + cbm_node_t *srcs = NULL; + int nsrc = 0; + if (cbm_store_find_nodes_by_name(store, project, src_name, &srcs, &nsrc) != CBM_STORE_OK) { + return -1; + } + int found = 0; + for (int i = 0; i < nsrc; i++) { + cbm_edge_t *edges = NULL; + int nedges = 0; + if (cbm_store_find_edges_by_source_type(store, srcs[i].id, type, &edges, &nedges) != + CBM_STORE_OK) { + continue; + } + for (int j = 0; j < nedges; j++) { + cbm_node_t dst; + if (cbm_store_find_node_by_id(store, edges[j].target_id, &dst) != CBM_STORE_OK) { + continue; + } + if (dst.name && strcmp(dst.name, dst_name) == 0) { + found++; + } + cbm_node_free_fields(&dst); + } + cbm_store_free_edges(edges, nedges); + } + cbm_store_free_nodes(srcs, nsrc); + return found; +} + +/* VB.NET, WinForms-shaped: a partial Form split across Form1.vb and its + * Form1.Designer.vb, a service behind an interface, a derived service. + * Graph level: IMPLEMENTS vs INHERITS by the base's label, the Handles + * clause reaching the WithEvents control declared in the other half of the + * partial class, a call across files, and a call written in another case + * (VB.NET names are case-insensitive). */ +TEST(contract_visualbasic_winforms_graph) { + static const LangFile f[] = { + {"Form1.Designer.vb", "Partial Class Form1\n" + " Inherits System.Windows.Forms.Form\n" + " Friend WithEvents SaveButton As System.Windows.Forms.Button\n" + " Private Sub InitializeComponent()\n" + " Me.SaveButton = New System.Windows.Forms.Button()\n" + " End Sub\n" + "End Class\n"}, + {"Form1.vb", "Public Class Form1\n" + " Private ReadOnly service As New CustomerService()\n" + " Private Sub SaveButton_Click(sender As Object, e As EventArgs) " + "Handles SaveButton.Click\n" + " service.Save(\"x\")\n" + " UPDATETITLE()\n" + " End Sub\n" + " Private Sub UpdateTitle()\n" + " End Sub\n" + "End Class\n"}, + {"CustomerService.vb", "Public Interface ICustomerStore\n" + " Sub Save(name As String)\n" + "End Interface\n" + "Public Class CustomerService\n" + " Implements ICustomerStore\n" + " Public Sub Save(name As String) Implements ICustomerStore.Save\n" + " End Sub\n" + "End Class\n" + "Public Class PremiumService\n" + " Inherits CustomerService\n" + "End Class\n"}}; + LangProj lp; + cbm_store_t *store = lang_index_files(&lp, f, 3); + ASSERT_TRUE(store != NULL); + int implements = + edges_between_names(store, lp.project, "CustomerService", "IMPLEMENTS", "ICustomerStore"); + int inherits = + edges_between_names(store, lp.project, "PremiumService", "INHERITS", "CustomerService"); + int handles = edges_between_names(store, lp.project, "SaveButton_Click", "USAGE", "SaveButton"); + int cross_call = edges_between_names(store, lp.project, "SaveButton_Click", "CALLS", "Save"); + int folded_call = + edges_between_names(store, lp.project, "SaveButton_Click", "CALLS", "UpdateTitle"); + lang_cleanup(&lp, store); + ASSERT_TRUE(implements >= 1); + ASSERT_TRUE(inherits >= 1); + ASSERT_TRUE(handles >= 1); + ASSERT_TRUE(cross_call >= 1); + ASSERT_TRUE(folded_call >= 1); + PASS(); +} + +/* VB.NET writes indexing like a call. `items(0)` and `Me.cache("k")` index a + * Field: the method references it (a USAGE, as C#'s `items[0]` does) and + * calls nothing, while `Compute(1)` stays a call. */ +TEST(contract_visualbasic_indexing_is_a_field_usage) { + static const LangFile f[] = {{"Worker.vb", "Public Class Worker\n" + " Private items As New List(Of String)()\n" + " Private cache As Dictionary(Of String, Integer)\n" + " Public Sub Indexed()\n" + " Dim x = items(0)\n" + " Dim y = Me.cache(\"k\")\n" + " Compute(1)\n" + " End Sub\n" + " Private Function Compute(v As Integer) As Integer\n" + " Return v\n" + " End Function\n" + "End Class\n"}}; + LangProj lp; + cbm_store_t *store = lang_index_files(&lp, f, 1); + ASSERT_TRUE(store != NULL); + int items_usage = edges_between_names(store, lp.project, "Indexed", "USAGE", "items"); + int cache_usage = edges_between_names(store, lp.project, "Indexed", "USAGE", "cache"); + int items_call = edges_between_names(store, lp.project, "Indexed", "CALLS", "items"); + int cache_call = edges_between_names(store, lp.project, "Indexed", "CALLS", "cache"); + int compute_call = edges_between_names(store, lp.project, "Indexed", "CALLS", "Compute"); + int compute_usage = edges_between_names(store, lp.project, "Indexed", "USAGE", "Compute"); + lang_cleanup(&lp, store); + ASSERT_EQ(items_usage, 1); + ASSERT_EQ(cache_usage, 1); + ASSERT_EQ(items_call, 0); + ASSERT_EQ(cache_call, 0); + ASSERT_EQ(compute_call, 1); + ASSERT_EQ(compute_usage, 0); + PASS(); +} + +/* An enum member is never called. `Refresh()` in a Form calls the framework's + * Form.Refresh; the only `Refresh` the project defines is an enum member, + * which the short-name registry would hand back. No CALLS edge may land on + * it, while `Draw()` stays a call. */ +TEST(contract_visualbasic_call_never_lands_on_enum_member) { + static const LangFile f[] = {{"Symbols.vb", "Public Enum Symbol\n" + " Refresh\n" + " Save\n" + "End Enum\n"}, + {"MainForm.vb", "Public Class MainForm\n" + " Public Sub Reload()\n" + " Refresh()\n" + " Draw()\n" + " End Sub\n" + " Private Sub Draw()\n" + " End Sub\n" + "End Class\n"}}; + LangProj lp; + cbm_store_t *store = lang_index_files(&lp, f, 2); + ASSERT_TRUE(store != NULL); + int enum_call = edges_between_names(store, lp.project, "Reload", "CALLS", "Refresh"); + int method_call = edges_between_names(store, lp.project, "Reload", "CALLS", "Draw"); + lang_cleanup(&lp, store); + ASSERT_EQ(enum_call, 0); + ASSERT_EQ(method_call, 1); + PASS(); +} + TEST(contract_all_grammars_in_graph) { int n = (int)CBM_GRAMMAR_CASES_COUNT; if (n > GRAMMAR_BREADTH_MAX) { @@ -1947,6 +2098,9 @@ SUITE(lang_contract) { /* Graph-level breadth across all grammars (P4). */ RUN_TEST(contract_chialisp_constant_resolves_across_files); + RUN_TEST(contract_visualbasic_winforms_graph); + RUN_TEST(contract_visualbasic_indexing_is_a_field_usage); + RUN_TEST(contract_visualbasic_call_never_lands_on_enum_member); RUN_TEST(contract_all_grammars_in_graph); /* CALLS-edge breadth across non-LSP languages (P5). */ diff --git a/tests/test_language.c b/tests/test_language.c index 56a0f829c2..b4247d636f 100644 --- a/tests/test_language.c +++ b/tests/test_language.c @@ -104,6 +104,11 @@ TEST(lang_ext_cshtml) { ASSERT_EQ(cbm_language_for_extension(".cshtml"), CBM_LANG_CSHARP); PASS(); } +TEST(lang_ext_visualbasic) { + ASSERT_EQ(cbm_language_for_extension(".vb"), CBM_LANG_VISUALBASIC); + ASSERT_EQ(cbm_language_for_filename("Form1.Designer.vb"), CBM_LANG_VISUALBASIC); + PASS(); +} TEST(lang_ext_php) { ASSERT_EQ(cbm_language_for_extension(".php"), CBM_LANG_PHP); PASS(); @@ -650,6 +655,10 @@ TEST(lang_name_csharp) { ASSERT_STR_EQ(cbm_language_name(CBM_LANG_CSHARP), "C#"); PASS(); } +TEST(lang_name_visualbasic) { + ASSERT_STR_EQ(cbm_language_name(CBM_LANG_VISUALBASIC), "VB.NET"); + PASS(); +} TEST(lang_name_unknown) { ASSERT_STR_EQ(cbm_language_name(CBM_LANG_COUNT), "Unknown"); PASS(); @@ -1684,6 +1693,7 @@ SUITE(language) { RUN_TEST(lang_ext_csharp); RUN_TEST(lang_ext_razor); RUN_TEST(lang_ext_cshtml); + RUN_TEST(lang_ext_visualbasic); RUN_TEST(lang_ext_php); RUN_TEST(lang_ext_lua); RUN_TEST(lang_ext_scala); @@ -1815,6 +1825,7 @@ SUITE(language) { RUN_TEST(lang_name_python); RUN_TEST(lang_name_cpp); RUN_TEST(lang_name_csharp); + RUN_TEST(lang_name_visualbasic); RUN_TEST(lang_name_unknown); /* .m disambiguation */ diff --git a/tests/test_registry.c b/tests/test_registry.c index 2baa5819a8..ed50ed9d8f 100644 --- a/tests/test_registry.c +++ b/tests/test_registry.c @@ -847,6 +847,81 @@ TEST(resolve_unresolved) { PASS(); } +/* VB.NET names are case-insensitive: a call spelled CALCULATE reaches the + * Calculate method (shape from #2885). */ +TEST(visual_basic_call_resolution_is_case_insensitive) { + cbm_registry_t *r = cbm_registry_new(); + ASSERT_NOT_NULL(r); + cbm_registry_add_lang(r, "Calculate", "proj.Worker.Calculate", "Method", + CBM_LANG_VISUALBASIC, false); + cbm_resolution_t res = + cbm_registry_resolve_call_scoped(r, "CALCULATE", "proj.Worker", NULL, NULL, 0, + CBM_LANG_VISUALBASIC, "proj.Worker.Run", false); + ASSERT_NOT_NULL(res.qualified_name); + ASSERT_STR_EQ(res.qualified_name, "proj.Worker.Calculate"); + /* Every segment of a qualified callee is respelled, not only the last. */ + cbm_registry_add_lang(r, "Helpers", "proj.Helpers.Helpers", "Class", CBM_LANG_VISUALBASIC, + false); + cbm_registry_add_lang(r, "Format", "proj.Helpers.Helpers.Format", "Method", + CBM_LANG_VISUALBASIC, false); + res = cbm_registry_resolve_lang(r, "helpers.format", "proj.Worker", NULL, NULL, 0, + CBM_LANG_VISUALBASIC); + ASSERT_NOT_NULL(res.qualified_name); + ASSERT_STR_EQ(res.qualified_name, "proj.Helpers.Helpers.Format"); + cbm_registry_free(r); + PASS(); +} + +/* References (USAGE, READS, WRITES) fold as calls do: they resolve through + * cbm_registry_resolve_ref, for production and test code alike. */ +TEST(visual_basic_reference_resolution_is_case_insensitive) { + cbm_registry_t *r = cbm_registry_new(); + ASSERT_NOT_NULL(r); + cbm_registry_add_lang(r, "Helpers", "proj.Helpers.Helpers", "Class", CBM_LANG_VISUALBASIC, + false); + cbm_resolution_t res = cbm_registry_resolve_ref(r, "helpers", "proj.Worker", NULL, NULL, 0, + CBM_LANG_VISUALBASIC, false); + ASSERT_NOT_NULL(res.qualified_name); + ASSERT_STR_EQ(res.qualified_name, "proj.Helpers.Helpers"); + res = cbm_registry_resolve_ref(r, "HELPERS", "proj.WorkerTests", NULL, NULL, 0, + CBM_LANG_VISUALBASIC, true); + ASSERT_NOT_NULL(res.qualified_name); + ASSERT_STR_EQ(res.qualified_name, "proj.Helpers.Helpers"); + cbm_registry_free(r); + PASS(); +} + +/* The folded retry runs only when the spelling as written finds nothing, so + * an exact spelling keeps its own target. */ +TEST(visual_basic_exact_spelling_wins) { + cbm_registry_t *r = cbm_registry_new(); + ASSERT_NOT_NULL(r); + cbm_registry_add_lang(r, "run", "proj.Lower.run", "Method", CBM_LANG_VISUALBASIC, false); + cbm_registry_add_lang(r, "RUN", "proj.Upper.RUN", "Method", CBM_LANG_VISUALBASIC, false); + cbm_resolution_t res = + cbm_registry_resolve_lang(r, "RUN", "proj.Upper", NULL, NULL, 0, CBM_LANG_VISUALBASIC); + ASSERT_NOT_NULL(res.qualified_name); + ASSERT_STR_EQ(res.qualified_name, "proj.Upper.RUN"); + cbm_registry_free(r); + PASS(); +} + +/* Only VB.NET folds: C# stays case-sensitive, even next to VB.NET symbols. */ +TEST(case_folding_is_visual_basic_only) { + cbm_registry_t *r = cbm_registry_new(); + ASSERT_NOT_NULL(r); + cbm_registry_add_lang(r, "Calculate", "proj.Worker.Calculate", "Method", CBM_LANG_CSHARP, + false); + cbm_registry_add_lang(r, "Total", "proj.Vb.Total", "Method", CBM_LANG_VISUALBASIC, false); + cbm_resolution_t res = + cbm_registry_resolve_lang(r, "CALCULATE", "proj.Worker", NULL, NULL, 0, CBM_LANG_CSHARP); + ASSERT_TRUE(res.qualified_name == NULL || res.qualified_name[0] == '\0'); + res = cbm_registry_resolve_lang(r, "total", "proj.Worker", NULL, NULL, 0, CBM_LANG_CSHARP); + ASSERT_TRUE(res.qualified_name == NULL || res.qualified_name[0] == '\0'); + cbm_registry_free(r); + PASS(); +} + TEST(resolve_many_nodes) { cbm_registry_t *r = cbm_registry_new(); /* Add 500 functions */ @@ -1912,6 +1987,12 @@ TEST(call_onto_field_follows_language_and_shape) { /* The same language as the Field keeps its resolution too. */ ASSERT_EQ(cbm_call_onto_field_policy(CBM_LANG_GO, "s.fn", "Field", "pkg/s.go"), CBM_FIELD_CALL_KEEP); + /* VB.NET writes indexing like a call: `items(0)` on a Field references it + * (a USAGE, as C#'s `items[0]`), it calls nothing. */ + ASSERT_EQ(cbm_call_onto_field_policy(CBM_LANG_VISUALBASIC, "items", "Field", "src/Form1.vb"), + CBM_FIELD_CALL_AS_USAGE); + ASSERT_EQ(cbm_call_onto_field_policy(CBM_LANG_VISUALBASIC, "Run", "Method", "src/Form1.vb"), + CBM_FIELD_CALL_KEEP); /* Not a Field target: not this rule's business. */ ASSERT_EQ(cbm_call_onto_field_policy(CBM_LANG_BASH, "main", "Function", "src/main.c"), CBM_FIELD_CALL_KEEP); @@ -2022,6 +2103,18 @@ TEST(java_call_never_binds_data_member) { PASS(); } +/* The language gate both call resolvers share: Java, and VB.NET (whose + * Variables are enum members, never called). Languages with callable data + * keep their binds. */ +TEST(call_never_names_data_gate) { + ASSERT_TRUE(cbm_call_never_names_data(CBM_LANG_JAVA)); + ASSERT_TRUE(cbm_call_never_names_data(CBM_LANG_VISUALBASIC)); + ASSERT_FALSE(cbm_call_never_names_data(CBM_LANG_KOTLIN)); + ASSERT_FALSE(cbm_call_never_names_data(CBM_LANG_C)); + ASSERT_FALSE(cbm_call_never_names_data(CBM_LANG_CSHARP)); + PASS(); +} + TEST(generated_member_registers_by_qn_only) { /* A generated member (a Java record's implicit accessor) is found by its * qualified name, never by a short-name guess. The same member registered @@ -3655,6 +3748,10 @@ SUITE(registry) { RUN_TEST(resolve_unique_name); RUN_TEST(resolve_qualified_receiver_awareness); RUN_TEST(resolve_unresolved); + RUN_TEST(visual_basic_call_resolution_is_case_insensitive); + RUN_TEST(visual_basic_reference_resolution_is_case_insensitive); + RUN_TEST(visual_basic_exact_spelling_wins); + RUN_TEST(case_folding_is_visual_basic_only); RUN_TEST(resolve_many_nodes); /* Confidence band */ RUN_TEST(confidence_band_high); @@ -3709,6 +3806,7 @@ SUITE(registry) { RUN_TEST(c_member_access_binds_by_owner_only); RUN_TEST(c_member_rule_covers_c_files_and_every_dot_h); RUN_TEST(java_call_never_binds_data_member); + RUN_TEST(call_never_names_data_gate); RUN_TEST(generated_member_registers_by_qn_only); RUN_TEST(generated_member_mark_on_defs_and_nodes); RUN_TEST(dynamic_suppress_drops_weak_method_matches); diff --git a/tests/test_userconfig.c b/tests/test_userconfig.c index 10eacec1b9..f066e3b302 100644 --- a/tests/test_userconfig.c +++ b/tests/test_userconfig.c @@ -55,6 +55,31 @@ TEST(userconfig_project_basic) { PASS(); } +/* `vb` and `visualbasic` name VB.NET (VB6 keeps its own name), as do the + * language's own spellings; names match regardless of case. */ +TEST(userconfig_visualbasic_aliases) { + char dir[256]; + snprintf(dir, sizeof(dir), "%s/uctest_vb_aliases", cbm_tmpdir()); + cbm_mkdir_p(dir, 0755); + + char proj[512]; + snprintf(proj, sizeof(proj), "%s/.codebase-memory.json", dir); + ASSERT_EQ(write_json(proj, "{\"extra_extensions\":{\".vbx1\":\"vb\",\".vbx2\":\"visualbasic\"," + "\".vbx3\":\"VB.NET\",\".vbx4\":\"vbnet\"}}"), + 0); + + cbm_userconfig_t *cfg = cbm_userconfig_load(dir); + ASSERT_NOT_NULL(cfg); + ASSERT_EQ(cbm_userconfig_lookup(cfg, ".vbx1"), CBM_LANG_VISUALBASIC); + ASSERT_EQ(cbm_userconfig_lookup(cfg, ".vbx2"), CBM_LANG_VISUALBASIC); + ASSERT_EQ(cbm_userconfig_lookup(cfg, ".vbx3"), CBM_LANG_VISUALBASIC); + ASSERT_EQ(cbm_userconfig_lookup(cfg, ".vbx4"), CBM_LANG_VISUALBASIC); + + cbm_userconfig_free(cfg); + remove(proj); + PASS(); +} + /* ── Tests: global config ────────────────────────────────────────── */ TEST(userconfig_global_via_env) { @@ -406,6 +431,7 @@ SUITE(userconfig) { RUN_TEST(userconfig_source_unavailable_clears_views); RUN_TEST(userconfig_project_basic); + RUN_TEST(userconfig_visualbasic_aliases); RUN_TEST(userconfig_global_via_env); RUN_TEST(userconfig_project_wins_over_global); RUN_TEST(userconfig_unknown_lang_skipped);