mellinoe / ShaderGen

Proof-of-concept library for generating HLSL, GLSL, and Metal shader code from C#,
MIT License
497 stars 56 forks source link

[Enhancement] Support method overloading #74

Open thargy opened 6 years ago

thargy commented 6 years ago

Currently, method overloading doesn't work. To support, method numbering would help, e.g. (extending the example in #73):

    public struct SimpleConstructedStruct
    {
        public readonly float OutFloat;

        public SimpleConstructedStruct(float outFloat)
        {
            OutFloat = outFloat;
        }

        public SimpleConstructedStruct Increment()
        {
            return new SimpleConstructedStruct (OutFloat + 1.0f);
        }

        public SimpleConstructedStruct Increment(float amount)
        {
            return new SimpleConstructedStruct (OutFloat + amount);
        }
    }

...
    SimpleConstructedStruct s = new SimpleConstructedStruct(1.0f);
    s = s.SimpleConstructedStruct();
    s = s.SimpleConstructedStruct(1.0f);

Should be written as:

    struct SimpleConstructedStruct
    {
        float OutFloat;
    };

    SimpleConstructedStruct_0_ctor(float outFloat)
    {
        SimpleConsructedStruct this;
        this.OutFloat = outFloat;
        return this;
    }

    SimpleConstructedStruct_Increment(SimpleConstructedStruct this)
    {
        return SimpleConstructedStruct_0_ctor(this.OutFloat + 1.0);
    }

    SimpleConstructedStruct_Increment_2(SimpleConstructedStruct this, float amount)
    {
        return SimpleConstructedStruct_0_ctor(this.OutFloat + amount);
    }

...
    SimpleConstructedStruct s = SimpleConstructedStruct_0_ctor(1.0);
    s = SimpleConstructedStruct_Increment(s);
    s = SimpleConstructedStruct_Increment_2(s, 1.0);