зеркало из https://github.com/mono/CppSharp.git
Misc changes (#1710)
* Minor code refactoring for re-use. * Add Class.FindVariable helper method. * Upgrade to .NET 6.
This commit is contained in:
Родитель
c4a24b0cce
Коммит
db7949b263
|
@ -61,7 +61,7 @@ msvc_cpp_defines = { }
|
|||
default_gcc_version = "9.0.0"
|
||||
generate_build_config = true
|
||||
premake.path = premake.path .. ";" .. path.join(builddir, "modules")
|
||||
targetframework = "netcoreapp3.1"
|
||||
targetframework = "net6.0"
|
||||
|
||||
function string.starts(str, start)
|
||||
if str == nil then return end
|
||||
|
|
|
@ -286,6 +286,11 @@ namespace CppSharp.AST
|
|||
.FirstOrDefault(m => m.USR == usr);
|
||||
}
|
||||
|
||||
public Variable FindVariable(string name)
|
||||
{
|
||||
return Variables.FirstOrDefault(m => m.Name == name);
|
||||
}
|
||||
|
||||
public override T Visit<T>(IDeclVisitor<T> visitor)
|
||||
{
|
||||
return visitor.VisitClassDecl(this);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -584,7 +584,8 @@ namespace CppSharp.Generators.C
|
|||
args.Add(arg.Type.Visit(this));
|
||||
break;
|
||||
case TemplateArgument.ArgumentKind.Declaration:
|
||||
args.Add(arg.Declaration.Visit(this));
|
||||
if (arg.Declaration != null)
|
||||
args.Add(arg.Declaration.Visit(this));
|
||||
break;
|
||||
case TemplateArgument.ArgumentKind.Integral:
|
||||
ClassTemplate template = specialization.TemplatedDecl;
|
||||
|
@ -596,6 +597,7 @@ namespace CppSharp.Generators.C
|
|||
{
|
||||
args.Add(arg.Integral.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -634,7 +636,7 @@ namespace CppSharp.Generators.C
|
|||
CppSharp.AST.Type desugared = function.FunctionType.Type.Desugar();
|
||||
if (!desugared.IsPointerTo(out functionType))
|
||||
functionType = (FunctionType)desugared;
|
||||
string exceptionType = Print(functionType.ExceptionSpecType);
|
||||
string exceptionType = functionType != null ? Print(functionType.ExceptionSpecType) : "";
|
||||
|
||||
var @return = function.OriginalReturnType.Visit(this);
|
||||
@return.Name = @class + name;
|
||||
|
|
|
@ -316,7 +316,7 @@ namespace CppSharp.Generators
|
|||
property.Visit(this);
|
||||
}
|
||||
|
||||
VisitClassConstructors(@class);
|
||||
VisitClassConstructors(@class.Constructors.Where(c => !ASTUtils.CheckIgnoreMethod(c)));
|
||||
VisitClassMethods(@class);
|
||||
|
||||
return true;
|
||||
|
@ -333,9 +333,9 @@ namespace CppSharp.Generators
|
|||
}
|
||||
}
|
||||
|
||||
public virtual void VisitClassConstructors(Class @class)
|
||||
public virtual void VisitClassConstructors(IEnumerable<Method> constructors)
|
||||
{
|
||||
foreach (var ctor in @class.Constructors.Where(c => !ASTUtils.CheckIgnoreMethod(c)))
|
||||
foreach (var ctor in constructors)
|
||||
{
|
||||
ctor.Visit(this);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using CppSharp.AST;
|
||||
using CppSharp.AST.Extensions;
|
||||
|
@ -9,11 +10,9 @@ using CppSharp.Generators.NAPI;
|
|||
|
||||
namespace CppSharp.Generators.Cpp
|
||||
{
|
||||
public class NAPICodeGenerator : CCodeGenerator
|
||||
public class MethodGroupCodeGenerator : CCodeGenerator
|
||||
{
|
||||
public override string FileExtension => "cpp";
|
||||
|
||||
public NAPICodeGenerator(BindingContext context, IEnumerable<TranslationUnit> units)
|
||||
protected MethodGroupCodeGenerator(BindingContext context, IEnumerable<TranslationUnit> units)
|
||||
: base(context, units)
|
||||
{
|
||||
}
|
||||
|
@ -43,9 +42,9 @@ namespace CppSharp.Generators.Cpp
|
|||
return VisitClassDeclContext(@class);
|
||||
}
|
||||
|
||||
public override void VisitClassConstructors(Class @class)
|
||||
public override void VisitClassConstructors(IEnumerable<Method> ctors)
|
||||
{
|
||||
var constructors = @class.Constructors.Where(c => c.IsGenerated && !c.IsCopyConstructor)
|
||||
var constructors = ctors.Where(c => c.IsGenerated && !c.IsCopyConstructor)
|
||||
.ToList();
|
||||
|
||||
if (!constructors.Any())
|
||||
|
@ -59,7 +58,7 @@ namespace CppSharp.Generators.Cpp
|
|||
if (!function.IsGenerated)
|
||||
return false;
|
||||
|
||||
if (!(function is Method method))
|
||||
if (function is not Method method)
|
||||
return true;
|
||||
|
||||
if (method.IsConstructor || method.IsDestructor)
|
||||
|
@ -88,10 +87,27 @@ namespace CppSharp.Generators.Cpp
|
|||
foreach (var method in @group)
|
||||
{
|
||||
method.Visit(this);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetTranslationUnitName(TranslationUnit unit)
|
||||
{
|
||||
var paths = unit.FileRelativePath.Split('/').ToList();
|
||||
paths = paths.Select(p => Path.GetFileNameWithoutExtension(p.ToLowerInvariant())).ToList();
|
||||
var name = string.Join('_', paths);
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
public class NAPICodeGenerator : MethodGroupCodeGenerator
|
||||
{
|
||||
public override string FileExtension => "cpp";
|
||||
|
||||
public NAPICodeGenerator(BindingContext context, IEnumerable<TranslationUnit> units)
|
||||
: base(context, units)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual MarshalPrinter<MarshalContext, CppTypePrinter> GetMarshalManagedToNativePrinter(MarshalContext ctx)
|
||||
{
|
||||
return new NAPIMarshalManagedToNativePrinter(ctx);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using CppSharp.AST;
|
||||
|
@ -24,14 +23,6 @@ namespace CppSharp.Generators.Cpp
|
|||
{
|
||||
}
|
||||
|
||||
public static string GetTranslationUnitName(TranslationUnit unit)
|
||||
{
|
||||
var paths = unit.FileRelativePath.Split('/').ToList();
|
||||
paths = paths.Select(p => Path.GetFileNameWithoutExtension(p.ToLowerInvariant())).ToList();
|
||||
var name = string.Join('_', paths);
|
||||
return name;
|
||||
}
|
||||
|
||||
public override void Process()
|
||||
{
|
||||
GenerateFilePreamble(CommentKind.BCPL);
|
||||
|
|
|
@ -198,7 +198,7 @@ namespace CppSharp.Generators.Cpp
|
|||
{
|
||||
}
|
||||
|
||||
public override void VisitClassConstructors(Class @class)
|
||||
public override void VisitClassConstructors(IEnumerable<Method> ctors)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче