Browse Source

Hooked up typedef processing to the code generator.

pull/1/head
triton 13 years ago
parent
commit
f2cc4c6d00
  1. 79
      src/Generator/Generator.cs

79
src/Generator/Generator.cs

@ -33,7 +33,7 @@ namespace Cxxi
GenerateModules(); GenerateModules();
} }
int UniqueType = 0; int UniqueName = 0;
void CleanupText(ref string debugText) void CleanupText(ref string debugText)
{ {
@ -46,34 +46,50 @@ namespace Cxxi
debugText = Regex.Replace(debugText, "\n", ""); debugText = Regex.Replace(debugText, "\n", "");
} }
void ProcessType(Declaration type) void ProcessDeclaration(Declaration decl)
{ {
// If after all the transformations the type still does // If after all the transformations the type still does
// not have a name, then generate one. // not have a name, then generate one.
if (String.IsNullOrWhiteSpace(type.Name)) if (string.IsNullOrWhiteSpace(decl.Name))
type.Name = String.Format("UnnamedType{0}", UniqueType++); decl.Name = string.Format("Unnamed{0}", UniqueName++);
CleanupText(ref type.DebugText); CleanupText(ref decl.DebugText);
} }
void ProcessTypes<T>(List<T> types) where T : Declaration void ProcessDeclarations<T>(List<T> decls) where T : Declaration
{ {
foreach (T type in types) foreach (T decl in decls)
ProcessType(type); ProcessDeclaration(decl);
} }
void ProcessClasses(List<Class> Classes) void ProcessClasses(List<Class> classes)
{ {
ProcessTypes(Classes); ProcessDeclarations(classes);
foreach (var @class in Classes) foreach (var @class in classes)
ProcessTypes(@class.Fields); ProcessDeclarations(@class.Fields);
}
void ProcessTypedefs(Namespace @namespace, List<Typedef> typedefs)
{
ProcessDeclarations(typedefs);
foreach (var typedef in typedefs)
{
var @class = @namespace.FindClass(typedef.Name);
// Clang will walk the typedef'd tag type and the typedef decl,
// so we ignore the class and process just the typedef.
if (@class != null)
typedef.Ignore = true;
}
} }
void ProcessFunctions(List<Function> Functions) void ProcessFunctions(List<Function> Functions)
{ {
ProcessTypes(Functions); ProcessDeclarations(Functions);
foreach (var function in Functions) foreach (var function in Functions)
{ {
@ -86,13 +102,16 @@ namespace Cxxi
Console.WriteLine(String.Format(s, function.Name)); Console.WriteLine(String.Format(s, function.Name));
} }
ProcessTypes(function.Parameters); foreach (var param in function.Parameters)
{
ProcessDeclaration(param);
}
} }
} }
void ProcessModules() void ProcessModules()
{ {
if (String.IsNullOrEmpty(Library.Name)) if (string.IsNullOrEmpty(Library.Name))
Library.Name = ""; Library.Name = "";
// Process everything in the global namespace for now. // Process everything in the global namespace for now.
@ -104,15 +123,16 @@ namespace Cxxi
void ProcessNamespace(Namespace @namespace) void ProcessNamespace(Namespace @namespace)
{ {
ProcessTypes(@namespace.Enums); ProcessDeclarations(@namespace.Enums);
ProcessFunctions(@namespace.Functions); ProcessFunctions(@namespace.Functions);
ProcessClasses(@namespace.Classes); ProcessClasses(@namespace.Classes);
ProcessTypedefs(@namespace, @namespace.Typedefs);
} }
void TransformModule() void TransformModule()
{ {
if (String.IsNullOrEmpty(Library.Name)) if (string.IsNullOrEmpty(Library.Name))
Library.Name = ""; Library.Name = string.Empty;
// Process everything in the global namespace for now. // Process everything in the global namespace for now.
foreach (var module in Library.Modules) foreach (var module in Library.Modules)
@ -125,35 +145,44 @@ namespace Cxxi
foreach (Class @class in module.Classes) foreach (Class @class in module.Classes)
TransformClass(@class); TransformClass(@class);
foreach (Typedef typedef in module.Typedefs)
TransformTypedef(typedef);
} }
} }
void TransformType(Declaration type) void TransformDeclaration(Declaration decl)
{
foreach (var transform in Transformations)
transform.ProcessDeclaration(decl);
}
void TransformTypedef(Typedef typedef)
{ {
foreach (var transform in Transformations) foreach (var transform in Transformations)
transform.ProcessDeclaration(type); transform.ProcessDeclaration(typedef);
} }
void TransformClass(Class @class) void TransformClass(Class @class)
{ {
TransformType(@class); TransformDeclaration(@class);
foreach (var field in @class.Fields) foreach (var field in @class.Fields)
TransformType(field); TransformDeclaration(field);
} }
void TransformFunction(Function function) void TransformFunction(Function function)
{ {
TransformType(function); TransformDeclaration(function);
foreach (var param in function.Parameters) foreach (var param in function.Parameters)
TransformType(param); TransformDeclaration(param);
} }
void TransformEnum(Enumeration @enum) void TransformEnum(Enumeration @enum)
{ {
TransformType(@enum); TransformDeclaration(@enum);
foreach (var transform in Transformations) foreach (var transform in Transformations)
{ {

Loading…
Cancel
Save