Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/parser/ExecutableTypeMethodParser.java @ 16759:23415229349b
Truffle-DSL: new package structure.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 11 Aug 2014 15:57:14 +0200 |
parents | graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/ExecutableTypeMethodParser.java@e8ef44830b50 |
children | 0370880ac9ce |
comparison
equal
deleted
inserted
replaced
16758:c5f8eeb3cbc8 | 16759:23415229349b |
---|---|
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.dsl.processor.parser; | |
24 | |
25 import java.lang.annotation.*; | |
26 import java.util.*; | |
27 | |
28 import javax.lang.model.element.*; | |
29 import javax.lang.model.type.*; | |
30 | |
31 import com.oracle.truffle.dsl.processor.*; | |
32 import com.oracle.truffle.dsl.processor.model.*; | |
33 | |
34 public class ExecutableTypeMethodParser extends NodeMethodParser<ExecutableTypeData> { | |
35 | |
36 public ExecutableTypeMethodParser(ProcessorContext context, NodeData node) { | |
37 super(context, node); | |
38 setEmitErrors(false); | |
39 setParseNullOnError(false); | |
40 setUseVarArgs(true); | |
41 } | |
42 | |
43 @Override | |
44 public MethodSpec createSpecification(ExecutableElement method, AnnotationMirror mirror) { | |
45 MethodSpec spec = createDefaultMethodSpec(method, mirror, false, null); | |
46 List<ParameterSpec> requiredSpecs = new ArrayList<>(spec.getRequired()); | |
47 spec.getRequired().clear(); | |
48 | |
49 List<TypeMirror> allowedTypes = getNode().getTypeSystem().getPrimitiveTypeMirrors(); | |
50 for (ParameterSpec originalSpec : requiredSpecs) { | |
51 spec.addRequired(new ParameterSpec(originalSpec, allowedTypes)); | |
52 } | |
53 spec.setIgnoreAdditionalSpecifications(true); | |
54 spec.setIgnoreAdditionalParameters(true); | |
55 spec.setVariableRequiredParameters(true); | |
56 // varargs | |
57 ParameterSpec otherParameters = new ParameterSpec("other", allowedTypes); | |
58 otherParameters.setSignature(true); | |
59 spec.addRequired(otherParameters); | |
60 return spec; | |
61 } | |
62 | |
63 @Override | |
64 public final boolean isParsable(ExecutableElement method) { | |
65 if (method.getModifiers().contains(Modifier.STATIC)) { | |
66 return false; | |
67 } else if (method.getModifiers().contains(Modifier.NATIVE)) { | |
68 return false; | |
69 } | |
70 return method.getSimpleName().toString().startsWith("execute"); | |
71 } | |
72 | |
73 @Override | |
74 protected List<TypeMirror> nodeTypeMirrors(NodeData nodeData) { | |
75 List<TypeMirror> types = new ArrayList<>(getNode().getTypeSystem().getPrimitiveTypeMirrors()); | |
76 types.add(getNode().getTypeSystem().getVoidType().getPrimitiveType()); | |
77 return types; | |
78 } | |
79 | |
80 @Override | |
81 public ExecutableTypeData create(TemplateMethod method, boolean invalid) { | |
82 TypeData resolvedType = method.getReturnType().getTypeSystemType(); | |
83 return new ExecutableTypeData(method, method.getMethod(), getNode().getTypeSystem(), resolvedType); | |
84 } | |
85 | |
86 @Override | |
87 public Class<? extends Annotation> getAnnotationType() { | |
88 return null; | |
89 } | |
90 | |
91 } |