Browse Source

Removed redundant qualification of types in the generated C#.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/761/head
Dimitar Dobrev 8 years ago
parent
commit
7ad1af0cac
  1. 16
      src/AST/CppTypePrinter.cs
  2. 2
      src/AST/Type.cs
  3. 786
      src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/CppSharp.CppParser.cs
  4. 22
      src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/Std.cs
  5. 786
      src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/CppSharp.CppParser.cs
  6. 29
      src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/Std.cs
  7. 786
      src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/CppSharp.CppParser.cs
  8. 22
      src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/Std.cs
  9. 786
      src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/CppSharp.CppParser.cs
  10. 31
      src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/Std.cs
  11. 786
      src/CppParser/Bindings/CSharp/x86_64-linux-gnu/CppSharp.CppParser.cs
  12. 31
      src/CppParser/Bindings/CSharp/x86_64-linux-gnu/Std.cs
  13. 786
      src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/CppSharp.CppParser.cs
  14. 29
      src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/Std.cs
  15. 6
      src/Generator.Tests/AST/TestAST.cs
  16. 14
      src/Generator/Generators/CSharp/CSharpSources.cs
  17. 49
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs
  18. 3
      src/Generator/Passes/DelegatesPass.cs
  19. 2
      src/Generator/Passes/GenerateTemplatesCodePass.cs
  20. 1
      src/Generator/Passes/GetterSetterToPropertyPass.cs
  21. 2
      src/Generator/Passes/InlinesCodeGenerator.cs
  22. 6
      src/Generator/Types/TypeMap.cs

16
src/AST/CppTypePrinter.cs

@ -12,7 +12,7 @@ namespace CppSharp.AST @@ -12,7 +12,7 @@ namespace CppSharp.AST
ObjC
}
public enum CppTypePrintScopeKind
public enum TypePrintScopeKind
{
Local,
Qualified,
@ -22,7 +22,7 @@ namespace CppSharp.AST @@ -22,7 +22,7 @@ namespace CppSharp.AST
public class CppTypePrinter : ITypePrinter<string>, IDeclVisitor<string>
{
public CppTypePrintFlavorKind PrintFlavorKind { get; set; }
public CppTypePrintScopeKind PrintScopeKind { get; set; }
public TypePrintScopeKind PrintScopeKind { get; set; }
public bool PrintLogicalNames { get; set; }
public bool PrintTypeQualifiers { get; set; }
public bool PrintTypeModifiers { get; set; }
@ -31,7 +31,7 @@ namespace CppSharp.AST @@ -31,7 +31,7 @@ namespace CppSharp.AST
public CppTypePrinter()
{
PrintFlavorKind = CppTypePrintFlavorKind.Cpp;
PrintScopeKind = CppTypePrintScopeKind.GlobalQualified;
PrintScopeKind = TypePrintScopeKind.GlobalQualified;
PrintTypeQualifiers = true;
PrintTypeModifiers = true;
}
@ -293,19 +293,19 @@ namespace CppSharp.AST @@ -293,19 +293,19 @@ namespace CppSharp.AST
throw new System.NotImplementedException();
}
public virtual string GetDeclName(Declaration declaration, CppTypePrintScopeKind scope)
public virtual string GetDeclName(Declaration declaration, TypePrintScopeKind scope)
{
switch (scope)
{
case CppTypePrintScopeKind.Local:
case TypePrintScopeKind.Local:
return PrintLogicalNames ? declaration.LogicalOriginalName
: declaration.OriginalName;
case CppTypePrintScopeKind.Qualified:
case TypePrintScopeKind.Qualified:
return PrintLogicalNames ? declaration.QualifiedLogicalOriginalName
: declaration.QualifiedOriginalName;
case CppTypePrintScopeKind.GlobalQualified:
case TypePrintScopeKind.GlobalQualified:
var qualifier = PrintFlavorKind == CppTypePrintFlavorKind.Cpp ? "::" : string.Empty;
return qualifier + GetDeclName(declaration, CppTypePrintScopeKind.Qualified);
return qualifier + GetDeclName(declaration, TypePrintScopeKind.Qualified);
}
throw new NotSupportedException();

2
src/AST/Type.cs

@ -28,7 +28,7 @@ namespace CppSharp.AST @@ -28,7 +28,7 @@ namespace CppSharp.AST
public string ToNativeString()
{
var cppTypePrinter = new CppTypePrinter { PrintScopeKind = CppTypePrintScopeKind.Qualified };
var cppTypePrinter = new CppTypePrinter { PrintScopeKind = TypePrintScopeKind.Qualified };
return Visit(cppTypePrinter);
}

786
src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/CppSharp.CppParser.cs

File diff suppressed because it is too large Load Diff

22
src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/Std.cs

@ -171,19 +171,19 @@ namespace Std @@ -171,19 +171,19 @@ namespace Std
return new Allocator(native.ToPointer(), skipVTables);
}
internal static Allocator __CreateInstance(Allocator.__Internal native, bool skipVTables = false)
internal static Allocator __CreateInstance(__Internal native, bool skipVTables = false)
{
return new Allocator(native, skipVTables);
}
private static void* __CopyValue(Allocator.__Internal native)
private static void* __CopyValue(__Internal native)
{
var ret = Marshal.AllocHGlobal(0);
*(Allocator.__Internal*) ret = native;
*(__Internal*) ret = native;
return ret.ToPointer();
}
private Allocator(Allocator.__Internal native, bool skipVTables = false)
private Allocator(__Internal native, bool skipVTables = false)
: this(__CopyValue(native), skipVTables)
{
__ownsNativeInstance = true;
@ -202,7 +202,7 @@ namespace Std @@ -202,7 +202,7 @@ namespace Std
__Instance = Marshal.AllocHGlobal(0);
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
__Internal.ctor_0((__Instance + __PointerAdjustment));
global::Std.__1.Allocator.__Internal.ctor_0((__Instance + __PointerAdjustment));
}
public void Dispose()
@ -1409,19 +1409,19 @@ namespace Std @@ -1409,19 +1409,19 @@ namespace Std
return new BasicString(native.ToPointer(), skipVTables);
}
internal static BasicString __CreateInstance(BasicString.__Internal native, bool skipVTables = false)
internal static BasicString __CreateInstance(__Internal native, bool skipVTables = false)
{
return new BasicString(native, skipVTables);
}
private static void* __CopyValue(BasicString.__Internal native)
private static void* __CopyValue(__Internal native)
{
var ret = Marshal.AllocHGlobal(12);
*(BasicString.__Internal*) ret = native;
*(__Internal*) ret = native;
return ret.ToPointer();
}
private BasicString(BasicString.__Internal native, bool skipVTables = false)
private BasicString(__Internal native, bool skipVTables = false)
: this(__CopyValue(native), skipVTables)
{
__ownsNativeInstance = true;
@ -1445,7 +1445,7 @@ namespace Std @@ -1445,7 +1445,7 @@ namespace Std
global::Std.__1.BasicString __dummy;
NativeToManagedMap.TryRemove(__Instance, out __dummy);
if (disposing)
__Internal.dtor_0((__Instance + __PointerAdjustment));
global::Std.__1.BasicString.__Internal.dtor_0((__Instance + __PointerAdjustment));
if (__ownsNativeInstance)
Marshal.FreeHGlobal(__Instance);
}
@ -1454,7 +1454,7 @@ namespace Std @@ -1454,7 +1454,7 @@ namespace Std
{
get
{
var __ret = __Internal.CStr_0((__Instance + __PointerAdjustment));
var __ret = global::Std.__1.BasicString.__Internal.CStr_0((__Instance + __PointerAdjustment));
return Marshal.PtrToStringAnsi(__ret);
}
}

