Browse Source

Rename type printer context variables in type printers.

pull/696/head
Joao Matos 10 years ago
parent
commit
fc5c09ab75
  1. 6
      src/Generator/Generators/CLI/CLIHeaders.cs
  2. 6
      src/Generator/Generators/CLI/CLISources.cs
  3. 26
      src/Generator/Generators/CLI/CLITypePrinter.cs
  4. 54
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs
  5. 2
      src/Generator/Passes/HandleDefaultParamValuesPass.cs

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

@ -314,7 +314,7 @@ namespace CppSharp.Generators.CLI
public void GenerateClassGenericMethods(Class @class) public void GenerateClassGenericMethods(Class @class)
{ {
var printer = TypePrinter; var printer = TypePrinter;
var oldCtx = printer.Context; var oldCtx = printer.TypePrinterContext;
PushIndent(); PushIndent();
foreach (var template in @class.Templates) foreach (var template in @class.Templates)
@ -334,7 +334,7 @@ namespace CppSharp.Generators.CLI
Declaration = template Declaration = template
}; };
printer.Context = typeCtx; printer.TypePrinterContext = typeCtx;
var typePrinter = new CLITypePrinter(Driver, typeCtx); var typePrinter = new CLITypePrinter(Driver, typeCtx);
var retType = function.ReturnType.Type.Visit(typePrinter, var retType = function.ReturnType.Type.Visit(typePrinter,
@ -369,7 +369,7 @@ namespace CppSharp.Generators.CLI
} }
PopIndent(); PopIndent();
printer.Context = oldCtx; printer.TypePrinterContext = oldCtx;
} }
public void GenerateClassConstructors(Class @class, string nativeType) public void GenerateClassConstructors(Class @class, string nativeType)

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

@ -292,7 +292,7 @@ namespace CppSharp.Generators.CLI
private void GenerateFunctionTemplate(FunctionTemplate template) private void GenerateFunctionTemplate(FunctionTemplate template)
{ {
var printer = TypePrinter; var printer = TypePrinter;
var oldCtx = printer.Context; var oldCtx = printer.TypePrinterContext;
PushBlock(CLIBlockKind.Template); PushBlock(CLIBlockKind.Template);
@ -304,7 +304,7 @@ namespace CppSharp.Generators.CLI
Declaration = template Declaration = template
}; };
printer.Context = typeCtx; printer.TypePrinterContext = typeCtx;
var typePrinter = new CLITypePrinter(Driver, typeCtx); var typePrinter = new CLITypePrinter(Driver, typeCtx);
var retType = function.ReturnType.Type.Visit(typePrinter, var retType = function.ReturnType.Type.Visit(typePrinter,
@ -330,7 +330,7 @@ namespace CppSharp.Generators.CLI
PopBlock(NewLineKind.BeforeNextBlock); PopBlock(NewLineKind.BeforeNextBlock);
printer.Context = oldCtx; printer.TypePrinterContext = oldCtx;
} }
private void GenerateProperty(Property property, Class realOwner) private void GenerateProperty(Property property, Class realOwner)

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

