diff --git a/src/Generator/Driver.cs b/src/Generator/Driver.cs index 5816a273..4bab6bd2 100644 --- a/src/Generator/Driver.cs +++ b/src/Generator/Driver.cs @@ -12,15 +12,14 @@ namespace Cxxi public class Driver { private readonly Options options; - private readonly Library library; private readonly ILibrary transform; private readonly TypeMapDatabase typeDatabase; + private Library library; public Driver(Options options, ILibrary transform) { this.options = options; this.transform = transform; - this.library = new Library(options.OutputNamespace, options.LibraryName); typeDatabase = new TypeMapDatabase(); typeDatabase.SetupTypeMaps(); } @@ -32,32 +31,11 @@ namespace Cxxi var headers = new List(); transform.SetupHeaders(headers); - foreach (var header in headers) - ParseHeader(header); + var parser = new Parser(options); + parser.ParseHeaders(headers); + parser.ParseHeaders(options.Headers); - foreach (var header in options.Headers) - ParseHeader(header); - } - - void ParseHeader(string file) - { - var parserOptions = new ParserOptions - { - Library = library, - Verbose = false, - IncludeDirs = options.IncludeDirs, - FileName = file, - Defines = options.Defines, - toolSetToUse = options.ToolsetToUse - }; - - if (!ClangParser.Parse(parserOptions)) - { - Console.WriteLine(" Could not parse '" + file + "'."); - return; - } - - Console.WriteLine(" Parsed '" + file + "'."); + library = parser.Library; } public void ProcessCode() diff --git a/src/Generator/Parser.cs b/src/Generator/Parser.cs new file mode 100644 index 00000000..7ac366b1 --- /dev/null +++ b/src/Generator/Parser.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; + +namespace Cxxi +{ + public class Parser + { + public Library Library { get; private set; } + private readonly Options options; + + public Parser(Options options) + { + this.options = options; + Library = new Library(options.OutputNamespace, options.LibraryName); + } + + public void ParseHeaders(IEnumerable headers) + { + foreach (var header in headers) + ParseHeader(header); + } + + bool ParseHeader(string file) + { + var parserOptions = new ParserOptions + { + Library = Library, + FileName = file, + Verbose = false, + IncludeDirs = options.IncludeDirs, + Defines = options.Defines, + toolSetToUse = options.ToolsetToUse + }; + + if (!ClangParser.Parse(parserOptions)) + { + //Console.WriteLine(" Could not parse '" + file + "'."); + return false; + } + + //Console.WriteLine(" Parsed '" + file + "'."); + return true; + } + } +}