786
src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/CppSharp.CppParser.cs

File diff suppressed because it is too large Load Diff

29
src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/Std.cs

@ -415,19 +415,19 @@ namespace Std @@ -415,19 +415,19 @@ namespace Std
return new Allocator(native.ToPointer(), skipVTables);
}
internal static Allocator __CreateInstance(Allocator.__Internal native, bool skipVTables = false)
internal static Allocator __CreateInstance(__Internal native, bool skipVTables = false)
{
return new Allocator(native, skipVTables);
}
private static void* __CopyValue(Allocator.__Internal native)
private static void* __CopyValue(__Internal native)
{
var ret = Marshal.AllocHGlobal(0);
*(Allocator.__Internal*) ret = native;
*(__Internal*) ret = native;
return ret.ToPointer();
}
private Allocator(Allocator.__Internal native, bool skipVTables = false)
private Allocator(__Internal native, bool skipVTables = false)
: this(__CopyValue(native), skipVTables)
{
__ownsNativeInstance = true;
@ -446,7 +446,7 @@ namespace Std @@ -446,7 +446,7 @@ namespace Std
__Instance = Marshal.AllocHGlobal(0);
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
__Internal.ctor_0((__Instance + __PointerAdjustment));
global::Std.Allocator.__Internal.ctor_0((__Instance + __PointerAdjustment));
}
public void Dispose()
@ -511,19 +511,19 @@ namespace Std @@ -511,19 +511,19 @@ namespace Std
return new BasicString(native.ToPointer(), skipVTables);
}
internal static BasicString __CreateInstance(BasicString.__Internal native, bool skipVTables = false)
internal static BasicString __CreateInstance(__Internal native, bool skipVTables = false)
{
return new BasicString(native, skipVTables);
}
private static void* __CopyValue(BasicString.__Internal native)
private static void* __CopyValue(__Internal native)
{
var ret = Marshal.AllocHGlobal(24);
*(BasicString.__Internal*) ret = native;
*(__Internal*) ret = native;
return ret.ToPointer();
}
private BasicString(BasicString.__Internal native, bool skipVTables = false)
private BasicString(__Internal native, bool skipVTables = false)
: this(__CopyValue(native), skipVTables)
{
__ownsNativeInstance = true;
@ -547,15 +547,18 @@ namespace Std @@ -547,15 +547,18 @@ namespace Std
global::Std.BasicString __dummy;
NativeToManagedMap.TryRemove(__Instance, out __dummy);
if (disposing)
__Internal.dtor_0((__Instance + __PointerAdjustment), 0);
global::Std.BasicString.__Internal.dtor_0((__Instance + __PointerAdjustment), 0);
if (__ownsNativeInstance)
Marshal.FreeHGlobal(__Instance);
}
public string CStr()
public string CStr
{
var __ret = __Internal.CStr_0((__Instance + __PointerAdjustment));
return Marshal.PtrToStringAnsi(__ret);
get
{
var __ret = global::Std.BasicString.__Internal.CStr_0((__Instance + __PointerAdjustment));
return Marshal.PtrToStringAnsi(__ret);
}
}
}

