use of com.oracle.truffle.sl.nodes.SLExpressionNode in project graal by oracle.
the class SLNodeFactory method createBinary.
/**
* Returns the corresponding subclass of {@link SLExpressionNode} for binary expressions. </br>
* These nodes are currently not instrumented.
*
* @param opToken The operator of the binary expression
* @param leftNode The left node of the expression
* @param rightNode The right node of the expression
* @return A subclass of SLExpressionNode using the given parameters based on the given opToken.
* null if either leftNode or rightNode is null.
*/
public SLExpressionNode createBinary(Token opToken, SLExpressionNode leftNode, SLExpressionNode rightNode) {
if (leftNode == null || rightNode == null) {
return null;
}
final SLExpressionNode leftUnboxed;
if (leftNode instanceof SLBinaryNode) {
// SLBinaryNode never returns boxed value
leftUnboxed = leftNode;
} else {
leftUnboxed = SLUnboxNodeGen.create(leftNode);
}
final SLExpressionNode rightUnboxed;
if (rightNode instanceof SLBinaryNode) {
// SLBinaryNode never returns boxed value
rightUnboxed = rightNode;
} else {
rightUnboxed = SLUnboxNodeGen.create(rightNode);
}
final SLExpressionNode result;
switch(opToken.val) {
case "+":
result = SLAddNodeGen.create(leftUnboxed, rightUnboxed);
break;
case "*":
result = SLMulNodeGen.create(leftUnboxed, rightUnboxed);
break;
case "/":
result = SLDivNodeGen.create(leftUnboxed, rightUnboxed);
break;
case "-":
result = SLSubNodeGen.create(leftUnboxed, rightUnboxed);
break;
case "<":
result = SLLessThanNodeGen.create(leftUnboxed, rightUnboxed);
break;
case "<=":
result = SLLessOrEqualNodeGen.create(leftUnboxed, rightUnboxed);
break;
case ">":
result = SLLogicalNotNodeGen.create(SLLessOrEqualNodeGen.create(leftUnboxed, rightUnboxed));
break;
case ">=":
result = SLLogicalNotNodeGen.create(SLLessThanNodeGen.create(leftUnboxed, rightUnboxed));
break;
case "==":
result = SLEqualNodeGen.create(leftUnboxed, rightUnboxed);
break;
case "!=":
result = SLLogicalNotNodeGen.create(SLEqualNodeGen.create(leftUnboxed, rightUnboxed));
break;
case "&&":
result = new SLLogicalAndNode(leftUnboxed, rightUnboxed);
break;
case "||":
result = new SLLogicalOrNode(leftUnboxed, rightUnboxed);
break;
default:
throw new RuntimeException("unexpected operation: " + opToken.val);
}
int start = leftNode.getSourceCharIndex();
int length = rightNode.getSourceEndIndex() - start;
result.setSourceSection(start, length);
return result;
}
use of com.oracle.truffle.sl.nodes.SLExpressionNode in project graal by oracle.
the class SLNodeFactory method createWriteProperty.
/**
* Returns an {@link SLWritePropertyNode} for the given parameters.
*
* @param receiverNode The receiver object of the property assignment
* @param nameNode The name of the property being assigned
* @param valueNode The value to be assigned
* @return An SLExpressionNode for the given parameters. null if receiverNode, nameNode or
* valueNode is null.
*/
public SLExpressionNode createWriteProperty(SLExpressionNode receiverNode, SLExpressionNode nameNode, SLExpressionNode valueNode) {
if (receiverNode == null || nameNode == null || valueNode == null) {
return null;
}
final SLExpressionNode result = SLWritePropertyNodeGen.create(receiverNode, nameNode, valueNode);
final int start = receiverNode.getSourceCharIndex();
final int length = valueNode.getSourceEndIndex() - start;
result.setSourceSection(start, length);
return result;
}
use of com.oracle.truffle.sl.nodes.SLExpressionNode in project graal by oracle.
the class SLNodeFactory method createNumericLiteral.
public SLExpressionNode createNumericLiteral(Token literalToken) {
SLExpressionNode result;
try {
/* Try if the literal is small enough to fit into a long value. */
result = new SLLongLiteralNode(Long.parseLong(literalToken.val));
} catch (NumberFormatException ex) {
/* Overflow of long value, so fall back to BigInteger. */
result = new SLBigIntegerLiteralNode(new BigInteger(literalToken.val));
}
srcFromToken(result, literalToken);
return result;
}
use of com.oracle.truffle.sl.nodes.SLExpressionNode in project graal by oracle.
the class SLNodeFactory method createCall.
/**
* Returns an {@link SLInvokeNode} for the given parameters.
*
* @param functionNode The function being called
* @param parameterNodes The parameters of the function call
* @param finalToken A token used to determine the end of the sourceSelection for this call
* @return An SLInvokeNode for the given parameters. null if functionNode or any of the
* parameterNodes are null.
*/
public SLExpressionNode createCall(SLExpressionNode functionNode, List<SLExpressionNode> parameterNodes, Token finalToken) {
if (functionNode == null || containsNull(parameterNodes)) {
return null;
}
final SLExpressionNode result = new SLInvokeNode(functionNode, parameterNodes.toArray(new SLExpressionNode[parameterNodes.size()]));
final int startPos = functionNode.getSourceCharIndex();
final int endPos = finalToken.charPos + finalToken.val.length();
result.setSourceSection(startPos, endPos - startPos);
return result;
}
Aggregations