<commit_before>﻿using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Generators;
using CppSharp.Generators.C;

namespace CppSharp.Passes
{
    public class SymbolsCodeGenerator : CodeGenerator
    {
        public override string FileExtension => "cpp";

        public SymbolsCodeGenerator(BindingContext context, IEnumerable<TranslationUnit> units)
            : base(context, units)
        {
        }

        public override void Process()
        {
            WriteLine("#define _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS");
            WriteLine("#define _LIBCPP_HIDE_FROM_ABI");
            NewLine();

            if (TranslationUnit.Module == Options.SystemModule)
                WriteLine("#include <string>");
            else
                foreach (var header in TranslationUnit.Module.Headers)
                    WriteLine($"#include <{header}>");
            NewLine();
        }

        public override bool VisitMethodDecl(Method method)
        {
            if (method.IsDestructor &&
                (!((Class) method.Namespace).HasNonTrivialDestructor ||
                 method.Access == AccessSpecifier.Private))
                return false;

            if (method.Namespace is ClassTemplateSpecialization &&
                (method.TranslationUnit.IsSystemHeader ||
                 ((method.IsConstructor || method.IsDestructor) &&
                  !method.IsImplicit && !method.IsDefaulted && !method.IsPure &&
                  string.IsNullOrEmpty(method.Body))))
            {
                WriteLine($"template {GetExporting()}{method.Visit(cppTypePrinter)};");
                return true;
            }
            if (method.IsConstructor)
            {
                WrapConstructor(method);
                return true;
            }
            if (method.IsDestructor)
            {
                WrapDestructor(method);
                return true;
            }
            return this.VisitFunctionDecl(method);
        }<commit_msg>Ensure generated symbols can use placement new<commit_after>﻿using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Generators;
using CppSharp.Generators.C;

namespace CppSharp.Passes
{
    public class SymbolsCodeGenerator : CodeGenerator
    {
        public override string FileExtension => "cpp";

        public SymbolsCodeGenerator(BindingContext context, IEnumerable<TranslationUnit> units)
            : base(context, units)
        {
        }

        public override void Process()
        {
            WriteLine("#define _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS");
            WriteLine("#define _LIBCPP_HIDE_FROM_ABI");
            NewLine();

            if (TranslationUnit.Module == Options.SystemModule)
                WriteLine("#include <string>");
            else
                foreach (var header in TranslationUnit.Module.Headers)
                    WriteLine($"#include <{header}>");
            WriteLine("#include <new>");
            NewLine();
        }

        public override bool VisitMethodDecl(Method method)
        {
            if (method.IsDestructor &&
                (!((Class) method.Namespace).HasNonTrivialDestructor ||
                 method.Access == AccessSpecifier.Private))
                return false;

            if (method.Namespace is ClassTemplateSpecialization &&
                (method.TranslationUnit.IsSystemHeader ||
                 ((method.IsConstructor || method.IsDestructor) &&
                  !method.IsImplicit && !method.IsDefaulted && !method.IsPure &&
                  string.IsNullOrEmpty(method.Body))))
            {
                WriteLine($"template {GetExporting()}{method.Visit(cppTypePrinter)};");
                return true;
            }
            if (method.IsConstructor)
            {
                WrapConstructor(method);
                return true;
            }
            if (method.IsDestructor)
            {
                WrapDestructor(method);
                return true;
            }
            return this.VisitFunctionDecl(method);
        }
{'fraction_non_alphanumeric': 0.09414519906323185, 'fraction_numerical': 0.0, 'mean_word_length': 1.864520456069752, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 12, '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': '3621545', 'n_tokens_mistral': 1084, 'n_tokens_neox': 1020, 'n_words': 202}