Skip to content
Snippets Groups Projects
Commit 38954661 authored by Julien Lopez's avatar Julien Lopez
Browse files

Moving to getters, because Java

parent 50dad48a
No related branches found
No related tags found
No related merge requests found
Showing
with 184 additions and 55 deletions
......@@ -28,12 +28,12 @@ public abstract class QIRTypes {
@ImplicitCast
@TruffleBoundary
public static QIRBigNumber castBigNumber(QIRNumber n) {
return new QIRBigNumber(n.sourceSection, BigInteger.valueOf(n.value));
return new QIRBigNumber(n.getSourceSection(), BigInteger.valueOf(n.getValue()));
}
@ImplicitCast
@TruffleBoundary
public static QIRDouble castDouble(QIRNumber n) {
return new QIRDouble(n.sourceSection, n.value);
return new QIRDouble(n.getSourceSection(), n.getValue());
}
}
\ No newline at end of file
......@@ -24,11 +24,11 @@ public final class QIRApply extends QIRNode {
/**
* The function involved in the application.
*/
@Child public QIRNode left;
@Child private QIRNode left;
/**
* The expression to be applied to {@link #left}.
*/
@Child public QIRNode right;
@Child private QIRNode right;
@Child protected IndirectCallNode callNode;
public QIRApply(final SourceSection source, final QIRNode left, final QIRNode right) {
......@@ -38,6 +38,14 @@ public final class QIRApply extends QIRNode {
this.callNode = Truffle.getRuntime().createIndirectCallNode();
}
public final QIRNode getLeft() {
return left;
}
public final QIRNode getRight() {
return right;
}
@Override
public final String toString() {
return left + "(" + right + ")";
......@@ -62,7 +70,7 @@ public final class QIRApply extends QIRNode {
if (l instanceof QIRLambda) {
final QIRLambda fun = (QIRLambda) l;
return (QIRNode) callNode.call(fun.target, new Object[]{fun.env, r});
return (QIRNode) callNode.call(fun.getTarget(), new Object[]{fun.getEnv(), r});
}
if (l instanceof QIRTruffleNode) {
final QIRTruffleNode fun = (QIRTruffleNode) l;
......
......@@ -17,11 +17,11 @@ public final class QIRDBNode<DBRepr> extends QIRNode {
/**
* The driver of the targeted database.
*/
public final DBDriver<DBRepr> driver;
private final DBDriver<DBRepr> driver;
/**
* The query in the representation for the database.
*/
public final DBRepr translation;
private final DBRepr translation;
public QIRDBNode(final SourceSection source, final DBDriver<DBRepr> driver, final QIRNode toTranslate) {
super(source);
......@@ -29,6 +29,14 @@ public final class QIRDBNode<DBRepr> extends QIRNode {
this.translation = driver.translate(toTranslate);
}
public final DBDriver<DBRepr> getDriver() {
return driver;
}
public final DBRepr getTranslation() {
return translation;
}
@Override
public final String toString() {
return "DBNode(" + translation + ")";
......
......@@ -13,13 +13,17 @@ public final class QIRExternal extends QIRNode {
/**
* The name of the external resource.
*/
public final String name;
private final String name;
public QIRExternal(SourceSection sourceSection, String name) {
super(sourceSection);
this.name = name;
}
public final String getName() {
return name;
}
@Override
public String toString() {
return "External(" + name + ")";
......
......@@ -15,15 +15,15 @@ public final class QIRIf extends QIRNode {
/**
* The condition to test.
*/
@Child public QIRNode condition;
@Child private QIRNode condition;
/**
* The expression to be executed if {@link #condition} is true.
*/
@Child public QIRNode thenNode;
@Child private QIRNode thenNode;
/**
* The expression to be executed if {@link #condition} is false.
*/
@Child public QIRNode elseNode;
@Child private QIRNode elseNode;
public QIRIf(final SourceSection source, final QIRNode condition, final QIRNode thenNode, final QIRNode elseNode) {
super(source);
......@@ -32,6 +32,18 @@ public final class QIRIf extends QIRNode {
this.elseNode = elseNode;
}
public final QIRNode getCondition() {
return condition;
}
public final QIRNode getThenNode() {
return thenNode;
}
public final QIRNode getElseNode() {
return elseNode;
}
@Override
public final String toString() {
return "if " + condition + " then " + thenNode + " else " + elseNode;
......
......@@ -17,20 +17,20 @@ public final class QIRLambda extends QIRNode {
/**
* The name of the function. {@code null} for an anonymous function.
*/
public final String funName;
private final String funName;
/**
* A {@link QIRVariable} that represents the argument of the function.
*/
public final QIRVariable var;
private final QIRVariable var;
/**
* The body of the function.
*/
@Child public QIRNode body;
public final RootCallTarget target;
@Child private QIRNode body;
private final RootCallTarget target;
/**
* The environment of the function.
*/
public MaterializedFrame env;
private MaterializedFrame env;
public QIRLambda(final SourceSection source, final String funName, final QIRVariable var, final QIRNode body, final FrameDescriptor frameDescr) {
super(source);
......@@ -40,6 +40,26 @@ public final class QIRLambda extends QIRNode {
this.target = Truffle.getRuntime().createCallTarget(new QIRRootNode(null, var != null ? frameDescr.findOrAddFrameSlot(var.id) : null, body, frameDescr));
}
public final String getFunName() {
return funName;
}
public final QIRVariable getVar() {
return var;
}
public final QIRNode getBody() {
return body;
}
public final RootCallTarget getTarget() {
return target;
}
public final MaterializedFrame getEnv() {
return env;
}
@Override
public final String toString() {
return (funName != null ? funName : "lambda") + " " + var + " -> {" + body + "}";
......
......@@ -26,7 +26,7 @@ public abstract class QIRNode extends Node {
/**
* The location in the source code of the expression represented by this node.
*/
public final SourceSection sourceSection;
protected final SourceSection sourceSection;
public QIRNode(final SourceSection sourceSection) {
this.sourceSection = sourceSection;
......
......@@ -10,8 +10,8 @@ import qir.QIRLanguage;
/**
* The root of all QIR execution trees.
*/
public class QIRRootNode extends RootNode {
@Child public QIRNode body;
public final class QIRRootNode extends RootNode {
@Child private QIRNode body;
private final FrameSlot param;
public QIRRootNode(final QIRLanguage language, final FrameSlot param, final QIRNode body, final FrameDescriptor descr) {
......
......@@ -20,22 +20,22 @@ public abstract class QIRTruffleNode extends QIRNode {
/**
* The name of the Truffle language this expression comes from.
*/
public final String languageName;
protected final String languageName;
/**
* A function that executes the expression.
*/
public final Function<String, QIRNode> executeTruffle;
protected final Function<String, QIRNode> executeTruffle;
/**
* A function that applies an object of the Truffle language to a function of the Truffle language
* and returns the result of this application.
*/
public final BiFunction<QIRTruffleNode, List<QIRNode>, QIRTruffleNode> apply;
protected final BiFunction<QIRTruffleNode, List<QIRNode>, QIRTruffleNode> apply;
/**
* The expression itself, encoded as a String for now.
*/
public final String code;
protected final String code;
public QIRTruffleNode(final SourceSection sourceSection, final String languageName, final Function<String, QIRNode> executeTruffle,
protected QIRTruffleNode(final SourceSection sourceSection, final String languageName, final Function<String, QIRNode> executeTruffle,
final BiFunction<QIRTruffleNode, List<QIRNode>, QIRTruffleNode> apply, final String code) {
super(sourceSection);
this.languageName = languageName;
......@@ -44,6 +44,14 @@ public abstract class QIRTruffleNode extends QIRNode {
this.code = code;
}
public final String getLanguageName() {
return languageName;
}
public final String getCode() {
return code;
}
@Override
public boolean equals(Object other) {
if (other instanceof QIRAny)
......
......@@ -14,11 +14,11 @@ public final class QIRLcons extends QIRList {
/**
* The first value of the {@link QIRList}.
*/
@Child public QIRNode value;
@Child private QIRNode value;
/**
* The rest of the {@link QIRList}.
*/
@Child public QIRNode tail;
@Child private QIRNode tail;
public QIRLcons(final SourceSection source, final QIRNode value, final QIRNode tail) {
super(source);
......@@ -26,6 +26,14 @@ public final class QIRLcons extends QIRList {
this.tail = tail;
}
public final QIRNode getValue() {
return value;
}
public final QIRNode getTail() {
return tail;
}
@Override
public final String toString() {
return "[ " + value + ", " + tail + "]";
......
......@@ -18,18 +18,18 @@ public final class QIRLdestr extends QIRNode {
/**
* The {@link QIRList} to access.
*/
@Child public QIRNode list;
@Child private QIRNode list;
/**
* The value to return if {@link #list} is empty.
*/
@Child public QIRNode ifEmpty;
@Child private QIRNode ifEmpty;
/**
* The handler is a function that takes two arguments: the first element of the non-empty
* {@link #list} to access, and the rest of the non-empty {@link #list} to access. It returns an
* element of the non-empty {@link #list}. If {@link #list} is empty, then {@link #ifEmpty} is
* returned.
*/
@Child public QIRNode handler;
@Child private QIRNode handler;
public QIRLdestr(final SourceSection source, final QIRNode list, final QIRNode ifEmpty, final QIRNode handler) {
super(source);
......@@ -38,6 +38,18 @@ public final class QIRLdestr extends QIRNode {
this.handler = handler;
}
public final QIRNode getList() {
return list;
}
public final QIRNode getIfEmpty() {
return ifEmpty;
}
public final QIRNode getHandler() {
return handler;
}
@Override
public final String toString() {
return "match " + list + " with\n| [] -> " + ifEmpty + "\n| e :: rest -> " + handler + "(e, rest)";
......@@ -69,10 +81,11 @@ public final class QIRLdestr extends QIRNode {
throw new QIRException("Expected function taking two arguments for list destructor, got: " + f);
final QIRLcons lcons = (QIRLcons) l;
final QIRLambda ff = (QIRLambda) f;
if (!(ff.body instanceof QIRLambda))
if (!(ff.getBody() instanceof QIRLambda))
throw new QIRException("Expected function taking two arguments for list destructor, got: " + f);
final QIRLambda body = (QIRLambda) ff.body;
return new QIRApply(null, new QIRLambda(null, null, ff.var, new QIRApply(null, new QIRLambda(null, null, body.var, body.body, null), lcons.tail), null), lcons.value).executeGeneric(frame);
final QIRLambda body = (QIRLambda) ff.getBody();
return new QIRApply(null, new QIRLambda(null, null, ff.getVar(), new QIRApply(null, new QIRLambda(null, null, body.getVar(), body.getBody(), null), lcons.getTail()), null),
lcons.getValue()).executeGeneric(frame);
}
@Override
......
......@@ -17,7 +17,11 @@ public final class QIRLnil extends QIRList {
/**
* The unique representation of the empty {@link QIRList}.
*/
public static final QIRLnil instance = new QIRLnil();
private static final QIRLnil instance = new QIRLnil();
public static final QIRLnil getInstance() {
return instance;
}
@Override
public final String toString() {
......
......@@ -14,19 +14,19 @@ public final class QIRTable extends QIRNode {
/**
* The name of the table.
*/
@Child public QIRNode tableName;
@Child private QIRNode tableName;
/**
* The name of the database the table belongs to.
*/
@Child public QIRNode dbName;
@Child private QIRNode dbName;
/**
* The name of the configuration file for connecting to the database.
*/
@Child public QIRNode configFile;
@Child private QIRNode configFile;
/**
* The name of the collection where to find the table.
*/
@Child public QIRNode schemaName;
@Child private QIRNode schemaName;
public QIRTable(final SourceSection source, final QIRNode tableName, final QIRNode dbName, final QIRNode configFile, final QIRNode schemaName) {
super(source);
......@@ -36,6 +36,22 @@ public final class QIRTable extends QIRNode {
this.schemaName = schemaName;
}
public final QIRNode getTableName() {
return tableName;
}
public final QIRNode getDbName() {
return dbName;
}
public final QIRNode getConfigFile() {
return configFile;
}
public final QIRNode getSchemaName() {
return schemaName;
}
@Override
public final String toString() {
return "Table(" + schemaName + ":" + tableName + "@" + dbName + ":" + configFile + ")";
......
......@@ -14,15 +14,15 @@ public final class QIRTcons extends QIRTuple {
/**
* The name of the first field in the {@link QIRTuple}.
*/
public final String id;
private final String id;
/**
* The value of the first field in the {@link QIRTuple}.
*/
@Child public QIRNode value;
@Child private QIRNode value;
/**
* The rest of the {@link QIRTuple}.
*/
@Child public QIRNode tail;
@Child private QIRNode tail;
public QIRTcons(final SourceSection source, final String id, final QIRNode value, final QIRNode tail) {
super(source);
......@@ -31,6 +31,18 @@ public final class QIRTcons extends QIRTuple {
this.tail = tail;
}
public final String getId() {
return id;
}
public final QIRNode getValue() {
return value;
}
public final QIRNode getTail() {
return tail;
}
@Override
public final String toString() {
return "{ " + id + ":" + value + "; " + tail + "}";
......
......@@ -15,11 +15,11 @@ public final class QIRTdestr extends QIRNode {
/**
* The {@link QIRTuple} to access.
*/
@Child public QIRNode tuple;
@Child private QIRNode tuple;
/**
* The name of the field to look for in the {@link QIRTuple}.
*/
public final String colName;
private final String colName;
public QIRTdestr(final SourceSection source, final QIRNode tuple, final String colName) {
super(source);
......@@ -27,6 +27,14 @@ public final class QIRTdestr extends QIRNode {
this.colName = colName;
}
public final QIRNode getTuple() {
return tuple;
}
public final String getColName() {
return colName;
}
@Override
public final String toString() {
return tuple + "." + colName;
......@@ -46,13 +54,13 @@ public final class QIRTdestr extends QIRNode {
QIRNode t = tuple.executeGeneric(frame);
// TODO: Should we allow this in QIR?
if (t instanceof QIRLcons && ((QIRLcons) t).tail == QIRLnil.instance)
t = ((QIRLcons) t).value;
if (t instanceof QIRLcons && ((QIRLcons) t).getTail() == QIRLnil.getInstance())
t = ((QIRLcons) t).getValue();
if (!(t instanceof QIRTuple))
throw new QIRException("Expected tuple for lhs of tuple destructor.");
for (QIRNode current = t; current instanceof QIRTcons; current = ((QIRTcons) current).tail)
if (colName.equals(((QIRTcons) current).id))
return ((QIRTcons) current).value;
for (QIRNode current = t; current instanceof QIRTcons; current = ((QIRTcons) current).getTail())
if (colName.equals(((QIRTcons) current).getId()))
return ((QIRTcons) current).getValue();
throw new QIRException("Typing error: destructor of tuple could not find " + colName + " in tuple " + t + ".");
}
......
......@@ -17,7 +17,11 @@ public final class QIRTnil extends QIRTuple {
/**
* The unique representation of the empty {@link QIRTuple}.
*/
public static final QIRTnil instance = new QIRTnil();
private static final QIRTnil instance = new QIRTnil();
public static final QIRTnil getInstance() {
return instance;
}
@Override
public final String toString() {
......
......@@ -14,13 +14,17 @@ public abstract class QIRBaseValue<BaseType> extends QIRNode {
/**
* The value in BaseType type.
*/
public final BaseType value;
protected final BaseType value;
public QIRBaseValue(final SourceSection source, final BaseType value) {
super(source);
this.value = value;
}
public final BaseType getValue() {
return value;
}
@Override
public String toString() {
return value.toString();
......
......@@ -27,13 +27,13 @@ public abstract class QIRDiv extends QIRBinaryNode {
@Specialization(rewriteOn = ArithmeticException.class)
@TruffleBoundary
public QIRNumber div(final QIRNumber left, final QIRNumber right) {
return new QIRNumber(sourceSection, left.value / right.value);
return new QIRNumber(sourceSection, left.getValue() / right.getValue());
}
@Specialization
@TruffleBoundary
protected QIRBigNumber div(QIRBigNumber left, QIRBigNumber right) {
return new QIRBigNumber(sourceSection, left.value.divide(right.value));
return new QIRBigNumber(sourceSection, left.getValue().divide(right.getValue()));
}
@Override
......
......@@ -27,13 +27,13 @@ public abstract class QIRMinus extends QIRBinaryNode {
@Specialization(rewriteOn = ArithmeticException.class)
@TruffleBoundary
protected QIRNumber minus(QIRNumber left, QIRNumber right) {
return new QIRNumber(sourceSection, left.value - right.value);
return new QIRNumber(sourceSection, left.getValue() - right.getValue());
}
@Specialization
@TruffleBoundary
protected QIRBigNumber minus(QIRBigNumber left, QIRBigNumber right) {
return new QIRBigNumber(sourceSection, left.value.subtract(right.value));
return new QIRBigNumber(sourceSection, left.getValue().subtract(right.getValue()));
}
@Override
......
......@@ -26,13 +26,13 @@ public abstract class QIRMod extends QIRBinaryNode {
@Specialization(rewriteOn = ArithmeticException.class)
protected QIRNumber mod(QIRNumber left, QIRNumber right) {
return new QIRNumber(sourceSection, left.value % right.value);
return new QIRNumber(sourceSection, left.getValue() % right.getValue());
}
@Specialization
@TruffleBoundary
protected QIRBigNumber mod(QIRBigNumber left, QIRBigNumber right) {
return new QIRBigNumber(sourceSection, left.value.mod(right.value));
return new QIRBigNumber(sourceSection, left.getValue().mod(right.getValue()));
}
@Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment