Skip to content

Commit 1e80e8c

Browse files
committed
Simplified the equalisation of access of overrides.
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent 45a9dc4 commit 1e80e8c

File tree

1 file changed

+8
-28
lines changed

1 file changed

+8
-28
lines changed
Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
34
using CppSharp.AST;
45

@@ -20,39 +21,18 @@ public EqualiseAccessOfOverrideAndBasePass()
2021
VisitOptions.VisitTemplateArguments = false;
2122
}
2223

23-
public override bool VisitASTContext(ASTContext context)
24-
{
25-
var result = base.VisitASTContext(context);
26-
27-
foreach (var baseOverride in basesOverrides)
28-
{
29-
var access = baseOverride.Value.Max(o => o.Access);
30-
foreach (var @override in baseOverride.Value)
31-
@override.Access = access;
32-
}
33-
34-
return result;
35-
}
36-
3724
public override bool VisitMethodDecl(Method method)
3825
{
39-
if (!base.VisitMethodDecl(method) || !method.IsOverride)
40-
return false;
41-
42-
var baseMethod = method.GetRootBaseMethod();
43-
if (!baseMethod.IsGenerated)
26+
if (!base.VisitMethodDecl(method) || !method.OverriddenMethods.Any())
4427
return false;
4528

46-
HashSet<Method> overrides;
47-
if (basesOverrides.ContainsKey(baseMethod))
48-
overrides = basesOverrides[baseMethod];
49-
else
50-
overrides = basesOverrides[baseMethod] = new HashSet<Method> { baseMethod };
51-
overrides.Add(method);
29+
var virtuals = new List<Method>(method.OverriddenMethods);
30+
virtuals.Add(method);
31+
AccessSpecifier access = virtuals.Max(o => o.Access);
32+
foreach (var @virtual in virtuals)
33+
@virtual.Access = access;
5234

5335
return true;
5436
}
55-
56-
private Dictionary<Method, HashSet<Method>> basesOverrides = new Dictionary<Method, HashSet<Method>>();
5737
}
5838
}

0 commit comments

Comments
 (0)