|
| 1 | +import powershell |
| 2 | + |
| 3 | +abstract private class AbstractFunction extends Ast { |
| 4 | + abstract string getName(); |
| 5 | + |
| 6 | + abstract ScriptBlock getBody(); |
| 7 | + |
| 8 | + abstract Parameter getFunctionParameter(int i); |
| 9 | + |
| 10 | + final Parameter getAFunctionParameter() { result = this.getFunctionParameter(_) } |
| 11 | + |
| 12 | + final int getNumberOfFunctionParameters() { result = count(this.getAFunctionParameter()) } |
| 13 | + |
| 14 | + final int getNumberOfParameters() { result = count(this.getAParameter()) } |
| 15 | + |
| 16 | + final Parameter getParameter(int i) { |
| 17 | + result = this.getFunctionParameter(i) |
| 18 | + or |
| 19 | + result = this.getBody().getParamBlock().getParameter(i) |
| 20 | + } |
| 21 | + |
| 22 | + final Parameter getAParameter() { result = this.getParameter(_) } |
| 23 | +} |
| 24 | + |
| 25 | +class NonMemberFunction extends @function_definition, Stmt, AbstractFunction { |
| 26 | + override string toString() { result = this.getName() } |
| 27 | + |
| 28 | + override SourceLocation getLocation() { function_definition_location(this, result) } |
| 29 | + |
| 30 | + override string getName() { function_definition(this, _, result, _, _) } |
| 31 | + |
| 32 | + override ScriptBlock getBody() { function_definition(this, result, _, _, _) } |
| 33 | + |
| 34 | + predicate isFilter() { function_definition(this, _, _, true, _) } |
| 35 | + |
| 36 | + predicate isWorkflow() { function_definition(this, _, _, _, true) } |
| 37 | + |
| 38 | + override Parameter getFunctionParameter(int i) { function_definition_parameter(this, i, result) } |
| 39 | +} |
| 40 | + |
| 41 | +class MemberFunction extends @function_member, Member, AbstractFunction { |
| 42 | + override string getName() { function_member(this, _, _, _, _, _, _, result, _) } |
| 43 | + |
| 44 | + override SourceLocation getLocation() { function_member_location(this, result) } |
| 45 | + |
| 46 | + override string toString() { result = this.getName() } |
| 47 | + |
| 48 | + override ScriptBlock getBody() { function_member(this, result, _, _, _, _, _, _, _) } |
| 49 | + |
| 50 | + override predicate isHidden() { function_member(this, _, _, true, _, _, _, _, _) } |
| 51 | + |
| 52 | + override predicate isPrivate() { function_member(this, _, _, _, true, _, _, _, _) } |
| 53 | + |
| 54 | + override predicate isPublic() { function_member(this, _, _, _, _, true, _, _, _) } |
| 55 | + |
| 56 | + override predicate isStatic() { function_member(this, _, _, _, _, _, true, _, _) } |
| 57 | + |
| 58 | + predicate isConstructor() { function_member(this, _, true, _, _, _, _, _, _) } |
| 59 | + |
| 60 | + override Parameter getFunctionParameter(int i) { function_member_parameter(this, i, result) } |
| 61 | + |
| 62 | + TypeConstraint getTypeConstraint() { function_member_return_type(this, result) } |
| 63 | +} |
| 64 | + |
| 65 | +class Constructor extends MemberFunction { |
| 66 | + Constructor() { this.isConstructor() } |
| 67 | +} |
| 68 | + |
| 69 | +final class Function = AbstractFunction; |
0 commit comments