Skip to content

Commit

Permalink
Updated to the latest C++# to use the handling of array parameters.
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
  • Loading branch information
ddobrev committed Sep 17, 2017
1 parent e50d94f commit d509ac6
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 104 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
@@ -1,3 +1,8 @@
0.7.2 - 18.9.2017
Added:
- Bindings for the constructors of QImage and QPixmap taking arrays;
- Bindings for QGraphicsScene::drawItems, QGraphicsView::drawItems and QAbstractVideoBuffer::mapPlanes.

0.7.1 - 10.2.2017
Fixed:
- Crashes when calling certain constructors and destructors.
Expand Down
20 changes: 7 additions & 13 deletions QtSharp.CLI/QtSharp.CLI.csproj
Expand Up @@ -63,28 +63,22 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="CppSharp, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\CppSharp.0.8.13\lib\CppSharp.dll</HintPath>
<Private>True</Private>
<HintPath>..\packages\CppSharp.0.8.14\lib\CppSharp.dll</HintPath>
</Reference>
<Reference Include="CppSharp.AST, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\CppSharp.0.8.13\lib\CppSharp.AST.dll</HintPath>
<Private>True</Private>
<HintPath>..\packages\CppSharp.0.8.14\lib\CppSharp.AST.dll</HintPath>
</Reference>
<Reference Include="CppSharp.Generator, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\CppSharp.0.8.13\lib\CppSharp.Generator.dll</HintPath>
<Private>True</Private>
<HintPath>..\packages\CppSharp.0.8.14\lib\CppSharp.Generator.dll</HintPath>
</Reference>
<Reference Include="CppSharp.Parser, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\CppSharp.0.8.13\lib\CppSharp.Parser.dll</HintPath>
<Private>True</Private>
<HintPath>..\packages\CppSharp.0.8.14\lib\CppSharp.Parser.dll</HintPath>
</Reference>
<Reference Include="CppSharp.Parser.CSharp, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\CppSharp.0.8.13\lib\CppSharp.Parser.CSharp.dll</HintPath>
<Private>True</Private>
<Reference Include="CppSharp.Parser.CLI, Version=0.0.0.0, Culture=neutral, processorArchitecture=AMD64">
<HintPath>..\packages\CppSharp.0.8.14\lib\CppSharp.Parser.CLI.dll</HintPath>
</Reference>
<Reference Include="CppSharp.Runtime, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\CppSharp.0.8.13\lib\CppSharp.Runtime.dll</HintPath>
<Private>True</Private>
<HintPath>..\packages\CppSharp.0.8.14\lib\CppSharp.Runtime.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.dll</HintPath>
Expand Down
2 changes: 1 addition & 1 deletion QtSharp.CLI/packages.config
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Baseclass.Contrib.Nuget.Output" version="2.3.0" targetFramework="net461" />
<package id="CppSharp" version="0.8.13" targetFramework="net461" developmentDependency="true" />
<package id="CppSharp" version="0.8.14" targetFramework="net461" developmentDependency="true" />
<package id="Mono.Cecil" version="0.9.6.4" targetFramework="net461" />
</packages>
28 changes: 22 additions & 6 deletions QtSharp/DocGeneration/Documentation.cs
Expand Up @@ -252,14 +252,19 @@ private void CollectTypesDocumentation(HtmlNode documentRoot, string docFile)

