|
| 1 | +private import unified |
| 2 | +private import codeql.util.ReportStats |
| 3 | +private import codeql.unified.internal.StaticNameBinding |
| 4 | +private import codeql.unified.internal.LocalNameBinding |
| 5 | +private import codeql.unified.internal.NameBindingPlugin |
| 6 | + |
| 7 | +/** Stats about identifiers that static name binding could resolve. */ |
| 8 | +module StaticNameResolutionStats implements EntityStatsSig { |
| 9 | + class Candidate extends Identifier { |
| 10 | + Candidate() { |
| 11 | + this = getIdentifierFromRef(_) and |
| 12 | + not this instanceof NameDeclaration |
| 13 | + // TODO: exclude names we know are not static references, e.g. unqualified instance-field access, |
| 14 | + // currently blocked on getting static name binding to report this information. |
| 15 | + } |
| 16 | + |
| 17 | + NameBindingNode getTarget() { |
| 18 | + ( |
| 19 | + exists(NameDeclaration decl | |
| 20 | + result.isIdentifier(decl) and |
| 21 | + trackNameDeclaration(decl).isIdentifier(this) |
| 22 | + ) |
| 23 | + or |
| 24 | + result.isModuleScopeNode(_) and |
| 25 | + result.(NamespaceNode).ref().isIdentifier(this) |
| 26 | + ) and |
| 27 | + // Do not consider a type extension to be a valid target |
| 28 | + // TODO: Fix in the AST mapping: type extensions should reference their type, not declare it |
| 29 | + not exists(ClassLikeDeclaration cls | |
| 30 | + cls.hasModifier("extension") and |
| 31 | + result.isIdentifier(cls.getName()) |
| 32 | + ) |
| 33 | + } |
| 34 | + |
| 35 | + predicate isOk() { exists(this.getTarget()) } |
| 36 | + } |
| 37 | + |
| 38 | + string getOkText() { result = "statically resolvable names" } |
| 39 | + |
| 40 | + string getNotOkText() { result = "statically unresolvable names" } |
| 41 | +} |
| 42 | + |
| 43 | +module StaticNameResolutionStatsReport = EntityReportStats<StaticNameResolutionStats>; |
| 44 | + |
| 45 | +/** Stats about which files are covered by a module manifest. */ |
| 46 | +module FilesCoveredByModuleManifestStats implements EntityStatsSig { |
| 47 | + class Candidate extends File { |
| 48 | + Candidate() { this.getExtension() = "swift" } |
| 49 | + |
| 50 | + ModuleScopeRepr getAModule() { result.getAnIncludedFile() = this } |
| 51 | + |
| 52 | + predicate isOk() { exists(this.getAModule()) } |
| 53 | + } |
| 54 | + |
| 55 | + string getOkText() { result = "files covered by a module manifest" } |
| 56 | + |
| 57 | + string getNotOkText() { result = "files not covered by any module manifest" } |
| 58 | +} |
| 59 | + |
| 60 | +module FilesCoveredByModuleManifestStatsReport = |
| 61 | + EntityReportStats<FilesCoveredByModuleManifestStats>; |
0 commit comments