Skip to content

Commit a207c80

Browse files
committed
PS: Add 'raw' AST classes coming directly from the extractor.
1 parent 6652021 commit a207c80

File tree

86 files changed

+3453
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+3453
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
private import Raw
2+
3+
class ArrayExpr extends @array_expression, Expr {
4+
override SourceLocation getLocation() { array_expression_location(this, result) }
5+
6+
StmtBlock getStmtBlock() { array_expression(this, result) }
7+
8+
final override Ast getChild(ChildIndex i) {
9+
i = ArrayExprStmtBlock() and result = this.getStmtBlock()
10+
}
11+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
private import Raw
2+
3+
class ArrayLiteral extends @array_literal, Expr {
4+
override SourceLocation getLocation() { array_literal_location(this, result) }
5+
6+
Expr getElement(int index) { array_literal_element(this, index, result) }
7+
8+
Expr getAnElement() { array_literal_element(this, _, result) }
9+
10+
final override Ast getChild(ChildIndex i) {
11+
exists(int index |
12+
i = ArrayLiteralExpr(index) and
13+
result = this.getElement(index)
14+
)
15+
}
16+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
private import Raw
2+
3+
class AssignStmt extends @assignment_statement, PipelineBase {
4+
override SourceLocation getLocation() { assignment_statement_location(this, result) }
5+
6+
int getKind() { assignment_statement(this, result, _, _) }
7+
8+
Expr getLeftHandSide() { assignment_statement(this, _, result, _) }
9+
10+
Stmt getRightHandSide() { assignment_statement(this, _, _, result) }
11+
12+
final override Ast getChild(ChildIndex i) {
13+
i = AssignStmtLeftHandSide() and
14+
result = this.getLeftHandSide()
15+
or
16+
i = AssignStmtRightHandSide() and
17+
result = this.getRightHandSide()
18+
}
19+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
private import Raw
2+
import Location
3+
private import Scope
4+
5+
class Ast extends @ast {
6+
final string toString() { none() }
7+
8+
final Ast getParent() { result.getAChild() = this }
9+
10+
Ast getChild(ChildIndex i) { none() }
11+
12+
final Ast getAChild() { result = this.getChild(_) }
13+
14+
Location getLocation() { none() }
15+
16+
Scope getScope() { result = scopeOf(this) }
17+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
private import Raw
2+
3+
class Attribute extends @attribute, AttributeBase {
4+
override SourceLocation getLocation() { attribute_location(this, result) }
5+
6+
string getName() { attribute(this, result, _, _) }
7+
8+
int getNumNamedArguments() { attribute(this, _, result, _) }
9+
10+
int getNumPositionalArguments() { attribute(this, _, _, result) }
11+
12+
NamedAttributeArgument getNamedArgument(int i) { attribute_named_argument(this, i, result) }
13+
14+
final override Ast getChild(ChildIndex i) {
15+
exists(int index |
16+
i = AttributeNamedArg(index) and
17+
result = this.getNamedArgument(index)
18+
or
19+
i = AttributePosArg(index) and
20+
result = this.getPositionalArgument(index)
21+
)
22+
}
23+
24+
NamedAttributeArgument getANamedArgument() { result = this.getNamedArgument(_) }
25+
26+
int getNumberOfArguments() { result = count(this.getAPositionalArgument()) }
27+
28+
Expr getPositionalArgument(int i) { attribute_positional_argument(this, i, result) }
29+
30+
Expr getAPositionalArgument() { result = this.getPositionalArgument(_) }
31+
32+
int getNumberOfPositionalArguments() { result = count(this.getAPositionalArgument()) }
33+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
private import Raw
2+
3+
class AttributeBase extends @attribute_base, Ast { }
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
private import Raw
2+
3+
class AttributedExpr extends AttributedExprBase, @attributed_expression {
4+
final override Expr getExpr() { attributed_expression(this, _, result) }
5+
6+
final override Attribute getAttribute() { attributed_expression(this, result, _) }
7+
8+
override Location getLocation() { attributed_expression_location(this, result) }
9+
10+
override Ast getChild(ChildIndex i) {
11+
i = AttributedExprExpr() and
12+
result = this.getExpr()
13+
or
14+
i = AttributedExprAttr() and
15+
result = this.getAttribute()
16+
}
17+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
private import Raw
2+
3+
class AttributedExprBase extends @attributed_expression_ast, Expr {
4+
Expr getExpr() { none() }
5+
6+
AttributeBase getAttribute() { none() }
7+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
private import Raw
2+
3+
/** The base class for constant expressions. */
4+
class BaseConstExpr extends @base_constant_expression, Expr {
5+
/** Gets the type of this constant expression. */
6+
string getType() { none() }
7+
8+
/** Gets a string literal of this constant expression. */
9+
StringLiteral getValue() { none() }
10+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
private import Raw
2+
3+
class BinaryExpr extends @binary_expression, Expr {
4+
override SourceLocation getLocation() { binary_expression_location(this, result) }
5+
6+
int getKind() { binary_expression(this, result, _, _) }
7+
8+
/** Gets an operand of this binary expression. */
9+
Expr getAnOperand() {
10+
result = this.getLeft()
11+
or
12+
result = this.getRight()
13+
}
14+
15+
final override Ast getChild(ChildIndex i) {
16+
i = BinaryExprLeft() and
17+
result = this.getLeft()
18+
or
19+
i = BinaryExprRight() and
20+
result = this.getRight()
21+
}
22+
23+
/** Holds if this binary expression has the operands `e1` and `e2`. */
24+
predicate hasOperands(Expr e1, Expr e2) {
25+
e1 = this.getLeft() and
26+
e2 = this.getRight()
27+
or
28+
e1 = this.getRight() and
29+
e2 = this.getLeft()
30+
}
31+
32+
Expr getLeft() { binary_expression(this, _, result, _) }
33+
34+
Expr getRight() { binary_expression(this, _, _, result) }
35+
}

0 commit comments

Comments
 (0)