Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

Commit

Permalink
Removed CheckTypeReferencesPass and TypeRefsVisitor
Browse files Browse the repository at this point in the history
  • Loading branch information
esdrubal committed Jul 22, 2013
1 parent e168e84 commit 7dd2771
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 178 deletions.
1 change: 0 additions & 1 deletion src/Generator/Driver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ public void AddPostPasses()
{
Passes.CleanInvalidDeclNames();
Passes.CheckIgnoredDecls();
Passes.CheckTypeReferences();
Passes.CheckFlagEnums();
Passes.CheckAmbiguousOverloads();
Generator.SetupPasses(Passes);
Expand Down
30 changes: 0 additions & 30 deletions src/Generator/Passes/CheckTypeReferencesPass.cs

This file was deleted.

147 changes: 0 additions & 147 deletions src/Generator/Types/Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,151 +117,4 @@ public override bool VisitTemplateSpecializationType(
}
}

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);
}

}
}

0 comments on commit 7dd2771

Please sign in to comment.