786
src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/CppSharp.CppParser.cs

File diff suppressed because it is too large Load Diff

22
src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/Std.cs

@ -171,19 +171,19 @@ namespace Std @@ -171,19 +171,19 @@ namespace Std
return new Allocator(native.ToPointer(), skipVTables);
}
internal static Allocator __CreateInstance(Allocator.__Internal native, bool skipVTables = false)
internal static Allocator __CreateInstance(__Internal native, bool skipVTables = false)
{
return new Allocator(native, skipVTables);
}
private static void* __CopyValue(Allocator.__Internal native)
private static void* __CopyValue(__Internal native)
{
var ret = Marshal.AllocHGlobal(0);
*(Allocator.__Internal*) ret = native;
*(__Internal*) ret = native;
return ret.ToPointer();
}
private Allocator(Allocator.__Internal native, bool skipVTables = false)
private Allocator(__Internal native, bool skipVTables = false)
: this(__CopyValue(native), skipVTables)
{
__ownsNativeInstance = true;
@ -202,7 +202,7 @@ namespace Std @@ -202,7 +202,7 @@ namespace Std
__Instance = Marshal.AllocHGlobal(0);
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
__Internal.ctor_0((__Instance + __PointerAdjustment));
global::Std.__1.Allocator.__Internal.ctor_0((__Instance + __PointerAdjustment));
}
public void Dispose()
@ -1409,19 +1409,19 @@ namespace Std @@ -1409,19 +1409,19 @@ namespace Std
return new BasicString(native.ToPointer(), skipVTables);
}
internal static BasicString __CreateInstance(BasicString.__Internal native, bool skipVTables = false)
internal static BasicString __CreateInstance(__Internal native, bool skipVTables = false)
{
return new BasicString(native, skipVTables);
}
private static void* __CopyValue(BasicString.__Internal native)
private static void* __CopyValue(__Internal native)
{
var ret = Marshal.AllocHGlobal(24);
*(BasicString.__Internal*) ret = native;
*(__Internal*) ret = native;
return ret.ToPointer();
}
private BasicString(BasicString.__Internal native, bool skipVTables = false)
private BasicString(__Internal native, bool skipVTables = false)
: this(__CopyValue(native), skipVTables)
{
__ownsNativeInstance = true;
@ -1445,7 +1445,7 @@ namespace Std @@ -1445,7 +1445,7 @@ namespace Std
global::Std.__1.BasicString __dummy;
NativeToManagedMap.TryRemove(__Instance, out __dummy);
if (disposing)
__Internal.dtor_0((__Instance + __PointerAdjustment));
global::Std.__1.BasicString.__Internal.dtor_0((__Instance + __PointerAdjustment));
if (__ownsNativeInstance)
Marshal.FreeHGlobal(__Instance);
}
@ -1454,7 +1454,7 @@ namespace Std @@ -1454,7 +1454,7 @@ namespace Std
{
get
{
var __ret = __Internal.CStr_0((__Instance + __PointerAdjustment));
var __ret = global::Std.__1.BasicString.__Internal.CStr_0((__Instance + __PointerAdjustment));
return Marshal.PtrToStringAnsi(__ret);
}
}

786
src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/CppSharp.CppParser.cs

File diff suppressed because it is too large Load Diff

31
src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/Std.cs

