Browse Source

Added a new pass to check for duplicated vtable components.

This helps workaround some Clang's work-in-progress vftable layouting implementation.
pull/100/head
triton 12 years ago
parent
commit
71de29790e
  1. 2
      src/Generator/Driver.cs
  2. 38
      src/Generator/Passes/CheckVTableComponentsPass.cs

2
src/Generator/Driver.cs

@ -213,6 +213,8 @@ namespace CppSharp @@ -213,6 +213,8 @@ namespace CppSharp
TranslationUnitPasses.AddPass(new MultipleInheritancePass());
TranslationUnitPasses.AddPass(new ParamTypeToInterfacePass());
}
if (Options.GenerateVirtualTables)
TranslationUnitPasses.AddPass(new CheckVTableComponentsPass());
if (Options.GenerateProperties)
TranslationUnitPasses.AddPass(new GetterSetterToPropertyAdvancedPass());
}

38
src/Generator/Passes/CheckVTableComponentsPass.cs

@ -0,0 +1,38 @@ @@ -0,0 +1,38 @@
using System.Collections.Generic;
using System.Linq;
using CppSharp.AST;
using CppSharp.Utils;
namespace CppSharp.Passes
{
/// <summary>
/// This pass checks for vftable entries with duplicated components.
/// This might happen because of bugs in Clang vftable layouting.
/// </summary>
public class CheckVTableComponentsPass : TranslationUnitPass
{
public override bool VisitClassDecl(AST.Class @class)
{
if (AlreadyVisited(@class))
return false;
foreach (var vfptr in @class.Layout.VFTables)
{
var uniqueEntries = new OrderedSet<VTableComponent>();
foreach (var entry in vfptr.Layout.Components)
uniqueEntries.Add(entry);
// The vftable does not have duplicated components.
if (vfptr.Layout.Components.Count == uniqueEntries.Count)
continue;
Driver.Diagnostics.EmitWarning(
"Class '{0}' found with duplicated vftable components",
@class.Name);
vfptr.Layout.Components = uniqueEntries.ToList();
}
return base.VisitClassDecl(@class);
}
}
}
Loading…
Cancel
Save