Browse Source

Remove CLITypePrinterContext and its usage in CLITypePrinter.

pull/829/head
Joao Matos 8 years ago
parent
commit
11f1956cde
  1. 21
      src/Generator/Generators/CLI/CLIHeaders.cs
  2. 23
      src/Generator/Generators/CLI/CLISources.cs
  3. 44
      src/Generator/Generators/CLI/CLITypePrinter.cs
  4. 14
      src/Generator/Types/Std/Stdlib.cs
  5. 4
      src/Generator/Types/TypeMap.cs
  6. 2
      tests/Common/Common.cs

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

@ -321,9 +321,6 @@ namespace CppSharp.Generators.CLI
public void GenerateClassGenericMethods(Class @class) public void GenerateClassGenericMethods(Class @class)
{ {
var printer = TypePrinter;
var oldCtx = printer.TypePrinterContext;
PushIndent(); PushIndent();
foreach (var template in @class.Templates) foreach (var template in @class.Templates)
{ {
@ -336,17 +333,13 @@ namespace CppSharp.Generators.CLI
var function = functionTemplate.TemplatedFunction; var function = functionTemplate.TemplatedFunction;
var typeCtx = new CLITypePrinterContext() var typePrinter = new CLITypePrinter(Context)
{ {
Kind = TypePrinterContextKind.Template, Declaration = template
Declaration = template };
}; typePrinter.PushContext(TypePrinterContextKind.Template);
printer.TypePrinterContext = typeCtx;
var typePrinter = new CLITypePrinter(Context, typeCtx); var retType = function.ReturnType.Visit(typePrinter);
var retType = function.ReturnType.Type.Visit(typePrinter,
function.ReturnType.Qualifiers);
var typeNames = ""; var typeNames = "";
var paramNames = template.Parameters.Select(param => param.Name).ToList(); var paramNames = template.Parameters.Select(param => param.Name).ToList();
@ -376,8 +369,6 @@ namespace CppSharp.Generators.CLI
PopBlock(NewLineKind.BeforeNextBlock); PopBlock(NewLineKind.BeforeNextBlock);
} }
PopIndent(); PopIndent();
printer.TypePrinterContext = oldCtx;
} }
public void GenerateClassConstructors(Class @class, string nativeType) public void GenerateClassConstructors(Class @class, string nativeType)

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

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
@ -285,24 +285,17 @@ namespace CppSharp.Generators.CLI
private void GenerateFunctionTemplate(FunctionTemplate template) private void GenerateFunctionTemplate(FunctionTemplate template)
{ {
var printer = TypePrinter;
var oldCtx = printer.TypePrinterContext;
PushBlock(BlockKind.Template); PushBlock(BlockKind.Template);
var function = template.TemplatedFunction; var function = template.TemplatedFunction;
var typeCtx = new CLITypePrinterContext() var typePrinter = new CLITypePrinter(Context)
{ {
Kind = TypePrinterContextKind.Template, Declaration = template
Declaration = template };
}; typePrinter.PushContext(TypePrinterContextKind.Template);
printer.TypePrinterContext = typeCtx;
var typePrinter = new CLITypePrinter(Context, typeCtx); var retType = function.ReturnType.Visit(typePrinter);
var retType = function.ReturnType.Type.Visit(typePrinter,
function.ReturnType.Qualifiers);
var typeNames = ""; var typeNames = "";
var paramNames = template.Parameters.Select(param => param.Name).ToList(); var paramNames = template.Parameters.Select(param => param.Name).ToList();
@ -323,8 +316,6 @@ namespace CppSharp.Generators.CLI
NewLine(); NewLine();
PopBlock(NewLineKind.BeforeNextBlock); PopBlock(NewLineKind.BeforeNextBlock);
printer.TypePrinterContext = oldCtx;
} }
private void GenerateProperty(Property property, Class realOwner) private void GenerateProperty(Property property, Class realOwner)

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

