From f743db743d488c0555f1e5fae289238e4595c859 Mon Sep 17 00:00:00 2001 From: triton Date: Wed, 18 Dec 2013 20:24:54 +0000 Subject: [PATCH] Reworked and improved checking of ignored declarations. It improves the logic to work when certain options are enabled. We would previously accept some declarations that should be ignored. --- src/Generator/Passes/CheckIgnoredDecls.cs | 38 ++++++++++++++++++----- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/src/Generator/Passes/CheckIgnoredDecls.cs b/src/Generator/Passes/CheckIgnoredDecls.cs index e65a0863..a9fe44eb 100644 --- a/src/Generator/Passes/CheckIgnoredDecls.cs +++ b/src/Generator/Passes/CheckIgnoredDecls.cs @@ -5,19 +5,40 @@ namespace CppSharp.Passes { public class CheckIgnoredDeclsPass : TranslationUnitPass { + public bool CheckDeclarationAccess(Declaration decl) + { + var generateAbstractImpls = Driver.Options.IsCSharpGenerator + && Driver.Options.GenerateAbstractImpls; + + switch (decl.Access) + { + case AccessSpecifier.Public: + return true; + case AccessSpecifier.Protected: + return generateAbstractImpls; + case AccessSpecifier.Private: + var method = decl as Method; + var isOverride = method != null && method.IsOverride; + return generateAbstractImpls && isOverride; + } + + return true; + } + public override bool VisitDeclaration(Declaration decl) { - if (decl.ExplicityIgnored) + if (AlreadyVisited(decl)) return false; - if (decl.Access == AccessSpecifier.Private) + if (decl.ExplicityIgnored) + return true; + + if (!CheckDeclarationAccess(decl)) { - Method method = decl as Method; - if (method == null || !method.IsOverride) - { - decl.ExplicityIgnored = true; - return false; - } + Log.Debug("Decl '{0}' was ignored due to invalid access", + decl.Name); + decl.ExplicityIgnored = true; + return true; } if (decl.IsDependent) @@ -25,6 +46,7 @@ namespace CppSharp.Passes decl.ExplicityIgnored = true; Log.Debug("Decl '{0}' was ignored due to dependent context", decl.Name); + return true; } return true;