Browse Source

Rework forward references to keep track of what declaration they came from. This allows proper processing per namespace.

pull/1/head
triton 13 years ago
parent
commit
d94c930b36
  1. 38
      src/Generator/Generators/CLI/CLIForwardReferencePrinter.cs
  2. 14
      src/Generator/Generators/CLI/CLIHeadersTemplate.cs

38
src/Generator/Generators/CLI/CLIForwardReferencePrinter.cs

@ -4,16 +4,22 @@ using System.IO; @@ -4,16 +4,22 @@ using System.IO;
namespace Cxxi.Generators.CLI
{
public struct CLIForwardReference
{
public Declaration Declaration;
public string Text;
}
public class CLIForwardReferencePrinter : IDeclVisitor<bool>
{
public readonly IList<string> Includes;
public readonly IList<string> Refs;
public readonly IList<CLIForwardReference> Refs;
private readonly TypeRefsVisitor TypeRefs;
public CLIForwardReferencePrinter(TypeRefsVisitor typeRefs)
{
Includes = new List<string>();
Refs = new List<string>();
Refs = new List<CLIForwardReference>();
TypeRefs = typeRefs;
}
@ -50,11 +56,21 @@ namespace Cxxi.Generators.CLI @@ -50,11 +56,21 @@ namespace Cxxi.Generators.CLI
if (@class.IsValueType)
{
Refs.Add(string.Format("value struct {0};", @class.Name));
Refs.Add(new CLIForwardReference()
{
Declaration = @class,
Text = string.Format("value struct {0};", @class.Name)
});
return true;
}
Refs.Add(string.Format("ref class {0};", @class.Name));
Refs.Add(new CLIForwardReference()
{
Declaration = @class,
Text = string.Format("ref class {0};", @class.Name)
});
return true;
}
@ -126,12 +142,20 @@ namespace Cxxi.Generators.CLI @@ -126,12 +142,20 @@ namespace Cxxi.Generators.CLI
if (@enum.Type.IsPrimitiveType(PrimitiveType.Int32))
{
Refs.Add(string.Format("enum struct {0};", @enum.Name));
Refs.Add(new CLIForwardReference()
{
Declaration = @enum,
Text = string.Format("enum struct {0};", @enum.Name)
});
return true;
}
Refs.Add(string.Format("enum struct {0} : {1};", @enum.Name,
@enum.Type));
Refs.Add(new CLIForwardReference()
{
Declaration = @enum,
Text = string.Format("enum struct {0} : {1};", @enum.Name, @enum.Type)
});
return true;
}

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

@ -10,8 +10,6 @@ namespace Cxxi.Generators.CLI @@ -10,8 +10,6 @@ namespace Cxxi.Generators.CLI
{
public override string FileExtension { get { return "h"; } }
private CLIForwardReferencePrinter forwardRefsPrinter;
public CLIHeadersTemplate(Driver driver, TranslationUnit unit)
: base(driver, unit)
{
@ -40,7 +38,7 @@ namespace Cxxi.Generators.CLI @@ -40,7 +38,7 @@ namespace Cxxi.Generators.CLI
{
var typeRefs = TranslationUnit.TypeReferences as TypeRefsVisitor;
forwardRefsPrinter = new CLIForwardReferencePrinter(typeRefs);
var forwardRefsPrinter = new CLIForwardReferencePrinter(typeRefs);
forwardRefsPrinter.Process();
var includes = new SortedSet<string>(StringComparer.InvariantCulture);
@ -65,12 +63,20 @@ namespace Cxxi.Generators.CLI @@ -65,12 +63,20 @@ namespace Cxxi.Generators.CLI
public void GenerateForwardRefs()
{
var typeRefs = TranslationUnit.TypeReferences as TypeRefsVisitor;
var forwardRefsPrinter = new CLIForwardReferencePrinter(typeRefs);
forwardRefsPrinter.Process();
// Use a set to remove duplicate entries.
var forwardRefs = new HashSet<string>();
foreach (var forwardRef in forwardRefsPrinter.Refs)
{
forwardRefs.Add(forwardRef);
if (forwardRef.Declaration.Namespace != @namespace)
continue;
forwardRefs.Add(forwardRef.Text);
}
foreach (var forwardRef in forwardRefs)

Loading…
Cancel
Save