Skip to content

Commit e26206f

Browse files
committed
Make the pass for properties more extendable
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent d986132 commit e26206f

File tree

5 files changed

+15
-14
lines changed

5 files changed

+15
-14
lines changed

src/Generator/Driver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public bool ParseLibraries()
216216
public void SetupPasses(ILibrary library)
217217
{
218218
var TranslationUnitPasses = Context.TranslationUnitPasses;
219-
219+
220220
TranslationUnitPasses.AddPass(new ResolveIncompleteDeclsPass());
221221
TranslationUnitPasses.AddPass(new IgnoreSystemDeclarationsPass());
222222
if (Options.IsCSharpGenerator)

src/Generator/Generators/CSharp/CSharpSources.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -638,13 +638,15 @@ private void GatherClassInternalFunctions(Class @class, bool includeCtors,
638638
tryAddOverload(method);
639639
}
640640

641-
foreach (var prop in @class.Properties)
641+
foreach (var prop in @class.Properties.Where(p => p.Field == null))
642642
{
643-
if (prop.GetMethod?.Namespace == @class)
643+
if ((!prop.IsOverride || prop.GetMethod.Namespace == @class) &&
644+
!functions.Contains(prop.GetMethod))
644645
tryAddOverload(prop.GetMethod);
645646

646-
if (prop.SetMethod?.Namespace == @class &&
647-
prop.SetMethod != prop.GetMethod)
647+
if (prop.SetMethod != null
648+
&& (!prop.IsOverride || prop.SetMethod.Namespace == @class)
649+
&& !functions.Contains(prop.SetMethod))
648650
tryAddOverload(prop.SetMethod);
649651
}
650652
}

src/Generator/Passes/GetterSetterToPropertyPass.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,12 @@ public override bool VisitClassDecl(Class @class)
6666
return false;
6767
}
6868

69-
protected virtual IEnumerable<Property> GenerateProperties(Class @class)
69+
protected virtual List<Property> GetProperties(Class @class) =>
70+
new List<Property>();
71+
72+
protected IEnumerable<Property> GenerateProperties(Class @class)
7073
{
71-
var properties = new List<Property>();
74+
List<Property> properties = GetProperties(@class);
7275
foreach (Method method in @class.Methods.Where(
7376
m => !m.IsConstructor && !m.IsDestructor && !m.IsOperator && m.IsGenerated &&
7477
m.SynthKind != FunctionSynthKind.DefaultValueOverload &&
@@ -101,7 +104,7 @@ private IEnumerable<Property> CleanUp(Class @class, List<Property> properties)
101104
for (int i = properties.Count - 1; i >= 0; i--)
102105
{
103106
Property property = properties[i];
104-
if (property.HasSetter)
107+
if (property.HasSetter || property.IsExplicitlyGenerated)
105108
continue;
106109

107110
string firstWord = GetFirstWord(property.GetMethod.Name);
@@ -173,8 +176,7 @@ private static bool Match(Property property, string name)
173176
return true;
174177
}
175178

176-
return property.SetMethod != null &&
177-
GetPropertyNameFromSetter(property.SetMethod.Name) == name;
179+
return false;
178180
}
179181

180182
private static string RemovePrefix(string identifier)

src/Generator/Passes/MultipleInheritancePass.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ private static Property CreateInterfaceProperty(Property property, DeclarationCo
193193
OriginalFunction = property.GetMethod,
194194
Namespace = @namespace
195195
};
196-
interfaceProperty.GetMethod.OverriddenMethods.Add(property.GetMethod);
197196
}
198197
if (property.SetMethod != null)
199198
{
@@ -204,7 +203,6 @@ private static Property CreateInterfaceProperty(Property property, DeclarationCo
204203
OriginalFunction = property.SetMethod,
205204
Namespace = @namespace
206205
};
207-
interfaceProperty.SetMethod.OverriddenMethods.Add(property.SetMethod);
208206
}
209207
return interfaceProperty;
210208
}
@@ -231,7 +229,6 @@ private void ImplementInterfaceMethods(Class @class, Class @interface)
231229
OriginalNamespace = @interface,
232230
OriginalFunction = method.OriginalFunction
233231
};
234-
impl.OverriddenMethods.Add((Method) method.OriginalFunction);
235232
var rootBaseMethod = @class.GetBaseMethod(method);
236233
if (rootBaseMethod != null && rootBaseMethod.IsDeclared)
237234
impl.ExplicitInterfaceImpl = @interface;

src/Generator/Passes/RenamePass.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public virtual bool Rename(Declaration decl, out string newName)
6666
var property = decl as Property;
6767
if (property != null && !property.IsStatic)
6868
{
69-
var rootBaseProperty = ((Class) property.Namespace).GetBaseProperty(property);
69+
var rootBaseProperty = ((Class) property.Namespace).GetBasePropertyByName(property);
7070
if (rootBaseProperty != null && rootBaseProperty != property)
7171
{
7272
newName = rootBaseProperty.Name;

0 commit comments

Comments
 (0)