|
| 1 | +private import swift |
| 2 | +private import DataFlowPrivate |
| 3 | + |
| 4 | +newtype TReturnKind = TNormalReturnKind() |
| 5 | + |
| 6 | +/** |
| 7 | + * Gets a node that can read the value returned from `call` with return kind |
| 8 | + * `kind`. |
| 9 | + */ |
| 10 | +OutNode getAnOutNode(DataFlowCall call, ReturnKind kind) { call = result.getCall(kind) } |
| 11 | + |
| 12 | +/** |
| 13 | + * A return kind. A return kind describes how a value can be returned |
| 14 | + * from a callable. |
| 15 | + */ |
| 16 | +abstract class ReturnKind extends TReturnKind { |
| 17 | + /** Gets a textual representation of this position. */ |
| 18 | + abstract string toString(); |
| 19 | +} |
| 20 | + |
| 21 | +/** |
| 22 | + * A value returned from a callable using a `return` statement or an expression |
| 23 | + * body, that is, a "normal" return. |
| 24 | + */ |
| 25 | +class NormalReturnKind extends ReturnKind, TNormalReturnKind { |
| 26 | + override string toString() { result = "return" } |
| 27 | +} |
| 28 | + |
| 29 | +/** |
| 30 | + * A callable. This includes callables from source code, as well as callables |
| 31 | + * defined in library code. |
| 32 | + */ |
| 33 | +class DataFlowCallable extends TDataFlowCallable { |
| 34 | + /** Gets a textual representation of this callable. */ |
| 35 | + string toString() { none() } |
| 36 | + |
| 37 | + /** Gets the location of this callable. */ |
| 38 | + Location getLocation() { none() } |
| 39 | +} |
| 40 | + |
| 41 | +/** |
| 42 | + * A call. This includes calls from source code, as well as call(back)s |
| 43 | + * inside library callables with a flow summary. |
| 44 | + */ |
| 45 | +class DataFlowCall extends TDataFlowCall { |
| 46 | + /** Gets the enclosing callable. */ |
| 47 | + DataFlowCallable getEnclosingCallable() { none() } |
| 48 | + |
| 49 | + /** Gets a textual representation of this call. */ |
| 50 | + string toString() { none() } |
| 51 | + |
| 52 | + /** Gets the location of this call. */ |
| 53 | + Location getLocation() { none() } |
| 54 | + |
| 55 | + /** |
| 56 | + * Holds if this element is at the specified location. |
| 57 | + * The location spans column `startcolumn` of line `startline` to |
| 58 | + * column `endcolumn` of line `endline` in file `filepath`. |
| 59 | + * For more information, see |
| 60 | + * [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries). |
| 61 | + */ |
| 62 | + predicate hasLocationInfo( |
| 63 | + string filepath, int startline, int startcolumn, int endline, int endcolumn |
| 64 | + ) { |
| 65 | + this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +cached |
| 70 | +private module Cached { |
| 71 | + cached |
| 72 | + newtype TDataFlowCallable = TODO_TDataFlowCallable() |
| 73 | + |
| 74 | + cached |
| 75 | + newtype TDataFlowCall = TODO_TDataFlowCall() |
| 76 | + |
| 77 | + /** Gets a viable run-time target for the call `call`. */ |
| 78 | + cached |
| 79 | + DataFlowCallable viableCallable(DataFlowCall call) { none() } |
| 80 | + |
| 81 | + cached |
| 82 | + newtype TArgumentPosition = TODO_TArgumentPosition() |
| 83 | + |
| 84 | + cached |
| 85 | + newtype TParameterPosition = TODO_TParameterPosition() |
| 86 | +} |
| 87 | + |
| 88 | +import Cached |
| 89 | + |
| 90 | +/** |
| 91 | + * Holds if the set of viable implementations that can be called by `call` |
| 92 | + * might be improved by knowing the call context. |
| 93 | + */ |
| 94 | +predicate mayBenefitFromCallContext(DataFlowCall call, DataFlowCallable c) { none() } |
| 95 | + |
| 96 | +/** |
| 97 | + * Gets a viable dispatch target of `call` in the context `ctx`. This is |
| 98 | + * restricted to those `call`s for which a context might make a difference. |
| 99 | + */ |
| 100 | +DataFlowCallable viableImplInCallContext(DataFlowCall call, DataFlowCall ctx) { none() } |
| 101 | + |
| 102 | +/** A parameter position. */ |
| 103 | +class ParameterPosition extends TParameterPosition { |
| 104 | + /** Gets a textual representation of this position. */ |
| 105 | + string toString() { none() } |
| 106 | +} |
| 107 | + |
| 108 | +/** An argument position. */ |
| 109 | +class ArgumentPosition extends TArgumentPosition { |
| 110 | + /** Gets a textual representation of this position. */ |
| 111 | + string toString() { none() } |
| 112 | +} |
| 113 | + |
| 114 | +/** Holds if arguments at position `apos` match parameters at position `ppos`. */ |
| 115 | +pragma[inline] |
| 116 | +predicate parameterMatch(ParameterPosition ppos, ArgumentPosition apos) { none() } |
0 commit comments