Browse Source

Minor refactoring fixes.

pull/1301/head
João Matos 6 years ago committed by João Matos
parent
commit
c19df0cc64
  1. 2
      src/AST/Template.cs
  2. 2
      src/Generator/Driver.cs
  3. 6
      src/Generator/Generators/C/CCodeGenerator.cs
  4. 6
      src/Generator/Generators/CLI/CLIMarshal.cs
  5. 37
      src/Generator/Generators/CLI/CLISources.cs
  6. 1
      src/Generator/Passes/CheckAbiParameters.cs
  7. 1
      src/Generator/Passes/CheckAmbiguousFunctions.cs

2
src/AST/Template.cs

@ -310,7 +310,7 @@ namespace CppSharp.AST @@ -310,7 +310,7 @@ namespace CppSharp.AST
public override string ToString()
{
var args = string.Join(", ", Arguments.Select(a => a.ToString()));
return string.Format("{0}<{1}> [{2}]", OriginalName, args, SpecializationKind);
return $"{OriginalName}<{args}> [{SpecializationKind}]";
}
}

2
src/Generator/Driver.cs

@ -322,7 +322,7 @@ namespace CppSharp @@ -322,7 +322,7 @@ namespace CppSharp
foreach (var template in output.Outputs)
{
var fileRelativePath = string.Format("{0}.{1}", fileBase, template.FileExtension);
var fileRelativePath = $"{fileBase}.{template.FileExtension}";
var file = Path.Combine(outputPath, fileRelativePath);
File.WriteAllText(file, template.Generate());

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

@ -20,8 +20,8 @@ namespace CppSharp.Generators.C @@ -20,8 +20,8 @@ namespace CppSharp.Generators.C
public override string ToString()
{
return string.Format(Kind == IncludeKind.Angled ?
"#include <{0}>" : "#include \"{0}\"", File);
return Kind == IncludeKind.Angled ?
$"#include <{File}>" : $"#include \"{File}\"";
}
}
@ -151,7 +151,7 @@ namespace CppSharp.Generators.C @@ -151,7 +151,7 @@ namespace CppSharp.Generators.C
if (!string.IsNullOrWhiteSpace(enumName) && useTypedefEnum)
WriteLine($"}} {enumName};");
else
WriteLine($"}};");
WriteLine("};");
PopBlock(NewLineKind.BeforeNextBlock);

6
src/Generator/Generators/CLI/CLIMarshal.cs

@ -288,9 +288,9 @@ namespace CppSharp.Generators.CLI @@ -288,9 +288,9 @@ namespace CppSharp.Generators.CLI
public string QualifiedIdentifier(Declaration decl)
{
if (!string.IsNullOrEmpty(decl.TranslationUnit.Module.OutputNamespace))
return string.Format("{0}::{1}", decl.TranslationUnit.Module.OutputNamespace,
decl.QualifiedName);
return string.Format("{0}", decl.QualifiedName);
return $"{decl.TranslationUnit.Module.OutputNamespace}::{decl.QualifiedName}";
return decl.QualifiedName;
}
public void WriteClassInstance(Class @class, string instance)

37
src/Generator/Generators/CLI/CLISources.cs

