Mercurial > hg > truffle
annotate truffle/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/generator/DSLExpressionGenerator.java @ 21951:9c8c0937da41
Moving all sources into truffle subdirectory
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Wed, 17 Jun 2015 10:58:08 +0200 |
parents | graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/generator/DSLExpressionGenerator.java@f83fd99b2962 |
children | dc83cc1f94f2 |
rev | line source |
---|---|
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1 /* |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
4 * |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
8 * |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
13 * accompanied this code). |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
14 * |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
18 * |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
21 * questions. |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
22 */ |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.dsl.processor.generator; |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
24 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
25 import java.util.*; |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
26 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
27 import javax.lang.model.element.*; |
20939
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
28 import javax.lang.model.type.*; |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
29 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
30 import com.oracle.truffle.dsl.processor.expression.*; |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
31 import com.oracle.truffle.dsl.processor.expression.DSLExpression.Binary; |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
32 import com.oracle.truffle.dsl.processor.expression.DSLExpression.Call; |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
33 import com.oracle.truffle.dsl.processor.expression.DSLExpression.DSLExpressionVisitor; |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
34 import com.oracle.truffle.dsl.processor.expression.DSLExpression.IntLiteral; |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
35 import com.oracle.truffle.dsl.processor.expression.DSLExpression.Negate; |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
36 import com.oracle.truffle.dsl.processor.expression.DSLExpression.Variable; |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
37 import com.oracle.truffle.dsl.processor.java.model.*; |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
38 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
39 public class DSLExpressionGenerator implements DSLExpressionVisitor { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
40 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
41 private final Map<Variable, CodeTree> bindings; |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
42 private final CodeTree root; |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
43 private final Deque<CodeTree> stack = new ArrayDeque<>(); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
44 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
45 public DSLExpressionGenerator(CodeTree root, Map<Variable, CodeTree> bindings) { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
46 this.bindings = bindings; |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
47 this.root = root; |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
48 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
49 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
50 public void visitBinary(Binary binary) { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
51 CodeTree right = stack.pop(); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
52 CodeTree left = stack.pop(); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
53 stack.push(combine(left, string(" " + binary.getOperator() + " "), right)); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
54 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
55 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
56 public void visitCall(Call call) { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
57 ExecutableElement method = call.getResolvedMethod(); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
58 CodeTree[] parameters = new CodeTree[method.getParameters().size()]; |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
59 for (int i = 0; i < parameters.length; i++) { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
60 parameters[parameters.length - i - 1] = pop(); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
61 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
62 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
63 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder(); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
64 |
19289
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19283
diff
changeset
|
65 if (call.getResolvedMethod().getKind() == ElementKind.CONSTRUCTOR) { |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19283
diff
changeset
|
66 builder.startNew(call.getResolvedType()); |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19283
diff
changeset
|
67 } else if (call.getReceiver() == null) { |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
68 if (isStatic(method)) { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
69 builder.startStaticCall(method); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
70 } else { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
71 if (root != null) { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
72 builder.tree(root).string("."); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
73 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
74 builder.startCall(method.getSimpleName().toString()); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
75 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
76 } else { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
77 if (isStatic(method)) { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
78 throw new AssertionError("Static calls must not have receivers."); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
79 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
80 builder.startCall(pop(), method.getSimpleName().toString()); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
81 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
82 for (CodeTree parameter : parameters) { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
83 builder.tree(parameter); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
84 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
85 builder.end(); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
86 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
87 push(builder.build()); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
88 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
89 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
90 public void visitIntLiteral(IntLiteral binary) { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
91 push(string(binary.getLiteral())); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
92 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
93 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
94 public void visitNegate(Negate negate) { |
19289
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19283
diff
changeset
|
95 push(combine(string("!"), combine(string("("), pop(), string(")")))); |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
96 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
97 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
98 public void visitVariable(Variable variable) { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
99 VariableElement resolvedVariable = variable.getResolvedVariable(); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
100 CodeTree tree; |
20939
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
101 if (variable.getResolvedType().getKind() == TypeKind.NULL) { |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
102 tree = CodeTreeBuilder.singleString("null"); |
f83fd99b2962
Truffle-DSL: add support for null literals.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
103 } else if (variable.getReceiver() == null) { |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
104 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
105 if (isStatic(resolvedVariable)) { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
106 tree = staticReference(resolvedVariable); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
107 } else { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
108 tree = bindings.get(variable); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
109 boolean bound = true; |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
110 if (tree == null) { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
111 tree = string(resolvedVariable.getSimpleName().toString()); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
112 bound = false; |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
113 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
114 if (root != null && !bound) { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
115 tree = combine(root, string("."), tree); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
116 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
117 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
118 } else { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
119 if (isStatic(resolvedVariable)) { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
120 throw new AssertionError("Static variables cannot have receivers."); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
121 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
122 tree = combine(pop(), string("."), string(resolvedVariable.getSimpleName().toString())); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
123 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
124 push(tree); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
125 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
126 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
127 private static boolean isStatic(Element element) { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
128 return element.getModifiers().contains(Modifier.STATIC); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
129 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
130 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
131 private static CodeTree combine(CodeTree tree1, CodeTree tree2) { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
132 return new CodeTreeBuilder(null).startGroup().tree(tree1).tree(tree2).end().build(); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
133 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
134 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
135 private static CodeTree combine(CodeTree tree1, CodeTree tree2, CodeTree tree3) { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
136 return new CodeTreeBuilder(null).startGroup().tree(tree1).tree(tree2).tree(tree3).end().build(); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
137 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
138 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
139 private static CodeTree string(String s) { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
140 return CodeTreeBuilder.singleString(s); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
141 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
142 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
143 private static CodeTree staticReference(VariableElement var) { |
19289
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19283
diff
changeset
|
144 return CodeTreeBuilder.createBuilder().staticReference(var.getEnclosingElement().asType(), var.getSimpleName().toString()).build(); |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
145 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
146 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
147 private void push(CodeTree tree) { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
148 stack.push(tree); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
149 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
150 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
151 private CodeTree pop() { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
152 return stack.pop(); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
153 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
154 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
155 public static CodeTree write(DSLExpression expression, CodeTree root, Map<Variable, CodeTree> bindings) { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
156 DSLExpressionGenerator writer = new DSLExpressionGenerator(root, bindings); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
157 expression.accept(writer); |
19289
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19283
diff
changeset
|
158 return combine(string("("), writer.pop(), string(")")); |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
159 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
160 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
161 } |