From d4e80fe5663af941b27f7002c277bbb96835158b Mon Sep 17 00:00:00 2001 From: Tarmo Pikaro Date: Sun, 13 Jan 2013 10:03:36 +0200 Subject: [PATCH] Make -a command line optional, fix #include's, disable warnings. --- src/Generator/CodeGenerator.cs | 9 +++++++-- src/Generator/Generators/CLI/CLIHelpers.cs | 16 ++++++++++++++-- src/Generator/Transforms/Transform.cs | 8 +++++--- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/Generator/CodeGenerator.cs b/src/Generator/CodeGenerator.cs index 15115d40..4f4aee42 100644 --- a/src/Generator/CodeGenerator.cs +++ b/src/Generator/CodeGenerator.cs @@ -185,8 +185,7 @@ namespace Cxxi if (string.IsNullOrWhiteSpace(path)) { - Console.WriteLine("Error: no assembly provided"); - return false; + return true; } try @@ -221,6 +220,12 @@ namespace Cxxi if (!ParseCommandLineOptions(args, options)) return; + // We need to know absolute pathes in order to determine correct include pathes. + for (int i = 0; i < options.IncludeDirs.Count; i++) + { + if (options.IncludeDirs[i] == ".") options.IncludeDirs[i] = Directory.GetCurrentDirectory(); + } + ILibrary library = null; if (!ParseLibraryAssembly(options.Assembly, out library)) return; diff --git a/src/Generator/Generators/CLI/CLIHelpers.cs b/src/Generator/Generators/CLI/CLIHelpers.cs index 806383b5..05fe2624 100644 --- a/src/Generator/Generators/CLI/CLIHelpers.cs +++ b/src/Generator/Generators/CLI/CLIHelpers.cs @@ -404,12 +404,24 @@ namespace Cxxi.Generators.CLI public void GenerateStart() { - Transform.GenerateStart(this); + if( Transform == null) + { + WriteLine("//----------------------------------------------------------------------------"); + WriteLine("// This is autogenerated code by cxxi-generator."); + WriteLine("// Do not edit this file or all your changes will be lost after re-generation."); + WriteLine("//----------------------------------------------------------------------------"); + + if( FileExtension == "cpp" ) + WriteLine(@"#include ""interop.h"" // marshalString"); + + }else + Transform.GenerateStart(this); } public void GenerateAfterNamespaces() { - Transform.GenerateAfterNamespaces(this); + if (Transform != null) + Transform.GenerateAfterNamespaces(this); } public void GenerateSummary(string comment) diff --git a/src/Generator/Transforms/Transform.cs b/src/Generator/Transforms/Transform.cs index 8f39e668..1118f454 100644 --- a/src/Generator/Transforms/Transform.cs +++ b/src/Generator/Transforms/Transform.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; namespace Cxxi.Passes { @@ -21,6 +22,7 @@ namespace Cxxi.Passes string GetIncludePath(string filePath) { string includePath = filePath; + string ShortestIncludePath = filePath; foreach (var path in Options.IncludeDirs) { @@ -29,11 +31,11 @@ namespace Cxxi.Passes string inc = filePath.Substring(path.Length); - if (inc.Length < includePath.Length) - includePath = inc; + if (inc.Length < includePath.Length && inc.Length < ShortestIncludePath.Length) + ShortestIncludePath = inc; } - return includePath.TrimStart(new char[] { '\\', '/' }); + return "..\\" + ShortestIncludePath.TrimStart(new char[] { '\\', '/' }); } void TransformModule(TranslationUnit unit)