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

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

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

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

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

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

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

2
src/Generator/Passes/HandleDefaultParamValuesPass.cs

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

Loading…
Cancel
Save