Skip to content

Commit

Permalink
Ensure CXCursor and CXType don't crash the debugger for default values
Browse files Browse the repository at this point in the history
  • Loading branch information
tannergooding committed Sep 18, 2022
1 parent f387011 commit acaeeff
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 48 deletions.
60 changes: 30 additions & 30 deletions sources/ClangSharp.Interop/Extensions/CXCursor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ public string DeclKindSpelling

public CXCursorKind Kind => clang.getCursorKind(this);

public CXString KindSpelling => clang.getCursorKindSpelling(Kind);
public CXString KindSpelling => (kind != default) ? clang.getCursorKindSpelling(Kind) : default;

public CXCursor LambdaCallOperator => clangsharp.Cursor_getLambdaCallOperator(this);

Expand Down Expand Up @@ -1166,7 +1166,7 @@ public ReadOnlySpan<CXCursor> OverriddenCursors

public CXCursor PrimaryTemplate => clangsharp.Cursor_getPrimaryTemplate(this);

public CXPrintingPolicy PrintingPolicy => (CXPrintingPolicy)clang.getCursorPrintingPolicy(this);
public CXPrintingPolicy PrintingPolicy => (kind != default) ? (CXPrintingPolicy)clang.getCursorPrintingPolicy(this) : default;

public CXString RawCommentText => clang.Cursor_getRawCommentText(this);

