Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended the support for ClangSharp via libClangSharp #159

Merged
merged 12 commits into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<PackageOutputPath>$(BaseArtifactsPath)pkg/$(Configuration)/</PackageOutputPath>
<Product>ClangSharp</Product>
<VersionPrefix>10.0.0</VersionPrefix>
<VersionSuffix>beta</VersionSuffix>
<VersionSuffix>beta2</VersionSuffix>
</PropertyGroup>

<!-- Default settings that are otherwise undefined -->
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<!-- Package versions for package references across all projects -->
<ItemGroup>
<PackageReference Update="libClang" Version="10.0.0" />
<PackageReference Update="libClangSharp" Version="10.0.0-beta1" />
<PackageReference Update="libClangSharp" Version="10.0.0-beta2" />
<PackageReference Update="Microsoft.Bcl.HashCode" Version="1.1.0" />
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Update="System.CommandLine" Version="2.0.0-beta1.20253.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata minClientVersion="2.12">
<id>libClangSharp.runtime.freebsd.11-x64</id>
<version>10.0.0-beta1</version>
<version>10.0.0-beta2</version>
<authors>Microsoft and Contributors</authors>
<owners>Microsoft and Contributors</owners>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata minClientVersion="2.12">
<id>libClangSharp.runtime.freebsd.11-x86</id>
<version>10.0.0-beta1</version>
<version>10.0.0-beta2</version>
<authors>Microsoft and Contributors</authors>
<owners>Microsoft and Contributors</owners>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata minClientVersion="2.12">
<id>libClangSharp.runtime.linux-arm</id>
<version>10.0.0-beta1</version>
<version>10.0.0-beta2</version>
<authors>Microsoft and Contributors</authors>
<owners>Microsoft and Contributors</owners>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata minClientVersion="2.12">
<id>libClangSharp.runtime.linux-arm64</id>
<version>10.0.0-beta1</version>
<version>10.0.0-beta2</version>
<authors>Microsoft and Contributors</authors>
<owners>Microsoft and Contributors</owners>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata minClientVersion="2.12">
<id>libClangSharp.runtime.osx-x64</id>
<version>10.0.0-beta1</version>
<version>10.0.0-beta2</version>
<authors>Microsoft and Contributors</authors>
<owners>Microsoft and Contributors</owners>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata minClientVersion="2.12">
<id>libClangSharp.runtime.sles-x64</id>
<version>10.0.0-beta1</version>
<version>10.0.0-beta2</version>
<authors>Microsoft and Contributors</authors>
<owners>Microsoft and Contributors</owners>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata minClientVersion="2.12">
<id>libClangSharp.runtime.ubuntu.16.04-x64</id>
<version>10.0.0-beta1</version>
<version>10.0.0-beta2</version>
<authors>Microsoft and Contributors</authors>
<owners>Microsoft and Contributors</owners>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata minClientVersion="2.12">
<id>libClangSharp.runtime.ubuntu.18.04-x64</id>
<version>10.0.0-beta1</version>
<version>10.0.0-beta2</version>
<authors>Microsoft and Contributors</authors>
<owners>Microsoft and Contributors</owners>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata minClientVersion="2.12">
<id>libClangSharp.runtime.ubuntu.20.04-x64</id>
<version>10.0.0-beta1</version>
<version>10.0.0-beta2</version>
<authors>Microsoft and Contributors</authors>
<owners>Microsoft and Contributors</owners>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata minClientVersion="2.12">
<id>libClangSharp.runtime.win-x64</id>
<version>10.0.0-beta1</version>
<version>10.0.0-beta2</version>
<authors>Microsoft and Contributors</authors>
<owners>Microsoft and Contributors</owners>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata minClientVersion="2.12">
<id>libClangSharp.runtime.win-x86</id>
<version>10.0.0-beta1</version>
<version>10.0.0-beta2</version>
<authors>Microsoft and Contributors</authors>
<owners>Microsoft and Contributors</owners>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
Expand Down
2 changes: 1 addition & 1 deletion packages/libClangSharp/libClangSharp/libClangSharp.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata minClientVersion="2.12">
<id>libClangSharp</id>
<version>10.0.0-beta1</version>
<version>10.0.0-beta2</version>
<authors>Microsoft and Contributors</authors>
<owners>Microsoft and Contributors</owners>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
Expand Down
22 changes: 11 additions & 11 deletions packages/libClangSharp/libClangSharp/runtime.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,57 @@
"runtimes": {
"freebsd.11-x64": {
"libClangSharp": {
"libClangSharp.runtime.freebsd.11-x64": "10.0.0-beta1"
"libClangSharp.runtime.freebsd.11-x64": "10.0.0-beta2"
}
},
"freebsd.11-x86": {
"libClangSharp": {
"libClangSharp.runtime.freebsd.11-x86": "10.0.0-beta1"
"libClangSharp.runtime.freebsd.11-x86": "10.0.0-beta2"
}
},
"linux-arm": {
"libClangSharp": {
"libClangSharp.runtime.linux-arm": "10.0.0-beta1"
"libClangSharp.runtime.linux-arm": "10.0.0-beta2"
}
},
"linux-arm64": {
"libClangSharp": {
"libClangSharp.runtime.linux-arm64": "10.0.0-beta1"
"libClangSharp.runtime.linux-arm64": "10.0.0-beta2"
}
},
"osx-x64": {
"libClangSharp": {
"libClangSharp.runtime.osx-x64": "10.0.0-beta1"
"libClangSharp.runtime.osx-x64": "10.0.0-beta2"
}
},
"sles-x64": {
"libClangSharp": {
"libClangSharp.runtime.sles-x64": "10.0.0-beta1"
"libClangSharp.runtime.sles-x64": "10.0.0-beta2"
}
},
"ubuntu.16.04-x64": {
"libClangSharp": {
"libClangSharp.runtime.ubuntu.16.04-x64": "10.0.0-beta1"
"libClangSharp.runtime.ubuntu.16.04-x64": "10.0.0-beta2"
}
},
"ubuntu.18.04-x64": {
"libClangSharp": {
"libClangSharp.runtime.ubuntu.18.04-x64": "10.0.0-beta1"
"libClangSharp.runtime.ubuntu.18.04-x64": "10.0.0-beta2"
}
},
"ubuntu.20.04-x64": {
"libClangSharp": {
"libClangSharp.runtime.ubuntu.20.04-x64": "10.0.0-beta1"
"libClangSharp.runtime.ubuntu.20.04-x64": "10.0.0-beta2"
}
},
"win-x64": {
"libClangSharp": {
"libClangSharp.runtime.win-x64": "10.0.0-beta1"
"libClangSharp.runtime.win-x64": "10.0.0-beta2"
}
},
"win-x86": {
"libClangSharp": {
"libClangSharp.runtime.win-x86": "10.0.0-beta1"
"libClangSharp.runtime.win-x86": "10.0.0-beta2"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ private void VisitExplicitCastExpr(ExplicitCastExpr explicitCastExpr)

private void VisitFloatingLiteral(FloatingLiteral floatingLiteral)
{
_outputBuilder.Write(floatingLiteral.Value);
_outputBuilder.Write(floatingLiteral.ValueString);
}

private void VisitForStmt(ForStmt forStmt)
Expand Down Expand Up @@ -656,14 +656,14 @@ private void VisitInitListExprForType(InitListExpr initListExpr, Type type)

private void VisitIntegerLiteral(IntegerLiteral integerLiteral)
{
var value = integerLiteral.Value;
var valueString = integerLiteral.ValueString;

if (value.EndsWith("l") || value.EndsWith("L"))
if (valueString.EndsWith("l") || valueString.EndsWith("L"))
{
value = value.Substring(0, value.Length - 1);
valueString = valueString.Substring(0, valueString.Length - 1);
}

_outputBuilder.Write(value);
_outputBuilder.Write(valueString);
}

private void VisitMemberExpr(MemberExpr memberExpr)
Expand Down
37 changes: 37 additions & 0 deletions sources/ClangSharp/Capture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.

using System;

namespace ClangSharp
{
public sealed class Capture
{
private readonly Decl _parentDecl;
private readonly uint _index;
private readonly Lazy<Expr> _copyExpr;
private readonly Lazy<VarDecl> _variable;

internal Capture(Decl parentDecl, uint index)
{
_parentDecl = parentDecl;
_index = index;

_copyExpr = new Lazy<Expr>(() => _parentDecl.TranslationUnit.GetOrCreate<Expr>(_parentDecl.Handle.GetCaptureCopyExpr(_index)));
_variable = new Lazy<VarDecl>(() => _parentDecl.TranslationUnit.GetOrCreate<VarDecl>(_parentDecl.Handle.GetCaptureVariable(_index)));
}

public Expr CopyExpr => _copyExpr.Value;

public bool HasCopyExpr => _parentDecl.Handle.GetCaptureHasCopyExpr(_index);

public bool IsByRef => _parentDecl.Handle.GetCaptureIsByRef(_index);

public bool IsEscapingByRef => _parentDecl.Handle.GetCaptureIsEscapingByRef(_index);

public bool IsNested => _parentDecl.Handle.GetCaptureIsNested(_index);

public bool IsNonEscapingByRef => _parentDecl.Handle.GetCaptureIsNonEscapingByRef(_index);

public VarDecl Variable => _variable.Value;
}
}
29 changes: 14 additions & 15 deletions sources/ClangSharp/Cursors/Cursor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ namespace ClangSharp
[DebuggerDisplay("{Handle.DebuggerDisplayString,nq}")]
public unsafe class Cursor : IEquatable<Cursor>
{
private readonly Lazy<List<Cursor>> _cursorChildren;
private readonly Lazy<TranslationUnit> _translationUnit;
private readonly List<Cursor> _cursorChildren;
private readonly TranslationUnit _translationUnit;

private protected Cursor(CXCursor handle, CXCursorKind expectedCursorKind)
{
Expand All @@ -21,23 +21,22 @@ private protected Cursor(CXCursor handle, CXCursorKind expectedCursorKind)
}
Handle = handle;

_cursorChildren = new Lazy<List<Cursor>>(() => {
var cursors = new List<Cursor>();
_translationUnit = TranslationUnit.GetOrCreate(Handle.TranslationUnit);

Handle.VisitChildren((cursor, parent, clientData) => {
var cursorChild = TranslationUnit.GetOrCreate<Cursor>(cursor);
cursorChild.CursorParent = this;
var cursorChildren = new List<Cursor>();

cursors.Add(cursorChild);
return CXChildVisitResult.CXChildVisit_Continue;
}, clientData: default);
Handle.VisitChildren((cursor, parent, clientData) => {
var cursorChild = TranslationUnit.GetOrCreate<Cursor>(cursor);
cursorChild.CursorParent = this;

return cursors;
});
_translationUnit = new Lazy<TranslationUnit>(() => TranslationUnit.GetOrCreate(Handle.TranslationUnit));
cursorChildren.Add(cursorChild);
return CXChildVisitResult.CXChildVisit_Continue;
}, clientData: default);

_cursorChildren = cursorChildren;
}

public IReadOnlyList<Cursor> CursorChildren => _cursorChildren.Value;
public IReadOnlyList<Cursor> CursorChildren => _cursorChildren;

public CXCursorKind CursorKind => Handle.Kind;

Expand All @@ -53,7 +52,7 @@ private protected Cursor(CXCursor handle, CXCursorKind expectedCursorKind)

public string Spelling => Handle.Spelling.ToString();

public TranslationUnit TranslationUnit => _translationUnit.Value;
public TranslationUnit TranslationUnit => _translationUnit;

public static bool operator ==(Cursor left, Cursor right) => (left is object) ? ((right is object) && (left.Handle == right.Handle)) : (right is null);

Expand Down
14 changes: 14 additions & 0 deletions sources/ClangSharp/Cursors/Decls/BindingDecl.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information.

using System;
using ClangSharp.Interop;

namespace ClangSharp
{
public sealed class BindingDecl : ValueDecl
{
private readonly Lazy<Expr> _binding;
private readonly Lazy<ValueDecl> _decomposedDecl;
private readonly Lazy<VarDecl> _holdingVar;

internal BindingDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedDecl, CX_DeclKind.CX_DeclKind_Binding)
{
_binding = new Lazy<Expr>(() => TranslationUnit.GetOrCreate<Expr>(Handle.Binding));
_decomposedDecl = new Lazy<ValueDecl>(() => TranslationUnit.GetOrCreate<ValueDecl>(Handle.DecomposedDecl));
_holdingVar = new Lazy<VarDecl>(() => TranslationUnit.GetOrCreate<VarDecl>(Handle.HoldingVar));
}

public Expr Binding => _binding.Value;

public ValueDecl DecomposedDecl => _decomposedDecl.Value;

public VarDecl HoldingVar => _holdingVar.Value;
}
}
Loading