Browse Source

Added support for scope kinds in `CSharpTypePrinter`.

pull/1177/head
Joao Matos 7 years ago committed by João Matos
parent
commit
86898121af
  1. 14
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs
  2. 3
      src/Generator/Generators/TypePrinter.cs

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

@ -13,7 +13,7 @@ namespace CppSharp.Generators.CSharp
{ {
public class CSharpTypePrinter : TypePrinter public class CSharpTypePrinter : TypePrinter
{ {
public string IntPtrType => "global::System.IntPtr"; public string IntPtrType => QualifiedType("System.IntPtr");
public BindingContext Context { get; set; } public BindingContext Context { get; set; }
@ -25,6 +25,11 @@ namespace CppSharp.Generators.CSharp
Context = context; Context = context;
} }
public string QualifiedType(string name)
{
return IsGlobalQualifiedScope ? $"global::{name}" : name;
}
public override TypePrinterResult VisitTagType(TagType tag, TypeQualifiers quals) public override TypePrinterResult VisitTagType(TagType tag, TypeQualifiers quals)
{ {
if (tag.Declaration == null) if (tag.Declaration == null)
@ -429,7 +434,8 @@ namespace CppSharp.Generators.CSharp
case TypeCode.String: case TypeCode.String:
return "string"; return "string";
} }
return $"global::{type.Type.FullName}";
return QualifiedType(type.Type.FullName);
} }
public static void GetPrimitiveTypeWidth(PrimitiveType primitive, public static void GetPrimitiveTypeWidth(PrimitiveType primitive,
@ -545,7 +551,7 @@ namespace CppSharp.Generators.CSharp
case PrimitiveType.LongDouble: return new TypePrinterResult { Type = "fixed byte", case PrimitiveType.LongDouble: return new TypePrinterResult { Type = "fixed byte",
NameSuffix = $"[{Context.TargetInfo.LongDoubleWidth}]"}; NameSuffix = $"[{Context.TargetInfo.LongDoubleWidth}]"};
case PrimitiveType.IntPtr: return IntPtrType; case PrimitiveType.IntPtr: return IntPtrType;
case PrimitiveType.UIntPtr: return "global::System.UIntPtr"; case PrimitiveType.UIntPtr: return QualifiedType("System.UIntPtr");
case PrimitiveType.Null: return "void*"; case PrimitiveType.Null: return "void*";
case PrimitiveType.String: return "string"; case PrimitiveType.String: return "string";
case PrimitiveType.Float128: return "__float128"; case PrimitiveType.Float128: return "__float128";
@ -645,7 +651,7 @@ namespace CppSharp.Generators.CSharp
!string.IsNullOrWhiteSpace(unit.Module.OutputNamespace)) !string.IsNullOrWhiteSpace(unit.Module.OutputNamespace))
names.Push(unit.Module.OutputNamespace); names.Push(unit.Module.OutputNamespace);
return $"global::{string.Join(".", names)}"; return QualifiedType(string.Join(".", names));
} }
public override TypePrinterResult VisitParameters(IEnumerable<Parameter> @params, public override TypePrinterResult VisitParameters(IEnumerable<Parameter> @params,

3
src/Generator/Generators/TypePrinter.cs

@ -34,6 +34,9 @@ namespace CppSharp.Generators
public MarshalKind MarshalKind => marshalKinds.Peek(); public MarshalKind MarshalKind => marshalKinds.Peek();
public TypePrintScopeKind ScopeKind = TypePrintScopeKind.GlobalQualified;
public bool IsGlobalQualifiedScope => ScopeKind == TypePrintScopeKind.GlobalQualified;
public TypePrinter() public TypePrinter()
{ {
contexts = new Stack<TypePrinterContextKind>(); contexts = new Stack<TypePrinterContextKind>();

Loading…
Cancel
Save