diff --git a/sources/ClangSharp/Cursors/Cursor.cs b/sources/ClangSharp/Cursors/Cursor.cs index 417557a3..aa9d4c3a 100644 --- a/sources/ClangSharp/Cursors/Cursor.cs +++ b/sources/ClangSharp/Cursors/Cursor.cs @@ -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}."); diff --git a/sources/ClangSharp/Cursors/Preprocessings/InclusionDirective.cs b/sources/ClangSharp/Cursors/Preprocessings/InclusionDirective.cs new file mode 100644 index 00000000..47186c85 --- /dev/null +++ b/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) + { + } + } +} diff --git a/sources/ClangSharp/Cursors/Preprocessings/MacroDefinition.cs b/sources/ClangSharp/Cursors/Preprocessings/MacroDefinition.cs new file mode 100644 index 00000000..ec83e15d --- /dev/null +++ b/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; + } +} diff --git a/sources/ClangSharp/Cursors/Preprocessings/MacroExpansion.cs b/sources/ClangSharp/Cursors/Preprocessings/MacroExpansion.cs new file mode 100644 index 00000000..27d46c3d --- /dev/null +++ b/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; + } +} diff --git a/sources/ClangSharp/Cursors/Preprocessings/PreprocessedEntity.cs b/sources/ClangSharp/Cursors/Preprocessings/PreprocessedEntity.cs new file mode 100644 index 00000000..aafa50ee --- /dev/null +++ b/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; + } + } +} diff --git a/sources/ClangSharp/Cursors/Preprocessings/PreprocessingDirective.cs b/sources/ClangSharp/Cursors/Preprocessings/PreprocessingDirective.cs new file mode 100644 index 00000000..f4b32362 --- /dev/null +++ b/sources/ClangSharp/Cursors/Preprocessings/PreprocessingDirective.cs @@ -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) + { + } + } +}