Browse Source

Moved Diagnostics class to new core project.

pull/86/head
triton 12 years ago
parent
commit
be0f73f471
  1. 1
      build/premake4.lua
  2. 6
      src/Core/Diagnostics.cs
  3. 107
      src/Generator/Generators/Generator.cs

1
build/premake4.lua

@ -40,6 +40,7 @@ solution "CppSharp" @@ -40,6 +40,7 @@ solution "CppSharp"
IncludeTests()
group "Libraries"
include (srcdir .. "/Core")
include (srcdir .. "/AST/AST.lua")
include (srcdir .. "/Generator/Generator.lua")
include (srcdir .. "/Generator.Tests/Generator.Tests.lua")

6
src/Generator/Diagnostics.cs → src/Core/Diagnostics.cs

@ -15,6 +15,9 @@ namespace CppSharp @@ -15,6 +15,9 @@ namespace CppSharp
PropertySynthetized
}
/// <summary>
/// Represents the kind of the diagnostic.
/// </summary>
public enum DiagnosticKind
{
Debug,
@ -23,6 +26,9 @@ namespace CppSharp @@ -23,6 +26,9 @@ namespace CppSharp
Error
}
/// <summary>
/// Keeps information related to a single diagnostic.
/// </summary>
public struct DiagnosticInfo
{
public DiagnosticKind Kind;

107
src/Generator/Generators/Generator.cs

@ -1,107 +0,0 @@ @@ -1,107 +0,0 @@
using System;
using System.Collections.Generic;
using CppSharp.AST;
namespace CppSharp.Generators
{
/// <summary>
/// Kinds of language generators.
/// </summary>
public enum LanguageGeneratorKind
{
CLI,
CSharp,
}
/// <summary>
/// Output generated by each backend generator.
/// </summary>
public struct GeneratorOutput
{
/// <summary>
/// Translation unit associated with output.
/// </summary>
public TranslationUnit TranslationUnit;
/// <summary>
/// Text templates with generated output.
/// </summary>
public List<Template> Templates;
}
/// <summary>
/// Generators are the base class for each language backend.
/// </summary>
public abstract class Generator
{
public Driver Driver { get; private set; }
protected Generator(Driver driver)
{
Driver = driver;
}
/// <summary>
/// Called when a translation unit is generated.
/// </summary>
public Action<GeneratorOutput> OnUnitGenerated = delegate { };
/// <summary>
/// Setup any generator-specific passes here.
/// </summary>
public abstract bool SetupPasses();
/// <summary>
/// Setup any generator-specific processing here.
/// </summary>
public virtual void Process()
{
}
/// <summary>
/// Generates the outputs.
/// </summary>
public virtual List<GeneratorOutput> Generate()
{
var outputs = new List<GeneratorOutput>();
foreach (var unit in Driver.Library.TranslationUnits)
{
if (unit.Ignore || !unit.HasDeclarations)
continue;
if (unit.IsSystemHeader)
continue;
var templates = Generate(unit);
if (templates.Count == 0)
continue;
foreach (var template in templates)
template.Process();
var output = new GeneratorOutput
{
TranslationUnit = unit,
Templates = templates
};
outputs.Add(output);
OnUnitGenerated(output);
}
return outputs;
}
/// <summary>
/// Generates the outputs for a given translation unit.
/// </summary>
public abstract List<Template> Generate(TranslationUnit unit);
public static string GeneratedIdentifier(string id)
{
return "__" + id;
}
}
}
Loading…
Cancel
Save