Skip to content

Commit

Permalink
Adding Attr, Decl, and Expr types for the full set of exposed kinds
Browse files Browse the repository at this point in the history
  • Loading branch information
tannergooding committed Nov 14, 2019
1 parent 4479bc0 commit 697d136
Show file tree
Hide file tree
Showing 318 changed files with 3,228 additions and 918 deletions.
128 changes: 30 additions & 98 deletions sources/ClangSharp/Cursors/Attrs/Attr.cs
Original file line number Diff line number Diff line change
@@ -1,122 +1,54 @@
// 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.Diagnostics;
using System;
using ClangSharp.Interop;

namespace ClangSharp
{
public class Attr : Cursor
{
private protected Attr(CXCursor handle, CXCursorKind expectedKind) : base(handle, expectedKind)
private protected Attr(CXCursor handle) : base(handle, handle.Kind)
{
if (handle.AttrKind == CX_AttrKind.CX_AK_Invalid)
{
throw new ArgumentException(nameof(handle));
}
}

internal static new Attr Create(CXCursor handle)
{
Attr result;

switch (handle.Kind)
if ((CX_AttrKind.CX_AK_FirstTypeAttr <= handle.AttrKind) && (handle.AttrKind <= CX_AttrKind.CX_AK_LastTypeAttr))
{
case CXCursorKind.CXCursor_UnexposedAttr:
{
result = new Attr(handle, CXCursorKind.CXCursor_UnexposedAttr);
break;
}

case CXCursorKind.CXCursor_IBActionAttr:
case CXCursorKind.CXCursor_IBOutletAttr:
case CXCursorKind.CXCursor_IBOutletCollectionAttr:
case CXCursorKind.CXCursor_CXXFinalAttr:
case CXCursorKind.CXCursor_CXXOverrideAttr:
{
result = new InheritableAttr(handle, handle.Kind);
break;
}


case CXCursorKind.CXCursor_AnnotateAttr:
{
result = new InheritableParamAttr(handle, handle.Kind);
break;
}

case CXCursorKind.CXCursor_AsmLabelAttr:
case CXCursorKind.CXCursor_PackedAttr:
case CXCursorKind.CXCursor_PureAttr:
case CXCursorKind.CXCursor_ConstAttr:
case CXCursorKind.CXCursor_NoDuplicateAttr:
case CXCursorKind.CXCursor_CUDAConstantAttr:
case CXCursorKind.CXCursor_CUDADeviceAttr:
case CXCursorKind.CXCursor_CUDAGlobalAttr:
case CXCursorKind.CXCursor_CUDAHostAttr:
case CXCursorKind.CXCursor_CUDASharedAttr:
case CXCursorKind.CXCursor_VisibilityAttr:
case CXCursorKind.CXCursor_DLLExport:
case CXCursorKind.CXCursor_DLLImport:
{
result = new InheritableAttr(handle, handle.Kind);
break;
}

case CXCursorKind.CXCursor_NSReturnsRetained:
{
result = new DeclOrTypeAttr(handle, handle.Kind);
break;
}

case CXCursorKind.CXCursor_NSReturnsNotRetained:
case CXCursorKind.CXCursor_NSReturnsAutoreleased:
case CXCursorKind.CXCursor_NSConsumesSelf:
{
result = new InheritableAttr(handle, handle.Kind);
break;
}

case CXCursorKind.CXCursor_NSConsumed:
{
result = new InheritableParamAttr(handle, handle.Kind);
break;
}

case CXCursorKind.CXCursor_ObjCException:
case CXCursorKind.CXCursor_ObjCNSObject:
case CXCursorKind.CXCursor_ObjCIndependentClass:
case CXCursorKind.CXCursor_ObjCPreciseLifetime:
case CXCursorKind.CXCursor_ObjCReturnsInnerPointer:
case CXCursorKind.CXCursor_ObjCRequiresSuper:
case CXCursorKind.CXCursor_ObjCRootClass:
case CXCursorKind.CXCursor_ObjCSubclassingRestricted:
case CXCursorKind.CXCursor_ObjCExplicitProtocolImpl:
{
result = new InheritableAttr(handle, handle.Kind);
break;
}

case CXCursorKind.CXCursor_ObjCDesignatedInitializer:
case CXCursorKind.CXCursor_ObjCRuntimeVisible:
case CXCursorKind.CXCursor_ObjCBoxable:
{
result = new Attr(handle, handle.Kind);
break;
}

case CXCursorKind.CXCursor_FlagEnum:
case CXCursorKind.CXCursor_ConvergentAttr:
case CXCursorKind.CXCursor_WarnUnusedAttr:
case CXCursorKind.CXCursor_WarnUnusedResultAttr:
case CXCursorKind.CXCursor_AlignedAttr:
result = new TypeAttr(handle);
}
else if ((CX_AttrKind.CX_AK_FirstStmtAttr <= handle.AttrKind) && (handle.AttrKind <= CX_AttrKind.CX_AK_LastStmtAttr))
{
result = new StmtAttr(handle);
}
else if ((CX_AttrKind.CX_AK_FirstInheritableAttr <= handle.AttrKind) && (handle.AttrKind <= CX_AttrKind.CX_AK_LastInheritableAttr))
{
if ((CX_AttrKind.CX_AK_FirstInheritableParamAttr <= handle.AttrKind) && (handle.AttrKind <= CX_AttrKind.CX_AK_LastInheritableParamAttr))
{
result = new InheritableAttr(handle, handle.Kind);
break;
if ((CX_AttrKind.CX_AK_FirstParameterABIAttr <= handle.AttrKind) && (handle.AttrKind <= CX_AttrKind.CX_AK_LastParameterABIAttr))
{
result = new ParameterABIAttr(handle);
}
else
{
result = new InheritableParamAttr(handle);
}
}

default:
else
{
Debug.WriteLine($"Unhandled attribute kind: {handle.KindSpelling}.");
result = new Attr(handle, handle.kind);
break;
result = new InheritableAttr(handle);
}
}
else
{
result = new Attr(handle);
}

return result;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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 class InheritableAttr : Attr
{
internal InheritableAttr(CXCursor handle) : base(handle)
{
if ((CX_AttrKind.CX_AK_LastInheritableAttr < handle.AttrKind) || (handle.AttrKind < CX_AttrKind.CX_AK_FirstInheritableAttr))
{
throw new ArgumentException(nameof(handle));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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 class InheritableParamAttr : InheritableAttr
{
internal InheritableParamAttr(CXCursor handle) : base(handle)
{
if ((CX_AttrKind.CX_AK_LastInheritableParamAttr < handle.AttrKind) || (handle.AttrKind < CX_AttrKind.CX_AK_FirstInheritableParamAttr))
{
throw new ArgumentException(nameof(handle));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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 ParameterABIAttr : InheritableParamAttr
{
internal ParameterABIAttr(CXCursor handle) : base(handle)
{
if ((CX_AttrKind.CX_AK_LastParameterABIAttr < handle.AttrKind) || (handle.AttrKind < CX_AttrKind.CX_AK_FirstParameterABIAttr))
{
throw new ArgumentException(nameof(handle));
}
}
}
}
18 changes: 18 additions & 0 deletions sources/ClangSharp/Cursors/Attrs/StmtAttr.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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 StmtAttr : Attr
{
internal StmtAttr(CXCursor handle) : base(handle)
{
if ((CX_AttrKind.CX_AK_LastStmtAttr < handle.AttrKind) || (handle.AttrKind < CX_AttrKind.CX_AK_FirstStmtAttr))
{
throw new ArgumentException(nameof(handle));
}
}
}
}
18 changes: 18 additions & 0 deletions sources/ClangSharp/Cursors/Attrs/TypeAttr.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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 TypeAttr : Attr
{
internal TypeAttr(CXCursor handle) : base(handle)
{
if ((CX_AttrKind.CX_AK_LastTypeAttr < handle.AttrKind) || (handle.AttrKind < CX_AttrKind.CX_AK_FirstTypeAttr))
{
throw new ArgumentException(nameof(handle));
}
}
}
}
4 changes: 2 additions & 2 deletions sources/ClangSharp/Cursors/Cursor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public unsafe class Cursor : IEquatable<Cursor>
private readonly Lazy<List<Cursor>> _cursorChildren;
private readonly Lazy<TranslationUnit> _translationUnit;

private protected Cursor(CXCursor handle, CXCursorKind expectedKind)
private protected Cursor(CXCursor handle, CXCursorKind expectedCursorKind)
{
if (handle.kind != expectedKind)
if (handle.kind != expectedCursorKind)
{
throw new ArgumentException(nameof(handle));
}
Expand Down
2 changes: 1 addition & 1 deletion sources/ClangSharp/Cursors/Decls/AccessSpecDecl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace ClangSharp
{
public sealed class AccessSpecDecl : Decl
{
internal AccessSpecDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_CXXAccessSpecifier)
internal AccessSpecDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_CXXAccessSpecifier, CX_DeclKind.CX_DK_AccessSpec)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// 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 ClangSharp.Interop;
using System;
using System.Collections.Generic;
using System.Linq;
using ClangSharp.Interop;

namespace ClangSharp
{
public class ObjCContainerDecl : NamedDecl, IDeclContext
public sealed class BlockDecl : Decl, IDeclContext
{
private readonly Lazy<IReadOnlyList<Decl>> _decls;

private protected ObjCContainerDecl(CXCursor handle, CXCursorKind expectedKind) : base(handle, expectedKind)
internal BlockDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedDecl, CX_DeclKind.CX_DK_Block)
{
_decls = new Lazy<IReadOnlyList<Decl>>(() => CursorChildren.Where((cursor) => cursor is Decl).Cast<Decl>().ToList());
_decls = new Lazy<IReadOnlyList<Decl>>(() => CursorChildren.OfType<Decl>().ToList());
}

public IReadOnlyList<Decl> Decls => _decls.Value;
Expand Down
25 changes: 25 additions & 0 deletions sources/ClangSharp/Cursors/Decls/CapturedDecl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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 ClangSharp.Interop;
using System;
using System.Collections.Generic;
using System.Linq;

namespace ClangSharp
{
public sealed class CapturedDecl : Decl, IDeclContext
{
private readonly Lazy<IReadOnlyList<Decl>> _decls;

internal CapturedDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedDecl, CX_DeclKind.CX_DK_Captured)
{
_decls = new Lazy<IReadOnlyList<Decl>>(() => CursorChildren.OfType<Decl>().ToList());
}

public IReadOnlyList<Decl> Decls => _decls.Value;

public IDeclContext LexicalParent => LexicalDeclContext;

public IDeclContext Parent => DeclContext;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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 ClangSharp.Interop;

namespace ClangSharp
{
public sealed class ClassScopeFunctionSpecializationDecl : Decl
{
internal ClassScopeFunctionSpecializationDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedDecl, CX_DeclKind.CX_DK_ClassScopeFunctionSpecialization)
{
}
}
}
Loading

0 comments on commit 697d136

Please sign in to comment.