@ -68,19 +68,19 @@ namespace Std @@ -68,19 +68,19 @@ namespace Std
return new Allocator(native.ToPointer(), skipVTables);
}
internal static Allocator __CreateInstance(Allocator.__Internal native, bool skipVTables = false)
internal static Allocator __CreateInstance(__Internal native, bool skipVTables = false)
{
return new Allocator(native, skipVTables);
}
private static void* __CopyValue(Allocator.__Internal native)
private static void* __CopyValue(__Internal native)
{
var ret = Marshal.AllocHGlobal(0);
*(Allocator.__Internal*) ret = native;
*(__Internal*) ret = native;
return ret.ToPointer();
}
private Allocator(Allocator.__Internal native, bool skipVTables = false)
private Allocator(__Internal native, bool skipVTables = false)
: this(__CopyValue(native), skipVTables)
{
__ownsNativeInstance = true;
@ -99,7 +99,7 @@ namespace Std @@ -99,7 +99,7 @@ namespace Std
__Instance = Marshal.AllocHGlobal(0);
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
__Internal.ctor_0((__Instance + __PointerAdjustment));
global::Std.Allocator.__Internal.ctor_0((__Instance + __PointerAdjustment));
}
public void Dispose()
@ -112,7 +112,7 @@ namespace Std @@ -112,7 +112,7 @@ namespace Std
global::Std.Allocator __dummy;
NativeToManagedMap.TryRemove(__Instance, out __dummy);
if (disposing)
__Internal.dtor_0((__Instance + __PointerAdjustment));
global::Std.Allocator.__Internal.dtor_0((__Instance + __PointerAdjustment));
if (__ownsNativeInstance)
Marshal.FreeHGlobal(__Instance);
}
@ -628,19 +628,19 @@ namespace Std @@ -628,19 +628,19 @@ namespace Std
return new BasicString(native.ToPointer(), skipVTables);
}
internal static BasicString __CreateInstance(BasicString.__Internal native, bool skipVTables = false)
internal static BasicString __CreateInstance(__Internal native, bool skipVTables = false)
{
return new BasicString(native, skipVTables);
}
private static void* __CopyValue(BasicString.__Internal native)
private static void* __CopyValue(__Internal native)
{
var ret = Marshal.AllocHGlobal(32);
*(BasicString.__Internal*) ret = native;
*(__Internal*) ret = native;
return ret.ToPointer();
}
private BasicString(BasicString.__Internal native, bool skipVTables = false)
private BasicString(__Internal native, bool skipVTables = false)
: this(__CopyValue(native), skipVTables)
{
__ownsNativeInstance = true;
@ -664,15 +664,18 @@ namespace Std @@ -664,15 +664,18 @@ namespace Std
global::Std.Cxx11.BasicString __dummy;
NativeToManagedMap.TryRemove(__Instance, out __dummy);
if (disposing)
__Internal.dtor_0((__Instance + __PointerAdjustment));
global::Std.Cxx11.BasicString.__Internal.dtor_0((__Instance + __PointerAdjustment));
if (__ownsNativeInstance)
Marshal.FreeHGlobal(__Instance);
}
public string CStr()
public string CStr
{
var __ret = __Internal.CStr_0((__Instance + __PointerAdjustment));
return Marshal.PtrToStringAnsi(__ret);
get
{
var __ret = global::Std.Cxx11.BasicString.__Internal.CStr_0((__Instance + __PointerAdjustment));
return Marshal.PtrToStringAnsi(__ret);
}
}
}

786
src/CppParser/Bindings/CSharp/x86_64-linux-gnu/CppSharp.CppParser.cs

File diff suppressed because it is too large Load Diff

31
src/CppParser/Bindings/CSharp/x86_64-linux-gnu/Std.cs

@ -68,19 +68,19 @@ namespace Std @@ -68,19 +68,19 @@ namespace Std
return new Allocator(native.ToPointer(), skipVTables);
}
internal static Allocator __CreateInstance(Allocator.__Internal native, bool skipVTables = false)
internal static Allocator __CreateInstance(__Internal native, bool skipVTables = false)
{
return new Allocator(native, skipVTables);
}
private static void* __CopyValue(Allocator.__Internal native)
private static void* __CopyValue(__Internal native)
{
var ret = Marshal.AllocHGlobal(0);
*(Allocator.__Internal*) ret = native;
*(__Internal*) ret = native;
return ret.ToPointer();
}
private Allocator(Allocator.__Internal native, bool skipVTables = false)
private Allocator(__Internal native, bool skipVTables = false)
: this(__CopyValue(native), skipVTables)
{
__ownsNativeInstance = true;
@ -99,7 +99,7 @@ namespace Std @@ -99,7 +99,7 @@ namespace Std
__Instance = Marshal.AllocHGlobal(0);
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
__Internal.ctor_0((__Instance + __PointerAdjustment));
global::Std.Allocator.__Internal.ctor_0((__Instance + __PointerAdjustment));
}
public void Dispose()
@ -112,7 +112,7 @@ namespace Std @@ -112,7 +112,7 @@ namespace Std
global::Std.Allocator __dummy;
NativeToManagedMap.TryRemove(__Instance, out __dummy);
if (disposing)
__Internal.dtor_0((__Instance + __PointerAdjustment));
global::Std.Allocator.__Internal.dtor_0((__Instance + __PointerAdjustment));
if (__ownsNativeInstance)
Marshal.FreeHGlobal(__Instance);
}
@ -619,19 +619,19 @@ namespace Std @@ -619,19 +619,19 @@ namespace Std
return new BasicString(native.ToPointer(), skipVTables);
}
internal static BasicString __CreateInstance(BasicString.__Internal native, bool skipVTables = false)
internal static BasicString __CreateInstance(__Internal native, bool skipVTables = false)
{
return new BasicString(native, skipVTables);
}
private static void* __CopyValue(BasicString.__Internal native)
private static void* __CopyValue(__Internal native)
{
var ret = Marshal.AllocHGlobal(8);
*(BasicString.__Internal*) ret = native;
*(__Internal*) ret = native;
return ret.ToPointer();
}
private BasicString(BasicString.__Internal native, bool skipVTables = false)
private BasicString(__Internal native, bool skipVTables = false)
: this(__CopyValue(native), skipVTables)
{
__ownsNativeInstance = true;
@ -655,15 +655,18 @@ namespace Std @@ -655,15 +655,18 @@ namespace Std
global::Std.BasicString __dummy;
NativeToManagedMap.TryRemove(__Instance, out __dummy);
if (disposing)
__Internal.dtor_0((__Instance + __PointerAdjustment));
global::Std.BasicString.__Internal.dtor_0((__Instance + __PointerAdjustment));
if (__ownsNativeInstance)
Marshal.FreeHGlobal(__Instance);
}
public string CStr()
public string CStr
{
var __ret = __Internal.CStr_0((__Instance + __PointerAdjustment));
return Marshal.PtrToStringAnsi(__ret);
get
{
var __ret = global::Std.BasicString.__Internal.CStr_0((__Instance + __PointerAdjustment));
return Marshal.PtrToStringAnsi(__ret);
}
}
}

