Skip to content

Commit 12c2854

Browse files
committed
Fix code review findings
1 parent 8e8c3a9 commit 12c2854

File tree

5 files changed

+7
-22
lines changed

5 files changed

+7
-22
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
lgtm,codescanning
22
* CIL extraction has been improved to store `modreq` and `modopt` custom modifiers.
33
The extracted information is surfaced through the `CustomModifierReceiver` class. Additionally,
4-
the information is also used to evaluate the new `Setter.isInitOnly` predicate.
4+
the information is also used to evaluate the new `Setter::isInitOnly` predicate.

csharp/extractor/Semmle.Extraction.CIL/Entities/ModifiedType.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,10 @@ public ModifiedType(Context cx, Type unmodified, Type modifier, bool isRequired)
3333

3434
public override Type Construct(IEnumerable<Type> typeArguments) => throw new NotImplementedException();
3535

36-
public override string Name => Unmodified.Name + (IsRequired ? " modreq" : " modopt") + $"({Modifier.Name})";
36+
public override string Name => $"{Unmodified.Name} {(IsRequired ? "modreq" : "modopt")}({Modifier.Name})";
3737

38-
public override void WriteAssemblyPrefix(TextWriter trapFile) => Unmodified.WriteAssemblyPrefix(trapFile);
38+
public override void WriteAssemblyPrefix(TextWriter trapFile) => throw new NotImplementedException();
3939

40-
public override void WriteId(TextWriter trapFile, bool inContext)
41-
{
42-
Unmodified.WriteId(trapFile, inContext);
43-
trapFile.Write(IsRequired ? " modreq" : " modopt");
44-
trapFile.Write("(");
45-
Modifier.WriteId(trapFile, inContext);
46-
trapFile.Write(")");
47-
}
40+
public override void WriteId(TextWriter trapFile, bool inContext) => throw new NotImplementedException();
4841
}
4942
}

csharp/ql/src/semmle/code/cil/CustomModifierReceiver.qll

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ private import CIL
66
private import dotnet
77

88
/**
9-
* A class to represent entities that can recive custom modifiers. Custom modifiers can be attached to
9+
* A class to represent entities that can receive custom modifiers. Custom modifiers can be attached to
1010
* - the type of a `Field`,
1111
* - the return type of a `Method` or `Property`,
1212
* - the type of parameters.
@@ -18,12 +18,4 @@ class CustomModifierReceiver extends Declaration, @cil_custom_modifier_receiver
1818

1919
/** Holds if this targeted type has `modifier` applied as `modopt`. */
2020
predicate hasOptionalCustomModifier(Type modifier) { cil_custom_modifiers(this, modifier, 0) }
21-
22-
/**
23-
* Holds if this targeted type has `modifier` applied as `kind`. `kind` 1 means `modreq`,
24-
* `kind` 0 represents `modopt`.
25-
*/
26-
predicate hasCustomModifier(Type modifier, int kind) {
27-
cil_custom_modifiers(this, modifier, kind)
28-
}
2921
}

csharp/ql/src/semmle/code/cil/Method.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ class Setter extends Accessor {
251251
/** Holds if this setter is an `init` accessor. */
252252
predicate isInitOnly() {
253253
exists(Type t | t.getQualifiedName() = "System.Runtime.CompilerServices.IsExternalInit" |
254-
cil_custom_modifiers(this, t, 1)
254+
this.hasRequiredCustomModifier(t)
255255
)
256256
}
257257
}

csharp/ql/test/library-tests/cil/init-only-prop/customModifiers.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ from string receiver, string modifier, int kind
77
where
88
exists(Type modType, CustomModifierReceiver cmr |
99
receiver = cmr.toString() and
10-
cmr.hasCustomModifier(modType, kind) and
10+
cil_custom_modifiers(cmr, modType, kind) and
1111
modType.getQualifiedName() = modifier
1212
)
1313
select receiver, modifier, getKind(kind)

0 commit comments

Comments
 (0)