Skip to content

Commit

Permalink
Add Preprocessing Wrappers (#84)
Browse files Browse the repository at this point in the history
* Add Preprocessing Wrappers

* Change structure layout.
  • Loading branch information
udaken authored and tannergooding committed Aug 19, 2019
1 parent 57c618b commit 6e994d7
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 0 deletions.
4 changes: 4 additions & 0 deletions sources/ClangSharp/Cursors/Cursor.cs
Expand Up @@ -80,6 +80,10 @@ internal static Cursor Create(CXCursor handle)
{
result = Attr.Create(handle);
}
else if (handle.IsPreprocessing)
{
result = PreprocessedEntity.Create(handle);
}
else
{
Debug.WriteLine($"Unhandled cursor kind: {handle.KindSpelling}.");
Expand Down
11 changes: 11 additions & 0 deletions sources/ClangSharp/Cursors/Preprocessings/InclusionDirective.cs
@@ -0,0 +1,11 @@
using ClangSharp.Interop;

namespace ClangSharp
{
public sealed class InclusionDirective : PreprocessingDirective
{
internal InclusionDirective(CXCursor handle) : base(handle, CXCursorKind.CXCursor_InclusionDirective)
{
}
}
}
15 changes: 15 additions & 0 deletions sources/ClangSharp/Cursors/Preprocessings/MacroDefinition.cs
@@ -0,0 +1,15 @@
using ClangSharp.Interop;

namespace ClangSharp
{
public sealed class MacroDefinitionRecord : PreprocessingDirective
{
internal MacroDefinitionRecord(CXCursor handle) : base(handle, CXCursorKind.CXCursor_MacroDefinition)
{
}

public bool IsMacroFunctionLike => Handle.IsMacroFunctionLike;

public bool IsMacroBuiltIn => Handle.IsMacroBuiltIn;
}
}
13 changes: 13 additions & 0 deletions sources/ClangSharp/Cursors/Preprocessings/MacroExpansion.cs
@@ -0,0 +1,13 @@
using ClangSharp.Interop;

namespace ClangSharp
{
public sealed class MacroExpansion : PreprocessedEntity
{
internal MacroExpansion(CXCursor handle) : base(handle, CXCursorKind.CXCursor_MacroExpansion)
{
}

public bool IsMacroBuiltIn => Handle.IsMacroBuiltIn;
}
}
58 changes: 58 additions & 0 deletions sources/ClangSharp/Cursors/Preprocessings/PreprocessedEntity.cs
@@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using ClangSharp.Interop;

namespace ClangSharp
{
public class PreprocessedEntity : Cursor
{
private protected PreprocessedEntity(CXCursor handle, CXCursorKind expectedKind) : base(handle, expectedKind)
{
}

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

switch (handle.Kind)
{
case CXCursorKind.CXCursor_MacroDefinition:
{
result = new MacroDefinitionRecord(handle);
break;
}

case CXCursorKind.CXCursor_MacroExpansion:
{
result = new MacroExpansion(handle);
break;
}

case CXCursorKind.CXCursor_PreprocessingDirective:
{
result = new PreprocessingDirective(handle);
break;
}

case CXCursorKind.CXCursor_InclusionDirective:
{
result = new InclusionDirective(handle);
break;
}

default:
{
Debug.WriteLine($"Unhandled preprocessing kind: {handle.KindSpelling}.");
Debugger.Break();

result = new PreprocessedEntity(handle, handle.Kind);
break;
}
}

return result;
}
}
}
@@ -0,0 +1,14 @@
using ClangSharp.Interop;

namespace ClangSharp
{
public class PreprocessingDirective : PreprocessedEntity
{
internal PreprocessingDirective(CXCursor handle) : this(handle, CXCursorKind.CXCursor_PreprocessingDirective)
{
}
private protected PreprocessingDirective(CXCursor handle, CXCursorKind expectedKind) : base(handle, expectedKind)
{
}
}
}

0 comments on commit 6e994d7

Please sign in to comment.