|
|
@ -1,24 +1,43 @@ |
|
|
|
using System; |
|
|
|
using Cxxi; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System; |
|
|
|
using System.Text.RegularExpressions; |
|
|
|
|
|
|
|
using System.Linq; |
|
|
|
|
|
|
|
using System.Globalization; |
|
|
|
using System.Globalization; |
|
|
|
using Cxxi; |
|
|
|
using System.Text.RegularExpressions; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Used to massage the library types into something more .NET friendly.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
public interface LibraryTransform |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
public void Transform(Generator g); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public abstract class Transformation |
|
|
|
/// <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 |
|
|
|
{ |
|
|
|
{ |
|
|
|
public virtual bool ProcessType(Declaration type) |
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Processes a declaration.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
public virtual bool ProcessDeclaration(Declaration declaration) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Processes an enum item.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
public virtual bool ProcessEnumItem(Enumeration.Item item) |
|
|
|
public virtual bool ProcessEnumItem(Enumeration.Item item) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public class RenameTransform : Transformation |
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Renames a declaration based on a regular expression pattern.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
public class RenameTransform : ModuleTransform |
|
|
|
{ |
|
|
|
{ |
|
|
|
public string Pattern; |
|
|
|
public string Pattern; |
|
|
|
public string Replacement; |
|
|
|
public string Replacement; |
|
|
@ -29,7 +48,7 @@ public class RenameTransform : Transformation |
|
|
|
Replacement = replacement; |
|
|
|
Replacement = replacement; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public override bool ProcessType(Declaration type) |
|
|
|
public override bool ProcessDeclaration(Declaration type) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return Rename(ref type.Name); |
|
|
|
return Rename(ref type.Name); |
|
|
|
} |
|
|
|
} |
|
|
@ -55,6 +74,8 @@ public class RenameTransform : Transformation |
|
|
|
|
|
|
|
|
|
|
|
public partial class Generator |
|
|
|
public partial class Generator |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
#region Transform Operations
|
|
|
|
|
|
|
|
|
|
|
|
public void RemovePrefix(string prefix) |
|
|
|
public void RemovePrefix(string prefix) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Transformations.Add(new RenameTransform(prefix, String.Empty)); |
|
|
|
Transformations.Add(new RenameTransform(prefix, String.Empty)); |
|
|
@ -65,41 +86,22 @@ public partial class Generator |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Enumeration FindEnum(string name) |
|
|
|
#endregion
|
|
|
|
{ |
|
|
|
|
|
|
|
foreach (var module in Library.Modules) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
var @enum = module.Global.FindEnumWithName(name); |
|
|
|
|
|
|
|
if (@enum != null) |
|
|
|
|
|
|
|
return @enum; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
#region Enum Helpers
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Enumeration GetEnumWithMatchingItem(string Pattern) |
|
|
|
public Enumeration FindEnum(string name) |
|
|
|
{ |
|
|
|
{ |
|
|
|
foreach (var module in Library.Modules) |
|
|
|
foreach (var module in Library.Modules) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Enumeration @enum = module.Global.FindEnumWithItem(Pattern); |
|
|
|
var @enum = module.FindEnum(name); |
|
|
|
if (@enum == null) continue; |
|
|
|
if (@enum != null) |
|
|
|
return @enum; |
|
|
|
return @enum; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Module IgnoreModuleWithName(string Pattern) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Module module = Library.Modules.Find( |
|
|
|
|
|
|
|
m => Regex.Match(m.FilePath, Pattern).Success); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (module != null) |
|
|
|
|
|
|
|
module.Ignore = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return module; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void IgnoreEnumWithMatchingItem(string Pattern) |
|
|
|
public void IgnoreEnumWithMatchingItem(string Pattern) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Enumeration @enum = GetEnumWithMatchingItem(Pattern); |
|
|
|
Enumeration @enum = GetEnumWithMatchingItem(Pattern); |
|
|
@ -114,26 +116,23 @@ public partial class Generator |
|
|
|
@enum.Name = Name; |
|
|
|
@enum.Name = Name; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static bool ParseToNumber(string num, out long val) |
|
|
|
public void SetNameOfEnumWithName(string enumName, string name) |
|
|
|
{ |
|
|
|
|
|
|
|
if (num.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase)) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
num = num.Substring(2); |
|
|
|
Enumeration @enum = FindEnum(enumName); |
|
|
|
|
|
|
|
if (@enum != null) |
|
|
|
return long.TryParse(num, NumberStyles.HexNumber, |
|
|
|
@enum.Name = name; |
|
|
|
CultureInfo.CurrentCulture, out val); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return long.TryParse(num, out val); |
|
|
|
public Enumeration GetEnumWithMatchingItem(string Pattern) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
foreach (var module in Library.Modules) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Enumeration @enum = module.FindEnumWithItem(Pattern); |
|
|
|
|
|
|
|
if (@enum == null) continue; |
|
|
|
|
|
|
|
return @enum; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static long ParseMacroExpression(string Expression) |
|
|
|
return null; |
|
|
|
{ |
|
|
|
|
|
|
|
long val; |
|
|
|
|
|
|
|
if (ParseToNumber(Expression, out val)) |
|
|
|
|
|
|
|
return val; |
|
|
|
|
|
|
|
// TODO: Handle string expressions
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Enumeration.Item GenerateEnumItemFromMacro(MacroDefine macro) |
|
|
|
public Enumeration.Item GenerateEnumItemFromMacro(MacroDefine macro) |
|
|
@ -146,12 +145,12 @@ public partial class Generator |
|
|
|
return item; |
|
|
|
return item; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Enumeration GenerateEnumFromMacros(string Name, params string[] Macros) |
|
|
|
public Enumeration GenerateEnumFromMacros(string name, params string[] macros) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Enumeration @enum = new Enumeration(); |
|
|
|
Enumeration @enum = new Enumeration(); |
|
|
|
@enum.Name = Name; |
|
|
|
@enum.Name = name; |
|
|
|
|
|
|
|
|
|
|
|
var pattern = String.Join("|", Macros); |
|
|
|
var pattern = String.Join("|", macros); |
|
|
|
var regex = new Regex(pattern); |
|
|
|
var regex = new Regex(pattern); |
|
|
|
|
|
|
|
|
|
|
|
foreach (var module in Library.Modules) |
|
|
|
foreach (var module in Library.Modules) |
|
|
@ -167,11 +166,97 @@ public partial class Generator |
|
|
|
|
|
|
|
|
|
|
|
if (@enum.Items.Count > 0) |
|
|
|
if (@enum.Items.Count > 0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
module.Global.Enums.Add(@enum); |
|
|
|
module.Enums.Add(@enum); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return @enum; |
|
|
|
return @enum; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region Class Helpers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Class FindClass(string name) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
foreach (var module in Library.Modules) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
var @class = module.FindClass(name); |
|
|
|
|
|
|
|
if (@class != null) |
|
|
|
|
|
|
|
return @class; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void SetNameOfClassWithName(string className, string name) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Class @class = FindClass(className); |
|
|
|
|
|
|
|
if (@class != null) |
|
|
|
|
|
|
|
@class.Name = name; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region Function Helpers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Function FindFunction(string name) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
foreach (var module in Library.Modules) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
var function = module.FindFunction(name); |
|
|
|
|
|
|
|
if (function != null) |
|
|
|
|
|
|
|
return function; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void IgnoreFunctionWithName(string name) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Function function = FindFunction(name); |
|
|
|
|
|
|
|
if (function != null) |
|
|
|
|
|
|
|
function.Ignore = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region Module Helpers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Module IgnoreModuleWithName(string Pattern) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Module module = Library.Modules.Find( |
|
|
|
|
|
|
|
m => Regex.Match(m.FilePath, Pattern).Success); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (module != null) |
|
|
|
|
|
|
|
module.Ignore = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return module; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static bool ParseToNumber(string num, out long val) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (num.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
num = num.Substring(2); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return long.TryParse(num, NumberStyles.HexNumber, |
|
|
|
|
|
|
|
CultureInfo.CurrentCulture, out val); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return long.TryParse(num, out val); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static long ParseMacroExpression(string Expression) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
long val; |
|
|
|
|
|
|
|
if (ParseToNumber(Expression, out val)) |
|
|
|
|
|
|
|
return val; |
|
|
|
|
|
|
|
// TODO: Handle string expressions
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |