Browse Source

Renamed a few functions and factored out the SDL transforms.

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

13
src/Generator/Program.cs

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

7
src/Generator/SDL.cs

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

56
src/Generator/Transform.cs

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