• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016 Google Inc. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.google.turbine.tree;
18 
19 /**
20  * An operator kind, with precedence. Only operators that can appear in compile-time constant
21  * expressions are included.
22  */
23 public enum TurbineOperatorKind {
24   POST_INCR("++", Precedence.POSTFIX),
25   POST_DECR("--", Precedence.POSTFIX),
26   PRE_INCR("++", Precedence.UNARY),
27   PRE_DECR("--", Precedence.UNARY),
28   UNARY_PLUS("+", Precedence.UNARY),
29   NEG("-", Precedence.UNARY),
30   BITWISE_COMP("~", Precedence.UNARY),
31   NOT("!", Precedence.UNARY),
32   MULT("*", Precedence.MULTIPLICATIVE),
33   DIVIDE("/", Precedence.MULTIPLICATIVE),
34   MODULO("%", Precedence.MULTIPLICATIVE),
35   PLUS("+", Precedence.ADDITIVE),
36   MINUS("-", Precedence.ADDITIVE),
37   SHIFT_LEFT("<<", Precedence.SHIFT),
38   SHIFT_RIGHT(">>", Precedence.SHIFT),
39   UNSIGNED_SHIFT_RIGHT(">>>", Precedence.SHIFT),
40   LESS_THAN("<", Precedence.RELATIONAL),
41   GREATER_THAN(">", Precedence.RELATIONAL),
42   GREATER_THAN_EQ(">=", Precedence.RELATIONAL),
43   LESS_THAN_EQ("<=", Precedence.RELATIONAL),
44   INSTANCE_OF("instanceof", Precedence.RELATIONAL),
45   EQUAL("==", Precedence.EQUALITY),
46   NOT_EQUAL("!=", Precedence.EQUALITY),
47   BITWISE_AND("&", Precedence.BIT_AND),
48   BITWISE_XOR("^", Precedence.BIT_XOR),
49   BITWISE_OR("|", Precedence.BIT_IOR),
50   AND("&&", Precedence.AND),
51   OR("||", Precedence.OR),
52   TERNARY("?", Precedence.TERNARY),
53   ASSIGN("=", Precedence.ASSIGNMENT);
54 
55   private final String name;
56   private final Precedence prec;
57 
TurbineOperatorKind(String name, Precedence prec)58   TurbineOperatorKind(String name, Precedence prec) {
59     this.name = name;
60     this.prec = prec;
61   }
62 
63   @Override
toString()64   public String toString() {
65     return name;
66   }
67 
prec()68   public Precedence prec() {
69     return prec;
70   }
71 
72   /** Operator precedence groups. */
73   public enum Precedence {
74     CAST(14),
75     POSTFIX(13),
76     UNARY(12),
77     MULTIPLICATIVE(11),
78     ADDITIVE(10),
79     SHIFT(9),
80     RELATIONAL(8),
81     EQUALITY(7),
82     BIT_AND(6),
83     BIT_XOR(5),
84     BIT_IOR(4),
85     AND(3),
86     OR(2),
87     TERNARY(1),
88     ASSIGNMENT(0);
89 
90     private final int rank;
91 
rank()92     public int rank() {
93       return rank;
94     }
95 
Precedence(int rank)96     Precedence(int rank) {
97       this.rank = rank;
98     }
99   }
100 }
101