diff --git a/ClangSharp.sln b/ClangSharp.sln index 7eb4f5be..090f87a1 100644 --- a/ClangSharp.sln +++ b/ClangSharp.sln @@ -163,29 +163,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libClangSharp.runtime.osx-x packages\libClangSharp\libClangSharp.runtime.osx-x64\libClangSharp.runtime.osx-x64.nuspec = packages\libClangSharp\libClangSharp.runtime.osx-x64\libClangSharp.runtime.osx-x64.nuspec EndProjectSection EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libClangSharp.runtime.sles-x64", "libClangSharp.runtime.sles-x64", "{4899758D-1953-4BCF-99FD-B0EC2BF136E6}" - ProjectSection(SolutionItems) = preProject - packages\libClangSharp\libClangSharp.runtime.sles-x64\libClangSharp.runtime.sles-x64.nuspec = packages\libClangSharp\libClangSharp.runtime.sles-x64\libClangSharp.runtime.sles-x64.nuspec - EndProjectSection -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libClangSharp.runtime.ubuntu.14.04-x64", "libClangSharp.runtime.ubuntu.14.04-x64", "{634CC4D7-B517-45C4-8747-CEAA675D6FCF}" - ProjectSection(SolutionItems) = preProject - packages\libClangSharp\libClangSharp.runtime.ubuntu.14.04-x64\libClangSharp.runtime.ubuntu.14.04-x64.nuspec = packages\libClangSharp\libClangSharp.runtime.ubuntu.14.04-x64\libClangSharp.runtime.ubuntu.14.04-x64.nuspec - EndProjectSection -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libClangSharp.runtime.ubuntu.16.04-x64", "libClangSharp.runtime.ubuntu.16.04-x64", "{2CA7E536-E6BE-4BE7-B29D-20C212EE9832}" - ProjectSection(SolutionItems) = preProject - packages\libClangSharp\libClangSharp.runtime.ubuntu.16.04-x64\libClangSharp.runtime.ubuntu.16.04-x64.nuspec = packages\libClangSharp\libClangSharp.runtime.ubuntu.16.04-x64\libClangSharp.runtime.ubuntu.16.04-x64.nuspec - EndProjectSection -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libClangSharp.runtime.ubuntu.18.04-x64", "libClangSharp.runtime.ubuntu.18.04-x64", "{A04F314B-2373-496E-879F-763B5C8EAF00}" ProjectSection(SolutionItems) = preProject packages\libClangSharp\libClangSharp.runtime.ubuntu.18.04-x64\libClangSharp.runtime.ubuntu.18.04-x64.nuspec = packages\libClangSharp\libClangSharp.runtime.ubuntu.18.04-x64\libClangSharp.runtime.ubuntu.18.04-x64.nuspec EndProjectSection EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libClangSharp.runtime.ubuntu.19.04-x64", "libClangSharp.runtime.ubuntu.19.04-x64", "{21997B0D-AE07-4F1E-8042-84EB399269D5}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libClangSharp.runtime.ubuntu.20.04-x64", "libClangSharp.runtime.ubuntu.20.04-x64", "{21997B0D-AE07-4F1E-8042-84EB399269D5}" ProjectSection(SolutionItems) = preProject - packages\libClangSharp\libClangSharp.runtime.ubuntu.19.04-x64\libClangSharp.runtime.ubuntu.19.04-x64.nuspec = packages\libClangSharp\libClangSharp.runtime.ubuntu.19.04-x64\libClangSharp.runtime.ubuntu.19.04-x64.nuspec + packages\libClangSharp\libClangSharp.runtime.ubuntu.20.04-x64\libClangSharp.runtime.ubuntu.20.04-x64.nuspec = packages\libClangSharp\libClangSharp.runtime.ubuntu.20.04-x64\libClangSharp.runtime.ubuntu.20.04-x64.nuspec EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libClangSharp.runtime.win-x64", "libClangSharp.runtime.win-x64", "{C1218464-0B5A-480E-BA13-2C6EA370987E}" @@ -276,9 +261,6 @@ Global {B48A71F0-AF48-4010-941F-AF24FDB614F2} = {EDEC2130-DA14-4415-91A3-225733FB61F8} {4F2F7171-202E-4E23-AABF-EB3501BDB0B2} = {EDEC2130-DA14-4415-91A3-225733FB61F8} {C2BE41E6-95E9-431A-9C49-923BD50692AB} = {EDEC2130-DA14-4415-91A3-225733FB61F8} - {4899758D-1953-4BCF-99FD-B0EC2BF136E6} = {EDEC2130-DA14-4415-91A3-225733FB61F8} - {634CC4D7-B517-45C4-8747-CEAA675D6FCF} = {EDEC2130-DA14-4415-91A3-225733FB61F8} - {2CA7E536-E6BE-4BE7-B29D-20C212EE9832} = {EDEC2130-DA14-4415-91A3-225733FB61F8} {A04F314B-2373-496E-879F-763B5C8EAF00} = {EDEC2130-DA14-4415-91A3-225733FB61F8} {21997B0D-AE07-4F1E-8042-84EB399269D5} = {EDEC2130-DA14-4415-91A3-225733FB61F8} {C1218464-0B5A-480E-BA13-2C6EA370987E} = {EDEC2130-DA14-4415-91A3-225733FB61F8} diff --git a/Directory.Build.targets b/Directory.Build.targets index 3fc78d4f..c964ceaa 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -34,7 +34,7 @@ - + diff --git a/packages/libClangSharp/libClangSharp.runtime.freebsd.11-x64/libClangSharp.runtime.freebsd.11-x64.nuspec b/packages/libClangSharp/libClangSharp.runtime.freebsd.11-x64/libClangSharp.runtime.freebsd.11-x64.nuspec index 10f8cf88..97a3385e 100644 --- a/packages/libClangSharp/libClangSharp.runtime.freebsd.11-x64/libClangSharp.runtime.freebsd.11-x64.nuspec +++ b/packages/libClangSharp/libClangSharp.runtime.freebsd.11-x64/libClangSharp.runtime.freebsd.11-x64.nuspec @@ -2,7 +2,7 @@ libClangSharp.runtime.freebsd.11-x64 - 11.0.0-beta1 + 11.0.0-beta2 Microsoft and Contributors Microsoft and Contributors true diff --git a/packages/libClangSharp/libClangSharp.runtime.freebsd.11-x86/libClangSharp.runtime.freebsd.11-x86.nuspec b/packages/libClangSharp/libClangSharp.runtime.freebsd.11-x86/libClangSharp.runtime.freebsd.11-x86.nuspec index 360cb07a..0be7b237 100644 --- a/packages/libClangSharp/libClangSharp.runtime.freebsd.11-x86/libClangSharp.runtime.freebsd.11-x86.nuspec +++ b/packages/libClangSharp/libClangSharp.runtime.freebsd.11-x86/libClangSharp.runtime.freebsd.11-x86.nuspec @@ -2,7 +2,7 @@ libClangSharp.runtime.freebsd.11-x86 - 11.0.0-beta1 + 11.0.0-beta2 Microsoft and Contributors Microsoft and Contributors true diff --git a/packages/libClangSharp/libClangSharp.runtime.linux-arm/libClangSharp.runtime.linux-arm.nuspec b/packages/libClangSharp/libClangSharp.runtime.linux-arm/libClangSharp.runtime.linux-arm.nuspec index b395bd32..258730ac 100644 --- a/packages/libClangSharp/libClangSharp.runtime.linux-arm/libClangSharp.runtime.linux-arm.nuspec +++ b/packages/libClangSharp/libClangSharp.runtime.linux-arm/libClangSharp.runtime.linux-arm.nuspec @@ -2,7 +2,7 @@ libClangSharp.runtime.linux-arm - 11.0.0-beta1 + 11.0.0-beta2 Microsoft and Contributors Microsoft and Contributors true diff --git a/packages/libClangSharp/libClangSharp.runtime.linux-arm64/libClangSharp.runtime.linux-arm64.nuspec b/packages/libClangSharp/libClangSharp.runtime.linux-arm64/libClangSharp.runtime.linux-arm64.nuspec index 774824ea..a218ae27 100644 --- a/packages/libClangSharp/libClangSharp.runtime.linux-arm64/libClangSharp.runtime.linux-arm64.nuspec +++ b/packages/libClangSharp/libClangSharp.runtime.linux-arm64/libClangSharp.runtime.linux-arm64.nuspec @@ -2,7 +2,7 @@ libClangSharp.runtime.linux-arm64 - 11.0.0-beta1 + 11.0.0-beta2 Microsoft and Contributors Microsoft and Contributors true diff --git a/packages/libClangSharp/libClangSharp.runtime.osx-x64/libClangSharp.runtime.osx-x64.nuspec b/packages/libClangSharp/libClangSharp.runtime.osx-x64/libClangSharp.runtime.osx-x64.nuspec index ec9ac94c..971bc1ef 100644 --- a/packages/libClangSharp/libClangSharp.runtime.osx-x64/libClangSharp.runtime.osx-x64.nuspec +++ b/packages/libClangSharp/libClangSharp.runtime.osx-x64/libClangSharp.runtime.osx-x64.nuspec @@ -2,7 +2,7 @@ libClangSharp.runtime.osx-x64 - 11.0.0-beta1 + 11.0.0-beta2 Microsoft and Contributors Microsoft and Contributors true diff --git a/packages/libClangSharp/libClangSharp.runtime.sles-x64/libClangSharp.runtime.sles-x64.nuspec b/packages/libClangSharp/libClangSharp.runtime.sles-x64/libClangSharp.runtime.sles-x64.nuspec deleted file mode 100644 index d5b83bb1..00000000 --- a/packages/libClangSharp/libClangSharp.runtime.sles-x64/libClangSharp.runtime.sles-x64.nuspec +++ /dev/null @@ -1,20 +0,0 @@ - - - - libClangSharp.runtime.sles-x64 - 11.0.0-beta1 - Microsoft and Contributors - Microsoft and Contributors - true - NCSA - https://github.com/microsoft/clangsharp - sles x64 native library for libClangSharp. - Copyright © Microsoft and Contributors - - - - - - - - diff --git a/packages/libClangSharp/libClangSharp.runtime.ubuntu.16.04-x64/libClangSharp.runtime.ubuntu.16.04-x64.nuspec b/packages/libClangSharp/libClangSharp.runtime.ubuntu.16.04-x64/libClangSharp.runtime.ubuntu.16.04-x64.nuspec deleted file mode 100644 index ce894a98..00000000 --- a/packages/libClangSharp/libClangSharp.runtime.ubuntu.16.04-x64/libClangSharp.runtime.ubuntu.16.04-x64.nuspec +++ /dev/null @@ -1,20 +0,0 @@ - - - - libClangSharp.runtime.ubuntu.16.04-x64 - 11.0.0-beta1 - Microsoft and Contributors - Microsoft and Contributors - true - NCSA - https://github.com/microsoft/clangsharp - ubuntu 16.04 x64 native library for libClangSharp. - Copyright © Microsoft and Contributors - - - - - - - - diff --git a/packages/libClangSharp/libClangSharp.runtime.ubuntu.18.04-x64/libClangSharp.runtime.ubuntu.18.04-x64.nuspec b/packages/libClangSharp/libClangSharp.runtime.ubuntu.18.04-x64/libClangSharp.runtime.ubuntu.18.04-x64.nuspec index fa65384b..c489478c 100644 --- a/packages/libClangSharp/libClangSharp.runtime.ubuntu.18.04-x64/libClangSharp.runtime.ubuntu.18.04-x64.nuspec +++ b/packages/libClangSharp/libClangSharp.runtime.ubuntu.18.04-x64/libClangSharp.runtime.ubuntu.18.04-x64.nuspec @@ -2,7 +2,7 @@ libClangSharp.runtime.ubuntu.18.04-x64 - 11.0.0-beta1 + 11.0.0-beta2 Microsoft and Contributors Microsoft and Contributors true diff --git a/packages/libClangSharp/libClangSharp.runtime.ubuntu.20.04-x64/libClangSharp.runtime.ubuntu.20.04-x64.nuspec b/packages/libClangSharp/libClangSharp.runtime.ubuntu.20.04-x64/libClangSharp.runtime.ubuntu.20.04-x64.nuspec index d2035a78..ba4c93d9 100644 --- a/packages/libClangSharp/libClangSharp.runtime.ubuntu.20.04-x64/libClangSharp.runtime.ubuntu.20.04-x64.nuspec +++ b/packages/libClangSharp/libClangSharp.runtime.ubuntu.20.04-x64/libClangSharp.runtime.ubuntu.20.04-x64.nuspec @@ -2,7 +2,7 @@ libClangSharp.runtime.ubuntu.20.04-x64 - 11.0.0-beta1 + 11.0.0-beta2 Microsoft and Contributors Microsoft and Contributors true diff --git a/packages/libClangSharp/libClangSharp.runtime.win-x64/libClangSharp.runtime.win-x64.nuspec b/packages/libClangSharp/libClangSharp.runtime.win-x64/libClangSharp.runtime.win-x64.nuspec index e78b5e69..7d97feba 100644 --- a/packages/libClangSharp/libClangSharp.runtime.win-x64/libClangSharp.runtime.win-x64.nuspec +++ b/packages/libClangSharp/libClangSharp.runtime.win-x64/libClangSharp.runtime.win-x64.nuspec @@ -2,7 +2,7 @@ libClangSharp.runtime.win-x64 - 11.0.0-beta1 + 11.0.0-beta2 Microsoft and Contributors Microsoft and Contributors true diff --git a/packages/libClangSharp/libClangSharp.runtime.win-x86/libClangSharp.runtime.win-x86.nuspec b/packages/libClangSharp/libClangSharp.runtime.win-x86/libClangSharp.runtime.win-x86.nuspec index a0aeae2d..d3f73a4a 100644 --- a/packages/libClangSharp/libClangSharp.runtime.win-x86/libClangSharp.runtime.win-x86.nuspec +++ b/packages/libClangSharp/libClangSharp.runtime.win-x86/libClangSharp.runtime.win-x86.nuspec @@ -2,7 +2,7 @@ libClangSharp.runtime.win-x86 - 11.0.0-beta1 + 11.0.0-beta2 Microsoft and Contributors Microsoft and Contributors true diff --git a/packages/libClangSharp/libClangSharp/libClangSharp.nuspec b/packages/libClangSharp/libClangSharp/libClangSharp.nuspec index 7a0f8d2b..b5efe85d 100644 --- a/packages/libClangSharp/libClangSharp/libClangSharp.nuspec +++ b/packages/libClangSharp/libClangSharp/libClangSharp.nuspec @@ -2,7 +2,7 @@ libClangSharp - 11.0.0-beta1 + 11.0.0-beta2 Microsoft and Contributors Microsoft and Contributors true diff --git a/packages/libClangSharp/libClangSharp/runtime.json b/packages/libClangSharp/libClangSharp/runtime.json index 59d34d41..dcf52d34 100644 --- a/packages/libClangSharp/libClangSharp/runtime.json +++ b/packages/libClangSharp/libClangSharp/runtime.json @@ -2,57 +2,47 @@ "runtimes": { "freebsd.11-x64": { "libClangSharp": { - "libClangSharp.runtime.freebsd.11-x64": "11.0.0-beta1" + "libClangSharp.runtime.freebsd.11-x64": "11.0.0-beta2" } }, "freebsd.11-x86": { "libClangSharp": { - "libClangSharp.runtime.freebsd.11-x86": "11.0.0-beta1" + "libClangSharp.runtime.freebsd.11-x86": "11.0.0-beta2" } }, "linux-arm": { "libClangSharp": { - "libClangSharp.runtime.linux-arm": "11.0.0-beta1" + "libClangSharp.runtime.linux-arm": "11.0.0-beta2" } }, "linux-arm64": { "libClangSharp": { - "libClangSharp.runtime.linux-arm64": "11.0.0-beta1" + "libClangSharp.runtime.linux-arm64": "11.0.0-beta2" } }, "osx-x64": { "libClangSharp": { - "libClangSharp.runtime.osx-x64": "11.0.0-beta1" - } - }, - "sles-x64": { - "libClangSharp": { - "libClangSharp.runtime.sles-x64": "11.0.0-beta1" - } - }, - "ubuntu.16.04-x64": { - "libClangSharp": { - "libClangSharp.runtime.ubuntu.16.04-x64": "11.0.0-beta1" + "libClangSharp.runtime.osx-x64": "11.0.0-beta2" } }, "ubuntu.18.04-x64": { "libClangSharp": { - "libClangSharp.runtime.ubuntu.18.04-x64": "11.0.0-beta1" + "libClangSharp.runtime.ubuntu.18.04-x64": "11.0.0-beta2" } }, "ubuntu.20.04-x64": { "libClangSharp": { - "libClangSharp.runtime.ubuntu.20.04-x64": "11.0.0-beta1" + "libClangSharp.runtime.ubuntu.20.04-x64": "11.0.0-beta2" } }, "win-x64": { "libClangSharp": { - "libClangSharp.runtime.win-x64": "11.0.0-beta1" + "libClangSharp.runtime.win-x64": "11.0.0-beta2" } }, "win-x86": { "libClangSharp": { - "libClangSharp.runtime.win-x86": "11.0.0-beta1" + "libClangSharp.runtime.win-x86": "11.0.0-beta2" } } } diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs index edb127df..a9f4faff 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs @@ -145,7 +145,13 @@ private void VisitDecl(Decl decl) // case CX_DeclKind.CX_DeclKind_UsingDirective: // case CX_DeclKind.CX_DeclKind_UsingPack: - // case CX_DeclKind.CX_DeclKind_UsingShadow: + + case CX_DeclKind.CX_DeclKind_UsingShadow: + { + VisitUsingShadowDecl((UsingShadowDecl)decl); + break; + } + // case CX_DeclKind.CX_DeclKind_ConstructorUsingShadow: // case CX_DeclKind.CX_DeclKind_Binding: @@ -197,7 +203,12 @@ private void VisitDecl(Decl decl) break; } - // case CX_DeclKind.CX_DeclKind_IndirectField: + case CX_DeclKind.CX_DeclKind_IndirectField: + { + VisitIndirectFieldDecl((IndirectFieldDecl)decl); + break; + } + // case CX_DeclKind.CX_DeclKind_OMPDeclareMapper: // case CX_DeclKind.CX_DeclKind_OMPDeclareReduction: // case CX_DeclKind.CX_DeclKind_UnresolvedUsingValue: @@ -297,6 +308,244 @@ private void VisitEnumConstantDecl(EnumConstantDecl enumConstantDecl) _outputBuilder.EndConstant(isAnonymousEnum); } + private void VisitIndirectFieldDecl(IndirectFieldDecl indirectFieldDecl) + { + if (IsPrevContextDecl(out var prevContext) && prevContext.IsAnonymousStructOrUnion) + { + // We shouldn't process indirect fields where the prev context is an anonymous record decl + return; + } + + var fieldDecl = indirectFieldDecl.AnonField; + var anonymousRecordDecl = fieldDecl.Parent; + + var rootRecordDecl = anonymousRecordDecl; + + var contextNameParts = new Stack(); + var contextTypeParts = new Stack(); + + while (rootRecordDecl.Parent is RecordDecl parentRecordDecl) + { + var contextNamePart = GetRemappedCursorName(rootRecordDecl); + + if (contextNamePart.StartsWith("_")) + { + int suffixLength = 0; + + if (contextNamePart.EndsWith("_e__Union")) + { + suffixLength = 10; + } + else if (contextNamePart.EndsWith("_e__Struct")) + { + suffixLength = 11; + } + + if (suffixLength != 0) + { + contextNamePart = contextNamePart.Substring(1, contextNamePart.Length - suffixLength); + } + } + + contextNameParts.Push(EscapeName(contextNamePart)); + contextTypeParts.Push(GetRemappedTypeName(anonymousRecordDecl, context: null, anonymousRecordDecl.TypeForDecl, out string nativeTypeName)); + + if (!rootRecordDecl.IsAnonymousStructOrUnion) + { + break; + } + + rootRecordDecl = parentRecordDecl; + } + + var contextNameBuilder = new StringBuilder(contextNameParts.Pop()); + var contextTypeBuilder = new StringBuilder(contextTypeParts.Pop()); + + while (contextNameParts.Count != 0) + { + contextNameBuilder.Append('.'); + contextNameBuilder.Append(contextNameParts.Pop()); + + contextTypeBuilder.Append('.'); + contextTypeBuilder.Append(contextTypeParts.Pop()); + } + + var contextName = contextNameBuilder.ToString(); + var contextType = contextTypeBuilder.ToString(); + + var type = fieldDecl.Type; + + var accessSpecifier = GetAccessSpecifier(anonymousRecordDecl); + var typeName = GetRemappedTypeName(fieldDecl, context: null, type, out var fieldNativeTypeName); + var name = GetRemappedCursorName(fieldDecl); + var escapedName = EscapeName(name); + + var desc = new FieldDesc + { + AccessSpecifier = accessSpecifier, + NativeTypeName = null, + EscapedName = escapedName, + Offset = null, + NeedsNewKeyword = false + }; + + _outputBuilder.WriteDivider(true); + _outputBuilder.BeginField(in desc); + + var isFixedSizedBuffer = (type.CanonicalType is ConstantArrayType); + var generateCompatibleCode = _config.GenerateCompatibleCode; + var typeString = string.Empty; + + if (!fieldDecl.IsBitField && (!isFixedSizedBuffer || generateCompatibleCode)) + { + typeString = "ref "; + } + + if (type.CanonicalType is RecordType recordType) + { + var recordDecl = recordType.Decl; + + while ((recordDecl.DeclContext is RecordDecl parentRecordDecl) && (parentRecordDecl != rootRecordDecl)) + { + var parentRecordDeclName = GetRemappedCursorName(parentRecordDecl); + var escapedParentRecordDeclName = EscapeName(parentRecordDeclName); + + typeString += escapedParentRecordDeclName + '.'; + + recordDecl = parentRecordDecl; + } + } + + var isSupportedFixedSizedBufferType = + isFixedSizedBuffer && IsSupportedFixedSizedBufferType(typeName); + + if (isFixedSizedBuffer) + { + if (!generateCompatibleCode) + { + _outputBuilder.EmitSystemSupport(); + typeString += "Span<"; + } + else if (!isSupportedFixedSizedBufferType) + { + typeString += contextType + '.'; + typeName = GetArtificialFixedSizedBufferName(fieldDecl); + } + } + + typeString += typeName; + if (isFixedSizedBuffer && !generateCompatibleCode) + { + typeString += '>'; + } + + _outputBuilder.WriteRegularField(typeString, escapedName); + + generateCompatibleCode |= + ((type.CanonicalType is PointerType) || (type.CanonicalType is ReferenceType)) && + ((typeName != "IntPtr") && (typeName != "UIntPtr")); + + _outputBuilder.BeginBody(); + _outputBuilder.BeginGetter(_config.GenerateAggressiveInlining); + var code = _outputBuilder.BeginCSharpCode(); + + if (fieldDecl.IsBitField) + { + code.WriteIndented("return "); + code.Write(contextName); + code.Write('.'); + code.Write(escapedName); + code.WriteSemicolon(); + code.WriteNewline(); + _outputBuilder.EndCSharpCode(code); + + _outputBuilder.EndGetter(); + + _outputBuilder.BeginSetter(_config.GenerateAggressiveInlining); + + code = _outputBuilder.BeginCSharpCode(); + code.WriteIndented(contextName); + code.Write('.'); + code.Write(escapedName); + code.Write(" = value"); + code.WriteSemicolon(); + code.WriteNewline(); + _outputBuilder.EndCSharpCode(code); + + _outputBuilder.EndSetter(); + } + else if (generateCompatibleCode) + { + code.WriteIndented("fixed ("); + code.Write(contextType); + code.Write("* pField = &"); + code.Write(contextName); + code.WriteLine(')'); + code.WriteBlockStart(); + code.WriteIndented("return ref pField->"); + code.Write(escapedName); + + if (isSupportedFixedSizedBufferType) + { + code.Write("[0]"); + } + + code.WriteSemicolon(); + code.WriteNewline(); + code.WriteBlockEnd(); + _outputBuilder.EndCSharpCode(code); + + _outputBuilder.EndGetter(); + } + else + { + code.WriteIndented("return "); + + if (!isFixedSizedBuffer) + { + code.AddUsingDirective("System.Runtime.InteropServices"); + code.Write("ref MemoryMarshal.GetReference("); + } + + if (!isFixedSizedBuffer || isSupportedFixedSizedBufferType) + { + code.Write("MemoryMarshal.CreateSpan(ref "); + } + + code.Write(contextName); + code.Write('.'); + code.Write(escapedName); + + if (isFixedSizedBuffer) + { + if (isSupportedFixedSizedBufferType) + { + code.Write("[0], "); + code.Write(((ConstantArrayType)type.CanonicalType).Size); + } + else + { + code.Write(".AsSpan("); + } + } + else + { + code.Write(", 1)"); + } + + code.Write(')'); + code.WriteSemicolon(); + code.WriteNewline(); + _outputBuilder.EndCSharpCode(code); + + _outputBuilder.EndGetter(); + } + + _outputBuilder.EndBody(); + _outputBuilder.EndField(false); + _outputBuilder.WriteDivider(); + } + private void VisitEnumDecl(EnumDecl enumDecl) { var accessSpecifier = GetAccessSpecifier(enumDecl); @@ -386,6 +635,12 @@ private void VisitFieldDecl(FieldDecl fieldDecl) private void VisitFunctionDecl(FunctionDecl functionDecl) { + if (!functionDecl.IsUserProvided) + { + // We shouldn't process injected functions + return; + } + if (IsExcluded(functionDecl)) { return; @@ -616,10 +871,8 @@ private void VisitFunctionTemplateDecl(FunctionTemplateDecl functionTemplateDecl private void VisitLinkageSpecDecl(LinkageSpecDecl linkageSpecDecl) { - foreach (var cursor in linkageSpecDecl.CursorChildren) - { - Visit(cursor); - } + Visit(linkageSpecDecl.Decls); + Visit(linkageSpecDecl.CursorChildren, linkageSpecDecl.Decls); } private void VisitNamespaceDecl(NamespaceDecl namespaceDecl) @@ -627,10 +880,8 @@ private void VisitNamespaceDecl(NamespaceDecl namespaceDecl) // We don't currently include the namespace name anywhere in the // generated bindings. We might want to in the future... - foreach (var cursor in namespaceDecl.CursorChildren) - { - Visit(cursor); - } + Visit(namespaceDecl.Decls); + Visit(namespaceDecl.CursorChildren, namespaceDecl.Decls); } private void VisitParmVarDecl(ParmVarDecl parmVarDecl) @@ -759,6 +1010,12 @@ void ForTypedefDecl(ParmVarDecl parmVarDecl, TypedefDecl typedefDecl) private void VisitRecordDecl(RecordDecl recordDecl) { + if (recordDecl.IsInjectedClassName) + { + // We shouldn't process injected records + return; + } + var nativeName = GetCursorName(recordDecl); var name = GetRemappedCursorName(recordDecl); var escapedName = EscapeName(name); @@ -1044,30 +1301,24 @@ private void VisitRecordDecl(RecordDecl recordDecl) var bitfieldPreviousSize = 0L; var bitfieldRemainingBits = 0L; - foreach (var declaration in recordDecl.Decls) + foreach (var fieldDecl in recordDecl.Fields) { - if (declaration is FieldDecl fieldDecl) + if (fieldDecl.IsBitField) { - if (fieldDecl.IsBitField) - { - VisitBitfieldDecl(fieldDecl, bitfieldTypes, recordDecl, contextName: "", ref bitfieldIndex, - ref bitfieldPreviousSize, ref bitfieldRemainingBits); - } - else - { - bitfieldPreviousSize = 0; - bitfieldRemainingBits = 0; - } - - Visit(fieldDecl); - _outputBuilder.WriteDivider(); + VisitBitfieldDecl(fieldDecl, bitfieldTypes, recordDecl, contextName: "", ref bitfieldIndex, ref bitfieldPreviousSize, ref bitfieldRemainingBits); } - else if ((declaration is RecordDecl nestedRecordDecl) && nestedRecordDecl.IsAnonymousStructOrUnion) + else { - VisitAnonymousRecordDecl(recordDecl, nestedRecordDecl); + bitfieldPreviousSize = 0; + bitfieldRemainingBits = 0; } + + Visit(fieldDecl); + _outputBuilder.WriteDivider(); } + Visit(recordDecl.IndirectFields); + if (cxxRecordDecl != null) { foreach (var cxxConstructorDecl in cxxRecordDecl.Ctors) @@ -1089,7 +1340,7 @@ private void VisitRecordDecl(RecordDecl recordDecl) } } - var excludedCursors = recordDecl.Fields.AsEnumerable(); + var excludedCursors = recordDecl.Fields.AsEnumerable().Concat(recordDecl.IndirectFields); if (cxxRecordDecl != null) { @@ -1117,9 +1368,7 @@ private void VisitRecordDecl(RecordDecl recordDecl) _outputBuilder.EmitFnPtrSupport(); } - int index = 0; - OutputVtblHelperMethods(cxxRecordDecl, cxxRecordDecl, ref index, - hitsPerName: new Dictionary()); + OutputVtblHelperMethods(cxxRecordDecl, cxxRecordDecl, hitsPerName: new Dictionary()); if (_config.GenerateExplicitVtbls) { @@ -1294,8 +1543,7 @@ void OutputVtblEntry(CXXRecordDecl cxxRecordDecl, CXXMethodDecl cxxMethodDecl, _outputBuilder.EndField(); } - void OutputVtblHelperMethod(CXXRecordDecl cxxRecordDecl, CXXMethodDecl cxxMethodDecl, ref int vtblIndex, - Dictionary hitsPerName) + void OutputVtblHelperMethod(CXXRecordDecl cxxRecordDecl, CXXMethodDecl cxxMethodDecl, Dictionary hitsPerName) { if (!cxxMethodDecl.IsVirtual) { @@ -1304,11 +1552,6 @@ void OutputVtblHelperMethod(CXXRecordDecl cxxRecordDecl, CXXMethodDecl cxxMethod if (IsExcluded(cxxMethodDecl, out var isExcludedByConflictingDefinition)) { - if (!isExcludedByConflictingDefinition) - { - vtblIndex += 1; - } - return; } @@ -1416,7 +1659,7 @@ void OutputVtblHelperMethod(CXXRecordDecl cxxRecordDecl, CXXMethodDecl cxxMethod body.Write(cxxMethodDeclTypeName); body.Write(")(lpVtbl["); body.BeginMarker("vtbl", new KeyValuePair("explicit", false)); - body.Write(vtblIndex); + body.Write(cxxMethodDecl.VtblIndex); body.EndMarker("vtbl"); body.Write("])"); @@ -1490,19 +1733,17 @@ void OutputVtblHelperMethod(CXXRecordDecl cxxRecordDecl, CXXMethodDecl cxxMethod _outputBuilder.EndInnerFunctionBody(); _outputBuilder.EndBody(); _outputBuilder.EndFunctionOrDelegate(false, false); - vtblIndex += 1; Debug.Assert(_context.Last == currentContext); _context.RemoveLast(); } - void OutputVtblHelperMethods(CXXRecordDecl rootCxxRecordDecl, CXXRecordDecl cxxRecordDecl, ref int index, - Dictionary hitsPerName) + void OutputVtblHelperMethods(CXXRecordDecl rootCxxRecordDecl, CXXRecordDecl cxxRecordDecl, Dictionary hitsPerName) { foreach (var cxxBaseSpecifier in cxxRecordDecl.Bases) { var baseCxxRecordDecl = GetRecordDeclForBaseSpecifier(cxxBaseSpecifier); - OutputVtblHelperMethods(rootCxxRecordDecl, baseCxxRecordDecl, ref index, hitsPerName); + OutputVtblHelperMethods(rootCxxRecordDecl, baseCxxRecordDecl, hitsPerName); } var cxxMethodDecls = cxxRecordDecl.Methods; @@ -1511,7 +1752,7 @@ void OutputVtblHelperMethods(CXXRecordDecl rootCxxRecordDecl, CXXRecordDecl cxxR foreach (var cxxMethodDecl in cxxMethodDecls) { _outputBuilder.WriteDivider(); - OutputVtblHelperMethod(rootCxxRecordDecl, cxxMethodDecl, ref index, hitsPerName); + OutputVtblHelperMethod(rootCxxRecordDecl, cxxMethodDecl, hitsPerName); } } @@ -1534,271 +1775,6 @@ void RestoreNameForMultipleHits(CXXMethodDecl cxxMethodDecl, Dictionary"); - code.Write(escapedName); - - if (isSupportedFixedSizedBufferType) - { - code.Write("[0]"); - } - - code.WriteSemicolon(); - code.WriteNewline(); - code.WriteBlockEnd(); - _outputBuilder.EndCSharpCode(code); - - _outputBuilder.EndGetter(); - } - else - { - code.WriteIndented("return "); - - if (!isFixedSizedBuffer) - { - code.AddUsingDirective("System.Runtime.InteropServices"); - code.Write("ref MemoryMarshal.GetReference("); - } - - if (!isFixedSizedBuffer || isSupportedFixedSizedBufferType) - { - code.Write("MemoryMarshal.CreateSpan(ref "); - } - - code.Write(contextName); - code.Write('.'); - code.Write(escapedName); - - if (isFixedSizedBuffer) - { - if (isSupportedFixedSizedBufferType) - { - code.Write("[0], "); - code.Write(((ConstantArrayType)type.CanonicalType).Size); - } - else - { - code.Write(".AsSpan("); - } - } - else - { - code.Write(", 1)"); - } - - code.Write(')'); - code.WriteSemicolon(); - code.WriteNewline(); - _outputBuilder.EndCSharpCode(code); - - _outputBuilder.EndGetter(); - } - - _outputBuilder.EndBody(); - _outputBuilder.EndField(false); - _outputBuilder.WriteDivider(); - } - else if ((declaration is RecordDecl nestedRecordDecl) && nestedRecordDecl.IsAnonymousStructOrUnion) - { - var nestedRecordDeclName = GetRemappedTypeName(nestedRecordDecl, context: null, - nestedRecordDecl.TypeForDecl, out string nativeTypeName); - var name = GetRemappedCursorName(nestedRecordDecl); - - if (name.StartsWith("_")) - { - int suffixLength = 0; - - if (name.EndsWith("_e__Union")) - { - suffixLength = 10; - } - else if (name.EndsWith("_e__Struct")) - { - suffixLength = 11; - } - - if (suffixLength != 0) - { - name = name.Substring(1, name.Length - suffixLength); - } - } - - var escapedName = EscapeName(name); - - VisitAnonymousRecordDeclFields(rootRecordDecl, nestedRecordDecl, - $"{contextType}.{nestedRecordDeclName}", $"{contextName}.{escapedName}"); - } - } - } - void VisitBitfieldDecl(FieldDecl fieldDecl, Type[] types, RecordDecl recordDecl, string contextName, ref int index, ref long previousSize, ref long remainingBits) { @@ -2426,10 +2402,8 @@ void VisitConstantArrayFieldDecl(RecordDecl recordDecl, FieldDecl constantArray) private void VisitTranslationUnitDecl(TranslationUnitDecl translationUnitDecl) { - foreach (var cursor in translationUnitDecl.CursorChildren) - { - Visit(cursor); - } + Visit(translationUnitDecl.Decls); + Visit(translationUnitDecl.CursorChildren, translationUnitDecl.Decls); } private void VisitTypedefDecl(TypedefDecl typedefDecl) @@ -2596,6 +2570,11 @@ string GetUndecoratedName(Type type) } } + private void VisitUsingShadowDecl(UsingShadowDecl usingShadowDecl) + { + // Nothing to handle for binding generation + } + private void VisitVarDecl(VarDecl varDecl) { if (IsPrevContextStmt(out var declStmt)) @@ -2791,6 +2770,10 @@ private void VisitVarDecl(VarDecl varDecl) _outputBuilder.WriteDivider(); } } + else if (IsPrevContextDecl(out var functionDecl)) + { + // This should be handled in the function body as part of a DeclStmt + } else { IsPrevContextDecl(out var previousContext); diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs index 1d3e193b..994e1d88 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs @@ -843,6 +843,15 @@ private string GetCursorName(NamedDecl namedDecl) { name = GetAnonymousName(fieldDecl, fieldDecl.CursorKindSpelling); } + else if (namedDecl is CXXConstructorDecl cxxConstructorDecl) + { + name = GetCursorName(cxxConstructorDecl.Parent); + } + else if (namedDecl is CXXDestructorDecl cxxDestructorDecl) + { + name = "~"; + name += GetCursorName(cxxDestructorDecl.Parent); + } else { AddDiagnostic(DiagnosticLevel.Error, $"Unsupported anonymous named declaration: '{namedDecl.Kind}'.", namedDecl); @@ -1089,9 +1098,9 @@ private string GetRemappedCursorName(NamedDecl namedDecl) { remappedName = "Anonymous"; - if (fieldDecl.Parent.AnonymousDecls.Count > 1) + if (fieldDecl.Parent.AnonymousFields.Count > 1) { - var index = fieldDecl.Parent.AnonymousDecls.IndexOf(fieldDecl) + 1; + var index = fieldDecl.Parent.AnonymousFields.IndexOf(fieldDecl) + 1; remappedName += index.ToString(); } } @@ -1108,9 +1117,9 @@ private string GetRemappedCursorName(NamedDecl namedDecl) remappedName = "_"; remappedName += GetRemappedCursorName(matchingField); } - else if (parentRecordDecl.AnonymousDecls.Count > 1) + else if (parentRecordDecl.AnonymousRecords.Count > 1) { - var index = parentRecordDecl.AnonymousDecls.IndexOf(recordDecl) + 1; + var index = parentRecordDecl.AnonymousRecords.IndexOf(recordDecl) + 1; remappedName += index.ToString(); } @@ -1179,9 +1188,9 @@ private string GetRemappedTypeName(Cursor cursor, Cursor context, Type type, out name = "_"; name += GetRemappedCursorName(matchingField); } - else if (parentRecordDecl.AnonymousDecls.Count > 1) + else if (parentRecordDecl.AnonymousRecords.Count > 1) { - var index = parentRecordDecl.AnonymousDecls.IndexOf(cursor) + 1; + var index = parentRecordDecl.AnonymousRecords.IndexOf(cursor) + 1; name += index.ToString(); } } diff --git a/sources/ClangSharp/Capture.cs b/sources/ClangSharp/Capture.cs deleted file mode 100644 index a7b9fa6a..00000000 --- a/sources/ClangSharp/Capture.cs +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. - -using System; - -namespace ClangSharp -{ - public sealed class Capture - { - private readonly Decl _parentDecl; - private readonly uint _index; - private readonly Lazy _copyExpr; - private readonly Lazy _variable; - - internal Capture(Decl parentDecl, uint index) - { - _parentDecl = parentDecl; - _index = index; - - _copyExpr = new Lazy(() => _parentDecl.TranslationUnit.GetOrCreate(_parentDecl.Handle.GetCaptureCopyExpr(_index))); - _variable = new Lazy(() => _parentDecl.TranslationUnit.GetOrCreate(_parentDecl.Handle.GetCaptureVariable(_index))); - } - - public Expr CopyExpr => _copyExpr.Value; - - public bool HasCopyExpr => _parentDecl.Handle.GetCaptureHasCopyExpr(_index); - - public bool IsByRef => _parentDecl.Handle.GetCaptureIsByRef(_index); - - public bool IsEscapingByRef => _parentDecl.Handle.GetCaptureIsEscapingByRef(_index); - - public bool IsNested => _parentDecl.Handle.GetCaptureIsNested(_index); - - public bool IsNonEscapingByRef => _parentDecl.Handle.GetCaptureIsNonEscapingByRef(_index); - - public VarDecl Variable => _variable.Value; - } -} diff --git a/sources/ClangSharp/Cursors/Attrs/Attr.cs b/sources/ClangSharp/Cursors/Attrs/Attr.cs index 396dbd50..b44d2148 100644 --- a/sources/ClangSharp/Cursors/Attrs/Attr.cs +++ b/sources/ClangSharp/Cursors/Attrs/Attr.cs @@ -316,6 +316,10 @@ private protected Attr(CXCursor handle) : base(handle, handle.Kind) _ => new Attr(handle), }; + public bool IsImplicit => Handle.IsImplicit; + + public bool IsPackExpansion => Handle.IsPackExpansion; + public CX_AttrKind Kind => Handle.AttrKind; public string KindSpelling => Handle.AttrKindSpelling; diff --git a/sources/ClangSharp/Cursors/Cursor.cs b/sources/ClangSharp/Cursors/Cursor.cs index 6fa09e8a..9763845b 100644 --- a/sources/ClangSharp/Cursors/Cursor.cs +++ b/sources/ClangSharp/Cursors/Cursor.cs @@ -10,7 +10,7 @@ namespace ClangSharp [DebuggerDisplay("{Handle.DebuggerDisplayString,nq}")] public unsafe class Cursor : IEquatable { - private readonly Lazy> _cursorChildren; + private readonly Lazy> _cursorChildren; private readonly Lazy _translationUnit; private protected Cursor(CXCursor handle, CXCursorKind expectedCursorKind) @@ -21,7 +21,7 @@ private protected Cursor(CXCursor handle, CXCursorKind expectedCursorKind) } Handle = handle; - _cursorChildren = new Lazy>(() => { + _cursorChildren = new Lazy>(() => { var cursors = new List(); Handle.VisitChildren((cursor, parent, clientData) => { @@ -32,6 +32,7 @@ private protected Cursor(CXCursor handle, CXCursorKind expectedCursorKind) return cursors; }); + _translationUnit = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TranslationUnit)); } diff --git a/sources/ClangSharp/Cursors/Decls/BindingDecl.cs b/sources/ClangSharp/Cursors/Decls/BindingDecl.cs index 04c7bf6a..5fd149bd 100644 --- a/sources/ClangSharp/Cursors/Decls/BindingDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/BindingDecl.cs @@ -13,9 +13,9 @@ public sealed class BindingDecl : ValueDecl internal BindingDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedDecl, CX_DeclKind.CX_DeclKind_Binding) { - _binding = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Binding)); + _binding = new Lazy(() => TranslationUnit.GetOrCreate(Handle.BindingExpr)); _decomposedDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.DecomposedDecl)); - _holdingVar = new Lazy(() => TranslationUnit.GetOrCreate(Handle.HoldingVar)); + _holdingVar = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(0))); } public Expr Binding => _binding.Value; diff --git a/sources/ClangSharp/Cursors/Decls/BlockDecl.Capture.cs b/sources/ClangSharp/Cursors/Decls/BlockDecl.Capture.cs new file mode 100644 index 00000000..a284c325 --- /dev/null +++ b/sources/ClangSharp/Cursors/Decls/BlockDecl.Capture.cs @@ -0,0 +1,40 @@ +// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. + +using System; + +namespace ClangSharp +{ + public partial class BlockDecl + { + public sealed class Capture + { + private readonly Decl _parentDecl; + private readonly uint _index; + private readonly Lazy _copyExpr; + private readonly Lazy _variable; + + internal Capture(Decl parentDecl, uint index) + { + _parentDecl = parentDecl; + _index = index; + + _copyExpr = new Lazy(() => _parentDecl.TranslationUnit.GetOrCreate(_parentDecl.Handle.GetCaptureCopyExpr(_index))); + _variable = new Lazy(() => _parentDecl.TranslationUnit.GetOrCreate(_parentDecl.Handle.GetCaptureVariable(_index))); + } + + public Expr CopyExpr => _copyExpr.Value; + + public bool HasCopyExpr => _parentDecl.Handle.GetCaptureHasCopyExpr(_index); + + public bool IsByRef => _parentDecl.Handle.GetCaptureIsByRef(_index); + + public bool IsEscapingByRef => _parentDecl.Handle.GetCaptureIsEscapingByRef(_index); + + public bool IsNested => _parentDecl.Handle.GetCaptureIsNested(_index); + + public bool IsNonEscapingByRef => _parentDecl.Handle.GetCaptureIsNonEscapingByRef(_index); + + public VarDecl Variable => _variable.Value; + } + } +} diff --git a/sources/ClangSharp/Cursors/Decls/BlockDecl.cs b/sources/ClangSharp/Cursors/Decls/BlockDecl.cs index 407f9956..d00a8a3e 100644 --- a/sources/ClangSharp/Cursors/Decls/BlockDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/BlockDecl.cs @@ -3,15 +3,13 @@ using ClangSharp.Interop; using System; using System.Collections.Generic; -using System.Linq; namespace ClangSharp { - public sealed class BlockDecl : Decl, IDeclContext + public sealed partial class BlockDecl : Decl, IDeclContext { private readonly Lazy _blockManglingContextDecl; private readonly Lazy> _captures; - private readonly Lazy> _decls; private readonly Lazy> _parameters; internal BlockDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedDecl, CX_DeclKind.CX_DeclKind_Block) @@ -29,7 +27,6 @@ internal BlockDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_Unexpos return captures; }); - _decls = new Lazy>(() => CursorChildren.OfType().ToList()); _parameters = new Lazy>(() => { var parameterCount = Handle.NumArguments; var parameters = new List(parameterCount); @@ -58,19 +55,23 @@ internal BlockDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_Unexpos public CompoundStmt CompoundBody => (CompoundStmt)Body; - public IReadOnlyList Decls => _decls.Value; - public bool DoesNotEscape => Handle.DoesNotEscape; + public bool HasCaptures => NumCaptures != 0; + public bool IsConversionFromLambda => Handle.IsConversionFromLambda; public bool IsVariadic => Handle.IsVariadic; - public IDeclContext LexicalParent => LexicalDeclContext; + public uint NumCaptures => unchecked((uint)Handle.NumCaptures); + + public uint NumParams => unchecked((uint)Handle.NumArguments); public IReadOnlyList Parameters => _parameters.Value; - public IDeclContext Parent => DeclContext; + public bool ParamEmpty => ParamSize == 0; + + public nuint ParamSize => NumParams; public bool CapturesVariable(VarDecl var) => Handle.CapturesVariable(var.Handle); } diff --git a/sources/ClangSharp/Cursors/Decls/CXXConstructorDecl.cs b/sources/ClangSharp/Cursors/Decls/CXXConstructorDecl.cs index 1d6b2fc4..9656577b 100644 --- a/sources/ClangSharp/Cursors/Decls/CXXConstructorDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/CXXConstructorDecl.cs @@ -1,23 +1,76 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; +using System.Collections.Generic; +using System.Linq; using ClangSharp.Interop; namespace ClangSharp { public sealed class CXXConstructorDecl : CXXMethodDecl { + private readonly Lazy _inheritedConstructor; + private readonly Lazy> _initExprs; + internal CXXConstructorDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_Constructor, CX_DeclKind.CX_DeclKind_CXXConstructor) { + _inheritedConstructor = new Lazy(() => TranslationUnit.GetOrCreate(Handle.InheritedConstructor)); + _initExprs = new Lazy>(() => { + var numInitExprs = Handle.NumExprs; + var initExprs = new List(numInitExprs); + + for (var i = 0; i < numInitExprs; i++) + { + var initExpr = TranslationUnit.GetOrCreate(Handle.GetExpr(unchecked((uint)i))); + initExprs.Add(initExpr); + } + + return initExprs; + }); } public new CXXConstructorDecl CanonicalDecl => (CXXConstructorDecl)base.CanonicalDecl; + public CXXConstructorDecl InheritedConstructor => _inheritedConstructor.Value; + + public IReadOnlyList InitExprs => _initExprs.Value; + public bool IsConvertingConstructor => Handle.CXXConstructor_IsConvertingConstructor; public bool IsCopyConstructor => Handle.CXXConstructor_IsCopyConstructor; + public bool IsCopyOrMoveConstructor => Handle.IsCopyOrMoveConstructor; + public bool IsDefaultConstructor => Handle.CXXConstructor_IsDefaultConstructor; + public bool IsDelegatingConstructor => Handle.IsDelegatingConstructor; + + public bool IsExplicit => !Handle.IsImplicit; + + public bool IsInheritingConstructor => Handle.IsInheritingConstructor; + public bool IsMoveConstructor => Handle.CXXConstructor_IsMoveConstructor; + + public uint NumCtorInitializers => unchecked((uint)Handle.NumExprs); + + public CXXConstructorDecl TargetConstructor + { + get + { + if (!IsDelegatingConstructor) + { + return null; + } + + Expr E = InitExprs.FirstOrDefault()?.IgnoreImplicit; + + if (E is CXXConstructExpr Construct) + { + return Construct.Constructor; + } + + return null; + } + } } } diff --git a/sources/ClangSharp/Cursors/Decls/CXXConversionDecl.cs b/sources/ClangSharp/Cursors/Decls/CXXConversionDecl.cs index 31bd37c8..8f0cd594 100644 --- a/sources/ClangSharp/Cursors/Decls/CXXConversionDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/CXXConversionDecl.cs @@ -1,15 +1,23 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; using ClangSharp.Interop; namespace ClangSharp { public sealed class CXXConversionDecl : CXXMethodDecl { + private readonly Lazy _conversionType; + internal CXXConversionDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_ConversionFunction, CX_DeclKind.CX_DeclKind_CXXConversion) { + _conversionType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); } public new CXXConversionDecl CanonicalDecl => (CXXConversionDecl)base.CanonicalDecl; + + public bool IsExplicit => !Handle.IsImplicit; + + public Type ConversionType => _conversionType.Value; } } diff --git a/sources/ClangSharp/Cursors/Decls/CXXDeductionGuideDecl.cs b/sources/ClangSharp/Cursors/Decls/CXXDeductionGuideDecl.cs index 3cf9a5e5..16b47dbb 100644 --- a/sources/ClangSharp/Cursors/Decls/CXXDeductionGuideDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/CXXDeductionGuideDecl.cs @@ -1,13 +1,21 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; using ClangSharp.Interop; namespace ClangSharp { public sealed class CXXDeductionGuideDecl : FunctionDecl { + private readonly Lazy _deducedTemplate; + internal CXXDeductionGuideDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedDecl, CX_DeclKind.CX_DeclKind_CXXDeductionGuide) { + _deducedTemplate = new Lazy(() => TranslationUnit.GetOrCreate(handle.TemplatedDecl)); } + + public bool IsExplicit => !Handle.IsImplicit; + + public TemplateDecl DeducedTemplate => _deducedTemplate.Value; } } diff --git a/sources/ClangSharp/Cursors/Decls/CXXDestructorDecl.cs b/sources/ClangSharp/Cursors/Decls/CXXDestructorDecl.cs index 0f58e376..494831f1 100644 --- a/sources/ClangSharp/Cursors/Decls/CXXDestructorDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/CXXDestructorDecl.cs @@ -1,13 +1,25 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; using ClangSharp.Interop; namespace ClangSharp { public sealed class CXXDestructorDecl : CXXMethodDecl { + private readonly Lazy _operatorDelete; + private readonly Lazy _operatorDeleteThisArg; + internal CXXDestructorDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_Destructor, CX_DeclKind.CX_DeclKind_CXXDestructor) { + _operatorDelete = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(0))); + _operatorDeleteThisArg = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetExpr(0))); } + + public new CXXDestructorDecl CanonicalDecl => (CXXDestructorDecl)base.CanonicalDecl; + + public Expr OperatorDeleteThisArg => _operatorDeleteThisArg.Value; + + public FunctionDecl OperatorDelete => _operatorDelete.Value; } } diff --git a/sources/ClangSharp/Cursors/Decls/CXXMethodDecl.cs b/sources/ClangSharp/Cursors/Decls/CXXMethodDecl.cs index e8e5d672..ab9fc613 100644 --- a/sources/ClangSharp/Cursors/Decls/CXXMethodDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/CXXMethodDecl.cs @@ -1,12 +1,14 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. using System; +using System.Collections.Generic; using ClangSharp.Interop; namespace ClangSharp { public class CXXMethodDecl : FunctionDecl { + private readonly Lazy> _overriddenMethods; private readonly Lazy _thisType; private readonly Lazy _thisObjectType; @@ -21,6 +23,19 @@ private protected CXXMethodDecl(CXCursor handle, CXCursorKind expectedCursorKind throw new ArgumentException(nameof(handle)); } + _overriddenMethods = new Lazy>(() => { + var numOverriddenMethods = Handle.NumMethods; + var overriddenMethods = new List(numOverriddenMethods); + + for (int i = 0; i < numOverriddenMethods; i++) + { + var overriddenMethod = TranslationUnit.GetOrCreate(Handle.GetMethod(unchecked((uint)i))); + overriddenMethods.Add(overriddenMethod); + } + + return overriddenMethods; + }); + _thisType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ThisType)); _thisObjectType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ThisObjectType)); } @@ -35,10 +50,16 @@ private protected CXXMethodDecl(CXCursor handle, CXCursorKind expectedCursorKind public new CXXMethodDecl MostRecentDecl => (CXXMethodDecl)base.MostRecentDecl; + public IReadOnlyList OverriddenMethods => _overriddenMethods.Value; + public new CXXRecordDecl Parent => (CXXRecordDecl)base.Parent; + public uint SizeOverriddenMethods => unchecked((uint)Handle.NumMethods); + public Type ThisType => _thisType.Value; public Type ThisObjectType => _thisObjectType.Value; + + public long VtblIndex => Handle.VtblIdx; } } diff --git a/sources/ClangSharp/Cursors/Decls/CXXRecordDecl.cs b/sources/ClangSharp/Cursors/Decls/CXXRecordDecl.cs index 90896ac1..425c8596 100644 --- a/sources/ClangSharp/Cursors/Decls/CXXRecordDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/CXXRecordDecl.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; -using System.Linq; using ClangSharp.Interop; namespace ClangSharp @@ -20,7 +19,6 @@ public class CXXRecordDecl : RecordDecl private readonly Lazy _lambdaContextDecl; private readonly Lazy _lambdaStaticInvoker; private readonly Lazy> _methods; - private readonly Lazy _mostRecentNonInjectedDecl; private readonly Lazy _templateInstantiationPattern; private readonly Lazy> _vbases; @@ -35,20 +33,81 @@ private protected CXXRecordDecl(CXCursor handle, CXCursorKind expectedCursorKind throw new ArgumentException(nameof(handle)); } - _bases = new Lazy>(() => CursorChildren.OfType().ToList()); - _ctors = new Lazy>(() => Methods.OfType().ToList()); + _bases = new Lazy>(() => { + var numBases = Handle.NumBases; + var bases = new List(numBases); + + for (var i = 0; i < numBases; i++) + { + var @base = TranslationUnit.GetOrCreate(Handle.GetBase(unchecked((uint)i))); + bases.Add(@base); + } + + return bases; + }); + + _ctors = new Lazy>(() => { + var numCtors = Handle.NumCtors; + var ctors = new List(numCtors); + + for (var i = 0; i < numCtors; i++) + { + var ctor = TranslationUnit.GetOrCreate(Handle.GetCtor(unchecked((uint)i))); + ctors.Add(ctor); + } + + return ctors; + }); + _dependentLambdaCallOperator = new Lazy(() => TranslationUnit.GetOrCreate(Handle.DependentLambdaCallOperator)); - _describedClassTemplate = new Lazy(() => TranslationUnit.GetOrCreate(Handle.DescribedClassTemplate)); + _describedClassTemplate = new Lazy(() => TranslationUnit.GetOrCreate(Handle.DescribedCursorTemplate)); _destructor = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Destructor)); - _friends = new Lazy>(() => Decls.OfType().ToList()); + + _friends = new Lazy>(() => { + var numFriends = Handle.NumFriends; + var friends = new List(numFriends); + + for (var i = 0; i < numFriends; i++) + { + var friend = TranslationUnit.GetOrCreate(Handle.GetFriend(unchecked((uint)i))); + friends.Add(friend); + } + + return friends; + }); + _instantiatedFromMemberClass = new Lazy(() => TranslationUnit.GetOrCreate(Handle.InstantiatedFromMember)); _lambdaCallOperator = new Lazy(() => TranslationUnit.GetOrCreate(Handle.LambdaCallOperator)); _lambdaContextDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.LambdaContextDecl)); _lambdaStaticInvoker = new Lazy(() => TranslationUnit.GetOrCreate(Handle.LambdaStaticInvoker)); - _methods = new Lazy>(() => Decls.OfType().ToList()); - _mostRecentNonInjectedDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.MostRecentNonInjectedDecl)); + + _methods = new Lazy>(() => { + var numMethods = Handle.NumMethods; + var methods = new List(numMethods); + + for (var i = 0; i < numMethods; i++) + { + var method = TranslationUnit.GetOrCreate(Handle.GetMethod(unchecked((uint)i))); + methods.Add(method); + } + + return methods; + }); + _templateInstantiationPattern = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TemplateInstantiationPattern)); - _vbases = new Lazy>(() => Bases.Where((@base) => @base.IsVirtual).ToList()); + + _vbases = new Lazy>(() => { + var numVBases = Handle.NumVBases; + var vbases = new List(numVBases); + + for (var i = 0; i < numVBases; i++) + { + var vbase = TranslationUnit.GetOrCreate(Handle.GetVBase(unchecked((uint)i))); + vbases.Add(vbase); + } + + return vbases; + }); } public bool IsAbstract => Handle.CXXRecord_IsAbstract; @@ -69,7 +128,23 @@ private protected CXXRecordDecl(CXCursor handle, CXCursorKind expectedCursorKind public IReadOnlyList Friends => _friends.Value; - public bool HasUserDeclaredDestructor => Decls.OfType().Any(); + public bool HasDefinition => Definition is not null; + + public bool HasFriends => Handle.NumFriends != 0; + + public bool HasUserDeclaredConstructor => Handle.HasUserDeclaredConstructor; + + public bool HasUserDeclaredCopyAssignment => Handle.HasUserDeclaredCopyAssignment; + + public bool HasUserDeclaredCopyConstructor => Handle.HasUserDeclaredCopyConstructor; + + public bool HasUserDeclaredDestructor => Handle.HasUserDeclaredDestructor; + + public bool HasUserDeclaredMoveAssignment => Handle.HasUserDeclaredMoveAssignment; + + public bool HasUserDeclaredMoveConstructor => Handle.HasUserDeclaredMoveConstructor; + + public bool HasUserDeclaredMoveOperation => Handle.HasUserDeclaredMoveOperation; public CXXRecordDecl InstantiatedFromMemberClass => _instantiatedFromMemberClass.Value; @@ -83,7 +158,23 @@ private protected CXXRecordDecl(CXCursor handle, CXCursorKind expectedCursorKind public new CXXRecordDecl MostRecentDecl => (CXXRecordDecl)base.MostRecentDecl; - public CXXRecordDecl MostRecentNonInjectedDecl => _mostRecentNonInjectedDecl.Value; + public CXXRecordDecl MostRecentNonInjectedDecl + { + get + { + CXXRecordDecl Recent = MostRecentDecl; + + while ((Recent != null) && Recent.IsInjectedClassName) + { + Recent = Recent.PreviousDecl; + } + return Recent; + } + } + + public uint NumBases => unchecked((uint)Handle.NumBases); + + public uint NumVBases => unchecked((uint)Handle.NumVBases); public new CXXRecordDecl PreviousDecl => (CXXRecordDecl)base.PreviousDecl; diff --git a/sources/ClangSharp/Cursors/Decls/CapturedDecl.cs b/sources/ClangSharp/Cursors/Decls/CapturedDecl.cs index 0b51bffe..e9e4e1a3 100644 --- a/sources/ClangSharp/Cursors/Decls/CapturedDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/CapturedDecl.cs @@ -3,20 +3,17 @@ using ClangSharp.Interop; using System; using System.Collections.Generic; -using System.Linq; namespace ClangSharp { public sealed class CapturedDecl : Decl, IDeclContext { private readonly Lazy _contextParam; - private readonly Lazy> _decls; private readonly Lazy> _parameters; internal CapturedDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedDecl, CX_DeclKind.CX_DeclKind_Captured) { _contextParam = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ContextParam)); - _decls = new Lazy>(() => CursorChildren.OfType().ToList()); _parameters = new Lazy>(() => { var parameterCount = Handle.NumArguments; var parameters = new List(parameterCount); @@ -33,16 +30,12 @@ internal CapturedDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_Unex public ImplicitParamDecl ContextParam => _contextParam.Value; - public int ContextParamPosition => Handle.ContextParamPosition; - - public IReadOnlyList Decls => _decls.Value; + public uint ContextParamPosition => unchecked((uint)Handle.ContextParamPosition); public bool IsNothrow => Handle.IsNothrow; - public IDeclContext LexicalParent => LexicalDeclContext; + public uint NumParams => unchecked((uint)Handle.NumArguments); public IReadOnlyList Parameters => _parameters.Value; - - public IDeclContext Parent => DeclContext; } } diff --git a/sources/ClangSharp/Cursors/Decls/ClassScopeFunctionSpecializationDecl.cs b/sources/ClangSharp/Cursors/Decls/ClassScopeFunctionSpecializationDecl.cs index 104d6b83..b69c624d 100644 --- a/sources/ClangSharp/Cursors/Decls/ClassScopeFunctionSpecializationDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ClassScopeFunctionSpecializationDecl.cs @@ -20,7 +20,7 @@ internal ClassScopeFunctionSpecializationDecl(CXCursor handle) : base(handle, CX for (int i = 0; i < templateArgCount; i++) { - var templateArg = new TemplateArgumentLoc(this, unchecked((uint)i)); + var templateArg = TranslationUnit.GetOrCreate(Handle.GetTemplateArgumentLoc(unchecked((uint)i))); templateArgs.Add(templateArg); } @@ -30,6 +30,8 @@ internal ClassScopeFunctionSpecializationDecl(CXCursor handle) : base(handle, CX public bool HasExplicitTemplateArgs => Handle.HasExplicitTemplateArgs; + public uint NumTemplateArgs => unchecked((uint)Handle.NumTemplateArguments); + public CXXMethodDecl Specialization => _specialization.Value; public IReadOnlyList TemplateArgs => _templateArgs.Value; diff --git a/sources/ClangSharp/Cursors/Decls/ClassTemplateDecl.cs b/sources/ClangSharp/Cursors/Decls/ClassTemplateDecl.cs index 7f165e4b..d40a0d88 100644 --- a/sources/ClangSharp/Cursors/Decls/ClassTemplateDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ClassTemplateDecl.cs @@ -1,17 +1,38 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; +using System.Collections.Generic; using ClangSharp.Interop; namespace ClangSharp { public sealed class ClassTemplateDecl : RedeclarableTemplateDecl { + private readonly Lazy _injectedClassNameSpecialization; + private readonly Lazy> _specializations; + internal ClassTemplateDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_ClassTemplate, CX_DeclKind.CX_DeclKind_ClassTemplate) { + _injectedClassNameSpecialization = new Lazy(() => TranslationUnit.GetOrCreate(Handle.InjectedSpecializationType)); + + _specializations = new Lazy>(() => { + var numSpecializations = Handle.NumSpecializations; + var specializations = new List(numSpecializations); + + for (var i = 0; i (Handle.GetSpecialization(unchecked((uint)i))); + specializations.Add(specialization); + } + + return specializations; + }); } public new ClassTemplateDecl CanonicalDecl => (ClassTemplateDecl)base.CanonicalDecl; + public Type InjectedClassNameSpecialization => _injectedClassNameSpecialization.Value; + public new ClassTemplateDecl InstantiatedFromMemberTemplate => (ClassTemplateDecl)base.InstantiatedFromMemberTemplate; public bool IsThisDeclarationADefinition => Handle.IsThisDeclarationADefinition; @@ -20,6 +41,8 @@ internal ClassTemplateDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor public new ClassTemplateDecl PreviousDecl => (ClassTemplateDecl)base.PreviousDecl; + public IReadOnlyList Specializations => _specializations.Value; + public new CXXRecordDecl TemplatedDecl => (CXXRecordDecl)base.TemplatedDecl; } } diff --git a/sources/ClangSharp/Cursors/Decls/ClassTemplatePartialSpecializationDecl.cs b/sources/ClangSharp/Cursors/Decls/ClassTemplatePartialSpecializationDecl.cs index 99f2d416..097e0e6e 100644 --- a/sources/ClangSharp/Cursors/Decls/ClassTemplatePartialSpecializationDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ClassTemplatePartialSpecializationDecl.cs @@ -9,7 +9,8 @@ namespace ClangSharp public sealed class ClassTemplatePartialSpecializationDecl : ClassTemplateSpecializationDecl { private readonly Lazy> _associatedConstraints; - private readonly Lazy _instantiatedFromMemberTemplate; + private readonly Lazy _injectedSpecializationType; + private readonly Lazy _instantiatedFromMember; private readonly Lazy> _templateParameters; internal ClassTemplatePartialSpecializationDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_ClassTemplatePartialSpecialization, CX_DeclKind.CX_DeclKind_ClassTemplatePartialSpecialization) @@ -26,14 +27,17 @@ internal ClassTemplatePartialSpecializationDecl(CXCursor handle) : base(handle, return associatedConstraints; }); - _instantiatedFromMemberTemplate = new Lazy(() => TranslationUnit.GetOrCreate(Handle.InstantiatedFromMember)); + + _injectedSpecializationType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.InjectedSpecializationType)); + _instantiatedFromMember = new Lazy(() => TranslationUnit.GetOrCreate(Handle.InstantiatedFromMember)); + _templateParameters = new Lazy>(() => { - var parameterCount = Handle.NumTemplateArguments; + var parameterCount = Handle.GetNumTemplateParameters(0); var parameters = new List(parameterCount); for (int i = 0; i < parameterCount; i++) { - var parameter = TranslationUnit.GetOrCreate(Handle.GetTemplateArgument(unchecked((uint)i))); + var parameter = TranslationUnit.GetOrCreate(Handle.GetTemplateParameter(0, unchecked((uint)i))); parameters.Add(parameter); } @@ -43,9 +47,15 @@ internal ClassTemplatePartialSpecializationDecl(CXCursor handle) : base(handle, public IReadOnlyList AssociatedConstraints => _associatedConstraints.Value; - public ClassTemplatePartialSpecializationDecl InstantiatedFromMember => InstantiatedFromMemberTemplate; + public bool HasAssociatedConstraints => Handle.NumAssociatedConstraints != 0; + + public Type InjectedSpecializationType => _injectedSpecializationType.Value; + + public ClassTemplatePartialSpecializationDecl InstantiatedFromMember => _instantiatedFromMember.Value; + + public ClassTemplatePartialSpecializationDecl InstantiatedFromMemberTemplate => InstantiatedFromMember; - public ClassTemplatePartialSpecializationDecl InstantiatedFromMemberTemplate => _instantiatedFromMemberTemplate.Value; + public bool IsMemberSpecialization => Handle.IsMemberSpecialization; public new ClassTemplatePartialSpecializationDecl MostRecentDecl => (ClassTemplatePartialSpecializationDecl)base.MostRecentDecl; diff --git a/sources/ClangSharp/Cursors/Decls/ClassTemplateSpecializationDecl.cs b/sources/ClangSharp/Cursors/Decls/ClassTemplateSpecializationDecl.cs index 4a595b5c..e3f12345 100644 --- a/sources/ClangSharp/Cursors/Decls/ClassTemplateSpecializationDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ClassTemplateSpecializationDecl.cs @@ -3,6 +3,7 @@ using ClangSharp.Interop; using System; using System.Collections.Generic; +using System.Diagnostics; namespace ClangSharp { @@ -13,6 +14,19 @@ public class ClassTemplateSpecializationDecl : CXXRecordDecl internal ClassTemplateSpecializationDecl(CXCursor handle) : this(handle, handle.Kind, CX_DeclKind.CX_DeclKind_ClassTemplateSpecialization) { + _specializedTemplate = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SpecializedCursorTemplate)); + _templateArgs = new Lazy>(() => { + var templateArgCount = Handle.NumTemplateArguments; + var templateArgs = new List(templateArgCount); + + for (int i = 0; i < templateArgCount; i++) + { + var templateArg = TranslationUnit.GetOrCreate(Handle.GetTemplateArgument(unchecked((uint)i))); + templateArgs.Add(templateArg); + } + + return templateArgs; + }); } private protected ClassTemplateSpecializationDecl(CXCursor handle, CXCursorKind expectedCursorKind, CX_DeclKind expectedDeclKind) : base(handle, expectedCursorKind, expectedDeclKind) @@ -29,7 +43,7 @@ private protected ClassTemplateSpecializationDecl(CXCursor handle, CXCursorKind for (int i = 0; i < templateArgCount; i++) { - var templateArg = new TemplateArgument(this, unchecked((uint)i)); + var templateArg = TranslationUnit.GetOrCreate(Handle.GetTemplateArgument(unchecked((uint)i))); templateArgs.Add(templateArg); } @@ -37,6 +51,35 @@ private protected ClassTemplateSpecializationDecl(CXCursor handle, CXCursorKind }); } + public bool IsClassScopeExplicitSpecialization => IsExplicitSpecialization && (LexicalDeclContext is CXXRecordDecl); + + public bool IsExplicitInstantiationOrSpecialization + { + get + { + switch (SpecializationKind) + { + case CX_TemplateSpecializationKind.CX_TSK_ExplicitSpecialization: + case CX_TemplateSpecializationKind.CX_TSK_ExplicitInstantiationDeclaration: + case CX_TemplateSpecializationKind.CX_TSK_ExplicitInstantiationDefinition: + { + return true; + } + + case CX_TemplateSpecializationKind.CX_TSK_Undeclared: + case CX_TemplateSpecializationKind.CX_TSK_ImplicitInstantiation: + { + return false; + } + } + + Debug.Fail("bad template specialization kind"); + return false; + } + } + + public bool IsExplicitSpecialization => SpecializationKind == CX_TemplateSpecializationKind.CX_TSK_ExplicitSpecialization; + public new ClassTemplateSpecializationDecl MostRecentDecl => (ClassTemplateSpecializationDecl)base.MostRecentDecl; public CX_TemplateSpecializationKind SpecializationKind => Handle.TemplateSpecializationKind; diff --git a/sources/ClangSharp/Cursors/Decls/ConceptDecl.cs b/sources/ClangSharp/Cursors/Decls/ConceptDecl.cs index 30a38ddf..b94bd431 100644 --- a/sources/ClangSharp/Cursors/Decls/ConceptDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ConceptDecl.cs @@ -14,6 +14,8 @@ internal ConceptDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_Unexp _constraintExpr = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ConstraintExpr)); } + public new ConceptDecl CanonicalDecl => (ConceptDecl)base.CanonicalDecl; + public Expr ConstraintExpr => _constraintExpr.Value; public bool IsTypeConcept => Handle.IsTypeConcept; diff --git a/sources/ClangSharp/Cursors/Decls/ConstructorUsingShadowDecl.cs b/sources/ClangSharp/Cursors/Decls/ConstructorUsingShadowDecl.cs index 3d08f193..4e5b99ad 100644 --- a/sources/ClangSharp/Cursors/Decls/ConstructorUsingShadowDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ConstructorUsingShadowDecl.cs @@ -30,6 +30,6 @@ internal ConstructorUsingShadowDecl(CXCursor handle) : base(handle, CXCursorKind public ConstructorUsingShadowDecl NominatedBaseClassShadowDecl => _nominatedBaseClassShadowDecl.Value; - public CXXRecordDecl Parent => (CXXRecordDecl)DeclContext; + public new CXXRecordDecl Parent => (CXXRecordDecl)DeclContext; } } diff --git a/sources/ClangSharp/Cursors/Decls/Decl.cs b/sources/ClangSharp/Cursors/Decls/Decl.cs index 65facf38..d1808328 100644 --- a/sources/ClangSharp/Cursors/Decls/Decl.cs +++ b/sources/ClangSharp/Cursors/Decls/Decl.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; -using System.Linq; using ClangSharp.Interop; namespace ClangSharp @@ -13,6 +12,7 @@ public class Decl : Cursor private readonly Lazy> _attrs; private readonly Lazy _body; private readonly Lazy _canonicalDecl; + private readonly Lazy> _decls; private readonly Lazy _declContext; private readonly Lazy _describedTemplate; private readonly Lazy _lexicalDeclContext; @@ -21,6 +21,7 @@ public class Decl : Cursor private readonly Lazy _nonClosureContext; private readonly Lazy _parentFunctionOrMethod; private readonly Lazy _previousDecl; + private readonly Lazy _redeclContext; private readonly Lazy _translationUnitDecl; private protected Decl(CXCursor handle, CXCursorKind expectedCursorKind, CX_DeclKind expectedDeclKind) : base(handle, expectedCursorKind) @@ -31,9 +32,36 @@ private protected Decl(CXCursor handle, CXCursorKind expectedCursorKind, CX_Decl } _asFunction = new Lazy(() => TranslationUnit.GetOrCreate(Handle.AsFunction)); - _attrs = new Lazy>(() => CursorChildren.OfType().ToList()); + + _attrs = new Lazy>(() => { + var attrCount = Handle.NumAttrs; + var attrs = new List(attrCount); + + for (int i = 0; i < attrCount; i++) + { + var attr = TranslationUnit.GetOrCreate(Handle.GetAttr(unchecked((uint)i))); + attrs.Add(attr); + } + + return attrs; + }); + _body = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Body)); _canonicalDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.CanonicalCursor)); + + _decls = new Lazy>(() => { + var declCount = Handle.NumDecls; + var decls = new List(declCount); + + for (int i = 0; i < declCount; i++) + { + var decl = TranslationUnit.GetOrCreate(Handle.GetDecl(unchecked((uint)i))); + decls.Add(decl); + } + + return decls; + }); + _declContext = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SemanticParent) as IDeclContext); _describedTemplate = new Lazy(() => TranslationUnit.GetOrCreate(Handle.DescribedTemplate)); _lexicalDeclContext = new Lazy(() => TranslationUnit.GetOrCreate(Handle.LexicalParent) as IDeclContext); @@ -42,6 +70,7 @@ private protected Decl(CXCursor handle, CXCursorKind expectedCursorKind, CX_Decl _nonClosureContext = new Lazy(() => TranslationUnit.GetOrCreate(Handle.NonClosureContext)); _parentFunctionOrMethod = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ParentFunctionOrMethod) as IDeclContext); _previousDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.PreviousDecl)); + _redeclContext = new Lazy(() => TranslationUnit.GetOrCreate(Handle.RedeclContext) as IDeclContext); _translationUnitDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TranslationUnit.Cursor)); } @@ -61,6 +90,8 @@ private protected Decl(CXCursor handle, CXCursorKind expectedCursorKind, CX_Decl public string DeclKindName => Handle.DeclKindSpelling; + public IReadOnlyList Decls => _decls.Value; + public TemplateDecl DescribedTemplate => _describedTemplate.Value; public bool HasAttrs => Handle.HasAttrs; @@ -69,16 +100,49 @@ private protected Decl(CXCursor handle, CXCursorKind expectedCursorKind, CX_Decl public bool IsDeprecated => Handle.IsDeprecated; + public bool IsInStdNamespace => (DeclContext?.IsStdNamespace).GetValueOrDefault(); + public bool IsInvalidDecl => Handle.IsInvalidDeclaration; + public bool IsNamespace => Kind == CX_DeclKind.CX_DeclKind_Namespace; + + public bool IsStdNamespace + { + get + { + if (this is not NamespaceDecl ND) + { + return false; + } + + if (ND.IsInline) + { + return ND.Parent.IsStdNamespace; + } + + if (!ND.Parent.RedeclContext.IsTranslationUnit) + { + return false; + } + + return ND.Name == "std"; + } + } + public bool IsTemplated => Handle.IsTemplated; + public bool IsTranslationUnit => Kind == CX_DeclKind.CX_DeclKind_TranslationUnit; + public bool IsUnavailable => Handle.IsUnavailable; + public bool IsUnconditionallyVisible => Handle.IsUnconditionallyVisible; + public CX_DeclKind Kind => Handle.DeclKind; public IDeclContext LexicalDeclContext => _lexicalDeclContext.Value; + public IDeclContext LexicalParent => (this is IDeclContext) ? LexicalDeclContext : null; + public uint MaxAlignment => Handle.MaxAlignment; public Decl MostRecentDecl => _mostRecentDecl.Value; @@ -87,10 +151,14 @@ private protected Decl(CXCursor handle, CXCursorKind expectedCursorKind, CX_Decl public Decl NonClosureContext => _nonClosureContext.Value; - // public IDeclContext ParentFunctionOrMethod => _parentFunctionOrMethod.Value; + public IDeclContext Parent => (this is IDeclContext) ? DeclContext : null; + + public IDeclContext ParentFunctionOrMethod => _parentFunctionOrMethod.Value; public Decl PreviousDecl => _previousDecl.Value; + public IDeclContext RedeclContext => _redeclContext.Value; + public CXSourceRange SourceRange => clangsharp.Cursor_getSourceRange(Handle); public TranslationUnitDecl TranslationUnitDecl => _translationUnitDecl.Value; diff --git a/sources/ClangSharp/Cursors/Decls/DeclaratorDecl.cs b/sources/ClangSharp/Cursors/Decls/DeclaratorDecl.cs index f1c68e21..c108addb 100644 --- a/sources/ClangSharp/Cursors/Decls/DeclaratorDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/DeclaratorDecl.cs @@ -1,12 +1,14 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. using System; +using System.Collections.Generic; using ClangSharp.Interop; namespace ClangSharp { public class DeclaratorDecl : ValueDecl { + private readonly Lazy>> _templateParameterLists; private readonly Lazy _trailingRequiresClause; private protected DeclaratorDecl(CXCursor handle, CXCursorKind expectedCursorKind, CX_DeclKind expectedDeclKind) : base(handle, expectedCursorKind, expectedDeclKind) @@ -16,9 +18,34 @@ private protected DeclaratorDecl(CXCursor handle, CXCursorKind expectedCursorKin throw new ArgumentException(nameof(handle)); } + _templateParameterLists = new Lazy>>(() => { + var numTemplateParameterLists = Handle.NumTemplateParameterLists; + var templateParameterLists = new List>(numTemplateParameterLists); + + for (var listIndex = 0; listIndex < numTemplateParameterLists; listIndex++) + { + var numTemplateParameters = Handle.GetNumTemplateParameters(unchecked((uint)listIndex)); + var templateParameterList = new List(numTemplateParameters); + + for (var parameterIndex = 0; parameterIndex < numTemplateParameters; parameterIndex++) + { + var templateParameter = TranslationUnit.GetOrCreate(Handle.GetTemplateParameter(unchecked((uint)listIndex), unchecked((uint)parameterIndex))); + templateParameterList.Add(templateParameter); + } + + templateParameterLists.Add(templateParameterList); + } + + return templateParameterLists; + }); + _trailingRequiresClause = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TrailingRequiresClause)); } + public uint NumTemplateParameterLists => unchecked((uint)Handle.NumTemplateParameterLists); + + public IReadOnlyList> TemplateParameterLists => _templateParameterLists.Value; + public Expr TrailingRequiresClause => _trailingRequiresClause.Value; } } diff --git a/sources/ClangSharp/Cursors/Decls/DecompositionDecl.cs b/sources/ClangSharp/Cursors/Decls/DecompositionDecl.cs index 9cdee17d..0dae652b 100644 --- a/sources/ClangSharp/Cursors/Decls/DecompositionDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/DecompositionDecl.cs @@ -1,13 +1,31 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; +using System.Collections.Generic; using ClangSharp.Interop; namespace ClangSharp { public sealed class DecompositionDecl : VarDecl { + private readonly Lazy> _bindings; + internal DecompositionDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedDecl, CX_DeclKind.CX_DeclKind_Decomposition) { + _bindings = new Lazy>(() => { + var numBindings = Handle.NumBindings; + var bindings = new List(numBindings); + + for (var i = 0; i < numBindings; i++) + { + var binding = TranslationUnit.GetOrCreate(Handle.GetBindingDecl(unchecked((uint)i))); + bindings.Add(binding); + } + + return bindings; + }); } + + public IReadOnlyList Bindings => _bindings.Value; } } diff --git a/sources/ClangSharp/Cursors/Decls/EnumDecl.cs b/sources/ClangSharp/Cursors/Decls/EnumDecl.cs index f18b458f..6e0f2dfc 100644 --- a/sources/ClangSharp/Cursors/Decls/EnumDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/EnumDecl.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; -using System.Linq; using ClangSharp.Interop; namespace ClangSharp @@ -17,7 +16,19 @@ public sealed class EnumDecl : TagDecl internal EnumDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_EnumDecl, CX_DeclKind.CX_DeclKind_Enum) { - _enumerators = new Lazy>(() => CursorChildren.OfType().ToList()); + _enumerators = new Lazy>(() => { + var numEnumerators = Handle.NumEnumerators; + var enumerators = new List(numEnumerators); + + for (var i = 0; i < numEnumerators; i++) + { + var enumerator = TranslationUnit.GetOrCreate(Handle.GetEnumerator(unchecked((uint)i))); + enumerators.Add(enumerator); + } + + return enumerators; + }); + _instantiatedFromMemberEnum = new Lazy(() => TranslationUnit.GetOrCreate(Handle.InstantiatedFromMember)); _integerType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.EnumDecl_IntegerType)); _promotionType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.EnumDecl_PromotionType)); @@ -34,6 +45,8 @@ internal EnumDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_EnumDecl public Type IntegerType => _integerType.Value; + public bool IsComplete => IsCompleteDefinition || (IntegerType is not null); + public bool IsScoped => Handle.EnumDecl_IsScoped; public new EnumDecl MostRecentDecl => (EnumDecl)base.MostRecentDecl; diff --git a/sources/ClangSharp/Cursors/Decls/ExportDecl.cs b/sources/ClangSharp/Cursors/Decls/ExportDecl.cs index de98ac79..74576dee 100644 --- a/sources/ClangSharp/Cursors/Decls/ExportDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ExportDecl.cs @@ -1,25 +1,13 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. using ClangSharp.Interop; -using System; -using System.Collections.Generic; -using System.Linq; namespace ClangSharp { public sealed class ExportDecl : Decl, IDeclContext { - private readonly Lazy> _decls; - internal ExportDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedDecl, CX_DeclKind.CX_DeclKind_Export) { - _decls = new Lazy>(() => CursorChildren.OfType().ToList()); } - - public IReadOnlyList Decls => _decls.Value; - - public IDeclContext LexicalParent => LexicalDeclContext; - - public IDeclContext Parent => DeclContext; } } diff --git a/sources/ClangSharp/Cursors/Decls/ExternCContextDecl.cs b/sources/ClangSharp/Cursors/Decls/ExternCContextDecl.cs index 2da9b6cc..42f36893 100644 --- a/sources/ClangSharp/Cursors/Decls/ExternCContextDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ExternCContextDecl.cs @@ -1,25 +1,13 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. using ClangSharp.Interop; -using System; -using System.Collections.Generic; -using System.Linq; namespace ClangSharp { public sealed class ExternCContextDecl : Decl, IDeclContext { - private readonly Lazy> _decls; - internal ExternCContextDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedDecl, CX_DeclKind.CX_DeclKind_ExternCContext) { - _decls = new Lazy>(() => CursorChildren.OfType().ToList()); } - - public IReadOnlyList Decls => _decls.Value; - - public IDeclContext LexicalParent => LexicalDeclContext; - - public IDeclContext Parent => DeclContext; } } diff --git a/sources/ClangSharp/Cursors/Decls/FieldDecl.cs b/sources/ClangSharp/Cursors/Decls/FieldDecl.cs index b5477ceb..b4fe1133 100644 --- a/sources/ClangSharp/Cursors/Decls/FieldDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/FieldDecl.cs @@ -45,6 +45,6 @@ private protected FieldDecl(CXCursor handle, CXCursorKind expectedCursorKind, CX public bool IsUnnamedBitfield => Handle.IsUnnamedBitfield; - public RecordDecl Parent => (RecordDecl)DeclContext; + public new RecordDecl Parent => (RecordDecl)DeclContext; } } diff --git a/sources/ClangSharp/Cursors/Decls/FriendDecl.cs b/sources/ClangSharp/Cursors/Decls/FriendDecl.cs index d653fdff..d6178b85 100644 --- a/sources/ClangSharp/Cursors/Decls/FriendDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/FriendDecl.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. using System; +using System.Collections.Generic; using ClangSharp.Interop; namespace ClangSharp @@ -8,14 +9,40 @@ namespace ClangSharp public sealed class FriendDecl : Decl { private readonly Lazy _friendNamedDecl; + private readonly Lazy>> _friendTypeTemplateParameterLists; internal FriendDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_FriendDecl, CX_DeclKind.CX_DeclKind_Friend) { _friendNamedDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.FriendDecl)); + + _friendTypeTemplateParameterLists = new Lazy>>(() => { + var numTemplateParameterLists = Handle.NumTemplateParameterLists; + var templateParameterLists = new List>(numTemplateParameterLists); + + for (var listIndex = 0; listIndex < numTemplateParameterLists; listIndex++) + { + var numTemplateParameters = Handle.GetNumTemplateParameters(unchecked((uint)listIndex)); + var templateParameterList = new List(numTemplateParameters); + + for (var parameterIndex = 0; parameterIndex < numTemplateParameters; parameterIndex++) + { + var templateParameter = TranslationUnit.GetOrCreate(Handle.GetTemplateParameter(unchecked((uint)listIndex), unchecked((uint)parameterIndex))); + templateParameterList.Add(templateParameter); + } + + templateParameterLists.Add(templateParameterList); + } + + return templateParameterLists; + }); } public NamedDecl FriendNamedDecl => _friendNamedDecl.Value; public bool IsUnsupportedFriend => Handle.IsUnsupportedFriend; + + public uint FriendTypeNumTemplateParameterLists => unchecked((uint)Handle.NumTemplateParameterLists); + + public IReadOnlyList> FriendTypeTemplateParameterLists => _friendTypeTemplateParameterLists.Value; } } diff --git a/sources/ClangSharp/Cursors/Decls/FriendTemplateDecl.cs b/sources/ClangSharp/Cursors/Decls/FriendTemplateDecl.cs index d56b7bf9..abdd021c 100644 --- a/sources/ClangSharp/Cursors/Decls/FriendTemplateDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/FriendTemplateDecl.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. using System; +using System.Collections.Generic; using ClangSharp.Interop; namespace ClangSharp @@ -8,12 +9,42 @@ namespace ClangSharp public sealed class FriendTemplateDecl : Decl { private readonly Lazy _friendDecl; + private readonly Lazy _friendType; + private readonly Lazy>> _templateParameterLists; internal FriendTemplateDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedDecl, CX_DeclKind.CX_DeclKind_FriendTemplate) { _friendDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.FriendDecl)); + _friendType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); + + _templateParameterLists = new Lazy>>(() => { + var numTemplateParameterLists = Handle.NumTemplateParameterLists; + var templateParameterLists = new List>(numTemplateParameterLists); + + for (var listIndex = 0; listIndex < numTemplateParameterLists; listIndex++) + { + var numTemplateParameters = Handle.GetNumTemplateParameters(unchecked((uint)listIndex)); + var templateParameterList = new List(numTemplateParameters); + + for (var parameterIndex = 0; parameterIndex < numTemplateParameters; parameterIndex++) + { + var templateParameter = TranslationUnit.GetOrCreate(Handle.GetTemplateParameter(unchecked((uint)listIndex), unchecked((uint)parameterIndex))); + templateParameterList.Add(templateParameter); + } + + templateParameterLists.Add(templateParameterList); + } + + return templateParameterLists; + }); } public NamedDecl FriendDecl => _friendDecl.Value; + + public Type FriendType => _friendType.Value; + + public uint NumTemplateParameterLists => unchecked((uint)Handle.NumTemplateParameterLists); + + public IReadOnlyList> TemplateParameterLists => _templateParameterLists.Value; } } diff --git a/sources/ClangSharp/Cursors/Decls/FunctionDecl.cs b/sources/ClangSharp/Cursors/Decls/FunctionDecl.cs index 2ae16214..11dfca42 100644 --- a/sources/ClangSharp/Cursors/Decls/FunctionDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/FunctionDecl.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; -using System.Linq; using ClangSharp.Interop; namespace ClangSharp @@ -11,13 +10,14 @@ public class FunctionDecl : DeclaratorDecl, IDeclContext, IRedeclarable _callResultType; private readonly Lazy _declaredReturnType; - private readonly Lazy> _decls; private readonly Lazy _definition; + private readonly Lazy _describedFunctionDecl; private readonly Lazy _instantiatedFromMemberFunction; private readonly Lazy> _parameters; private readonly Lazy _primaryTemplate; private readonly Lazy _returnType; private readonly Lazy _templateInstantiationPattern; + private readonly Lazy> _templateSpecializationArgs; internal FunctionDecl(CXCursor handle) : this(handle, CXCursorKind.CXCursor_FunctionDecl, CX_DeclKind.CX_DeclKind_Function) { @@ -32,9 +32,10 @@ private protected FunctionDecl(CXCursor handle, CXCursorKind expectedCursorKind, _callResultType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.CallResultType)); _declaredReturnType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.DeclaredReturnType)); - _decls = new Lazy>(() => CursorChildren.OfType().ToList()); _definition = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Definition)); + _describedFunctionDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.DescribedCursorTemplate)); _instantiatedFromMemberFunction = new Lazy(() => TranslationUnit.GetOrCreate(Handle.InstantiatedFromMember)); + _parameters = new Lazy>(() => { var parameterCount = Handle.NumArguments; var parameters = new List(parameterCount); @@ -47,9 +48,23 @@ private protected FunctionDecl(CXCursor handle, CXCursorKind expectedCursorKind, return parameters; }); + _primaryTemplate = new Lazy(() => TranslationUnit.GetOrCreate(Handle.PrimaryTemplate)); _returnType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ReturnType)); _templateInstantiationPattern = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TemplateInstantiationPattern)); + + _templateSpecializationArgs = new Lazy>(() => { + var templateArgCount = Handle.NumTemplateArguments; + var templateArgs = new List(templateArgCount); + + for (int i = 0; i < templateArgCount; i++) + { + var templateArg = TranslationUnit.GetOrCreate(Handle.GetTemplateArgument(unchecked((uint)i))); + templateArgs.Add(templateArg); + } + + return templateArgs; + }); } public Type CallResultType => _callResultType.Value; @@ -58,22 +73,26 @@ private protected FunctionDecl(CXCursor handle, CXCursorKind expectedCursorKind, public Type DeclaredReturnType => _declaredReturnType.Value; - public IReadOnlyList Decls => _decls.Value; - public FunctionDecl Definition => _definition.Value; + public FunctionTemplateDecl DescribedFunctionDecl => _describedFunctionDecl.Value; + public CXCursor_ExceptionSpecificationKind ExceptionSpecType => (CXCursor_ExceptionSpecificationKind)Handle.ExceptionSpecificationType; public bool HasBody => Handle.HasBody; public bool HasImplicitReturnZero => Handle.HasImplicitReturnZero; - public FunctionDecl InstantiatedFromMemberEnum => _instantiatedFromMemberFunction.Value; + public FunctionDecl InstantiatedFromMemberFunction => _instantiatedFromMemberFunction.Value; public bool IsDefaulted => Handle.CXXMethod_IsDefaulted; public bool IsDefined => Handle.IsDefined; + public bool IsDeleted => Handle.IsDeleted; + + public bool IsExplicitlyDefaulted => Handle.IsExplicitlyDefaulted; + public bool IsExternC => Handle.IsExternC; public bool IsGlobal => Handle.IsGlobal; @@ -90,13 +109,17 @@ private protected FunctionDecl(CXCursor handle, CXCursorKind expectedCursorKind, public bool IsThisDeclarationADefinition => Handle.IsThisDeclarationADefinition; + public bool IsUserProvided => Handle.IsUserProvided; + public bool IsVariadic => Handle.IsVariadic; - public IDeclContext LexicalParent => LexicalDeclContext; + public string NameInfoName => Handle.Name.CString; - public IReadOnlyList Parameters => _parameters.Value; + public uint NumParams => unchecked((uint)Handle.NumArguments); + + public CX_OverloadedOperatorKind OverloadedOperator => Handle.OverloadedOperatorKind; - public IDeclContext Parent => DeclContext; + public IReadOnlyList Parameters => _parameters.Value; public FunctionTemplateDecl PrimaryTemplate => _primaryTemplate.Value; @@ -106,6 +129,8 @@ private protected FunctionDecl(CXCursor handle, CXCursorKind expectedCursorKind, public FunctionDecl TemplateInstantiationPattern => _templateInstantiationPattern.Value; + public IReadOnlyList TemplateSpecializationArgs => _templateSpecializationArgs.Value; + public CX_TemplateSpecializationKind TemplateSpecializationKind => Handle.TemplateSpecializationKind; } } diff --git a/sources/ClangSharp/Cursors/Decls/FunctionTemplateDecl.cs b/sources/ClangSharp/Cursors/Decls/FunctionTemplateDecl.cs index dc80fb39..6dc448e4 100644 --- a/sources/ClangSharp/Cursors/Decls/FunctionTemplateDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/FunctionTemplateDecl.cs @@ -1,17 +1,49 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; +using System.Collections.Generic; using ClangSharp.Interop; namespace ClangSharp { public sealed class FunctionTemplateDecl : RedeclarableTemplateDecl { + private readonly Lazy> _injectedTemplateArgs; + private readonly Lazy> _specializations; + internal FunctionTemplateDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_FunctionTemplate, CX_DeclKind.CX_DeclKind_FunctionTemplate) { + _injectedTemplateArgs = new Lazy>(() => { + var templateArgCount = Handle.NumTemplateArguments; + var templateArgs = new List(templateArgCount); + + for (int i = 0; i < templateArgCount; i++) + { + var templateArg = TranslationUnit.GetOrCreate(Handle.GetTemplateArgument(unchecked((uint)i))); + templateArgs.Add(templateArg); + } + + return templateArgs; + }); + + _specializations = new Lazy>(() => { + var numSpecializations = Handle.NumSpecializations; + var specializations = new List(numSpecializations); + + for (var i = 0; i < numSpecializations; i++) + { + var specialization = TranslationUnit.GetOrCreate(Handle.GetSpecialization(unchecked((uint)i))); + specializations.Add(specialization); + } + + return specializations; + }); } public new FunctionTemplateDecl CanonicalDecl => (FunctionTemplateDecl)base.CanonicalDecl; + public IReadOnlyList InjectedTemplateArgs => _injectedTemplateArgs.Value; + public new FunctionTemplateDecl InstantiatedFromMemberTemplate => (FunctionTemplateDecl)base.InstantiatedFromMemberTemplate; public bool IsThisDeclarationADefinition => Handle.IsThisDeclarationADefinition; @@ -20,6 +52,8 @@ internal FunctionTemplateDecl(CXCursor handle) : base(handle, CXCursorKind.CXCur public new FunctionTemplateDecl PreviousDecl => (FunctionTemplateDecl)base.PreviousDecl; + public IReadOnlyList Specializations => _specializations.Value; + public new FunctionDecl TemplatedDecl => (FunctionDecl)base.TemplatedDecl; } } diff --git a/sources/ClangSharp/Cursors/Decls/IndirectFieldDecl.cs b/sources/ClangSharp/Cursors/Decls/IndirectFieldDecl.cs index 0779f4b6..4a1e0f16 100644 --- a/sources/ClangSharp/Cursors/Decls/IndirectFieldDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/IndirectFieldDecl.cs @@ -1,13 +1,23 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; using ClangSharp.Interop; namespace ClangSharp { public sealed class IndirectFieldDecl : ValueDecl, IMergeable { + private readonly Lazy _anonField; + private readonly Lazy _varDecl; + internal IndirectFieldDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedDecl, CX_DeclKind.CX_DeclKind_IndirectField) { + _anonField = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(0))); + _varDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(1))); } + + public FieldDecl AnonField => _anonField.Value; + + public VarDecl VarDecl => _varDecl.Value; } } diff --git a/sources/ClangSharp/Cursors/Decls/LabelDecl.cs b/sources/ClangSharp/Cursors/Decls/LabelDecl.cs index e9c5bede..43de775b 100644 --- a/sources/ClangSharp/Cursors/Decls/LabelDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/LabelDecl.cs @@ -1,13 +1,19 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; using ClangSharp.Interop; namespace ClangSharp { public sealed class LabelDecl : NamedDecl { + private readonly Lazy _stmt; + internal LabelDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedDecl, CX_DeclKind.CX_DeclKind_Label) { + _stmt = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetExpr(0))); } + + public LabelStmt Stmt => _stmt.Value; } } diff --git a/sources/ClangSharp/Cursors/Decls/LifetimeExtendedTemporaryDecl.cs b/sources/ClangSharp/Cursors/Decls/LifetimeExtendedTemporaryDecl.cs index 1d6f1449..c19ccc08 100644 --- a/sources/ClangSharp/Cursors/Decls/LifetimeExtendedTemporaryDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/LifetimeExtendedTemporaryDecl.cs @@ -1,13 +1,23 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; using ClangSharp.Interop; namespace ClangSharp { public sealed class LifetimeExtendedTemporaryDecl : Decl, IMergeable { + private readonly Lazy _extendingDecl; + private readonly Lazy _temporaryExpr; + internal LifetimeExtendedTemporaryDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedDecl, CX_DeclKind.CX_DeclKind_LifetimeExtendedTemporary) { + _extendingDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(1))); + _temporaryExpr = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetExpr(0))); } + + public ValueDecl ExtendingDecl => _extendingDecl.Value; + + public Expr TemporaryExpr => _temporaryExpr.Value; } } diff --git a/sources/ClangSharp/Cursors/Decls/LinkageSpecDecl.cs b/sources/ClangSharp/Cursors/Decls/LinkageSpecDecl.cs index bd4fd0c5..da37ddb8 100644 --- a/sources/ClangSharp/Cursors/Decls/LinkageSpecDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/LinkageSpecDecl.cs @@ -1,32 +1,20 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. using System; -using System.Collections.Generic; -using System.Linq; using ClangSharp.Interop; namespace ClangSharp { public sealed class LinkageSpecDecl : Decl, IDeclContext { - private readonly Lazy> _decls; - internal LinkageSpecDecl(CXCursor handle) : base(handle, handle.Kind, CX_DeclKind.CX_DeclKind_LinkageSpec) { if ((handle.Kind != CXCursorKind.CXCursor_LinkageSpec) && (handle.Kind != CXCursorKind.CXCursor_UnexposedDecl)) { throw new ArgumentException(nameof(handle)); } - - _decls = new Lazy>(() => CursorChildren.OfType().ToList()); } - public IReadOnlyList Decls => _decls.Value; - public CXLanguageKind Langage => Handle.Language; - - public IDeclContext LexicalParent => LexicalDeclContext; - - public IDeclContext Parent => DeclContext; } } diff --git a/sources/ClangSharp/Cursors/Decls/NamespaceAliasDecl.cs b/sources/ClangSharp/Cursors/Decls/NamespaceAliasDecl.cs index 564d26ac..83691b1d 100644 --- a/sources/ClangSharp/Cursors/Decls/NamespaceAliasDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/NamespaceAliasDecl.cs @@ -1,13 +1,25 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; using ClangSharp.Interop; namespace ClangSharp { public sealed class NamespaceAliasDecl : NamedDecl, IRedeclarable { + private readonly Lazy _aliasedNamespace; + private readonly Lazy _namespace; + internal NamespaceAliasDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_NamespaceAlias, CX_DeclKind.CX_DeclKind_NamespaceAlias) { + _aliasedNamespace = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(0))); + _namespace = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(1))); } + + public NamedDecl AliasedNamespace => _aliasedNamespace.Value; + + public new NamespaceAliasDecl CanonicalDecl => (NamespaceAliasDecl)base.CanonicalDecl; + + public NamespaceDecl Namespace => _namespace.Value; } } diff --git a/sources/ClangSharp/Cursors/Decls/NamespaceDecl.cs b/sources/ClangSharp/Cursors/Decls/NamespaceDecl.cs index 2fa8b643..4ab22db7 100644 --- a/sources/ClangSharp/Cursors/Decls/NamespaceDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/NamespaceDecl.cs @@ -1,31 +1,29 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. using System; -using System.Collections.Generic; -using System.Linq; using ClangSharp.Interop; namespace ClangSharp { public sealed class NamespaceDecl : NamedDecl, IDeclContext, IRedeclarable { - private readonly Lazy> _decls; + private readonly Lazy _anonymousNamespace; + private readonly Lazy _originalNamespace; internal NamespaceDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_Namespace, CX_DeclKind.CX_DeclKind_Namespace) { - _decls = new Lazy>(() => CursorChildren.OfType().ToList()); + _anonymousNamespace = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(0))); + _originalNamespace = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(1))); } + public NamespaceDecl AnonymousNamespace => _anonymousNamespace.Value; + public new NamespaceDecl CanonicalDecl => (NamespaceDecl)base.CanonicalDecl; public bool IsAnonymousNamespace => Handle.IsAnonymous; public bool IsInline => Handle.IsInlineNamespace; - public IReadOnlyList Decls => _decls.Value; - - public IDeclContext LexicalParent => LexicalDeclContext; - - public IDeclContext Parent => DeclContext; + public NamespaceDecl OriginalNamespace => _originalNamespace.Value; } } diff --git a/sources/ClangSharp/Cursors/Decls/NonTypeTemplateParmDecl.cs b/sources/ClangSharp/Cursors/Decls/NonTypeTemplateParmDecl.cs index 69e0578c..76e07a6b 100644 --- a/sources/ClangSharp/Cursors/Decls/NonTypeTemplateParmDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/NonTypeTemplateParmDecl.cs @@ -10,6 +10,7 @@ public sealed class NonTypeTemplateParmDecl : DeclaratorDecl, ITemplateParmPosit { private readonly Lazy> _associatedConstraints; private readonly Lazy _defaultArgument; + private readonly Lazy> _expansionTypes; private readonly Lazy _placeholderTypeConstraint; internal NonTypeTemplateParmDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_NonTypeTemplateParameter, CX_DeclKind.CX_DeclKind_NonTypeTemplateParm) @@ -26,7 +27,22 @@ internal NonTypeTemplateParmDecl(CXCursor handle) : base(handle, CXCursorKind.CX return associatedConstraints; }); + _defaultArgument = new Lazy(() => TranslationUnit.GetOrCreate(Handle.DefaultArg)); + + _expansionTypes = new Lazy>(() => { + var numExpansionTypes = Handle.NumExpansionTypes; + var expansionTypes = new List(numExpansionTypes); + + for (int i = 0; i < numExpansionTypes; i++) + { + var expansionType = TranslationUnit.GetOrCreate(Handle.GetExpansionType(unchecked((uint)i))); + expansionTypes.Add(expansionType); + } + + return expansionTypes; + }); + _placeholderTypeConstraint = new Lazy(() => TranslationUnit.GetOrCreate(Handle.PlaceholderTypeConstraint)); } @@ -36,14 +52,22 @@ internal NonTypeTemplateParmDecl(CXCursor handle) : base(handle, CXCursorKind.CX public bool DefaultArgumentWasInherited => Handle.HasInheritedDefaultArg; + public uint Depth => unchecked((uint)Handle.TemplateTypeParmDepth); + + public IReadOnlyList ExpansionTypes => _expansionTypes.Value; + public bool HasDefaultArgument => Handle.HasDefaultArg; public bool HasPlaceholderTypeConstraint => Handle.HasPlaceholderTypeConstraint; + public uint Index => unchecked((uint)Handle.TemplateTypeParmIndex); + public bool IsPackExpansion => Handle.IsPackExpansion; public bool IsParameterPack => Handle.IsParameterPack; public Expr PlaceholderTypeConstraint => _placeholderTypeConstraint.Value; + + public uint Position => unchecked((uint)Handle.TemplateTypeParmPosition); } } diff --git a/sources/ClangSharp/Cursors/Decls/OMPDeclareMapperDecl.cs b/sources/ClangSharp/Cursors/Decls/OMPDeclareMapperDecl.cs index 117179f5..13d0d9ea 100644 --- a/sources/ClangSharp/Cursors/Decls/OMPDeclareMapperDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/OMPDeclareMapperDecl.cs @@ -1,25 +1,13 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. using ClangSharp.Interop; -using System; -using System.Collections.Generic; -using System.Linq; namespace ClangSharp { public sealed class OMPDeclareMapperDecl : ValueDecl, IDeclContext { - private readonly Lazy> _decls; - internal OMPDeclareMapperDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedDecl, CX_DeclKind.CX_DeclKind_OMPDeclareMapper) { - _decls = new Lazy>(() => CursorChildren.OfType().ToList()); } - - public IReadOnlyList Decls => _decls.Value; - - public IDeclContext LexicalParent => LexicalDeclContext; - - public IDeclContext Parent => DeclContext; } } diff --git a/sources/ClangSharp/Cursors/Decls/OMPDeclareReductionDecl.cs b/sources/ClangSharp/Cursors/Decls/OMPDeclareReductionDecl.cs index 9e206fb9..94b2d91e 100644 --- a/sources/ClangSharp/Cursors/Decls/OMPDeclareReductionDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/OMPDeclareReductionDecl.cs @@ -1,25 +1,13 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. using ClangSharp.Interop; -using System; -using System.Collections.Generic; -using System.Linq; namespace ClangSharp { public sealed class OMPDeclareReductionDecl : ValueDecl, IDeclContext { - private readonly Lazy> _decls; - internal OMPDeclareReductionDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedDecl, CX_DeclKind.CX_DeclKind_OMPDeclareReduction) { - _decls = new Lazy>(() => CursorChildren.OfType().ToList()); } - - public IReadOnlyList Decls => _decls.Value; - - public IDeclContext LexicalParent => LexicalDeclContext; - - public IDeclContext Parent => DeclContext; } } diff --git a/sources/ClangSharp/Cursors/Decls/ObjCCategoryDecl.cs b/sources/ClangSharp/Cursors/Decls/ObjCCategoryDecl.cs index a08c8338..8388eb80 100644 --- a/sources/ClangSharp/Cursors/Decls/ObjCCategoryDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ObjCCategoryDecl.cs @@ -1,13 +1,73 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; +using System.Collections.Generic; +using System.Linq; using ClangSharp.Interop; namespace ClangSharp { public sealed class ObjCCategoryDecl : ObjCContainerDecl { + private readonly Lazy _classInterface; + private readonly Lazy _implementation; + private readonly Lazy> _ivars; + private readonly Lazy _nextClassCategory; + private readonly Lazy _nextClassCategoryRaw; + private readonly Lazy> _protocols; + private readonly Lazy> _typeParamList; + internal ObjCCategoryDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_ObjCCategoryDecl, CX_DeclKind.CX_DeclKind_ObjCCategory) { + _classInterface = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(0))); + _implementation = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(1))); + _ivars = new Lazy>(() => Decls.OfType().ToList()); + _nextClassCategory = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(2))); + _nextClassCategoryRaw = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(3))); + + _protocols = new Lazy>(() => { + var numProtocols = Handle.NumProtocols; + var protocols = new List(numProtocols); + + for (int i = 0; i < numProtocols; i++) + { + var protocol = TranslationUnit.GetOrCreate(Handle.GetProtocol(unchecked((uint)i))); + protocols.Add(protocol); + } + + return protocols; + }); + + _typeParamList = new Lazy>(() => { + var numTypeParams = Handle.NumArguments; + var typeParams = new List(numTypeParams); + + for (int i = 0; i < numTypeParams; i++) + { + var typeParam = TranslationUnit.GetOrCreate(Handle.GetArgument(unchecked((uint)i))); + typeParams.Add(typeParam); + } + + return typeParams; + }); } + + public ObjCInterfaceDecl ClassInterface => _classInterface.Value; + + public ObjCCategoryImplDecl Implementation => _implementation.Value; + + public bool IsClassExtension => Handle.IsClassExtension; + + public IReadOnlyList Ivars => _ivars.Value; + + public ObjCCategoryDecl NextClassCategory => _nextClassCategory.Value; + + public ObjCCategoryDecl NextClassCategoryRaw => _nextClassCategoryRaw.Value; + + public IReadOnlyList Protocols => _protocols.Value; + + public IReadOnlyList ReferencedProtocols => Protocols; + + public IReadOnlyList TypeParamList => _typeParamList.Value; } } diff --git a/sources/ClangSharp/Cursors/Decls/ObjCCategoryImplDecl.cs b/sources/ClangSharp/Cursors/Decls/ObjCCategoryImplDecl.cs index 943b6a71..ab047f8f 100644 --- a/sources/ClangSharp/Cursors/Decls/ObjCCategoryImplDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ObjCCategoryImplDecl.cs @@ -1,13 +1,19 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; using ClangSharp.Interop; namespace ClangSharp { public sealed class ObjCCategoryImplDecl : ObjCImplDecl { + private readonly Lazy _categoryDecl; + internal ObjCCategoryImplDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_ObjCCategoryImplDecl, CX_DeclKind.CX_DeclKind_ObjCCategoryImpl) { + _categoryDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(1))); } + + public ObjCCategoryDecl CategoryDecl => _categoryDecl.Value; } } diff --git a/sources/ClangSharp/Cursors/Decls/ObjCCompatibleAliasDecl.cs b/sources/ClangSharp/Cursors/Decls/ObjCCompatibleAliasDecl.cs index 0ffc18eb..84643063 100644 --- a/sources/ClangSharp/Cursors/Decls/ObjCCompatibleAliasDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ObjCCompatibleAliasDecl.cs @@ -1,13 +1,20 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; using ClangSharp.Interop; namespace ClangSharp { public sealed class ObjCCompatibleAliasDecl : NamedDecl { + private readonly Lazy _classInterface; + internal ObjCCompatibleAliasDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedDecl, CX_DeclKind.CX_DeclKind_ObjCCompatibleAlias) { + + _classInterface = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(0))); } + + public ObjCInterfaceDecl ClassInterface => _classInterface.Value; } } diff --git a/sources/ClangSharp/Cursors/Decls/ObjCContainerDecl.cs b/sources/ClangSharp/Cursors/Decls/ObjCContainerDecl.cs index 9bd63f7e..ae0f6705 100644 --- a/sources/ClangSharp/Cursors/Decls/ObjCContainerDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ObjCContainerDecl.cs @@ -9,7 +9,12 @@ namespace ClangSharp { public class ObjCContainerDecl : NamedDecl, IDeclContext { - private readonly Lazy> _decls; + private readonly Lazy> _classMethods; + private readonly Lazy> _classProperties; + private readonly Lazy> _instanceMethods; + private readonly Lazy> _instanceProperties; + private readonly Lazy> _methods; + private readonly Lazy> _properties; private protected ObjCContainerDecl(CXCursor handle, CXCursorKind expectedCursorKind, CX_DeclKind expectedDeclKind) : base(handle, expectedCursorKind, expectedDeclKind) { @@ -18,13 +23,24 @@ private protected ObjCContainerDecl(CXCursor handle, CXCursorKind expectedCursor throw new ArgumentException(nameof(handle)); } - _decls = new Lazy>(() => CursorChildren.OfType().ToList()); + _classMethods = new Lazy>(() => Methods.Where((method) => method.IsClassMethod).ToList()); + _classProperties = new Lazy>(() => Properties.Where((property) => property.IsClassProperty).ToList()); + _instanceMethods = new Lazy>(() => Methods.Where((method) => method.IsInstanceMethod).ToList()); + _instanceProperties = new Lazy>(() => Properties.Where((property) => property.IsInstanceProperty).ToList()); + _methods = new Lazy>(() => Decls.OfType().ToList()); + _properties = new Lazy>(() => Decls.OfType().ToList()); } - public IReadOnlyList Decls => _decls.Value; + public IReadOnlyList ClassMethods => _classMethods.Value; - public IDeclContext LexicalParent => LexicalDeclContext; + public IReadOnlyList ClassProperties => _classProperties.Value; - public IDeclContext Parent => DeclContext; + public IReadOnlyList InstanceMethods => _instanceMethods.Value; + + public IReadOnlyList InstanceProperties => _instanceProperties.Value; + + public IReadOnlyList Methods => _methods.Value; + + public IReadOnlyList Properties => _properties.Value; } } diff --git a/sources/ClangSharp/Cursors/Decls/ObjCImplDecl.cs b/sources/ClangSharp/Cursors/Decls/ObjCImplDecl.cs index f3bc9eb4..090a927f 100644 --- a/sources/ClangSharp/Cursors/Decls/ObjCImplDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ObjCImplDecl.cs @@ -1,18 +1,30 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. using System; +using System.Collections.Generic; +using System.Linq; using ClangSharp.Interop; namespace ClangSharp { public class ObjCImplDecl : ObjCContainerDecl { + private readonly Lazy _classInterface; + private readonly Lazy> _propertyImpls; + private protected ObjCImplDecl(CXCursor handle, CXCursorKind expectedCursorKind, CX_DeclKind expectedDeclKind) : base(handle, expectedCursorKind, expectedDeclKind) { if ((CX_DeclKind.CX_DeclKind_LastObjCImpl < handle.DeclKind) || (handle.DeclKind < CX_DeclKind.CX_DeclKind_FirstObjCImpl)) { throw new ArgumentException(nameof(handle)); } + + _classInterface = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(0))); + _propertyImpls = new Lazy>(() => Decls.OfType().ToList()); } + + public ObjCInterfaceDecl ClassInterface => _classInterface.Value; + + public IReadOnlyList PropertyImpls => _propertyImpls.Value; } } diff --git a/sources/ClangSharp/Cursors/Decls/ObjCImplementationDecl.cs b/sources/ClangSharp/Cursors/Decls/ObjCImplementationDecl.cs index 9a94a099..32b8dc3e 100644 --- a/sources/ClangSharp/Cursors/Decls/ObjCImplementationDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ObjCImplementationDecl.cs @@ -1,13 +1,43 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System.Collections.Generic; +using System; using ClangSharp.Interop; +using System.Linq; namespace ClangSharp { public sealed class ObjCImplementationDecl : ObjCImplDecl { + private readonly Lazy> _initExprs; + private readonly Lazy> _ivars; + private readonly Lazy _superClass; + internal ObjCImplementationDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_ObjCImplementationDecl, CX_DeclKind.CX_DeclKind_ObjCImplementation) { + _initExprs = new Lazy>(() => { + var numInitExprs = Handle.NumExprs; + var initExprs = new List(numInitExprs); + + for (var i = 0; i < numInitExprs; i++) + { + var initExpr = TranslationUnit.GetOrCreate(Handle.GetExpr(unchecked((uint)i))); + initExprs.Add(initExpr); + } + + return initExprs; + }); + + _ivars = new Lazy>(() => Decls.OfType().ToList()); + _superClass = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(1))); } + + public IReadOnlyList InitExprs => _initExprs.Value; + + public IReadOnlyList Ivars => _ivars.Value; + + public uint NumIvarInitializers => unchecked((uint)_ivars.Value.Count); + + public ObjCInterfaceDecl SuperClass => _superClass.Value; } } diff --git a/sources/ClangSharp/Cursors/Decls/ObjCInterfaceDecl.cs b/sources/ClangSharp/Cursors/Decls/ObjCInterfaceDecl.cs index a8c54732..fe1bf832 100644 --- a/sources/ClangSharp/Cursors/Decls/ObjCInterfaceDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ObjCInterfaceDecl.cs @@ -1,13 +1,112 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System.Collections.Generic; +using System; using ClangSharp.Interop; +using System.Linq; namespace ClangSharp { public sealed class ObjCInterfaceDecl : ObjCContainerDecl, IRedeclarable { + private readonly Lazy> _categoryList; + private readonly Lazy _definition; + private readonly Lazy _implementation; + private readonly Lazy> _ivars; + private readonly Lazy> _knownExtensions; + private readonly Lazy> _protocols; + private readonly Lazy _superClass; + private readonly Lazy _superClassType; + private readonly Lazy _typeForDecl; + private readonly Lazy> _typeParamList; + private readonly Lazy> _visibleCategories; + private readonly Lazy> _visibleExtensions; + internal ObjCInterfaceDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_ObjCInterfaceDecl, CX_DeclKind.CX_DeclKind_ObjCInterface) { + _categoryList = new Lazy>(() => { + var categories = new List(); + + ObjCCategoryDecl category = TranslationUnit.GetOrCreate(handle.GetSubDecl(0)); + + while (category != null) + { + categories.Add(category); + category = category.NextClassCategoryRaw; + } + + return categories; + }); + + _definition = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Definition)); + _implementation = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(1))); + _ivars = new Lazy>(() => Decls.OfType().ToList()); + _knownExtensions = new Lazy>(() => CategoryList.Where((category) => category.IsClassExtension).ToList()); + + _protocols = new Lazy>(() => { + var numProtocols = Handle.NumProtocols; + var protocols = new List(numProtocols); + + for (int i = 0; i < numProtocols; i++) + { + var protocol = TranslationUnit.GetOrCreate(Handle.GetProtocol(unchecked((uint)i))); + protocols.Add(protocol); + } + + return protocols; + }); + + _superClass = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(2))); + _superClassType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); + _typeForDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ThisType)); + + _typeParamList = new Lazy>(() => { + var numTypeParams = Handle.NumArguments; + var typeParams = new List(numTypeParams); + + for (int i = 0; i < numTypeParams; i++) + { + var typeParam = TranslationUnit.GetOrCreate(Handle.GetArgument(unchecked((uint)i))); + typeParams.Add(typeParam); + } + + return typeParams; + }); + + _visibleCategories = new Lazy>(() => CategoryList.Where((category) => category.IsUnconditionallyVisible).ToList()); + _visibleExtensions = new Lazy>(() => CategoryList.Where((category) => category.IsClassExtension && category.IsUnconditionallyVisible).ToList()); } + + public new ObjCInterfaceDecl CanonicalDecl => (ObjCInterfaceDecl)base.CanonicalDecl; + + public IReadOnlyList CategoryList => _categoryList.Value; + + public ObjCInterfaceDecl Definition => _definition.Value; + + public bool IsThisDeclarationADefinition => Handle.IsThisDeclarationADefinition; + + public ObjCImplementationDecl Implementation => _implementation.Value; + + public IReadOnlyList Ivars => _ivars.Value; + + public IReadOnlyList KnownCategories => CategoryList; + + public IReadOnlyList KnownExtensions => _knownExtensions.Value; + + public ObjCInterfaceDecl SuperClass => _superClass.Value; + + public ObjCObjectType SuperClassType => _superClassType.Value; + + public IReadOnlyList Protocols => _protocols.Value; + + public IReadOnlyList ReferencedProtocols => Protocols; + + public IReadOnlyList TypeParamList => _typeParamList.Value; + + public Type TypeForDecl => _typeForDecl.Value; + + public IReadOnlyList VisibleCategories => _visibleCategories.Value; + + public IReadOnlyList VisibleExtensions => _visibleExtensions.Value; } } diff --git a/sources/ClangSharp/Cursors/Decls/ObjCIvarDecl.cs b/sources/ClangSharp/Cursors/Decls/ObjCIvarDecl.cs index 4573bb0c..7c0088d1 100644 --- a/sources/ClangSharp/Cursors/Decls/ObjCIvarDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ObjCIvarDecl.cs @@ -1,13 +1,23 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; using ClangSharp.Interop; namespace ClangSharp { public sealed class ObjCIvarDecl : FieldDecl { + private readonly Lazy _containingInterface; + private readonly Lazy _nextIvar; + internal ObjCIvarDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_ObjCIvarDecl, CX_DeclKind.CX_DeclKind_ObjCIvar) { + _containingInterface = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(0))); + _nextIvar = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(1))); } + + public ObjCInterfaceDecl ContainingInterface => _containingInterface.Value; + + public ObjCIvarDecl NextIvar => _nextIvar.Value; } } diff --git a/sources/ClangSharp/Cursors/Decls/ObjCMethodDecl.cs b/sources/ClangSharp/Cursors/Decls/ObjCMethodDecl.cs index b6f44d5b..7e3e0c8f 100644 --- a/sources/ClangSharp/Cursors/Decls/ObjCMethodDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ObjCMethodDecl.cs @@ -2,14 +2,18 @@ using System; using System.Collections.Generic; -using System.Linq; using ClangSharp.Interop; namespace ClangSharp { public sealed class ObjCMethodDecl : NamedDecl, IDeclContext { - private readonly Lazy> _decls; + private readonly Lazy _classInterface; + private readonly Lazy _cmdDecl; + private readonly Lazy> _parameters; + private readonly Lazy _returnType; + private readonly Lazy _selfDecl; + private readonly Lazy _sendResultType; internal ObjCMethodDecl(CXCursor handle) : base(handle, handle.Kind, CX_DeclKind.CX_DeclKind_ObjCMethod) { @@ -18,17 +22,47 @@ internal ObjCMethodDecl(CXCursor handle) : base(handle, handle.Kind, CX_DeclKind throw new ArgumentException(nameof(handle)); } - _decls = new Lazy>(() => CursorChildren.OfType().ToList()); + _classInterface = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(0))); + _cmdDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(1))); + + _parameters = new Lazy>(() => { + var parameterCount = Handle.NumArguments; + var parameters = new List(parameterCount); + + for (int i = 0; i < parameterCount; i++) + { + var parameter = TranslationUnit.GetOrCreate(Handle.GetArgument(unchecked((uint)i))); + parameters.Add(parameter); + } + + return parameters; + }); + + _selfDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(2))); + _returnType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ReturnType)); + _sendResultType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); } - public IReadOnlyList Decls => _decls.Value; + public new ObjCMethodDecl CanonicalDecl => (ObjCMethodDecl)base.CanonicalDecl; + + public ObjCInterfaceDecl ClassInterface => _classInterface.Value; + + public ImplicitParamDecl CmdDecl => _cmdDecl.Value; + + public bool IsClassMethod => CursorKind == CXCursorKind.CXCursor_ObjCClassMethodDecl; + + public bool IsInstanceMethod => CursorKind == CXCursorKind.CXCursor_ObjCInstanceMethodDecl; + + public bool IsThisDeclarationADefinition => Handle.IsThisDeclarationADefinition; + + public CXObjCDeclQualifierKind ObjCDeclQualifier => Handle.ObjCDeclQualifiers; - public bool IsClassMethod() => CursorKind == CXCursorKind.CXCursor_ObjCClassMethodDecl; + public IReadOnlyList Parameters => _parameters.Value; - public bool IsInstanceMethod() => CursorKind == CXCursorKind.CXCursor_ObjCInstanceMethodDecl; + public Type ReturnType => _returnType.Value; - public IDeclContext LexicalParent => LexicalDeclContext; + public ImplicitParamDecl SelfDecl => _selfDecl.Value; - public IDeclContext Parent => DeclContext; + public Type SendResultType => _sendResultType.Value; } } diff --git a/sources/ClangSharp/Cursors/Decls/ObjCPropertyDecl.cs b/sources/ClangSharp/Cursors/Decls/ObjCPropertyDecl.cs index b8afcd29..e08d4958 100644 --- a/sources/ClangSharp/Cursors/Decls/ObjCPropertyDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ObjCPropertyDecl.cs @@ -1,13 +1,37 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; using ClangSharp.Interop; namespace ClangSharp { public sealed class ObjCPropertyDecl : NamedDecl { + private readonly Lazy _getterMethodDecl; + private readonly Lazy _propertyIvarDecl; + private readonly Lazy _setterMethodDecl; + private readonly Lazy _type; + internal ObjCPropertyDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_ObjCPropertyDecl, CX_DeclKind.CX_DeclKind_ObjCProperty) { + _getterMethodDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(0))); + _propertyIvarDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(1))); + _setterMethodDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(2))); + _type = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ReturnType)); } + + public ObjCMethodDecl GetterMethodDecl => _getterMethodDecl.Value; + + public bool IsClassProperty => (PropertyAttributes & CXObjCPropertyAttrKind.CXObjCPropertyAttr_class) != 0; + + public bool IsInstanceProperty => !IsClassProperty; + + CXObjCPropertyAttrKind PropertyAttributes => Handle.GetObjCPropertyAttributes(0); + + public ObjCIvarDecl PropertyIvarDecl => _propertyIvarDecl.Value; + + public ObjCMethodDecl SetterMethodDecl => _setterMethodDecl.Value; + + public Type Type => _type.Value; } } diff --git a/sources/ClangSharp/Cursors/Decls/ObjCPropertyImplDecl.cs b/sources/ClangSharp/Cursors/Decls/ObjCPropertyImplDecl.cs index 990362d5..1d5a4b89 100644 --- a/sources/ClangSharp/Cursors/Decls/ObjCPropertyImplDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ObjCPropertyImplDecl.cs @@ -7,12 +7,38 @@ namespace ClangSharp { public sealed class ObjCPropertyImplDecl : Decl { + private readonly Lazy _getterCXXConstructor; + private readonly Lazy _getterMethodDecl; + private readonly Lazy _propertyDecl; + private readonly Lazy _propertyIvarDecl; + private readonly Lazy _setterMethodDecl; + private readonly Lazy _setterCXXAssignment; + internal ObjCPropertyImplDecl(CXCursor handle) : base(handle, handle.Kind, CX_DeclKind.CX_DeclKind_ObjCPropertyImpl) { if ((handle.Kind != CXCursorKind.CXCursor_ObjCSynthesizeDecl) && (handle.Kind != CXCursorKind.CXCursor_ObjCDynamicDecl)) { throw new ArgumentException(nameof(handle)); } + + _getterCXXConstructor = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetExpr(0))); + _getterMethodDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(0))); + _propertyDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(1))); + _propertyIvarDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(2))); + _setterMethodDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetSubDecl(3))); + _setterCXXAssignment = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetExpr(1))); } + + public Expr GetterCXXConstructor => _getterCXXConstructor.Value; + + public ObjCMethodDecl GetterMethodDecl => _getterMethodDecl.Value; + + public ObjCPropertyDecl PropertyDecl => _propertyDecl.Value; + + public ObjCIvarDecl PropertyIvarDecl => _propertyIvarDecl.Value; + + public Expr SetterCXXAssignment => _setterCXXAssignment.Value; + + public ObjCMethodDecl SetterMethodDecl => _setterMethodDecl.Value; } } diff --git a/sources/ClangSharp/Cursors/Decls/ObjCProtocolDecl.cs b/sources/ClangSharp/Cursors/Decls/ObjCProtocolDecl.cs index d95cd468..6a713c26 100644 --- a/sources/ClangSharp/Cursors/Decls/ObjCProtocolDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ObjCProtocolDecl.cs @@ -1,13 +1,46 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; +using System.Collections.Generic; using ClangSharp.Interop; namespace ClangSharp { public sealed class ObjCProtocolDecl : ObjCContainerDecl, IRedeclarable { + private readonly Lazy _definition; + private readonly Lazy> _protocols; + internal ObjCProtocolDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_ObjCProtocolDecl, CX_DeclKind.CX_DeclKind_ObjCProtocol) { + _definition = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Definition)); + + _protocols = new Lazy>(() => { + var numProtocols = Handle.NumProtocols; + var protocols = new List(numProtocols); + + for (int i = 0; i < numProtocols; i++) + { + var protocol = TranslationUnit.GetOrCreate(Handle.GetProtocol(unchecked((uint)i))); + protocols.Add(protocol); + } + + return protocols; + }); } + + public new ObjCProtocolDecl CanonicalDecl => (ObjCProtocolDecl)base.CanonicalDecl; + + public ObjCProtocolDecl Definition => _definition.Value; + + public bool IsThisDeclarationADefinition => Handle.IsThisDeclarationADefinition; + + public string ObjCRuntimeNameAsString => Handle.Name.CString; + + public IReadOnlyList Protocols => _protocols.Value; + + public uint ProtocolSize => unchecked((uint)Handle.NumProtocols); + + public IReadOnlyList ReferencedProtocols => Protocols; } } diff --git a/sources/ClangSharp/Cursors/Decls/ObjCTypeParamDecl.cs b/sources/ClangSharp/Cursors/Decls/ObjCTypeParamDecl.cs index 6d66f972..e7a9f05e 100644 --- a/sources/ClangSharp/Cursors/Decls/ObjCTypeParamDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/ObjCTypeParamDecl.cs @@ -9,5 +9,7 @@ public sealed class ObjCTypeParamDecl : TypedefNameDecl internal ObjCTypeParamDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedDecl, CX_DeclKind.CX_DeclKind_ObjCTypeParam) { } + + public uint Index => unchecked((uint)Handle.TemplateTypeParmIndex); } } diff --git a/sources/ClangSharp/Cursors/Decls/RecordDecl.cs b/sources/ClangSharp/Cursors/Decls/RecordDecl.cs index f5d0dfdc..e102dcd3 100644 --- a/sources/ClangSharp/Cursors/Decls/RecordDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/RecordDecl.cs @@ -9,8 +9,12 @@ namespace ClangSharp { public class RecordDecl : TagDecl { - private readonly Lazy> _anonymousDecls; + private readonly Lazy> _anonymousFields; + private readonly Lazy> _anonymousRecords; private readonly Lazy> _fields; + private readonly Lazy> _indirectFields; + private readonly Lazy _injectedClassName; + internal RecordDecl(CXCursor handle) : this(handle, handle.Kind, CX_DeclKind.CX_DeclKind_Record) { @@ -28,18 +32,41 @@ private protected RecordDecl(CXCursor handle, CXCursorKind expectedCursorKind, C throw new ArgumentException(nameof(handle)); } - _fields = new Lazy>(() => Decls.OfType().ToList()); - _anonymousDecls = new Lazy>(() => Decls.Where(decl => ((decl is FieldDecl field) && field.IsAnonymousField) || ((decl is RecordDecl record) && record.IsAnonymousStructOrUnion)).ToList()); + _fields = new Lazy>(() => { + var numFields = Handle.NumFields; + var fields = new List(numFields); + + for (var i = 0; i < numFields; i++) + { + var field = TranslationUnit.GetOrCreate(Handle.GetField(unchecked((uint)i))); + fields.Add(field); + } + + return fields; + }); + + _anonymousFields = new Lazy>(() => Decls.OfType().Where(decl => decl.IsAnonymousField).ToList()); + _anonymousRecords = new Lazy>(() => Decls.OfType().Where(decl => decl.IsAnonymousStructOrUnion && !decl.IsInjectedClassName).ToList()); + _indirectFields = new Lazy>(() => Decls.OfType().ToList()); + _injectedClassName = new Lazy(() => Decls.OfType().Where(decl => decl.IsInjectedClassName).SingleOrDefault()); } public bool IsAnonymousStructOrUnion => Handle.IsAnonymousStructOrUnion; - public IReadOnlyList AnonymousDecls => _anonymousDecls.Value; + public IReadOnlyList AnonymousFields => _anonymousFields.Value; + + public IReadOnlyList AnonymousRecords => _anonymousRecords.Value; public new RecordDecl Definition => (RecordDecl)base.Definition; public IReadOnlyList Fields => _fields.Value; + public IReadOnlyList IndirectFields => _indirectFields.Value; + + public RecordDecl InjectedClassName => _injectedClassName.Value; + + public bool IsInjectedClassName => Handle.IsInjectedClassName; + public new RecordDecl MostRecentDecl => (RecordDecl)base.MostRecentDecl; public new RecordDecl PreviousDecl => (RecordDecl)base.PreviousDecl; diff --git a/sources/ClangSharp/Cursors/Decls/RequiresExprBodyDecl.cs b/sources/ClangSharp/Cursors/Decls/RequiresExprBodyDecl.cs index 1c7c63f0..f22dc0c5 100644 --- a/sources/ClangSharp/Cursors/Decls/RequiresExprBodyDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/RequiresExprBodyDecl.cs @@ -1,25 +1,13 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. -using System; -using System.Collections.Generic; -using System.Linq; using ClangSharp.Interop; namespace ClangSharp { public sealed class RequiresExprBodyDecl : Decl, IDeclContext { - private readonly Lazy> _decls; - internal RequiresExprBodyDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedDecl, CX_DeclKind.CX_DeclKind_RequiresExprBody) { - _decls = new Lazy>(() => CursorChildren.OfType().ToList()); } - - public IReadOnlyList Decls => _decls.Value; - - public IDeclContext LexicalParent => LexicalDeclContext; - - public IDeclContext Parent => DeclContext; } } diff --git a/sources/ClangSharp/Cursors/Decls/StaticAssertDecl.cs b/sources/ClangSharp/Cursors/Decls/StaticAssertDecl.cs index 23202b0e..809159f2 100644 --- a/sources/ClangSharp/Cursors/Decls/StaticAssertDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/StaticAssertDecl.cs @@ -1,13 +1,23 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; using ClangSharp.Interop; namespace ClangSharp { public sealed class StaticAssertDecl : Decl { + private readonly Lazy _assertExpr; + private readonly Lazy _message; + internal StaticAssertDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_StaticAssert, CX_DeclKind.CX_DeclKind_StaticAssert) { + _assertExpr = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetExpr(0))); + _message = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetExpr(1))); } + + public Expr AssertExpr => _assertExpr.Value; + + public StringLiteral Message => _message.Value; } } diff --git a/sources/ClangSharp/Cursors/Decls/TagDecl.cs b/sources/ClangSharp/Cursors/Decls/TagDecl.cs index 491765a0..a3a54bb3 100644 --- a/sources/ClangSharp/Cursors/Decls/TagDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/TagDecl.cs @@ -2,15 +2,14 @@ using System; using System.Collections.Generic; -using System.Linq; using ClangSharp.Interop; namespace ClangSharp { public unsafe class TagDecl : TypeDecl, IDeclContext, IRedeclarable { - private readonly Lazy> _decls; private readonly Lazy _definition; + private readonly Lazy>> _templateParameterLists; private readonly Lazy _typedefNameForAnonDecl; private protected TagDecl(CXCursor handle, CXCursorKind expectedCursorKind, CX_DeclKind expectedDeclKind) : base(handle, expectedCursorKind, expectedDeclKind) @@ -20,19 +19,40 @@ private protected TagDecl(CXCursor handle, CXCursorKind expectedCursorKind, CX_D throw new ArgumentException(nameof(handle)); } - _decls = new Lazy>(() => CursorChildren.OfType().ToList()); _definition = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Definition)); + + _templateParameterLists = new Lazy>>(() => { + var numTemplateParameterLists = Handle.NumTemplateParameterLists; + var templateParameterLists = new List>(numTemplateParameterLists); + + for (var listIndex = 0; listIndex < numTemplateParameterLists; listIndex++) + { + var numTemplateParameters = Handle.GetNumTemplateParameters(unchecked((uint)listIndex)); + var templateParameterList = new List(numTemplateParameters); + + for (var parameterIndex = 0; parameterIndex < numTemplateParameters; parameterIndex++) + { + var templateParameter = TranslationUnit.GetOrCreate(Handle.GetTemplateParameter(unchecked((uint)listIndex), unchecked((uint)parameterIndex))); + templateParameterList.Add(templateParameter); + } + + templateParameterLists.Add(templateParameterList); + } + + return templateParameterLists; + }); + _typedefNameForAnonDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypedefNameForAnonDecl)); } public new TagDecl CanonicalDecl => (TagDecl)base.CanonicalDecl; - public IReadOnlyList Decls => _decls.Value; - public TagDecl Definition => _definition.Value; public bool IsClass => CursorKind == CXCursorKind.CXCursor_ClassDecl; + public bool IsCompleteDefinition => Handle.IsCompleteDefinition; + public bool IsEnum => CursorKind == CXCursorKind.CXCursor_EnumDecl; public bool IsStruct => CursorKind == CXCursorKind.CXCursor_StructDecl; @@ -41,9 +61,9 @@ private protected TagDecl(CXCursor handle, CXCursorKind expectedCursorKind, CX_D public bool IsUnion => CursorKind == CXCursorKind.CXCursor_UnionDecl; - public IDeclContext LexicalParent => LexicalDeclContext; + public uint NumTemplateParameterLists => unchecked((uint)Handle.NumTemplateParameterLists); - public IDeclContext Parent => DeclContext; + public IReadOnlyList> TemplateParameterLists => _templateParameterLists.Value; public TypedefNameDecl TypedefNameForAnonDecl => _typedefNameForAnonDecl.Value; } diff --git a/sources/ClangSharp/Cursors/Decls/TemplateDecl.cs b/sources/ClangSharp/Cursors/Decls/TemplateDecl.cs index 4494fa88..fb81a23c 100644 --- a/sources/ClangSharp/Cursors/Decls/TemplateDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/TemplateDecl.cs @@ -33,12 +33,12 @@ private protected TemplateDecl(CXCursor handle, CXCursorKind expectedCursorKind, }); _templatedDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TemplatedDecl)); _templateParameters = new Lazy>(() => { - var parameterCount = Handle.NumTemplateArguments; + var parameterCount = Handle.GetNumTemplateParameters(0); var parameters = new List(parameterCount); for (int i = 0; i < parameterCount; i++) { - var parameter = TranslationUnit.GetOrCreate(Handle.GetTemplateArgument(unchecked((uint)i))); + var parameter = TranslationUnit.GetOrCreate(Handle.GetTemplateParameter(0, unchecked((uint)i))); parameters.Add(parameter); } diff --git a/sources/ClangSharp/Cursors/Decls/TemplateTemplateParmDecl.cs b/sources/ClangSharp/Cursors/Decls/TemplateTemplateParmDecl.cs index 10df57ac..ce5151ce 100644 --- a/sources/ClangSharp/Cursors/Decls/TemplateTemplateParmDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/TemplateTemplateParmDecl.cs @@ -1,26 +1,33 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; using ClangSharp.Interop; namespace ClangSharp { public sealed class TemplateTemplateParmDecl : TemplateDecl, ITemplateParmPosition { - private readonly TemplateArgumentLoc _defaultArgument; + private readonly Lazy _defaultArgument; internal TemplateTemplateParmDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_TemplateTemplateParameter, CX_DeclKind.CX_DeclKind_TemplateTemplateParm) { - _defaultArgument = new TemplateArgumentLoc(this, 0); + _defaultArgument = new Lazy(() => TranslationUnit.GetOrCreate(handle.GetTemplateArgumentLoc(0))); } - public TemplateArgumentLoc DefaultArgument => _defaultArgument; + public TemplateArgumentLoc DefaultArgument => _defaultArgument.Value; public bool DefaultArgumentWasInherited => Handle.HasInheritedDefaultArg; + public uint Depth => unchecked((uint)Handle.TemplateTypeParmDepth); + + public uint Index => unchecked((uint)Handle.TemplateTypeParmIndex); + public bool IsExpandedParameterPack => Handle.IsExpandedParameterPack; public bool IsPackExpansion => Handle.IsPackExpansion; public bool IsParameterPack => Handle.IsParameterPack; + + public uint Position => unchecked((uint)Handle.TemplateTypeParmPosition); } } diff --git a/sources/ClangSharp/Cursors/Decls/TranslationUnitDecl.cs b/sources/ClangSharp/Cursors/Decls/TranslationUnitDecl.cs index 184c1a63..948d17b1 100644 --- a/sources/ClangSharp/Cursors/Decls/TranslationUnitDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/TranslationUnitDecl.cs @@ -1,25 +1,13 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. -using System; -using System.Collections.Generic; -using System.Linq; using ClangSharp.Interop; namespace ClangSharp { public sealed unsafe class TranslationUnitDecl : Decl, IDeclContext { - private readonly Lazy> _decls; - internal TranslationUnitDecl(CXCursor handle) : base(handle, CXCursorKind.CXCursor_TranslationUnit, CX_DeclKind.CX_DeclKind_TranslationUnit) { - _decls = new Lazy>(() => CursorChildren.OfType().ToList()); } - - public IReadOnlyList Decls => _decls.Value; - - public IDeclContext LexicalParent => LexicalDeclContext; - - public IDeclContext Parent => DeclContext; } } diff --git a/sources/ClangSharp/Cursors/Decls/TypedefNameDecl.cs b/sources/ClangSharp/Cursors/Decls/TypedefNameDecl.cs index faefca48..2fa5bf61 100644 --- a/sources/ClangSharp/Cursors/Decls/TypedefNameDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/TypedefNameDecl.cs @@ -21,7 +21,7 @@ private protected TypedefNameDecl(CXCursor handle, CXCursorKind expectedCursorKi public new TypedefNameDecl CanonicalDecl => (TypedefNameDecl)base.CanonicalDecl; - public bool IsTransparentTag => Handle.IsTransparentTag; + public bool IsTransparentTag => Handle.IsTransparent; public Type UnderlyingType => _underlyingType.Value; } diff --git a/sources/ClangSharp/Cursors/Decls/VarTemplatePartialSpecializationDecl.cs b/sources/ClangSharp/Cursors/Decls/VarTemplatePartialSpecializationDecl.cs index 8d36e04a..00e2cfe0 100644 --- a/sources/ClangSharp/Cursors/Decls/VarTemplatePartialSpecializationDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/VarTemplatePartialSpecializationDecl.cs @@ -28,12 +28,12 @@ internal VarTemplatePartialSpecializationDecl(CXCursor handle) : base(handle, CX }); _instantiatedFromMember = new Lazy(() => TranslationUnit.GetOrCreate(Handle.InstantiatedFromMember)); _templateParameters = new Lazy>(() => { - var parameterCount = Handle.NumTemplateArguments; + var parameterCount = Handle.GetNumTemplateParameters(0); var parameters = new List(parameterCount); for (int i = 0; i < parameterCount; i++) { - var parameter = TranslationUnit.GetOrCreate(Handle.GetTemplateArgument(unchecked((uint)i))); + var parameter = TranslationUnit.GetOrCreate(Handle.GetTemplateParameter(0, unchecked((uint)i))); parameters.Add(parameter); } diff --git a/sources/ClangSharp/Cursors/Decls/VarTemplateSpecializationDecl.cs b/sources/ClangSharp/Cursors/Decls/VarTemplateSpecializationDecl.cs index 9ed09c36..6e9df6ca 100644 --- a/sources/ClangSharp/Cursors/Decls/VarTemplateSpecializationDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/VarTemplateSpecializationDecl.cs @@ -29,7 +29,7 @@ private protected VarTemplateSpecializationDecl(CXCursor handle, CXCursorKind ex for (int i = 0; i < templateArgCount; i++) { - var templateArg = new TemplateArgument(this, unchecked((uint)i)); + var templateArg = TranslationUnit.GetOrCreate(Handle.GetTemplateArgument(unchecked((uint)i))); templateArgs.Add(templateArg); } diff --git a/sources/ClangSharp/Cursors/Exprs/AbstractConditionalOperator.cs b/sources/ClangSharp/Cursors/Exprs/AbstractConditionalOperator.cs index d39c7d22..45169db8 100644 --- a/sources/ClangSharp/Cursors/Exprs/AbstractConditionalOperator.cs +++ b/sources/ClangSharp/Cursors/Exprs/AbstractConditionalOperator.cs @@ -7,26 +7,48 @@ namespace ClangSharp { public class AbstractConditionalOperator : Expr { - private readonly Lazy _cond; - private readonly Lazy _falseExpr; - private readonly Lazy _trueExpr; - private protected AbstractConditionalOperator(CXCursor handle, CXCursorKind expectedCursorKind, CX_StmtClass expectedStmtClass) : base(handle, expectedCursorKind, expectedStmtClass) { if ((CX_StmtClass.CX_StmtClass_LastAbstractConditionalOperator < handle.StmtClass) || (handle.StmtClass < CX_StmtClass.CX_StmtClass_FirstAbstractConditionalOperator)) { throw new ArgumentException(nameof(handle)); } - - _cond = new Lazy(() => TranslationUnit.GetOrCreate(Handle.CondExpr)); - _falseExpr = new Lazy(() => TranslationUnit.GetOrCreate(Handle.FalseExpr)); - _trueExpr = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TrueExpr)); } - public Expr Cond => _cond.Value; + public Expr Cond + { + get + { + if (this is ConditionalOperator co) + { + return co.Cond; + } + return ((BinaryConditionalOperator)this).Cond; + } + } - public Expr FalseExpr => _falseExpr.Value; + public Expr FalseExpr + { + get + { + if (this is ConditionalOperator co) + { + return co.FalseExpr; + } + return ((BinaryConditionalOperator)this).FalseExpr; + } + } - public Expr TrueExpr => _trueExpr.Value; + public Expr TrueExpr + { + get + { + if (this is ConditionalOperator co) + { + return co.TrueExpr; + } + return ((BinaryConditionalOperator)this).TrueExpr; + } + } } } diff --git a/sources/ClangSharp/Cursors/Exprs/AddrLabelExpr.cs b/sources/ClangSharp/Cursors/Exprs/AddrLabelExpr.cs index 717bf127..7d9a959d 100644 --- a/sources/ClangSharp/Cursors/Exprs/AddrLabelExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/AddrLabelExpr.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp @@ -11,6 +12,7 @@ public sealed class AddrLabelExpr : Expr internal AddrLabelExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_AddrLabelExpr, CX_StmtClass.CX_StmtClass_AddrLabelExpr) { + Debug.Assert(NumChildren is 0); _label = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); } diff --git a/sources/ClangSharp/Cursors/Exprs/ArrayInitIndexExpr.cs b/sources/ClangSharp/Cursors/Exprs/ArrayInitIndexExpr.cs index efdb6822..d9407e6d 100644 --- a/sources/ClangSharp/Cursors/Exprs/ArrayInitIndexExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/ArrayInitIndexExpr.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp @@ -8,6 +9,7 @@ public sealed class ArrayInitIndexExpr : Expr { internal ArrayInitIndexExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedExpr, CX_StmtClass.CX_StmtClass_ArrayInitIndexExpr) { + Debug.Assert(NumChildren is 0); } } } diff --git a/sources/ClangSharp/Cursors/Exprs/ArrayInitLoopExpr.cs b/sources/ClangSharp/Cursors/Exprs/ArrayInitLoopExpr.cs index cfa351c6..bd80b88e 100644 --- a/sources/ClangSharp/Cursors/Exprs/ArrayInitLoopExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/ArrayInitLoopExpr.cs @@ -1,25 +1,21 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. -using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public sealed class ArrayInitLoopExpr : Expr { - private readonly Lazy _commonExpr; - private readonly Lazy _subExpr; - internal ArrayInitLoopExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedExpr, CX_StmtClass.CX_StmtClass_ArrayInitLoopExpr) { - _commonExpr = new Lazy(() => TranslationUnit.GetOrCreate(Handle.CommonExpr)); - _subExpr = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SubExpr)); + Debug.Assert(NumChildren is 2); } public long ArraySize => Handle.ArraySize; - public OpaqueValueExpr CommonExpr => _commonExpr.Value; + public OpaqueValueExpr CommonExpr => (OpaqueValueExpr)Children[0]; - public Expr SubExpr => _subExpr.Value; + public Expr SubExpr => (Expr)Children[1]; } } diff --git a/sources/ClangSharp/Cursors/Exprs/ArraySubscriptExpr.cs b/sources/ClangSharp/Cursors/Exprs/ArraySubscriptExpr.cs index c3d47a47..c89125c5 100644 --- a/sources/ClangSharp/Cursors/Exprs/ArraySubscriptExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/ArraySubscriptExpr.cs @@ -1,31 +1,25 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. -using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public sealed class ArraySubscriptExpr : Expr { - private readonly Lazy _base; - private readonly Lazy _idx; - private readonly Lazy _lhs; - private readonly Lazy _rhs; - internal ArraySubscriptExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_ArraySubscriptExpr, CX_StmtClass.CX_StmtClass_ArraySubscriptExpr) { - _base = new Lazy(() => TranslationUnit.GetOrCreate(Handle.BaseExpr)); - _idx = new Lazy(() => TranslationUnit.GetOrCreate(Handle.IdxExpr)); - _lhs = new Lazy(() => TranslationUnit.GetOrCreate(Handle.LhsExpr)); - _rhs = new Lazy(() => TranslationUnit.GetOrCreate(Handle.RhsExpr)); + Debug.Assert(NumChildren is 2); } - public Expr Base => _base.Value; + public Expr Base => LHSIsBase ? LHS : RHS; + + public Expr Idx => LHSIsBase ? RHS : LHS; - public Expr Idx => _idx.Value; + public Expr LHS => (Expr)Children[0]; - public Expr LHS => _lhs.Value; + public Expr RHS => (Expr)Children[1]; - public Expr RHS => _rhs.Value; + private bool LHSIsBase => RHS.Type.IsIntegerType; } } diff --git a/sources/ClangSharp/Cursors/Exprs/AsTypeExpr.cs b/sources/ClangSharp/Cursors/Exprs/AsTypeExpr.cs index 84db41ae..f5a7c08c 100644 --- a/sources/ClangSharp/Cursors/Exprs/AsTypeExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/AsTypeExpr.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp @@ -8,6 +9,9 @@ public sealed class AsTypeExpr : Expr { internal AsTypeExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedExpr, CX_StmtClass.CX_StmtClass_AsTypeExpr) { + Debug.Assert(NumChildren is 1); } + + public Expr SrcExpr => (Expr)Children[0]; } } diff --git a/sources/ClangSharp/Cursors/Exprs/AtomicExpr.cs b/sources/ClangSharp/Cursors/Exprs/AtomicExpr.cs index dfc3fff7..1dae90ff 100644 --- a/sources/ClangSharp/Cursors/Exprs/AtomicExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/AtomicExpr.cs @@ -1,13 +1,63 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; +using System.Collections.Generic; +using System.Linq; using ClangSharp.Interop; namespace ClangSharp { public sealed class AtomicExpr : Expr { + private readonly Lazy> _subExprs; + private readonly Lazy _valueType; + internal AtomicExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedExpr, CX_StmtClass.CX_StmtClass_AtomicExpr) { + _subExprs = new Lazy>(() => Children.Cast().ToList()); + _valueType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); + } + + public CX_AtomicOperatorKind Op => Handle.AtomicOperatorKind; + + public uint NumSubExprs => NumChildren; + + public Expr Order => SubExprs[1]; + + public Expr OrderFail => NumSubExprs > 3 ? SubExprs[3] : null; + + public Expr Ptr => SubExprs[0]; + + public Expr Scope => (Op >= CX_AtomicOperatorKind.CX_AO__opencl_atomic_load && Op <= CX_AtomicOperatorKind.CX_AO__opencl_atomic_fetch_max) ? SubExprs[(int)(NumSubExprs - 1)] : null; + + public IReadOnlyList SubExprs => _subExprs.Value; + + public Expr Val1 + { + get + { + if (Op == CX_AtomicOperatorKind.CX_AO__c11_atomic_init || Op == CX_AtomicOperatorKind.CX_AO__opencl_atomic_init) + { + return Order; + } + return (NumSubExprs > 2) ? SubExprs[2] : null; + } + } + + public Expr Val + { + get + { + if (Op == CX_AtomicOperatorKind.CX_AO__atomic_exchange) + { + return OrderFail; + } + return (NumSubExprs > 4) ? SubExprs[4] : null; + } } + + public Type ValueType => _valueType.Value; + + public Expr Weak => (NumSubExprs > 5) ? SubExprs[5] : null; } } diff --git a/sources/ClangSharp/Cursors/Exprs/BinaryConditionalOperator.cs b/sources/ClangSharp/Cursors/Exprs/BinaryConditionalOperator.cs index c0ec8589..369d4c9c 100644 --- a/sources/ClangSharp/Cursors/Exprs/BinaryConditionalOperator.cs +++ b/sources/ClangSharp/Cursors/Exprs/BinaryConditionalOperator.cs @@ -1,23 +1,29 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public sealed class BinaryConditionalOperator : AbstractConditionalOperator { - private readonly Lazy _common; private readonly Lazy _opaqueValue; internal BinaryConditionalOperator(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedExpr, CX_StmtClass.CX_StmtClass_BinaryConditionalOperator) { - _common = new Lazy(() => TranslationUnit.GetOrCreate(Handle.CommonExpr)); - _opaqueValue = new Lazy(() => TranslationUnit.GetOrCreate(Handle.OpaqueValueExpr)); + Debug.Assert(NumChildren is 4); + _opaqueValue = new Lazy(() => TranslationUnit.GetOrCreate(Handle.OpaqueValue)); } - public Expr Common => _common.Value; + public Expr Common => (Expr)Children[0]; - public OpaqueValueExpr OpaqueValueExpr => _opaqueValue.Value; + public new Expr Cond => (Expr)Children[1]; + + public new Expr FalseExpr => (Expr)Children[3]; + + public OpaqueValueExpr OpaqueValue => _opaqueValue.Value; + + public new Expr TrueExpr => (Expr)Children[2]; } } diff --git a/sources/ClangSharp/Cursors/Exprs/BinaryOperator.cs b/sources/ClangSharp/Cursors/Exprs/BinaryOperator.cs index 2f660ad2..28521e58 100644 --- a/sources/ClangSharp/Cursors/Exprs/BinaryOperator.cs +++ b/sources/ClangSharp/Cursors/Exprs/BinaryOperator.cs @@ -1,15 +1,13 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public class BinaryOperator : Expr { - private readonly Lazy _lhs; - private readonly Lazy _rhs; - internal BinaryOperator(CXCursor handle) : this(handle, CXCursorKind.CXCursor_BinaryOperator, CX_StmtClass.CX_StmtClass_BinaryOperator) { } @@ -21,16 +19,41 @@ private protected BinaryOperator(CXCursor handle, CXCursorKind expectedCursorKin throw new ArgumentException(nameof(handle)); } - _lhs = new Lazy(() => TranslationUnit.GetOrCreate(Handle.LhsExpr)); - _rhs = new Lazy(() => TranslationUnit.GetOrCreate(Handle.RhsExpr)); + Debug.Assert(NumChildren is 2); } - public Expr LHS => _lhs.Value; + public bool IsAdditiveOp => (Opcode == CX_BinaryOperatorKind.CX_BO_Add) || (Opcode == CX_BinaryOperatorKind.CX_BO_Sub); + + public bool IsAssignmentOp => (Opcode >= CX_BinaryOperatorKind.CX_BO_Assign) && (Opcode <= CX_BinaryOperatorKind.CX_BO_OrAssign); + + public bool IsBitwiseOp => (Opcode >= CX_BinaryOperatorKind.CX_BO_And) && (Opcode <= CX_BinaryOperatorKind.CX_BO_Or); + + public bool IsCommaOp => Opcode == CX_BinaryOperatorKind.CX_BO_Comma; + + public bool IsComparisonOp => (Opcode >= CX_BinaryOperatorKind.CX_BO_Cmp) && (Opcode <= CX_BinaryOperatorKind.CX_BO_NE); + + public bool IsCompoundAssignmentOp=> (Opcode > CX_BinaryOperatorKind.CX_BO_Assign) && (Opcode <= CX_BinaryOperatorKind.CX_BO_OrAssign); + + public bool IsEqualityOp => (Opcode == CX_BinaryOperatorKind.CX_BO_EQ) || (Opcode == CX_BinaryOperatorKind.CX_BO_NE); + + public bool IsLogicalOp => (Opcode == CX_BinaryOperatorKind.CX_BO_LAnd) || (Opcode == CX_BinaryOperatorKind.CX_BO_LOr); + + public bool IsMultiplicativeOp => (Opcode >= CX_BinaryOperatorKind.CX_BO_Mul) && (Opcode <= CX_BinaryOperatorKind.CX_BO_Rem); + + public bool IsPtrMemOp => (Opcode == CX_BinaryOperatorKind.CX_BO_PtrMemD) || (Opcode == CX_BinaryOperatorKind.CX_BO_PtrMemI); + + public bool IsRelationalOp => (Opcode >= CX_BinaryOperatorKind.CX_BO_LT) && (Opcode <= CX_BinaryOperatorKind.CX_BO_GE); + + public bool IsShiftAssignOp=> (Opcode == CX_BinaryOperatorKind.CX_BO_ShlAssign) || (Opcode == CX_BinaryOperatorKind.CX_BO_ShrAssign); + + public bool IsShiftOp => (Opcode == CX_BinaryOperatorKind.CX_BO_Shl) || (Opcode == CX_BinaryOperatorKind.CX_BO_Shr); + + public Expr LHS => (Expr)Children[0]; public CX_BinaryOperatorKind Opcode => Handle.BinaryOperatorKind; - public string OpcodeStr => Handle.BinaryOperatorKindSpelling.ToString(); + public string OpcodeStr => Handle.BinaryOperatorKindSpelling.CString; - public Expr RHS => _rhs.Value; + public Expr RHS => (Expr)Children[1]; } } diff --git a/sources/ClangSharp/Cursors/Exprs/BlockExpr.cs b/sources/ClangSharp/Cursors/Exprs/BlockExpr.cs index 2ff6adf3..5268b962 100644 --- a/sources/ClangSharp/Cursors/Exprs/BlockExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/BlockExpr.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp @@ -8,14 +9,17 @@ namespace ClangSharp public sealed class BlockExpr : Expr { private readonly Lazy _blockDecl; - private readonly Lazy _body; - private readonly Lazy _functionType; internal BlockExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_BlockExpr, CX_StmtClass.CX_StmtClass_BlockExpr) { + Debug.Assert(NumChildren is 0); _blockDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); - _body = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Body)); - _functionType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.FunctionType)); } + + public BlockDecl BlockDecl => _blockDecl.Value; + + public Stmt Body => BlockDecl.Body; + + public FunctionProtoType FunctionType => (FunctionProtoType)((BlockPointerType)Type).PointeeType; } } diff --git a/sources/ClangSharp/Cursors/Exprs/CXXBindTemporaryExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXBindTemporaryExpr.cs index 1418d321..a257e414 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXBindTemporaryExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXBindTemporaryExpr.cs @@ -1,19 +1,17 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. -using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public sealed class CXXBindTemporaryExpr : Expr { - private readonly Lazy _subExpr; - internal CXXBindTemporaryExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedExpr, CX_StmtClass.CX_StmtClass_CXXBindTemporaryExpr) { - _subExpr = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SubExpr)); + Debug.Assert(NumChildren is 1); } - public Expr SubExpr => _subExpr.Value; + public Expr SubExpr => (Expr)Children[0]; } } diff --git a/sources/ClangSharp/Cursors/Exprs/CXXBoolLiteralExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXBoolLiteralExpr.cs index 74f2a5eb..39a415ae 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXBoolLiteralExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXBoolLiteralExpr.cs @@ -12,6 +12,8 @@ public sealed class CXXBoolLiteralExpr : Expr internal CXXBoolLiteralExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_CXXBoolLiteralExpr, CX_StmtClass.CX_StmtClass_CXXBoolLiteralExpr) { + Debug.Assert(NumChildren is 0); + _valueString = new Lazy(() => { var tokens = Handle.TranslationUnit.Tokenize(Handle.SourceRange); @@ -24,7 +26,7 @@ internal CXXBoolLiteralExpr(CXCursor handle) : base(handle, CXCursorKind.CXCurso }); } - public bool Value => Handle.CXXBoolLiteralExprValue; + public bool Value => Handle.BoolLiteralValue; public string ValueString => _valueString.Value; } diff --git a/sources/ClangSharp/Cursors/Exprs/CXXConstructExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXConstructExpr.cs index 96054960..5cb51f94 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXConstructExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXConstructExpr.cs @@ -2,6 +2,8 @@ using System; using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; using ClangSharp.Interop; namespace ClangSharp @@ -21,19 +23,9 @@ private protected CXXConstructExpr(CXCursor handle, CXCursorKind expectedCursorK { throw new ArgumentException(nameof(handle)); } + Debug.Assert(NumChildren == NumArgs); - _args = new Lazy>(() => { - var numArgs = NumArgs; - var args = new List((int)numArgs); - - for (var index = 0u; index < numArgs; index++) - { - var arg = Handle.GetArgument(index); - args.Add(TranslationUnit.GetOrCreate(arg)); - } - - return args; - }); + _args = new Lazy>(() => Children.Cast().ToList()); _constructor = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); } @@ -41,6 +33,18 @@ private protected CXXConstructExpr(CXCursor handle, CXCursorKind expectedCursorK public CXXConstructorDecl Constructor => _constructor.Value; + public CX_ConstructionKind ConstructionKind => Handle.ConstructionKind; + + public bool HadMultipleCandidates => Handle.HadMultipleCandidates; + + public bool IsElidable => Handle.IsElidable; + + public bool IsListInitialization => Handle.IsListInitialization; + + public bool IsStdInitListInitialization => Handle.IsStdInitListInitialization; + public uint NumArgs => (uint)Handle.NumArguments; + + public bool RequiresZeroInitialization => Handle.RequiresZeroInitialization; } } diff --git a/sources/ClangSharp/Cursors/Exprs/CXXDefaultArgExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXDefaultArgExpr.cs index 4ebce830..56a2952d 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXDefaultArgExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXDefaultArgExpr.cs @@ -1,24 +1,25 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public sealed class CXXDefaultArgExpr : Expr { - private readonly Lazy _expr; private readonly Lazy _param; private readonly Lazy _usedContext; internal CXXDefaultArgExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedExpr, CX_StmtClass.CX_StmtClass_CXXDefaultArgExpr) { - _expr = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SubExpr)); + Debug.Assert(NumChildren is 0); + _param = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); _usedContext = new Lazy(() => TranslationUnit.GetOrCreate(Handle.UsedContext) as IDeclContext); } - public Expr Expr => _expr.Value; + public Expr Expr => Param.DefaultArg; public ParmVarDecl Param => _param.Value; diff --git a/sources/ClangSharp/Cursors/Exprs/CXXDefaultInitExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXDefaultInitExpr.cs index 3aca182c..b1f0e369 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXDefaultInitExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXDefaultInitExpr.cs @@ -1,24 +1,25 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public sealed class CXXDefaultInitExpr : Expr { - private Lazy _expr; private Lazy _field; private Lazy _usedContext; internal CXXDefaultInitExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedExpr, CX_StmtClass.CX_StmtClass_CXXDefaultInitExpr) { - _expr = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SubExpr)); + Debug.Assert(NumChildren is 0); + _field = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); _usedContext = new Lazy(() => TranslationUnit.GetOrCreate(Handle.UsedContext) as IDeclContext); } - public Expr Expr => _expr.Value; + public Expr Expr => Field.InClassInitializer; public FieldDecl Field => _field.Value; diff --git a/sources/ClangSharp/Cursors/Exprs/CXXDeleteExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXDeleteExpr.cs index b18ff432..0f876844 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXDeleteExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXDeleteExpr.cs @@ -1,22 +1,35 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public sealed class CXXDeleteExpr : Expr { - private Lazy _argument; + private Lazy _destroyedType; private Lazy _operatorDelete; internal CXXDeleteExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_CXXDeleteExpr, CX_StmtClass.CX_StmtClass_CXXDeleteExpr) { - _argument = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SubExpr)); + Debug.Assert(NumChildren is 1); + + _destroyedType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); _operatorDelete = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); } - public Expr Argument => _argument.Value; + public Expr Argument => (Expr)Children[0]; + + public Type DestroyedType => _destroyedType.Value; + + public bool DoesUsualArrayDeleteWantSize => Handle.DoesUsualArrayDeleteWantSize; + + public bool IsArrayForm => Handle.IsArrayForm; + + public bool IsArrayFormAsWritten => Handle.IsArrayFormAsWritten; + + public bool IsGlobalDelete => Handle.IsGlobal; public FunctionDecl OperatorDelete => _operatorDelete.Value; } diff --git a/sources/ClangSharp/Cursors/Exprs/CXXDependentScopeMemberExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXDependentScopeMemberExpr.cs index 41a2166f..b0e59246 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXDependentScopeMemberExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXDependentScopeMemberExpr.cs @@ -1,13 +1,57 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; using ClangSharp.Interop; namespace ClangSharp { public sealed class CXXDependentScopeMemberExpr : Expr { + private readonly Lazy _baseType; + private readonly Lazy _firstQualifierFoundInScope; + private readonly Lazy> _templateArgs; + internal CXXDependentScopeMemberExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_MemberRefExpr, CX_StmtClass.CX_StmtClass_CXXDependentScopeMemberExpr) { + Debug.Assert(NumChildren is 0 or 1); + + _baseType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); + _firstQualifierFoundInScope = new Lazy(() => TranslationUnit.GetOrCreate(handle.Referenced)); + _templateArgs = new Lazy>(() => { + var templateArgCount = Handle.NumTemplateArguments; + var templateArgs = new List(templateArgCount); + + for (int i = 0; i < templateArgCount; i++) + { + var templateArg = TranslationUnit.GetOrCreate(Handle.GetTemplateArgumentLoc(unchecked((uint)i))); + templateArgs.Add(templateArg); + } + + return templateArgs; + }); } + + public Expr Base => (Expr)Children.SingleOrDefault(); + + public Type BaseType => _baseType.Value; + + public NamedDecl FirstQualifierFoundInScope => _firstQualifierFoundInScope.Value; + + public bool HasExplicitTemplateArgs => Handle.HasExplicitTemplateArgs; + + public bool HasTemplateKeyword => Handle.HasTemplateKeyword; + + public bool IsArrow => Handle.IsArrow; + + public bool IsImplicitAccess => (Base is null) || Base.IsImplicitCXXThis; + + public string MemberName => Handle.Name.CString; + + public uint NumTemplateArgs => unchecked((uint)Handle.NumTemplateArguments); + + public IReadOnlyList TemplateArgs => _templateArgs.Value; } } diff --git a/sources/ClangSharp/Cursors/Exprs/CXXDynamicCastExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXDynamicCastExpr.cs index 16405a57..98a080ae 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXDynamicCastExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXDynamicCastExpr.cs @@ -9,5 +9,7 @@ public sealed class CXXDynamicCastExpr : CXXNamedCastExpr internal CXXDynamicCastExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_CXXDynamicCastExpr, CX_StmtClass.CX_StmtClass_CXXDynamicCastExpr) { } + + public bool IsAlwaysNull => Handle.IsAlwaysNull; } } diff --git a/sources/ClangSharp/Cursors/Exprs/CXXFoldExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXFoldExpr.cs index 91a5f9c0..bccf1f94 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXFoldExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXFoldExpr.cs @@ -1,33 +1,31 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. -using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public sealed class CXXFoldExpr : Expr { - private readonly Lazy _init; - private readonly Lazy _lhs; - private readonly Lazy _pattern; - private readonly Lazy _rhs; - internal CXXFoldExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedExpr, CX_StmtClass.CX_StmtClass_CXXFoldExpr) { - _init = new Lazy(() => TranslationUnit.GetOrCreate(Handle.InitExpr)); - _lhs = new Lazy(() => TranslationUnit.GetOrCreate(Handle.LhsExpr)); - _pattern = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SubExpr)); - _rhs = new Lazy(() => TranslationUnit.GetOrCreate(Handle.RhsExpr)); + Debug.Assert(NumChildren is 3); } - public Expr Init => _init.Value; + public UnresolvedLookupExpr Callee => (UnresolvedLookupExpr)Children[0]; + + public Expr Init => IsLeftFold ? LHS : RHS; + + public bool IsLeftFold => !IsRightFold; + + public bool IsRightFold => (LHS != null) && LHS.ContainsUnexpandedParameterPack; - public Expr LHS => _lhs.Value; + public Expr LHS => (Expr)Children[1]; public CX_BinaryOperatorKind Operator => Handle.BinaryOperatorKind; - public Expr Pattern => _pattern.Value; + public Expr Pattern => IsLeftFold ? RHS : LHS; - public Expr RHS => _rhs.Value; + public Expr RHS => (Expr)Children[2]; } } diff --git a/sources/ClangSharp/Cursors/Exprs/CXXFunctionalCastExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXFunctionalCastExpr.cs index e28fd7aa..d09e1d0d 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXFunctionalCastExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXFunctionalCastExpr.cs @@ -9,5 +9,7 @@ public sealed class CXXFunctionalCastExpr : ExplicitCastExpr internal CXXFunctionalCastExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_CXXFunctionalCastExpr, CX_StmtClass.CX_StmtClass_CXXFunctionalCastExpr) { } + + public bool IsListInitialization => Handle.IsListInitialization; } } diff --git a/sources/ClangSharp/Cursors/Exprs/CXXInheritedCtorInitExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXInheritedCtorInitExpr.cs index 4469e1e2..b028dfc2 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXInheritedCtorInitExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXInheritedCtorInitExpr.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp @@ -11,9 +12,16 @@ public sealed class CXXInheritedCtorInitExpr : Expr internal CXXInheritedCtorInitExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_CallExpr, CX_StmtClass.CX_StmtClass_CXXInheritedCtorInitExpr) { + Debug.Assert(NumChildren is 0); _constructor = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); } + public CX_ConstructionKind ConstructionKind => ConstructsVBase ? CX_ConstructionKind.CX_CK_VirtualBase : CX_ConstructionKind.CX_CK_NonVirtualBase; + public CXXConstructorDecl Constructor => _constructor.Value; + + public bool ConstructsVBase => Handle.ConstructsVirtualBase; + + public bool InheritedFromVBase => Handle.InheritedFromVBase; } } diff --git a/sources/ClangSharp/Cursors/Exprs/CXXMemberCallExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXMemberCallExpr.cs index 600fff3f..196b87ca 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXMemberCallExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXMemberCallExpr.cs @@ -9,5 +9,75 @@ public sealed class CXXMemberCallExpr : CallExpr internal CXXMemberCallExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_CallExpr, CX_StmtClass.CX_StmtClass_CXXMemberCallExpr) { } + + public Expr ImplicitObjectArgument + { + get + { + Expr callee = Callee.IgnoreParens; + + if (callee is MemberExpr MemExpr) + { + return MemExpr.Base; + } + + if (callee is BinaryOperator BO) + { + if (BO.IsPtrMemOp) + { + return BO.LHS; + } + } + + return null; + } + } + + public CXXMethodDecl MethodDecl + { + get + { + if (Callee.IgnoreParens is MemberExpr MemExpr) + { + return (CXXMethodDecl)MemExpr.MemberDecl; + } + + return null; + } + } + + public Type ObjectType + { + get + { + Type Ty = ImplicitObjectArgument.Type; + + if (Ty.IsPointerType) + { + Ty = Ty.PointeeType; + } + return Ty; + } + } + + public CXXRecordDecl RecordDecl + { + get + { + Expr ThisArg = ImplicitObjectArgument; + + if (ThisArg is null) + { + return null; + } + + if (ThisArg.Type.IsAnyPointerType) + { + return ThisArg.Type.PointeeType.AsCXXRecordDecl; + } + + return ThisArg.Type.AsCXXRecordDecl; + } + } } } diff --git a/sources/ClangSharp/Cursors/Exprs/CXXNamedCastExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXNamedCastExpr.cs index 4f44964a..026d4b0e 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXNamedCastExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXNamedCastExpr.cs @@ -14,5 +14,7 @@ private protected CXXNamedCastExpr(CXCursor handle, CXCursorKind expectedCursorK throw new ArgumentException(nameof(handle)); } } + + public string CastName => Handle.Name.CString; } } diff --git a/sources/ClangSharp/Cursors/Exprs/CXXNewExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXNewExpr.cs index bda9f47d..faf6f834 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXNewExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXNewExpr.cs @@ -1,13 +1,53 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; +using System.Collections.Generic; +using System.Linq; using ClangSharp.Interop; namespace ClangSharp { public sealed class CXXNewExpr : Expr { + private readonly Lazy _operatorDelete; + private readonly Lazy _operatorNew; + private readonly Lazy> _placementArgs; + internal CXXNewExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_CXXNewExpr, CX_StmtClass.CX_StmtClass_CXXNewExpr) { + _operatorDelete = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetDecl(0))); + _operatorNew = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetDecl(1))); + _placementArgs = new Lazy>(() => Children.Skip(PlacementNewArgsOffset).Cast().ToList()); } + + public Type AllocatedType => ((PointerType)Type).PointeeType; + + public Expr ArraySize => IsArray ? (Expr)Children[ArraySizeOffset] : null; + + public CXXConstructExpr ConstructExpr => Initializer as CXXConstructExpr; + + public bool DoesUsualArrayDeleteWantSize => Handle.DoesUsualArrayDeleteWantSize; + + public bool HasInitializer => Handle.HasInit; + + public Expr Initializer => HasInitializer ? (Expr)Children[InitExprOffset] : null; + + public bool IsArray => Handle.IsArrayForm; + + public bool IsGlobalNew => Handle.IsGlobal; + + public uint NumPlacementArgs => unchecked((uint)(Handle.NumArguments - PlacementNewArgsOffset)); + + public FunctionDecl OperatorDelete => _operatorDelete.Value; + + public FunctionDecl OperatorNew => _operatorNew.Value; + + public IReadOnlyList PlacementArgs => _placementArgs.Value; + + private int ArraySizeOffset => 0; + + private int InitExprOffset => ArraySizeOffset + (IsArray ? 1 : 0); + + private int PlacementNewArgsOffset => InitExprOffset + (HasInitializer ? 1 : 0); } } diff --git a/sources/ClangSharp/Cursors/Exprs/CXXNoexceptExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXNoexceptExpr.cs index 4a1f6ec5..4a2b24e8 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXNoexceptExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXNoexceptExpr.cs @@ -1,19 +1,19 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. -using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public sealed class CXXNoexceptExpr : Expr { - private readonly Lazy _operand; - internal CXXNoexceptExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnaryExpr, CX_StmtClass.CX_StmtClass_CXXNoexceptExpr) { - _operand = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SubExpr)); + Debug.Assert(NumChildren is 1); } - public Expr Operand => _operand.Value; + public Expr Operand => (Expr)Children[0]; + + public bool Value => Handle.BoolLiteralValue; } } diff --git a/sources/ClangSharp/Cursors/Exprs/CXXNullPtrLiteralExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXNullPtrLiteralExpr.cs index 5c34da23..3e7c4a9f 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXNullPtrLiteralExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXNullPtrLiteralExpr.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp @@ -8,6 +9,7 @@ public sealed class CXXNullPtrLiteralExpr : Expr { internal CXXNullPtrLiteralExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_CXXNullPtrLiteralExpr, CX_StmtClass.CX_StmtClass_CXXNullPtrLiteralExpr) { + Debug.Assert(NumChildren is 0); } } } diff --git a/sources/ClangSharp/Cursors/Exprs/CXXOperatorCallExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXOperatorCallExpr.cs index bb0c95a2..ba6e7d2c 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXOperatorCallExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXOperatorCallExpr.cs @@ -9,5 +9,7 @@ public sealed class CXXOperatorCallExpr : CallExpr internal CXXOperatorCallExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_CallExpr, CX_StmtClass.CX_StmtClass_CXXOperatorCallExpr) { } + + public CX_OverloadedOperatorKind Operator => Handle.OverloadedOperatorKind; } } diff --git a/sources/ClangSharp/Cursors/Exprs/CXXPseudoDestructorExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXPseudoDestructorExpr.cs index 1351ee48..e3dfdb86 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXPseudoDestructorExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXPseudoDestructorExpr.cs @@ -1,13 +1,25 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public sealed class CXXPseudoDestructorExpr : Expr { + private readonly Lazy _destroyedType; + internal CXXPseudoDestructorExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_MemberRefExpr, CX_StmtClass.CX_StmtClass_CXXPseudoDestructorExpr) { + Debug.Assert(NumChildren is 1); + _destroyedType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); } + + public Expr Base => (Expr)Children[0]; + + public Type DestroyedType => _destroyedType.Value; + + public bool IsArrow => Handle.IsArrow; } } diff --git a/sources/ClangSharp/Cursors/Exprs/CXXRewrittenBinaryOperator.cs b/sources/ClangSharp/Cursors/Exprs/CXXRewrittenBinaryOperator.cs index 1c530785..2b7a1a99 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXRewrittenBinaryOperator.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXRewrittenBinaryOperator.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp @@ -12,14 +13,26 @@ public sealed class CXXRewrittenBinaryOperator : Expr internal CXXRewrittenBinaryOperator(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedExpr, CX_StmtClass.CX_StmtClass_CXXRewrittenBinaryOperator) { + Debug.Assert(NumChildren is 1); + _lhs = new Lazy(() => TranslationUnit.GetOrCreate(Handle.LhsExpr)); _rhs = new Lazy(() => TranslationUnit.GetOrCreate(Handle.RhsExpr)); } public Expr LHS => _lhs.Value; + public bool IsAssignmentOp => false; + + public bool IsComparisonOp => true; + + public CX_BinaryOperatorKind Opcode => Operator; + public CX_BinaryOperatorKind Operator => Handle.BinaryOperatorKind; + public string OpcodeStr => Handle.BinaryOperatorKindSpelling.CString; + public Expr RHS => _rhs.Value; + + public Expr SemanticForm => (Expr)Children[0]; } } diff --git a/sources/ClangSharp/Cursors/Exprs/CXXScalarValueInitExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXScalarValueInitExpr.cs index 1696ef0a..94579d42 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXScalarValueInitExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXScalarValueInitExpr.cs @@ -1,13 +1,21 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public sealed class CXXScalarValueInitExpr : Expr { + private readonly Lazy _typeSourceInfoType; + internal CXXScalarValueInitExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedExpr, CX_StmtClass.CX_StmtClass_CXXScalarValueInitExpr) { + Debug.Assert(NumChildren is 0); + _typeSourceInfoType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); } + + public Type TypeSourceInfoType => _typeSourceInfoType.Value; } } diff --git a/sources/ClangSharp/Cursors/Exprs/CXXStdInitializerListExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXStdInitializerListExpr.cs index 7e758635..591cbfc3 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXStdInitializerListExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXStdInitializerListExpr.cs @@ -1,19 +1,17 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. -using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public sealed class CXXStdInitializerListExpr : Expr { - private readonly Lazy _subExpr; - internal CXXStdInitializerListExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedExpr, CX_StmtClass.CX_StmtClass_CXXStdInitializerListExpr) { - _subExpr = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SubExpr)); + Debug.Assert(NumChildren is 1); } - public Expr SubExpr => _subExpr.Value; + public Expr SubExpr => (Expr)Children[0]; } } diff --git a/sources/ClangSharp/Cursors/Exprs/CXXTemporaryObjectExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXTemporaryObjectExpr.cs index 067f3d15..5e9d73e9 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXTemporaryObjectExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXTemporaryObjectExpr.cs @@ -1,13 +1,19 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; using ClangSharp.Interop; namespace ClangSharp { public sealed class CXXTemporaryObjectExpr : CXXConstructExpr { + private readonly Lazy _typeSourceInfoType; + internal CXXTemporaryObjectExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_CallExpr, CX_StmtClass.CX_StmtClass_CXXTemporaryObjectExpr) { + _typeSourceInfoType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); } + + public Type TypeSourceInfoType => _typeSourceInfoType.Value; } } diff --git a/sources/ClangSharp/Cursors/Exprs/CXXThisExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXThisExpr.cs index 0e8f3238..d392d80d 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXThisExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXThisExpr.cs @@ -9,5 +9,7 @@ public sealed class CXXThisExpr : Expr internal CXXThisExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_CXXThisExpr, CX_StmtClass.CX_StmtClass_CXXThisExpr) { } + + public bool IsImplicit => Handle.IsImplicit; } } diff --git a/sources/ClangSharp/Cursors/Exprs/CXXThrowExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXThrowExpr.cs index 26e87cea..7cbf8fa9 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXThrowExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXThrowExpr.cs @@ -1,19 +1,19 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. -using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public sealed class CXXThrowExpr : Expr { - private readonly Lazy _subExpr; - internal CXXThrowExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_CXXThrowExpr, CX_StmtClass.CX_StmtClass_CXXThrowExpr) { - _subExpr = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SubExpr)); + Debug.Assert(NumChildren is 1); } - public Expr SubExpr => _subExpr.Value; + public bool IsThrownVariableInScope => Handle.IsThrownVariableInScope; + + public Expr SubExpr => (Expr)Children[0]; } } diff --git a/sources/ClangSharp/Cursors/Exprs/CXXTypeidExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXTypeidExpr.cs index b25e95c2..fa1b0e82 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXTypeidExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXTypeidExpr.cs @@ -1,13 +1,28 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; +using System.Diagnostics; +using System.Linq; using ClangSharp.Interop; namespace ClangSharp { public sealed class CXXTypeidExpr : Expr { + private readonly Lazy _typeOperand; + internal CXXTypeidExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_CXXTypeidExpr, CX_StmtClass.CX_StmtClass_CXXTypeidExpr) { + Debug.Assert(NumChildren is 0 or 1); + _typeOperand = new Lazy(() => TranslationUnit.GetOrCreate(handle.TypeOperand)); } + + public Expr ExprOperand => (Expr)Children.SingleOrDefault(); + + public bool IsPotentiallyEvaluated => Handle.IsPotentiallyEvaluated; + + public bool IsTypeOperand => NumChildren is 0; + + public Type TypeOperand => _typeOperand.Value; } } diff --git a/sources/ClangSharp/Cursors/Exprs/CXXUnresolvedConstructExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXUnresolvedConstructExpr.cs index efc4e726..b4bb0e18 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXUnresolvedConstructExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXUnresolvedConstructExpr.cs @@ -1,13 +1,29 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; +using System.Collections.Generic; +using System.Linq; using ClangSharp.Interop; namespace ClangSharp { public sealed class CXXUnresolvedConstructExpr : Expr { + private readonly Lazy> _args; + private readonly Lazy _typeAsWritten; + internal CXXUnresolvedConstructExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_CallExpr, CX_StmtClass.CX_StmtClass_CXXUnresolvedConstructExpr) { + _args = new Lazy>(() => Children.Cast().ToList()); + _typeAsWritten = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); } + + public IReadOnlyList Args => _args.Value; + + public bool IsListInitialization => Handle.IsListInitialization; + + public uint NumArgs => unchecked((uint)Handle.NumArguments); + + public Type TypeAsWritten => _typeAsWritten.Value; } } diff --git a/sources/ClangSharp/Cursors/Exprs/CXXUuidofExpr.cs b/sources/ClangSharp/Cursors/Exprs/CXXUuidofExpr.cs index 0d0fbf03..6607d9fb 100644 --- a/sources/ClangSharp/Cursors/Exprs/CXXUuidofExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CXXUuidofExpr.cs @@ -1,24 +1,30 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. using System; +using System.Diagnostics; +using System.Linq; using ClangSharp.Interop; namespace ClangSharp { public sealed class CXXUuidofExpr : Expr { - private readonly Lazy _exprOperand; private readonly Lazy _typeOperand; + private readonly Lazy _guidDecl; internal CXXUuidofExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedExpr, CX_StmtClass.CX_StmtClass_CXXUuidofExpr) { - _exprOperand = new Lazy(() => TranslationUnit.GetOrCreate(handle.SubExpr)); - _typeOperand = new Lazy(() => TranslationUnit.GetOrCreate(handle.TypeOperand)); + Debug.Assert(NumChildren is 0 or 1); + + _typeOperand = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); + _guidDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); } - public Expr ExprOperand => _exprOperand.Value; + public Expr ExprOperand => (Expr)Children.SingleOrDefault(); + + public MSGuidDecl GuidDecl => _guidDecl.Value; - public bool IsTypeOperand => Handle.IsTypeOperand; + public bool IsTypeOperand => NumChildren is 0; public Type TypeOperand => _typeOperand.Value; } diff --git a/sources/ClangSharp/Cursors/Exprs/CallExpr.cs b/sources/ClangSharp/Cursors/Exprs/CallExpr.cs index 74df9aa8..c7b6196f 100644 --- a/sources/ClangSharp/Cursors/Exprs/CallExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CallExpr.cs @@ -2,6 +2,8 @@ using System; using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; using ClangSharp.Interop; namespace ClangSharp @@ -9,9 +11,7 @@ namespace ClangSharp public class CallExpr : Expr { private readonly Lazy> _args; - private readonly Lazy _callee; private readonly Lazy _calleeDecl; - private readonly Lazy _directCallee; internal CallExpr(CXCursor handle) : this(handle, CXCursorKind.CXCursor_CallExpr, CX_StmtClass.CX_StmtClass_CallExpr) { @@ -24,30 +24,21 @@ private protected CallExpr(CXCursor handle, CXCursorKind expectedCursorKind, CX_ throw new ArgumentException(nameof(handle)); } - _args = new Lazy>(() => { - var numArgs = Handle.NumArguments; - var args = new List(numArgs); + Debug.Assert(NumChildren >= 1); - for (var index = 0; index < numArgs; index++) - { - var arg = TranslationUnit.GetOrCreate(Handle.GetArgument(unchecked((uint)index))); - args.Add(arg); - } - - return args; - }); - _callee = new Lazy(() => TranslationUnit.GetOrCreate(Handle.CalleeExpr)); + _args = new Lazy>(() => Children.Skip(1).Take((int)NumArgs).Cast().ToList()); _calleeDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); - _directCallee = new Lazy(() => TranslationUnit.GetOrCreate(Handle.DirectCallee)); } public IReadOnlyList Args => _args.Value; - public Expr Callee => _callee.Value; + public Expr Callee => (Expr)Children[0]; public Decl CalleeDecl => _calleeDecl.Value; - public FunctionDecl DirectCallee => _directCallee.Value; + public FunctionDecl DirectCallee => CalleeDecl as FunctionDecl; + + public bool IsCallToStdMove => (NumArgs == 1) && (DirectCallee is FunctionDecl FD) && FD.IsInStdNamespace && (FD.Name == "move"); public uint NumArgs => (uint)Handle.NumArguments; } diff --git a/sources/ClangSharp/Cursors/Exprs/CastExpr.cs b/sources/ClangSharp/Cursors/Exprs/CastExpr.cs index cfe5369c..4c4067a8 100644 --- a/sources/ClangSharp/Cursors/Exprs/CastExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CastExpr.cs @@ -1,15 +1,15 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. using System; +using System.Collections.Generic; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public class CastExpr : Expr { - private readonly Lazy _conversionFunction; - private readonly Lazy _subExpr; - private readonly Lazy _subExprAsWritten; + private readonly Lazy> _path; private readonly Lazy _targetUnionField; private protected CastExpr(CXCursor handle, CXCursorKind expectedCursorKind, CX_StmtClass expectedStmtClass) : base(handle, expectedCursorKind, expectedStmtClass) @@ -19,21 +19,96 @@ private protected CastExpr(CXCursor handle, CXCursorKind expectedCursorKind, CX_ throw new ArgumentException(nameof(handle)); } - _conversionFunction = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ConversionFunction)); - _subExpr = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SubExpr)); - _subExprAsWritten = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SubExprAsWritten)); + Debug.Assert(NumChildren is 1); + + _path = new Lazy>(() => { + var pathSize = Handle.NumArguments; + var path = new List(pathSize); + + for (int i = 0; i < pathSize; i++) + { + var item = TranslationUnit.GetOrCreate(Handle.GetArgument(unchecked((uint)i))); + path.Add(item); + } + + return path; + }); _targetUnionField = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TargetUnionField)); } public CX_CastKind CastKind => Handle.CastKind; - public string CastKindSpelling => Handle.CastKindSpelling; + public string CastKindName => Handle.CastKindSpelling; + + public NamedDecl ConversionFunction + { + get + { + Expr SubExpr; + + for (CastExpr E = this; E is not null; E = SubExpr as ImplicitCastExpr) + { + SubExpr = SkipImplicitTemporary(E.SubExpr); + + if (E.CastKind == CX_CastKind.CX_CK_ConstructorConversion) + { + return ((CXXConstructExpr)SubExpr).Constructor; + } + + if (E.CastKind == CX_CastKind.CX_CK_UserDefinedConversion) + { + if (SubExpr is CXXMemberCallExpr MCE) + { + return MCE.MethodDecl; + } + } + } + + return null; + } + } - public NamedDecl ConversionFunction => _conversionFunction.Value; + public bool PathEmpty => PathSize == 0; - public Expr SubExpr => _subExpr.Value; + public IReadOnlyList Path => _path.Value; - public Expr SubExprAsWritten => _subExprAsWritten.Value; + public uint PathSize => unchecked((uint)Handle.NumArguments); + + public Expr SubExpr => (Expr)Children[0]; + + public Expr SubExprAsWritten + { + get + { + Expr SubExpr; + CastExpr E = this; + + do + { + SubExpr = SkipImplicitTemporary(E.SubExpr); + + // Conversions by constructor and conversion functions have a subexpression describing the call; strip it off. + if (E.CastKind == CX_CastKind.CX_CK_ConstructorConversion) + { + SubExpr = SkipImplicitTemporary(((CXXConstructExpr)SubExpr).Args[0]); + } + else if (E.CastKind == CX_CastKind.CX_CK_UserDefinedConversion) + { + Debug.Assert((SubExpr is CXXMemberCallExpr) || (SubExpr is BlockExpr), "Unexpected SubExpr for CK_UserDefinedConversion."); + + if (SubExpr is CXXMemberCallExpr MCE) + { + SubExpr = MCE.ImplicitObjectArgument; + } + } + + // If the subexpression we're left with is an implicit cast, look + // through that, too. + } while ((E = SubExpr as ImplicitCastExpr) is not null); + + return SubExpr; + } + } public FieldDecl TargetUnionField => _targetUnionField.Value; } diff --git a/sources/ClangSharp/Cursors/Exprs/CharacterLiteral.cs b/sources/ClangSharp/Cursors/Exprs/CharacterLiteral.cs index b92aa844..002bf762 100644 --- a/sources/ClangSharp/Cursors/Exprs/CharacterLiteral.cs +++ b/sources/ClangSharp/Cursors/Exprs/CharacterLiteral.cs @@ -12,6 +12,8 @@ public sealed class CharacterLiteral : Expr internal CharacterLiteral(CXCursor handle) : base(handle, CXCursorKind.CXCursor_CharacterLiteral, CX_StmtClass.CX_StmtClass_CharacterLiteral) { + Debug.Assert(NumChildren is 0); + _valueString = new Lazy(() => { var tokens = Handle.TranslationUnit.Tokenize(Handle.SourceRange); diff --git a/sources/ClangSharp/Cursors/Exprs/ChooseExpr.cs b/sources/ClangSharp/Cursors/Exprs/ChooseExpr.cs index 02b0e737..57b175da 100644 --- a/sources/ClangSharp/Cursors/Exprs/ChooseExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/ChooseExpr.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp @@ -8,6 +9,19 @@ public sealed class ChooseExpr : Expr { internal ChooseExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedExpr, CX_StmtClass.CX_StmtClass_ChooseExpr) { + Debug.Assert(NumChildren is 3); } + + public Expr ChosenSubExpr => IsConditionDependent ? (IsConditionTrue ? LHS : RHS) : null; + + public Expr Cond => (Expr)Children[0]; + + public bool IsConditionTrue => Handle.IsConditionTrue; + + public bool IsConditionDependent => Cond.IsTypeDependent || Cond.IsValueDependent; + + public Expr LHS => (Expr)Children[1]; + + public Expr RHS => (Expr)Children[2]; } } diff --git a/sources/ClangSharp/Cursors/Exprs/CompoundLiteralExpr.cs b/sources/ClangSharp/Cursors/Exprs/CompoundLiteralExpr.cs index 4b66aabe..75dac60d 100644 --- a/sources/ClangSharp/Cursors/Exprs/CompoundLiteralExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/CompoundLiteralExpr.cs @@ -1,19 +1,25 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public sealed class CompoundLiteralExpr : Expr { - private readonly Lazy _initializer; + private readonly Lazy _typeSourceinfoType; internal CompoundLiteralExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_CompoundLiteralExpr, CX_StmtClass.CX_StmtClass_CompoundLiteralExpr) { - _initializer = new Lazy(() => TranslationUnit.GetOrCreate(Handle.InitExpr)); + Debug.Assert(NumChildren is 1); + _typeSourceinfoType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); } - public Expr Initializer => _initializer.Value; + public bool IsFileScope => Handle.IsFileScope; + + public Expr Initializer => (Expr)Children[0]; + + public Type TypeSourceInfoType => _typeSourceinfoType.Value; } } diff --git a/sources/ClangSharp/Cursors/Exprs/ConditionalOperator.cs b/sources/ClangSharp/Cursors/Exprs/ConditionalOperator.cs index 6ddf2d28..ba69e42b 100644 --- a/sources/ClangSharp/Cursors/Exprs/ConditionalOperator.cs +++ b/sources/ClangSharp/Cursors/Exprs/ConditionalOperator.cs @@ -1,23 +1,25 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. -using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public sealed class ConditionalOperator : AbstractConditionalOperator { - private readonly Lazy _lhs; - private readonly Lazy _rhs; - internal ConditionalOperator(CXCursor handle) : base(handle, CXCursorKind.CXCursor_ConditionalOperator, CX_StmtClass.CX_StmtClass_ConditionalOperator) { - _lhs = new Lazy(() => TranslationUnit.GetOrCreate(Handle.LhsExpr)); - _rhs = new Lazy(() => TranslationUnit.GetOrCreate(Handle.RhsExpr)); + Debug.Assert(NumChildren is 3); } - public Expr LHS => _lhs.Value; + public new Expr Cond => (Expr)Children[0]; + + public new Expr FalseExpr => RHS; + + public Expr LHS => (Expr)Children[1]; + + public Expr RHS => (Expr)Children[2]; - public Expr RHS => _rhs.Value; + public new Expr TrueExpr => LHS; } } diff --git a/sources/ClangSharp/Cursors/Exprs/DeclRefExpr.cs b/sources/ClangSharp/Cursors/Exprs/DeclRefExpr.cs index cbf5a383..af157a5a 100644 --- a/sources/ClangSharp/Cursors/Exprs/DeclRefExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/DeclRefExpr.cs @@ -1,6 +1,8 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. using System; +using System.Collections.Generic; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp @@ -8,6 +10,8 @@ namespace ClangSharp public sealed class DeclRefExpr : Expr { private readonly Lazy _decl; + private readonly Lazy _foundDecl; + private readonly Lazy> _templateArgs; internal DeclRefExpr(CXCursor handle) : base(handle, handle.Kind, CX_StmtClass.CX_StmtClass_DeclRefExpr) { @@ -16,9 +20,39 @@ internal DeclRefExpr(CXCursor handle) : base(handle, handle.Kind, CX_StmtClass.C throw new ArgumentException(nameof(handle)); } + Debug.Assert(NumChildren is 0); + _decl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); + _foundDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.FoundDecl)); + + _templateArgs = new Lazy>(() => { + var templateArgCount = Handle.NumTemplateArguments; + var templateArgs = new List(templateArgCount); + + for (int i = 0; i < templateArgCount; i++) + { + var templateArg = TranslationUnit.GetOrCreate(Handle.GetTemplateArgumentLoc(unchecked((uint)i))); + templateArgs.Add(templateArg); + } + + return templateArgs; + }); } public ValueDecl Decl => _decl.Value; + + public NamedDecl FoundDecl => _foundDecl.Value; + + public bool HadMultipleCandidates => Handle.HadMultipleCandidates; + + public bool HasExplicitTemplateArgs => Handle.HasExplicitTemplateArgs; + + public bool HasTemplateKeyword => Handle.HasTemplateKeyword; + + public string Name => Handle.Name.CString; + + public uint NumTemplateArgs => unchecked((uint)Handle.NumTemplateArguments); + + public IReadOnlyList TemplateArgs => _templateArgs.Value; } } diff --git a/sources/ClangSharp/Cursors/Exprs/DependentScopeDeclRefExpr.cs b/sources/ClangSharp/Cursors/Exprs/DependentScopeDeclRefExpr.cs index 026277e9..81b2fd43 100644 --- a/sources/ClangSharp/Cursors/Exprs/DependentScopeDeclRefExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/DependentScopeDeclRefExpr.cs @@ -1,13 +1,40 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; +using System.Collections.Generic; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public sealed class DependentScopeDeclRefExpr : Expr { + private readonly Lazy> _templateArgs; + internal DependentScopeDeclRefExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_DeclRefExpr, CX_StmtClass.CX_StmtClass_DependentScopeDeclRefExpr) { + Debug.Assert(NumChildren is 0); + + _templateArgs = new Lazy>(() => { + var numTemplateArgs = Handle.NumTemplateArguments; + var templateArgs = new List(numTemplateArgs); + + for (var i = 0; i < numTemplateArgs; i++) + { + var templateArg = TranslationUnit.GetOrCreate(Handle.GetTemplateArgumentLoc(unchecked((uint)i))); + templateArgs.Add(templateArg); + } + + return templateArgs; + }); } + + public string DeclName => Handle.Name.CString; + + public bool HasExplicitTemplateArgs => Handle.HasExplicitTemplateArgs; + + public bool HasTemplateKeyword => Handle.HasTemplateKeyword; + + public IReadOnlyList TemplateArgs => _templateArgs.Value; } } diff --git a/sources/ClangSharp/Cursors/Exprs/ExplicitCastExpr.cs b/sources/ClangSharp/Cursors/Exprs/ExplicitCastExpr.cs index 80988dff..83b01574 100644 --- a/sources/ClangSharp/Cursors/Exprs/ExplicitCastExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/ExplicitCastExpr.cs @@ -7,12 +7,18 @@ namespace ClangSharp { public class ExplicitCastExpr : CastExpr { + private readonly Lazy _typeAsWritten; + private protected ExplicitCastExpr(CXCursor handle, CXCursorKind expectedCursorKind, CX_StmtClass expectedStmtClass) : base(handle, expectedCursorKind, expectedStmtClass) { if ((CX_StmtClass.CX_StmtClass_LastExplicitCastExpr < handle.StmtClass) || (handle.StmtClass < CX_StmtClass.CX_StmtClass_FirstExplicitCastExpr)) { throw new ArgumentException(nameof(handle)); } + + _typeAsWritten = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); } + + public Type TypeAsWritten => _typeAsWritten.Value; } } diff --git a/sources/ClangSharp/Cursors/Exprs/Expr.cs b/sources/ClangSharp/Cursors/Exprs/Expr.cs index 503099f5..69aa8a74 100644 --- a/sources/ClangSharp/Cursors/Exprs/Expr.cs +++ b/sources/ClangSharp/Cursors/Exprs/Expr.cs @@ -7,6 +7,75 @@ namespace ClangSharp { public class Expr : ValueStmt { + private static readonly Func IgnoreImplicitCastsSingleStep = (E) => + { + if (E is ImplicitCastExpr ICE) + { + return ICE.SubExpr; + } + + if (E is FullExpr FE) + { + return FE.SubExpr; + } + + return E; + }; + + private static readonly Func IgnoreImplicitSingleStep = (E) => + { + Expr SubE = IgnoreImplicitCastsSingleStep(E); + + if (SubE != E) + { + return SubE; + } + + if (E is MaterializeTemporaryExpr MTE) + { + return MTE.SubExpr; + } + + if (E is CXXBindTemporaryExpr BTE) + { + return BTE.SubExpr; + } + + return E; + }; + + private static readonly Func IgnoreParensSingleStep = (E) => + { + if (E is ParenExpr PE) + { + return PE.SubExpr; + } + + if (E is UnaryOperator UO) + { + if (UO.Opcode == CX_UnaryOperatorKind.CX_UO_Extension) + { + return UO.SubExpr; + } + } + else if (E is GenericSelectionExpr GSE) + { + if (!GSE.IsResultDependent) + { + return GSE.ResultExpr; + } + } + else if (E is ChooseExpr CE) + { + if (!CE.IsConditionDependent) + { + return CE.ChosenSubExpr; + } + } + + return E; + }; + private readonly Lazy _type; private protected Expr(CXCursor handle, CXCursorKind expectedCursorKind, CX_StmtClass expectedStmtClass) : base(handle, expectedCursorKind, expectedStmtClass) @@ -19,6 +88,102 @@ private protected Expr(CXCursor handle, CXCursorKind expectedCursorKind, CX_Stmt _type = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Type)); } + public bool ContainsErrors => (Dependence & CX_ExprDependence.CX_ED_Error) != 0; + + public bool ContainsUnexpandedParameterPack => (Dependence & CX_ExprDependence.CX_ED_UnexpandedPack) != 0; + + public CX_ExprDependence Dependence => Handle.ExprDependence; + + public Expr IgnoreImplicit => IgnoreExprNodes(this, IgnoreImplicitSingleStep); + + public Expr IgnoreParens => IgnoreExprNodes(this, IgnoreParensSingleStep); + + public bool IsImplicitCXXThis + { + get + { + Expr E = this; + + while (true) + { + if (E is ParenExpr Paren) + { + E = Paren.SubExpr; + continue; + } + + if (E is ImplicitCastExpr ICE) + { + if ((ICE.CastKind == CX_CastKind.CX_CK_NoOp) || (ICE.CastKind == CX_CastKind.CX_CK_LValueToRValue) || (ICE.CastKind == CX_CastKind.CX_CK_DerivedToBase) || (ICE.CastKind == CX_CastKind.CX_CK_UncheckedDerivedToBase)) + { + E = ICE.SubExpr; + continue; + } + } + + if (E is UnaryOperator UnOp) + { + if (UnOp.Opcode == CX_UnaryOperatorKind.CX_UO_Extension) + { + E = UnOp.SubExpr; + continue; + } + } + + if (E is MaterializeTemporaryExpr M) + { + E = M.SubExpr; + continue; + } + + break; + } + + if (E is CXXThisExpr This) + { + return This.IsImplicit; + } + + return false; + } + } + + public bool IsInstantiationDependent => (Dependence & CX_ExprDependence.CX_ED_Instantiation) != 0; + + public bool IsTypeDependent => (Dependence & CX_ExprDependence.CX_ED_Type) != 0; + + public bool IsValueDependent => (Dependence & CX_ExprDependence.CX_ED_Value) != 0; + public Type Type => _type.Value; + + private static Expr IgnoreExprNodes(Expr E, Func Fn) + { + Expr LastE = null; + + while (E != LastE) + { + LastE = E; + E = Fn(E); + } + + return E; + } + + protected static Expr SkipImplicitTemporary(Expr E) + { + // Skip through reference binding to temporary. + if (E is MaterializeTemporaryExpr Materialize) + { + E = Materialize.SubExpr; + } + + // Skip any temporary bindings; they're implicit. + if (E is CXXBindTemporaryExpr Binder) + { + E = Binder.SubExpr; + } + + return E; + } } } diff --git a/sources/ClangSharp/Cursors/Exprs/ExprWithCleanups.cs b/sources/ClangSharp/Cursors/Exprs/ExprWithCleanups.cs index 2783478f..ad199b3f 100644 --- a/sources/ClangSharp/Cursors/Exprs/ExprWithCleanups.cs +++ b/sources/ClangSharp/Cursors/Exprs/ExprWithCleanups.cs @@ -1,13 +1,33 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; +using System.Collections.Generic; using ClangSharp.Interop; namespace ClangSharp { public sealed class ExprWithCleanups : FullExpr { + private readonly Lazy> _objects; + internal ExprWithCleanups(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedExpr, CX_StmtClass.CX_StmtClass_ExprWithCleanups) { + _objects = new Lazy>(() => { + var numObjects = Handle.NumArguments; + var objects = new List(numObjects); + + for (var i = 0; i < numObjects; i++) + { + var obj = TranslationUnit.GetOrCreate(Handle.GetArgument(unchecked((uint)i))); + objects.Add(obj); + } + + return objects; + }); } + + public uint NumObjects => unchecked((uint)Handle.NumArguments); + + public IReadOnlyList Objects => _objects.Value; } } diff --git a/sources/ClangSharp/Cursors/Exprs/FullExpr.cs b/sources/ClangSharp/Cursors/Exprs/FullExpr.cs index e28c659a..facd5d52 100644 --- a/sources/ClangSharp/Cursors/Exprs/FullExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/FullExpr.cs @@ -1,14 +1,13 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public class FullExpr : Expr { - private readonly Lazy _subExpr; - private protected FullExpr(CXCursor handle, CXCursorKind expectedCursorKind, CX_StmtClass expectedStmtClass) : base(handle, expectedCursorKind, expectedStmtClass) { if ((CX_StmtClass.CX_StmtClass_LastFullExpr < handle.StmtClass) || (handle.StmtClass < CX_StmtClass.CX_StmtClass_FirstFullExpr)) @@ -16,9 +15,9 @@ private protected FullExpr(CXCursor handle, CXCursorKind expectedCursorKind, CX_ throw new ArgumentException(nameof(handle)); } - _subExpr = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SubExpr)); + Debug.Assert(NumChildren is 1); } - public Expr SubExpr => _subExpr.Value; + public Expr SubExpr => (Expr)Children[0]; } } diff --git a/sources/ClangSharp/Cursors/Exprs/FunctionParmPackExpr.cs b/sources/ClangSharp/Cursors/Exprs/FunctionParmPackExpr.cs index a469c832..2720d079 100644 --- a/sources/ClangSharp/Cursors/Exprs/FunctionParmPackExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/FunctionParmPackExpr.cs @@ -1,13 +1,40 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; +using System.Collections.Generic; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public sealed class FunctionParmPackExpr : Expr { + private readonly Lazy> _expansions; + private readonly Lazy _parameterPack; + internal FunctionParmPackExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_DeclRefExpr, CX_StmtClass.CX_StmtClass_FunctionParmPackExpr) { + Debug.Assert(NumChildren is 0); + + _expansions = new Lazy>(() => { + var numExpansions = Handle.NumDecls; + var expansions = new List(numExpansions); + + for (var i = 0; i < numExpansions; i++) + { + var expansion = TranslationUnit.GetOrCreate(Handle.GetDecl(unchecked((uint)i))); + expansions.Add(expansion); + } + + return expansions; + }); + _parameterPack = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); } + + public IReadOnlyList Expansions => _expansions.Value; + + public uint NumExpansions => unchecked((uint)Handle.NumDecls); + + public VarDecl ParameterPack => _parameterPack.Value; } } diff --git a/sources/ClangSharp/Cursors/Exprs/GenericSelectionExpr.cs b/sources/ClangSharp/Cursors/Exprs/GenericSelectionExpr.cs index 78a04a3e..e29ec6d2 100644 --- a/sources/ClangSharp/Cursors/Exprs/GenericSelectionExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/GenericSelectionExpr.cs @@ -1,13 +1,31 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; +using System.Collections.Generic; +using System.Linq; using ClangSharp.Interop; namespace ClangSharp { public sealed class GenericSelectionExpr : Expr { + private readonly Lazy> _assocExprs; + internal GenericSelectionExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_GenericSelectionExpr, CX_StmtClass.CX_StmtClass_GenericSelectionExpr) { + _assocExprs = new Lazy>(() => Children.Skip(1).Take((int)NumAssocs).Cast().ToList()); } + + public IReadOnlyList AssocExprs => _assocExprs.Value; + + public Expr ControllingExpr => (Expr)Children[0]; + + public bool IsResultDependent => Handle.IsResultDependent; + + public uint NumAssocs => unchecked((uint)Handle.NumAssocs); + + public Expr ResultExpr => IsResultDependent ? null : (Expr)Children[(int)ResultIndex]; + + public uint ResultIndex => unchecked((uint)Handle.ResultIndex); } } diff --git a/sources/ClangSharp/Cursors/Exprs/ImplicitCastExpr.cs b/sources/ClangSharp/Cursors/Exprs/ImplicitCastExpr.cs index 6583019d..3bb4008c 100644 --- a/sources/ClangSharp/Cursors/Exprs/ImplicitCastExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/ImplicitCastExpr.cs @@ -9,5 +9,7 @@ public sealed class ImplicitCastExpr : CastExpr internal ImplicitCastExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedExpr, CX_StmtClass.CX_StmtClass_ImplicitCastExpr) { } + + public bool IsPartOfExplicitCast => !Handle.IsImplicit; } } diff --git a/sources/ClangSharp/Cursors/Exprs/InitListExpr.cs b/sources/ClangSharp/Cursors/Exprs/InitListExpr.cs index a021f533..1098b739 100644 --- a/sources/ClangSharp/Cursors/Exprs/InitListExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/InitListExpr.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; +using System.Linq; using ClangSharp.Interop; namespace ClangSharp @@ -16,20 +17,21 @@ internal InitListExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_Init { _arrayFiller = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SubExpr)); _initializedFieldInUnion = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); - _inits = new Lazy>(() => { - var initCount = Handle.NumExprs; - var inits = new List(initCount); - - for (int i = 0; i < initCount; i++) - { - var init = TranslationUnit.GetOrCreate(Handle.GetExpr(unchecked((uint)i))); - inits.Add(init); - } - - return inits; - }); + _inits = new Lazy>(() => Children.Cast().ToList()); } + public Expr ArrayFiller => _arrayFiller.Value; + + public bool HasArrayFiller => ArrayFiller is not null; + + public FieldDecl InitializedFieldInUnion => _initializedFieldInUnion.Value; + public IReadOnlyList Inits => _inits.Value; + + public bool IsExplicit => !Handle.IsImplicit; + + public bool IsTransparent => Handle.IsTransparent; + + public uint NumInits => NumChildren; } } diff --git a/sources/ClangSharp/Cursors/Exprs/MaterializeTemporaryExpr.cs b/sources/ClangSharp/Cursors/Exprs/MaterializeTemporaryExpr.cs index e50a4f79..28248f42 100644 --- a/sources/ClangSharp/Cursors/Exprs/MaterializeTemporaryExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/MaterializeTemporaryExpr.cs @@ -1,13 +1,23 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; using ClangSharp.Interop; namespace ClangSharp { public sealed class MaterializeTemporaryExpr : Expr { + private readonly Lazy _lifetimeExtendedTemporaryDecl; + internal MaterializeTemporaryExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedExpr, CX_StmtClass.CX_StmtClass_MaterializeTemporaryExpr) { + _lifetimeExtendedTemporaryDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); } + + public ValueDecl ExtendingDecl => LifetimeExtendedTemporaryDecl?.ExtendingDecl; + + public LifetimeExtendedTemporaryDecl LifetimeExtendedTemporaryDecl => _lifetimeExtendedTemporaryDecl.Value; + + public Expr SubExpr => (Expr)Children[0]; } } diff --git a/sources/ClangSharp/Cursors/Exprs/MatrixSubscriptExpr.cs b/sources/ClangSharp/Cursors/Exprs/MatrixSubscriptExpr.cs index 40836c68..089b1401 100644 --- a/sources/ClangSharp/Cursors/Exprs/MatrixSubscriptExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/MatrixSubscriptExpr.cs @@ -1,29 +1,23 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. -using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public sealed class MatrixSubscriptExpr : Expr { - private readonly Lazy _base; - private readonly Lazy _rowIdx; - private readonly Lazy _columnIdx; - internal MatrixSubscriptExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedExpr, CX_StmtClass.CX_StmtClass_MatrixSubscriptExpr) { - _base = new Lazy(() => TranslationUnit.GetOrCreate(handle.BaseExpr)); - _rowIdx = new Lazy(() => TranslationUnit.GetOrCreate(handle.RowIdxExpr)); - _columnIdx = new Lazy(() => TranslationUnit.GetOrCreate(handle.ColumnIdxExpr)); + Debug.Assert(NumChildren is 3); } - public Expr Base => _base.Value; + public Expr Base => (Expr)Children[0]; - public Expr ColumnIdx => _columnIdx.Value; + public Expr ColumnIdx => IsIncomplete ? null : (Expr)Children[2]; public bool IsIncomplete => Handle.IsIncomplete; - public Expr RowIdx => _rowIdx.Value; + public Expr RowIdx => (Expr)Children[1]; } } diff --git a/sources/ClangSharp/Cursors/Exprs/MemberExpr.cs b/sources/ClangSharp/Cursors/Exprs/MemberExpr.cs index 2a63a87f..14c8766e 100644 --- a/sources/ClangSharp/Cursors/Exprs/MemberExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/MemberExpr.cs @@ -1,25 +1,54 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. using System; +using System.Collections.Generic; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public sealed class MemberExpr : Expr { - private readonly Lazy _base; private readonly Lazy _memberDecl; + private readonly Lazy> _templateArgs; internal MemberExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_MemberRefExpr, CX_StmtClass.CX_StmtClass_MemberExpr) { - _base = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SubExpr)); + Debug.Assert(NumChildren is 1); + _memberDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); + _templateArgs = new Lazy>(() => { + var templateArgCount = Handle.NumTemplateArguments; + var templateArgs = new List(templateArgCount); + + for (int i = 0; i < templateArgCount; i++) + { + var templateArg = TranslationUnit.GetOrCreate(Handle.GetTemplateArgumentLoc(unchecked((uint)i))); + templateArgs.Add(templateArg); + } + + return templateArgs; + }); } - public Expr Base => _base.Value; + public Expr Base => (Expr)Children[0]; + + public bool HadMultipleCandidates => Handle.HadMultipleCandidates; + + public bool HasExplicitTemplateArg => Handle.HasExplicitTemplateArgs; - public bool IsImplicitAccess => Handle.IsImplicitAccess; + public bool HasTemplateKeyword => Handle.HasTemplateKeyword; + + public bool IsArrow => Handle.IsArrow; + + public bool IsImplicitAccess => Handle.IsImplicit; public ValueDecl MemberDecl => _memberDecl.Value; + + public string MemberName => Handle.Name.CString; + + public uint NumTemplateArgs => unchecked((uint)Handle.NumTemplateArguments); + + public IReadOnlyList TemplateArgs => _templateArgs.Value; } } diff --git a/sources/ClangSharp/Cursors/Exprs/ObjCArrayLiteral.cs b/sources/ClangSharp/Cursors/Exprs/ObjCArrayLiteral.cs index 49780453..77fcd6f8 100644 --- a/sources/ClangSharp/Cursors/Exprs/ObjCArrayLiteral.cs +++ b/sources/ClangSharp/Cursors/Exprs/ObjCArrayLiteral.cs @@ -1,13 +1,27 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; +using System.Collections.Generic; +using System.Linq; using ClangSharp.Interop; namespace ClangSharp { public sealed class ObjCArrayLiteral : Expr { + private readonly Lazy _arrayWithObjectsMethod; + private readonly Lazy> _elements; + internal ObjCArrayLiteral(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedExpr, CX_StmtClass.CX_StmtClass_ObjCArrayLiteral) { + _arrayWithObjectsMethod = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); + _elements = new Lazy>(() => Children.Cast().ToList()); } + + public ObjCMethodDecl ArrayWithObjectsMethod => _arrayWithObjectsMethod.Value; + + public IReadOnlyList Elements => _elements.Value; + + public uint NumElements => NumChildren; } } diff --git a/sources/ClangSharp/Cursors/Exprs/ObjCBoolLiteralExpr.cs b/sources/ClangSharp/Cursors/Exprs/ObjCBoolLiteralExpr.cs index 4f23c497..ce544387 100644 --- a/sources/ClangSharp/Cursors/Exprs/ObjCBoolLiteralExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/ObjCBoolLiteralExpr.cs @@ -9,5 +9,7 @@ public sealed class ObjCBoolLiteralExpr : Expr internal ObjCBoolLiteralExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_ObjCBoolLiteralExpr, CX_StmtClass.CX_StmtClass_ObjCBoolLiteralExpr) { } + + public bool Value => Handle.BoolLiteralValue; } } diff --git a/sources/ClangSharp/Cursors/Exprs/ObjCBoxedExpr.cs b/sources/ClangSharp/Cursors/Exprs/ObjCBoxedExpr.cs index becb62a6..93c1fb7a 100644 --- a/sources/ClangSharp/Cursors/Exprs/ObjCBoxedExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/ObjCBoxedExpr.cs @@ -1,13 +1,23 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public sealed class ObjCBoxedExpr : Expr { + private readonly Lazy _boxingMethod; + internal ObjCBoxedExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedExpr, CX_StmtClass.CX_StmtClass_ObjCBoxedExpr) { + Debug.Assert(NumChildren is 1); + _boxingMethod = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); } + + public ObjCMethodDecl BoxingMethod => _boxingMethod.Value; + + public Expr SubExpr => (Expr)Children[0]; } } diff --git a/sources/ClangSharp/Cursors/Exprs/ObjCBridgedCastExpr.cs b/sources/ClangSharp/Cursors/Exprs/ObjCBridgedCastExpr.cs index 673fd6d2..20dcb182 100644 --- a/sources/ClangSharp/Cursors/Exprs/ObjCBridgedCastExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/ObjCBridgedCastExpr.cs @@ -9,5 +9,7 @@ public sealed class ObjCBridgedCastExpr : ExplicitCastExpr internal ObjCBridgedCastExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_ObjCBridgedCastExpr, CX_StmtClass.CX_StmtClass_ObjCBridgedCastExpr) { } + + public string BridgeKindName => Handle.Name.CString; } } diff --git a/sources/ClangSharp/Cursors/Exprs/ObjCDictionaryLiteral.cs b/sources/ClangSharp/Cursors/Exprs/ObjCDictionaryLiteral.cs index 841cf48d..f6a48db7 100644 --- a/sources/ClangSharp/Cursors/Exprs/ObjCDictionaryLiteral.cs +++ b/sources/ClangSharp/Cursors/Exprs/ObjCDictionaryLiteral.cs @@ -1,13 +1,39 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; +using System.Collections.Generic; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public sealed class ObjCDictionaryLiteral : Expr { + private readonly Lazy _dictWithObjectsMethod; + private readonly Lazy> _keyValueElements; + internal ObjCDictionaryLiteral(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedExpr, CX_StmtClass.CX_StmtClass_ObjCDictionaryLiteral) { + Debug.Assert((NumChildren % 2) == 0); + _dictWithObjectsMethod = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); + + _keyValueElements = new Lazy>(() => { + var numChildren = Handle.NumChildren; + var keyValueElements = new List<(Expr Key, Expr Value)>(numChildren / 2); + + for (var i = 0; i < numChildren; i += 2) + { + keyValueElements.Add(((Expr)Children[i + 0], (Expr)Children[i + 1])); + } + + return keyValueElements; + }); } + + public ObjCMethodDecl DictWithObjectsMethod => _dictWithObjectsMethod.Value; + + public IReadOnlyList<(Expr Key, Expr Value)> KeyValueElements => _keyValueElements.Value; + + public uint NumElements => NumChildren / 2; } } diff --git a/sources/ClangSharp/Cursors/Exprs/ObjCEncodeExpr.cs b/sources/ClangSharp/Cursors/Exprs/ObjCEncodeExpr.cs index 1905a419..dc0bbc01 100644 --- a/sources/ClangSharp/Cursors/Exprs/ObjCEncodeExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/ObjCEncodeExpr.cs @@ -1,13 +1,21 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public sealed class ObjCEncodeExpr : Expr { + private readonly Lazy _encodedType; + internal ObjCEncodeExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_ObjCEncodeExpr, CX_StmtClass.CX_StmtClass_ObjCEncodeExpr) { + Debug.Assert(NumChildren is 0); + _encodedType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); } + + public Type EncodedType => _encodedType.Value; } } diff --git a/sources/ClangSharp/Cursors/Exprs/ObjCIndirectCopyRestoreExpr.cs b/sources/ClangSharp/Cursors/Exprs/ObjCIndirectCopyRestoreExpr.cs index 3c322d0e..2b919ae9 100644 --- a/sources/ClangSharp/Cursors/Exprs/ObjCIndirectCopyRestoreExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/ObjCIndirectCopyRestoreExpr.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp @@ -8,6 +9,11 @@ public sealed class ObjCIndirectCopyRestoreExpr : Expr { internal ObjCIndirectCopyRestoreExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedExpr, CX_StmtClass.CX_StmtClass_ObjCIndirectCopyRestoreExpr) { + Debug.Assert(NumChildren is 1); } + + public bool ShouldCopy => Handle.ShouldCopy; + + public Expr SubExpr => (Expr)Children[0]; } } diff --git a/sources/ClangSharp/Cursors/Exprs/ObjCIsaExpr.cs b/sources/ClangSharp/Cursors/Exprs/ObjCIsaExpr.cs index ce34e592..508cb690 100644 --- a/sources/ClangSharp/Cursors/Exprs/ObjCIsaExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/ObjCIsaExpr.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp @@ -8,6 +9,11 @@ public sealed class ObjCIsaExpr : Expr { internal ObjCIsaExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_MemberRefExpr, CX_StmtClass.CX_StmtClass_ObjCIsaExpr) { + Debug.Assert(NumChildren is 1); } + + public Expr Base => (Expr)Children[0]; + + public bool IsArrow => Handle.IsArrow; } } diff --git a/sources/ClangSharp/Cursors/Exprs/ObjCIvarRefExpr.cs b/sources/ClangSharp/Cursors/Exprs/ObjCIvarRefExpr.cs index 250b99b7..7d716031 100644 --- a/sources/ClangSharp/Cursors/Exprs/ObjCIvarRefExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/ObjCIvarRefExpr.cs @@ -1,13 +1,25 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public sealed class ObjCIvarRefExpr : Expr { + private readonly Lazy _decl; + internal ObjCIvarRefExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_MemberRefExpr, CX_StmtClass.CX_StmtClass_ObjCIvarRefExpr) { + Debug.Assert(NumChildren is 1); + _decl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); } + + public Expr Base => (Expr)Children[0]; + + public ObjCIvarDecl Decl => _decl.Value; + + public bool IsArrow => Handle.IsArrow; } } diff --git a/sources/ClangSharp/Cursors/Exprs/ObjCMessageExpr.cs b/sources/ClangSharp/Cursors/Exprs/ObjCMessageExpr.cs index 9d630daf..dae607e5 100644 --- a/sources/ClangSharp/Cursors/Exprs/ObjCMessageExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/ObjCMessageExpr.cs @@ -1,13 +1,56 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; +using System.Collections.Generic; using ClangSharp.Interop; namespace ClangSharp { public sealed class ObjCMessageExpr : Expr { + private readonly Lazy> _args; + private readonly Lazy _classReceiver; + private readonly Lazy _instanceReceiver; + private readonly Lazy _methodDecl; + private readonly Lazy _receiverType; + private readonly Lazy _superType; + internal ObjCMessageExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_ObjCMessageExpr, CX_StmtClass.CX_StmtClass_ObjCMessageExpr) { + _args = new Lazy>(() => { + var numArgs = Handle.NumArguments; + var args = new List(numArgs); + + for (int i = 0; i < numArgs; i++) + { + var arg = TranslationUnit.GetOrCreate(Handle.GetArgument(unchecked((uint)i))); + args.Add(arg); + } + + return args; + }); + + _classReceiver = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); + _instanceReceiver = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetExpr(0))); + _methodDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); + _receiverType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ReceiverType)); + _superType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ThisObjectType)); } + + public IReadOnlyList Args => _args.Value; + + public Type ClassReceiver => _classReceiver.Value; + + public bool IsImplicit => Handle.IsImplicit; + + public Expr InstanceReceiver => _instanceReceiver.Value; + + public Type ReceiverType => _receiverType.Value; + + public Type SuperType => _superType.Value; + + public ObjCMethodDecl MethodDecl => _methodDecl.Value; + + public uint NumArgs => unchecked((uint)Handle.NumArguments); } } diff --git a/sources/ClangSharp/Cursors/Exprs/ObjCPropertyRefExpr.cs b/sources/ClangSharp/Cursors/Exprs/ObjCPropertyRefExpr.cs index 42064258..723b9521 100644 --- a/sources/ClangSharp/Cursors/Exprs/ObjCPropertyRefExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/ObjCPropertyRefExpr.cs @@ -1,13 +1,44 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; using ClangSharp.Interop; namespace ClangSharp { public sealed class ObjCPropertyRefExpr : Expr { + private readonly Lazy _base; + private readonly Lazy _classReceiver; + private readonly Lazy _explicitProperty; + private readonly Lazy _implicitPropertyGetter; + private readonly Lazy _implicitPropertySetter; + private readonly Lazy _superReceiverType; + internal ObjCPropertyRefExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_MemberRefExpr, CX_StmtClass.CX_StmtClass_ObjCPropertyRefExpr) { + _base = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetExpr(0))); + _classReceiver = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetDecl(0))); + _explicitProperty = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetDecl(1))); + _implicitPropertyGetter = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetDecl(2))); + _implicitPropertySetter = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetDecl(3))); + _superReceiverType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); } + + + public Expr Base => _base.Value; + + public ObjCInterfaceDecl ClassReceiver => _classReceiver.Value; + + public ObjCPropertyDecl ExplicitProperty => _explicitProperty.Value; + + public bool IsExplicitProperty => !IsImplicitProperty; + + public bool IsImplicitProperty => Handle.IsImplicit; + + public ObjCMethodDecl ImplicitPropertyGetter => _implicitPropertyGetter.Value; + + public ObjCMethodDecl ImplicitPropertySetter => _implicitPropertySetter.Value; + + public Type SuperReceiverType => _superReceiverType.Value; } } diff --git a/sources/ClangSharp/Cursors/Exprs/ObjCProtocolExpr.cs b/sources/ClangSharp/Cursors/Exprs/ObjCProtocolExpr.cs index dc67fc4d..95bf738e 100644 --- a/sources/ClangSharp/Cursors/Exprs/ObjCProtocolExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/ObjCProtocolExpr.cs @@ -1,13 +1,21 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public sealed class ObjCProtocolExpr : Expr { + private readonly Lazy _protocol; + internal ObjCProtocolExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_ObjCProtocolExpr, CX_StmtClass.CX_StmtClass_ObjCProtocolExpr) { + Debug.Assert(NumChildren is 0); + _protocol = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); } + + public ObjCProtocolDecl Protocol => _protocol.Value; } } diff --git a/sources/ClangSharp/Cursors/Exprs/ObjCStringLiteral.cs b/sources/ClangSharp/Cursors/Exprs/ObjCStringLiteral.cs index 71efde71..2e151e0e 100644 --- a/sources/ClangSharp/Cursors/Exprs/ObjCStringLiteral.cs +++ b/sources/ClangSharp/Cursors/Exprs/ObjCStringLiteral.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp @@ -8,6 +9,9 @@ public sealed class ObjCStringLiteral : Expr { internal ObjCStringLiteral(CXCursor handle) : base(handle, CXCursorKind.CXCursor_ObjCStringLiteral, CX_StmtClass.CX_StmtClass_ObjCStringLiteral) { + Debug.Assert(NumChildren is 1); } + + public StringLiteral String => (StringLiteral)Children[0]; } } diff --git a/sources/ClangSharp/Cursors/Exprs/ObjCSubscriptRefExpr.cs b/sources/ClangSharp/Cursors/Exprs/ObjCSubscriptRefExpr.cs index a5cac9d0..bf730c5d 100644 --- a/sources/ClangSharp/Cursors/Exprs/ObjCSubscriptRefExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/ObjCSubscriptRefExpr.cs @@ -1,13 +1,27 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public sealed class ObjCSubscriptRefExpr : Expr { + private readonly Lazy _atIndexMethodDecl; + internal ObjCSubscriptRefExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedExpr, CX_StmtClass.CX_StmtClass_ObjCSubscriptRefExpr) { + Debug.Assert(NumChildren is 2); + _atIndexMethodDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); } + + public ObjCMethodDecl AtIndexMethodDecl => _atIndexMethodDecl.Value; + + public Expr BaseExpr => (Expr)Children[0]; + + public Expr KeyExpr => (Expr)Children[1]; + + public bool IsArraySubscriptRefExpr => KeyExpr.Type.IsIntegralOrEnumerationType; } } diff --git a/sources/ClangSharp/Cursors/Exprs/OffsetOfExpr.cs b/sources/ClangSharp/Cursors/Exprs/OffsetOfExpr.cs index f36251db..16540d4c 100644 --- a/sources/ClangSharp/Cursors/Exprs/OffsetOfExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/OffsetOfExpr.cs @@ -1,13 +1,27 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; +using System.Collections.Generic; +using System.Linq; using ClangSharp.Interop; namespace ClangSharp { public sealed class OffsetOfExpr : Expr { + private readonly Lazy> _indexExprs; + private readonly Lazy _typeSourceInfoType; + internal OffsetOfExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedExpr, CX_StmtClass.CX_StmtClass_OffsetOfExpr) { + _indexExprs = new Lazy>(() => Children.Cast().ToList()); + _typeSourceInfoType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); } + + public IReadOnlyList IndexExprs => _indexExprs.Value; + + public uint NumExpressions => NumChildren; + + public Type TypeSourceInfoType => _typeSourceInfoType.Value; } } diff --git a/sources/ClangSharp/Cursors/Exprs/OverloadExpr.cs b/sources/ClangSharp/Cursors/Exprs/OverloadExpr.cs index a68509c9..d80086b4 100644 --- a/sources/ClangSharp/Cursors/Exprs/OverloadExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/OverloadExpr.cs @@ -1,18 +1,67 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. using System; +using System.Collections.Generic; using ClangSharp.Interop; namespace ClangSharp { public class OverloadExpr : Expr { + private readonly Lazy> _decls; + private readonly Lazy _namingClass; + private readonly Lazy> _templateArgs; + private protected OverloadExpr(CXCursor handle, CXCursorKind expectedCursorKind, CX_StmtClass expectedStmtClass) : base(handle, expectedCursorKind, expectedStmtClass) { if ((CX_StmtClass.CX_StmtClass_LastOverloadExpr < handle.StmtClass) || (handle.StmtClass < CX_StmtClass.CX_StmtClass_FirstOverloadExpr)) { throw new ArgumentException(nameof(handle)); } + + _decls = new Lazy>(() => { + var numDecls = Handle.NumDecls; + var decls = new List(numDecls); + + for (int i = 0; i < numDecls; i++) + { + var decl = TranslationUnit.GetOrCreate(Handle.GetDecl(unchecked((uint)i))); + decls.Add(decl); + } + + return decls; + }); + + _namingClass = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); + + _templateArgs = new Lazy>(() => { + var templateArgCount = Handle.NumTemplateArguments; + var templateArgs = new List(templateArgCount); + + for (int i = 0; i < templateArgCount; i++) + { + var templateArg = TranslationUnit.GetOrCreate(Handle.GetTemplateArgumentLoc(unchecked((uint)i))); + templateArgs.Add(templateArg); + } + + return templateArgs; + }); } + + public IReadOnlyList Decls => _decls.Value; + + public bool HasExplicitTemplateArgs => Handle.HasExplicitTemplateArgs; + + public bool HasTemplateKeyword => Handle.HasTemplateKeyword; + + public CXXRecordDecl NamingClass => _namingClass.Value; + + public string Name => Handle.Name.CString; + + public uint NumDecls => unchecked((uint)Handle.NumDecls); + + public uint NumTemplateArgs => unchecked((uint)Handle.NumTemplateArguments); + + public IReadOnlyList TemplateArgs => _templateArgs.Value; } } diff --git a/sources/ClangSharp/Cursors/Exprs/PackExpansionExpr.cs b/sources/ClangSharp/Cursors/Exprs/PackExpansionExpr.cs index 99e80a28..8e2f95c2 100644 --- a/sources/ClangSharp/Cursors/Exprs/PackExpansionExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/PackExpansionExpr.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp @@ -8,6 +9,9 @@ public sealed class PackExpansionExpr : Expr { internal PackExpansionExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_PackExpansionExpr, CX_StmtClass.CX_StmtClass_PackExpansionExpr) { + Debug.Assert(NumChildren is 1); } + + public Expr Pattern => (Expr)Children[0]; } } diff --git a/sources/ClangSharp/Cursors/Exprs/ParenExpr.cs b/sources/ClangSharp/Cursors/Exprs/ParenExpr.cs index 3914423b..939c57a1 100644 --- a/sources/ClangSharp/Cursors/Exprs/ParenExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/ParenExpr.cs @@ -1,19 +1,17 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. -using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public sealed class ParenExpr : Expr { - private readonly Lazy _subExpr; - internal ParenExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_ParenExpr, CX_StmtClass.CX_StmtClass_ParenExpr) { - _subExpr = new Lazy(() => TranslationUnit.GetOrCreate(handle.SubExpr)); + Debug.Assert(NumChildren is 1); } - public Expr SubExpr => _subExpr.Value; + public Expr SubExpr => (Expr)Children[0]; } } diff --git a/sources/ClangSharp/Cursors/Exprs/ParenListExpr.cs b/sources/ClangSharp/Cursors/Exprs/ParenListExpr.cs index 3e254d9a..8317dd4b 100644 --- a/sources/ClangSharp/Cursors/Exprs/ParenListExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/ParenListExpr.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; +using System.Linq; using ClangSharp.Interop; namespace ClangSharp @@ -12,20 +13,11 @@ public sealed class ParenListExpr : Expr internal ParenListExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedExpr, CX_StmtClass.CX_StmtClass_ParenListExpr) { - _exprs = new Lazy>(() => { - var exprCount = Handle.NumExprs; - var exprs = new List(exprCount); - - for (int i = 0; i < exprCount; i++) - { - var expr = TranslationUnit.GetOrCreate(Handle.GetExpr(unchecked((uint)i))); - exprs.Add(expr); - } - - return exprs; - }); + _exprs = new Lazy>(() => Children.Cast().ToList()); } public IReadOnlyList Exprs => _exprs.Value; + + public uint NumExprs => NumChildren; } } diff --git a/sources/ClangSharp/Cursors/Exprs/PredefinedExpr.cs b/sources/ClangSharp/Cursors/Exprs/PredefinedExpr.cs index b7b1ba8b..0c13a96d 100644 --- a/sources/ClangSharp/Cursors/Exprs/PredefinedExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/PredefinedExpr.cs @@ -1,5 +1,7 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System.Diagnostics; +using System.Linq; using ClangSharp.Interop; namespace ClangSharp @@ -8,6 +10,9 @@ public sealed class PredefinedExpr : Expr { internal PredefinedExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedExpr, CX_StmtClass.CX_StmtClass_PredefinedExpr) { + Debug.Assert(NumChildren is 0 or 1); } + + public StringLiteral FunctionName => (StringLiteral)Children.SingleOrDefault(); } } diff --git a/sources/ClangSharp/Cursors/Exprs/PseudoObjectExpr.cs b/sources/ClangSharp/Cursors/Exprs/PseudoObjectExpr.cs index a5e84496..a134e92f 100644 --- a/sources/ClangSharp/Cursors/Exprs/PseudoObjectExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/PseudoObjectExpr.cs @@ -1,13 +1,31 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; using ClangSharp.Interop; namespace ClangSharp { public sealed class PseudoObjectExpr : Expr { + private readonly Lazy> _semantics; + internal PseudoObjectExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedExpr, CX_StmtClass.CX_StmtClass_PseudoObjectExpr) { + Debug.Assert(NumChildren >= 1); + _semantics = new Lazy>(() => Children.Skip(1).Cast().ToList()); } + + public uint NumSemanticExprs => NumChildren - 1; + + public Expr ResultExpr => (ResultExprIndex == 0) ? null : (Expr)Children[unchecked((int)ResultExprIndex)]; + + public uint ResultExprIndex => unchecked((uint)Handle.ResultIndex); + + public IReadOnlyList Semantics => _semantics.Value; + + public Expr SyntacticForm => (Expr)Children[0]; } } diff --git a/sources/ClangSharp/Cursors/Exprs/RecoveryExpr.cs b/sources/ClangSharp/Cursors/Exprs/RecoveryExpr.cs index d7fa9660..56e67e70 100644 --- a/sources/ClangSharp/Cursors/Exprs/RecoveryExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/RecoveryExpr.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; +using System.Linq; using ClangSharp.Interop; namespace ClangSharp @@ -12,18 +13,7 @@ public sealed class RecoveryExpr : Expr internal RecoveryExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedExpr, CX_StmtClass.CX_StmtClass_RecoveryExpr) { - _subExpressions = new Lazy>(() => { - var numExprs = Handle.NumExprs; - var exprs = new List(numExprs); - - for (var index = 0; index < numExprs; index++) - { - var expr = TranslationUnit.GetOrCreate(Handle.GetExpr(unchecked((uint)index))); - exprs.Add(expr); - } - - return exprs; - }); + _subExpressions = new Lazy>(() => Children.Cast().ToList()); } public IReadOnlyList SubExpressions => _subExpressions.Value; diff --git a/sources/ClangSharp/Cursors/Exprs/SizeOfPackExpr.cs b/sources/ClangSharp/Cursors/Exprs/SizeOfPackExpr.cs index 4527eb3a..077ccc86 100644 --- a/sources/ClangSharp/Cursors/Exprs/SizeOfPackExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/SizeOfPackExpr.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. using System; +using System.Collections.Generic; using ClangSharp.Interop; namespace ClangSharp @@ -8,12 +9,31 @@ namespace ClangSharp public sealed class SizeOfPackExpr : Expr { private readonly Lazy _pack; + private readonly Lazy> _partialArguments; internal SizeOfPackExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_SizeOfPackExpr, CX_StmtClass.CX_StmtClass_SizeOfPackExpr) { _pack = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); + _partialArguments = new Lazy>(() => { + var templateArgCount = Handle.NumTemplateArguments; + var templateArgs = new List(templateArgCount); + + for (int i = 0; i < templateArgCount; i++) + { + var templateArg = TranslationUnit.GetOrCreate(Handle.GetTemplateArgument(unchecked((uint)i))); + templateArgs.Add(templateArg); + } + + return templateArgs; + }); } public NamedDecl Pack => _pack.Value; + + public uint PackLength => unchecked((uint)Handle.PackLength); + + public bool IsPartiallySubstituted => Handle.IsPartiallySubstituted; + + public IReadOnlyList PartialArguments => _partialArguments.Value; } } diff --git a/sources/ClangSharp/Cursors/Exprs/StmtExpr.cs b/sources/ClangSharp/Cursors/Exprs/StmtExpr.cs index 567cff40..72a77275 100644 --- a/sources/ClangSharp/Cursors/Exprs/StmtExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/StmtExpr.cs @@ -1,19 +1,17 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. -using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public sealed class StmtExpr : Expr { - private readonly Lazy _subStmt; - internal StmtExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_StmtExpr, CX_StmtClass.CX_StmtClass_StmtExpr) { - _subStmt = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SubStmt)); + Debug.Assert(NumChildren is 1); } - public CompoundStmt SubStmt => _subStmt.Value; + public CompoundStmt SubStmt => (CompoundStmt)Children[0]; } } diff --git a/sources/ClangSharp/Cursors/Exprs/SubstNonTypeTemplateParmExpr.cs b/sources/ClangSharp/Cursors/Exprs/SubstNonTypeTemplateParmExpr.cs index d420979f..bbf9a69d 100644 --- a/sources/ClangSharp/Cursors/Exprs/SubstNonTypeTemplateParmExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/SubstNonTypeTemplateParmExpr.cs @@ -1,13 +1,23 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public sealed class SubstNonTypeTemplateParmExpr : Expr { + private readonly Lazy _parameter; + internal SubstNonTypeTemplateParmExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_DeclRefExpr, CX_StmtClass.CX_StmtClass_SubstNonTypeTemplateParmExpr) { + Debug.Assert(NumChildren is 1); + _parameter = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); } + + public NonTypeTemplateParmDecl Parameter => _parameter.Value; + + public Expr Replacement => (Expr)Children[0]; } } diff --git a/sources/ClangSharp/Cursors/Exprs/SubstNonTypeTemplateParmPackExpr.cs b/sources/ClangSharp/Cursors/Exprs/SubstNonTypeTemplateParmPackExpr.cs index b6faa9ed..1c3b8e74 100644 --- a/sources/ClangSharp/Cursors/Exprs/SubstNonTypeTemplateParmPackExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/SubstNonTypeTemplateParmPackExpr.cs @@ -1,13 +1,26 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System.Diagnostics; +using System; using ClangSharp.Interop; namespace ClangSharp { public sealed class SubstNonTypeTemplateParmPackExpr : Expr { + private readonly Lazy _argumentPack; + private readonly Lazy _parameterPack; + internal SubstNonTypeTemplateParmPackExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_DeclRefExpr, CX_StmtClass.CX_StmtClass_SubstNonTypeTemplateParmPackExpr) { + Debug.Assert(NumChildren is 0); + + _argumentPack = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetTemplateArgument(0))); + _parameterPack = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); } + + public TemplateArgument ArgumentPack => _argumentPack.Value; + + public NonTypeTemplateParmDecl Parameter => _parameterPack.Value; } } diff --git a/sources/ClangSharp/Cursors/Exprs/UnaryOperator.cs b/sources/ClangSharp/Cursors/Exprs/UnaryOperator.cs index c6158454..95880457 100644 --- a/sources/ClangSharp/Cursors/Exprs/UnaryOperator.cs +++ b/sources/ClangSharp/Cursors/Exprs/UnaryOperator.cs @@ -1,19 +1,25 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. -using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public sealed class UnaryOperator : Expr { - private readonly Lazy _subExpr; - internal UnaryOperator(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnaryOperator, CX_StmtClass.CX_StmtClass_UnaryOperator) { - _subExpr = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SubExpr)); + Debug.Assert(NumChildren is 1); } + public bool IsArithmetic => (Opcode >= CX_UnaryOperatorKind.CX_UO_Plus) && (Opcode <= CX_UnaryOperatorKind.CX_UO_LNot); + + public bool IsDecrementOp => (Opcode == CX_UnaryOperatorKind.CX_UO_PreDec) || (Opcode == CX_UnaryOperatorKind.CX_UO_PostDec); + + public bool IsIncrementOp => (Opcode == CX_UnaryOperatorKind.CX_UO_PreInc) || (Opcode == CX_UnaryOperatorKind.CX_UO_PostInc); + + public bool IsIncrementDecrementOp => (Opcode <= CX_UnaryOperatorKind.CX_UO_PreDec); + public bool IsPrefix => (Opcode == CX_UnaryOperatorKind.CX_UO_PreInc) || (Opcode == CX_UnaryOperatorKind.CX_UO_PreDec); public bool IsPostfix => (Opcode == CX_UnaryOperatorKind.CX_UO_PostInc) || (Opcode == CX_UnaryOperatorKind.CX_UO_PostDec); @@ -22,6 +28,6 @@ internal UnaryOperator(CXCursor handle) : base(handle, CXCursorKind.CXCursor_Una public string OpcodeStr => Handle.UnaryOperatorKindSpelling.ToString(); - public Expr SubExpr => _subExpr.Value; + public Expr SubExpr => (Expr)Children[0]; } } diff --git a/sources/ClangSharp/Cursors/Exprs/UnresolvedMemberExpr.cs b/sources/ClangSharp/Cursors/Exprs/UnresolvedMemberExpr.cs index c5eddcdd..9d45a648 100644 --- a/sources/ClangSharp/Cursors/Exprs/UnresolvedMemberExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/UnresolvedMemberExpr.cs @@ -1,13 +1,30 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; +using System.Diagnostics; +using System.Linq; using ClangSharp.Interop; namespace ClangSharp { public sealed class UnresolvedMemberExpr : OverloadExpr { + private readonly Lazy _baseType; + internal UnresolvedMemberExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_MemberRefExpr, CX_StmtClass.CX_StmtClass_UnresolvedMemberExpr) { + Debug.Assert(NumChildren is 0 or 1); + _baseType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); } + + public Expr Base => (Expr)Children.SingleOrDefault(); + + public Type BaseType => _baseType.Value; + + public bool IsImplicitAccess => NumChildren == 0; + + public bool IsArrow => Handle.IsArrow; + + public string MemberName => Handle.Name.CString; } } diff --git a/sources/ClangSharp/Cursors/Exprs/VAArgExpr.cs b/sources/ClangSharp/Cursors/Exprs/VAArgExpr.cs index 16d9d043..e762fc08 100644 --- a/sources/ClangSharp/Cursors/Exprs/VAArgExpr.cs +++ b/sources/ClangSharp/Cursors/Exprs/VAArgExpr.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp @@ -8,6 +9,9 @@ public sealed class VAArgExpr : Expr { internal VAArgExpr(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedExpr, CX_StmtClass.CX_StmtClass_VAArgExpr) { + Debug.Assert(NumChildren is 1); } + + public Expr SubExpr => (Expr)Children[0]; } } diff --git a/sources/ClangSharp/Cursors/Stmts/AttributedStmt.cs b/sources/ClangSharp/Cursors/Stmts/AttributedStmt.cs index 18f44325..bca04b83 100644 --- a/sources/ClangSharp/Cursors/Stmts/AttributedStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/AttributedStmt.cs @@ -1,13 +1,36 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; +using System.Collections.Generic; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public sealed class AttributedStmt : ValueStmt { + private readonly Lazy> _attrs; + internal AttributedStmt(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedStmt, CX_StmtClass.CX_StmtClass_AttributedStmt) { + Debug.Assert(NumChildren == 1); + + _attrs = new Lazy>(() => { + var numAttrs = Handle.NumAttrs; + var attrs = new List(numAttrs); + + for (var i = 0; i < numAttrs; i++) + { + var attr = TranslationUnit.GetOrCreate(Handle.GetAttr(unchecked((uint)i))); + attrs.Add(attr); + } + + return attrs; + }); } + + public IReadOnlyList Attrs => _attrs.Value; + + public Stmt SubStmt => Children[0]; } } diff --git a/sources/ClangSharp/Cursors/Stmts/BreakStmt.cs b/sources/ClangSharp/Cursors/Stmts/BreakStmt.cs index 4278d253..d063baf9 100644 --- a/sources/ClangSharp/Cursors/Stmts/BreakStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/BreakStmt.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp @@ -8,6 +9,7 @@ public sealed class BreakStmt : Stmt { internal BreakStmt(CXCursor handle) : base(handle, CXCursorKind.CXCursor_BreakStmt, CX_StmtClass.CX_StmtClass_BreakStmt) { + Debug.Assert(NumChildren is 0); } } } diff --git a/sources/ClangSharp/Cursors/Stmts/CXXCatchStmt.cs b/sources/ClangSharp/Cursors/Stmts/CXXCatchStmt.cs index aef43f97..4110b47a 100644 --- a/sources/ClangSharp/Cursors/Stmts/CXXCatchStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/CXXCatchStmt.cs @@ -1,13 +1,28 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public sealed class CXXCatchStmt : Stmt { + private readonly Lazy _caughtType; + private readonly Lazy _exceptionDecl; + internal CXXCatchStmt(CXCursor handle) : base(handle, CXCursorKind.CXCursor_CXXCatchStmt, CX_StmtClass.CX_StmtClass_CXXCatchStmt) { + Debug.Assert(NumChildren is 1); + + _caughtType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TypeOperand)); + _exceptionDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); } + + public Type CaughtType => _caughtType.Value; + + public VarDecl ExceptionDecl => _exceptionDecl.Value; + + public Stmt HandlerBlock => Children[0]; } } diff --git a/sources/ClangSharp/Cursors/Stmts/CXXForRangeStmt.cs b/sources/ClangSharp/Cursors/Stmts/CXXForRangeStmt.cs index e994736b..ac6add0a 100644 --- a/sources/ClangSharp/Cursors/Stmts/CXXForRangeStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/CXXForRangeStmt.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp @@ -8,6 +9,27 @@ public sealed class CXXForRangeStmt : Stmt { internal CXXForRangeStmt(CXCursor handle) : base(handle, CXCursorKind.CXCursor_CXXForRangeStmt, CX_StmtClass.CX_StmtClass_CXXForRangeStmt) { + Debug.Assert(NumChildren is 8); } + + public DeclStmt BeginStmt => (DeclStmt)Children[2]; + + public Stmt Body => Children[7]; + + public Expr Cond => (Expr)Children[4]; + + public DeclStmt EndStmt => (DeclStmt)Children[3]; + + public Expr Inc => (Expr)Children[5]; + + public VarDecl LoopVariable => (VarDecl)LoopVarStmt.SingleDecl; + + public DeclStmt LoopVarStmt => (DeclStmt)Children[6]; + + public Stmt Init => Children[0]; + + public Expr RangeInit => ((VarDecl)RangeStmt.SingleDecl).Init; + + public DeclStmt RangeStmt => (DeclStmt)Children[1]; } } diff --git a/sources/ClangSharp/Cursors/Stmts/CXXTryStmt.cs b/sources/ClangSharp/Cursors/Stmts/CXXTryStmt.cs index 776b0257..cddba2aa 100644 --- a/sources/ClangSharp/Cursors/Stmts/CXXTryStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/CXXTryStmt.cs @@ -1,13 +1,27 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; using ClangSharp.Interop; namespace ClangSharp { public sealed class CXXTryStmt : Stmt { + private readonly Lazy> _handlers; + internal CXXTryStmt(CXCursor handle) : base(handle, CXCursorKind.CXCursor_CXXTryStmt, CX_StmtClass.CX_StmtClass_CXXTryStmt) { + Debug.Assert(NumChildren is >= 1); + _handlers = new Lazy>(() => Children.Skip(1).Cast().ToList()); } + + public IReadOnlyList Handlers => _handlers.Value; + + public uint NumHandlers => (uint)(Children.Count - 1); + + public CompoundStmt TryBlock => (CompoundStmt)Children[0]; } } diff --git a/sources/ClangSharp/Cursors/Stmts/CapturedStmt.Capture.cs b/sources/ClangSharp/Cursors/Stmts/CapturedStmt.Capture.cs new file mode 100644 index 00000000..42b8adff --- /dev/null +++ b/sources/ClangSharp/Cursors/Stmts/CapturedStmt.Capture.cs @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. + +using System; +using ClangSharp.Interop; + +namespace ClangSharp +{ + public partial class CapturedStmt + { + public sealed class Capture + { + private readonly CapturedStmt _parentStmt; + private readonly uint _index; + private readonly Lazy _capturedVar; + + internal Capture(CapturedStmt parentStmt, uint index) + { + _parentStmt = parentStmt; + _index = index; + + _capturedVar = new Lazy(() => _parentStmt.TranslationUnit.GetOrCreate(_parentStmt.Handle.GetCapturedVar(_index))); + } + + public VarDecl CapturedVar => _capturedVar.Value; + + public CX_VariableCaptureKind CaptureKind => _parentStmt.Handle.GetCaptureKind(_index); + + public bool CapturesThis => CaptureKind == CX_VariableCaptureKind.CX_VCK_This; + + public bool CapturesVariable => CaptureKind == CX_VariableCaptureKind.CX_VCK_ByRef; + + public bool CapturesVariableByCopy => CaptureKind == CX_VariableCaptureKind.CX_VCK_ByCopy; + + public bool CapturesVariableArrayType => CaptureKind == CX_VariableCaptureKind.CX_VCK_VLAType; + } + } +} diff --git a/sources/ClangSharp/Cursors/Stmts/CapturedStmt.cs b/sources/ClangSharp/Cursors/Stmts/CapturedStmt.cs index 42862ccd..f07aba5b 100644 --- a/sources/ClangSharp/Cursors/Stmts/CapturedStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/CapturedStmt.cs @@ -1,13 +1,71 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; +using System.Collections.Generic; +using System.Linq; using ClangSharp.Interop; namespace ClangSharp { - public sealed class CapturedStmt : Stmt + public sealed partial class CapturedStmt : Stmt { + private readonly Lazy _capturedDecl; + private readonly Lazy _capturedRecordDecl; + private readonly Lazy _captureStmt; + private readonly Lazy> _captures; + private readonly Lazy> _captureInits; + internal CapturedStmt(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedStmt, CX_StmtClass.CX_StmtClass_CapturedStmt) { + _capturedDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.CapturedDecl)); + _capturedRecordDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.CapturedRecordDecl)); + _captureStmt = new Lazy(() => TranslationUnit.GetOrCreate(Handle.CapturedStmt)); + + _captures = new Lazy>(() => { + var numCaptures = Handle.NumCaptures; + var captures = new List(numCaptures); + + for (var i = 0; i < numCaptures; i++) + { + var capture = new Capture(this, unchecked((uint)i)); + captures.Add(capture); + } + + return captures; + }); + + _captureInits = new Lazy>(() => Children.Cast().ToList()); + } + + public CapturedDecl CapturedDecl => _capturedDecl.Value; + + public RecordDecl CapturedRecordDecl => _capturedRecordDecl.Value; + + CX_CapturedRegionKind CapturedRegionKind => Handle.CapturedRegionKind; + + public Stmt CaptureStmt => _captureStmt.Value; + + public IReadOnlyList Captures => _captures.Value; + + public uint CaptureSize => unchecked((uint)Handle.NumCaptures); + + public IReadOnlyList CaptureInits => _captureInits.Value; + + public bool CapturesVariable(VarDecl var) + { + foreach (var I in Captures) + { + if (!I.CapturesVariable && !I.CapturesVariableByCopy) + { + continue; + } + + if (I.CapturedVar.CanonicalDecl == var.CanonicalDecl) + { + return true; + } + } + return false; } } } diff --git a/sources/ClangSharp/Cursors/Stmts/CaseStmt.cs b/sources/ClangSharp/Cursors/Stmts/CaseStmt.cs index 32876b12..e528bded 100644 --- a/sources/ClangSharp/Cursors/Stmts/CaseStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/CaseStmt.cs @@ -1,23 +1,29 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. -using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public sealed class CaseStmt : SwitchCase { - private readonly Lazy _lhs; - private readonly Lazy _rhs; - internal CaseStmt(CXCursor handle) : base(handle, CXCursorKind.CXCursor_CaseStmt, CX_StmtClass.CX_StmtClass_CaseStmt) { - _lhs = new Lazy(() => TranslationUnit.GetOrCreate(Handle.LhsExpr)); - _rhs = new Lazy(() => TranslationUnit.GetOrCreate(Handle.RhsExpr)); + Debug.Assert(NumChildren is 2 or 3); } - public Expr LHS => _lhs.Value; + public bool CaseStmtIsGNURange => NumChildren is 3; + + public Expr LHS => (Expr)Children[LHSOffset]; + + public Expr RHS => CaseStmtIsGNURange ? (Expr)Children[RHSOffset] : null; + + public new Stmt SubStmt => Children[SubStmtOffset]; + + private int LHSOffset => 0; + + private int RHSOffset => LHSOffset + (CaseStmtIsGNURange ? 1 : 0); - public Expr RHS => _rhs.Value; + private int SubStmtOffset => RHSOffset + 1; } } diff --git a/sources/ClangSharp/Cursors/Stmts/CompoundStmt.cs b/sources/ClangSharp/Cursors/Stmts/CompoundStmt.cs index c6fe500e..841d3d7e 100644 --- a/sources/ClangSharp/Cursors/Stmts/CompoundStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/CompoundStmt.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. using System.Collections.Generic; +using System.Linq; using ClangSharp.Interop; namespace ClangSharp @@ -12,5 +13,26 @@ public CompoundStmt(CXCursor handle) : base(handle, CXCursorKind.CXCursor_Compou } public IReadOnlyList Body => Children; + + public Stmt BodyBack => Children.LastOrDefault(); + + public Stmt BodyFront => Children.FirstOrDefault(); + + public uint Size => unchecked((uint)NumChildren); + + public Stmt StmtExprResult + { + get + { + foreach (var B in Body.Reverse()) + { + if (B is not NullStmt) + { + return B; + } + } + return BodyBack; + } + } } } diff --git a/sources/ClangSharp/Cursors/Stmts/ContinueStmt.cs b/sources/ClangSharp/Cursors/Stmts/ContinueStmt.cs index ff26ce42..ba84904b 100644 --- a/sources/ClangSharp/Cursors/Stmts/ContinueStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/ContinueStmt.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp @@ -8,6 +9,7 @@ public sealed class ContinueStmt : Stmt { internal ContinueStmt(CXCursor handle) : base(handle, CXCursorKind.CXCursor_ContinueStmt, CX_StmtClass.CX_StmtClass_ContinueStmt) { + Debug.Assert(NumChildren is 0); } } } diff --git a/sources/ClangSharp/Cursors/Stmts/DeclStmt.cs b/sources/ClangSharp/Cursors/Stmts/DeclStmt.cs index fae8bac8..96d8c8ce 100644 --- a/sources/ClangSharp/Cursors/Stmts/DeclStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/DeclStmt.cs @@ -13,13 +13,24 @@ public sealed class DeclStmt : Stmt internal DeclStmt(CXCursor handle) : base(handle, CXCursorKind.CXCursor_DeclStmt, CX_StmtClass.CX_StmtClass_DeclStmt) { - _decls = new Lazy>(() => CursorChildren.OfType().ToList()); + _decls = new Lazy>(() => { + var numDecls = Handle.NumDecls; + var decls = new List(numDecls); + + for (var i = 0; i < numDecls; i++) + { + var decl = TranslationUnit.GetOrCreate(Handle.GetDecl(unchecked((uint)i))); + decls.Add(decl); + } + + return decls; + }); } public IReadOnlyList Decls => _decls.Value; public bool IsSingleDecl => Decls.Count == 1; - public Decl SingleDecl => Decls.Single(); + public Decl SingleDecl => Decls.SingleOrDefault(); } } diff --git a/sources/ClangSharp/Cursors/Stmts/DefaultStmt.cs b/sources/ClangSharp/Cursors/Stmts/DefaultStmt.cs index c6e6ad37..4da7f55c 100644 --- a/sources/ClangSharp/Cursors/Stmts/DefaultStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/DefaultStmt.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp @@ -8,6 +9,9 @@ public sealed class DefaultStmt : SwitchCase { internal DefaultStmt(CXCursor handle) : base(handle, CXCursorKind.CXCursor_DefaultStmt, CX_StmtClass.CX_StmtClass_DefaultStmt) { + Debug.Assert(NumChildren is 1); } + + public new Stmt SubStmt => Children[0]; } } diff --git a/sources/ClangSharp/Cursors/Stmts/DoStmt.cs b/sources/ClangSharp/Cursors/Stmts/DoStmt.cs index eff062ac..721a31fa 100644 --- a/sources/ClangSharp/Cursors/Stmts/DoStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/DoStmt.cs @@ -1,23 +1,19 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. -using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public sealed class DoStmt : Stmt { - private readonly Lazy _body; - private readonly Lazy _cond; - internal DoStmt(CXCursor handle) : base(handle, CXCursorKind.CXCursor_DoStmt, CX_StmtClass.CX_StmtClass_DoStmt) { - _body = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Body)); - _cond = new Lazy(() => TranslationUnit.GetOrCreate(Handle.CondExpr)); + Debug.Assert(NumChildren is 2); } - public Stmt Body => _body.Value; + public Stmt Body => Children[0]; - public Expr Cond => _cond.Value; + public Expr Cond => (Expr)Children[1]; } } diff --git a/sources/ClangSharp/Cursors/Stmts/ForStmt.cs b/sources/ClangSharp/Cursors/Stmts/ForStmt.cs index d76e98e8..38b16113 100644 --- a/sources/ClangSharp/Cursors/Stmts/ForStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/ForStmt.cs @@ -1,39 +1,27 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. -using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public sealed class ForStmt : Stmt { - private readonly Lazy _body; - private readonly Lazy _cond; - private readonly Lazy _conditionVariable; - private readonly Lazy _conditionVariableDeclStmt; - private readonly Lazy _inc; - private readonly Lazy _init; - internal ForStmt(CXCursor handle) : base(handle, CXCursorKind.CXCursor_ForStmt, CX_StmtClass.CX_StmtClass_ForStmt) { - _body = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Body)); - _cond = new Lazy(() => TranslationUnit.GetOrCreate(Handle.CondExpr)); - _conditionVariable = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); - _conditionVariableDeclStmt = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ConditionVariableDeclStmt)); - _inc = new Lazy(() => TranslationUnit.GetOrCreate(Handle.IncExpr)); - _init = new Lazy(() => TranslationUnit.GetOrCreate(Handle.InitExpr)); + Debug.Assert(NumChildren is 5); } - public Stmt Body => _body.Value; + public Stmt Body => Children[4]; - public Expr Cond => _cond.Value; + public Expr Cond => (Expr)Children[2]; - public VarDecl ConditionVariable => _conditionVariable.Value; + public VarDecl ConditionVariable => (VarDecl)ConditionVariableDeclStmt?.SingleDecl; - public DeclStmt ConditionVariableDeclStmt => _conditionVariableDeclStmt.Value; + public DeclStmt ConditionVariableDeclStmt => (DeclStmt)Children[1]; - public Expr Inc => _inc.Value; + public Expr Inc => (Expr)Children[3]; - public Stmt Init => _init.Value; + public Stmt Init => Children[0]; } } diff --git a/sources/ClangSharp/Cursors/Stmts/GotoStmt.cs b/sources/ClangSharp/Cursors/Stmts/GotoStmt.cs index eef40564..fd93d432 100644 --- a/sources/ClangSharp/Cursors/Stmts/GotoStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/GotoStmt.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp @@ -11,6 +12,7 @@ public sealed class GotoStmt : Stmt internal GotoStmt(CXCursor handle) : base(handle, CXCursorKind.CXCursor_GotoStmt, CX_StmtClass.CX_StmtClass_GotoStmt) { + Debug.Assert(NumChildren is 0); _label = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); } diff --git a/sources/ClangSharp/Cursors/Stmts/IfStmt.cs b/sources/ClangSharp/Cursors/Stmts/IfStmt.cs index c089af6e..7a75bce6 100644 --- a/sources/ClangSharp/Cursors/Stmts/IfStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/IfStmt.cs @@ -1,35 +1,47 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. -using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public sealed class IfStmt : Stmt { - private readonly Lazy _cond; - private readonly Lazy _conditionVariable; - private readonly Lazy _conditionVariableDeclStmt; - private readonly Lazy _else; - private readonly Lazy _then; - internal IfStmt(CXCursor handle) : base(handle, CXCursorKind.CXCursor_IfStmt, CX_StmtClass.CX_StmtClass_IfStmt) { - _cond = new Lazy(() => TranslationUnit.GetOrCreate(Handle.CondExpr)); - _conditionVariable = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); - _conditionVariableDeclStmt = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ConditionVariableDeclStmt)); - _else = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SubStmt)); - _then = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Body)); + Debug.Assert(NumChildren is >= 2 and <= 4); } - public Expr Cond => _cond.Value; + public Expr Cond => (Expr)Children[CondOffset]; + + public VarDecl ConditionVariable => (VarDecl)ConditionVariableDeclStmt?.SingleDecl; + + public DeclStmt ConditionVariableDeclStmt => HasVarStorage ? (DeclStmt)Children[VarOffset] : null; + + public Stmt Else => HasElseStorage ? Children[ElseOffset] : null; + + public bool HasElseStorage => Handle.HasElseStorage; + + public bool HasInitStorage => Handle.HasInitStorage; + + public bool HasVarStorage => Handle.HasVarStorage; + + public Stmt Init => HasInitStorage ? Children[InitOffset] : null; + + public bool IsConstexpr => Handle.IsConstexpr; + + public bool IsObjcAvailabilityCheck => Cond is ObjCAvailabilityCheckExpr; + + public Stmt Then => Children[ThenOffset]; + + private int CondOffset => VarOffset + (HasVarStorage ? 1 : 0); - public VarDecl ConditionVariable => _conditionVariable.Value; + private int ElseOffset => CondOffset + 2; - public DeclStmt ConditionVariableDeclStmt => _conditionVariableDeclStmt.Value; + private int InitOffset => 0; - public Stmt Else => _else.Value; + private int ThenOffset => CondOffset + 1; - public Stmt Then => _then.Value; + private int VarOffset => InitOffset + (HasInitStorage ? 1 : 0); } } diff --git a/sources/ClangSharp/Cursors/Stmts/IndirectGotoStmt.cs b/sources/ClangSharp/Cursors/Stmts/IndirectGotoStmt.cs index f8f86544..5d712a3a 100644 --- a/sources/ClangSharp/Cursors/Stmts/IndirectGotoStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/IndirectGotoStmt.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp @@ -8,16 +9,15 @@ namespace ClangSharp public sealed class IndirectGotoStmt : Stmt { private readonly Lazy _constantTarget; - private readonly Lazy _target; internal IndirectGotoStmt(CXCursor handle) : base(handle, CXCursorKind.CXCursor_IndirectGotoStmt, CX_StmtClass.CX_StmtClass_IndirectGotoStmt) { + Debug.Assert(NumChildren is 1); _constantTarget = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); - _target = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SubStmt)); } public LabelDecl ConstantTarget => _constantTarget.Value; - public Expr Target => _target.Value; + public Expr Target => (Expr)Children[0]; } } diff --git a/sources/ClangSharp/Cursors/Stmts/LabelStmt.cs b/sources/ClangSharp/Cursors/Stmts/LabelStmt.cs index da361054..f8b479ae 100644 --- a/sources/ClangSharp/Cursors/Stmts/LabelStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/LabelStmt.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp @@ -8,16 +9,17 @@ namespace ClangSharp public sealed class LabelStmt : ValueStmt { private readonly Lazy _decl; - private readonly Lazy _subStmt; internal LabelStmt(CXCursor handle) : base(handle, CXCursorKind.CXCursor_LabelStmt, CX_StmtClass.CX_StmtClass_LabelStmt) { + Debug.Assert(NumChildren is 1); _decl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); - _subStmt = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SubStmt)); } public LabelDecl Decl => _decl.Value; - public Stmt SubStmt => _subStmt.Value; + public string Name => Handle.Name.CString; + + public Stmt SubStmt => Children[0]; } } diff --git a/sources/ClangSharp/Cursors/Stmts/MSDependentExistsStmt.cs b/sources/ClangSharp/Cursors/Stmts/MSDependentExistsStmt.cs index 5ca89519..2116ee1b 100644 --- a/sources/ClangSharp/Cursors/Stmts/MSDependentExistsStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/MSDependentExistsStmt.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp @@ -8,6 +9,15 @@ public sealed class MSDependentExistsStmt : Stmt { internal MSDependentExistsStmt(CXCursor handle) : base(handle, CXCursorKind.CXCursor_UnexposedStmt, CX_StmtClass.CX_StmtClass_MSDependentExistsStmt) { + Debug.Assert(NumChildren is 1); } + + public bool IsIfExists => Handle.IsIfExists; + + public bool IsIfNotExists => !IsIfExists; + + public string Name => Handle.Name.CString; + + public CompoundStmt SubStmt => (CompoundStmt)Children[0]; } } diff --git a/sources/ClangSharp/Cursors/Stmts/NullStmt.cs b/sources/ClangSharp/Cursors/Stmts/NullStmt.cs index eda7a900..97703fa0 100644 --- a/sources/ClangSharp/Cursors/Stmts/NullStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/NullStmt.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp @@ -8,6 +9,9 @@ public sealed class NullStmt : Stmt { internal NullStmt(CXCursor handle) : base(handle, CXCursorKind.CXCursor_NullStmt, CX_StmtClass.CX_StmtClass_NullStmt) { + Debug.Assert(NumChildren is 0); } + + public bool HasLeadingEmptyMacro => Handle.HasLeadingEmptyMacro; } } diff --git a/sources/ClangSharp/Cursors/Stmts/ObjCAtCatchStmt.cs b/sources/ClangSharp/Cursors/Stmts/ObjCAtCatchStmt.cs index 3d6733dc..9547b04e 100644 --- a/sources/ClangSharp/Cursors/Stmts/ObjCAtCatchStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/ObjCAtCatchStmt.cs @@ -1,13 +1,25 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public sealed class ObjCAtCatchStmt : Stmt { + private readonly Lazy _catchParamDecl; + internal ObjCAtCatchStmt(CXCursor handle) : base(handle, CXCursorKind.CXCursor_ObjCAtCatchStmt, CX_StmtClass.CX_StmtClass_ObjCAtCatchStmt) { + Debug.Assert(NumChildren is 1); + _catchParamDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); } + + public Stmt CatchBody => Children[0]; + + public VarDecl CatchParamDecl => _catchParamDecl.Value; + + public bool HasEllipsis => CatchParamDecl == null; } } diff --git a/sources/ClangSharp/Cursors/Stmts/ObjCAtFinallyStmt.cs b/sources/ClangSharp/Cursors/Stmts/ObjCAtFinallyStmt.cs index d2b70ae1..0ae3fe45 100644 --- a/sources/ClangSharp/Cursors/Stmts/ObjCAtFinallyStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/ObjCAtFinallyStmt.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp @@ -8,6 +9,9 @@ public sealed class ObjCAtFinallyStmt : Stmt { internal ObjCAtFinallyStmt(CXCursor handle) : base(handle, CXCursorKind.CXCursor_ObjCAtFinallyStmt, CX_StmtClass.CX_StmtClass_ObjCAtFinallyStmt) { + Debug.Assert(NumChildren is 1); } + + public Stmt FinallyBody => Children[0]; } } diff --git a/sources/ClangSharp/Cursors/Stmts/ObjCAtSynchronizedStmt.cs b/sources/ClangSharp/Cursors/Stmts/ObjCAtSynchronizedStmt.cs index 9cfe653f..18c8bb09 100644 --- a/sources/ClangSharp/Cursors/Stmts/ObjCAtSynchronizedStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/ObjCAtSynchronizedStmt.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp @@ -8,6 +9,11 @@ public sealed class ObjCAtSynchronizedStmt : Stmt { internal ObjCAtSynchronizedStmt(CXCursor handle) : base(handle, CXCursorKind.CXCursor_ObjCAtSynchronizedStmt, CX_StmtClass.CX_StmtClass_ObjCAtSynchronizedStmt) { + Debug.Assert(NumChildren is 2); } + + public CompoundStmt SynchBody => (CompoundStmt)Children[1]; + + public Expr SynchExpr => (Expr)Children[0]; } } diff --git a/sources/ClangSharp/Cursors/Stmts/ObjCAtThrowStmt.cs b/sources/ClangSharp/Cursors/Stmts/ObjCAtThrowStmt.cs index f6174013..41101491 100644 --- a/sources/ClangSharp/Cursors/Stmts/ObjCAtThrowStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/ObjCAtThrowStmt.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp @@ -8,6 +9,9 @@ public sealed class ObjCAtThrowStmt : Stmt { internal ObjCAtThrowStmt(CXCursor handle) : base(handle, CXCursorKind.CXCursor_ObjCAtThrowStmt, CX_StmtClass.CX_StmtClass_ObjCAtThrowStmt) { + Debug.Assert(NumChildren is 1); } + + public Expr ThrowExpr => (Expr)Children[0]; } } diff --git a/sources/ClangSharp/Cursors/Stmts/ObjCAtTryStmt.cs b/sources/ClangSharp/Cursors/Stmts/ObjCAtTryStmt.cs index f2651b0e..a21a823f 100644 --- a/sources/ClangSharp/Cursors/Stmts/ObjCAtTryStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/ObjCAtTryStmt.cs @@ -1,13 +1,51 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; using ClangSharp.Interop; namespace ClangSharp { public sealed class ObjCAtTryStmt : Stmt { + private readonly Lazy> _catchStmts; + private readonly Lazy _finallyStmt; + internal ObjCAtTryStmt(CXCursor handle) : base(handle, CXCursorKind.CXCursor_ObjCAtTryStmt, CX_StmtClass.CX_StmtClass_ObjCAtTryStmt) { + Debug.Assert(NumChildren is >= 1); + + _catchStmts = new Lazy>(() => { + var children = Children; + var skipLast = 0; + + if (children.Last() is ObjCAtFinallyStmt) { + skipLast++; + } + + return children.Skip(1).Take((int)(NumChildren - 1 - skipLast)).Cast().ToList(); + }); + + _finallyStmt = new Lazy(() => { + var children = Children; + + if (children.Last() is ObjCAtFinallyStmt finallyStmt) + { + return finallyStmt; + } + + return null; + }); } + + public Stmt Body => Children[0]; + + public IReadOnlyList CatchStmts => _catchStmts.Value; + + public ObjCAtFinallyStmt FinallyStmt => _finallyStmt.Value; + + public uint NumCatchStmts => (uint)CatchStmts.Count; } } diff --git a/sources/ClangSharp/Cursors/Stmts/ObjCAutoreleasePoolStmt.cs b/sources/ClangSharp/Cursors/Stmts/ObjCAutoreleasePoolStmt.cs index 3bc02e34..da6f3041 100644 --- a/sources/ClangSharp/Cursors/Stmts/ObjCAutoreleasePoolStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/ObjCAutoreleasePoolStmt.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp @@ -8,6 +9,9 @@ public sealed class ObjCAutoreleasePoolStmt : Stmt { internal ObjCAutoreleasePoolStmt(CXCursor handle) : base(handle, CXCursorKind.CXCursor_ObjCAutoreleasePoolStmt, CX_StmtClass.CX_StmtClass_ObjCAutoreleasePoolStmt) { + Debug.Assert(NumChildren is 1); } + + public Stmt SubStmt => Children[0]; } } diff --git a/sources/ClangSharp/Cursors/Stmts/ObjCForCollectionStmt.cs b/sources/ClangSharp/Cursors/Stmts/ObjCForCollectionStmt.cs index 4a57ac40..67ad4ff7 100644 --- a/sources/ClangSharp/Cursors/Stmts/ObjCForCollectionStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/ObjCForCollectionStmt.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp @@ -8,6 +9,13 @@ public sealed class ObjCForCollectionStmt : Stmt { internal ObjCForCollectionStmt(CXCursor handle) : base(handle, CXCursorKind.CXCursor_ObjCForCollectionStmt, CX_StmtClass.CX_StmtClass_ObjCForCollectionStmt) { + Debug.Assert(NumChildren is 3); } + + public Stmt Body => Children[2]; + + public Expr Collection => (Expr)Children[1]; + + public Stmt Element => Children[0]; } } diff --git a/sources/ClangSharp/Cursors/Stmts/ReturnStmt.cs b/sources/ClangSharp/Cursors/Stmts/ReturnStmt.cs index c096f372..bd7b94f0 100644 --- a/sources/ClangSharp/Cursors/Stmts/ReturnStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/ReturnStmt.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp @@ -8,16 +9,16 @@ namespace ClangSharp public sealed class ReturnStmt : Stmt { private readonly Lazy _nrvoCandidate; - private readonly Lazy _retValue; internal ReturnStmt(CXCursor handle) : base(handle, CXCursorKind.CXCursor_ReturnStmt, CX_StmtClass.CX_StmtClass_ReturnStmt) { + Debug.Assert(NumChildren is 0 or 1); + _nrvoCandidate = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); - _retValue = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SubStmt)); } public VarDecl NRVOCandidate => _nrvoCandidate.Value; - public Expr RetValue => _retValue.Value; + public Expr RetValue => NumChildren != 0 ? (Expr)Children[0] : null; } } diff --git a/sources/ClangSharp/Cursors/Stmts/SEHExceptStmt.cs b/sources/ClangSharp/Cursors/Stmts/SEHExceptStmt.cs index 23ac58bd..02807876 100644 --- a/sources/ClangSharp/Cursors/Stmts/SEHExceptStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/SEHExceptStmt.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp @@ -8,6 +9,11 @@ public sealed class SEHExceptStmt : Stmt { internal SEHExceptStmt(CXCursor handle) : base(handle, CXCursorKind.CXCursor_SEHExceptStmt, CX_StmtClass.CX_StmtClass_SEHExceptStmt) { + Debug.Assert(NumChildren is 2); } + + public Expr FilterExpr => (Expr)Children[0]; + + public CompoundStmt Block => (CompoundStmt)Children[1]; } } diff --git a/sources/ClangSharp/Cursors/Stmts/SEHFinallyStmt.cs b/sources/ClangSharp/Cursors/Stmts/SEHFinallyStmt.cs index 277ebb49..26f186de 100644 --- a/sources/ClangSharp/Cursors/Stmts/SEHFinallyStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/SEHFinallyStmt.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp @@ -8,6 +9,9 @@ public sealed class SEHFinallyStmt : Stmt { internal SEHFinallyStmt(CXCursor handle) : base(handle, CXCursorKind.CXCursor_SEHFinallyStmt, CX_StmtClass.CX_StmtClass_SEHFinallyStmt) { + Debug.Assert(NumChildren is 1); } + + public CompoundStmt Block => (CompoundStmt)Children[0]; } } diff --git a/sources/ClangSharp/Cursors/Stmts/SEHLeaveStmt.cs b/sources/ClangSharp/Cursors/Stmts/SEHLeaveStmt.cs index f95318ad..a7a63c22 100644 --- a/sources/ClangSharp/Cursors/Stmts/SEHLeaveStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/SEHLeaveStmt.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp @@ -8,6 +9,7 @@ public sealed class SEHLeaveStmt : Stmt { internal SEHLeaveStmt(CXCursor handle) : base(handle, CXCursorKind.CXCursor_SEHLeaveStmt, CX_StmtClass.CX_StmtClass_SEHLeaveStmt) { + Debug.Assert(NumChildren is 0); } } } diff --git a/sources/ClangSharp/Cursors/Stmts/SEHTryStmt.cs b/sources/ClangSharp/Cursors/Stmts/SEHTryStmt.cs index 5fc9d1c9..1fb3abb8 100644 --- a/sources/ClangSharp/Cursors/Stmts/SEHTryStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/SEHTryStmt.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp @@ -8,6 +9,17 @@ public sealed class SEHTryStmt : Stmt { internal SEHTryStmt(CXCursor handle) : base(handle, CXCursorKind.CXCursor_SEHTryStmt, CX_StmtClass.CX_StmtClass_SEHTryStmt) { + Debug.Assert(NumChildren is 2); } + + public SEHExceptStmt ExceptHandler => Handler as SEHExceptStmt; + + public SEHFinallyStmt FinallyHandler => Handler as SEHFinallyStmt; + + public bool IsCXXTry => Handle.IsCXXTry; + + public Stmt Handler => Children[1]; + + public CompoundStmt TryBlock => (CompoundStmt)Children[0]; } } diff --git a/sources/ClangSharp/Cursors/Stmts/Stmt.cs b/sources/ClangSharp/Cursors/Stmts/Stmt.cs index 503d7d3c..f8104a6a 100644 --- a/sources/ClangSharp/Cursors/Stmts/Stmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/Stmt.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; -using System.Linq; using ClangSharp.Interop; namespace ClangSharp @@ -19,7 +18,19 @@ private protected Stmt(CXCursor handle, CXCursorKind expectedCursorKind, CX_Stmt throw new ArgumentException(nameof(handle)); } - _children = new Lazy>(() => CursorChildren.OfType().ToList()); + _children = new Lazy>(() => { + var numChildren = Handle.NumChildren; + var children = new List(numChildren); + + for (int i = 0; i < numChildren; i++) + { + var child = TranslationUnit.GetOrCreate(Handle.GetChild(unchecked((uint)i))); + children.Add(child); + } + + return children; + }); + _declContext = new Lazy(() => { var semanticParent = TranslationUnit.GetOrCreate(Handle.SemanticParent); @@ -36,10 +47,72 @@ private protected Stmt(CXCursor handle, CXCursorKind expectedCursorKind, CX_Stmt public IDeclContext DeclContext => _declContext.Value; + public uint NumChildren => unchecked((uint)Handle.NumChildren); + public CX_StmtClass StmtClass => Handle.StmtClass; public string StmtClassName => Handle.StmtClassSpelling; + public Stmt IgnoreContainers(bool IgnoreCaptured = false) + { + Stmt S = this; + + if (IgnoreCaptured) + { + if (S is CapturedStmt CapS) + { + S = CapS.CaptureStmt; + } + } + + while (true) + { + if (S is AttributedStmt AS) + { + S = AS.SubStmt; + } + else if (S is CompoundStmt CS) + { + if (CS.Size != 1) + { + break; + } + + S = CS.BodyBack; + } + else + { + break; + } + } + return S; + } + + public Stmt StripLabelLikeStatements() + { + Stmt S = this; + + while (true) + { + if (S is LabelStmt LS) + { + S = LS.SubStmt; + } + else if (S is SwitchCase SC) + { + S = SC.SubStmt; + } + else if (S is AttributedStmt AS) + { + S = AS.SubStmt; + } + else + { + return S; + } + } + } + internal static new Stmt Create(CXCursor handle) => handle.StmtClass switch { CX_StmtClass.CX_StmtClass_GCCAsmStmt => new GCCAsmStmt(handle), diff --git a/sources/ClangSharp/Cursors/Stmts/SwitchCase.cs b/sources/ClangSharp/Cursors/Stmts/SwitchCase.cs index d747a83e..bc03062b 100644 --- a/sources/ClangSharp/Cursors/Stmts/SwitchCase.cs +++ b/sources/ClangSharp/Cursors/Stmts/SwitchCase.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp @@ -8,7 +9,6 @@ namespace ClangSharp public class SwitchCase : Stmt { private readonly Lazy _nextSwitchCase; - private readonly Lazy _subStmt; private protected SwitchCase(CXCursor handle, CXCursorKind expectedCursorKind, CX_StmtClass expectedStmtClass) : base(handle, expectedCursorKind, expectedStmtClass) { @@ -18,11 +18,26 @@ private protected SwitchCase(CXCursor handle, CXCursorKind expectedCursorKind, C } _nextSwitchCase = new Lazy(() => TranslationUnit.GetOrCreate(Handle.NextSwitchCase)); - _subStmt = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SubStmt)); } public SwitchCase NextSwitchCase => _nextSwitchCase.Value; - public Stmt SubStmt => _subStmt.Value; + public Stmt SubStmt + { + get + { + if (this is CaseStmt CS) + { + return CS.SubStmt; + } + else if (this is DefaultStmt DS) + { + return DS.SubStmt; + } + + Debug.Fail("SwitchCase is neither a CaseStmt nor a DefaultStmt!"); + return null; + } + } } } diff --git a/sources/ClangSharp/Cursors/Stmts/SwitchStmt.cs b/sources/ClangSharp/Cursors/Stmts/SwitchStmt.cs index a46606c2..b68481a7 100644 --- a/sources/ClangSharp/Cursors/Stmts/SwitchStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/SwitchStmt.cs @@ -1,39 +1,46 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public sealed class SwitchStmt : Stmt { - private readonly Lazy _body; - private readonly Lazy _cond; - private readonly Lazy _conditionVariable; - private readonly Lazy _conditionVariableDeclStmt; - private readonly Lazy _init; private readonly Lazy _switchCaseList; internal SwitchStmt(CXCursor handle) : base(handle, CXCursorKind.CXCursor_SwitchStmt, CX_StmtClass.CX_StmtClass_SwitchStmt) { - _body = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Body)); - _cond = new Lazy(() => TranslationUnit.GetOrCreate(Handle.CondExpr)); - _conditionVariable = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); - _conditionVariableDeclStmt = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ConditionVariableDeclStmt)); - _init = new Lazy(() => TranslationUnit.GetOrCreate(Handle.InitExpr)); + Debug.Assert(NumChildren is >= 2 and <= 4); _switchCaseList = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SubStmt)); } - public Stmt Body => _body.Value; + public Stmt Body => Children[BodyOffset]; - public Expr Cond => _cond.Value; + public Expr Cond => (Expr)Children[CondOffset]; - public VarDecl ConditionVariable => _conditionVariable.Value; + public VarDecl ConditionVariable => (VarDecl)ConditionVariableDeclStmt?.SingleDecl; - public DeclStmt ConditionVariableDeclStmt => _conditionVariableDeclStmt.Value; + public DeclStmt ConditionVariableDeclStmt => HasVarStorage ? (DeclStmt)Children[VarOffset] : null; - public Stmt Init => _init.Value; + public bool HasInitStorage => Handle.HasInit; + + public bool HasVarStorage => Handle.HasVarStorage; + + public Stmt Init => HasInitStorage ? Children[InitOffset] : null; + + public bool IsAllEnumCasesCovered => Handle.IsAllEnumCasesCovered; public SwitchCase SwitchCaseList => _switchCaseList.Value; + + private int BodyOffset => CondOffset + 1; + + private int CondOffset => VarOffset + (HasVarStorage ? 1 : 0); + + private int InitOffset => 0; + + private int VarOffset => InitOffset + (HasInitStorage ? 1 : 0); + } } diff --git a/sources/ClangSharp/Cursors/Stmts/ValueStmt.cs b/sources/ClangSharp/Cursors/Stmts/ValueStmt.cs index b0bd4c2e..f1489b16 100644 --- a/sources/ClangSharp/Cursors/Stmts/ValueStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/ValueStmt.cs @@ -1,24 +1,49 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public class ValueStmt : Stmt { - private readonly Lazy _exprStmt; - private protected ValueStmt(CXCursor handle, CXCursorKind expectedCursorKind, CX_StmtClass expectedStmtClass) : base(handle, expectedCursorKind, expectedStmtClass) { if ((CX_StmtClass.CX_StmtClass_LastValueStmt < handle.StmtClass) || (handle.StmtClass < CX_StmtClass.CX_StmtClass_FirstValueStmt)) { throw new ArgumentException(nameof(handle)); } - - _exprStmt = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SubStmt)); } - public Expr ExprStmt => _exprStmt.Value; + public Expr ExprStmt + { + get + { + Stmt S = this; + do + { + if (S is Expr E) + { + return E; + } + + if (S is LabelStmt LS) + { + S = LS.SubStmt; + } + else if (S is AttributedStmt AS) + { + S = AS.SubStmt; + } + else + { + Debug.Fail("unknown kind of ValueStmt"); + } + } while (S is ValueStmt); + + return null; + } + } } } diff --git a/sources/ClangSharp/Cursors/Stmts/WhileStmt.cs b/sources/ClangSharp/Cursors/Stmts/WhileStmt.cs index a1b286a2..65052f1d 100644 --- a/sources/ClangSharp/Cursors/Stmts/WhileStmt.cs +++ b/sources/ClangSharp/Cursors/Stmts/WhileStmt.cs @@ -1,31 +1,31 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. -using System; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { public sealed class WhileStmt : Stmt { - private readonly Lazy _body; - private readonly Lazy _cond; - private readonly Lazy _conditionVariable; - private readonly Lazy _conditionVariableDeclStmt; - internal WhileStmt(CXCursor handle) : base(handle, CXCursorKind.CXCursor_WhileStmt, CX_StmtClass.CX_StmtClass_WhileStmt) { - _body = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Body)); - _cond = new Lazy(() => TranslationUnit.GetOrCreate(Handle.CondExpr)); - _conditionVariable = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Referenced)); - _conditionVariableDeclStmt = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ConditionVariableDeclStmt)); + Debug.Assert(NumChildren is 2 or 3); } - public Stmt Body => _body.Value; + public Stmt Body => Children[BodyOffset]; + + public Expr Cond => (Expr)Children[CondOffset]; + + public bool HasVarStorage => Handle.HasVarStorage; + + public VarDecl ConditionVariable => (VarDecl)ConditionVariableDeclStmt?.SingleDecl; + + public DeclStmt ConditionVariableDeclStmt => HasVarStorage ? (DeclStmt)Children[VarOffset] : null; - public Expr Cond => _cond.Value; + private int BodyOffset => CondOffset + 1; - public VarDecl ConditionVariable => _conditionVariable.Value; + private int CondOffset => VarOffset + (HasVarStorage ? 1 : 0); - public DeclStmt ConditionVariableDeclStmt => _conditionVariableDeclStmt.Value; + private int VarOffset => 0; } } diff --git a/sources/ClangSharp/IDeclContext.cs b/sources/ClangSharp/IDeclContext.cs index 1e8e3e37..2889b4c1 100644 --- a/sources/ClangSharp/IDeclContext.cs +++ b/sources/ClangSharp/IDeclContext.cs @@ -8,8 +8,16 @@ public interface IDeclContext { IReadOnlyList Decls { get; } + bool IsNamespace { get; } + + bool IsStdNamespace { get; } + + bool IsTranslationUnit { get; } + IDeclContext LexicalParent { get; } IDeclContext Parent { get; } + + IDeclContext RedeclContext { get; } } } diff --git a/sources/ClangSharp/Interop.Extensions/CXCursor.cs b/sources/ClangSharp/Interop.Extensions/CXCursor.cs index 3f2c2aea..f822d243 100644 --- a/sources/ClangSharp/Interop.Extensions/CXCursor.cs +++ b/sources/ClangSharp/Interop.Extensions/CXCursor.cs @@ -17,6 +17,8 @@ public unsafe partial struct CXCursor : IEquatable public CXCursor AsFunction => clangsharp.Cursor_getAsFunction(this); + public CX_AtomicOperatorKind AtomicOperatorKind => clangsharp.Cursor_getAtomicOpcode(this); + public CX_AttrKind AttrKind => clangsharp.Cursor_getAttrKind(this); public string AttrKindSpelling @@ -351,13 +353,11 @@ public string AttrKindSpelling public CXAvailabilityKind Availability => clang.getCursorAvailability(this); - public CXCursor BaseExpr => clangsharp.Cursor_getBaseExpr(this); - public CX_BinaryOperatorKind BinaryOperatorKind => clangsharp.Cursor_getBinaryOpcode(this); public CXString BinaryOperatorKindSpelling => clangsharp.Cursor_getBinaryOpcodeSpelling(BinaryOperatorKind); - public CXCursor Binding => clangsharp.Cursor_getBinding(this); + public CXCursor BindingExpr => clangsharp.Cursor_getBindingExpr(this); public CXCursor BitWidth => clangsharp.Cursor_getBitWidth(this); @@ -371,13 +371,19 @@ public string AttrKindSpelling public CXString BriefCommentText => clang.Cursor_getBriefCommentText(this); - public CXCursor CalleeExpr => clangsharp.Cursor_getCalleeExpr(this); - public CXType CallResultType => clangsharp.Cursor_getCallResultType(this); public bool CanAvoidCopyToHeap => clangsharp.Cursor_getCanAvoidCopyToHeap(this) != 0; - public CXCursor CanonicalCursor => clang.getCanonicalCursor(this); + public CXCursor CanonicalCursor => clangsharp.Cursor_getCanonical(this); + + public CXCursor CapturedDecl => clangsharp.Cursor_getCapturedDecl(this); + + public CXCursor CapturedRecordDecl => clangsharp.Cursor_getCapturedRecordDecl(this); + + public CX_CapturedRegionKind CapturedRegionKind => clangsharp.Cursor_getCapturedRegionKind(this); + + public CXCursor CapturedStmt => clangsharp.Cursor_getCapturedStmt(this); public bool CapturesCXXThis => clangsharp.Cursor_getCapturesCXXThis(this) != 0; @@ -461,39 +467,31 @@ public string CastKindSpelling public uint CharacterLiteralValue => clangsharp.Cursor_getCharacterLiteralValue(this); - public CXCursor ColumnIdxExpr => throw null; // clangsharp.Cursor_getColumnIdxExpr(this); - public CXSourceRange CommentRange => clang.Cursor_getCommentRange(this); - public CXCursor CommonExpr => clangsharp.Cursor_getCommonExpr(this); - public CXCompletionString CompletionString => (CXCompletionString)clang.getCursorCompletionString(this); public CXType ComputationLhsType => clangsharp.Cursor_getComputationLhsType(this); public CXType ComputationResultType => clangsharp.Cursor_getComputationResultType(this); - public CXCursor CondExpr => clangsharp.Cursor_getCondExpr(this); - - public CXCursor ConditionVariableDeclStmt => clangsharp.Cursor_getConditionVariableDeclStmt(this); - public CXCursor ConstraintExpr => clangsharp.Cursor_getConstraintExpr(this); public CXCursor ConstructedBaseClass => clangsharp.Cursor_getConstructedBaseClass(this); public CXCursor ConstructedBaseClassShadowDecl => clangsharp.Cursor_getConstructedBaseClassShadowDecl(this); + public CX_ConstructionKind ConstructionKind => clangsharp.Cursor_getConstructionKind(this); + public bool ConstructsVirtualBase => clangsharp.Cursor_getConstructsVirtualBase(this) != 0; public CXCursor ContextParam => clangsharp.Cursor_getContextParam(this); public int ContextParamPosition => clangsharp.Cursor_getContextParamPosition(this); - public CXCursor ConversionFunction => clangsharp.Cursor_getConversionFunction(this); - public CX_CXXAccessSpecifier CXXAccessSpecifier => clang.getCXXAccessSpecifier(this); - public bool CXXBoolLiteralExprValue => clangsharp.Cursor_getCXXBoolLiteralExprValue(this) != 0; + public bool BoolLiteralValue => clangsharp.Cursor_getBoolLiteralValue(this) != 0; public bool CXXConstructor_IsConvertingConstructor => clang.CXXConstructor_isConvertingConstructor(this) != 0; @@ -664,22 +662,22 @@ public string DeclKindSpelling public CXType DefaultArgType => clangsharp.Cursor_getDefaultArgType(this); - public CXCursor Definition => clang.getCursorDefinition(this); + public CXCursor Definition => clangsharp.Cursor_getDefinition(this); public CXCursor DependentLambdaCallOperator => clangsharp.Cursor_getDependentLambdaCallOperator(this); - public CXCursor DescribedClassTemplate => clangsharp.Cursor_getDescribedClassTemplate(this); + public CXCursor DescribedCursorTemplate => clangsharp.Cursor_getDescribedCursorTemplate(this); public CXCursor DescribedTemplate => clangsharp.Cursor_getDescribedTemplate(this); public CXCursor Destructor => clangsharp.Cursor_getDestructor(this); - public CXCursor DirectCallee => clangsharp.Cursor_getDirectCallee(this); - public CXString DisplayName => clang.getCursorDisplayName(this); public bool DoesNotEscape => clangsharp.Cursor_getDoesNotEscape(this) != 0; + public bool DoesUsualArrayDeleteWantSize => clangsharp.Cursor_getDoesUsualArrayDeleteWantSize(this) != 0; + public ulong EnumConstantDeclUnsignedValue => clang.getEnumConstantDeclUnsignedValue(this); public long EnumConstantDeclValue => clang.getEnumConstantDeclValue(this); @@ -694,9 +692,9 @@ public string DeclKindSpelling public int ExceptionSpecificationType => clang.getCursorExceptionSpecificationType(this); - public CXSourceRange Extent => clang.getCursorExtent(this); + public CX_ExprDependence ExprDependence => clangsharp.Cursor_getExprDependence(this); - public CXCursor FalseExpr => clangsharp.Cursor_getFalseExpr(this); + public CXSourceRange Extent => clang.getCursorExtent(this); public CX_FloatingSemantics FloatingLiteralSemantics => clangsharp.Cursor_getFloatingLiteralSemantics(this); @@ -706,15 +704,17 @@ public string DeclKindSpelling public int FieldIndex => clangsharp.Cursor_getFieldIndex(this); + public CXCursor FoundDecl => clangsharp.Cursor_getFoundDecl(this); + public CXCursor FriendDecl => clangsharp.Cursor_getFriendDecl(this); public int FunctionScopeDepth => clangsharp.Cursor_getFunctionScopeDepth(this); public int FunctionScopeIndex => clangsharp.Cursor_getFunctionScopeIndex(this); - public CXType FunctionType => clangsharp.Cursor_getFunctionType(this); + public Guid GuidValue => clangsharp.Cursor_getGuidValue(this); - public Guid GuidValue => throw null; // clangsharp.Cursor_getGuidValue(this); + public bool HadMultipleCandidates => clangsharp.Cursor_getHadMultipleCandidates(this) != 0; public bool HasAttrs => clang.Cursor_hasAttrs(this) != 0; @@ -722,6 +722,8 @@ public string DeclKindSpelling public bool HasDefaultArg => clangsharp.Cursor_getHasDefaultArg(this) != 0; + public bool HasElseStorage => clangsharp.Cursor_getHasElseStorage(this) != 0; + public bool HasExplicitTemplateArgs => clangsharp.Cursor_getHasExplicitTemplateArgs(this) != 0; public bool HasExternalStorage => clangsharp.Cursor_getHasExternalStorage(this) != 0; @@ -734,30 +736,56 @@ public string DeclKindSpelling public bool HasInit => clangsharp.Cursor_getHasInit(this) != 0; + public bool HasInitStorage => clangsharp.Cursor_getHasInitStorage(this) != 0; + + public bool HasLeadingEmptyMacro => clangsharp.Cursor_getHasLeadingEmptyMacro(this) != 0; + public bool HasLocalStorage => clangsharp.Cursor_getHasLocalStorage(this) != 0; public bool HasPlaceholderTypeConstraint => clangsharp.Cursor_getHasPlaceholderTypeConstraint(this) != 0; public uint Hash => clang.hashCursor(this); - public CXCursor HoldingVar => clangsharp.Cursor_getHoldingVar(this); + public bool HasTemplateKeyword => clangsharp.Cursor_getHasTemplateKeyword(this) != 0; - public CXType IBOutletCollectionType => clang.getIBOutletCollectionType(this); + public bool HasUserDeclaredConstructor => clangsharp.Cursor_getHasUserDeclaredConstructor(this) != 0; - public CXCursor IdxExpr => clangsharp.Cursor_getIdxExpr(this); + public bool HasUserDeclaredCopyAssignment => clangsharp.Cursor_getHasUserDeclaredCopyAssignment(this) != 0; - public CXFile IncludedFile => (CXFile)clang.getIncludedFile(this); + public bool HasUserDeclaredCopyConstructor => clangsharp.Cursor_getHasUserDeclaredCopyConstructor(this) != 0; + + public bool HasUserDeclaredDestructor => clangsharp.Cursor_getHasUserDeclaredDestructor(this) != 0; + + public bool HasUserDeclaredMoveAssignment => clangsharp.Cursor_getHasUserDeclaredMoveAssignment(this) != 0; + + public bool HasUserDeclaredMoveConstructor => clangsharp.Cursor_getHasUserDeclaredMoveConstructor(this) != 0; + + public bool HasUserDeclaredMoveOperation => clangsharp.Cursor_getHasUserDeclaredMoveOperation(this) != 0; + + public bool HasVarStorage => clangsharp.Cursor_getHasVarStorage(this) != 0; - public CXCursor IncExpr => clangsharp.Cursor_getIncExpr(this); + public CXType IBOutletCollectionType => clang.getIBOutletCollectionType(this); + + public CXFile IncludedFile => (CXFile)clang.getIncludedFile(this); public CXCursor InClassInitializer => clangsharp.Cursor_getInClassInitializer(this); + public CXCursor InheritedConstructor => clangsharp.Cursor_getInheritedConstructor(this); + + public bool InheritedFromVBase => clangsharp.Cursor_getInheritedFromVBase(this) != 0; + public CXCursor InitExpr => clangsharp.Cursor_getInitExpr(this); + public CXType InjectedSpecializationType => clangsharp.Cursor_getInjectedSpecializationType(this); + public CXCursor InstantiatedFromMember => clangsharp.Cursor_getInstantiatedFromMember(this); public long IntegerLiteralValue => clangsharp.Cursor_getIntegerLiteralValue(this); + public bool IsAllEnumCasesCovered => clangsharp.Cursor_getIsAllEnumCasesCovered(this) != 0; + + public bool IsAlwaysNull => clangsharp.Cursor_getIsAlwaysNull(this) != 0; + public bool IsAnonymous => clang.Cursor_isAnonymous(this) != 0; public bool IsAnonymousRecordDecl => clang.Cursor_isAnonymousRecordDecl(this) != 0; @@ -766,44 +794,80 @@ public string DeclKindSpelling public bool IsArgumentType => clangsharp.Cursor_getIsArgumentType(this) != 0; + public bool IsArrayForm => clangsharp.Cursor_getIsArrayForm(this) != 0; + + public bool IsArrayFormAsWritten => clangsharp.Cursor_getIsArrayFormAsWritten(this) != 0; + + public bool IsArrow => clangsharp.Cursor_getIsArrow(this) != 0; + public bool IsAttribute => clang.isAttribute(Kind) != 0; public bool IsBitField => clang.Cursor_isBitField(this) != 0; public bool IsCanonical => Equals(CanonicalCursor); + public bool IsClassExtension => clangsharp.Cursor_getIsClassExtension(this) != 0; + + public bool IsCompleteDefinition => clangsharp.Cursor_getIsCompleteDefinition(this) != 0; + + public bool IsConditionTrue => clangsharp.Cursor_getIsConditionTrue(this) != 0; + + public bool IsConstexpr => clangsharp.Cursor_getIsConstexpr(this) != 0; + public bool IsConversionFromLambda => clangsharp.Cursor_getIsConversionFromLambda(this) != 0; + public bool IsCopyOrMoveConstructor => clangsharp.Cursor_getIsCopyOrMoveConstructor(this) != 0; + + public bool IsCXXTry => clangsharp.Cursor_getIsCXXTry(this) != 0; + public bool IsDeclaration => clang.isDeclaration(Kind) != 0; public bool IsDefined => clangsharp.Cursor_getIsDefined(this) != 0; public bool IsDefinition => clang.isCursorDefinition(this) != 0; + public bool IsDelegatingConstructor => clangsharp.Cursor_getIsDelegatingConstructor(this) != 0; + + public bool IsDeleted => clangsharp.Cursor_getIsDeleted(this) != 0; + public bool IsDeprecated => clangsharp.Cursor_getIsDeprecated(this) != 0; public bool IsDynamicCall => clang.Cursor_isDynamicCall(this) != 0; + public bool IsElidable => clangsharp.Cursor_getIsElidable(this) != 0; + + public bool IsExplicitlyDefaulted => clangsharp.Cursor_getIsExplicitlyDefaulted(this) != 0; + public bool IsExpression => clang.isExpression(Kind) != 0; public bool IsExternC => clangsharp.Cursor_getIsExternC(this) != 0; public bool IsExpandedParameterPack => clangsharp.Cursor_getIsExpandedParameterPack(this) != 0; + public bool IsFileScope => clangsharp.Cursor_getIsFileScope(this) != 0; + public bool IsFunctionInlined => clang.Cursor_isFunctionInlined(this) != 0; public bool IsGlobal => clangsharp.Cursor_getIsGlobal(this) != 0; - public bool IsImplicitAccess => clangsharp.Cursor_getIsImplicitAccess(this) != 0; + public bool IsInjectedClassName => clangsharp.Cursor_getIsInjectedClassName(this) != 0; public bool IsInlineNamespace => clang.Cursor_isInlineNamespace(this) != 0; - public bool IsIncomplete => throw null; // clangsharp.Cursor_getIsIncomplete(this) != 0; + public bool IsIfExists => clangsharp.Cursor_getIsIfExists(this) != 0; + + public bool IsImplicit => clangsharp.Cursor_getIsImplicit(this) != 0; + + public bool IsIncomplete => clangsharp.Cursor_getIsIncomplete(this) != 0; + + public bool IsInheritingConstructor => clangsharp.Cursor_getIsInheritingConstructor(this) != 0; public bool IsInvalid => clang.isInvalid(Kind) != 0; public bool IsInvalidDeclaration => clang.isInvalidDeclaration(this) != 0; + public bool IsListInitialization => clangsharp.Cursor_getIsListInitialization(this) != 0; + public bool IsLocalVarDecl => clangsharp.Cursor_getIsLocalVarDecl(this) != 0; public bool IsLocalVarDeclOrParm => clangsharp.Cursor_getIsLocalVarDeclOrParm(this) != 0; @@ -832,12 +896,20 @@ public string DeclKindSpelling public bool IsParameterPack => clangsharp.Cursor_getIsParameterPack(this) != 0; + public bool IsPartiallySubstituted => clangsharp.Cursor_getIsPartiallySubstituted(this) != 0; + + public bool IsPotentiallyEvaluated => clangsharp.Cursor_getIsPotentiallyEvaluated(this) != 0; + public bool IsPreprocessing => clang.isPreprocessing(Kind) != 0; public bool IsPure => clangsharp.Cursor_getIsPure(this) != 0; public bool IsReference => clang.isReference(Kind) != 0; + public bool IsResultDependent => clangsharp.Cursor_getIsResultDependent(this) != 0; + + public bool IsStdInitListInitialization => clangsharp.Cursor_getIsStdInitListInitialization(this) != 0; + public bool IsSigned => clangsharp.Cursor_getIsSigned(this) != 0; public bool IsStatement => clang.isStatement(Kind) != 0; @@ -852,16 +924,18 @@ public string DeclKindSpelling public bool IsThisDeclarationADefinition => clangsharp.Cursor_getIsThisDeclarationADefinition(this) != 0; + public bool IsThrownVariableInScope => clangsharp.Cursor_getIsThrownVariableInScope(this) != 0; + public bool IsTranslationUnit => clang.isTranslationUnit(Kind) != 0; - public bool IsTransparentTag => clangsharp.Cursor_getIsTransparentTag(this) != 0; + public bool IsTransparent => clangsharp.Cursor_getIsTransparent(this) != 0; public bool IsTypeConcept => clangsharp.Cursor_getIsTypeConcept(this) != 0; - public bool IsTypeOperand => clangsharp.Cursor_getIsTypeOperand(this) != 0; - public bool IsUnavailable => clangsharp.Cursor_getIsUnavailable(this) != 0; + public bool IsUnconditionallyVisible => clangsharp.Cursor_getIsUnconditionallyVisible(this) != 0; + public bool IsUnexposed => clang.isUnexposed(Kind) != 0; public bool IsUnnamedBitfield => clangsharp.Cursor_getIsUnnamedBitfield(this) != 0; @@ -870,6 +944,8 @@ public string DeclKindSpelling public bool IsUnsupportedFriend => clangsharp.Cursor_getIsUnsupportedFriend(this) != 0; + public bool IsUserProvided => clangsharp.Cursor_getIsUserProvided(this) != 0; + public bool IsVariadic => clangsharp.Cursor_getIsVariadic(this) != 0; public bool IsVirtualBase => clang.isVirtualBase(this) != 0; @@ -902,7 +978,7 @@ public string DeclKindSpelling public CXCursor MostRecentDecl => clangsharp.Cursor_getMostRecentDecl(this); - public CXCursor MostRecentNonInjectedDecl => clangsharp.Cursor_getMostRecentNonInjectedDecl(this); + public CXString Name => clangsharp.Cursor_getName(this); public CXCursor NextDeclInContext => clangsharp.Cursor_getNextDeclInContext(this); @@ -918,16 +994,46 @@ public string DeclKindSpelling public int NumArguments => clangsharp.Cursor_getNumArguments(this); + public int NumAssocs => clangsharp.Cursor_getNumAssocs(this); + + public int NumAttrs => clangsharp.Cursor_getNumAttrs(this); + + public int NumBases => clangsharp.Cursor_getNumBases(this); + + public int NumBindings => clangsharp.Cursor_getNumBindings(this); + public int NumCaptures => clangsharp.Cursor_getNumCaptures(this); + public int NumChildren => clangsharp.Cursor_getNumChildren(this); + + public int NumCtors => clangsharp.Cursor_getNumCtors(this); + + public int NumDecls => clangsharp.Cursor_getNumDecls(this); + + public int NumEnumerators => clangsharp.Cursor_getNumEnumerators(this); + + public int NumExpansionTypes => clangsharp.Cursor_getNumExpansionTypes(this); + public int NumExprs => clangsharp.Cursor_getNumExprs(this); + public int NumFields => clangsharp.Cursor_getNumFields(this); + + public int NumFriends => clangsharp.Cursor_getNumFriends(this); + + public int NumMethods => clangsharp.Cursor_getNumMethods(this); + public uint NumOverloadedDecls => clang.getNumOverloadedDecls(this); + public int NumProtocols => clangsharp.Cursor_getNumProtocols(this); + public int NumSpecializations => clangsharp.Cursor_getNumSpecializations(this); public int NumTemplateArguments => clangsharp.Cursor_getNumTemplateArguments(this); + public int NumTemplateParameterLists => clangsharp.Cursor_getNumTemplateParameterLists(this); + + public int NumVBases => clangsharp.Cursor_getNumVBases(this); + public CXObjCDeclQualifierKind ObjCDeclQualifiers => (CXObjCDeclQualifierKind)clang.Cursor_getObjCDeclQualifiers(this); public CXStringSet* ObjCManglings => clang.Cursor_getObjCManglings(this); @@ -940,10 +1046,12 @@ public string DeclKindSpelling public long OffsetOfField => clang.Cursor_getOffsetOfField(this); - public CXCursor OpaqueValueExpr => clangsharp.Cursor_getOpaqueValueExpr(this); + public CXCursor OpaqueValue => clangsharp.Cursor_getOpaqueValue(this); public CXType OriginalType => clangsharp.Cursor_getOriginalType(this); + public CX_OverloadedOperatorKind OverloadedOperatorKind => clangsharp.Cursor_getOverloadedOperatorKind(this); + public ReadOnlySpan OverriddenCursors { get @@ -956,6 +1064,8 @@ public ReadOnlySpan OverriddenCursors } } + public int PackLength => clangsharp.Cursor_getPackLength(this); + public CXCursor ParentFunctionOrMethod => clangsharp.Cursor_getParentFunctionOrMethod(this); public CXComment ParsedComment => clang.Cursor_getParsedComment(this); @@ -972,18 +1082,24 @@ public ReadOnlySpan OverriddenCursors public CXType ReceiverType => !IsExpression ? default : clang.Cursor_getReceiverType(this); + public CXCursor RedeclContext => clangsharp.Cursor_getRedeclContext(this); + public CXCursor Referenced => clangsharp.Cursor_getReferenced(this); + public bool RequiresZeroInitialization => clangsharp.Cursor_getRequiresZeroInitialization(this) != 0; + + public int ResultIndex => clangsharp.Cursor_getResultIndex(this); + public CXType ResultType => clang.getCursorResultType(this); public CXType ReturnType => clangsharp.Cursor_getReturnType(this); public CXCursor RhsExpr => clangsharp.Cursor_getRhsExpr(this); - public CXCursor RowIdxExpr => throw null; // clangsharp.Cursor_getRowIdxExpr(this); - public CXCursor SemanticParent => clang.getCursorSemanticParent(this); + public bool ShouldCopy => clangsharp.Cursor_getShouldCopy(this) != 0; + public CXSourceRange SourceRange => clangsharp.Cursor_getSourceRange(this); public CXCursor SpecializedCursorTemplate => clang.getSpecializedCursorTemplate(this); @@ -1262,7 +1378,7 @@ public string StmtClassSpelling public CXCursor SubStmt => clangsharp.Cursor_getSubStmt(this); - public CXCursor TargetUnionField => (CastKind == CX_CastKind.CX_CK_ToUnion) ? clangsharp.Cursor_getTargetUnionField(this) : Null; + public CXCursor TargetUnionField => clangsharp.Cursor_getTargetUnionField(this); public CXCursorKind TemplateCursorKind => clang.getTemplateCursorKind(this); @@ -1276,6 +1392,8 @@ public string StmtClassSpelling public int TemplateTypeParmIndex => clangsharp.Cursor_getTemplateTypeParmIndex(this); + public int TemplateTypeParmPosition => clangsharp.Cursor_getTemplateTypeParmPosition(this); + public CXType ThisObjectType => clangsharp.Cursor_getThisObjectType(this); public CXType ThisType => clangsharp.Cursor_getThisType(this); @@ -1284,8 +1402,6 @@ public string StmtClassSpelling public CXCursor TrailingRequiresClause => clangsharp.Cursor_getTrailingRequiresClause(this); - public CXCursor TrueExpr => clangsharp.Cursor_getTrueExpr(this); - public CXTranslationUnit TranslationUnit => clang.Cursor_getTranslationUnit(this); public CXType Type => clang.getCursorType(this); @@ -1312,6 +1428,8 @@ public string StmtClassSpelling public CXVisibilityKind Visibility => clang.getCursorVisibility(this); + public long VtblIdx => clangsharp.Cursor_getVtblIdx(this); + internal string DebuggerDisplayString { get @@ -1374,8 +1492,20 @@ public void DisposeOverriddenCursors(ReadOnlySpan overridden) public CXCursor GetArgument(uint index) => clangsharp.Cursor_getArgument(this, index); + public CXCursor GetAttr(uint index) => clangsharp.Cursor_getAttr(this, index); + + public CXCursor GetBase(uint index) => clangsharp.Cursor_getBase(this, index); + + public CXCursor GetBindingDecl(uint index) => clangsharp.Cursor_getBindingDecl(this, index); + + public CXCursor GetCtor(uint index) => clangsharp.Cursor_getCtor(this, index); + public CXCursor GetCaptureCopyExpr(uint index) => clangsharp.Cursor_getCaptureCopyExpr(this, index); + public CXCursor GetCapturedVar(uint index) => clangsharp.Cursor_getCapturedVar(this, index); + + public CX_VariableCaptureKind GetCaptureKind(uint index) => clangsharp.Cursor_getCaptureKind(this, index); + public bool GetCaptureHasCopyExpr(uint index) => clangsharp.Cursor_getCaptureHasCopyExpr(this, index) != 0; public bool GetCaptureIsByRef(uint index) => clangsharp.Cursor_getCaptureIsByRef(this, index) != 0; @@ -1388,6 +1518,10 @@ public void DisposeOverriddenCursors(ReadOnlySpan overridden) public CXCursor GetCaptureVariable(uint index) => clangsharp.Cursor_getCaptureVariable(this, index); + public CXCursor GetChild(uint index) => clangsharp.Cursor_getChild(this, index); + + public CXCursor GetDecl(uint index) => clangsharp.Cursor_getDecl(this, index); + public void GetDefinitionSpellingAndExtent(out string spelling, out uint startLine, out uint startColumn, out uint endLine, out uint endColumn) { fixed (uint* pStartLine = &startLine) @@ -1402,8 +1536,16 @@ public void GetDefinitionSpellingAndExtent(out string spelling, out uint startLi } } + public CXCursor GetEnumerator(uint index) => clangsharp.Cursor_getEnumerator(this, index); + + public CXType GetExpansionType(uint index) => clangsharp.Cursor_getExpansionType(this, index); + public CXCursor GetExpr(uint index) => clangsharp.Cursor_getExpr(this, index); + public CXCursor GetField(uint index) => clangsharp.Cursor_getField(this, index); + + public CXCursor GetFriend(uint index) => clangsharp.Cursor_getFriend(this, index); + public override int GetHashCode() => (int)Hash; public bool GetIsExternalSymbol(out CXString language, out CXString definedIn, out bool isGenerated) @@ -1418,6 +1560,10 @@ public bool GetIsExternalSymbol(out CXString language, out CXString definedIn, o } } + public CXCursor GetMethod(uint index) => clangsharp.Cursor_getMethod(this, index); + + public int GetNumTemplateParameters(uint listIndex) => clangsharp.Cursor_getNumTemplateParameters(this, listIndex); + public CXObjCPropertyAttrKind GetObjCPropertyAttributes(uint reserved) => (CXObjCPropertyAttrKind)clang.Cursor_getObjCPropertyAttributes(this, reserved); public CXCursor GetOverloadedDecl(uint index) => clang.getOverloadedDecl(this, index); @@ -1439,37 +1585,21 @@ public int GetPlatformAvailability(out bool alwaysDeprecated, out CXString depre public CXString GetPrettyPrinted(CXPrintingPolicy policy) => clang.getCursorPrettyPrinted(this, policy); + public CXCursor GetProtocol(uint index) => clangsharp.Cursor_getProtocol(this, index); + public CXSourceRange GetReferenceNameRange(CXNameRefFlags nameFlags, uint pieceIndex) => clang.getCursorReferenceNameRange(this, (uint)nameFlags, pieceIndex); public CXCursor GetSpecialization(uint index) => clangsharp.Cursor_getSpecialization(this, index); public CXSourceRange GetSpellingNameRange(uint pieceIndex, uint options) => clang.Cursor_getSpellingNameRange(this, pieceIndex, options); - public CXCursor GetTemplateArgument(uint index) => clangsharp.Cursor_getTemplateArgument(this, index); - - public CXCursor GetTemplateArgumentAsDecl(uint i) => clangsharp.Cursor_getTemplateArgumentAsDecl(this, i); - - public CXCursor GetTemplateArgumentAsExpr(uint i) => clangsharp.Cursor_getTemplateArgumentAsExpr(this, i); - - public long GetTemplateArgumentAsIntegral(uint i) => clangsharp.Cursor_getTemplateArgumentAsIntegral(this, i); + public CXCursor GetSubDecl(uint i) => clangsharp.Cursor_getSubDecl(this, i); - public CXType GetTemplateArgumentAsType(uint i) => clangsharp.Cursor_getTemplateArgumentAsType(this, i); + public CX_TemplateArgument GetTemplateArgument(uint index) => clangsharp.Cursor_getTemplateArgument(this, index); - public CXType GetTemplateArgumentIntegralType(uint i) => clangsharp.Cursor_getTemplateArgumentIntegralType(this, i); + public CX_TemplateArgumentLoc GetTemplateArgumentLoc(uint index) => clangsharp.Cursor_getTemplateArgumentLoc(this, index); - public CXTemplateArgumentKind GetTemplateArgumentKind(uint i) => clangsharp.Cursor_getTemplateArgumentKind(this, i); - - public CXSourceLocation GetTemplateArgumentLocLocation(uint i) => clangsharp.Cursor_getTemplateArgumentLocLocation(this, i); - - public CXCursor GetTemplateArgumentLocSourceDeclExpression(uint i) => clangsharp.Cursor_getTemplateArgumentLocSourceDeclExpression(this, i); - - public CXCursor GetTemplateArgumentLocSourceExpression(uint i) => clangsharp.Cursor_getTemplateArgumentLocSourceExpression(this, i); - - public CXCursor GetTemplateArgumentLocSourceIntegralExpression(uint i) => clangsharp.Cursor_getTemplateArgumentLocSourceIntegralExpression(this, i); - - public CXCursor GetTemplateArgumentLocSourceNullPtrExpression(uint i) => clangsharp.Cursor_getTemplateArgumentLocSourceNullPtrExpression(this, i); - - public CXType GetTemplateArgumentNullPtrType(uint i) => clangsharp.Cursor_getTemplateArgumentNullPtrType(this, i); + public CXCursor GetTemplateParameter(uint listIndex, uint parameterIndex) => clangsharp.Cursor_getTemplateParameter(this, listIndex, parameterIndex); public CXType GetTemplateArgumentType(uint i) => clang.Cursor_getTemplateArgumentType(this, i); @@ -1477,6 +1607,8 @@ public int GetPlatformAvailability(out bool alwaysDeprecated, out CXString depre public long GetTemplateArgumentValue(uint i) => clang.Cursor_getTemplateArgumentValue(this, i); + public CXCursor GetVBase(uint index) => clangsharp.Cursor_getVBase(this, index); + public override string ToString() => Spelling.ToString(); public CXChildVisitResult VisitChildren(CXCursorVisitor visitor, CXClientData clientData) diff --git a/sources/ClangSharp/Interop.Extensions/CXType.cs b/sources/ClangSharp/Interop.Extensions/CXType.cs index 4296638e..152cc203 100644 --- a/sources/ClangSharp/Interop.Extensions/CXType.cs +++ b/sources/ClangSharp/Interop.Extensions/CXType.cs @@ -29,7 +29,7 @@ public unsafe partial struct CXType : IEquatable public CXType ClassType => clang.Type_getClassType(this); - public CXCursor ColumnExpr => throw null; // clangsharp.Type_getColumnExpr(this); + public CXCursor ColumnExpr => clangsharp.Type_getColumnExpr(this); public CXRefQualifierKind CXXRefQualifier => clang.Type_getCXXRefQualifier(this); @@ -41,6 +41,8 @@ public unsafe partial struct CXType : IEquatable public int Depth => clangsharp.Type_getDepth(this); + public CXType Desugar => clangsharp.Type_desugar(this); + public CXType ElementType => clangsharp.Type_getElementType(this); public CXType EquivalentType => clangsharp.Type_getEquivalentType(this); @@ -65,7 +67,7 @@ public unsafe partial struct CXType : IEquatable public bool IsRestrictQualified => clang.isRestrictQualifiedType(this) != 0; - public bool IsSigned => throw null; // clangsharp.Type_getIsSigned(this) != 0; + public bool IsSigned => clangsharp.Type_getIsSigned(this) != 0; public bool IsSugared => clangsharp.Type_getIsSugared(this) != 0; @@ -73,7 +75,7 @@ public unsafe partial struct CXType : IEquatable public bool IsTypeAlias => clangsharp.Type_getIsTypeAlias(this) != 0; - public bool IsUnsigned => throw null; // clangsharp.Type_getIsUnsigned(this) != 0; + public bool IsUnsigned => clangsharp.Type_getIsUnsigned(this) != 0; public bool IsVolatileQualified => clang.isVolatileQualifiedType(this) != 0; @@ -87,15 +89,15 @@ public unsafe partial struct CXType : IEquatable public int NumArgTypes => clang.getNumArgTypes(this); - public int NumBits => throw null; // clangsharp.Type_getNumBits(this); + public int NumBits => clangsharp.Type_getNumBits(this); - public CXCursor NumBitsExpr => throw null; // clangsharp.Type_getNumBitsExpr(this); + public CXCursor NumBitsExpr => clangsharp.Type_getNumBitsExpr(this); - public int NumColumns => throw null; // clangsharp.Type_getNumColumns(this); + public int NumColumns => clangsharp.Type_getNumColumns(this); - public int NumElementsFlattened => throw null; // clangsharp.Type_getNumElementsFlattened(this); + public int NumElementsFlattened => clangsharp.Type_getNumElementsFlattened(this); - public int NumRows => throw null; // clangsharp.Type_getNumRows(this); + public int NumRows => clangsharp.Type_getNumRows(this); public long NumElements => clang.getNumElements(this); @@ -115,7 +117,7 @@ public unsafe partial struct CXType : IEquatable public CXType ResultType => clang.getResultType(this); - public CXCursor RowExpr => throw null; // clangsharp.Type_getRowExpr(this); + public CXCursor RowExpr => clangsharp.Type_getRowExpr(this); public CXCursor SizeExpr => clangsharp.Type_getSizeExpr(this); @@ -123,6 +125,8 @@ public unsafe partial struct CXType : IEquatable public CXString Spelling => clang.getTypeSpelling(this); + public CX_TemplateName TemplateName => clangsharp.Type_getTemplateName(this); + public CX_TypeClass TypeClass => clangsharp.Type_getTypeClass(this); public string TypeClassSpelling @@ -199,7 +203,7 @@ public string TypeClassSpelling public CXType UnderlyingType => clangsharp.Type_getUnderlyingType(this); - public CXType ValueType => throw null; // clang.Type_getValueType(this); + public CXType ValueType => clang.Type_getValueType(this); internal string DebuggerDisplayString { @@ -213,8 +217,6 @@ internal string DebuggerDisplayString public static bool operator !=(CXType left, CXType right) => clang.equalTypes(left, right) == 0; - public CXType Desugar() => clangsharp.Type_desugar(this); - public override bool Equals(object obj) => (obj is CXType other) && Equals(other); public bool Equals(CXType other) => this == other; @@ -235,19 +237,7 @@ public long GetOffsetOf(string s) return clang.Type_getOffsetOf(this, marshaledS); } - public CXCursor GetTemplateArgumentAsDecl(uint i) => clangsharp.Type_getTemplateArgumentAsDecl(this, i); - - public CXCursor GetTemplateArgumentAsExpr(uint i) => clangsharp.Type_getTemplateArgumentAsExpr(this, i); - - public long GetTemplateArgumentAsIntegral(uint i) => clangsharp.Type_getTemplateArgumentAsIntegral(this, i); - - public CXType GetTemplateArgumentAsType(uint i) => clangsharp.Type_getTemplateArgumentAsType(this, i); - - public CXType GetTemplateArgumentIntegralType(uint i) => clangsharp.Type_getTemplateArgumentIntegralType(this, i); - - public CXTemplateArgumentKind GetTemplateArgumentKind(uint i) => clangsharp.Type_getTemplateArgumentKind(this, i); - - public CXType GetTemplateArgumentNullPtrType(uint i) => clangsharp.Type_getTemplateArgumentNullPtrType(this, i); + public CX_TemplateArgument GetTemplateArgument(uint i) => clangsharp.Type_getTemplateArgument(this, i); public override string ToString() => Spelling.ToString(); diff --git a/sources/ClangSharp/Interop.Extensions/CX_TemplateArgument.cs b/sources/ClangSharp/Interop.Extensions/CX_TemplateArgument.cs new file mode 100644 index 00000000..95a61ccd --- /dev/null +++ b/sources/ClangSharp/Interop.Extensions/CX_TemplateArgument.cs @@ -0,0 +1,39 @@ +// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. + +using System; + +namespace ClangSharp.Interop +{ + public unsafe partial struct CX_TemplateArgument : IDisposable + { + public CXCursor AsDecl => clangsharp.TemplateArgument_getAsDecl(this); + + public CXCursor AsExpr => clangsharp.TemplateArgument_getAsExpr(this); + + public long AsIntegral => clangsharp.TemplateArgument_getAsIntegral(this); + + public CX_TemplateName AsTemplate => clangsharp.TemplateArgument_getAsTemplate(this); + + public CX_TemplateName AsTemplateOrTemplatePattern => clangsharp.TemplateArgument_getAsTemplateOrTemplatePattern(this); + + public CXType AsType => clangsharp.TemplateArgument_getAsType(this); + + public CX_TemplateArgumentDependence Dependence => clangsharp.TemplateArgument_getDependence(this); + + public CXType IntegralType => clangsharp.TemplateArgument_getIntegralType(this); + + public CXType NonTypeTemplateArgumentType => clangsharp.TemplateArgument_getNonTypeTemplateArgumentType(this); + + public CXType NullPtrType => clangsharp.TemplateArgument_getNullPtrType(this); + + public int NumPackElements => clangsharp.TemplateArgument_getNumPackElements(this); + + public CX_TemplateArgument PackExpansionPattern => clangsharp.TemplateArgument_getPackExpansionPattern(this); + + public CXType ParamTypeForDecl => clangsharp.TemplateArgument_getParamTypeForDecl(this); + + public CX_TemplateArgument GetPackElement(uint i) => clangsharp.TemplateArgument_getPackElement(this, i); + + public void Dispose() => clangsharp.TemplateArgument_dispose(this); + } +} diff --git a/sources/ClangSharp/Interop.Extensions/CX_TemplateArgumentLoc.cs b/sources/ClangSharp/Interop.Extensions/CX_TemplateArgumentLoc.cs new file mode 100644 index 00000000..87ca375a --- /dev/null +++ b/sources/ClangSharp/Interop.Extensions/CX_TemplateArgumentLoc.cs @@ -0,0 +1,21 @@ +// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. + +namespace ClangSharp.Interop +{ + public unsafe partial struct CX_TemplateArgumentLoc + { + public CX_TemplateArgument Argument => clangsharp.TemplateArgumentLoc_getArgument(this); + + public CXSourceLocation Location => clangsharp.TemplateArgumentLoc_getLocation(this); + + public CXCursor SourceDeclExpression => clangsharp.TemplateArgumentLoc_getSourceDeclExpression(this); + + public CXCursor SourceExpression => clangsharp.TemplateArgumentLoc_getSourceExpression(this); + + public CXCursor SourceIntegralExpression => clangsharp.TemplateArgumentLoc_getSourceIntegralExpression(this); + + public CXCursor SourceNullPtrExpression => clangsharp.TemplateArgumentLoc_getSourceNullPtrExpression(this); + + public CXSourceRange SourceRange => clangsharp.TemplateArgumentLoc_getSourceRange(this); + } +} diff --git a/sources/ClangSharp/Interop.Extensions/CX_TemplateName.cs b/sources/ClangSharp/Interop.Extensions/CX_TemplateName.cs new file mode 100644 index 00000000..9575cf9a --- /dev/null +++ b/sources/ClangSharp/Interop.Extensions/CX_TemplateName.cs @@ -0,0 +1,10 @@ +// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +// Ported from https://github.com/microsoft/ClangSharp/blob/master/sources/libClangSharp + +namespace ClangSharp.Interop +{ + public unsafe partial struct CX_TemplateName + { + public CXCursor AsTemplateDecl => clangsharp.TemplateName_getAsTemplateDecl(this); + } +} diff --git a/sources/ClangSharp/Interop/CX_AtomicOperatorKind.cs b/sources/ClangSharp/Interop/CX_AtomicOperatorKind.cs new file mode 100644 index 00000000..cdefc3a0 --- /dev/null +++ b/sources/ClangSharp/Interop/CX_AtomicOperatorKind.cs @@ -0,0 +1,60 @@ +// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +// Ported from https://github.com/microsoft/ClangSharp/blob/master/sources/libClangSharp + +namespace ClangSharp.Interop +{ + public enum CX_AtomicOperatorKind + { + CX_AO_Invalid, + CX_AO__c11_atomic_init, + CX_AO__c11_atomic_load, + CX_AO__c11_atomic_store, + CX_AO__c11_atomic_exchange, + CX_AO__c11_atomic_compare_exchange_strong, + CX_AO__c11_atomic_compare_exchange_weak, + CX_AO__c11_atomic_fetch_add, + CX_AO__c11_atomic_fetch_sub, + CX_AO__c11_atomic_fetch_and, + CX_AO__c11_atomic_fetch_or, + CX_AO__c11_atomic_fetch_xor, + CX_AO__c11_atomic_fetch_max, + CX_AO__c11_atomic_fetch_min, + CX_AO__atomic_load, + CX_AO__atomic_load_n, + CX_AO__atomic_store, + CX_AO__atomic_store_n, + CX_AO__atomic_exchange, + CX_AO__atomic_exchange_n, + CX_AO__atomic_compare_exchange, + CX_AO__atomic_compare_exchange_n, + CX_AO__atomic_fetch_add, + CX_AO__atomic_fetch_sub, + CX_AO__atomic_fetch_and, + CX_AO__atomic_fetch_or, + CX_AO__atomic_fetch_xor, + CX_AO__atomic_fetch_nand, + CX_AO__atomic_add_fetch, + CX_AO__atomic_sub_fetch, + CX_AO__atomic_and_fetch, + CX_AO__atomic_or_fetch, + CX_AO__atomic_xor_fetch, + CX_AO__atomic_max_fetch, + CX_AO__atomic_min_fetch, + CX_AO__atomic_nand_fetch, + CX_AO__opencl_atomic_init, + CX_AO__opencl_atomic_load, + CX_AO__opencl_atomic_store, + CX_AO__opencl_atomic_exchange, + CX_AO__opencl_atomic_compare_exchange_strong, + CX_AO__opencl_atomic_compare_exchange_weak, + CX_AO__opencl_atomic_fetch_add, + CX_AO__opencl_atomic_fetch_sub, + CX_AO__opencl_atomic_fetch_and, + CX_AO__opencl_atomic_fetch_or, + CX_AO__opencl_atomic_fetch_xor, + CX_AO__opencl_atomic_fetch_min, + CX_AO__opencl_atomic_fetch_max, + CX_AO__atomic_fetch_min, + CX_AO__atomic_fetch_max, + } +} diff --git a/sources/ClangSharp/Interop/CX_CapturedRegionKind.cs b/sources/ClangSharp/Interop/CX_CapturedRegionKind.cs new file mode 100644 index 00000000..d302ec73 --- /dev/null +++ b/sources/ClangSharp/Interop/CX_CapturedRegionKind.cs @@ -0,0 +1,13 @@ +// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +// Ported from https://github.com/microsoft/ClangSharp/blob/master/sources/libClangSharp + +namespace ClangSharp.Interop +{ + public enum CX_CapturedRegionKind + { + CX_CR_Invalid, + CX_CR_Default, + CX_CR_ObjCAtFinally, + CX_CR_OpenMP, + } +} diff --git a/sources/ClangSharp/Interop/CX_ConstructionKind.cs b/sources/ClangSharp/Interop/CX_ConstructionKind.cs new file mode 100644 index 00000000..7dfd88c9 --- /dev/null +++ b/sources/ClangSharp/Interop/CX_ConstructionKind.cs @@ -0,0 +1,14 @@ +// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +// Ported from https://github.com/microsoft/ClangSharp/blob/master/sources/libClangSharp + +namespace ClangSharp.Interop +{ + public enum CX_ConstructionKind + { + CX_CK_Invalid, + CX_CK_Complete, + CX_CK_NonVirtualBase, + CX_CK_VirtualBase, + CX_CK_Delegating + } +} diff --git a/sources/ClangSharp/Interop/CX_ExprDependence.cs b/sources/ClangSharp/Interop/CX_ExprDependence.cs new file mode 100644 index 00000000..2bf240fc --- /dev/null +++ b/sources/ClangSharp/Interop/CX_ExprDependence.cs @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +// Ported from https://github.com/microsoft/ClangSharp/blob/master/sources/libClangSharp + +using System; + +namespace ClangSharp.Interop +{ + [Flags] + public enum CX_ExprDependence + { + CX_ED_None = 0, + CX_ED_UnexpandedPack = 1, + CX_ED_Instantiation = 2, + CX_ED_Type = 4, + CX_ED_Value = 8, + CX_ED_Error = 16, + CX_ED_All = 31, + + CX_ED_TypeValue = CX_ED_Type | CX_ED_Value, + CX_ED_TypeInstantiation = CX_ED_Type | CX_ED_Instantiation, + CX_ED_ValueInstantiation = CX_ED_Value | CX_ED_Instantiation, + CX_ED_TypeValueInstantiation = CX_ED_Type | CX_ED_Value | CX_ED_Instantiation, + } +} diff --git a/sources/ClangSharp/Interop/CX_OverloadedOperatorKind.cs b/sources/ClangSharp/Interop/CX_OverloadedOperatorKind.cs new file mode 100644 index 00000000..c663baba --- /dev/null +++ b/sources/ClangSharp/Interop/CX_OverloadedOperatorKind.cs @@ -0,0 +1,55 @@ +// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +// Ported from https://github.com/microsoft/ClangSharp/blob/master/sources/libClangSharp + +namespace ClangSharp.Interop +{ + public enum CX_OverloadedOperatorKind + { + CX_OO_Invalid, + CX_OO_New, + CX_OO_Delete, + CX_OO_Array_New, + CX_OO_Array_Delete, + CX_OO_Plus, + CX_OO_Minus, + CX_OO_Star, + CX_OO_Slash, + CX_OO_Percent, + CX_OO_Caret, + CX_OO_Amp, + CX_OO_Pipe, + CX_OO_Tilde, + CX_OO_Exclaim, + CX_OO_Equal, + CX_OO_Less, + CX_OO_Greater, + CX_OO_PlusEqual, + CX_OO_MinusEqual, + CX_OO_StarEqual, + CX_OO_SlashEqual, + CX_OO_PercentEqual, + CX_OO_CaretEqual, + CX_OO_AmpEqual, + CX_OO_PipeEqual, + CX_OO_LessLess, + CX_OO_GreaterGreater, + CX_OO_LessLessEqual, + CX_OO_GreaterGreaterEqual, + CX_OO_EqualEqual, + CX_OO_ExclaimEqual, + CX_OO_LessEqual, + CX_OO_GreaterEqual, + CX_OO_Spaceship, + CX_OO_AmpAmp, + CX_OO_PipePipe, + CX_OO_PlusPlus, + CX_OO_MinusMinus, + CX_OO_Comma, + CX_OO_ArrowStar, + CX_OO_Arrow, + CX_OO_Call, + CX_OO_Subscript, + CX_OO_Conditional, + CX_OO_Coawait, + } +} diff --git a/sources/ClangSharp/Interop/CX_TemplateArgument.cs b/sources/ClangSharp/Interop/CX_TemplateArgument.cs new file mode 100644 index 00000000..b5ce2cbf --- /dev/null +++ b/sources/ClangSharp/Interop/CX_TemplateArgument.cs @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +// Ported from https://github.com/microsoft/ClangSharp/blob/master/sources/libClangSharp + +namespace ClangSharp.Interop +{ + public unsafe partial struct CX_TemplateArgument + { + public CXTemplateArgumentKind kind; + + public int xdata; + + [NativeTypeName("const clang::TemplateArgument *")] + public void* value; + + [NativeTypeName("CXTranslationUnit")] + public CXTranslationUnitImpl* tu; + } +} diff --git a/sources/ClangSharp/Interop/CX_TemplateArgumentDependence.cs b/sources/ClangSharp/Interop/CX_TemplateArgumentDependence.cs new file mode 100644 index 00000000..b22953bd --- /dev/null +++ b/sources/ClangSharp/Interop/CX_TemplateArgumentDependence.cs @@ -0,0 +1,19 @@ +// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +// Ported from https://github.com/microsoft/ClangSharp/blob/master/sources/libClangSharp + +using System; + +namespace ClangSharp.Interop +{ + [Flags] + public enum CX_TemplateArgumentDependence + { + CX_TAD_None = 0, + CX_TAD_UnexpandedPack = 1, + CX_TAD_Instantiation = 2, + CX_TAD_Dependent = 4, + CX_TAD_Error = 8, + CX_TAD_DependentInstantiation = CX_TAD_Dependent | CX_TAD_Instantiation, + CX_TAD_All = 15, + } +} diff --git a/sources/ClangSharp/Interop/CX_TemplateArgumentLoc.cs b/sources/ClangSharp/Interop/CX_TemplateArgumentLoc.cs new file mode 100644 index 00000000..3ded9172 --- /dev/null +++ b/sources/ClangSharp/Interop/CX_TemplateArgumentLoc.cs @@ -0,0 +1,14 @@ +// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +// Ported from https://github.com/microsoft/ClangSharp/blob/master/sources/libClangSharp + +namespace ClangSharp.Interop +{ + public unsafe partial struct CX_TemplateArgumentLoc + { + [NativeTypeName("const clang::TemplateArgumentLoc *")] + public void* value; + + [NativeTypeName("CXTranslationUnit")] + public CXTranslationUnitImpl* tu; + } +} diff --git a/sources/ClangSharp/Interop/CX_TemplateName.cs b/sources/ClangSharp/Interop/CX_TemplateName.cs new file mode 100644 index 00000000..fe376011 --- /dev/null +++ b/sources/ClangSharp/Interop/CX_TemplateName.cs @@ -0,0 +1,16 @@ +// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +// Ported from https://github.com/microsoft/ClangSharp/blob/master/sources/libClangSharp + +namespace ClangSharp.Interop +{ + public unsafe partial struct CX_TemplateName + { + public CX_TemplateNameKind kind; + + [NativeTypeName("const void *")] + public void* value; + + [NativeTypeName("CXTranslationUnit")] + public CXTranslationUnitImpl* tu; + } +} diff --git a/sources/ClangSharp/Interop/CX_TemplateNameKind.cs b/sources/ClangSharp/Interop/CX_TemplateNameKind.cs new file mode 100644 index 00000000..b96b036a --- /dev/null +++ b/sources/ClangSharp/Interop/CX_TemplateNameKind.cs @@ -0,0 +1,17 @@ +// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +// Ported from https://github.com/microsoft/ClangSharp/blob/master/sources/libClangSharp + +namespace ClangSharp.Interop +{ + public enum CX_TemplateNameKind + { + CX_TNK_Invalid, + CX_TNK_Template = 1, + CX_TNK_OverloadedTemplate = 2, + CX_TNK_AssumedTemplate = 3, + CX_TNK_QualifiedTemplate = 4, + CX_TNK_DependentTemplate = 5, + CX_TNK_SubstTemplateTemplateParm = 6, + CX_TNK_SubstTemplateTemplateParmPack = 7 + } +} diff --git a/sources/ClangSharp/Interop/CX_VariableCaptureKind.cs b/sources/ClangSharp/Interop/CX_VariableCaptureKind.cs new file mode 100644 index 00000000..70ec65d2 --- /dev/null +++ b/sources/ClangSharp/Interop/CX_VariableCaptureKind.cs @@ -0,0 +1,14 @@ +// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +// Ported from https://github.com/microsoft/ClangSharp/blob/master/sources/libClangSharp + +namespace ClangSharp.Interop +{ + public enum CX_VariableCaptureKind + { + CX_VCK_Invalid, + CX_VCK_This, + CX_VCK_ByRef, + CX_VCK_ByCopy, + CX_VCK_VLAType + } +} diff --git a/sources/ClangSharp/Interop/clangsharp.cs b/sources/ClangSharp/Interop/clangsharp.cs index 0fead75a..e8a52c14 100644 --- a/sources/ClangSharp/Interop/clangsharp.cs +++ b/sources/ClangSharp/Interop/clangsharp.cs @@ -24,11 +24,17 @@ public static partial class clangsharp [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getAsFunction", ExactSpelling = true)] public static extern CXCursor Cursor_getAsFunction(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getAtomicOpcode", ExactSpelling = true)] + public static extern CX_AtomicOperatorKind Cursor_getAtomicOpcode(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getAttr", ExactSpelling = true)] + public static extern CXCursor Cursor_getAttr(CXCursor C, [NativeTypeName("unsigned int")] uint i); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getAttrKind", ExactSpelling = true)] public static extern CX_AttrKind Cursor_getAttrKind(CXCursor C); - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getBaseExpr", ExactSpelling = true)] - public static extern CXCursor Cursor_getBaseExpr(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getBase", ExactSpelling = true)] + public static extern CXCursor Cursor_getBase(CXCursor C, [NativeTypeName("unsigned int")] uint i); [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getBinaryOpcode", ExactSpelling = true)] public static extern CX_BinaryOperatorKind Cursor_getBinaryOpcode(CXCursor C); @@ -36,8 +42,11 @@ public static partial class clangsharp [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getBinaryOpcodeSpelling", ExactSpelling = true)] public static extern CXString Cursor_getBinaryOpcodeSpelling(CX_BinaryOperatorKind Op); - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getBinding", ExactSpelling = true)] - public static extern CXCursor Cursor_getBinding(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getBindingDecl", ExactSpelling = true)] + public static extern CXCursor Cursor_getBindingDecl(CXCursor C, [NativeTypeName("unsigned int")] uint i); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getBindingExpr", ExactSpelling = true)] + public static extern CXCursor Cursor_getBindingExpr(CXCursor C); [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getBitWidth", ExactSpelling = true)] public static extern CXCursor Cursor_getBitWidth(CXCursor C); @@ -55,9 +64,6 @@ public static partial class clangsharp [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getBody", ExactSpelling = true)] public static extern CXCursor Cursor_getBody(CXCursor C); - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getCalleeExpr", ExactSpelling = true)] - public static extern CXCursor Cursor_getCalleeExpr(CXCursor C); - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getCallResultType", ExactSpelling = true)] public static extern CXType Cursor_getCallResultType(CXCursor C); @@ -65,9 +71,18 @@ public static partial class clangsharp [return: NativeTypeName("unsigned int")] public static extern uint Cursor_getCanAvoidCopyToHeap(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getCanonical", ExactSpelling = true)] + public static extern CXCursor Cursor_getCanonical(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getCaptureCopyExpr", ExactSpelling = true)] public static extern CXCursor Cursor_getCaptureCopyExpr(CXCursor C, [NativeTypeName("unsigned int")] uint i); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getCapturedVar", ExactSpelling = true)] + public static extern CXCursor Cursor_getCapturedVar(CXCursor C, [NativeTypeName("unsigned int")] uint i); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getCaptureKind", ExactSpelling = true)] + public static extern CX_VariableCaptureKind Cursor_getCaptureKind(CXCursor C, [NativeTypeName("unsigned int")] uint i); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getCaptureHasCopyExpr", ExactSpelling = true)] [return: NativeTypeName("unsigned int")] public static extern uint Cursor_getCaptureHasCopyExpr(CXCursor C, [NativeTypeName("unsigned int")] uint i); @@ -88,6 +103,18 @@ public static partial class clangsharp [return: NativeTypeName("unsigned int")] public static extern uint Cursor_getCaptureIsNonEscapingByRef(CXCursor C, [NativeTypeName("unsigned int")] uint i); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getCapturedDecl", ExactSpelling = true)] + public static extern CXCursor Cursor_getCapturedDecl(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getCapturedRecordDecl", ExactSpelling = true)] + public static extern CXCursor Cursor_getCapturedRecordDecl(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getCapturedRegionKind", ExactSpelling = true)] + public static extern CX_CapturedRegionKind Cursor_getCapturedRegionKind(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getCapturedStmt", ExactSpelling = true)] + public static extern CXCursor Cursor_getCapturedStmt(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getCapturesCXXThis", ExactSpelling = true)] [return: NativeTypeName("unsigned int")] public static extern uint Cursor_getCapturesCXXThis(CXCursor C); @@ -109,11 +136,8 @@ public static partial class clangsharp [return: NativeTypeName("unsigned int")] public static extern uint Cursor_getCharacterLiteralValue(CXCursor C); - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getColumnIdxExpr", ExactSpelling = true)] - public static extern CXCursor Cursor_getColumnIdxExpr(CXCursor C); - - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getCommonExpr", ExactSpelling = true)] - public static extern CXCursor Cursor_getCommonExpr(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getChild", ExactSpelling = true)] + public static extern CXCursor Cursor_getChild(CXCursor C, [NativeTypeName("unsigned int")] uint i); [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getComputationLhsType", ExactSpelling = true)] public static extern CXType Cursor_getComputationLhsType(CXCursor C); @@ -121,12 +145,6 @@ public static partial class clangsharp [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getComputationResultType", ExactSpelling = true)] public static extern CXType Cursor_getComputationResultType(CXCursor C); - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getCondExpr", ExactSpelling = true)] - public static extern CXCursor Cursor_getCondExpr(CXCursor C); - - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getConditionVariableDeclStmt", ExactSpelling = true)] - public static extern CXCursor Cursor_getConditionVariableDeclStmt(CXCursor C); - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getConstraintExpr", ExactSpelling = true)] public static extern CXCursor Cursor_getConstraintExpr(CXCursor C); @@ -136,6 +154,9 @@ public static partial class clangsharp [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getConstructedBaseClassShadowDecl", ExactSpelling = true)] public static extern CXCursor Cursor_getConstructedBaseClassShadowDecl(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getConstructionKind", ExactSpelling = true)] + public static extern CX_ConstructionKind Cursor_getConstructionKind(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getConstructsVirtualBase", ExactSpelling = true)] [return: NativeTypeName("unsigned int")] public static extern uint Cursor_getConstructsVirtualBase(CXCursor C); @@ -146,16 +167,19 @@ public static partial class clangsharp [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getContextParamPosition", ExactSpelling = true)] public static extern int Cursor_getContextParamPosition(CXCursor C); - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getConversionFunction", ExactSpelling = true)] - public static extern CXCursor Cursor_getConversionFunction(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getCtor", ExactSpelling = true)] + public static extern CXCursor Cursor_getCtor(CXCursor C, [NativeTypeName("unsigned int")] uint i); - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getCXXBoolLiteralExprValue", ExactSpelling = true)] + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getBoolLiteralValue", ExactSpelling = true)] [return: NativeTypeName("unsigned int")] - public static extern uint Cursor_getCXXBoolLiteralExprValue(CXCursor C); + public static extern uint Cursor_getBoolLiteralValue(CXCursor C); [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getDeclaredReturnType", ExactSpelling = true)] public static extern CXType Cursor_getDeclaredReturnType(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getDecl", ExactSpelling = true)] + public static extern CXCursor Cursor_getDecl(CXCursor C, [NativeTypeName("unsigned int")] uint i); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getDeclKind", ExactSpelling = true)] public static extern CX_DeclKind Cursor_getDeclKind(CXCursor C); @@ -168,11 +192,14 @@ public static partial class clangsharp [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getDefaultArgType", ExactSpelling = true)] public static extern CXType Cursor_getDefaultArgType(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getDefinition", ExactSpelling = true)] + public static extern CXCursor Cursor_getDefinition(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getDependentLambdaCallOperator", ExactSpelling = true)] public static extern CXCursor Cursor_getDependentLambdaCallOperator(CXCursor C); - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getDescribedClassTemplate", ExactSpelling = true)] - public static extern CXCursor Cursor_getDescribedClassTemplate(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getDescribedCursorTemplate", ExactSpelling = true)] + public static extern CXCursor Cursor_getDescribedCursorTemplate(CXCursor C); [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getDescribedTemplate", ExactSpelling = true)] public static extern CXCursor Cursor_getDescribedTemplate(CXCursor C); @@ -180,21 +207,28 @@ public static partial class clangsharp [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getDestructor", ExactSpelling = true)] public static extern CXCursor Cursor_getDestructor(CXCursor C); - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getDirectCallee", ExactSpelling = true)] - public static extern CXCursor Cursor_getDirectCallee(CXCursor C); - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getDoesNotEscape", ExactSpelling = true)] [return: NativeTypeName("unsigned int")] public static extern uint Cursor_getDoesNotEscape(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getDoesUsualArrayDeleteWantSize", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getDoesUsualArrayDeleteWantSize(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getEnumDeclPromotionType", ExactSpelling = true)] public static extern CXType Cursor_getEnumDeclPromotionType(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getEnumerator", ExactSpelling = true)] + public static extern CXCursor Cursor_getEnumerator(CXCursor C, [NativeTypeName("unsigned int")] uint i); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getExpansionType", ExactSpelling = true)] + public static extern CXType Cursor_getExpansionType(CXCursor C, [NativeTypeName("unsigned int")] uint i); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getExpr", ExactSpelling = true)] public static extern CXCursor Cursor_getExpr(CXCursor C, [NativeTypeName("unsigned int")] uint i); - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getFalseExpr", ExactSpelling = true)] - public static extern CXCursor Cursor_getFalseExpr(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getExprDependence", ExactSpelling = true)] + public static extern CX_ExprDependence Cursor_getExprDependence(CXCursor C); [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getFieldIndex", ExactSpelling = true)] public static extern int Cursor_getFieldIndex(CXCursor C); @@ -205,6 +239,15 @@ public static partial class clangsharp [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getFloatingLiteralValueAsApproximateDouble", ExactSpelling = true)] public static extern double Cursor_getFloatingLiteralValueAsApproximateDouble(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getFoundDecl", ExactSpelling = true)] + public static extern CXCursor Cursor_getFoundDecl(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getField", ExactSpelling = true)] + public static extern CXCursor Cursor_getField(CXCursor C, [NativeTypeName("unsigned int")] uint i); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getFriend", ExactSpelling = true)] + public static extern CXCursor Cursor_getFriend(CXCursor C, [NativeTypeName("unsigned int")] uint i); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getFriendDecl", ExactSpelling = true)] public static extern CXCursor Cursor_getFriendDecl(CXCursor C); @@ -214,12 +257,14 @@ public static partial class clangsharp [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getFunctionScopeIndex", ExactSpelling = true)] public static extern int Cursor_getFunctionScopeIndex(CXCursor C); - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getFunctionType", ExactSpelling = true)] - public static extern CXType Cursor_getFunctionType(CXCursor C); - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getGuidValue", ExactSpelling = true)] + [return: NativeTypeName("clang::MSGuidDeclParts")] public static extern Guid Cursor_getGuidValue(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getHadMultipleCandidates", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getHadMultipleCandidates(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getHasBody", ExactSpelling = true)] [return: NativeTypeName("unsigned int")] public static extern uint Cursor_getHasBody(CXCursor C); @@ -228,6 +273,10 @@ public static partial class clangsharp [return: NativeTypeName("unsigned int")] public static extern uint Cursor_getHasDefaultArg(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getHasElseStorage", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getHasElseStorage(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getHasExplicitTemplateArgs", ExactSpelling = true)] [return: NativeTypeName("unsigned int")] public static extern uint Cursor_getHasExplicitTemplateArgs(CXCursor C); @@ -252,6 +301,14 @@ public static partial class clangsharp [return: NativeTypeName("unsigned int")] public static extern uint Cursor_getHasInit(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getHasInitStorage", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getHasInitStorage(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getHasLeadingEmptyMacro", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getHasLeadingEmptyMacro(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getHasLocalStorage", ExactSpelling = true)] [return: NativeTypeName("unsigned int")] public static extern uint Cursor_getHasLocalStorage(CXCursor C); @@ -260,21 +317,61 @@ public static partial class clangsharp [return: NativeTypeName("unsigned int")] public static extern uint Cursor_getHasPlaceholderTypeConstraint(CXCursor C); - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getHoldingVar", ExactSpelling = true)] - public static extern CXCursor Cursor_getHoldingVar(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getHasTemplateKeyword", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getHasTemplateKeyword(CXCursor C); - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIdxExpr", ExactSpelling = true)] - public static extern CXCursor Cursor_getIdxExpr(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getHasUserDeclaredConstructor", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getHasUserDeclaredConstructor(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getHasUserDeclaredCopyAssignment", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getHasUserDeclaredCopyAssignment(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getHasUserDeclaredCopyConstructor", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getHasUserDeclaredCopyConstructor(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getHasUserDeclaredDestructor", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getHasUserDeclaredDestructor(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getHasUserDeclaredMoveAssignment", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getHasUserDeclaredMoveAssignment(CXCursor C); - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIncExpr", ExactSpelling = true)] - public static extern CXCursor Cursor_getIncExpr(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getHasUserDeclaredMoveConstructor", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getHasUserDeclaredMoveConstructor(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getHasUserDeclaredMoveOperation", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getHasUserDeclaredMoveOperation(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getHasVarStorage", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getHasVarStorage(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getHoldingVar", ExactSpelling = true)] + public static extern CXCursor Cursor_getHoldingVar(CXCursor C); [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getInClassInitializer", ExactSpelling = true)] public static extern CXCursor Cursor_getInClassInitializer(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getInheritedConstructor", ExactSpelling = true)] + public static extern CXCursor Cursor_getInheritedConstructor(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getInheritedFromVBase", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getInheritedFromVBase(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getInitExpr", ExactSpelling = true)] public static extern CXCursor Cursor_getInitExpr(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getInjectedSpecializationType", ExactSpelling = true)] + public static extern CXType Cursor_getInjectedSpecializationType(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getInstantiatedFromMember", ExactSpelling = true)] public static extern CXCursor Cursor_getInstantiatedFromMember(CXCursor C); @@ -282,6 +379,14 @@ public static partial class clangsharp [return: NativeTypeName("int64_t")] public static extern long Cursor_getIntegerLiteralValue(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsAllEnumCasesCovered", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getIsAllEnumCasesCovered(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsAlwaysNull", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getIsAlwaysNull(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsAnonymousStructOrUnion", ExactSpelling = true)] [return: NativeTypeName("unsigned int")] public static extern uint Cursor_getIsAnonymousStructOrUnion(CXCursor C); @@ -290,33 +395,109 @@ public static partial class clangsharp [return: NativeTypeName("unsigned int")] public static extern uint Cursor_getIsArgumentType(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsArrayForm", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getIsArrayForm(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsArrayFormAsWritten", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getIsArrayFormAsWritten(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsArrow", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getIsArrow(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsClassExtension", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getIsClassExtension(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsCompleteDefinition", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getIsCompleteDefinition(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsConditionTrue", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getIsConditionTrue(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsConstexpr", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getIsConstexpr(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsConversionFromLambda", ExactSpelling = true)] [return: NativeTypeName("unsigned int")] public static extern uint Cursor_getIsConversionFromLambda(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsCopyOrMoveConstructor", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getIsCopyOrMoveConstructor(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsCXXTry", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getIsCXXTry(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsDefined", ExactSpelling = true)] [return: NativeTypeName("unsigned int")] public static extern uint Cursor_getIsDefined(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsDelegatingConstructor", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getIsDelegatingConstructor(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsDeleted", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getIsDeleted(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsDeprecated", ExactSpelling = true)] [return: NativeTypeName("unsigned int")] public static extern uint Cursor_getIsDeprecated(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsElidable", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getIsElidable(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsExpandedParameterPack", ExactSpelling = true)] [return: NativeTypeName("unsigned int")] public static extern uint Cursor_getIsExpandedParameterPack(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsExplicitlyDefaulted", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getIsExplicitlyDefaulted(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsExternC", ExactSpelling = true)] [return: NativeTypeName("unsigned int")] public static extern uint Cursor_getIsExternC(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsFileScope", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getIsFileScope(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsGlobal", ExactSpelling = true)] [return: NativeTypeName("unsigned int")] public static extern uint Cursor_getIsGlobal(CXCursor C); - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsImplicitAccess", ExactSpelling = true)] + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsInjectedClassName", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getIsInjectedClassName(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsIfExists", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getIsIfExists(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsImplicit", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getIsImplicit(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsIncomplete", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getIsIncomplete(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsInheritingConstructor", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getIsInheritingConstructor(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsListInitialization", ExactSpelling = true)] [return: NativeTypeName("unsigned int")] - public static extern uint Cursor_getIsImplicitAccess(CXCursor C); + public static extern uint Cursor_getIsListInitialization(CXCursor C); [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsLocalVarDecl", ExactSpelling = true)] [return: NativeTypeName("unsigned int")] @@ -358,10 +539,26 @@ public static partial class clangsharp [return: NativeTypeName("unsigned int")] public static extern uint Cursor_getIsParameterPack(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsPartiallySubstituted", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getIsPartiallySubstituted(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsPotentiallyEvaluated", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getIsPotentiallyEvaluated(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsPure", ExactSpelling = true)] [return: NativeTypeName("unsigned int")] public static extern uint Cursor_getIsPure(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsResultDependent", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getIsResultDependent(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsReversed", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getIsReversed(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsSigned", ExactSpelling = true)] [return: NativeTypeName("unsigned int")] public static extern uint Cursor_getIsSigned(CXCursor C); @@ -374,6 +571,10 @@ public static partial class clangsharp [return: NativeTypeName("unsigned int")] public static extern uint Cursor_getIsStaticDataMember(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsStdInitListInitialization", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getIsStdInitListInitialization(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsStrictlyPositive", ExactSpelling = true)] [return: NativeTypeName("unsigned int")] public static extern uint Cursor_getIsStrictlyPositive(CXCursor C); @@ -386,22 +587,26 @@ public static partial class clangsharp [return: NativeTypeName("unsigned int")] public static extern uint Cursor_getIsThisDeclarationADefinition(CXCursor C); - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsTransparentTag", ExactSpelling = true)] + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsThrownVariableInScope", ExactSpelling = true)] [return: NativeTypeName("unsigned int")] - public static extern uint Cursor_getIsTransparentTag(CXCursor C); + public static extern uint Cursor_getIsThrownVariableInScope(CXCursor C); - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsTypeConcept", ExactSpelling = true)] + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsTransparent", ExactSpelling = true)] [return: NativeTypeName("unsigned int")] - public static extern uint Cursor_getIsTypeConcept(CXCursor C); + public static extern uint Cursor_getIsTransparent(CXCursor C); - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsTypeOperand", ExactSpelling = true)] + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsTypeConcept", ExactSpelling = true)] [return: NativeTypeName("unsigned int")] - public static extern uint Cursor_getIsTypeOperand(CXCursor C); + public static extern uint Cursor_getIsTypeConcept(CXCursor C); [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsUnavailable", ExactSpelling = true)] [return: NativeTypeName("unsigned int")] public static extern uint Cursor_getIsUnavailable(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsUnconditionallyVisible", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getIsUnconditionallyVisible(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsUnnamedBitfield", ExactSpelling = true)] [return: NativeTypeName("unsigned int")] public static extern uint Cursor_getIsUnnamedBitfield(CXCursor C); @@ -414,6 +619,10 @@ public static partial class clangsharp [return: NativeTypeName("unsigned int")] public static extern uint Cursor_getIsUnsupportedFriend(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsUserProvided", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getIsUserProvided(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getIsVariadic", ExactSpelling = true)] [return: NativeTypeName("unsigned int")] public static extern uint Cursor_getIsVariadic(CXCursor C); @@ -434,11 +643,14 @@ public static partial class clangsharp [return: NativeTypeName("unsigned int")] public static extern uint Cursor_getMaxAlignment(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getMethod", ExactSpelling = true)] + public static extern CXCursor Cursor_getMethod(CXCursor C, [NativeTypeName("unsigned int")] uint i); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getMostRecentDecl", ExactSpelling = true)] public static extern CXCursor Cursor_getMostRecentDecl(CXCursor C); - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getMostRecentNonInjectedDecl", ExactSpelling = true)] - public static extern CXCursor Cursor_getMostRecentNonInjectedDecl(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getName", ExactSpelling = true)] + public static extern CXString Cursor_getName(CXCursor C); [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getNextDeclInContext", ExactSpelling = true)] public static extern CXCursor Cursor_getNextDeclInContext(CXCursor C); @@ -455,30 +667,84 @@ public static partial class clangsharp [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getNonClosureContext", ExactSpelling = true)] public static extern CXCursor Cursor_getNonClosureContext(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getNumArguments", ExactSpelling = true)] + public static extern int Cursor_getNumArguments(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getNumAssocs", ExactSpelling = true)] + public static extern int Cursor_getNumAssocs(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getNumAssociatedConstraints", ExactSpelling = true)] public static extern int Cursor_getNumAssociatedConstraints(CXCursor C); - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getNumArguments", ExactSpelling = true)] - public static extern int Cursor_getNumArguments(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getNumAttrs", ExactSpelling = true)] + public static extern int Cursor_getNumAttrs(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getNumBases", ExactSpelling = true)] + public static extern int Cursor_getNumBases(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getNumBindings", ExactSpelling = true)] + public static extern int Cursor_getNumBindings(CXCursor C); [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getNumCaptures", ExactSpelling = true)] public static extern int Cursor_getNumCaptures(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getNumChildren", ExactSpelling = true)] + public static extern int Cursor_getNumChildren(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getNumCtors", ExactSpelling = true)] + public static extern int Cursor_getNumCtors(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getNumDecls", ExactSpelling = true)] + public static extern int Cursor_getNumDecls(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getNumEnumerators", ExactSpelling = true)] + public static extern int Cursor_getNumEnumerators(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getNumExpansionTypes", ExactSpelling = true)] + public static extern int Cursor_getNumExpansionTypes(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getNumExprs", ExactSpelling = true)] public static extern int Cursor_getNumExprs(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getNumFields", ExactSpelling = true)] + public static extern int Cursor_getNumFields(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getNumFriends", ExactSpelling = true)] + public static extern int Cursor_getNumFriends(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getNumMethods", ExactSpelling = true)] + public static extern int Cursor_getNumMethods(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getNumProtocols", ExactSpelling = true)] + public static extern int Cursor_getNumProtocols(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getNumSpecializations", ExactSpelling = true)] public static extern int Cursor_getNumSpecializations(CXCursor C); [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getNumTemplateArguments", ExactSpelling = true)] public static extern int Cursor_getNumTemplateArguments(CXCursor C); - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getOpaqueValueExpr", ExactSpelling = true)] - public static extern CXCursor Cursor_getOpaqueValueExpr(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getNumTemplateParameters", ExactSpelling = true)] + public static extern int Cursor_getNumTemplateParameters(CXCursor C, [NativeTypeName("unsigned int")] uint listIndex); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getNumTemplateParameterLists", ExactSpelling = true)] + public static extern int Cursor_getNumTemplateParameterLists(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getNumVBases", ExactSpelling = true)] + public static extern int Cursor_getNumVBases(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getOpaqueValue", ExactSpelling = true)] + public static extern CXCursor Cursor_getOpaqueValue(CXCursor C); [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getOriginalType", ExactSpelling = true)] public static extern CXType Cursor_getOriginalType(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getOverloadedOperatorKind", ExactSpelling = true)] + public static extern CX_OverloadedOperatorKind Cursor_getOverloadedOperatorKind(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getPackLength", ExactSpelling = true)] + public static extern int Cursor_getPackLength(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getParentFunctionOrMethod", ExactSpelling = true)] public static extern CXCursor Cursor_getParentFunctionOrMethod(CXCursor C); @@ -491,17 +757,31 @@ public static partial class clangsharp [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getPrimaryTemplate", ExactSpelling = true)] public static extern CXCursor Cursor_getPrimaryTemplate(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getProtocol", ExactSpelling = true)] + public static extern CXCursor Cursor_getProtocol(CXCursor C, [NativeTypeName("unsigned int")] uint i); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getRedeclContext", ExactSpelling = true)] + public static extern CXCursor Cursor_getRedeclContext(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getReferenced", ExactSpelling = true)] public static extern CXCursor Cursor_getReferenced(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getRequiresZeroInitialization", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getRequiresZeroInitialization(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getResultIndex", ExactSpelling = true)] + public static extern int Cursor_getResultIndex(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getReturnType", ExactSpelling = true)] public static extern CXType Cursor_getReturnType(CXCursor C); [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getRhsExpr", ExactSpelling = true)] public static extern CXCursor Cursor_getRhsExpr(CXCursor C); - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getRowIdxExpr", ExactSpelling = true)] - public static extern CXCursor Cursor_getRowIdxExpr(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getShouldCopy", ExactSpelling = true)] + [return: NativeTypeName("unsigned int")] + public static extern uint Cursor_getShouldCopy(CXCursor C); [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getSourceRange", ExactSpelling = true)] public static extern CXSourceRange Cursor_getSourceRange(CXCursor C); @@ -515,6 +795,9 @@ public static partial class clangsharp [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getStringLiteralValue", ExactSpelling = true)] public static extern CXString Cursor_getStringLiteralValue(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getSubDecl", ExactSpelling = true)] + public static extern CXCursor Cursor_getSubDecl(CXCursor C, [NativeTypeName("unsigned int")] uint i); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getSubExpr", ExactSpelling = true)] public static extern CXCursor Cursor_getSubExpr(CXCursor C); @@ -528,44 +811,13 @@ public static partial class clangsharp public static extern CXCursor Cursor_getTargetUnionField(CXCursor C); [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getTemplateArgument", ExactSpelling = true)] - public static extern CXCursor Cursor_getTemplateArgument(CXCursor C, [NativeTypeName("unsigned int")] uint i); - - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getTemplateArgumentAsDecl", ExactSpelling = true)] - public static extern CXCursor Cursor_getTemplateArgumentAsDecl(CXCursor C, [NativeTypeName("unsigned int")] uint i); - - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getTemplateArgumentAsExpr", ExactSpelling = true)] - public static extern CXCursor Cursor_getTemplateArgumentAsExpr(CXCursor C, [NativeTypeName("unsigned int")] uint i); - - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getTemplateArgumentAsIntegral", ExactSpelling = true)] - [return: NativeTypeName("int64_t")] - public static extern long Cursor_getTemplateArgumentAsIntegral(CXCursor C, [NativeTypeName("unsigned int")] uint i); - - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getTemplateArgumentAsType", ExactSpelling = true)] - public static extern CXType Cursor_getTemplateArgumentAsType(CXCursor C, [NativeTypeName("unsigned int")] uint i); - - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getTemplateArgumentIntegralType", ExactSpelling = true)] - public static extern CXType Cursor_getTemplateArgumentIntegralType(CXCursor C, [NativeTypeName("unsigned int")] uint i); - - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getTemplateArgumentKind", ExactSpelling = true)] - public static extern CXTemplateArgumentKind Cursor_getTemplateArgumentKind(CXCursor C, [NativeTypeName("unsigned int")] uint i); - - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getTemplateArgumentLocLocation", ExactSpelling = true)] - public static extern CXSourceLocation Cursor_getTemplateArgumentLocLocation(CXCursor C, [NativeTypeName("unsigned int")] uint i); - - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getTemplateArgumentLocSourceDeclExpression", ExactSpelling = true)] - public static extern CXCursor Cursor_getTemplateArgumentLocSourceDeclExpression(CXCursor C, [NativeTypeName("unsigned int")] uint i); - - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getTemplateArgumentLocSourceExpression", ExactSpelling = true)] - public static extern CXCursor Cursor_getTemplateArgumentLocSourceExpression(CXCursor C, [NativeTypeName("unsigned int")] uint i); + public static extern CX_TemplateArgument Cursor_getTemplateArgument(CXCursor C, [NativeTypeName("unsigned int")] uint i); - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getTemplateArgumentLocSourceIntegralExpression", ExactSpelling = true)] - public static extern CXCursor Cursor_getTemplateArgumentLocSourceIntegralExpression(CXCursor C, [NativeTypeName("unsigned int")] uint i); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getTemplateArgumentLoc", ExactSpelling = true)] + public static extern CX_TemplateArgumentLoc Cursor_getTemplateArgumentLoc(CXCursor C, [NativeTypeName("unsigned int")] uint i); - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getTemplateArgumentLocSourceNullPtrExpression", ExactSpelling = true)] - public static extern CXCursor Cursor_getTemplateArgumentLocSourceNullPtrExpression(CXCursor C, [NativeTypeName("unsigned int")] uint i); - - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getTemplateArgumentNullPtrType", ExactSpelling = true)] - public static extern CXType Cursor_getTemplateArgumentNullPtrType(CXCursor C, [NativeTypeName("unsigned int")] uint i); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getTemplateParameter", ExactSpelling = true)] + public static extern CXCursor Cursor_getTemplateParameter(CXCursor C, [NativeTypeName("unsigned int")] uint listIndex, [NativeTypeName("unsigned int")] uint parameterIndex); [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getTemplatedDecl", ExactSpelling = true)] public static extern CXCursor Cursor_getTemplatedDecl(CXCursor C); @@ -582,6 +834,9 @@ public static partial class clangsharp [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getTemplateTypeParmIndex", ExactSpelling = true)] public static extern int Cursor_getTemplateTypeParmIndex(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getTemplateTypeParmPosition", ExactSpelling = true)] + public static extern int Cursor_getTemplateTypeParmPosition(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getThisObjectType", ExactSpelling = true)] public static extern CXType Cursor_getThisObjectType(CXCursor C); @@ -591,9 +846,6 @@ public static partial class clangsharp [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getTrailingRequiresClause", ExactSpelling = true)] public static extern CXCursor Cursor_getTrailingRequiresClause(CXCursor C); - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getTrueExpr", ExactSpelling = true)] - public static extern CXCursor Cursor_getTrueExpr(CXCursor C); - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getTypedefNameForAnonDecl", ExactSpelling = true)] public static extern CXCursor Cursor_getTypedefNameForAnonDecl(CXCursor C); @@ -618,6 +870,83 @@ public static partial class clangsharp [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getUsedContext", ExactSpelling = true)] public static extern CXCursor Cursor_getUsedContext(CXCursor C); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getVBase", ExactSpelling = true)] + public static extern CXCursor Cursor_getVBase(CXCursor C, [NativeTypeName("unsigned int")] uint i); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Cursor_getVtblIdx", ExactSpelling = true)] + [return: NativeTypeName("int64_t")] + public static extern long Cursor_getVtblIdx(CXCursor C); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_TemplateArgument_dispose", ExactSpelling = true)] + public static extern void TemplateArgument_dispose(CX_TemplateArgument T); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_TemplateArgument_getAsDecl", ExactSpelling = true)] + public static extern CXCursor TemplateArgument_getAsDecl(CX_TemplateArgument T); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_TemplateArgument_getAsExpr", ExactSpelling = true)] + public static extern CXCursor TemplateArgument_getAsExpr(CX_TemplateArgument T); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_TemplateArgument_getAsIntegral", ExactSpelling = true)] + [return: NativeTypeName("int64_t")] + public static extern long TemplateArgument_getAsIntegral(CX_TemplateArgument T); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_TemplateArgument_getAsTemplate", ExactSpelling = true)] + public static extern CX_TemplateName TemplateArgument_getAsTemplate(CX_TemplateArgument T); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_TemplateArgument_getAsTemplateOrTemplatePattern", ExactSpelling = true)] + public static extern CX_TemplateName TemplateArgument_getAsTemplateOrTemplatePattern(CX_TemplateArgument T); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_TemplateArgument_getAsType", ExactSpelling = true)] + public static extern CXType TemplateArgument_getAsType(CX_TemplateArgument T); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_TemplateArgument_getDependence", ExactSpelling = true)] + public static extern CX_TemplateArgumentDependence TemplateArgument_getDependence(CX_TemplateArgument T); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_TemplateArgument_getIntegralType", ExactSpelling = true)] + public static extern CXType TemplateArgument_getIntegralType(CX_TemplateArgument T); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_TemplateArgument_getNonTypeTemplateArgumentType", ExactSpelling = true)] + public static extern CXType TemplateArgument_getNonTypeTemplateArgumentType(CX_TemplateArgument T); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_TemplateArgument_getNullPtrType", ExactSpelling = true)] + public static extern CXType TemplateArgument_getNullPtrType(CX_TemplateArgument T); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_TemplateArgument_getNumPackElements", ExactSpelling = true)] + public static extern int TemplateArgument_getNumPackElements(CX_TemplateArgument T); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_TemplateArgument_getPackElement", ExactSpelling = true)] + public static extern CX_TemplateArgument TemplateArgument_getPackElement(CX_TemplateArgument T, [NativeTypeName("unsigned int")] uint i); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_TemplateArgument_getPackExpansionPattern", ExactSpelling = true)] + public static extern CX_TemplateArgument TemplateArgument_getPackExpansionPattern(CX_TemplateArgument T); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_TemplateArgument_getParamTypeForDecl", ExactSpelling = true)] + public static extern CXType TemplateArgument_getParamTypeForDecl(CX_TemplateArgument T); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_TemplateArgumentLoc_getArgument", ExactSpelling = true)] + public static extern CX_TemplateArgument TemplateArgumentLoc_getArgument(CX_TemplateArgumentLoc T); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_TemplateArgumentLoc_getLocation", ExactSpelling = true)] + public static extern CXSourceLocation TemplateArgumentLoc_getLocation(CX_TemplateArgumentLoc T); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_TemplateArgumentLoc_getSourceDeclExpression", ExactSpelling = true)] + public static extern CXCursor TemplateArgumentLoc_getSourceDeclExpression(CX_TemplateArgumentLoc T); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_TemplateArgumentLoc_getSourceExpression", ExactSpelling = true)] + public static extern CXCursor TemplateArgumentLoc_getSourceExpression(CX_TemplateArgumentLoc T); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_TemplateArgumentLoc_getSourceIntegralExpression", ExactSpelling = true)] + public static extern CXCursor TemplateArgumentLoc_getSourceIntegralExpression(CX_TemplateArgumentLoc T); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_TemplateArgumentLoc_getSourceNullPtrExpression", ExactSpelling = true)] + public static extern CXCursor TemplateArgumentLoc_getSourceNullPtrExpression(CX_TemplateArgumentLoc T); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_TemplateArgumentLoc_getSourceRange", ExactSpelling = true)] + public static extern CXSourceRange TemplateArgumentLoc_getSourceRange(CX_TemplateArgumentLoc T); + + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_TemplateName_getAsTemplateDecl", ExactSpelling = true)] + public static extern CXCursor TemplateName_getAsTemplateDecl(CX_TemplateName T); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_desugar", ExactSpelling = true)] public static extern CXType Type_desugar(CXType CT); @@ -712,27 +1041,11 @@ public static partial class clangsharp [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getSizeExpr", ExactSpelling = true)] public static extern CXCursor Type_getSizeExpr(CXType CT); - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getTemplateArgumentAsDecl", ExactSpelling = true)] - public static extern CXCursor Type_getTemplateArgumentAsDecl(CXType CT, [NativeTypeName("unsigned int")] uint i); - - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getTemplateArgumentAsExpr", ExactSpelling = true)] - public static extern CXCursor Type_getTemplateArgumentAsExpr(CXType CT, [NativeTypeName("unsigned int")] uint i); - - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getTemplateArgumentAsIntegral", ExactSpelling = true)] - [return: NativeTypeName("int64_t")] - public static extern long Type_getTemplateArgumentAsIntegral(CXType CT, [NativeTypeName("unsigned int")] uint i); - - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getTemplateArgumentAsType", ExactSpelling = true)] - public static extern CXType Type_getTemplateArgumentAsType(CXType CT, [NativeTypeName("unsigned int")] uint i); - - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getTemplateArgumentIntegralType", ExactSpelling = true)] - public static extern CXType Type_getTemplateArgumentIntegralType(CXType CT, [NativeTypeName("unsigned int")] uint i); - - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getTemplateArgumentKind", ExactSpelling = true)] - public static extern CXTemplateArgumentKind Type_getTemplateArgumentKind(CXType CT, [NativeTypeName("unsigned int")] uint i); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getTemplateArgument", ExactSpelling = true)] + public static extern CX_TemplateArgument Type_getTemplateArgument(CXType C, [NativeTypeName("unsigned int")] uint i); - [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getTemplateArgumentNullPtrType", ExactSpelling = true)] - public static extern CXType Type_getTemplateArgumentNullPtrType(CXType CT, [NativeTypeName("unsigned int")] uint i); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getTemplateName", ExactSpelling = true)] + public static extern CX_TemplateName Type_getTemplateName(CXType C); [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getTypeClass", ExactSpelling = true)] public static extern CX_TypeClass Type_getTypeClass(CXType CT); diff --git a/sources/ClangSharp/TemplateArgument.cs b/sources/ClangSharp/TemplateArgument.cs index 75ea8fbb..9aa81106 100644 --- a/sources/ClangSharp/TemplateArgument.cs +++ b/sources/ClangSharp/TemplateArgument.cs @@ -1,57 +1,146 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. using System; +using System.Collections.Generic; +using System.Diagnostics; using ClangSharp.Interop; namespace ClangSharp { - public sealed class TemplateArgument + public sealed unsafe class TemplateArgument : IDisposable { - private readonly Decl _parentDecl; - private readonly Type _parentType; - private readonly uint _index; private readonly Lazy _asDecl; private readonly Lazy _asExpr; + private readonly Lazy _asTemplate; + private readonly Lazy _asTemplateOrTemplatePattern; private readonly Lazy _asType; private readonly Lazy _integralType; + private readonly Lazy _nonTypeTemplateArgumentType; private readonly Lazy _nullPtrType; + private readonly Lazy> _packElements; + private readonly Lazy _packExpansionPattern; + private readonly Lazy _paramTypeForDecl; + private readonly Lazy _translationUnit; - internal TemplateArgument(Decl parentDecl, uint index) + internal TemplateArgument(CX_TemplateArgument handle) { - _parentDecl = parentDecl; - _index = index; - _asDecl = new Lazy(() => _parentDecl.TranslationUnit.GetOrCreate(_parentDecl.Handle.GetTemplateArgumentAsDecl(_index))); - _asExpr = new Lazy(() => _parentDecl.TranslationUnit.GetOrCreate(_parentDecl.Handle.GetTemplateArgumentAsExpr(_index))); - _asType = new Lazy(() => _parentDecl.TranslationUnit.GetOrCreate(_parentDecl.Handle.GetTemplateArgumentAsType(_index))); - _integralType = new Lazy(() => _parentDecl.TranslationUnit.GetOrCreate(_parentDecl.Handle.GetTemplateArgumentIntegralType(_index))); - _nullPtrType = new Lazy(() => _parentDecl.TranslationUnit.GetOrCreate(_parentDecl.Handle.GetTemplateArgumentNullPtrType(_index))); - } + Handle = handle; - internal TemplateArgument(Type parentType, uint index) - { - _parentType = parentType; - _index = index; - _asDecl = new Lazy(() => _parentType.TranslationUnit.GetOrCreate(_parentType.Handle.GetTemplateArgumentAsDecl(_index))); - _asExpr = new Lazy(() => _parentType.TranslationUnit.GetOrCreate(_parentType.Handle.GetTemplateArgumentAsExpr(_index))); - _asType = new Lazy(() => _parentType.TranslationUnit.GetOrCreate(_parentType.Handle.GetTemplateArgumentAsType(_index))); - _integralType = new Lazy(() => _parentType.TranslationUnit.GetOrCreate(_parentType.Handle.GetTemplateArgumentIntegralType(_index))); - _nullPtrType = new Lazy(() => _parentType.TranslationUnit.GetOrCreate(_parentType.Handle.GetTemplateArgumentNullPtrType(_index))); + _asDecl = new Lazy(() => _translationUnit.Value.GetOrCreate(Handle.AsDecl)); + _asExpr = new Lazy(() => _translationUnit.Value.GetOrCreate(Handle.AsExpr)); + _asTemplate = new Lazy(() => _translationUnit.Value.GetOrCreate(Handle.AsTemplate)); + _asTemplateOrTemplatePattern = new Lazy(() => _translationUnit.Value.GetOrCreate(Handle.AsTemplateOrTemplatePattern)); + _asType = new Lazy(() => _translationUnit.Value.GetOrCreate(Handle.AsType)); + _integralType = new Lazy(() => _translationUnit.Value.GetOrCreate(Handle.IntegralType)); + _nonTypeTemplateArgumentType = new Lazy(() => _translationUnit.Value.GetOrCreate(Handle.NonTypeTemplateArgumentType)); + _nullPtrType = new Lazy(() => _translationUnit.Value.GetOrCreate(Handle.NullPtrType)); + _packExpansionPattern = new Lazy(() => _translationUnit.Value.GetOrCreate(Handle.PackExpansionPattern)); + + _packElements = new Lazy>(() => { + var numPackElements = Handle.NumPackElements; + var packElements = new List(numPackElements); + + for (var i = 0; i < numPackElements; i++) + { + var packElement = _translationUnit.Value.GetOrCreate(Handle.GetPackElement(unchecked((uint)i))); + packElements.Add(packElement); + } + + return packElements; + }); + + _paramTypeForDecl = new Lazy(() => _translationUnit.Value.GetOrCreate(Handle.ParamTypeForDecl)); + _translationUnit = new Lazy(() => TranslationUnit.GetOrCreate(Handle.tu)); } + ~TemplateArgument() => Dispose(isDisposing: false); + public ValueDecl AsDecl => _asDecl.Value; public Expr AsExpr => _asExpr.Value; - public long AsIntegral => (_parentDecl != null) ? _parentDecl.Handle.GetTemplateArgumentAsIntegral(_index) : _parentType.Handle.GetTemplateArgumentAsIntegral(_index); + public long AsIntegral => Handle.AsIntegral; + + public TemplateName AsTemplate => _asTemplate.Value; + + public TemplateName AsTemplateOrTemplatePattern => _asTemplateOrTemplatePattern.Value; public Type AsType => _asType.Value; + public bool ContainsUnexpandedParameterPack => (Dependence & CX_TemplateArgumentDependence.CX_TAD_UnexpandedPack) != 0; + + public CX_TemplateArgumentDependence Dependence => Handle.Dependence; + public Type IntegralType => _integralType.Value; + public bool IsDependent => (Dependence & CX_TemplateArgumentDependence.CX_TAD_Dependent) != 0; + + public bool IsInstantiationDependent => (Dependence & CX_TemplateArgumentDependence.CX_TAD_Instantiation) != 0; + public bool IsNull => Kind == CXTemplateArgumentKind.CXTemplateArgumentKind_Null; - public CXTemplateArgumentKind Kind => (_parentDecl != null) ? _parentDecl.Handle.GetTemplateArgumentKind(_index) : _parentType.Handle.GetTemplateArgumentKind(_index); + public bool IsPackExpansion + { + get + { + switch (Kind) +{ + case CXTemplateArgumentKind.CXTemplateArgumentKind_Null: + case CXTemplateArgumentKind.CXTemplateArgumentKind_Declaration: + case CXTemplateArgumentKind.CXTemplateArgumentKind_Integral: + case CXTemplateArgumentKind.CXTemplateArgumentKind_Pack: + case CXTemplateArgumentKind.CXTemplateArgumentKind_Template: + case CXTemplateArgumentKind.CXTemplateArgumentKind_NullPtr: + { + return false; + } + + case CXTemplateArgumentKind.CXTemplateArgumentKind_TemplateExpansion: + { + return true; + } + + case CXTemplateArgumentKind.CXTemplateArgumentKind_Type: + { + return AsType is PackExpansionType; + } + + case CXTemplateArgumentKind.CXTemplateArgumentKind_Expression: + { + return AsExpr is PackExpansionExpr; + } + } + + Debug.Fail("Invalid TemplateArgument Kind!"); + return false; + } + } + + public CX_TemplateArgument Handle { get; } + + public CXTemplateArgumentKind Kind => Handle.kind; + + public Type NonTypeTemplateArgumentType => _nonTypeTemplateArgumentType.Value; public Type NullPtrType => _nullPtrType.Value; + + public IReadOnlyList PackElements => _packElements.Value; + + public TemplateArgument PackExpansionPattern => _packExpansionPattern.Value; + + public Type ParamTypeForDecl => _paramTypeForDecl.Value; + + public TranslationUnit TranslationUnit => _translationUnit.Value; + + public void Dispose() + { + Dispose(isDisposing: true); + GC.SuppressFinalize(this); + } + + private void Dispose(bool isDisposing) + { + Handle.Dispose(); + } } } diff --git a/sources/ClangSharp/TemplateArgumentLoc.cs b/sources/ClangSharp/TemplateArgumentLoc.cs index 12fcfc23..55e66bba 100644 --- a/sources/ClangSharp/TemplateArgumentLoc.cs +++ b/sources/ClangSharp/TemplateArgumentLoc.cs @@ -5,32 +5,32 @@ namespace ClangSharp { - public sealed class TemplateArgumentLoc + public sealed unsafe class TemplateArgumentLoc { - private readonly TemplateArgument _argument; - private readonly Decl _parentDecl; - private readonly uint _index; - + private readonly Lazy _argument; private readonly Lazy _sourceDeclExpression; private readonly Lazy _sourceExpression; private readonly Lazy _sourceIntegralExpression; private readonly Lazy _sourceNullPtrExpression; + private readonly Lazy _translationUnit; - internal TemplateArgumentLoc(Decl parentDecl, uint index) + internal TemplateArgumentLoc(CX_TemplateArgumentLoc handle) { - _argument = new TemplateArgument(parentDecl, index); - _parentDecl = parentDecl; - _index = index; - - _sourceDeclExpression = new Lazy(() => _parentDecl.TranslationUnit.GetOrCreate(_parentDecl.Handle.GetTemplateArgumentLocSourceDeclExpression(_index))); - _sourceExpression = new Lazy(() => _parentDecl.TranslationUnit.GetOrCreate(_parentDecl.Handle.GetTemplateArgumentLocSourceExpression(_index))); - _sourceIntegralExpression = new Lazy(() => _parentDecl.TranslationUnit.GetOrCreate(_parentDecl.Handle.GetTemplateArgumentLocSourceIntegralExpression(_index))); - _sourceNullPtrExpression = new Lazy(() => _parentDecl.TranslationUnit.GetOrCreate(_parentDecl.Handle.GetTemplateArgumentLocSourceNullPtrExpression(_index))); + Handle = handle; + + _argument = new Lazy(() => _translationUnit.Value.GetOrCreate(Handle.Argument)); + _sourceDeclExpression = new Lazy(() => _translationUnit.Value.GetOrCreate(Handle.SourceDeclExpression)); + _sourceExpression = new Lazy(() => _translationUnit.Value.GetOrCreate(Handle.SourceExpression)); + _sourceIntegralExpression = new Lazy(() => _translationUnit.Value.GetOrCreate(Handle.SourceIntegralExpression)); + _sourceNullPtrExpression = new Lazy(() => _translationUnit.Value.GetOrCreate(Handle.SourceNullPtrExpression)); + _translationUnit = new Lazy(() => TranslationUnit.GetOrCreate(Handle.tu)); } - public TemplateArgument Argument => _argument; + public TemplateArgument Argument => _argument.Value; + + public CXSourceLocation Location => Handle.Location; - public CXSourceLocation Location => _parentDecl.Handle.GetTemplateArgumentLocLocation(_index); + public CX_TemplateArgumentLoc Handle { get; } public Expr SourceDeclExpression => _sourceDeclExpression.Value; @@ -39,5 +39,9 @@ internal TemplateArgumentLoc(Decl parentDecl, uint index) public Expr SourceIntegralExpression => _sourceIntegralExpression.Value; public Expr SourceNullPtrExpression => _sourceNullPtrExpression.Value; + + public CXSourceRange SourceRange => Handle.SourceRange; + + public TranslationUnit TranslationUnit => _translationUnit.Value; } } diff --git a/sources/ClangSharp/TemplateName.cs b/sources/ClangSharp/TemplateName.cs new file mode 100644 index 00000000..9c54d093 --- /dev/null +++ b/sources/ClangSharp/TemplateName.cs @@ -0,0 +1,27 @@ +// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. + +using System; +using ClangSharp.Interop; + +namespace ClangSharp +{ + public sealed unsafe class TemplateName + { + private readonly Lazy _asTemplateDecl; + private readonly Lazy _translationUnit; + + internal TemplateName(CX_TemplateName handle) + { + Handle = handle; + + _asTemplateDecl = new Lazy(() => _translationUnit.Value.GetOrCreate(Handle.AsTemplateDecl)); + _translationUnit = new Lazy(() => TranslationUnit.GetOrCreate(Handle.tu)); + } + + public TemplateDecl AsTemplateDecl => _asTemplateDecl.Value; + + public CX_TemplateName Handle { get; } + + public TranslationUnit TranslationUnit => _translationUnit.Value; + } +} diff --git a/sources/ClangSharp/TranslationUnit.cs b/sources/ClangSharp/TranslationUnit.cs index 5c6d420d..ea894b5b 100644 --- a/sources/ClangSharp/TranslationUnit.cs +++ b/sources/ClangSharp/TranslationUnit.cs @@ -1,17 +1,21 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. using System; +using System.Collections.Concurrent; using System.Collections.Generic; using ClangSharp.Interop; namespace ClangSharp { - public sealed class TranslationUnit : IDisposable, IEquatable + public sealed unsafe class TranslationUnit : IDisposable, IEquatable { - private static readonly Dictionary> _createdTranslationUnits = new Dictionary>(); + private static readonly ConcurrentDictionary> _createdTranslationUnits = new ConcurrentDictionary>(); private static readonly object _createTranslationUnitLock = new object(); private readonly Dictionary> _createdCursors; + private readonly Dictionary> _createdTemplateArguments; + private readonly Dictionary> _createdTemplateArgumentLocs; + private readonly Dictionary> _createdTemplateNames; private readonly Dictionary> _createdTypes; private readonly Lazy _translationUnitDecl; @@ -22,6 +26,9 @@ private TranslationUnit(CXTranslationUnit handle) Handle = handle; _createdCursors = new Dictionary>(); + _createdTemplateArguments = new Dictionary>(); + _createdTemplateArgumentLocs = new Dictionary>(); + _createdTemplateNames = new Dictionary>(); _createdTypes = new Dictionary>(); _translationUnitDecl = new Lazy(() => GetOrCreate(Handle.Cursor)); @@ -42,23 +49,12 @@ private TranslationUnit(CXTranslationUnit handle) public static TranslationUnit GetOrCreate(CXTranslationUnit handle) { - WeakReference translationUnitRef; - if (handle == null) { return null; } - else if (!_createdTranslationUnits.TryGetValue(handle, out translationUnitRef)) - { - lock (_createTranslationUnitLock) - { - if (!_createdTranslationUnits.TryGetValue(handle, out translationUnitRef)) - { - translationUnitRef = new WeakReference(null); - _createdTranslationUnits.Add(handle, translationUnitRef); - } - } - } + + var translationUnitRef = _createdTranslationUnits.GetOrAdd(handle, (handle) => new WeakReference(null)); if (!translationUnitRef.TryGetTarget(out TranslationUnit translationUnit)) { @@ -109,6 +105,72 @@ internal TCursor GetOrCreate(CXCursor handle) return (TCursor)cursor; } + internal TemplateArgument GetOrCreate(CX_TemplateArgument handle) + { + WeakReference templateArgumentRef; + + if (handle.kind == CXTemplateArgumentKind.CXTemplateArgumentKind_Invalid) + { + return null; + } + else if (!_createdTemplateArguments.TryGetValue(handle, out templateArgumentRef)) + { + templateArgumentRef = new WeakReference(null); + _createdTemplateArguments.Add(handle, templateArgumentRef); + } + + if (!templateArgumentRef.TryGetTarget(out TemplateArgument templateArgument)) + { + templateArgument = new TemplateArgument(handle); + templateArgumentRef.SetTarget(templateArgument); +} + return templateArgument; + } + + internal TemplateArgumentLoc GetOrCreate(CX_TemplateArgumentLoc handle) + { + WeakReference templateArgumentLocRef; + + if (handle.value == null) + { + return null; + } + else if (!_createdTemplateArgumentLocs.TryGetValue(handle, out templateArgumentLocRef)) + { + templateArgumentLocRef = new WeakReference(null); + _createdTemplateArgumentLocs.Add(handle, templateArgumentLocRef); + } + + if (!templateArgumentLocRef.TryGetTarget(out TemplateArgumentLoc templateArgumentLoc)) + { + templateArgumentLoc = new TemplateArgumentLoc(handle); + templateArgumentLocRef.SetTarget(templateArgumentLoc); + } + return templateArgumentLoc; + } + + internal TemplateName GetOrCreate(CX_TemplateName handle) + { + WeakReference templateNameRef; + + if (handle.kind == CX_TemplateNameKind.CX_TNK_Invalid) + { + return null; + } + else if (!_createdTemplateNames.TryGetValue(handle, out templateNameRef)) + { + templateNameRef = new WeakReference(null); + _createdTemplateNames.Add(handle, templateNameRef); + } + + if (!templateNameRef.TryGetTarget(out TemplateName templateName)) + { + templateName = new TemplateName(handle); + templateNameRef.SetTarget(templateName); + } + return templateName; + } + internal TType GetOrCreate(CXType handle) where TType : Type { @@ -145,10 +207,7 @@ private void Dispose(bool isDisposing) Handle.Dispose(); } - lock (_createTranslationUnitLock) - { - _createdTranslationUnits.Remove(Handle); - } + _createdTranslationUnits.TryRemove(Handle, out _); } } } diff --git a/sources/ClangSharp/Types/AdjustedType.cs b/sources/ClangSharp/Types/AdjustedType.cs index 84dc0521..20f3926a 100644 --- a/sources/ClangSharp/Types/AdjustedType.cs +++ b/sources/ClangSharp/Types/AdjustedType.cs @@ -8,7 +8,6 @@ namespace ClangSharp public class AdjustedType : Type { private readonly Lazy _adjustedType; - private readonly Lazy _desugaredType; private readonly Lazy _originalType; internal AdjustedType(CXType handle) : this(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_Adjusted) @@ -18,16 +17,11 @@ internal AdjustedType(CXType handle) : this(handle, CXTypeKind.CXType_Unexposed, private protected AdjustedType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass) { _adjustedType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.AdjustedType)); - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); _originalType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.OriginalType)); } public Type GetAdjustedType => _adjustedType.Value; - public bool IsSugared => Handle.IsSugared; - public Type OriginalType => _originalType.Value; - - public Type Desugar() => _desugaredType.Value; } } diff --git a/sources/ClangSharp/Types/AtomicType.cs b/sources/ClangSharp/Types/AtomicType.cs index 4a8df597..8b25af1a 100644 --- a/sources/ClangSharp/Types/AtomicType.cs +++ b/sources/ClangSharp/Types/AtomicType.cs @@ -7,19 +7,13 @@ namespace ClangSharp { public sealed class AtomicType : Type { - private readonly Lazy _desugaredType; private readonly Lazy _valueType; internal AtomicType(CXType handle) : base(handle, CXTypeKind.CXType_Atomic, CX_TypeClass.CX_TypeClass_Atomic) { - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); _valueType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ValueType)); } - public bool IsSugared => Handle.IsSugared; - public Type ValueType => _valueType.Value; - - public Type Desugar() => _desugaredType.Value; } } diff --git a/sources/ClangSharp/Types/AttributedType.cs b/sources/ClangSharp/Types/AttributedType.cs index 895208f4..b386aadb 100644 --- a/sources/ClangSharp/Types/AttributedType.cs +++ b/sources/ClangSharp/Types/AttributedType.cs @@ -7,13 +7,11 @@ namespace ClangSharp { public sealed class AttributedType : Type { - private readonly Lazy _desugaredType; private readonly Lazy _equivalentType; private readonly Lazy _modifiedType; internal AttributedType(CXType handle) : base(handle, CXTypeKind.CXType_Attributed, CX_TypeClass.CX_TypeClass_Attributed) { - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); _equivalentType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.EquivalentType)); _modifiedType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ModifiedType)); } @@ -23,9 +21,5 @@ internal AttributedType(CXType handle) : base(handle, CXTypeKind.CXType_Attribut public Type EquivalentType => _equivalentType.Value; public Type ModifiedType => _modifiedType.Value; - - public bool IsSugared => Handle.IsSugared; - - public Type Desugar() => _desugaredType.Value; } } diff --git a/sources/ClangSharp/Types/AutoType.cs b/sources/ClangSharp/Types/AutoType.cs index 8bd895c5..8f59aaa2 100644 --- a/sources/ClangSharp/Types/AutoType.cs +++ b/sources/ClangSharp/Types/AutoType.cs @@ -18,7 +18,7 @@ internal AutoType(CXType handle) : base(handle, CXTypeKind.CXType_Auto, CX_TypeC for (int i = 0; i < templateArgCount; i++) { - var templateArg = new TemplateArgument(this, unchecked((uint)i)); + var templateArg = TranslationUnit.GetOrCreate(Handle.GetTemplateArgument(unchecked((uint)i))); templateArgs.Add(templateArg); } diff --git a/sources/ClangSharp/Types/BlockPointerType.cs b/sources/ClangSharp/Types/BlockPointerType.cs index 287a158a..ce4109de 100644 --- a/sources/ClangSharp/Types/BlockPointerType.cs +++ b/sources/ClangSharp/Types/BlockPointerType.cs @@ -1,25 +1,13 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. -using System; using ClangSharp.Interop; namespace ClangSharp { public sealed class BlockPointerType : Type { - private readonly Lazy _desugaredType; - private readonly Lazy _pointeeType; - internal BlockPointerType(CXType handle) : base(handle, CXTypeKind.CXType_BlockPointer, CX_TypeClass.CX_TypeClass_BlockPointer) { - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); - _pointeeType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.PointeeType)); } - - public bool IsSugared => Handle.IsSugared; - - public Type PointeeType => _pointeeType.Value; - - public Type Desugar() => _desugaredType.Value; } } diff --git a/sources/ClangSharp/Types/BuiltinType.cs b/sources/ClangSharp/Types/BuiltinType.cs index 92597c0d..d7bcdaf9 100644 --- a/sources/ClangSharp/Types/BuiltinType.cs +++ b/sources/ClangSharp/Types/BuiltinType.cs @@ -1,21 +1,14 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. -using System; using ClangSharp.Interop; namespace ClangSharp { public sealed class BuiltinType : Type { - private readonly Lazy _desugaredType; internal BuiltinType(CXType handle) : base(handle, handle.kind, CX_TypeClass.CX_TypeClass_Builtin) { - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); } - - public bool IsSugared => Handle.IsSugared; - - public Type Desugar() => _desugaredType.Value; } } diff --git a/sources/ClangSharp/Types/ComplexType.cs b/sources/ClangSharp/Types/ComplexType.cs index 858b8b18..8e00faf0 100644 --- a/sources/ClangSharp/Types/ComplexType.cs +++ b/sources/ClangSharp/Types/ComplexType.cs @@ -7,19 +7,13 @@ namespace ClangSharp { public sealed class ComplexType : Type { - private readonly Lazy _desugaredType; private readonly Lazy _elementType; internal ComplexType(CXType handle) : base(handle, CXTypeKind.CXType_Complex, CX_TypeClass.CX_TypeClass_Complex) { - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); _elementType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ElementType)); } public Type ElementType => _elementType.Value; - - public bool IsSugared => Handle.IsSugared; - - public Type Desugar() => _desugaredType.Value; } } diff --git a/sources/ClangSharp/Types/ConstantArrayType.cs b/sources/ClangSharp/Types/ConstantArrayType.cs index 37fc72b3..bbafbe69 100644 --- a/sources/ClangSharp/Types/ConstantArrayType.cs +++ b/sources/ClangSharp/Types/ConstantArrayType.cs @@ -7,21 +7,15 @@ namespace ClangSharp { public sealed class ConstantArrayType : ArrayType { - private readonly Lazy _desugaredType; private readonly Lazy _sizeExpr; internal ConstantArrayType(CXType handle) : base(handle, CXTypeKind.CXType_ConstantArray, CX_TypeClass.CX_TypeClass_ConstantArray) { - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); _sizeExpr = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SizeExpr)); } - public bool IsSugared => Handle.IsSugared; - public long Size => Handle.ArraySize; public Expr SizeExpr => _sizeExpr.Value; - - public Type Desugar() => _desugaredType.Value; } } diff --git a/sources/ClangSharp/Types/DecayedType.cs b/sources/ClangSharp/Types/DecayedType.cs index f9f2903e..e9201ffc 100644 --- a/sources/ClangSharp/Types/DecayedType.cs +++ b/sources/ClangSharp/Types/DecayedType.cs @@ -8,16 +8,12 @@ namespace ClangSharp public sealed class DecayedType : AdjustedType { private readonly Lazy _decayedType; - private readonly Lazy _pointeeType; internal DecayedType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_Decayed) { _decayedType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.DecayedType)); - _pointeeType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.PointeeType)); } public Type GetDecayedType => _decayedType.Value; - - public Type PointeeType => _pointeeType.Value; } } diff --git a/sources/ClangSharp/Types/DecltypeType.cs b/sources/ClangSharp/Types/DecltypeType.cs index 53421ab0..e3dc2bcb 100644 --- a/sources/ClangSharp/Types/DecltypeType.cs +++ b/sources/ClangSharp/Types/DecltypeType.cs @@ -7,23 +7,17 @@ namespace ClangSharp { public sealed class DecltypeType : Type { - private readonly Lazy _desugaredType; private readonly Lazy _underlyingExpr; private readonly Lazy _underlyingType; internal DecltypeType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_Decltype) { - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); _underlyingExpr = new Lazy(() => TranslationUnit.GetOrCreate(Handle.UnderlyingExpr)); _underlyingType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.UnderlyingType)); } - public bool IsSugared => Handle.IsSugared; - public Expr UnderlyingExpr => _underlyingExpr.Value; public Type UnderlyingType => _underlyingType.Value; - - public Type Desugar() => _desugaredType.Value; } } diff --git a/sources/ClangSharp/Types/DeducedTemplateSpecializationType.cs b/sources/ClangSharp/Types/DeducedTemplateSpecializationType.cs index 576020c4..bc939833 100644 --- a/sources/ClangSharp/Types/DeducedTemplateSpecializationType.cs +++ b/sources/ClangSharp/Types/DeducedTemplateSpecializationType.cs @@ -1,13 +1,19 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; using ClangSharp.Interop; namespace ClangSharp { public sealed class DeducedTemplateSpecializationType : DeducedType { + private readonly Lazy _templateName; + internal DeducedTemplateSpecializationType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_DeducedTemplateSpecialization) { + _templateName = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TemplateName)); } + + public TemplateName TemplateName => _templateName.Value; } } diff --git a/sources/ClangSharp/Types/DeducedType.cs b/sources/ClangSharp/Types/DeducedType.cs index 4a9e0fb2..1330dccd 100644 --- a/sources/ClangSharp/Types/DeducedType.cs +++ b/sources/ClangSharp/Types/DeducedType.cs @@ -8,18 +8,12 @@ namespace ClangSharp public class DeducedType : Type { private readonly Lazy _deducedType; - private readonly Lazy _desugaredType; private protected DeducedType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass) { _deducedType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.DeducedType)); - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); } public Type GetDeducedType => _deducedType.Value; - - public bool IsSugared => Handle.IsSugared; - - public Type Desugar() => _desugaredType.Value; } } diff --git a/sources/ClangSharp/Types/DependentAddressSpaceType.cs b/sources/ClangSharp/Types/DependentAddressSpaceType.cs index 00ef9bd6..c5d7bf1b 100644 --- a/sources/ClangSharp/Types/DependentAddressSpaceType.cs +++ b/sources/ClangSharp/Types/DependentAddressSpaceType.cs @@ -8,22 +8,12 @@ namespace ClangSharp public sealed class DependentAddressSpaceType : Type { private readonly Lazy _addrSpaceExpr; - private readonly Lazy _desugaredType; - private readonly Lazy _pointeeType; internal DependentAddressSpaceType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_DependentAddressSpace) { _addrSpaceExpr = new Lazy(() => TranslationUnit.GetOrCreate(Handle.AddrSpaceExpr)); - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); - _pointeeType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.PointeeType)); } public Expr AddrSpaceExpr => _addrSpaceExpr.Value; - - public bool IsSugared => Handle.IsSugared; - - public Type PointeeType => _pointeeType.Value; - - public Type Desugar() => _desugaredType.Value; } } diff --git a/sources/ClangSharp/Types/DependentExtIntType.cs b/sources/ClangSharp/Types/DependentExtIntType.cs index d770b41e..93f7b7e5 100644 --- a/sources/ClangSharp/Types/DependentExtIntType.cs +++ b/sources/ClangSharp/Types/DependentExtIntType.cs @@ -7,23 +7,17 @@ namespace ClangSharp { public sealed class DependentExtIntType : Type { - private readonly Lazy _desugaredType; private readonly Lazy _numBitsExpr; internal DependentExtIntType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_DependentExtInt) { - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); _numBitsExpr = new Lazy(() => TranslationUnit.GetOrCreate(handle.NumBitsExpr)); } public bool IsSigned => Handle.IsSigned; - public bool IsSugared => Handle.IsSugared; - public bool IsUnsigned => Handle.IsUnsigned; public Expr NumBitsExpr => _numBitsExpr.Value; - - public Type Desugar() => _desugaredType.Value; } } diff --git a/sources/ClangSharp/Types/DependentNameType.cs b/sources/ClangSharp/Types/DependentNameType.cs index 19a59285..f5225f9e 100644 --- a/sources/ClangSharp/Types/DependentNameType.cs +++ b/sources/ClangSharp/Types/DependentNameType.cs @@ -1,21 +1,14 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. -using System; using ClangSharp.Interop; namespace ClangSharp { public sealed class DependentNameType : TypeWithKeyword { - private readonly Lazy _desugaredType; internal DependentNameType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_DependentName) { - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); } - - public bool IsSugared => Handle.IsSugared; - - public Type Desugar() => _desugaredType.Value; } } diff --git a/sources/ClangSharp/Types/DependentSizedArrayType.cs b/sources/ClangSharp/Types/DependentSizedArrayType.cs index 928a2cdc..164dbfe9 100644 --- a/sources/ClangSharp/Types/DependentSizedArrayType.cs +++ b/sources/ClangSharp/Types/DependentSizedArrayType.cs @@ -7,19 +7,13 @@ namespace ClangSharp { public sealed class DependentSizedArrayType : ArrayType { - private readonly Lazy _desugaredType; private readonly Lazy _sizeExpr; internal DependentSizedArrayType(CXType handle) : base(handle, CXTypeKind.CXType_DependentSizedArray, CX_TypeClass.CX_TypeClass_DependentSizedArray) { - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); _sizeExpr = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SizeExpr)); } - public bool IsSugared => Handle.IsSugared; - public Expr SizeExpr => _sizeExpr.Value; - - public Type Desugar() => _desugaredType.Value; } } diff --git a/sources/ClangSharp/Types/DependentSizedExtVectorType.cs b/sources/ClangSharp/Types/DependentSizedExtVectorType.cs index eda7c705..1726ba98 100644 --- a/sources/ClangSharp/Types/DependentSizedExtVectorType.cs +++ b/sources/ClangSharp/Types/DependentSizedExtVectorType.cs @@ -7,25 +7,19 @@ namespace ClangSharp { public sealed class DependentSizedExtVectorType : Type { - private readonly Lazy _desugaredType; private readonly Lazy _elementType; private readonly Lazy _sizeExpr; internal DependentSizedExtVectorType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_DependentSizedExtVector) { - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); _elementType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ElementType)); _sizeExpr = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SizeExpr)); } public Type ElementType => _elementType.Value; - public bool IsSugared => Handle.IsSugared; - public long Size => Handle.ArraySize; public Expr SizeExpr => _sizeExpr.Value; - - public Type Desugar() => _desugaredType.Value; } } diff --git a/sources/ClangSharp/Types/DependentTemplateSpecializationType.cs b/sources/ClangSharp/Types/DependentTemplateSpecializationType.cs index 2c2f3e78..f497f5f3 100644 --- a/sources/ClangSharp/Types/DependentTemplateSpecializationType.cs +++ b/sources/ClangSharp/Types/DependentTemplateSpecializationType.cs @@ -8,19 +8,17 @@ namespace ClangSharp { public sealed class DependentTemplateSpecializationType : TypeWithKeyword { - private readonly Lazy _desugaredType; private readonly Lazy> _templateArgs; internal DependentTemplateSpecializationType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_DependentTemplateSpecialization) { - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); _templateArgs = new Lazy>(() => { var templateArgCount = Handle.NumTemplateArguments; var templateArgs = new List(templateArgCount); for (int i = 0; i < templateArgCount; i++) { - var templateArg = new TemplateArgument(this, unchecked((uint)i)); + var templateArg = TranslationUnit.GetOrCreate(Handle.GetTemplateArgument(unchecked((uint)i))); templateArgs.Add(templateArg); } @@ -29,9 +27,5 @@ internal DependentTemplateSpecializationType(CXType handle) : base(handle, CXTyp } public IReadOnlyList Args => _templateArgs.Value; - - public bool IsSugared => Handle.IsSugared; - - public Type Desugar() => _desugaredType.Value; } } diff --git a/sources/ClangSharp/Types/DependentVectorType.cs b/sources/ClangSharp/Types/DependentVectorType.cs index 8ef0e025..a2955ff4 100644 --- a/sources/ClangSharp/Types/DependentVectorType.cs +++ b/sources/ClangSharp/Types/DependentVectorType.cs @@ -7,25 +7,19 @@ namespace ClangSharp { public sealed class DependentVectorType : Type { - private readonly Lazy _desugaredType; private readonly Lazy _elementType; private readonly Lazy _sizeExpr; internal DependentVectorType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_DependentVector) { - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); _elementType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ElementType)); _sizeExpr = new Lazy(() => TranslationUnit.GetOrCreate(Handle.SizeExpr)); } public Type ElementType => _elementType.Value; - public bool IsSugared => Handle.IsSugared; - public long Size => Handle.ArraySize; public Expr SizeExpr => _sizeExpr.Value; - - public Type Desugar() => _desugaredType.Value; } } diff --git a/sources/ClangSharp/Types/ElaboratedType.cs b/sources/ClangSharp/Types/ElaboratedType.cs index 851d3e1b..9c7c544b 100644 --- a/sources/ClangSharp/Types/ElaboratedType.cs +++ b/sources/ClangSharp/Types/ElaboratedType.cs @@ -7,23 +7,17 @@ namespace ClangSharp { public sealed class ElaboratedType : TypeWithKeyword { - private readonly Lazy _desugaredType; private readonly Lazy _namedType; private readonly Lazy _ownedTagDecl; internal ElaboratedType(CXType handle) : base(handle, CXTypeKind.CXType_Elaborated, CX_TypeClass.CX_TypeClass_Elaborated) { - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); _namedType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.NamedType)); _ownedTagDecl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.OwnedTagDecl)); } - public bool IsSugared => Handle.IsSugared; - public Type NamedType => _namedType.Value; public TagDecl OwnedTagDecl => _ownedTagDecl.Value; - - public Type Desugar() => _desugaredType.Value; } } diff --git a/sources/ClangSharp/Types/EnumType.cs b/sources/ClangSharp/Types/EnumType.cs index 7c94a62e..7e500432 100644 --- a/sources/ClangSharp/Types/EnumType.cs +++ b/sources/ClangSharp/Types/EnumType.cs @@ -1,23 +1,16 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. -using System; using ClangSharp.Interop; namespace ClangSharp { public sealed class EnumType : TagType { - private readonly Lazy _desugaredType; internal EnumType(CXType handle) : base(handle, CXTypeKind.CXType_Enum, CX_TypeClass.CX_TypeClass_Enum) { - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); } public new EnumDecl Decl => (EnumDecl)base.Decl; - - public bool IsSugared => Handle.IsSugared; - - public Type Desugar() => _desugaredType.Value; } } diff --git a/sources/ClangSharp/Types/ExtIntType.cs b/sources/ClangSharp/Types/ExtIntType.cs index 374f8c3e..163b9af1 100644 --- a/sources/ClangSharp/Types/ExtIntType.cs +++ b/sources/ClangSharp/Types/ExtIntType.cs @@ -1,27 +1,20 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. -using System; using ClangSharp.Interop; namespace ClangSharp { public sealed class ExtIntType : Type { - private readonly Lazy _desugaredType; internal ExtIntType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_ExtInt) { - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); } public bool IsSigned => Handle.IsSigned; - public bool IsSugared => Handle.IsSugared; - public bool IsUnsigned => Handle.IsUnsigned; public uint NumBits => unchecked((uint)Handle.NumBits); - - public Type Desugar() => _desugaredType.Value; } } diff --git a/sources/ClangSharp/Types/ExtVectorType.cs b/sources/ClangSharp/Types/ExtVectorType.cs index b4ed325e..e51423c6 100644 --- a/sources/ClangSharp/Types/ExtVectorType.cs +++ b/sources/ClangSharp/Types/ExtVectorType.cs @@ -1,21 +1,14 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. -using System; using ClangSharp.Interop; namespace ClangSharp { public sealed class ExtVectorType : Type { - private readonly Lazy _desugaredType; internal ExtVectorType(CXType handle) : base(handle, CXTypeKind.CXType_ExtVector, CX_TypeClass.CX_TypeClass_ExtVector) { - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); } - - public bool IsSugared => Handle.IsSugared; - - public Type Desugar() => _desugaredType.Value; } } diff --git a/sources/ClangSharp/Types/FunctionNoProtoType.cs b/sources/ClangSharp/Types/FunctionNoProtoType.cs index 89361d6d..ed1588ce 100644 --- a/sources/ClangSharp/Types/FunctionNoProtoType.cs +++ b/sources/ClangSharp/Types/FunctionNoProtoType.cs @@ -1,21 +1,14 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. -using System; using ClangSharp.Interop; namespace ClangSharp { public sealed class FunctionNoProtoType : FunctionType { - private readonly Lazy _desugaredType; internal FunctionNoProtoType(CXType handle) : base(handle, CXTypeKind.CXType_FunctionNoProto, CX_TypeClass.CX_TypeClass_FunctionNoProto) { - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); } - - public bool IsSugared => Handle.IsSugared; - - public Type Desugar() => _desugaredType.Value; } } diff --git a/sources/ClangSharp/Types/FunctionProtoType.cs b/sources/ClangSharp/Types/FunctionProtoType.cs index c925fabb..2368d41b 100644 --- a/sources/ClangSharp/Types/FunctionProtoType.cs +++ b/sources/ClangSharp/Types/FunctionProtoType.cs @@ -8,12 +8,10 @@ namespace ClangSharp { public sealed class FunctionProtoType : FunctionType { - private readonly Lazy _desugaredType; private readonly Lazy> _paramTypes; internal FunctionProtoType(CXType handle) : base(handle, CXTypeKind.CXType_FunctionProto, CX_TypeClass.CX_TypeClass_FunctionProto) { - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); _paramTypes = new Lazy>(() => { var paramTypeCount = Handle.NumArgTypes; var paramTypes = new List(paramTypeCount); @@ -30,8 +28,6 @@ internal FunctionProtoType(CXType handle) : base(handle, CXTypeKind.CXType_Funct public CXCursor_ExceptionSpecificationKind ExceptionSpecType => Handle.ExceptionSpecificationType; - public bool IsSugared => Handle.IsSugared; - public bool IsVariadic => Handle.IsFunctionTypeVariadic; public uint NumParams => (uint)Handle.NumArgTypes; @@ -39,7 +35,5 @@ internal FunctionProtoType(CXType handle) : base(handle, CXTypeKind.CXType_Funct public IReadOnlyList ParamTypes => _paramTypes.Value; public CXRefQualifierKind RefQualifier => Handle.CXXRefQualifier; - - public Type Desugar() => _desugaredType.Value; } } diff --git a/sources/ClangSharp/Types/IncompleteArrayType.cs b/sources/ClangSharp/Types/IncompleteArrayType.cs index 615275ff..3aa1a899 100644 --- a/sources/ClangSharp/Types/IncompleteArrayType.cs +++ b/sources/ClangSharp/Types/IncompleteArrayType.cs @@ -1,21 +1,14 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. -using System; using ClangSharp.Interop; namespace ClangSharp { public sealed class IncompleteArrayType : ArrayType { - private readonly Lazy _desugaredType; internal IncompleteArrayType(CXType handle) : base(handle, CXTypeKind.CXType_IncompleteArray, CX_TypeClass.CX_TypeClass_IncompleteArray) { - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); } - - public bool IsSugared => Handle.IsSugared; - - public Type Desugar() => _desugaredType.Value; } } diff --git a/sources/ClangSharp/Types/InjectedClassNameType.cs b/sources/ClangSharp/Types/InjectedClassNameType.cs index 77b1c523..aae60aed 100644 --- a/sources/ClangSharp/Types/InjectedClassNameType.cs +++ b/sources/ClangSharp/Types/InjectedClassNameType.cs @@ -8,16 +8,16 @@ namespace ClangSharp public sealed class InjectedClassNameType : Type { private readonly Lazy _decl; - private readonly Lazy _desugaredType; private readonly Lazy _injectedSpecializationType; private readonly Lazy _injectedTST; + private readonly Lazy _templateName; internal InjectedClassNameType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_InjectedClassName) { _decl = new Lazy(() => TranslationUnit.GetOrCreate(handle.Declaration)); - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); _injectedSpecializationType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.InjectedSpecializationType)); _injectedTST = new Lazy(() => TranslationUnit.GetOrCreate(Handle.InjectedTST)); + _templateName = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TemplateName)); } public CXXRecordDecl Decl => _decl.Value; @@ -26,8 +26,6 @@ internal InjectedClassNameType(CXType handle) : base(handle, CXTypeKind.CXType_U public TemplateSpecializationType InjectedTST => _injectedTST.Value; - public bool IsSugared => Handle.IsSugared; - - public Type Desugar() => _desugaredType.Value; + public TemplateName TemplateName => _templateName.Value; } } diff --git a/sources/ClangSharp/Types/LValueReferenceType.cs b/sources/ClangSharp/Types/LValueReferenceType.cs index 7f4fdd06..22200f28 100644 --- a/sources/ClangSharp/Types/LValueReferenceType.cs +++ b/sources/ClangSharp/Types/LValueReferenceType.cs @@ -1,21 +1,14 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. -using System; using ClangSharp.Interop; namespace ClangSharp { public sealed class LValueReferenceType : ReferenceType { - private readonly Lazy _desugaredType; internal LValueReferenceType(CXType handle) : base(handle, CXTypeKind.CXType_LValueReference, CX_TypeClass.CX_TypeClass_LValueReference) { - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); } - - public bool IsSugared => Handle.IsSugared; - - public Type Desugar() => _desugaredType.Value; } } diff --git a/sources/ClangSharp/Types/MacroQualifiedType.cs b/sources/ClangSharp/Types/MacroQualifiedType.cs index 72c597e9..5ecbf412 100644 --- a/sources/ClangSharp/Types/MacroQualifiedType.cs +++ b/sources/ClangSharp/Types/MacroQualifiedType.cs @@ -7,23 +7,17 @@ namespace ClangSharp { public sealed class MacroQualifiedType : Type { - private readonly Lazy _desugaredType; private readonly Lazy _modifiedType; private readonly Lazy _underlyingType; internal MacroQualifiedType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_MacroQualified) { - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); _modifiedType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ModifiedType)); _underlyingType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.UnderlyingType)); } - public bool IsSugared => Handle.IsSugared; - public Type ModifiedType => _modifiedType.Value; public Type UnderlyingType => _underlyingType.Value; - - public Type Desugar() => _desugaredType.Value; } } diff --git a/sources/ClangSharp/Types/MatrixType.cs b/sources/ClangSharp/Types/MatrixType.cs index 69f91e67..1e2aee25 100644 --- a/sources/ClangSharp/Types/MatrixType.cs +++ b/sources/ClangSharp/Types/MatrixType.cs @@ -7,19 +7,13 @@ namespace ClangSharp { public class MatrixType : Type { - private readonly Lazy _desugaredType; private readonly Lazy _elementType; private protected MatrixType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass) { - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); _elementType = new Lazy(() => TranslationUnit.GetOrCreate(handle.ElementType)); } public Type ElementType => _elementType.Value; - - public bool IsSugared => Handle.IsSugared; - - public Type Desugar() => _desugaredType.Value; } } diff --git a/sources/ClangSharp/Types/MemberPointerType.cs b/sources/ClangSharp/Types/MemberPointerType.cs index 5da5c8e5..51985279 100644 --- a/sources/ClangSharp/Types/MemberPointerType.cs +++ b/sources/ClangSharp/Types/MemberPointerType.cs @@ -1,25 +1,13 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. -using System; using ClangSharp.Interop; namespace ClangSharp { public sealed class MemberPointerType : Type { - private readonly Lazy _desugaredType; - private readonly Lazy _pointeeType; - internal MemberPointerType(CXType handle) : base(handle, CXTypeKind.CXType_MemberPointer, CX_TypeClass.CX_TypeClass_MemberPointer) { - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); - _pointeeType = new Lazy(() => TranslationUnit.GetOrCreate(handle.PointeeType)); } - - public bool IsSugared => Handle.IsSugared; - - public Type PointeeType => _pointeeType.Value; - - public Type Desugar() => _desugaredType.Value; } } diff --git a/sources/ClangSharp/Types/ObjCInterfaceType.cs b/sources/ClangSharp/Types/ObjCInterfaceType.cs index 8b1a7b42..60557e61 100644 --- a/sources/ClangSharp/Types/ObjCInterfaceType.cs +++ b/sources/ClangSharp/Types/ObjCInterfaceType.cs @@ -1,13 +1,19 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; using ClangSharp.Interop; namespace ClangSharp { public sealed class ObjCInterfaceType : ObjCObjectType { + private readonly Lazy _decl; + internal ObjCInterfaceType(CXType handle) : base(handle, CXTypeKind.CXType_ObjCObject, CX_TypeClass.CX_TypeClass_ObjCInterface) { + _decl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Declaration)); } + + public ObjCInterfaceDecl Decl => _decl.Value; } } diff --git a/sources/ClangSharp/Types/ObjCObjectPointerType.cs b/sources/ClangSharp/Types/ObjCObjectPointerType.cs index ffefdd91..7cae4f34 100644 --- a/sources/ClangSharp/Types/ObjCObjectPointerType.cs +++ b/sources/ClangSharp/Types/ObjCObjectPointerType.cs @@ -1,13 +1,32 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; +using System.Collections.Generic; using ClangSharp.Interop; namespace ClangSharp { public sealed class ObjCObjectPointerType : Type { + private readonly Lazy _interfaceType; + private readonly Lazy _superClassType; + internal ObjCObjectPointerType(CXType handle) : base(handle, CXTypeKind.CXType_ObjCObjectPointer, CX_TypeClass.CX_TypeClass_ObjCObjectPointer) { + _interfaceType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.OriginalType)); + _superClassType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.UnderlyingType)); } + + public ObjCInterfaceDecl InterfaceDecl => ObjectType.Interface; + + public ObjCInterfaceType InterfaceType => _interfaceType.Value; + + public ObjCObjectType ObjectType => PointeeType.CastAs(); + + public IReadOnlyList Protocols => ObjectType.Protocols; + + public Type SuperClassType => _superClassType.Value; + + public IReadOnlyList TypeArgs => ObjectType.TypeArgs; } } diff --git a/sources/ClangSharp/Types/ObjCObjectType.cs b/sources/ClangSharp/Types/ObjCObjectType.cs index 7244a2b8..cfb6ce6c 100644 --- a/sources/ClangSharp/Types/ObjCObjectType.cs +++ b/sources/ClangSharp/Types/ObjCObjectType.cs @@ -1,17 +1,64 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; +using System.Collections.Generic; using ClangSharp.Interop; namespace ClangSharp { public class ObjCObjectType : Type { + private readonly Lazy _baseType; + private readonly Lazy _interface; + private readonly Lazy> _protocols; + private readonly Lazy _superClassType; + private readonly Lazy> _typeArgs; + internal ObjCObjectType(CXType handle) : this(handle, CXTypeKind.CXType_ObjCObject, CX_TypeClass.CX_TypeClass_ObjCObject) { } private protected ObjCObjectType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass) { + _baseType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ObjCObjectBaseType)); + _interface = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Declaration)); + + _protocols = new Lazy>(() => { + var numProtocols = unchecked((int)Handle.NumObjCProtocolRefs); + var protocols = new List(numProtocols); + + for (var i = 0; i < numProtocols; i++) + { + var protocol = TranslationUnit.GetOrCreate(Handle.GetObjCProtocolDecl(unchecked((uint)i))); + protocols.Add(protocol); + } + + return protocols; + }); + + _superClassType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.UnderlyingType)); + _typeArgs = new Lazy>(() => { + var numTypeArgs = unchecked((int)Handle.NumObjCTypeArgs); + var typeArgs = new List(numTypeArgs); + + for (var i = 0; i < numTypeArgs; i++) + { + var typeArg = TranslationUnit.GetOrCreate(Handle.GetObjCTypeArg(unchecked((uint)i))); + typeArgs.Add(typeArg); + } + + return typeArgs; + }); } + + public Type BaseType => _baseType.Value; + + public ObjCInterfaceDecl Interface => _interface.Value; + + public IReadOnlyList Protocols => _protocols.Value; + + public Type SuperClassType => _superClassType.Value; + + public IReadOnlyList TypeArgs => _typeArgs.Value; } } diff --git a/sources/ClangSharp/Types/ObjCTypeParamType.cs b/sources/ClangSharp/Types/ObjCTypeParamType.cs index 7623ebf3..ce80d2ba 100644 --- a/sources/ClangSharp/Types/ObjCTypeParamType.cs +++ b/sources/ClangSharp/Types/ObjCTypeParamType.cs @@ -1,13 +1,19 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. +using System; using ClangSharp.Interop; namespace ClangSharp { public sealed class ObjCTypeParamType : Type { + private readonly Lazy _decl; + internal ObjCTypeParamType(CXType handle) : base(handle, CXTypeKind.CXType_ObjCTypeParam, CX_TypeClass.CX_TypeClass_ObjCTypeParam) { + _decl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Declaration)); } + + public ObjCTypeParamDecl Decl => _decl.Value; } } diff --git a/sources/ClangSharp/Types/PackExpansionType.cs b/sources/ClangSharp/Types/PackExpansionType.cs index f79f8ae7..f7327a87 100644 --- a/sources/ClangSharp/Types/PackExpansionType.cs +++ b/sources/ClangSharp/Types/PackExpansionType.cs @@ -7,15 +7,13 @@ namespace ClangSharp { public sealed class PackExpansionType : Type { - private readonly Lazy _desugaredType; + private readonly Lazy _pattern; internal PackExpansionType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_PackExpansion) { - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); + _pattern = new Lazy(() => TranslationUnit.GetOrCreate(Handle.OriginalType)); } - public bool IsSugared => Handle.IsSugared; - - public Type Desugar() => _desugaredType.Value; + public Type Pattern => _pattern.Value; } } diff --git a/sources/ClangSharp/Types/ParenType.cs b/sources/ClangSharp/Types/ParenType.cs index 204946c7..bfc841bd 100644 --- a/sources/ClangSharp/Types/ParenType.cs +++ b/sources/ClangSharp/Types/ParenType.cs @@ -1,23 +1,16 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. -using System; using ClangSharp.Interop; namespace ClangSharp { public sealed class ParenType : Type { - private readonly Lazy _desugaredType; internal ParenType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_Paren) { - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); } - public Type InnerType => _desugaredType.Value; - - public bool IsSugared => Handle.IsSugared; - - public Type Desugar() => _desugaredType.Value; + public Type InnerType => Desugar; } } diff --git a/sources/ClangSharp/Types/PipeType.cs b/sources/ClangSharp/Types/PipeType.cs index 1fbef7e7..b322f63f 100644 --- a/sources/ClangSharp/Types/PipeType.cs +++ b/sources/ClangSharp/Types/PipeType.cs @@ -7,19 +7,13 @@ namespace ClangSharp { public sealed class PipeType : Type { - private readonly Lazy _desugaredType; private readonly Lazy _elementType; internal PipeType(CXType handle) : base(handle, CXTypeKind.CXType_Pipe, CX_TypeClass.CX_TypeClass_Pipe) { - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); _elementType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ElementType)); } public Type ElementType => _elementType.Value; - - public bool IsSugared => Handle.IsSugared; - - public Type Desugar() => _desugaredType.Value; } } diff --git a/sources/ClangSharp/Types/PointerType.cs b/sources/ClangSharp/Types/PointerType.cs index 02c47321..568b01a5 100644 --- a/sources/ClangSharp/Types/PointerType.cs +++ b/sources/ClangSharp/Types/PointerType.cs @@ -1,25 +1,13 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. -using System; using ClangSharp.Interop; namespace ClangSharp { public sealed class PointerType : Type { - private readonly Lazy _desugaredType; - private readonly Lazy _pointeeType; - internal PointerType(CXType handle) : base(handle, CXTypeKind.CXType_Pointer, CX_TypeClass.CX_TypeClass_Pointer) { - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); - _pointeeType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.PointeeType)); } - - public bool IsSugared => Handle.IsSugared; - - public Type PointeeType => _pointeeType.Value; - - public Type Desugar() => _desugaredType.Value; } } diff --git a/sources/ClangSharp/Types/RValueReferenceType.cs b/sources/ClangSharp/Types/RValueReferenceType.cs index 39a16a3c..0097b09d 100644 --- a/sources/ClangSharp/Types/RValueReferenceType.cs +++ b/sources/ClangSharp/Types/RValueReferenceType.cs @@ -1,20 +1,13 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. -using System; using ClangSharp.Interop; namespace ClangSharp { public sealed class RValueReferenceType : ReferenceType { - private readonly Lazy _desugaredType; internal RValueReferenceType(CXType handle) : base(handle, CXTypeKind.CXType_RValueReference, CX_TypeClass.CX_TypeClass_RValueReference) { - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); } - - public bool IsSugared => Handle.IsSugared; - - public Type Desugar() => _desugaredType.Value; } } diff --git a/sources/ClangSharp/Types/RecordType.cs b/sources/ClangSharp/Types/RecordType.cs index d59f84da..ecdc70c1 100644 --- a/sources/ClangSharp/Types/RecordType.cs +++ b/sources/ClangSharp/Types/RecordType.cs @@ -1,23 +1,16 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. -using System; using ClangSharp.Interop; namespace ClangSharp { public sealed class RecordType : TagType { - private readonly Lazy _desugaredType; internal RecordType(CXType handle) : base(handle, CXTypeKind.CXType_Record, CX_TypeClass.CX_TypeClass_Record) { - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); } public new RecordDecl Decl => (RecordDecl)base.Decl; - - public bool IsSugared => Handle.IsSugared; - - public Type Desugar() => _desugaredType.Value; } } diff --git a/sources/ClangSharp/Types/ReferenceType.cs b/sources/ClangSharp/Types/ReferenceType.cs index 96dc7a94..ae074c0e 100644 --- a/sources/ClangSharp/Types/ReferenceType.cs +++ b/sources/ClangSharp/Types/ReferenceType.cs @@ -1,19 +1,13 @@ // Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. -using System; using ClangSharp.Interop; namespace ClangSharp { public class ReferenceType : Type { - private readonly Lazy _pointeeType; - private protected ReferenceType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass) { - _pointeeType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.PointeeType)); } - - public Type PointeeType => _pointeeType.Value; } } diff --git a/sources/ClangSharp/Types/SubstTemplateTypeParmPackType.cs b/sources/ClangSharp/Types/SubstTemplateTypeParmPackType.cs index c86f1e61..63466cc5 100644 --- a/sources/ClangSharp/Types/SubstTemplateTypeParmPackType.cs +++ b/sources/ClangSharp/Types/SubstTemplateTypeParmPackType.cs @@ -7,14 +7,13 @@ namespace ClangSharp { public sealed class SubstTemplateTypeParmPackType : Type { - private readonly Lazy _desugaredType; + private readonly Lazy _argumentPack; + private readonly Lazy _replacedParameter; + internal SubstTemplateTypeParmPackType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_SubstTemplateTypeParmPack) { - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); + _argumentPack = new Lazy(() => TranslationUnit.GetOrCreate(Handle.GetTemplateArgument(0))); + _replacedParameter = new Lazy(() => TranslationUnit.GetOrCreate(Handle.OriginalType)); } - - public bool IsSugared => Handle.IsSugared; - - public Type Desugar() => _desugaredType.Value; } } diff --git a/sources/ClangSharp/Types/SubstTemplateTypeParmType.cs b/sources/ClangSharp/Types/SubstTemplateTypeParmType.cs index 37f15da8..565e9300 100644 --- a/sources/ClangSharp/Types/SubstTemplateTypeParmType.cs +++ b/sources/ClangSharp/Types/SubstTemplateTypeParmType.cs @@ -7,17 +7,15 @@ namespace ClangSharp { public sealed class SubstTemplateTypeParmType : Type { - private readonly Lazy _desugaredType; + private readonly Lazy _replacedParameter; internal SubstTemplateTypeParmType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_SubstTemplateTypeParm) { - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); + _replacedParameter = new Lazy(() => TranslationUnit.GetOrCreate(Handle.OriginalType)); } - public bool IsSugared => Handle.IsSugared; + public TemplateTypeParmType ReplacedParameter => _replacedParameter.Value; - public Type ReplacementType => _desugaredType.Value; - - public Type Desugar() => _desugaredType.Value; + public Type ReplacementType => Desugar; } } diff --git a/sources/ClangSharp/Types/TemplateSpecializationType.cs b/sources/ClangSharp/Types/TemplateSpecializationType.cs index 7ac38140..832461ca 100644 --- a/sources/ClangSharp/Types/TemplateSpecializationType.cs +++ b/sources/ClangSharp/Types/TemplateSpecializationType.cs @@ -8,34 +8,33 @@ namespace ClangSharp { public sealed class TemplateSpecializationType : Type { - private readonly Lazy _desugaredType; private readonly Lazy> _templateArgs; + private readonly Lazy _templateName; internal TemplateSpecializationType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_TemplateSpecialization) { - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); _templateArgs = new Lazy>(() => { var templateArgCount = Handle.NumTemplateArguments; var templateArgs = new List(templateArgCount); for (int i = 0; i < templateArgCount; i++) { - var templateArg = new TemplateArgument(this, unchecked((uint)i)); + var templateArg = TranslationUnit.GetOrCreate(Handle.GetTemplateArgument(unchecked((uint)i))); templateArgs.Add(templateArg); } return templateArgs; }); + + _templateName = new Lazy(() => TranslationUnit.GetOrCreate(Handle.TemplateName)); } - public Type AliasedType => IsTypeAlias ? _desugaredType.Value : null; + public Type AliasedType => IsTypeAlias ? Desugar : null; public IReadOnlyList Args => _templateArgs.Value; - public bool IsSugared => Handle.IsSugared; - public bool IsTypeAlias => Handle.IsTypeAlias; - public Type Desugar() => _desugaredType.Value; + public TemplateName TemplateName => _templateName.Value; } } diff --git a/sources/ClangSharp/Types/TemplateTypeParmType.cs b/sources/ClangSharp/Types/TemplateTypeParmType.cs index a0868bec..3d34ab37 100644 --- a/sources/ClangSharp/Types/TemplateTypeParmType.cs +++ b/sources/ClangSharp/Types/TemplateTypeParmType.cs @@ -8,12 +8,10 @@ namespace ClangSharp public sealed class TemplateTypeParmType : Type { private readonly Lazy _decl; - private readonly Lazy _desugaredType; internal TemplateTypeParmType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_TemplateTypeParm) { _decl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Declaration)); - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); } public TemplateTypeParmDecl Decl => _decl.Value; @@ -21,9 +19,5 @@ internal TemplateTypeParmType(CXType handle) : base(handle, CXTypeKind.CXType_Un public uint Depth => unchecked((uint)Handle.Depth); public uint Index => unchecked((uint)Handle.Index); - - public bool IsSugared => Handle.IsSugared; - - public Type Desugar() => _desugaredType.Value; } } diff --git a/sources/ClangSharp/Types/Type.cs b/sources/ClangSharp/Types/Type.cs index 8fd4ab9f..0fa23536 100644 --- a/sources/ClangSharp/Types/Type.cs +++ b/sources/ClangSharp/Types/Type.cs @@ -10,6 +10,8 @@ namespace ClangSharp public unsafe class Type : IEquatable { private readonly Lazy _canonicalType; + private readonly Lazy _desugar; + private readonly Lazy _pointeeType; private readonly Lazy _translationUnit; protected Type(CXType handle, CXTypeKind expectedKind, CX_TypeClass expectedTypeClass) @@ -26,15 +28,43 @@ protected Type(CXType handle, CXTypeKind expectedKind, CX_TypeClass expectedType Handle = handle; _canonicalType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.CanonicalType)); + _desugar = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar)); + _pointeeType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.PointeeType)); _translationUnit = new Lazy(() => TranslationUnit.GetOrCreate((CXTranslationUnit)Handle.data[1])); } + public CXXRecordDecl AsCXXRecordDecl => AsTagDecl as CXXRecordDecl; + public string AsString => Handle.Spelling.ToString(); + public TagDecl AsTagDecl + { + get + { + if (GetAs() is TagType TT) + { + return TT.Decl; + } + + if (GetAs() is InjectedClassNameType Injected) + { + return Injected.Decl; + } + + return null; + } + } + public Type CanonicalType => _canonicalType.Value; + public Type Desugar => _desugar.Value; + public CXType Handle { get; } + public bool IsAnyPointerType => IsAnyPointerType || IsObjCObjectPointerType; + + public bool IsExtIntType => CanonicalType is ExtIntType; + public bool IsIntegerType { get @@ -48,20 +78,61 @@ public bool IsIntegerType } } - public bool IsPointerType => this is PointerType; + public bool IsIntegralOrEnumerationType + { + get + { + if (CanonicalType is BuiltinType BT) + { + return (BT.Kind >= CXTypeKind.CXType_Bool) && (BT.Kind <= CXTypeKind.CXType_Int128); + } + + if (CanonicalType is EnumType ET) + { + return ET.Decl.IsComplete; + } + + return IsExtIntType; + } + } public bool IsLocalConstQualified => Handle.IsConstQualified; + public bool IsObjCObjectPointerType => CanonicalType is ObjCObjectPointerType; + + public bool IsPointerType => CanonicalType is PointerType; + + public bool IsSugared => Handle.IsSugared; + public CXTypeKind Kind => Handle.kind; public string KindSpelling => Handle.KindSpelling.ToString(); + public Type PointeeType => _pointeeType.Value; + public TranslationUnit TranslationUnit => _translationUnit.Value; public CX_TypeClass TypeClass => Handle.TypeClass; public string TypeClassSpelling => Handle.TypeClassSpelling; + public Type UnqualifiedDesugaredType + { + get + { + Type Cur = this; + + while (true) + { + if (!Cur.IsSugared) + { + return Cur; + } + Cur = Cur.Desugar; + } + } + } + public static bool operator ==(Type left, Type right) => (left is object) ? ((right is object) && (left.Handle == right.Handle)) : (right is null); public static bool operator !=(Type left, Type right) => (left is object) ? ((right is null) || (left.Handle != right.Handle)) : (right is object); @@ -123,6 +194,38 @@ public bool IsIntegerType public bool Equals(Type other) => this == other; + public T CastAs() + where T : Type + { + Debug.Assert(typeof(ArrayType).IsAssignableFrom(typeof(T)), "ArrayType cannot be used with castAs!"); + + if (this is T ty) + { + return ty; + } + + Debug.Assert(CanonicalType is T); + return (T)UnqualifiedDesugaredType; + } + + public T GetAs() + where T : Type + { + Debug.Assert(typeof(ArrayType).IsAssignableFrom(typeof(T)), "ArrayType cannot be used with getAs!"); + + if (this is T Ty) + { + return Ty; + } + + if (CanonicalType is not T) + { + return null; + } + + return (T)UnqualifiedDesugaredType; + } + public override int GetHashCode() => Handle.GetHashCode(); public override string ToString() => Handle.ToString(); diff --git a/sources/ClangSharp/Types/TypeOfExprType.cs b/sources/ClangSharp/Types/TypeOfExprType.cs index eec98a09..11801621 100644 --- a/sources/ClangSharp/Types/TypeOfExprType.cs +++ b/sources/ClangSharp/Types/TypeOfExprType.cs @@ -7,19 +7,13 @@ namespace ClangSharp { public sealed class TypeOfExprType : Type { - private readonly Lazy _desugaredType; private readonly Lazy _underlyingExpr; internal TypeOfExprType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_TypeOfExpr) { - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); _underlyingExpr = new Lazy(() => TranslationUnit.GetOrCreate(handle.UnderlyingExpr)); } - public bool IsSugared => Handle.IsSugared; - public Expr UnderlyingExpr => _underlyingExpr.Value; - - public Type Desugar() => _desugaredType.Value; } } diff --git a/sources/ClangSharp/Types/TypeOfType.cs b/sources/ClangSharp/Types/TypeOfType.cs index bb2abb37..2af59e56 100644 --- a/sources/ClangSharp/Types/TypeOfType.cs +++ b/sources/ClangSharp/Types/TypeOfType.cs @@ -7,19 +7,13 @@ namespace ClangSharp { public sealed class TypeOfType : Type { - private readonly Lazy _desugaredType; private readonly Lazy _underlyingType; internal TypeOfType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_TypeOf) { - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); _underlyingType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.UnderlyingType)); } - public bool IsSugared => Handle.IsSugared; - - public Type Desugar() => _desugaredType.Value; - public Type UnderlyingType => _underlyingType.Value; } } diff --git a/sources/ClangSharp/Types/TypedefType.cs b/sources/ClangSharp/Types/TypedefType.cs index 6e0cfd7e..d731d2a0 100644 --- a/sources/ClangSharp/Types/TypedefType.cs +++ b/sources/ClangSharp/Types/TypedefType.cs @@ -8,18 +8,12 @@ namespace ClangSharp public sealed class TypedefType : Type { private readonly Lazy _decl; - private readonly Lazy _desugaredType; internal TypedefType(CXType handle) : base(handle, CXTypeKind.CXType_Typedef, CX_TypeClass.CX_TypeClass_Typedef) { _decl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Declaration)); - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); } - public bool IsSugared => Handle.IsSugared; - - public Type Desugar() => _desugaredType.Value; - public TypedefNameDecl Decl => _decl.Value; } } diff --git a/sources/ClangSharp/Types/UnaryTransformType.cs b/sources/ClangSharp/Types/UnaryTransformType.cs index 729d64ed..c446e167 100644 --- a/sources/ClangSharp/Types/UnaryTransformType.cs +++ b/sources/ClangSharp/Types/UnaryTransformType.cs @@ -8,7 +8,6 @@ namespace ClangSharp public class UnaryTransformType : Type { private readonly Lazy _baseType; - private readonly Lazy _desugaredType; private readonly Lazy _underlyingType; internal UnaryTransformType(CXType handle) : this(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_UnaryTransform) @@ -18,16 +17,11 @@ internal UnaryTransformType(CXType handle) : this(handle, CXTypeKind.CXType_Unex private protected UnaryTransformType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass) { _baseType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.BaseType)); - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); _underlyingType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.UnderlyingType)); } public Type BaseType => _baseType.Value; - public bool IsSugared => Handle.IsSugared; - public Type UnderlyingType => _underlyingType.Value; - - public Type Desugar() => _desugaredType.Value; } } diff --git a/sources/ClangSharp/Types/UnresolvedUsingType.cs b/sources/ClangSharp/Types/UnresolvedUsingType.cs index f316d6e8..b588ec38 100644 --- a/sources/ClangSharp/Types/UnresolvedUsingType.cs +++ b/sources/ClangSharp/Types/UnresolvedUsingType.cs @@ -8,18 +8,12 @@ namespace ClangSharp public sealed class UnresolvedUsingType : Type { private readonly Lazy _decl; - private readonly Lazy _desugaredType; internal UnresolvedUsingType(CXType handle) : base(handle, CXTypeKind.CXType_Unexposed, CX_TypeClass.CX_TypeClass_UnresolvedUsing) { _decl = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Declaration)); - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); } public UnresolvedUsingTypenameDecl Decl => _decl.Value; - - public bool IsSugared => Handle.IsSugared; - - public Type Desugar() => _desugaredType.Value; } } diff --git a/sources/ClangSharp/Types/VariableArrayType.cs b/sources/ClangSharp/Types/VariableArrayType.cs index 2dd3859b..c4db2054 100644 --- a/sources/ClangSharp/Types/VariableArrayType.cs +++ b/sources/ClangSharp/Types/VariableArrayType.cs @@ -7,19 +7,13 @@ namespace ClangSharp { public sealed class VariableArrayType : ArrayType { - private readonly Lazy _desugaredType; private readonly Lazy _sizeExpr; internal VariableArrayType(CXType handle) : base(handle, CXTypeKind.CXType_VariableArray, CX_TypeClass.CX_TypeClass_VariableArray) { - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); _sizeExpr = new Lazy(() => TranslationUnit.GetOrCreate(handle.SizeExpr)); } - public bool IsSugared => Handle.IsSugared; - - public Type Desugar() => _desugaredType.Value; - public Expr SizeExpr => _sizeExpr.Value; } } diff --git a/sources/ClangSharp/Types/VectorType.cs b/sources/ClangSharp/Types/VectorType.cs index 7369a7dd..f86e4176 100644 --- a/sources/ClangSharp/Types/VectorType.cs +++ b/sources/ClangSharp/Types/VectorType.cs @@ -7,7 +7,6 @@ namespace ClangSharp { public class VectorType : Type { - private readonly Lazy _desugaredType; private readonly Lazy _elementType; internal VectorType(CXType handle) : base(handle, CXTypeKind.CXType_Vector, CX_TypeClass.CX_TypeClass_Vector) @@ -16,16 +15,11 @@ internal VectorType(CXType handle) : base(handle, CXTypeKind.CXType_Vector, CX_T private protected VectorType(CXType handle, CXTypeKind expectedTypeKind, CX_TypeClass expectedTypeClass) : base(handle, expectedTypeKind, expectedTypeClass) { - _desugaredType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.Desugar())); _elementType = new Lazy(() => TranslationUnit.GetOrCreate(Handle.ElementType)); } public Type ElementType => _elementType.Value; - public bool IsSugared => Handle.IsSugared; - public long NumElements => Handle.NumElements; - - public Type Desugar() => _desugaredType.Value; } } diff --git a/sources/libClangSharp/CIndexDiagnostic.h b/sources/libClangSharp/CIndexDiagnostic.h index 6c40b0a6..14dd16cb 100644 --- a/sources/libClangSharp/CIndexDiagnostic.h +++ b/sources/libClangSharp/CIndexDiagnostic.h @@ -6,6 +6,9 @@ #ifndef LIBCLANGSHARP_CINDEXDIAGNOSTIC_H #define LIBCLANGSHARP_CINDEXDIAGNOSTIC_H +#pragma warning(push) +#pragma warning(disable : 4146 4244 4267 4291 4624 4996) + #include #include @@ -14,6 +17,8 @@ #include #include +#pragma warning(pop) + namespace clang { class CXDiagnosticImpl; diff --git a/sources/libClangSharp/CXCursor.cpp b/sources/libClangSharp/CXCursor.cpp index 12ead1a7..e90fe3df 100644 --- a/sources/libClangSharp/CXCursor.cpp +++ b/sources/libClangSharp/CXCursor.cpp @@ -908,4 +908,9 @@ namespace clang::cxcursor { CXCursor C = { K, 0, { Parent, S, TU } }; return C; } + + CXCursor MakeCXCursor(const CXXBaseSpecifier* B, CXTranslationUnit TU) { + CXCursor C = { CXCursor_CXXBaseSpecifier, 0, { B, nullptr, TU } }; + return C; + } } diff --git a/sources/libClangSharp/CXCursor.h b/sources/libClangSharp/CXCursor.h index a9070121..39375b7e 100644 --- a/sources/libClangSharp/CXCursor.h +++ b/sources/libClangSharp/CXCursor.h @@ -6,6 +6,9 @@ #ifndef LIBCLANGSHARP_CXCURSOR_H #define LIBCLANGSHARP_CXCURSOR_H +#pragma warning(push) +#pragma warning(disable : 4146 4244 4267 4291 4624 4996) + #include #include #include @@ -20,6 +23,8 @@ #include +#pragma warning(pop) + namespace clang::cxcursor { typedef llvm::PointerUnion OverloadedDeclRefStorage; @@ -116,6 +121,7 @@ namespace clang::cxcursor { bool isFirstInDeclGroup(CXCursor C); CXCursor MakeCXCursor(const Attr* A, const Decl* Parent, CXTranslationUnit TU); + CXCursor MakeCXCursor(const CXXBaseSpecifier* B, CXTranslationUnit TU); CXCursor MakeCXCursor(const Decl* D, CXTranslationUnit TU, SourceRange RegionOfInterest = SourceRange(), bool FirstInDeclGroup = true); CXCursor MakeCXCursor(const Stmt* S, const Decl* Parent, CXTranslationUnit TU, SourceRange RegionOfInterest = SourceRange()); } diff --git a/sources/libClangSharp/CXLoadedDiagnostic.cpp b/sources/libClangSharp/CXLoadedDiagnostic.cpp index 25a37e3c..bc1fe9ae 100644 --- a/sources/libClangSharp/CXLoadedDiagnostic.cpp +++ b/sources/libClangSharp/CXLoadedDiagnostic.cpp @@ -6,9 +6,14 @@ #include "CXLoadedDiagnostic.h" #include "CXString.h" +#pragma warning(push) +#pragma warning(disable : 4146 4244 4267 4291 4624 4996) + #include #include +#pragma warning(pop) + namespace clang { CXLoadedDiagnostic::~CXLoadedDiagnostic() { } diff --git a/sources/libClangSharp/CXLoadedDiagnostic.h b/sources/libClangSharp/CXLoadedDiagnostic.h index b8e77fd6..a7c9c09e 100644 --- a/sources/libClangSharp/CXLoadedDiagnostic.h +++ b/sources/libClangSharp/CXLoadedDiagnostic.h @@ -7,8 +7,14 @@ #define LIBCLANGSHARP_CXLOADEDDIAGNOSTIC_H #include "CIndexDiagnostic.h" + +#pragma warning(push) +#pragma warning(disable : 4146 4244 4267 4291 4624 4996) + #include +#pragma warning(pop) + namespace clang { class CXLoadedDiagnostic : public CXDiagnosticImpl { public: diff --git a/sources/libClangSharp/CXSourceLocation.cpp b/sources/libClangSharp/CXSourceLocation.cpp index e52773a5..17471bce 100644 --- a/sources/libClangSharp/CXSourceLocation.cpp +++ b/sources/libClangSharp/CXSourceLocation.cpp @@ -7,10 +7,15 @@ #include "CXCursor.h" #include "CXSourceLocation.h" +#pragma warning(push) +#pragma warning(disable : 4146 4244 4267 4291 4624 4996) + #include #include #include +#pragma warning(pop) + void createNullLocation(CXFile* file, unsigned* line, unsigned* column, unsigned* offset) { if (file) *file = nullptr; diff --git a/sources/libClangSharp/CXSourceLocation.h b/sources/libClangSharp/CXSourceLocation.h index ef5e0695..7b5242e2 100644 --- a/sources/libClangSharp/CXSourceLocation.h +++ b/sources/libClangSharp/CXSourceLocation.h @@ -6,11 +6,16 @@ #ifndef LIBCLANGSHARP_CXSOURCELOCATION_H #define LIBCLANGSHARP_CXSOURCELOCATION_H +#pragma warning(push) +#pragma warning(disable : 4146 4244 4267 4291 4624 4996) + #include #include #include #include +#pragma warning(pop) + void createNullLocation(CXFile* file, unsigned* line, unsigned* column, unsigned* offset); clang::SourceRange getCursorSourceRange(CXCursor C); diff --git a/sources/libClangSharp/CXString.cpp b/sources/libClangSharp/CXString.cpp index 8986420d..4c96d0b5 100644 --- a/sources/libClangSharp/CXString.cpp +++ b/sources/libClangSharp/CXString.cpp @@ -4,8 +4,14 @@ // Original source is Copyright (c) the LLVM Project and Contributors. Licensed under the Apache License v2.0 with LLVM Exceptions. See NOTICE.txt in the project root for license information. #include "CXString.h" + +#pragma warning(push) +#pragma warning(disable : 4146 4244 4267 4291 4624 4996) + #include +#pragma warning(pop) + namespace clang::cxstring { CXString createDup(llvm::StringRef String) { CXString Result; diff --git a/sources/libClangSharp/CXString.h b/sources/libClangSharp/CXString.h index 3fd733b9..f018696e 100644 --- a/sources/libClangSharp/CXString.h +++ b/sources/libClangSharp/CXString.h @@ -6,9 +6,14 @@ #ifndef LIBCLANGSHARP_CXSTRING_H #define LIBCLANGSHARP_CXSTRING_H +#pragma warning(push) +#pragma warning(disable : 4146 4244 4267 4291 4624 4996) + #include #include +#pragma warning(pop) + /// Describes the kind of underlying data in CXString. enum CXStringFlag { /// CXString contains a 'const char*' that it doesn't own. diff --git a/sources/libClangSharp/CXTranslationUnit.h b/sources/libClangSharp/CXTranslationUnit.h index 638845bd..3ededd5f 100644 --- a/sources/libClangSharp/CXTranslationUnit.h +++ b/sources/libClangSharp/CXTranslationUnit.h @@ -6,9 +6,14 @@ #ifndef LIBCLANGSHARP_CXTRANSLATIONUNIT_H #define LIBCLANGSHARP_CXTRANSLATIONUNIT_H +#pragma warning(push) +#pragma warning(disable : 4146 4244 4267 4291 4624 4996) + #include #include +#pragma warning(pop) + namespace clang { class CIndexer; } diff --git a/sources/libClangSharp/CXType.h b/sources/libClangSharp/CXType.h index 57e9ee1d..cc212138 100644 --- a/sources/libClangSharp/CXType.h +++ b/sources/libClangSharp/CXType.h @@ -6,9 +6,14 @@ #ifndef LIBCLANGSHARP_CXTYPE_H #define LIBCLANGSHARP_CXTYPE_H +#pragma warning(push) +#pragma warning(disable : 4146 4244 4267 4291 4624 4996) + #include #include +#pragma warning(pop) + clang::QualType GetQualType(CXType CT); CXTranslationUnit GetTypeTU(CXType CT); diff --git a/sources/libClangSharp/ClangSharp.cpp b/sources/libClangSharp/ClangSharp.cpp index a9d2087a..baf68fe2 100644 --- a/sources/libClangSharp/ClangSharp.cpp +++ b/sources/libClangSharp/ClangSharp.cpp @@ -8,8 +8,13 @@ #include "CXTranslationUnit.h" #include "CXType.h" +#pragma warning(push) +#pragma warning(disable : 4146 4244 4267 4291 4624 4996) + #include +#pragma warning(pop) + using namespace clang; using namespace clang::cxcursor; using namespace clang::cxloc; @@ -17,16 +22,107 @@ using namespace clang::cxstring; using namespace clang::cxtu; using namespace clang::cxtype; +CX_TemplateArgument MakeCXTemplateArgument(const TemplateArgument* TA, CXTranslationUnit TU, bool needsDispose = false) { + if (TA) { + assert(TU && "Invalid arguments!"); + return { static_cast(TA->getKind()), (needsDispose ? 1 : 0), TA, TU }; + } + + return { }; +} + +CX_TemplateArgumentLoc MakeCXTemplateArgumentLoc(const TemplateArgumentLoc* TAL, CXTranslationUnit TU) { + if (TAL) { + assert(TU && "Invalid arguments!"); + return { TAL, TU }; + } + + return { }; +} + +CX_TemplateName MakeCXTemplateName(const TemplateName TN, CXTranslationUnit TU) { + if (TN.getAsVoidPointer()) { + assert(TU && "Invalid arguments!"); + return { static_cast(TN.getKind() + 1), TN.getAsVoidPointer(), TU }; + } + + return { }; +} + +bool isAttr(CXCursorKind kind) { + return clang_isAttribute(kind); +} + +bool isDeclOrTU(CXCursorKind kind) { + return clang_isDeclaration(kind) || clang_isTranslationUnit(kind); +} + +bool isStmtOrExpr(CXCursorKind kind) { + return clang_isStatement(kind) || clang_isExpression(kind); +} + CXCursor clangsharp_Cursor_getArgument(CXCursor C, unsigned i) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const BlockDecl* BD = dyn_cast(D)) { - return MakeCXCursor(BD->parameters()[i], getCursorTU(C)); + if (i < BD->getNumParams()) { + return MakeCXCursor(BD->parameters()[i], getCursorTU(C)); + } } if (const CapturedDecl* CD = dyn_cast(D)) { - return MakeCXCursor(CD->parameters()[i], getCursorTU(C)); + if (i < CD->getNumParams()) { + return MakeCXCursor(CD->parameters()[i], getCursorTU(C)); + } + } + + if (const ObjCCategoryDecl* OCCD = dyn_cast(D)) { + ObjCTypeParamList* typeParamList = OCCD->getTypeParamList(); + + if (i < typeParamList->size()) { + return MakeCXCursor(&typeParamList->front()[i], getCursorTU(C)); + } + } + } + + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + + if (const CastExpr* CE = dyn_cast(S)) { + unsigned n = 0; + + for (auto path : CE->path()) { + if (n == i) { + return MakeCXCursor(path, getCursorTU(C)); + } + n++; + } + } + + if (const CXXUnresolvedConstructExpr* CXXUCE = dyn_cast(S)) { + if (i < CXXUCE->arg_size()) { + return MakeCXCursor(CXXUCE->getArg(i), getCursorDecl(C), getCursorTU(C)); + } + } + + if (const ExprWithCleanups* EWC = dyn_cast(S)) { + if (i < EWC->getNumObjects()) { + llvm::PointerUnion object = EWC->getObject(i); + + if (object.is()) { + return MakeCXCursor(object.get(), getCursorTU(C)); + } + else { + return MakeCXCursor(object.get(), getCursorDecl(C), getCursorTU(C)); + } + } + } + + if (const ObjCMessageExpr* OCME = dyn_cast(S)) { + if (i < OCME->getNumArgs()) { + return MakeCXCursor(OCME->getArgs()[i], getCursorDecl(C), getCursorTU(C)); + } } } @@ -34,10 +130,10 @@ CXCursor clangsharp_Cursor_getArgument(CXCursor C, unsigned i) { } CXType clangsharp_Cursor_getArgumentType(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const UnaryExprOrTypeTraitExpr* UETTE = dyn_cast(E)) { + if (const UnaryExprOrTypeTraitExpr* UETTE = dyn_cast(S)) { if (UETTE->isArgumentType()) { return MakeCXType(UETTE->getArgumentType(), getCursorTU(C)); } @@ -48,10 +144,10 @@ CXType clangsharp_Cursor_getArgumentType(CXCursor C) { } int64_t clangsharp_Cursor_getArraySize(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const ArrayInitLoopExpr* AILE = dyn_cast(E)) { + if (const ArrayInitLoopExpr* AILE = dyn_cast(S)) { return AILE->getArraySize().getSExtValue(); } } @@ -60,37 +156,52 @@ int64_t clangsharp_Cursor_getArraySize(CXCursor C) { } CXCursor clangsharp_Cursor_getAssociatedConstraint(CXCursor C, unsigned i) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const ClassTemplatePartialSpecializationDecl* CTPSD = dyn_cast(D)) { SmallVector associatedConstraints; CTPSD->getAssociatedConstraints(associatedConstraints); - return MakeCXCursor(associatedConstraints[i], CTPSD, getCursorTU(C)); + + if (i < associatedConstraints.size()) { + return MakeCXCursor(associatedConstraints[i], CTPSD, getCursorTU(C)); + } } if (const NonTypeTemplateParmDecl* NTTPD = dyn_cast(D)) { SmallVector associatedConstraints; NTTPD->getAssociatedConstraints(associatedConstraints); - return MakeCXCursor(associatedConstraints[i], NTTPD, getCursorTU(C)); + + if (i < associatedConstraints.size()) { + return MakeCXCursor(associatedConstraints[i], NTTPD, getCursorTU(C)); + } } if (const TemplateDecl* TD = dyn_cast(D)) { SmallVector associatedConstraints; TD->getAssociatedConstraints(associatedConstraints); - return MakeCXCursor(associatedConstraints[i], TD, getCursorTU(C)); + + if (i < associatedConstraints.size()) { + return MakeCXCursor(associatedConstraints[i], TD, getCursorTU(C)); + } } if (const TemplateTypeParmDecl* TTPD = dyn_cast(D)) { SmallVector associatedConstraints; TTPD->getAssociatedConstraints(associatedConstraints); - return MakeCXCursor(associatedConstraints[i], TTPD, getCursorTU(C)); + + if (i < associatedConstraints.size()) { + return MakeCXCursor(associatedConstraints[i], TTPD, getCursorTU(C)); + } } if (const VarTemplatePartialSpecializationDecl* VTPSD = dyn_cast(D)) { SmallVector associatedConstraints; VTPSD->getAssociatedConstraints(associatedConstraints); - return MakeCXCursor(associatedConstraints[i], VTPSD, getCursorTU(C)); + + if (i < associatedConstraints.size()) { + return MakeCXCursor(associatedConstraints[i], VTPSD, getCursorTU(C)); + } } } @@ -98,7 +209,7 @@ CXCursor clangsharp_Cursor_getAssociatedConstraint(CXCursor C, unsigned i) { } CXCursor clangsharp_Cursor_getAsFunction(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); return MakeCXCursor(D->getAsFunction(), getCursorTU(C)); } @@ -106,6 +217,43 @@ CXCursor clangsharp_Cursor_getAsFunction(CXCursor C) { return clang_getNullCursor(); } +CX_AtomicOperatorKind clangsharp_Cursor_getAtomicOpcode(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + + if (const AtomicExpr* AE = dyn_cast(S)) { + return static_cast(AE->getOp() + 1); + } + } + + return CX_AO_Invalid; +} + +CXCursor clangsharp_Cursor_getAttr(CXCursor C, unsigned i) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + SmallVector attrs = D->getAttrs(); + + if (i < attrs.size()) { + return MakeCXCursor(attrs[i], D, getCursorTU(C)); + } + } + + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + + if (const AttributedStmt* AS = dyn_cast(S)) { + ArrayRef attrs = AS->getAttrs(); + + if (i < attrs.size()) { + return MakeCXCursor(attrs[i], getCursorDecl(C), getCursorTU(C)); + } + } + } + + return clang_Cursor_getArgument(C, i); +} + CX_AttrKind clangsharp_Cursor_getAttrKind(CXCursor C) { if (clang_isAttribute(C.kind)) { const Attr* A = getCursorAttr(C); @@ -115,16 +263,21 @@ CX_AttrKind clangsharp_Cursor_getAttrKind(CXCursor C) { return CX_AttrKind_Invalid; } -CXCursor clangsharp_Cursor_getBaseExpr(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); +CXCursor clangsharp_Cursor_getBase(CXCursor C, unsigned i) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); - if (const ArraySubscriptExpr* ASE = dyn_cast(E)) { - return MakeCXCursor(ASE->getBase(), getCursorDecl(C), getCursorTU(C)); - } + if (const CXXRecordDecl* CXXRD = dyn_cast(D)) { + if (CXXRD->getDefinition()) { + unsigned n = 0; - if (const MatrixSubscriptExpr* MSE = dyn_cast(E)) { - return MakeCXCursor(MSE->getBase(), getCursorDecl(C), getCursorTU(C)); + for (auto& base : CXXRD->bases()) { + if (n == i) { + return MakeCXCursor(&base, getCursorTU(C)); + } + n++; + } + } } } @@ -132,18 +285,18 @@ CXCursor clangsharp_Cursor_getBaseExpr(CXCursor C) { } CX_BinaryOperatorKind clangsharp_Cursor_getBinaryOpcode(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const BinaryOperator* BO = dyn_cast(E)) { + if (const BinaryOperator* BO = dyn_cast(S)) { return static_cast(BO->getOpcode() + 1); } - if (const CXXFoldExpr* CFE = dyn_cast(E)) { + if (const CXXFoldExpr* CFE = dyn_cast(S)) { return static_cast(CFE->getOperator() + 1); } - if (const CXXRewrittenBinaryOperator* CRBO = dyn_cast(E)) { + if (const CXXRewrittenBinaryOperator* CRBO = dyn_cast(S)) { return static_cast(CRBO->getOperator() + 1); } } @@ -160,8 +313,22 @@ CXString clangsharp_Cursor_getBinaryOpcodeSpelling(CX_BinaryOperatorKind Op) { return createEmpty(); } -CXCursor clangsharp_Cursor_getBinding(CXCursor C) { - if (clang_isDeclaration(C.kind)) { +CXCursor clangsharp_Cursor_getBindingDecl(CXCursor C, unsigned i) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const DecompositionDecl* DD = dyn_cast(D)) { + if (i < DD->bindings().size()) { + return MakeCXCursor(DD->bindings()[i], getCursorTU(C)); + } + } + } + + return clang_getNullCursor(); +} + +CXCursor clangsharp_Cursor_getBindingExpr(CXCursor C) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const BindingDecl* BD = dyn_cast(D)) { @@ -173,7 +340,7 @@ CXCursor clangsharp_Cursor_getBinding(CXCursor C) { } CXCursor clangsharp_Cursor_getBitWidth(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const FieldDecl* FD = dyn_cast(D)) { @@ -185,7 +352,7 @@ CXCursor clangsharp_Cursor_getBitWidth(CXCursor C) { } CXCursor clangsharp_Cursor_getBlockManglingContextDecl(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const BlockDecl* BD = dyn_cast(D)) { @@ -197,7 +364,7 @@ CXCursor clangsharp_Cursor_getBlockManglingContextDecl(CXCursor C) { } int clangsharp_Cursor_getBlockManglingNumber(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const BlockDecl* BD = dyn_cast(D)) { @@ -209,7 +376,7 @@ int clangsharp_Cursor_getBlockManglingNumber(CXCursor C) { } unsigned clangsharp_Cursor_getBlockMissingReturnType(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const BlockDecl* BD = dyn_cast(D)) { @@ -221,60 +388,16 @@ unsigned clangsharp_Cursor_getBlockMissingReturnType(CXCursor C) { } CXCursor clangsharp_Cursor_getBody(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); return MakeCXCursor(D->getBody(), D, getCursorTU(C)); } - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); - - if (const BlockExpr* BE = dyn_cast(E)) { - return MakeCXCursor(BE->getBody(), getCursorDecl(C), getCursorTU(C)); - } - } - - if (clang_isStatement(C.kind)) { - const Stmt* S = getCursorStmt(C); - - if (const DoStmt* DS = dyn_cast(S)) { - return MakeCXCursor(DS->getBody(), getCursorDecl(C), getCursorTU(C)); - } - - if (const ForStmt* FS = dyn_cast(S)) { - return MakeCXCursor(FS->getBody(), getCursorDecl(C), getCursorTU(C)); - } - - if (const IfStmt* IS = dyn_cast(S)) { - return MakeCXCursor(IS->getThen(), getCursorDecl(C), getCursorTU(C)); - } - - if (const SwitchStmt* SS = dyn_cast(S)) { - return MakeCXCursor(SS->getBody(), getCursorDecl(C), getCursorTU(C)); - } - - if (const WhileStmt* WS = dyn_cast(S)) { - return MakeCXCursor(WS->getBody(), getCursorDecl(C), getCursorTU(C)); - } - } - - return clang_getNullCursor(); -} - -CXCursor clangsharp_Cursor_getCalleeExpr(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); - - if (const CallExpr* CE = dyn_cast (E)) { - return MakeCXCursor(CE->getCallee(), getCursorDecl(C), getCursorTU(C)); - } - } - return clang_getNullCursor(); } CXType clangsharp_Cursor_getCallResultType(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const FunctionDecl* FD = dyn_cast(D)) { @@ -286,7 +409,7 @@ CXType clangsharp_Cursor_getCallResultType(CXCursor C) { } unsigned clangsharp_Cursor_getCanAvoidCopyToHeap(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const BlockDecl* BD = dyn_cast(D)) { @@ -297,24 +420,79 @@ unsigned clangsharp_Cursor_getCanAvoidCopyToHeap(CXCursor C) { return 0; } +CXCursor clangsharp_Cursor_getCanonical(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + return MakeCXCursor(D->getCanonicalDecl(), getCursorTU(C)); + } + + return clang_getCanonicalCursor(C); +} + CXCursor clangsharp_Cursor_getCaptureCopyExpr(CXCursor C, unsigned i) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const BlockDecl* BD = dyn_cast(D)) { - return MakeCXCursor(BD->captures()[i].getCopyExpr(), BD, getCursorTU(C)); + ArrayRef captures = BD->captures(); + + if (i < captures.size()) { + return MakeCXCursor(captures[i].getCopyExpr(), BD, getCursorTU(C)); + } + } + } + + return clang_getNullCursor(); +} + +CXCursor clangsharp_Cursor_getCapturedVar(CXCursor C, unsigned i) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + + if (const CapturedStmt* CS = dyn_cast(S)) { + unsigned n = 0; + + for (auto capture : CS->captures()) { + if (n == i) { + return MakeCXCursor(capture.getCapturedVar(), getCursorTU(C)); + } + n++; + } } } return clang_getNullCursor(); } +CX_VariableCaptureKind clangsharp_Cursor_getCaptureKind(CXCursor C, unsigned i) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + + if (const CapturedStmt* CS = dyn_cast(S)) { + unsigned n = 0; + + for (auto capture : CS->captures()) { + if (n == i) { + return static_cast(capture.getCaptureKind() + 1); + } + n++; + } + } + } + + return CX_VCK_Invalid; +} + unsigned clangsharp_Cursor_getCaptureHasCopyExpr(CXCursor C, unsigned i) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const BlockDecl* BD = dyn_cast(D)) { - return BD->captures()[i].hasCopyExpr(); + ArrayRef captures = BD->captures(); + + if (i < captures.size()) { + return captures[i].hasCopyExpr(); + } } } @@ -322,11 +500,15 @@ unsigned clangsharp_Cursor_getCaptureHasCopyExpr(CXCursor C, unsigned i) { } unsigned clangsharp_Cursor_getCaptureIsByRef(CXCursor C, unsigned i) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const BlockDecl* BD = dyn_cast(D)) { - return BD->captures()[i].isByRef(); + ArrayRef captures = BD->captures(); + + if (i < captures.size()) { + return captures[i].isByRef(); + } } } @@ -334,11 +516,15 @@ unsigned clangsharp_Cursor_getCaptureIsByRef(CXCursor C, unsigned i) { } unsigned clangsharp_Cursor_getCaptureIsEscapingByRef(CXCursor C, unsigned i) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const BlockDecl* BD = dyn_cast(D)) { - return BD->captures()[i].isEscapingByref(); + ArrayRef captures = BD->captures(); + + if (i < captures.size()) { + return captures[i].isEscapingByref(); + } } } @@ -346,11 +532,15 @@ unsigned clangsharp_Cursor_getCaptureIsEscapingByRef(CXCursor C, unsigned i) { } unsigned clangsharp_Cursor_getCaptureIsNested(CXCursor C, unsigned i) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const BlockDecl* BD = dyn_cast(D)) { - return BD->captures()[i].isNested(); + ArrayRef captures = BD->captures(); + + if (i < captures.size()) { + return captures[i].isNested(); + } } } @@ -358,19 +548,71 @@ unsigned clangsharp_Cursor_getCaptureIsNested(CXCursor C, unsigned i) { } unsigned clangsharp_Cursor_getCaptureIsNonEscapingByRef(CXCursor C, unsigned i) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const BlockDecl* BD = dyn_cast(D)) { - return BD->captures()[i].isNonEscapingByref(); + ArrayRef captures = BD->captures(); + + if (i < captures.size()) { + return captures[i].isNonEscapingByref(); + } } } return 0; } +CXCursor clangsharp_Cursor_getCapturedDecl(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + + if (const CapturedStmt* CS = dyn_cast(S)) { + return MakeCXCursor(CS->getCapturedDecl(), getCursorTU(C)); + } + } + + return clang_getNullCursor(); +} + +CXCursor clangsharp_Cursor_getCapturedRecordDecl(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + + if (const CapturedStmt* CS = dyn_cast(S)) { + return MakeCXCursor(CS->getCapturedRecordDecl(), getCursorTU(C)); + } + } + + return clang_getNullCursor(); +} + +CX_CapturedRegionKind clangsharp_Cursor_getCapturedRegionKind(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + + if (const CapturedStmt* CS = dyn_cast(S)) { + return static_cast(CS->getCapturedRegionKind() + 1); + } + } + + return CX_CR_Invalid; +} + +CXCursor clangsharp_Cursor_getCapturedStmt(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + + if (const CapturedStmt* CS = dyn_cast(S)) { + return MakeCXCursor(CS->getCapturedStmt(), getCursorDecl(C), getCursorTU(C)); + } + } + + return clang_getNullCursor(); +} + unsigned clangsharp_Cursor_getCapturesCXXThis(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const BlockDecl* BD = dyn_cast(D)) { @@ -382,7 +624,7 @@ unsigned clangsharp_Cursor_getCapturesCXXThis(CXCursor C) { } unsigned clangsharp_Cursor_getCapturesVariable(CXCursor C, CXCursor V) { - if (clang_isDeclaration(C.kind) && clang_isDeclaration(V.kind)) { + if (isDeclOrTU(C.kind) && isDeclOrTU(V.kind)) { const BlockDecl* BD = dyn_cast(getCursorDecl(C)); const VarDecl* VD = dyn_cast(getCursorDecl(V)); @@ -395,11 +637,15 @@ unsigned clangsharp_Cursor_getCapturesVariable(CXCursor C, CXCursor V) { } CXCursor clangsharp_Cursor_getCaptureVariable(CXCursor C, unsigned i) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const BlockDecl* BD = dyn_cast(D)) { - return MakeCXCursor(BD->captures()[i].getVariable(), getCursorTU(C)); + ArrayRef captures = BD->captures(); + + if (i < captures.size()) { + return MakeCXCursor(captures[i].getVariable(), getCursorTU(C)); + } } } @@ -407,10 +653,10 @@ CXCursor clangsharp_Cursor_getCaptureVariable(CXCursor C, unsigned i) { } CX_CastKind clangsharp_Cursor_getCastKind(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const CastExpr* CastEx = dyn_cast(E)) { + if (const CastExpr* CastEx = dyn_cast(S)) { return static_cast(CastEx->getCastKind() + 1); } } @@ -419,14 +665,14 @@ CX_CastKind clangsharp_Cursor_getCastKind(CXCursor C) { } CX_CharacterKind clangsharp_Cursor_getCharacterLiteralKind(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const CharacterLiteral* CL = dyn_cast(E)) { + if (const CharacterLiteral* CL = dyn_cast(S)) { return static_cast(CL->getKind() + 1); } - if (const StringLiteral* SL = dyn_cast(E)) { + if (const StringLiteral* SL = dyn_cast(S)) { return static_cast(SL->getKind() + 1); } } @@ -435,10 +681,10 @@ CX_CharacterKind clangsharp_Cursor_getCharacterLiteralKind(CXCursor C) { } unsigned clangsharp_Cursor_getCharacterLiteralValue(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const CharacterLiteral* CL = dyn_cast(E)) { + if (const CharacterLiteral* CL = dyn_cast(S)) { return CL->getValue(); } } @@ -446,28 +692,17 @@ unsigned clangsharp_Cursor_getCharacterLiteralValue(CXCursor C) { return 0; } -CXCursor clangsharp_Cursor_getColumnIdxExpr(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); - - if (const MatrixSubscriptExpr* MSE = dyn_cast(E)) { - return MakeCXCursor(MSE->getColumnIdx(), getCursorDecl(C), getCursorTU(C)); - } - } - - return clang_getNullCursor(); -} - -CXCursor clangsharp_Cursor_getCommonExpr(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); +CXCursor clangsharp_Cursor_getChild(CXCursor C, unsigned i) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const ArrayInitLoopExpr* AILE = dyn_cast(E)) { - return MakeCXCursor(AILE->getCommonExpr(), getCursorDecl(C), getCursorTU(C)); - } + unsigned n = 0; - if (const BinaryConditionalOperator* BCO = dyn_cast(E)) { - return MakeCXCursor(BCO->getCommon(), getCursorDecl(C), getCursorTU(C)); + for (auto child : S->children()) { + if (n == i) { + return MakeCXCursor(child, getCursorDecl(C), getCursorTU(C)); + } + n++; } } @@ -475,10 +710,10 @@ CXCursor clangsharp_Cursor_getCommonExpr(CXCursor C) { } CXType clangsharp_Cursor_getComputationLhsType(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const CompoundAssignOperator* CAO = dyn_cast(E)) { + if (const CompoundAssignOperator* CAO = dyn_cast(S)) { return MakeCXType(CAO->getComputationLHSType(), getCursorTU(C)); } } @@ -487,10 +722,10 @@ CXType clangsharp_Cursor_getComputationLhsType(CXCursor C) { } CXType clangsharp_Cursor_getComputationResultType(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const CompoundAssignOperator* CAO = dyn_cast(E)) { + if (const CompoundAssignOperator* CAO = dyn_cast(S)) { return MakeCXType(CAO->getComputationResultType(), getCursorTU(C)); } } @@ -498,68 +733,8 @@ CXType clangsharp_Cursor_getComputationResultType(CXCursor C) { return MakeCXType(QualType(), getCursorTU(C)); } -CXCursor clangsharp_Cursor_getCondExpr(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); - - if (const AbstractConditionalOperator* ACO = dyn_cast(E)) { - return MakeCXCursor(ACO->getCond(), getCursorDecl(C), getCursorTU(C)); - } - } - - if (clang_isStatement(C.kind)) { - const Stmt* S = getCursorStmt(C); - - if (const DoStmt* DS = dyn_cast(S)) { - return MakeCXCursor(DS->getCond(), getCursorDecl(C), getCursorTU(C)); - } - - if (const ForStmt* FS = dyn_cast(S)) { - return MakeCXCursor(FS->getCond(), getCursorDecl(C), getCursorTU(C)); - } - - if (const IfStmt* IS = dyn_cast(S)) { - return MakeCXCursor(IS->getCond(), getCursorDecl(C), getCursorTU(C)); - } - - if (const SwitchStmt* SS = dyn_cast(S)) { - return MakeCXCursor(SS->getCond(), getCursorDecl(C), getCursorTU(C)); - } - - if (const WhileStmt* WS = dyn_cast(S)) { - return MakeCXCursor(WS->getCond(), getCursorDecl(C), getCursorTU(C)); - } - } - - return clang_getNullCursor(); -} - -CXCursor clangsharp_Cursor_getConditionVariableDeclStmt(CXCursor C) { - if (clang_isStatement(C.kind)) { - const Stmt* S = getCursorStmt(C); - - if (const ForStmt* FS = dyn_cast(S)) { - return MakeCXCursor(FS->getConditionVariableDeclStmt(), getCursorDecl(C), getCursorTU(C)); - } - - if (const IfStmt* IS = dyn_cast(S)) { - return MakeCXCursor(IS->getConditionVariableDeclStmt(), getCursorDecl(C), getCursorTU(C)); - } - - if (const SwitchStmt* SS = dyn_cast(S)) { - return MakeCXCursor(SS->getConditionVariableDeclStmt(), getCursorDecl(C), getCursorTU(C)); - } - - if (const WhileStmt* WS = dyn_cast(S)) { - return MakeCXCursor(WS->getConditionVariableDeclStmt(), getCursorDecl(C), getCursorTU(C)); - } - } - - return clang_getNullCursor(); -} - CXCursor clangsharp_Cursor_getConstraintExpr(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const ConceptDecl* CD = dyn_cast(D)) { @@ -571,7 +746,7 @@ CXCursor clangsharp_Cursor_getConstraintExpr(CXCursor C) { } CXCursor clangsharp_Cursor_getConstructedBaseClass(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const ConstructorUsingShadowDecl* CUSD = dyn_cast(D)) { @@ -583,7 +758,7 @@ CXCursor clangsharp_Cursor_getConstructedBaseClass(CXCursor C) { } CXCursor clangsharp_Cursor_getConstructedBaseClassShadowDecl(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const ConstructorUsingShadowDecl* CUSD = dyn_cast(D)) { @@ -594,8 +769,20 @@ CXCursor clangsharp_Cursor_getConstructedBaseClassShadowDecl(CXCursor C) { return clang_getNullCursor(); } +CX_ConstructionKind clangsharp_Cursor_getConstructionKind(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + + if (const CXXConstructExpr* CXXCE = dyn_cast(S)) { + return static_cast(CXXCE->getConstructionKind() + 1); + } + } + + return _CX_CK_Invalid; +} + unsigned clangsharp_Cursor_getConstructsVirtualBase(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const ConstructorUsingShadowDecl* CUSD = dyn_cast(D)) { @@ -603,11 +790,19 @@ unsigned clangsharp_Cursor_getConstructsVirtualBase(CXCursor C) { } } + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + + if (const CXXInheritedCtorInitExpr* CXXICIE = dyn_cast(S)) { + return CXXICIE->constructsVBase(); + } + } + return 0; } CXCursor clangsharp_Cursor_getContextParam(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const CapturedDecl* CD = dyn_cast(D)) { @@ -619,7 +814,7 @@ CXCursor clangsharp_Cursor_getContextParam(CXCursor C) { } int clangsharp_Cursor_getContextParamPosition(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const CapturedDecl* CD = dyn_cast(D)) { @@ -630,32 +825,47 @@ int clangsharp_Cursor_getContextParamPosition(CXCursor C) { return -1; } -CXCursor clangsharp_Cursor_getConversionFunction(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); +CXCursor clangsharp_Cursor_getCtor(CXCursor C, unsigned i) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const CXXRecordDecl* CXXRD = dyn_cast(D)) { + unsigned n = 0; - if (const CastExpr* CE = dyn_cast(E)) { - return MakeCXCursor(CE->getConversionFunction(), getCursorTU(C)); + for (auto ctor : CXXRD->ctors()) { + if (n == i) { + return MakeCXCursor(ctor, getCursorTU(C)); + } + n++; + } } } return clang_getNullCursor(); } -unsigned clangsharp_Cursor_getCXXBoolLiteralExprValue(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); +unsigned clangsharp_Cursor_getBoolLiteralValue(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const CXXBoolLiteralExpr* CBLE = dyn_cast(E)) { + if (const CXXBoolLiteralExpr* CBLE = dyn_cast(S)) { return CBLE->getValue(); } + + if (const CXXNoexceptExpr* CXXNE = dyn_cast(S)) { + return CXXNE->getValue(); + } + + if (const ObjCBoolLiteralExpr* OCBLE = dyn_cast(S)) { + return OCBLE->getValue(); + } } return 0; } CXType clangsharp_Cursor_getDeclaredReturnType(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const FunctionDecl* FD = dyn_cast(D)) { @@ -666,8 +876,89 @@ CXType clangsharp_Cursor_getDeclaredReturnType(CXCursor C) { return MakeCXType(QualType(), getCursorTU(C)); } +CXCursor clangsharp_Cursor_getDecl(CXCursor C, unsigned i) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const DeclContext* DC = dyn_cast(D)) { + unsigned n = 0; + + for (auto decl : DC->decls()) { + if (n == i) { + return MakeCXCursor(decl, getCursorTU(C)); + } + n++; + } + } + } + + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + + if (const CXXNewExpr* CXXNE = dyn_cast(S)) { + if (i == 0) { + return MakeCXCursor(CXXNE->getOperatorDelete(), getCursorTU(C)); + } + else if (i == 1) { + return MakeCXCursor(CXXNE->getOperatorNew(), getCursorTU(C)); + } + } + + if (const DeclStmt* DS = dyn_cast(S)) { + unsigned n = 0; + + for (auto decl : DS->decls()) { + if (n == i) { + return MakeCXCursor(decl, getCursorTU(C)); + } + n++; + } + } + + if (const FunctionParmPackExpr* FPPE = dyn_cast(S)) { + if (i < FPPE->getNumExpansions()) { + return MakeCXCursor(FPPE->getExpansion(i), getCursorTU(C)); + } + } + + if (const ObjCPropertyRefExpr* OCPRE = dyn_cast(S)) { + if (i == 0) { + return MakeCXCursor(OCPRE->getClassReceiver(), getCursorTU(C)); + } + else if (i == 1) { + if (OCPRE->isExplicitProperty()) { + return MakeCXCursor(OCPRE->getExplicitProperty(), getCursorTU(C)); + } + } + else if (i == 2) { + if (OCPRE->isImplicitProperty()) { + return MakeCXCursor(OCPRE->getImplicitPropertyGetter(), getCursorTU(C)); + } + } + else if (i == 3) { + if (OCPRE->isImplicitProperty()) { + return MakeCXCursor(OCPRE->getImplicitPropertySetter(), getCursorTU(C)); + } + } + } + + if (const OverloadExpr* OE = dyn_cast(S)) { + unsigned n = 0; + + for (auto decl : OE->decls()) { + if (n == i) { + return MakeCXCursor(decl, getCursorTU(C)); + } + n++; + } + } + } + + return clang_Cursor_getArgument(C, i); +} + CX_DeclKind clangsharp_Cursor_getDeclKind(CXCursor C) { - if (clang_isDeclaration(C.kind) || clang_isTranslationUnit(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); return static_cast(D->getKind() + 1); } @@ -676,7 +967,7 @@ CX_DeclKind clangsharp_Cursor_getDeclKind(CXCursor C) { } CXCursor clangsharp_Cursor_getDecomposedDecl(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const BindingDecl* BD = dyn_cast(D)) { @@ -688,7 +979,7 @@ CXCursor clangsharp_Cursor_getDecomposedDecl(CXCursor C) { } CXCursor clangsharp_Cursor_getDefaultArg(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const NonTypeTemplateParmDecl* NTTPD = dyn_cast(D)) { @@ -704,7 +995,7 @@ CXCursor clangsharp_Cursor_getDefaultArg(CXCursor C) { } CXType clangsharp_Cursor_getDefaultArgType(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const TemplateTypeParmDecl* TTPD = dyn_cast(D)) { @@ -715,8 +1006,36 @@ CXType clangsharp_Cursor_getDefaultArgType(CXCursor C) { return MakeCXType(QualType(), getCursorTU(C)); } +CXCursor clangsharp_Cursor_getDefinition(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const FunctionDecl* FD = dyn_cast(D)) { + return MakeCXCursor(FD->getDefinition(), getCursorTU(C)); + } + + if (const ObjCInterfaceDecl* OCID = dyn_cast(D)) { + return MakeCXCursor(OCID->getDefinition(), getCursorTU(C)); + } + + if (const ObjCProtocolDecl* OCPD = dyn_cast(D)) { + return MakeCXCursor(OCPD->getDefinition(), getCursorTU(C)); + } + + if (const TagDecl* TD = dyn_cast(D)) { + return MakeCXCursor(TD->getDefinition(), getCursorTU(C)); + } + + if (const VarDecl* VD = dyn_cast(D)) { + return MakeCXCursor(VD->getDefinition(), getCursorTU(C)); + } + } + + return clang_getCursorDefinition(C); +} + CXCursor clangsharp_Cursor_getDependentLambdaCallOperator(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const CXXRecordDecl* CRD = dyn_cast(D)) { @@ -727,20 +1046,28 @@ CXCursor clangsharp_Cursor_getDependentLambdaCallOperator(CXCursor C) { return clang_getNullCursor(); } -CXCursor clangsharp_Cursor_getDescribedClassTemplate(CXCursor C) { - if (clang_isDeclaration(C.kind)) { +CXCursor clangsharp_Cursor_getDescribedCursorTemplate(CXCursor C) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); + if (const ClassTemplateSpecializationDecl* CTSD = dyn_cast(D)) { + return MakeCXCursor(CTSD->getDescribedClassTemplate(), getCursorTU(C)); + } + if (const CXXRecordDecl* CRD = dyn_cast(D)) { return MakeCXCursor(CRD->getDescribedClassTemplate(), getCursorTU(C)); } + + if (const FunctionDecl* FD = dyn_cast(D)) { + return MakeCXCursor(FD->getDescribedFunctionTemplate(), getCursorTU(C)); + } } return clang_getNullCursor(); } CXCursor clangsharp_Cursor_getDescribedTemplate(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); return MakeCXCursor(D->getDescribedTemplate(), getCursorTU(C)); } @@ -749,7 +1076,7 @@ CXCursor clangsharp_Cursor_getDescribedTemplate(CXCursor C) { } CXCursor clangsharp_Cursor_getDestructor(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const CXXRecordDecl* CRD = dyn_cast(D)) { @@ -760,24 +1087,28 @@ CXCursor clangsharp_Cursor_getDestructor(CXCursor C) { return clang_getNullCursor(); } -CXCursor clangsharp_Cursor_getDirectCallee(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); +unsigned clangsharp_Cursor_getDoesNotEscape(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); - if (const CallExpr* CE = dyn_cast (E)) { - return MakeCXCursor(CE->getDirectCallee(), getCursorTU(C)); + if (const BlockDecl* BD = dyn_cast(D)) { + return BD->doesNotEscape(); } } - return clang_getNullCursor(); + return 0; } -unsigned clangsharp_Cursor_getDoesNotEscape(CXCursor C) { - if (clang_isDeclaration(C.kind)) { - const Decl* D = getCursorDecl(C); +unsigned clangsharp_Cursor_getDoesUsualArrayDeleteWantSize(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const BlockDecl* BD = dyn_cast(D)) { - return BD->doesNotEscape(); + if (const CXXNewExpr* CXXNE = dyn_cast(S)) { + return CXXNE->doesUsualArrayDeleteWantSize(); + } + + if (const CXXDeleteExpr* CXXDE = dyn_cast(S)) { + return CXXDE->doesUsualArrayDeleteWantSize(); } } @@ -785,7 +1116,7 @@ unsigned clangsharp_Cursor_getDoesNotEscape(CXCursor C) { } CXType clangsharp_Cursor_getEnumDeclPromotionType(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const EnumDecl* ED = dyn_cast(D)) { @@ -796,40 +1127,131 @@ CXType clangsharp_Cursor_getEnumDeclPromotionType(CXCursor C) { return MakeCXType(QualType(), getCursorTU(C)); } +CXCursor clangsharp_Cursor_getEnumerator(CXCursor C, unsigned i) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const EnumDecl* ED = dyn_cast(D)) { + unsigned n = 0; + + for (auto enumerator : ED->enumerators()) { + if (n == i) { + return MakeCXCursor(enumerator, getCursorTU(C)); + } + n++; + } + } + } + + return clang_getNullCursor(); +} + +CXType clangsharp_Cursor_getExpansionType(CXCursor C, unsigned i) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const NonTypeTemplateParmDecl* NTTPD = dyn_cast(D)) { + if (i < NTTPD->getNumExpansionTypes()) { + return MakeCXType(NTTPD->getExpansionType(i), getCursorTU(C)); + } + } + } + + return MakeCXType(QualType(), getCursorTU(C)); +} + CXCursor clangsharp_Cursor_getExpr(CXCursor C, unsigned i) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const CXXConstructorDecl* CXXCD = dyn_cast(D)) { + unsigned n = 0; + + for (auto init : CXXCD->inits()) { + if (n == i) { + return MakeCXCursor(init->getInit(), D, getCursorTU(C)); + } + n++; + } + } + + if (const CXXDestructorDecl* CXXDD = dyn_cast(D)) { + if (i == 0) { + return MakeCXCursor(CXXDD->getOperatorDeleteThisArg(), D, getCursorTU(C)); + } + } + + if (const LabelDecl* LD = dyn_cast(D)) { + if (i == 0) { + return MakeCXCursor(LD->getStmt(), D, getCursorTU(C)); + } + } - if (const InitListExpr* ILE = dyn_cast(E)) { - return MakeCXCursor(ILE->getInit(i), getCursorDecl(C), getCursorTU(C)); + if (const LifetimeExtendedTemporaryDecl* LETD = dyn_cast(D)) { + if (i == 0) { + return MakeCXCursor(LETD->getTemporaryExpr(), D, getCursorTU(C)); + } + } + + if (const ObjCImplementationDecl* OCID = dyn_cast(D)) { + unsigned n = 0; + + for (auto init : OCID->inits()) { + if (n == i) { + return MakeCXCursor(init->getInit(), D, getCursorTU(C)); + } + n++; + } + } + + if (const ObjCPropertyImplDecl* OCPID = dyn_cast(D)) { + if (i == 0) { + return MakeCXCursor(OCPID->getGetterCXXConstructor(), D, getCursorTU(C)); + } + else if (i == 1) { + return MakeCXCursor(OCPID->getSetterCXXAssignment(), D, getCursorTU(C)); + } + } + + if (const StaticAssertDecl* SAD = dyn_cast(D)) { + if (i == 0) { + return MakeCXCursor(SAD->getAssertExpr(), D, getCursorTU(C)); + } + else if (i == 1) { + return MakeCXCursor(SAD->getMessage(), D, getCursorTU(C)); + } } + } + + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const ParenListExpr* PLE = dyn_cast(E)) { - return MakeCXCursor(PLE->getExpr(i), getCursorDecl(C), getCursorTU(C)); + if (const ObjCMessageExpr* OCME = dyn_cast(S)) { + return MakeCXCursor(OCME->getInstanceReceiver(), getCursorDecl(C), getCursorTU(C)); } - if (const RecoveryExpr* RE = dyn_cast(E)) { - return MakeCXCursor(RE->subExpressions()[i], getCursorDecl(C), getCursorTU(C)); + if (const ObjCPropertyRefExpr* OCPRE = dyn_cast(S)) { + return MakeCXCursor(OCPRE->getBase(), getCursorDecl(C), getCursorTU(C)); } } return clang_getNullCursor(); } -CXCursor clangsharp_Cursor_getFalseExpr(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); +CX_ExprDependence clangsharp_Cursor_getExprDependence(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const AbstractConditionalOperator* ACO = dyn_cast(E)) { - return MakeCXCursor(ACO->getFalseExpr(), getCursorDecl(C), getCursorTU(C)); + if (const Expr* E = dyn_cast(S)) { + return static_cast(E->getDependence()); } } - return clang_getNullCursor(); + return CX_ED_None; } int clangsharp_Cursor_getFieldIndex(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const FieldDecl* FD = dyn_cast(D)) { @@ -841,10 +1263,10 @@ int clangsharp_Cursor_getFieldIndex(CXCursor C) { } CX_FloatingSemantics clangsharp_Cursor_getFloatingLiteralSemantics(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const FloatingLiteral* FL = dyn_cast(E)) { + if (const FloatingLiteral* FL = dyn_cast(S)) { return static_cast(FL->getRawSemantics() + 1); } } @@ -853,10 +1275,10 @@ CX_FloatingSemantics clangsharp_Cursor_getFloatingLiteralSemantics(CXCursor C) { } double clangsharp_Cursor_getFloatingLiteralValueAsApproximateDouble(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const FloatingLiteral* FL = dyn_cast(E)) { + if (const FloatingLiteral* FL = dyn_cast(S)) { return FL->getValueAsApproximateDouble(); } } @@ -864,8 +1286,60 @@ double clangsharp_Cursor_getFloatingLiteralValueAsApproximateDouble(CXCursor C) return 0; } +CXCursor clangsharp_Cursor_getFoundDecl(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + + if (const DeclRefExpr* DRE = dyn_cast(S)) { + return MakeCXCursor(DRE->getFoundDecl(), getCursorTU(C)); + } + } + + return clang_getNullCursor(); +} + +CXCursor clangsharp_Cursor_getField(CXCursor C, unsigned i) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const RecordDecl* RD = dyn_cast(D)) { + unsigned n = 0; + + for (auto field : RD->fields()) { + if (n == i) { + return MakeCXCursor(field, getCursorTU(C)); + } + n++; + } + } + } + + return clang_getNullCursor(); +} + +CXCursor clangsharp_Cursor_getFriend(CXCursor C, unsigned i) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const CXXRecordDecl* CXXRD = dyn_cast(D)) { + if (CXXRD->getDefinition()) { + unsigned n = 0; + + for (auto f : CXXRD->friends()) { + if (n == i) { + return MakeCXCursor(f, getCursorTU(C)); + } + n++; + } + } + } + } + + return clang_getNullCursor(); +} + CXCursor clangsharp_Cursor_getFriendDecl(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const FriendDecl* FD = dyn_cast(D)) { @@ -881,7 +1355,7 @@ CXCursor clangsharp_Cursor_getFriendDecl(CXCursor C) { } int clangsharp_Cursor_getFunctionScopeDepth(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const ParmVarDecl* PVD = dyn_cast(D)) { @@ -893,7 +1367,7 @@ int clangsharp_Cursor_getFunctionScopeDepth(CXCursor C) { } int clangsharp_Cursor_getFunctionScopeIndex(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const ParmVarDecl* PVD = dyn_cast(D)) { @@ -904,32 +1378,40 @@ int clangsharp_Cursor_getFunctionScopeIndex(CXCursor C) { return -1; } -CXType clangsharp_Cursor_getFunctionType(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); +MSGuidDeclParts clangsharp_Cursor_getGuidValue(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); - if (const BlockExpr* BE = dyn_cast(E)) { - return MakeCXType(QualType(BE->getFunctionType(), 0), getCursorTU(C)); + if (const MSGuidDecl* MSGD = dyn_cast(D)) { + return MSGD->getParts(); } } - return MakeCXType(QualType(), getCursorTU(C)); + return MSGuidDeclParts(); } -MSGuidDeclParts clangsharp_Cursor_getGuidValue(CXCursor C) { - if (clang_isDeclaration(C.kind)) { - const Decl* D = getCursorDecl(C); +unsigned clangsharp_Cursor_getHadMultipleCandidates(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const MSGuidDecl* MSGD = dyn_cast(D)) { - return MSGD->getParts(); + if (const CXXConstructExpr* CXXCE = dyn_cast(S)) { + return CXXCE->hadMultipleCandidates(); + } + + if (const DeclRefExpr* DRE = dyn_cast(S)) { + return DRE->hadMultipleCandidates(); + } + + if (const MemberExpr* ME = dyn_cast(S)) { + return ME->hadMultipleCandidates(); } } - return MSGuidDeclParts(); + return 0; } unsigned clangsharp_Cursor_getHasBody(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const FunctionDecl* FD = dyn_cast(D)) { @@ -941,7 +1423,7 @@ unsigned clangsharp_Cursor_getHasBody(CXCursor C) { } unsigned clangsharp_Cursor_getHasDefaultArg(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const NonTypeTemplateParmDecl* NTTPD = dyn_cast(D)) { @@ -960,8 +1442,20 @@ unsigned clangsharp_Cursor_getHasDefaultArg(CXCursor C) { return 0; } +unsigned clangsharp_Cursor_getHasElseStorage(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + + if (const IfStmt* IS = dyn_cast(S)) { + return IS->hasElseStorage(); + } + } + + return 0; +} + unsigned clangsharp_Cursor_getHasExplicitTemplateArgs(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const ClassScopeFunctionSpecializationDecl* CSFSD = dyn_cast(D)) { @@ -969,11 +1463,35 @@ unsigned clangsharp_Cursor_getHasExplicitTemplateArgs(CXCursor C) { } } + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + + if (const CXXDependentScopeMemberExpr* CXXDSME = dyn_cast(S)) { + return CXXDSME->hasExplicitTemplateArgs(); + } + + if (const DeclRefExpr* DRE = dyn_cast(S)) { + return DRE->hasExplicitTemplateArgs(); + } + + if (const DependentScopeDeclRefExpr* DSDRE = dyn_cast(S)) { + return DSDRE->hasExplicitTemplateArgs(); + } + + if (const MemberExpr* ME = dyn_cast(S)) { + return ME->hasExplicitTemplateArgs(); + } + + if (const OverloadExpr* OE = dyn_cast(S)) { + return OE->hasExplicitTemplateArgs(); + } + } + return 0; } unsigned clangsharp_Cursor_getHasExternalStorage(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const VarDecl* VD = dyn_cast(D)) { @@ -985,7 +1503,7 @@ unsigned clangsharp_Cursor_getHasExternalStorage(CXCursor C) { } unsigned clangsharp_Cursor_getHasGlobalStorage(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const VarDecl* VD = dyn_cast(D)) { @@ -997,7 +1515,7 @@ unsigned clangsharp_Cursor_getHasGlobalStorage(CXCursor C) { } unsigned clangsharp_Cursor_getHasImplicitReturnZero(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const FunctionDecl* FD = dyn_cast(D)) { @@ -1009,7 +1527,7 @@ unsigned clangsharp_Cursor_getHasImplicitReturnZero(CXCursor C) { } unsigned clangsharp_Cursor_getHasInheritedDefaultArg(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const NonTypeTemplateParmDecl* NTTPD = dyn_cast(D)) { @@ -1033,7 +1551,7 @@ unsigned clangsharp_Cursor_getHasInheritedDefaultArg(CXCursor C) { } unsigned clangsharp_Cursor_getHasInit(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const VarDecl* VD = dyn_cast(D)) { @@ -1041,11 +1559,47 @@ unsigned clangsharp_Cursor_getHasInit(CXCursor C) { } } + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + + if (const CXXNewExpr* CXXNE = dyn_cast(S)) { + return CXXNE->hasInitializer(); + } + } + + return 0; +} + +unsigned clangsharp_Cursor_getHasInitStorage(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + + if (const IfStmt* IS = dyn_cast(S)) { + return IS->hasInitStorage(); + } + + if (const SwitchStmt* SS = dyn_cast(S)) { + return SS->hasInitStorage(); + } + } + + return 0; +} + +unsigned clangsharp_Cursor_getHasLeadingEmptyMacro(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + + if (const NullStmt* NS = dyn_cast(S)) { + return NS->hasLeadingEmptyMacro(); + } + } + return 0; } unsigned clangsharp_Cursor_getHasLocalStorage(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const VarDecl* VD = dyn_cast(D)) { @@ -1057,7 +1611,7 @@ unsigned clangsharp_Cursor_getHasLocalStorage(CXCursor C) { } unsigned clangsharp_Cursor_getHasPlaceholderTypeConstraint(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const NonTypeTemplateParmDecl* NTTPD = dyn_cast(D)) { @@ -1068,100 +1622,212 @@ unsigned clangsharp_Cursor_getHasPlaceholderTypeConstraint(CXCursor C) { return 0; } -CXCursor clangsharp_Cursor_getHoldingVar(CXCursor C) { - if (clang_isDeclaration(C.kind)) { - const Decl* D = getCursorDecl(C); +unsigned clangsharp_Cursor_getHasTemplateKeyword(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const BindingDecl* BD = dyn_cast(D)) { - return MakeCXCursor(BD->getHoldingVar(), getCursorTU(C)); + if (const CXXDependentScopeMemberExpr* CXXDSME = dyn_cast(S)) { + return CXXDSME->hasTemplateKeyword(); } - } - return clang_getNullCursor(); -} + if (const DeclRefExpr* DRE = dyn_cast(S)) { + return DRE->hasTemplateKeyword(); + } + + if (const DependentScopeDeclRefExpr* DSDRE = dyn_cast(S)) { + return DSDRE->hasTemplateKeyword(); + } -CXCursor clangsharp_Cursor_getIdxExpr(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); + if (const MemberExpr* ME = dyn_cast(S)) { + return ME->hasTemplateKeyword(); + } - if (const ArraySubscriptExpr* ASE = dyn_cast(E)) { - return MakeCXCursor(ASE->getIdx(), getCursorDecl(C), getCursorTU(C)); + if (const OverloadExpr* OE = dyn_cast(S)) { + return OE->hasTemplateKeyword(); } } - return clang_getNullCursor(); + return 0; } -CXCursor clangsharp_Cursor_getIncExpr(CXCursor C) { - if (clang_isStatement(C.kind)) { - const Stmt* S = getCursorStmt(C); +unsigned clangsharp_Cursor_getHasUserDeclaredConstructor(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); - if (const ForStmt* FS = dyn_cast(S)) { - return MakeCXCursor(FS->getInc(), getCursorDecl(C), getCursorTU(C)); + if (const CXXRecordDecl* CXXRD = dyn_cast(D)) { + return CXXRD->getDefinition() && CXXRD->hasUserDeclaredConstructor(); } } - return clang_getNullCursor(); + return 0; } -CXCursor clangsharp_Cursor_getInClassInitializer(CXCursor C) { - if (clang_isDeclaration(C.kind)) { +unsigned clangsharp_Cursor_getHasUserDeclaredCopyAssignment(CXCursor C) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); - if (const FieldDecl* FD = dyn_cast(D)) { - return MakeCXCursor(FD->getInClassInitializer(), FD, getCursorTU(C)); + if (const CXXRecordDecl* CXXRD = dyn_cast(D)) { + return CXXRD->getDefinition() && CXXRD->hasUserDeclaredCopyAssignment(); } } - return clang_getNullCursor(); + return 0; } -CXCursor clangsharp_Cursor_getInitExpr(CXCursor C) { - if (clang_isDeclaration(C.kind)) { +unsigned clangsharp_Cursor_getHasUserDeclaredCopyConstructor(CXCursor C) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); - if (const EnumConstantDecl* ECD = dyn_cast(D)) { - return MakeCXCursor(ECD->getInitExpr(), ECD, getCursorTU(C)); - } - - if (const VarDecl* VD = dyn_cast(D)) { - return MakeCXCursor(VD->getInit(), VD, getCursorTU(C)); + if (const CXXRecordDecl* CXXRD = dyn_cast(D)) { + return CXXRD->getDefinition() && CXXRD->hasUserDeclaredCopyConstructor(); } } - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); + return 0; +} + +unsigned clangsharp_Cursor_getHasUserDeclaredDestructor(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const CXXRecordDecl* CXXRD = dyn_cast(D)) { + return CXXRD->getDefinition() && CXXRD->hasUserDeclaredDestructor(); + } + } + + return 0; +} + +unsigned clangsharp_Cursor_getHasUserDeclaredMoveAssignment(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const CXXRecordDecl* CXXRD = dyn_cast(D)) { + return CXXRD->getDefinition() && CXXRD->hasUserDeclaredMoveAssignment(); + } + } + + return 0; +} + +unsigned clangsharp_Cursor_getHasUserDeclaredMoveConstructor(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); - if (const CompoundLiteralExpr* CLE = dyn_cast(E)) { - return MakeCXCursor(CLE->getInitializer(), getCursorDecl(C), getCursorTU(C)); + if (const CXXRecordDecl* CXXRD = dyn_cast(D)) { + return CXXRD->getDefinition() && CXXRD->hasUserDeclaredMoveConstructor(); } + } + + return 0; +} - if (const CXXFoldExpr* CFE = dyn_cast(E)) { - return MakeCXCursor(CFE->getInit(), getCursorDecl(C), getCursorTU(C)); +unsigned clangsharp_Cursor_getHasUserDeclaredMoveOperation(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const CXXRecordDecl* CXXRD = dyn_cast(D)) { + return CXXRD->getDefinition() && CXXRD->hasUserDeclaredMoveOperation(); } } - if (clang_isStatement(C.kind)) { + return 0; +} + +unsigned clangsharp_Cursor_getHasVarStorage(CXCursor C) { + if (isStmtOrExpr(C.kind)) { const Stmt* S = getCursorStmt(C); - if (const ForStmt* FS = dyn_cast(S)) { - return MakeCXCursor(FS->getInit(), getCursorDecl(C), getCursorTU(C)); + if (const IfStmt* IS = dyn_cast(S)) { + return IS->hasVarStorage(); } if (const SwitchStmt* SS = dyn_cast(S)) { - return MakeCXCursor(SS->getInit(), getCursorDecl(C), getCursorTU(C)); + return SS->hasVarStorage(); + } + + if (const WhileStmt* WS = dyn_cast(S)) { + return WS->hasVarStorage(); + } + } + + return 0; +} + +CXCursor clangsharp_Cursor_getInClassInitializer(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const FieldDecl* FD = dyn_cast(D)) { + return MakeCXCursor(FD->getInClassInitializer(), FD, getCursorTU(C)); + } + } + + return clang_getNullCursor(); +} + +CXCursor clangsharp_Cursor_getInheritedConstructor(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const CXXConstructorDecl* CXXCD = dyn_cast(D)) { + return MakeCXCursor(CXXCD->getInheritedConstructor().getConstructor(), getCursorTU(C)); + } + } + + return clang_getNullCursor(); +} + +unsigned clangsharp_Cursor_getInheritedFromVBase(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + + if (const CXXInheritedCtorInitExpr* CXXICIE = dyn_cast(S)) { + return CXXICIE->inheritedFromVBase(); + } + } + + return 0; +} + +CXCursor clangsharp_Cursor_getInitExpr(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const EnumConstantDecl* ECD = dyn_cast(D)) { + return MakeCXCursor(ECD->getInitExpr(), ECD, getCursorTU(C)); + } + + if (const VarDecl* VD = dyn_cast(D)) { + return MakeCXCursor(VD->getInit(), VD, getCursorTU(C)); } } return clang_getNullCursor(); } +CXType clangsharp_Cursor_getInjectedSpecializationType(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (ClassTemplateDecl* CTD = const_cast(dyn_cast(D))) { + return MakeCXType(CTD->getInjectedClassNameSpecialization(), getCursorTU(C)); + } + + if (const ClassTemplatePartialSpecializationDecl* CTPSD = dyn_cast(D)) { + return MakeCXType(CTPSD->getInjectedSpecializationType(), getCursorTU(C)); + } + } + + return MakeCXType(QualType(), getCursorTU(C)); +} + CXCursor clangsharp_Cursor_getInstantiatedFromMember(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const ClassTemplatePartialSpecializationDecl* CTPSD = dyn_cast(D)) { - return MakeCXCursor(CTPSD->getInstantiatedFromMemberTemplate(), getCursorTU(C)); + return MakeCXCursor(CTPSD->getInstantiatedFromMember(), getCursorTU(C)); } if (const CXXRecordDecl* CRD = dyn_cast(D)) { @@ -1189,10 +1855,10 @@ CXCursor clangsharp_Cursor_getInstantiatedFromMember(CXCursor C) { } int64_t clangsharp_Cursor_getIntegerLiteralValue(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const IntegerLiteral* IL = dyn_cast(E)) { + if (const IntegerLiteral* IL = dyn_cast(S)) { return IL->getValue().getSExtValue(); } } @@ -1200,8 +1866,32 @@ int64_t clangsharp_Cursor_getIntegerLiteralValue(CXCursor C) { return 0; } +unsigned clangsharp_Cursor_getIsAllEnumCasesCovered(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + + if (const SwitchStmt* SS = dyn_cast(S)) { + return SS->isAllEnumCasesCovered(); + } + } + + return 0; +} + +unsigned clangsharp_Cursor_getIsAlwaysNull(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + + if (const CXXDynamicCastExpr* CXXDCE = dyn_cast(S)) { + return CXXDCE->isAlwaysNull(); + } + } + + return 0; +} + unsigned clangsharp_Cursor_getIsAnonymousStructOrUnion(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const FieldDecl* FD = dyn_cast(D)) { @@ -1217,10 +1907,10 @@ unsigned clangsharp_Cursor_getIsAnonymousStructOrUnion(CXCursor C) { } unsigned clangsharp_Cursor_getIsArgumentType(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const UnaryExprOrTypeTraitExpr* UETTE = dyn_cast(E)) { + if (const UnaryExprOrTypeTraitExpr* UETTE = dyn_cast(S)) { return UETTE->isArgumentType(); } } @@ -1228,741 +1918,1619 @@ unsigned clangsharp_Cursor_getIsArgumentType(CXCursor C) { return 0; } -unsigned clangsharp_Cursor_getIsConversionFromLambda(CXCursor C) { - if (clang_isDeclaration(C.kind)) { - const Decl* D = getCursorDecl(C); +unsigned clangsharp_Cursor_getIsArrayForm(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const BlockDecl* BD = dyn_cast(D)) { - return BD->isConversionFromLambda(); + if (const CXXDeleteExpr* CXXDE = dyn_cast(S)) { + return CXXDE->isArrayForm(); + } + + if (const CXXNewExpr* CXXNE = dyn_cast(S)) { + return CXXNE->isArray(); } } return 0; } -unsigned clangsharp_Cursor_getIsDefined(CXCursor C) { - if (clang_isDeclaration(C.kind)) { - const Decl* D = getCursorDecl(C); +unsigned clangsharp_Cursor_getIsArrayFormAsWritten(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const FunctionDecl* FD = dyn_cast(D)) { - return FD->isDefined(); + if (const CXXDeleteExpr* CXXDE = dyn_cast(S)) { + return CXXDE->isArrayFormAsWritten(); } } return 0; } -unsigned clangsharp_Cursor_getIsDeprecated(CXCursor C) { - if (clang_isDeclaration(C.kind)) { - const Decl* D = getCursorDecl(C); - return D->isDeprecated(); - } +unsigned clangsharp_Cursor_getIsArrow(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - return 0; -} + if (const CXXDependentScopeMemberExpr* CXXDSME = dyn_cast(S)) { + return CXXDSME->isArrow(); + } -unsigned clangsharp_Cursor_getIsExternC(CXCursor C) { - if (clang_isDeclaration(C.kind)) { - const Decl* D = getCursorDecl(C); + if (const MemberExpr* ME = dyn_cast(S)) { + return ME->isArrow(); + } - if (const FunctionDecl* FD = dyn_cast(D)) { - return FD->isExternC(); + if (const ObjCIsaExpr* OCIE = dyn_cast(S)) { + return OCIE->isArrow(); + } + + if (const ObjCIvarRefExpr* OCIRE = dyn_cast(S)) { + return OCIRE->isArrow(); + } + + if (const CXXPseudoDestructorExpr* CXXPSDE = dyn_cast(S)) { + return CXXPSDE->isArrow(); + } + + if (const UnresolvedMemberExpr* UME = dyn_cast(S)) { + return UME->isArrow(); } } return 0; } -unsigned clangsharp_Cursor_getIsExpandedParameterPack(CXCursor C) { - if (clang_isDeclaration(C.kind)) { +unsigned clangsharp_Cursor_getIsClassExtension(CXCursor C) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); - if (const TemplateTemplateParmDecl* TTPD = dyn_cast(D)) { - return TTPD->isExpandedParameterPack(); - } - - if (const TemplateTypeParmDecl* TTPD = dyn_cast(D)) { - return TTPD->isExpandedParameterPack(); + if (const ObjCCategoryDecl* OCCD = dyn_cast(D)) { + return OCCD->IsClassExtension(); } } return 0; } -unsigned clangsharp_Cursor_getIsGlobal(CXCursor C) { - if (clang_isDeclaration(C.kind)) { +unsigned clangsharp_Cursor_getIsCompleteDefinition(CXCursor C) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); - if (const FunctionDecl* FD = dyn_cast(D)) { - return FD->isGlobal(); + if (const TagDecl* TD = dyn_cast(D)) { + return TD->isCompleteDefinition(); } } return 0; } -unsigned clangsharp_Cursor_getIsImplicitAccess(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); +unsigned clangsharp_Cursor_getIsConditionTrue(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const MemberExpr* ME = dyn_cast(E)) { - return ME->isImplicitAccess(); + if (const ChooseExpr* CE = dyn_cast(S)) { + if (!CE->isConditionDependent()) { + return CE->isConditionTrue(); + } } } return 0; } -unsigned clangsharp_Cursor_getIsIncomplete(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); +unsigned clangsharp_Cursor_getIsConstexpr(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const MatrixSubscriptExpr* MSE = dyn_cast(E)) { - return MSE->isIncomplete(); + if (const IfStmt* IS = dyn_cast(S)) { + return IS->isConstexpr(); } } return 0; } -unsigned clangsharp_Cursor_getIsLocalVarDecl(CXCursor C) { - if (clang_isDeclaration(C.kind)) { +unsigned clangsharp_Cursor_getIsConversionFromLambda(CXCursor C) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); - if (const VarDecl* VD = dyn_cast(D)) { - return VD->isLocalVarDecl(); + if (const BlockDecl* BD = dyn_cast(D)) { + return BD->isConversionFromLambda(); } } return 0; } -unsigned clangsharp_Cursor_getIsLocalVarDeclOrParm(CXCursor C) { - if (clang_isDeclaration(C.kind)) { +unsigned clangsharp_Cursor_getIsCopyOrMoveConstructor(CXCursor C) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); - if (const VarDecl* VD = dyn_cast(D)) { - return VD->isLocalVarDeclOrParm(); + if (const CXXConstructorDecl* CXXCD = dyn_cast(D)) { + return !CXXCD->isCopyOrMoveConstructor(); } } return 0; } -unsigned clangsharp_Cursor_getIsMemberSpecialization(CXCursor C) { - if (clang_isDeclaration(C.kind)) { - const Decl* D = getCursorDecl(C); +unsigned clangsharp_Cursor_getIsCXXTry(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const RedeclarableTemplateDecl* RTD = dyn_cast(D)) { - return RTD->isMemberSpecialization(); + if (const SEHTryStmt* SEHTS = dyn_cast(S)) { + return SEHTS->getIsCXXTry(); } } return 0; } -unsigned clangsharp_Cursor_getIsNegative(CXCursor C) { - if (clang_isDeclaration(C.kind)) { +unsigned clangsharp_Cursor_getIsDefined(CXCursor C) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); - if (const EnumConstantDecl* ECD = dyn_cast(D)) { - return ECD->getInitVal().isNegative(); + if (const FunctionDecl* FD = dyn_cast(D)) { + return FD->isDefined(); } } - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); + return 0; +} + +unsigned clangsharp_Cursor_getIsDelegatingConstructor(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); - if (const IntegerLiteral* IL = dyn_cast(E)) { - return IL->getValue().isNegative(); + if (const CXXConstructorDecl* CXXCD = dyn_cast(D)) { + return !CXXCD->isDelegatingConstructor(); } } return 0; } -unsigned clangsharp_Cursor_getIsNonNegative(CXCursor C) { - if (clang_isDeclaration(C.kind)) { +unsigned clangsharp_Cursor_getIsDeleted(CXCursor C) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); - if (const EnumConstantDecl* ECD = dyn_cast(D)) { - return ECD->getInitVal().isNonNegative(); + if (const FunctionDecl* FD = dyn_cast(D)) { + return !FD->isDeleted(); } } - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); + return 0; +} - if (const IntegerLiteral* IL = dyn_cast(E)) { - return IL->getValue().isNonNegative(); - } +unsigned clangsharp_Cursor_getIsDeprecated(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + return D->isDeprecated(); } return 0; } -unsigned clangsharp_Cursor_getIsNoReturn(CXCursor C) { - if (clang_isDeclaration(C.kind)) { - const Decl* D = getCursorDecl(C); +unsigned clangsharp_Cursor_getIsElidable(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const FunctionDecl* FD = dyn_cast(D)) { - return FD->isNoReturn(); + if (const CXXConstructExpr* CXXCE = dyn_cast(S)) { + return CXXCE->isElidable(); } } return 0; } -unsigned clangsharp_Cursor_getIsNothrow(CXCursor C) { - if (clang_isDeclaration(C.kind)) { +unsigned clangsharp_Cursor_getIsExplicitlyDefaulted(CXCursor C) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); - if (const CapturedDecl* CD = dyn_cast(D)) { - return CD->isNothrow(); + if (const FunctionDecl* FD = dyn_cast(D)) { + return !FD->isExplicitlyDefaulted(); } } return 0; } -unsigned clangsharp_Cursor_getIsOverloadedOperator(CXCursor C) { - if (clang_isDeclaration(C.kind)) { +unsigned clangsharp_Cursor_getIsExternC(CXCursor C) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const FunctionDecl* FD = dyn_cast(D)) { - return FD->isOverloadedOperator(); + return FD->isExternC(); } } return 0; } -unsigned clangsharp_Cursor_getIsPackExpansion(CXCursor C) { - if (clang_isDeclaration(C.kind)) { +unsigned clangsharp_Cursor_getIsExpandedParameterPack(CXCursor C) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); - if (const NonTypeTemplateParmDecl* NTTPD = dyn_cast(D)) { - return NTTPD->isPackExpansion(); - } - if (const TemplateTemplateParmDecl* TTPD = dyn_cast(D)) { - return TTPD->isPackExpansion(); + return TTPD->isExpandedParameterPack(); } if (const TemplateTypeParmDecl* TTPD = dyn_cast(D)) { - return TTPD->isPackExpansion(); + return TTPD->isExpandedParameterPack(); } } return 0; } -unsigned clangsharp_Cursor_getIsParameterPack(CXCursor C) { - if (clang_isDeclaration(C.kind)) { - const Decl* D = getCursorDecl(C); - - if (const NonTypeTemplateParmDecl* NTTPD = dyn_cast(D)) { - return NTTPD->isParameterPack(); - } - - if (const TemplateTemplateParmDecl* TTPD = dyn_cast(D)) { - return TTPD->isParameterPack(); - } +unsigned clangsharp_Cursor_getIsFileScope(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const TemplateTypeParmDecl* TTPD = dyn_cast(D)) { - return TTPD->isParameterPack(); + if (const CompoundLiteralExpr* CLE = dyn_cast(S)) { + return CLE->isFileScope(); } } return 0; } -unsigned clangsharp_Cursor_getIsPure(CXCursor C) { - if (clang_isDeclaration(C.kind)) { +unsigned clangsharp_Cursor_getIsGlobal(CXCursor C) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const FunctionDecl* FD = dyn_cast(D)) { - return FD->isPure(); + return FD->isGlobal(); } } - return 0; -} + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); -unsigned clangsharp_Cursor_getIsSigned(CXCursor C) { - if (clang_isDeclaration(C.kind)) { - const Decl* D = getCursorDecl(C); + if (const CXXNewExpr* CXXNE = dyn_cast(S)) { + return CXXNE->isGlobalNew(); + } - if (const EnumConstantDecl* ECD = dyn_cast(D)) { - return ECD->getInitVal().isSigned(); + if (const CXXDeleteExpr* CXXDE = dyn_cast(S)) { + return CXXDE->isGlobalDelete(); } } return 0; } -unsigned clangsharp_Cursor_getIsStatic(CXCursor C) { - if (clang_isDeclaration(C.kind)) { +unsigned clangsharp_Cursor_getIsInjectedClassName(CXCursor C) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); - if (const FunctionDecl* FD = dyn_cast(D)) { - return FD->isStatic(); + if (const RecordDecl* RD = dyn_cast(D)) { + return RD->isInjectedClassName(); } } return 0; } -unsigned clangsharp_Cursor_getIsStaticDataMember(CXCursor C) { - if (clang_isDeclaration(C.kind)) { - const Decl* D = getCursorDecl(C); +unsigned clangsharp_Cursor_getIsIfExists(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const VarDecl* VD = dyn_cast(D)) { - return VD->isStaticDataMember(); + if (const MSDependentExistsStmt* MSDES = dyn_cast(S)) { + return MSDES->isIfExists(); } } return 0; } -unsigned clangsharp_Cursor_getIsStrictlyPositive(CXCursor C) { - if (clang_isDeclaration(C.kind)) { +unsigned clangsharp_Cursor_getIsImplicit(CXCursor C) { + if (clang_isAttribute(C.kind)) { + const Attr* A = getCursorAttr(C); + return A->isImplicit(); + } + + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); - if (const EnumConstantDecl* ECD = dyn_cast(D)) { - return ECD->getInitVal().isStrictlyPositive(); + if (const CXXConstructorDecl* CXXCD = dyn_cast(D)) { + return !CXXCD->isExplicit(); } - } - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); + if (const CXXConversionDecl* CXXCD = dyn_cast(D)) { + return !CXXCD->isExplicit(); + } - if (const IntegerLiteral* IL = dyn_cast(E)) { - return IL->getValue().isStrictlyPositive(); + if (const CXXDeductionGuideDecl* CXXDGD = dyn_cast(D)) { + return !CXXDGD->isExplicit(); + } + } + + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + + if (const CXXThisExpr* CXXTE = dyn_cast(S)) { + return CXXTE->isImplicit(); + } + + if (const ImplicitCastExpr* ICE = dyn_cast(S)) { + return !ICE->isPartOfExplicitCast(); + } + + if (const InitListExpr* ILE = dyn_cast(S)) { + return !ILE->isExplicit(); + } + + if (const MemberExpr* ME = dyn_cast(S)) { + return ME->isImplicitAccess(); + } + + if (const ObjCMessageExpr* OCME = dyn_cast(S)) { + return OCME->isImplicit(); + } + + if (const ObjCPropertyRefExpr* OCPRE = dyn_cast(S)) { + return OCPRE->isImplicitProperty(); } } return 0; } -unsigned clangsharp_Cursor_getIsTemplated(CXCursor C) { - if (clang_isDeclaration(C.kind)) { - const Decl* D = getCursorDecl(C); - return D->isTemplated(); +unsigned clangsharp_Cursor_getIsIncomplete(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + + if (const MatrixSubscriptExpr* MSE = dyn_cast(S)) { + return MSE->isIncomplete(); + } } return 0; } -unsigned clangsharp_Cursor_getIsThisDeclarationADefinition(CXCursor C) { - if (clang_isDeclaration(C.kind)) { +unsigned clangsharp_Cursor_getIsInheritingConstructor(CXCursor C) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); - if (const ClassTemplateDecl* CTD = dyn_cast(D)) { - return CTD->isThisDeclarationADefinition(); + if (const CXXConstructorDecl* CXXCD = dyn_cast(D)) { + return !CXXCD->isInheritingConstructor(); } + } - if (const FunctionDecl* FD = dyn_cast(D)) { - return FD->isThisDeclarationADefinition(); - } + return 0; +} - if (const FunctionTemplateDecl* FTD = dyn_cast(D)) { - return FTD->isThisDeclarationADefinition(); +unsigned clangsharp_Cursor_getIsListInitialization(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + + if (const CXXConstructExpr* CXXCE = dyn_cast(S)) { + return CXXCE->isListInitialization(); } - if (const TagDecl* TD = dyn_cast(D)) { - return TD->isThisDeclarationADefinition(); + if (const CXXFunctionalCastExpr* CXXFCE = dyn_cast(S)) { + return CXXFCE->isListInitialization(); } - if (const VarTemplateDecl* VTD = dyn_cast(D)) { - return VTD->isThisDeclarationADefinition(); + if (const CXXUnresolvedConstructExpr* CXXUCE = dyn_cast(S)) { + return CXXUCE->isListInitialization(); } } return 0; } -unsigned clangsharp_Cursor_getIsTransparentTag(CXCursor C) { - if (clang_isDeclaration(C.kind)) { +unsigned clangsharp_Cursor_getIsLocalVarDecl(CXCursor C) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); - if (const TypedefNameDecl* TND = dyn_cast(D)) { - return TND->isTransparentTag(); + if (const VarDecl* VD = dyn_cast(D)) { + return VD->isLocalVarDecl(); } } return 0; } -unsigned clangsharp_Cursor_getIsTypeConcept(CXCursor C) { - if (clang_isDeclaration(C.kind)) { +unsigned clangsharp_Cursor_getIsLocalVarDeclOrParm(CXCursor C) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); - if (const ConceptDecl* CTD = dyn_cast(D)) { - return CTD->isTypeConcept(); + if (const VarDecl* VD = dyn_cast(D)) { + return VD->isLocalVarDeclOrParm(); } } return 0; } -unsigned clangsharp_Cursor_getIsTypeOperand(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); +unsigned clangsharp_Cursor_getIsMemberSpecialization(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const ClassTemplatePartialSpecializationDecl* CTPSD = dyn_cast(D)) { + return const_cast(CTPSD)->isMemberSpecialization(); + } - if (const CXXUuidofExpr* CUE = dyn_cast(E)) { - return CUE->isTypeOperand(); + if (const RedeclarableTemplateDecl* RTD = dyn_cast(D)) { + return RTD->isMemberSpecialization(); } } return 0; } -unsigned clangsharp_Cursor_getIsUnavailable(CXCursor C) { - if (clang_isDeclaration(C.kind)) { +unsigned clangsharp_Cursor_getIsNegative(CXCursor C) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); - return D->isUnavailable(); - } - return 0; -} + if (const EnumConstantDecl* ECD = dyn_cast(D)) { + return ECD->getInitVal().isNegative(); + } + } -unsigned clangsharp_Cursor_getIsUnnamedBitfield(CXCursor C) { - if (clang_isDeclaration(C.kind)) { - const Decl* D = getCursorDecl(C); + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const FieldDecl* FD = dyn_cast(D)) { - return FD->isUnnamedBitfield(); + if (const IntegerLiteral* IL = dyn_cast(S)) { + return IL->getValue().isNegative(); } } return 0; } -unsigned clangsharp_Cursor_getIsUnsigned(CXCursor C) { - if (clang_isDeclaration(C.kind)) { +unsigned clangsharp_Cursor_getIsNonNegative(CXCursor C) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const EnumConstantDecl* ECD = dyn_cast(D)) { - return ECD->getInitVal().isUnsigned(); + return ECD->getInitVal().isNonNegative(); + } + } + + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + + if (const IntegerLiteral* IL = dyn_cast(S)) { + return IL->getValue().isNonNegative(); } } return 0; } -unsigned clangsharp_Cursor_getIsUnsupportedFriend(CXCursor C) { - if (clang_isDeclaration(C.kind)) { +unsigned clangsharp_Cursor_getIsNoReturn(CXCursor C) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); - if (const FriendDecl* FD = dyn_cast(D)) { - return FD->isUnsupportedFriend(); + if (const FunctionDecl* FD = dyn_cast(D)) { + return FD->isNoReturn(); } } return 0; } -unsigned clangsharp_Cursor_getIsVariadic(CXCursor C) { - if (clang_isDeclaration(C.kind)) { +unsigned clangsharp_Cursor_getIsNothrow(CXCursor C) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); - if (const BlockDecl* BD = dyn_cast(D)) { - return BD->isVariadic(); + if (const CapturedDecl* CD = dyn_cast(D)) { + return CD->isNothrow(); } } - return clang_Cursor_isVariadic(C); + return 0; } -CXCursor clangsharp_Cursor_getLambdaCallOperator(CXCursor C) { - if (clang_isDeclaration(C.kind)) { +unsigned clangsharp_Cursor_getIsOverloadedOperator(CXCursor C) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); - if (const CXXRecordDecl* CRD = dyn_cast(D)) { - return MakeCXCursor(CRD->getLambdaCallOperator(), getCursorTU(C)); + if (const FunctionDecl* FD = dyn_cast(D)) { + return FD->isOverloadedOperator(); } } - return clang_getNullCursor(); + return 0; } -CXCursor clangsharp_Cursor_getLambdaContextDecl(CXCursor C) { - if (clang_isDeclaration(C.kind)) { +unsigned clangsharp_Cursor_getIsPackExpansion(CXCursor C) { + if (clang_isAttribute(C.kind)) { + const Attr* A = getCursorAttr(C); + return A->isPackExpansion(); + } + + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); - if (const CXXRecordDecl* CRD = dyn_cast(D)) { - if( CRD->isLambda() ) - return MakeCXCursor(CRD->getLambdaContextDecl(), getCursorTU(C)); + if (const NonTypeTemplateParmDecl* NTTPD = dyn_cast(D)) { + return NTTPD->isPackExpansion(); + } + + if (const TemplateTemplateParmDecl* TTPD = dyn_cast(D)) { + return TTPD->isPackExpansion(); + } + + if (const TemplateTypeParmDecl* TTPD = dyn_cast(D)) { + return TTPD->isPackExpansion(); } } - return clang_getNullCursor(); + return 0; } -CXCursor clangsharp_Cursor_getLambdaStaticInvoker(CXCursor C) { - if (clang_isDeclaration(C.kind)) { +unsigned clangsharp_Cursor_getIsParameterPack(CXCursor C) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); - if (const CXXRecordDecl* CRD = dyn_cast(D)) { - return MakeCXCursor(CRD->getLambdaStaticInvoker(), getCursorTU(C)); + if (const NonTypeTemplateParmDecl* NTTPD = dyn_cast(D)) { + return NTTPD->isParameterPack(); + } + + if (const TemplateTemplateParmDecl* TTPD = dyn_cast(D)) { + return TTPD->isParameterPack(); + } + + if (const TemplateTypeParmDecl* TTPD = dyn_cast(D)) { + return TTPD->isParameterPack(); } } - return clang_getNullCursor(); + return 0; } -CXCursor clangsharp_Cursor_getLhsExpr(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); +unsigned clangsharp_Cursor_getIsPartiallySubstituted(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const ArraySubscriptExpr* ASE = dyn_cast(E)) { - return MakeCXCursor(ASE->getLHS(), getCursorDecl(C), getCursorTU(C)); + if (const SizeOfPackExpr* SOPE = dyn_cast(S)) { + return SOPE->isPartiallySubstituted(); } + } - if (const BinaryOperator* BO = dyn_cast(E)) { - return MakeCXCursor(BO->getLHS(), getCursorDecl(C), getCursorTU(C)); - } + return 0; +} - if (const ConditionalOperator* CO = dyn_cast(E)) { - return MakeCXCursor(CO->getLHS(), getCursorDecl(C), getCursorTU(C)); - } +unsigned clangsharp_Cursor_getIsPotentiallyEvaluated(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const CXXFoldExpr* CFE = dyn_cast(E)) { - return MakeCXCursor(CFE->getLHS(), getCursorDecl(C), getCursorTU(C)); + if (const CXXTypeidExpr* CXXTE = dyn_cast(S)) { + return CXXTE->isPotentiallyEvaluated(); } + } - if (const CXXRewrittenBinaryOperator* CRBO = dyn_cast(E)) { - return MakeCXCursor(CRBO->getLHS(), getCursorDecl(C), getCursorTU(C)); + return 0; +} + +unsigned clangsharp_Cursor_getIsPure(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const FunctionDecl* FD = dyn_cast(D)) { + return FD->isPure(); } } - if (clang_isStatement(C.kind)) { + return 0; +} + +unsigned clangsharp_Cursor_getIsResultDependent(CXCursor C) { + if (isStmtOrExpr(C.kind)) { const Stmt* S = getCursorStmt(C); - if (const CaseStmt* CS = dyn_cast(S)) { - return MakeCXCursor(CS->getLHS(), getCursorDecl(C), getCursorTU(C)); + if (const GenericSelectionExpr* GSE = dyn_cast(S)) { + return GSE->isResultDependent(); } } - return clang_getNullCursor(); + return 0; } -unsigned clangsharp_Cursor_getMaxAlignment(CXCursor C) { - if (clang_isDeclaration(C.kind)) { - const Decl* D = getCursorDecl(C); - return D->getMaxAlignment(); +unsigned clangsharp_Cursor_getIsReversed(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + + if (const CXXRewrittenBinaryOperator* CXXRBO = dyn_cast(S)) { + return CXXRBO->isReversed(); + } } return 0; } -CXCursor clangsharp_Cursor_getMostRecentDecl(CXCursor C) { - if (clang_isDeclaration(C.kind)) { +unsigned clangsharp_Cursor_getIsSigned(CXCursor C) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); - return MakeCXCursor(D->getMostRecentDecl(), getCursorTU(C)); + + if (const EnumConstantDecl* ECD = dyn_cast(D)) { + return ECD->getInitVal().isSigned(); + } } - return clang_getNullCursor(); + return 0; } -CXCursor clangsharp_Cursor_getMostRecentNonInjectedDecl(CXCursor C) { - if (clang_isDeclaration(C.kind)) { +unsigned clangsharp_Cursor_getIsStatic(CXCursor C) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); - if (const CXXRecordDecl* CRD = dyn_cast(D)) { - return MakeCXCursor(CRD->getMostRecentNonInjectedDecl(), getCursorTU(C)); + if (const FunctionDecl* FD = dyn_cast(D)) { + return FD->isStatic(); } } - return clang_getNullCursor(); + return 0; } -CXCursor clangsharp_Cursor_getNextDeclInContext(CXCursor C) { - if (clang_isDeclaration(C.kind)) { +unsigned clangsharp_Cursor_getIsStaticDataMember(CXCursor C) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); - return MakeCXCursor(D->getNextDeclInContext(), getCursorTU(C)); + + if (const VarDecl* VD = dyn_cast(D)) { + return VD->isStaticDataMember(); + } } - return clang_getNullCursor(); + return 0; } -CXCursor clangsharp_Cursor_getNextSwitchCase(CXCursor C) { - if (clang_isStatement(C.kind)) { +unsigned clangsharp_Cursor_getIsStdInitListInitialization(CXCursor C) { + if (isStmtOrExpr(C.kind)) { const Stmt* S = getCursorStmt(C); - if (const SwitchCase* SC = dyn_cast(S)) { - return MakeCXCursor(SC->getNextSwitchCase(), getCursorDecl(C), getCursorTU(C)); + if (const CXXConstructExpr* CXXCE = dyn_cast(S)) { + return CXXCE->isStdInitListInitialization(); } } - return clang_getNullCursor(); + return 0; } -CXCursor clangsharp_Cursor_getNominatedBaseClass(CXCursor C) { - if (clang_isDeclaration(C.kind)) { +unsigned clangsharp_Cursor_getIsStrictlyPositive(CXCursor C) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); - if (const ConstructorUsingShadowDecl* CUSD = dyn_cast(D)) { - return MakeCXCursor(CUSD->getNominatedBaseClass(), getCursorTU(C)); + if (const EnumConstantDecl* ECD = dyn_cast(D)) { + return ECD->getInitVal().isStrictlyPositive(); } } - return clang_getNullCursor(); -} - -CXCursor clangsharp_Cursor_getNominatedBaseClassShadowDecl(CXCursor C) { - if (clang_isDeclaration(C.kind)) { - const Decl* D = getCursorDecl(C); + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const ConstructorUsingShadowDecl* CUSD = dyn_cast(D)) { - return MakeCXCursor(CUSD->getNominatedBaseClassShadowDecl(), getCursorTU(C)); + if (const IntegerLiteral* IL = dyn_cast(S)) { + return IL->getValue().isStrictlyPositive(); } } - return clang_getNullCursor(); + return 0; } -CXCursor clangsharp_Cursor_getNonClosureContext(CXCursor C) { - if (clang_isDeclaration(C.kind)) { +unsigned clangsharp_Cursor_getIsTemplated(CXCursor C) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); - return MakeCXCursor(D->getNonClosureContext(), getCursorTU(C)); + return D->isTemplated(); } - return clang_getNullCursor(); + return 0; } -int clangsharp_Cursor_getNumAssociatedConstraints(CXCursor C) { - if (clang_isDeclaration(C.kind)) { +unsigned clangsharp_Cursor_getIsThisDeclarationADefinition(CXCursor C) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); - if (const ClassTemplatePartialSpecializationDecl* CTPSD = dyn_cast(D)) { - SmallVector associatedConstraints; - CTPSD->getAssociatedConstraints(associatedConstraints); - return associatedConstraints.size(); + if (const ClassTemplateDecl* CTD = dyn_cast(D)) { + return CTD->isThisDeclarationADefinition(); } - if (const NonTypeTemplateParmDecl* NTTPD = dyn_cast(D)) { - SmallVector associatedConstraints; - NTTPD->getAssociatedConstraints(associatedConstraints); - return associatedConstraints.size(); + if (const FunctionDecl* FD = dyn_cast(D)) { + return FD->isThisDeclarationADefinition(); } - if (const TemplateDecl* TD = dyn_cast(D)) { - SmallVector associatedConstraints; - TD->getAssociatedConstraints(associatedConstraints); - return associatedConstraints.size(); + if (const FunctionTemplateDecl* FTD = dyn_cast(D)) { + return FTD->isThisDeclarationADefinition(); } - if (const TemplateTypeParmDecl* TTPD = dyn_cast(D)) { - SmallVector associatedConstraints; - TTPD->getAssociatedConstraints(associatedConstraints); - return associatedConstraints.size(); + if (const ObjCInterfaceDecl* OCID = dyn_cast(D)) { + return OCID->isThisDeclarationADefinition(); } - if (const VarTemplatePartialSpecializationDecl* VTPSD = dyn_cast(D)) { - SmallVector associatedConstraints; - VTPSD->getAssociatedConstraints(associatedConstraints); - return associatedConstraints.size(); + if (const ObjCMethodDecl* OCMD = dyn_cast(D)) { + return OCMD->isThisDeclarationADefinition(); } - } - return -1; -} + if (const ObjCProtocolDecl* OCPD = dyn_cast(D)) { + return OCPD->isThisDeclarationADefinition(); + } + + if (const TagDecl* TD = dyn_cast(D)) { + return TD->isThisDeclarationADefinition(); + } + + if (const VarTemplateDecl* VTD = dyn_cast(D)) { + return VTD->isThisDeclarationADefinition(); + } + } + + return 0; +} + +unsigned clangsharp_Cursor_getIsThrownVariableInScope(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + + if (const CXXThrowExpr* CXXTE = dyn_cast(S)) { + return CXXTE->isThrownVariableInScope(); + } + } + + return 0; +} + +unsigned clangsharp_Cursor_getIsTransparent(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const TypedefNameDecl* TND = dyn_cast(D)) { + return TND->isTransparentTag(); + } + } + + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + + if (const InitListExpr* ILE = dyn_cast(S)) { + return ILE->isTransparent(); + } + } + + return 0; +} + +unsigned clangsharp_Cursor_getIsTypeConcept(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const ConceptDecl* CTD = dyn_cast(D)) { + return CTD->isTypeConcept(); + } + } + + return 0; +} + +unsigned clangsharp_Cursor_getIsUnavailable(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + return D->isUnavailable(); + } + + return 0; +} + +unsigned clangsharp_Cursor_getIsUnconditionallyVisible(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + return D->isUnconditionallyVisible(); + } + + return 0; +} + +unsigned clangsharp_Cursor_getIsUnnamedBitfield(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const FieldDecl* FD = dyn_cast(D)) { + return FD->isUnnamedBitfield(); + } + } + + return 0; +} + +unsigned clangsharp_Cursor_getIsUnsigned(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const EnumConstantDecl* ECD = dyn_cast(D)) { + return ECD->getInitVal().isUnsigned(); + } + } + + return 0; +} + +unsigned clangsharp_Cursor_getIsUnsupportedFriend(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const FriendDecl* FD = dyn_cast(D)) { + return FD->isUnsupportedFriend(); + } + } + + return 0; +} + +unsigned clangsharp_Cursor_getIsUserProvided(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const FunctionDecl* FD = dyn_cast(D)) { + return FD->isUserProvided(); + } + } + + return 0; +} + +unsigned clangsharp_Cursor_getIsVariadic(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const BlockDecl* BD = dyn_cast(D)) { + return BD->isVariadic(); + } + } + + return clang_Cursor_isVariadic(C); +} + +CXCursor clangsharp_Cursor_getLambdaCallOperator(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const CXXRecordDecl* CRD = dyn_cast(D)) { + return MakeCXCursor(CRD->getLambdaCallOperator(), getCursorTU(C)); + } + } + + return clang_getNullCursor(); +} + +CXCursor clangsharp_Cursor_getLambdaContextDecl(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const CXXRecordDecl* CRD = dyn_cast(D)) { + if (CRD->isLambda()) { + return MakeCXCursor(CRD->getLambdaContextDecl(), getCursorTU(C)); + } + } + } + + return clang_getNullCursor(); +} + +CXCursor clangsharp_Cursor_getLambdaStaticInvoker(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const CXXRecordDecl* CRD = dyn_cast(D)) { + return MakeCXCursor(CRD->getLambdaStaticInvoker(), getCursorTU(C)); + } + } + + return clang_getNullCursor(); +} + +CXCursor clangsharp_Cursor_getLhsExpr(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + + if (const CXXRewrittenBinaryOperator* CRBO = dyn_cast(S)) { + return MakeCXCursor(CRBO->getLHS(), getCursorDecl(C), getCursorTU(C)); + } + } + + return clang_getNullCursor(); +} + +unsigned clangsharp_Cursor_getMaxAlignment(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + return D->getMaxAlignment(); + } + + return 0; +} + +CXCursor clangsharp_Cursor_getMethod(CXCursor C, unsigned i) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const CXXMethodDecl* CXXMD = dyn_cast(D)) { + unsigned n = 0; + + for (auto overriddenMethod : CXXMD->overridden_methods()) { + if (n == i) { + return MakeCXCursor(overriddenMethod, getCursorTU(C)); + } + n++; + } + } + + if (const CXXRecordDecl* CXXRD = dyn_cast(D)) { + unsigned n = 0; + + for (auto method : CXXRD->methods()) { + if (n == i) { + return MakeCXCursor(method, getCursorTU(C)); + } + n++; + } + } + } + + return clang_getNullCursor(); +} + +CXCursor clangsharp_Cursor_getMostRecentDecl(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + return MakeCXCursor(D->getMostRecentDecl(), getCursorTU(C)); + } + + return clang_getNullCursor(); +} + +CXString clangsharp_Cursor_getName(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const FunctionDecl* FD = dyn_cast(D)) { + return createDup(FD->getNameInfo().getAsString()); + } + + if (const ObjCProtocolDecl* OCPD = dyn_cast(D)) { + return createDup(OCPD->getObjCRuntimeNameAsString()); + } + } + + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + + if (const CXXDependentScopeMemberExpr* CXXDSME = dyn_cast(S)) { + return createDup(CXXDSME->getMemberNameInfo().getAsString()); + } + + if (const CXXNamedCastExpr* CXXNCE = dyn_cast(S)) { + return createDup(CXXNCE->getCastName()); + } + + if (const DeclRefExpr* DRE = dyn_cast(S)) { + return createDup(DRE->getNameInfo().getAsString()); + } + + if (const DependentScopeDeclRefExpr* DSDRE = dyn_cast(S)) { + return createDup(DSDRE->getDeclName().getAsString()); + } + + if (const LabelStmt* LS = dyn_cast(S)) { + return createDup(LS->getName()); + } + + if (const MemberExpr* ME = dyn_cast(S)) { + return createDup(ME->getMemberNameInfo().getAsString()); + } + + if (const MSDependentExistsStmt* MSDES = dyn_cast(S)) { + return createDup( + MSDES->getNameInfo().getAsString()); + } + + if (const ObjCBridgedCastExpr* OCBCE = dyn_cast(S)) { + return createDup(OCBCE->getBridgeKindName()); + } + + if (const OverloadExpr* OE = dyn_cast(S)) { + return createDup(OE->getName().getAsString()); + } + + if (const UnresolvedMemberExpr* UME = dyn_cast(S)) { + return createDup(UME->getMemberName().getAsString()); + } + } + + return createEmpty(); +} + +CXCursor clangsharp_Cursor_getNextDeclInContext(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + return MakeCXCursor(D->getNextDeclInContext(), getCursorTU(C)); + } + + return clang_getNullCursor(); +} + +CXCursor clangsharp_Cursor_getNextSwitchCase(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + + if (const SwitchCase* SC = dyn_cast(S)) { + return MakeCXCursor(SC->getNextSwitchCase(), getCursorDecl(C), getCursorTU(C)); + } + } + + return clang_getNullCursor(); +} + +CXCursor clangsharp_Cursor_getNominatedBaseClass(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const ConstructorUsingShadowDecl* CUSD = dyn_cast(D)) { + return MakeCXCursor(CUSD->getNominatedBaseClass(), getCursorTU(C)); + } + } + + return clang_getNullCursor(); +} + +CXCursor clangsharp_Cursor_getNominatedBaseClassShadowDecl(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const ConstructorUsingShadowDecl* CUSD = dyn_cast(D)) { + return MakeCXCursor(CUSD->getNominatedBaseClassShadowDecl(), getCursorTU(C)); + } + } + + return clang_getNullCursor(); +} + +CXCursor clangsharp_Cursor_getNonClosureContext(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + return MakeCXCursor(D->getNonClosureContext(), getCursorTU(C)); + } + + return clang_getNullCursor(); +} + +int clangsharp_Cursor_getNumArguments(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const BlockDecl* BD = dyn_cast(D)) { + return BD->param_size(); + } + + if (const CapturedDecl* CD = dyn_cast(D)) { + return CD->getNumParams(); + } + + if (const ObjCCategoryDecl* OCCD = dyn_cast(D)) { + return OCCD->getTypeParamList()->size(); + } + } + + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + + if (const CastExpr* CE = dyn_cast(S)) { + return CE->path_size(); + } + + if (const CXXUnresolvedConstructExpr* CXXUCE = dyn_cast(S)) { + return CXXUCE->arg_size(); + } + + if (const ExprWithCleanups* EWC = dyn_cast(S)) { + return EWC->getNumObjects(); + } + + if (const ObjCMessageExpr* OCME = dyn_cast(S)) { + return OCME->getNumArgs(); + } + } + + return clang_Cursor_getNumArguments(C); +} + +int clangsharp_Cursor_getNumAssocs(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + + if (const GenericSelectionExpr* GSE = dyn_cast(S)) { + return GSE->getNumAssocs(); + } + } -int clangsharp_Cursor_getNumArguments(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + return -1; +} + +int clangsharp_Cursor_getNumAssociatedConstraints(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const ClassTemplatePartialSpecializationDecl* CTPSD = dyn_cast(D)) { + SmallVector associatedConstraints; + CTPSD->getAssociatedConstraints(associatedConstraints); + return associatedConstraints.size(); + } + + if (const NonTypeTemplateParmDecl* NTTPD = dyn_cast(D)) { + SmallVector associatedConstraints; + NTTPD->getAssociatedConstraints(associatedConstraints); + return associatedConstraints.size(); + } + + if (const TemplateDecl* TD = dyn_cast(D)) { + SmallVector associatedConstraints; + TD->getAssociatedConstraints(associatedConstraints); + return associatedConstraints.size(); + } + + if (const TemplateTypeParmDecl* TTPD = dyn_cast(D)) { + SmallVector associatedConstraints; + TTPD->getAssociatedConstraints(associatedConstraints); + return associatedConstraints.size(); + } + + if (const VarTemplatePartialSpecializationDecl* VTPSD = dyn_cast(D)) { + SmallVector associatedConstraints; + VTPSD->getAssociatedConstraints(associatedConstraints); + return associatedConstraints.size(); + } + } + + return -1; +} + +int clangsharp_Cursor_getNumAttrs(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + return D->getAttrs().size(); + } + + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + + if (const AttributedStmt* AS = dyn_cast(S)) { + return AS->getAttrs().size(); + } + } + + return -1; +} + +int clangsharp_Cursor_getNumBases(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const CXXRecordDecl* CXXRD = dyn_cast(D)) { + return CXXRD->getDefinition() ? CXXRD->getNumBases() : 0; + } + } + + return -1; +} + +int clangsharp_Cursor_getNumBindings(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const DecompositionDecl* DD = dyn_cast(D)) { + return DD->bindings().size(); + } + } + + return -1; +} + +int clangsharp_Cursor_getNumCaptures(CXCursor C) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const BlockDecl* BD = dyn_cast(D)) { - return BD->param_size(); + return BD->captures().size(); + } + } + + return -1; +} + +int clangsharp_Cursor_getNumChildren(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + unsigned n = 0; + + for (auto child : S->children()) { + n++; + } + + return n; + } + + return -1; +} + +int clangsharp_Cursor_getNumCtors(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const CXXRecordDecl* CXXRD = dyn_cast(D)) { + unsigned n = 0; + + for (auto ctor : CXXRD->ctors()) { + n++; + } + + return n; + } + } + + return -1; +} + +int clangsharp_Cursor_getNumDecls(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const DeclContext* DC = dyn_cast(D)) { + unsigned n = 0; + + for (auto decl : DC->decls()) { + n++; + } + + return n; + } + + return 0; + } + + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + + if (const CXXNewExpr* CXXNE = dyn_cast(S)) { + return 2; + } + + if (const DeclStmt* DS = dyn_cast(S)) { + unsigned n = 0; + + for (auto decl : DS->decls()) { + n++; + } + + return n; + } + + if (const FunctionParmPackExpr* FPPE = dyn_cast(S)) { + return FPPE->getNumExpansions(); + } + + if (const OverloadExpr* OE = dyn_cast(S)) { + return OE->getNumDecls(); + } + } + + return -1; +} + +int clangsharp_Cursor_getNumEnumerators(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const EnumDecl* ED = dyn_cast(D)) { + unsigned n = 0; + + for (auto enumerator : ED->enumerators()) { + n++; + } + + return n; + } + } + + return -1; +} + +int clangsharp_Cursor_getNumExpansionTypes(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const NonTypeTemplateParmDecl* NTTPD = dyn_cast(D)) { + return NTTPD->getNumExpansionTypes(); + } + } + + return -1; +} + +int clangsharp_Cursor_getNumExprs(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const CXXConstructorDecl* CXXCD = dyn_cast(D)) { + return CXXCD->getNumCtorInitializers(); + } + + if (const ObjCImplementationDecl* OCID = dyn_cast(D)) { + return OCID->getNumIvarInitializers(); + } + } + + return -1; +} + +int clangsharp_Cursor_getNumFields(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const RecordDecl* RD = dyn_cast(D)) { + unsigned n = 0; + + for (auto f : RD->fields()) { + n++; + } + + return n; + } + } + + return -1; +} + +int clangsharp_Cursor_getNumFriends(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const CXXRecordDecl* CXXRD = dyn_cast(D)) { + unsigned n = 0; + + if (CXXRD->getDefinition()) { + for (auto f : CXXRD->friends()) { + n++; + } + } + + return n; + } + } + + return -1; +} + +int clangsharp_Cursor_getNumMethods(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const CXXMethodDecl* CXXMD = dyn_cast(D)) { + return CXXMD->size_overridden_methods(); + } + + if (const CXXRecordDecl* CXXRD = dyn_cast(D)) { + unsigned n = 0; + + for (auto method : CXXRD->methods()) { + n++; + } + + return n; + } + } + + return -1; +} + +int clangsharp_Cursor_getNumProtocols(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const ObjCCategoryDecl* OCCD = dyn_cast(D)) { + return OCCD->protocol_size(); + } + + if (const ObjCProtocolDecl* OCPD = dyn_cast(D)) { + return OCPD->protocol_size(); + } + } + + return -1; +} + +int clangsharp_Cursor_getNumSpecializations(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const ClassScopeFunctionSpecializationDecl* CSFSD = dyn_cast(D)) { + return 1; + } + + if (const ClassTemplateDecl* CTD = dyn_cast(D)) { + unsigned n = 0; + + for (auto specialization : CTD->specializations()) { + n++; + } + + return n; + } + + if (const FunctionTemplateDecl* FTD = dyn_cast(D)) { + unsigned n = 0; + + for (auto specialization : FTD->specializations()) { + n++; + } + + return n; + } + } + + return 0; +} + +int clangsharp_Cursor_getNumTemplateArguments(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const ClassScopeFunctionSpecializationDecl* CSFSD = dyn_cast(D)) { + return CSFSD->getTemplateArgsAsWritten()->getNumTemplateArgs(); + } + + if (const ClassTemplateSpecializationDecl* CTSD = dyn_cast(D)) { + return CTSD->getTemplateArgs().size(); + } + + if (const FunctionDecl* FD = dyn_cast(D)) { + const TemplateArgumentList* TAL = FD->getTemplateSpecializationArgs(); + return TAL && TAL->size(); + } + + if (FunctionTemplateDecl* FTD = const_cast(dyn_cast(D))) { + return FTD->getInjectedTemplateArgs().size(); + } + + if (const VarTemplateSpecializationDecl* VTSD = dyn_cast(D)) { + return VTSD->getTemplateArgs().size(); + } + } + + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + + if (const CXXDependentScopeMemberExpr* CXXDSME = dyn_cast(S)) { + return CXXDSME->getNumTemplateArgs(); + } + + if (const DeclRefExpr* DRE = dyn_cast(S)) { + return DRE->getNumTemplateArgs(); + } + + if (const DependentScopeDeclRefExpr* DSDRE = dyn_cast(S)) { + return DSDRE->getNumTemplateArgs(); + } + + if (const MemberExpr* ME = dyn_cast(S)) { + return ME->getNumTemplateArgs(); + } + + if (const OverloadExpr* OE = dyn_cast(S)) { + return OE->getNumTemplateArgs(); + } + + if (const SizeOfPackExpr* SOPE = dyn_cast(S)) { + return SOPE->getPartialArguments().size(); } - if (const CapturedDecl* CD = dyn_cast(D)) { - return CD->getNumParams(); + if (const SubstNonTypeTemplateParmPackExpr* SNTTPPE = dyn_cast(S)) { + return 1; } } - return clang_Cursor_getNumArguments(C); + return clang_Cursor_getNumTemplateArguments(C); } -int clangsharp_Cursor_getNumCaptures(CXCursor C) { - if (clang_isDeclaration(C.kind)) { +int clangsharp_Cursor_getNumTemplateParameters(CXCursor C, unsigned listIndex) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); - if (const BlockDecl* BD = dyn_cast(D)) { - return BD->captures().size(); + if (const ClassTemplatePartialSpecializationDecl* CTPSD = dyn_cast(D)) { + if (listIndex == 0) { + return CTPSD->getTemplateParameters()->size(); + } } - } - return -1; -} + if (const DeclaratorDecl* DD = dyn_cast(D)) { + if (listIndex < DD->getNumTemplateParameterLists()) { + return DD->getTemplateParameterList(listIndex)->size(); + } + } -int clangsharp_Cursor_getNumExprs(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); + if (const FriendDecl* FD = dyn_cast(D)) { + if (listIndex < FD->getFriendTypeNumTemplateParameterLists()) { + return FD->getFriendTypeTemplateParameterList(listIndex)->size(); + } + } + + if (const FriendTemplateDecl* FTD = dyn_cast(D)) { + if (listIndex < FTD->getNumTemplateParameters()) { + return FTD->getTemplateParameterList(listIndex)->size(); + } + } + + if (const TagDecl* TD = dyn_cast(D)) { + if (listIndex < TD->getNumTemplateParameterLists()) { + return TD->getTemplateParameterList(listIndex)->size(); + } + } - if (const InitListExpr* ILE = dyn_cast(E)) { - return ILE->getNumInits(); + if (const TemplateDecl* TD = dyn_cast(D)) { + if (listIndex == 0) { + return TD->getTemplateParameters()->size(); + } } - if (const ParenListExpr* PLE = dyn_cast(E)) { - return PLE->getNumExprs(); + if (const VarTemplatePartialSpecializationDecl* VTPSD = dyn_cast(D)) { + if (listIndex == 0) { + return VTPSD->getTemplateParameters()->size(); + } } } return -1; } -int clangsharp_Cursor_getNumSpecializations(CXCursor C) { - if (clang_isDeclaration(C.kind)) { +int clangsharp_Cursor_getNumTemplateParameterLists(CXCursor C) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); - if (const ClassScopeFunctionSpecializationDecl* CSFSD = dyn_cast(D)) { + if (const ClassTemplatePartialSpecializationDecl* CTPSD = dyn_cast(D)) { return 1; } - } - - return 0; -} -int clangsharp_Cursor_getNumTemplateArguments(CXCursor C) { - if (clang_isDeclaration(C.kind)) { - const Decl* D = getCursorDecl(C); + if (const DeclaratorDecl* DD = dyn_cast(D)) { + return DD->getNumTemplateParameterLists(); + } - if (const ClassScopeFunctionSpecializationDecl* CSFSD = dyn_cast(D)) { - return CSFSD->getTemplateArgsAsWritten()->getNumTemplateArgs(); + if (const FriendDecl* FD = dyn_cast(D)) { + return FD->getFriendTypeNumTemplateParameterLists(); } - if (const ClassTemplatePartialSpecializationDecl* CTPSD = dyn_cast(D)) { - return CTPSD->getTemplateParameters()->size(); + if (const FriendTemplateDecl* FTD = dyn_cast(D)) { + return FTD->getNumTemplateParameters(); } - if (const ClassTemplateSpecializationDecl* CTSD = dyn_cast(D)) { - return CTSD->getTemplateArgs().size(); + if (const TagDecl* TD = dyn_cast(D)) { + return TD->getNumTemplateParameterLists(); } if (const TemplateDecl* TD = dyn_cast(D)) { - return TD->getTemplateParameters()->size(); + return 1; } if (const VarTemplatePartialSpecializationDecl* VTPSD = dyn_cast(D)) { - return VTPSD->getTemplateArgs().size(); + return 1; } + } - if (const VarTemplateSpecializationDecl* VTSD = dyn_cast(D)) { - return VTSD->getTemplateArgs().size(); + return -1; +} + +int clangsharp_Cursor_getNumVBases(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const CXXRecordDecl* CXXRD = dyn_cast(D)) { + return CXXRD->getDefinition() ? CXXRD->getNumVBases() : 0; } } - return clang_Cursor_getNumTemplateArguments(C); + return -1; } -CXCursor clangsharp_Cursor_getOpaqueValueExpr(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); +CXCursor clangsharp_Cursor_getOpaqueValue(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const BinaryConditionalOperator* BCO = dyn_cast(E)) { + if (const BinaryConditionalOperator* BCO = dyn_cast(S)) { return MakeCXCursor(BCO->getOpaqueValue(), getCursorDecl(C), getCursorTU(C)); } } @@ -1971,7 +3539,7 @@ CXCursor clangsharp_Cursor_getOpaqueValueExpr(CXCursor C) { } CXType clangsharp_Cursor_getOriginalType(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const ParmVarDecl* PVD = dyn_cast(D)) { @@ -1982,12 +3550,43 @@ CXType clangsharp_Cursor_getOriginalType(CXCursor C) { return MakeCXType(QualType(), getCursorTU(C)); } +CX_OverloadedOperatorKind clangsharp_Cursor_getOverloadedOperatorKind(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const FunctionDecl* FD = dyn_cast(D)) { + return static_cast(FD->getOverloadedOperator()); + } + } + + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + + if (const CXXOperatorCallExpr* CXXOCE = dyn_cast(S)) { + return static_cast(CXXOCE->getOperator()); + } + } + + return CX_OO_Invalid; +} + +int clangsharp_Cursor_getPackLength(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + + if (const SizeOfPackExpr* SOPE = dyn_cast(S)) { + return SOPE->getPackLength(); + } + } + + return -1; +} + CXCursor clangsharp_Cursor_getParentFunctionOrMethod(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); - const Decl* PD = dyn_cast_or_null(D->getParentFunctionOrMethod()); - if (PD) { + if (const Decl* PD = dyn_cast_or_null(D->getParentFunctionOrMethod())) { return MakeCXCursor(PD, getCursorTU(C)); } } @@ -1996,7 +3595,7 @@ CXCursor clangsharp_Cursor_getParentFunctionOrMethod(CXCursor C) { } CXCursor clangsharp_Cursor_getPlaceholderTypeConstraint(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const NonTypeTemplateParmDecl* NTTPD = dyn_cast(D)) { @@ -2008,7 +3607,7 @@ CXCursor clangsharp_Cursor_getPlaceholderTypeConstraint(CXCursor C) { } CXCursor clangsharp_Cursor_getPreviousDecl(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); return MakeCXCursor(D->getPreviousDecl(), getCursorTU(C)); } @@ -2017,7 +3616,7 @@ CXCursor clangsharp_Cursor_getPreviousDecl(CXCursor C) { } CXCursor clangsharp_Cursor_getPrimaryTemplate(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const FunctionDecl* FD = dyn_cast(D)) { @@ -2028,136 +3627,240 @@ CXCursor clangsharp_Cursor_getPrimaryTemplate(CXCursor C) { return clang_getNullCursor(); } +CXCursor clangsharp_Cursor_getProtocol(CXCursor C, unsigned i) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const ObjCCategoryDecl* OCCD = dyn_cast(D)) { + unsigned n = 0; + + for (auto protocol : OCCD->protocols()) { + if (n == i) { + return MakeCXCursor(protocol, getCursorTU(C)); + } + n++; + } + } + + if (const ObjCProtocolDecl* OCPD = dyn_cast(D)) { + unsigned n = 0; + + for (auto protocol : OCPD->protocols()) { + if (n == i) { + return MakeCXCursor(protocol, getCursorTU(C)); + } + n++; + } + } + } + + return clang_getNullCursor(); +} + +CXCursor clangsharp_Cursor_getRedeclContext(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const DeclContext* DC = dyn_cast(D)) { + return MakeCXCursor(dyn_cast(DC->getRedeclContext()), getCursorTU(C)); + } + } + + return clang_getNullCursor(); +} + CXCursor clangsharp_Cursor_getReferenced(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const AddrLabelExpr* ALE = dyn_cast(E)) { + if (const AddrLabelExpr* ALE = dyn_cast(S)) { return MakeCXCursor(ALE->getLabel(), getCursorTU(C)); } - if (const BlockExpr* BE = dyn_cast(E)) { + if (const BlockExpr* BE = dyn_cast(S)) { return MakeCXCursor(BE->getBlockDecl(), getCursorTU(C)); } - if (const CXXConstructExpr* CCE = dyn_cast(E)) { - return MakeCXCursor(CCE->getConstructor(), getCursorTU(C)); + if (const CXXCatchStmt* CXXCS = dyn_cast(S)) { + return MakeCXCursor(CXXCS->getExceptionDecl(), getCursorTU(C)); } - if (const CXXDefaultArgExpr* CDAE = dyn_cast(E)) { - return MakeCXCursor(CDAE->getParam(), getCursorTU(C)); + if (const CXXConstructExpr* CXXCE = dyn_cast(S)) { + return MakeCXCursor(CXXCE->getConstructor(), getCursorTU(C)); } - if (const CXXDefaultInitExpr* CDIE = dyn_cast(E)) { - return MakeCXCursor(CDIE->getField(), getCursorTU(C)); + if (const CXXDefaultArgExpr* CXXDAE = dyn_cast(S)) { + return MakeCXCursor(CXXDAE->getParam(), getCursorTU(C)); } - if (const CXXDeleteExpr* CDE = dyn_cast(E)) { - return MakeCXCursor(CDE->getOperatorDelete(), getCursorTU(C)); + if (const CXXDefaultInitExpr* CXXDIE = dyn_cast(S)) { + return MakeCXCursor(CXXDIE->getField(), getCursorTU(C)); } - if (const InitListExpr* ILE = dyn_cast(E)) { - return MakeCXCursor(ILE->getInitializedFieldInUnion(), getCursorTU(C)); + if (const CXXDeleteExpr* CXXDE = dyn_cast(S)) { + return MakeCXCursor(CXXDE->getOperatorDelete(), getCursorTU(C)); } - } - if (clang_isStatement(C.kind)) { - const Stmt* S = getCursorStmt(C); + if (const CXXDependentScopeMemberExpr* CXXDSME = dyn_cast(S)) { + return MakeCXCursor(CXXDSME->getFirstQualifierFoundInScope(), getCursorTU(C)); + } - if (const ForStmt* FS = dyn_cast(S)) { - return MakeCXCursor(FS->getConditionVariable(), getCursorTU(C)); + if (const CXXUuidofExpr* CXXUE = dyn_cast(S)) { + return MakeCXCursor(CXXUE->getGuidDecl(), getCursorTU(C)); } - if (const GotoStmt* GS = dyn_cast(S)) { - return MakeCXCursor(GS->getLabel(), getCursorTU(C)); + if (const FunctionParmPackExpr* FPPE = dyn_cast(S)) { + return MakeCXCursor(FPPE->getParameterPack(), getCursorTU(C)); } - if (const IfStmt* IS = dyn_cast(S)) { - return MakeCXCursor(IS->getConditionVariable(), getCursorTU(C)); + if (const GotoStmt* GS = dyn_cast(S)) { + return MakeCXCursor(GS->getLabel(), getCursorTU(C)); } if (const IndirectGotoStmt* IGS = dyn_cast(S)) { return MakeCXCursor(IGS->getConstantTarget(), getCursorTU(C)); } + if (const InitListExpr* ILE = dyn_cast(S)) { + return MakeCXCursor(ILE->getInitializedFieldInUnion(), getCursorTU(C)); + } + if (const LabelStmt* LS = dyn_cast(S)) { return MakeCXCursor(LS->getDecl(), getCursorTU(C)); } + if (const MaterializeTemporaryExpr* MTE = dyn_cast(S)) { + return MakeCXCursor(MTE->getLifetimeExtendedTemporaryDecl(), getCursorTU(C)); + } + + if (const ObjCArrayLiteral* OCAL = dyn_cast(S)) { + return MakeCXCursor(OCAL->getArrayWithObjectsMethod(), getCursorTU(C)); + } + + if (const ObjCAtCatchStmt* OCACS = dyn_cast(S)) { + return MakeCXCursor(OCACS->getCatchParamDecl(), getCursorTU(C)); + } + + if (const ObjCBoxedExpr* OCBE = dyn_cast(S)) { + return MakeCXCursor(OCBE->getBoxingMethod(), getCursorTU(C)); + } + + if (const ObjCDictionaryLiteral* OCDL = dyn_cast(S)) { + return MakeCXCursor(OCDL->getDictWithObjectsMethod(), getCursorTU(C)); + } + + if (const ObjCIvarRefExpr* OCIRE = dyn_cast(S)) { + return MakeCXCursor(OCIRE->getDecl(), getCursorTU(C)); + } + + if (const ObjCMessageExpr* OCME = dyn_cast(S)) { + return MakeCXCursor(OCME->getMethodDecl(), getCursorTU(C)); + } + + if (const ObjCProtocolExpr* OCPE = dyn_cast(S)) { + return MakeCXCursor(OCPE->getProtocol(), getCursorTU(C)); + } + + if (const ObjCSubscriptRefExpr* OCSRE = dyn_cast(S)) { + return MakeCXCursor(OCSRE->getAtIndexMethodDecl(), getCursorTU(C)); + } + + if (const OverloadExpr* OE = dyn_cast(S)) { + return MakeCXCursor(OE->getNamingClass(), getCursorTU(C)); + } + if (const ReturnStmt* RS = dyn_cast(S)) { return MakeCXCursor(RS->getNRVOCandidate(), getCursorTU(C)); } - if (const SwitchStmt* SS = dyn_cast(S)) { - return MakeCXCursor(SS->getConditionVariable(), getCursorTU(C)); + if (const SubstNonTypeTemplateParmExpr* SNTTPE = dyn_cast(S)) { + return MakeCXCursor(SNTTPE->getParameter(), getCursorTU(C)); } - if (const WhileStmt* WS = dyn_cast(S)) { - return MakeCXCursor(WS->getConditionVariable(), getCursorTU(C)); + if (const SubstNonTypeTemplateParmPackExpr* SNTTPPE = dyn_cast(S)) { + return MakeCXCursor(SNTTPPE->getParameterPack(), getCursorTU(C)); } } return clang_getCursorReferenced(C); } -CXType clangsharp_Cursor_getReturnType(CXCursor C) { - if (clang_isDeclaration(C.kind)) { - const Decl* D = getCursorDecl(C); +unsigned clangsharp_Cursor_getRequiresZeroInitialization(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const FunctionDecl* FD = dyn_cast(D)) { - return MakeCXType(FD->getReturnType(), getCursorTU(C)); + if (const CXXConstructExpr* CXXCE = dyn_cast(S)) { + return CXXCE->requiresZeroInitialization(); } } - return MakeCXType(QualType(), getCursorTU(C)); + return 0; } -CXCursor clangsharp_Cursor_getRhsExpr(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); +int clangsharp_Cursor_getResultIndex(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const ArraySubscriptExpr* ASE = dyn_cast(E)) { - return MakeCXCursor(ASE->getRHS(), getCursorDecl(C), getCursorTU(C)); + if (const GenericSelectionExpr* GSE = dyn_cast(S)) { + if (!GSE->isResultDependent()) { + return GSE->getResultIndex(); + } + } + + if (const PseudoObjectExpr* POE = dyn_cast(S)) { + return POE->getResultExprIndex(); } + } + + return -1; +} + +CXType clangsharp_Cursor_getReturnType(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); - if (const BinaryOperator* BO = dyn_cast(E)) { - return MakeCXCursor(BO->getRHS(), getCursorDecl(C), getCursorTU(C)); + if (const FunctionDecl* FD = dyn_cast(D)) { + return MakeCXType(FD->getReturnType(), getCursorTU(C)); } - if (const ConditionalOperator* CO = dyn_cast(E)) { - return MakeCXCursor(CO->getRHS(), getCursorDecl(C), getCursorTU(C)); + if (const ObjCPropertyDecl* OCPD = dyn_cast(D)) { + return MakeCXType(OCPD->getType(), getCursorTU(C)); } - if (const CXXFoldExpr* CFE = dyn_cast(E)) { - return MakeCXCursor(CFE->getRHS(), getCursorDecl(C), getCursorTU(C)); + if (const ObjCMethodDecl* OCMD = dyn_cast(D)) { + return MakeCXType(OCMD->getReturnType(), getCursorTU(C)); } - if (const CXXRewrittenBinaryOperator* CRBO = dyn_cast(E)) { - return MakeCXCursor(CRBO->getRHS(), getCursorDecl(C), getCursorTU(C)); + if (const ObjCPropertyDecl* OCPD = dyn_cast(D)) { + return MakeCXType(OCPD->getType(), getCursorTU(C)); } } - if (clang_isStatement(C.kind)) { + return MakeCXType(QualType(), getCursorTU(C)); +} + +CXCursor clangsharp_Cursor_getRhsExpr(CXCursor C) { + if (isStmtOrExpr(C.kind)) { const Stmt* S = getCursorStmt(C); - if (const CaseStmt* CS = dyn_cast(S)) { - return MakeCXCursor(CS->getRHS(), getCursorDecl(C), getCursorTU(C)); + if (const CXXRewrittenBinaryOperator* CRBO = dyn_cast(S)) { + return MakeCXCursor(CRBO->getRHS(), getCursorDecl(C), getCursorTU(C)); } } return clang_getNullCursor(); } -CXCursor clangsharp_Cursor_getRowIdxExpr(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); +unsigned clangsharp_Cursor_getShouldCopy(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const MatrixSubscriptExpr* MSE = dyn_cast(E)) { - return MakeCXCursor(MSE->getRowIdx(), getCursorDecl(C), getCursorTU(C)); + if (const ObjCIndirectCopyRestoreExpr* OCICRE = dyn_cast(S)) { + return OCICRE->shouldCopy(); } } - return clang_getNullCursor(); + return 0; } CXSourceRange clangsharp_Cursor_getSourceRange(CXCursor C) { @@ -2170,7 +3873,7 @@ CXSourceRange clangsharp_Cursor_getSourceRange(CXCursor C) { } CXCursor clangsharp_Cursor_getSpecialization(CXCursor C, unsigned i) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const ClassScopeFunctionSpecializationDecl* CSFSD = dyn_cast(D)) { @@ -2178,13 +3881,35 @@ CXCursor clangsharp_Cursor_getSpecialization(CXCursor C, unsigned i) { return MakeCXCursor(CSFSD->getSpecialization(), getCursorTU(C)); } } + + if (const ClassTemplateDecl* CTD = dyn_cast(D)) { + unsigned n = 0; + + for (auto specialization : CTD->specializations()) { + if (n == i) { + return MakeCXCursor(specialization, getCursorTU(C)); + } + n++; + } + } + + if (const FunctionTemplateDecl* FTD = dyn_cast(D)) { + unsigned n = 0; + + for (auto specialization : FTD->specializations()) { + if (n == i) { + return MakeCXCursor(specialization, getCursorTU(C)); + } + n++; + } + } } return clang_getNullCursor(); } CX_StmtClass clangsharp_Cursor_getStmtClass(CXCursor C) { - if (clang_isExpression(C.kind) || clang_isStatement(C.kind)) { + if (isStmtOrExpr(C.kind)) { const Stmt* S = getCursorStmt(C); return static_cast(S->getStmtClass()); } @@ -2193,10 +3918,10 @@ CX_StmtClass clangsharp_Cursor_getStmtClass(CXCursor C) { } CXString clangsharp_Cursor_getStringLiteralValue(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const StringLiteral* SL = dyn_cast(E)) { + if (const StringLiteral* SL = dyn_cast(S)) { return createDup(SL->getString()); } } @@ -2204,139 +3929,207 @@ CXString clangsharp_Cursor_getStringLiteralValue(CXCursor C) { return createEmpty(); } -CXCursor clangsharp_Cursor_getSubExpr(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); - - if (const ArrayInitLoopExpr* AILE = dyn_cast(E)) { - return MakeCXCursor(AILE->getSubExpr(), getCursorDecl(C), getCursorTU(C)); - } - - if (const CastExpr* CE = dyn_cast(E)) { - return MakeCXCursor(CE->getSubExpr(), getCursorDecl(C), getCursorTU(C)); - } +CXCursor clangsharp_Cursor_getSubDecl(CXCursor C, unsigned i) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); - if (const CXXBindTemporaryExpr* CBTE = dyn_cast(E)) { - return MakeCXCursor(CBTE->getSubExpr(), getCursorDecl(C), getCursorTU(C)); + if (const BindingDecl* BD = dyn_cast(D)) { + if (i == 0) { + return MakeCXCursor(BD->getHoldingVar(), getCursorTU(C)); + } } - if (const CXXDefaultArgExpr* CDAE = dyn_cast(E)) { - return MakeCXCursor(CDAE->getExpr(), getCursorDecl(C), getCursorTU(C)); + if (const CXXDestructorDecl* CXXDD = dyn_cast(D)) { + if (i == 0) { + return MakeCXCursor(CXXDD->getOperatorDelete(), getCursorTU(C)); + } } - if (const CXXDefaultInitExpr* CDIE = dyn_cast(E)) { - return MakeCXCursor(CDIE->getExpr(), getCursorDecl(C), getCursorTU(C)); + if (const IndirectFieldDecl* IFD = dyn_cast(D)) { + if (i == 0) { + return MakeCXCursor(IFD->getAnonField(), getCursorTU(C)); + } + else if (i == 1) { + return MakeCXCursor(IFD->getVarDecl(), getCursorTU(C)); + } } - if (const CXXDeleteExpr* CDE = dyn_cast(E)) { - return MakeCXCursor(CDE->getArgument(), getCursorDecl(C), getCursorTU(C)); + if (const LifetimeExtendedTemporaryDecl* LETD = dyn_cast(D)) { + if (i == 0) { + return MakeCXCursor(LETD->getExtendingDecl(), getCursorTU(C)); + } } - if (const CXXFoldExpr* CFE = dyn_cast(E)) { - return MakeCXCursor(CFE->getPattern(), getCursorDecl(C), getCursorTU(C)); + if (const NamespaceAliasDecl* NAD = dyn_cast(D)) { + if (i == 0) { + return MakeCXCursor(NAD->getAliasedNamespace(), getCursorTU(C)); + } + else if (i == 1) { + return MakeCXCursor(NAD->getNamespace(), getCursorTU(C)); + } } - if (const CXXNoexceptExpr* CNEE = dyn_cast(E)) { - return MakeCXCursor(CNEE->getOperand(), getCursorDecl(C), getCursorTU(C)); + if (const NamespaceDecl* ND = dyn_cast(D)) { + if (i == 0) { + return MakeCXCursor(ND->getAnonymousNamespace(), getCursorTU(C)); + } + else if (i == 1) { + return MakeCXCursor(ND->getOriginalNamespace(), getCursorTU(C)); + } } - if (const CXXStdInitializerListExpr* CSILE = dyn_cast(E)) { - return MakeCXCursor(CSILE->getSubExpr(), getCursorDecl(C), getCursorTU(C)); + if (const ObjCCategoryDecl* OCCD = dyn_cast(D)) { + if (i == 0) { + return MakeCXCursor(OCCD->getClassInterface(), getCursorTU(C)); + } + else if (i == 1) { + return MakeCXCursor(OCCD->getImplementation(), getCursorTU(C)); + } + else if (i == 2) { + return MakeCXCursor(OCCD->getNextClassCategory(), getCursorTU(C)); + } + else if (i == 3) { + return MakeCXCursor(OCCD->getNextClassCategoryRaw(), getCursorTU(C)); + } } - if (const CXXThrowExpr* CTE = dyn_cast(E)) { - return MakeCXCursor(CTE->getSubExpr(), getCursorDecl(C), getCursorTU(C)); + if (const ObjCCategoryImplDecl* OCCID = dyn_cast(D)) { + if (i == 0) { + return MakeCXCursor(OCCID->getClassInterface(), getCursorTU(C)); + } + else if (i == 1) { + return MakeCXCursor(OCCID->getCategoryDecl(), getCursorTU(C)); + } } - if (const CXXUuidofExpr* CUE = dyn_cast(E)) { - if (!CUE->isTypeOperand()) { - return MakeCXCursor(CUE->getExprOperand(), getCursorDecl(C), getCursorTU(C)); + if (const ObjCCompatibleAliasDecl* OCCAD = dyn_cast(D)) { + if (i == 0) { + return MakeCXCursor(OCCAD->getClassInterface(), getCursorTU(C)); } } - if (const FullExpr* FE = dyn_cast(E)) { - return MakeCXCursor(FE->getSubExpr(), getCursorDecl(C), getCursorTU(C)); + if (const ObjCImplDecl* OCID = dyn_cast(D)) { + if (i == 0) { + return MakeCXCursor(OCID->getClassInterface(), getCursorTU(C)); + } } - if (const InitListExpr* ILE = dyn_cast(E)) { - return MakeCXCursor(ILE->getArrayFiller(), getCursorDecl(C), getCursorTU(C)); + if (const ObjCImplementationDecl* OCID = dyn_cast(D)) { + if (i == 0) { + return MakeCXCursor(OCID->getClassInterface(), getCursorTU(C)); + } + else if (i == 1) { + return MakeCXCursor(OCID->getSuperClass(), getCursorTU(C)); + } } - if (const MemberExpr* ME = dyn_cast(E)) { - return MakeCXCursor(ME->getBase(), getCursorDecl(C), getCursorTU(C)); + if (const ObjCInterfaceDecl* OCID = dyn_cast(D)) { + if (i == 0) { + return MakeCXCursor(OCID->getCategoryListRaw(), getCursorTU(C)); + } + else if (i == 1) { + return MakeCXCursor(OCID->getImplementation(), getCursorTU(C)); + } + else if (i == 2) { + return MakeCXCursor(OCID->getSuperClass(), getCursorTU(C)); + } } - if (const OpaqueValueExpr* OVE = dyn_cast(E)) { - return MakeCXCursor(OVE->getSourceExpr(), getCursorDecl(C), getCursorTU(C)); + if (const ObjCIvarDecl* OCID = dyn_cast(D)) { + if (i == 0) { + return MakeCXCursor(OCID->getContainingInterface(), getCursorTU(C)); + } + else if (i == 1) { + return MakeCXCursor(OCID->getNextIvar(), getCursorTU(C)); + } } - if (const ParenExpr* PE = dyn_cast(E)) { - return MakeCXCursor(PE->getSubExpr(), getCursorDecl(C), getCursorTU(C)); + if (const ObjCMethodDecl* OCMD = dyn_cast(D)) { + if (i == 0) { + return MakeCXCursor(OCMD->getClassInterface(), getCursorTU(C)); + } + else if (i == 1) { + return MakeCXCursor(OCMD->getCmdDecl(), getCursorTU(C)); + } + else if (i == 2) { + return MakeCXCursor(OCMD->getSelfDecl(), getCursorTU(C)); + } } - if (const UnaryExprOrTypeTraitExpr* UETTE = dyn_cast(E)) { - if (!UETTE->isArgumentType()) { - return MakeCXCursor(UETTE->getArgumentExpr(), getCursorDecl(C), getCursorTU(C)); + if (const ObjCPropertyDecl* OCPD = dyn_cast(D)) { + if (i == 0) { + return MakeCXCursor(OCPD->getGetterMethodDecl(), getCursorTU(C)); + } + else if (i == 1) { + return MakeCXCursor(OCPD->getPropertyIvarDecl(), getCursorTU(C)); + } + else if (i == 2) { + return MakeCXCursor(OCPD->getSetterMethodDecl(), getCursorTU(C)); } } - if (const UnaryOperator* UO = dyn_cast(E)) { - return MakeCXCursor(UO->getSubExpr(), getCursorDecl(C), getCursorTU(C)); + if (const ObjCPropertyImplDecl* OCPID = dyn_cast(D)) { + if (i == 0) { + return MakeCXCursor(OCPID->getGetterMethodDecl(), getCursorTU(C)); + } + else if (i == 1) { + return MakeCXCursor(OCPID->getPropertyDecl(), getCursorTU(C)); + } + else if (i == 2) { + return MakeCXCursor(OCPID->getPropertyIvarDecl(), getCursorTU(C)); + } + else if (i == 3) { + return MakeCXCursor(OCPID->getSetterMethodDecl(), getCursorTU(C)); + } } } return clang_getNullCursor(); } -CXCursor clangsharp_Cursor_getSubStmt(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); +CXCursor clangsharp_Cursor_getSubExpr(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const StmtExpr* SE = dyn_cast(E)) { - return MakeCXCursor(SE->getSubStmt(), getCursorDecl(C), getCursorTU(C)); + if (const InitListExpr* ILE = dyn_cast(S)) { + return MakeCXCursor(ILE->getArrayFiller(), getCursorDecl(C), getCursorTU(C)); } - } - - if (clang_isStatement(C.kind)) { - const Stmt* S = getCursorStmt(C); - if (const IfStmt* IS = dyn_cast(S)) { - return MakeCXCursor(IS->getElse(), getCursorDecl(C), getCursorTU(C)); + if (const OpaqueValueExpr* OVE = dyn_cast(S)) { + return MakeCXCursor(OVE->getSourceExpr(), getCursorDecl(C), getCursorTU(C)); } - if (const IndirectGotoStmt* IGS = dyn_cast(S)) { - return MakeCXCursor(IGS->getTarget(), getCursorDecl(C), getCursorTU(C)); + if (const UnaryExprOrTypeTraitExpr* UETTE = dyn_cast(S)) { + if (!UETTE->isArgumentType()) { + return MakeCXCursor(UETTE->getArgumentExpr(), getCursorDecl(C), getCursorTU(C)); + } } - if (const LabelStmt* LS = dyn_cast(S)) { - return MakeCXCursor(LS->getSubStmt(), getCursorDecl(C), getCursorTU(C)); + if (const UnaryOperator* UO = dyn_cast(S)) { + return MakeCXCursor(UO->getSubExpr(), getCursorDecl(C), getCursorTU(C)); } + } - if (const ReturnStmt* RS = dyn_cast(S)) { - return MakeCXCursor(RS->getRetValue(), getCursorDecl(C), getCursorTU(C)); - } + return clang_getNullCursor(); +} - if (const SwitchCase* SC = dyn_cast(S)) { - return MakeCXCursor(SC->getSubStmt(), getCursorDecl(C), getCursorTU(C)); - } +CXCursor clangsharp_Cursor_getSubStmt(CXCursor C) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); if (const SwitchStmt* SS = dyn_cast(S)) { return MakeCXCursor(SS->getSwitchCaseList(), getCursorDecl(C), getCursorTU(C)); } - - if (const ValueStmt* VS = dyn_cast(S)) { - return MakeCXCursor(VS->getExprStmt(), getCursorDecl(C), getCursorTU(C)); - } } return clang_getNullCursor(); } CXCursor clangsharp_Cursor_getSubExprAsWritten(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const CastExpr* CE = dyn_cast(E)) { + if (const CastExpr* CE = dyn_cast(S)) { return MakeCXCursor(CE->getSubExprAsWritten(), getCursorDecl(C), getCursorTU(C)); } } @@ -2345,233 +4138,224 @@ CXCursor clangsharp_Cursor_getSubExprAsWritten(CXCursor C) { } CXCursor clangsharp_Cursor_getTargetUnionField(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const CastExpr* CE = dyn_cast(E)) { - return MakeCXCursor(CE->getTargetUnionField(), getCursorTU(C)); + if (const CastExpr* CE = dyn_cast(S)) { + if (CE->getCastKind() == CK_ToUnion) { + return MakeCXCursor(CE->getTargetUnionField(), getCursorTU(C)); + } } } return clang_getNullCursor(); } -bool clangsharp_Cursor_getTemplateArgumentLoc(CXCursor C, unsigned i, TemplateArgumentLoc* TAL) { - if (clang_isDeclaration(C.kind)) { +CX_TemplateArgument clangsharp_Cursor_getTemplateArgument(CXCursor C, unsigned i) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); - if (const ClassScopeFunctionSpecializationDecl* CSFSD = dyn_cast(D)) { - *TAL = (*CSFSD->getTemplateArgsAsWritten())[i]; - return true; - } - - if (const TemplateTemplateParmDecl* TTPD = dyn_cast(D)) { - *TAL = TTPD->getDefaultArgument(); - return true; + if (const ClassTemplateSpecializationDecl* CTSD = dyn_cast(D)) { + if (i < CTSD->getTemplateArgs().size()) { + const TemplateArgument* TA = &CTSD->getTemplateArgs()[i]; + return MakeCXTemplateArgument(TA, getCursorTU(C)); + } } - } - return false; -} - -bool clangsharp_Cursor_getTemplateArgument(CXCursor C, unsigned i, TemplateArgument* TA) { - if (clang_isDeclaration(C.kind)) { - const Decl* D = getCursorDecl(C); + if (const FunctionDecl* FD = dyn_cast(D)) { + const TemplateArgumentList* TAL = FD->getTemplateSpecializationArgs(); - if (const ClassTemplateSpecializationDecl* CTSD = dyn_cast(D)) { - *TA = CTSD->getTemplateArgs().get(i); - return true; + if (TAL && (i < TAL->size())) { + const TemplateArgument* TA = &(*TAL)[i]; + return MakeCXTemplateArgument(TA, getCursorTU(C)); + } } - if (const VarTemplatePartialSpecializationDecl* VTPSD = dyn_cast(D)) { - *TA = VTPSD->getTemplateArgs().get(i); - return true; + if (FunctionTemplateDecl* FTD = const_cast(dyn_cast(D))) { + if (i < FTD->getInjectedTemplateArgs().size()) { + const TemplateArgument* TA = &FTD->getInjectedTemplateArgs()[i]; + return MakeCXTemplateArgument(TA, getCursorTU(C)); + } } - if (const VarTemplateSpecializationDecl* VTSD = dyn_cast(D)) { - *TA = VTSD->getTemplateArgs().get(i); - return true; + if (const VarTemplatePartialSpecializationDecl* VTPSD = dyn_cast(D)) { + if (i < VTPSD->getTemplateArgs().size()) { + const TemplateArgument* TA = &VTPSD->getTemplateArgs()[i]; + return MakeCXTemplateArgument(TA, getCursorTU(C)); + } } } - TemplateArgumentLoc TAL; - - if (clangsharp_Cursor_getTemplateArgumentLoc(C, i, &TAL)) { - *TA = TAL.getArgument(); - return true; - } - - return false; -} + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); -CXCursor clangsharp_Cursor_getTemplateArgument(CXCursor C, unsigned i) { - if (clang_isDeclaration(C.kind)) { - const Decl* D = getCursorDecl(C); + if (const SizeOfPackExpr* SOPE = dyn_cast(S)) { + ArrayRef partialArguments = SOPE->getPartialArguments(); - if (const ClassTemplatePartialSpecializationDecl* CTPSD = dyn_cast(D)) { - return MakeCXCursor(CTPSD->getTemplateParameters()->getParam(i), getCursorTU(C)); + if (i < partialArguments.size()) { + const TemplateArgument* TA = &partialArguments[i]; + return MakeCXTemplateArgument(TA, getCursorTU(C)); + } } - if (const TemplateDecl* TD = dyn_cast(D)) { - return MakeCXCursor(TD->getTemplateParameters()->getParam(i), getCursorTU(C)); + if (const SubstNonTypeTemplateParmPackExpr* SNTTPPE = dyn_cast(S)) { + if (i == 0) { + const TemplateArgument* TA = new TemplateArgument(SNTTPPE->getArgumentPack()); + return MakeCXTemplateArgument(TA, getCursorTU(C), true); + } } } - return clang_getNullCursor(); + return MakeCXTemplateArgument(nullptr, getCursorTU(C)); } -CXCursor clangsharp_Cursor_getTemplateArgumentAsDecl(CXCursor C, unsigned i) { - TemplateArgument TA; +CX_TemplateArgumentLoc clangsharp_Cursor_getTemplateArgumentLoc(CXCursor C, unsigned i) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); - if (clangsharp_Cursor_getTemplateArgument(C, i, &TA)) { - if (TA.getKind() == TemplateArgument::ArgKind::Declaration) { - return MakeCXCursor(TA.getAsDecl(), getCursorTU(C)); + if (const ClassScopeFunctionSpecializationDecl* CSFSD = dyn_cast(D)) { + if (i < CSFSD->getTemplateArgsAsWritten()->getNumTemplateArgs()) { + const TemplateArgumentLoc* TAL = &CSFSD->getTemplateArgsAsWritten()->getTemplateArgs()[i]; + return MakeCXTemplateArgumentLoc(TAL, getCursorTU(C)); + } } - } - - return clang_getNullCursor(); -} -CXCursor clangsharp_Cursor_getTemplateArgumentAsExpr(CXCursor C, unsigned i) { - TemplateArgument TA; - - if (clangsharp_Cursor_getTemplateArgument(C, i, &TA)) { - if (TA.getKind() == TemplateArgument::ArgKind::Expression) { - return MakeCXCursor(TA.getAsExpr(), getCursorDecl(C), getCursorTU(C)); + if (const TemplateTemplateParmDecl* TTPD = dyn_cast(D)) { + if (i == 0) { + const TemplateArgumentLoc* TAL = &TTPD->getDefaultArgument(); + return MakeCXTemplateArgumentLoc(TAL, getCursorTU(C)); + } } } - return clang_getNullCursor(); -} - -int64_t clangsharp_Cursor_getTemplateArgumentAsIntegral(CXCursor C, unsigned i) { - TemplateArgument TA; + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (clangsharp_Cursor_getTemplateArgument(C, i, &TA)) { - if (TA.getKind() == TemplateArgument::ArgKind::Integral) { - return TA.getAsIntegral().getSExtValue();; + if (const CXXDependentScopeMemberExpr* CXXDSME = dyn_cast(S)) { + if (i < CXXDSME->getNumTemplateArgs()) { + const TemplateArgumentLoc* TAL = &CXXDSME->getTemplateArgs()[i]; + return MakeCXTemplateArgumentLoc(TAL, getCursorTU(C)); + } } - } - return -1; -} - -CXType clangsharp_Cursor_getTemplateArgumentAsType(CXCursor C, unsigned i) { - TemplateArgument TA; - - if (clangsharp_Cursor_getTemplateArgument(C, i, &TA)) { - if (TA.getKind() == TemplateArgument::ArgKind::Type) { - return MakeCXType(TA.getAsType(), getCursorTU(C)); + if (const DeclRefExpr* DRE = dyn_cast(S)) { + if (i < DRE->getNumTemplateArgs()) { + const TemplateArgumentLoc* TAL = &DRE->getTemplateArgs()[i]; + return MakeCXTemplateArgumentLoc(TAL, getCursorTU(C)); + } } - } - - return MakeCXType(QualType(), getCursorTU(C)); -} - -CXType clangsharp_Cursor_getTemplateArgumentIntegralType(CXCursor C, unsigned i) { - TemplateArgument TA; - if (clangsharp_Cursor_getTemplateArgument(C, i, &TA)) { - if (TA.getKind() == TemplateArgument::ArgKind::Integral) { - return MakeCXType(TA.getIntegralType(), getCursorTU(C)); + if (const DependentScopeDeclRefExpr* DSDRE = dyn_cast(S)) { + if (i < DSDRE->getNumTemplateArgs()) { + const TemplateArgumentLoc* TAL = &DSDRE->getTemplateArgs()[i]; + return MakeCXTemplateArgumentLoc(TAL, getCursorTU(C)); + } } - } - return MakeCXType(QualType(), getCursorTU(C)); -} - -CXTemplateArgumentKind clangsharp_Cursor_getTemplateArgumentKind(CXCursor C, unsigned i) { - TemplateArgument TA; + if (const MemberExpr* ME = dyn_cast(S)) { + if (i < ME->getNumTemplateArgs()) { + const TemplateArgumentLoc* TAL = &ME->getTemplateArgs()[i]; + return MakeCXTemplateArgumentLoc(TAL, getCursorTU(C)); + } + } - if (clangsharp_Cursor_getTemplateArgument(C, i, &TA)) { - return static_cast(TA.getKind() + 1); + if (const OverloadExpr* OE = dyn_cast(S)) { + if (i < OE->getNumTemplateArgs()) { + const TemplateArgumentLoc* TAL = &OE->getTemplateArgs()[i]; + return MakeCXTemplateArgumentLoc(TAL, getCursorTU(C)); + } + } } - return CXTemplateArgumentKind_Invalid; + return MakeCXTemplateArgumentLoc(nullptr, getCursorTU(C)); } -CXSourceLocation clangsharp_Cursor_getTemplateArgumentLocLocation(CXCursor C, unsigned i) { - TemplateArgumentLoc TAL; - - if (clangsharp_Cursor_getTemplateArgumentLoc(C, i, &TAL)) { - SourceLocation SLoc = TAL.getLocation(); - return translateSourceLocation(getASTUnit(getCursorTU(C))->getASTContext(), SLoc); - } - - return clang_getNullLocation(); -} +CXCursor clangsharp_Cursor_getTemplateParameter(CXCursor C, unsigned listIndex, unsigned parameterIndex) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); -CXCursor clangsharp_Cursor_getTemplateArgumentLocSourceDeclExpression(CXCursor C, unsigned i) { - TemplateArgumentLoc TAL; + if (const ClassTemplatePartialSpecializationDecl* CTPSD = dyn_cast(D)) { + if (listIndex == 0) { + TemplateParameterList* templateParameters = CTPSD->getTemplateParameters(); - if (clangsharp_Cursor_getTemplateArgumentLoc(C, i, &TAL)) { - if (TAL.getArgument().getKind() == TemplateArgument::ArgKind::Declaration) { - const Expr* E = TAL.getSourceDeclExpression(); - return MakeCXCursor(E, getCursorDecl(C), getCursorTU(C)); + if (parameterIndex < templateParameters->size()) { + return MakeCXCursor(templateParameters->getParam(parameterIndex), getCursorTU(C)); + } + } } - } - return clang_getNullCursor(); -} - -CXCursor clangsharp_Cursor_getTemplateArgumentLocSourceExpression(CXCursor C, unsigned i) { - TemplateArgumentLoc TAL; + if (const DeclaratorDecl* DD = dyn_cast(D)) { + if (listIndex < DD->getNumTemplateParameterLists()) { + TemplateParameterList* templateParameters = DD->getTemplateParameterList(listIndex); - if (clangsharp_Cursor_getTemplateArgumentLoc(C, i, &TAL)) { - if (TAL.getArgument().getKind() == TemplateArgument::ArgKind::Expression) { - const Expr* E = TAL.getSourceExpression(); - return MakeCXCursor(E, getCursorDecl(C), getCursorTU(C)); + if (parameterIndex < templateParameters->size()) { + return MakeCXCursor(templateParameters->getParam(parameterIndex), getCursorTU(C)); + } + } } - } - - - return clang_getNullCursor(); -} -CXCursor clangsharp_Cursor_getTemplateArgumentLocSourceIntegralExpression(CXCursor C, unsigned i) { - TemplateArgumentLoc TAL; + if (const FriendDecl* FD = dyn_cast(D)) { + if (listIndex < FD->getFriendTypeNumTemplateParameterLists()) { + TemplateParameterList* templateParameters = FD->getFriendTypeTemplateParameterList(listIndex); - if (clangsharp_Cursor_getTemplateArgumentLoc(C, i, &TAL)) { - if (TAL.getArgument().getKind() == TemplateArgument::ArgKind::Integral) { - const Expr* E = TAL.getSourceIntegralExpression(); - return MakeCXCursor(E, getCursorDecl(C), getCursorTU(C)); + if (parameterIndex < templateParameters->size()) { + return MakeCXCursor(templateParameters->getParam(parameterIndex), getCursorTU(C)); + } + } } - } + if (const FriendTemplateDecl* FTD = dyn_cast(D)) { + if (listIndex < FTD->getNumTemplateParameters()) { + TemplateParameterList* templateParameters = FTD->getTemplateParameterList(listIndex); - return clang_getNullCursor(); -} + if (parameterIndex < templateParameters->size()) { + return MakeCXCursor(templateParameters->getParam(parameterIndex), getCursorTU(C)); + } + } + } -CXCursor clangsharp_Cursor_getTemplateArgumentLocSourceNullPtrExpression(CXCursor C, unsigned i) { - TemplateArgumentLoc TAL; + if (const TagDecl* TD = dyn_cast(D)) { + if (listIndex < TD->getNumTemplateParameterLists()) { + TemplateParameterList* templateParameters = TD->getTemplateParameterList(listIndex); - if (clangsharp_Cursor_getTemplateArgumentLoc(C, i, &TAL)) { - if (TAL.getArgument().getKind() == TemplateArgument::ArgKind::NullPtr) { - const Expr* E = TAL.getSourceNullPtrExpression(); - return MakeCXCursor(E, getCursorDecl(C), getCursorTU(C)); + if (parameterIndex < templateParameters->size()) { + return MakeCXCursor(templateParameters->getParam(parameterIndex), getCursorTU(C)); + } + } } - } + if (const TemplateDecl* TD = dyn_cast(D)) { + if (listIndex == 0) { + TemplateParameterList* templateParameters = TD->getTemplateParameters(); - return clang_getNullCursor(); -} + if (parameterIndex < templateParameters->size()) { + return MakeCXCursor(templateParameters->getParam(parameterIndex), getCursorTU(C)); + } + } + } -CXType clangsharp_Cursor_getTemplateArgumentNullPtrType(CXCursor C, unsigned i) { - TemplateArgument TA; + if (const VarTemplatePartialSpecializationDecl* VTPSD = dyn_cast(D)) { + if (listIndex == 0) { + TemplateParameterList* templateParameters = VTPSD->getTemplateParameters(); - if (clangsharp_Cursor_getTemplateArgument(C, i, &TA)) { - if (TA.getKind() == TemplateArgument::ArgKind::NullPtr) { - return MakeCXType(TA.getIntegralType(), getCursorTU(C)); + if (parameterIndex < templateParameters->size()) { + return MakeCXCursor(templateParameters->getParam(parameterIndex), getCursorTU(C)); + } + } } } - return MakeCXType(QualType(), getCursorTU(C)); + return clang_getNullCursor(); } CXCursor clangsharp_Cursor_getTemplatedDecl(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); + if (const CXXDeductionGuideDecl* CXXDGD = dyn_cast(D)) { + return MakeCXCursor(CXXDGD->getDeducedTemplate(), getCursorTU(C)); + } + if (const TemplateDecl* TD = dyn_cast(D)) { return MakeCXCursor(TD->getTemplatedDecl(), getCursorTU(C)); } @@ -2581,7 +4365,7 @@ CXCursor clangsharp_Cursor_getTemplatedDecl(CXCursor C) { } CXCursor clangsharp_Cursor_getTemplateInstantiationPattern(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const CXXRecordDecl* CRD = dyn_cast(D)) { @@ -2601,10 +4385,10 @@ CXCursor clangsharp_Cursor_getTemplateInstantiationPattern(CXCursor C) { } CX_TemplateSpecializationKind clangsharp_Cursor_getTemplateSpecializationKind(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); - if (const CXXRecordDecl* CRD = dyn_cast(D)) { + if (const CXXRecordDecl* CRD = dyn_cast(D)) { return static_cast(CRD->getTemplateSpecializationKind() + 1); } @@ -2621,9 +4405,17 @@ CX_TemplateSpecializationKind clangsharp_Cursor_getTemplateSpecializationKind(CX } int clangsharp_Cursor_getTemplateTypeParmDepth(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); + if (const NonTypeTemplateParmDecl* NTTPD = dyn_cast(D)) { + return NTTPD->getDepth(); + } + + if (const TemplateTemplateParmDecl* TTPD = dyn_cast(D)) { + return TTPD->getDepth(); + } + if (const TemplateTypeParmDecl* TTPD = dyn_cast(D)) { return TTPD->getDepth(); } @@ -2633,9 +4425,21 @@ int clangsharp_Cursor_getTemplateTypeParmDepth(CXCursor C) { } int clangsharp_Cursor_getTemplateTypeParmIndex(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); + if (const NonTypeTemplateParmDecl* NTTPD = dyn_cast(D)) { + return NTTPD->getIndex(); + } + + if (const ObjCTypeParamDecl* OCTPD = dyn_cast(D)) { + return OCTPD->getIndex(); + } + + if (const TemplateTemplateParmDecl* TTPD = dyn_cast(D)) { + return TTPD->getIndex(); + } + if (const TemplateTypeParmDecl* TTPD = dyn_cast(D)) { return TTPD->getIndex(); } @@ -2644,8 +4448,24 @@ int clangsharp_Cursor_getTemplateTypeParmIndex(CXCursor C) { return -1; } +int clangsharp_Cursor_getTemplateTypeParmPosition(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const NonTypeTemplateParmDecl* NTTPD = dyn_cast(D)) { + return NTTPD->getPosition(); + } + + if (const TemplateTemplateParmDecl* TTPD = dyn_cast(D)) { + return TTPD->getPosition(); + } + } + + return -1; +} + CXType clangsharp_Cursor_getThisObjectType(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const CXXMethodDecl* CMD = dyn_cast(D)) { @@ -2653,23 +4473,35 @@ CXType clangsharp_Cursor_getThisObjectType(CXCursor C) { } } + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + + if (const ObjCMessageExpr* OCME = dyn_cast(S)) { + return MakeCXType(OCME->getSuperType(), getCursorTU(C)); + } + } + return MakeCXType(QualType(), getCursorTU(C)); } CXType clangsharp_Cursor_getThisType(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const CXXMethodDecl* CMD = dyn_cast(D)) { return MakeCXType(CMD->getThisType(), getCursorTU(C)); } + + if (const ObjCInterfaceDecl* OCID = dyn_cast(D)) { + return MakeCXType(QualType(OCID->getTypeForDecl(), 0), getCursorTU(C)); + } } return MakeCXType(QualType(), getCursorTU(C)); } CXCursor clangsharp_Cursor_getTrailingRequiresClause(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const DeclaratorDecl* DD = dyn_cast(D)) { @@ -2680,49 +4512,123 @@ CXCursor clangsharp_Cursor_getTrailingRequiresClause(CXCursor C) { return clang_getNullCursor(); } -CXCursor clangsharp_Cursor_getTrueExpr(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); +CXCursor clangsharp_Cursor_getTypedefNameForAnonDecl(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); - if (const AbstractConditionalOperator* ACO = dyn_cast(E)) { - return MakeCXCursor(ACO->getTrueExpr(), getCursorDecl(C), getCursorTU(C)); + if (const TagDecl* TD = dyn_cast(D)) { + return MakeCXCursor(TD->getTypedefNameForAnonDecl(), getCursorTU(C)); } } return clang_getNullCursor(); } -CXCursor clangsharp_Cursor_getTypedefNameForAnonDecl(CXCursor C) { - if (clang_isDeclaration(C.kind)) { +CXType clangsharp_Cursor_getTypeOperand(CXCursor C) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); - if (const TagDecl* TD = dyn_cast(D)) { - return MakeCXCursor(TD->getTypedefNameForAnonDecl(), getCursorTU(C)); + if (const CXXConversionDecl* CXXCD = dyn_cast(D)) { + return MakeCXType(CXXCD->getConversionType(), getCursorTU(C)); + } + + if (const FriendTemplateDecl* FTD = dyn_cast(D)) { + return MakeCXType(FTD->getFriendType()->getType(), getCursorTU(C)); + } + + if (const ObjCInterfaceDecl* OCID = dyn_cast(D)) { + return MakeCXType(QualType(OCID->getSuperClassType(), 0), getCursorTU(C)); + } + + if (const ObjCMethodDecl* OCMD = dyn_cast(D)) { + return MakeCXType(OCMD->getSendResultType(), getCursorTU(C)); } } - return clang_getNullCursor(); -} + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); -CXType clangsharp_Cursor_getTypeOperand(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); + if (const AtomicExpr* AE = dyn_cast(S)) { + return MakeCXType(AE->getValueType(), getCursorTU(C)); + } + + if (const CompoundLiteralExpr* CLE = dyn_cast(S)) { + return MakeCXType(CLE->getTypeSourceInfo()->getType(), getCursorTU(C)); + } + + if (const CXXCatchStmt* CXXCS = dyn_cast(S)) { + return MakeCXType(CXXCS->getCaughtType(), getCursorTU(C)); + } + + if (const CXXDeleteExpr* CXXDE = dyn_cast(S)) { + return MakeCXType(CXXDE->getDestroyedType(), getCursorTU(C)); + } + + if (const CXXDependentScopeMemberExpr* CXXDSME = dyn_cast(S)) { + return MakeCXType(CXXDSME->getBaseType(), getCursorTU(C)); + } + + if (const CXXScalarValueInitExpr* CXXSVIE = dyn_cast(S)) { + return MakeCXType(CXXSVIE->getTypeSourceInfo()->getType(), getCursorTU(C)); + } + + if (const CXXTemporaryObjectExpr* CXXTOE = dyn_cast(S)) { + return MakeCXType(CXXTOE->getTypeSourceInfo()->getType(), getCursorTU(C)); + } - if (const CXXUuidofExpr* CUE = dyn_cast(E)) { - if (CUE->isTypeOperand()) { - return MakeCXType(CUE->getTypeOperandSourceInfo()->getType(), getCursorTU(C)); + if (const CXXTypeidExpr* CXXTE = dyn_cast(S)) { + if (CXXTE->isTypeOperand()) { + return MakeCXType(CXXTE->getTypeOperandSourceInfo()->getType(), getCursorTU(C)); } } + + if (const CXXUnresolvedConstructExpr* CXXUCE = dyn_cast(S)) { + return MakeCXType(CXXUCE->getTypeAsWritten(), getCursorTU(C)); + } + + if (const CXXUuidofExpr* CXXUE = dyn_cast(S)) { + if (CXXUE->isTypeOperand()) { + return MakeCXType(CXXUE->getTypeOperandSourceInfo()->getType(), getCursorTU(C)); + } + } + + if (const ExplicitCastExpr* ECE = dyn_cast(S)) { + return MakeCXType(ECE->getTypeAsWritten(), getCursorTU(C)); + } + + if (const ObjCEncodeExpr* OCEE = dyn_cast(S)) { + return MakeCXType(OCEE->getEncodedType(), getCursorTU(C)); + } + + if (const ObjCMessageExpr* OCME = dyn_cast(S)) { + return MakeCXType(OCME->getClassReceiver(), getCursorTU(C)); + } + + if (const ObjCPropertyRefExpr* OCPRE = dyn_cast(S)) { + return MakeCXType(OCPRE->getSuperReceiverType(), getCursorTU(C)); + } + + if (const OffsetOfExpr* OOE = dyn_cast(S)) { + return MakeCXType(OOE->getTypeSourceInfo()->getType(), getCursorTU(C)); + } + + if (const CXXPseudoDestructorExpr* CXXPSDE = dyn_cast(S)) { + return MakeCXType(CXXPSDE->getDestroyedType(), getCursorTU(C)); + } + + if (const UnresolvedMemberExpr* UME = dyn_cast(S)) { + return MakeCXType(UME->getBaseType(), getCursorTU(C)); + } } return MakeCXType(QualType(), getCursorTU(C)); } CX_UnaryExprOrTypeTrait clangsharp_Cursor_getUnaryExprOrTypeTraitKind(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const UnaryExprOrTypeTraitExpr* UETTE = dyn_cast(E)) { + if (const UnaryExprOrTypeTraitExpr* UETTE = dyn_cast(S)) { return static_cast(UETTE->getKind() + 1); } } @@ -2731,9 +4637,9 @@ CX_UnaryExprOrTypeTrait clangsharp_Cursor_getUnaryExprOrTypeTraitKind(CXCursor C } CX_UnaryOperatorKind clangsharp_Cursor_getUnaryOpcode(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); - if (const UnaryOperator* UnOp = dyn_cast(E)) { + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); + if (const UnaryOperator* UnOp = dyn_cast(S)) { return static_cast(UnOp->getOpcode() + 1); } } @@ -2751,7 +4657,7 @@ CXString clangsharp_Cursor_getUnaryOpcodeSpelling(CX_UnaryOperatorKind Op) { } CXCursor clangsharp_Cursor_getUnderlyingDecl(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const NamedDecl* ND = dyn_cast(D)) { @@ -2763,7 +4669,7 @@ CXCursor clangsharp_Cursor_getUnderlyingDecl(CXCursor C) { } CXCursor clangsharp_Cursor_getUninstantiatedDefaultArg(CXCursor C) { - if (clang_isDeclaration(C.kind)) { + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const ParmVarDecl* PVD = dyn_cast(D)) { @@ -2775,14 +4681,14 @@ CXCursor clangsharp_Cursor_getUninstantiatedDefaultArg(CXCursor C) { } CXCursor clangsharp_Cursor_getUsedContext(CXCursor C) { - if (clang_isExpression(C.kind)) { - const Expr* E = getCursorExpr(C); + if (isStmtOrExpr(C.kind)) { + const Stmt* S = getCursorStmt(C); - if (const CXXDefaultArgExpr* CDAE = dyn_cast(E)) { + if (const CXXDefaultArgExpr* CDAE = dyn_cast(S)) { return MakeCXCursor(dyn_cast(CDAE->getUsedContext()), getCursorTU(C)); } - if (const CXXDefaultInitExpr* CDIE = dyn_cast(E)) { + if (const CXXDefaultInitExpr* CDIE = dyn_cast(S)) { return MakeCXCursor(dyn_cast(CDIE->getUsedContext()), getCursorTU(C)); } } @@ -2790,189 +4696,270 @@ CXCursor clangsharp_Cursor_getUsedContext(CXCursor C) { return clang_getNullCursor(); } -CXType clangsharp_Type_desugar(CXType CT) { - QualType T = GetQualType(CT); - const Type* TP = T.getTypePtrOrNull(); +CXCursor clangsharp_Cursor_getVBase(CXCursor C, unsigned i) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); - if (const AdjustedType* AT = dyn_cast(TP)) { - return MakeCXType(AT->desugar(), GetTypeTU(CT)); - } + if (const CXXRecordDecl* CXXRD = dyn_cast(D)) { + if (CXXRD->getDefinition()) { + unsigned n = 0; - if (const AtomicType* AT = dyn_cast(TP)) { - return MakeCXType(AT->desugar(), GetTypeTU(CT)); + for (auto& vbase : CXXRD->vbases()) { + if (n == i) { + return MakeCXCursor(&vbase, getCursorTU(C)); + } + n++; + } + } + } } - if (const AdjustedType* AT = dyn_cast(TP)) { - return MakeCXType(AT->desugar(), GetTypeTU(CT)); + return clang_getNullCursor(); +} + +int64_t clangsharp_Cursor_getVtblIdx(CXCursor C) { + if (isDeclOrTU(C.kind)) { + const Decl* D = getCursorDecl(C); + + if (const CXXMethodDecl* CMD = dyn_cast(D)) { + if (VTableContextBase::hasVtableSlot(CMD)) { + VTableContextBase* VTC = getASTUnit(getCursorTU(C))->getASTContext().getVTableContext(); + + if (MicrosoftVTableContext* MSVTC = dyn_cast(VTC)) { + MethodVFTableLocation ML = MSVTC->getMethodVFTableLocation(CMD); + return ML.Index; + } + + if (ItaniumVTableContext* IVTC = dyn_cast(VTC)) { + return IVTC->getMethodVTableIndex(CMD); + } + } + } } - if (const BlockPointerType* BPT = dyn_cast(TP)) { - return MakeCXType(BPT->desugar(), GetTypeTU(CT)); + return -1; +} + +void clangsharp_TemplateArgument_dispose(CX_TemplateArgument T) { + if (T.xdata & 1) { + return delete T.value; } +} - if (const BuiltinType* BT = dyn_cast(TP)) { - return MakeCXType(BT->desugar(), GetTypeTU(CT)); +CXCursor clangsharp_TemplateArgument_getAsDecl(CX_TemplateArgument T) { + if (T.kind == CXTemplateArgumentKind_Declaration) { + return MakeCXCursor(T.value->getAsDecl(), T.tu); } - if (const ComplexType* ComplexT = dyn_cast(TP)) { - return MakeCXType(ComplexT->desugar(), GetTypeTU(CT)); + return clang_getNullCursor(); +} + +CXCursor clangsharp_TemplateArgument_getAsExpr(CX_TemplateArgument T) { + if (T.kind == CXTemplateArgumentKind_Expression) { + return MakeCXCursor(T.value->getAsExpr(), nullptr, T.tu); } - if (const ConstantArrayType* CAT = dyn_cast(TP)) { - return MakeCXType(CAT->desugar(), GetTypeTU(CT)); + return clang_getNullCursor(); +} + +int64_t clangsharp_TemplateArgument_getAsIntegral(CX_TemplateArgument T) { + if (T.kind == CXTemplateArgumentKind_Integral) { + return T.value->getAsIntegral().getSExtValue(); } - if (const DecltypeType* DT = dyn_cast(TP)) { - return MakeCXType(DT->desugar(), GetTypeTU(CT)); + return -1; +} + +CX_TemplateName clangsharp_TemplateArgument_getAsTemplate(CX_TemplateArgument T) { + if (T.kind == CXTemplateArgumentKind_Template) { + TemplateName TN = T.value->getAsTemplate(); + return MakeCXTemplateName(TN, T.tu); } - if (const DeducedType* DT = dyn_cast(TP)) { - return MakeCXType(DT->desugar(), GetTypeTU(CT)); + return MakeCXTemplateName(TemplateName::getFromVoidPointer(nullptr), T.tu); +} + +CX_TemplateName clangsharp_TemplateArgument_getAsTemplateOrTemplatePattern(CX_TemplateArgument T) { + if ((T.kind == CXTemplateArgumentKind_Template) || (T.kind == CXTemplateArgumentKind_TemplateExpansion)) { + TemplateName TN = T.value->getAsTemplateOrTemplatePattern(); + return MakeCXTemplateName(TN, T.tu); } - if (const DependentAddressSpaceType* DAST = dyn_cast(TP)) { - return MakeCXType(DAST->desugar(), GetTypeTU(CT)); + return MakeCXTemplateName(TemplateName::getFromVoidPointer(nullptr), T.tu); +} + +CXType clangsharp_TemplateArgument_getAsType(CX_TemplateArgument T) { + if (T.kind == CXTemplateArgumentKind_Type) { + return MakeCXType(T.value->getAsType(), T.tu); } - if (const DependentExtIntType* DEIT = dyn_cast(TP)) { - return MakeCXType(DEIT->desugar(), GetTypeTU(CT)); + return MakeCXType(QualType(), T.tu); +} + +CX_TemplateArgumentDependence clangsharp_TemplateArgument_getDependence(CX_TemplateArgument T) { + if (T.value) { + return static_cast(T.value->getDependence()); } - if (const DependentNameType* DNT = dyn_cast(TP)) { - return MakeCXType(DNT->desugar(), GetTypeTU(CT)); - } + return CX_TAD_None; +} - if (const DependentSizedArrayType* DSAT = dyn_cast(TP)) { - return MakeCXType(DSAT->desugar(), GetTypeTU(CT)); +CXType clangsharp_TemplateArgument_getIntegralType(CX_TemplateArgument T) { + if (T.kind == CXTemplateArgumentKind_Integral) { + return MakeCXType(T.value->getIntegralType(), T.tu); } - if (const DependentSizedExtVectorType* DSEVT = dyn_cast(TP)) { - return MakeCXType(DSEVT->desugar(), GetTypeTU(CT)); - } + return MakeCXType(QualType(), T.tu); +} - if (const DependentTemplateSpecializationType* DTST = dyn_cast(TP)) { - return MakeCXType(DTST->desugar(), GetTypeTU(CT)); +CXType clangsharp_TemplateArgument_getNonTypeTemplateArgumentType(CX_TemplateArgument T) { + if (T.value) { + return MakeCXType(T.value->getNonTypeTemplateArgumentType(), T.tu); } - if (const DependentVectorType* DVT = dyn_cast(TP)) { - return MakeCXType(DVT->desugar(), GetTypeTU(CT)); - } + return MakeCXType(QualType(), T.tu); +} - if (const ElaboratedType* ET = dyn_cast(TP)) { - return MakeCXType(ET->desugar(), GetTypeTU(CT)); +CXType clangsharp_TemplateArgument_getNullPtrType(CX_TemplateArgument T) { + if (T.kind == CXTemplateArgumentKind_NullPtr) { + return MakeCXType(T.value->getNullPtrType(), T.tu); } - if (const EnumType* ET = dyn_cast(TP)) { - return MakeCXType(ET->desugar(), GetTypeTU(CT)); - } + return MakeCXType(QualType(), T.tu); +} - if (const ExtIntType* EIT = dyn_cast(TP)) { - return MakeCXType(EIT->desugar(), GetTypeTU(CT)); +int clangsharp_TemplateArgument_getNumPackElements(CX_TemplateArgument T) { + if (T.kind == CXTemplateArgumentKind_Pack) { + return T.value->getPackAsArray().size(); } - if (const ExtVectorType* EVT = dyn_cast(TP)) { - return MakeCXType(EVT->desugar(), GetTypeTU(CT)); - } + return -1; +} - if (const FunctionNoProtoType* FNPT = dyn_cast(TP)) { - return MakeCXType(FNPT->desugar(), GetTypeTU(CT)); - } +CX_TemplateArgument clangsharp_TemplateArgument_getPackElement(CX_TemplateArgument T, unsigned i) { + if (T.kind == CXTemplateArgumentKind_Pack) { + ArrayRef packAsArray = T.value->getPackAsArray(); - if (const FunctionProtoType* FPT = dyn_cast(TP)) { - return MakeCXType(FPT->desugar(), GetTypeTU(CT)); + if (i < packAsArray.size()) { + return MakeCXTemplateArgument(&packAsArray[i], T.tu); + } } - if (const IncompleteArrayType* IAT = dyn_cast(TP)) { - return MakeCXType(IAT->desugar(), GetTypeTU(CT)); - } + return MakeCXTemplateArgument(nullptr, T.tu); +} - if (const InjectedClassNameType* ICNT = dyn_cast(TP)) { - return MakeCXType(ICNT->desugar(), GetTypeTU(CT)); +CX_TemplateArgument clangsharp_TemplateArgument_getPackExpansionPattern(CX_TemplateArgument T) { + if (T.value->isPackExpansion()) { + const TemplateArgument* TA = new TemplateArgument(T.value->getPackExpansionPattern()); + return MakeCXTemplateArgument(TA, T.tu, true); } - if (const LValueReferenceType* LVRT = dyn_cast(TP)) { - return MakeCXType(LVRT->desugar(), GetTypeTU(CT)); - } + return MakeCXTemplateArgument(nullptr, T.tu); +} - if (const MacroQualifiedType* MQT = dyn_cast(TP)) { - return MakeCXType(MQT->desugar(), GetTypeTU(CT)); +CXType clangsharp_TemplateArgument_getParamTypeForDecl(CX_TemplateArgument T) { + if (T.kind == CXTemplateArgumentKind_Declaration) { + return MakeCXType(T.value->getParamTypeForDecl(), T.tu); } - if (const MatrixType* MT = dyn_cast(TP)) { - return MakeCXType(MT->desugar(), GetTypeTU(CT)); - } + return MakeCXType(QualType(), T.tu); +} - if (const MemberPointerType* MPT = dyn_cast(TP)) { - return MakeCXType(MPT->desugar(), GetTypeTU(CT)); +CX_TemplateArgument clangsharp_TemplateArgumentLoc_getArgument(CX_TemplateArgumentLoc T) { + if (T.value) { + const TemplateArgument* TA = &T.value->getArgument(); + return MakeCXTemplateArgument(TA, T.tu); } - if (const PackExpansionType* PET = dyn_cast(TP)) { - return MakeCXType(PET->desugar(), GetTypeTU(CT)); - } + return MakeCXTemplateArgument(nullptr, T.tu); +} - if (const ParenType* PT = dyn_cast(TP)) { - return MakeCXType(PT->desugar(), GetTypeTU(CT)); +CXSourceLocation clangsharp_TemplateArgumentLoc_getLocation(CX_TemplateArgumentLoc T) { + if (T.value) { + SourceLocation SLoc = T.value->getLocation(); + return translateSourceLocation(getASTUnit(T.tu)->getASTContext(), SLoc); } - if (const PipeType* PT = dyn_cast(TP)) { - return MakeCXType(PT->desugar(), GetTypeTU(CT)); - } + return clang_getNullLocation(); +} - if (const PointerType* PT = dyn_cast(TP)) { - return MakeCXType(PT->desugar(), GetTypeTU(CT)); +CXCursor clangsharp_TemplateArgumentLoc_getSourceDeclExpression(CX_TemplateArgumentLoc T) { + if (T.value) { + if (T.value->getArgument().getKind() == TemplateArgument::ArgKind::Declaration) { + const Expr* E = T.value->getSourceDeclExpression(); + return MakeCXCursor(E, nullptr, T.tu); + } } - if (const RecordType* RT = dyn_cast(TP)) { - return MakeCXType(RT->desugar(), GetTypeTU(CT)); - } + return clang_getNullCursor(); +} - if (const RValueReferenceType* RVRT = dyn_cast(TP)) { - return MakeCXType(RVRT->desugar(), GetTypeTU(CT)); +CXCursor clangsharp_TemplateArgumentLoc_getSourceExpression(CX_TemplateArgumentLoc T) { + if (T.value) { + if (T.value->getArgument().getKind() == TemplateArgument::ArgKind::Expression) { + const Expr* E = T.value->getSourceExpression(); + return MakeCXCursor(E, nullptr, T.tu); + } } - if (const SubstTemplateTypeParmPackType* STTPPT = dyn_cast(TP)) { - return MakeCXType(STTPPT->desugar(), GetTypeTU(CT)); - } + return clang_getNullCursor(); +} - if (const SubstTemplateTypeParmType* STTPT = dyn_cast(TP)) { - return MakeCXType(STTPT->desugar(), GetTypeTU(CT)); +CXCursor clangsharp_TemplateArgumentLoc_getSourceIntegralExpression(CX_TemplateArgumentLoc T) { + if (T.value) { + if (T.value->getArgument().getKind() == TemplateArgument::ArgKind::Integral) { + const Expr* E = T.value->getSourceIntegralExpression(); + return MakeCXCursor(E, nullptr, T.tu); + } } - if (const TemplateSpecializationType* TST = dyn_cast(TP)) { - return MakeCXType(TST->desugar(), GetTypeTU(CT)); - } + return clang_getNullCursor(); +} - if (const TemplateTypeParmType* TTPT = dyn_cast(TP)) { - return MakeCXType(TTPT->desugar(), GetTypeTU(CT)); +CXCursor clangsharp_TemplateArgumentLoc_getSourceNullPtrExpression(CX_TemplateArgumentLoc T) { + if (T.value) { + if (T.value->getArgument().getKind() == TemplateArgument::ArgKind::NullPtr) { + const Expr* E = T.value->getSourceNullPtrExpression(); + return MakeCXCursor(E, nullptr, T.tu); + } } - if (const TypedefType* TT = dyn_cast(TP)) { - return MakeCXType(TT->desugar(), GetTypeTU(CT)); - } + return clang_getNullCursor(); +} - if (const TypeOfExprType* TOET = dyn_cast(TP)) { - return MakeCXType(TOET->desugar(), GetTypeTU(CT)); +CXSourceRange clangsharp_TemplateArgumentLoc_getSourceRange(CX_TemplateArgumentLoc T) { + if (!T.value) { + return clang_getNullRange(); } - if (const TypeOfType* TOT = dyn_cast(TP)) { - return MakeCXType(TOT->desugar(), GetTypeTU(CT)); - } + SourceRange R = T.value->getSourceRange(); - if (const UnaryTransformType* UTT = dyn_cast(TP)) { - return MakeCXType(UTT->desugar(), GetTypeTU(CT)); + if (R.isInvalid()) { + return clang_getNullRange(); } - if (const UnresolvedUsingType* UUT = dyn_cast(TP)) { - return MakeCXType(UUT->desugar(), GetTypeTU(CT)); - } + return translateSourceRange(getASTUnit(T.tu)->getASTContext(), R); +} - if (const VariableArrayType* VAT = dyn_cast(TP)) { - return MakeCXType(VAT->desugar(), GetTypeTU(CT)); +CXCursor clangsharp_TemplateName_getAsTemplateDecl(CX_TemplateName T) { + if (T.value) { + TemplateName TN = TemplateName::getFromVoidPointer(const_cast(T.value)); + return MakeCXCursor(TN.getAsTemplateDecl(), T.tu); } - if (const VectorType* VT = dyn_cast(TP)) { - return MakeCXType(VT->desugar(), GetTypeTU(CT)); - } + return clang_getNullCursor(); +} + +CXType clangsharp_Type_desugar(CXType CT) { + QualType T = GetQualType(CT); + const Type* TP = T.getTypePtrOrNull(); + +#define ABSTRACT_TYPE(Class, Parent) +#define TYPE(Class, Parent) \ + if (const Class##Type* Ty = dyn_cast(TP)) { \ + return MakeCXType(Ty->desugar(), GetTypeTU(CT)); \ + } +#include "clang/AST/TypeNodes.inc" return MakeCXType(QualType(), GetTypeTU(CT)); } @@ -3049,6 +5036,18 @@ CXCursor clangsharp_Type_getDeclaration(CXType CT) { QualType T = GetQualType(CT); const Type* TP = T.getTypePtrOrNull(); + if (const ObjCInterfaceType* OCIT = dyn_cast(TP)) { + return MakeCXCursor(OCIT->getDecl(), GetTypeTU(CT)); + } + + if (const ObjCObjectType* OCOT = dyn_cast(TP)) { + return MakeCXCursor(OCOT->getInterface(), GetTypeTU(CT)); + } + + if (const ObjCTypeParamType* OCTPT = dyn_cast(TP)) { + return MakeCXCursor(OCTPT->getDecl(), GetTypeTU(CT)); + } + if (const TemplateTypeParmType* TTPT = dyn_cast(TP)) { return MakeCXCursor(TTPT->getDecl(), GetTypeTU(CT)); } @@ -3169,185 +5168,12 @@ unsigned clangsharp_Type_getIsSugared(CXType CT) { QualType T = GetQualType(CT); const Type* TP = T.getTypePtrOrNull(); - if (const AdjustedType* AT = dyn_cast(TP)) { - return AT->isSugared(); - } - - if (const AtomicType* AT = dyn_cast(TP)) { - return AT->isSugared(); - } - - if (const AttributedType* AT = dyn_cast(TP)) { - return AT->isSugared(); - } - - if (const BlockPointerType* BPT = dyn_cast(TP)) { - return BPT->isSugared(); - } - - if (const BuiltinType* BT = dyn_cast(TP)) { - return BT->isSugared(); - } - - if (const ComplexType* CT = dyn_cast(TP)) { - return CT->isSugared(); - } - - if (const ConstantArrayType* CAT = dyn_cast(TP)) { - return CAT->isSugared(); - } - - if (const DecltypeType* DT = dyn_cast(TP)) { - return DT->isSugared(); - } - - if (const DeducedType* DT = dyn_cast(TP)) { - return DT->isSugared(); - } - - if (const DependentAddressSpaceType* DAST = dyn_cast(TP)) { - return DAST->isSugared(); - } - - if (const DependentExtIntType* DEIT = dyn_cast(TP)) { - return DEIT->isSugared(); - } - - if (const DependentNameType* DNT = dyn_cast(TP)) { - return DNT->isSugared(); - } - - if (const DependentSizedArrayType* DSAT = dyn_cast(TP)) { - return DSAT->isSugared(); - } - - if (const DependentSizedExtVectorType* DSEVT = dyn_cast(TP)) { - return DSEVT->isSugared(); - } - - if (const DependentTemplateSpecializationType* DTST = dyn_cast(TP)) { - return DTST->isSugared(); - } - - if (const DependentVectorType* DVT = dyn_cast(TP)) { - return DVT->isSugared(); - } - - if (const ElaboratedType* ET = dyn_cast(TP)) { - return ET->isSugared(); - } - - if (const EnumType* ET = dyn_cast(TP)) { - return ET->isSugared(); - } - - if (const ExtIntType* EIT = dyn_cast(TP)) { - return EIT->isSugared(); - } - - if (const ExtVectorType* EVT = dyn_cast(TP)) { - return EVT->isSugared(); - } - - if (const FunctionNoProtoType* FNPT = dyn_cast(TP)) { - return FNPT->isSugared(); - } - - if (const FunctionProtoType* FPT = dyn_cast(TP)) { - return FPT->isSugared(); - } - - if (const IncompleteArrayType* IAT = dyn_cast(TP)) { - return IAT->isSugared(); - } - - if (const InjectedClassNameType* ICNT = dyn_cast(TP)) { - return ICNT->isSugared(); - } - - if (const LValueReferenceType* LVRT = dyn_cast(TP)) { - return LVRT->isSugared(); - } - - if (const MacroQualifiedType* MQT = dyn_cast(TP)) { - return MQT->isSugared(); - } - - if (const MatrixType* MT = dyn_cast(TP)) { - return MT->isSugared(); - } - - if (const MemberPointerType* MPT = dyn_cast(TP)) { - return MPT->isSugared(); - } - - if (const PackExpansionType* PET = dyn_cast(TP)) { - return PET->isSugared(); - } - - if (const ParenType* PT = dyn_cast(TP)) { - return PT->isSugared(); - } - - if (const PipeType* PT = dyn_cast(TP)) { - return PT->isSugared(); - } - - if (const PointerType* PT = dyn_cast(TP)) { - return PT->isSugared(); - } - - if (const RecordType* RT = dyn_cast(TP)) { - return RT->isSugared(); - } - - if (const RValueReferenceType* RVRT = dyn_cast(TP)) { - return RVRT->isSugared(); - } - - if (const SubstTemplateTypeParmPackType* STTPPT = dyn_cast(TP)) { - return STTPPT->isSugared(); - } - - if (const SubstTemplateTypeParmType* STTPT = dyn_cast(TP)) { - return STTPT->isSugared(); - } - - if (const TemplateSpecializationType* TST = dyn_cast(TP)) { - return TST->isSugared(); - } - - if (const TemplateTypeParmType* TTPT = dyn_cast(TP)) { - return TTPT->isSugared(); - } - - if (const TypedefType* TT = dyn_cast(TP)) { - return TT->isSugared(); - } - - if (const TypeOfExprType* TOET = dyn_cast(TP)) { - return TOET->isSugared(); - } - - if (const TypeOfType* TOT = dyn_cast(TP)) { - return TOT->isSugared(); - } - - if (const UnaryTransformType* UTT = dyn_cast(TP)) { - return UTT->isSugared(); - } - - if (const UnresolvedUsingType* UUT = dyn_cast(TP)) { - return UUT->isSugared(); - } - - if (const VariableArrayType* VAT = dyn_cast(TP)) { - return VAT->isSugared(); - } - - if (const VectorType* VT = dyn_cast(TP)) { - return VT->isSugared(); - } +#define ABSTRACT_TYPE(Class, Parent) +#define TYPE(Class, Parent) \ + if (const Class##Type* Ty = dyn_cast(TP)) { \ + return Ty->isSugared(); \ + } +#include "clang/AST/TypeNodes.inc" return 0; } @@ -3456,6 +5282,22 @@ CXType clangsharp_Type_getOriginalType(CXType CT) { return MakeCXType(AT->getOriginalType(), GetTypeTU(CT)); } + if (const ObjCObjectPointerType* OCOPT = dyn_cast(TP)) { + return MakeCXType(QualType(OCOPT->getInterfaceType(), 0), GetTypeTU(CT)); + } + + if (const PackExpansionType* PET = dyn_cast(TP)) { + return MakeCXType(PET->getPattern(), GetTypeTU(CT)); + } + + if (const SubstTemplateTypeParmPackType* STTPPT = dyn_cast(TP)) { + return MakeCXType(QualType(STTPPT->getReplacedParameter(), 0), GetTypeTU(CT)); + } + + if (const SubstTemplateTypeParmType* STTPT = dyn_cast(TP)) { + return MakeCXType(QualType(STTPT->getReplacedParameter(), 0), GetTypeTU(CT)); + } + return MakeCXType(QualType(), GetTypeTU(CT)); } @@ -3474,12 +5316,8 @@ CXType clangsharp_Type_getPointeeType(CXType CT) { QualType T = GetQualType(CT); const Type* TP = T.getTypePtrOrNull(); - if (const DecayedType* DT = dyn_cast(TP)) { - return MakeCXType(DT->getPointeeType(), GetTypeTU(CT)); - } - - if (const DependentAddressSpaceType* DAST = dyn_cast(TP)) { - return MakeCXType(DAST->getPointeeType(), GetTypeTU(CT)); + if (TP) { + return MakeCXType(TP->getPointeeType(), GetTypeTU(CT)); } return clang_getPointeeType(CT); @@ -3529,109 +5367,58 @@ CXCursor clangsharp_Type_getSizeExpr(CXType CT) { return clang_getNullCursor(); } -bool clangsharp_Type_getTemplateArgument(CXType CT, unsigned i, TemplateArgument* TA) { +CX_TemplateArgument clangsharp_Type_getTemplateArgument(CXType CT, unsigned i) { QualType T = GetQualType(CT); const Type* TP = T.getTypePtrOrNull(); if (const AutoType* AT = dyn_cast(TP)) { - *TA = AT->getArg(i); - return true; - } - - if (const DependentTemplateSpecializationType* DTST = dyn_cast(TP)) { - *TA = DTST->getArg(i); - return true; - } - - if (const TemplateSpecializationType* TST = dyn_cast(TP)) { - *TA = TST->getArg(i); - return true; - } - - return false; -} - -CXCursor clangsharp_Type_getTemplateArgumentAsDecl(CXType CT, unsigned i) { - TemplateArgument TA; - - if (clangsharp_Type_getTemplateArgument(CT, i, &TA)) { - if (TA.getKind() == TemplateArgument::ArgKind::Declaration) { - return MakeCXCursor(TA.getAsDecl(), GetTypeTU(CT)); + if (i < AT->getNumArgs()) { + return MakeCXTemplateArgument(&AT->getArg(i), GetTypeTU(CT)); } } - return clang_getNullCursor(); -} - -CXCursor clangsharp_Type_getTemplateArgumentAsExpr(CXType CT, unsigned i) { - TemplateArgument TA; - - if (clangsharp_Type_getTemplateArgument(CT, i, &TA)) { - if (TA.getKind() == TemplateArgument::ArgKind::Expression) { - CXCursor C = clang_getTypeDeclaration(CT); - return MakeCXCursor(TA.getAsExpr(), getCursorDecl(C), GetTypeTU(CT)); + if (const DependentTemplateSpecializationType* DTST = dyn_cast(TP)) { + if (i < DTST->getNumArgs()) { + return MakeCXTemplateArgument(&DTST->getArg(i), GetTypeTU(CT)); } } - return clang_getNullCursor(); -} - -int64_t clangsharp_Type_getTemplateArgumentAsIntegral(CXType CT, unsigned i) { - TemplateArgument TA; - - if (clangsharp_Type_getTemplateArgument(CT, i, &TA)) { - if (TA.getKind() == TemplateArgument::ArgKind::Integral) { - return TA.getAsIntegral().getSExtValue(); + if (const SubstTemplateTypeParmPackType* STTPPT = dyn_cast(TP)) { + if (i == 0) { + const TemplateArgument* TA = new TemplateArgument(STTPPT->getArgumentPack()); + return MakeCXTemplateArgument(TA, GetTypeTU(CT), true); } } - return -1; -} - -CXType clangsharp_Type_getTemplateArgumentAsType(CXType CT, unsigned i) { - TemplateArgument TA; - - if (clangsharp_Type_getTemplateArgument(CT, i, &TA)) { - if (TA.getKind() == TemplateArgument::ArgKind::Type) { - return MakeCXType(TA.getAsType(), GetTypeTU(CT)); + if (const TemplateSpecializationType* TST = dyn_cast(TP)) { + if (i < TST->getNumArgs()) { + return MakeCXTemplateArgument(&TST->getArg(i), GetTypeTU(CT)); } } - return MakeCXType(QualType(), GetTypeTU(CT)); + return MakeCXTemplateArgument(nullptr, GetTypeTU(CT)); } -CXType clangsharp_Type_getTemplateArgumentIntegralType(CXType CT, unsigned i) { - TemplateArgument TA; +CX_TemplateName clangsharp_Type_getTemplateName(CXType CT) { + QualType T = GetQualType(CT); + const Type* TP = T.getTypePtrOrNull(); - if (clangsharp_Type_getTemplateArgument(CT, i, &TA)) { - if (TA.getKind() == TemplateArgument::ArgKind::Type) { - return MakeCXType(TA.getIntegralType(), GetTypeTU(CT)); - } + if (const DeducedTemplateSpecializationType* DTST = dyn_cast(TP)) { + TemplateName TN = DTST->getTemplateName(); + return { static_cast(TN.getKind() + 1), TN.getAsVoidPointer() }; } - return MakeCXType(QualType(), GetTypeTU(CT)); -} - -CXTemplateArgumentKind clangsharp_Type_getTemplateArgumentKind(CXType CT, unsigned i) { - TemplateArgument TA; - - if (clangsharp_Type_getTemplateArgument(CT, i, &TA)) { - return static_cast(TA.getKind() + 1); + if (const InjectedClassNameType* ICNT = dyn_cast(TP)) { + TemplateName TN = ICNT->getTemplateName(); + return { static_cast(TN.getKind() + 1), TN.getAsVoidPointer() }; } - return CXTemplateArgumentKind_Invalid; -} - -CXType clangsharp_Type_getTemplateArgumentNullPtrType(CXType CT, unsigned i) { - TemplateArgument TA; - - if (clangsharp_Type_getTemplateArgument(CT, i, &TA)) { - if (TA.getKind() == TemplateArgument::ArgKind::NullPtr) { - return MakeCXType(TA.getNullPtrType(), GetTypeTU(CT)); - } + if (const TemplateSpecializationType* TST = dyn_cast(TP)) { + TemplateName TN = TST->getTemplateName(); + return { static_cast(TN.getKind() + 1), TN.getAsVoidPointer() }; } - return MakeCXType(QualType(), GetTypeTU(CT)); + return { }; } CX_TypeClass clangsharp_Type_getTypeClass(CXType CT) { @@ -3674,6 +5461,14 @@ CXType clangsharp_Type_getUnderlyingType(CXType CT) { return MakeCXType(MQT->getUnderlyingType(), GetTypeTU(CT)); } + if (const ObjCObjectPointerType* OCOPT = dyn_cast(TP)) { + return MakeCXType(OCOPT->getSuperClassType(), GetTypeTU(CT)); + } + + if (const ObjCObjectType* OCOT = dyn_cast(TP)) { + return MakeCXType(OCOT->getSuperClassType(), GetTypeTU(CT)); + } + if (const TypeOfType* TOT = dyn_cast(TP)) { return MakeCXType(TOT->getUnderlyingType(), GetTypeTU(CT)); } diff --git a/sources/libClangSharp/ClangSharp.h b/sources/libClangSharp/ClangSharp.h index 7ec4054b..6b280747 100644 --- a/sources/libClangSharp/ClangSharp.h +++ b/sources/libClangSharp/ClangSharp.h @@ -3,11 +3,24 @@ #ifndef LIBCLANGSHARP_CLANGSHARP_H #define LIBCLANGSHARP_CLANGSHARP_H +#pragma warning(push) +#pragma warning(disable : 4146 4244 4267 4291 4624 4996) + +#include #include +#include #include +#include +#include +#include +#include +#include +#include #include #include +#pragma warning(pop) + #ifdef __cplusplus #define EXTERN_C extern "C" #else @@ -23,6 +36,13 @@ #define CLANGSHARP_LINKAGE EXTERN_C #endif +enum CX_AtomicOperatorKind { + CX_AO_Invalid, +#define BUILTIN(ID, TYPE, ATTRS) +#define ATOMIC_BUILTIN(ID, TYPE, ATTRS) CX_AO##ID, +#include +}; + enum CX_AttrKind { CX_AttrKind_Invalid, #define ATTR(X) CX_AttrKind_##X, @@ -36,6 +56,13 @@ enum CX_BinaryOperatorKind { #include }; +enum CX_CapturedRegionKind { + CX_CR_Invalid, + CX_CR_Default = clang::CR_Default + 1, + CX_CR_ObjCAtFinally = clang::CR_ObjCAtFinally + 1, + CX_CR_OpenMP = clang::CR_OpenMP + 1, +}; + enum CX_CastKind { CX_CK_Invalid, #define CAST_OPERATION(Name) CX_CK_##Name, @@ -51,6 +78,14 @@ enum CX_CharacterKind { CX_CLK_UTF32 = clang::CharacterLiteral::UTF32 + 1, }; +enum CX_ConstructionKind { + _CX_CK_Invalid, + CX_CK_Complete = clang::CXXConstructExpr::CK_Complete + 1, + CX_CK_NonVirtualBase = clang::CXXConstructExpr::CK_NonVirtualBase + 1, + CX_CK_VirtualBase = clang::CXXConstructExpr::CK_VirtualBase + 1, + CX_CK_Delegating = clang::CXXConstructExpr::CK_Delegating + 1 +}; + enum CX_DeclKind { CX_DeclKind_Invalid, #define DECL(DERIVED, BASE) CX_DeclKind_##DERIVED, @@ -60,6 +95,21 @@ enum CX_DeclKind { #include }; +enum CX_ExprDependence { + CX_ED_None = clang::ExprDependenceScope::None, + CX_ED_UnexpandedPack = clang::ExprDependenceScope::UnexpandedPack, + CX_ED_Instantiation = clang::ExprDependenceScope::Instantiation, + CX_ED_Type = clang::ExprDependenceScope::Type, + CX_ED_Value = clang::ExprDependenceScope::Value, + CX_ED_Error = clang::ExprDependenceScope::Error, + CX_ED_All = clang::ExprDependenceScope::All, + + CX_ED_TypeValue = clang::ExprDependenceScope::TypeValue, + CX_ED_TypeInstantiation = clang::ExprDependenceScope::TypeInstantiation, + CX_ED_ValueInstantiation = clang::ExprDependenceScope::ValueInstantiation, + CX_ED_TypeValueInstantiation = clang::ExprDependenceScope::TypeValueInstantiation, +}; + enum CX_FloatingSemantics { CX_FLK_Invalid, CX_FLK_IEEEhalf = llvm::APFloatBase::S_IEEEhalf + 1, @@ -71,17 +121,15 @@ enum CX_FloatingSemantics { CX_FLK_PPCDoubleDouble = llvm::APFloatBase::S_PPCDoubleDouble + 1, }; -enum CX_TemplateSpecializationKind { - CX_TSK_Invalid, - CX_TSK_Undeclared = clang::TSK_Undeclared + 1, - CX_TSK_ImplicitInstantiation = clang::TSK_ImplicitInstantiation + 1, - CX_TSK_ExplicitSpecialization = clang::TSK_ExplicitSpecialization + 1, - CX_TSK_ExplicitInstantiationDeclaration = clang::TSK_ExplicitInstantiationDeclaration + 1, - CX_TSK_ExplicitInstantiationDefinition = clang::TSK_ExplicitInstantiationDefinition + 1, +enum CX_OverloadedOperatorKind { + CX_OO_Invalid = clang::OO_None, +#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ + CX_OO_##Name = clang::OO_##Name, +#include "clang/Basic/OperatorKinds.def" }; enum CX_StmtClass { - CX_StmtClass_Invalid, + CX_StmtClass_Invalid = clang::Stmt::NoStmtClass, #define STMT(CLASS, PARENT) CX_StmtClass_##CLASS, #define STMT_RANGE(BASE, FIRST, LAST) CX_StmtClass_First##BASE = CX_StmtClass_##FIRST, CX_StmtClass_Last##BASE = CX_StmtClass_##LAST, #define LAST_STMT_RANGE(BASE, FIRST, LAST) CX_StmtClass_First##BASE = CX_StmtClass_##FIRST, CX_StmtClass_Last##BASE = CX_StmtClass_##LAST @@ -89,6 +137,36 @@ enum CX_StmtClass { #include }; +enum CX_TemplateArgumentDependence { + CX_TAD_None = clang::TemplateArgumentDependenceScope::None, + CX_TAD_UnexpandedPack = clang::TemplateArgumentDependenceScope::UnexpandedPack, + CX_TAD_Instantiation = clang::TemplateArgumentDependenceScope::Instantiation, + CX_TAD_Dependent = clang::TemplateArgumentDependenceScope::Dependent, + CX_TAD_Error = clang::TemplateArgumentDependenceScope::Error, + CX_TAD_DependentInstantiation = clang::TemplateArgumentDependenceScope::DependentInstantiation, + CX_TAD_All = clang::TemplateArgumentDependenceScope::All +}; + +enum CX_TemplateNameKind { + CX_TNK_Invalid, + CX_TNK_Template = clang::TemplateName::Template + 1, + CX_TNK_OverloadedTemplate = clang::TemplateName::OverloadedTemplate + 1, + CX_TNK_AssumedTemplate = clang::TemplateName::AssumedTemplate + 1, + CX_TNK_QualifiedTemplate = clang::TemplateName::QualifiedTemplate + 1, + CX_TNK_DependentTemplate = clang::TemplateName::DependentTemplate + 1, + CX_TNK_SubstTemplateTemplateParm = clang::TemplateName::SubstTemplateTemplateParm + 1, + CX_TNK_SubstTemplateTemplateParmPack = clang::TemplateName::SubstTemplateTemplateParmPack + 1 +}; + +enum CX_TemplateSpecializationKind { + CX_TSK_Invalid, + CX_TSK_Undeclared = clang::TSK_Undeclared + 1, + CX_TSK_ImplicitInstantiation = clang::TSK_ImplicitInstantiation + 1, + CX_TSK_ExplicitSpecialization = clang::TSK_ExplicitSpecialization + 1, + CX_TSK_ExplicitInstantiationDeclaration = clang::TSK_ExplicitInstantiationDeclaration + 1, + CX_TSK_ExplicitInstantiationDefinition = clang::TSK_ExplicitInstantiationDefinition + 1, +}; + enum CX_TypeClass { CX_TypeClass_Invalid, #define TYPE(Class, Base) CX_TypeClass_##Class, @@ -115,6 +193,32 @@ enum CX_UnaryOperatorKind { #include }; +enum CX_VariableCaptureKind { + CX_VCK_Invalid, + CX_VCK_This = clang::CapturedStmt::VCK_This + 1, + CX_VCK_ByRef = clang::CapturedStmt::VCK_ByRef + 1, + CX_VCK_ByCopy = clang::CapturedStmt::VCK_ByCopy + 1, + CX_VCK_VLAType = clang::CapturedStmt::VCK_VLAType + 1 +}; + +struct CX_TemplateArgument { + CXTemplateArgumentKind kind; + int xdata; + const clang::TemplateArgument* value; + CXTranslationUnit tu; +}; + +struct CX_TemplateArgumentLoc { + const clang::TemplateArgumentLoc* value; + CXTranslationUnit tu; +}; + +struct CX_TemplateName { + CX_TemplateNameKind kind; + const void* value; + CXTranslationUnit tu; +}; + CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getArgument(CXCursor C, unsigned i); CLANGSHARP_LINKAGE CXType clangsharp_Cursor_getArgumentType(CXCursor C); @@ -125,15 +229,21 @@ CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getAssociatedConstraint(CXCursor C CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getAsFunction(CXCursor C); +CLANGSHARP_LINKAGE CX_AtomicOperatorKind clangsharp_Cursor_getAtomicOpcode(CXCursor C); + +CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getAttr(CXCursor C, unsigned i); + CLANGSHARP_LINKAGE CX_AttrKind clangsharp_Cursor_getAttrKind(CXCursor C); -CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getBaseExpr(CXCursor C); +CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getBase(CXCursor C, unsigned i); CLANGSHARP_LINKAGE CX_BinaryOperatorKind clangsharp_Cursor_getBinaryOpcode(CXCursor C); CLANGSHARP_LINKAGE CXString clangsharp_Cursor_getBinaryOpcodeSpelling(CX_BinaryOperatorKind Op); -CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getBinding(CXCursor C); +CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getBindingDecl(CXCursor C, unsigned i); + +CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getBindingExpr(CXCursor C); CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getBitWidth(CXCursor C); @@ -145,14 +255,18 @@ CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getBlockMissingReturnType(CXCursor CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getBody(CXCursor C); -CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getCalleeExpr(CXCursor C); - CLANGSHARP_LINKAGE CXType clangsharp_Cursor_getCallResultType(CXCursor C); CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getCanAvoidCopyToHeap(CXCursor C); +CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getCanonical(CXCursor C); + CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getCaptureCopyExpr(CXCursor C, unsigned i); +CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getCapturedVar(CXCursor C, unsigned i); + +CLANGSHARP_LINKAGE CX_VariableCaptureKind clangsharp_Cursor_getCaptureKind(CXCursor C, unsigned i); + CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getCaptureHasCopyExpr(CXCursor C, unsigned i); CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getCaptureIsByRef(CXCursor C, unsigned i); @@ -163,6 +277,14 @@ CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getCaptureIsNested(CXCursor C, uns CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getCaptureIsNonEscapingByRef(CXCursor C, unsigned i); +CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getCapturedDecl(CXCursor C); + +CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getCapturedRecordDecl(CXCursor C); + +CLANGSHARP_LINKAGE CX_CapturedRegionKind clangsharp_Cursor_getCapturedRegionKind(CXCursor C); + +CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getCapturedStmt(CXCursor C); + CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getCapturesCXXThis(CXCursor C); CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getCapturesVariable(CXCursor C, CXCursor V); @@ -175,36 +297,34 @@ CLANGSHARP_LINKAGE CX_CharacterKind clangsharp_Cursor_getCharacterLiteralKind(CX CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getCharacterLiteralValue(CXCursor C); -CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getColumnIdxExpr(CXCursor C); - -CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getCommonExpr(CXCursor C); +CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getChild(CXCursor C, unsigned i); CLANGSHARP_LINKAGE CXType clangsharp_Cursor_getComputationLhsType(CXCursor C); CLANGSHARP_LINKAGE CXType clangsharp_Cursor_getComputationResultType(CXCursor C); -CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getCondExpr(CXCursor C); - -CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getConditionVariableDeclStmt(CXCursor C); - CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getConstraintExpr(CXCursor C); CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getConstructedBaseClass(CXCursor C); CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getConstructedBaseClassShadowDecl(CXCursor C); +CLANGSHARP_LINKAGE CX_ConstructionKind clangsharp_Cursor_getConstructionKind(CXCursor C); + CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getConstructsVirtualBase(CXCursor C); CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getContextParam(CXCursor C); CLANGSHARP_LINKAGE int clangsharp_Cursor_getContextParamPosition(CXCursor C); -CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getConversionFunction(CXCursor C); +CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getCtor(CXCursor C, unsigned i); -CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getCXXBoolLiteralExprValue(CXCursor C); +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getBoolLiteralValue(CXCursor C); CLANGSHARP_LINKAGE CXType clangsharp_Cursor_getDeclaredReturnType(CXCursor C); +CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getDecl(CXCursor C, unsigned i); + CLANGSHARP_LINKAGE CX_DeclKind clangsharp_Cursor_getDeclKind(CXCursor C); CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getDecomposedDecl(CXCursor C); @@ -213,23 +333,29 @@ CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getDefaultArg(CXCursor C); CLANGSHARP_LINKAGE CXType clangsharp_Cursor_getDefaultArgType(CXCursor C); +CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getDefinition(CXCursor C); + CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getDependentLambdaCallOperator(CXCursor C); -CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getDescribedClassTemplate(CXCursor C); +CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getDescribedCursorTemplate(CXCursor C); CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getDescribedTemplate(CXCursor C); CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getDestructor(CXCursor C); -CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getDirectCallee(CXCursor C); - CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getDoesNotEscape(CXCursor C); +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getDoesUsualArrayDeleteWantSize(CXCursor C); + CLANGSHARP_LINKAGE CXType clangsharp_Cursor_getEnumDeclPromotionType(CXCursor C); +CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getEnumerator(CXCursor C, unsigned i); + +CLANGSHARP_LINKAGE CXType clangsharp_Cursor_getExpansionType(CXCursor C, unsigned i); + CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getExpr(CXCursor C, unsigned i); -CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getFalseExpr(CXCursor C); +CLANGSHARP_LINKAGE CX_ExprDependence clangsharp_Cursor_getExprDependence(CXCursor C); CLANGSHARP_LINKAGE int clangsharp_Cursor_getFieldIndex(CXCursor C); @@ -237,20 +363,28 @@ CLANGSHARP_LINKAGE CX_FloatingSemantics clangsharp_Cursor_getFloatingLiteralSema CLANGSHARP_LINKAGE double clangsharp_Cursor_getFloatingLiteralValueAsApproximateDouble(CXCursor C); +CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getFoundDecl(CXCursor C); + +CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getField(CXCursor C, unsigned i); + +CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getFriend(CXCursor C, unsigned i); + CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getFriendDecl(CXCursor C); CLANGSHARP_LINKAGE int clangsharp_Cursor_getFunctionScopeDepth(CXCursor C); CLANGSHARP_LINKAGE int clangsharp_Cursor_getFunctionScopeIndex(CXCursor C); -CLANGSHARP_LINKAGE CXType clangsharp_Cursor_getFunctionType(CXCursor C); - CLANGSHARP_LINKAGE clang::MSGuidDeclParts clangsharp_Cursor_getGuidValue(CXCursor C); +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getHadMultipleCandidates(CXCursor C); + CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getHasBody(CXCursor C); CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getHasDefaultArg(CXCursor C); +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getHasElseStorage(CXCursor C); + CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getHasExplicitTemplateArgs(CXCursor C); CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getHasExternalStorage(CXCursor C); @@ -263,41 +397,107 @@ CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getHasInheritedDefaultArg(CXCursor CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getHasInit(CXCursor C); +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getHasInitStorage(CXCursor C); + +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getHasLeadingEmptyMacro(CXCursor C); + CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getHasLocalStorage(CXCursor C); CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getHasPlaceholderTypeConstraint(CXCursor C); -CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getHoldingVar(CXCursor C); +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getHasTemplateKeyword(CXCursor C); + +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getHasUserDeclaredConstructor(CXCursor C); + +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getHasUserDeclaredCopyAssignment(CXCursor C); + +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getHasUserDeclaredCopyConstructor(CXCursor C); + +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getHasUserDeclaredDestructor(CXCursor C); + +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getHasUserDeclaredMoveAssignment(CXCursor C); -CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getIdxExpr(CXCursor C); +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getHasUserDeclaredMoveConstructor(CXCursor C); -CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getIncExpr(CXCursor C); +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getHasUserDeclaredMoveOperation(CXCursor C); + +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getHasVarStorage(CXCursor C); + +CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getHoldingVar(CXCursor C); CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getInClassInitializer(CXCursor C); +CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getInheritedConstructor(CXCursor C); + +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getInheritedFromVBase(CXCursor C); + CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getInitExpr(CXCursor C); +CLANGSHARP_LINKAGE CXType clangsharp_Cursor_getInjectedSpecializationType(CXCursor C); + CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getInstantiatedFromMember(CXCursor C); CLANGSHARP_LINKAGE int64_t clangsharp_Cursor_getIntegerLiteralValue(CXCursor C); +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsAllEnumCasesCovered(CXCursor C); + +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsAlwaysNull(CXCursor C); + CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsAnonymousStructOrUnion(CXCursor C); CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsArgumentType(CXCursor C); +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsArrayForm(CXCursor C); + +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsArrayFormAsWritten(CXCursor C); + +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsArrow(CXCursor C); + +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsClassExtension(CXCursor C); + +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsCompleteDefinition(CXCursor C); + +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsConditionTrue(CXCursor C); + +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsConstexpr(CXCursor C); + CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsConversionFromLambda(CXCursor C); +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsCopyOrMoveConstructor(CXCursor C); + +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsCXXTry(CXCursor C); + CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsDefined(CXCursor C); +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsDelegatingConstructor(CXCursor C); + +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsDeleted(CXCursor C); + CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsDeprecated(CXCursor C); +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsElidable(CXCursor C); + CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsExpandedParameterPack(CXCursor C); +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsExplicitlyDefaulted(CXCursor C); + CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsExternC(CXCursor C); +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsFileScope(CXCursor C); + CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsGlobal(CXCursor C); -CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsImplicitAccess(CXCursor C); +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsInjectedClassName(CXCursor C); + +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsIfExists(CXCursor C); + +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsImplicit(CXCursor C); + +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsIncomplete(CXCursor C); + +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsInheritingConstructor(CXCursor C); + +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsListInitialization(CXCursor C); CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsLocalVarDecl(CXCursor C); @@ -319,34 +519,48 @@ CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsPackExpansion(CXCursor C); CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsParameterPack(CXCursor C); +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsPartiallySubstituted(CXCursor C); + +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsPotentiallyEvaluated(CXCursor C); + CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsPure(CXCursor C); +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsResultDependent(CXCursor C); + +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsReversed(CXCursor C); + CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsSigned(CXCursor C); CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsStatic(CXCursor C); CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsStaticDataMember(CXCursor C); +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsStdInitListInitialization(CXCursor C); + CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsStrictlyPositive(CXCursor C); CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsTemplated(CXCursor C); CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsThisDeclarationADefinition(CXCursor C); -CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsTransparentTag(CXCursor C); +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsThrownVariableInScope(CXCursor C); -CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsTypeConcept(CXCursor C); +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsTransparent(CXCursor C); -CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsTypeOperand(CXCursor C); +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsTypeConcept(CXCursor C); CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsUnavailable(CXCursor C); +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsUnconditionallyVisible(CXCursor C); + CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsUnnamedBitfield(CXCursor C); CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsUnsigned(CXCursor C); CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsUnsupportedFriend(CXCursor C); +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsUserProvided(CXCursor C); + CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getIsVariadic(CXCursor C); CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getLambdaCallOperator(CXCursor C); @@ -359,9 +573,11 @@ CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getLhsExpr(CXCursor C); CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getMaxAlignment(CXCursor C); +CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getMethod(CXCursor C, unsigned i); + CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getMostRecentDecl(CXCursor C); -CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getMostRecentNonInjectedDecl(CXCursor C); +CLANGSHARP_LINKAGE CXString clangsharp_Cursor_getName(CXCursor C); CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getNextDeclInContext(CXCursor C); @@ -373,22 +589,58 @@ CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getNominatedBaseClassShadowDecl(CX CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getNonClosureContext(CXCursor C); +CLANGSHARP_LINKAGE int clangsharp_Cursor_getNumArguments(CXCursor C); + +CLANGSHARP_LINKAGE int clangsharp_Cursor_getNumAssocs(CXCursor C); + CLANGSHARP_LINKAGE int clangsharp_Cursor_getNumAssociatedConstraints(CXCursor C); -CLANGSHARP_LINKAGE int clangsharp_Cursor_getNumArguments(CXCursor C); +CLANGSHARP_LINKAGE int clangsharp_Cursor_getNumAttrs(CXCursor C); + +CLANGSHARP_LINKAGE int clangsharp_Cursor_getNumBases(CXCursor C); + +CLANGSHARP_LINKAGE int clangsharp_Cursor_getNumBindings(CXCursor C); CLANGSHARP_LINKAGE int clangsharp_Cursor_getNumCaptures(CXCursor C); +CLANGSHARP_LINKAGE int clangsharp_Cursor_getNumChildren(CXCursor C); + +CLANGSHARP_LINKAGE int clangsharp_Cursor_getNumCtors(CXCursor C); + +CLANGSHARP_LINKAGE int clangsharp_Cursor_getNumDecls(CXCursor C); + +CLANGSHARP_LINKAGE int clangsharp_Cursor_getNumEnumerators(CXCursor C); + +CLANGSHARP_LINKAGE int clangsharp_Cursor_getNumExpansionTypes(CXCursor C); + CLANGSHARP_LINKAGE int clangsharp_Cursor_getNumExprs(CXCursor C); +CLANGSHARP_LINKAGE int clangsharp_Cursor_getNumFields(CXCursor C); + +CLANGSHARP_LINKAGE int clangsharp_Cursor_getNumFriends(CXCursor C); + +CLANGSHARP_LINKAGE int clangsharp_Cursor_getNumMethods(CXCursor C); + +CLANGSHARP_LINKAGE int clangsharp_Cursor_getNumProtocols(CXCursor C); + CLANGSHARP_LINKAGE int clangsharp_Cursor_getNumSpecializations(CXCursor C); CLANGSHARP_LINKAGE int clangsharp_Cursor_getNumTemplateArguments(CXCursor C); -CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getOpaqueValueExpr(CXCursor C); +CLANGSHARP_LINKAGE int clangsharp_Cursor_getNumTemplateParameters(CXCursor C, unsigned listIndex); + +CLANGSHARP_LINKAGE int clangsharp_Cursor_getNumTemplateParameterLists(CXCursor C); + +CLANGSHARP_LINKAGE int clangsharp_Cursor_getNumVBases(CXCursor C); + +CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getOpaqueValue(CXCursor C); CLANGSHARP_LINKAGE CXType clangsharp_Cursor_getOriginalType(CXCursor C); +CLANGSHARP_LINKAGE CX_OverloadedOperatorKind clangsharp_Cursor_getOverloadedOperatorKind(CXCursor C); + +CLANGSHARP_LINKAGE int clangsharp_Cursor_getPackLength(CXCursor C); + CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getParentFunctionOrMethod(CXCursor C); CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getPlaceholderTypeConstraint(CXCursor C); @@ -397,13 +649,21 @@ CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getPreviousDecl(CXCursor C); CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getPrimaryTemplate(CXCursor C); +CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getProtocol(CXCursor C, unsigned i); + +CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getRedeclContext(CXCursor C); + CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getReferenced(CXCursor C); +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getRequiresZeroInitialization(CXCursor C); + +CLANGSHARP_LINKAGE int clangsharp_Cursor_getResultIndex(CXCursor C); + CLANGSHARP_LINKAGE CXType clangsharp_Cursor_getReturnType(CXCursor C); CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getRhsExpr(CXCursor C); -CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getRowIdxExpr(CXCursor C); +CLANGSHARP_LINKAGE unsigned clangsharp_Cursor_getShouldCopy(CXCursor C); CLANGSHARP_LINKAGE CXSourceRange clangsharp_Cursor_getSourceRange(CXCursor C); @@ -413,6 +673,8 @@ CLANGSHARP_LINKAGE CX_StmtClass clangsharp_Cursor_getStmtClass(CXCursor C); CLANGSHARP_LINKAGE CXString clangsharp_Cursor_getStringLiteralValue(CXCursor C); +CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getSubDecl(CXCursor C, unsigned i); + CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getSubExpr(CXCursor C); CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getSubExprAsWritten(CXCursor C); @@ -421,31 +683,11 @@ CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getSubStmt(CXCursor C); CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getTargetUnionField(CXCursor C); -CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getTemplateArgument(CXCursor C, unsigned i); - -CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getTemplateArgumentAsDecl(CXCursor C, unsigned i); - -CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getTemplateArgumentAsExpr(CXCursor C, unsigned i); - -CLANGSHARP_LINKAGE int64_t clangsharp_Cursor_getTemplateArgumentAsIntegral(CXCursor C, unsigned i); - -CLANGSHARP_LINKAGE CXType clangsharp_Cursor_getTemplateArgumentAsType(CXCursor C, unsigned i); - -CLANGSHARP_LINKAGE CXType clangsharp_Cursor_getTemplateArgumentIntegralType(CXCursor C, unsigned i); - -CLANGSHARP_LINKAGE CXTemplateArgumentKind clangsharp_Cursor_getTemplateArgumentKind(CXCursor C, unsigned i); - -CLANGSHARP_LINKAGE CXSourceLocation clangsharp_Cursor_getTemplateArgumentLocLocation(CXCursor C, unsigned i); - -CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getTemplateArgumentLocSourceDeclExpression(CXCursor C, unsigned i); - -CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getTemplateArgumentLocSourceExpression(CXCursor C, unsigned i); +CLANGSHARP_LINKAGE CX_TemplateArgument clangsharp_Cursor_getTemplateArgument(CXCursor C, unsigned i); -CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getTemplateArgumentLocSourceIntegralExpression(CXCursor C, unsigned i); +CLANGSHARP_LINKAGE CX_TemplateArgumentLoc clangsharp_Cursor_getTemplateArgumentLoc(CXCursor C, unsigned i); -CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getTemplateArgumentLocSourceNullPtrExpression(CXCursor C, unsigned i); - -CLANGSHARP_LINKAGE CXType clangsharp_Cursor_getTemplateArgumentNullPtrType(CXCursor C, unsigned i); +CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getTemplateParameter(CXCursor C, unsigned listIndex, unsigned parameterIndex); CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getTemplatedDecl(CXCursor C); @@ -457,14 +699,14 @@ CLANGSHARP_LINKAGE int clangsharp_Cursor_getTemplateTypeParmDepth(CXCursor C); CLANGSHARP_LINKAGE int clangsharp_Cursor_getTemplateTypeParmIndex(CXCursor C); +CLANGSHARP_LINKAGE int clangsharp_Cursor_getTemplateTypeParmPosition(CXCursor C); + CLANGSHARP_LINKAGE CXType clangsharp_Cursor_getThisObjectType(CXCursor C); CLANGSHARP_LINKAGE CXType clangsharp_Cursor_getThisType(CXCursor C); CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getTrailingRequiresClause(CXCursor C); -CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getTrueExpr(CXCursor C); - CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getTypedefNameForAnonDecl(CXCursor C); CLANGSHARP_LINKAGE CXType clangsharp_Cursor_getTypeOperand(CXCursor C); @@ -481,6 +723,56 @@ CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getUninstantiatedDefaultArg(CXCurs CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getUsedContext(CXCursor C); +CLANGSHARP_LINKAGE CXCursor clangsharp_Cursor_getVBase(CXCursor C, unsigned i); + +CLANGSHARP_LINKAGE int64_t clangsharp_Cursor_getVtblIdx(CXCursor C); + +CLANGSHARP_LINKAGE void clangsharp_TemplateArgument_dispose(CX_TemplateArgument T); + +CLANGSHARP_LINKAGE CXCursor clangsharp_TemplateArgument_getAsDecl(CX_TemplateArgument T); + +CLANGSHARP_LINKAGE CXCursor clangsharp_TemplateArgument_getAsExpr(CX_TemplateArgument T); + +CLANGSHARP_LINKAGE int64_t clangsharp_TemplateArgument_getAsIntegral(CX_TemplateArgument T); + +CLANGSHARP_LINKAGE CX_TemplateName clangsharp_TemplateArgument_getAsTemplate(CX_TemplateArgument T); + +CLANGSHARP_LINKAGE CX_TemplateName clangsharp_TemplateArgument_getAsTemplateOrTemplatePattern(CX_TemplateArgument T); + +CLANGSHARP_LINKAGE CXType clangsharp_TemplateArgument_getAsType(CX_TemplateArgument T); + +CLANGSHARP_LINKAGE CX_TemplateArgumentDependence clangsharp_TemplateArgument_getDependence(CX_TemplateArgument T); + +CLANGSHARP_LINKAGE CXType clangsharp_TemplateArgument_getIntegralType(CX_TemplateArgument T); + +CLANGSHARP_LINKAGE CXType clangsharp_TemplateArgument_getNonTypeTemplateArgumentType(CX_TemplateArgument T); + +CLANGSHARP_LINKAGE CXType clangsharp_TemplateArgument_getNullPtrType(CX_TemplateArgument T); + +CLANGSHARP_LINKAGE int clangsharp_TemplateArgument_getNumPackElements(CX_TemplateArgument T); + +CLANGSHARP_LINKAGE CX_TemplateArgument clangsharp_TemplateArgument_getPackElement(CX_TemplateArgument T, unsigned i); + +CLANGSHARP_LINKAGE CX_TemplateArgument clangsharp_TemplateArgument_getPackExpansionPattern(CX_TemplateArgument T); + +CLANGSHARP_LINKAGE CXType clangsharp_TemplateArgument_getParamTypeForDecl(CX_TemplateArgument T); + +CLANGSHARP_LINKAGE CX_TemplateArgument clangsharp_TemplateArgumentLoc_getArgument(CX_TemplateArgumentLoc T); + +CLANGSHARP_LINKAGE CXSourceLocation clangsharp_TemplateArgumentLoc_getLocation(CX_TemplateArgumentLoc T); + +CLANGSHARP_LINKAGE CXCursor clangsharp_TemplateArgumentLoc_getSourceDeclExpression(CX_TemplateArgumentLoc T); + +CLANGSHARP_LINKAGE CXCursor clangsharp_TemplateArgumentLoc_getSourceExpression(CX_TemplateArgumentLoc T); + +CLANGSHARP_LINKAGE CXCursor clangsharp_TemplateArgumentLoc_getSourceIntegralExpression(CX_TemplateArgumentLoc T); + +CLANGSHARP_LINKAGE CXCursor clangsharp_TemplateArgumentLoc_getSourceNullPtrExpression(CX_TemplateArgumentLoc T); + +CLANGSHARP_LINKAGE CXSourceRange clangsharp_TemplateArgumentLoc_getSourceRange(CX_TemplateArgumentLoc T); + +CLANGSHARP_LINKAGE CXCursor clangsharp_TemplateName_getAsTemplateDecl(CX_TemplateName T); + CLANGSHARP_LINKAGE CXType clangsharp_Type_desugar(CXType CT); CLANGSHARP_LINKAGE CXCursor clangsharp_Type_getAddrSpaceExpr(CXType CT); @@ -541,19 +833,9 @@ CLANGSHARP_LINKAGE CXCursor clangsharp_Type_getRowExpr(CXType CT); CLANGSHARP_LINKAGE CXCursor clangsharp_Type_getSizeExpr(CXType CT); -CLANGSHARP_LINKAGE CXCursor clangsharp_Type_getTemplateArgumentAsDecl(CXType CT, unsigned i); - -CLANGSHARP_LINKAGE CXCursor clangsharp_Type_getTemplateArgumentAsExpr(CXType CT, unsigned i); - -CLANGSHARP_LINKAGE int64_t clangsharp_Type_getTemplateArgumentAsIntegral(CXType CT, unsigned i); - -CLANGSHARP_LINKAGE CXType clangsharp_Type_getTemplateArgumentAsType(CXType CT, unsigned i); - -CLANGSHARP_LINKAGE CXType clangsharp_Type_getTemplateArgumentIntegralType(CXType CT, unsigned i); - -CLANGSHARP_LINKAGE CXTemplateArgumentKind clangsharp_Type_getTemplateArgumentKind(CXType CT, unsigned i); +CLANGSHARP_LINKAGE CX_TemplateArgument clangsharp_Type_getTemplateArgument(CXType C, unsigned i); -CLANGSHARP_LINKAGE CXType clangsharp_Type_getTemplateArgumentNullPtrType(CXType CT, unsigned i); +CLANGSHARP_LINKAGE CX_TemplateName clangsharp_Type_getTemplateName(CXType C); CLANGSHARP_LINKAGE CX_TypeClass clangsharp_Type_getTypeClass(CXType CT); diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleUnix/CXXMethodDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleUnix/CXXMethodDeclarationTest.cs index e9c239e5..af1dfceb 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleUnix/CXXMethodDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleUnix/CXXMethodDeclarationTest.cs @@ -447,7 +447,7 @@ public int GetType(int obj) {{ fixed (MyStruct* pThis = &this) {{ - return Marshal.GetDelegateForFunctionPointer<_GetType>((IntPtr)(lpVtbl[0]))(pThis, obj); + return Marshal.GetDelegateForFunctionPointer<_GetType>((IntPtr)(lpVtbl[{(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? 2 : 0)}]))(pThis, obj); }} }} @@ -463,7 +463,7 @@ public int GetType(int objA, int objB) {{ fixed (MyStruct* pThis = &this) {{ - return Marshal.GetDelegateForFunctionPointer<_GetType2>((IntPtr)(lpVtbl[2]))(pThis, objA, objB); + return Marshal.GetDelegateForFunctionPointer<_GetType2>((IntPtr)(lpVtbl[{(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? 0 : 2)}]))(pThis, objA, objB); }} }} }} diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleWindows/CXXMethodDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleWindows/CXXMethodDeclarationTest.cs index c0371eea..82fef42d 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleWindows/CXXMethodDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleWindows/CXXMethodDeclarationTest.cs @@ -447,7 +447,7 @@ public int GetType(int obj) {{ fixed (MyStruct* pThis = &this) {{ - return Marshal.GetDelegateForFunctionPointer<_GetType>((IntPtr)(lpVtbl[0]))(pThis, obj); + return Marshal.GetDelegateForFunctionPointer<_GetType>((IntPtr)(lpVtbl[{(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? 2 : 0)}]))(pThis, obj); }} }} @@ -463,7 +463,7 @@ public int GetType(int objA, int objB) {{ fixed (MyStruct* pThis = &this) {{ - return Marshal.GetDelegateForFunctionPointer<_GetType2>((IntPtr)(lpVtbl[2]))(pThis, objA, objB); + return Marshal.GetDelegateForFunctionPointer<_GetType2>((IntPtr)(lpVtbl[{(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? 0 : 2)}]))(pThis, objA, objB); }} }} }} diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/CXXMethodDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/CXXMethodDeclarationTest.cs index 60371f71..c7ef3964 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/CXXMethodDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/CXXMethodDeclarationTest.cs @@ -446,7 +446,7 @@ public unsafe partial struct MyStruct public int GetType(int obj) {{ - return Marshal.GetDelegateForFunctionPointer<_GetType>((IntPtr)(lpVtbl[0]))((MyStruct*)Unsafe.AsPointer(ref this), obj); + return Marshal.GetDelegateForFunctionPointer<_GetType>((IntPtr)(lpVtbl[{(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? 2 : 0)}]))((MyStruct*)Unsafe.AsPointer(ref this), obj); }} public new int GetType() @@ -456,7 +456,7 @@ public int GetType(int obj) public int GetType(int objA, int objB) {{ - return Marshal.GetDelegateForFunctionPointer<_GetType2>((IntPtr)(lpVtbl[2]))((MyStruct*)Unsafe.AsPointer(ref this), objA, objB); + return Marshal.GetDelegateForFunctionPointer<_GetType2>((IntPtr)(lpVtbl[{(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? 0 : 2)}]))((MyStruct*)Unsafe.AsPointer(ref this), objA, objB); }} }} }} diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/CXXMethodDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/CXXMethodDeclarationTest.cs index eda47533..9478c113 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/CXXMethodDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/CXXMethodDeclarationTest.cs @@ -446,7 +446,7 @@ public unsafe partial struct MyStruct public int GetType(int obj) {{ - return Marshal.GetDelegateForFunctionPointer<_GetType>((IntPtr)(lpVtbl[0]))((MyStruct*)Unsafe.AsPointer(ref this), obj); + return Marshal.GetDelegateForFunctionPointer<_GetType>((IntPtr)(lpVtbl[{(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? 2 : 0)}]))((MyStruct*)Unsafe.AsPointer(ref this), obj); }} public new int GetType() @@ -456,7 +456,7 @@ public int GetType(int obj) public int GetType(int objA, int objB) {{ - return Marshal.GetDelegateForFunctionPointer<_GetType2>((IntPtr)(lpVtbl[2]))((MyStruct*)Unsafe.AsPointer(ref this), objA, objB); + return Marshal.GetDelegateForFunctionPointer<_GetType2>((IntPtr)(lpVtbl[{(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? 0 : 2)}]))((MyStruct*)Unsafe.AsPointer(ref this), objA, objB); }} }} }} diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/Properties/launchSettings.json b/tests/ClangSharp.PInvokeGenerator.UnitTests/Properties/launchSettings.json new file mode 100644 index 00000000..7eaa9638 --- /dev/null +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "ClangSharp.PInvokeGenerator.UnitTests": { + "commandName": "Project", + "nativeDebugging": true + } + } +} \ No newline at end of file diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleUnix/CXXMethodDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleUnix/CXXMethodDeclarationTest.cs index 37e1b126..8002c7cb 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleUnix/CXXMethodDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleUnix/CXXMethodDeclarationTest.cs @@ -520,7 +520,7 @@ public override Task NewKeywordVirtualTest() fixed (MyStruct* pThis = &this) {{ - return Marshal.GetDelegateForFunctionPointer<_GetType>((IntPtr)(lpVtbl[0]))(pThis, obj); + return Marshal.GetDelegateForFunctionPointer<_GetType>((IntPtr)(lpVtbl[{(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? 2 : 0)}]))(pThis, obj); }} @@ -544,7 +544,7 @@ public override Task NewKeywordVirtualTest() fixed (MyStruct* pThis = &this) {{ - return Marshal.GetDelegateForFunctionPointer<_GetType2>((IntPtr)(lpVtbl[2]))(pThis, objA, objB); + return Marshal.GetDelegateForFunctionPointer<_GetType2>((IntPtr)(lpVtbl[{(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? 0 : 2)}]))(pThis, objA, objB); }} diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleWindows/CXXMethodDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleWindows/CXXMethodDeclarationTest.cs index da367060..9ab21ffc 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleWindows/CXXMethodDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleWindows/CXXMethodDeclarationTest.cs @@ -520,7 +520,7 @@ public override Task NewKeywordVirtualTest() fixed (MyStruct* pThis = &this) {{ - return Marshal.GetDelegateForFunctionPointer<_GetType>((IntPtr)(lpVtbl[0]))(pThis, obj); + return Marshal.GetDelegateForFunctionPointer<_GetType>((IntPtr)(lpVtbl[{(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? 2 : 0)}]))(pThis, obj); }} @@ -544,7 +544,7 @@ public override Task NewKeywordVirtualTest() fixed (MyStruct* pThis = &this) {{ - return Marshal.GetDelegateForFunctionPointer<_GetType2>((IntPtr)(lpVtbl[2]))(pThis, objA, objB); + return Marshal.GetDelegateForFunctionPointer<_GetType2>((IntPtr)(lpVtbl[{(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? 0 : 2)}]))(pThis, objA, objB); }} diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestUnix/CXXMethodDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestUnix/CXXMethodDeclarationTest.cs index 4baa99cd..fde606cc 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestUnix/CXXMethodDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestUnix/CXXMethodDeclarationTest.cs @@ -518,7 +518,7 @@ public override Task NewKeywordVirtualTest() int - return Marshal.GetDelegateForFunctionPointer<_GetType>((IntPtr)(lpVtbl[0]))((MyStruct*)Unsafe.AsPointer(ref this), obj); + return Marshal.GetDelegateForFunctionPointer<_GetType>((IntPtr)(lpVtbl[{(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? 2 : 0)}]))((MyStruct*)Unsafe.AsPointer(ref this), obj); @@ -536,7 +536,7 @@ public override Task NewKeywordVirtualTest() int - return Marshal.GetDelegateForFunctionPointer<_GetType2>((IntPtr)(lpVtbl[2]))((MyStruct*)Unsafe.AsPointer(ref this), objA, objB); + return Marshal.GetDelegateForFunctionPointer<_GetType2>((IntPtr)(lpVtbl[{(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? 0 : 2)}]))((MyStruct*)Unsafe.AsPointer(ref this), objA, objB); diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestWindows/CXXMethodDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestWindows/CXXMethodDeclarationTest.cs index 5b1caa67..81931502 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestWindows/CXXMethodDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestWindows/CXXMethodDeclarationTest.cs @@ -518,7 +518,7 @@ public override Task NewKeywordVirtualTest() int - return Marshal.GetDelegateForFunctionPointer<_GetType>((IntPtr)(lpVtbl[0]))((MyStruct*)Unsafe.AsPointer(ref this), obj); + return Marshal.GetDelegateForFunctionPointer<_GetType>((IntPtr)(lpVtbl[{(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? 2 : 0)}]))((MyStruct*)Unsafe.AsPointer(ref this), obj); @@ -536,7 +536,7 @@ public override Task NewKeywordVirtualTest() int - return Marshal.GetDelegateForFunctionPointer<_GetType2>((IntPtr)(lpVtbl[2]))((MyStruct*)Unsafe.AsPointer(ref this), objA, objB); + return Marshal.GetDelegateForFunctionPointer<_GetType2>((IntPtr)(lpVtbl[{(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? 0 : 2)}]))((MyStruct*)Unsafe.AsPointer(ref this), objA, objB); diff --git a/tests/ClangSharp.UnitTests/CursorTests/DeclTest.cs b/tests/ClangSharp.UnitTests/CursorTests/DeclTest.cs index 840ce8e8..b558d7d5 100644 --- a/tests/ClangSharp.UnitTests/CursorTests/DeclTest.cs +++ b/tests/ClangSharp.UnitTests/CursorTests/DeclTest.cs @@ -22,7 +22,7 @@ public void AccessSpecDeclTest(string accessSpecifier, CX_CXXAccessSpecifier exp using var translationUnit = CreateTranslationUnit(inputContents); - var recordDecl = translationUnit.TranslationUnitDecl.Decls.OfType().Single(); + var recordDecl = translationUnit.TranslationUnitDecl.Decls.OfType().Where((recordDecl) => recordDecl.Name == "MyStruct").Single(); var accessSpecDecl = recordDecl.Decls.OfType().Single(); Assert.Equal(expectedAccessSpecifier, accessSpecDecl.Access);