Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/model/NodeExecutionData.java @ 16851:2db61eddcb97
Truffle-DSL: argument syntax support for guards
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 18 Aug 2014 18:41:16 +0200 |
parents | |
children | 906367e494ca |
comparison
equal
deleted
inserted
replaced
16850:d6c002f4d2a9 | 16851:2db61eddcb97 |
---|---|
1 /* | |
2 * Copyright (c) 2012, 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.dsl.processor.model; | |
24 | |
25 import javax.lang.model.type.*; | |
26 | |
27 import com.oracle.truffle.dsl.processor.model.NodeChildData.Cardinality; | |
28 | |
29 public class NodeExecutionData { | |
30 | |
31 private final NodeChildData child; | |
32 private final String name; | |
33 private final int index; | |
34 private final boolean shortCircuit; | |
35 | |
36 public NodeExecutionData(NodeChildData child, int index, boolean shortCircuit) { | |
37 this.child = child; | |
38 this.index = index; | |
39 this.shortCircuit = shortCircuit; | |
40 this.name = createName(); | |
41 } | |
42 | |
43 private String createName() { | |
44 return createName(child.getName(), index); | |
45 } | |
46 | |
47 public TypeMirror getNodeType() { | |
48 TypeMirror type; | |
49 if (child.getCardinality() == Cardinality.MANY && child.getNodeType().getKind() == TypeKind.ARRAY) { | |
50 type = ((ArrayType) child.getNodeType()).getComponentType(); | |
51 } else { | |
52 type = child.getNodeType(); | |
53 } | |
54 return type; | |
55 } | |
56 | |
57 public String getName() { | |
58 return name; | |
59 } | |
60 | |
61 public NodeChildData getChild() { | |
62 return child; | |
63 } | |
64 | |
65 public int getIndex() { | |
66 return index; | |
67 } | |
68 | |
69 public boolean isIndexed() { | |
70 return index > -1; | |
71 } | |
72 | |
73 public boolean isShortCircuit() { | |
74 return shortCircuit; | |
75 } | |
76 | |
77 public String getShortCircuitId() { | |
78 return createShortCircuitId(child, index); | |
79 } | |
80 | |
81 public static String createShortCircuitId(NodeChildData child, int varArgsIndex) { | |
82 String shortCircuitName = child.getName(); | |
83 if (child.getCardinality().isMany()) { | |
84 shortCircuitName = shortCircuitName + "[" + varArgsIndex + "]"; | |
85 } | |
86 return shortCircuitName; | |
87 } | |
88 | |
89 public static String createName(String childName, int index) { | |
90 if (index > -1) { | |
91 return childName + index; | |
92 } | |
93 return childName; | |
94 } | |
95 | |
96 } |