@@ -10,7 +10,7 @@ class ScriptBlock extends @script_block, Ast {
1010 else result = "{...}"
1111 }
1212
13- override SourceLocation getLocation ( ) { script_block_location ( this , result ) }
13+ override Location getLocation ( ) { script_block_location ( this , result ) }
1414
1515 int getNumUsings ( ) { script_block ( this , result , _, _, _, _) }
1616
@@ -51,6 +51,42 @@ class ScriptBlock extends @script_block, Ast {
5151 ModuleSpecification getAModuleSpecification ( ) { result = this .getModuleSpecification ( _) }
5252
5353 final override Scope getEnclosingScope ( ) { result = this }
54+
55+ /**
56+ * Gets the `i`'th paramter in this scope.
57+ *
58+ * This may be both function paramters and parameter block parameters.
59+ */
60+ Parameter getParameter ( int i ) {
61+ exists ( Function func |
62+ func .getBody ( ) = this and
63+ result = func .getParameter ( i )
64+ )
65+ or
66+ this .isTopLevel ( ) and
67+ result = this .getParamBlock ( ) .getParameter ( i )
68+ }
69+
70+ /**
71+ * Gets a paramter in this scope.
72+ *
73+ * This may be both function parameters and parameter block parameters.
74+ */
75+ Parameter getAParameter ( ) { result = this .getParameter ( _) }
76+
77+ Parameter getThisParameter ( ) {
78+ exists ( Function func |
79+ func .getBody ( ) = this and
80+ result = func .getThisParameter ( )
81+ )
82+ }
83+
84+ /** Gets the number of function parameters. */
85+ final int getNumberOfParameters ( ) { result = count ( this .getAParameter ( ) ) }
86+
87+ final Parameter getParameterExcludingPiplines ( int i ) {
88+ result = this .getParamBlock ( ) .getParameterExcludingPiplines ( i )
89+ }
5490}
5591
5692/** A `process` block. */
@@ -69,3 +105,7 @@ class ProcessBlock extends NamedBlock {
69105 result = scriptBlock .getEnclosingFunction ( ) .getAParameter ( )
70106 }
71107}
108+
109+ class TopLevelScriptBlock extends ScriptBlock {
110+ TopLevelScriptBlock ( ) { this .isTopLevel ( ) }
111+ }
0 commit comments