comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/TruffleTypes.java @ 10597:79041ab43660

Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
author Christian Humer <christian.humer@gmail.com>
date Mon, 01 Jul 2013 20:58:32 +0200
parents
children 3ae117e62905
comparison
equal deleted inserted replaced
10596:f43eb2f1bbbc 10597:79041ab43660
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;
24
25 import java.util.*;
26
27 import javax.lang.model.element.*;
28 import javax.lang.model.type.*;
29 import javax.tools.Diagnostic.Kind;
30
31 import com.oracle.truffle.api.*;
32 import com.oracle.truffle.api.frame.*;
33 import com.oracle.truffle.api.nodes.*;
34 import com.oracle.truffle.api.nodes.Node.Child;
35 import com.oracle.truffle.api.nodes.Node.Children;
36
37 /**
38 * THIS IS NOT PUBLIC API.
39 */
40 public final class TruffleTypes {
41
42 private final TypeMirror node;
43 private final TypeMirror nodeArray;
44 private final TypeMirror unexpectedValueException;
45 private final TypeMirror frame;
46 private final TypeMirror assumption;
47 private final TypeMirror invalidAssumption;
48 private final DeclaredType childAnnotation;
49 private final DeclaredType childrenAnnotation;
50 private final DeclaredType nodeInfoAnnotation;
51 private final DeclaredType nodeInfoKind;
52 private final TypeMirror compilerDirectives;
53 private final TypeMirror compilerAsserts;
54
55 private final List<String> errors = new ArrayList<>();
56
57 public TruffleTypes(ProcessorContext context) {
58 node = getRequired(context, Node.class);
59 nodeArray = context.getEnvironment().getTypeUtils().getArrayType(node);
60 unexpectedValueException = getRequired(context, UnexpectedResultException.class);
61 frame = getRequired(context, VirtualFrame.class);
62 childAnnotation = getRequired(context, Child.class);
63 childrenAnnotation = getRequired(context, Children.class);
64 compilerDirectives = getRequired(context, CompilerDirectives.class);
65 compilerAsserts = getRequired(context, CompilerAsserts.class);
66 assumption = getRequired(context, Assumption.class);
67 invalidAssumption = getRequired(context, InvalidAssumptionException.class);
68 nodeInfoAnnotation = getRequired(context, NodeInfo.class);
69 nodeInfoKind = getRequired(context, NodeInfo.Kind.class);
70 }
71
72 public DeclaredType getNodeInfoAnnotation() {
73 return nodeInfoAnnotation;
74 }
75
76 public boolean verify(ProcessorContext context, Element element, AnnotationMirror mirror) {
77 if (errors.isEmpty()) {
78 return true;
79 }
80
81 for (String error : errors) {
82 context.getLog().message(Kind.ERROR, element, mirror, null, error);
83 }
84
85 return false;
86 }
87
88 public DeclaredType getNodeInfoKind() {
89 return nodeInfoKind;
90 }
91
92 private DeclaredType getRequired(ProcessorContext context, Class clazz) {
93 TypeMirror type = context.getType(clazz);
94 if (type == null) {
95 errors.add(String.format("Could not find required type: %s", clazz.getSimpleName()));
96 }
97 return (DeclaredType) type;
98 }
99
100 public TypeMirror getInvalidAssumption() {
101 return invalidAssumption;
102 }
103
104 public TypeMirror getAssumption() {
105 return assumption;
106 }
107
108 public TypeMirror getCompilerDirectives() {
109 return compilerDirectives;
110 }
111
112 public TypeMirror getNode() {
113 return node;
114 }
115
116 public TypeMirror getNodeArray() {
117 return nodeArray;
118 }
119
120 public TypeMirror getFrame() {
121 return frame;
122 }
123
124 public TypeMirror getUnexpectedValueException() {
125 return unexpectedValueException;
126 }
127
128 public DeclaredType getChildAnnotation() {
129 return childAnnotation;
130 }
131
132 public DeclaredType getChildrenAnnotation() {
133 return childrenAnnotation;
134 }
135
136 public TypeMirror getCompilerAsserts() {
137 return compilerAsserts;
138 }
139 }