Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

record parameter with direction != in not yet supported. #1120

Open
BehroozAmoozad opened this issue Sep 12, 2024 · 2 comments
Open

record parameter with direction != in not yet supported. #1120

BehroozAmoozad opened this issue Sep 12, 2024 · 2 comments

Comments

@BehroozAmoozad
Copy link

I'm getting a bunch of these warnings when generating code. Is there any way for me or you to fix the issue? Even manually for the couple functions that I need will be really helpful. I don't know where to start and what to modify. point me in the right direction and I'll do it.

What brought me here is that I can't initialize ListStores and a whole lot of treemodel code that I converted from gtk 3 stopped working which I removed thinking it's no longer supported in gtk 4.

[16:24:54 WRN] Did not generate method 'TreeModel.Get': Variadic parameters are not yet supported
[16:24:54 DBG] Did not generate method 'TreeModel.GetIter': GirModel.AnyType: GirModel.Type: Gtk.TreeIter: record parameter 'iter' with direction != in not yet supported
[16:24:54 DBG] Did not generate method 'TreeModel.GetIterFirst': GirModel.AnyType: GirModel.Type: Gtk.TreeIter: record parameter 'iter' with direction != in not yet supported
[16:24:54 DBG] Did not generate method 'TreeModel.GetIterFromString': GirModel.AnyType: GirModel.Type: Gtk.TreeIter: record parameter 'iter' with direction != in not yet supported
[16:24:54 DBG] Did not generate method 'TreeModel.GetValue': GirModel.AnyType: GirModel.Type: GObject.Value: record parameter 'value' with direction != in not yet supported
[16:24:54 DBG] Did not generate method 'TreeModel.IterChildren': GirModel.AnyType: GirModel.Type: Gtk.TreeIter: record parameter 'iter' with direction != in not yet supported
[16:24:54 DBG] Did not generate method 'TreeModel.IterNthChild': GirModel.AnyType: GirModel.Type: Gtk.TreeIter: record parameter 'iter' with direction != in not yet supported
[16:24:54 DBG] Did not generate method 'TreeModel.IterParent': GirModel.AnyType: GirModel.Type: Gtk.TreeIter: record parameter 'iter' with direction != in not yet supported

@BehroozAmoozad
Copy link
Author

I did something. but now the internal function is not generated. I have no idea where that one is.

        if (parameter.Parameter.Direction == GirModel.Direction.In)
        {
            var record = (GirModel.Record) parameter.Parameter.AnyTypeOrVarArgs.AsT0.AsT0;
            var typeHandle = Model.TypedRecord.GetFullyQuallifiedHandle(record);
            var nullHandle = Model.TypedRecord.GetFullyQuallifiedNullHandle(record);
            var signatureName = Model.Parameter.GetName(parameter.Parameter);

            var callName = parameter.Parameter switch
            {
                { Nullable: true, Transfer: GirModel.Transfer.None } => $"({typeHandle}?) {signatureName}?.Handle ?? {nullHandle}",
                { Nullable: false, Transfer: GirModel.Transfer.None } => $"{signatureName}.Handle",
                { Nullable: true, Transfer: GirModel.Transfer.Full } => $"{signatureName}?.Handle.UnownedCopy() ?? {nullHandle}",
                { Nullable: false, Transfer: GirModel.Transfer.Full } => $"{signatureName}.Handle.UnownedCopy()",
                _ => throw new Exception($"Can't detect call name for parameter record parameter {parameter.Parameter.Name}")
            };

            parameter.SetSignatureName(() => signatureName);
            parameter.SetCallName(() => callName);
        }
        else if (parameter.Parameter.Direction == GirModel.Direction.Out)
        {
            if (parameter.Parameter.Transfer != Transfer.Full)
                throw new NotImplementedException($"{parameter.Parameter.AnyTypeOrVarArgs}: record parameter '{parameter.Parameter.Name}' with direction == out and transfer != full not yet supported");

            var record = (GirModel.Record) parameter.Parameter.AnyTypeOrVarArgs.AsT0.AsT0;
            var type = Model.TypedRecord.GetFullyQualifiedPublicClassName(record);
            var typeHandle = Model.TypedRecord.GetFullyQuallifiedOwnedHandle(record);
            var signatureName = Model.Parameter.GetName(parameter.Parameter);

            var callName = $"out {typeHandle} _handle_{signatureName}";

            string? postCallExpression;

            if (parameter.Parameter is { Nullable: true, Transfer: GirModel.Transfer.Full })
            {
                postCallExpression = $"{signatureName} = _handle_{signatureName}.IsInvalid ? default : new {type} (_handle_{signatureName});";
            }
            else if (parameter.Parameter is { Nullable: false, Transfer: GirModel.Transfer.Full })
            {
                postCallExpression = $"{signatureName} = new {type} (_handle_{signatureName});";
            }
            else
            {
                throw new Exception($"Can't detect call name for parameter record parameter {parameter.Parameter.Name}");
            }

            parameter.SetSignatureName(() => signatureName);
            parameter.SetCallName(() => callName);
            parameter.SetPostCallExpression(() => postCallExpression);
        }
        else
            throw new NotImplementedException($"{parameter.Parameter.AnyTypeOrVarArgs}: record parameter '{parameter.Parameter.Name}' with direction != in not yet supported");
        

@badcel
Copy link
Member

badcel commented Sep 13, 2024

Hi, thanks for stopping by and the offer to contribute. I would be very grateful for any contribution from your side.

Unfortunately I can't give you very specific advice as I would need to analyze the problem myself which is actually as time consuming as writing the code myself.

But I can offer you guidance to find your way around the codebase and implement the bits you are missing.

As a start you need to be familiar with the generated code around the class you want to improve. Be aware of the Internal namespace, check what is generated there an how it plays together with the public code.

Then you need to find a technical solution how you want to bind the method you are missing. You can implement this manually as a proof of concept on your local machine. If you got this working I would like to see the code you want to generate.

Then we can take the next step and see how to make the generator create the code you want.

You are welcome to step by in the matrix channel (see readme) for adhoc communication.

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

No branches or pull requests

2 participants