Browse Source

Remove the Driver dependency from the generators with a BindingContext.

pull/696/head
Joao Matos 10 years ago
parent
commit
4e48af9a4c
  1. 57
      src/Generator/BindingContext.cs
  2. 117
      src/Generator/Driver.cs
  3. 15
      src/Generator/Generator.cs
  4. 12
      src/Generator/Generators/CLI/CLIGenerator.cs
  5. 16
      src/Generator/Generators/CLI/CLIHeaders.cs
  6. 24
      src/Generator/Generators/CLI/CLIMarshal.cs
  7. 38
      src/Generator/Generators/CLI/CLISources.cs
  8. 6
      src/Generator/Generators/CLI/CLITemplate.cs
  9. 19
      src/Generator/Generators/CLI/CLITypePrinter.cs
  10. 8
      src/Generator/Generators/CSharp/CSharpGenerator.cs
  11. 42
      src/Generator/Generators/CSharp/CSharpMarshal.cs
  12. 68
      src/Generator/Generators/CSharp/CSharpSources.cs
  13. 32
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs
  14. 6
      src/Generator/Generators/Marshal.cs
  15. 17
      src/Generator/Generators/Template.cs
  16. 2
      src/Generator/Passes/CheckAbiParameters.cs
  17. 2
      src/Generator/Passes/CheckAmbiguousFunctions.cs
  18. 8
      src/Generator/Passes/CheckDuplicatedNamesPass.cs
  19. 42
      src/Generator/Passes/CheckIgnoredDecls.cs
  20. 2
      src/Generator/Passes/CheckMacrosPass.cs
  21. 6
      src/Generator/Passes/CheckOperatorsOverloads.cs
  22. 2
      src/Generator/Passes/CheckStaticClass.cs
  23. 2
      src/Generator/Passes/CheckVTableComponentsPass.cs
  24. 2
      src/Generator/Passes/CheckVirtualOverrideReturnCovariance.cs
  25. 2
      src/Generator/Passes/CleanInvalidDeclNamesPass.cs
  26. 17
      src/Generator/Passes/CleanUnitPass.cs
  27. 4
      src/Generator/Passes/ConstructorToConversionOperatorPass.cs
  28. 18
      src/Generator/Passes/DelegatesPass.cs
  29. 2
      src/Generator/Passes/FieldToPropertyPass.cs
  30. 7
      src/Generator/Passes/FindSymbolsPass.cs
  31. 4
      src/Generator/Passes/FunctionToInstanceMethodPass.cs
  32. 4
      src/Generator/Passes/FunctionToStaticMethodPass.cs
  33. 6
      src/Generator/Passes/GenerateInlinesCodePass.cs
  34. 8
      src/Generator/Passes/GenerateTemplatesCodePass.cs
  35. 12
      src/Generator/Passes/GetterSetterToPropertyAdvancedPass.cs
  36. 8
      src/Generator/Passes/GetterSetterToPropertyPass.cs
  37. 16
      src/Generator/Passes/HandleDefaultParamValuesPass.cs
  38. 2
      src/Generator/Passes/IgnoreSystemDeclarationsPass.cs
  39. 6
      src/Generator/Passes/MoveFunctionToClassPass.cs
  40. 2
      src/Generator/Passes/MoveOperatorToClassPass.cs
  41. 15
      src/Generator/Passes/ObjectOverridesPass.cs
  42. 17
      src/Generator/Passes/Pass.cs
  43. 9
      src/Generator/Passes/PassBuilder.cs
  44. 8
      src/Generator/Passes/ResolveIncompleteDeclsPass.cs
  45. 10
      src/Generator/Types/Std/Stdlib.cs

57
src/Generator/BindingContext.cs

@ -0,0 +1,57 @@ @@ -0,0 +1,57 @@
using CppSharp.AST;
using CppSharp.Generators.CLI;
using CppSharp.Generators.CSharp;
using CppSharp.Passes;
using CppSharp.Types;
using CppSharp.Parser;
using CppSharp.Utils;
using System.Collections.Generic;
namespace CppSharp.Generators
{
public class BindingContext
{
public IDiagnostics Diagnostics { get; set; }
public DriverOptions Options { get; private set; }
public ASTContext ASTContext { get; set; }
public ParserTargetInfo TargetInfo { get; set; }
public SymbolContext Symbols { get; private set; }
public TypeMapDatabase TypeDatabase { get; private set; }
public PassBuilder<TranslationUnitPass> TranslationUnitPasses { get; private set; }
public PassBuilder<GeneratorOutputPass> GeneratorOutputPasses { get; private set; }
public Dictionary<Function, DelegatesPass.DelegateDefinition> Delegates { get; private set; }
private static readonly Dictionary<string, string> libraryMappings = new Dictionary<string, string>();
public BindingContext(IDiagnostics diagnostics, DriverOptions options)
{
Options = options;
Diagnostics = diagnostics;
Symbols = new SymbolContext();
Delegates = new Dictionary<Function, DelegatesPass.DelegateDefinition>();
TypeDatabase = new TypeMapDatabase();
TypeDatabase.SetupTypeMaps(Options.GeneratorKind);
TranslationUnitPasses = new PassBuilder<TranslationUnitPass>(this);
GeneratorOutputPasses = new PassBuilder<GeneratorOutputPass>(this);
}
public void RunPasses()
{
TranslationUnitPasses.RunPasses(pass =>
{
Diagnostics.Debug("Pass '{0}'", pass);
Diagnostics.PushIndent();
pass.VisitLibrary(ASTContext);
Diagnostics.PopIndent();
});
}
}
}

117
src/Generator/Driver.cs

