Browse Source

Reused the method for generating a string representation of an access qualifier.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/68/head
Dimitar Dobrev 12 years ago
parent
commit
c45c015a75
  1. 27
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  2. 5
      src/Generator/Passes/GenerateAbstractImplementationsPass.cs

27
src/Generator/Generators/CSharp/CSharpTextTemplate.cs

@ -58,9 +58,9 @@ namespace CppSharp.Generators.CSharp
get { return Generator.GeneratedIdentifier("Instance"); } get { return Generator.GeneratedIdentifier("Instance"); }
} }
public static string GetAccess(Class @class) public static string GetAccess(AccessSpecifier accessSpecifier)
{ {
switch (@class.Access) switch (accessSpecifier)
{ {
case AccessSpecifier.Private: case AccessSpecifier.Private:
return "internal "; return "internal ";
@ -676,7 +676,7 @@ namespace CppSharp.Generators.CSharp
if (@class.IsUnion) if (@class.IsUnion)
WriteLine("[StructLayout(LayoutKind.Explicit)]"); WriteLine("[StructLayout(LayoutKind.Explicit)]");
Write(Helpers.GetAccess(@class)); Write(Helpers.GetAccess(@class.Access));
Write("unsafe "); Write("unsafe ");
if (Driver.Options.GenerateAbstractImpls && @class.IsAbstract) if (Driver.Options.GenerateAbstractImpls && @class.IsAbstract)
@ -992,8 +992,7 @@ namespace CppSharp.Generators.CSharp
type = ((PointerType) prop.Type).Pointee; type = ((PointerType) prop.Type).Pointee;
if (prop.ExplicitInterfaceImpl == null) if (prop.ExplicitInterfaceImpl == null)
WriteLine("{0} {1} {2}", WriteLine("{0}{1} {2}", Helpers.GetAccess(prop.Access),
prop.Access == AccessSpecifier.Public ? "public" : "protected",
type, GetPropertyName(prop)); type, GetPropertyName(prop));
else else
WriteLine("{0} {1}.{2}", type, prop.ExplicitInterfaceImpl.Name, GetPropertyName(prop)); WriteLine("{0} {1}.{2}", type, prop.ExplicitInterfaceImpl.Name, GetPropertyName(prop));
@ -1590,15 +1589,7 @@ namespace CppSharp.Generators.CSharp
if (method.ExplicitInterfaceImpl == null) if (method.ExplicitInterfaceImpl == null)
{ {
switch (GetValidMethodAccess(method, @class)) Write(Helpers.GetAccess(GetValidMethodAccess(method)));
{
case AccessSpecifier.Public:
Write("public ");
break;
case AccessSpecifier.Protected:
Write("protected ");
break;
}
} }
if (method.IsVirtual && !method.IsOverride && if (method.IsVirtual && !method.IsOverride &&
@ -1688,7 +1679,7 @@ namespace CppSharp.Generators.CSharp
PopBlock(NewLineKind.BeforeNextBlock); PopBlock(NewLineKind.BeforeNextBlock);
} }
private static AccessSpecifier GetValidMethodAccess(Method method, Class @class) private static AccessSpecifier GetValidMethodAccess(Method method)
{ {
switch (method.Access) switch (method.Access)
{ {
@ -1696,7 +1687,7 @@ namespace CppSharp.Generators.CSharp
return AccessSpecifier.Public; return AccessSpecifier.Public;
default: default:
return method.IsOverride ? return method.IsOverride ?
@class.GetRootBaseMethod(method).Access : method.Access; ((Class) method.Namespace).GetRootBaseMethod(method).Access : method.Access;
} }
} }
@ -2086,8 +2077,8 @@ namespace CppSharp.Generators.CSharp
WriteLine("[UnmanagedFunctionPointerAttribute(CallingConvention.{0})]", WriteLine("[UnmanagedFunctionPointerAttribute(CallingConvention.{0})]",
Helpers.ToCSharpCallConv(functionType.CallingConvention)); Helpers.ToCSharpCallConv(functionType.CallingConvention));
TypePrinter.PushContext(CSharpTypePrinterContextKind.Native); TypePrinter.PushContext(CSharpTypePrinterContextKind.Native);
WriteLine("{0} unsafe {1};", WriteLine("{0}unsafe {1};",
typedef.Access == AccessSpecifier.Public ? "public" : "protected", Helpers.GetAccess(typedef.Access),
string.Format(TypePrinter.VisitDelegate(functionType).Type, string.Format(TypePrinter.VisitDelegate(functionType).Type,
SafeIdentifier(typedef.Name))); SafeIdentifier(typedef.Name)));
TypePrinter.PopContext(); TypePrinter.PopContext();

5
src/Generator/Passes/GenerateAbstractImplementationsPass.cs

@ -1,7 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using CppSharp.AST; using CppSharp.AST;
using CppSharp.Utils;
namespace CppSharp.Passes namespace CppSharp.Passes
{ {
@ -52,7 +51,9 @@ namespace CppSharp.Passes
foreach (var abstractMethod in abstractMethods) foreach (var abstractMethod in abstractMethods)
{ {
internalImpl.Methods.Add(new Method(abstractMethod)); var method = new Method(abstractMethod);
method.Namespace = internalImpl;
internalImpl.Methods.Add(method);
var @delegate = new TypedefDecl var @delegate = new TypedefDecl
{ {
Name = abstractMethod.Name + "Delegate", Name = abstractMethod.Name + "Delegate",

Loading…
Cancel
Save