Browse Source

Pass Driver to CSharpTypePrinter

We need Driver.TargeInfo in CSharpTypePrinter so that we can find out the
widths of the integer types.

This patch changes CSharpTypePrinter to get the Driver reference in its
constructor. As all the other constructor parameters can be found from the
Driver reference, we can remove all the other parameters.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@iki.fi>
pull/252/head
Tomi Valkeinen 12 years ago committed by triton
parent
commit
4818d3974d
  1. 2
      src/Generator/Generators/CSharp/CSharpGenerator.cs
  2. 18
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs

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

@ -11,7 +11,7 @@ namespace CppSharp.Generators.CSharp @@ -11,7 +11,7 @@ namespace CppSharp.Generators.CSharp
public CSharpGenerator(Driver driver) : base(driver)
{
typePrinter = new CSharpTypePrinter(driver.TypeDatabase, driver.Options, driver.ASTContext);
typePrinter = new CSharpTypePrinter(driver);
expressionPrinter = new CSharpExpressionPrinter();
CppSharp.AST.Type.TypePrinterDelegate += type => type.Visit(typePrinter).Type;
}

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

@ -52,9 +52,7 @@ namespace CppSharp.Generators.CSharp @@ -52,9 +52,7 @@ namespace CppSharp.Generators.CSharp
public class CSharpTypePrinter : ITypePrinter<CSharpTypePrinterResult>,
IDeclVisitor<CSharpTypePrinterResult>
{
public ASTContext AstContext { get; set; }
private readonly ITypeMapDatabase TypeMapDatabase;
private readonly DriverOptions driverOptions;
private Driver driver;
private readonly Stack<CSharpTypePrinterContextKind> contexts;
@ -65,11 +63,9 @@ namespace CppSharp.Generators.CSharp @@ -65,11 +63,9 @@ namespace CppSharp.Generators.CSharp
public CSharpTypePrinterContext Context;
public CSharpTypePrinter(ITypeMapDatabase database, DriverOptions driverOptions, ASTContext context)
public CSharpTypePrinter(Driver driver)
{
TypeMapDatabase = database;
this.driverOptions = driverOptions;
AstContext = context;
this.driver = driver;
contexts = new Stack<CSharpTypePrinterContextKind>();
PushContext(CSharpTypePrinterContextKind.Managed);
@ -93,7 +89,7 @@ namespace CppSharp.Generators.CSharp @@ -93,7 +89,7 @@ namespace CppSharp.Generators.CSharp
return string.Empty;
TypeMap typeMap;
if (TypeMapDatabase.FindTypeMap(tag.Declaration, out typeMap))
if (this.driver.TypeDatabase.FindTypeMap(tag.Declaration, out typeMap))
{
typeMap.Type = tag;
Context.CSharpKind = ContextKind;
@ -269,7 +265,7 @@ namespace CppSharp.Generators.CSharp @@ -269,7 +265,7 @@ namespace CppSharp.Generators.CSharp
var decl = typedef.Declaration;
TypeMap typeMap;
if (TypeMapDatabase.FindTypeMap(decl, out typeMap))
if (this.driver.TypeDatabase.FindTypeMap(decl, out typeMap))
{
typeMap.Type = typedef;
Context.CSharpKind = ContextKind;
@ -314,7 +310,7 @@ namespace CppSharp.Generators.CSharp @@ -314,7 +310,7 @@ namespace CppSharp.Generators.CSharp
var decl = template.Template.TemplatedDecl;
TypeMap typeMap = null;
if (TypeMapDatabase.FindTypeMap(template, out typeMap))
if (this.driver.TypeDatabase.FindTypeMap(template, out typeMap))
{
typeMap.Declaration = decl;
typeMap.Type = template;
@ -386,7 +382,7 @@ namespace CppSharp.Generators.CSharp @@ -386,7 +382,7 @@ namespace CppSharp.Generators.CSharp
case PrimitiveType.Void: return "void";
case PrimitiveType.Char16:
case PrimitiveType.WideChar: return "char";
case PrimitiveType.Char: return driverOptions.MarshalCharAsManagedChar ? "char" : "sbyte";
case PrimitiveType.Char: return this.driver.Options.MarshalCharAsManagedChar ? "char" : "sbyte";
case PrimitiveType.UChar: return "byte";
case PrimitiveType.Short: return "short";
case PrimitiveType.UShort: return "ushort";

Loading…
Cancel
Save