@ -150,7 +150,7 @@ namespace CppSharp.Generators.CLI @@ -150,7 +150,7 @@ namespace CppSharp.Generators.CLI
WriteLine("void {0}::{1}::set(System::IntPtr object)",
qualifiedIdentifier, Helpers.InstanceIdentifier);
WriteOpenBraceAndIndent();
var nativeType = string.Format("::{0}*", @class.QualifiedOriginalName);
var nativeType = $"::{@class.QualifiedOriginalName}*";
WriteLine("NativePtr = ({0})object.ToPointer();", nativeType);
UnindentAndWriteCloseBrace();
PopBlock(NewLineKind.BeforeNextBlock);
@ -356,11 +356,11 @@ namespace CppSharp.Generators.CLI @@ -356,11 +356,11 @@ namespace CppSharp.Generators.CLI
var args = new List<string>();
var isIndexer = indexParameter != null;
if (isIndexer)
args.Add(string.Format("{0} {1}", indexParameter.Type, indexParameter.Name));
args.Add($"{indexParameter.Type} {indexParameter.Name}");
var function = decl as Function;
var argName = function != null && !isIndexer ? function.Parameters[0].Name : "value";
args.Add(string.Format("{0} {1}", type, argName));
args.Add($"{type} {argName}");
WriteLine("void {0}::{1}::set({2})", QualifiedIdentifier(@class),
name, string.Join(", ", args));
@ -468,33 +468,33 @@ namespace CppSharp.Generators.CLI @@ -468,33 +468,33 @@ namespace CppSharp.Generators.CLI
{
if (@class.IsValueType && decl is Field)
{
WriteLine("return {0};", decl.Name);
WriteLine($"return {decl.Name};");
UnindentAndWriteCloseBrace();
NewLine();
return;
}
string variable;
if (decl is Variable)
variable = string.Format("::{0}::{1}",
@class.QualifiedOriginalName, decl.OriginalName);
variable = $"::{@class.QualifiedOriginalName}::{decl.OriginalName}";
else
variable = string.Format("((::{0}*)NativePtr)->{1}",
@class.QualifiedOriginalName, decl.OriginalName);
variable = $"((::{@class.QualifiedOriginalName}*)NativePtr)->{decl.OriginalName}";
var ctx = new MarshalContext(Context, CurrentIndentation)
{
ArgName = decl.Name,
ReturnVarName = variable,
ReturnType = decl.QualifiedType
};
{
ArgName = decl.Name,
ReturnVarName = variable,
ReturnType = decl.QualifiedType
};
ctx.PushMarshalKind(MarshalKind.NativeField);
var marshal = new CLIMarshalNativeToManagedPrinter(ctx);
decl.Visit(marshal);
if (!string.IsNullOrWhiteSpace(marshal.Context.Before))
Write(marshal.Context.Before);
WriteLine("return {0};", marshal.Context.Return);
WriteLine($"return {marshal.Context.Return};");
}
@ -864,7 +864,7 @@ namespace CppSharp.Generators.CLI @@ -864,7 +864,7 @@ namespace CppSharp.Generators.CLI
{
if (!property.IsDeclared || property.Field == null) continue;
var varName = string.Format("_native.{0}", property.Field.OriginalName);
var varName = $"_native.{property.Field.OriginalName}";
var ctx = new MarshalContext(Context, CurrentIndentation)
{
@ -991,12 +991,12 @@ namespace CppSharp.Generators.CLI @@ -991,12 +991,12 @@ namespace CppSharp.Generators.CLI
{
if (IsNativeFunctionOrStaticMethod(function))
{
Write("::{0}(", function.QualifiedOriginalName);
Write($"::{function.QualifiedOriginalName}(");
}
else
{
if (isValueType)
Write("{0}.", valueMarshalName);
Write($"{valueMarshalName}.");
else if (IsNativeMethod(function))
Write("((::{0}*)NativePtr)->", @class.QualifiedOriginalName);
Write("{0}(", function.OriginalName);
@ -1175,8 +1175,7 @@ namespace CppSharp.Generators.CLI @@ -1175,8 +1175,7 @@ namespace CppSharp.Generators.CLI
effectiveParam.Visit(marshal);
if (string.IsNullOrEmpty(marshal.Context.Return))
throw new Exception(string.Format("Cannot marshal argument of function '{0}'",
function.QualifiedOriginalName));
throw new Exception($"Cannot marshal argument of function '{function.QualifiedOriginalName}'");
if (isRef)
{

1
src/Generator/Passes/CheckAbiParameters.cs

@ -1,5 +1,4 @@ @@ -1,5 +1,4 @@
using CppSharp.AST;
using CppSharp.AST.Extensions;
using System.Linq;
namespace CppSharp.Passes

1
src/Generator/Passes/CheckAmbiguousFunctions.cs

@ -3,7 +3,6 @@ using System.Collections.Generic; @@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Linq;
using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Types;
using CppSharp.Generators;
namespace CppSharp.Passes

Loading…
Cancel
Save