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 @@ -6,7 +6,8 @@ namespace CppSharp
{
AmbiguousOverload,
InvalidOperatorOverload,
SymbolNotFound
SymbolNotFound,
FileGenerated,
}
public enum DiagnosticKind

2
src/Generator/Driver.cs

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

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

@ -1,6 +1,5 @@ @@ -1,6 +1,5 @@
using System;
using System.IO;
using CppSharp.Types;
namespace CppSharp.Generators.CLI
{
@ -18,27 +17,22 @@ namespace CppSharp.Generators.CLI @@ -18,27 +17,22 @@ namespace CppSharp.Generators.CLI
void WriteTemplate(TextTemplate template)
{
var file = Path.GetFileNameWithoutExtension(template.TranslationUnit.FileName)
+ Driver.Options.WrapperSuffix + "."
+ template.FileExtension;
var path = Path.Combine(Driver.Options.OutputDir, file);
var fullPath = Path.GetFullPath(path);
var path = GetOutputPath(template.TranslationUnit)
+ "." + template.FileExtension;
template.Generate();
Console.WriteLine(" Generated '" + file + "'.");
var str = template.ToString();
var text = template.ToString();
if(Driver.Options.WriteOnlyWhenChanged)
{
var updated = fileHashes.UpdateHash(path, str.GetHashCode());
if(File.Exists(fullPath) && !updated)
var updated = fileHashes.UpdateHash(path, text.GetHashCode());
if (File.Exists(path) && !updated)
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)

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

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

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

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

15
src/Generator/Generators/Generator.cs

@ -1,4 +1,6 @@ @@ -1,4 +1,6 @@
namespace CppSharp.Generators
using System.IO;
namespace CppSharp.Generators
{
public enum LanguageGeneratorKind
{
@ -21,5 +23,16 @@ @@ -21,5 +23,16 @@
}
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