Skip to content

Commit 597147b

Browse files
committed
PS: Refactor the way we do 'internal' AST related classes.
1 parent ca1c912 commit 597147b

File tree

8 files changed

+49
-60
lines changed

8 files changed

+49
-60
lines changed

powershell/ql/lib/powershell.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,5 @@ import semmle.code.powershell.IndexExpr
7979
import semmle.code.powershell.HashTable
8080
import semmle.code.powershell.SplitExpr
8181
import semmle.code.powershell.CommentEntity
82-
import semmle.code.powershell.Variable
82+
import semmle.code.powershell.Variable
83+
import semmle.code.powershell.internal.Internal::Public

powershell/ql/lib/semmle/code/powershell/Command.qll

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -65,30 +65,3 @@ class Cmd extends @command, CmdBase {
6565

6666
Redirection getARedirection() { result = this.getRedirection(_) }
6767
}
68-
69-
/**
70-
* An argument to a command.
71-
*
72-
* The argument may be named or positional.
73-
*/
74-
class Argument extends Expr {
75-
Cmd cmd;
76-
77-
Argument() { cmd.getAnArgument() = this }
78-
79-
Cmd getCmd() { result = cmd }
80-
81-
int getPosition() { cmd.getPositionalArgument(result) = this }
82-
83-
string getName() { cmd.getNamedArgument(result) = this }
84-
}
85-
86-
/** A positional argument to a command. */
87-
class PositionalArgument extends Argument {
88-
PositionalArgument() { not this instanceof NamedArgument }
89-
}
90-
91-
/** A named argument to a command. */
92-
class NamedArgument extends Argument {
93-
NamedArgument() { this = cmd.getNamedArgument(_) }
94-
}

powershell/ql/lib/semmle/code/powershell/IndexExpr.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import powershell
2-
private import internal.ExplicitWrite
2+
private import internal.ExplicitWrite::Private
33

44
class IndexExpr extends @index_expression, Expr {
55
override string toString() { result = "...[...]" }

powershell/ql/lib/semmle/code/powershell/Variable.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
private import powershell
22
private import semmle.code.powershell.controlflow.internal.Scope
3-
private import internal.Internal as Internal
3+
private import internal.Parameter::Private as Internal
44

55
private predicate isFunctionParameterImpl(Internal::Parameter p, Function f, int i) {
66
function_definition_parameter(f, i, p)

powershell/ql/lib/semmle/code/powershell/VariableExpression.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import powershell
2-
private import internal.ExplicitWrite
2+
private import internal.ExplicitWrite::Private
33

44
private predicate isParameterName(@variable_expression ve) { parameter(_, ve, _, _) }
55

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
private import powershell
22

3-
/**
4-
* Holds if `e` is written to by `assign`.
5-
*
6-
* Note there may be more than one `e` for which `isExplicitWrite(e, assign)`
7-
* holds if the left-hand side is an array literal.
8-
*/
9-
predicate isExplicitWrite(Expr e, AssignStmt assign) {
10-
e = assign.getLeftHandSide()
11-
or
12-
e = any(ConvertExpr convert | isExplicitWrite(convert, assign)).getExpr()
13-
or
14-
e = any(ArrayLiteral array | isExplicitWrite(array, assign)).getAnElement()
3+
module Private {
4+
/**
5+
* Holds if `e` is written to by `assign`.
6+
*
7+
* Note there may be more than one `e` for which `isExplicitWrite(e, assign)`
8+
* holds if the left-hand side is an array literal.
9+
*/
10+
predicate isExplicitWrite(Expr e, AssignStmt assign) {
11+
e = assign.getLeftHandSide()
12+
or
13+
e = any(ConvertExpr convert | isExplicitWrite(convert, assign)).getExpr()
14+
or
15+
e = any(ArrayLiteral array | isExplicitWrite(array, assign)).getAnElement()
16+
}
1517
}
18+
19+
module Public { }
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1-
import Parameter
2-
import ExplicitWrite
1+
module Private {
2+
import Parameter::Private
3+
import ExplicitWrite::Private
4+
}
5+
6+
module Public {
7+
import Parameter::Public
8+
import ExplicitWrite::Public
9+
}
Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11
import powershell
22

3-
class Parameter extends @parameter, Ast {
4-
override string toString() { result = this.getName().toString() }
5-
6-
string getName() {
7-
exists(@variable_expression ve |
8-
parameter(this, ve, _, _) and
9-
variable_expression(ve, result, _, _, _, _, _, _, _, _, _, _)
10-
)
11-
}
3+
module Private {
4+
class Parameter extends @parameter, Ast {
5+
override string toString() { result = this.getName().toString() }
6+
7+
string getName() {
8+
exists(@variable_expression ve |
9+
parameter(this, ve, _, _) and
10+
variable_expression(ve, result, _, _, _, _, _, _, _, _, _, _)
11+
)
12+
}
1213

13-
string getStaticType() { parameter(this, _, result, _) }
14+
string getStaticType() { parameter(this, _, result, _) }
1415

15-
int getNumAttributes() { parameter(this, _, _, result) }
16+
int getNumAttributes() { parameter(this, _, _, result) }
1617

17-
AttributeBase getAttribute(int i) { parameter_attribute(this, i, result) }
18+
AttributeBase getAttribute(int i) { parameter_attribute(this, i, result) }
1819

19-
AttributeBase getAnAttribute() { result = this.getAttribute(_) }
20+
AttributeBase getAnAttribute() { result = this.getAttribute(_) }
2021

21-
Expr getDefaultValue() { parameter_default_value(this, result) }
22+
Expr getDefaultValue() { parameter_default_value(this, result) }
2223

23-
override SourceLocation getLocation() { parameter_location(this, result) }
24+
override SourceLocation getLocation() { parameter_location(this, result) }
25+
}
2426
}
27+
28+
module Public { }

0 commit comments

Comments
 (0)