|
| 1 | +/** |
| 2 | + * @name Fetch a subset of valid access paths of input and output parameters of a method (framework mode). |
| 3 | + * @description A list of access paths for input and output parameters of a method. Excludes test and generated code. |
| 4 | + * @kind table |
| 5 | + * @id ruby/utils/modeleditor/framework-mode-access-paths |
| 6 | + * @tags modeleditor access-paths framework-mode |
| 7 | + */ |
| 8 | + |
| 9 | +private import ruby |
| 10 | +private import codeql.ruby.ApiGraphs |
| 11 | +private import queries.modeling.internal.Util as Util |
| 12 | + |
| 13 | +predicate simpleParameters(string type, string path, string value, string details) { |
| 14 | + exists(DataFlow::MethodNode methodNode, DataFlow::ParameterNode paramNode | |
| 15 | + methodNode.getLocation().getFile() instanceof Util::RelevantFile and |
| 16 | + ( |
| 17 | + // Check that this parameter belongs to this method |
| 18 | + // Block parameter explicitly excluded because it's already included |
| 19 | + // as part of the blockArguments predicate |
| 20 | + paramNode = Util::getAnyParameter(methodNode) and |
| 21 | + paramNode != methodNode.getBlockParameter() |
| 22 | + ) |
| 23 | + | |
| 24 | + Util::pathToMethod(methodNode, type, path) and |
| 25 | + value = Util::getArgumentPath(paramNode) and |
| 26 | + details = paramNode.toString() |
| 27 | + ) |
| 28 | +} |
| 29 | + |
| 30 | +predicate blockArguments(string type, string path, string value, string details) { |
| 31 | + exists(DataFlow::MethodNode methodNode, DataFlow::CallNode callNode | |
| 32 | + methodNode.getLocation().getFile() instanceof Util::RelevantFile and |
| 33 | + callNode = methodNode.getABlockCall() |
| 34 | + | |
| 35 | + ( |
| 36 | + exists(DataFlow::ExprNode argNode, int i | argNode = callNode.getPositionalArgument(i) | |
| 37 | + value = "Argument[block].Parameter[" + i + "]" and |
| 38 | + details = argNode.toString() |
| 39 | + ) |
| 40 | + or |
| 41 | + exists(DataFlow::ExprNode argNode, string keyword | |
| 42 | + argNode = callNode.getKeywordArgument(keyword) |
| 43 | + | |
| 44 | + value = "Argument[block].Parameter[" + keyword + ":]" and |
| 45 | + details = ":" + keyword |
| 46 | + ) |
| 47 | + or |
| 48 | + value = "Argument[block]" and details = callNode.toString() |
| 49 | + ) and |
| 50 | + Util::pathToMethod(methodNode, type, path) |
| 51 | + ) |
| 52 | +} |
| 53 | + |
| 54 | +predicate returnValue(string type, string path, string value, string details) { |
| 55 | + exists(DataFlow::MethodNode methodNode, DataFlow::Node returnNode | |
| 56 | + methodNode.getLocation().getFile() instanceof Util::RelevantFile and |
| 57 | + returnNode = methodNode.getAReturnNode() |
| 58 | + | |
| 59 | + Util::pathToMethod(methodNode, type, path) and |
| 60 | + value = "ReturnValue" and |
| 61 | + details = returnNode.toString() |
| 62 | + ) |
| 63 | +} |
| 64 | + |
| 65 | +predicate inputSuggestions(string type, string path, string value, string details, string defType) { |
| 66 | + simpleParameters(type, path, value, details) and defType = "parameter" |
| 67 | + or |
| 68 | + blockArguments(type, path, value, details) and defType = "parameter" |
| 69 | +} |
| 70 | + |
| 71 | +predicate outputSuggestions(string type, string path, string value, string details, string defType) { |
| 72 | + simpleParameters(type, path, value, details) and defType = "parameter" |
| 73 | + or |
| 74 | + blockArguments(type, path, value, details) and defType = "parameter" |
| 75 | + or |
| 76 | + returnValue(type, path, value, details) and defType = "return" |
| 77 | +} |
| 78 | + |
| 79 | +query predicate input = inputSuggestions/5; |
| 80 | + |
| 81 | +query predicate output = outputSuggestions/5; |
0 commit comments