mirror of
https://github.com/github/codeql.git
synced 2026-04-29 10:45:15 +02:00
Fix code review findings
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
lgtm,codescanning
|
||||
* CIL extraction has been improved to store `modreq` and `modopt` custom modifiers.
|
||||
The extracted information is surfaced through the `CustomModifierReceiver` class. Additionally,
|
||||
the information is also used to evaluate the new `Setter.isInitOnly` predicate.
|
||||
the information is also used to evaluate the new `Setter::isInitOnly` predicate.
|
||||
@@ -33,17 +33,10 @@ namespace Semmle.Extraction.CIL.Entities
|
||||
|
||||
public override Type Construct(IEnumerable<Type> typeArguments) => throw new NotImplementedException();
|
||||
|
||||
public override string Name => Unmodified.Name + (IsRequired ? " modreq" : " modopt") + $"({Modifier.Name})";
|
||||
public override string Name => $"{Unmodified.Name} {(IsRequired ? "modreq" : "modopt")}({Modifier.Name})";
|
||||
|
||||
public override void WriteAssemblyPrefix(TextWriter trapFile) => Unmodified.WriteAssemblyPrefix(trapFile);
|
||||
public override void WriteAssemblyPrefix(TextWriter trapFile) => throw new NotImplementedException();
|
||||
|
||||
public override void WriteId(TextWriter trapFile, bool inContext)
|
||||
{
|
||||
Unmodified.WriteId(trapFile, inContext);
|
||||
trapFile.Write(IsRequired ? " modreq" : " modopt");
|
||||
trapFile.Write("(");
|
||||
Modifier.WriteId(trapFile, inContext);
|
||||
trapFile.Write(")");
|
||||
}
|
||||
public override void WriteId(TextWriter trapFile, bool inContext) => throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ private import CIL
|
||||
private import dotnet
|
||||
|
||||
/**
|
||||
* A class to represent entities that can recive custom modifiers. Custom modifiers can be attached to
|
||||
* A class to represent entities that can receive custom modifiers. Custom modifiers can be attached to
|
||||
* - the type of a `Field`,
|
||||
* - the return type of a `Method` or `Property`,
|
||||
* - the type of parameters.
|
||||
@@ -18,12 +18,4 @@ class CustomModifierReceiver extends Declaration, @cil_custom_modifier_receiver
|
||||
|
||||
/** Holds if this targeted type has `modifier` applied as `modopt`. */
|
||||
predicate hasOptionalCustomModifier(Type modifier) { cil_custom_modifiers(this, modifier, 0) }
|
||||
|
||||
/**
|
||||
* Holds if this targeted type has `modifier` applied as `kind`. `kind` 1 means `modreq`,
|
||||
* `kind` 0 represents `modopt`.
|
||||
*/
|
||||
predicate hasCustomModifier(Type modifier, int kind) {
|
||||
cil_custom_modifiers(this, modifier, kind)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,7 +251,7 @@ class Setter extends Accessor {
|
||||
/** Holds if this setter is an `init` accessor. */
|
||||
predicate isInitOnly() {
|
||||
exists(Type t | t.getQualifiedName() = "System.Runtime.CompilerServices.IsExternalInit" |
|
||||
cil_custom_modifiers(this, t, 1)
|
||||
this.hasRequiredCustomModifier(t)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ from string receiver, string modifier, int kind
|
||||
where
|
||||
exists(Type modType, CustomModifierReceiver cmr |
|
||||
receiver = cmr.toString() and
|
||||
cmr.hasCustomModifier(modType, kind) and
|
||||
cil_custom_modifiers(cmr, modType, kind) and
|
||||
modType.getQualifiedName() = modifier
|
||||
)
|
||||
select receiver, modifier, getKind(kind)
|
||||
|
||||
Reference in New Issue
Block a user