1- /**
2- * Defines entity discard predicates for C++ overlay analysis.
3- *
4- * The discard strategy is based on TRAP file and tag tracking rather than
5- * source locations. The extractor records which TRAP file or tag each element
6- * is defined in (`in_trap_or_tag`), which source files use which TRAP files
7- * (`source_file_uses_trap`), and which TRAP files use which tags
8- * (`trap_uses_tag`). These relations allow us to precisely determine whether
9- * a base element should be discarded or retained in the combined database.
10- */
11-
121private import OverlayXml
132
143/**
154 * Holds always for the overlay variant and never for the base variant.
16- * This local predicate is used to define local predicates that behave
17- * differently for the base and overlay variant.
185 */
196overlay [ local]
207predicate isOverlay ( ) { databaseMetadata ( "isOverlay" , "true" ) }
218
229/**
2310 * Holds if TRAP file or tag `t` is reachable from a source file named
2411 * `source_file` in the given variant (base or overlay).
25- *
26- * A TRAP file is directly reachable from its source file. A tag is reachable
27- * if the TRAP file that uses it is reachable.
2812 */
2913overlay [ local]
30- private predicate locallyReachableTrapOrTag (
31- boolean isOverlayVariant , string source_file , @trap_or_tag t
32- ) {
14+ private predicate locally_reachable_trap_or_tag ( boolean is_overlay , string source_file , @trap_or_tag t ) {
3315 exists ( @source_file sf , string source_file_raw , @trap trap |
34- ( if isOverlay ( ) then isOverlayVariant = true else isOverlayVariant = false ) and
16+ ( if isOverlay ( ) then is_overlay = true else is_overlay = false ) and
3517 source_file_uses_trap ( sf , trap ) and
3618 source_file_name ( sf , source_file_raw ) and
3719 source_file = source_file_raw .replaceAll ( "\\" , "/" ) and
@@ -44,39 +26,36 @@ private predicate locallyReachableTrapOrTag(
4426 * variant (base or overlay).
4527 */
4628overlay [ local]
47- private predicate locallyInTrapOrTag ( boolean isOverlayVariant , @element e , @trap_or_tag t ) {
48- ( if isOverlay ( ) then isOverlayVariant = true else isOverlayVariant = false ) and
29+ private predicate locally_in_trap_or_tag ( boolean is_overlay , @element e , @trap_or_tag t ) {
30+ ( if isOverlay ( ) then is_overlay = true else is_overlay = false ) and
4931 in_trap_or_tag ( e , t )
5032}
5133
5234/**
53- * Discards an element from the base variant if:
54- * - It is known to be in a base TRAP file or tag, and
55- * - It is not reachable from any overlay source file, and
56- * - Every base source file that reaches it has either changed or had its TRAP
57- * file redefined by the overlay.
35+ * Holds if element `e` from the base variant should be discarded because
36+ * it has been redefined or is no longer reachable in the overlay.
5837 */
5938overlay [ discard_entity]
60- private predicate discardElement ( @element e ) {
39+ private predicate discard_element ( @element e ) {
6140 // If we don't have any knowledge about what TRAP file something
6241 // is in, then we don't want to discard it, so we only consider
6342 // entities that are known to be in a base TRAP file.
64- locallyInTrapOrTag ( false , e , _) and
43+ locally_in_trap_or_tag ( false , e , _) and
6544 // Anything that is reachable from an overlay source file should
6645 // not be discarded.
67- not exists ( @trap_or_tag t | locallyInTrapOrTag ( true , e , t ) |
68- locallyReachableTrapOrTag ( true , _, t )
46+ not exists ( @trap_or_tag t | locally_in_trap_or_tag ( true , e , t ) |
47+ locally_reachable_trap_or_tag ( true , _, t )
6948 ) and
7049 // Finally, we have to make sure that base shouldn't retain it.
7150 // If it is reachable from a base source file, then that is
7251 // sufficient unless either the base source file has changed (in
7352 // particular, been deleted) or the overlay has redefined the TRAP
7453 // file it is in.
7554 forall ( @trap_or_tag t , string source_file |
76- locallyInTrapOrTag ( false , e , t ) and
77- locallyReachableTrapOrTag ( false , source_file , t )
55+ locally_in_trap_or_tag ( false , e , t ) and
56+ locally_reachable_trap_or_tag ( false , source_file , t )
7857 |
7958 overlayChangedFiles ( source_file ) or
80- locallyReachableTrapOrTag ( true , _, t )
59+ locally_reachable_trap_or_tag ( true , _, t )
8160 )
8261}
0 commit comments