Skip to content

Commit 30f3846

Browse files
author
Killian Perlin
committed
Remove selector pattern binding
Closes: #696
1 parent 2498f78 commit 30f3846

15 files changed

Lines changed: 46 additions & 294 deletions

File tree

lkql/build/railroad-diagrams/selector_call.svg

Lines changed: 8 additions & 13 deletions
Loading

lkql/lkql.lkt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ grammar lkql_grammar {
145145
)
146146
selector_call <- SelectorCall(
147147
Identifier(or(@Identifier("any") | @Identifier("all")))
148-
?pick(id "@")
149148
value_expr
150149
)
151150
objectlit <- ObjectLiteral("{" list*(object_assoc, ",") "}")
@@ -1139,9 +1138,6 @@ class SelectorCall: LkqlNode {
11391138
@parse_field
11401139
quantifier: Identifier
11411140
@parse_field
1142-
@nullable
1143-
binding: Identifier
1144-
@parse_field
11451141
selector_call: Expr
11461142

11471143
|" Return the selector's quantifier name.
@@ -1151,9 +1147,6 @@ class SelectorCall: LkqlNode {
11511147
fun quantifier_name(): String =
11521148
if node.quantifier.is_null then "all" else node.quantifier.text
11531149

1154-
|" Return the binding name associated with this selector call, if any.
1155-
@exported
1156-
fun binding_name(): Identifier = node.binding
11571150
}
11581151

11591152
|" Wrapper for a SubBlockLiteral token.

lkql_checker/share/lkql/deeply_nested_instantiations.lkql

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1+
import stdlib
2+
13
fun check_instantiations(node, n : int) =
24
|" Return true if node has a chain of at least n instantiations
35
n == 0 or
46
match node
5-
| GenericPackageInstantiation =>
6-
node.f_generic_pkg_name?.p_referenced_decl() is
7-
*(any c@children: GenericInstantiation)
8-
when [x for x in c if check_instantiations(x, n - 1)]
9-
| GenericSubpInstantiation =>
10-
node.f_generic_subp_name?.p_referenced_decl() is
11-
*(any c@children: GenericInstantiation)
12-
when [x for x in c if check_instantiations(x, n - 1)]
7+
| GenericPackageInstantiation => {
8+
val c =
9+
from node.f_generic_pkg_name?.p_referenced_decl()
10+
select GenericInstantiation;
11+
stdlib.any([x for x in c if check_instantiations(x, n - 1)])
12+
}
13+
| GenericSubpInstantiation => {
14+
val c =
15+
from node.f_generic_subp_name?.p_referenced_decl()
16+
select GenericInstantiation;
17+
stdlib.any([x for x in c if check_instantiations(x, n - 1)])
18+
}
1319
| * => false
1420

1521
@check(message="deeply nested instantiation",

lkql_jit/language/src/main/java/com/adacore/lkql_jit/langkit_translator/passes/FramingPass.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,6 @@ public Void visit(Liblkqllang.ParameterDecl parameterDecl) {
257257
*/
258258
@Override
259259
public Void visit(Liblkqllang.SelectorCall selectorCall) {
260-
final Liblkqllang.Identifier binding = selectorCall.fBinding();
261-
if (!binding.isNone()) {
262-
final String symbol = binding.getText();
263-
checkDuplicateBindings(symbol, binding);
264-
this.scriptFramesBuilder.addBinding(symbol);
265-
}
266260
selectorCall.fSelectorCall().accept(this);
267261
return null;
268262
}

lkql_jit/language/src/main/java/com/adacore/lkql_jit/langkit_translator/passes/TranslationPass.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,9 +1590,6 @@ public LKQLNode visit(Liblkqllang.SelectorCall selectorCall) {
15901590
quantifier = SelectorCall.Quantifier.ALL;
15911591
}
15921592

1593-
final Liblkqllang.Identifier bindingBase = selectorCall.fBinding();
1594-
final String binding = bindingBase.isNone() ? null : bindingBase.getText();
1595-
15961593
final Liblkqllang.Expr selectorExprBase = selectorCall.fSelectorCall();
15971594
final Expr selectorExpr;
15981595
final ArgList args;
@@ -1606,15 +1603,9 @@ public LKQLNode visit(Liblkqllang.SelectorCall selectorCall) {
16061603

16071604
// Get the slot for the binding
16081605
final int bindingSlot;
1609-
if (binding != null) {
1610-
this.frames.declareBinding(binding);
1611-
bindingSlot = this.frames.getBinding(binding);
1612-
} else {
1613-
bindingSlot = -1;
1614-
}
16151606

16161607
// Return the new node
1617-
return new SelectorCall(loc(selectorCall), quantifier, bindingSlot, selectorExpr, args);
1608+
return new SelectorCall(loc(selectorCall), quantifier, selectorExpr, args);
16181609
}
16191610

16201611
// --- Node patterns

lkql_jit/language/src/main/java/com/adacore/lkql_jit/nodes/patterns/SelectorCall.java

Lines changed: 2 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,12 @@
1313
import com.adacore.lkql_jit.nodes.arguments.NamedArg;
1414
import com.adacore.lkql_jit.nodes.expressions.Expr;
1515
import com.adacore.lkql_jit.runtime.values.LKQLSelector;
16-
import com.adacore.lkql_jit.runtime.values.interfaces.Iterator;
17-
import com.adacore.lkql_jit.runtime.values.lists.LKQLList;
1816
import com.adacore.lkql_jit.runtime.values.lists.LKQLSelectorList;
1917
import com.adacore.lkql_jit.utils.Constants;
2018
import com.adacore.lkql_jit.utils.LKQLTypesHelper;
21-
import com.adacore.lkql_jit.utils.functions.FrameUtils;
2219
import com.oracle.truffle.api.frame.VirtualFrame;
2320
import com.oracle.truffle.api.nodes.UnexpectedResultException;
2421
import com.oracle.truffle.api.source.SourceSection;
25-
import java.util.ArrayList;
26-
import java.util.List;
2722

2823
/**
2924
* This node represents the call of a selector in the LKQL language.
@@ -37,9 +32,6 @@ public final class SelectorCall extends LKQLNode {
3732
/** The quantifier for the selector call. */
3833
private final Quantifier quantifier;
3934

40-
/** The slot to put the binding value in, might be -1 if there is no binding. */
41-
private final int bindingSlot;
42-
4335
// ----- Children -----
4436

4537
/** The selector to call. */
@@ -59,20 +51,17 @@ public final class SelectorCall extends LKQLNode {
5951
*
6052
* @param location The location of the node in the source.
6153
* @param quantifier The quantifier for the selector.
62-
* @param bindingSlot The slot of the binding.
6354
* @param selectorExpr The selector expression.
6455
* @param args The arguments for the call.
6556
*/
6657
public SelectorCall(
6758
SourceSection location,
6859
Quantifier quantifier,
69-
int bindingSlot,
7060
Expr selectorExpr,
7161
ArgList args
7262
) {
7363
super(location);
7464
this.quantifier = quantifier;
75-
this.bindingSlot = bindingSlot;
7665
this.selectorExpr = selectorExpr;
7766
this.args = args;
7867
}
@@ -109,11 +98,6 @@ public boolean executeVerification(VirtualFrame frame, Object node, Pattern patt
10998
isValid = this.isAny(frame, selectorListValue, pattern);
11099
}
111100

112-
// Do the bindings
113-
if (this.bindingSlot > -1) {
114-
this.doBinding(frame, selectorListValue, pattern);
115-
}
116-
117101
// Return the result
118102
return isValid;
119103
}
@@ -233,61 +217,6 @@ private boolean isAny(VirtualFrame frame, LKQLSelectorList selectorListValue, Pa
233217
return false;
234218
}
235219

236-
/**
237-
* Get the list value filtered with the given pattern.
238-
*
239-
* @param frame The frame to execute in.
240-
* @param selectorListValue The selector list value to filter.
241-
* @param pattern The pattern for the filtering.
242-
* @return The list value
243-
*/
244-
private LKQLList getFilteredList(
245-
VirtualFrame frame,
246-
LKQLSelectorList selectorListValue,
247-
Pattern pattern
248-
) {
249-
// Prepare the result
250-
List<Object> resList = new ArrayList<>();
251-
252-
// Iterate on nodes
253-
Iterator iterator = selectorListValue.iterator();
254-
while (iterator.hasNext()) {
255-
Object value = iterator.next();
256-
if (pattern.executeValue(frame, value)) {
257-
resList.add(value);
258-
}
259-
}
260-
261-
// Return the result
262-
return new LKQLList(resList.toArray(new Object[0]));
263-
}
264-
265-
/**
266-
* Do the binding process.
267-
*
268-
* @param frame The frame to execute in.
269-
* @param selectorListValue The selector list to bind.
270-
* @param pattern The pattern to filter the list.
271-
*/
272-
private void doBinding(
273-
VirtualFrame frame,
274-
LKQLSelectorList selectorListValue,
275-
Pattern pattern
276-
) {
277-
LKQLList listValue = this.getFilteredList(frame, selectorListValue, pattern);
278-
this.doBinding(frame, listValue);
279-
}
280-
281-
/**
282-
* Do the binding with the already computed list.
283-
*
284-
* @param frame The frame to execute in.
285-
* @param listValue The list bind.
286-
*/
287-
private void doBinding(VirtualFrame frame, LKQLList listValue) {
288-
FrameUtils.writeLocal(frame, this.bindingSlot, listValue);
289-
}
290-
291220
// ----- Override methods -----
292221

293222
/**
@@ -297,8 +226,8 @@ private void doBinding(VirtualFrame frame, LKQLList listValue) {
297226
public String toString(int indentLevel) {
298227
return this.nodeRepresentation(
299228
indentLevel,
300-
new String[] { "quantifier", "slot" },
301-
new Object[] { this.quantifier, this.bindingSlot }
229+
new String[] { "quantifier" },
230+
new Object[] { this.quantifier }
302231
);
303232
}
304233

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
val withAspect = select ObjectDecl(any cs @ children: AspectAssoc)
2-
when cs.length == 1
1+
val withAspect = select node @ ObjectDecl
2+
when (from node select AspectAssoc).length == 1
33
print (withAspect)

testsuite/tests/parser/annotated_fun/test.out

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ FunDecl
4444
| | | | | | | | SelectorCall
4545
| | | | | | | | |f_quantifier:
4646
| | | | | | | | | Identifier: any
47-
| | | | | | | | |f_binding: <null>
4847
| | | | | | | | |f_selector_call:
4948
| | | | | | | | | Identifier: children
5049
| | | | | | | |f_pattern_detail_delimiter:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
all c@children(min_depth=1, max_depth=3)
1+
all children(min_depth=1, max_depth=3)

testsuite/tests/parser/full_selector_call/test.out

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
SelectorCall
22
|f_quantifier:
33
| Identifier: all
4-
|f_binding:
5-
| Identifier: c
64
|f_selector_call:
75
| FunCall
86
| |f_name:

0 commit comments

Comments
 (0)