Browse Source

Process base class references as forward references.

pull/1/head
triton 13 years ago
parent
commit
8d7dc79ead
  1. 24
      src/Generator/Generators/CLI/CLIForwardRefeferencePrinter.cs
  2. 7
      src/Generator/Generators/CLI/CLIHeadersTemplate.cs
  3. 13
      src/Generator/Types/Types.cs

24
src/Generator/Generators/CLI/CLIForwardRefeferencePrinter.cs

@ -8,11 +8,33 @@ namespace Cxxi.Generators.CLI
{ {
public readonly IList<string> Includes; public readonly IList<string> Includes;
public readonly IList<string> Refs; public readonly IList<string> Refs;
private readonly TypeRefsVisitor TypeRefs;
public CLIForwardRefeferencePrinter() public CLIForwardRefeferencePrinter(TypeRefsVisitor typeRefs)
{ {
Includes = new List<string>(); Includes = new List<string>();
Refs = new List<string>(); Refs = new List<string>();
TypeRefs = typeRefs;
}
public void Process()
{
foreach (var forwardRef in TypeRefs.ForwardReferences)
forwardRef.Visit(this);
foreach (var baseClass in TypeRefs.Bases)
VisitBaseClass(baseClass);
}
public void VisitBaseClass(Class @class)
{
if (@class.IsIncomplete)
@class = @class.CompleteDeclaration as Class;
if (@class == null)
return;
Includes.Add(GetHeaderFromDecl(@class));
} }
public bool VisitDeclaration(Declaration decl) public bool VisitDeclaration(Declaration decl)

7
src/Generator/Generators/CLI/CLIHeadersTemplate.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
namespace Cxxi.Generators.CLI namespace Cxxi.Generators.CLI
@ -36,10 +37,10 @@ namespace Cxxi.Generators.CLI
public void GenerateIncludeForwardRefs() public void GenerateIncludeForwardRefs()
{ {
forwardRefsPrinter = new CLIForwardRefeferencePrinter(); var typeRefs = unit.TypeReferences as TypeRefsVisitor;
foreach (var forwardRef in unit.ForwardReferences) forwardRefsPrinter = new CLIForwardRefeferencePrinter(typeRefs);
forwardRef.Visit(forwardRefsPrinter); forwardRefsPrinter.Process();
var includes = new HashSet<string>(); var includes = new HashSet<string>();

13
src/Generator/Types/Types.cs

@ -1,4 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using Cxxi.Generators; using Cxxi.Generators;
using Cxxi.Types; using Cxxi.Types;
@ -136,9 +137,10 @@ namespace Cxxi
/// that a file needs to be reference something that has not been declared /// 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. /// yet. In that case, we need to declare it before referencing it.
/// </summary> /// </summary>
class TypeRefsVisitor : AstVisitor public class TypeRefsVisitor : AstVisitor
{ {
public ISet<Declaration> ForwardReferences; public ISet<Declaration> ForwardReferences;
public ISet<Class> Bases;
public void Collect(Declaration declaration) public void Collect(Declaration declaration)
{ {
@ -154,6 +156,7 @@ namespace Cxxi
public TypeRefsVisitor() public TypeRefsVisitor()
{ {
ForwardReferences = new HashSet<Declaration>(); ForwardReferences = new HashSet<Declaration>();
Bases = new HashSet<Class>();
} }
public override bool VisitClassDecl(Class @class) public override bool VisitClassDecl(Class @class)
@ -175,6 +178,14 @@ namespace Cxxi
foreach (var method in @class.Methods) foreach (var method in @class.Methods)
VisitMethodDecl(method); VisitMethodDecl(method);
foreach (var @base in @class.Bases)
{
if (!@base.IsClass)
continue;
Bases.Add(@base.Class);
}
return true; return true;
} }

Loading…
Cancel
Save