1/* 2 * Copyright (C) 2016 The Android Open Source Project 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 17package [email protected]; 18 19interface IExpression { 20 enum UInt64LiteralTypeGuessing : uint64_t { 21 noSuffixDec1 = 0, 22 noSuffixDec2 = 1, 23 noSuffixDec3 = -1, 24 noSuffixDec4 = ~0, 25 noSuffixDec5 = 2147483647, 26 noSuffixDec6 = -2147483648, 27 noSuffixDec7 = 2147483648, 28 noSuffixDec8 = -2147483649, 29 noSuffixDec9 = ~(-1), 30 noSuffixHex1 = 0x7fffffff, 31 noSuffixHex2 = 0x80000000, 32 noSuffixHex3 = 0xffffffff, 33 longHex1 = 0xffffffffl, 34 longHex2 = 0Xfffffffff, 35 longHex3 = 0x7fffffffffffffff, 36 longHex4 = 0x8000000000000000, 37 longHex5 = 0xFFFFFFFFFFFFFFFF, 38 }; 39 40 enum SuffixedLiteralTypeGuessing : int32_t { 41 // Should be all true / ones. 42 // dec literals are either int32_t or int64_t 43 decInt32_1 = (~(-1)) == 0, 44 decInt32_2 = -(1 << 31) == (1 << 31), 45 decInt64_1 = (~(-1l)) == 0, 46 decInt64_2 = (~4294967295) != 0, 47 decInt64_3 = (~4294967295l) != 0, 48 decInt64_4 = -(1l << 63) == (1l << 63), 49 // hex literals could be (u)int32_t or (u)int64_t 50 // 0x7fffffff is int32_t, hence can be negated 51 hexInt32_1 = -0x7fffffff < 0, 52 // 0x80000000 is uint32_t; if it were int32_t then -(int32_t)0x80000000 == (int32_t)0x80000000 > 0 53 hexUInt32_1 = -0x80000000 > 0, 54 // 0xFFFFFFFF is uint32_t, not int64_t; if it were int64_t then ~(int64_t)0xFFFFFFFF != 0 55 hexUInt32_2 = ~0xFFFFFFFF == 0, 56 // 0x7FFFFFFFFFFFFFFF is int64_t, hence can be negated 57 hexInt64_1 = -0x7FFFFFFFFFFFFFFF < 0, 58 // 0x8000000000000000 is uint64_t 59 hexUInt64_1 = -0x8000000000000000 > 0, 60 }; 61 62 enum Int64LiteralTypeGuessing : int64_t { 63 // both treated int32_t, sum = (int64_t)(int32_t)0x80000000 = (int64_t)(-2147483648) 64 noSuffixDec11 = 1 + 0x7fffffff, 65 // 0x80000000 is uint32_t, sum = (int64_t)(uint32_t)0x7fffffff = (int64_t)(2147483647) 66 noSuffixDec12 = 0x80000000 - 1, 67 }; 68 69 enum Int32BitShifting : int32_t { 70 // Shifting for more than 31 bits are undefined. Not tested. 71 int32BitShift1 = 1 << 31, 72 }; 73 74 enum UInt32BitShifting : uint32_t { 75 uint32BitShift1 = 1 << 31, 76 }; 77 78 enum Int64BitShifting : int64_t { 79 int64BitShift1 = 1l << 63, 80 }; 81 82 enum UInt64BitShifting : uint64_t { 83 uint64BitShift1 = 1l << 63, 84 }; 85 86 enum Precedence : int32_t { 87 literal = 4, 88 neg = -4, 89 literalL = -4L, 90 hex = 0xffffffff, 91 hexLong = 0xffffffffl, 92 hexLong2 = 0xfffffffff, 93 simpleArithmetic = 4 + 1, 94 simpleArithmetic2 = 2 + 3 - 4, 95 simpleArithmetic3 = 2 - 3 + 4, 96 simpleBoolExpr = 1 == 4, 97 simpleLogical = 1 && 1, 98 simpleLogical2 = 1 || 1 && 0, // && higher than || 99 simpleComp = 1 < 2, 100 boolExpr1 = !((3 != 4 || (2 < 3 <= 3 > 4)) >= 0), 101 boolExpr = 1 == 7 && !((3 != 4 || (2 < 3 <= 3 > 4)) >= 0), 102 simpleBitShift = 1 << 2, 103 simpleBitShift2 = 4 >> 1, 104 simpleBitShiftNeg = 4 << -1, 105 simpleArithmeticRightShift = 1 << 31 >> 31, 106 simpleBitExpr = 1 | 16 >> 2, 107 simpleBitExpr2 = 0x0f ^ 0x33 & 0x99, // & higher than ^ 108 bitExpr = ~42 & (1 << 3 | 16 >> 2) ^ 7, 109 arithmeticExpr = 2 + 3 - 4 * -7 / (10 % 3), 110 messyExpr = 2 + (-3&4 / 7), 111 paranExpr = (((((1 + 1))))), 112 ternary = 1?2:3, 113 ternary2 = 1&&2?3:4, 114 complicatedTernary2 = 1 - 1 && 2 + 3 || 5 ? 7 * 8 : -3, 115 }; 116 117 enum OperatorSanityCheck : int32_t { 118 // Should be all true / ones. 119 plus = (1 + 2) == 3, 120 minus = (8 - 9) == -1, 121 product = (9 * 9) == 81, 122 division = (29 / 3) == 9, 123 mod = (29 % 3) == 2, 124 bit_or = (0xC0010000 | 0xF00D) == (0xC001F00D), 125 bit_or2 = (10 | 6) == 14, 126 bit_and = (10 & 6) == 2, 127 bit_xor = (10 ^ 6) == 12, 128 lt1 = 6 < 10, 129 lt2 = (10 < 10) == 0, 130 gt1 = (6 > 10) == 0, 131 gt2 = (10 > 10) == 0, 132 gte1 = 19 >= 10, 133 gte2 = 10 >= 10, 134 lte1 = 5 <= 10, 135 lte2 = (19 <= 10) == 0, 136 ne1 = 19 != 10, 137 ne2 = (10 != 10) == 0, 138 lshift = (22 << 1) == 44, 139 rshift = (11 >> 1) == 5, 140 logor1 = (1 || 0) == 1, 141 logor2 = (1 || 1) == 1, 142 logor3 = (0 || 0) == 0, 143 logor4 = (0 || 1) == 1, 144 logand1 = (1 && 0) == 0, 145 logand2 = (1 && 1) == 1, 146 logand3 = (0 && 0) == 0, 147 logand4 = (0 && 1) == 0, 148 }; 149 150 // Tests for enum tags 151 enum NoElements : uint32_t {}; 152 enum OneElement : uint32_t {A}; 153 enum TwoElement : uint32_t {A,B}; 154 enum TwoCollidingElements : uint32_t {A=1,B=1}; 155 enum ThreeFromInheritance : TwoElement {C}; 156 enum ThreeFromDoubleInheritance : ThreeFromInheritance {}; 157 enum ThreeCollidingFromInheritance : TwoCollidingElements {C}; 158 159 enum EnumTagTest : uint32_t { 160 a = NoElements#len == 0, 161 b = OneElement#len == 1, 162 c = TwoElement#len == 2, 163 d = TwoCollidingElements#len == 2, 164 e = ThreeFromInheritance#len == 3, 165 f = ThreeFromDoubleInheritance#len == 3, 166 g = ThreeCollidingFromInheritance#len == 3, 167 168 // fine to reference current enum as well 169 h = EnumTagTest#len == 8, 170 }; 171 172 enum Grayscale : int8_t { 173 WHITE = 126, 174 GRAY, // 127 175 DARK_GRAY, // -128 176 BLACK // -127 177 }; 178 179 enum Color : Grayscale { 180 RED, // -126 181 RUBY = 0, 182 GREEN, // 1 183 BLUE = 5, 184 CYAN, // 6 185 ORANGE, // 7 186 ROSE = WHITE, 187 }; 188 189 enum Foo1 : int8_t {}; 190 enum Foo2 : Foo1 {}; 191 enum Foo3 : Foo2 { 192 BAR1, // 0 193 BAR2 = 10, 194 }; 195 enum Foo4 : Foo3 { 196 BAR3, // 11 197 BAR4 = BAR2 + BAR3 // 21 198 }; 199 200 enum Number : uint8_t { 201 MAX = 255, 202 MAX_PLUS_1, // 0 203 MAX_PLUS_2 // 1 204 }; 205 206 enum Constants : int32_t { 207 CONST_FOO, 208 CONST_BAR = 70, 209 MAX_ARRAY_SIZE = 20, 210 MAX_ARRAY_SIZE2, 211 MAX_ARRAY_SIZE3 = MAX_ARRAY_SIZE + MAX_ARRAY_SIZE, 212 MY_INT32_MAX_MINUS_1 = 0x7FFFFFFE, 213 MY_INT32_MAX, // 0x7FFFFFFF 214 MY_INT32_MIN, // 0x80000000 215 MY_INT32_MIN_PLUS_1, // 0x80000001 216 }; 217 218 foo1(int32_t[Constants:CONST_FOO + 1] array); 219 foo2(int32_t[5 + 8] array); 220 foo3(int32_t[Constants:MAX_ARRAY_SIZE] array); 221}; 222