Skip to content

Commit 2395ecd

Browse files
committed
Add SourceSection information to LKQLObject
1 parent dc687bb commit 2395ecd

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

lkql_jit/language/src/main/java/com/adacore/lkql_jit/nodes/expressions/literals/ObjectLiteral.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public Object executeGeneric(VirtualFrame frame) {
8080
@ExplodeLoop
8181
public LKQLObject executeObject(final VirtualFrame frame) {
8282
// Create the result object
83-
LKQLObject res = new LKQLObject(this.shape);
83+
LKQLObject res = new LKQLObject(this.shape, this.location);
8484
for (int i = 0; i < this.keys.length; i++) {
8585
this.objectLibrary.put(res, this.keys[i], this.values[i].executeGeneric(frame));
8686
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public boolean onObject(
7272
// If the splat has a binding, we need to compute the new object without the keys
7373
// that have already been matched
7474
if (splat.hasBinding()) {
75-
LKQLObject splatObject = new LKQLObject(shape);
75+
LKQLObject splatObject = new LKQLObject(shape, location);
7676
DynamicObjectLibrary splatObjectLib = DynamicObjectLibrary.getUncached();
7777

7878
for (var objKey : objKeys) {

lkql_jit/language/src/main/java/com/adacore/lkql_jit/nodes/utils/ValueCombiner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected LKQLObject onObjects(
3737
@Cached ValueCombiner recursiveCombiner
3838
) {
3939
// Create the result object
40-
LKQLObject res = new LKQLObject(LKQLObject.emptyShape());
40+
LKQLObject res = new LKQLObject(LKQLObject.emptyShape(), caller.getSourceSection());
4141

4242
// Insert all keys of the left object in the result, resolving conflicts by combining
4343
// values.

lkql_jit/language/src/main/java/com/adacore/lkql_jit/runtime/values/LKQLObject.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.oracle.truffle.api.library.ExportMessage;
1919
import com.oracle.truffle.api.object.DynamicObjectLibrary;
2020
import com.oracle.truffle.api.object.Shape;
21+
import com.oracle.truffle.api.source.SourceSection;
2122
import com.oracle.truffle.api.utilities.TriState;
2223

2324
/** This class represents an object value in the LKQL language. */
@@ -27,12 +28,17 @@ public final class LKQLObject extends ObjectLKQLValue implements LKQLValue {
2728
// ----- Attributes -----*
2829

2930
private static final Shape.Builder shapeBuilder = Shape.newBuilder();
31+
/** The source location where this object was created. This attribute was
32+
* introduced to provide location information for object instances defined
33+
* in LKQL rules files. */
34+
private final SourceSection creationLocation;
3035

3136
// ----- Constructors -----
3237

3338
/** Create a new LKQL object with its dynamic shape. */
34-
public LKQLObject(final Shape shape) {
39+
public LKQLObject(final Shape shape, SourceSection creationLocation) {
3540
super(shape);
41+
this.creationLocation = creationLocation;
3642
}
3743

3844
// ----- Class methods -----
@@ -42,7 +48,8 @@ public LKQLObject(final Shape shape) {
4248
* library so this is not designed for performance critical usages.
4349
*/
4450
public static LKQLObject createUncached(final Object[] keys, final Object[] values) {
45-
final LKQLObject res = new LKQLObject(emptyShape());
51+
// NOTE: this LKQL object doesn't have a source location for now
52+
final LKQLObject res = new LKQLObject(emptyShape(), null);
4653
for (int i = 0; i < keys.length; i++) {
4754
uncachedObjectLibrary.put(res, keys[i], values[i]);
4855
}
@@ -57,6 +64,16 @@ public static Shape emptyShape() {
5764

5865
// ----- Value methods -----
5966

67+
@ExportMessage
68+
public boolean hasSourceLocation() {
69+
return creationLocation != null;
70+
}
71+
72+
@ExportMessage
73+
public SourceSection getSourceLocation() {
74+
return creationLocation;
75+
}
76+
6077
/** Exported message to compare two LKQL objects. */
6178
@ExportMessage
6279
static class IsIdenticalOrUndefined {

0 commit comments

Comments
 (0)