mirror of https://github.com/mono/CppSharp.git
c-sharpdotnetmonobindingsbridgecclangcpluspluscppsharpglueinteropparserparsingpinvokeswigsyntax-treevisitorsxamarinxamarin-bindings
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.6 KiB
55 lines
1.6 KiB
using System; |
|
using System.IO; |
|
using Cxxi.Types; |
|
|
|
namespace Cxxi.Generators.CLI |
|
{ |
|
public class CLIGenerator : Generator |
|
{ |
|
private readonly CLITypePrinter typePrinter; |
|
private readonly FileHashes fileHashes; |
|
|
|
public CLIGenerator(Driver driver) : base(driver) |
|
{ |
|
typePrinter = new CLITypePrinter(driver); |
|
Type.TypePrinterDelegate += type => type.Visit(typePrinter); |
|
fileHashes = FileHashes.Load("hashes.ser"); |
|
} |
|
|
|
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); |
|
|
|
template.Generate(); |
|
|
|
Console.WriteLine(" Generated '" + file + "'."); |
|
|
|
var str = template.ToString(); |
|
|
|
if(Driver.Options.WriteOnlyWhenChanged) |
|
{ |
|
var updated = fileHashes.UpdateHash(path, str.GetHashCode()); |
|
if(File.Exists(fullPath) && !updated) |
|
return; |
|
} |
|
|
|
File.WriteAllText(fullPath,str); |
|
} |
|
|
|
public override bool Generate(TranslationUnit unit) |
|
{ |
|
var header = new CLIHeadersTemplate(Driver, unit); |
|
WriteTemplate(header); |
|
|
|
var source = new CLISourcesTemplate(Driver, unit); |
|
WriteTemplate(source); |
|
|
|
return true; |
|
} |
|
} |
|
} |