|
| 1 | +/** |
| 2 | + * Defines entity discard predicates for Java overlay analysis. |
| 3 | + */ |
| 4 | +overlay[local?] |
| 5 | +module; |
| 6 | + |
| 7 | +import java |
| 8 | + |
| 9 | +/** |
| 10 | + * A local predicate that always holds for the overlay variant and |
| 11 | + * never holds for the base variant. This is used to define local |
| 12 | + * predicates that behave differently for the base and overlay variant. |
| 13 | + */ |
| 14 | +overlay[local] |
| 15 | +predicate isOverlay() { databaseMetadata("isOverlay", "true") } |
| 16 | + |
| 17 | +/** Gets the raw file for a locatable. */ |
| 18 | +overlay[local] |
| 19 | +string getRawFile(@locatable el) { |
| 20 | + exists(@location loc, @file file | |
| 21 | + hasLocation(el, loc) and |
| 22 | + locations_default(loc, file, _, _, _, _) and |
| 23 | + files(file, result) |
| 24 | + ) |
| 25 | +} |
| 26 | + |
| 27 | +/** Gets the raw file for a location. */ |
| 28 | +overlay[local] |
| 29 | +string getRawFileForLoc(@location l) { |
| 30 | + exists(@file f | locations_default(l, f, _, _, _, _) and files(f, result)) |
| 31 | +} |
| 32 | + |
| 33 | +/** Holds for files fully extracted in the overlay. */ |
| 34 | +overlay[local] |
| 35 | +predicate extractedInOverlay(string file) { |
| 36 | + isOverlay() and |
| 37 | + // numlines is used to restrict attention to fully extracted files and |
| 38 | + // ignore skeleton extracted files in the overlay |
| 39 | + exists(@locatable l | numlines(l, _, _, _) and file = getRawFile(l)) |
| 40 | +} |
| 41 | + |
| 42 | +/** |
| 43 | + * A `@locatable` that should be discarded in the base variant if its file is |
| 44 | + * extracted in the overlay variant. |
| 45 | + */ |
| 46 | +overlay[local] |
| 47 | +abstract class DiscardableLocatable extends @locatable { |
| 48 | + /** Gets the raw file for a locatable in base. */ |
| 49 | + string getRawFileInBase() { not isOverlay() and result = getRawFile(this) } |
| 50 | + |
| 51 | + /** Gets a textual representation of this discardable locatable. */ |
| 52 | + string toString() { none() } |
| 53 | +} |
| 54 | + |
| 55 | +overlay[discard_entity] |
| 56 | +private predicate discardLocatable(@locatable el) { |
| 57 | + extractedInOverlay(el.(DiscardableLocatable).getRawFileInBase()) |
| 58 | +} |
| 59 | + |
| 60 | +/** |
| 61 | + * A `@locatable` that should be discarded in the base variant if its file is |
| 62 | + * extracted in the overlay variant and it is itself not extracted in the |
| 63 | + * overlay, that is, it is deleted in the overlay. |
| 64 | + */ |
| 65 | +overlay[local] |
| 66 | +abstract class DiscardableReferableLocatable extends @locatable { |
| 67 | + /** Gets the raw file for a locatable in base. */ |
| 68 | + string getRawFileInBase() { not isOverlay() and result = getRawFile(this) } |
| 69 | + |
| 70 | + /** Holds if the locatable exists in the overlay. */ |
| 71 | + predicate existsInOverlay() { isOverlay() and exists(this) } |
| 72 | + |
| 73 | + /** Gets a textual representation of this discardable locatable. */ |
| 74 | + string toString() { none() } |
| 75 | +} |
| 76 | + |
| 77 | +overlay[discard_entity] |
| 78 | +private predicate discardReferableLocatable(@locatable el) { |
| 79 | + exists(DiscardableReferableLocatable drl | drl = el | |
| 80 | + extractedInOverlay(drl.getRawFileInBase()) and |
| 81 | + not drl.existsInOverlay() |
| 82 | + ) |
| 83 | +} |
0 commit comments