11private import binary
22
3+ class CilField extends @field {
4+ string toString ( ) { result = this .getName ( ) }
5+
6+ string getName ( ) { fields ( this , result , _) }
7+
8+ CilType getDeclaringType ( ) { fields ( this , _, result ) }
9+
10+ Location getLocation ( ) { none ( ) } // TODO: Extract
11+ }
12+
313/**
414 * A CIL type (class, struct, interface, etc.).
515 */
@@ -18,6 +28,9 @@ class CilType extends @type {
1828 /** Gets a method declared in this type. */
1929 CilMethod getAMethod ( ) { result .getDeclaringType ( ) = this }
2030
31+ /** Gets a field declared by this type. */
32+ CilField getAField ( ) { result .getDeclaringType ( ) = this }
33+
2134 Location getLocation ( ) { none ( ) } // TODO: Extract
2235}
2336
@@ -625,14 +638,33 @@ class CilLdsfld extends @il_ldsfld, CilLoadFieldInstruction { }
625638/** An instruction that loads the address of a static field. */
626639class CilLdsflda extends @il_ldsflda, CilLoadFieldInstruction { }
627640
641+ pragma [ nomagic]
642+ private predicate fieldHasDeclaringTypeNameAndName (
643+ string declaringTypeName , string fieldName , CilField f
644+ ) {
645+ f .getDeclaringType ( ) .getFullName ( ) = declaringTypeName and
646+ f .getName ( ) = fieldName
647+ }
648+
628649/** An instruction that stores a value to a field. */
629- abstract class CilStoreFieldInstruction extends CilInstruction { }
650+ abstract class CilStoreFieldInstruction extends CilInstruction {
651+ CilField getField ( ) {
652+ exists ( string declaringTypeName , string fieldName |
653+ il_field_operand ( this , declaringTypeName , fieldName ) and
654+ fieldHasDeclaringTypeNameAndName ( declaringTypeName , fieldName , result )
655+ )
656+ }
657+
658+ predicate isStatic ( ) { none ( ) }
659+ }
630660
631661/** An instruction that stores a value to an instance field. */
632662class CilStfld extends @il_stfld, CilStoreFieldInstruction { }
633663
634664/** An instruction that stores a value to a static field. */
635- class CilStsfld extends @il_stsfld, CilStoreFieldInstruction { }
665+ class CilStsfld extends @il_stsfld, CilStoreFieldInstruction {
666+ final override predicate isStatic ( ) { any ( ) }
667+ }
636668
637669class CilStobj extends @il_stobj, CilInstruction { }
638670
0 commit comments