Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLLogicalAndNode.java @ 16913:b879421229db
SL: better toString for SL nodes.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Sat, 23 Aug 2014 19:31:33 +0200 |
parents | abe7128ca473 |
children | c0455554d45b |
rev | line source |
---|---|
7503
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1 /* |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. |
7503
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
4 * |
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
8 * |
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
13 * accompanied this code). |
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
14 * |
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
18 * |
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
21 * questions. |
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
22 */ |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
10597
diff
changeset
|
23 package com.oracle.truffle.sl.nodes.expression; |
7503
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
24 |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
9222
diff
changeset
|
25 import com.oracle.truffle.api.dsl.*; |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
26 import com.oracle.truffle.api.nodes.*; |
16512
abe7128ca473
SL: upgrade source attribution
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
13836
diff
changeset
|
27 import com.oracle.truffle.api.source.*; |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
10597
diff
changeset
|
28 import com.oracle.truffle.sl.nodes.*; |
7503
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
29 |
13836
64c77f0577bb
More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
30 /** |
64c77f0577bb
More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
31 * This class declares specializations similar to the extensively documented {@link SLAddNode}. It |
64c77f0577bb
More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
32 * uses one additional feature of the Truffle DSL: {@link ShortCircuit}. |
64c77f0577bb
More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
33 * <p> |
64c77f0577bb
More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
34 * Logical operations in SL use short circuit evaluation: if the evaluation of the left operand |
64c77f0577bb
More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
35 * already decides the result of the operation, the right operand must not be executed. This is |
64c77f0577bb
More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
36 * expressed in the Truffle DSL via a method annotated with {@link ShortCircuit}, which returns |
64c77f0577bb
More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
37 * whether a child needs to be executed based on the result of already executed children. |
64c77f0577bb
More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
38 */ |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
39 @NodeInfo(shortName = "&&") |
7503
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
40 @SuppressWarnings("unused") |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
10597
diff
changeset
|
41 public abstract class SLLogicalAndNode extends SLBinaryNode { |
7503
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
42 |
16512
abe7128ca473
SL: upgrade source attribution
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
13836
diff
changeset
|
43 public SLLogicalAndNode(SourceSection src) { |
abe7128ca473
SL: upgrade source attribution
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
13836
diff
changeset
|
44 super(src); |
abe7128ca473
SL: upgrade source attribution
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
13836
diff
changeset
|
45 } |
abe7128ca473
SL: upgrade source attribution
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
13836
diff
changeset
|
46 |
13836
64c77f0577bb
More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
47 /** |
64c77f0577bb
More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
48 * This method is called after the left child was evaluated, but before the right child is |
64c77f0577bb
More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
49 * evaluated. The right child is only evaluated when the return value is {code true}. |
64c77f0577bb
More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
50 */ |
7503
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
51 @ShortCircuit("rightNode") |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
52 protected boolean needsRightNode(boolean left) { |
7503
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
53 return left; |
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
54 } |
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
55 |
13836
64c77f0577bb
More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
56 /** |
64c77f0577bb
More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
57 * Similar to {@link #needsRightNode(boolean)}, but for generic cases where the type of the left |
64c77f0577bb
More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
58 * child is not known. |
64c77f0577bb
More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
59 */ |
7503
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
60 @ShortCircuit("rightNode") |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
61 protected boolean needsRightNode(Object left) { |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
10597
diff
changeset
|
62 return left instanceof Boolean && needsRightNode(((Boolean) left).booleanValue()); |
7503
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
63 } |
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
64 |
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
65 @Specialization |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
66 protected boolean doBoolean(boolean left, boolean hasRight, boolean right) { |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
10597
diff
changeset
|
67 return left && right; |
7503
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
68 } |
31da1716950f
Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
69 } |