Browse Source

Renamed a few functions and factored out the SDL transforms.

pull/1/head
triton 13 years ago
parent
commit
b84196c0b7
  1. 13
      src/Generator/Generator.cs
  2. 13
      src/Generator/Program.cs
  3. 7
      src/Generator/SDL.cs
  4. 56
      src/Generator/Transform.cs

13
src/Generator/Generator.cs

@ -1,13 +1,13 @@ @@ -1,13 +1,13 @@
using System;
using Cxxi.Templates;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using Cxxi;
using Cxxi.Templates;
public partial class Generator
namespace Cxxi
{
public partial class Generator
{
public List<ModuleTransform> Transformations { get; set; }
Library Library;
@ -83,7 +83,7 @@ public partial class Generator @@ -83,7 +83,7 @@ public partial class Generator
function.Ignore = true;
var s = "Function '{0}' was ignored due to unknown return type...";
Console.WriteLine( String.Format(s, function.Name) );
Console.WriteLine(String.Format(s, function.Name));
}
ProcessTypes(function.Parameters);
@ -238,4 +238,5 @@ public partial class Generator @@ -238,4 +238,5 @@ public partial class Generator
File.WriteAllText(path, code);
}
}
}
}

13
src/Generator/Program.cs

@ -69,14 +69,20 @@ class Program @@ -69,14 +69,20 @@ class Program
Library library;
Options options;
public void GenerateCode()
public void GenerateCode(LibraryTransform libTransform)
{
Console.WriteLine("Generating wrapper code...");
if (library.Modules.Count > 0)
{
var gen = new Generator(library, options);
TransformSDL(gen);
libTransform.Preprocess(gen);
gen.Process();
libTransform.Postprocess(gen);
gen.Generate();
}
}
@ -126,7 +132,8 @@ class Program @@ -126,7 +132,8 @@ class Program
library = new Library(options.OutputNamespace);
ParseCode();
GenerateCode();
GenerateCode(new SDLTransforms());
}
static void Main(String[] args)

7
src/Generator/SDL.cs

@ -6,7 +6,7 @@ namespace Cxxi @@ -6,7 +6,7 @@ namespace Cxxi
/// </summary>
class SDLTransforms : LibraryTransform
{
public override void Transform(Generator g)
public void Preprocess(Generator g)
{
g.IgnoreEnumWithMatchingItem("SDL_FALSE");
g.IgnoreEnumWithMatchingItem("DUMMY_ENUM_VALUE");
@ -40,9 +40,10 @@ namespace Cxxi @@ -40,9 +40,10 @@ namespace Cxxi
g.RemovePrefix("SDLK_");
g.RemovePrefix("KMOD_");
g.RemovePrefix("LOG_CATEGORY_");
}
g.Process();
public void Postprocess(Generator g)
{
g.SetNameOfEnumWithName("PIXELTYPE", "PixelType");
g.SetNameOfEnumWithName("BITMAPORDER", "BitmapOrder");
g.SetNameOfEnumWithName("PACKEDORDER", "PackedOrder");

56
src/Generator/Transform.cs

@ -1,22 +1,31 @@ @@ -1,22 +1,31 @@
using Cxxi;
using System;
using System;
using System.Globalization;
using System.Text.RegularExpressions;
/// <summary>
/// Used to massage the library types into something more .NET friendly.
/// </summary>
public interface LibraryTransform
namespace Cxxi
{
public void Transform(Generator g);
}
/// <summary>
/// Used to massage the library types into something more .NET friendly.
/// </summary>
public interface LibraryTransform
{
/// <summary>
/// Do transformations that should happen before processing here.
/// </summary>
void Preprocess(Generator g);
/// <summary>
/// Used to provide different types of code transformation on a module
/// declarations and types before the code generation process is started.
/// </summary>
public abstract class ModuleTransform
{
/// <summary>
/// Do transformations that should happen after processing here.
/// </summary>
void Postprocess(Generator g);
}
/// <summary>
/// Used to provide different types of code transformation on a module
/// declarations and types before the code generation process is started.
/// </summary>
public abstract class ModuleTransform
{
/// <summary>
/// Processes a declaration.
/// </summary>
@ -32,13 +41,13 @@ public abstract class ModuleTransform @@ -32,13 +41,13 @@ public abstract class ModuleTransform
{
return false;
}
}
}
/// <summary>
/// Renames a declaration based on a regular expression pattern.
/// </summary>
public class RenameTransform : ModuleTransform
{
/// <summary>
/// Renames a declaration based on a regular expression pattern.
/// </summary>
public class RenameTransform : ModuleTransform
{
public string Pattern;
public string Replacement;
@ -70,10 +79,10 @@ public class RenameTransform : ModuleTransform @@ -70,10 +79,10 @@ public class RenameTransform : ModuleTransform
return false;
}
}
}
public partial class Generator
{
public partial class Generator
{
#region Transform Operations
public void RemovePrefix(string prefix)
@ -259,4 +268,5 @@ public partial class Generator @@ -259,4 +268,5 @@ public partial class Generator
return 0;
}
}
}
Loading…
Cancel
Save