Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/parser/GuardParser.java @ 16764:f9fff060dc41
Truffle-DSL: fixed behaviour of insertBefore to be more intuitive.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 11 Aug 2014 16:37:40 +0200 |
parents | 23415229349b |
children | 0370880ac9ce |
rev | line source |
---|---|
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1 /* |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
4 * |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
8 * |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
13 * accompanied this code). |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
14 * |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
18 * |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
21 * questions. |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
22 */ |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
23 package com.oracle.truffle.dsl.processor.parser; |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
24 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
25 import java.lang.annotation.*; |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
26 import java.util.*; |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
27 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
28 import javax.lang.model.element.*; |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
29 import javax.lang.model.type.*; |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
30 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
31 import com.oracle.truffle.api.dsl.*; |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
32 import com.oracle.truffle.dsl.processor.*; |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
33 import com.oracle.truffle.dsl.processor.java.*; |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
34 import com.oracle.truffle.dsl.processor.model.*; |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
35 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
36 public class GuardParser extends NodeMethodParser<GuardData> { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
37 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
38 private final Set<String> guardNames; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
39 private final TemplateMethod compatibleSource; |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
40 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
41 public GuardParser(ProcessorContext context, NodeData node, TemplateMethod compatibleSource, Set<String> guardNames) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
42 super(context, node); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
43 this.guardNames = guardNames; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
44 this.compatibleSource = compatibleSource; |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
45 setEmitErrors(false); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
46 setParseNullOnError(false); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
47 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
48 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
49 @Override |
13527
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13271
diff
changeset
|
50 protected ParameterSpec createValueParameterSpec(NodeExecutionData execution) { |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13271
diff
changeset
|
51 return super.createValueParameterSpec(execution); |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13271
diff
changeset
|
52 } |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13271
diff
changeset
|
53 |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13271
diff
changeset
|
54 @Override |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
55 public MethodSpec createSpecification(ExecutableElement method, AnnotationMirror mirror) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
56 MethodSpec spec = createDefaultMethodSpec(method, mirror, true, null); |
13527
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13271
diff
changeset
|
57 spec.setIgnoreAdditionalSpecifications(true); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
58 if (compatibleSource != null) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
59 spec.getRequired().clear(); |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
60 for (Parameter parameter : compatibleSource.getRequiredParameters()) { |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
61 spec.addRequired(new ParameterSpec(parameter.getSpecification(), ElementUtils.getAssignableTypes(getContext(), parameter.getType()))); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
62 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
63 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
64 return spec; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
65 } |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
66 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
67 @Override |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
68 protected List<TypeMirror> nodeTypeMirrors(NodeData nodeData) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
69 Set<TypeMirror> typeMirrors = new LinkedHashSet<>(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
70 typeMirrors.addAll(nodeData.getTypeSystem().getPrimitiveTypeMirrors()); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
71 typeMirrors.addAll(nodeData.getTypeSystem().getBoxedTypeMirrors()); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
72 return new ArrayList<>(typeMirrors); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
73 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
74 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
75 @Override |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
76 protected ParameterSpec createReturnParameterSpec() { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
77 return new ParameterSpec("returnType", getContext().getType(boolean.class)); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
78 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
79 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
80 @Override |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
81 public boolean isParsable(ExecutableElement method) { |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
82 return guardNames.contains(method.getSimpleName().toString()); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
83 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
84 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
85 @Override |
11467
43eab069ca9b
Truffle-DSL: improved error recovery of type systems and improved error testability infrastructure.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
86 public GuardData create(TemplateMethod method, boolean invalid) { |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
87 Implies impliesAnnotation = method.getMethod().getAnnotation(Implies.class); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
88 String[] impliesExpressions = new String[0]; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
89 if (impliesAnnotation != null) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
90 impliesExpressions = impliesAnnotation.value(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
91 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
92 List<GuardExpression> guardExpressions = new ArrayList<>(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
93 for (String string : impliesExpressions) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
94 guardExpressions.add(new GuardExpression(string)); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
95 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
96 return new GuardData(method, guardExpressions); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
97 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
98 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
99 @Override |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
100 public Class<? extends Annotation> getAnnotationType() { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
101 return null; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
102 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
103 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
104 } |