@@ -54,3 +54,39 @@ private predicate discardLocatable(@locatable locatable) {
5454 discardableLocatable ( file , locatable ) and discardableFile ( path )
5555 )
5656}
57+
58+ /**
59+ * Holds if the given `structtype` should be discarded, because it is part of
60+ * the overlay base and is only defined in files that were extracted as part of
61+ * the overlay database.
62+ *
63+ * Note that struct types use structural typing. In other words, two different
64+ * files can define defined types whose underlying types are struct types with
65+ * the same fields (names, types and tags), and they will be considered to be
66+ * the exact same struct type.
67+ */
68+ private predicate discardableStructType ( @structtype structtype ) {
69+ not isOverlay ( ) and
70+ forex ( @definedtype dt , @typeobject to , @ident declIdent , string path |
71+ underlying_type ( dt , structtype ) and
72+ type_objects ( dt , to ) and
73+ defs ( declIdent , to ) and
74+ files ( getFile ( declIdent ) , path )
75+ |
76+ discardableFile ( path )
77+ )
78+ }
79+
80+ overlay [ discard_entity]
81+ private predicate discardStructType ( @structtype structtype ) { discardableStructType ( structtype ) }
82+
83+ /**
84+ * Holds if the given `field` should be discarded, because it is defined in a
85+ * struct type which should be discarded.
86+ */
87+ overlay [ discard_entity]
88+ private predicate discardField ( @varobject field ) {
89+ exists ( @structtype structtype | fieldstructs ( field , structtype ) |
90+ discardableStructType ( structtype )
91+ )
92+ }
0 commit comments