@@ -2,32 +2,58 @@ import powershell
22import semmle.code.powershell.controlflow.BasicBlocks
33
44abstract private class AbstractFunction extends Ast {
5+ /** Gets the name of this function. */
56 abstract string getName ( ) ;
67
8+ /** Holds if this function has name `name`. */
79 final predicate hasName ( string name ) { this .getName ( ) = name }
810
11+ /** Gets the body of this function. */
912 abstract ScriptBlock getBody ( ) ;
1013
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+ */
1120 abstract Parameter getFunctionParameter ( int i ) ;
1221
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+ */
1331 final Parameter getAFunctionParameter ( ) { result = this .getFunctionParameter ( _) }
1432
33+ /** Gets the number of function parameters. */
1534 final int getNumberOfFunctionParameters ( ) { result = count ( this .getAFunctionParameter ( ) ) }
1635
36+ /** Gets the number of parameters (both function and block). */
1737 final int getNumberOfParameters ( ) { result = count ( this .getAParameter ( ) ) }
1838
39+ /** Gets the i'th parameter of this function, if any. */
1940 final Parameter getParameter ( int i ) {
2041 result = this .getFunctionParameter ( i )
2142 or
2243 result = this .getBody ( ) .getParamBlock ( ) .getParameter ( i )
2344 }
2445
46+ /** Gets any parameter of this function. */
2547 final Parameter getAParameter ( ) { result = this .getParameter ( _) }
2648
49+ /** Gets the entry point of this function in the control-flow graph. */
2750 EntryBasicBlock getEntryBasicBlock ( ) { result .getScope ( ) = this .getBody ( ) }
2851}
2952
30- class NonMemberFunction extends @function_definition, Stmt , AbstractFunction {
53+ /**
54+ * A function definition.
55+ */
56+ private class FunctionBase extends @function_definition, Stmt , AbstractFunction {
3157 override string toString ( ) { result = this .getName ( ) }
3258
3359 override SourceLocation getLocation ( ) { function_definition_location ( this , result ) }
@@ -41,34 +67,32 @@ class NonMemberFunction extends @function_definition, Stmt, AbstractFunction {
4167 predicate isWorkflow ( ) { function_definition ( this , _, _, _, true ) }
4268
4369 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 ( ) }
5270
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+ }
5873
59- override predicate isPublic ( ) { function_member ( this , _, _, _, _, true , _, _, _) }
74+ private predicate isMethod ( Member m , ScriptBlock body ) {
75+ function_member ( m , body , _, _, _, _, _, _, _)
76+ }
6077
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 ( ) ) }
6283
63- predicate isConstructor ( ) { function_member ( this , _, true , _, _, _, _, _, _) }
84+ /** Gets the member corresponding to this function definition. */
85+ Member getMember ( ) { isMethod ( result , super .getBody ( ) ) }
6486
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 , _, _, _, _, _, _) }
6689
67- TypeConstraint getTypeConstraint ( ) { function_member_return_type ( this , result ) }
90+ final override Type getDeclaringType ( ) { result = this . getMember ( ) . getDeclaringType ( ) }
6891}
6992
70- class Constructor extends MemberFunction {
93+ /** A constructor definition. */
94+ class Constructor extends Method {
7195 Constructor ( ) { this .isConstructor ( ) }
7296}
7397
74- final class Function = AbstractFunction ;
98+ final class Function = FunctionBase ;
0 commit comments