using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using CppSharp.AST; using CppSharp.Generators; namespace CppSharp { public enum GenerationOutputMode { FilePerModule, FilePerUnit } public class DriverOptions { public DriverOptions() { OutputDir = Directory.GetCurrentDirectory(); SystemModule = new Module("Std") { OutputNamespace = string.Empty }; Modules = new List { SystemModule }; GeneratorKind = GeneratorKind.CSharp; OutputInteropIncludes = true; StripLibPrefix = true; ExplicitlyPatchedVirtualFunctions = new HashSet(); } #region General options /// /// Set to true to enable quiet output mode. /// public bool Quiet; /// /// Set to true to enable verbose output mode. /// public bool Verbose; /// /// Set to true to simulate generating without actually writing /// any output to disk. /// public bool DryRun; /// /// Whether the generated code should be automatically compiled. /// public bool CompileCode; #endregion #region Module options public Module SystemModule { get; } public List Modules { get; } public Module AddModule(string libraryName) { var module = new Module(libraryName); Modules.Add(module); return module; } public bool DoAllModulesHaveLibraries() => Modules.All(m => m == SystemModule || m.Libraries.Count > 0); #endregion public CompilationOptions Compilation = new CompilationOptions(); #region Generator options public GeneratorKind GeneratorKind; public bool CheckSymbols; public string OutputDir; public bool OutputInteropIncludes; public bool GenerateFunctionTemplates; /// /// C# only: gets or sets a value indicating whether to generate class templates. /// Still experimental - do not use in production. /// /// /// true to generate class templates; otherwise, false. /// public bool GenerateClassTemplates { get; set; } public bool AllowRenaming { get; set; } = true; public bool PutAllGlobalsInGlobalClass { get; set; } = false; public bool GenerateInternalImports; public bool GenerateSequentialLayout { get; set; } = true; public bool UseHeaderDirectories; /// /// If set to true, the generated code will be generated with extra /// debug output. /// public bool GenerateDebugOutput; /// /// If set to true the CLI generator will use ObjectOverridesPass to create /// Equals, GetHashCode and (if the insertion operator << is overloaded) /// ToString methods. /// public bool GenerateObjectOverrides; //List of include directories that are used but not generated public List NoGenIncludeDirs; /// /// Enable this option to enable generation of finalizers. Works in both CLI and /// C# backends. /// /// /// Use to specify a filter so that /// finalizers are generated for only a subset of classes. /// public bool GenerateFinalizers; /// /// A filter that can restrict the classes for which finalizers are generated when /// is true. /// /// /// The default filter performs no filtering so that whenever is true, finalizers will be generated for /// all classes. If finalizers should be generated selectively, inspect the /// supplied parameter and return true if a finalizer /// should be generated and false if a finalizer should not be generated. /// public Func GenerateFinalizersFilter = (@class) => true; /// /// An internal convenience method that combines the effect of and . /// /// /// The to be filtered by . /// /// /// true if a finalizer should be generated for . /// false if a finalizer should not be generated for . /// internal bool GenerateFinalizerFor(Class @class) => GenerateFinalizers && GenerateFinalizersFilter(@class); /// /// If returns true for a given , /// unmanaged memory allocated in the class' default constructor will be initialized with /// zeros. The default implementation always returns false. Currently, C# only. /// /// /// If this option returns true, you must take a reference to the nuget package /// System.Runtime.CompilerServices.Unsafe in the project(s) containing the generated file(s) to /// resolve the Unsafe.InitBlock method. /// public Func ZeroAllocatedMemory = (@class) => false; public string IncludePrefix; public Func GenerateName; /// /// Set this option to the kind of comments that you want generated /// in the source code. This overrides the default kind set by the /// target generator. /// public CommentKind? CommentKind; public Encoding Encoding { get; set; } = Encoding.UTF8; public bool IsCSharpGenerator => GeneratorKind == GeneratorKind.CSharp; public bool IsCppGenerator => GeneratorKind == GeneratorKind.CPlusPlus; public bool IsCLIGenerator => GeneratorKind == GeneratorKind.CLI; public readonly List DependentNameSpaces = new List(); public bool MarshalCharAsManagedChar { get; set; } /// /// Use Span Struct instead of Managed Array /// public bool UseSpan { get; set; } /// /// Generates a single C# file. /// [Obsolete("Use the more general GenerationOutputMode property instead.")] public bool GenerateSingleCSharpFile { get { return GenerationOutputMode == GenerationOutputMode.FilePerModule; } set { GenerationOutputMode = value ? GenerationOutputMode.FilePerModule : GenerationOutputMode.FilePerUnit; } } /// /// Sets the generation output mode which affects how output files are /// generated, either as one output file per binding module, or as one /// output file for each input translation unit. /// Note: Currently only available for C# generator. /// public GenerationOutputMode GenerationOutputMode { get; set; } = GenerationOutputMode.FilePerModule; /// /// Generates default values of arguments in the C# code. /// public bool GenerateDefaultValuesForArguments { get; set; } /// /// If set to false, then deprecated C/C++ declarations (those that have /// the `__attribute__((deprecated))` or equivalent attribute) will not be /// generated. /// public bool GenerateDeprecatedDeclarations { get; set; } = true; public bool StripLibPrefix { get; set; } /// /// C# end only: force patching of the virtual entries of the functions in this list. /// public HashSet ExplicitlyPatchedVirtualFunctions { get; } public bool UsePropertyDetectionHeuristics { get; set; } = true; /// /// Experimental option that makes the C/C++ generator generate some extra data storage /// on the generated instance, for supporting higher-level binding of the code. /// public bool GenerateExternalDataFields { get; set; } = false; #endregion } public class InvalidOptionException : Exception { public InvalidOptionException(string message) : base(message) { } } }