@@ -2093,8 +2093,8 @@ private Field getAFieldWithSize(Union u, int bytes) {
20932093
20942094cached
20952095private newtype TContent =
2096- TFieldContent ( Field f , int indirectionIndex ) {
2097- // the indirection index for field content starts at 1 (because `TFieldContent ` is thought of as
2096+ TNonUnionContent ( Field f , int indirectionIndex ) {
2097+ // the indirection index for field content starts at 1 (because `TNonUnionContent ` is thought of as
20982098 // the address of the field, `FieldAddress` in the IR).
20992099 indirectionIndex = [ 1 .. SsaImpl:: getMaxIndirectionsForType ( f .getUnspecifiedType ( ) ) ] and
21002100 // Reads and writes of union fields are tracked using `UnionContent`.
@@ -2124,14 +2124,14 @@ private newtype TContent =
21242124 */
21252125class Content extends TContent {
21262126 /** Gets a textual representation of this element. */
2127- abstract string toString ( ) ;
2127+ string toString ( ) { none ( ) } // overridden in subclasses
21282128
21292129 predicate hasLocationInfo ( string path , int sl , int sc , int el , int ec ) {
21302130 path = "" and sl = 0 and sc = 0 and el = 0 and ec = 0
21312131 }
21322132
21332133 /** Gets the indirection index of this `Content`. */
2134- abstract int getIndirectionIndex ( ) ;
2134+ int getIndirectionIndex ( ) { none ( ) } // overridden in subclasses
21352135
21362136 /**
21372137 * INTERNAL: Do not use.
@@ -2142,7 +2142,7 @@ class Content extends TContent {
21422142 * For example, a write to a field `f` implies that any content of
21432143 * the form `*f` is also cleared.
21442144 */
2145- abstract predicate impliesClearOf ( Content c ) ;
2145+ predicate impliesClearOf ( Content c ) { none ( ) } // overridden in subclasses
21462146}
21472147
21482148/**
@@ -2162,22 +2162,42 @@ private module ContentStars {
21622162
21632163private import ContentStars
21642164
2165- /** A reference through a non-union instance field. */
2165+ private class TFieldContent = TNonUnionContent or TUnionContent ;
2166+
2167+ /**
2168+ * A `Content` that references a `Field`. This may be a field of a `struct`,
2169+ * `class`, or `union`. In the case of a `union` there may be multiple fields
2170+ * associated with the same `Content`.
2171+ */
21662172class FieldContent extends Content , TFieldContent {
2173+ /** Gets a `Field` of this `Content`. */
2174+ Field getAField ( ) { none ( ) }
2175+
2176+ /**
2177+ * Gets the field associated with this `Content`, if a unique one exists.
2178+ */
2179+ final Field getField ( ) { result = unique( | | this .getAField ( ) ) }
2180+
2181+ override int getIndirectionIndex ( ) { none ( ) } // overridden in subclasses
2182+
2183+ override string toString ( ) { none ( ) } // overridden in subclasses
2184+
2185+ override predicate impliesClearOf ( Content c ) { none ( ) } // overridden in subclasses
2186+ }
2187+
2188+ /** A reference through a non-union instance field. */
2189+ class NonUnionFieldContent extends FieldContent , TNonUnionContent {
21672190 private Field f ;
21682191 private int indirectionIndex ;
21692192
2170- FieldContent ( ) { this = TFieldContent ( f , indirectionIndex ) }
2193+ NonUnionFieldContent ( ) { this = TNonUnionContent ( f , indirectionIndex ) }
21712194
21722195 override string toString ( ) { result = contentStars ( this ) + f .toString ( ) }
21732196
2174- Field getField ( ) { result = f }
2197+ override Field getAField ( ) { result = f }
21752198
21762199 /** Gets the indirection index of this `FieldContent`. */
2177- pragma [ inline]
2178- override int getIndirectionIndex ( ) {
2179- pragma [ only_bind_into ] ( result ) = pragma [ only_bind_out ] ( indirectionIndex )
2180- }
2200+ override int getIndirectionIndex ( ) { result = indirectionIndex }
21812201
21822202 override predicate impliesClearOf ( Content c ) {
21832203 exists ( FieldContent fc |
@@ -2191,7 +2211,7 @@ class FieldContent extends Content, TFieldContent {
21912211}
21922212
21932213/** A reference through an instance field of a union. */
2194- class UnionContent extends Content , TUnionContent {
2214+ class UnionContent extends FieldContent , TUnionContent {
21952215 private Union u ;
21962216 private int indirectionIndex ;
21972217 private int bytes ;
@@ -2201,16 +2221,13 @@ class UnionContent extends Content, TUnionContent {
22012221 override string toString ( ) { result = contentStars ( this ) + u .toString ( ) }
22022222
22032223 /** Gets a field of the underlying union of this `UnionContent`, if any. */
2204- Field getAField ( ) { result = u .getAField ( ) and getFieldSize ( result ) = bytes }
2224+ override Field getAField ( ) { result = u .getAField ( ) and getFieldSize ( result ) = bytes }
22052225
22062226 /** Gets the underlying union of this `UnionContent`. */
22072227 Union getUnion ( ) { result = u }
22082228
22092229 /** Gets the indirection index of this `UnionContent`. */
2210- pragma [ inline]
2211- override int getIndirectionIndex ( ) {
2212- pragma [ only_bind_into ] ( result ) = pragma [ only_bind_out ] ( indirectionIndex )
2213- }
2230+ override int getIndirectionIndex ( ) { result = indirectionIndex }
22142231
22152232 override predicate impliesClearOf ( Content c ) {
22162233 exists ( UnionContent uc |
@@ -2234,10 +2251,7 @@ class ElementContent extends Content, TElementContent {
22342251
22352252 ElementContent ( ) { this = TElementContent ( indirectionIndex ) }
22362253
2237- pragma [ inline]
2238- override int getIndirectionIndex ( ) {
2239- pragma [ only_bind_into ] ( result ) = pragma [ only_bind_out ] ( indirectionIndex )
2240- }
2254+ override int getIndirectionIndex ( ) { result = indirectionIndex }
22412255
22422256 override predicate impliesClearOf ( Content c ) { none ( ) }
22432257
0 commit comments