Skip to content

Conversation

@konard
Copy link
Member

@konard konard commented Sep 13, 2025

Summary

This PR implements the four key improvements requested in issue #67:

#pragma once support: #pragma once directives are now preserved while other pragma directives (like #pragma warning disable) are removed

struct instead of class with public: support: Interfaces are now converted to structs instead of classes, providing better C++ semantics

Virtual destructors: Virtual destructors with = default are automatically added to interface-derived structs to ensure proper cleanup

Better template type arguments placement: Template declarations and class/struct definitions are now placed on separate lines for better readability (addresses issue #68)

Technical Implementation

1. #pragma once Support

  • Modified the pragma removal regex to use negative lookahead: #pragma(?! once)
  • This preserves #pragma once while removing other pragma directives

2. Interface to Struct Conversion

  • Updated both simple and templated interface handling rules
  • Simple interfaces: interface ITeststruct ITest
  • Templated interfaces: interface ITest<T>template <typename T>\nstruct ITest<T>

3. Virtual Destructors

  • Added selective virtual destructor insertion for interface-derived structs
  • Only applies to structs containing virtual methods (originally interfaces)
  • Uses two-stage rule processing to ensure proper = default instead of = 0

4. Template Type Arguments Placement

  • Separated template declarations from class/struct definitions
  • template <typename T> class Footemplate <typename T>\nclass Foo

Test Coverage

Added comprehensive test cases covering:

  • #pragma once preservation vs #pragma warning removal
  • Simple interface to struct conversion with virtual destructors
  • Templated interface to struct conversion with proper template placement
  • Regular struct handling (no unwanted virtual destructors)
  • Templated class and struct separation

All existing tests continue to pass, ensuring backward compatibility.

Example Transformations

Before:

#pragma once
interface ITest<T>
{
    void Method(T value);
}

After:

#pragma once
template <typename ...> struct ITest;
template <typename T>
struct ITest<T>
{
    public:
    virtual void Method(T value) = 0;
    virtual ~ITest() = default;
};

🤖 Generated with Claude Code


Resolves #67

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

Issue: #67
@konard konard self-assigned this Sep 13, 2025
This commit adds the four key improvements requested:

1. **#pragma once support**: Modified regex on line 32 to preserve `#pragma once`
   while removing other pragma directives like `#pragma warning disable`

2. **struct instead of class with public: support**: Updated interface handling
   (lines 96, 283) to convert interfaces to structs instead of classes

3. **Virtual destructors**: Added virtual destructors with `= default` to structs
   that contain virtual methods (originally interfaces). Added rule on line 287
   in FirstStage and fixing rule on line 763 in LastStage with proper priority.

4. **Better template type arguments placement**: Modified template generation
   (lines 90, 96) to place template declarations on separate lines from
   class/struct definitions as per issue #68.

Key technical changes:
- Modified pragma regex to use negative lookahead: `#pragma(?! once)`
- Updated interface-to-struct conversion rules in both templated and non-templated cases
- Added selective virtual destructor insertion for interface-derived structs
- Implemented two-stage rule processing to handle destructors correctly
- Added comprehensive test coverage for all new features

All existing tests pass, and new tests verify the four requested features work correctly.

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

Co-Authored-By: Claude <[email protected]>
@konard konard changed the title [WIP] Better support for interfaces Better support for interfaces (issue #67) Sep 13, 2025
@konard konard marked this pull request as ready for review September 13, 2025 02:16
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.

Better support for interfaces

2 participants