comparison graal/com.oracle.truffle.api.codegen/src/com/oracle/truffle/api/codegen/TypeCheck.java @ 7291:a748e4d44694

Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
author Christian Humer <christian.humer@gmail.com>
date Fri, 21 Dec 2012 10:44:31 -0800
parents
children 2232848be438
comparison
equal deleted inserted replaced
7290:a81db08fe930 7291:a748e4d44694
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.api.codegen;
24
25 import java.lang.annotation.*;
26
27 /**
28 * <p>
29 * Provides a way to define a custom type check for a defined type. The name of the annotated method must fit to the
30 * pattern is${typeName} (eg. isInteger), where ${typeName} must be a valid type defined in the parent
31 * {@link TypeSystem}. The annotated method must have exactly one argument where the type of the argument is the generic
32 * type {@link Object} or a more specific one from the {@link TypeSystem}. You can define multiple overloaded
33 * {@link TypeCheck} methods for the same type. This can be used to reduce the boxing overhead in type conversions.
34 * </p>
35 *
36 * <p>
37 * By default the system generates type checks for all types in the parent {@link TypeSystem} which look like the
38 * follows:
39 *
40 * <pre>
41 * &#064;TypeCheck
42 * boolean is${typeName}(Object value) {
43 * return value instanceof ${typeName};
44 * }
45 * </pre>
46 *
47 * </p>
48 *
49 * <b>Example:</b>
50 * <p>
51 * A type check for BigInteger with one overloaded optimized variant to reduce boxing.
52 * </p>
53 *
54 * <pre>
55 *
56 *
57 * &#064;TypeSystem(types = {int.class, BigInteger.class, String.class}, nodeBaseClass = TypedNode.class)
58 * public abstract class Types {
59 *
60 * &#064;TypeCheck
61 * public boolean isBigInteger(Object value) {
62 * return value instanceof Integer || value instanceof BigInteger;
63 * }
64 *
65 * &#064;TypeCheck
66 * public boolean isBigInteger(int value) {
67 * return true;
68 * }
69 *
70 * }
71 * </pre>
72 *
73 *
74 */
75 @Retention(RetentionPolicy.CLASS)
76 @Target({ElementType.METHOD})
77 public @interface TypeCheck {
78
79 }