Skip to content

C++ extraction: C++/CLI files and nested C++ types lose their symbols #2876

Closed

Description

@MatejBorovinsek

C++ extraction: C++/CLI files and nested C++ types lose their symbols

graphify 0.9.47 · Python 3.12.10 · tree-sitter 0.25.2 · tree-sitter-cpp 0.23.4 · Windows

Two independent gaps in the C++ extractor, both hit by a .NET interop wrapper (a 141-method C++/CLI
class extracted 12 symbols). Happy to split into two issues.

Reproducer for both — _get_extractor(p)(p), labels shown verbatim:

1. C++/CLI is unparseable, and the failure takes the whole class body with it

// cli.h
namespace N {
    public ref class Wrapper
    {
    public:
        static void Init() { }
        static System::String^ Name() { return gcnew System::String(""); }
    };
}
parse_errors={'first_error_line': 2, 'multiline_error': False}
labels=['cli.h', 'Wrapper()', 'public']

tree-sitter-cpp implements none of ref class, Type^, Type%, gcnew, [assembly:...]. Because the
ERROR lands on the type header, everything inside dissolves and recovery invents Wrapper() / public.
Expected: Wrapper, .Init(), .Name().

2. Nested C++ types are dropped — silently, in plain C++

// nested.h
namespace N {
    class Outer
    {
    public:
        class Inner
        {
        public:
            static void Method() { }
        };
    };
}
parse_errors=None
labels=['nested.h', 'Outer']

No parse error and no warning — Inner and everything in it are simply gone. Cause: a nested type is a
field_declaration whose type field is the class_specifier, and the C++ member-variable branch in
extractors/engine.py (config.ts_module == "tree_sitter_cpp" and t == "field_declaration") consumes the
node and returns before the walk can descend. The engine already supports nested classes for other
languages (is_nested_type, the contains edge).

Fix I'm running locally

Both patched against 0.9.47, giving ['cli.h', 'Wrapper', '.Init()', '.Name()', 'String'] and
['nested.h', 'Outer', 'Inner', '.Method()']:

  1. A source_override for extract_cpp that normalizes C++/CLI to the nearest standard C++ spelling.
    It is byte-length preserving (removed tokens overwritten with spaces, never deleted), so every
    offset, line and column still points at the same place in the file on disk, and it only engages on
    files carrying a CLI marker — plain C/C++/CUDA parses byte-for-byte as before.
  2. In that field_declaration branch, descend into a class_specifier type field with parent_class_nid
    threaded through, returning unless a member is declared alongside it (class Inner { } inst;).

On a 1475-file repo this took GmshCommon.h from 13 nodes to 116 (107 methods, 8 nested classes) with no
change elsewhere. Glad to open a PR if the approach looks right.

Unrelated, one line

--force doesn't invalidate graphify-out/cache/ast/<version>, so any extractor change is masked until
that directory is deleted by hand — worth a flag or a note.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions