Browse Source

Merge pull request #244 from esdrubal/internal-fields

Internal fields
pull/232/merge
João Matos 11 years ago
parent
commit
b2f419f350
  1. 4
      src/AST/Declaration.cs
  2. 4
      src/Generator/AST/Utils.cs
  3. 18
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs

4
src/AST/Declaration.cs

@ -221,9 +221,7 @@ namespace CppSharp.AST
{ {
get get
{ {
var k = GenerationKind; return GenerationKind == GenerationKind.Internal;
return k == GenerationKind.Generate
|| k == GenerationKind.Internal;
} }
} }

4
src/Generator/AST/Utils.cs

@ -60,7 +60,7 @@ namespace CppSharp.AST
return false; return false;
} }
public static bool CheckIgnoreField(Field field) public static bool CheckIgnoreField(Field field, bool useInternals = false)
{ {
if (field.Access == AccessSpecifier.Private) if (field.Access == AccessSpecifier.Private)
return true; return true;
@ -68,7 +68,7 @@ namespace CppSharp.AST
if (field.Class.IsValueType && field.IsDeclared) if (field.Class.IsValueType && field.IsDeclared)
return false; return false;
return !field.IsGenerated; return !field.IsGenerated && (!useInternals || !field.IsInternal);
} }
public static bool CheckIgnoreProperty(Property prop) public static bool CheckIgnoreProperty(Property prop)

18
src/Generator/Generators/CSharp/CSharpTextTemplate.cs

@ -223,7 +223,7 @@ namespace CppSharp.Generators.CSharp
// Generate all the internal function declarations. // Generate all the internal function declarations.
foreach (var function in context.Functions) foreach (var function in context.Functions)
{ {
if (!function.IsInternal) continue; if (!function.IsGenerated && !function.IsInternal ) continue;
GenerateInternalFunction(function); GenerateInternalFunction(function);
} }
@ -315,7 +315,7 @@ namespace CppSharp.Generators.CSharp
public void GenerateClass(Class @class) public void GenerateClass(Class @class)
{ {
if (@class.IsIncomplete) if (!@class.IsGenerated || @class.IsIncomplete)
return; return;
PushBlock(CSharpBlockKind.Class); PushBlock(CSharpBlockKind.Class);
@ -331,7 +331,7 @@ namespace CppSharp.Generators.CSharp
GenerateClassInternals(@class); GenerateClassInternals(@class);
GenerateDeclContext(@class); GenerateDeclContext(@class);
if (!@class.IsGenerated || @class.IsDependent) if (@class.IsDependent)
goto exit; goto exit;
if (ShouldGenerateClassNativeField(@class)) if (ShouldGenerateClassNativeField(@class))
@ -706,7 +706,7 @@ namespace CppSharp.Generators.CSharp
if (@class.IsUnion) if (@class.IsUnion)
WriteLine("[StructLayout(LayoutKind.Explicit)]"); WriteLine("[StructLayout(LayoutKind.Explicit)]");
Write(!@class.IsGenerated ? "internal " : Helpers.GetAccess(@class.Access)); Write(@class.IsInternal ? "internal " : Helpers.GetAccess(@class.Access));
Write("unsafe "); Write("unsafe ");
if (Driver.Options.GenerateAbstractImpls && @class.IsAbstract) if (Driver.Options.GenerateAbstractImpls && @class.IsAbstract)
@ -761,7 +761,7 @@ namespace CppSharp.Generators.CSharp
foreach (var field in @class.Fields) foreach (var field in @class.Fields)
{ {
if (!nativeFields && ASTUtils.CheckIgnoreField(field)) continue; if (ASTUtils.CheckIgnoreField(field, nativeFields)) continue;
action(field); action(field);
} }
} }
@ -788,13 +788,11 @@ namespace CppSharp.Generators.CSharp
if (field.Expression != null) if (field.Expression != null)
{ {
var fieldValuePrinted = field.Expression.CSharpValue(ExpressionPrinter); var fieldValuePrinted = field.Expression.CSharpValue(ExpressionPrinter);
Write("{0} {1} {2} = {3};", !field.IsGenerated ? "internal" : "public", Write("public {0} {1} = {2};", fieldTypePrinted.Type, safeIdentifier, fieldValuePrinted);
fieldTypePrinted.Type, safeIdentifier, fieldValuePrinted);
} }
else else
{ {
Write("{0} {1} {2};", !field.IsGenerated ? "internal" : "public", Write("public {0} {1};", fieldTypePrinted.Type, safeIdentifier);
fieldTypePrinted.Type, safeIdentifier);
} }
PopBlock(NewLineKind.BeforeNextBlock); PopBlock(NewLineKind.BeforeNextBlock);
@ -2659,7 +2657,7 @@ namespace CppSharp.Generators.CSharp
public void GenerateInternalFunction(Function function) public void GenerateInternalFunction(Function function)
{ {
if (!function.IsInternal || function.IsPure) if (function.IsPure)
return; return;
if (function.OriginalFunction != null) if (function.OriginalFunction != null)

Loading…
Cancel
Save