@ -20,36 +20,19 @@ namespace CppSharp @@ -20,36 +20,19 @@ namespace CppSharp
{
public class Driver
{
public IDiagnostics Diagnostics { get; set; }
public IDiagnostics Diagnostics { get; private set; }
public DriverOptions Options { get; private set; }
public Project Project { get; private set; }
public TypeMapDatabase TypeDatabase { get; private set; }
public PassBuilder<TranslationUnitPass> TranslationUnitPasses { get; private set; }
public PassBuilder<GeneratorOutputPass> GeneratorOutputPasses { get; private set; }
public BindingContext Context { get; private set; }
public Generator Generator { get; private set; }
public ASTContext ASTContext { get; private set; }
public SymbolContext Symbols { get; private set; }
public Dictionary<Function, DelegatesPass.DelegateDefinition> Delegates { get; private set; }
public bool HasCompilationErrors { get; set; }
private static readonly Dictionary<string, string> libraryMappings = new Dictionary<string, string>();
public Driver(DriverOptions options, IDiagnostics diagnostics)
{
Options = options;
Diagnostics = diagnostics;
Project = new Project();
ASTContext = new ASTContext();
Symbols = new SymbolContext();
Delegates = new Dictionary<Function, DelegatesPass.DelegateDefinition>();
TypeDatabase = new TypeMapDatabase();
TranslationUnitPasses = new PassBuilder<TranslationUnitPass>(this);
GeneratorOutputPasses = new PassBuilder<GeneratorOutputPass>(this);
}
Generator CreateGeneratorFromKind(GeneratorKind kind)
@ -57,9 +40,9 @@ namespace CppSharp @@ -57,9 +40,9 @@ namespace CppSharp
switch (kind)
{
case GeneratorKind.CLI:
return new CLIGenerator(this);
return new CLIGenerator(Context);
case GeneratorKind.CSharp:
return new CSharpGenerator(this);
return new CSharpGenerator(Context);
}
return null;
@ -81,16 +64,6 @@ namespace CppSharp @@ -81,16 +64,6 @@ namespace CppSharp
options.addIncludeDirs(incDir);
}
public void Setup()
{
ValidateOptions(Options);
SetupIncludes();
TypeDatabase.SetupTypeMaps(Options.GeneratorKind);
Generator = CreateGeneratorFromKind(Options.GeneratorKind);
}
public void SetupIncludes()
{
if (Platform.IsMacOS)
@ -99,21 +72,12 @@ namespace CppSharp @@ -99,21 +72,12 @@ namespace CppSharp
Options.SetupMSVC();
}
public void SortModulesByDependencies()
public void Setup()
{
if (Options.Modules.All(m => m.Libraries.Any()))
{
var sortedModules = Options.Modules.TopologicalSort(m =>
{
return from library in Symbols.Libraries
where m.Libraries.Contains(library.FileName)
from module in Options.Modules
where library.Dependencies.Intersect(module.Libraries).Any()
select module;
});
Options.Modules.Clear();
Options.Modules.AddRange(sortedModules);
}
ValidateOptions(Options);
SetupIncludes();
Context = new BindingContext(Diagnostics, Options);
Generator = CreateGeneratorFromKind(Options.GeneratorKind);
}
void OnSourceFileParsed(IList<SourceFile> files, ParserResult result)
@ -244,9 +208,8 @@ namespace CppSharp @@ -244,9 +208,8 @@ namespace CppSharp
parser.SourcesParsed += OnSourceFileParsed;
parser.ParseProject(Project, Options.UnityBuild);
TargetInfo = parser.GetTargetInfo(Options);
ASTContext = ClangParser.ConvertASTContext(parser.ASTContext);
Context.TargetInfo = parser.GetTargetInfo(Options);
Context.ASTContext = ClangParser.ConvertASTContext(parser.ASTContext);
return !hasParsingErrors;
}
@ -265,6 +228,23 @@ namespace CppSharp @@ -265,6 +228,23 @@ namespace CppSharp
public ParserTargetInfo TargetInfo { get; set; }
public void SortModulesByDependencies()
{
if (Options.Modules.All(m => m.Libraries.Any()))
{
var sortedModules = Options.Modules.TopologicalSort(m =>
{
return from library in Context.Symbols.Libraries
where m.Libraries.Contains(library.FileName)
from module in Options.Modules
where library.Dependencies.Intersect(module.Libraries).Any()
select module;
});
Options.Modules.Clear();
Options.Modules.AddRange(sortedModules);
}
}
public bool ParseLibraries()
{
foreach (var module in Options.Modules)
@ -274,7 +254,7 @@ namespace CppSharp @@ -274,7 +254,7 @@ namespace CppSharp
foreach (var library in module.Libraries)
{
if (Symbols.Libraries.Any(l => l.FileName == library))
if (Context.Symbols.Libraries.Any(l => l.FileName == library))
continue;
var parser = new ClangParser();
@ -285,18 +265,23 @@ namespace CppSharp @@ -285,18 +265,23 @@ namespace CppSharp
if (res.Kind != ParserResultKind.Success)
continue;
Symbols.Libraries.Add(ClangParser.ConvertLibrary(res.Library));
Context.Symbols.Libraries.Add(ClangParser.ConvertLibrary(res.Library));
res.Library.Dispose();
}
}
}
Context.Symbols.IndexSymbols();
SortModulesByDependencies();
return true;
}
public void SetupPasses(ILibrary library)
{
var TranslationUnitPasses = Context.TranslationUnitPasses;
TranslationUnitPasses.AddPass(new SortDeclarationsPass());
TranslationUnitPasses.AddPass(new ResolveIncompleteDeclsPass());
if (Options.IsCSharpGenerator)
@ -365,14 +350,7 @@ namespace CppSharp @@ -365,14 +350,7 @@ namespace CppSharp
public void ProcessCode()
{
TranslationUnitPasses.RunPasses(pass =>
{
Diagnostics.Debug("Pass '{0}'", pass);
Diagnostics.PushIndent(4);
pass.VisitLibrary(ASTContext);
Diagnostics.PopIndent();
});
Context.RunPasses();
Generator.Process();
}
@ -415,6 +393,8 @@ namespace CppSharp @@ -415,6 +393,8 @@ namespace CppSharp
}
}
private static readonly Dictionary<string, string> libraryMappings = new Dictionary<string, string>();
public void CompileCode(AST.Module module)
{
var assemblyFile = string.IsNullOrEmpty(module.LibraryName) ?
@ -447,7 +427,7 @@ namespace CppSharp @@ -447,7 +427,7 @@ namespace CppSharp
var locationRuntime = Path.Combine(outputDir, "CppSharp.Runtime.dll");
compilerParameters.ReferencedAssemblies.Add(locationRuntime);
compilerParameters.ReferencedAssemblies.AddRange(Symbols.Libraries.SelectMany(
compilerParameters.ReferencedAssemblies.AddRange(Context.Symbols.Libraries.SelectMany(
lib => lib.Dependencies.Where(
d => libraryMappings.ContainsKey(d) &&
!compilerParameters.ReferencedAssemblies.Contains(libraryMappings[d]))
@ -480,12 +460,12 @@ namespace CppSharp @@ -480,12 +460,12 @@ namespace CppSharp
public void AddTranslationUnitPass(TranslationUnitPass pass)
{
TranslationUnitPasses.AddPass(pass);
Context.TranslationUnitPasses.AddPass(pass);
}
public void AddGeneratorOutputPass(GeneratorOutputPass pass)
{
GeneratorOutputPasses.AddPass(pass);
Context.GeneratorOutputPasses.AddPass(pass);
}
private bool hasParsingErrors;
@ -513,15 +493,9 @@ namespace CppSharp @@ -513,15 +493,9 @@ namespace CppSharp
if (!driver.ParseLibraries())
return;
if (!options.Quiet)
Log.Message("Indexing library symbols...");
driver.Symbols.IndexSymbols();
if (!options.Quiet)
Log.Message("Parsing code...");
driver.SortModulesByDependencies();
driver.BuildParseOptions();
if (!driver.ParseCode())
@ -530,18 +504,18 @@ namespace CppSharp @@ -530,18 +504,18 @@ namespace CppSharp
return;
}
new CleanUnitPass(options).VisitLibrary(driver.ASTContext);
new CleanUnitPass().VisitLibrary(driver.Context.ASTContext);
options.Modules.RemoveAll(m => m != options.SystemModule && !m.Units.GetGenerated().Any());
if (!options.Quiet)
Log.Message("Processing code...");
library.Preprocess(driver, driver.ASTContext);
library.Preprocess(driver, driver.Context.ASTContext);
driver.SetupPasses(library);
driver.ProcessCode();
library.Postprocess(driver, driver.ASTContext);
library.Postprocess(driver, driver.Context.ASTContext);
if (!options.Quiet)
Log.Message("Generating code...");
@ -550,9 +524,8 @@ namespace CppSharp @@ -550,9 +524,8 @@ namespace CppSharp
foreach (var output in outputs)
{
foreach (var pass in driver.GeneratorOutputPasses.Passes)
foreach (var pass in driver.Context.GeneratorOutputPasses.Passes)
{
pass.Driver = driver;
pass.VisitGeneratorOutput(output);
}
}

15
src/Generator/Generator.cs

@ -38,11 +38,11 @@ namespace CppSharp.Generators @@ -38,11 +38,11 @@ namespace CppSharp.Generators
{
public static string CurrentOutputNamespace = string.Empty;
public Driver Driver { get; private set; }
public BindingContext Context { get; private set; }
protected Generator(Driver driver)
protected Generator(BindingContext context)
{
Driver = driver;
Context = context;
CppSharp.AST.Type.TypePrinterDelegate += TypePrinterDelegate;
}
@ -71,11 +71,13 @@ namespace CppSharp.Generators @@ -71,11 +71,13 @@ namespace CppSharp.Generators
{
var outputs = new List<GeneratorOutput>();
var units = Driver.ASTContext.TranslationUnits.GetGenerated().ToList();
if (Driver.Options.IsCSharpGenerator)
var units = Context.ASTContext.TranslationUnits.GetGenerated().ToList();
if (Context.Options.IsCSharpGenerator)
GenerateSingleTemplate(outputs);
else
GenerateTemplates(outputs, units.Where(u => !u.IsSystemHeader));
return outputs;
}
@ -99,6 +101,7 @@ namespace CppSharp.Generators @@ -99,6 +101,7 @@ namespace CppSharp.Generators
TranslationUnit = unit,
Templates = templates
};
outputs.Add(output);
OnUnitGenerated(output);
@ -107,7 +110,7 @@ namespace CppSharp.Generators @@ -107,7 +110,7 @@ namespace CppSharp.Generators
private void GenerateSingleTemplate(ICollection<GeneratorOutput> outputs)
{
foreach (var module in Driver.Options.Modules)
foreach (var module in Context.Options.Modules)
{
CurrentOutputNamespace = module.OutputNamespace;
var output = new GeneratorOutput

12
src/Generator/Generators/CLI/CLIGenerator.cs

@ -11,19 +11,19 @@ namespace CppSharp.Generators.CLI @@ -11,19 +11,19 @@ namespace CppSharp.Generators.CLI
{
private readonly CLITypePrinter typePrinter;
public CLIGenerator(Driver driver) : base(driver)
public CLIGenerator(BindingContext context) : base(context)
{
typePrinter = new CLITypePrinter(driver);
typePrinter = new CLITypePrinter(context);
}
public override List<Template> Generate(IEnumerable<TranslationUnit> units)
{
var outputs = new List<Template>();
var header = new CLIHeaders(Driver, units);
var header = new CLIHeaders(Context, units);
outputs.Add(header);
var source = new CLISources(Driver, units);
var source = new CLISources(Context, units);
outputs.Add(source);
return outputs;
@ -33,8 +33,8 @@ namespace CppSharp.Generators.CLI @@ -33,8 +33,8 @@ namespace CppSharp.Generators.CLI
{
// Note: The ToString override will only work if this pass runs
// after the MoveOperatorToCallPass.
if (Driver.Options.GenerateObjectOverrides)
Driver.TranslationUnitPasses.AddPass(new ObjectOverridesPass());
if (Context.Options.GenerateObjectOverrides)
Context.TranslationUnitPasses.AddPass(new ObjectOverridesPass(this));
return true;
}

16
src/Generator/Generators/CLI/CLIHeaders.cs

@ -15,8 +15,8 @@ namespace CppSharp.Generators.CLI @@ -15,8 +15,8 @@ namespace CppSharp.Generators.CLI
{
public override string FileExtension { get { return "h"; } }
public CLIHeaders(Driver driver, IEnumerable<TranslationUnit> units)
: base(driver, units)
public CLIHeaders(BindingContext context, IEnumerable<TranslationUnit> units)
: base(context, units)
{
}
@ -52,8 +52,8 @@ namespace CppSharp.Generators.CLI @@ -52,8 +52,8 @@ namespace CppSharp.Generators.CLI
public void GenerateIncludeForwardRefs()
{
var typeReferenceCollector = new CLITypeReferenceCollector(Driver.TypeDatabase,
Driver.Options);
var typeReferenceCollector = new CLITypeReferenceCollector(Context.TypeDatabase,
Context.Options);
typeReferenceCollector.Process(TranslationUnit, filterNamespaces: false);
var includes = new SortedSet<string>(StringComparer.InvariantCulture);
@ -131,8 +131,8 @@ namespace CppSharp.Generators.CLI @@ -131,8 +131,8 @@ namespace CppSharp.Generators.CLI
public void GenerateForwardRefs()
{
var typeReferenceCollector = new CLITypeReferenceCollector(Driver.TypeDatabase,
Driver.Options);
var typeReferenceCollector = new CLITypeReferenceCollector(Context.TypeDatabase,
Context.Options);
typeReferenceCollector.Process(TranslationUnit);
var typeReferences = typeReferenceCollector.TypeReferences;
@ -336,7 +336,7 @@ namespace CppSharp.Generators.CLI @@ -336,7 +336,7 @@ namespace CppSharp.Generators.CLI
printer.TypePrinterContext = typeCtx;
var typePrinter = new CLITypePrinter(Driver, typeCtx);
var typePrinter = new CLITypePrinter(Context, typeCtx);
var retType = function.ReturnType.Type.Visit(typePrinter,
function.ReturnType.Qualifiers);
@ -493,7 +493,7 @@ namespace CppSharp.Generators.CLI @@ -493,7 +493,7 @@ namespace CppSharp.Generators.CLI
WriteLine("void add({0} evt);", @event.Type);
WriteLine("void remove({0} evt);", @event.Type);
var cliTypePrinter = new CLITypePrinter(Driver);
var cliTypePrinter = new CLITypePrinter(Context);
var cliArgs = cliTypePrinter.VisitParameters(@event.Parameters, hasNames: true);
WriteLine("void raise({0});", cliArgs);

24
src/Generator/Generators/CLI/CLIMarshal.cs

@ -20,7 +20,7 @@ namespace CppSharp.Generators.CLI @@ -20,7 +20,7 @@ namespace CppSharp.Generators.CLI
public override bool VisitType(Type type, TypeQualifiers quals)
{
TypeMap typeMap;
if (Context.Driver.TypeDatabase.FindTypeMap(type, out typeMap) && typeMap.DoesMarshalling)
if (Context.Context.TypeDatabase.FindTypeMap(type, out typeMap) && typeMap.DoesMarshalling)
{
typeMap.Type = type;
typeMap.CLIMarshalToManaged(Context);
@ -155,7 +155,7 @@ namespace CppSharp.Generators.CLI @@ -155,7 +155,7 @@ namespace CppSharp.Generators.CLI
}
TypeMap typeMap = null;
Context.Driver.TypeDatabase.FindTypeMap(pointee, out typeMap);
Context.Context.TypeDatabase.FindTypeMap(pointee, out typeMap);
Class @class;
if (pointee.TryGetClass(out @class) && typeMap == null)
@ -175,7 +175,7 @@ namespace CppSharp.Generators.CLI @@ -175,7 +175,7 @@ namespace CppSharp.Generators.CLI
Encoding.ASCII : Encoding.Unicode;
if (Equals(encoding, Encoding.ASCII))
encoding = Context.Driver.Options.Encoding;
encoding = Context.Context.Options.Encoding;
string param;
if (Equals(encoding, Encoding.ASCII))
@ -185,7 +185,7 @@ namespace CppSharp.Generators.CLI @@ -185,7 +185,7 @@ namespace CppSharp.Generators.CLI
param = "E_UTF16";
else
throw new NotSupportedException(string.Format("{0} is not supported yet.",
Context.Driver.Options.Encoding.EncodingName));
Context.Context.Options.Encoding.EncodingName));
return string.Format(
"({0} == 0 ? nullptr : clix::marshalString<clix::{1}>({0}))",
@ -237,7 +237,7 @@ namespace CppSharp.Generators.CLI @@ -237,7 +237,7 @@ namespace CppSharp.Generators.CLI
var decl = typedef.Declaration;
TypeMap typeMap;
if (Context.Driver.TypeDatabase.FindTypeMap(decl, out typeMap) && typeMap.DoesMarshalling)
if (Context.Context.TypeDatabase.FindTypeMap(decl, out typeMap) && typeMap.DoesMarshalling)
{
typeMap.Type = typedef;
typeMap.CLIMarshalToManaged(Context);
@ -262,7 +262,7 @@ namespace CppSharp.Generators.CLI @@ -262,7 +262,7 @@ namespace CppSharp.Generators.CLI
TypeQualifiers quals)
{
TypeMap typeMap;
if (Context.Driver.TypeDatabase.FindTypeMap(template, out typeMap) && typeMap.DoesMarshalling)
if (Context.Context.TypeDatabase.FindTypeMap(template, out typeMap) && typeMap.DoesMarshalling)
{
typeMap.Type = template;
typeMap.CLIMarshalToManaged(Context);
@ -374,7 +374,7 @@ namespace CppSharp.Generators.CLI @@ -374,7 +374,7 @@ namespace CppSharp.Generators.CLI
private string ToCLITypeName(Declaration decl)
{
var typePrinter = new CLITypePrinter(Context.Driver);
var typePrinter = new CLITypePrinter(Context.Context);
return typePrinter.VisitDeclaration(decl);
}
@ -426,7 +426,7 @@ namespace CppSharp.Generators.CLI @@ -426,7 +426,7 @@ namespace CppSharp.Generators.CLI
public override bool VisitType(Type type, TypeQualifiers quals)
{
TypeMap typeMap;
if (Context.Driver.TypeDatabase.FindTypeMap(type, out typeMap) && typeMap.DoesMarshalling)
if (Context.Context.TypeDatabase.FindTypeMap(type, out typeMap) && typeMap.DoesMarshalling)
{
typeMap.Type = type;
typeMap.CLIMarshalToNative(Context);
@ -611,7 +611,7 @@ namespace CppSharp.Generators.CLI @@ -611,7 +611,7 @@ namespace CppSharp.Generators.CLI
var decl = typedef.Declaration;
TypeMap typeMap;
if (Context.Driver.TypeDatabase.FindTypeMap(decl, out typeMap) && typeMap.DoesMarshalling)
if (Context.Context.TypeDatabase.FindTypeMap(decl, out typeMap) && typeMap.DoesMarshalling)
{
typeMap.CLIMarshalToNative(Context);
return typeMap.IsValueType;
@ -647,7 +647,7 @@ namespace CppSharp.Generators.CLI @@ -647,7 +647,7 @@ namespace CppSharp.Generators.CLI
TypeQualifiers quals)
{
TypeMap typeMap;
if (Context.Driver.TypeDatabase.FindTypeMap(template, out typeMap) && typeMap.DoesMarshalling)
if (Context.Context.TypeDatabase.FindTypeMap(template, out typeMap) && typeMap.DoesMarshalling)
{
typeMap.Type = template;
typeMap.CLIMarshalToNative(Context);
@ -693,7 +693,7 @@ namespace CppSharp.Generators.CLI @@ -693,7 +693,7 @@ namespace CppSharp.Generators.CLI
private void MarshalRefClass(Class @class)
{
TypeMap typeMap;
if (Context.Driver.TypeDatabase.FindTypeMap(@class, out typeMap) && typeMap.DoesMarshalling)
if (Context.Context.TypeDatabase.FindTypeMap(@class, out typeMap) && typeMap.DoesMarshalling)
{
typeMap.CLIMarshalToNative(Context);
return;
@ -775,7 +775,7 @@ namespace CppSharp.Generators.CLI @@ -775,7 +775,7 @@ namespace CppSharp.Generators.CLI
var fieldRef = string.Format("{0}.{1}", Context.Parameter.Name,
property.Name);
var marshalCtx = new MarshalContext(Context.Driver)
var marshalCtx = new MarshalContext(Context.Context)
{
ArgName = fieldRef,
ParameterIndex = Context.ParameterIndex++,

38
src/Generator/Generators/CLI/CLISources.cs

@ -16,8 +16,8 @@ namespace CppSharp.Generators.CLI @@ -16,8 +16,8 @@ namespace CppSharp.Generators.CLI
/// </summary>
public class CLISources : CLITemplate
{
public CLISources(Driver driver, IEnumerable<TranslationUnit> units)
: base(driver, units)
public CLISources(BindingContext context, IEnumerable<TranslationUnit> units)
: base(context, units)
{
}
@ -30,8 +30,8 @@ namespace CppSharp.Generators.CLI @@ -30,8 +30,8 @@ namespace CppSharp.Generators.CLI
var file = Path.GetFileNameWithoutExtension(TranslationUnit.FileName)
.Replace('\\', '/');
if (Driver.Options.GenerateName != null)
file = Driver.Options.GenerateName(TranslationUnit);
if (Context.Options.GenerateName != null)
file = Context.Options.GenerateName(TranslationUnit);
PushBlock(CLIBlockKind.Includes);
WriteLine("#include \"{0}.h\"", file);
@ -60,7 +60,7 @@ namespace CppSharp.Generators.CLI @@ -60,7 +60,7 @@ namespace CppSharp.Generators.CLI
{
PushBlock(CLIBlockKind.IncludesForwardReferences);
var typeReferenceCollector = new CLITypeReferenceCollector(Driver.TypeDatabase, Driver.Options);
var typeReferenceCollector = new CLITypeReferenceCollector(Context.TypeDatabase, Context.Options);
typeReferenceCollector.Process(TranslationUnit, filterNamespaces: false);
var includes = new SortedSet<string>(StringComparer.InvariantCulture);
@ -306,7 +306,7 @@ namespace CppSharp.Generators.CLI @@ -306,7 +306,7 @@ namespace CppSharp.Generators.CLI
printer.TypePrinterContext = typeCtx;
var typePrinter = new CLITypePrinter(Driver, typeCtx);
var typePrinter = new CLITypePrinter(Context, typeCtx);
var retType = function.ReturnType.Type.Visit(typePrinter,
function.ReturnType.Qualifiers);
@ -412,7 +412,7 @@ namespace CppSharp.Generators.CLI @@ -412,7 +412,7 @@ namespace CppSharp.Generators.CLI
variable = string.Format("((::{0}*)NativePtr)->{1}",
@class.QualifiedOriginalName, decl.OriginalName);
var ctx = new MarshalContext(Driver)
var ctx = new MarshalContext(Context)
{
Parameter = param,
ArgName = param.Name,
@ -424,7 +424,7 @@ namespace CppSharp.Generators.CLI @@ -424,7 +424,7 @@ namespace CppSharp.Generators.CLI
if (isIndexer)
{
var ctx2 = new MarshalContext(Driver)
var ctx2 = new MarshalContext(Context)
{
Parameter = indexParameter,
ArgName = indexParameter.Name
@ -499,7 +499,7 @@ namespace CppSharp.Generators.CLI @@ -499,7 +499,7 @@ namespace CppSharp.Generators.CLI
variable = string.Format("((::{0}*)NativePtr)->{1}",
@class.QualifiedOriginalName, decl.OriginalName);
var ctx = new MarshalContext(Driver)
var ctx = new MarshalContext(Context)
{
Declaration = decl,
ArgName = decl.Name,
@ -581,7 +581,7 @@ namespace CppSharp.Generators.CLI @@ -581,7 +581,7 @@ namespace CppSharp.Generators.CLI
private void GenerateEventRaise(Event @event, Class @class)
{
var typePrinter = new CLITypePrinter(Driver);
var typePrinter = new CLITypePrinter(Context);
var args = typePrinter.VisitParameters(@event.Parameters, hasNames: true);
WriteLine("void {0}::{1}::raise({2})", QualifiedIdentifier(@class),
@ -608,7 +608,7 @@ namespace CppSharp.Generators.CLI @@ -608,7 +608,7 @@ namespace CppSharp.Generators.CLI
var returns = new List<string>();
foreach (var param in @event.Parameters)
{
var ctx = new MarshalContext(Driver)
var ctx = new MarshalContext(Context)
{
ReturnVarName = param.Name,
ReturnType = param.QualifiedType
@ -701,7 +701,7 @@ namespace CppSharp.Generators.CLI @@ -701,7 +701,7 @@ namespace CppSharp.Generators.CLI
var nativeField = string.Format("{0}{1}",
nativeVar, property.Field.OriginalName);
var ctx = new MarshalContext(Driver)
var ctx = new MarshalContext(Context)
{
ArgName = property.Name,
ReturnVarName = nativeField,
@ -847,7 +847,7 @@ namespace CppSharp.Generators.CLI @@ -847,7 +847,7 @@ namespace CppSharp.Generators.CLI
var paramIndex = 0;
foreach (var param in method.Parameters)
{
var ctx = new MarshalContext(Driver)
var ctx = new MarshalContext(Context)
{
Function = method,
Parameter = param,
@ -883,7 +883,7 @@ namespace CppSharp.Generators.CLI @@ -883,7 +883,7 @@ namespace CppSharp.Generators.CLI
var varName = string.Format("_native.{0}", property.Field.OriginalName);
var ctx = new MarshalContext(Driver)
var ctx = new MarshalContext(Context)
{
ReturnVarName = varName,
ReturnType = property.QualifiedType
@ -959,7 +959,7 @@ namespace CppSharp.Generators.CLI @@ -959,7 +959,7 @@ namespace CppSharp.Generators.CLI
WriteLine("auto {0} = ::{1}();", valueMarshalName, @class.QualifiedOriginalName);
var param = new Parameter { Name = "(*this)" };
var ctx = new MarshalContext(Driver)
var ctx = new MarshalContext(Context)
{
MarshalVarPrefix = valueMarshalName,
Parameter = param
@ -1034,7 +1034,7 @@ namespace CppSharp.Generators.CLI @@ -1034,7 +1034,7 @@ namespace CppSharp.Generators.CLI
var nativeVarName = paramInfo.Name;
var ctx = new MarshalContext(Driver)
var ctx = new MarshalContext(Context)
{
ArgName = nativeVarName,
ReturnVarName = nativeVarName,
@ -1067,7 +1067,7 @@ namespace CppSharp.Generators.CLI @@ -1067,7 +1067,7 @@ namespace CppSharp.Generators.CLI
isIntPtr ? "System::IntPtr()" : "nullptr");
}
var ctx = new MarshalContext(Driver)
var ctx = new MarshalContext(Context)
{
ArgName = returnIdentifier,
ReturnVarName = returnIdentifier,
@ -1095,7 +1095,7 @@ namespace CppSharp.Generators.CLI @@ -1095,7 +1095,7 @@ namespace CppSharp.Generators.CLI
private void CheckArgumentRange(Function method)
{
if (Driver.Options.MarshalCharAsManagedChar)
if (Context.Options.MarshalCharAsManagedChar)
{
foreach (var param in method.Parameters.Where(
p => p.Type.IsPrimitiveType(PrimitiveType.Char)))
@ -1180,7 +1180,7 @@ namespace CppSharp.Generators.CLI @@ -1180,7 +1180,7 @@ namespace CppSharp.Generators.CLI
QualifiedType = new QualifiedType(paramType)
};
var ctx = new MarshalContext(Driver)
var ctx = new MarshalContext(Context)
{
Parameter = effectiveParam,
ParameterIndex = paramIndex,

6
src/Generator/Generators/CLI/CLITemplate.cs

@ -61,10 +61,10 @@ namespace CppSharp.Generators.CLI @@ -61,10 +61,10 @@ namespace CppSharp.Generators.CLI
public ISet<Include> Includes;
protected CLITemplate(Driver driver, IEnumerable<TranslationUnit> units)
: base(driver, units)
protected CLITemplate(BindingContext context, IEnumerable<TranslationUnit> units)
: base(context, units)
{
TypePrinter = new CLITypePrinter(driver);
TypePrinter = new CLITypePrinter(context);
Includes = new HashSet<Include>();
}

19
src/Generator/Generators/CLI/CLITypePrinter.cs

@ -23,24 +23,23 @@ namespace CppSharp.Generators.CLI @@ -23,24 +23,23 @@ namespace CppSharp.Generators.CLI
public class CLITypePrinter : ITypePrinter<string>, IDeclVisitor<string>
{
public Driver Driver { get; set; }
public CLITypePrinterContext TypePrinterContext { get; set; }
readonly ITypeMapDatabase TypeMapDatabase;
readonly DriverOptions Options;
public BindingContext Context { get; private set; }
public CLITypePrinter(Driver driver)
public DriverOptions Options { get { return Context.Options; } }
public TypeMapDatabase TypeMapDatabase { get { return Context.TypeDatabase; } }
public CLITypePrinter(BindingContext context)
{
Driver = driver;
TypeMapDatabase = driver.TypeDatabase;
Options = driver.Options;
Context = context;
TypePrinterContext = new CLITypePrinterContext();
}
public CLITypePrinter(Driver driver, CLITypePrinterContext context)
: this(driver)
public CLITypePrinter(BindingContext context, CLITypePrinterContext typePrinterContext)
: this(context)
{
TypePrinterContext = context;
TypePrinterContext = typePrinterContext;
}
public string VisitTagType(TagType tag, TypeQualifiers quals)

8
src/Generator/Generators/CSharp/CSharpGenerator.cs

@ -9,9 +9,9 @@ namespace CppSharp.Generators.CSharp @@ -9,9 +9,9 @@ namespace CppSharp.Generators.CSharp
private readonly CSharpTypePrinter typePrinter;
private readonly CSharpExpressionPrinter expressionPrinter;
public CSharpGenerator(Driver driver) : base(driver)
public CSharpGenerator(BindingContext context) : base(context)
{
typePrinter = new CSharpTypePrinter(driver);
typePrinter = new CSharpTypePrinter(context);
expressionPrinter = new CSharpExpressionPrinter(typePrinter);
}
@ -19,7 +19,7 @@ namespace CppSharp.Generators.CSharp @@ -19,7 +19,7 @@ namespace CppSharp.Generators.CSharp
{
var outputs = new List<Template>();
var template = new CSharpSources(Driver, units, typePrinter, expressionPrinter);
var template = new CSharpSources(Context, units, typePrinter, expressionPrinter);
outputs.Add(template);
return outputs;
@ -32,7 +32,7 @@ namespace CppSharp.Generators.CSharp @@ -32,7 +32,7 @@ namespace CppSharp.Generators.CSharp
// CheckAbiParameters runs last because hidden structure parameters
// should always occur first.
Driver.AddTranslationUnitPass(new CheckAbiParameters());
Context.TranslationUnitPasses.AddPass(new CheckAbiParameters());
return true;
}

42
src/Generator/Generators/CSharp/CSharpMarshal.cs

@ -19,8 +19,8 @@ namespace CppSharp.Generators.CSharp @@ -19,8 +19,8 @@ namespace CppSharp.Generators.CSharp
public class CSharpMarshalContext : MarshalContext
{
public CSharpMarshalContext(Driver driver)
: base(driver)
public CSharpMarshalContext(BindingContext context)
: base(context)
{
Kind = CSharpMarshalKind.Unknown;
ArgumentPrefix = new TextGenerator();
@ -56,7 +56,7 @@ namespace CppSharp.Generators.CSharp @@ -56,7 +56,7 @@ namespace CppSharp.Generators.CSharp
public CSharpMarshalNativeToManagedPrinter(CSharpMarshalContext context)
: base(context)
{
typePrinter = new CSharpTypePrinter(context.Driver);
typePrinter = new CSharpTypePrinter(context.Context);
}
public bool MarshalsParameter { get; set; }
@ -64,7 +64,7 @@ namespace CppSharp.Generators.CSharp @@ -64,7 +64,7 @@ namespace CppSharp.Generators.CSharp
public override bool VisitType(Type type, TypeQualifiers quals)
{
TypeMap typeMap;
if (Context.Driver.TypeDatabase.FindTypeMap(type, out typeMap) && typeMap.DoesMarshalling)
if (Context.Context.TypeDatabase.FindTypeMap(type, out typeMap) && typeMap.DoesMarshalling)
{
typeMap.Type = type;
typeMap.CSharpMarshalToManaged(Context);
@ -77,7 +77,7 @@ namespace CppSharp.Generators.CSharp @@ -77,7 +77,7 @@ namespace CppSharp.Generators.CSharp
public override bool VisitDeclaration(Declaration decl)
{
TypeMap typeMap;
if (Context.Driver.TypeDatabase.FindTypeMap(decl, out typeMap) && typeMap.DoesMarshalling)
if (Context.Context.TypeDatabase.FindTypeMap(decl, out typeMap) && typeMap.DoesMarshalling)
{
typeMap.Declaration = decl;
typeMap.CSharpMarshalToManaged(Context);
@ -116,7 +116,7 @@ namespace CppSharp.Generators.CSharp @@ -116,7 +116,7 @@ namespace CppSharp.Generators.CSharp
else
{
if (arrayType.IsPrimitiveType(PrimitiveType.Char) &&
Context.Driver.Options.MarshalCharAsManagedChar)
Context.Context.Options.MarshalCharAsManagedChar)
{
supportBefore.WriteLineIndent(
"{0}[i] = global::System.Convert.ToChar({1}[i]);",
@ -179,7 +179,7 @@ namespace CppSharp.Generators.CSharp @@ -179,7 +179,7 @@ namespace CppSharp.Generators.CSharp
return true;
}
if (Context.Driver.Options.MarshalCharAsManagedChar && primitive == PrimitiveType.Char)
if (Context.Context.Options.MarshalCharAsManagedChar && primitive == PrimitiveType.Char)
Context.Return.Write(string.Format("({0}) ", pointer));
Context.Return.Write(Context.ReturnVarName);
return true;
@ -194,14 +194,14 @@ namespace CppSharp.Generators.CSharp @@ -194,14 +194,14 @@ namespace CppSharp.Generators.CSharp
var encoding = isChar ? Encoding.ASCII : Encoding.Unicode;
if (Equals(encoding, Encoding.ASCII))
encoding = Context.Driver.Options.Encoding;
encoding = Context.Context.Options.Encoding;
if (Equals(encoding, Encoding.ASCII))
return string.Format("Marshal.PtrToStringAnsi({0})", varName);
// If we reach this, we know the string is Unicode.
if (type.Type == PrimitiveType.Char ||
Context.Driver.TargetInfo.WCharWidth == 16)
Context.Context.TargetInfo.WCharWidth == 16)
return string.Format("Marshal.PtrToStringUni({0})", varName);
// If we reach this, we should have an UTF-32 wide string.
@ -219,7 +219,7 @@ namespace CppSharp.Generators.CSharp @@ -219,7 +219,7 @@ namespace CppSharp.Generators.CSharp
return true;
case PrimitiveType.Char:
// returned structs must be blittable and char isn't
if (Context.Driver.Options.MarshalCharAsManagedChar)
if (Context.Context.Options.MarshalCharAsManagedChar)
{
Context.Return.Write("global::System.Convert.ToChar({0})",
Context.ReturnVarName);
@ -305,7 +305,7 @@ namespace CppSharp.Generators.CSharp @@ -305,7 +305,7 @@ namespace CppSharp.Generators.CSharp
if (parameter.Usage == ParameterUsage.Unknown || parameter.IsIn)
return base.VisitParameterDecl(parameter);
var ctx = new CSharpMarshalContext(Context.Driver)
var ctx = new CSharpMarshalContext(Context.Context)
{
ReturnType = Context.ReturnType,
ReturnVarName = Context.ReturnVarName
@ -375,13 +375,13 @@ namespace CppSharp.Generators.CSharp @@ -375,13 +375,13 @@ namespace CppSharp.Generators.CSharp
public CSharpMarshalManagedToNativePrinter(CSharpMarshalContext context)
: base(context)
{
typePrinter = new CSharpTypePrinter(context.Driver);
typePrinter = new CSharpTypePrinter(context.Context);
}
public override bool VisitType(Type type, TypeQualifiers quals)
{
TypeMap typeMap;
if (Context.Driver.TypeDatabase.FindTypeMap(type, out typeMap) && typeMap.DoesMarshalling)
if (Context.Context.TypeDatabase.FindTypeMap(type, out typeMap) && typeMap.DoesMarshalling)
{
typeMap.Type = type;
typeMap.CSharpMarshalToNative(Context);
@ -394,7 +394,7 @@ namespace CppSharp.Generators.CSharp @@ -394,7 +394,7 @@ namespace CppSharp.Generators.CSharp
public override bool VisitDeclaration(Declaration decl)
{
TypeMap typeMap;
if (Context.Driver.TypeDatabase.FindTypeMap(decl, out typeMap) && typeMap.DoesMarshalling)
if (Context.Context.TypeDatabase.FindTypeMap(decl, out typeMap) && typeMap.DoesMarshalling)
{
typeMap.Declaration = decl;
typeMap.CSharpMarshalToNative(Context);
@ -446,7 +446,7 @@ namespace CppSharp.Generators.CSharp @@ -446,7 +446,7 @@ namespace CppSharp.Generators.CSharp
else
{
if (arrayType.IsPrimitiveType(PrimitiveType.Char) &&
Context.Driver.Options.MarshalCharAsManagedChar)
Context.Context.Options.MarshalCharAsManagedChar)
{
supportBefore.WriteLineIndent(
"{0}[i] = global::System.Convert.ToSByte({1}[i]);",
@ -579,7 +579,7 @@ namespace CppSharp.Generators.CSharp @@ -579,7 +579,7 @@ namespace CppSharp.Generators.CSharp
else
{
if (!marshalAsString &&
Context.Driver.Options.MarshalCharAsManagedChar &&
Context.Context.Options.MarshalCharAsManagedChar &&
primitive == PrimitiveType.Char)
{
typePrinter.PushContext(CSharpTypePrinterContextKind.Native);
@ -601,17 +601,17 @@ namespace CppSharp.Generators.CSharp @@ -601,17 +601,17 @@ namespace CppSharp.Generators.CSharp
private string MarshalStringToUnmanaged(string varName)
{
if (Equals(Context.Driver.Options.Encoding, Encoding.ASCII))
if (Equals(Context.Context.Options.Encoding, Encoding.ASCII))
{
return string.Format("Marshal.StringToHGlobalAnsi({0})", varName);
}
if (Equals(Context.Driver.Options.Encoding, Encoding.Unicode) ||
Equals(Context.Driver.Options.Encoding, Encoding.BigEndianUnicode))
if (Equals(Context.Context.Options.Encoding, Encoding.Unicode) ||
Equals(Context.Context.Options.Encoding, Encoding.BigEndianUnicode))
{
return string.Format("Marshal.StringToHGlobalUni({0})", varName);
}
throw new NotSupportedException(string.Format("{0} is not supported yet.",
Context.Driver.Options.Encoding.EncodingName));
Context.Context.Options.Encoding.EncodingName));
}
public override bool VisitPrimitiveType(PrimitiveType primitive, TypeQualifiers quals)
@ -622,7 +622,7 @@ namespace CppSharp.Generators.CSharp @@ -622,7 +622,7 @@ namespace CppSharp.Generators.CSharp
return true;
case PrimitiveType.Char:
// returned structs must be blittable and char isn't
if (Context.Driver.Options.MarshalCharAsManagedChar)
if (Context.Context.Options.MarshalCharAsManagedChar)
{
Context.Return.Write("global::System.Convert.ToSByte({0})",
Context.Parameter.Name);

68
src/Generator/Generators/CSharp/CSharpSources.cs

@ -131,9 +131,9 @@ namespace CppSharp.Generators.CSharp @@ -131,9 +131,9 @@ namespace CppSharp.Generators.CSharp
get { return "cs"; }
}
public CSharpSources(Driver driver, IEnumerable<TranslationUnit> units,
public CSharpSources(BindingContext context, IEnumerable<TranslationUnit> units,
CSharpTypePrinter typePrinter, CSharpExpressionPrinter expressionPrinter)
: base(driver, units)
: base(context, units)
{
TypePrinter = typePrinter;
ExpressionPrinter = expressionPrinter;
@ -163,7 +163,7 @@ namespace CppSharp.Generators.CSharp @@ -163,7 +163,7 @@ namespace CppSharp.Generators.CSharp
PopBlock(NewLineKind.BeforeNextBlock);
var module = TranslationUnits.Count == 0 ?
Driver.Options.SystemModule : TranslationUnit.Module;
Context.Options.SystemModule : TranslationUnit.Module;
if (!string.IsNullOrEmpty(module.OutputNamespace))
{
PushBlock(CSharpBlockKind.Namespace);
@ -426,11 +426,11 @@ namespace CppSharp.Generators.CSharp @@ -426,11 +426,11 @@ namespace CppSharp.Generators.CSharp
GenerateClassTemplateSpecializationInternal(nestedTemplate);
System.Type typeMap = null;
if (Driver.TypeDatabase.TypeMaps.ContainsKey(@class.Name))
if (Context.TypeDatabase.TypeMaps.ContainsKey(@class.Name))
{
typeMap = Driver.TypeDatabase.TypeMaps[@class.Name];
typeMap = Context.TypeDatabase.TypeMaps[@class.Name];
// disable the type map for the mapped class itself so that operator params are not mapped
Driver.TypeDatabase.TypeMaps.Remove(@class.Name);
Context.TypeDatabase.TypeMaps.Remove(@class.Name);
}
PushBlock(CSharpBlockKind.Class);
@ -499,7 +499,7 @@ namespace CppSharp.Generators.CSharp @@ -499,7 +499,7 @@ namespace CppSharp.Generators.CSharp
PopBlock(NewLineKind.BeforeNextBlock);
if (typeMap != null)
Driver.TypeDatabase.TypeMaps.Add(@class.Name, typeMap);
Context.TypeDatabase.TypeMaps.Add(@class.Name, typeMap);
}
private void GenerateClassMarshals(Class @class)
@ -672,7 +672,7 @@ namespace CppSharp.Generators.CSharp @@ -672,7 +672,7 @@ namespace CppSharp.Generators.CSharp
retType = function.ReturnType.CSharpType(TypePrinter);
var @params = function.GatherInternalParams(Driver.Options.IsItaniumLikeAbi).Select(p =>
var @params = function.GatherInternalParams(Context.Options.IsItaniumLikeAbi).Select(p =>
string.Format("{0} {1}", p.CSharpType(TypePrinter), p.Name)).ToList();
TypePrinter.PopContext();
@ -753,7 +753,7 @@ namespace CppSharp.Generators.CSharp @@ -753,7 +753,7 @@ namespace CppSharp.Generators.CSharp
foreach (var @base in @class.Bases.Where(b => b.Class != null))
{
TypeMap typeMap;
if ((!Driver.TypeDatabase.FindTypeMap(@base.Type, out typeMap) && !@base.Class.IsDeclared) ||
if ((!Context.TypeDatabase.FindTypeMap(@base.Type, out typeMap) && !@base.Class.IsDeclared) ||
@base.Class.OriginalClass == @class)
continue;
@ -871,7 +871,7 @@ namespace CppSharp.Generators.CSharp @@ -871,7 +871,7 @@ namespace CppSharp.Generators.CSharp
QualifiedType = decl.QualifiedType
};
var ctx = new CSharpMarshalContext(Driver)
var ctx = new CSharpMarshalContext(Context)
{
Parameter = param,
ArgName = param.Name,
@ -985,9 +985,9 @@ namespace CppSharp.Generators.CSharp @@ -985,9 +985,9 @@ namespace CppSharp.Generators.CSharp
var isChar = finalElementType.IsPrimitiveType(PrimitiveType.Char);
string type;
if (Driver.Options.MarshalCharAsManagedChar && isChar)
if (Context.Options.MarshalCharAsManagedChar && isChar)
{
var typePrinter = new CSharpTypePrinter(Driver);
var typePrinter = new CSharpTypePrinter(Context);
typePrinter.PushContext(CSharpTypePrinterContextKind.Native);
type = originalType.Visit(typePrinter).Type;
}
@ -1090,7 +1090,7 @@ namespace CppSharp.Generators.CSharp @@ -1090,7 +1090,7 @@ namespace CppSharp.Generators.CSharp
WriteStartBraceIndent();
var name = @class.Layout.Fields.First(f => f.FieldPtr == field.OriginalPtr).Name;
var ctx = new CSharpMarshalContext(Driver)
var ctx = new CSharpMarshalContext(Context)
{
Kind = CSharpMarshalKind.NativeField,
ArgName = decl.Name,
@ -1125,7 +1125,7 @@ namespace CppSharp.Generators.CSharp @@ -1125,7 +1125,7 @@ namespace CppSharp.Generators.CSharp
var final = field.Type.GetFinalPointee().Desugar();
if (final.IsPrimitiveType() && !final.IsPrimitiveType(PrimitiveType.Void) &&
(!final.IsPrimitiveType(PrimitiveType.Char) ||
(!Driver.Options.MarshalCharAsManagedChar &&
(!Context.Options.MarshalCharAsManagedChar &&
!((PointerType) field.Type).QualifiedPointee.Qualifiers.IsConst)))
@return = string.Format("({0}*) {1}", field.Type.GetPointee().Desugar(), @return);
}
@ -1159,7 +1159,7 @@ namespace CppSharp.Generators.CSharp @@ -1159,7 +1159,7 @@ namespace CppSharp.Generators.CSharp
TypePrinter.PopContext();
var ctx = new CSharpMarshalContext(Driver)
var ctx = new CSharpMarshalContext(Context)
{
ArgName = decl.Name,
ReturnVarName = (isRefTypeArray ? string.Empty : "*") + Generator.GeneratedIdentifier("ptr"),
@ -1495,7 +1495,7 @@ namespace CppSharp.Generators.CSharp @@ -1495,7 +1495,7 @@ namespace CppSharp.Generators.CSharp
private void SaveOriginalVTablePointers(Class @class)
{
var suffix = Helpers.GetSuffixForInternal(@class);
if (Driver.Options.IsMicrosoftAbi)
if (Context.Options.IsMicrosoftAbi)
WriteLine("__OriginalVTables = new void*[] {{ {0} }};",
string.Join(", ",
@class.Layout.VTablePointers.Select(v => string.Format(
@ -1518,7 +1518,7 @@ namespace CppSharp.Generators.CSharp @@ -1518,7 +1518,7 @@ namespace CppSharp.Generators.CSharp
var vfptr = @class.Layout.VFTables[i];
var size = vfptr.Layout.Components.Count;
WriteLine("var vfptr{0} = Marshal.AllocHGlobal({1} * {2});",
i, size, Driver.TargetInfo.PointerWidth / 8);
i, size, Context.TargetInfo.PointerWidth / 8);
WriteLine("{0}[{1}] = vfptr{1}.ToPointer();", managedVTables, i);
AllocateNewVTableEntries(vfptr.Layout.Components, wrappedEntries,
@ -1540,7 +1540,7 @@ namespace CppSharp.Generators.CSharp @@ -1540,7 +1540,7 @@ namespace CppSharp.Generators.CSharp
WriteLine("{0} = new void*[1];", managedVTables);
var size = @class.Layout.Layout.Components.Count;
var pointerSize = Driver.TargetInfo.PointerWidth / 8;
var pointerSize = Context.TargetInfo.PointerWidth / 8;
WriteLine("var vtptr = Marshal.AllocHGlobal({0} * {1});", size, pointerSize);
WriteLine("var vfptr0 = vtptr + {0} * {1};", VTables.ItaniumOffsetToTopAndRTTI, pointerSize);
@ -1559,7 +1559,7 @@ namespace CppSharp.Generators.CSharp @@ -1559,7 +1559,7 @@ namespace CppSharp.Generators.CSharp
private void AllocateNewVTableEntries(IList<VTableComponent> entries,
IList<VTableComponent> wrappedEntries, string vptr, int tableIndex, bool destructorOnly)
{
var pointerSize = Driver.TargetInfo.PointerWidth / 8;
var pointerSize = Context.TargetInfo.PointerWidth / 8;
for (var i = 0; i < entries.Count; i++)
{
var entry = entries[i];
@ -1573,7 +1573,7 @@ namespace CppSharp.Generators.CSharp @@ -1573,7 +1573,7 @@ namespace CppSharp.Generators.CSharp
entry.Kind == VTableComponentKind.DeletingDtorPointer) &&
!entry.IsIgnored() &&
(!destructorOnly || entry.Method.IsDestructor ||
Driver.Options.ExplicitlyPatchedVirtualFunctions.Contains(entry.Method.QualifiedOriginalName)))
Context.Options.ExplicitlyPatchedVirtualFunctions.Contains(entry.Method.QualifiedOriginalName)))
WriteLine("{0} = _Thunks[{1}];", managedVftableEntry, wrappedEntries.IndexOf(entry));
else
WriteLine("{0} = {1};", managedVftableEntry, nativeVftableEntry);
@ -1615,7 +1615,7 @@ namespace CppSharp.Generators.CSharp @@ -1615,7 +1615,7 @@ namespace CppSharp.Generators.CSharp
if (param.Kind == ParameterKind.IndirectReturnType)
continue;
var ctx = new CSharpMarshalContext(Driver)
var ctx = new CSharpMarshalContext(Context)
{
ReturnType = param.QualifiedType,
ReturnVarName = param.Name,
@ -1655,7 +1655,7 @@ namespace CppSharp.Generators.CSharp @@ -1655,7 +1655,7 @@ namespace CppSharp.Generators.CSharp
};
// Marshal the managed result to native
var ctx = new CSharpMarshalContext(Driver)
var ctx = new CSharpMarshalContext(Context)
{
ArgName = Helpers.ReturnIdentifier,
Parameter = param,
@ -1837,7 +1837,7 @@ namespace CppSharp.Generators.CSharp @@ -1837,7 +1837,7 @@ namespace CppSharp.Generators.CSharp
var returns = new List<string>();
foreach (var param in @event.Parameters)
{
var ctx = new CSharpMarshalContext(Driver)
var ctx = new CSharpMarshalContext(Context)
{
ReturnVarName = param.Name,
ReturnType = param.QualifiedType
@ -1970,7 +1970,7 @@ namespace CppSharp.Generators.CSharp @@ -1970,7 +1970,7 @@ namespace CppSharp.Generators.CSharp
{
NativeLibrary library;
if (!Options.CheckSymbols ||
Driver.Symbols.FindLibraryBySymbol(dtor.Mangled, out library))
Context.Symbols.FindLibraryBySymbol(dtor.Mangled, out library))
{
WriteLine("if (disposing)");
if (dtor.IsVirtual)
@ -2486,7 +2486,7 @@ namespace CppSharp.Generators.CSharp @@ -2486,7 +2486,7 @@ namespace CppSharp.Generators.CSharp
{
var i = VTables.GetVTableIndex(method.OriginalFunction ?? method, @class);
WriteLine("var {0} = *(void**) ((IntPtr) __OriginalVTables[0] + {1} * {2});",
Helpers.SlotIdentifier, i, Driver.TargetInfo.PointerWidth / 8);
Helpers.SlotIdentifier, i, Context.TargetInfo.PointerWidth / 8);
if (method.IsDestructor && @class.IsAbstract)
{
WriteLine("if ({0} != null)", Helpers.SlotIdentifier);
@ -2503,7 +2503,7 @@ namespace CppSharp.Generators.CSharp @@ -2503,7 +2503,7 @@ namespace CppSharp.Generators.CSharp
private string GetDelegateName(Function function, string outputNamespace)
{
var @delegate = Driver.Delegates[function];
var @delegate = Context.Delegates[function];
if (string.IsNullOrWhiteSpace(@delegate.Namespace) ||
outputNamespace == @delegate.Namespace)
{
@ -2651,7 +2651,7 @@ namespace CppSharp.Generators.CSharp @@ -2651,7 +2651,7 @@ namespace CppSharp.Generators.CSharp
TypeMap typeMap;
string construct = null;
if (Driver.TypeDatabase.FindTypeMap(retClass, out typeMap))
if (Context.TypeDatabase.FindTypeMap(retClass, out typeMap))
construct = typeMap.CSharpConstruct();
if (construct == null)
@ -2750,7 +2750,7 @@ namespace CppSharp.Generators.CSharp @@ -2750,7 +2750,7 @@ namespace CppSharp.Generators.CSharp
if (needsReturn)
{
var ctx = new CSharpMarshalContext(Driver)
var ctx = new CSharpMarshalContext(Context)
{
ArgName = Helpers.ReturnIdentifier,
ReturnVarName = Helpers.ReturnIdentifier,
@ -2838,7 +2838,7 @@ namespace CppSharp.Generators.CSharp @@ -2838,7 +2838,7 @@ namespace CppSharp.Generators.CSharp
var nativeVarName = paramInfo.Name;
var ctx = new CSharpMarshalContext(Driver)
var ctx = new CSharpMarshalContext(Context)
{
Parameter = param,
ArgName = nativeVarName,
@ -2911,7 +2911,7 @@ namespace CppSharp.Generators.CSharp @@ -2911,7 +2911,7 @@ namespace CppSharp.Generators.CSharp
}
}
var ctx = new CSharpMarshalContext(Driver)
var ctx = new CSharpMarshalContext(Context)
{
Parameter = param,
ParameterIndex = paramIndex,
@ -3135,14 +3135,14 @@ namespace CppSharp.Generators.CSharp @@ -3135,14 +3135,14 @@ namespace CppSharp.Generators.CSharp
private string GetLibraryOf(Declaration declaration)
{
if (declaration.TranslationUnit.IsSystemHeader)
return Driver.Options.SystemModule.TemplatesLibraryName;
return Context.Options.SystemModule.TemplatesLibraryName;
string libName = declaration.TranslationUnit.Module.SharedLibraryName;
if (Options.CheckSymbols)
{
NativeLibrary library;
Driver.Symbols.FindLibraryBySymbol(((IMangledDecl) declaration).Mangled, out library);
Context.Symbols.FindLibraryBySymbol(((IMangledDecl) declaration).Mangled, out library);
if (library != null)
libName = Path.GetFileNameWithoutExtension(library.FileName);
@ -3161,9 +3161,9 @@ namespace CppSharp.Generators.CSharp @@ -3161,9 +3161,9 @@ namespace CppSharp.Generators.CSharp
if (Platform.IsMacOS)
{
var framework = libName + ".framework";
for (uint i = 0; i < Driver.Options.LibraryDirsCount; i++)
for (uint i = 0; i < Context.Options.LibraryDirsCount; i++)
{
var libDir = Driver.Options.getLibraryDirs(i);
var libDir = Context.Options.getLibraryDirs(i);
if (Path.GetFileName(libDir) == framework && File.Exists(Path.Combine(libDir, libName)))
{
libName = string.Format("@executable_path/../Frameworks/{0}/{1}", framework, libName);

32
src/Generator/Generators/CSharp/CSharpTypePrinter.cs

@ -52,8 +52,6 @@ namespace CppSharp.Generators.CSharp @@ -52,8 +52,6 @@ namespace CppSharp.Generators.CSharp
AppendGlobal = true;
}
private readonly Driver driver;
private readonly Stack<CSharpTypePrinterContextKind> contexts;
private readonly Stack<CSharpMarshalKind> marshalKinds;
@ -69,10 +67,14 @@ namespace CppSharp.Generators.CSharp @@ -69,10 +67,14 @@ namespace CppSharp.Generators.CSharp
public CSharpTypePrinterContext TypePrinterContext;
public CSharpTypePrinter(Driver driver)
{
this.driver = driver;
public BindingContext Context { get; set; }
public DriverOptions Options { get { return Context.Options; } }
public TypeMapDatabase TypeMapDatabase { get { return Context.TypeDatabase; } }
public CSharpTypePrinter(BindingContext context)
{
Context = context;
contexts = new Stack<CSharpTypePrinterContextKind>();
marshalKinds = new Stack<CSharpMarshalKind>();
PushContext(CSharpTypePrinterContextKind.Managed);
@ -107,7 +109,7 @@ namespace CppSharp.Generators.CSharp @@ -107,7 +109,7 @@ namespace CppSharp.Generators.CSharp
return string.Empty;
TypeMap typeMap;
if (driver.TypeDatabase.FindTypeMap(tag.Declaration, out typeMap))
if (TypeMapDatabase.FindTypeMap(tag.Declaration, out typeMap))
{
typeMap.Type = tag;
TypePrinterContext.CSharpKind = ContextKind;
@ -165,7 +167,7 @@ namespace CppSharp.Generators.CSharp @@ -165,7 +167,7 @@ namespace CppSharp.Generators.CSharp
// C# does not support fixed arrays of machine pointer type (void* or IntPtr).
// In that case, replace it by a pointer to an integer type of the same size.
if (arrayElemType == IntPtrType)
arrayElemType = driver.TargetInfo.PointerWidth == 64 ? "long" : "int";
arrayElemType = Context.TargetInfo.PointerWidth == 64 ? "long" : "int";
// Do not write the fixed keyword multiple times for nested array types
var fixedKeyword = array.Type is ArrayType ? string.Empty : "fixed ";
@ -271,13 +273,13 @@ namespace CppSharp.Generators.CSharp @@ -271,13 +273,13 @@ namespace CppSharp.Generators.CSharp
return "string";
if (TypePrinterContext.Parameter == null || TypePrinterContext.Parameter.Name == Helpers.ReturnIdentifier)
return IntPtrType;
if (driver.Options.Encoding == Encoding.ASCII)
if (Options.Encoding == Encoding.ASCII)
return string.Format("[MarshalAs(UnmanagedType.LPStr)] string");
if (driver.Options.Encoding == Encoding.Unicode ||
driver.Options.Encoding == Encoding.BigEndianUnicode)
if (Options.Encoding == Encoding.Unicode ||
Options.Encoding == Encoding.BigEndianUnicode)
return string.Format("[MarshalAs(UnmanagedType.LPWStr)] string");
throw new NotSupportedException(string.Format("{0} is not supported yet.",
driver.Options.Encoding.EncodingName));
Options.Encoding.EncodingName));
}
var desugared = pointee.Desugar();
@ -360,7 +362,7 @@ namespace CppSharp.Generators.CSharp @@ -360,7 +362,7 @@ namespace CppSharp.Generators.CSharp
var decl = typedef.Declaration;
TypeMap typeMap;
if (driver.TypeDatabase.FindTypeMap(decl, out typeMap))
if (TypeMapDatabase.FindTypeMap(decl, out typeMap))
{
typeMap.Type = typedef;
TypePrinterContext.CSharpKind = ContextKind;
@ -408,7 +410,7 @@ namespace CppSharp.Generators.CSharp @@ -408,7 +410,7 @@ namespace CppSharp.Generators.CSharp
var decl = template.Template.TemplatedDecl;
TypeMap typeMap;
if (!driver.TypeDatabase.FindTypeMap(template, out typeMap))
if (!TypeMapDatabase.FindTypeMap(template, out typeMap))
{
if (ContextKind != CSharpTypePrinterContextKind.Native)
return GetNestedQualifiedName(decl);
@ -563,7 +565,7 @@ namespace CppSharp.Generators.CSharp @@ -563,7 +565,7 @@ namespace CppSharp.Generators.CSharp
case PrimitiveType.WideChar: return "char";
case PrimitiveType.Char:
// returned structs must be blittable and char isn't
return driver.Options.MarshalCharAsManagedChar &&
return Options.MarshalCharAsManagedChar &&
ContextKind != CSharpTypePrinterContextKind.Native
? "char"
: "sbyte";
@ -576,7 +578,7 @@ namespace CppSharp.Generators.CSharp @@ -576,7 +578,7 @@ namespace CppSharp.Generators.CSharp
case PrimitiveType.ULong:
case PrimitiveType.LongLong:
case PrimitiveType.ULongLong:
return GetIntString(primitive, driver.TargetInfo);
return GetIntString(primitive, Context.TargetInfo);
case PrimitiveType.Int128: return "__int128";
case PrimitiveType.UInt128: return "__uint128_t";
case PrimitiveType.Half: return "__fp16";

6
src/Generator/Generators/Marshal.cs

@ -4,15 +4,15 @@ namespace CppSharp.Generators @@ -4,15 +4,15 @@ namespace CppSharp.Generators
{
public class MarshalContext
{
public MarshalContext(Driver driver)
public MarshalContext(BindingContext context)
{
Driver = driver;
Context = context;
SupportBefore = new TextGenerator();
Return = new TextGenerator();
MarshalVarPrefix = string.Empty;
}
public Driver Driver { get; private set; }
public BindingContext Context { get; private set; }
public MarshalPrinter<MarshalContext> MarshalToNative;

17
src/Generator/Generators/Template.cs

@ -280,26 +280,23 @@ namespace CppSharp.Generators @@ -280,26 +280,23 @@ namespace CppSharp.Generators
public abstract class Template : ITextGenerator
{
public Driver Driver { get; private set; }
public DriverOptions Options { get; private set; }
public BindingContext Context { get; private set; }
public IDiagnostics Log { get { return Context.Diagnostics; } }
public DriverOptions Options { get { return Context.Options; } }
public List<TranslationUnit> TranslationUnits { get; private set; }
public TranslationUnit TranslationUnit { get { return TranslationUnits[0]; } }
public IDiagnostics Log
{
get { return Driver.Diagnostics; }
}
public Block RootBlock { get; private set; }
public Block ActiveBlock { get; private set; }
public abstract string FileExtension { get; }
protected Template(Driver driver, IEnumerable<TranslationUnit> units)
protected Template(BindingContext context, IEnumerable<TranslationUnit> units)
{
Driver = driver;
Options = driver.Options;
Context = context;
TranslationUnits = new List<TranslationUnit>(units);
RootBlock = new Block();
ActiveBlock = RootBlock;

2
src/Generator/Passes/CheckAbiParameters.cs

@ -67,7 +67,7 @@ namespace CppSharp.Passes @@ -67,7 +67,7 @@ namespace CppSharp.Passes
// Deleting destructors (default in v-table) accept an i32 bitfield as a
// second parameter.in MS ABI.
if (method != null && method.IsDestructor && Driver.Options.IsMicrosoftAbi)
if (method != null && method.IsDestructor && Options.IsMicrosoftAbi)
{
method.Parameters.Add(new Parameter
{

2
src/Generator/Passes/CheckAmbiguousFunctions.cs

@ -59,7 +59,7 @@ namespace CppSharp.Passes @@ -59,7 +59,7 @@ namespace CppSharp.Passes
}
if (function.IsAmbiguous)
Driver.Diagnostics.Debug("Found ambiguous overload: {0}",
Diagnostics.Debug("Found ambiguous overload: {0}",
function.QualifiedOriginalName);
return true;

8
src/Generator/Passes/CheckDuplicatedNamesPass.cs

@ -130,7 +130,7 @@ namespace CppSharp.Passes @@ -130,7 +130,7 @@ namespace CppSharp.Passes
if (!VisitDeclaration(decl))
return false;
if (ASTUtils.CheckIgnoreFunction(decl, Driver.Options))
if (ASTUtils.CheckIgnoreFunction(decl, Options))
return false;
CheckDuplicate(decl);
@ -142,7 +142,7 @@ namespace CppSharp.Passes @@ -142,7 +142,7 @@ namespace CppSharp.Passes
if (!VisitDeclaration(decl))
return false;
if (ASTUtils.CheckIgnoreMethod(decl, Driver.Options))
if (ASTUtils.CheckIgnoreMethod(decl, Options))
return false;
if (decl.ExplicitInterfaceImpl == null)
@ -219,11 +219,11 @@ namespace CppSharp.Passes @@ -219,11 +219,11 @@ namespace CppSharp.Passes
// If the name is not yet on the map, then add it.
if (!names.ContainsKey(fullName))
names.Add(fullName, new DeclarationName(Driver.Diagnostics));
names.Add(fullName, new DeclarationName(Diagnostics));
if (names[fullName].UpdateName(decl))
{
Driver.Diagnostics.Debug("Duplicate name {0}, renamed to {1}",
Diagnostics.Debug("Duplicate name {0}, renamed to {1}",
fullName, decl.Name);
}
}

42
src/Generator/Passes/CheckIgnoredDecls.cs

@ -9,7 +9,7 @@ namespace CppSharp.Passes @@ -9,7 +9,7 @@ namespace CppSharp.Passes
{
public bool CheckDeclarationAccess(Declaration decl)
{
var generateNonPublicDecls = Driver.Options.IsCSharpGenerator;
var generateNonPublicDecls = Options.IsCSharpGenerator;
switch (decl.Access)
{
@ -56,7 +56,7 @@ namespace CppSharp.Passes @@ -56,7 +56,7 @@ namespace CppSharp.Passes
if (!CheckDeclarationAccess(decl))
{
Log.Debug("Decl '{0}' was ignored due to invalid access",
Diagnostics.Debug("Decl '{0}' was ignored due to invalid access",
decl.Name);
decl.GenerationKind = decl is Field ? GenerationKind.Internal : GenerationKind.None;
return true;
@ -65,7 +65,7 @@ namespace CppSharp.Passes @@ -65,7 +65,7 @@ namespace CppSharp.Passes
if (decl.IsDependent)
{
decl.GenerationKind = decl is Field ? GenerationKind.Internal : GenerationKind.None;
Log.Debug("Decl '{0}' was ignored due to dependent context",
Diagnostics.Debug("Decl '{0}' was ignored due to dependent context",
decl.Name);
return true;
}
@ -94,7 +94,7 @@ namespace CppSharp.Passes @@ -94,7 +94,7 @@ namespace CppSharp.Passes
var cppTypePrinter = new CppTypePrinter();
var typeName = field.Type.Visit(cppTypePrinter);
Log.Debug("Field '{0}::{1}' was ignored due to {2} type '{3}'",
Diagnostics.Debug("Field '{0}::{1}' was ignored due to {2} type '{3}'",
@class.Name, field.Name, msg, typeName);
return true;
@ -111,7 +111,7 @@ namespace CppSharp.Passes @@ -111,7 +111,7 @@ namespace CppSharp.Passes
if (HasInvalidType(ret.Type, out msg))
{
function.ExplicitlyIgnore();
Log.Debug("Function '{0}' was ignored due to {1} return decl",
Diagnostics.Debug("Function '{0}' was ignored due to {1} return decl",
function.Name, msg);
return false;
}
@ -121,7 +121,7 @@ namespace CppSharp.Passes @@ -121,7 +121,7 @@ namespace CppSharp.Passes
if (HasInvalidDecl(param, out msg))
{
function.ExplicitlyIgnore();
Log.Debug("Function '{0}' was ignored due to {1} param",
Diagnostics.Debug("Function '{0}' was ignored due to {1} param",
function.Name, msg);
return false;
}
@ -129,7 +129,7 @@ namespace CppSharp.Passes @@ -129,7 +129,7 @@ namespace CppSharp.Passes
if (HasInvalidType(param.Type, out msg))
{
function.ExplicitlyIgnore();
Log.Debug("Function '{0}' was ignored due to {1} param",
Diagnostics.Debug("Function '{0}' was ignored due to {1} param",
function.Name, msg);
return false;
}
@ -138,7 +138,7 @@ namespace CppSharp.Passes @@ -138,7 +138,7 @@ namespace CppSharp.Passes
if (decayedType != null)
{
function.ExplicitlyIgnore();
Log.Debug("Function '{0}' was ignored due to unsupported decayed type param",
Diagnostics.Debug("Function '{0}' was ignored due to unsupported decayed type param",
function.Name);
return false;
}
@ -150,7 +150,7 @@ namespace CppSharp.Passes @@ -150,7 +150,7 @@ namespace CppSharp.Passes
if (retClass == null)
{
function.ExplicitlyIgnore();
Log.Debug(
Diagnostics.Debug(
"Function '{0}' was ignored due to an indirect return param not of a tag type",
function.Name);
return false;
@ -178,7 +178,7 @@ namespace CppSharp.Passes @@ -178,7 +178,7 @@ namespace CppSharp.Passes
Class ignoredBase;
if (HasIgnoredBaseClass(method, @class, out ignoredBase))
{
Log.Debug(
Diagnostics.Debug(
"Virtual method '{0}' was ignored due to ignored base '{1}'",
method.QualifiedOriginalName, ignoredBase.Name);
@ -225,7 +225,7 @@ namespace CppSharp.Passes @@ -225,7 +225,7 @@ namespace CppSharp.Passes
if (HasInvalidType(typedef.Type, out msg))
{
typedef.ExplicitlyIgnore();
Log.Debug("Typedef '{0}' was ignored due to {1} type",
Diagnostics.Debug("Typedef '{0}' was ignored due to {1} type",
typedef.Name, msg);
return false;
}
@ -242,7 +242,7 @@ namespace CppSharp.Passes @@ -242,7 +242,7 @@ namespace CppSharp.Passes
if (HasInvalidDecl(property, out msg))
{
property.ExplicitlyIgnore();
Log.Debug("Property '{0}' was ignored due to {1} decl",
Diagnostics.Debug("Property '{0}' was ignored due to {1} decl",
property.Name, msg);
return false;
}
@ -250,7 +250,7 @@ namespace CppSharp.Passes @@ -250,7 +250,7 @@ namespace CppSharp.Passes
if (HasInvalidType(property.Type, out msg))
{
property.ExplicitlyIgnore();
Log.Debug("Property '{0}' was ignored due to {1} type",
Diagnostics.Debug("Property '{0}' was ignored due to {1} type",
property.Name, msg);
return false;
}
@ -267,7 +267,7 @@ namespace CppSharp.Passes @@ -267,7 +267,7 @@ namespace CppSharp.Passes
if (HasInvalidDecl(variable, out msg))
{
variable.ExplicitlyIgnore();
Log.Debug("Variable '{0}' was ignored due to {1} decl",
Diagnostics.Debug("Variable '{0}' was ignored due to {1} decl",
variable.Name, msg);
return false;
}
@ -275,7 +275,7 @@ namespace CppSharp.Passes @@ -275,7 +275,7 @@ namespace CppSharp.Passes
if (HasInvalidType(variable.Type, out msg))
{
variable.ExplicitlyIgnore();
Log.Debug("Variable '{0}' was ignored due to {1} type",
Diagnostics.Debug("Variable '{0}' was ignored due to {1} type",
variable.Name, msg);
return false;
}
@ -292,7 +292,7 @@ namespace CppSharp.Passes @@ -292,7 +292,7 @@ namespace CppSharp.Passes
if (HasInvalidDecl(@event, out msg))
{
@event.ExplicitlyIgnore();
Log.Debug("Event '{0}' was ignored due to {1} decl",
Diagnostics.Debug("Event '{0}' was ignored due to {1} decl",
@event.Name, msg);
return false;
}
@ -302,7 +302,7 @@ namespace CppSharp.Passes @@ -302,7 +302,7 @@ namespace CppSharp.Passes
if (HasInvalidDecl(param, out msg))
{
@event.ExplicitlyIgnore();
Log.Debug("Event '{0}' was ignored due to {1} param",
Diagnostics.Debug("Event '{0}' was ignored due to {1} param",
@event.Name, msg);
return false;
}
@ -310,7 +310,7 @@ namespace CppSharp.Passes @@ -310,7 +310,7 @@ namespace CppSharp.Passes
if (HasInvalidType(param.Type, out msg))
{
@event.ExplicitlyIgnore();
Log.Debug("Event '{0}' was ignored due to {1} param",
Diagnostics.Debug("Event '{0}' was ignored due to {1} param",
@event.Name, msg);
return false;
}
@ -377,7 +377,7 @@ namespace CppSharp.Passes @@ -377,7 +377,7 @@ namespace CppSharp.Passes
private bool IsTypeComplete(Type type)
{
TypeMap typeMap;
if (Driver.TypeDatabase.FindTypeMap(type, out typeMap) && !typeMap.IsIgnored)
if (TypeDatabase.FindTypeMap(type, out typeMap) && !typeMap.IsIgnored)
return true;
var desugared = type.Desugar();
@ -394,7 +394,7 @@ namespace CppSharp.Passes @@ -394,7 +394,7 @@ namespace CppSharp.Passes
private bool IsTypeIgnored(Type type)
{
var checker = new TypeIgnoreChecker(Driver.TypeDatabase);
var checker = new TypeIgnoreChecker(TypeDatabase);
type.Visit(checker);
return checker.IsIgnored;
@ -407,7 +407,7 @@ namespace CppSharp.Passes @@ -407,7 +407,7 @@ namespace CppSharp.Passes
return true;
TypeMap typeMap;
return Driver.TypeDatabase.FindTypeMap(decl, out typeMap) ? typeMap.IsIgnored : decl.Ignore;
return TypeDatabase.FindTypeMap(decl, out typeMap) ? typeMap.IsIgnored : decl.Ignore;
}
#endregion

2
src/Generator/Passes/CheckMacrosPass.cs

@ -79,7 +79,7 @@ namespace CppSharp.Passes @@ -79,7 +79,7 @@ namespace CppSharp.Passes
e.MacroLocation != MacroLocation.FunctionBody &&
e.MacroLocation != MacroLocation.FunctionParameters))
{
Log.Debug("Decl '{0}' was ignored due to ignore macro",
Diagnostics.Debug("Decl '{0}' was ignored due to ignore macro",
decl.Name);
decl.ExplicitlyIgnore();
}

6
src/Generator/Passes/CheckOperatorsOverloads.cs

@ -26,7 +26,7 @@ namespace CppSharp.Passes @@ -26,7 +26,7 @@ namespace CppSharp.Passes
// Check for C++ operators that cannot be represented in C#.
CheckInvalidOperators(@class);
if (Driver.Options.IsCSharpGenerator)
if (Options.IsCSharpGenerator)
{
// The comparison operators, if overloaded, must be overloaded in pairs;
// that is, if == is overloaded, != must also be overloaded. The reverse
@ -51,7 +51,7 @@ namespace CppSharp.Passes @@ -51,7 +51,7 @@ namespace CppSharp.Passes
{
if (!IsValidOperatorOverload(@operator) || @operator.IsPure)
{
Driver.Diagnostics.Debug("Invalid operator overload {0}::{1}",
Diagnostics.Debug("Invalid operator overload {0}::{1}",
@class.OriginalName, @operator.OperatorKind);
@operator.ExplicitlyIgnore();
continue;
@ -115,7 +115,7 @@ namespace CppSharp.Passes @@ -115,7 +115,7 @@ namespace CppSharp.Passes
property.QualifiedType = new QualifiedType(
pointerType.Pointee, property.QualifiedType.Qualifiers);
if (Driver.Options.IsCLIGenerator)
if (Options.IsCLIGenerator)
// C++/CLI uses "default" as the indexer property name.
property.Name = "default";

2
src/Generator/Passes/CheckStaticClass.cs

@ -19,7 +19,7 @@ namespace CppSharp.Passes @@ -19,7 +19,7 @@ namespace CppSharp.Passes
if (!base.VisitDeclaration(decl))
return false;
if (Driver.Options.IsCSharpGenerator)
if (Options.IsCSharpGenerator)
{
// C# cannot have protected members in static classes.
var @class = decl.Namespace as Class;

2
src/Generator/Passes/CheckVTableComponentsPass.cs

@ -22,7 +22,7 @@ namespace CppSharp.Passes @@ -22,7 +22,7 @@ namespace CppSharp.Passes
if (vfptr.Layout.Components.Count == uniqueEntries.Count)
continue;
Driver.Diagnostics.Warning(
Diagnostics.Warning(
"Class '{0}' found with duplicated vftable components",
@class.Name);
vfptr.Layout.Components = uniqueEntries.ToList();

2
src/Generator/Passes/CheckVirtualOverrideReturnCovariance.cs

@ -334,7 +334,7 @@ namespace CppSharp.Passes @@ -334,7 +334,7 @@ namespace CppSharp.Passes
{
method.ReturnType = overridenMethod.ReturnType;
Driver.Diagnostics.Debug(
Diagnostics.Debug(
"{0} return type is co-variant with overriden base",
method.QualifiedOriginalName);
}

2
src/Generator/Passes/CleanInvalidDeclNamesPass.cs

@ -20,7 +20,7 @@ namespace CppSharp.Passes @@ -20,7 +20,7 @@ namespace CppSharp.Passes
if (char.IsNumber(name[0]))
return '_' + name;
if (Driver.Options.IsCLIGenerator)
if (Options.IsCLIGenerator)
return CLITemplate.SafeIdentifier(name);
return Helpers.SafeIdentifier(name);
}

17
src/Generator/Passes/CleanUnitPass.cs

@ -6,11 +6,8 @@ namespace CppSharp.Passes @@ -6,11 +6,8 @@ namespace CppSharp.Passes
{
public class CleanUnitPass : TranslationUnitPass
{
public DriverOptions DriverOptions;
public CleanUnitPass(DriverOptions options)
public CleanUnitPass()
{
DriverOptions = options;
}
public override bool VisitTranslationUnit(TranslationUnit unit)
@ -20,14 +17,14 @@ namespace CppSharp.Passes @@ -20,14 +17,14 @@ namespace CppSharp.Passes
if (unit.IsSystemHeader)
{
unit.Module = DriverOptions.SystemModule;
unit.Module = Options.SystemModule;
}
else
{
var includeDir = Path.GetFullPath(Path.GetDirectoryName(unit.FilePath));
unit.Module = DriverOptions.Modules.FirstOrDefault(
unit.Module = Options.Modules.FirstOrDefault(
m => m.IncludeDirs.Any(i => Path.GetFullPath(i) == includeDir)) ??
DriverOptions.MainModule;
Options.MainModule;
}
unit.Module.Units.Add(unit);
// Try to get an include path that works from the original include directories paths
@ -45,9 +42,9 @@ namespace CppSharp.Passes @@ -45,9 +42,9 @@ namespace CppSharp.Passes
var includePath = filePath;
var shortestIncludePath = filePath;
for (uint i = 0; i < DriverOptions.IncludeDirsCount; ++i)
for (uint i = 0; i < Options.IncludeDirsCount; ++i)
{
var path = DriverOptions.getIncludeDirs(i);
var path = Options.getIncludeDirs(i);
int idx = filePath.IndexOf(path, System.StringComparison.Ordinal);
if (idx == -1)
@ -64,7 +61,7 @@ namespace CppSharp.Passes @@ -64,7 +61,7 @@ namespace CppSharp.Passes
shortestIncludePath = inc;
}
includePath = DriverOptions.IncludePrefix
includePath = Options.IncludePrefix
+ shortestIncludePath.TrimStart(new char[] { '\\', '/' });
return includePath.Replace('\\', '/');

4
src/Generator/Passes/ConstructorToConversionOperatorPass.cs

@ -20,7 +20,7 @@ namespace CppSharp.Passes @@ -20,7 +20,7 @@ namespace CppSharp.Passes
if (@params.Count == 0)
return false;
if (Driver.Options.GenerateDefaultValuesForArguments)
if (Options.GenerateDefaultValuesForArguments)
{
var nonDefaultParams = @params.Count(p => p.DefaultArgument == null);
if (nonDefaultParams > 1)
@ -34,7 +34,7 @@ namespace CppSharp.Passes @@ -34,7 +34,7 @@ namespace CppSharp.Passes
var parameter = method.Parameters[0];
// TODO: disable implicit operators for C++/CLI because they seem not to be support parameters
if (!Driver.Options.IsCSharpGenerator)
if (!Options.IsCSharpGenerator)
{
var pointerType = parameter.Type as PointerType;
if (pointerType != null && !pointerType.IsReference)

18
src/Generator/Passes/DelegatesPass.cs

@ -37,7 +37,7 @@ namespace CppSharp.Passes @@ -37,7 +37,7 @@ namespace CppSharp.Passes
public override bool VisitLibrary(ASTContext context)
{
foreach (var library in Driver.Options.Modules.SelectMany(m => m.Libraries))
foreach (var library in Options.Modules.SelectMany(m => m.Libraries))
libsDelegates[library] = new Dictionary<string, DelegateDefinition>();
var unit = context.TranslationUnits.GetGenerated().LastOrDefault();
@ -47,7 +47,7 @@ namespace CppSharp.Passes @@ -47,7 +47,7 @@ namespace CppSharp.Passes
var result = base.VisitLibrary(context);
foreach (var module in Driver.Options.Modules.Where(m => namespacesDelegates.ContainsKey(m)))
foreach (var module in Options.Modules.Where(m => namespacesDelegates.ContainsKey(m)))
module.Units.Last(u => u.HasDeclarations).Declarations.Add(namespacesDelegates[module]);
return result;
@ -61,7 +61,7 @@ namespace CppSharp.Passes @@ -61,7 +61,7 @@ namespace CppSharp.Passes
// dependent types with virtuals have no own virtual layouts
// so virtuals are considered different objects in template instantiations
// therefore the method itself won't be visited, so let's visit it through the v-table
if (Driver.Options.IsMicrosoftAbi)
if (Options.IsMicrosoftAbi)
{
foreach (var method in from vfTable in @class.Layout.VFTables
from component in vfTable.Layout.Components
@ -88,7 +88,7 @@ namespace CppSharp.Passes @@ -88,7 +88,7 @@ namespace CppSharp.Passes
if (!base.VisitMethodDecl(method) || !method.IsVirtual || method.Ignore)
return false;
var @params = method.GatherInternalParams(Driver.Options.IsItaniumLikeAbi, true).ToList();
var @params = method.GatherInternalParams(Options.IsItaniumLikeAbi, true).ToList();
var delegateName = GenerateDelegateSignature(@params, method.ReturnType);
var module = method.TranslationUnit.Module;
@ -132,12 +132,12 @@ namespace CppSharp.Passes @@ -132,12 +132,12 @@ namespace CppSharp.Passes
if (existingDelegate != null)
{
Driver.Delegates.Add(method, existingDelegate);
Context.Delegates.Add(method, existingDelegate);
return true;
}
existingDelegate = new DelegateDefinition(module.OutputNamespace, delegateString);
Driver.Delegates.Add(method, existingDelegate);
Context.Delegates.Add(method, existingDelegate);
foreach (var library in module.Libraries)
libsDelegates[library].Add(delegateString, existingDelegate);
@ -150,11 +150,11 @@ namespace CppSharp.Passes @@ -150,11 +150,11 @@ namespace CppSharp.Passes
private DelegateDefinition GetExistingDelegate(IList<string> libraries, string delegateString)
{
if (libraries.Count == 0)
return Driver.Delegates.Values.FirstOrDefault(t => t.Signature == delegateString);
return Context.Delegates.Values.FirstOrDefault(t => t.Signature == delegateString);
DelegateDefinition @delegate = null;
if (libraries.Union(
Driver.Symbols.Libraries.Where(l => libraries.Contains(l.FileName)).SelectMany(
Context.Symbols.Libraries.Where(l => libraries.Contains(l.FileName)).SelectMany(
l => l.Dependencies)).Any(l => libsDelegates.ContainsKey(l) &&
libsDelegates[l].TryGetValue(delegateString, out @delegate)))
return @delegate;
@ -196,7 +196,7 @@ namespace CppSharp.Passes @@ -196,7 +196,7 @@ namespace CppSharp.Passes
{
if (typePrinter == null)
{
typePrinter = new CSharpTypePrinter(Driver);
typePrinter = new CSharpTypePrinter(Context);
typePrinter.PushContext(CSharpTypePrinterContextKind.Native);
typePrinter.PushMarshalKind(CSharpMarshalKind.GenericDelegate);
}

2
src/Generator/Passes/FieldToPropertyPass.cs

@ -51,7 +51,7 @@ namespace CppSharp.Passes @@ -51,7 +51,7 @@ namespace CppSharp.Passes
@class.Properties.Add(prop);
Log.Debug("Property created from field: {0}::{1}", @class.Name,
Diagnostics.Debug("Property created from field: {0}::{1}", @class.Name,
field.Name);
return false;

7
src/Generator/Passes/FindSymbolsPass.cs

@ -21,8 +21,7 @@ namespace CppSharp.Passes @@ -21,8 +21,7 @@ namespace CppSharp.Passes
if (!base.VisitDeclaration(decl))
return false;
var options = Driver.Options;
if (!options.CheckSymbols || options.IsCLIGenerator)
if (!Options.CheckSymbols || Options.IsCLIGenerator)
return false;
var mangledDecl = decl as IMangledDecl;
@ -42,9 +41,9 @@ namespace CppSharp.Passes @@ -42,9 +41,9 @@ namespace CppSharp.Passes
{
var symbol = mangledDecl.Mangled;
if (!Driver.Symbols.FindSymbol(ref symbol))
if (!Context.Symbols.FindSymbol(ref symbol))
{
Driver.Diagnostics.Warning("Symbol not found: {0}", symbol);
Diagnostics.Warning("Symbol not found: {0}", symbol);
return false;
}

4
src/Generator/Passes/FunctionToInstanceMethodPass.cs

@ -59,12 +59,12 @@ namespace CppSharp.Passes @@ -59,12 +59,12 @@ namespace CppSharp.Passes
Conversion = MethodConversionKind.FunctionToInstanceMethod
};
if (Driver.Options.GeneratorKind == GeneratorKind.CSharp)
if (Options.GeneratorKind == GeneratorKind.CSharp)
method.Parameters = method.Parameters.Skip(1).ToList();
@class.Methods.Add(method);
Log.Debug("Function converted to instance method: {0}::{1}", @class.Name,
Diagnostics.Debug("Function converted to instance method: {0}::{1}", @class.Name,
function.Name);
return true;

4
src/Generator/Passes/FunctionToStaticMethodPass.cs

@ -21,7 +21,7 @@ namespace CppSharp.Passes @@ -21,7 +21,7 @@ namespace CppSharp.Passes
if (types.Length == 0)
return false;
var @class = AstContext.FindCompleteClass(types[0]);
var @class = ASTContext.FindCompleteClass(types[0]);
if (@class == null)
return false;
@ -56,7 +56,7 @@ namespace CppSharp.Passes @@ -56,7 +56,7 @@ namespace CppSharp.Passes
@class.Methods.Add(method);
Log.Debug("Function converted to static method: {0}::{1}",
Diagnostics.Debug("Function converted to static method: {0}::{1}",
@class.Name, function.Name);
return true;

6
src/Generator/Passes/GenerateInlinesCodePass.cs

@ -14,14 +14,14 @@ namespace CppSharp.Passes @@ -14,14 +14,14 @@ namespace CppSharp.Passes
private void WriteInlinesIncludes()
{
foreach (var module in Driver.Options.Modules)
foreach (var module in Options.Modules)
{
var cppBuilder = new StringBuilder();
foreach (var header in module.Headers)
cppBuilder.AppendFormat("#include <{0}>\n", header);
var cpp = string.Format("{0}.cpp", module.InlinesLibraryName);
Directory.CreateDirectory(Driver.Options.OutputDir);
var path = Path.Combine(Driver.Options.OutputDir, cpp);
Directory.CreateDirectory(Options.OutputDir);
var path = Path.Combine(Options.OutputDir, cpp);
File.WriteAllText(path, cppBuilder.ToString());
}
}

8
src/Generator/Passes/GenerateTemplatesCodePass.cs

@ -39,10 +39,10 @@ namespace CppSharp.Passes @@ -39,10 +39,10 @@ namespace CppSharp.Passes
private void WriteTemplateInstantiations()
{
foreach (var module in Driver.Options.Modules.Where(m => templateInstantiations.ContainsKey(m)))
foreach (var module in Options.Modules.Where(m => templateInstantiations.ContainsKey(m)))
{
var cppBuilder = new StringBuilder();
if (module == Driver.Options.SystemModule)
if (module == Options.SystemModule)
{
cppBuilder.Append("#include <string>\n");
cppBuilder.Append("#include <vector>\n");
@ -55,8 +55,8 @@ namespace CppSharp.Passes @@ -55,8 +55,8 @@ namespace CppSharp.Passes
cppBuilder.AppendFormat("\ntemplate class {0}{1};",
Platform.IsWindows ? "__declspec(dllexport) " : string.Empty, templateInstantiation);
var cpp = string.Format("{0}.cpp", module.TemplatesLibraryName);
Directory.CreateDirectory(Driver.Options.OutputDir);
var path = Path.Combine(Driver.Options.OutputDir, cpp);
Directory.CreateDirectory(Options.OutputDir);
var path = Path.Combine(Options.OutputDir, cpp);
File.WriteAllText(path, cppBuilder.ToString());
}
}

12
src/Generator/Passes/GetterSetterToPropertyAdvancedPass.cs

@ -15,15 +15,15 @@ namespace CppSharp.Passes @@ -15,15 +15,15 @@ namespace CppSharp.Passes
{
private class PropertyGenerator
{
private readonly IDiagnostics log;
private readonly IDiagnostics Diagnostics;
private readonly List<Method> getters = new List<Method>();
private readonly List<Method> setters = new List<Method>();
private readonly List<Method> setMethods = new List<Method>();
private readonly List<Method> nonSetters = new List<Method>();
public PropertyGenerator(Class @class, IDiagnostics log)
public PropertyGenerator(Class @class, IDiagnostics diags)
{
this.log = log;
Diagnostics = diags;
foreach (var method in @class.Methods.Where(
m => !m.IsConstructor && !m.IsDestructor && !m.IsOperator && m.IsGenerated))
DistributeMethod(method);
@ -70,14 +70,14 @@ namespace CppSharp.Passes @@ -70,14 +70,14 @@ namespace CppSharp.Passes
var oldName = method.Name;
method.Name = string.Format("get{0}{1}",
char.ToUpperInvariant(method.Name[0]), method.Name.Substring(1));
log.Debug("Method {0}::{1} renamed to {2}", method.Namespace.Name, oldName, method.Name);
Diagnostics.Debug("Method {0}::{1} renamed to {2}", method.Namespace.Name, oldName, method.Name);
}
foreach (var @event in type.Events.Where(e => e.Name == name))
{
var oldName = @event.Name;
@event.Name = string.Format("on{0}{1}",
char.ToUpperInvariant(@event.Name[0]), @event.Name.Substring(1));
log.Debug("Event {0}::{1} renamed to {2}", @event.Namespace.Name, oldName, @event.Name);
Diagnostics.Debug("Event {0}::{1} renamed to {2}", @event.Namespace.Name, oldName, @event.Name);
}
getter.Name = name;
GenerateProperty(getter.Namespace, getter, readOnly ? null : setter);
@ -337,7 +337,7 @@ namespace CppSharp.Passes @@ -337,7 +337,7 @@ namespace CppSharp.Passes
if (baseClass.IsClass)
VisitClassDecl(baseClass.Class);
new PropertyGenerator(@class, Log).GenerateProperties();
new PropertyGenerator(@class, Diagnostics).GenerateProperties();
}
return false;
}

8
src/Generator/Passes/GetterSetterToPropertyPass.cs

@ -54,7 +54,7 @@ namespace CppSharp.Passes @@ -54,7 +54,7 @@ namespace CppSharp.Passes
var prop2 = @class.Properties.FirstOrDefault(property => property.Name == name);
if (prop == null && prop2 != null)
Driver.Diagnostics.Debug("Property {0}::{1} already exists (type: {2})",
Diagnostics.Debug("Property {0}::{1} already exists (type: {2})",
@class.Name, name, type.Type.ToString());
if (prop != null)
@ -76,7 +76,7 @@ namespace CppSharp.Passes @@ -76,7 +76,7 @@ namespace CppSharp.Passes
if (!VisitDeclaration(method))
return false;
if (ASTUtils.CheckIgnoreMethod(method, Driver.Options))
if (ASTUtils.CheckIgnoreMethod(method, Options))
return false;
var @class = method.Namespace as Class;
@ -100,7 +100,7 @@ namespace CppSharp.Passes @@ -100,7 +100,7 @@ namespace CppSharp.Passes
// Do not generate the original method now that we know it is a getter.
method.GenerationKind = GenerationKind.Internal;
Driver.Diagnostics.Debug("Getter created: {0}::{1}", @class.Name, name);
Diagnostics.Debug("Getter created: {0}::{1}", @class.Name, name);
return false;
}
@ -117,7 +117,7 @@ namespace CppSharp.Passes @@ -117,7 +117,7 @@ namespace CppSharp.Passes
// Ignore the original method now that we know it is a setter.
method.GenerationKind = GenerationKind.Internal;
Driver.Diagnostics.Debug("Setter created: {0}::{1}", @class.Name, name);
Diagnostics.Debug("Setter created: {0}::{1}", @class.Name, name);
return false;
}

16
src/Generator/Passes/HandleDefaultParamValuesPass.cs

@ -68,7 +68,7 @@ namespace CppSharp.Passes @@ -68,7 +68,7 @@ namespace CppSharp.Passes
// constants are obtained through dynamic calls at present so they are not compile-time values in target languages
if (expression.Declaration is Variable ||
(!Driver.Options.MarshalCharAsManagedChar &&
(!Options.MarshalCharAsManagedChar &&
desugared.IsPrimitiveType(PrimitiveType.UChar)) ||
type.IsPrimitiveTypeConvertibleToRef())
return null;
@ -120,7 +120,7 @@ namespace CppSharp.Passes @@ -120,7 +120,7 @@ namespace CppSharp.Passes
if (desugared.GetFinalPointee().TryGetClass(out @class) && @class.IsValueType)
{
result = string.Format("new {0}()",
new CSharpTypePrinter(Driver).VisitClassDecl(@class));
new CSharpTypePrinter(Context).VisitClassDecl(@class));
return true;
}
@ -141,10 +141,10 @@ namespace CppSharp.Passes @@ -141,10 +141,10 @@ namespace CppSharp.Passes
TypeMap typeMap;
var typePrinter = new CSharpTypePrinter(Driver);
var typePrinter = new CSharpTypePrinter(Context);
typePrinter.PushMarshalKind(CSharpMarshalKind.DefaultExpression);
var typePrinterResult = type.Visit(typePrinter).Type;
if (Driver.TypeDatabase.FindTypeMap(decl, type, out typeMap))
if (TypeDatabase.FindTypeMap(decl, type, out typeMap))
{
var typeInSignature = typeMap.CSharpSignatureType(
typePrinter.TypePrinterContext).SkipPointerRefs().Desugar();
@ -263,13 +263,13 @@ namespace CppSharp.Passes @@ -263,13 +263,13 @@ namespace CppSharp.Passes
{
statement.Declaration = null;
result = string.Format("(int) {0}.{1}",
new CSharpTypePrinter(Driver).VisitEnumDecl(
new CSharpTypePrinter(Context).VisitEnumDecl(
(Enumeration) enumItem.Namespace), enumItem.Name);
}
else
{
result = string.Format("{0}.{1}",
new CSharpTypePrinter(Driver).VisitEnumDecl(
new CSharpTypePrinter(Context).VisitEnumDecl(
(Enumeration) enumItem.Namespace), enumItem.Name);
}
return true;
@ -292,7 +292,7 @@ namespace CppSharp.Passes @@ -292,7 +292,7 @@ namespace CppSharp.Passes
TypeMap typeMap;
if ((function.Parameters.Count == 0 ||
HasSingleZeroArgExpression(function)) &&
Driver.TypeDatabase.FindTypeMap(desugared, out typeMap))
TypeDatabase.FindTypeMap(desugared, out typeMap))
{
var typeInSignature = typeMap.CSharpSignatureType(new CSharpTypePrinterContext
{
@ -324,7 +324,7 @@ namespace CppSharp.Passes @@ -324,7 +324,7 @@ namespace CppSharp.Passes
{
int value;
if (int.TryParse(result, out value) &&
((Driver.Options.MarshalCharAsManagedChar &&
((Options.MarshalCharAsManagedChar &&
desugared.IsPrimitiveType(PrimitiveType.Char)) ||
desugared.IsPrimitiveType(PrimitiveType.WideChar)))
{

2
src/Generator/Passes/IgnoreSystemDeclarationsPass.cs

@ -35,7 +35,7 @@ namespace CppSharp.Passes @@ -35,7 +35,7 @@ namespace CppSharp.Passes
public override bool VisitClassDecl(Class @class)
{
if (!base.VisitClassDecl(@class) || Driver.Options.IsCLIGenerator)
if (!base.VisitClassDecl(@class) || Options.IsCLIGenerator)
return false;
if (!@class.TranslationUnit.IsSystemHeader)

6
src/Generator/Passes/MoveFunctionToClassPass.cs

@ -20,7 +20,7 @@ namespace CppSharp.Passes @@ -20,7 +20,7 @@ namespace CppSharp.Passes
if (@class != null && @class.TranslationUnit.Module == function.TranslationUnit.Module)
{
MoveFunction(function, @class);
Log.Debug("Function moved to class: {0}::{1}", @class.Name, function.Name);
Diagnostics.Debug("Function moved to class: {0}::{1}", @class.Name, function.Name);
}
if (function.IsOperator)
@ -34,10 +34,10 @@ namespace CppSharp.Passes @@ -34,10 +34,10 @@ namespace CppSharp.Passes
var unit = @namespace as TranslationUnit;
if (unit == null)
{
return Driver.ASTContext.FindClass(
return ASTContext.FindClass(
@namespace.Name, ignoreCase: true).FirstOrDefault();
}
return Driver.ASTContext.FindCompleteClass(
return ASTContext.FindCompleteClass(
unit.FileNameWithoutExtension.ToLowerInvariant(), true);
}

2
src/Generator/Passes/MoveOperatorToClassPass.cs

@ -41,7 +41,7 @@ namespace CppSharp.Passes @@ -41,7 +41,7 @@ namespace CppSharp.Passes
@class.Methods.Add(method);
Driver.Diagnostics.Debug("Function converted to operator: {0}::{1}",
Diagnostics.Debug("Function converted to operator: {0}::{1}",
@class.Name, function.Name);
return true;

15
src/Generator/Passes/ObjectOverridesPass.cs

@ -15,6 +15,13 @@ namespace CppSharp @@ -15,6 +15,13 @@ namespace CppSharp
// this to work.
public class ObjectOverridesPass : TranslationUnitPass
{
private Generator Generator { get; set; }
public ObjectOverridesPass(Generator generator)
{
Generator = generator;
}
private bool needsStreamInclude;
private void OnUnitGenerated(GeneratorOutput output)
{
@ -67,7 +74,7 @@ namespace CppSharp @@ -67,7 +74,7 @@ namespace CppSharp
void GenerateEquals(Class @class, Block block, Method method)
{
var cliTypePrinter = new CLITypePrinter(Driver);
var cliTypePrinter = new CLITypePrinter(Context);
var classCliType = @class.Visit(cliTypePrinter);
block.WriteLine("if (!object) return false;");
@ -93,7 +100,7 @@ namespace CppSharp @@ -93,7 +100,7 @@ namespace CppSharp
// FIXME: Add a better way to hook the event
if (!isHooked)
{
Driver.Generator.OnUnitGenerated += OnUnitGenerated;
Generator.OnUnitGenerated += OnUnitGenerated;
isHooked = true;
}
@ -126,7 +133,7 @@ namespace CppSharp @@ -126,7 +133,7 @@ namespace CppSharp
@class.Methods.Add(toStringMethod);
Driver.Diagnostics.Debug("Function converted to ToString: {0}::{1}",
Diagnostics.Debug("Function converted to ToString: {0}::{1}",
@class.Name, method.Name);
break;
@ -172,7 +179,7 @@ namespace CppSharp @@ -172,7 +179,7 @@ namespace CppSharp
AST.Type result;
if (!typeCache.TryGetValue(typeName, out result))
{
var typeDef = Driver.ASTContext.FindTypedef(typeName)
var typeDef = ASTContext.FindTypedef(typeName)
.FirstOrDefault();
if (typeDef != null)
result = new TypedefType() { Declaration = typeDef };

17
src/Generator/Passes/Pass.cs

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
using CppSharp.AST;
using CppSharp.Generators;
using CppSharp.Types;
namespace CppSharp.Passes
{
@ -9,19 +10,17 @@ namespace CppSharp.Passes @@ -9,19 +10,17 @@ namespace CppSharp.Passes
/// </summary>
public abstract class TranslationUnitPass : AstVisitor
{
public Driver Driver { get; set; }
public ASTContext AstContext { get; set; }
public IDiagnostics Log
{
get { return Driver.Diagnostics; }
}
public BindingContext Context { get; set; }
public IDiagnostics Diagnostics { get { return Context.Diagnostics; } }
public DriverOptions Options { get { return Context.Options; } }
public ASTContext ASTContext { get { return Context.ASTContext; } }
public TypeMapDatabase TypeDatabase { get { return Context.TypeDatabase; } }
public bool ClearVisitedDeclarations = false;
public virtual bool VisitLibrary(ASTContext context)
{
AstContext = context;
foreach (var unit in context.TranslationUnits)
VisitTranslationUnit(unit);
@ -58,7 +57,7 @@ namespace CppSharp.Passes @@ -58,7 +57,7 @@ namespace CppSharp.Passes
/// </summary>
public abstract class GeneratorOutputPass
{
public Driver Driver { get; set; }
public IDiagnostics Log { get; set; }
public virtual void VisitGeneratorOutput(GeneratorOutput output)
{

9
src/Generator/Passes/PassBuilder.cs

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using CppSharp.Generators;
using CppSharp.Passes;
namespace CppSharp
@ -11,13 +12,13 @@ namespace CppSharp @@ -11,13 +12,13 @@ namespace CppSharp
/// </summary>
public class PassBuilder<T>
{
public BindingContext Context { get; private set; }
public List<T> Passes { get; private set; }
public Driver Driver { get; private set; }
public PassBuilder(Driver driver)
public PassBuilder(BindingContext context)
{
Context = context;
Passes = new List<T>();
Driver = driver;
}
/// <summary>
@ -26,7 +27,7 @@ namespace CppSharp @@ -26,7 +27,7 @@ namespace CppSharp
public void AddPass(T pass)
{
if (pass is TranslationUnitPass)
(pass as TranslationUnitPass).Driver = Driver;
(pass as TranslationUnitPass).Context = Context;
Passes.Add(pass);
}

8
src/Generator/Passes/ResolveIncompleteDeclsPass.cs

@ -43,12 +43,12 @@ namespace CppSharp.Passes @@ -43,12 +43,12 @@ namespace CppSharp.Passes
goto Out;
@enum.CompleteDeclaration =
AstContext.FindCompleteEnum(@enum.QualifiedName);
ASTContext.FindCompleteEnum(@enum.QualifiedName);
if (@enum.CompleteDeclaration == null)
{
@enum.GenerationKind = GenerationKind.Internal;
Driver.Diagnostics.Warning("Unresolved declaration: {0}", @enum.Name);
Diagnostics.Warning("Unresolved declaration: {0}", @enum.Name);
}
Out:
@ -65,12 +65,12 @@ namespace CppSharp.Passes @@ -65,12 +65,12 @@ namespace CppSharp.Passes
return;
declaration.CompleteDeclaration =
AstContext.FindCompleteClass(declaration.QualifiedName);
ASTContext.FindCompleteClass(declaration.QualifiedName);
if (declaration.CompleteDeclaration == null)
{
declaration.GenerationKind = GenerationKind.Internal;
Driver.Diagnostics.Debug("Unresolved declaration: {0}",
Diagnostics.Debug("Unresolved declaration: {0}",
declaration.Name);
}
}

10
src/Generator/Types/Std/Stdlib.cs

@ -61,12 +61,12 @@ namespace CppSharp.Types.Std @@ -61,12 +61,12 @@ namespace CppSharp.Types.Std
{
var type = ctx.Parameter.Type.Desugar();
ClassTemplateSpecialization basicString = GetBasicString(type);
var typePrinter = new CSharpTypePrinter(ctx.Driver);
var typePrinter = new CSharpTypePrinter(ctx.Context);
typePrinter.PushContext(CSharpTypePrinterContextKind.Native);
if (!ctx.Parameter.Type.Desugar().IsAddress())
ctx.Return.Write("*({0}*) ", basicString.Visit(typePrinter));
typePrinter.PopContext();
var allocator = ctx.Driver.ASTContext.FindClass("allocator", false, true).First(
var allocator = ctx.Context.ASTContext.FindClass("allocator", false, true).First(
a => a.IsDependent);
if (type.IsPointer() || (type.IsReference() && ctx.Declaration is Field))
{
@ -97,7 +97,7 @@ namespace CppSharp.Types.Std @@ -97,7 +97,7 @@ namespace CppSharp.Types.Std
Declaration c_str = basicString.Methods.FirstOrDefault(m => m.OriginalName == "c_str");
if (!c_str.IsGenerated)
c_str = basicString.Properties.First(p => p.OriginalName == "c_str");
var typePrinter = new CSharpTypePrinter(ctx.Driver);
var typePrinter = new CSharpTypePrinter(ctx.Context);
if (type.IsPointer() || ctx.Declaration is Field)
{
ctx.Return.Write("{0}.{1}({2}).{3}{4}",
@ -220,7 +220,7 @@ namespace CppSharp.Types.Std @@ -220,7 +220,7 @@ namespace CppSharp.Types.Std
QualifiedType = type
};
var elementCtx = new MarshalContext(ctx.Driver)
var elementCtx = new MarshalContext(ctx.Context)
{
Parameter = param,
ArgName = param.Name,
@ -265,7 +265,7 @@ namespace CppSharp.Types.Std @@ -265,7 +265,7 @@ namespace CppSharp.Types.Std
ctx.ReturnVarName);
ctx.SupportBefore.WriteStartBraceIndent();
{
var elementCtx = new MarshalContext(ctx.Driver)
var elementCtx = new MarshalContext(ctx.Context)
{
ReturnVarName = "_element",
ReturnType = type

Loading…
Cancel
Save