Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/SpecializationMethodParser.java @ 8252:0905d796944a
Refactored codegen error model to make error redirection a lot easier.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Wed, 13 Mar 2013 19:58:28 +0100 |
parents | c4c3f50fa9c2 |
children | 89006c76f737 |
comparison
equal
deleted
inserted
replaced
8251:cb70ed101b5f | 8252:0905d796944a |
---|---|
55 } | 55 } |
56 | 56 |
57 private SpecializationData parseSpecialization(TemplateMethod method) { | 57 private SpecializationData parseSpecialization(TemplateMethod method) { |
58 int order = Utils.getAnnotationValue(Integer.class, method.getMarkerAnnotation(), "order"); | 58 int order = Utils.getAnnotationValue(Integer.class, method.getMarkerAnnotation(), "order"); |
59 if (order < 0 && order != Specialization.DEFAULT_ORDER) { | 59 if (order < 0 && order != Specialization.DEFAULT_ORDER) { |
60 getContext().getLog().error(method.getMethod(), method.getMarkerAnnotation(), "Invalid order attribute %d. The value must be >= 0 or the default value."); | 60 method.addError("Invalid order attribute %d. The value must be >= 0 or the default value."); |
61 return null; | 61 return null; |
62 } | 62 } |
63 | 63 |
64 AnnotationValue rewriteValue = Utils.getAnnotationValue(method.getMarkerAnnotation(), "rewriteOn"); | |
64 List<TypeMirror> exceptionTypes = Utils.getAnnotationValueList(TypeMirror.class, method.getMarkerAnnotation(), "rewriteOn"); | 65 List<TypeMirror> exceptionTypes = Utils.getAnnotationValueList(TypeMirror.class, method.getMarkerAnnotation(), "rewriteOn"); |
65 List<SpecializationThrowsData> exceptionData = new ArrayList<>(); | 66 List<SpecializationThrowsData> exceptionData = new ArrayList<>(); |
66 for (TypeMirror exceptionType : exceptionTypes) { | 67 for (TypeMirror exceptionType : exceptionTypes) { |
67 exceptionData.add(new SpecializationThrowsData(method.getMarkerAnnotation(), exceptionType)); | 68 SpecializationThrowsData throwsData = new SpecializationThrowsData(method.getMarkerAnnotation(), rewriteValue, exceptionType); |
68 | |
69 if (!Utils.canThrowType(method.getMethod().getThrownTypes(), exceptionType)) { | 69 if (!Utils.canThrowType(method.getMethod().getThrownTypes(), exceptionType)) { |
70 getContext().getLog().error(method.getMethod(), "Method must specify a throws clause with the exception type '%s'.", Utils.getQualifiedName(exceptionType)); | 70 throwsData.addError("Method must specify a throws clause with the exception type '%s'.", Utils.getQualifiedName(exceptionType)); |
71 return null; | |
72 } | 71 } |
72 exceptionData.add(throwsData); | |
73 } | 73 } |
74 | 74 |
75 Collections.sort(exceptionData, new Comparator<SpecializationThrowsData>() { | 75 Collections.sort(exceptionData, new Comparator<SpecializationThrowsData>() { |
76 | 76 |
77 @Override | 77 @Override |
79 return Utils.compareByTypeHierarchy(o1.getJavaClass(), o2.getJavaClass()); | 79 return Utils.compareByTypeHierarchy(o1.getJavaClass(), o2.getJavaClass()); |
80 } | 80 } |
81 }); | 81 }); |
82 SpecializationData specialization = new SpecializationData(method, order, exceptionData); | 82 SpecializationData specialization = new SpecializationData(method, order, exceptionData); |
83 boolean valid = true; | 83 boolean valid = true; |
84 AnnotationValue guardsValue = Utils.getAnnotationValue(method.getMarkerAnnotation(), "guards"); | |
84 List<String> guardDefs = Utils.getAnnotationValueList(String.class, specialization.getMarkerAnnotation(), "guards"); | 85 List<String> guardDefs = Utils.getAnnotationValueList(String.class, specialization.getMarkerAnnotation(), "guards"); |
85 SpecializationGuardData[] guardData = new SpecializationGuardData[guardDefs.size()]; | 86 List<SpecializationGuardData> guardData = new ArrayList<>(guardDefs.size()); |
86 for (int i = 0; i < guardData.length; i++) { | 87 for (int i = 0; i < guardDefs.size(); i++) { |
87 String guardMethod = guardDefs.get(i); | 88 String guardMethod = guardDefs.get(i); |
88 | 89 |
89 boolean onSpecialization = true; | 90 SpecializationGuardData assignedGuard = new SpecializationGuardData(specialization, guardsValue, guardMethod, true, true); |
90 boolean onExecution = true; | |
91 | 91 |
92 if (!onSpecialization && !onExecution) { | 92 guardData.add(assignedGuard); |
93 String message = "Either onSpecialization, onExecution or both must be enabled."; | |
94 getContext().getLog().error(method.getMethod(), message); | |
95 valid = false; | |
96 continue; | |
97 } | |
98 | 93 |
99 guardData[i] = new SpecializationGuardData(guardMethod, onSpecialization, onExecution); | 94 GuardData compatibleGuard = matchSpecializationGuard(specialization, assignedGuard); |
100 | |
101 GuardData compatibleGuard = matchSpecializationGuard(specialization, guardData[i]); | |
102 if (compatibleGuard != null) { | 95 if (compatibleGuard != null) { |
103 guardData[i].setGuardDeclaration(compatibleGuard); | 96 assignedGuard.setGuardDeclaration(compatibleGuard); |
104 } else { | 97 } else { |
105 valid = false; | 98 valid = false; |
106 } | 99 } |
107 } | 100 } |
108 | 101 |
134 ParameterSpec spec = param.getSpecification(); | 127 ParameterSpec spec = param.getSpecification(); |
135 expectedParameterSpecs.add(new ParameterSpec(spec.getName(), param.getActualType(), false)); | 128 expectedParameterSpecs.add(new ParameterSpec(spec.getName(), param.getActualType(), false)); |
136 } | 129 } |
137 List<TypeDef> typeDefs = createTypeDefinitions(returnTypeSpec, expectedParameterSpecs); | 130 List<TypeDef> typeDefs = createTypeDefinitions(returnTypeSpec, expectedParameterSpecs); |
138 String expectedSignature = TemplateMethodParser.createExpectedSignature(specializationGuard.getGuardMethod(), returnTypeSpec, expectedParameterSpecs, typeDefs); | 131 String expectedSignature = TemplateMethodParser.createExpectedSignature(specializationGuard.getGuardMethod(), returnTypeSpec, expectedParameterSpecs, typeDefs); |
139 AnnotationValue value = Utils.getAnnotationValue(specialization.getMarkerAnnotation(), "guards"); | 132 specializationGuard.addError("No guard with signature '%s' found in type system.", expectedSignature); |
140 getContext().getLog().error(specialization.getMethod(), specialization.getMarkerAnnotation(), value, "No guard with signature '%s' found in type system.", expectedSignature); | |
141 return null; | |
142 } | 133 } |
143 | 134 |
144 return compatibleGuard; | 135 return compatibleGuard; |
145 } | 136 } |
146 | 137 |