mirror of
https://github.com/github/codeql.git
synced 2026-05-05 21:55:19 +02:00
C#: Extract structs representing inline arrays as inline arrays.
This commit is contained in:
@@ -43,6 +43,9 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
|
||||
public sealed override Microsoft.CodeAnalysis.Location? ReportingLocation => base.ReportingLocation;
|
||||
|
||||
private static bool IsArray(ITypeSymbol symbol) =>
|
||||
symbol.TypeKind == Microsoft.CodeAnalysis.TypeKind.Array || symbol.IsInlineArray();
|
||||
|
||||
private static ExprKind GetKind(Context cx, ExpressionSyntax qualifier)
|
||||
{
|
||||
var qualifierType = cx.GetType(qualifier);
|
||||
@@ -59,7 +62,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
|
||||
return IsDynamic(cx, qualifier)
|
||||
? ExprKind.DYNAMIC_ELEMENT_ACCESS
|
||||
: qualifierType.Symbol.TypeKind == Microsoft.CodeAnalysis.TypeKind.Array
|
||||
: IsArray(qualifierType.Symbol)
|
||||
? ExprKind.ARRAY_ACCESS
|
||||
: ExprKind.INDEXER_ACCESS;
|
||||
}
|
||||
|
||||
@@ -52,9 +52,15 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
{
|
||||
case TypeKind.Class: return Kinds.TypeKind.CLASS;
|
||||
case TypeKind.Struct:
|
||||
return ((INamedTypeSymbol)Symbol).IsTupleType && !constructUnderlyingTupleType
|
||||
? Kinds.TypeKind.TUPLE
|
||||
: Kinds.TypeKind.STRUCT;
|
||||
{
|
||||
if (((INamedTypeSymbol)Symbol).IsTupleType && !constructUnderlyingTupleType)
|
||||
{
|
||||
return Kinds.TypeKind.TUPLE;
|
||||
}
|
||||
return Symbol.IsInlineArray()
|
||||
? Kinds.TypeKind.INLINE_ARRAY
|
||||
: Kinds.TypeKind.STRUCT;
|
||||
}
|
||||
case TypeKind.Interface: return Kinds.TypeKind.INTERFACE;
|
||||
case TypeKind.Array: return Kinds.TypeKind.ARRAY;
|
||||
case TypeKind.Enum: return Kinds.TypeKind.ENUM;
|
||||
|
||||
@@ -524,6 +524,13 @@ namespace Semmle.Extraction.CSharp
|
||||
public static bool IsUnboundReadOnlySpan(this ITypeSymbol type) =>
|
||||
type.ToString() == "System.ReadOnlySpan<T>";
|
||||
|
||||
public static bool IsInlineArray(this ITypeSymbol type)
|
||||
{
|
||||
var attributes = type.GetAttributes();
|
||||
var isInline = attributes.Any(attribute => attribute.AttributeClass?.Name == "InlineArrayAttribute");
|
||||
return isInline;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Holds if this type is of the form <code>System.ReadOnlySpan<byte></code>.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user