@@ -2,32 +2,58 @@ import powershell
2
2
import semmle.code.powershell.controlflow.BasicBlocks
3
3
4
4
abstract private class AbstractFunction extends Ast {
5
+ /** Gets the name of this function. */
5
6
abstract string getName ( ) ;
6
7
8
+ /** Holds if this function has name `name`. */
7
9
final predicate hasName ( string name ) { this .getName ( ) = name }
8
10
11
+ /** Gets the body of this function. */
9
12
abstract ScriptBlock getBody ( ) ;
10
13
14
+ /**
15
+ * Gets the i'th function parameter, if any.
16
+ *
17
+ * Note that this predicate only returns _function_ parameters.
18
+ * To also get _block_ parameters use the `getParameter` predicate.
19
+ */
11
20
abstract Parameter getFunctionParameter ( int i ) ;
12
21
22
+ /** Gets the declaring type of this function, if any. */
23
+ abstract Type getDeclaringType ( ) ;
24
+
25
+ /**
26
+ * Gets any function parameter of this function.
27
+ *
28
+ * Note that this only gets _function_ paramters. To get any parameter
29
+ * use the `getAParameter` predicate.
30
+ */
13
31
final Parameter getAFunctionParameter ( ) { result = this .getFunctionParameter ( _) }
14
32
33
+ /** Gets the number of function parameters. */
15
34
final int getNumberOfFunctionParameters ( ) { result = count ( this .getAFunctionParameter ( ) ) }
16
35
36
+ /** Gets the number of parameters (both function and block). */
17
37
final int getNumberOfParameters ( ) { result = count ( this .getAParameter ( ) ) }
18
38
39
+ /** Gets the i'th parameter of this function, if any. */
19
40
final Parameter getParameter ( int i ) {
20
41
result = this .getFunctionParameter ( i )
21
42
or
22
43
result = this .getBody ( ) .getParamBlock ( ) .getParameter ( i )
23
44
}
24
45
46
+ /** Gets any parameter of this function. */
25
47
final Parameter getAParameter ( ) { result = this .getParameter ( _) }
26
48
49
+ /** Gets the entry point of this function in the control-flow graph. */
27
50
EntryBasicBlock getEntryBasicBlock ( ) { result .getScope ( ) = this .getBody ( ) }
28
51
}
29
52
30
- class NonMemberFunction extends @function_definition, Stmt , AbstractFunction {
53
+ /**
54
+ * A function definition.
55
+ */
56
+ private class FunctionBase extends @function_definition, Stmt , AbstractFunction {
31
57
override string toString ( ) { result = this .getName ( ) }
32
58
33
59
override SourceLocation getLocation ( ) { function_definition_location ( this , result ) }
@@ -41,34 +67,32 @@ class NonMemberFunction extends @function_definition, Stmt, AbstractFunction {
41
67
predicate isWorkflow ( ) { function_definition ( this , _, _, _, true ) }
42
68
43
69
override Parameter getFunctionParameter ( int i ) { result .isFunctionParameter ( this , i ) }
44
- }
45
-
46
- class MemberFunction extends @function_member, Member , AbstractFunction {
47
- override string getName ( ) { function_member ( this , _, _, _, _, _, _, result , _) }
48
-
49
- override SourceLocation getLocation ( ) { function_member_location ( this , result ) }
50
-
51
- override string toString ( ) { result = this .getName ( ) }
52
70
53
- override ScriptBlock getBody ( ) { function_member ( this , result , _, _, _, _, _, _, _) }
54
-
55
- override predicate isHidden ( ) { function_member ( this , _, _, true , _, _, _, _, _) }
56
-
57
- override predicate isPrivate ( ) { function_member ( this , _, _, _, true , _, _, _, _) }
71
+ override Type getDeclaringType ( ) { none ( ) }
72
+ }
58
73
59
- override predicate isPublic ( ) { function_member ( this , _, _, _, _, true , _, _, _) }
74
+ private predicate isMethod ( Member m , ScriptBlock body ) {
75
+ function_member ( m , body , _, _, _, _, _, _, _)
76
+ }
60
77
61
- override predicate isStatic ( ) { function_member ( this , _, _, _, _, _, true , _, _) }
78
+ /**
79
+ * A method definition. That is, a function defined inside a class definition.
80
+ */
81
+ class Method extends FunctionBase {
82
+ Method ( ) { isMethod ( _, super .getBody ( ) ) }
62
83
63
- predicate isConstructor ( ) { function_member ( this , _, true , _, _, _, _, _, _) }
84
+ /** Gets the member corresponding to this function definition. */
85
+ Member getMember ( ) { isMethod ( result , super .getBody ( ) ) }
64
86
65
- override Parameter getFunctionParameter ( int i ) { result .isFunctionParameter ( this , i ) }
87
+ /** Holds if this method is a constructor. */
88
+ predicate isConstructor ( ) { function_member ( this .getMember ( ) , _, true , _, _, _, _, _, _) }
66
89
67
- TypeConstraint getTypeConstraint ( ) { function_member_return_type ( this , result ) }
90
+ final override Type getDeclaringType ( ) { result = this . getMember ( ) . getDeclaringType ( ) }
68
91
}
69
92
70
- class Constructor extends MemberFunction {
93
+ /** A constructor definition. */
94
+ class Constructor extends Method {
71
95
Constructor ( ) { this .isConstructor ( ) }
72
96
}
73
97
74
- final class Function = AbstractFunction ;
98
+ final class Function = FunctionBase ;
0 commit comments