Browse Source

Removed CheckTypeReferencesPass and TypeRefsVisitor

pull/13/head
marcos henrich 13 years ago
parent
commit
7dd2771604
  1. 1
      src/Generator/Driver.cs
  2. 30
      src/Generator/Passes/CheckTypeReferencesPass.cs
  3. 147
      src/Generator/Types/Types.cs

1
src/Generator/Driver.cs

@ -131,7 +131,6 @@ namespace CppSharp @@ -131,7 +131,6 @@ namespace CppSharp
{
Passes.CleanInvalidDeclNames();
Passes.CheckIgnoredDecls();
Passes.CheckTypeReferences();
Passes.CheckFlagEnums();
Passes.CheckAmbiguousOverloads();
Generator.SetupPasses(Passes);

30
src/Generator/Passes/CheckTypeReferencesPass.cs

@ -1,30 +0,0 @@ @@ -1,30 +0,0 @@
using CppSharp.AST;
namespace CppSharp.Passes
{
public class CheckTypeReferencesPass : TranslationUnitPass
{
TypeRefsVisitor typeRefs;
public override bool VisitTranslationUnit(TranslationUnit unit)
{
if (unit.Ignore)
return false;
if (unit.IsSystemHeader)
return false;
typeRefs = new TypeRefsVisitor();
return typeRefs.VisitTranslationUnit(unit);
}
}
public static class CheckTypeReferencesExtensions
{
public static void CheckTypeReferences(this PassBuilder builder)
{
var pass = new CheckTypeReferencesPass();
builder.AddPass(pass);
}
}
}

147
src/Generator/Types/Types.cs

@ -117,151 +117,4 @@ namespace CppSharp @@ -117,151 +117,4 @@ namespace CppSharp
}
}
public struct TypeReference
{
public Declaration Declaration;
public Namespace Namespace;
}
/// <summary>
/// This is used to get the declarations that each file needs to forward
/// reference or include from other header files. Since in C++ everything
/// that is referenced needs to have been declared previously, it can happen
/// that a file needs to be reference something that has not been declared
/// yet. In that case, we need to declare it before referencing it.
/// </summary>
public class TypeRefsVisitor : AstVisitor
{
public ISet<TypeReference> References;
public ISet<Class> Bases;
private TranslationUnit unit;
private Namespace currentNamespace;
public TypeRefsVisitor()
{
References = new HashSet<TypeReference>();
Bases = new HashSet<Class>();
}
public void Collect(Declaration declaration)
{
var @namespace = declaration.Namespace;
if (@namespace != null)
if (@namespace.TranslationUnit.IsSystemHeader)
return;
References.Add(new TypeReference()
{
Declaration = declaration,
Namespace = currentNamespace
});
}
public bool VisitTranslationUnit(TranslationUnit unit)
{
this.unit = unit;
unit.TypeReferences = this;
VisitNamespace(unit);
foreach (var @namespace in unit.Namespaces)
VisitNamespace(@namespace);
return true;
}
public override bool VisitNamespace(Namespace @namespace)
{
currentNamespace = @namespace;
return base.VisitNamespace(@namespace);
}
public override bool VisitClassDecl(Class @class)
{
if (@class.Ignore)
{
Visited.Add(@class);
return false;
}
if (Visited.Contains(@class))
return References.Any(reference => reference.Declaration == @class);
Collect(@class);
// If the class is incomplete, then we cannot process the record
// members, else it will add references to declarations that
// should have not been found.
if (@class.IsIncomplete)
goto OutVisited;
if (string.IsNullOrWhiteSpace(@class.Name))
goto OutVisited;
var unitClass = unit.FindClass(@class.Name);
if (unitClass == null || unitClass.IsIncomplete)
goto OutVisited;
foreach (var @base in @class.Bases)
{
if (!@base.IsClass)
continue;
Bases.Add(@base.Class);
}
return base.VisitClassDecl(@class);
OutVisited:
Visited.Add(@class);
return true;
}
public override bool VisitEnumDecl(Enumeration @enum)
{
Collect(@enum);
return true;
}
public override bool VisitFieldDecl(Field field)
{
if (base.VisitFieldDecl(field))
Collect(field);
return true;
}
public override bool VisitTypedefType(TypedefType typedef,
TypeQualifiers quals)
{
var decl = typedef.Declaration;
if (decl.Type == null)
return false;
FunctionType function;
if (decl.Type.IsPointerTo<FunctionType>(out function))
{
Collect(decl);
return true;
}
return decl.Type.Visit(this);
}
public override bool VisitTagType(TagType tag, TypeQualifiers quals)
{
Collect(tag.Declaration);
return true;
}
public override bool VisitTemplateSpecializationType(TemplateSpecializationType template, TypeQualifiers quals)
{
Collect(template.Template);
return base.VisitTemplateSpecializationType(template, quals);
}
}
}

Loading…
Cancel
Save