Expand Down Expand Up @@ -1563,34 +1563,34 @@ internal string DebuggerDisplayString
{
get
{
if (AttrKind != CX_AttrKind.CX_AttrKind_Invalid)
{
return $"{AttrKindSpelling}: {this}";
}
else if (DeclKind != CX_DeclKind.CX_DeclKind_Invalid)
{
return $"{DeclKindSpelling}: {this}";
}
else if (StmtClass != CX_StmtClass.CX_StmtClass_Invalid)
{
var additionalInfo = string.Empty;

if (BinaryOperatorKind != CX_BinaryOperatorKind.CX_BO_Invalid)
{
additionalInfo = $" ({BinaryOperatorKindSpelling})";
}
else if (CastKind != CX_CastKind.CX_CK_Invalid)
{
additionalInfo = $" ({CastKindSpelling})";
}
else if (UnaryOperatorKind != CX_UnaryOperatorKind.CX_UO_Invalid)
{
additionalInfo = $" ({UnaryOperatorKindSpelling})";
}

return $"{StmtClassSpelling}: {this}{additionalInfo}";
}
else
// if (AttrKind != CX_AttrKind.CX_AttrKind_Invalid)
// {
// return $"{AttrKindSpelling}: {this}";
// }
// else if (DeclKind != CX_DeclKind.CX_DeclKind_Invalid)
// {
// return $"{DeclKindSpelling}: {this}";
// }
// else if (StmtClass != CX_StmtClass.CX_StmtClass_Invalid)
// {
// var additionalInfo = string.Empty;
//
// if (BinaryOperatorKind != CX_BinaryOperatorKind.CX_BO_Invalid)
// {
// additionalInfo = $" ({BinaryOperatorKindSpelling})";
// }
// else if (CastKind != CX_CastKind.CX_CK_Invalid)
// {
// additionalInfo = $" ({CastKindSpelling})";
// }
// else if (UnaryOperatorKind != CX_UnaryOperatorKind.CX_UO_Invalid)
// {
// additionalInfo = $" ({UnaryOperatorKindSpelling})";
// }
//
// return $"{StmtClassSpelling}: {this}{additionalInfo}";
// }
// else
{
return $"{KindSpelling}: {this}";
}
Expand Down
36 changes: 18 additions & 18 deletions sources/ClangSharp.Interop/Extensions/CXType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public unsafe partial struct CXType : IEquatable<CXType>

public CXCursor AddrSpaceExpr => clangsharp.Type_getAddrSpaceExpr(this);

public CXType AdjustedType => clangsharp.Type_getAdjustedType(this);
public CXType AdjustedType => (kind != CXTypeKind.CXType_Invalid) ? clangsharp.Type_getAdjustedType(this) : default;

public long AlignOf => clang.Type_getAlignOf(this);

Expand All @@ -35,27 +35,27 @@ public unsafe partial struct CXType : IEquatable<CXType>

public CXType DecayedType => clangsharp.Type_getDecayedType(this);

public CXCursor Declaration => clangsharp.Type_getDeclaration(this);
public CXCursor Declaration => (kind != CXTypeKind.CXType_Invalid) ? clangsharp.Type_getDeclaration(this) : default;

public CXType DeducedType => clangsharp.Type_getDeducedType(this);
public CXType DeducedType => (kind != CXTypeKind.CXType_Invalid) ? clangsharp.Type_getDeducedType(this) : default;

public int Depth => clangsharp.Type_getDepth(this);

public CXType Desugar => clangsharp.Type_desugar(this);
public CXType Desugar => (kind != CXTypeKind.CXType_Invalid) ? clangsharp.Type_desugar(this) : default;

public CXType ElementType => clangsharp.Type_getElementType(this);
public CXType ElementType => (kind != CXTypeKind.CXType_Invalid) ? clangsharp.Type_getElementType(this) :default;

public CXType EquivalentType => clangsharp.Type_getEquivalentType(this);
public CXType EquivalentType => (kind != CXTypeKind.CXType_Invalid) ? clangsharp.Type_getEquivalentType(this) : default;

public CXCursor_ExceptionSpecificationKind ExceptionSpecificationType => (CXCursor_ExceptionSpecificationKind)clang.getExceptionSpecificationType(this);

public CXCallingConv FunctionTypeCallingConv => clang.getFunctionTypeCallingConv(this);

public int Index => clangsharp.Type_getIndex(this);

public CXType InjectedSpecializationType => clangsharp.Type_getInjectedSpecializationType(this);
public CXType InjectedSpecializationType => (kind != CXTypeKind.CXType_Invalid) ? clangsharp.Type_getInjectedSpecializationType(this) : default;

public CXType InjectedTST => clangsharp.Type_getInjectedTST(this);
public CXType InjectedTST => (kind != CXTypeKind.CXType_Invalid) ? clangsharp.Type_getInjectedTST(this) : default;

public bool IsCanonical => Equals(CanonicalType);

Expand All @@ -69,7 +69,7 @@ public unsafe partial struct CXType : IEquatable<CXType>

public bool IsSigned => clangsharp.Type_getIsSigned(this) != 0;

public bool IsSugared => clangsharp.Type_getIsSugared(this) != 0;
public bool IsSugared => (kind != CXTypeKind.CXType_Invalid) && clangsharp.Type_getIsSugared(this) != 0;

public bool IsTransparentTagTypedef => clang.Type_isTransparentTagTypedef(this) != 0;

Expand Down Expand Up @@ -109,21 +109,21 @@ public unsafe partial struct CXType : IEquatable<CXType>

public CXType ObjCObjectBaseType => clang.Type_getObjCObjectBaseType(this);

public CXType OriginalType => clangsharp.Type_getOriginalType(this);
public CXType OriginalType => (kind != CXTypeKind.CXType_Invalid) ? clangsharp.Type_getOriginalType(this) : default;

public CXCursor OwnedTagDecl => clangsharp.Type_getOwnedTagDecl(this);
public CXCursor OwnedTagDecl => (kind != CXTypeKind.CXType_Invalid) ? clangsharp.Type_getOwnedTagDecl(this) : default;

public CXType PointeeType => clangsharp.Type_getPointeeType(this);
public CXType PointeeType => (kind != CXTypeKind.CXType_Invalid) ? clangsharp.Type_getPointeeType(this) : default;

public CXType ResultType => clang.getResultType(this);

public CXCursor RowExpr => clangsharp.Type_getRowExpr(this);
public CXCursor RowExpr => (kind != CXTypeKind.CXType_Invalid) ? clangsharp.Type_getRowExpr(this) : default;

public CXCursor SizeExpr => clangsharp.Type_getSizeExpr(this);
public CXCursor SizeExpr => (kind != CXTypeKind.CXType_Invalid) ? clangsharp.Type_getSizeExpr(this) : default;

public long SizeOf => clang.Type_getSizeOf(this);

public CXString Spelling => clang.getTypeSpelling(this);
public CXString Spelling => (kind != CXTypeKind.CXType_Invalid) ? clang.getTypeSpelling(this) : default;

public CX_TemplateName TemplateName
{
Expand Down Expand Up @@ -206,11 +206,11 @@ public string TypeClassSpelling
}
}

public CXString TypedefName => clang.getTypedefName(this);
public CXString TypedefName => (kind != CXTypeKind.CXType_Invalid) ? clang.getTypedefName(this) : default;

public CXCursor UnderlyingExpr => clangsharp.Type_getUnderlyingExpr(this);
public CXCursor UnderlyingExpr => (kind != CXTypeKind.CXType_Invalid) ? clangsharp.Type_getUnderlyingExpr(this) : default;

public CXType UnderlyingType => clangsharp.Type_getUnderlyingType(this);
public CXType UnderlyingType => (kind != CXTypeKind.CXType_Invalid) ? clangsharp.Type_getUnderlyingType(this) : default;

public CXType ValueType => clang.Type_getValueType(this);

Expand Down

0 comments on commit acaeeff

Please sign in to comment.