mirror of https://github.com/mono/CppSharp.git
c-sharpdotnetmonobindingsbridgecclangcpluspluscppsharpglueinteropparserparsingpinvokeswigsyntax-treevisitorsxamarinxamarin-bindings
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.7 KiB
66 lines
1.7 KiB
using System; |
|
using System.Collections.Generic; |
|
|
|
namespace Cxxi.Passes |
|
{ |
|
public class DuplicatedNamesCheckerPass : TranslationUnitPass |
|
{ |
|
private readonly IDictionary<string, Declaration> names; |
|
|
|
public DuplicatedNamesCheckerPass() |
|
{ |
|
names = new Dictionary<string, Declaration>(); |
|
} |
|
|
|
public override bool ProcessClass(Class @class) |
|
{ |
|
if (@class.Ignore) return false; |
|
|
|
names.Clear(); |
|
|
|
foreach (var baseClass in @class.Bases) |
|
if (baseClass.IsClass) |
|
ProcessClass(baseClass.Class); |
|
|
|
CheckDuplicates(@class.Fields); |
|
CheckDuplicates(@class.Methods); |
|
CheckDuplicates(@class.Properties); |
|
|
|
return true; |
|
} |
|
|
|
void CheckDuplicates(IEnumerable<Declaration> decls) |
|
{ |
|
foreach (var decl in decls) |
|
{ |
|
if (decl.Ignore) continue; |
|
CheckDuplicate(decl); |
|
} |
|
} |
|
|
|
void CheckDuplicate(Declaration decl) |
|
{ |
|
Declaration duplicate; |
|
|
|
// If the name is not yet on the map, then add it. |
|
if (!names.TryGetValue(decl.Name, out duplicate)) |
|
{ |
|
names[decl.Name] = decl; |
|
return; |
|
} |
|
|
|
// Else we found a duplicate name and need to change it. |
|
Console.WriteLine("Found a duplicate named declaration: {0}", |
|
decl.Name); |
|
} |
|
} |
|
|
|
public static class CheckDuplicateNamesExtensions |
|
{ |
|
public static void CheckDuplicateNames(this PassBuilder builder) |
|
{ |
|
var pass = new DuplicatedNamesCheckerPass(); |
|
builder.AddPass(pass); |
|
} |
|
} |
|
}
|
|
|