From 61a6811816253331953e2b44181ae224d3a1dd85 Mon Sep 17 00:00:00 2001 From: triton Date: Fri, 18 Jan 2013 16:59:50 +0000 Subject: [PATCH] Improved the printing of CLI forward references. --- src/Generator/Generators/CLI/CLIHelpers.cs | 85 +++++++++++++++++----- 1 file changed, 67 insertions(+), 18 deletions(-) diff --git a/src/Generator/Generators/CLI/CLIHelpers.cs b/src/Generator/Generators/CLI/CLIHelpers.cs index 781fa5f2..e459fe45 100644 --- a/src/Generator/Generators/CLI/CLIHelpers.cs +++ b/src/Generator/Generators/CLI/CLIHelpers.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.IO; using Cxxi.Types; @@ -243,64 +244,112 @@ namespace Cxxi.Generators.CLI } } - public class CLIForwardRefeferencePrinter : IDeclVisitor + public class CLIForwardRefeferencePrinter : IDeclVisitor { - public string VisitDeclaration(Declaration decl) + public readonly IList Includes; + public readonly IList Refs; + + public CLIForwardRefeferencePrinter() + { + Includes = new List(); + Refs = new List(); + } + + public bool VisitDeclaration(Declaration decl) { throw new NotImplementedException(); } - public string VisitClassDecl(Class @class) + public bool VisitClassDecl(Class @class) { if (@class.IsValueType) - return string.Format("value struct {0};", @class.Name); - return string.Format("ref class {0};", @class.Name); + { + Refs.Add(string.Format("value struct {0};", @class.Name)); + return true; + } + + Refs.Add(string.Format("ref class {0};", @class.Name)); + return true; } - public string VisitFieldDecl(Field field) + public bool VisitFieldDecl(Field field) { - throw new NotImplementedException(); + Class @class; + if (field.Type.IsTagDecl(out @class)) + { + Includes.Add(GetHeaderFromDecl(@class)); + return true; + } + + Includes.Add(GetHeaderFromDecl(field)); + return true; } - public string VisitFunctionDecl(Function function) + public bool VisitFunctionDecl(Function function) { throw new NotImplementedException(); } - public string VisitMethodDecl(Method method) + public bool VisitMethodDecl(Method method) { throw new NotImplementedException(); } - public string VisitParameterDecl(Parameter parameter) + public bool VisitParameterDecl(Parameter parameter) { throw new NotImplementedException(); } - public string VisitTypedefDecl(TypedefDecl typedef) + public string GetHeaderFromDecl(Declaration decl) { + var @namespace = decl.Namespace; + var unit = @namespace.TranslationUnit; + + if (unit.Ignore) + return string.Empty; + + if (unit.IsSystemHeader) + return string.Empty; + + return Path.GetFileNameWithoutExtension(unit.FileName); + } + + public bool VisitTypedefDecl(TypedefDecl typedef) + { + FunctionType function; + if (typedef.Type.IsPointerTo(out function)) + { + Includes.Add(GetHeaderFromDecl(typedef)); + return true; + } + throw new NotImplementedException(); } - public string VisitEnumDecl(Enumeration @enum) + public bool VisitEnumDecl(Enumeration @enum) { if (@enum.Type.IsPrimitiveType(PrimitiveType.Int32)) - return string.Format("enum struct {0};", @enum.Name); - return string.Format("enum struct {0} : {1};", @enum.Name, - @enum.Type); + { + Refs.Add(string.Format("enum struct {0};", @enum.Name)); + return true; + } + + Refs.Add(string.Format("enum struct {0} : {1};", @enum.Name, + @enum.Type)); + return true; } - public string VisitClassTemplateDecl(ClassTemplate template) + public bool VisitClassTemplateDecl(ClassTemplate template) { throw new NotImplementedException(); } - public string VisitFunctionTemplateDecl(FunctionTemplate template) + public bool VisitFunctionTemplateDecl(FunctionTemplate template) { throw new NotImplementedException(); } - public string VisitMacroDefinition(MacroDefinition macro) + public bool VisitMacroDefinition(MacroDefinition macro) { throw new NotImplementedException(); }