@ -24,7 +24,7 @@ namespace CppSharp.Generators.CLI
public class CLITypePrinter : ITypePrinter<string>, IDeclVisitor<string> public class CLITypePrinter : ITypePrinter<string>, IDeclVisitor<string>
{ {
public Driver Driver { get; set; } public Driver Driver { get; set; }
public CLITypePrinterContext Context { get; set; } public CLITypePrinterContext TypePrinterContext { get; set; }
readonly ITypeMapDatabase TypeMapDatabase; readonly ITypeMapDatabase TypeMapDatabase;
readonly DriverOptions Options; readonly DriverOptions Options;
@ -34,13 +34,13 @@ namespace CppSharp.Generators.CLI
Driver = driver; Driver = driver;
TypeMapDatabase = driver.TypeDatabase; TypeMapDatabase = driver.TypeDatabase;
Options = driver.Options; Options = driver.Options;
Context = new CLITypePrinterContext(); TypePrinterContext = new CLITypePrinterContext();
} }
public CLITypePrinter(Driver driver, CLITypePrinterContext context) public CLITypePrinter(Driver driver, CLITypePrinterContext context)
: this(driver) : this(driver)
{ {
Context = context; TypePrinterContext = context;
} }
public string VisitTagType(TagType tag, TypeQualifiers quals) public string VisitTagType(TagType tag, TypeQualifiers quals)
@ -49,8 +49,8 @@ namespace CppSharp.Generators.CLI
if (TypeMapDatabase.FindTypeMap(tag, out typeMap)) if (TypeMapDatabase.FindTypeMap(tag, out typeMap))
{ {
typeMap.Type = tag; typeMap.Type = tag;
Context.Type = tag; TypePrinterContext.Type = tag;
return typeMap.CLISignature(Context); return typeMap.CLISignature(TypePrinterContext);
} }
Declaration decl = tag.Declaration; Declaration decl = tag.Declaration;
@ -107,9 +107,9 @@ namespace CppSharp.Generators.CLI
public string VisitParameter(Parameter param, bool hasName = true) public string VisitParameter(Parameter param, bool hasName = true)
{ {
Context.Parameter = param; TypePrinterContext.Parameter = param;
var type = param.Type.Visit(this, param.QualifiedType.Qualifiers); var type = param.Type.Visit(this, param.QualifiedType.Qualifiers);
Context.Parameter = null; TypePrinterContext.Parameter = null;
var str = string.Empty; var str = string.Empty;
if(param.Usage == ParameterUsage.Out) if(param.Usage == ParameterUsage.Out)
@ -159,7 +159,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 = Context.Parameter; var param = TypePrinterContext.Parameter;
bool isRefParam = param != null && (param.IsOut || param.IsInOut); bool isRefParam = param != null && (param.IsOut || param.IsInOut);
if (isRefParam) if (isRefParam)
return pointee.Visit(this, quals); return pointee.Visit(this, quals);
@ -177,7 +177,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 = Context.Parameter; var param = TypePrinterContext.Parameter;
if (param != null && (param.IsOut || param.IsInOut) if (param != null && (param.IsOut || param.IsInOut)
&& pointee == finalPointee) && pointee == finalPointee)
return string.Format("{0}", typeName); return string.Format("{0}", typeName);
@ -238,8 +238,8 @@ namespace CppSharp.Generators.CLI
if (TypeMapDatabase.FindTypeMap(decl, out typeMap)) if (TypeMapDatabase.FindTypeMap(decl, out typeMap))
{ {
typeMap.Type = typedef; typeMap.Type = typedef;
Context.Type = typedef; TypePrinterContext.Type = typedef;
return typeMap.CLISignature(Context); return typeMap.CLISignature(TypePrinterContext);
} }
FunctionType func; FunctionType func;
@ -274,8 +274,8 @@ namespace CppSharp.Generators.CLI
{ {
typeMap.Declaration = decl; typeMap.Declaration = decl;
typeMap.Type = template; typeMap.Type = template;
Context.Type = template; TypePrinterContext.Type = template;
return typeMap.CLISignature(Context); return typeMap.CLISignature(TypePrinterContext);
} }
return decl.Name; return decl.Name;

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

@ -67,7 +67,7 @@ namespace CppSharp.Generators.CSharp
get { return marshalKinds.Peek(); } get { return marshalKinds.Peek(); }
} }
public CSharpTypePrinterContext Context; public CSharpTypePrinterContext TypePrinterContext;
public CSharpTypePrinter(Driver driver) public CSharpTypePrinter(Driver driver)
{ {
@ -78,7 +78,7 @@ namespace CppSharp.Generators.CSharp
PushContext(CSharpTypePrinterContextKind.Managed); PushContext(CSharpTypePrinterContextKind.Managed);
PushMarshalKind(CSharpMarshalKind.Unknown); PushMarshalKind(CSharpMarshalKind.Unknown);
Context = new CSharpTypePrinterContext(); TypePrinterContext = new CSharpTypePrinterContext();
} }
public void PushContext(CSharpTypePrinterContextKind contextKind) public void PushContext(CSharpTypePrinterContextKind contextKind)
@ -110,11 +110,11 @@ namespace CppSharp.Generators.CSharp
if (driver.TypeDatabase.FindTypeMap(tag.Declaration, out typeMap)) if (driver.TypeDatabase.FindTypeMap(tag.Declaration, out typeMap))
{ {
typeMap.Type = tag; typeMap.Type = tag;
Context.CSharpKind = ContextKind; TypePrinterContext.CSharpKind = ContextKind;
Context.MarshalKind = MarshalKind; TypePrinterContext.MarshalKind = MarshalKind;
Context.Type = tag; TypePrinterContext.Type = tag;
string type = typeMap.CSharpSignature(Context); string type = typeMap.CSharpSignature(TypePrinterContext);
if (!string.IsNullOrEmpty(type)) if (!string.IsNullOrEmpty(type))
{ {
return new CSharpTypePrinterResult return new CSharpTypePrinterResult
@ -147,7 +147,7 @@ namespace CppSharp.Generators.CSharp
return string.Format("{0}*", array.Type.Visit(this, quals)); return string.Format("{0}*", array.Type.Visit(this, quals));
} }
if (Context.Parameter != null) if (TypePrinterContext.Parameter != null)
return string.Format("global::System.IntPtr"); return string.Format("global::System.IntPtr");
Class @class; Class @class;
@ -269,7 +269,7 @@ namespace CppSharp.Generators.CSharp
{ {
if (isManagedContext || MarshalKind == CSharpMarshalKind.GenericDelegate) if (isManagedContext || MarshalKind == CSharpMarshalKind.GenericDelegate)
return "string"; return "string";
if (Context.Parameter == null || Context.Parameter.Name == Helpers.ReturnIdentifier) if (TypePrinterContext.Parameter == null || TypePrinterContext.Parameter.Name == Helpers.ReturnIdentifier)
return IntPtrType; return IntPtrType;
if (driver.Options.Encoding == Encoding.ASCII) if (driver.Options.Encoding == Encoding.ASCII)
return string.Format("[MarshalAs(UnmanagedType.LPStr)] string"); return string.Format("[MarshalAs(UnmanagedType.LPStr)] string");
@ -293,7 +293,7 @@ namespace CppSharp.Generators.CSharp
if (finalPointee.IsPrimitiveType()) if (finalPointee.IsPrimitiveType())
{ {
// Skip one indirection if passed by reference // Skip one indirection if passed by reference
var param = Context.Parameter; var param = TypePrinterContext.Parameter;
bool isRefParam = param != null && (param.IsOut || param.IsInOut); bool isRefParam = param != null && (param.IsOut || param.IsInOut);
if (isManagedContext && isRefParam) if (isManagedContext && isRefParam)
return pointee.Visit(this, quals); return pointee.Visit(this, quals);
@ -317,7 +317,7 @@ namespace CppSharp.Generators.CSharp
if (desugared.TryGetEnum(out @enum)) if (desugared.TryGetEnum(out @enum))
{ {
// Skip one indirection if passed by reference // Skip one indirection if passed by reference
var param = Context.Parameter; var param = TypePrinterContext.Parameter;
if (isManagedContext && param != null && (param.IsOut || param.IsInOut) if (isManagedContext && param != null && (param.IsOut || param.IsInOut)
&& pointee == finalPointee) && pointee == finalPointee)
return pointee.Visit(this, quals); return pointee.Visit(this, quals);
@ -327,7 +327,7 @@ namespace CppSharp.Generators.CSharp
Class @class; Class @class;
if ((desugared.IsDependent || desugared.TryGetClass(out @class) || if ((desugared.IsDependent || desugared.TryGetClass(out @class) ||
(desugared is ArrayType && Context.Parameter != null)) (desugared is ArrayType && TypePrinterContext.Parameter != null))
&& ContextKind == CSharpTypePrinterContextKind.Native) && ContextKind == CSharpTypePrinterContextKind.Native)
{ {
return IntPtrType; return IntPtrType;
@ -363,11 +363,11 @@ namespace CppSharp.Generators.CSharp
if (driver.TypeDatabase.FindTypeMap(decl, out typeMap)) if (driver.TypeDatabase.FindTypeMap(decl, out typeMap))
{ {
typeMap.Type = typedef; typeMap.Type = typedef;
Context.CSharpKind = ContextKind; TypePrinterContext.CSharpKind = ContextKind;
Context.MarshalKind = MarshalKind; TypePrinterContext.MarshalKind = MarshalKind;
Context.Type = typedef; TypePrinterContext.Type = typedef;
string type = typeMap.CSharpSignature(Context); string type = typeMap.CSharpSignature(TypePrinterContext);
if (!string.IsNullOrEmpty(type)) if (!string.IsNullOrEmpty(type))
{ {
return new CSharpTypePrinterResult return new CSharpTypePrinterResult
@ -420,9 +420,9 @@ namespace CppSharp.Generators.CSharp
typeMap.Declaration = decl; typeMap.Declaration = decl;
typeMap.Type = template; typeMap.Type = template;
Context.Type = template; TypePrinterContext.Type = template;
Context.CSharpKind = ContextKind; TypePrinterContext.CSharpKind = ContextKind;
Context.MarshalKind = MarshalKind; TypePrinterContext.MarshalKind = MarshalKind;
var type = GetCSharpSignature(typeMap); var type = GetCSharpSignature(typeMap);
if (!string.IsNullOrEmpty(type)) if (!string.IsNullOrEmpty(type))
@ -449,9 +449,9 @@ namespace CppSharp.Generators.CSharp
private string GetCSharpSignature(TypeMap typeMap) private string GetCSharpSignature(TypeMap typeMap)
{ {
Context.CSharpKind = ContextKind; TypePrinterContext.CSharpKind = ContextKind;
Context.MarshalKind = MarshalKind; TypePrinterContext.MarshalKind = MarshalKind;
return typeMap.CSharpSignature(Context); return typeMap.CSharpSignature(TypePrinterContext);
} }
public CSharpTypePrinterResult VisitTemplateParameterType( public CSharpTypePrinterResult VisitTemplateParameterType(
@ -642,9 +642,9 @@ namespace CppSharp.Generators.CSharp
if (parameter.Kind == ParameterKind.IndirectReturnType) if (parameter.Kind == ParameterKind.IndirectReturnType)
return IntPtrType; return IntPtrType;
Context.Parameter = parameter; TypePrinterContext.Parameter = parameter;
var ret = paramType.Visit(this); var ret = paramType.Visit(this);
Context.Parameter = null; TypePrinterContext.Parameter = null;
return ret; return ret;
} }
@ -763,11 +763,11 @@ namespace CppSharp.Generators.CSharp
foreach (var param in @params) foreach (var param in @params)
{ {
Context.Parameter = param; TypePrinterContext.Parameter = param;
args.Add(VisitParameter(param, hasNames).Type); args.Add(VisitParameter(param, hasNames).Type);
} }
Context.Parameter = null; TypePrinterContext.Parameter = null;
return string.Join(", ", args); return string.Join(", ", args);
} }
@ -842,7 +842,7 @@ namespace CppSharp.Generators.CSharp
public static CSharpTypePrinterResult CSharpType(this QualifiedType type, public static CSharpTypePrinterResult CSharpType(this QualifiedType type,
CSharpTypePrinter printer) CSharpTypePrinter printer)
{ {
printer.Context.FullType = type; printer.TypePrinterContext.FullType = type;
return type.Visit(printer); return type.Visit(printer);
} }
@ -858,7 +858,7 @@ namespace CppSharp.Generators.CSharp
if (decl is ITypedDecl) if (decl is ITypedDecl)
{ {
var type = (decl as ITypedDecl).QualifiedType; var type = (decl as ITypedDecl).QualifiedType;
printer.Context.FullType = type; printer.TypePrinterContext.FullType = type;
} }
return decl.Visit(printer); return decl.Visit(printer);

2
src/Generator/Passes/HandleDefaultParamValuesPass.cs

@ -147,7 +147,7 @@ namespace CppSharp.Passes
if (Driver.TypeDatabase.FindTypeMap(decl, type, out typeMap)) if (Driver.TypeDatabase.FindTypeMap(decl, type, out typeMap))
{ {
var typeInSignature = typeMap.CSharpSignatureType( var typeInSignature = typeMap.CSharpSignatureType(
typePrinter.Context).SkipPointerRefs().Desugar(); typePrinter.TypePrinterContext).SkipPointerRefs().Desugar();
Enumeration @enum; Enumeration @enum;
if (typeInSignature.TryGetEnum(out @enum)) if (typeInSignature.TryGetEnum(out @enum))
{ {

Loading…
Cancel
Save