Skip to content

Implement Class, Actor, Extension, and Protocol syntax wrappers #9

Closed
@stackotter

Description

@stackotter

So far the only declaration group wrappers in the toolkit are Enum and Struct. By declaration group I mean a declaration with an attached block which itself contains declarations. For example, a function isn't a declaration group because its block contains statements instead of declarations, whereas a class is a declaration group because its block contains 'member's which are all declarations (and could themselves also be classes).

The remaining declaration groups are class, actor, extension, and protocol. Implementing wrappers for these would unlock quite a few more use cases for the toolkit.

Implementing new wrappers

The wrappers themselves are pretty cookie cutter: simply create a new file (matching the new of the wrapper) and copy an existing wrapper for another declaration group and then modify it.

Bonus points!

This isn't strictly necessary but it would be a very welcome extension to this task; a DeclGroupProtocol protocol. This would enable macros to generically operate over the members of a declaration group without having to actually know what specific type of declaration group it is. As a rough idea, the protocol would probably look something like this;

public protocol DeclGroupProtocol {
    var inheritanceClause: [Type] { get }
    var members: [Decl] { get }
}

Also, if DeclProtocol exists by the time someone gets to this, DeclGroupProtocol should inherit from DeclProtocol too.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions