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 @@ -8,11 +8,33 @@ namespace Cxxi.Generators.CLI
{
public readonly IList<string> Includes;
public readonly IList<string> Refs;
private readonly TypeRefsVisitor TypeRefs;
public CLIForwardRefeferencePrinter()
public CLIForwardRefeferencePrinter(TypeRefsVisitor typeRefs)
{
Includes = 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)

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

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

13
src/Generator/Types/Types.cs

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Diagnostics;
using Cxxi.Generators;
using Cxxi.Types;
@ -136,9 +137,10 @@ namespace Cxxi @@ -136,9 +137,10 @@ namespace Cxxi
/// 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>
class TypeRefsVisitor : AstVisitor
public class TypeRefsVisitor : AstVisitor
{
public ISet<Declaration> ForwardReferences;
public ISet<Class> Bases;
public void Collect(Declaration declaration)
{
@ -154,6 +156,7 @@ namespace Cxxi @@ -154,6 +156,7 @@ namespace Cxxi
public TypeRefsVisitor()
{
ForwardReferences = new HashSet<Declaration>();
Bases = new HashSet<Class>();
}
public override bool VisitClassDecl(Class @class)
@ -175,6 +178,14 @@ namespace Cxxi @@ -175,6 +178,14 @@ namespace Cxxi
foreach (var method in @class.Methods)
VisitMethodDecl(method);
foreach (var @base in @class.Bases)
{
if (!@base.IsClass)
continue;
Bases.Add(@base.Class);
}
return true;
}

Loading…
Cancel
Save