Skip to content

Commit e50d94f

Browse files
committed
Updated to the latest C++#.
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent 829e3a5 commit e50d94f

11 files changed

+111
-54
lines changed

QtSharp.CLI/Program.cs

-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ static bool QueryQt(QtInfo qt, bool debug)
141141
.Select(s => s.Trim()).ToList();
142142

143143
const string frameworkDirectory = "(framework directory)";
144-
includeDirs.Insert(0, Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "include"));
145144
qt.SystemIncludeDirs = includeDirs.Where(s => !s.Contains(frameworkDirectory))
146145
.Select(Path.GetFullPath);
147146

QtSharp.CLI/QtSharp.CLI.csproj

+8-8
Original file line numberDiff line numberDiff line change
@@ -63,27 +63,27 @@
6363
</PropertyGroup>
6464
<ItemGroup>
6565
<Reference Include="CppSharp, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
66-
<HintPath>..\packages\CppSharp.0.8.6\lib\CppSharp.dll</HintPath>
66+
<HintPath>..\packages\CppSharp.0.8.13\lib\CppSharp.dll</HintPath>
6767
<Private>True</Private>
6868
</Reference>
6969
<Reference Include="CppSharp.AST, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
70-
<HintPath>..\packages\CppSharp.0.8.6\lib\CppSharp.AST.dll</HintPath>
70+
<HintPath>..\packages\CppSharp.0.8.13\lib\CppSharp.AST.dll</HintPath>
7171
<Private>True</Private>
7272
</Reference>
7373
<Reference Include="CppSharp.Generator, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
74-
<HintPath>..\packages\CppSharp.0.8.6\lib\CppSharp.Generator.dll</HintPath>
74+
<HintPath>..\packages\CppSharp.0.8.13\lib\CppSharp.Generator.dll</HintPath>
7575
<Private>True</Private>
7676
</Reference>
7777
<Reference Include="CppSharp.Parser, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
78-
<HintPath>..\packages\CppSharp.0.8.6\lib\CppSharp.Parser.dll</HintPath>
78+
<HintPath>..\packages\CppSharp.0.8.13\lib\CppSharp.Parser.dll</HintPath>
7979
<Private>True</Private>
8080
</Reference>
8181
<Reference Include="CppSharp.Parser.CSharp, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
82-
<HintPath>..\packages\CppSharp.0.8.6\lib\CppSharp.Parser.CSharp.dll</HintPath>
82+
<HintPath>..\packages\CppSharp.0.8.13\lib\CppSharp.Parser.CSharp.dll</HintPath>
8383
<Private>True</Private>
8484
</Reference>
8585
<Reference Include="CppSharp.Runtime, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
86-
<HintPath>..\packages\CppSharp.0.8.6\lib\CppSharp.Runtime.dll</HintPath>
86+
<HintPath>..\packages\CppSharp.0.8.13\lib\CppSharp.Runtime.dll</HintPath>
8787
<Private>True</Private>
8888
</Reference>
8989
<Reference Include="Mono.Cecil, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
@@ -127,12 +127,12 @@
127127
<None Include="packages.config" />
128128
</ItemGroup>
129129
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
130-
<Import Project="..\packages\Baseclass.Contrib.Nuget.Output.2.1.0\build\net40\Baseclass.Contrib.Nuget.Output.targets" Condition="Exists('..\packages\Baseclass.Contrib.Nuget.Output.2.1.0\build\net40\Baseclass.Contrib.Nuget.Output.targets')" />
130+
<Import Project="..\packages\Baseclass.Contrib.Nuget.Output.2.3.0\build\net40\Baseclass.Contrib.Nuget.Output.targets" Condition="Exists('..\packages\Baseclass.Contrib.Nuget.Output.2.3.0\build\net40\Baseclass.Contrib.Nuget.Output.targets')" />
131131
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
132132
<PropertyGroup>
133133
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
134134
</PropertyGroup>
135-
<Error Condition="!Exists('..\packages\Baseclass.Contrib.Nuget.Output.2.1.0\build\net40\Baseclass.Contrib.Nuget.Output.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Baseclass.Contrib.Nuget.Output.2.1.0\build\net40\Baseclass.Contrib.Nuget.Output.targets'))" />
135+
<Error Condition="!Exists('..\packages\Baseclass.Contrib.Nuget.Output.2.3.0\build\net40\Baseclass.Contrib.Nuget.Output.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Baseclass.Contrib.Nuget.Output.2.3.0\build\net40\Baseclass.Contrib.Nuget.Output.targets'))" />
136136
</Target>
137137
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
138138
Other similar extension points exist, see Microsoft.Common.targets.

