Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/instrument/SLStandardASTProber.java @ 18485:e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Sun, 23 Nov 2014 16:07:23 -0800 |
parents | |
children | d1c1cd2530d7 |
comparison
equal
deleted
inserted
replaced
18484:e97e1f07a3d6 | 18485:e3c95cbbb50c |
---|---|
1 /* | |
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 package com.oracle.truffle.sl.nodes.instrument; | |
24 | |
25 import static com.oracle.truffle.api.instrument.StandardSyntaxTag.*; | |
26 | |
27 import com.oracle.truffle.api.instrument.*; | |
28 import com.oracle.truffle.api.nodes.*; | |
29 import com.oracle.truffle.sl.nodes.*; | |
30 import com.oracle.truffle.sl.nodes.controlflow.*; | |
31 import com.oracle.truffle.sl.nodes.local.*; | |
32 | |
33 /** | |
34 * A visitor which traverses a completely parsed Simple AST (presumed not yet executed) and enables | |
35 * instrumentation at a few standard kinds of nodes. | |
36 */ | |
37 public class SLStandardASTProber implements NodeVisitor, ASTProber { | |
38 | |
39 /** | |
40 * {@inheritDoc} | |
41 * <p> | |
42 * Instruments and tags all relevant {@link SLStatementNode}s and {@link SLExpressionNode}s. | |
43 * Currently, only SLStatementNodes that are not SLExpressionNodes are tagged as statements. | |
44 */ | |
45 public boolean visit(Node node) { | |
46 | |
47 if (node instanceof SLStatementNode) { | |
48 | |
49 // We have to distinguish between SLExpressionNode and SLStatementNode since some of the | |
50 // generated factories have methods that require SLExpressionNodes as parameters. Since | |
51 // SLExpressionNodes are a subclass of SLStatementNode, we check if something is an | |
52 // SLExpressionNode first. | |
53 if (node instanceof SLExpressionNode && node.getParent() != null) { | |
54 SLExpressionNode expressionNode = (SLExpressionNode) node; | |
55 if (expressionNode.getSourceSection() != null) { | |
56 Probe probe = expressionNode.probe(); | |
57 | |
58 if (node instanceof SLWriteLocalVariableNode) { | |
59 probe.tagAs(STATEMENT, null); | |
60 probe.tagAs(ASSIGNMENT, null); | |
61 } | |
62 } | |
63 } else if (node instanceof SLStatementNode && node.getParent() != null) { | |
64 | |
65 SLStatementNode statementNode = (SLStatementNode) node; | |
66 if (statementNode.getSourceSection() != null) { | |
67 Probe probe = statementNode.probe(); | |
68 probe.tagAs(STATEMENT, null); | |
69 | |
70 if (node instanceof SLWhileNode) { | |
71 probe.tagAs(START_LOOP, null); | |
72 } | |
73 } | |
74 } | |
75 } | |
76 return true; | |
77 } | |
78 | |
79 public void probeAST(Node node) { | |
80 node.accept(this); | |
81 } | |
82 } |