nativegate 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.
Files changed (50) hide show
  1. nativegate/__init__.py +1 -0
  2. nativegate/__main__.py +4 -0
  3. nativegate/buildinfo.py +344 -0
  4. nativegate/cli.py +2007 -0
  5. nativegate/config.py +991 -0
  6. nativegate/declared_invariants.py +565 -0
  7. nativegate/discovery.py +167 -0
  8. nativegate/driverbuild.py +626 -0
  9. nativegate/drivers/__init__.py +5 -0
  10. nativegate/drivers/cpp.py +616 -0
  11. nativegate/drivers/fortran.py +507 -0
  12. nativegate/generators/__init__.py +0 -0
  13. nativegate/generators/cmake_gen.py +101 -0
  14. nativegate/generators/docker_gen.py +614 -0
  15. nativegate/generators/error_gen.py +104 -0
  16. nativegate/generators/f2py_gen.py +91 -0
  17. nativegate/generators/gateway_gen.py +110 -0
  18. nativegate/generators/golden_gen.py +50 -0
  19. nativegate/generators/k8s_gen.py +212 -0
  20. nativegate/generators/mcp_gen.py +281 -0
  21. nativegate/generators/middleware_gen.py +717 -0
  22. nativegate/generators/pybind_gen.py +406 -0
  23. nativegate/generators/pyproject_gen.py +61 -0
  24. nativegate/generators/python_pkg_gen.py +1164 -0
  25. nativegate/generators/test_gen.py +160 -0
  26. nativegate/golden.py +747 -0
  27. nativegate/invariants.py +532 -0
  28. nativegate/ir.py +789 -0
  29. nativegate/lattice.py +350 -0
  30. nativegate/locking.py +216 -0
  31. nativegate/oracle.py +904 -0
  32. nativegate/parsers/__init__.py +0 -0
  33. nativegate/parsers/cpp.py +105 -0
  34. nativegate/parsers/cpp_ast.py +1652 -0
  35. nativegate/parsers/cpp_regex.py +812 -0
  36. nativegate/parsers/fixed_form.py +868 -0
  37. nativegate/parsers/fortran.py +157 -0
  38. nativegate/parsers/fortran_fparser.py +1116 -0
  39. nativegate/parsers/fortran_regex.py +686 -0
  40. nativegate/preprocess.py +335 -0
  41. nativegate/structural_invariants.py +762 -0
  42. nativegate/suggest.py +208 -0
  43. nativegate/templates/__init__.py +20 -0
  44. nativegate/templates/golden_test_template.py +248 -0
  45. nativegate/wire.py +438 -0
  46. nativegate-0.1.0.dist-info/METADATA +547 -0
  47. nativegate-0.1.0.dist-info/RECORD +50 -0
  48. nativegate-0.1.0.dist-info/WHEEL +5 -0
  49. nativegate-0.1.0.dist-info/entry_points.txt +3 -0
  50. nativegate-0.1.0.dist-info/top_level.txt +1 -0
File without changes
@@ -0,0 +1,105 @@
1
+ """C++ parser front door — picks a backend and hides the difference.
2
+
3
+ Two backends produce the identical `ir.ModuleIR`:
4
+
5
+ * `cpp_ast` — a real Clang AST parse (libclang). Runs the preprocessor, so
6
+ `#include`s, macros and `#ifdef`s are resolved; understands templates,
7
+ typedefs, overloads, inheritance and incompleteness properly. This is the
8
+ parser design.md section 7 specifies, and the default whenever libclang is
9
+ importable.
10
+ * `cpp_regex` — the original token/brace reader. No preprocessor, no template
11
+ support, and it can only see what one header spells literally. Kept as the
12
+ fallback for machines without libclang, and selectable explicitly for
13
+ reproducing its behaviour.
14
+
15
+ Selection order, first match wins:
16
+
17
+ 1. the `backend=` argument,
18
+ 2. `$NATIVEGATE_CPP_PARSER` (`auto` | `clang` | `regex`),
19
+ 3. `parser:` in nativegate.yaml, passed through by the CLI,
20
+ 4. `auto` — Clang if available, regex otherwise.
21
+
22
+ Asking for `clang` explicitly and not having it is an error, not a silent
23
+ downgrade: a build that quietly loses macro-defined symbols because a wheel
24
+ was missing is exactly the failure this module exists to prevent.
25
+ """
26
+
27
+ from __future__ import annotations
28
+
29
+ import os
30
+ from pathlib import Path
31
+
32
+ from ..config import ExposeConfig
33
+ from ..ir import ModuleIR
34
+ from . import cpp_ast, cpp_regex
35
+ from .cpp_ast import ClangOptions
36
+
37
+ BACKENDS = ("auto", "clang", "regex")
38
+ _ENV_VAR = "NATIVEGATE_CPP_PARSER"
39
+
40
+
41
+ class ParserUnavailable(RuntimeError):
42
+ """Raised when the requested C++ backend cannot run on this machine."""
43
+
44
+
45
+ def resolve_backend(backend: str | None = None) -> str:
46
+ """Return "clang" or "regex" for a possibly-"auto" request."""
47
+ choice = (backend or os.environ.get(_ENV_VAR) or "auto").lower()
48
+ if choice not in BACKENDS:
49
+ raise ParserUnavailable(
50
+ f"Unknown C++ parser backend '{choice}'; expected one of {', '.join(BACKENDS)}."
51
+ )
52
+
53
+ if choice == "regex":
54
+ return "regex"
55
+
56
+ if choice == "clang":
57
+ if not cpp_ast.is_available():
58
+ raise ParserUnavailable(
59
+ "The Clang parser was requested but libclang is not usable: "
60
+ f"{cpp_ast.unavailable_reason()}. Install it with "
61
+ '`pip install "nativegate[clang]"`, point NATIVEGATE_LIBCLANG at a '
62
+ "libclang shared library, or set parser: regex in nativegate.yaml."
63
+ )
64
+ return "clang"
65
+
66
+ return "clang" if cpp_ast.is_available() else "regex"
67
+
68
+
69
+ def backend_description(backend: str | None = None) -> str:
70
+ """One line naming the backend in use, for `ngate inspect`/`generate`."""
71
+ try:
72
+ resolved = resolve_backend(backend)
73
+ except ParserUnavailable as exc:
74
+ return str(exc)
75
+ if resolved == "clang":
76
+ return f"clang AST ({cpp_ast.clang_version()})"
77
+ if (backend or os.environ.get(_ENV_VAR) or "").lower() == "regex":
78
+ return "regex reader (selected explicitly)"
79
+ return f"regex reader (libclang unavailable: {cpp_ast.unavailable_reason()})"
80
+
81
+
82
+ def parse_header(
83
+ path: Path,
84
+ expose: ExposeConfig,
85
+ extra_known_records: frozenset[str] = frozenset(),
86
+ *,
87
+ backend: str | None = None,
88
+ options: ClangOptions | None = None,
89
+ ) -> ModuleIR:
90
+ """Parse one C++ header into a ModuleIR using the selected backend."""
91
+ if resolve_backend(backend) == "clang":
92
+ return cpp_ast.parse_header(path, expose, extra_known_records, options)
93
+ return cpp_regex.parse_header(path, expose, extra_known_records)
94
+
95
+
96
+ def defined_record_names(
97
+ path: Path,
98
+ *,
99
+ backend: str | None = None,
100
+ options: ClangOptions | None = None,
101
+ ) -> frozenset[str]:
102
+ """Records defined (not merely forward-declared) in this header."""
103
+ if resolve_backend(backend) == "clang":
104
+ return cpp_ast.defined_record_names(path, options)
105
+ return cpp_regex.defined_record_names(path)