public void DocumentFunction(Function function)
{
if (!this.functionNodes.ContainsKey(function.OriginalName))
var nodeKey = function.OriginalName;
if (function.IsDependent && !function.IsOperator && nodeKey.Contains('<'))
{
nodeKey = nodeKey.Substring(0, nodeKey.IndexOf('<'));
}
if (!this.functionNodes.ContainsKey(nodeKey))
{
return;
}

var lineStart = function.LineNumberStart;
var lineEnd = function.LineNumberEnd;
var functions = this.functionNodes[function.OriginalName];
var functions = this.functionNodes[nodeKey];
var unit = function.OriginalNamespace.TranslationUnit;
var location = unit.FileName;
FunctionDocIndexNode node = null;
Expand Down Expand Up @@ -313,8 +318,7 @@ public void DocumentFunction(Function function)
var i = 0;
// HACK: work around https://bugreports.qt.io/browse/QTBUG-53941
if (function.Namespace.Name == "QByteArray" &&
((function.OriginalName == "qCompress" && @params.Count == 2) ||
(function.OriginalName == "qUncompress" && @params.Count == 1)))
function.OriginalName == "qCompress" && @params.Count == 2)
{
docs = this.membersDocumentation[file][key + "-hack"];
}
Expand Down Expand Up @@ -344,6 +348,14 @@ public void DocumentFunction(Function function)
{
AddObsoleteAttribute(function);
}
var @event = function.Namespace.Events.FirstOrDefault(e => e.OriginalDeclaration == function);
if (@event != null)
{
for (i = 0; i < function.Parameters.Count; i++)
{
@event.Parameters[i].Name = function.Parameters[i].Name;
}
}
}
}
}
Expand Down Expand Up @@ -451,7 +463,11 @@ public void DocumentProperty(Property property)
{
if (property.IsOverride)
{
comment.BriefText = ((Class) property.Namespace).GetBaseProperty(property).Comment.BriefText;
Property baseProperty = ((Class) property.Namespace).GetBaseProperty(property);
if (baseProperty.Comment != null)
{
comment.BriefText = baseProperty.Comment.BriefText;
}
}
if (string.IsNullOrEmpty(comment.BriefText))
{
Expand Down Expand Up @@ -545,7 +561,7 @@ public void DocumentType(Class type)
summary.Content.Add(new TextComment { Text = briefText });
type.Comment.FullComment.Blocks.Add(summary);
var remarks = new ParagraphComment();
remarks.Content.AddRange(text.Split('\n').Select(t => new TextComment { Text = t }));
remarks.Content.AddRange(text.Split('\n').Select(t => new TextComment { Text = t, HasTrailingNewline = true }));
type.Comment.FullComment.Blocks.Add(remarks);
}
}
Expand Down
5 changes: 1 addition & 4 deletions QtSharp/GenerateEventEventsPass.cs
Expand Up @@ -90,10 +90,7 @@ public override bool VisitMethodDecl(Method method)
{
var name = char.ToUpperInvariant(method.Name[0]) + method.Name.Substring(1);
method.Name = "on" + name;
Method baseMethod;
if (!method.IsOverride ||
(baseMethod = ((Class) method.Namespace).GetBaseMethod(method, true, true)) == null ||
baseMethod.IsPure)
if (!method.IsOverride || method.BaseMethod.IsPure)
{
this.events.Add(method);
this.Context.Options.ExplicitlyPatchedVirtualFunctions.Add(method.QualifiedOriginalName);
Expand Down
17 changes: 9 additions & 8 deletions QtSharp/GenerateSignalEventsPass.cs
Expand Up @@ -108,14 +108,14 @@ private void GenerateSignalEvents(GeneratorOutput generatorOutput)
}
block.WriteLine(string.Format(@"public event {0} {1}
{{
add
{{
add
{{
ConnectDynamicSlot(this, ""{2}"", value);
}}
remove
{{
}}
remove
{{
DisconnectDynamicSlot(this, ""{2}"", value);
}}
}}
}}", fullNameBuilder, finalName, signature));
}
}
Expand Down Expand Up @@ -184,9 +184,10 @@ private void HandleQSignal(Class @class, Method method)
Name = method.Name,
OriginalName = method.OriginalName,
Namespace = method.Namespace,
QualifiedType = new QualifiedType(method.FunctionType.Type),
Parameters = method.Parameters
QualifiedType = new QualifiedType(method.FunctionType.Type)
};
@event.Parameters.AddRange(method.Parameters.Select(
p => new Parameter(p) { Namespace = @event }));
if (method.IsGenerated)
{
method.ExplicitlyIgnore();
Expand Down
2 changes: 2 additions & 0 deletions QtSharp/QFlags.cs
Expand Up @@ -50,6 +50,8 @@ public override void CSharpMarshalToManaged(CSharpMarshalContext ctx)
}
}

public override bool IsIgnored => Type != null ? Type.IsDependent : Declaration.IsDependent;

