@@ -10,7 +10,7 @@ class ScriptBlock extends @script_block, Ast {
10
10
else result = "{...}"
11
11
}
12
12
13
- override SourceLocation getLocation ( ) { script_block_location ( this , result ) }
13
+ override Location getLocation ( ) { script_block_location ( this , result ) }
14
14
15
15
int getNumUsings ( ) { script_block ( this , result , _, _, _, _) }
16
16
@@ -51,6 +51,42 @@ class ScriptBlock extends @script_block, Ast {
51
51
ModuleSpecification getAModuleSpecification ( ) { result = this .getModuleSpecification ( _) }
52
52
53
53
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
+ }
54
90
}
55
91
56
92
/** A `process` block. */
@@ -69,3 +105,7 @@ class ProcessBlock extends NamedBlock {
69
105
result = scriptBlock .getEnclosingFunction ( ) .getAParameter ( )
70
106
}
71
107
}
108
+
109
+ class TopLevelScriptBlock extends ScriptBlock {
110
+ TopLevelScriptBlock ( ) { this .isTopLevel ( ) }
111
+ }
0 commit comments