Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/template/ParameterSpec.java @ 8593:54e227b2e199
Refactored ParameterSpec constructors.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 01 Apr 2013 12:14:54 +0200 |
parents | a80bf36c6a1e |
children | ce6e8672f798 |
comparison
equal
deleted
inserted
replaced
8592:a80bf36c6a1e | 8593:54e227b2e199 |
---|---|
25 import java.util.*; | 25 import java.util.*; |
26 | 26 |
27 import javax.lang.model.type.*; | 27 import javax.lang.model.type.*; |
28 | 28 |
29 import com.oracle.truffle.codegen.processor.*; | 29 import com.oracle.truffle.codegen.processor.*; |
30 import com.oracle.truffle.codegen.processor.node.*; | |
31 import com.oracle.truffle.codegen.processor.typesystem.*; | |
32 | 30 |
33 public class ParameterSpec { | 31 public class ParameterSpec { |
34 | 32 |
35 public enum Cardinality { | 33 public enum Cardinality { |
36 ONE, MULTIPLE; | 34 ONE, MULTIPLE; |
37 } | 35 } |
38 | 36 |
39 private final String name; | 37 private final String name; |
40 private final List<TypeMirror> allowedTypes; | 38 private final List<TypeMirror> allowedTypes; |
39 | |
40 /** Cardinality one or multiple. */ | |
41 private Cardinality cardinality; | 41 private Cardinality cardinality; |
42 private final boolean optional; | 42 /** Type is optional can be dismissed. */ |
43 private final boolean signature; | 43 private boolean optional; |
44 /** Type is part of the method signature. Relevant for comparisons. */ | |
45 private boolean signature; | |
46 /** Type must be indexed when parsing. */ | |
44 private boolean indexed; | 47 private boolean indexed; |
48 /** Type is bound to local final variable. */ | |
45 private boolean local; | 49 private boolean local; |
46 | 50 |
47 public ParameterSpec(String name, List<TypeMirror> allowedTypes, boolean optional, Cardinality cardinality, boolean signature) { | 51 public ParameterSpec(String name, TypeMirror... allowedTypes) { |
48 this.allowedTypes = allowedTypes; | 52 this(name, Arrays.asList(allowedTypes)); |
49 this.name = name; | |
50 this.optional = optional; | |
51 this.cardinality = cardinality; | |
52 this.signature = signature; | |
53 } | 53 } |
54 | 54 |
55 /** Type constructor. */ | 55 public ParameterSpec(String name, List<TypeMirror> allowedTypes) { |
56 public ParameterSpec(String name, TypeMirror singleFixedType, boolean optional, boolean signature) { | 56 this.name = name; |
57 this(name, Arrays.asList(singleFixedType), optional, Cardinality.ONE, signature); | 57 this.allowedTypes = allowedTypes; |
58 } | 58 } |
59 | 59 |
60 /** Type system value constructor. */ | 60 public void setOptional(boolean optional) { |
61 public ParameterSpec(String name, TypeSystemData typeSystem, boolean optional, Cardinality cardinality, boolean signature) { | 61 this.optional = optional; |
62 this(name, typeSystem.getPrimitiveTypeMirrors(), optional, cardinality, signature); | |
63 } | 62 } |
64 | 63 |
65 /** Node value constructor. */ | 64 public void setSignature(boolean signature) { |
66 public ParameterSpec(String name, NodeData nodeData, boolean optional, Cardinality cardinality, boolean signature) { | 65 this.signature = signature; |
67 this(name, nodeTypeMirrors(nodeData), optional, cardinality, signature); | |
68 } | 66 } |
69 | 67 |
70 public void setLocal(boolean local) { | 68 public void setLocal(boolean local) { |
71 this.local = local; | 69 this.local = local; |
72 } | 70 } |
87 this.indexed = indexed; | 85 this.indexed = indexed; |
88 } | 86 } |
89 | 87 |
90 public void setCardinality(Cardinality cardinality) { | 88 public void setCardinality(Cardinality cardinality) { |
91 this.cardinality = cardinality; | 89 this.cardinality = cardinality; |
92 } | |
93 | |
94 private static List<TypeMirror> nodeTypeMirrors(NodeData nodeData) { | |
95 Set<TypeMirror> typeMirrors = new LinkedHashSet<>(); | |
96 | |
97 for (ExecutableTypeData typeData : nodeData.getExecutableTypes()) { | |
98 typeMirrors.add(typeData.getType().getPrimitiveType()); | |
99 } | |
100 | |
101 typeMirrors.add(nodeData.getTypeSystem().getGenericType()); | |
102 | |
103 return new ArrayList<>(typeMirrors); | |
104 } | 90 } |
105 | 91 |
106 public final String getName() { | 92 public final String getName() { |
107 return name; | 93 return name; |
108 } | 94 } |