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

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

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

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

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

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

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

4
src/Generator/Types/TypeMap.cs

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

2
tests/Common/Common.cs

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

Loading…
Cancel
Save