Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/TruffleTypes.java @ 7291:a748e4d44694
Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Fri, 21 Dec 2012 10:44:31 -0800 |
parents | |
children | 4969921f57b7 |
comparison
equal
deleted
inserted
replaced
7290:a81db08fe930 | 7291:a748e4d44694 |
---|---|
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.codegen.processor; | |
24 | |
25 import java.util.*; | |
26 | |
27 import javax.lang.model.element.*; | |
28 import javax.lang.model.type.*; | |
29 | |
30 import com.oracle.truffle.api.frame.*; | |
31 import com.oracle.truffle.api.nodes.*; | |
32 import com.oracle.truffle.api.nodes.Node.Child; | |
33 import com.oracle.truffle.api.nodes.Node.Children; | |
34 | |
35 /** | |
36 * THIS IS NOT PUBLIC API. | |
37 */ | |
38 public final class TruffleTypes { | |
39 | |
40 private final TypeMirror node; | |
41 private final TypeMirror nodeArray; | |
42 private final TypeMirror unexpectedValueException; | |
43 private final TypeMirror frame; | |
44 private final TypeMirror stableAnnotation; | |
45 private final TypeMirror contentStableAnnotation; | |
46 private final TypeMirror typeConversion; | |
47 | |
48 private final List<String> errors = new ArrayList<>(); | |
49 | |
50 public TruffleTypes(ProcessorContext context) { | |
51 node = getRequired(context, Node.class); | |
52 nodeArray = context.getEnvironment().getTypeUtils().getArrayType(node); | |
53 unexpectedValueException = getRequired(context, UnexpectedResultException.class); | |
54 frame = getRequired(context, VirtualFrame.class); | |
55 stableAnnotation = getRequired(context, Child.class); | |
56 contentStableAnnotation = getRequired(context, Children.class); | |
57 typeConversion = getRequired(context, TypeConversion.class); | |
58 } | |
59 | |
60 public boolean verify(ProcessorContext context, Element element, AnnotationMirror mirror) { | |
61 if (errors.isEmpty()) { | |
62 return true; | |
63 } | |
64 | |
65 for (String error : errors) { | |
66 context.getLog().error(element, mirror, error); | |
67 } | |
68 | |
69 return false; | |
70 } | |
71 | |
72 private TypeMirror getRequired(ProcessorContext context, Class clazz) { | |
73 TypeMirror type = context.getType(clazz); | |
74 if (type == null) { | |
75 errors.add(String.format("Could not find required type: %s", clazz.getSimpleName())); | |
76 } | |
77 return type; | |
78 } | |
79 | |
80 public TypeMirror getTypeConversion() { | |
81 return typeConversion; | |
82 } | |
83 | |
84 public TypeMirror getNode() { | |
85 return node; | |
86 } | |
87 | |
88 public TypeMirror getNodeArray() { | |
89 return nodeArray; | |
90 } | |
91 | |
92 public TypeMirror getFrame() { | |
93 return frame; | |
94 } | |
95 | |
96 public TypeMirror getUnexpectedValueException() { | |
97 return unexpectedValueException; | |
98 } | |
99 | |
100 public TypeMirror getStableAnnotation() { | |
101 return stableAnnotation; | |
102 } | |
103 | |
104 public TypeMirror getContentStableAnnotation() { | |
105 return contentStableAnnotation; | |
106 } | |
107 } |