private static Type GetEnumType(Type mappedType)
{
var type = mappedType.Desugar();
Expand Down
16 changes: 8 additions & 8 deletions QtSharp/QString.cs
Expand Up @@ -13,15 +13,15 @@ public override string CSharpSignature(TypePrinterContext ctx)
{
if (ctx.Kind == TypePrinterContextKind.Native)
{
return string.Format("QtCore.QString.{0}{1}", Helpers.InternalStruct, ctx.Type.IsAddress() ? "*" : string.Empty);
return $"QtCore.QString.{Helpers.InternalStruct}{(ctx.Type.IsAddress() ? "*" : string.Empty)}";
}
return "string";
}

public override void CSharpMarshalToNative(CSharpMarshalContext ctx)
{
var type = ctx.Parameter.Type.Desugar();
var finalType = (type.GetFinalPointee() ?? type).Desugar();
var type = ctx.Parameter.Type.Desugar(false);
var finalType = (type.GetFinalPointee() ?? type).Desugar(false);
var substitution = finalType as TemplateParameterSubstitutionType;
string param;
if (substitution != null)
Expand Down Expand Up @@ -57,13 +57,13 @@ public override void CSharpMarshalToNative(CSharpMarshalContext ctx)

public override void CSharpMarshalToManaged(CSharpMarshalContext ctx)
{
var type = ctx.ReturnType.Type.Desugar();
var finalType = (type.GetFinalPointee() ?? type).Desugar();
var substitution = finalType as TemplateParameterSubstitutionType;
var type = ctx.ReturnType.Type.Desugar(false);
var finalType = (type.GetFinalPointee() ?? type).Desugar(false);
var templateParameter = finalType as TemplateParameterType;
string cast = string.Empty;
if (substitution != null)
if (templateParameter != null)
{
cast = $"({substitution.ReplacedParameter.Parameter.Name}) (object) ";
cast = $"({templateParameter.Parameter.Name}) (object) ";
}
ctx.Return.Write($@"{cast}Marshal.PtrToStringUni(new IntPtr(QtCore.QString.{
Helpers.CreateInstanceIdentifier}({ctx.ReturnVarName}).Utf16))");
Expand Down
48 changes: 2 additions & 46 deletions QtSharp/QtSharp.cs
Expand Up @@ -92,34 +92,6 @@ where string.IsNullOrEmpty(@enum.Name)
{
enumeration.Name = "TypeEnum";
}

// HACK: work around https://github.com/mono/CppSharp/issues/692
foreach (var name in new[] { "QImage", "QPixmap" })
{
var @class = lib.FindCompleteClass(name);
var ctorWithArray = @class.Constructors.FirstOrDefault(
c => c.Parameters.Count == 1 && c.Parameters[0].Type.Desugar() is ArrayType);
if (ctorWithArray != null)
{
ctorWithArray.ExplicitlyIgnore();
}
}
foreach (var name in new[] { "QGraphicsScene", "QGraphicsView" })
{
var @class = lib.FindCompleteClass(name);
var drawItems = @class.Methods.FirstOrDefault(m => m.OriginalName == "drawItems");
if (drawItems != null)
{
drawItems.ExplicitlyIgnore();
}
}
lib.FindCompleteClass("QAbstractPlanarVideoBuffer").ExplicitlyIgnore();
var qAbstractVideoBuffer = lib.FindCompleteClass("QAbstractVideoBuffer");
var mapPlanes = qAbstractVideoBuffer.Methods.FirstOrDefault(m => m.OriginalName == "mapPlanes");
if (mapPlanes != null)
{
mapPlanes.ExplicitlyIgnore();
}
}

public void Postprocess(Driver driver, ASTContext lib)
Expand Down Expand Up @@ -224,6 +196,7 @@ public void Setup(Driver driver)
module.Libraries.Add(libFile);
if (moduleName == "Core")
{
module.Headers.Insert(0, "guiddef.h");
module.CodeFiles.Add(Path.Combine(dir, "QObject.cs"));
module.CodeFiles.Add(Path.Combine(dir, "QChar.cs"));
module.CodeFiles.Add(Path.Combine(dir, "QEvent.cs"));
Expand All @@ -243,9 +216,6 @@ public void Setup(Driver driver)
driver.ParserOptions.AddIncludeDirs(qtInfo.Headers);

driver.ParserOptions.AddLibraryDirs(Platform.IsWindows ? qtInfo.Bins : qtInfo.Libs);

// Qt defines its own GUID with the same header guard as the system GUID, so ensure the system GUID is read first
driver.Project.AddFile("guiddef.h");
}

