Mercurial > hg > truffle
diff graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/SLNodeFactory.java @ 16702:2a5ec181dad4
SL: Added instrumentation testing
author | David Piorkowski <david.piorkowski@oracle.com> |
---|---|
date | Tue, 05 Aug 2014 16:34:08 -0700 |
parents | 7c8ddb4233cd |
children | 7661cc464239 |
line wrap: on
line diff
--- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/SLNodeFactory.java Tue Aug 05 22:00:12 2014 +0200 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/SLNodeFactory.java Tue Aug 05 16:34:08 2014 -0700 @@ -155,40 +155,127 @@ } } + /** + * Returns a {@link SLBreakNode} for the given token. This node will be instrumented, tagged as + * a statement and wrapped in an {@link SLStatementWrapper} if an {@link SLASTProber} was + * initialized in this class. ({@link #prober} != null) + * + * @param breakToken The token containing the break node's info + * @return either: + * <ul> + * <li>An un-instrumented SLBreakNode if there is no prober</li> + * <li>An {@link SLStatementWrapper} instrumenting this node.</li> + * </ul> + */ public SLStatementNode createBreak(Token breakToken) { - return new SLBreakNode(srcFromToken(breakToken)); + final SLBreakNode breakNode = new SLBreakNode(srcFromToken(breakToken)); + if (prober != null) { + return prober.probeAsStatement(breakNode); + } + return breakNode; } + /** + * Returns a {@link SLContinueNode} for the given token. This node will be instrumented, tagged + * as a statement and wrapped in an {@link SLStatementWrapper} if an {@link SLASTProber} was + * initialized in this class. ({@link #prober} != null) + * + * @param continueToken The token containing the continue node's info + * @return either: + * <ul> + * <li>An un-instrumented SLContinueNode if there is no prober</li> + * <li>An {@link SLStatementWrapper} instrumenting this node.</li> + * </ul> + */ public SLStatementNode createContinue(Token continueToken) { - return new SLContinueNode(srcFromToken(continueToken)); + final SLContinueNode continueNode = new SLContinueNode(srcFromToken(continueToken)); + if (prober != null) { + return prober.probeAsStatement(continueNode); + } + return continueNode; } + /** + * Returns a {@link SLWhileNode} for the given token. This node will be instrumented, tagged as + * a statement and wrapped in an {@link SLStatementWrapper} if an {@link SLASTProber} was + * initialized in this class. ({@link #prober} != null) + * + * @param whileToken The token containing the while node's info + * @param conditionNode The conditional node for this while loop + * @param bodyNode The body of the while loop + * @return either: + * <ul> + * <li>An un-instrumented SLWhileNode if there is no prober</li> + * <li>An {@link SLStatementWrapper} instrumenting this node.</li> + * </ul> + */ public SLStatementNode createWhile(Token whileToken, SLExpressionNode conditionNode, SLStatementNode bodyNode) { final int start = whileToken.charPos; final int end = bodyNode.getSourceSection().getCharEndIndex(); - return new SLWhileNode(source.createSection(whileToken.val, start, end - start), conditionNode, bodyNode); + final SLWhileNode whileNode = new SLWhileNode(source.createSection(whileToken.val, start, end - start), conditionNode, bodyNode); + if (prober != null) { + return prober.probeAsStatement(whileNode); + } + return whileNode; } + /** + * Returns a {@link SLIfNode} for the given token. This node will be instrumented, tagged as a + * statement and wrapped in an {@link SLStatementWrapper} if an {@link SLASTProber} was + * initialized in this class. ({@link #prober} != null) + * + * @param ifToken The token containing the if node's info + * @param conditionNode The condition node of this if statement + * @param thenPartNode The then part of the if + * @param elsePartNode The else part of the if + * @return either: + * <ul> + * <li>An un-instrumented SLIfNode if there is no prober</li> + * <li>An {@link SLStatementWrapper} instrumenting this node.</li> + * </ul> + */ public SLStatementNode createIf(Token ifToken, SLExpressionNode conditionNode, SLStatementNode thenPartNode, SLStatementNode elsePartNode) { final int start = ifToken.charPos; final int end = elsePartNode == null ? thenPartNode.getSourceSection().getCharEndIndex() : elsePartNode.getSourceSection().getCharEndIndex(); - - // if (prober != null) { - // SLStatementNode wrappedThenNode = prober.probeAsStatement(thenPartNode); - // // SLStatementNode wrappedElseNode = prober.probeAsStatement(elsePartNode); - // return new SLIfNode(source.createSection(t.val, start, end - start), conditionNode, - // wrappedThenNode, elsePartNode); - // } - - return new SLIfNode(source.createSection(ifToken.val, start, end - start), conditionNode, thenPartNode, elsePartNode); + final SLIfNode ifNode = new SLIfNode(source.createSection(ifToken.val, start, end - start), conditionNode, thenPartNode, elsePartNode); + if (prober != null) { + return prober.probeAsStatement(ifNode); + } + return ifNode; } + /** + * Returns a {@link SLReturnNode} for the given token. This node will be instrumented, tagged as + * a statement and wrapped in an {@link SLStatementWrapper} if an {@link SLASTProber} was + * initialized in this class. ({@link #prober} != null) + * + * @param t The token containing the return node's info + * @param valueNode The value of the return + * @return either: + * <ul> + * <li>An un-instrumented SLReturnNode if there is no prober</li> + * <li>An {@link SLStatementWrapper} instrumenting this node.</li> + * </ul> + */ public SLStatementNode createReturn(Token t, SLExpressionNode valueNode) { final int start = t.charPos; final int length = valueNode == null ? t.val.length() : valueNode.getSourceSection().getCharEndIndex() - start; - return new SLReturnNode(source.createSection(t.val, start, length), valueNode); + final SLReturnNode returnNode = new SLReturnNode(source.createSection(t.val, start, length), valueNode); + if (prober != null) { + return prober.probeAsStatement(returnNode); + } + return returnNode; } + /** + * 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 for the operation given by opToken. + */ public SLExpressionNode createBinary(Token opToken, SLExpressionNode leftNode, SLExpressionNode rightNode) { int start = leftNode.getSourceSection().getCharIndex(); int length = rightNode.getSourceSection().getCharEndIndex() - start; @@ -223,6 +310,20 @@ } } + /** + * Returns a {@link SLInvokeNode} for the given token. This node will be instrumented, tagged as + * a call and wrapped in an {@link SLExpressionWrapper} if an {@link SLASTProber} was + * initialized in this class. ({@link #prober} != null) + * + * @param nameToken The name of 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 either: + * <ul> + * <li>An un-instrumented SLInvokeNode if there is no prober</li> + * <li>An {@link SLExpressionWrapper} instrumenting this node.</li> + * </ul> + */ public SLExpressionNode createCall(Token nameToken, List<SLExpressionNode> parameterNodes, Token finalToken) { final int startPos = nameToken.charPos; final int endPos = finalToken.charPos + finalToken.val.length(); @@ -235,18 +336,44 @@ return SLInvokeNode.create(src, functionNode, parameterNodes.toArray(new SLExpressionNode[parameterNodes.size()])); } + /** + * Returns a {@link SLWriteLocalVariableNode} for the given token. This node will be + * instrumented, tagged as an assignment and wrapped in an {@link SLExpressionWrapper} if an + * {@link SLASTProber} was initialized in this class. ({@link #prober} != null) + * + * @param nameToken The name of the variable being assigned + * @param valueNode The value to be assigned + * @return either: + * <ul> + * <li>An un-instrumented SLWriteLocalVariableNode if there is no prober</li> + * <li>An {@link SLExpressionWrapper} instrumenting this node.</li> + * </ul> + */ public SLExpressionNode createAssignment(Token nameToken, SLExpressionNode valueNode) { FrameSlot frameSlot = frameDescriptor.findOrAddFrameSlot(nameToken.val); lexicalScope.locals.put(nameToken.val, frameSlot); final int start = nameToken.charPos; final int length = valueNode.getSourceSection().getCharEndIndex() - start; if (prober != null) { - final SLExpressionNode wrappedNode = prober.probeAsLocalAssignment(valueNode, nameToken.val); - return SLWriteLocalVariableNodeFactory.create(source.createSection("=", start, length), wrappedNode, frameSlot); + SLWriteLocalVariableNode writeNode = SLWriteLocalVariableNodeFactory.create(source.createSection("=", start, length), valueNode, frameSlot); + final SLExpressionNode wrappedNode = prober.probeAsLocalAssignment(writeNode, nameToken.val); + return wrappedNode; } return SLWriteLocalVariableNodeFactory.create(source.createSection("=", start, length), valueNode, frameSlot); } + /** + * Returns a {@link SLReadLocalVariableNode} if this read is a local variable or a + * {@link SLFunctionLiteralNode} if this read is global. In Simple, the only global names are + * functions. </br> There is currently no instrumentation for this node. + * + * @param nameToken The name of the variable/function being read + * @return either: + * <ul> + * <li>A SLReadLocalVariableNode representing the local variable being read.</li> + * <li>A SLFunctionLiteralNode representing the function definition</li> + * </ul> + */ public SLExpressionNode createRead(Token nameToken) { final FrameSlot frameSlot = lexicalScope.locals.get(nameToken.val); final SourceSection src = srcFromToken(nameToken);