Skip to content

Conversation

@allenday
Copy link

feat: add Solidity compatibility enhancements

Summary

  • Add comprehensive Solidity reserved keywords detection and mangling
  • Fix boolean parameter parsing to support flag-style options
  • Update parameter processing for better buf integration

Changes

Reserved Keyword Handling

  • Comprehensive list of Solidity reserved keywords (types, control flow, language features)
  • Automatic field name mangling with _field suffix for conflicts
  • Transparent resolution during code generation

Enhanced Parameter Processing

  • Support for both boolean flags (gen_runtime) and value parameters (gen_runtime=file.sol)
  • Improved plugin configuration flexibility
  • Better integration with build tools like buf

Cross-platform Compatibility

  • File path normalization for different operating systems
  • Improved error handling and diagnostics

Technical Details

Files Modified:

  • protobuf-solidity/src/protoc/plugin/gen_util.py - Added SOLIDITY_RESERVED_KEYWORDS set and mangle_solidity_field_name function
  • protobuf-solidity/src/protoc/plugin/gen_sol.py - Fixed boolean parameter parsing for gen_runtime option
  • README.md - Added Solidity Compatibility documentation section

Key Functions Added:

  • mangle_solidity_field_name() - Automatically mangles conflicting field names
  • Enhanced parse_urllike_parameter() - Supports both boolean flags and value parameters

Test Plan

  • Verify keyword mangling works for common conflicts (uint32, bytes, etc.)
  • Test boolean parameter parsing with buf generate
  • Confirm backward compatibility with existing configurations
  • Validate cross-platform path handling

Impact

This enhancement improves the plugin's robustness and usability, particularly for projects using buf toolchain and modern Solidity development practices. Field name conflicts are resolved automatically without manual intervention.

Backward Compatibility

All changes are backward compatible. Existing protobuf schemas and plugin configurations continue to work unchanged.

- Add comprehensive Solidity reserved keywords detection and mangling
- Implement automatic field name mangling with _field suffix for conflicts
- Fix boolean parameter parsing to support flag-style options (gen_runtime=true)
- Update parameter processing to handle both boolean flags and value parameters
- Add file path normalization for cross-platform compatibility
- Update documentation with Solidity compatibility features
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.

1 participant