mirror of
https://github.com/github/codeql.git
synced 2026-04-28 02:05:14 +02:00
C#: Add extractor and QL library support for ref readonly parameters.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user