auryn-cpp 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,43 @@
1
+ """Import-light C++ language registration -- the `auryn.languages` entry-point target.
2
+
3
+ Importing this module registers the C++ GitLanguage without importing tree-sitter: the
4
+ GitLanguage's `sync` is a lazy thunk that imports auryn.ingestors.cpp.git_sync only when a
5
+ source actually contains C++ files. Single-phase today (fast tree-sitter-cpp); a deep libclang
6
+ pass -- template instantiation, overload resolution, ADL, precise header<->source linking,
7
+ cross-TU calls (needing a compile_commands.json) -- would slot in here as `deep_sync` (making
8
+ C++ two-phase like Python). Suffix/exclude constants live here (single source of truth);
9
+ git_sync imports them back.
10
+
11
+ SUFFIX SPLIT WITH THE C INGESTOR: the C plugin already claims `.c` and `.h`, so this plugin
12
+ claims ONLY unambiguous C++ suffixes and leaves `.c`/`.h` to C. Known limitation: a C++ project
13
+ that puts class declarations in `.h` headers (rather than `.hpp`) won't get those headers'
14
+ classes extracted here -- they're routed to the C ingestor, which has no class model. Projects
15
+ using `.hpp`/`.hh`/... for headers are fully covered."""
16
+
17
+ from __future__ import annotations
18
+
19
+ from auryn.core.registry import GitLanguage, register_git_language
20
+
21
+ LANGUAGE = "cpp"
22
+ # Only unambiguous C++ suffixes -- `.c`/`.h` stay with the C ingestor (see the module docstring).
23
+ FILE_SUFFIXES = (".cpp", ".cc", ".cxx", ".c++", ".hpp", ".hh", ".hxx", ".h++", ".ipp", ".tpp", ".inl")
24
+ EXCLUDED_DIR_NAMES = frozenset(
25
+ {".git", "build", "cmake-build-debug", "node_modules", "vendor", "third_party", "external", "out"}
26
+ )
27
+
28
+
29
+ def _sync(*args, **kwargs):
30
+ """Deferred until a source has C++ files -- imports the tree-sitter-cpp engine."""
31
+ from auryn.ingestors.cpp.git_sync import _git_language_sync
32
+
33
+ return _git_language_sync(*args, **kwargs)
34
+
35
+
36
+ register_git_language(
37
+ GitLanguage(
38
+ language=LANGUAGE,
39
+ file_suffixes=FILE_SUFFIXES,
40
+ excluded_dir_names=EXCLUDED_DIR_NAMES,
41
+ sync=_sync,
42
+ )
43
+ )
@@ -0,0 +1,136 @@
1
+ """Picklable dataclasses produced by file_parser (phase-1, per-file, no shared state -- safe
2
+ under a ProcessPoolExecutor). No tree-sitter node ever crosses this boundary; resolution.py
3
+ turns these into graph nodes/edges once every file has been parsed.
4
+
5
+ Everything here is what a single tree-sitter parse of one C++ translation unit can know on its
6
+ own -- names, types-as-written (text), storage/virtual/const flags, base clauses, template
7
+ parameters, call *names* (with receiver/scope). Cross-file decisions (does a base name a
8
+ project type? which class owns this out-of-line `Class::method` definition? does this call
9
+ resolve to a project method or free function?) are made later, in resolution.py, where all
10
+ files are visible at once.
11
+
12
+ Modelled after the union of the C ingestor (free functions/records/enums/macros/includes) and
13
+ the Java ingestor (types-with-members, hierarchy). line_start/line_end are 1-based inclusive
14
+ (from tree-sitter node positions), matching the C/Java/Python ingestors; 0 means not captured."""
15
+
16
+ from __future__ import annotations
17
+
18
+ from dataclasses import dataclass, field
19
+
20
+
21
+ @dataclass
22
+ class RawParameter:
23
+ name: str # "" for an unnamed prototype parameter
24
+ type: str # type as written, e.g. "int", "const Shape *", "Point"
25
+ position: int
26
+
27
+
28
+ @dataclass
29
+ class RawCall:
30
+ name: str # the callee's simple name (function/method name, or the created type for `new`)
31
+ receiver: str | None = None
32
+ """The receiver's own simple name for `obj.m()` / `ptr->m()` / `this->m()` ("obj", "ptr",
33
+ "this"), or None for a bare `foo()`, a `Class::m()` qualified call, or a receiver too
34
+ complex to name. resolution.py uses it to prefer resolving against a field's/param's
35
+ declared type."""
36
+ scope: str | None = None # the last scope segment of a qualified call `A::B::stat()` -> "B"
37
+ is_new: bool = False # `new Widget()` -> resolves against Widget's constructor
38
+
39
+
40
+ @dataclass
41
+ class RawMethod:
42
+ name: str # ctor == class name; dtor == "~Class"
43
+ kind: str # "ORDINARY" | "CONSTRUCTOR" | "DESTRUCTOR"
44
+ return_type: str | None = None # None for ctor/dtor
45
+ params: list[RawParameter] = field(default_factory=list)
46
+ is_static: bool = False
47
+ is_virtual: bool = False
48
+ is_const: bool = False
49
+ is_definition: bool = False # True = has a body (inline, or an out-of-line def)
50
+ calls: list[RawCall] = field(default_factory=list) # from the body (definitions only)
51
+ # For an out-of-line `ReturnT Owner::method(...) {..}`: the owning type's simple name and the
52
+ # full written scope chain (["A","B"] for A::B::method). Empty/None for an in-class member.
53
+ owner_name: str | None = None
54
+ owner_scope: list[str] = field(default_factory=list)
55
+ namespace: str = "" # the `::`-joined namespace the (out-of-line) definition sits in
56
+ source: str = ""
57
+ doc: str = "" # shared `doc` property: the leading comment above the declaration, cleaned
58
+ line_start: int = 0
59
+ line_end: int = 0
60
+
61
+
62
+ @dataclass
63
+ class RawField:
64
+ name: str
65
+ type: str # type as written; keeps const/*/&/[]
66
+ is_static: bool = False
67
+ line_start: int = 0
68
+ line_end: int = 0
69
+
70
+
71
+ @dataclass
72
+ class RawBase:
73
+ name: str # base class simple name (generic args stripped)
74
+ access: str # "public" | "private" | "protected"
75
+
76
+
77
+ @dataclass
78
+ class RawType:
79
+ kind: str # "Class" | "Struct" | "Union" | "Enum"
80
+ name: str
81
+ namespace: str = "" # "" for the global namespace
82
+ is_scoped: bool = False # Enum only: `enum class`/`enum struct` (scoped enumerator names)
83
+ type_parameters: list[str] = field(default_factory=list) # template type params
84
+ bases: list[RawBase] = field(default_factory=list) # class/struct only (EXTENDS)
85
+ methods: list[RawMethod] = field(default_factory=list)
86
+ fields: list[RawField] = field(default_factory=list)
87
+ enum_members: list[str] = field(default_factory=list)
88
+ nested_types: list["RawType"] = field(default_factory=list)
89
+ is_definition: bool = True # False = forward declaration (no body)
90
+ source: str = ""
91
+ doc: str = "" # shared `doc` property: the leading comment above the declaration, cleaned
92
+ line_start: int = 0
93
+ line_end: int = 0
94
+
95
+
96
+ @dataclass
97
+ class RawFunction:
98
+ """A free (non-member) function. Member functions are RawMethod; out-of-line member
99
+ *definitions* are RawMethod too (in RawFile.member_defs), so this stays purely free."""
100
+
101
+ name: str
102
+ namespace: str = ""
103
+ return_type: str = ""
104
+ params: list[RawParameter] = field(default_factory=list)
105
+ is_definition: bool = False # True = has a body; False = prototype
106
+ calls: list[RawCall] = field(default_factory=list)
107
+ signature: str = ""
108
+ source: str = ""
109
+ doc: str = "" # shared `doc` property: the leading comment above the declaration, cleaned
110
+ line_start: int = 0
111
+ line_end: int = 0
112
+
113
+
114
+ @dataclass
115
+ class RawMacro:
116
+ name: str
117
+ is_function_like: bool = False
118
+ source: str = ""
119
+ line_start: int = 0
120
+ line_end: int = 0
121
+
122
+
123
+ @dataclass
124
+ class RawInclude:
125
+ path: str # as written, e.g. "geometry.hpp" or "vector"
126
+ is_system: bool # True for <...>, False for "..."
127
+
128
+
129
+ @dataclass
130
+ class RawFile:
131
+ path: str
132
+ includes: list[RawInclude] = field(default_factory=list)
133
+ macros: list[RawMacro] = field(default_factory=list)
134
+ types: list[RawType] = field(default_factory=list) # top-level (namespaced or global) types
135
+ functions: list[RawFunction] = field(default_factory=list) # free functions
136
+ member_defs: list[RawMethod] = field(default_factory=list) # out-of-line `Class::method` defs