|
|
|
@ -13,66 +13,18 @@ namespace CppSharp.Passes
@@ -13,66 +13,18 @@ namespace CppSharp.Passes
|
|
|
|
|
{ |
|
|
|
|
public class GetterSetterToPropertyAdvancedPass : TranslationUnitPass |
|
|
|
|
{ |
|
|
|
|
// collect all types of methods first to be able to match pairs and detect virtuals and overrides;
|
|
|
|
|
// (a property needs to) be virtual or an override if either of its constituent methods are such)
|
|
|
|
|
private class PropertyGenerator |
|
|
|
|
{ |
|
|
|
|
private readonly List<Method> getters = new List<Method>(); |
|
|
|
|
private readonly List<Method> setters = new List<Method>(); |
|
|
|
|
private readonly List<Method> setMethods = new List<Method>(); |
|
|
|
|
private readonly List<Method> nonSetters = new List<Method>(); |
|
|
|
|
private readonly HashSet<Method> getters = new HashSet<Method>(); |
|
|
|
|
private static readonly HashSet<string> verbs = new HashSet<string>(); |
|
|
|
|
|
|
|
|
|
static GetterSetterToPropertyAdvancedPass() |
|
|
|
|
{ |
|
|
|
|
LoadVerbs(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static Stream GetResourceStream (Assembly assembly) |
|
|
|
|
public PropertyGenerator(Class @class) |
|
|
|
|
{ |
|
|
|
|
var stream = assembly.GetManifestResourceStream("CppSharp.Generator.Passes.verbs.txt"); |
|
|
|
|
if (stream != null) |
|
|
|
|
return stream; |
|
|
|
|
|
|
|
|
|
stream = assembly.GetManifestResourceStream("verbs.txt"); |
|
|
|
|
return stream; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static void LoadVerbs() |
|
|
|
|
{ |
|
|
|
|
var assembly = Assembly.GetExecutingAssembly(); |
|
|
|
|
using (var resourceStream = GetResourceStream(assembly)) |
|
|
|
|
{ |
|
|
|
|
using (var streamReader = new StreamReader(resourceStream)) |
|
|
|
|
while (!streamReader.EndOfStream) |
|
|
|
|
verbs.Add(streamReader.ReadLine()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public GetterSetterToPropertyAdvancedPass() |
|
|
|
|
{ |
|
|
|
|
Options.VisitClassFields = false; |
|
|
|
|
Options.VisitClassProperties = false; |
|
|
|
|
Options.VisitNamespaceEnums = false; |
|
|
|
|
Options.VisitNamespaceTemplates = false; |
|
|
|
|
Options.VisitNamespaceTypedefs = false; |
|
|
|
|
Options.VisitNamespaceEvents = false; |
|
|
|
|
Options.VisitNamespaceVariables = false; |
|
|
|
|
Options.VisitFunctionParameters = false; |
|
|
|
|
Options.VisitTemplateArguments = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override bool VisitTranslationUnit(TranslationUnit unit) |
|
|
|
|
{ |
|
|
|
|
bool result = base.VisitTranslationUnit(unit); |
|
|
|
|
GenerateProperties(); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override bool VisitMethodDecl(Method method) |
|
|
|
|
{ |
|
|
|
|
if (!method.IsConstructor && !method.IsDestructor && !method.IsOperator && |
|
|
|
|
method.IsGenerated && !method.IsSynthetized) |
|
|
|
|
foreach (var method in @class.Methods.Where( |
|
|
|
|
m => !m.IsConstructor && !m.IsDestructor && !m.IsOperator && !m.Ignore)) |
|
|
|
|
DistributeMethod(method); |
|
|
|
|
return base.VisitMethodDecl(method); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void GenerateProperties() |
|
|
|
@ -93,9 +45,7 @@ namespace CppSharp.Passes
@@ -93,9 +45,7 @@ namespace CppSharp.Passes
|
|
|
|
|
|
|
|
|
|
private void GenerateProperties(IEnumerable<Method> settersToUse, bool readOnly) |
|
|
|
|
{ |
|
|
|
|
foreach (var group in settersToUse.GroupBy(m => m.Namespace)) |
|
|
|
|
{ |
|
|
|
|
foreach (var setter in group) |
|
|
|
|
foreach (var setter in settersToUse) |
|
|
|
|
{ |
|
|
|
|
Class type = (Class) setter.Namespace; |
|
|
|
|
StringBuilder nameBuilder = new StringBuilder(setter.Name.Substring(3)); |
|
|
|
@ -125,7 +75,6 @@ namespace CppSharp.Passes
@@ -125,7 +75,6 @@ namespace CppSharp.Passes
|
|
|
|
|
next: |
|
|
|
|
; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
foreach (Method nonSetter in nonSetters) |
|
|
|
|
{ |
|
|
|
|
Class type = (Class) nonSetter.Namespace; |
|
|
|
@ -205,9 +154,9 @@ namespace CppSharp.Passes
@@ -205,9 +154,9 @@ namespace CppSharp.Passes
|
|
|
|
|
property.Comment = comment; |
|
|
|
|
} |
|
|
|
|
type.Properties.Add(property); |
|
|
|
|
getter.GenerationKind = GenerationKind.Internal; |
|
|
|
|
getter.GenerationKind = GenerationKind.None; |
|
|
|
|
if (setter != null) |
|
|
|
|
setter.GenerationKind = GenerationKind.Internal; |
|
|
|
|
setter.GenerationKind = GenerationKind.None; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -250,7 +199,7 @@ namespace CppSharp.Passes
@@ -250,7 +199,7 @@ namespace CppSharp.Passes
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private bool IsGetter(Method method) |
|
|
|
|
private static bool IsGetter(Method method) |
|
|
|
|
{ |
|
|
|
|
if (method.IsDestructor || |
|
|
|
|
(method.OriginalReturnType.Type.IsPrimitiveType(PrimitiveType.Void)) || |
|
|
|
@ -273,4 +222,37 @@ namespace CppSharp.Passes
@@ -273,4 +222,37 @@ namespace CppSharp.Passes
|
|
|
|
|
return new string(firstVerb.ToArray()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static readonly HashSet<string> verbs = new HashSet<string>(); |
|
|
|
|
|
|
|
|
|
static GetterSetterToPropertyAdvancedPass() |
|
|
|
|
{ |
|
|
|
|
LoadVerbs(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static void LoadVerbs() |
|
|
|
|
{ |
|
|
|
|
using (var resourceStream = Assembly.GetExecutingAssembly() |
|
|
|
|
.GetManifestResourceStream("CppSharp.Generator.Passes.verbs.txt")) |
|
|
|
|
{ |
|
|
|
|
using (StreamReader streamReader = new StreamReader(resourceStream)) |
|
|
|
|
while (!streamReader.EndOfStream) |
|
|
|
|
verbs.Add(streamReader.ReadLine()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public GetterSetterToPropertyAdvancedPass() |
|
|
|
|
{ |
|
|
|
|
Options.VisitClassProperties = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override bool VisitClassDecl(Class @class) |
|
|
|
|
{ |
|
|
|
|
bool result = base.VisitClassDecl(@class); |
|
|
|
|
|
|
|
|
|
new PropertyGenerator(@class).GenerateProperties(); |
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|