Browse Source

Added a new type printer context concept to support generation of different type names in different contexts.

pull/1/head
triton 12 years ago
parent
commit
54b0504f67
  1. 34
      src/Generator/Generators/CLI/CLITypePrinter.cs
  2. 12
      src/Generator/Types/Std/Stdlib.cs
  3. 2
      src/Generator/Types/TypeMap.cs

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

@ -1,21 +1,47 @@ @@ -1,21 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Cxxi.Types;
namespace Cxxi.Generators.CLI
{
public enum TypePrinterContextKind
{
Normal,
}
public class TypePrinterContext
{
public TypePrinterContext()
{
Kind = TypePrinterContextKind.Normal;
}
public TypePrinterContextKind Kind;
public Declaration Declaration;
public Type Type;
}
public class CLITypePrinter : ITypePrinter, IDeclVisitor<string>
{
public Library Library { get; set; }
public TypePrinterContext Context { get; set; }
readonly ITypeMapDatabase TypeMapDatabase;
readonly DriverOptions Options;
public CLITypePrinter(Driver driver)
{
TypeMapDatabase = driver.TypeDatabase;
Library = driver.Library;
TypeMapDatabase = driver.TypeDatabase;
Options = driver.Options;
Context = new TypePrinterContext();
}
public CLITypePrinter(Driver driver, TypePrinterContext context)
: this(driver)
{
Context = context;
}
public string VisitTagType(TagType tag, TypeQualifiers quals)
@ -149,7 +175,8 @@ namespace Cxxi.Generators.CLI @@ -149,7 +175,8 @@ namespace Cxxi.Generators.CLI
if (TypeMapDatabase.FindTypeMap(decl, out typeMap))
{
typeMap.Type = typedef;
return typeMap.CLISignature();
Context.Type = typedef;
return typeMap.CLISignature(Context);
}
FunctionType func;
@ -172,7 +199,8 @@ namespace Cxxi.Generators.CLI @@ -172,7 +199,8 @@ namespace Cxxi.Generators.CLI
{
typeMap.Declaration = decl;
typeMap.Type = template;
return typeMap.CLISignature();
Context.Type = template;
return typeMap.CLISignature(Context);
}
return decl.Name;

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

@ -1,4 +1,6 @@ @@ -1,4 +1,6 @@
using System;
using System.Linq;
using Cxxi.Generators.CLI;
namespace Cxxi.Types.Std
{
@ -14,7 +16,7 @@ namespace Cxxi.Types.Std @@ -14,7 +16,7 @@ namespace Cxxi.Types.Std
[TypeMap("std::string")]
public class String : TypeMap
{
public override string CLISignature()
public override string CLISignature(TypePrinterContext ctx)
{
return "System::String^";
}
@ -48,7 +50,7 @@ namespace Cxxi.Types.Std @@ -48,7 +50,7 @@ namespace Cxxi.Types.Std
[TypeMap("std::wstring")]
public class WString : TypeMap
{
public override string CLISignature()
public override string CLISignature(TypePrinterContext ctx)
{
return "System::String^";
}
@ -69,7 +71,7 @@ namespace Cxxi.Types.Std @@ -69,7 +71,7 @@ namespace Cxxi.Types.Std
{
public override bool IsIgnored { get { return true; } }
public override string CLISignature()
public override string CLISignature(TypePrinterContext ctx)
{
var type = Type as TemplateSpecializationType;
var typeName = type.Arguments[0].Type.ToString();
@ -92,7 +94,7 @@ namespace Cxxi.Types.Std @@ -92,7 +94,7 @@ namespace Cxxi.Types.Std
{
public override bool IsIgnored { get { return true; } }
public override string CLISignature()
public override string CLISignature(TypePrinterContext ctx)
{
var type = Type as TemplateSpecializationType;
return string.Format("System::Collections::Generic::Dictionary<{0}, {1}>^",
@ -120,7 +122,7 @@ namespace Cxxi.Types.Std @@ -120,7 +122,7 @@ namespace Cxxi.Types.Std
[TypeMap("std::shared_ptr")]
public class SharedPtr : TypeMap
{
public override string CLISignature()
public override string CLISignature(TypePrinterContext ctx)
{
throw new System.NotImplementedException();
}

2
src/Generator/Types/TypeMap.cs

@ -85,7 +85,7 @@ namespace Cxxi.Types @@ -85,7 +85,7 @@ namespace Cxxi.Types
#region C++/CLI backend
public virtual string CLISignature()
public virtual string CLISignature(TypePrinterContext ctx)
{
throw new NotImplementedException();
}

Loading…
Cancel
Save