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

Add Preprocessing Wrappers #84

Merged
merged 2 commits into from
Aug 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions sources/ClangSharp/Cursors/Cursor.cs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Original file line number Diff line number Diff line change
@@ -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)
{
}
}
}