Skip to content
Permalink
Browse files

Add Preprocessing Wrappers (#84)

* Add Preprocessing Wrappers

* Change structure layout.
  • Loading branch information...
udaken authored and tannergooding committed Aug 19, 2019
1 parent 57c618b commit 6e994d700f746fe6d2df0aaa817351b503c8376d
@@ -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}.");
@@ -0,0 +1,11 @@
using ClangSharp.Interop;

namespace ClangSharp
{
public sealed class InclusionDirective : PreprocessingDirective
{
internal InclusionDirective(CXCursor handle) : base(handle, CXCursorKind.CXCursor_InclusionDirective)
{
}
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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.
You can’t perform that action at this time.