Browse Source

Remove and simplify code in the major refactoring

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/1307/head
Dimitar Dobrev 6 years ago committed by João Matos
parent
commit
89efbf69fd
  1. 8
      src/Generator/Generators/C/CppTypePrinter.cs
  2. 5
      src/Generator/Generators/TypePrinter.cs
  3. 5
      src/Generator/Passes/MultipleInheritancePass.cs
  4. 6
      src/Generator/Passes/ParamTypeToInterfacePass.cs

8
src/Generator/Generators/C/CppTypePrinter.cs

@ -332,10 +332,7 @@ namespace CppSharp.Generators.C @@ -332,10 +332,7 @@ namespace CppSharp.Generators.C
public override TypePrinterResult VisitParameter(Parameter param, bool hasName = true)
{
Parameter oldParam = Parameter;
Parameter = param;
var result = param.Type.Visit(this, param.QualifiedType.Qualifiers);
Parameter = oldParam;
string name = param.Name;
bool printName = hasName && !string.IsNullOrEmpty(name);
@ -346,11 +343,8 @@ namespace CppSharp.Generators.C @@ -346,11 +343,8 @@ namespace CppSharp.Generators.C
if (!printName)
return result;
string typeName;
result.Name = param.Name;
typeName = result.ToString();
return typeName;
return result.ToString();
}
public override TypePrinterResult VisitDelegate(FunctionType function)

5
src/Generator/Generators/TypePrinter.cs

@ -12,8 +12,6 @@ namespace CppSharp.Generators @@ -12,8 +12,6 @@ namespace CppSharp.Generators
public StringBuilder NamePrefix { get; set; } = new StringBuilder();
public StringBuilder NameSuffix { get; set; } = new StringBuilder();
public bool HasNamePlaceholder => Type.Contains("{0}");
public TypePrinterResult(string type = "", string nameSuffix = "")
{
Type = type;
@ -28,7 +26,8 @@ namespace CppSharp.Generators @@ -28,7 +26,8 @@ namespace CppSharp.Generators
public override string ToString()
{
if (HasNamePlaceholder)
bool hasPlaceholder = Type.Contains("{0}");
if (hasPlaceholder)
return string.Format(Type, $"{NamePrefix}{Name}{NameSuffix}");
var namePrefix = (Name.Length > 0) ? $"{NamePrefix} " : NamePrefix.ToString();

5
src/Generator/Passes/MultipleInheritancePass.cs

@ -83,11 +83,6 @@ namespace CppSharp.Passes @@ -83,11 +83,6 @@ namespace CppSharp.Passes
if (@base.CompleteDeclaration != null)
@base = (Class) @base.CompleteDeclaration;
// Prevent multiple interfaces from being generated in cases of
// a secondary base being inherited multiple times in a chain.
if (@base.IsInterface)
return @base;
return interfaces.FirstOrDefault(i => i.OriginalClass == @base) ??
GetNewInterface("I" + @base.Name, @base);
}

6
src/Generator/Passes/ParamTypeToInterfacePass.cs

@ -31,10 +31,6 @@ namespace CppSharp.Passes @@ -31,10 +31,6 @@ namespace CppSharp.Passes
if (!base.VisitFunctionDecl(function))
return false;
// TODO: Fix this once Dispose methods are generated in a pass.
if (function.SynthKind == FunctionSynthKind.InterfaceDispose)
return false;
// parameters and returns from a specialised interface
// must not be replaced if the templated interface uses a template parameter
var interfaceFunction = GetInterfaceFunction(function);
@ -101,7 +97,7 @@ namespace CppSharp.Passes @@ -101,7 +97,7 @@ namespace CppSharp.Passes
if (@class == null || !@class.IsInterface)
return null;
return @class.Methods.FirstOrDefault(m => m.OriginalFunction == function.OriginalFunction);
return @class.Methods.First(m => m.OriginalFunction == function.OriginalFunction);
}
private static Property GetTemplateInterfaceProperty(Property property)

Loading…
Cancel
Save