Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/model/GuardExpression.java @ 19291:f4792a544170
Truffle-DSL: implement new assumptions semantics.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Wed, 11 Feb 2015 12:13:44 +0100 |
parents | 08aa0372dad4 |
children |
rev | line source |
---|---|
16766
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
1 /* |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
2 * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
4 * |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
7 * published by the Free Software Foundation. |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
8 * |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
13 * accompanied this code). |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
14 * |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
18 * |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
21 * questions. |
90984ae0eaa8
Truffle-DSL: Fixed headers.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
22 */ |
16763
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16759
diff
changeset
|
23 package com.oracle.truffle.dsl.processor.model; |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16759
diff
changeset
|
24 |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16759
diff
changeset
|
25 import java.util.*; |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16759
diff
changeset
|
26 |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
27 import javax.lang.model.element.*; |
16763
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16759
diff
changeset
|
28 |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
29 import com.oracle.truffle.dsl.processor.expression.*; |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
30 import com.oracle.truffle.dsl.processor.expression.DSLExpression.Negate; |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
31 import com.oracle.truffle.dsl.processor.java.*; |
16851
2db61eddcb97
Truffle-DSL: argument syntax support for guards
Christian Humer <christian.humer@gmail.com>
parents:
16766
diff
changeset
|
32 |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
33 public final class GuardExpression extends MessageContainer { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
34 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
35 private final TemplateMethod source; |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
36 private final DSLExpression expression; |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
37 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
38 public GuardExpression(TemplateMethod source, DSLExpression expression) { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
39 this.source = source; |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
40 this.expression = expression; |
16851
2db61eddcb97
Truffle-DSL: argument syntax support for guards
Christian Humer <christian.humer@gmail.com>
parents:
16766
diff
changeset
|
41 } |
2db61eddcb97
Truffle-DSL: argument syntax support for guards
Christian Humer <christian.humer@gmail.com>
parents:
16766
diff
changeset
|
42 |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
43 @Override |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
44 public Element getMessageElement() { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
45 return source.getMessageElement(); |
16763
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16759
diff
changeset
|
46 } |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16759
diff
changeset
|
47 |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
48 @Override |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
49 public AnnotationMirror getMessageAnnotation() { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
50 return source.getMessageAnnotation(); |
16763
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16759
diff
changeset
|
51 } |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16759
diff
changeset
|
52 |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16759
diff
changeset
|
53 @Override |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
54 public AnnotationValue getMessageAnnotationValue() { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
55 return ElementUtils.getAnnotationValue(getMessageAnnotation(), "guards"); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
56 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
57 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
58 public DSLExpression getExpression() { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
59 return expression; |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
60 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
61 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
62 public boolean equalsNegated(GuardExpression other) { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
63 boolean negated = false; |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
64 DSLExpression thisExpression = expression; |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
65 if (thisExpression instanceof Negate) { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
66 negated = true; |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
67 thisExpression = ((Negate) thisExpression).getReceiver(); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
68 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
69 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
70 boolean otherNegated = false; |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
71 DSLExpression otherExpression = other.expression; |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
72 if (otherExpression instanceof Negate) { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
73 otherNegated = true; |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
74 otherExpression = ((Negate) otherExpression).getReceiver(); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
75 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
76 return Objects.equals(thisExpression, otherExpression) && negated != otherNegated; |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
77 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
78 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
79 public boolean implies(GuardExpression other) { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
80 if (Objects.equals(expression, other.expression)) { |
16851
2db61eddcb97
Truffle-DSL: argument syntax support for guards
Christian Humer <christian.humer@gmail.com>
parents:
16766
diff
changeset
|
81 return true; |
16763
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16759
diff
changeset
|
82 } |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16759
diff
changeset
|
83 return false; |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16759
diff
changeset
|
84 } |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16759
diff
changeset
|
85 |
e6d15134ca86
Truffle-DSL: fixed formatting problems.
Christian Humer <christian.humer@gmail.com>
parents:
16759
diff
changeset
|
86 } |