Browse Source

Normalized line endings of CSharpTypePrinter.cs

pull/124/head
triton 12 years ago
parent
commit
7520c25d30
  1. 956
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs

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

@ -1,92 +1,92 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using CppSharp.AST; using CppSharp.AST;
using CppSharp.Types; using CppSharp.Types;
using Type = CppSharp.AST.Type; using Type = CppSharp.AST.Type;
namespace CppSharp.Generators.CSharp namespace CppSharp.Generators.CSharp
{ {
public enum CSharpTypePrinterContextKind public enum CSharpTypePrinterContextKind
{ {
Native, Native,
Managed, Managed,
ManagedPointer, ManagedPointer,
GenericDelegate, GenericDelegate,
PrimitiveIndexer PrimitiveIndexer
} }
public class CSharpTypePrinterContext : TypePrinterContext public class CSharpTypePrinterContext : TypePrinterContext
{ {
public CSharpTypePrinterContextKind CSharpKind; public CSharpTypePrinterContextKind CSharpKind;
public QualifiedType FullType; public QualifiedType FullType;
public CSharpTypePrinterContext() public CSharpTypePrinterContext()
{ {
} }
public CSharpTypePrinterContext(TypePrinterContextKind kind, public CSharpTypePrinterContext(TypePrinterContextKind kind,
CSharpTypePrinterContextKind csharpKind) : base(kind) CSharpTypePrinterContextKind csharpKind) : base(kind)
{ {
CSharpKind = csharpKind; CSharpKind = csharpKind;
} }
} }
public class CSharpTypePrinterResult public class CSharpTypePrinterResult
{ {
public string Type; public string Type;
public TypeMap TypeMap; public TypeMap TypeMap;
public string NameSuffix; public string NameSuffix;
public static implicit operator CSharpTypePrinterResult(string type) public static implicit operator CSharpTypePrinterResult(string type)
{ {
return new CSharpTypePrinterResult() {Type = type}; return new CSharpTypePrinterResult() {Type = type};
} }
public override string ToString() public override string ToString()
{ {
return Type; return Type;
} }
} }
public class CSharpTypePrinter : ITypePrinter<CSharpTypePrinterResult>, public class CSharpTypePrinter : ITypePrinter<CSharpTypePrinterResult>,
IDeclVisitor<CSharpTypePrinterResult> IDeclVisitor<CSharpTypePrinterResult>
{ {
public ASTContext AstContext { get; set; } public ASTContext AstContext { get; set; }
private readonly ITypeMapDatabase TypeMapDatabase; private readonly ITypeMapDatabase TypeMapDatabase;
private readonly Stack<CSharpTypePrinterContextKind> contexts; private readonly Stack<CSharpTypePrinterContextKind> contexts;
public CSharpTypePrinterContextKind ContextKind public CSharpTypePrinterContextKind ContextKind
{ {
get { return contexts.Peek(); } get { return contexts.Peek(); }
} }
public CSharpTypePrinterContext Context; public CSharpTypePrinterContext Context;
public CSharpTypePrinter(ITypeMapDatabase database, ASTContext context) public CSharpTypePrinter(ITypeMapDatabase database, ASTContext context)
{ {
TypeMapDatabase = database; TypeMapDatabase = database;
AstContext = context; AstContext = context;
contexts = new Stack<CSharpTypePrinterContextKind>(); contexts = new Stack<CSharpTypePrinterContextKind>();
PushContext(CSharpTypePrinterContextKind.Managed); PushContext(CSharpTypePrinterContextKind.Managed);
Context = new CSharpTypePrinterContext(); Context = new CSharpTypePrinterContext();
} }
public void PushContext(CSharpTypePrinterContextKind contextKind) public void PushContext(CSharpTypePrinterContextKind contextKind)
{ {
contexts.Push(contextKind); contexts.Push(contextKind);
} }
public CSharpTypePrinterContextKind PopContext() public CSharpTypePrinterContextKind PopContext()
{ {
return contexts.Pop(); return contexts.Pop();
} }
public CSharpTypePrinterResult VisitTagType(TagType tag, TypeQualifiers quals) public CSharpTypePrinterResult VisitTagType(TagType tag, TypeQualifiers quals)
{ {
if (tag.Declaration == null) if (tag.Declaration == null)
return string.Empty; return string.Empty;
@ -102,102 +102,102 @@ namespace CppSharp.Generators.CSharp
Type = typeMap.CSharpSignature(Context), Type = typeMap.CSharpSignature(Context),
TypeMap = typeMap TypeMap = typeMap
}; };
} }
return tag.Declaration.Visit(this); return tag.Declaration.Visit(this);
} }
public CSharpTypePrinterResult VisitArrayType(ArrayType array, public CSharpTypePrinterResult VisitArrayType(ArrayType array,
TypeQualifiers quals) TypeQualifiers quals)
{ {
if (ContextKind == CSharpTypePrinterContextKind.Native && if (ContextKind == CSharpTypePrinterContextKind.Native &&
array.SizeType == ArrayType.ArraySize.Constant) array.SizeType == ArrayType.ArraySize.Constant)
{ {
return new CSharpTypePrinterResult() return new CSharpTypePrinterResult()
{ {
Type = string.Format("fixed {0}", array.Type.Visit(this, quals)), Type = string.Format("fixed {0}", array.Type.Visit(this, quals)),
NameSuffix = string.Format("[{0}]", array.Size) NameSuffix = string.Format("[{0}]", array.Size)
}; };
} }
return string.Format("{0}[]", array.Type.Visit(this)); return string.Format("{0}[]", array.Type.Visit(this));
// C# only supports fixed arrays in unsafe sections // C# only supports fixed arrays in unsafe sections
// and they are constrained to a set of built-in types. // and they are constrained to a set of built-in types.
} }
public CSharpTypePrinterResult VisitFunctionType(FunctionType function, public CSharpTypePrinterResult VisitFunctionType(FunctionType function,
TypeQualifiers quals) TypeQualifiers quals)
{ {
var arguments = function.Parameters; var arguments = function.Parameters;
var returnType = function.ReturnType; var returnType = function.ReturnType;
var args = string.Empty; var args = string.Empty;
PushContext(CSharpTypePrinterContextKind.GenericDelegate); PushContext(CSharpTypePrinterContextKind.GenericDelegate);
if (arguments.Count > 0) if (arguments.Count > 0)
args = VisitParameters(function.Parameters, hasNames: false).Type; args = VisitParameters(function.Parameters, hasNames: false).Type;
PopContext(); PopContext();
if (ContextKind != CSharpTypePrinterContextKind.Managed) if (ContextKind != CSharpTypePrinterContextKind.Managed)
return "global::System.IntPtr"; return "global::System.IntPtr";
if (returnType.Type.IsPrimitiveType(PrimitiveType.Void)) if (returnType.Type.IsPrimitiveType(PrimitiveType.Void))
{ {
if (!string.IsNullOrEmpty(args)) if (!string.IsNullOrEmpty(args))
args = string.Format("<{0}>", args); args = string.Format("<{0}>", args);
return string.Format("Action{0}", args); return string.Format("Action{0}", args);
} }
if (!string.IsNullOrEmpty(args)) if (!string.IsNullOrEmpty(args))
args = string.Format(", {0}", args); args = string.Format(", {0}", args);
return string.Format("Func<{0}{1}>", returnType.Visit(this), args); return string.Format("Func<{0}{1}>", returnType.Visit(this), args);
} }
public static bool IsConstCharString(PointerType pointer) public static bool IsConstCharString(PointerType pointer)
{ {
var pointee = pointer.Pointee.Desugar(); var pointee = pointer.Pointee.Desugar();
return (pointee.IsPrimitiveType(PrimitiveType.Char) || return (pointee.IsPrimitiveType(PrimitiveType.Char) ||
pointee.IsPrimitiveType(PrimitiveType.WideChar)) && pointee.IsPrimitiveType(PrimitiveType.WideChar)) &&
pointer.QualifiedPointee.Qualifiers.IsConst; pointer.QualifiedPointee.Qualifiers.IsConst;
} }
public static bool IsConstCharString(QualifiedType qualType) public static bool IsConstCharString(QualifiedType qualType)
{ {
var desugared = qualType.Type.Desugar(); var desugared = qualType.Type.Desugar();
if (!(desugared is PointerType)) if (!(desugared is PointerType))
return false; return false;
var pointer = desugared as PointerType; var pointer = desugared as PointerType;
return IsConstCharString(pointer); return IsConstCharString(pointer);
} }
public CSharpTypePrinterResult VisitPointerType(PointerType pointer, public CSharpTypePrinterResult VisitPointerType(PointerType pointer,
TypeQualifiers quals) TypeQualifiers quals)
{ {
var pointee = pointer.Pointee; var pointee = pointer.Pointee;
if (pointee is FunctionType) if (pointee is FunctionType)
{ {
var function = pointee as FunctionType; var function = pointee as FunctionType;
return string.Format("{0}", function.Visit(this, quals)); return string.Format("{0}", function.Visit(this, quals));
} }
var isManagedContext = ContextKind == CSharpTypePrinterContextKind.Managed; var isManagedContext = ContextKind == CSharpTypePrinterContextKind.Managed;
if (IsConstCharString(pointer)) if (IsConstCharString(pointer))
return isManagedContext ? "string" : "global::System.IntPtr"; return isManagedContext ? "string" : "global::System.IntPtr";
PrimitiveType primitive; PrimitiveType primitive;
var desugared = pointee.Desugar(); var desugared = pointee.Desugar();
if (desugared.IsPrimitiveType(out primitive)) if (desugared.IsPrimitiveType(out primitive))
{ {
if (isManagedContext && Context.Parameter != null && if (isManagedContext && Context.Parameter != null &&
(Context.Parameter.IsOut || Context.Parameter.IsInOut)) (Context.Parameter.IsOut || Context.Parameter.IsInOut))
return VisitPrimitiveType(primitive, quals); return VisitPrimitiveType(primitive, quals);
if (ContextKind == CSharpTypePrinterContextKind.GenericDelegate) if (ContextKind == CSharpTypePrinterContextKind.GenericDelegate)
@ -205,269 +205,269 @@ namespace CppSharp.Generators.CSharp
return VisitPrimitiveType(primitive, quals) + "*"; return VisitPrimitiveType(primitive, quals) + "*";
} }
Class @class; Class @class;
if (desugared.IsTagDecl(out @class) if (desugared.IsTagDecl(out @class)
&& ContextKind == CSharpTypePrinterContextKind.Native) && ContextKind == CSharpTypePrinterContextKind.Native)
{ {
return "global::System.IntPtr"; return "global::System.IntPtr";
} }
return pointee.Visit(this, quals); return pointee.Visit(this, quals);
} }
public CSharpTypePrinterResult VisitMemberPointerType(MemberPointerType member, public CSharpTypePrinterResult VisitMemberPointerType(MemberPointerType member,
TypeQualifiers quals) TypeQualifiers quals)
{ {
FunctionType functionType; FunctionType functionType;
if (member.IsPointerTo(out functionType)) if (member.IsPointerTo(out functionType))
{ {
return functionType.Visit(this, quals); return functionType.Visit(this, quals);
} }
throw new InvalidOperationException("A function pointer not pointing to a function type."); throw new InvalidOperationException("A function pointer not pointing to a function type.");
} }
public CSharpTypePrinterResult VisitBuiltinType(BuiltinType builtin, public CSharpTypePrinterResult VisitBuiltinType(BuiltinType builtin,
TypeQualifiers quals) TypeQualifiers quals)
{ {
return VisitPrimitiveType(builtin.Type, quals); return VisitPrimitiveType(builtin.Type, quals);
} }
public CSharpTypePrinterResult VisitTypedefType(TypedefType typedef, public CSharpTypePrinterResult VisitTypedefType(TypedefType typedef,
TypeQualifiers quals) TypeQualifiers quals)
{ {
var decl = typedef.Declaration; var decl = typedef.Declaration;
TypeMap typeMap; TypeMap typeMap;
if (TypeMapDatabase.FindTypeMap(decl, out typeMap)) if (TypeMapDatabase.FindTypeMap(decl, out typeMap))
{ {
typeMap.Type = typedef; typeMap.Type = typedef;
Context.CSharpKind = ContextKind; Context.CSharpKind = ContextKind;
Context.Type = typedef; Context.Type = typedef;
return new CSharpTypePrinterResult() return new CSharpTypePrinterResult()
{ {
Type = typeMap.CSharpSignature(Context), Type = typeMap.CSharpSignature(Context),
TypeMap = typeMap TypeMap = typeMap
}; };
} }
FunctionType func; FunctionType func;
if (decl.Type.IsPointerTo<FunctionType>(out func)) if (decl.Type.IsPointerTo<FunctionType>(out func))
{ {
if (ContextKind == CSharpTypePrinterContextKind.Native) if (ContextKind == CSharpTypePrinterContextKind.Native)
return "global::System.IntPtr"; return "global::System.IntPtr";
// TODO: Use SafeIdentifier() // TODO: Use SafeIdentifier()
return VisitDeclaration(decl); return VisitDeclaration(decl);
} }
return decl.Type.Visit(this); return decl.Type.Visit(this);
} }
public CSharpTypePrinterResult VisitDecayedType(DecayedType decayed, TypeQualifiers quals) public CSharpTypePrinterResult VisitDecayedType(DecayedType decayed, TypeQualifiers quals)
{ {
return decayed.Decayed.Visit(this); return decayed.Decayed.Visit(this);
} }
public CSharpTypePrinterResult VisitTemplateSpecializationType( public CSharpTypePrinterResult VisitTemplateSpecializationType(
TemplateSpecializationType template, TypeQualifiers quals) TemplateSpecializationType template, TypeQualifiers quals)
{ {
var decl = template.Template.TemplatedDecl; var decl = template.Template.TemplatedDecl;
TypeMap typeMap = null; TypeMap typeMap = null;
if (TypeMapDatabase.FindTypeMap(template, out typeMap)) if (TypeMapDatabase.FindTypeMap(template, out typeMap))
{ {
typeMap.Declaration = decl; typeMap.Declaration = decl;
typeMap.Type = template; typeMap.Type = template;
Context.Type = template; Context.Type = template;
Context.CSharpKind = ContextKind; Context.CSharpKind = ContextKind;
return new CSharpTypePrinterResult() return new CSharpTypePrinterResult()
{ {
Type = GetCSharpSignature(typeMap), Type = GetCSharpSignature(typeMap),
TypeMap = typeMap TypeMap = typeMap
}; };
} }
return decl.Name; return decl.Name;
} }
private string GetCSharpSignature(TypeMap typeMap) private string GetCSharpSignature(TypeMap typeMap)
{ {
Context.CSharpKind = ContextKind; Context.CSharpKind = ContextKind;
return typeMap.CSharpSignature(Context); return typeMap.CSharpSignature(Context);
} }
public CSharpTypePrinterResult VisitTemplateParameterType( public CSharpTypePrinterResult VisitTemplateParameterType(
TemplateParameterType param, TypeQualifiers quals) TemplateParameterType param, TypeQualifiers quals)
{ {
return param.Parameter.Name; return param.Parameter.Name;
} }
public CSharpTypePrinterResult VisitTemplateParameterSubstitutionType( public CSharpTypePrinterResult VisitTemplateParameterSubstitutionType(
TemplateParameterSubstitutionType param, TypeQualifiers quals) TemplateParameterSubstitutionType param, TypeQualifiers quals)
{ {
var type = param.Replacement.Type; var type = param.Replacement.Type;
return type.Visit(this, param.Replacement.Qualifiers); return type.Visit(this, param.Replacement.Qualifiers);
} }
public CSharpTypePrinterResult VisitInjectedClassNameType( public CSharpTypePrinterResult VisitInjectedClassNameType(
InjectedClassNameType injected, TypeQualifiers quals) InjectedClassNameType injected, TypeQualifiers quals)
{ {
return injected.Class.Name; return injected.Class.Name;
} }
public CSharpTypePrinterResult VisitDependentNameType(DependentNameType dependent, public CSharpTypePrinterResult VisitDependentNameType(DependentNameType dependent,
TypeQualifiers quals) TypeQualifiers quals)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public CSharpTypePrinterResult VisitCILType(CILType type, TypeQualifiers quals) public CSharpTypePrinterResult VisitCILType(CILType type, TypeQualifiers quals)
{ {
return type.Type.FullName; return type.Type.FullName;
} }
public CSharpTypePrinterResult VisitPrimitiveType(PrimitiveType primitive, public CSharpTypePrinterResult VisitPrimitiveType(PrimitiveType primitive,
TypeQualifiers quals) TypeQualifiers quals)
{ {
switch (primitive) switch (primitive)
{ {
case PrimitiveType.Bool: return "bool"; case PrimitiveType.Bool: return "bool";
case PrimitiveType.Void: return "void"; case PrimitiveType.Void: return "void";
case PrimitiveType.WideChar: return "char"; case PrimitiveType.WideChar: return "char";
case PrimitiveType.Int8: return "sbyte"; case PrimitiveType.Int8: return "sbyte";
case PrimitiveType.UInt8: return "byte"; case PrimitiveType.UInt8: return "byte";
case PrimitiveType.Int16: return "short"; case PrimitiveType.Int16: return "short";
case PrimitiveType.UInt16: return "ushort"; case PrimitiveType.UInt16: return "ushort";
case PrimitiveType.Int32: return "int"; case PrimitiveType.Int32: return "int";
case PrimitiveType.UInt32: return "uint"; case PrimitiveType.UInt32: return "uint";
case PrimitiveType.Int64: return "long"; case PrimitiveType.Int64: return "long";
case PrimitiveType.UInt64: return "ulong"; case PrimitiveType.UInt64: return "ulong";
case PrimitiveType.Float: return "float"; case PrimitiveType.Float: return "float";
case PrimitiveType.Double: return "double"; case PrimitiveType.Double: return "double";
case PrimitiveType.IntPtr: return "global::System.IntPtr"; case PrimitiveType.IntPtr: return "global::System.IntPtr";
} }
throw new NotSupportedException(); throw new NotSupportedException();
} }
public CSharpTypePrinterResult VisitDeclaration(Declaration decl, public CSharpTypePrinterResult VisitDeclaration(Declaration decl,
TypeQualifiers quals) TypeQualifiers quals)
{ {
return VisitDeclaration(decl); return VisitDeclaration(decl);
} }
public CSharpTypePrinterResult VisitDeclaration(Declaration decl) public CSharpTypePrinterResult VisitDeclaration(Declaration decl)
{ {
return GetNestedQualifiedName(decl); return GetNestedQualifiedName(decl);
} }
public CSharpTypePrinterResult VisitClassDecl(Class @class) public CSharpTypePrinterResult VisitClassDecl(Class @class)
{ {
if (ContextKind == CSharpTypePrinterContextKind.Native) if (ContextKind == CSharpTypePrinterContextKind.Native)
return string.Format("{0}.Internal", return string.Format("{0}.Internal",
GetNestedQualifiedName(@class.OriginalClass ?? @class)); GetNestedQualifiedName(@class.OriginalClass ?? @class));
return GetNestedQualifiedName(@class); return GetNestedQualifiedName(@class);
} }
public CSharpTypePrinterResult VisitFieldDecl(Field field) public CSharpTypePrinterResult VisitFieldDecl(Field field)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public CSharpTypePrinterResult VisitFunctionDecl(Function function) public CSharpTypePrinterResult VisitFunctionDecl(Function function)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public CSharpTypePrinterResult VisitMethodDecl(Method method) public CSharpTypePrinterResult VisitMethodDecl(Method method)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public CSharpTypePrinterResult VisitParameterDecl(Parameter parameter) public CSharpTypePrinterResult VisitParameterDecl(Parameter parameter)
{ {
var paramType = parameter.Type; var paramType = parameter.Type;
if (parameter.Kind == ParameterKind.IndirectReturnType) if (parameter.Kind == ParameterKind.IndirectReturnType)
return "global::System.IntPtr"; return "global::System.IntPtr";
Context.Parameter = parameter; Context.Parameter = parameter;
var ret = paramType.Visit(this); var ret = paramType.Visit(this);
Context.Parameter = null; Context.Parameter = null;
return ret; return ret;
} }
public CSharpTypePrinterResult VisitTypedefDecl(TypedefDecl typedef) public CSharpTypePrinterResult VisitTypedefDecl(TypedefDecl typedef)
{ {
return GetNestedQualifiedName(typedef); return GetNestedQualifiedName(typedef);
} }
public CSharpTypePrinterResult VisitEnumDecl(Enumeration @enum) public CSharpTypePrinterResult VisitEnumDecl(Enumeration @enum)
{ {
return GetNestedQualifiedName(@enum); return GetNestedQualifiedName(@enum);
} }
static private string GetNestedQualifiedName(Declaration decl) static private string GetNestedQualifiedName(Declaration decl)
{ {
var names = new List<string> { decl.Name }; var names = new List<string> { decl.Name };
var ctx = decl.Namespace; var ctx = decl.Namespace;
while (ctx != null) while (ctx != null)
{ {
if (ctx is TranslationUnit) if (ctx is TranslationUnit)
break; break;
if (!string.IsNullOrWhiteSpace(ctx.Name)) if (!string.IsNullOrWhiteSpace(ctx.Name))
names.Add(ctx.Name); names.Add(ctx.Name);
ctx = ctx.Namespace; ctx = ctx.Namespace;
} }
names.Reverse(); names.Reverse();
return string.Join(".", names); return string.Join(".", names);
} }
public CSharpTypePrinterResult VisitVariableDecl(Variable variable) public CSharpTypePrinterResult VisitVariableDecl(Variable variable)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public CSharpTypePrinterResult VisitClassTemplateDecl(ClassTemplate template) public CSharpTypePrinterResult VisitClassTemplateDecl(ClassTemplate template)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public CSharpTypePrinterResult VisitFunctionTemplateDecl(FunctionTemplate template) public CSharpTypePrinterResult VisitFunctionTemplateDecl(FunctionTemplate template)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public CSharpTypePrinterResult VisitMacroDefinition(MacroDefinition macro) public CSharpTypePrinterResult VisitMacroDefinition(MacroDefinition macro)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public CSharpTypePrinterResult VisitNamespace(Namespace @namespace) public CSharpTypePrinterResult VisitNamespace(Namespace @namespace)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public CSharpTypePrinterResult VisitEvent(Event @event) public CSharpTypePrinterResult VisitEvent(Event @event)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public CSharpTypePrinterResult VisitProperty(Property property) public CSharpTypePrinterResult VisitProperty(Property property)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public CSharpTypePrinterResult VisitParameters(IEnumerable<Parameter> @params, public CSharpTypePrinterResult VisitParameters(IEnumerable<Parameter> @params,
bool hasNames) bool hasNames)
{ {
var args = new List<string>(); var args = new List<string>();
foreach (var param in @params) foreach (var param in @params)
@ -477,58 +477,58 @@ namespace CppSharp.Generators.CSharp
} }
Context.Parameter = null; Context.Parameter = null;
return string.Join(", ", args); return string.Join(", ", args);
} }
public CSharpTypePrinterResult VisitParameter(Parameter arg, bool hasName) public CSharpTypePrinterResult VisitParameter(Parameter arg, bool hasName)
{ {
var type = arg.Type.Visit(this, arg.QualifiedType.Qualifiers); var type = arg.Type.Visit(this, arg.QualifiedType.Qualifiers);
var name = Helpers.SafeIdentifier(arg.Name); var name = Helpers.SafeIdentifier(arg.Name);
if (hasName && !string.IsNullOrEmpty(name)) if (hasName && !string.IsNullOrEmpty(name))
return string.Format("{0} {1}", type, name); return string.Format("{0} {1}", type, name);
return type; return type;
} }
public CSharpTypePrinterResult VisitDelegate(FunctionType function) public CSharpTypePrinterResult VisitDelegate(FunctionType function)
{ {
return string.Format("delegate {0} {{0}}({1})", return string.Format("delegate {0} {{0}}({1})",
function.ReturnType.Visit(this), function.ReturnType.Visit(this),
VisitParameters(function.Parameters, hasNames: true)); VisitParameters(function.Parameters, hasNames: true));
} }
public string ToString(Type type) public string ToString(Type type)
{ {
return type.Visit(this).Type; return type.Visit(this).Type;
} }
} }
public static class CSharpTypePrinterExtensions public static class CSharpTypePrinterExtensions
{ {
public static CSharpTypePrinterResult CSharpType(this QualifiedType type, public static CSharpTypePrinterResult CSharpType(this QualifiedType type,
CSharpTypePrinter printer) CSharpTypePrinter printer)
{ {
printer.Context.FullType = type; printer.Context.FullType = type;
return type.Visit(printer); return type.Visit(printer);
} }
public static CSharpTypePrinterResult CSharpType(this Type type, public static CSharpTypePrinterResult CSharpType(this Type type,
CSharpTypePrinter printer) CSharpTypePrinter printer)
{ {
return CSharpType(new QualifiedType(type), printer); return CSharpType(new QualifiedType(type), printer);
} }
public static CSharpTypePrinterResult CSharpType(this Declaration decl, public static CSharpTypePrinterResult CSharpType(this Declaration decl,
CSharpTypePrinter printer) CSharpTypePrinter printer)
{ {
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.Context.FullType = type;
} }
return decl.Visit(printer); return decl.Visit(printer);
} }
} }
} }
Loading…
Cancel
Save