@@ -2,7 +2,7 @@ private import codeql.actions.ast.internal.Actions
22private import codeql.Locations
33
44/**
5- * Base class for thejAST tree. Based on YamlNode from the Yaml library.
5+ * Base class for the AST tree. Based on YamlNode from the Yaml library.
66 */
77class AstNode instanceof YamlNode {
88 AstNode getParentNode ( ) { result = super .getParentNode ( ) }
@@ -23,7 +23,7 @@ class AstNode instanceof YamlNode {
2323 /**
2424 * Gets a environment variable expression by name in the scope of the current node.
2525 */
26- EnvExpr getEnvExpr ( string name ) {
26+ Expression getEnvExpr ( string name ) {
2727 exists ( Actions:: Env env |
2828 env .( YamlMapping ) .maps ( any ( YamlScalar s | s .getValue ( ) = name ) , result )
2929 |
@@ -42,9 +42,18 @@ class AstNode instanceof YamlNode {
4242class CompositeAction extends AstNode instanceof Actions:: CompositeAction {
4343 Runs getRuns ( ) { result = super .getRuns ( ) }
4444
45- Inputs getInputs ( ) { result = this .( YamlMapping ) .lookup ( "inputs" ) }
46-
4745 Outputs getOutputs ( ) { result = this .( YamlMapping ) .lookup ( "outputs" ) }
46+
47+ Expression getAnOutputExpr ( ) { result = this .getOutputs ( ) .getAnOutputExpr ( ) }
48+
49+ Expression getOutputExpr ( string name ) { result = this .getOutputs ( ) .getOutputExpr ( name ) }
50+
51+ Input getAnInput ( ) { this .( YamlMapping ) .lookup ( "inputs" ) .( YamlMapping ) .maps ( result , _) }
52+
53+ Input getInput ( string name ) {
54+ this .( YamlMapping ) .lookup ( "inputs" ) .( YamlMapping ) .maps ( result , _) and
55+ result .( YamlString ) .getValue ( ) = name
56+ }
4857}
4958
5059class Runs extends AstNode instanceof Actions:: Runs {
@@ -81,34 +90,43 @@ class ReusableWorkflow extends Workflow {
8190
8291 ReusableWorkflow ( ) { this .( Actions:: Workflow ) .getOn ( ) .getNode ( "workflow_call" ) = workflow_call }
8392
84- Inputs getInputs ( ) { result = workflow_call .( YamlMapping ) .lookup ( "inputs" ) }
85-
8693 Outputs getOutputs ( ) { result = workflow_call .( YamlMapping ) .lookup ( "outputs" ) }
87- }
8894
89- class Inputs extends AstNode instanceof YamlMapping {
90- YamlMapping parent ;
95+ Expression getAnOutputExpr ( ) { result = this .getOutputs ( ) .getAnOutputExpr ( ) }
9196
92- Inputs ( ) { parent . lookup ( "inputs" ) = this }
97+ Expression getOutputExpr ( string name ) { result = this . getOutputs ( ) . getOutputExpr ( name ) }
9398
94- /**
95- * Gets a specific input expression (YamlMapping) by name.
96- */
97- InputExpr getInputExpr ( string name ) {
98- result .( YamlString ) .getValue ( ) = name and
99- this .( YamlMapping ) .maps ( result , _)
99+ Input getAnInput ( ) { workflow_call .( YamlMapping ) .lookup ( "inputs" ) .( YamlMapping ) .maps ( result , _) }
100+
101+ Input getInput ( string name ) {
102+ workflow_call .( YamlMapping ) .lookup ( "inputs" ) .( YamlMapping ) .maps ( result , _) and
103+ result .( YamlString ) .getValue ( ) = name
100104 }
101105}
102106
107+ class Input extends AstNode {
108+ YamlMapping parent ;
109+
110+ Input ( ) { parent .lookup ( "inputs" ) .( YamlMapping ) .maps ( this , _) }
111+ }
112+
103113class Outputs extends AstNode instanceof YamlMapping {
104114 YamlMapping parent ;
105115
106116 Outputs ( ) { parent .lookup ( "outputs" ) = this }
107117
108118 /**
109- * Gets a specific output expression (YamlMapping) by name.
119+ * Gets an output expression.
120+ */
121+ Expression getAnOutputExpr ( ) {
122+ this .( YamlMapping ) .lookup ( _) .( YamlMapping ) .lookup ( "value" ) = result or
123+ this .( YamlMapping ) .lookup ( _) = result
124+ }
125+
126+ /**
127+ * Gets a specific output expression by name.
110128 */
111- OutputExpr getOutputExpr ( string name ) {
129+ Expression getOutputExpr ( string name ) {
112130 this .( YamlMapping ) .lookup ( name ) .( YamlMapping ) .lookup ( "value" ) = result or
113131 this .( YamlMapping ) .lookup ( name ) = result
114132 }
@@ -130,7 +148,7 @@ class Strategy extends AstNode instanceof YamlMapping {
130148 /**
131149 * Gets a specific matric expression (YamlMapping) by name.
132150 */
133- MatrixVariableExpr getMatrixVariableExpr ( string name ) {
151+ Expression getMatrixVariableExpr ( string name ) {
134152 this .( YamlMapping ) .lookup ( "matrix" ) .( YamlMapping ) .lookup ( name ) = result
135153 }
136154
@@ -318,41 +336,40 @@ class Run extends Step {
318336 string getScript ( ) { result = scriptExpr .getValue ( ) }
319337}
320338
321- /**
322- * An AST node associated with a Reusable Workflow input.
323- */
324- class InputExpr extends AstNode {
325- InputExpr ( ) { exists ( Inputs inputs | inputs .( YamlMapping ) .maps ( this , _) ) }
326- }
327-
328- /**
329- * An AST node holding an Env var value.
330- */
331- class EnvExpr extends AstNode {
332- EnvExpr ( ) { exists ( Actions:: Env env | env .( YamlMapping ) .lookup ( _) = this ) }
333- }
334-
335- /**
336- * An AST node holding a job or workflow output var.
337- */
338- class OutputExpr extends AstNode {
339- OutputExpr ( ) {
340- exists ( Outputs outputs |
341- outputs .( YamlMapping ) .lookup ( _) .( YamlMapping ) .lookup ( "value" ) = this or
342- outputs .( YamlMapping ) .lookup ( _) = this
343- )
344- }
345- }
346-
347- /**
348- * An AST node holding a matrix var.
349- */
350- class MatrixVariableExpr extends AstNode {
351- MatrixVariableExpr ( ) {
352- exists ( Strategy outputs | outputs .( YamlMapping ) .lookup ( "matrix" ) .( YamlMapping ) .lookup ( _) = this )
353- }
354- }
355-
339+ // /**
340+ // * An AST node associated with a Reusable Workflow input.
341+ // */
342+ // class InputExpr extends AstNode {
343+ // InputExpr() { exists(Inputs inputs | inputs.(YamlMapping).maps(this, _)) }
344+ // }
345+ //
346+ // /**
347+ // * An AST node holding an Env var value.
348+ // */
349+ // class EnvExpr extends AstNode {
350+ // EnvExpr() { exists(Actions::Env env | env.(YamlMapping).lookup(_) = this) }
351+ // }
352+ //
353+ // /**
354+ // * An AST node holding a job or workflow output var.
355+ // */
356+ // class OutputExpr extends AstNode {
357+ // OutputExpr() {
358+ // exists(Outputs outputs |
359+ // outputs.(YamlMapping).lookup(_).(YamlMapping).lookup("value") = this or
360+ // outputs.(YamlMapping).lookup(_) = this
361+ // )
362+ // }
363+ // }
364+ //
365+ // /**
366+ // * An AST node holding a matrix var.
367+ // */
368+ // class MatrixVariableExpr extends AstNode {
369+ // MatrixVariableExpr() {
370+ // exists(Strategy outputs | outputs.(YamlMapping).lookup("matrix").(YamlMapping).lookup(_) = this)
371+ // }
372+ // }
356373/**
357374 * Evaluation of a workflow expression ${{}}.
358375 */
@@ -508,9 +525,9 @@ class InputsExpression extends ContextExpression {
508525 override AstNode getTarget ( ) {
509526 result .getLocation ( ) .getFile ( ) = this .getLocation ( ) .getFile ( ) and
510527 (
511- exists ( ReusableWorkflow w | w .getInputs ( ) . getInputExpr ( fieldName ) = result )
528+ exists ( ReusableWorkflow w | w .getInput ( fieldName ) = result )
512529 or
513- exists ( CompositeAction a | a .getInputs ( ) . getInputExpr ( fieldName ) = result )
530+ exists ( CompositeAction a | a .getInput ( fieldName ) = result )
514531 )
515532 }
516533}
0 commit comments