Skip to content

Commit a429485

Browse files
committed
PS: Create an internal class to model 'Arguments'.
1 parent 597147b commit a429485

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
private import powershell
2+
3+
module Private {
4+
/**
5+
* An argument to a call.
6+
*
7+
* The argument may be named or positional.
8+
*/
9+
abstract class AbstractArgument extends Expr {
10+
Ast call;
11+
12+
/** Gets the call that this is an argumnt of. */
13+
final Ast getCall() { result = call }
14+
15+
/** Gets the position if this is a positional argument. */
16+
abstract int getPosition();
17+
18+
/** Gets the name if this is a keyword argument. */
19+
abstract string getName();
20+
21+
/** Holds if this is a qualifier of a call */
22+
abstract predicate isQualifier();
23+
}
24+
25+
class CmdArgument extends AbstractArgument {
26+
override Cmd call;
27+
28+
CmdArgument() { call.getAnArgument() = this }
29+
30+
override int getPosition() { call.getPositionalArgument(result) = this }
31+
32+
override string getName() { call.getNamedArgument(result) = this }
33+
34+
final override predicate isQualifier() { none() }
35+
}
36+
37+
class InvokeArgument extends AbstractArgument {
38+
override InvokeMemberExpr call;
39+
40+
InvokeArgument() { call.getAnArgument() = this or call.getQualifier() = this }
41+
42+
override int getPosition() { call.getArgument(result) = this }
43+
44+
override string getName() { none() }
45+
46+
final override predicate isQualifier() { call.getQualifier() = this }
47+
}
48+
}
49+
50+
private import Private
51+
52+
module Public {
53+
final class Argument = AbstractArgument;
54+
55+
/** A positional argument to a command. */
56+
class PositionalArgument extends Argument {
57+
PositionalArgument() {
58+
not this instanceof NamedArgument and not this instanceof QualifierArgument
59+
}
60+
}
61+
62+
/** A named argument to a command. */
63+
class NamedArgument extends Argument {
64+
NamedArgument() { exists(this.getName()) }
65+
}
66+
67+
/** An argument that is a qualifier to a method. */
68+
class QualifierArgument extends Argument {
69+
QualifierArgument() { this.isQualifier() }
70+
}
71+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
module Private {
22
import Parameter::Private
33
import ExplicitWrite::Private
4+
import Argument::Private
45
}
56

67
module Public {
78
import Parameter::Public
89
import ExplicitWrite::Public
10+
import Argument::Public
911
}

0 commit comments

Comments
 (0)