|
| 1 | +/** |
| 2 | + * Defines entity discard predicates for C++ overlay analysis. |
| 3 | + */ |
| 4 | + |
| 5 | +/** |
| 6 | + * Holds always for the overlay variant and never for the base variant. |
| 7 | + * This local predicate is used to define local predicates that behave |
| 8 | + * differently for the base and overlay variant. |
| 9 | + */ |
| 10 | +overlay[local] |
| 11 | +predicate isOverlay() { databaseMetadata("isOverlay", "true") } |
| 12 | + |
| 13 | +overlay[local] |
| 14 | +private string getLocationFilePath(@location_default loc) { |
| 15 | + exists(@file file | locations_default(loc, file, _, _, _, _) | files(file, result)) |
| 16 | +} |
| 17 | + |
| 18 | +/** |
| 19 | + * Gets the file path for an element with a single location. |
| 20 | + */ |
| 21 | +overlay[local] |
| 22 | +private string getSingleLocationFilePath(@element e) { |
| 23 | + // @var_decl has a direct location in the var_decls relation |
| 24 | + exists(@location_default loc | var_decls(e, _, _, _, loc) | result = getLocationFilePath(loc)) |
| 25 | + //TODO: add other kinds of elements with single locations |
| 26 | +} |
| 27 | + |
| 28 | +/** |
| 29 | + * Gets the file path for an element with potentially multiple locations. |
| 30 | + */ |
| 31 | +overlay[local] |
| 32 | +private string getMultiLocationFilePath(@element e) { |
| 33 | + // @variable gets its location(s) from its @var_decl(s) |
| 34 | + exists(@var_decl vd, @location_default loc | var_decls(vd, e, _, _, loc) | |
| 35 | + result = getLocationFilePath(loc) |
| 36 | + ) |
| 37 | + //TODO: add other kinds of elements with multiple locations |
| 38 | +} |
| 39 | + |
| 40 | +/** |
| 41 | + * A local helper predicate that holds in the base variant and never in the |
| 42 | + * overlay variant. |
| 43 | + */ |
| 44 | +overlay[local] |
| 45 | +private predicate holdsInBase() { not isOverlay() } |
| 46 | + |
| 47 | +/** |
| 48 | + * Discards an element from the base variant if: |
| 49 | + * - It has a single location in a changed file, or |
| 50 | + * - All of its locations are in changed files. |
| 51 | + */ |
| 52 | +overlay[discard_entity] |
| 53 | +private predicate discardElement(@element e) { |
| 54 | + holdsInBase() and |
| 55 | + ( |
| 56 | + overlayChangedFiles(getSingleLocationFilePath(e)) |
| 57 | + or |
| 58 | + forex(string path | path = getMultiLocationFilePath(e) | overlayChangedFiles(path)) |
| 59 | + ) |
| 60 | +} |
0 commit comments