Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.api.dsl/src/com/oracle/truffle/api/dsl/TypeCheck.java @ 18782:3ea386a1036f
Truffle-DSL: breaking: @TypeCheck and @TypeCast now require casted/checked type as explicit parameter. Previously the type was parsed from the method name. (GRAAL-446 #resolve)
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 05 Jan 2015 20:23:22 +0100 |
parents | e6d15134ca86 |
children |
comparison
equal
deleted
inserted
replaced
18781:941761f6b736 | 18782:3ea386a1036f |
---|---|
25 package com.oracle.truffle.api.dsl; | 25 package com.oracle.truffle.api.dsl; |
26 | 26 |
27 import java.lang.annotation.*; | 27 import java.lang.annotation.*; |
28 | 28 |
29 /** | 29 /** |
30 * <p> | 30 * Overrides the standard way of checking for a certain type in a {@link TypeSystem}. This is useful |
31 * Provides a way to define a custom type check for a defined type. The name of the annotated method | 31 * for types where the guest language specific type check can be implemented more efficiently than a |
32 * must fit to the pattern is${typeName} (eg. isInteger), where ${typeName} must be a valid type | 32 * direct cast. The annotated method must be contained in a {@link TypeSystem} annotated class. Type |
33 * defined in the parent {@link TypeSystem}. The annotated method must have exactly one argument | 33 * checks must conform to the following signature: <code>public static boolean is{TypeName}(Object |
34 * where the type of the argument is the generic type {@link Object} or a more specific one from the | 34 * value)</code>. The checked type must be a type declared in the {@link TypeSystem}. |
35 * {@link TypeSystem}. You can define multiple overloaded {@link TypeCheck} methods for the same | |
36 * type. This can be used to reduce the boxing overhead in type conversions. | |
37 * </p> | |
38 * | 35 * |
39 * <p> | 36 * <p> |
40 * By default the system generates type checks for all types in the parent {@link TypeSystem} which | 37 * If no {@link TypeCheck} is declared then the type system implicitly uses a type check that can be |
41 * look like the follows: | 38 * declared as follows: |
42 * | 39 * |
43 * <pre> | 40 * <pre> |
44 * {@literal @}TypeCheck | 41 * {@literal @}TypeCheck(Type.class) |
45 * boolean is${typeName}(Object value) { | 42 * public static boolean isType(Object value) { |
46 * return value instanceof ${typeName}; | 43 * return value instanceof Type; |
47 * } | 44 * } |
48 * </pre> | 45 * </pre> |
49 * | 46 * |
50 * <b>Example:</b> | 47 * @see TypeCast |
51 * <p> | |
52 * A type check for BigInteger with one overloaded optimized variant to reduce boxing. | |
53 * </p> | |
54 * | |
55 * <pre> | |
56 * | |
57 * | |
58 * {@literal @}TypeSystem(types = {int.class, BigInteger.class, String.class}, nodeBaseClass = TypedNode.class) | |
59 * public abstract class Types { | |
60 * | |
61 * {@literal @}TypeCheck | |
62 * public boolean isBigInteger(Object value) { | |
63 * return value instanceof Integer || value instanceof BigInteger; | |
64 * } | |
65 * | |
66 * {@literal @}TypeCheck | |
67 * public boolean isBigInteger(int value) { | |
68 * return true; | |
69 * } | |
70 * | |
71 * } | |
72 * </pre> | |
73 * | |
74 * | |
75 */ | 48 */ |
76 @Retention(RetentionPolicy.CLASS) | 49 @Retention(RetentionPolicy.CLASS) |
77 @Target({ElementType.METHOD}) | 50 @Target({ElementType.METHOD}) |
78 public @interface TypeCheck { | 51 public @interface TypeCheck { |
79 | 52 |
53 Class<?> value(); | |
54 | |
80 } | 55 } |