comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/model/Parameter.java @ 16759:23415229349b

Truffle-DSL: new package structure.
author Christian Humer <christian.humer@gmail.com>
date Mon, 11 Aug 2014 15:57:14 +0200
parents graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/template/ActualParameter.java@85b485b1e8e1
children 08aa0372dad4
comparison
equal deleted inserted replaced
16758:c5f8eeb3cbc8 16759:23415229349b
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.java.*;
28
29 public final class Parameter {
30
31 private final ParameterSpec specification;
32 private TypeData typeSystemType;
33 private TemplateMethod method;
34 private final String localName;
35 private final int specificationVarArgsIndex;
36 private final int typeVarArgsIndex;
37 private final TypeMirror actualType;
38
39 public Parameter(ParameterSpec specification, TypeMirror actualType, int specificationVarArgsIndex, int typeVarArgsIndex) {
40 this.specification = specification;
41 this.actualType = actualType;
42 this.typeSystemType = null;
43
44 this.specificationVarArgsIndex = specificationVarArgsIndex;
45
46 String valueName = specification.getName() + "Value";
47 if (specificationVarArgsIndex > -1) {
48 valueName += specificationVarArgsIndex;
49 }
50 this.typeVarArgsIndex = typeVarArgsIndex;
51 this.localName = valueName;
52 }
53
54 public Parameter(ParameterSpec specification, TypeData actualType, int specificationIndex, int varArgsIndex) {
55 this(specification, actualType.getPrimitiveType(), specificationIndex, varArgsIndex);
56 this.typeSystemType = actualType;
57 }
58
59 public Parameter(Parameter parameter, TypeData otherType) {
60 this(parameter.specification, otherType, parameter.specificationVarArgsIndex, parameter.typeVarArgsIndex);
61 }
62
63 public Parameter(Parameter parameter) {
64 this.specification = parameter.specification;
65 this.actualType = parameter.actualType;
66 this.typeSystemType = parameter.typeSystemType;
67 this.specificationVarArgsIndex = parameter.specificationVarArgsIndex;
68 this.localName = parameter.localName;
69 this.typeVarArgsIndex = parameter.typeVarArgsIndex;
70 }
71
72 public int getTypeVarArgsIndex() {
73 return typeVarArgsIndex;
74 }
75
76 public int getSpecificationVarArgsIndex() {
77 return specificationVarArgsIndex;
78 }
79
80 public String getLocalName() {
81 return localName;
82 }
83
84 void setMethod(TemplateMethod method) {
85 this.method = method;
86 }
87
88 public ParameterSpec getSpecification() {
89 return specification;
90 }
91
92 public TemplateMethod getMethod() {
93 return method;
94 }
95
96 public TypeMirror getType() {
97 return actualType;
98 }
99
100 public TypeData getTypeSystemType() {
101 return typeSystemType;
102 }
103
104 public boolean isTypeVarArgs() {
105 return typeVarArgsIndex >= 0;
106 }
107
108 public Parameter getPreviousParameter() {
109 return method.getPreviousParam(this);
110 }
111
112 @Override
113 public String toString() {
114 return ElementUtils.getSimpleName(actualType);
115 }
116 }