Skip to content

Commit 069afa4

Browse files
CrazyDubyaclaude
andcommitted
Initial commit: PyToC++ with class and Union type support
Major features implemented: - Python to C++ code conversion with AST analysis - Class definitions with inheritance support - Union type support using std::variant with visitor pattern - Advanced f-string handling with mixed string/numeric concatenation - Method translation with proper const-correctness - Python-C++ interoperability via pybind11 bindings - Comprehensive testing framework - End-to-end examples with performance benchmarking Technical achievements: - Fixed string type detection and handling - Implemented protected attributes for std::visit compatibility - Added proper getter methods for encapsulation - Created working CMake build system - Demonstrated 4.4x performance improvements over Python Project includes complete documentation, examples, and development setup. 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
0 parents  commit 069afa4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+8560
-0
lines changed

.gitignore

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
MANIFEST
27+
28+
# PyInstaller
29+
# Usually these files are written by a python script from a template
30+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
31+
*.manifest
32+
*.spec
33+
34+
# Installer logs
35+
pip-log.txt
36+
pip-delete-this-directory.txt
37+
38+
# Unit test / coverage reports
39+
htmlcov/
40+
.tox/
41+
.nox/
42+
.coverage
43+
.coverage.*
44+
.cache
45+
nosetests.xml
46+
coverage.xml
47+
*.cover
48+
.hypothesis/
49+
.pytest_cache/
50+
51+
# Translations
52+
*.mo
53+
*.pot
54+
55+
# Django stuff:
56+
*.log
57+
local_settings.py
58+
db.sqlite3
59+
60+
# Flask stuff:
61+
instance/
62+
.webassets-cache
63+
64+
# Scrapy stuff:
65+
.scrapy
66+
67+
# Sphinx documentation
68+
docs/_build/
69+
70+
# PyBuilder
71+
target/
72+
73+
# Jupyter Notebook
74+
.ipynb_checkpoints
75+
76+
# IPython
77+
profile_default/
78+
ipython_config.py
79+
80+
# pyenv
81+
.python-version
82+
83+
# celery beat schedule file
84+
celerybeat-schedule
85+
86+
# SageMath parsed files
87+
*.sage.py
88+
89+
# Environments
90+
.env
91+
.venv
92+
env/
93+
venv/
94+
ENV/
95+
env.bak/
96+
venv.bak/
97+
98+
# Spyder project settings
99+
.spyderproject
100+
.spyproject
101+
102+
# Rope project settings
103+
.ropeproject
104+
105+
# mkdocs documentation
106+
/site
107+
108+
# mypy
109+
.mypy_cache/
110+
.dmypy.json
111+
dmypy.json
112+
113+
# Pyre type checker
114+
.pyre/
115+
116+
# C++ build artifacts
117+
*.o
118+
*.obj
119+
*.exe
120+
*.dll
121+
*.so
122+
*.dylib
123+
*.a
124+
*.lib
125+
126+
# CMake
127+
CMakeCache.txt
128+
CMakeFiles/
129+
cmake_install.cmake
130+
Makefile
131+
*.cmake
132+
!CMakeLists.txt
133+
134+
# Generated directories and files
135+
generated/build/
136+
generated/*.o
137+
generated/pytocpp_generated
138+
generated/test_app
139+
generated/*.cpython-*
140+
generated/*.egg-info/
141+
142+
# Backup files
143+
*_bak.py
144+
*_fixed2.py
145+
146+
# IDE files
147+
.vscode/
148+
.idea/
149+
*.swp
150+
*.swo
151+
*~
152+
153+
# OS files
154+
.DS_Store
155+
.DS_Store?
156+
._*
157+
.Spotlight-V100
158+
.Trashes
159+
ehthumbs.db
160+
Thumbs.db
161+
162+
# Temporary files
163+
*.tmp
164+
*.temp
165+
*.bak
166+
*.backup

CONTRIBUTING.md

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
# Contributing to PyToC++
2+
3+
Thank you for your interest in contributing to PyToC++! This document provides guidelines for contributing to the project.
4+
5+
## Current Status
6+
7+
PyToC++ has recently completed major milestones:
8+
- ✅ Class and inheritance support
9+
- ✅ Union type support with std::variant
10+
- ✅ Advanced f-string handling
11+
- ✅ Python-C++ interoperability via pybind11
12+
13+
## How to Contribute
14+
15+
### Reporting Issues
16+
17+
1. Check existing [issues](../../issues) to avoid duplicates
18+
2. Use clear, descriptive titles
19+
3. Include:
20+
- Python code that fails to convert
21+
- Expected C++ output
22+
- Actual output/error messages
23+
- Python and system version info
24+
25+
### Development Setup
26+
27+
1. **Clone the repository**:
28+
```bash
29+
git clone https://github.com/[username]/pytocplusplus.git
30+
cd pytocplusplus
31+
```
32+
33+
2. **Install dependencies**:
34+
```bash
35+
pip install -r requirements.txt
36+
```
37+
38+
3. **Run tests**:
39+
```bash
40+
pytest tests/
41+
```
42+
43+
4. **Test with examples**:
44+
```bash
45+
python -m src.main examples/class_example.py
46+
```
47+
48+
### Priority Areas for Contribution
49+
50+
Based on our current roadmap, we're looking for help with:
51+
52+
#### High Priority
53+
- **Exception handling translation**: Improve try/except C++ code generation
54+
- **Generic type support**: Add template-based generic types
55+
- **Container comprehensions**: List and dict comprehensions
56+
- **Standard library mapping**: Python standard library to C++ equivalents
57+
58+
#### Medium Priority
59+
- **Regular expression translation**: Python regex to C++ regex
60+
- **File I/O operations**: Python file operations to C++ equivalents
61+
- **Advanced control flow**: match/case statements
62+
- **Decorator support**: Basic decorator translation
63+
64+
#### Advanced Features
65+
- **Generator functions**: Python generators to C++ equivalents
66+
- **Context managers**: Resource management translation
67+
- **Multiple inheritance**: Beyond current single inheritance support
68+
69+
### Code Style Guidelines
70+
71+
1. **Python Code**:
72+
- Follow PEP 8
73+
- Use type hints where appropriate
74+
- Add docstrings to all public functions/classes
75+
- Maximum line length: 88 characters (Black formatter)
76+
77+
2. **Generated C++ Code**:
78+
- Follow modern C++ best practices (C++17/20)
79+
- Use RAII patterns
80+
- Prefer `std::` containers over raw arrays
81+
- Use `const` correctness
82+
83+
3. **Testing**:
84+
- Add tests for new functionality
85+
- Include both unit tests and integration tests
86+
- Test with realistic Python examples
87+
- Verify generated C++ compiles and runs correctly
88+
89+
### Submitting Changes
90+
91+
1. **Fork the repository**
92+
2. **Create a feature branch**:
93+
```bash
94+
git checkout -b feature/your-feature-name
95+
```
96+
3. **Make your changes**
97+
4. **Add/update tests**
98+
5. **Update documentation** if needed
99+
6. **Run tests** to ensure everything works
100+
7. **Commit with clear messages**:
101+
```bash
102+
git commit -m "Add support for list comprehensions
103+
104+
- Implement basic list comprehension translation
105+
- Add tests for simple comprehension cases
106+
- Update documentation with new feature"
107+
```
108+
8. **Push to your fork**
109+
9. **Create a Pull Request**
110+
111+
### Pull Request Guidelines
112+
113+
- **Title**: Clear, descriptive summary
114+
- **Description**:
115+
- What changes were made
116+
- Why the changes were needed
117+
- How to test the changes
118+
- Any breaking changes
119+
- **Testing**: Include test results
120+
- **Documentation**: Update relevant docs
121+
122+
### Code Review Process
123+
124+
1. Automated tests must pass
125+
2. Code review by maintainers
126+
3. Documentation review if applicable
127+
4. Final approval and merge
128+
129+
## Development Workflow
130+
131+
### Working with the Analyzer
132+
133+
The `CodeAnalyzer` (`src/analyzer/code_analyzer_fixed.py`) handles Python AST analysis:
134+
- Add new node type handlers in `_visit_*` methods
135+
- Update type inference in `_infer_type`
136+
- Extend class analysis in `_analyze_class_definition`
137+
138+
### Working with the Generator
139+
140+
The `CodeGenerator` (`src/converter/code_generator_fixed.py`) handles C++ generation:
141+
- Add new statement translation in `_translate_statement`
142+
- Extend expression handling in `_translate_expression`
143+
- Add new C++ patterns in helper methods
144+
145+
### Testing Strategy
146+
147+
1. **Unit Tests**: Test individual components
148+
2. **Integration Tests**: Test full conversion process
149+
3. **Example Tests**: Verify realistic Python code conversion
150+
4. **Performance Tests**: Ensure C++ code is actually faster
151+
152+
## Resources
153+
154+
- [Project Roadmap](docs/roadmap.md)
155+
- [Implementation Gaps Report](docs/implementation_gaps_report.md)
156+
- [Enhancement Sprint Plan](docs/enhancement_sprint_plan.md)
157+
158+
## Questions?
159+
160+
- Open an [issue](../../issues) for questions
161+
- Check existing documentation in the `docs/` directory
162+
- Look at `examples/` for usage patterns
163+
164+
## Recognition
165+
166+
Contributors will be acknowledged in:
167+
- README.md contributor section
168+
- Release notes for significant contributions
169+
- Code comments for major features
170+
171+
Thank you for helping make PyToC++ better! 🚀

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 PyToC++ Project
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

0 commit comments

Comments
 (0)