Browse Source

Refactor CodeGenerator.GenerateMethodSpecifier to allow explicit specifier kind.

pull/1359/head
João Matos 5 years ago committed by João Matos
parent
commit
9ba53acc11
  1. 18
      src/Generator/Generators/C/CCodeGenerator.cs
  2. 2
      src/Generator/Generators/C/CppHeaders.cs
  3. 2
      src/Generator/Generators/C/CppSources.cs
  4. 5
      src/Generator/Generators/CLI/CLIHeaders.cs
  5. 5
      src/Generator/Generators/CSharp/CSharpSources.cs
  6. 9
      src/Generator/Generators/CodeGenerator.cs

18
src/Generator/Generators/C/CCodeGenerator.cs

@ -332,10 +332,16 @@ namespace CppSharp.Generators.C @@ -332,10 +332,16 @@ namespace CppSharp.Generators.C
function.Name : function.OriginalName;
}
public override void GenerateMethodSpecifier(Method method, Class @class)
public override void GenerateMethodSpecifier(Method method,
MethodSpecifierKind? kind = null)
{
var isHeaderFile = FileExtension == "h";
if (isHeaderFile)
bool isDeclaration;
if (kind.HasValue)
isDeclaration = kind == MethodSpecifierKind.Declaration;
else
isDeclaration = FileExtension == "h";
if (isDeclaration)
{
if (method.IsVirtual || method.IsOverride)
Write("virtual ");
@ -363,7 +369,7 @@ namespace CppSharp.Generators.C @@ -363,7 +369,7 @@ namespace CppSharp.Generators.C
Write(")");
if (method.IsOverride && isHeaderFile)
if (method.IsOverride && isDeclaration)
Write(" override");
}
@ -376,7 +382,7 @@ namespace CppSharp.Generators.C @@ -376,7 +382,7 @@ namespace CppSharp.Generators.C
{
PushBlock(BlockKind.Method, method);
GenerateMethodSpecifier(method, method.Namespace as Class);
GenerateMethodSpecifier(method);
Write(";");
PopBlock(NewLineKind.BeforeNextBlock);
@ -406,7 +412,7 @@ namespace CppSharp.Generators.C @@ -406,7 +412,7 @@ namespace CppSharp.Generators.C
public virtual void GeneratePropertyAccessorSpecifier(Method method)
{
GenerateMethodSpecifier(method, method.Namespace as Class);
GenerateMethodSpecifier(method);
}
public virtual void GeneratePropertyGetter(Method method)

2
src/Generator/Generators/C/CppHeaders.cs

@ -546,7 +546,7 @@ namespace CppSharp.Generators.Cpp @@ -546,7 +546,7 @@ namespace CppSharp.Generators.Cpp
PushBlock(BlockKind.Method, method);
GenerateDeclarationCommon(method);
GenerateMethodSpecifier(method, method.Namespace as Class);
GenerateMethodSpecifier(method);
WriteLine(";");
PopBlock(NewLineKind.BeforeNextBlock);

2
src/Generator/Generators/C/CppSources.cs

@ -348,7 +348,7 @@ namespace CppSharp.Generators.Cpp @@ -348,7 +348,7 @@ namespace CppSharp.Generators.Cpp
PushBlock(BlockKind.Method, method);
GenerateMethodSpecifier(method, method.Namespace as Class);
GenerateMethodSpecifier(method);
NewLine();
var @class = method.Namespace as Class;

5
src/Generator/Generators/CLI/CLIHeaders.cs

@ -676,7 +676,8 @@ namespace CppSharp.Generators.CLI @@ -676,7 +676,8 @@ namespace CppSharp.Generators.CLI
PopBlock(NewLineKind.BeforeNextBlock);
}
public override void GenerateMethodSpecifier(Method method, Class @class)
public override void GenerateMethodSpecifier(Method method,
MethodSpecifierKind? kind = null)
{
if ((method.IsVirtual || method.IsOverride) && !method.IsOperator)
Write("virtual ");
@ -712,7 +713,7 @@ namespace CppSharp.Generators.CLI @@ -712,7 +713,7 @@ namespace CppSharp.Generators.CLI
PushBlock(BlockKind.Method, method);
GenerateDeclarationCommon(method);
GenerateMethodSpecifier(method, method.Namespace as Class);
GenerateMethodSpecifier(method);
WriteLine(";");
if (method.OperatorKind == CXXOperatorKind.EqualEqual)

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

@ -2340,7 +2340,8 @@ namespace CppSharp.Generators.CSharp @@ -2340,7 +2340,8 @@ namespace CppSharp.Generators.CSharp
PopBlock(NewLineKind.BeforeNextBlock);
}
public override void GenerateMethodSpecifier(Method method, Class @class)
public override void GenerateMethodSpecifier(Method method,
MethodSpecifierKind? kind = null)
{
bool isTemplateMethod = method.Parameters.Any(
p => p.Kind == ParameterKind.Extension);
@ -2392,7 +2393,7 @@ namespace CppSharp.Generators.CSharp @@ -2392,7 +2393,7 @@ namespace CppSharp.Generators.CSharp
Write(Helpers.GetAccess(method.Access));
}
GenerateMethodSpecifier(method, @class);
GenerateMethodSpecifier(method);
if (method.SynthKind == FunctionSynthKind.DefaultValueOverload && method.IsConstructor && !method.IsPure)
{

9
src/Generator/Generators/CodeGenerator.cs

@ -222,7 +222,14 @@ namespace CppSharp.Generators @@ -222,7 +222,14 @@ namespace CppSharp.Generators
#region Method generation
public virtual void GenerateMethodSpecifier(Method method, Class @class)
public enum MethodSpecifierKind
{
Declaration,
Definition
}
public virtual void GenerateMethodSpecifier(Method method,
MethodSpecifierKind? kind = null)
{
}

Loading…
Cancel
Save