Browse Source

Extract namespace-level functions and variable generation into its own method.

pull/818/head
Joao Matos 9 years ago
parent
commit
2bba0d6486
  1. 40
      src/Generator/Generators/CSharp/CSharpSources.cs

40
src/Generator/Generators/CSharp/CSharpSources.cs

@ -219,29 +219,34 @@ namespace CppSharp.Generators.CSharp
public override bool VisitDeclContext(DeclarationContext context) public override bool VisitDeclContext(DeclarationContext context)
{ {
// Generate all the enum declarations.
foreach (var @enum in context.Enums) foreach (var @enum in context.Enums)
{
GenerateEnum(@enum); GenerateEnum(@enum);
}
// Generate all the typedef declarations.
foreach (var typedef in context.Typedefs) foreach (var typedef in context.Typedefs)
{
GenerateTypedef(typedef); GenerateTypedef(typedef);
}
// Generate all the struct/class declarations.
foreach (var @class in context.Classes) foreach (var @class in context.Classes)
{
@class.Visit(this); @class.Visit(this);
foreach (var @event in context.Events)
GenerateEvent(@event);
GenerateNamespaceFunctionsAndVariables(context);
foreach(var childNamespace in context.Namespaces)
childNamespace.Visit(this);
return true;
} }
if (context.Functions.Any(f => f.IsGenerated) || void GenerateNamespaceFunctionsAndVariables(DeclarationContext context)
(!(context is Class) &&
context.Variables.Any(
v => v.IsGenerated && v.Access == AccessSpecifier.Public)))
{ {
var hasGlobalVariables = !(context is Class) && context.Variables.Any(
v => v.IsGenerated && v.Access == AccessSpecifier.Public);
if (!context.Functions.Any(f => f.IsGenerated) && !hasGlobalVariables)
return;
PushBlock(CSharpBlockKind.Functions); PushBlock(CSharpBlockKind.Functions);
var parentName = Helpers.SafeIdentifier(context.TranslationUnit.FileNameWithoutExtension); var parentName = Helpers.SafeIdentifier(context.TranslationUnit.FileNameWithoutExtension);
WriteLine("public unsafe partial class {0}", parentName); WriteLine("public unsafe partial class {0}", parentName);
@ -277,17 +282,6 @@ namespace CppSharp.Generators.CSharp
PopBlock(NewLineKind.BeforeNextBlock); PopBlock(NewLineKind.BeforeNextBlock);
} }
foreach (var @event in context.Events)
{
GenerateEvent(@event);
}
foreach(var childNamespace in context.Namespaces)
childNamespace.Visit(this);
return true;
}
private void GenerateClassTemplateSpecializationInternal(Class classTemplate) private void GenerateClassTemplateSpecializationInternal(Class classTemplate)
{ {
if (classTemplate.Specializations.Count == 0) if (classTemplate.Specializations.Count == 0)

Loading…
Cancel
Save