@ -8,23 +8,8 @@ using Type = CppSharp.AST.Type;
namespace CppSharp.Generators.CLI namespace CppSharp.Generators.CLI
{ {
public class CLITypePrinterContext : TypePrinterContext
{
public CLITypePrinterContext()
{
}
public CLITypePrinterContext(TypePrinterContextKind kind)
: base(kind)
{
}
}
public class CLITypePrinter : TypePrinter public class CLITypePrinter : TypePrinter
{ {
public CLITypePrinterContext TypePrinterContext { get; set; }
public BindingContext Context { get; private set; } public BindingContext Context { get; private set; }
public DriverOptions Options { get { return Context.Options; } } public DriverOptions Options { get { return Context.Options; } }
@ -33,13 +18,6 @@ namespace CppSharp.Generators.CLI
public CLITypePrinter(BindingContext context) public CLITypePrinter(BindingContext context)
{ {
Context = context; Context = context;
TypePrinterContext = new CLITypePrinterContext();
}
public CLITypePrinter(BindingContext context, CLITypePrinterContext typePrinterContext)
: this(context)
{
TypePrinterContext = typePrinterContext;
} }
public override TypePrinterResult VisitTagType(TagType tag, TypeQualifiers quals) public override TypePrinterResult VisitTagType(TagType tag, TypeQualifiers quals)
@ -48,8 +26,8 @@ namespace CppSharp.Generators.CLI
if (TypeMapDatabase.FindTypeMap(tag, out typeMap)) if (TypeMapDatabase.FindTypeMap(tag, out typeMap))
{ {
typeMap.Type = tag; typeMap.Type = tag;
TypePrinterContext.Type = tag; var typePrinterContext = new TypePrinterContext { Type = tag };
return typeMap.CLISignature(TypePrinterContext); return typeMap.CLISignature(typePrinterContext);
} }
Declaration decl = tag.Declaration; Declaration decl = tag.Declaration;
@ -109,9 +87,9 @@ namespace CppSharp.Generators.CLI
public override TypePrinterResult VisitParameter(Parameter param, public override TypePrinterResult VisitParameter(Parameter param,
bool hasName = true) bool hasName = true)
{ {
TypePrinterContext.Parameter = param; Parameter = param;
var type = param.Type.Visit(this, param.QualifiedType.Qualifiers); var type = param.Type.Visit(this, param.QualifiedType.Qualifiers);
TypePrinterContext.Parameter = null; Parameter = null;
var str = string.Empty; var str = string.Empty;
if(param.Usage == ParameterUsage.Out) if(param.Usage == ParameterUsage.Out)
@ -162,8 +140,7 @@ namespace CppSharp.Generators.CLI
if (finalPointee.IsPrimitiveType()) if (finalPointee.IsPrimitiveType())
{ {
// Skip one indirection if passed by reference // Skip one indirection if passed by reference
var param = TypePrinterContext.Parameter; bool isRefParam = Parameter != null && (Parameter.IsOut || Parameter.IsInOut);
bool isRefParam = param != null && (param.IsOut || param.IsInOut);
if (isRefParam) if (isRefParam)
return pointer.QualifiedPointee.Visit(this); return pointer.QualifiedPointee.Visit(this);
@ -180,8 +157,7 @@ namespace CppSharp.Generators.CLI
var typeName = @enum.Visit(this); var typeName = @enum.Visit(this);
// Skip one indirection if passed by reference // Skip one indirection if passed by reference
var param = TypePrinterContext.Parameter; if (Parameter != null && (Parameter.IsOut || Parameter.IsInOut)
if (param != null && (param.IsOut || param.IsInOut)
&& pointee == finalPointee) && pointee == finalPointee)
return string.Format("{0}", typeName); return string.Format("{0}", typeName);
@ -247,8 +223,8 @@ namespace CppSharp.Generators.CLI
if (TypeMapDatabase.FindTypeMap(decl, out typeMap)) if (TypeMapDatabase.FindTypeMap(decl, out typeMap))
{ {
typeMap.Type = typedef; typeMap.Type = typedef;
TypePrinterContext.Type = typedef; var typePrinterContext = new TypePrinterContext { Type = typedef };
return typeMap.CLISignature(TypePrinterContext); return typeMap.CLISignature(typePrinterContext);
} }
FunctionType func; FunctionType func;
@ -285,8 +261,8 @@ namespace CppSharp.Generators.CLI
{ {
typeMap.Declaration = decl; typeMap.Declaration = decl;
typeMap.Type = template; typeMap.Type = template;
TypePrinterContext.Type = template; var typePrinterContext = new TypePrinterContext { Type = template };
return typeMap.CLISignature(TypePrinterContext); return typeMap.CLISignature(typePrinterContext);
} }
return decl.Name; return decl.Name;

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

@ -11,7 +11,7 @@ namespace CppSharp.Types.Std
[TypeMap("va_list")] [TypeMap("va_list")]
public class VaList : TypeMap public class VaList : TypeMap
{ {
public override string CLISignature(CLITypePrinterContext ctx) public override string CLISignature(TypePrinterContext ctx)
{ {
return "va_list"; return "va_list";
} }
@ -30,7 +30,7 @@ namespace CppSharp.Types.Std
[TypeMap("std::basic_string<char, std::char_traits<char>, std::allocator<char>>")] [TypeMap("std::basic_string<char, std::char_traits<char>, std::allocator<char>>")]
public class String : TypeMap public class String : TypeMap
{ {
public override string CLISignature(CLITypePrinterContext ctx) public override string CLISignature(TypePrinterContext ctx)
{ {
return "System::String^"; return "System::String^";
} }
@ -131,7 +131,7 @@ namespace CppSharp.Types.Std
[TypeMap("std::wstring", GeneratorKind = GeneratorKind.CLI)] [TypeMap("std::wstring", GeneratorKind = GeneratorKind.CLI)]
public class WString : TypeMap public class WString : TypeMap
{ {
public override string CLISignature(CLITypePrinterContext ctx) public override string CLISignature(TypePrinterContext ctx)
{ {
return "System::String^"; return "System::String^";
} }
@ -185,7 +185,7 @@ namespace CppSharp.Types.Std
} }
} }
public override string CLISignature(CLITypePrinterContext ctx) public override string CLISignature(TypePrinterContext ctx)
{ {
return string.Format("System::Collections::Generic::List<{0}>^", return string.Format("System::Collections::Generic::List<{0}>^",
ctx.GetTemplateParameterList()); ctx.GetTemplateParameterList());
@ -320,7 +320,7 @@ namespace CppSharp.Types.Std
{ {
public override bool IsIgnored { get { return true; } } public override bool IsIgnored { get { return true; } }
public override string CLISignature(CLITypePrinterContext ctx) public override string CLISignature(TypePrinterContext ctx)
{ {
var type = Type as TemplateSpecializationType; var type = Type as TemplateSpecializationType;
return string.Format( return string.Format(
@ -361,7 +361,7 @@ namespace CppSharp.Types.Std
{ {
public override bool IsIgnored { get { return true; } } public override bool IsIgnored { get { return true; } }
public override string CLISignature(CLITypePrinterContext ctx) public override string CLISignature(TypePrinterContext ctx)
{ {
throw new System.NotImplementedException(); throw new System.NotImplementedException();
} }
@ -380,7 +380,7 @@ namespace CppSharp.Types.Std
[TypeMap("std::ostream", GeneratorKind.CLI)] [TypeMap("std::ostream", GeneratorKind.CLI)]
public class OStream : TypeMap public class OStream : TypeMap
{ {
public override string CLISignature(CLITypePrinterContext ctx) public override string CLISignature(TypePrinterContext ctx)
{ {
return "System::IO::TextWriter^"; return "System::IO::TextWriter^";
} }

4
src/Generator/Types/TypeMap.cs

@ -90,12 +90,12 @@ namespace CppSharp.Types
#region C++/CLI backend #region C++/CLI backend
public virtual Type CLISignatureType(CLITypePrinterContext ctx) public virtual Type CLISignatureType(TypePrinterContext ctx)
{ {
return new CILType(typeof(object)); return new CILType(typeof(object));
} }
public virtual string CLISignature(CLITypePrinterContext ctx) public virtual string CLISignature(TypePrinterContext ctx)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

2
tests/Common/Common.cs

@ -12,7 +12,7 @@ namespace CppSharp.Tests
[TypeMap("TypeMappedIndex")] [TypeMap("TypeMappedIndex")]
public class TypeMappedIndex : TypeMap public class TypeMappedIndex : TypeMap
{ {
public override string CLISignature(CLITypePrinterContext ctx) public override string CLISignature(TypePrinterContext ctx)
{ {
return "unsigned short"; return "unsigned short";
} }

Loading…
Cancel
Save