Skip to content

Conversation

@konard
Copy link
Member

@konard konard commented Sep 13, 2025

Summary

This PR implements automatic generation of necessary #include statements for C++ standard library features used in the transformation, resolving issue #45.

What's Changed

  • New TransformWithIncludes() method in C# that analyzes transformed output and generates required includes
  • Comprehensive mapping of std library features to their corresponding headers
  • Python implementation with similar functionality
  • Extensive test coverage for various scenarios

Features Added

Automatic Include Generation

The transformer now detects when std library features are used and automatically generates the necessary include statements:

// Input: string message;
// Output:
#include <string>

std::string message;

Supported Libraries

  • std::string<string>
  • std::vector<vector>
  • std::function<functional>
  • std::tuple<tuple>
  • std::numeric_limits<limits>
  • std::exception<exception>
  • std::mutex, std::lock_guard<mutex>
  • std::ostream<ostream>
  • Integer types (std::int32_t, etc.) → <cstdint>

Usage Examples

C# Usage

var transformer = new CSharpToCppTransformer();

// Use new method for includes
string result = transformer.TransformWithIncludes(csharpCode);

// Original method still works without includes  
string result = transformer.Transform(csharpCode);

Python Usage

from cs2cpp import CSharpToCpp

transformer = CSharpToCpp()
result = transformer.translate(csharp_code)  # Now includes headers automatically

Test Results

  • ✅ All existing tests pass (backward compatibility maintained)
  • ✅ New comprehensive test suite covering:
    • Basic string transformation with includes
    • Multiple std library features
    • Empty input handling
    • Edge cases

Breaking Changes

None. This is a purely additive feature with full backward compatibility.

Version Update

Bumped version to 0.4.0 to reflect the new functionality.

🤖 Generated with Claude Code

Co-Authored-By: Claude [email protected]


Resolves #45

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #45
@konard konard self-assigned this Sep 13, 2025
Resolves issue #45 by implementing automatic detection and generation
of required #include statements for std library features used in the
C++ transformation.

## New Features

### C# Implementation
- New `TransformWithIncludes()` method that analyzes transformed output
  and generates necessary include statements
- Comprehensive mapping of std library features to their headers:
  - `std::string` → `<string>`
  - `std::vector` → `<vector>`
  - `std::function` → `<functional>`
  - `std::tuple` → `<tuple>`
  - `std::numeric_limits` → `<limits>`
  - `std::exception` → `<exception>`
  - `std::mutex`, `std::lock_guard` → `<mutex>`
  - `std::ostream` → `<ostream>`
  - Integer types → `<cstdint>`
- Includes are sorted alphabetically and only generated when needed
- Maintains backward compatibility with existing `Transform()` method

### Python Implementation
- Similar functionality added to Python version
- `translate()` method now automatically generates includes
- Uses same mapping as C# implementation

## Tests
- Comprehensive test suite covering:
  - Basic string transformation with includes
  - Multiple std library features
  - Empty input handling
  - Edge cases with mixed features
- All existing tests continue to pass

## Version Update
- Bumped version to 0.4.0 to reflect new feature

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@konard konard changed the title [WIP] Generate necessary includes Generate necessary C++ standard library includes Sep 13, 2025
@konard konard marked this pull request as ready for review September 13, 2025 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generate necessary includes

2 participants