Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add opApply for UDAs, and lexicallize properly methods and functions #86

Copy link
Copy link

Description

@Dadoum
Issue body actions

Description

UDAs could be way more powerful if we could manipulate the element they are attached to. It would permit to get types and methods and mixin them or even better implement them if they have no implementation.

This would require a better way to handle methods and functions as template types, since they currently require to use "(T...) if (T.length == 1)" and there is no way to get their body.

It could even allow to write code before and after, and allow Aspect-oriented programming:

Example (with terrible syntax, should find something better):

@tracedMethod void functionThatCanCauseProblem()
{
    writeln("Some dangerous operation");
}

struct tracedMethod
{
    void opApply(T)()
    {
        if (is(T U == A function(P) U)) // this will also ensure that T has a body; A would be the attributes, P tuple of params types, and U the original body
        {
            T = A function(P) // or A T(P) ?
            {
                writeln(T.stringof ~ " IN");
                auto ret = U(P);
                writeln(T.stringof ~ " OUT");
                return ret;
            }
        }
    }
}

What are rough milestones of this project?

  • Find a cleaner syntax to use methods as template arguments, and if possible find way to get their keyword separately like "static" or their body as "type".
  • Determine how we would implement an opApply(T)() for UDAs.
  • Create a DIP from what came out of the previous steps.

How does this project help the D community?

Improve meta-programming capabilities of D, add aspect-oriented programming, and simplify some mixins.

Example:

public class ImportedMethods {
    mixin importMethod(void function(), "init", "externalClassCtor");
}
// will become
public class ImportedMethods {
    @importMethod("externalClassCtor") void init();
}

Recommended skills

  • Knowledge about D parsing
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.