Metadata-Version: 2.4
Name: c2r
Version: 1.0.2
Classifier: Programming Language :: Rust
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: POSIX :: Linux
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Operating System :: Microsoft :: Windows
Requires-Dist: click
Summary: Deterministic C++ to Rust Transpiler with Industrial-Grade Static Analysis
Author-email: Ferrum Team <dev@ferrum.io>
License: MIT
Requires-Python: >=3.8, <3.13
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM

# c2r: The Industrial C++ to Rust Transpiler

**c2r** (formerly Ferrum) is a deterministic, static-analysis driven tool designed to migrate legacy C++ codebases to idiomatic, safe Rust. Unlike LLM-based solutions that hallucinate, c2r uses rigorous mathematical models to prove ownership and lifetimes.

## 🚀 Features

*   **Deterministic Translation**: No AI guessing. Uses Steensgaard's and Andersen's analysis for aliasing.
*   **Ownership Reconstruction**: Infers `Box<T>`, `Arc<T>`, `Rc<T>` based on usage patterns.
*   **Thread Safety Analysis**: Automatically detects data races and injects `Arc<Mutex<T>>`.
*   **Cycle Detection**: Identifies reference cycles (SCCs) and suggests `Weak<T>` or `RefCell<T>`.
*   **Smart Pointers**: Maps `std::unique_ptr` and `std::shared_ptr` to Rust equivalents.
*   **Safety Audit**: Reports a "Safety Score" indicating the ratio of safe/unsafe code generated.

## 📦 Installation

c2r is available as a Python package with a high-performance Rust backend.

```bash
pip install c2r
```

## 🛠 Usage

c2r provides a CLI to migrate projects.

### Migrate a Project

```bash
c2r migrate ./legacy_cpp_project -o ./new_rust_project
```

This command will:
1.  Analyze all `.cpp` and `.h` files in the input directory.
2.  Generate a valid Cargo project structure (`src/models`, `src/utils`).
3.  Create a `Cargo.toml` with necessary production dependencies (`tokio`, `serde`, `parking_lot`).
4.  Transpile the code, resolving include dependencies and type definitions.

## 🚀 Publishing to PyPI

To publish a new version of `c2r`, ensure you have `maturin` installed.

1.  **Build Release Artifacts**:
    ```bash
    maturin build --release
    ```

2.  **Publish to PyPI**:
    ```bash
    maturin publish
    ```

## 🏗 Architecture

c2r operates on a multi-pass architecture:

1.  **Ingestion (Industrial Frontend)**: Simulates Clang AST parsing to generate a Property-Oriented Intermediate Representation (PIIR).
2.  **Points-To Analysis**:
    *   **Steensgaard ($O(N \alpha(N))$)**: Fast partitioning of memory regions.
    *   **Andersen ($O(N^3)$)**: Precise subset-based constraint solving for aliasing.
3.  **Region Inference (Tofte-Talpin)**: Infers lifetimes (`'a`) and scopes.
4.  **Cycle Detection**: Detects Strongly Connected Components using Tarjan's algorithm concepts.
5.  **Thread Safety Pass**: Simulates execution flow to detect concurrent mutations.
6.  **Code Generation**: Uses `syn` and `quote` to construct a valid Rust AST.

## 📊 Benchmarks

c2r includes a built-in benchmarking harness to verify the scalability of its analysis algorithms.

*   **100 Pointers**: ~0.2ms
*   **1,000 Pointers**: ~2.2ms
*   **5,000 Pointers**: ~11.4ms

## 📄 License

MIT License.