public static string GetModuleNameFromLibFile(string libFile)
Expand Down Expand Up @@ -322,21 +292,7 @@ private void CompileMakefile(GenerateSymbolsPass.SymbolsCodeEventArgs e)
proBuilder.Append("LIBS += -loleaut32 -lole32");
}
File.WriteAllText(path, proBuilder.ToString());
// HACK: work around https://bugreports.qt.io/browse/QTBUG-55952
if (e.Module.LibraryName == "Qt3DRender.Sharp")
{
var cpp = Path.ChangeExtension(pro, "cpp");
var unlinkable = new[]
{
"&Qt3DRender::QSortCriterion::tr;",
"&Qt3DRender::QSortCriterion::trUtf8;",
"&Qt3DRender::qt_getEnumMetaObject;"
};
var linkable = (from line in File.ReadLines(cpp)
where unlinkable.All(ul => !line.EndsWith(ul, StringComparison.Ordinal))
select line).ToList();
File.WriteAllLines(cpp, linkable);
}

int error;
string errorMessage;
ProcessHelper.Run(this.qtInfo.QMake, $"\"{path}\"", out error, out errorMessage);
Expand Down
25 changes: 9 additions & 16 deletions QtSharp/QtSharp.csproj
Expand Up @@ -38,32 +38,25 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="CppSharp, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\CppSharp.0.8.13\lib\CppSharp.dll</HintPath>
<Private>True</Private>
<HintPath>..\packages\CppSharp.0.8.14\lib\CppSharp.dll</HintPath>
</Reference>
<Reference Include="CppSharp.AST, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\CppSharp.0.8.13\lib\CppSharp.AST.dll</HintPath>
<Private>True</Private>
<HintPath>..\packages\CppSharp.0.8.14\lib\CppSharp.AST.dll</HintPath>
</Reference>
<Reference Include="CppSharp.Generator, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\CppSharp.0.8.13\lib\CppSharp.Generator.dll</HintPath>
<Private>True</Private>
<HintPath>..\packages\CppSharp.0.8.14\lib\CppSharp.Generator.dll</HintPath>
</Reference>
<Reference Include="CppSharp.Parser, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\CppSharp.0.8.13\lib\CppSharp.Parser.dll</HintPath>
<Private>True</Private>
<HintPath>..\packages\CppSharp.0.8.14\lib\CppSharp.Parser.dll</HintPath>
</Reference>
<Reference Include="CppSharp.Parser.CSharp, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\CppSharp.0.8.13\lib\CppSharp.Parser.CSharp.dll</HintPath>
<Private>True</Private>
<Reference Include="CppSharp.Parser.CLI, Version=0.0.0.0, Culture=neutral, processorArchitecture=AMD64">
<HintPath>..\packages\CppSharp.0.8.14\lib\CppSharp.Parser.CLI.dll</HintPath>
</Reference>
<Reference Include="CppSharp.Runtime, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\CppSharp.0.8.13\lib\CppSharp.Runtime.dll</HintPath>
<Private>True</Private>
<HintPath>..\packages\CppSharp.0.8.14\lib\CppSharp.Runtime.dll</HintPath>
</Reference>
<Reference Include="HtmlAgilityPack, Version=1.5.1.0, Culture=neutral, PublicKeyToken=bd319b19eaf3b43a, processorArchitecture=MSIL">
<HintPath>..\packages\HtmlAgilityPack.1.5.1\lib\Net45\HtmlAgilityPack.dll</HintPath>
<Private>True</Private>
<Reference Include="HtmlAgilityPack, Version=1.5.5.0, Culture=neutral, PublicKeyToken=bd319b19eaf3b43a, processorArchitecture=MSIL">
<HintPath>..\packages\HtmlAgilityPack.1.5.5\lib\Net45\HtmlAgilityPack.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.dll</HintPath>
Expand Down
4 changes: 2 additions & 2 deletions QtSharp/packages.config
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Baseclass.Contrib.Nuget.Output" version="2.3.0" targetFramework="net461" />
<package id="CppSharp" version="0.8.13" targetFramework="net461" developmentDependency="true" />
<package id="HtmlAgilityPack" version="1.5.1" targetFramework="net461" />
<package id="CppSharp" version="0.8.14" targetFramework="net461" developmentDependency="true" />
<package id="HtmlAgilityPack" version="1.5.5" targetFramework="net461" />
<package id="Mono.Cecil" version="0.9.6.4" targetFramework="net461" />
<package id="zlib.net" version="1.0.4" targetFramework="net451" />
</packages>

0 comments on commit d509ac6

Please sign in to comment.