C#: Add extractor and QL library support for ref readonly parameters.

This commit is contained in:
Michael Nebel
2024-02-26 11:08:59 +01:00
parent a86de9de2f
commit 692d7036a0
3 changed files with 22 additions and 1 deletions

View File

@@ -53,6 +53,7 @@ namespace Semmle.Extraction.CSharp.Entities
trapFile.type_annotation(this, Kinds.TypeAnnotation.Ref);
break;
case RefKind.RefReadOnly:
case RefKind.RefReadOnlyParameter:
trapFile.type_annotation(this, Kinds.TypeAnnotation.ReadonlyRef);
break;
}

View File

@@ -24,7 +24,13 @@ namespace Semmle.Extraction.CSharp.Entities
public enum Kind
{
None, Ref, Out, Params, This, In
None = 0,
Ref = 1,
Out = 2,
Params = 3,
This = 4,
In = 5,
RefReadOnly = 6
}
protected virtual int Ordinal => Symbol.Ordinal;
@@ -41,6 +47,8 @@ namespace Semmle.Extraction.CSharp.Entities
return Kind.Ref;
case RefKind.In:
return Kind.In;
case RefKind.RefReadOnlyParameter:
return Kind.RefReadOnly;
default:
if (Symbol.IsParams)
return Kind.Params;

View File

@@ -167,6 +167,18 @@ class Parameter extends DotNet::Parameter, LocalScopeVariable, Attributable, Top
*/
predicate isParams() { params(this, _, _, _, 3, _, _) }
/**
* Holds if this parameter if a ref readonly parameter.
* For example, `p` is a ref readonly parameter in
*
* ```csharp
* void M(ref readonly int p) {
* ...
* }
* ```
*/
predicate isReadonlyRef() { params(this, _, _, _, 6, _, _) }
/**
* Holds this parameter is the first parameter of an extension method.
* For example, `list` is the first parameter of the extension method