786
src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/CppSharp.CppParser.cs

File diff suppressed because it is too large Load Diff

29
src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/Std.cs

@ -415,19 +415,19 @@ namespace Std @@ -415,19 +415,19 @@ namespace Std
return new Allocator(native.ToPointer(), skipVTables);
}
internal static Allocator __CreateInstance(Allocator.__Internal native, bool skipVTables = false)
internal static Allocator __CreateInstance(__Internal native, bool skipVTables = false)
{
return new Allocator(native, skipVTables);
}
private static void* __CopyValue(Allocator.__Internal native)
private static void* __CopyValue(__Internal native)
{
var ret = Marshal.AllocHGlobal(0);
*(Allocator.__Internal*) ret = native;
*(__Internal*) ret = native;
return ret.ToPointer();
}
private Allocator(Allocator.__Internal native, bool skipVTables = false)
private Allocator(__Internal native, bool skipVTables = false)
: this(__CopyValue(native), skipVTables)
{
__ownsNativeInstance = true;
@ -446,7 +446,7 @@ namespace Std @@ -446,7 +446,7 @@ namespace Std
__Instance = Marshal.AllocHGlobal(0);
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
__Internal.ctor_0((__Instance + __PointerAdjustment));
global::Std.Allocator.__Internal.ctor_0((__Instance + __PointerAdjustment));
}
public void Dispose()
@ -521,19 +521,19 @@ namespace Std @@ -521,19 +521,19 @@ namespace Std
return new BasicString(native.ToPointer(), skipVTables);
}
internal static BasicString __CreateInstance(BasicString.__Internal native, bool skipVTables = false)
internal static BasicString __CreateInstance(__Internal native, bool skipVTables = false)
{
return new BasicString(native, skipVTables);
}
private static void* __CopyValue(BasicString.__Internal native)
private static void* __CopyValue(__Internal native)
{
var ret = Marshal.AllocHGlobal(32);
*(BasicString.__Internal*) ret = native;
*(__Internal*) ret = native;
return ret.ToPointer();
}
private BasicString(BasicString.__Internal native, bool skipVTables = false)
private BasicString(__Internal native, bool skipVTables = false)
: this(__CopyValue(native), skipVTables)
{
__ownsNativeInstance = true;
@ -557,15 +557,18 @@ namespace Std @@ -557,15 +557,18 @@ namespace Std
global::Std.BasicString __dummy;
NativeToManagedMap.TryRemove(__Instance, out __dummy);
if (disposing)
__Internal.dtor_0((__Instance + __PointerAdjustment), 0);
global::Std.BasicString.__Internal.dtor_0((__Instance + __PointerAdjustment), 0);
if (__ownsNativeInstance)
Marshal.FreeHGlobal(__Instance);
}
public string CStr()
public string CStr
{
var __ret = __Internal.CStr_0((__Instance + __PointerAdjustment));
return Marshal.PtrToStringAnsi(__ret);
get
{
var __ret = global::Std.BasicString.__Internal.CStr_0((__Instance + __PointerAdjustment));
return Marshal.PtrToStringAnsi(__ret);
}
}
}

6
src/Generator.Tests/AST/TestAST.cs

