From 86b6588951611ec2cbc43b780a56ab9a45a99a7c Mon Sep 17 00:00:00 2001 From: triton Date: Wed, 11 Sep 2013 01:21:25 +0100 Subject: [PATCH] Check for invalid virtual method overrides due to ignored base classes. --- src/Generator/Passes/CheckIgnoredDecls.cs | 51 ++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/src/Generator/Passes/CheckIgnoredDecls.cs b/src/Generator/Passes/CheckIgnoredDecls.cs index ea3246ef..102f4d53 100644 --- a/src/Generator/Passes/CheckIgnoredDecls.cs +++ b/src/Generator/Passes/CheckIgnoredDecls.cs @@ -103,7 +103,56 @@ namespace CppSharp.Passes public override bool VisitMethodDecl(Method method) { - return VisitDeclaration(method) && base.VisitMethodDecl(method); + if (!VisitDeclaration(method)) + return false; + + if (!CheckIgnoredBaseOverridenMethod(method)) + return false; + + return base.VisitMethodDecl(method); + } + + bool CheckIgnoredBaseOverridenMethod(Method method) + { + var @class = method.Namespace as Class; + + Class ignoredBase; + if (method.IsVirtual && HasIgnoredBaseClass(method, @class, out ignoredBase)) + { + Driver.Diagnostics.EmitMessage( + "Virtual method '{0}' was ignored due to ignored base '{1}'", + method.QualifiedOriginalName, ignoredBase.Name); + + method.ExplicityIgnored = true; + return false; + } + return true; + } + + static bool HasIgnoredBaseClass(INamedDecl @override, Class @class, + out Class ignoredBase) + { + var isIgnored = false; + ignoredBase = null; + + foreach (var baseClassSpec in @class.Bases) + { + if (!baseClassSpec.IsClass) + continue; + + var @base = baseClassSpec.Class; + if (!@base.Methods.Exists(m => m.Name == @override.Name)) + continue; + + ignoredBase = @base; + isIgnored |= @base.Ignore + || HasIgnoredBaseClass(@override, @base, out ignoredBase); + + if (isIgnored) + break; + } + + return isIgnored; } public override bool VisitTypedefDecl(TypedefDecl typedef)