Browse Source

Remove the WrapperSuffix option and replace with a more general GenerateName delegate that can be hooked up by the user to customize the output name of the generated files.

pull/1/head
triton 12 years ago
parent
commit
dd03761f6c
  1. 3
      src/Generator/Diagnostics.cs
  2. 2
      src/Generator/Driver.cs
  3. 24
      src/Generator/Generators/CLI/CLIGenerator.cs
  4. 9
      src/Generator/Generators/CLI/CLISourcesTemplate.cs
  5. 13
      src/Generator/Generators/CSharp/CSharpGenerator.cs
  6. 15
      src/Generator/Generators/Generator.cs

3
src/Generator/Diagnostics.cs

@ -6,7 +6,8 @@ namespace CppSharp
{ {
AmbiguousOverload, AmbiguousOverload,
InvalidOperatorOverload, InvalidOperatorOverload,
SymbolNotFound SymbolNotFound,
FileGenerated,
} }
public enum DiagnosticKind public enum DiagnosticKind

2
src/Generator/Driver.cs

@ -259,6 +259,6 @@ namespace CppSharp
public string Assembly; public string Assembly;
public string IncludePrefix; public string IncludePrefix;
public bool WriteOnlyWhenChanged; public bool WriteOnlyWhenChanged;
public Func<TranslationUnit, string> GenerateName;
} }
} }

24
src/Generator/Generators/CLI/CLIGenerator.cs

@ -1,6 +1,5 @@
using System; using System;
using System.IO; using System.IO;
using CppSharp.Types;
namespace CppSharp.Generators.CLI namespace CppSharp.Generators.CLI
{ {
@ -18,27 +17,22 @@ namespace CppSharp.Generators.CLI
void WriteTemplate(TextTemplate template) void WriteTemplate(TextTemplate template)
{ {
var file = Path.GetFileNameWithoutExtension(template.TranslationUnit.FileName) var path = GetOutputPath(template.TranslationUnit)
+ Driver.Options.WrapperSuffix + "." + "." + template.FileExtension;
+ template.FileExtension;
var path = Path.Combine(Driver.Options.OutputDir, file);
var fullPath = Path.GetFullPath(path);
template.Generate(); template.Generate();
var text = template.ToString();
Console.WriteLine(" Generated '" + file + "'.");
var str = template.ToString();
if(Driver.Options.WriteOnlyWhenChanged) if(Driver.Options.WriteOnlyWhenChanged)
{ {
var updated = fileHashes.UpdateHash(path, str.GetHashCode()); var updated = fileHashes.UpdateHash(path, text.GetHashCode());
if(File.Exists(fullPath) && !updated) if (File.Exists(path) && !updated)
return; return;
} }
File.WriteAllText(fullPath,str); Driver.Diagnostics.EmitMessage(DiagnosticId.FileGenerated,
" Generated '{0}'.", Path.GetFileName(path));
File.WriteAllText(path, text);
} }
public override bool Generate(TranslationUnit unit) public override bool Generate(TranslationUnit unit)

9
src/Generator/Generators/CLI/CLISourcesTemplate.cs

@ -19,9 +19,12 @@ namespace CppSharp.Generators.CLI
{ {
GenerateStart(); GenerateStart();
WriteLine("#include \"{0}{1}.h\"", var file = Path.GetFileNameWithoutExtension(TranslationUnit.FileName);
TranslationUnit.FileNameWithoutExtension,
Options.WrapperSuffix); if (Driver.Options.GenerateName != null)
file = Driver.Options.GenerateName(TranslationUnit);
WriteLine("#include \"{0}{1}.h\"", file);
GenerateForwardReferenceHeaders(); GenerateForwardReferenceHeaders();

13
src/Generator/Generators/CSharp/CSharpGenerator.cs

@ -1,6 +1,5 @@
using System; using System;
using System.IO; using System.IO;
using CppSharp.Types;
namespace CppSharp.Generators.CSharp namespace CppSharp.Generators.CSharp
{ {
@ -16,16 +15,14 @@ namespace CppSharp.Generators.CSharp
void WriteTemplate(TextTemplate template) void WriteTemplate(TextTemplate template)
{ {
var file = Path.GetFileNameWithoutExtension(template.TranslationUnit.FileName) var path = GetOutputPath(template.TranslationUnit)
+ Driver.Options.WrapperSuffix + "." + "." + template.FileExtension;
+ template.FileExtension;
var path = Path.Combine(Driver.Options.OutputDir, file);
template.Generate(); template.Generate();
Console.WriteLine(" Generated '" + file + "'."); File.WriteAllText(path, template.ToString());
File.WriteAllText(Path.GetFullPath(path), template.ToString()); Driver.Diagnostics.EmitMessage(DiagnosticId.FileGenerated,
" Generated '{0}'.", Path.GetFileName(path));
} }
public override bool Generate(TranslationUnit unit) public override bool Generate(TranslationUnit unit)

15
src/Generator/Generators/Generator.cs

@ -1,4 +1,6 @@
namespace CppSharp.Generators using System.IO;
namespace CppSharp.Generators
{ {
public enum LanguageGeneratorKind public enum LanguageGeneratorKind
{ {
@ -21,5 +23,16 @@
} }
public abstract bool Generate(TranslationUnit unit); public abstract bool Generate(TranslationUnit unit);
public string GetOutputPath(TranslationUnit unit)
{
var file = unit.FileNameWithoutExtension;
if (Driver.Options.GenerateName != null)
file = Driver.Options.GenerateName(unit);
var path = Path.Combine(Driver.Options.OutputDir, file);
return Path.GetFullPath(path);
}
} }
} }
Loading…
Cancel
Save