@ -420,7 +420,7 @@ namespace CppSharp.Generator.Tests.AST @@ -420,7 +420,7 @@ namespace CppSharp.Generator.Tests.AST
[Test]
public void TestPrintingConstPointerWithConstType()
{
var cppTypePrinter = new CppTypePrinter { PrintScopeKind = CppTypePrintScopeKind.Qualified };
var cppTypePrinter = new CppTypePrinter { PrintScopeKind = TypePrintScopeKind.Qualified };
var builtin = new BuiltinType(PrimitiveType.Char);
var pointee = new QualifiedType(builtin, new TypeQualifiers { IsConst = true });
var pointer = new QualifiedType(new PointerType(pointee), new TypeQualifiers { IsConst = true });
@ -432,7 +432,7 @@ namespace CppSharp.Generator.Tests.AST @@ -432,7 +432,7 @@ namespace CppSharp.Generator.Tests.AST
public void TestPrintingSpecializationWithConstValue()
{
var template = AstContext.FindDecl<ClassTemplate>("TestSpecializationArguments").First();
var cppTypePrinter = new CppTypePrinter { PrintScopeKind = CppTypePrintScopeKind.Qualified };
var cppTypePrinter = new CppTypePrinter { PrintScopeKind = TypePrintScopeKind.Qualified };
Assert.That(template.Specializations.Last().Visit(cppTypePrinter),
Is.EqualTo("TestSpecializationArguments<const TestASTEnumItemByName>"));
}
@ -474,7 +474,7 @@ namespace CppSharp.Generator.Tests.AST @@ -474,7 +474,7 @@ namespace CppSharp.Generator.Tests.AST
[Test]
public void TestVolatile()
{
var cppTypePrinter = new CppTypePrinter { PrintScopeKind = CppTypePrintScopeKind.Qualified };
var cppTypePrinter = new CppTypePrinter { PrintScopeKind = TypePrintScopeKind.Qualified };
var builtin = new BuiltinType(PrimitiveType.Char);
var pointee = new QualifiedType(builtin, new TypeQualifiers { IsConst = true, IsVolatile = true });
var type = pointee.Visit(cppTypePrinter);

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

@ -447,7 +447,7 @@ namespace CppSharp.Generators.CSharp @@ -447,7 +447,7 @@ namespace CppSharp.Generators.CSharp
System.Type typeMap = null;
string key = string.Empty;
var cppTypePrinter = new CppTypePrinter { PrintScopeKind = CppTypePrintScopeKind.Qualified };
var cppTypePrinter = new CppTypePrinter { PrintScopeKind = TypePrintScopeKind.Qualified };
foreach (var name in new[] { @class.OriginalName, @class.Visit(cppTypePrinter) })
{
if (Context.TypeMaps.TypeMaps.ContainsKey(name))
@ -501,8 +501,10 @@ namespace CppSharp.Generators.CSharp @@ -501,8 +501,10 @@ namespace CppSharp.Generators.CSharp
// use interfaces if any - derived types with a secondary base this class must be compatible with the map
var @interface = @class.Namespace.Classes.Find(c => c.OriginalClass == @class);
TypePrinter.PushPrintScopeKind(TypePrintScopeKind.Local);
var dict = string.Format("global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, {0}>",
(@interface ?? @class).Visit(TypePrinter));
TypePrinter.PopPrintScopeKind();
WriteLine("internal static readonly {0} NativeToManagedMap = new {0}();", dict);
WriteLine("protected void*[] __OriginalVTables;");
}
@ -906,6 +908,7 @@ namespace CppSharp.Generators.CSharp @@ -906,6 +908,7 @@ namespace CppSharp.Generators.CSharp
var arrayType = field.Type as ArrayType;
TypePrinter.PushPrintScopeKind(TypePrintScopeKind.Local);
if (arrayType != null && @class.IsValueType)
{
ctx.ReturnVarName = HandleValueArray(arrayType, field);
@ -919,6 +922,7 @@ namespace CppSharp.Generators.CSharp @@ -919,6 +922,7 @@ namespace CppSharp.Generators.CSharp
(@class.IsValueType ? "." : "->")}{Helpers.SafeIdentifier(name)}";
TypePrinter.PopContext();
}
TypePrinter.PopPrintScopeKind();
param.Visit(marshal);
if (!string.IsNullOrWhiteSpace(marshal.Context.SupportBefore))
@ -1113,6 +1117,7 @@ namespace CppSharp.Generators.CSharp @@ -1113,6 +1117,7 @@ namespace CppSharp.Generators.CSharp
var name = @class.Layout.Fields.First(f => f.FieldPtr == field.OriginalPtr).Name;
TypePrinter.PushContext(CSharpTypePrinterContextKind.Native);
TypePrinter.PushPrintScopeKind(TypePrintScopeKind.Local);
var ctx = new CSharpMarshalContext(Context)
{
Kind = CSharpMarshalKind.NativeField,
@ -1123,6 +1128,7 @@ namespace CppSharp.Generators.CSharp @@ -1123,6 +1128,7 @@ namespace CppSharp.Generators.CSharp
(@class.IsValueType ? "." : "->")}{Helpers.SafeIdentifier(name)}",
ReturnType = decl.QualifiedType
};
TypePrinter.PopPrintScopeKind();
TypePrinter.PopContext();
var arrayType = field.Type as ArrayType;
@ -2045,6 +2051,7 @@ namespace CppSharp.Generators.CSharp @@ -2045,6 +2051,7 @@ namespace CppSharp.Generators.CSharp
var className = @class.IsAbstractImpl ? @class.BaseClass.Name : @class.Name;
TypePrinter.PushPrintScopeKind(TypePrintScopeKind.Local);
var ctorCall = string.Format("{0}{1}", @class.Name, @class.IsAbstract ? "Internal" : "");
if (!@class.IsAbstractImpl)
{
@ -2110,6 +2117,7 @@ namespace CppSharp.Generators.CSharp @@ -2110,6 +2117,7 @@ namespace CppSharp.Generators.CSharp
WriteLine($"{Helpers.InstanceField} = *({@class.Visit(TypePrinter)}*) native;");
TypePrinter.PopContext();
}
TypePrinter.PopPrintScopeKind();
WriteCloseBraceIndent();
PopBlock(NewLineKind.BeforeNextBlock);
@ -2117,6 +2125,7 @@ namespace CppSharp.Generators.CSharp @@ -2117,6 +2125,7 @@ namespace CppSharp.Generators.CSharp
private void GenerateNativeConstructorByValue(Class @class, string ctorCall)
{
TypePrinter.PushPrintScopeKind(TypePrintScopeKind.Local);
TypePrinter.PushContext(CSharpTypePrinterContextKind.Native);
var @internal = (@class.IsAbstractImpl ? @class.BaseClass : @class).Visit(TypePrinter);
TypePrinter.PopContext();
@ -2179,6 +2188,7 @@ namespace CppSharp.Generators.CSharp @@ -2179,6 +2188,7 @@ namespace CppSharp.Generators.CSharp
WriteCloseBraceIndent();
PopBlock(NewLineKind.BeforeNextBlock);
}
TypePrinter.PopPrintScopeKind();
}
private void GenerateClassConstructorBase(Class @class, Method method)
@ -2617,8 +2627,10 @@ namespace CppSharp.Generators.CSharp @@ -2617,8 +2627,10 @@ namespace CppSharp.Generators.CSharp
else
{
TypePrinter.PushContext(CSharpTypePrinterContextKind.Native);
TypePrinter.PushPrintScopeKind(TypePrintScopeKind.Local);
var classInternal = @class.Visit(TypePrinter);
TypePrinter.PopContext();
TypePrinter.PopPrintScopeKind();
WriteLine($@"*(({classInternal}*) {Helpers.InstanceIdentifier}) = *(({
classInternal}*) {method.Parameters[0].Name}.{Helpers.InstanceIdentifier});");
}

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

