C#: Include store steps into readonly properties.

This commit is contained in:
Michael Nebel
2024-02-19 13:16:39 +01:00
parent 3112bf4682
commit e4d41194b4
2 changed files with 25 additions and 5 deletions

View File

@@ -127,6 +127,13 @@ class Property extends DotNet::Property, DeclarationWithGetSetAccessors, @proper
properties(this, _, _, getTypeRef(result), _)
}
private predicate isAutoPartial() {
this.fromSource() and
not this.isExtern() and
not this.isAbstract() and
not this.getAnAccessor().hasBody()
}
/**
* Holds if this property is automatically implemented. For example, `P1`
* on line 2 is automatically implemented, while `P2` on line 5 is not in
@@ -147,11 +154,22 @@ class Property extends DotNet::Property, DeclarationWithGetSetAccessors, @proper
* code.
*/
predicate isAutoImplemented() {
this.fromSource() and
this.isReadWrite() and
not this.isExtern() and
not this.isAbstract() and
not this.getAnAccessor().hasBody()
this.isAutoPartial() and
this.isReadWrite()
}
/**
* Holds if this property is automatically implemented and read-only. For
* example, `P1` on line 2 is automatically implemented and read-only
* ```csharp
* class C {
* public int P1 { get; }
* }
* ```
*/
predicate isAutoImplementedReadOnly() {
this.isAutoPartial() and
this.isReadOnly()
}
override Property getUnboundDeclaration() { properties(this, _, _, _, result) }

View File

@@ -1899,6 +1899,8 @@ class FieldOrProperty extends Assignable, Modifiable {
(
p.isAutoImplemented()
or
p.isAutoImplementedReadOnly()
or
p.matchesHandle(any(CIL::TrivialProperty tp))
or
p.getDeclaringType() instanceof AnonymousClass