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 1 commit
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
Expand Up @@ -80,6 +80,10 @@ internal static Cursor Create(CXCursor handle)
{
result = Attr.Create(handle);
}
else if (handle.IsPreprocessing)
{
result = Preprocessing.Create(handle);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I've tried to mirror the Clang C++ API structure where applicable.

In this case, it would be:

class PreprocessedEntity : Cursor  { }
class MacroExpansion : PreprocessedEntity { }
class PreprocessingDirective : PreprocessedEntity { }
class InclusionDirective : PreprocessingDirective { }
class MacroDefinitionRecord : PreprocessingDirective { }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following the C++ API gives a structured layout that closely mirrors the actual OOP API design and allows various bits of code to be shared where it makes sense due to the backing data the cursor handles represent

}
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 : Preprocessing
{
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 MacroDefinition : Preprocessing
{
internal MacroDefinition(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 : Preprocessing
{
internal MacroExpansion(CXCursor handle) : base(handle, CXCursorKind.CXCursor_MacroExpansion)
{
}

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

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

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

switch (handle.Kind)
{
case CXCursorKind.CXCursor_MacroDefinition:
{
result = new MacroDefinition(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 Preprocessing(handle, handle.Kind);
break;
}
}

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

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