Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
description: Add @rangeelementexpr, grouping the loop variables of a range statement
compatibility: partial
compatibility: full

exprs.rel: run upgrade.qlo new_exprs
has_location.rel: run upgrade.qlo new_has_location
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
class Expr extends @expr {
string toString() { none() }
}

class ExprParent extends @exprparent {
string toString() { none() }
}

class RangeStmt extends @rangestmt {
string toString() { none() }
}

class Location extends @location {
string toString() { none() }
}

newtype TAddedExpr = TRangeElement(RangeStmt stmt)

module Fresh = QlBuiltins::NewEntity<TAddedExpr>;

class TNewExpr = @expr or Fresh::EntityId;

class NewExpr extends TNewExpr {
string toString() { none() }
}

class TNewExprParent = @exprparent or Fresh::EntityId;

class NewExprParent extends TNewExprParent {
string toString() { none() }
}

class TNewLocatable = @locatable or Fresh::EntityId;

class NewLocatable extends TNewLocatable {
string toString() { none() }
}

predicate isRangeElementChild(ExprParent parent, int idx, RangeStmt range) {
parent = range and
idx in [0 .. 1]
}

query predicate new_exprs(NewExpr id, int kind, NewExprParent parent, int idx) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the upgrade script, the parent/child relation is expanded
Before

range_stmt ->_0 expr_0
range_stmt ->_1 expr_1

After

range_stm ->_0 range_expression
range_expression ->_0 expr_0
range_expression ->_1 expr_1

Perhaps, a downgrade script is needed as well that contracts the parent/child relation (and deletes the range_expression's).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was already done in the original commit.

exists(RangeStmt range |
id = Fresh::map(TRangeElement(range)) and
kind = 55 and
parent = range and
idx = 0
)
or
exists(Expr oldId, int oldKind, ExprParent oldParent, int oldIdx |
exprs(oldId, oldKind, oldParent, oldIdx) and
id = oldId and
kind = oldKind and
idx = oldIdx
Comment thread
owen-mc marked this conversation as resolved.
Outdated
|
exists(RangeStmt range | isRangeElementChild(oldParent, oldIdx, range) |
parent = Fresh::map(TRangeElement(range))
)
or
not isRangeElementChild(oldParent, oldIdx, _) and
parent = oldParent
)
}

query predicate new_has_location(NewLocatable locatable, Location location) {
has_location(locatable, location)
or
exists(RangeStmt range |
locatable = Fresh::map(TRangeElement(range)) and
has_location(range, location)
)
}
Loading