QtSharp.CLI/packages.config

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Baseclass.Contrib.Nuget.Output" version="2.1.0" targetFramework="net451" />
4-
<package id="CppSharp" version="0.8.6" targetFramework="net461" developmentDependency="true" />
3+
<package id="Baseclass.Contrib.Nuget.Output" version="2.3.0" targetFramework="net461" />
4+
<package id="CppSharp" version="0.8.13" targetFramework="net461" developmentDependency="true" />
55
<package id="Mono.Cecil" version="0.9.6.4" targetFramework="net461" />
66
</packages>

QtSharp/DocGeneration/Documentation.cs

+12-2
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,17 @@ public void DocumentFunction(Function function)
323323
// variadic and void "parameters" are invalid
324324
if (function.IsVariadic && @params.Count == i || match.Groups[1].Value == "void")
325325
break;
326-
@params[i++].Name = csharpSources.SafeIdentifier(match.Groups[1].Value);
326+
var param = csharpSources.SafeIdentifier(match.Groups[1].Value);
327+
@params[i].Name = param;
328+
if (function.IsDependent && function is Method && function.Namespace.IsDependent)
329+
{
330+
foreach (var specialization in ((Class) function.Namespace).Specializations)
331+
{
332+
var specializedFunction = specialization.Methods.First(m => m.InstantiatedFrom == function);
333+
specializedFunction.Parameters.Where(p => p.Kind == ParameterKind.Regular).ElementAt(i).Name = param;
334+
}
335+
}
336+
i++;
327337
}
328338
// TODO: create links in the "See Also" section
329339
function.Comment = new RawComment
@@ -574,7 +584,7 @@ public void DocumentEnum(Enumeration @enum)
574584
var enumPrefix = @enum.Namespace is TranslationUnit ? "" : (@enum.Namespace.Name + "::");
575585
foreach (var item in @enum.Items)
576586
{
577-
var itemQualifiedName = enumPrefix + item.Name;
587+
var itemQualifiedName = enumPrefix + item.OriginalName;
578588
var enumMemberDocs = (from member in enumMembersDocs
579589
from code in member.Codes
580590
where code.InnerText == itemQualifiedName

QtSharp/GenerateSignalEventsPass.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ from block in output.FindBlocks(BlockKind.Event)
7070
string.Join(", ",
7171
from e in @event.Parameters
7272
select GetOriginalParameterType(e)));
73-
Event existing = @class.Events.FirstOrDefault(e => e.Name == @event.Name);
73+
Event existing = @class.Events.FirstOrDefault(e => e.OriginalName == @event.OriginalName);
7474
if (existing != null && existing != @event)
7575
{
7676
if (@event.Parameters.Count > 0)
@@ -85,8 +85,8 @@ from e in @event.Parameters
8585
else
8686
{
8787
if (@event.Parameters.Count > 0 &&
88-
(@class.Methods.Any(m => m.IsGenerated && m.OriginalName == @event.Name) ||
89-
@class.Properties.Any(p => p.IsGenerated && p.OriginalName == @event.Name)))
88+
(@class.Methods.Any(m => m.IsGenerated && m.OriginalName == @event.OriginalName) ||
89+
@class.Properties.Any(p => p.IsGenerated && p.OriginalName == @event.OriginalName)))
9090
{
9191
@event.Name += GetSignalEventSuffix(@event);
9292
}

QtSharp/GetCommentsFromQtDocsPass.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ public class GetCommentsFromQtDocsPass : TranslationUnitPass
1111
public GetCommentsFromQtDocsPass(string docsPath, IEnumerable<string> modules)
1212
{
1313
this.documentation = new Documentation(docsPath, modules);
14+
this.VisitOptions.VisitClassFields = false;
15+
this.VisitOptions.VisitClassTemplateSpecializations = false;
1416
this.VisitOptions.VisitFunctionReturnType = false;
1517
this.VisitOptions.VisitFunctionParameters = false;
1618
this.VisitOptions.VisitEventParameters = false;
1719
this.VisitOptions.VisitClassBases = false;
1820
this.VisitOptions.VisitTemplateArguments = false;
19-
this.VisitOptions.VisitClassFields = false;
2021
}
2122

2223
public override bool VisitASTContext(ASTContext context)

QtSharp/QFlags.cs

+16-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using CppSharp.AST;
1+
using System.Linq;
2+
using CppSharp.AST;
23
using CppSharp.AST.Extensions;
3-
using CppSharp.Generators;
44
using CppSharp.Generators.CSharp;
55
using CppSharp.Types;
66

@@ -9,18 +9,22 @@ namespace QtSharp
99
[TypeMap("QFlags")]
1010
public class QFlags : TypeMap
1111
{
12-
public override string CSharpConstruct()
13-
{
14-
return string.Empty;
15-
}
12+
public override string CSharpConstruct() => string.Empty;
1613

17-
public override Type CSharpSignatureType(CSharpTypePrinterContext ctx)
14+
public override Type CSharpSignatureType(TypePrinterContext ctx)
1815
{
1916
return GetEnumType(ctx.Type);
2017
}
2118

22-
public override string CSharpSignature(CSharpTypePrinterContext ctx)
19+
public override string CSharpSignature(TypePrinterContext ctx)
2320
{
21+
var enumType = GetEnumType(ctx.Type);
22+
if (enumType == null)
23+
{
24+
var specializationType = (TemplateSpecializationType) ctx.Type;
25+
return $@"{specializationType.Template.Name}<{
26+
string.Join(", ", specializationType.Arguments.Select(a => a.Type.Type))}>";
27+
}
2428
return this.CSharpSignatureType(ctx).ToString();
2529
}
2630

@@ -55,6 +59,10 @@ private static Type GetEnumType(Type mappedType)
5559
classTemplateSpecialization = templateSpecializationType.GetClassTemplateSpecialization();
5660
else
5761
classTemplateSpecialization = (ClassTemplateSpecialization) ((TagType) type).Declaration;
62+
if (classTemplateSpecialization == null)
63+
{
64+
return null;
65+
}
5866
return classTemplateSpecialization.Arguments[0].Type.Type;
5967
}
6068
}

