<commit_before>﻿using System;
using System.Text;
using CppSharp.AST;
using CppSharp.Types;
using Delegate = CppSharp.AST.Delegate;

namespace CppSharp.Generators.CLI
{
    public class CLIMarshalNativeToManagedPrinter : MarshalPrinter
    {
        public CLIMarshalNativeToManagedPrinter(MarshalContext marshalContext)
            : base(marshalContext)
        {
            Context.MarshalToManaged = this;
        }

        public override bool VisitTagType(TagType tag, TypeQualifiers quals)
        {
            var decl = tag.Declaration;
            return decl.Visit(this);
        }

        public override bool VisitArrayType(ArrayType array, TypeQualifiers quals)
        {
            switch (array.SizeType)
            {
                case ArrayType.ArraySize.Constant:
                    Context.Return.Write("nullptr");
                    break;
                case ArrayType.ArraySize.Variable:
                    Context.Return.Write("nullptr");
                    break;
            }

            return true;
        }

        public override bool VisitFunctionType(FunctionType function, TypeQualifiers quals)
        {
            var returnType = function.ReturnType;
            return returnType.Visit(this);
        }

        public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
        {
            var pointee = pointer.Pointee;

            if (pointee.Desugar().IsPrimitiveType(PrimitiveType.Void))
            {
                Context.Return.Write("IntPtr({0})", Context.ReturnVarName);
                return true;
            }

            if (pointee.IsPrimitiveType(PrimitiveType.Char))
            {
                Context.Return.Write("clix::marshalString<clix::E_UTF8>({0})",
                             Context.ReturnVarName);
                return true;
            }

            PrimitiveType primitive;
            if (pointee.Desugar().IsPrimitiveType(out primitive))
            {
                Context.Return.Write("IntPtr({0})", Context.ReturnVarName);
                return true;
            }

            if (!pointee.Visit(this, quals))
                return false;

            return true;
        }<commit_msg>Fixed marshaling of pointers to classes in CLI generator.<commit_after>﻿using System;
using System.Text;
using CppSharp.AST;
using CppSharp.Types;
using Delegate = CppSharp.AST.Delegate;

namespace CppSharp.Generators.CLI
{
    public class CLIMarshalNativeToManagedPrinter : MarshalPrinter
    {
        public CLIMarshalNativeToManagedPrinter(MarshalContext marshalContext)
            : base(marshalContext)
        {
            Context.MarshalToManaged = this;
        }

        public override bool VisitTagType(TagType tag, TypeQualifiers quals)
        {
            var decl = tag.Declaration;
            return decl.Visit(this);
        }

        public override bool VisitArrayType(ArrayType array, TypeQualifiers quals)
        {
            switch (array.SizeType)
            {
                case ArrayType.ArraySize.Constant:
                    Context.Return.Write("nullptr");
                    break;
                case ArrayType.ArraySize.Variable:
                    Context.Return.Write("nullptr");
                    break;
            }

            return true;
        }

        public override bool VisitFunctionType(FunctionType function, TypeQualifiers quals)
        {
            var returnType = function.ReturnType;
            return returnType.Visit(this);
        }

        public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
        {
            var pointee = pointer.Pointee;

            if (pointee.Desugar().IsPrimitiveType(PrimitiveType.Void))
            {
                Context.Return.Write("IntPtr({0})", Context.ReturnVarName);
                return true;
            }

            if (pointee.IsPrimitiveType(PrimitiveType.Char))
            {
                Context.Return.Write("clix::marshalString<clix::E_UTF8>({0})",
                             Context.ReturnVarName);
                return true;
            }

            PrimitiveType primitive;
            if (pointee.Desugar().IsPrimitiveType(out primitive))
            {
                Context.Return.Write("IntPtr({0})", Context.ReturnVarName);
                return true;
            }

            Class @class;
            if (pointee.Desugar().IsTagDecl(out @class))
            {
                var instance = (pointer.IsReference) ? "&" + Context.ReturnVarName
                    : Context.ReturnVarName;
                WriteClassInstance(@class, instance);
                return true;
            }

            if (!pointee.Visit(this, quals))
                return false;

            return true;
        }
{'fraction_non_alphanumeric': 0.08272556782663054, 'fraction_numerical': 0.0016670139612419254, 'mean_word_length': 1.6272577996715927, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4429694', 'n_tokens_mistral': 1242, 'n_tokens_neox': 1178, 'n_words': 230}