Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/model/NodeExecutionData.java @ 21951:9c8c0937da41
Moving all sources into truffle subdirectory
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Wed, 17 Jun 2015 10:58:08 +0200 |
parents | graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/model/NodeExecutionData.java@18c0f02fa4d2 |
children | dc83cc1f94f2 |
comparison
equal
deleted
inserted
replaced
21950:2a5011c7e641 | 21951:9c8c0937da41 |
---|---|
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 java.util.*; | |
26 | |
27 import javax.lang.model.type.*; | |
28 | |
29 import com.oracle.truffle.dsl.processor.model.NodeChildData.Cardinality; | |
30 | |
31 public class NodeExecutionData { | |
32 | |
33 private final NodeChildData child; | |
34 private final String name; | |
35 private final int index; | |
36 private final int childIndex; | |
37 private final boolean shortCircuit; | |
38 private final List<TypeMirror> typeRestrictions = new ArrayList<>(); | |
39 | |
40 public NodeExecutionData(NodeChildData child, int index, int childIndex, boolean shortCircuit) { | |
41 this.child = child; | |
42 this.index = index; | |
43 this.childIndex = childIndex; | |
44 this.shortCircuit = shortCircuit; | |
45 this.name = createName(); | |
46 } | |
47 | |
48 private String createName() { | |
49 return child != null ? createName(child.getName(), childIndex) : ("arg" + index); | |
50 } | |
51 | |
52 public int getIndex() { | |
53 return index; | |
54 } | |
55 | |
56 public List<TypeMirror> getTypeRestrictions() { | |
57 return typeRestrictions; | |
58 } | |
59 | |
60 public TypeMirror getNodeType() { | |
61 TypeMirror type; | |
62 if (child.getCardinality() == Cardinality.MANY && child.getNodeType().getKind() == TypeKind.ARRAY) { | |
63 type = ((ArrayType) child.getNodeType()).getComponentType(); | |
64 } else { | |
65 type = child.getNodeType(); | |
66 } | |
67 return type; | |
68 } | |
69 | |
70 public String getName() { | |
71 return name; | |
72 } | |
73 | |
74 public NodeChildData getChild() { | |
75 return child; | |
76 } | |
77 | |
78 public int getChildIndex() { | |
79 return childIndex; | |
80 } | |
81 | |
82 public boolean isIndexed() { | |
83 return childIndex > -1; | |
84 } | |
85 | |
86 public boolean isShortCircuit() { | |
87 return shortCircuit; | |
88 } | |
89 | |
90 public String getIndexedName() { | |
91 return createIndexedName(child, childIndex); | |
92 } | |
93 | |
94 public static String createIndexedName(NodeChildData child, int varArgsIndex) { | |
95 String shortCircuitName = child.getName(); | |
96 if (child.getCardinality().isMany()) { | |
97 shortCircuitName = shortCircuitName + "[" + varArgsIndex + "]"; | |
98 } | |
99 return shortCircuitName; | |
100 } | |
101 | |
102 public static String createName(String childName, int index) { | |
103 if (index > -1) { | |
104 return childName + index; | |
105 } | |
106 return childName; | |
107 } | |
108 | |
109 } |