QtSharp/QString.cs

+28-8
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ namespace QtSharp
99
[TypeMap("QString")]
1010
public class QString : TypeMap
1111
{
12-
public override string CSharpSignature(CSharpTypePrinterContext ctx)
12+
public override string CSharpSignature(TypePrinterContext ctx)
1313
{
14-
if (ctx.CSharpKind == TypePrinterContextKind.Native)
14+
if (ctx.Kind == TypePrinterContextKind.Native)
1515
{
1616
return string.Format("QtCore.QString.{0}{1}", Helpers.InternalStruct, ctx.Type.IsAddress() ? "*" : string.Empty);
1717
}
@@ -20,11 +20,23 @@ public override string CSharpSignature(CSharpTypePrinterContext ctx)
2020

2121
public override void CSharpMarshalToNative(CSharpMarshalContext ctx)
2222
{
23-
ctx.SupportBefore.WriteLine("var __stringPtr{0} = ReferenceEquals({1}, null) ? null : (ushort*) Marshal.StringToHGlobalUni({1}).ToPointer();",
24-
ctx.ParameterIndex, ctx.Parameter.Name);
25-
ctx.SupportBefore.WriteLine("var __qstring{0} = __stringPtr{0} == null ? null : QtCore.QString.FromUtf16(ref *__stringPtr{0}, {1}.Length);",
26-
ctx.ParameterIndex, ctx.Parameter.Name);
2723
var type = ctx.Parameter.Type.Desugar();
24+
var finalType = (type.GetFinalPointee() ?? type).Desugar();
25+
var substitution = finalType as TemplateParameterSubstitutionType;
26+
string param;
27+
if (substitution != null)
28+
{
29+
param = Generator.GeneratedIdentifier(ctx.Parameter.Name.Trim('@'));
30+
ctx.Before.WriteLine($"var {param} = (string) (object) {ctx.Parameter.Name};");
31+
}
32+
else
33+
{
34+
param = ctx.Parameter.Name;
35+
}
36+
ctx.Before.WriteLine("var __stringPtr{0} = ReferenceEquals({1}, null) ? null : (ushort*) Marshal.StringToHGlobalUni({1}).ToPointer();",
37+
ctx.ParameterIndex, param);
38+
ctx.Before.WriteLine("var __qstring{0} = __stringPtr{0} == null ? null : QtCore.QString.FromUtf16(ref *__stringPtr{0}, {1}.Length);",
39+
ctx.ParameterIndex, param);
2840
if (type.IsAddress())
2941
{
3042
ctx.Return.Write("ReferenceEquals(__qstring{0}, null) ? global::System.IntPtr.Zero : __qstring{0}.{1}",
@@ -45,8 +57,16 @@ public override void CSharpMarshalToNative(CSharpMarshalContext ctx)
4557

4658
public override void CSharpMarshalToManaged(CSharpMarshalContext ctx)
4759
{
48-
ctx.Return.Write("Marshal.PtrToStringUni(new IntPtr(QtCore.QString.{0}({1}).Utf16))",
49-
Helpers.CreateInstanceIdentifier, ctx.ReturnVarName);
60+
var type = ctx.ReturnType.Type.Desugar();
61+
var finalType = (type.GetFinalPointee() ?? type).Desugar();
62+
var substitution = finalType as TemplateParameterSubstitutionType;
63+
string cast = string.Empty;
64+
if (substitution != null)
65+
{
66+
cast = $"({substitution.ReplacedParameter.Parameter.Name}) (object) ";
67+
}
68+
ctx.Return.Write($@"{cast}Marshal.PtrToStringUni(new IntPtr(QtCore.QString.{
69+
Helpers.CreateInstanceIdentifier}({ctx.ReturnVarName}).Utf16))");
5070
}
5171

5272
private CSharpTypePrinter typePrinter;

QtSharp/QtSharp.cs

+27-8
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ public void Preprocess(Driver driver, ASTContext lib)
4141
IgnorePrivateDeclarations(unit);
4242
}
4343

44+
lib.FindFunction("QtSharedPointer::weakPointerFromVariant_internal").First().ExplicitlyIgnore();
45+
lib.FindFunction("QtSharedPointer::sharedPointerFromVariant_internal").First().ExplicitlyIgnore();
46+
4447
// QString is type-mapped to string so we only need two methods for the conversion
4548
var qString = lib.FindCompleteClass("QString");
4649
foreach (var @class in qString.Declarations)
@@ -52,6 +55,23 @@ public void Preprocess(Driver driver, ASTContext lib)
5255
method.ExplicitlyIgnore();
5356
}
5457

58+
foreach (var template in lib.FindDecl<ClassTemplate>("QList"))
59+
{
60+
var qListQVariant = template.Specializations.FirstOrDefault(
61+
s =>
62+
{
63+
var type = s.Arguments[0].Type.Type;
64+
if (type == null)
65+
return false;
66+
Class @class;
67+
return s.Arguments[0].Type.Type.TryGetClass(out @class) && @class.Name == "QVariant";
68+
});
69+
if (qListQVariant != null)
70+
{
71+
qListQVariant.Methods.First(m => m.OriginalName == "toSet").ExplicitlyIgnore();
72+
}
73+
}
74+
5575
// HACK: work around https://github.com/mono/CppSharp/issues/594
5676
lib.FindCompleteClass("QGraphicsItem").FindEnum("Extension").Access = AccessSpecifier.Public;
5777
lib.FindCompleteClass("QAbstractSlider").FindEnum("SliderChange").Access = AccessSpecifier.Public;
@@ -132,7 +152,7 @@ public void Postprocess(Driver driver, ASTContext lib)
132152
{
133153
var prefix = Platform.IsWindows ? string.Empty : "lib";
134154
var extension = Platform.IsWindows ? ".dll" : Platform.IsMacOS ? ".dylib" : ".so";
135-
var inlinesLibraryFile = string.Format("{0}{1}{2}", prefix, module.InlinesLibraryName, extension);
155+
var inlinesLibraryFile = $"{prefix}{module.SymbolsLibraryName}{extension}";
136156
var inlinesLibraryPath = Path.Combine(driver.Options.OutputDir, Platform.IsWindows ? "release" : string.Empty, inlinesLibraryFile);
137157
this.wrappedModules.Add(new KeyValuePair<string, string>(module.LibraryName + ".dll", inlinesLibraryPath));
138158
}
@@ -166,8 +186,7 @@ public void Setup(Driver driver)
166186
moduleName.StartsWith("3D", StringComparison.Ordinal))
167187
{
168188
module.OutputNamespace = string.Empty;
169-
module.InlinesLibraryName = $"{qtModule}-inlines";
170-
module.TemplatesLibraryName = $"{qtModule}-templates";
189+
module.SymbolsLibraryName = $"{qtModule}-symbols";
171190
}
172191
else
173192
{
@@ -245,8 +264,8 @@ public void SetupPasses(Driver driver)
245264
driver.Context.TranslationUnitPasses.AddPass(new GenerateEventEventsPass(driver.Generator));
246265
driver.Context.TranslationUnitPasses.AddPass(new RemoveQObjectMembersPass());
247266

248-
var generateInlinesPass = driver.Context.TranslationUnitPasses.FindPass<GenerateInlinesPass>();
249-
generateInlinesPass.InlinesCodeGenerated += (sender, e) =>
267+
var generateSymbolsPass = driver.Context.TranslationUnitPasses.FindPass<GenerateSymbolsPass>();
268+
generateSymbolsPass.SymbolsCodeGenerated += (sender, e) =>
250269
{
251270
e.OutputDir = driver.Context.Options.OutputDir;
252271
this.CompileMakefile(e);
@@ -279,9 +298,9 @@ private static void IgnorePrivateDeclaration(Declaration declaration)
279298
}
280299
}
281300

