diff --git a/src/Generator/Generators/CLI/CLIForwardRefeferencePrinter.cs b/src/Generator/Generators/CLI/CLIForwardRefeferencePrinter.cs new file mode 100644 index 00000000..cb0ea7fb --- /dev/null +++ b/src/Generator/Generators/CLI/CLIForwardRefeferencePrinter.cs @@ -0,0 +1,134 @@ +using System; +using System.Collections.Generic; +using System.IO; + +namespace Cxxi.Generators.CLI +{ + public class CLIForwardRefeferencePrinter : IDeclVisitor + { + 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 bool VisitClassDecl(Class @class) + { + var completeDecl = @class.CompleteDeclaration as Class; + if (@class.IsIncomplete && completeDecl != null) + return VisitClassDecl(completeDecl); + + if (@class.IsValueType) + { + Refs.Add(string.Format("value struct {0};", @class.Name)); + return true; + } + + Refs.Add(string.Format("ref class {0};", @class.Name)); + return true; + } + + public bool VisitFieldDecl(Field field) + { + Class @class; + if (field.Type.IsTagDecl(out @class)) + { + if (@class.IsValueType) + Includes.Add(GetHeaderFromDecl(@class)); + else + VisitClassDecl(@class); + + return true; + } + + Enumeration @enum; + if (field.Type.IsTagDecl(out @enum)) + return VisitEnumDecl(@enum); + + Includes.Add(GetHeaderFromDecl(field)); + return true; + } + + public bool VisitFunctionDecl(Function function) + { + throw new NotImplementedException(); + } + + public bool VisitMethodDecl(Method method) + { + throw new NotImplementedException(); + } + + public bool VisitParameterDecl(Parameter parameter) + { + throw new NotImplementedException(); + } + + 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 bool VisitEnumDecl(Enumeration @enum) + { + if (@enum.Type.IsPrimitiveType(PrimitiveType.Int32)) + { + 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 bool VisitClassTemplateDecl(ClassTemplate template) + { + throw new NotImplementedException(); + } + + public bool VisitFunctionTemplateDecl(FunctionTemplate template) + { + throw new NotImplementedException(); + } + + public bool VisitMacroDefinition(MacroDefinition macro) + { + throw new NotImplementedException(); + } + + public bool VisitNamespace(Namespace @namespace) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/src/Generator/Generators/CLI/CLIHelpers.cs b/src/Generator/Generators/CLI/CLIHelpers.cs index b14390c3..f267c9c4 100644 --- a/src/Generator/Generators/CLI/CLIHelpers.cs +++ b/src/Generator/Generators/CLI/CLIHelpers.cs @@ -1,138 +1,9 @@ using System; -using System.Collections.Generic; using System.IO; using Cxxi.Types; namespace Cxxi.Generators.CLI { - public class CLIForwardRefeferencePrinter : IDeclVisitor - { - 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 bool VisitClassDecl(Class @class) - { - var completeDecl = @class.CompleteDeclaration as Class; - if (@class.IsIncomplete && completeDecl != null) - return VisitClassDecl(completeDecl); - - if (@class.IsValueType) - { - Refs.Add(string.Format("value struct {0};", @class.Name)); - return true; - } - - Refs.Add(string.Format("ref class {0};", @class.Name)); - return true; - } - - public bool VisitFieldDecl(Field field) - { - Class @class; - if (field.Type.IsTagDecl(out @class)) - { - if (@class.IsValueType) - Includes.Add(GetHeaderFromDecl(@class)); - else - VisitClassDecl(@class); - - return true; - } - - Enumeration @enum; - if (field.Type.IsTagDecl(out @enum)) - return VisitEnumDecl(@enum); - - Includes.Add(GetHeaderFromDecl(field)); - return true; - } - - public bool VisitFunctionDecl(Function function) - { - throw new NotImplementedException(); - } - - public bool VisitMethodDecl(Method method) - { - throw new NotImplementedException(); - } - - public bool VisitParameterDecl(Parameter parameter) - { - throw new NotImplementedException(); - } - - 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 bool VisitEnumDecl(Enumeration @enum) - { - if (@enum.Type.IsPrimitiveType(PrimitiveType.Int32)) - { - 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 bool VisitClassTemplateDecl(ClassTemplate template) - { - throw new NotImplementedException(); - } - - public bool VisitFunctionTemplateDecl(FunctionTemplate template) - { - throw new NotImplementedException(); - } - - public bool VisitMacroDefinition(MacroDefinition macro) - { - throw new NotImplementedException(); - } - - public bool VisitNamespace(Namespace @namespace) - { - throw new NotImplementedException(); - } - } - #region CLI Text Templates public abstract class CLITextTemplate : TextTemplate {