<commit_before>using CppSharp;
using CppSharp.AST;
using CppSharp.Generators;
using MonoEmbeddinator4000.Passes;
using System.Linq;
 
namespace MonoEmbeddinator4000.Generators
{
    public class ObjCHeaders : CHeaders
    {
        public ObjCHeaders(BindingContext context, TranslationUnit unit)
            : base(context, unit)
        {
        }

        public override void Process()
        {
            base.Process();
        }

        public override void WriteHeaders()
        {
            base.WriteHeaders();
            WriteLine("#import <Foundation/Foundation.h>");
        }

        public override void WriteForwardDecls()
        {
            var refs = new GetReferencedClasses();
            TranslationUnit.Visit(refs);

            var classes = refs.Classes.ToList();
            classes.RemoveAll((c) => c == GenerateArrayTypes.MonoEmbedArray);
            classes.RemoveAll((c) => c == GenerateObjectTypesPass.MonoEmbedObject);

            foreach (var @class in classes.Distinct())
                WriteLine($"@class {@class.QualifiedName};");
        }

        public override void GenerateMethodSignature(Method method,
            bool isSource)
        {
            this.GenerateObjCMethodSignature(method);
        }

        public override bool VisitClassDecl(Class @class)
        {
            PushBlock();

            Write("@interface {0} : NSObject", @class.QualifiedName);

            var hasFields = @class.Fields.Count != 0;
            if (hasFields)
            {
                Write(" ");
                WriteStartBraceIndent();

                foreach (var field in @class.Fields)
                    field.Visit(this);

                WriteCloseBraceIndent();
                NewLine();
            }
            
            VisitDeclContext(@class);

            WriteLine("@end");

            PopBlock(NewLineKind.BeforeNextBlock);

            return true;
        }

        public override bool VisitFieldDecl(Field field)
        {
            return this.GenerateObjCField(field);
        }
    }
}
<commit_msg>Use a block to generate Objective-C forward declarations.<commit_after>using CppSharp;
using CppSharp.AST;
using CppSharp.Generators;
using MonoEmbeddinator4000.Passes;
using System.Linq;
 
namespace MonoEmbeddinator4000.Generators
{
    public class ObjCHeaders : CHeaders
    {
        public ObjCHeaders(BindingContext context, TranslationUnit unit)
            : base(context, unit)
        {
        }

        public override void Process()
        {
            base.Process();
        }

        public override void WriteHeaders()
        {
            base.WriteHeaders();
            WriteLine("#import <Foundation/Foundation.h>");
        }

        public override void WriteForwardDecls()
        {
            var refs = new GetReferencedClasses();
            TranslationUnit.Visit(refs);

            var classes = refs.Classes.ToList();
            classes.RemoveAll((c) => c == GenerateArrayTypes.MonoEmbedArray);
            classes.RemoveAll((c) => c == GenerateObjectTypesPass.MonoEmbedObject);

            PushBlock();

            foreach (var @class in classes.Distinct())
                WriteLine($"@class {@class.QualifiedName};");

            PopBlock(NewLineKind.BeforeNextBlock);
        }

        public override void GenerateMethodSignature(Method method,
            bool isSource)
        {
            this.GenerateObjCMethodSignature(method);
        }

        public override bool VisitClassDecl(Class @class)
        {
            PushBlock();

            Write("@interface {0} : NSObject", @class.QualifiedName);

            var hasFields = @class.Fields.Count != 0;
            if (hasFields)
            {
                Write(" ");
                WriteStartBraceIndent();

                foreach (var field in @class.Fields)
                    field.Visit(this);

                WriteCloseBraceIndent();
                NewLine();
            }
            
            VisitDeclContext(@class);

            WriteLine("@end");

            PopBlock(NewLineKind.BeforeNextBlock);

            return true;
        }

        public override bool VisitFieldDecl(Field field)
        {
            return this.GenerateObjCField(field);
        }
    }
}

{'fraction_non_alphanumeric': 0.091094956837801, 'fraction_numerical': 0.004543389368468878, 'mean_word_length': 1.6161616161616161, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '6067648', 'n_tokens_mistral': 1173, 'n_tokens_neox': 1058, 'n_words': 221}