282-
private void CompileMakefile(GenerateInlinesPass.InlinesCodeEventArgs e)
301+
private void CompileMakefile(GenerateSymbolsPass.SymbolsCodeEventArgs e)
283302
{
284-
var pro = $"{e.Module.InlinesLibraryName}.pro";
303+
var pro = $"{e.Module.SymbolsLibraryName}.pro";
285304
var path = Path.Combine(e.OutputDir, pro);
286305
var proBuilder = new StringBuilder();
287306
var qtModules = string.Join(" ", from header in e.Module.Headers
@@ -295,7 +314,7 @@ private void CompileMakefile(GenerateInlinesPass.InlinesCodeEventArgs e)
295314

296315
proBuilder.Append($"QT += {qtModules}\n");
297316
proBuilder.Append("CONFIG += c++11\n");
298-
proBuilder.Append($"TARGET = {e.Module.InlinesLibraryName}\n");
317+
proBuilder.Append($"TARGET = {e.Module.SymbolsLibraryName}\n");
299318
proBuilder.Append("TEMPLATE = lib\n");
300319
proBuilder.Append($"SOURCES += {Path.ChangeExtension(pro, "cpp")}\n");
301320
if (Environment.OSVersion.Platform == PlatformID.Win32NT)

0 commit comments

Comments
 (0)