Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/typesystem/ImplicitCastParser.java @ 11828:1d64bfb3f481
new PrintAfterCompilation option, simplify PrintCompilation output
author | Lukas Stadler <lukas.stadler@jku.at> |
---|---|
date | Mon, 30 Sep 2013 14:02:07 +0200 |
parents | 2fb276f5e3e9 |
children | 25ecb47a6d0e |
rev | line source |
---|---|
11468
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1 /* |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
4 * |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
8 * |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
13 * accompanied this code). |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
14 * |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
18 * |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
21 * questions. |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
22 */ |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.dsl.processor.typesystem; |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
24 |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
25 import java.lang.annotation.*; |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
26 import java.util.*; |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
27 |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
28 import javax.lang.model.element.*; |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
29 import javax.lang.model.type.*; |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
30 |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
31 import com.oracle.truffle.api.dsl.*; |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
32 import com.oracle.truffle.dsl.processor.*; |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
33 import com.oracle.truffle.dsl.processor.template.*; |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
34 |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
35 public class ImplicitCastParser extends TypeSystemMethodParser<ImplicitCastData> { |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
36 |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
37 public ImplicitCastParser(ProcessorContext context, TypeSystemData typeSystem) { |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
38 super(context, typeSystem); |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
39 } |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
40 |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
41 @Override |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
42 public Class<? extends Annotation> getAnnotationType() { |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
43 return ImplicitCast.class; |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
44 } |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
45 |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
46 @Override |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
47 public MethodSpec createSpecification(ExecutableElement method, AnnotationMirror mirror) { |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
48 List<TypeMirror> types = new ArrayList<>(); |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
49 for (TypeData typeData : getTypeSystem().getTypes()) { |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
50 types.add(typeData.getPrimitiveType()); |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
51 } |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
52 MethodSpec spec = new MethodSpec(new ParameterSpec("target", types)); |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
53 spec.addRequired(new ParameterSpec("source", types)).setSignature(true); |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
54 return spec; |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
55 } |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
56 |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
57 @Override |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
58 public ImplicitCastData create(TemplateMethod method, boolean invalid) { |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11468
diff
changeset
|
59 if (invalid) { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11468
diff
changeset
|
60 return new ImplicitCastData(method, null, null); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11468
diff
changeset
|
61 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11468
diff
changeset
|
62 |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11468
diff
changeset
|
63 ActualParameter target = method.findParameter("targetValue"); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11468
diff
changeset
|
64 ActualParameter source = method.findParameter("sourceValue"); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11468
diff
changeset
|
65 |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11468
diff
changeset
|
66 TypeData targetType = target.getTypeSystemType(); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11468
diff
changeset
|
67 TypeData sourceType = source.getTypeSystemType(); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11468
diff
changeset
|
68 |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11468
diff
changeset
|
69 if (targetType.equals(sourceType)) { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11468
diff
changeset
|
70 method.addError("Target type and source type of an @%s must not be the same type.", ImplicitCast.class.getSimpleName()); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11468
diff
changeset
|
71 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11468
diff
changeset
|
72 |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11468
diff
changeset
|
73 return new ImplicitCastData(method, sourceType, targetType); |
11468
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
74 } |
79d4c4b2d6db
Truffle-DSL: added ImplicitCast api classes. (non functional yet)
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
75 } |