comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/parser/ImplicitCastParser.java @ 20938:18c0f02fa4d2

Truffle-DSL: make type systems optional.
author Christian Humer <christian.humer@gmail.com>
date Tue, 14 Apr 2015 15:12:48 +0200
parents a665483c3881
children
comparison
equal deleted inserted replaced
20937:37ea76052733 20938:18c0f02fa4d2
21 * questions. 21 * questions.
22 */ 22 */
23 package com.oracle.truffle.dsl.processor.parser; 23 package com.oracle.truffle.dsl.processor.parser;
24 24
25 import java.lang.annotation.*; 25 import java.lang.annotation.*;
26 import java.util.*;
27 26
28 import javax.lang.model.element.*; 27 import javax.lang.model.element.*;
29 import javax.lang.model.type.*; 28 import javax.lang.model.type.*;
30 29
31 import com.oracle.truffle.api.dsl.*; 30 import com.oracle.truffle.api.dsl.*;
32 import com.oracle.truffle.dsl.processor.*; 31 import com.oracle.truffle.dsl.processor.*;
32 import com.oracle.truffle.dsl.processor.java.*;
33 import com.oracle.truffle.dsl.processor.model.*; 33 import com.oracle.truffle.dsl.processor.model.*;
34 34
35 public class ImplicitCastParser extends TypeSystemMethodParser<ImplicitCastData> { 35 public class ImplicitCastParser extends TypeSystemMethodParser<ImplicitCastData> {
36 36
37 public ImplicitCastParser(ProcessorContext context, TypeSystemData typeSystem) { 37 public ImplicitCastParser(ProcessorContext context, TypeSystemData typeSystem) {
43 return ImplicitCast.class; 43 return ImplicitCast.class;
44 } 44 }
45 45
46 @Override 46 @Override
47 public MethodSpec createSpecification(ExecutableElement method, AnnotationMirror mirror) { 47 public MethodSpec createSpecification(ExecutableElement method, AnnotationMirror mirror) {
48 List<TypeMirror> types = getTypeSystem().getPrimitiveTypeMirrors(); 48 MethodSpec spec = new MethodSpec(new ParameterSpec("target", getContext().getType(Object.class)));
49 Set<String> identifiers = getTypeSystem().getTypeIdentifiers(); 49 spec.addRequired(new ParameterSpec("source", getContext().getType(Object.class))).setSignature(true);
50 MethodSpec spec = new MethodSpec(new ParameterSpec("target", types, identifiers));
51 spec.addRequired(new ParameterSpec("source", types, identifiers)).setSignature(true);
52 return spec; 50 return spec;
53 } 51 }
54 52
55 @Override 53 @Override
56 public ImplicitCastData create(TemplateMethod method, boolean invalid) { 54 public ImplicitCastData create(TemplateMethod method, boolean invalid) {
59 } 57 }
60 58
61 Parameter target = method.findParameter("targetValue"); 59 Parameter target = method.findParameter("targetValue");
62 Parameter source = method.findParameter("sourceValue"); 60 Parameter source = method.findParameter("sourceValue");
63 61
64 TypeData targetType = target.getTypeSystemType(); 62 TypeMirror targetType = target.getType();
65 TypeData sourceType = source.getTypeSystemType(); 63 TypeMirror sourceType = source.getType();
66 64
67 if (targetType.equals(sourceType)) { 65 if (ElementUtils.typeEquals(targetType, sourceType)) {
68 method.addError("Target type and source type of an @%s must not be the same type.", ImplicitCast.class.getSimpleName()); 66 method.addError("Target type and source type of an @%s must not be the same type.", ImplicitCast.class.getSimpleName());
69 } 67 }
70 68
71 if (!method.getMethod().getModifiers().contains(Modifier.STATIC)) { 69 if (!method.getMethod().getModifiers().contains(Modifier.STATIC)) {
72 method.addError("@%s annotated method %s must be static.", ImplicitCast.class.getSimpleName(), method.getMethodName()); 70 method.addError("@%s annotated method %s must be static.", ImplicitCast.class.getSimpleName(), method.getMethodName());