Skip to content

Commit faa9473

Browse files
committed
PS: Add an implicit this parameter to all methods.
1 parent 31f14ba commit faa9473

File tree

1 file changed

+25
-0
lines changed
  • powershell/ql/lib/semmle/code/powershell/ast/internal

1 file changed

+25
-0
lines changed

powershell/ql/lib/semmle/code/powershell/ast/internal/Synthesis.qll

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,28 @@ Ast getResultAst(Raw::Ast r) {
113113
}
114114

115115
Raw::Ast getRawAst(Ast r) { r = getResultAst(result) }
116+
117+
private module ThisSynthesis {
118+
private class ThisSynthesis extends Synthesis {
119+
override predicate child(Raw::Ast parent, ChildIndex i, Child child) {
120+
parent instanceof Raw::MethodScriptBlock and
121+
i = ThisVar() and
122+
child = SynthChild(VarSynthKind(ThisVarKind()))
123+
or
124+
parent.getChild(toRawChildIndex(i)).(Raw::VarAccess).getUserPath().toLowerCase() = "this" and
125+
child = SynthChild(VarAccessSynthKind(TVariableSynth(parent.getScope(), ThisVar())))
126+
}
127+
128+
override predicate variableSynthName(VariableSynth v, string name) {
129+
v = TVariableSynth(_, ThisVar()) and
130+
name = "this"
131+
}
132+
133+
override Location getLocation(Ast n) {
134+
exists(Raw::Ast scope |
135+
n = TVariableSynth(scope, ThisVar()) and
136+
result = scope.getLocation()
137+
)
138+
}
139+
}
140+
}

0 commit comments

Comments
 (0)