Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/SpecializationMethodParser.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 | 4830676526e3 |
comparison
equal
deleted
inserted
replaced
10596:f43eb2f1bbbc | 10597:79041ab43660 |
---|---|
1 /* | |
2 * Copyright (c) 2012, 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.node; | |
24 | |
25 import java.lang.annotation.*; | |
26 import java.util.*; | |
27 | |
28 import javax.lang.model.element.*; | |
29 import javax.lang.model.type.*; | |
30 | |
31 import com.oracle.truffle.api.dsl.*; | |
32 import com.oracle.truffle.dsl.processor.*; | |
33 import com.oracle.truffle.dsl.processor.template.*; | |
34 | |
35 public class SpecializationMethodParser extends NodeMethodParser<SpecializationData> { | |
36 | |
37 public SpecializationMethodParser(ProcessorContext context, NodeData operation) { | |
38 super(context, operation); | |
39 } | |
40 | |
41 @Override | |
42 public MethodSpec createSpecification(ExecutableElement method, AnnotationMirror mirror) { | |
43 return createDefaultMethodSpec(method, mirror, true, null); | |
44 } | |
45 | |
46 @Override | |
47 public SpecializationData create(TemplateMethod method) { | |
48 return parseSpecialization(method); | |
49 } | |
50 | |
51 @Override | |
52 public Class<? extends Annotation> getAnnotationType() { | |
53 return Specialization.class; | |
54 } | |
55 | |
56 private SpecializationData parseSpecialization(TemplateMethod method) { | |
57 int order = Utils.getAnnotationValue(Integer.class, method.getMarkerAnnotation(), "order"); | |
58 if (order < 0 && order != Specialization.DEFAULT_ORDER) { | |
59 method.addError("Invalid order attribute %d. The value must be >= 0 or the default value."); | |
60 return null; | |
61 } | |
62 | |
63 AnnotationValue rewriteValue = Utils.getAnnotationValue(method.getMarkerAnnotation(), "rewriteOn"); | |
64 List<TypeMirror> exceptionTypes = Utils.getAnnotationValueList(TypeMirror.class, method.getMarkerAnnotation(), "rewriteOn"); | |
65 List<SpecializationThrowsData> exceptionData = new ArrayList<>(); | |
66 for (TypeMirror exceptionType : exceptionTypes) { | |
67 SpecializationThrowsData throwsData = new SpecializationThrowsData(method.getMarkerAnnotation(), rewriteValue, exceptionType); | |
68 if (!Utils.canThrowType(method.getMethod().getThrownTypes(), exceptionType)) { | |
69 throwsData.addError("Method must specify a throws clause with the exception type '%s'.", Utils.getQualifiedName(exceptionType)); | |
70 } | |
71 exceptionData.add(throwsData); | |
72 } | |
73 | |
74 Collections.sort(exceptionData, new Comparator<SpecializationThrowsData>() { | |
75 | |
76 @Override | |
77 public int compare(SpecializationThrowsData o1, SpecializationThrowsData o2) { | |
78 return Utils.compareByTypeHierarchy(o1.getJavaClass(), o2.getJavaClass()); | |
79 } | |
80 }); | |
81 SpecializationData specialization = new SpecializationData(method, order, exceptionData); | |
82 List<String> guardDefs = Utils.getAnnotationValueList(String.class, specialization.getMarkerAnnotation(), "guards"); | |
83 specialization.setGuardDefinitions(guardDefs); | |
84 | |
85 List<String> assumptionDefs = Utils.getAnnotationValueList(String.class, specialization.getMarkerAnnotation(), "assumptions"); | |
86 specialization.setAssumptions(assumptionDefs); | |
87 | |
88 for (String assumption : assumptionDefs) { | |
89 if (!getNode().getAssumptions().contains(assumption)) { | |
90 specialization.addError("Undeclared assumption '%s' used. Use @NodeAssumptions to declare them.", assumption); | |
91 } | |
92 } | |
93 | |
94 return specialization; | |
95 } | |
96 } |