Browse Source

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

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

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

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

2
src/Generator/Types/TypeMap.cs

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

Loading…
Cancel
Save