<commit_before>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using CppSharp;
using CppSharp.AST;
using CppSharp.Generators;
using CppSharp.Passes;
using MonoManagedToNative.Generators;
using MonoManagedToNative.Passes;
using BindingContext = CppSharp.Generators.BindingContext;

namespace MonoManagedToNative
{
    public class Driver
    {
        public Options Options { get; private set; }
        public IDiagnostics Diagnostics { get; private set; }

        public BindingContext Context { get; private set; }

        public List<IKVM.Reflection.Assembly> Assemblies { get; private set; }

        public ProjectOutput Output { get; private set; }

        public Driver(Options options, IDiagnostics diagnostics = null)
        {
            Options = options;
            Diagnostics = diagnostics;

            if (Diagnostics == null)
                Diagnostics = new TextDiagnosticPrinter();

            if (Options.OutputDir == null)
                Options.OutputDir = Directory.GetCurrentDirectory();

            Assemblies = new List<IKVM.Reflection.Assembly>();

            Context = new BindingContext(Diagnostics, new DriverOptions());
            Context.ASTContext = new ASTContext();

            CppSharp.AST.Type.TypePrinterDelegate = type =>
            {
                var typePrinter = new CppTypePrinter();
                return type.Visit(typePrinter);
            };
        }

        bool Parse()
        {
            var parser = new Parser();
            parser.OnAssemblyParsed += HandleAssemblyParsed;

            return parser.Parse(Options.Project);
        }

        void Process()
        {
            var astGenerator = new ASTGenerator(Context.ASTContext, Options);

            foreach (var assembly in Assemblies)
                astGenerator.Visit(assembly);

            if (Options.Language != GeneratorKind.CPlusPlus)
                Context.TranslationUnitPasses.AddPass(new RenameEnumItemsPass());

            Context.TranslationUnitPasses.AddPass(new RenameDuplicatedDeclsPass());
            Context.TranslationUnitPasses.AddPass(new CheckDuplicatedNamesPass());
            Context.RunPasses();
        }

        public static string GetSupportDirectory()
        {
            var directory = Directory.GetParent(Directory.GetCurrentDirectory());

            while (directory != null)
            {
                var path = Path.Combine(directory.FullName, "support");

                if (Directory.Exists(path))
                    return path;

                directory = directory.Parent;
            }<commit_msg>Added CheckIgnoredDeclsPass to check unsupported types more robustly.<commit_after>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using CppSharp;
using CppSharp.AST;
using CppSharp.Generators;
using CppSharp.Passes;
using MonoManagedToNative.Generators;
using MonoManagedToNative.Passes;
using BindingContext = CppSharp.Generators.BindingContext;

namespace MonoManagedToNative
{
    public class Driver
    {
        public Options Options { get; private set; }
        public IDiagnostics Diagnostics { get; private set; }

        public BindingContext Context { get; private set; }

        public List<IKVM.Reflection.Assembly> Assemblies { get; private set; }

        public ProjectOutput Output { get; private set; }

        public Driver(Options options, IDiagnostics diagnostics = null)
        {
            Options = options;
            Diagnostics = diagnostics;

            if (Diagnostics == null)
                Diagnostics = new TextDiagnosticPrinter();

            if (Options.OutputDir == null)
                Options.OutputDir = Directory.GetCurrentDirectory();

            Assemblies = new List<IKVM.Reflection.Assembly>();

            Context = new BindingContext(Diagnostics, new DriverOptions());
            Context.ASTContext = new ASTContext();

            CppSharp.AST.Type.TypePrinterDelegate = type =>
            {
                var typePrinter = new CppTypePrinter();
                return type.Visit(typePrinter);
            };
        }

        bool Parse()
        {
            var parser = new Parser();
            parser.OnAssemblyParsed += HandleAssemblyParsed;

            return parser.Parse(Options.Project);
        }

        void Process()
        {
            var astGenerator = new ASTGenerator(Context.ASTContext, Options);

            foreach (var assembly in Assemblies)
                astGenerator.Visit(assembly);

            Context.TranslationUnitPasses.AddPass(new CheckIgnoredDeclsPass());

            if (Options.Language != GeneratorKind.CPlusPlus)
                Context.TranslationUnitPasses.AddPass(new RenameEnumItemsPass());

            Context.TranslationUnitPasses.AddPass(new RenameDuplicatedDeclsPass());
            Context.TranslationUnitPasses.AddPass(new CheckDuplicatedNamesPass());
            Context.RunPasses();
        }

        public static string GetSupportDirectory()
        {
            var directory = Directory.GetParent(Directory.GetCurrentDirectory());

            while (directory != null)
            {
                var path = Path.Combine(directory.FullName, "support");

                if (Directory.Exists(path))
                    return path;

                directory = directory.Parent;
            }
{'fraction_non_alphanumeric': 0.08224710850009179, 'fraction_numerical': 0.0, 'mean_word_length': 2.204705882352941, 'pattern_counts': {'":': 0, '<': 7, '<?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': '5238774', 'n_tokens_mistral': 1378, 'n_tokens_neox': 1290, 'n_words': 315}