@ -42,15 +42,16 @@ namespace CppSharp.Generators.CSharp @@ -42,15 +42,16 @@ namespace CppSharp.Generators.CSharp
{
public const string IntPtrType = "global::System.IntPtr";
public bool FullyQualify { get; set; } = true;
private readonly Stack<CSharpTypePrinterContextKind> contexts;
private readonly Stack<CSharpMarshalKind> marshalKinds;
private readonly Stack<TypePrintScopeKind> printScopeKinds;
public CSharpTypePrinterContextKind ContextKind => contexts.Peek();
public CSharpMarshalKind MarshalKind => marshalKinds.Peek();
public TypePrintScopeKind PrintScopeKind => printScopeKinds.Peek();
public CSharpTypePrinterContext TypePrinterContext;
public BindingContext Context { get; set; }
@ -63,8 +64,10 @@ namespace CppSharp.Generators.CSharp @@ -63,8 +64,10 @@ namespace CppSharp.Generators.CSharp
Context = context;
contexts = new Stack<CSharpTypePrinterContextKind>();
marshalKinds = new Stack<CSharpMarshalKind>();
printScopeKinds = new Stack<TypePrintScopeKind>();
PushContext(CSharpTypePrinterContextKind.Managed);
PushMarshalKind(CSharpMarshalKind.Unknown);
PushPrintScopeKind(TypePrintScopeKind.GlobalQualified);
TypePrinterContext = new CSharpTypePrinterContext();
}
@ -83,6 +86,13 @@ namespace CppSharp.Generators.CSharp @@ -83,6 +86,13 @@ namespace CppSharp.Generators.CSharp
public CSharpMarshalKind PopMarshalKind() => marshalKinds.Pop();
public void PushPrintScopeKind(TypePrintScopeKind printScopeKind)
{
printScopeKinds.Push(printScopeKind);
}
public TypePrintScopeKind PopPrintScopeKind() => printScopeKinds.Pop();
public CSharpTypePrinterResult VisitTagType(TagType tag, TypeQualifiers quals)
{
if (tag.Declaration == null)
@ -423,9 +433,7 @@ namespace CppSharp.Generators.CSharp @@ -423,9 +433,7 @@ namespace CppSharp.Generators.CSharp
};
}
return GetNestedQualifiedName(decl) +
(ContextKind == CSharpTypePrinterContextKind.Native ?
Helpers.InternalStruct : string.Empty);
return decl.Visit(this);
}
public CSharpTypePrinterResult VisitDependentTemplateSpecializationType(
@ -596,17 +604,19 @@ namespace CppSharp.Generators.CSharp @@ -596,17 +604,19 @@ namespace CppSharp.Generators.CSharp
public CSharpTypePrinterResult VisitDeclaration(Declaration decl)
{
return GetNestedQualifiedName(decl);
return GetName(decl);
}
public CSharpTypePrinterResult VisitClassDecl(Class @class)
{
if (ContextKind == CSharpTypePrinterContextKind.Native)
return string.Format("{0}.{1}",
GetNestedQualifiedName(@class.OriginalClass ?? @class),
Helpers.InternalStruct);
{
if (PrintScopeKind == TypePrintScopeKind.Local)
return Helpers.InternalStruct;
return GetNestedQualifiedName(@class);
return $"{GetName(@class.OriginalClass ?? @class)}.{Helpers.InternalStruct}";
}
return GetName(@class);
}
public CSharpTypePrinterResult VisitClassTemplateSpecializationDecl(ClassTemplateSpecialization specialization)
@ -648,17 +658,17 @@ namespace CppSharp.Generators.CSharp @@ -648,17 +658,17 @@ namespace CppSharp.Generators.CSharp
public CSharpTypePrinterResult VisitTypedefDecl(TypedefDecl typedef)
{
return GetNestedQualifiedName(typedef);
return GetName(typedef);
}
public CSharpTypePrinterResult VisitTypeAliasDecl(TypeAlias typeAlias)
{
return GetNestedQualifiedName(typeAlias);
return GetName(typeAlias);
}
public CSharpTypePrinterResult VisitEnumDecl(Enumeration @enum)
{
return GetNestedQualifiedName(@enum);
return GetName(@enum);
}
public CSharpTypePrinterResult VisitEnumItemDecl(Enumeration.Item item)
@ -666,8 +676,11 @@ namespace CppSharp.Generators.CSharp @@ -666,8 +676,11 @@ namespace CppSharp.Generators.CSharp
return VisitDeclaration(item);
}
public string GetNestedQualifiedName(Declaration decl)
public string GetName(Declaration decl)
{
if (PrintScopeKind == TypePrintScopeKind.Local)
return decl.Name;
var names = new Stack<string>();
Declaration ctx;
@ -706,16 +719,18 @@ namespace CppSharp.Generators.CSharp @@ -706,16 +719,18 @@ namespace CppSharp.Generators.CSharp
names.Reverse();
var isInCurrentOutputNamespace = names.Peek() == Generator.CurrentOutputNamespace;
if (isInCurrentOutputNamespace || !FullyQualify)
if (isInCurrentOutputNamespace ||
PrintScopeKind != TypePrintScopeKind.GlobalQualified)
names.Pop();
return (isInCurrentOutputNamespace || !FullyQualify ?
return (isInCurrentOutputNamespace ||
PrintScopeKind != TypePrintScopeKind.GlobalQualified ?
string.Empty : "global::") + string.Join(".", names);
}
public CSharpTypePrinterResult VisitVariableDecl(Variable variable)
{
return GetNestedQualifiedName(variable);
return GetName(variable);
}
public CSharpTypePrinterResult VisitClassTemplateDecl(ClassTemplate template)

3
src/Generator/Passes/DelegatesPass.cs

@ -170,7 +170,8 @@ namespace CppSharp.Passes @@ -170,7 +170,8 @@ namespace CppSharp.Passes
{
if (typePrinter == null)
{
typePrinter = new CSharpTypePrinter(Context) { FullyQualify = false };
typePrinter = new CSharpTypePrinter(Context);
typePrinter.PushPrintScopeKind(TypePrintScopeKind.Qualified);
typePrinter.PushContext(CSharpTypePrinterContextKind.Native);
typePrinter.PushMarshalKind(CSharpMarshalKind.GenericDelegate);
}

2
src/Generator/Passes/GenerateTemplatesCodePass.cs

@ -22,7 +22,7 @@ namespace CppSharp.Passes @@ -22,7 +22,7 @@ namespace CppSharp.Passes
var cppTypePrinter = new CppTypePrinter
{
PrintScopeKind = CppTypePrintScopeKind.Qualified,
PrintScopeKind = TypePrintScopeKind.Qualified,
PrintLogicalNames = true
};
foreach (var specialization in @class.Specializations.Where(s => !s.IsDependent && !s.Ignore))

1
src/Generator/Passes/GetterSetterToPropertyPass.cs

@ -331,6 +331,7 @@ namespace CppSharp.Passes @@ -331,6 +331,7 @@ namespace CppSharp.Passes
VisitOptions.VisitClassFields = false;
VisitOptions.VisitClassProperties = false;
VisitOptions.VisitClassMethods = false;
VisitOptions.VisitClassTemplateSpecializations = false;
VisitOptions.VisitNamespaceEnums = false;
VisitOptions.VisitNamespaceTemplates = false;
VisitOptions.VisitNamespaceTypedefs = false;

2
src/Generator/Passes/InlinesCodeGenerator.cs

@ -232,7 +232,7 @@ namespace CppSharp.Passes @@ -232,7 +232,7 @@ namespace CppSharp.Passes
private CppTypePrinter cppTypePrinter = new CppTypePrinter
{
PrintScopeKind = CppTypePrintScopeKind.Qualified
PrintScopeKind = TypePrintScopeKind.Qualified
};
private int functionCount;
}

6
src/Generator/Types/TypeMap.cs

@ -173,7 +173,7 @@ namespace CppSharp.Types @@ -173,7 +173,7 @@ namespace CppSharp.Types
return true;
}
typePrinter.PrintScopeKind = CppTypePrintScopeKind.Qualified;
typePrinter.PrintScopeKind = TypePrintScopeKind.Qualified;
if (FindTypeMap(decl.Visit(typePrinter), out typeMap))
{
typeMap.Type = type;
@ -188,7 +188,7 @@ namespace CppSharp.Types @@ -188,7 +188,7 @@ namespace CppSharp.Types
}
typePrinter.ResolveTypedefs = false;
typePrinter.PrintScopeKind = CppTypePrintScopeKind.Local;
typePrinter.PrintScopeKind = TypePrintScopeKind.Local;
if (FindTypeMap(decl.Visit(typePrinter), out typeMap))
{
typeMap.Type = type;
@ -239,7 +239,7 @@ namespace CppSharp.Types @@ -239,7 +239,7 @@ namespace CppSharp.Types
return true;
}
typePrinter.PrintScopeKind = CppTypePrintScopeKind.Qualified;
typePrinter.PrintScopeKind = TypePrintScopeKind.Qualified;
if (FindTypeMap(type.Visit(typePrinter), out typeMap))
{
typeMap.Type = type;

Loading…
Cancel
Save