Martijn Coenen | cbe590c | 2016-08-30 11:27:56 -0700 | [diff] [blame] | 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 | |
Yifan Hong | ab407f0 | 2016-08-12 17:39:44 -0700 | [diff] [blame] | 17 | package android.hardware.tests.expression@1.0; |
Yifan Hong | 252c1c5 | 2016-09-19 10:19:24 -0700 | [diff] [blame^] | 18 | |
Yifan Hong | ab407f0 | 2016-08-12 17:39:44 -0700 | [diff] [blame] | 19 | interface IExpression { |
Yifan Hong | a401680 | 2016-08-18 15:09:28 -0700 | [diff] [blame] | 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 { |
Yifan Hong | ab407f0 | 2016-08-12 17:39:44 -0700 | [diff] [blame] | 87 | literal = 4, |
Yifan Hong | a401680 | 2016-08-18 15:09:28 -0700 | [diff] [blame] | 88 | neg = -4, |
Yifan Hong | ab407f0 | 2016-08-12 17:39:44 -0700 | [diff] [blame] | 89 | literalL = -4L, |
Yifan Hong | a401680 | 2016-08-18 15:09:28 -0700 | [diff] [blame] | 90 | hex = 0xffffffff, |
| 91 | hexLong = 0xffffffffl, |
| 92 | hexLong2 = 0xfffffffff, |
Yifan Hong | ab407f0 | 2016-08-12 17:39:44 -0700 | [diff] [blame] | 93 | simpleArithmetic = 4 + 1, |
Yifan Hong | a401680 | 2016-08-18 15:09:28 -0700 | [diff] [blame] | 94 | simpleArithmetic2 = 2 + 3 - 4, |
| 95 | simpleBoolExpr = 1 == 4, |
| 96 | simpleLogical = 1 && 1, |
| 97 | simpleComp = 1 < 2, |
| 98 | boolExpr1 = !((3 != 4 || (2 < 3 <= 3 > 4)) >= 0), |
Yifan Hong | ab407f0 | 2016-08-12 17:39:44 -0700 | [diff] [blame] | 99 | boolExpr = 1 == 7 && !((3 != 4 || (2 < 3 <= 3 > 4)) >= 0), |
Yifan Hong | a401680 | 2016-08-18 15:09:28 -0700 | [diff] [blame] | 100 | simpleBitShift = 1 << 2, |
| 101 | simpleBitShift2 = 4 >> 1, |
| 102 | simpleBitShiftNeg = 4 << -1, |
| 103 | simpleArithmeticRightShift = 1 << 31 >> 31, |
| 104 | simpleBitExpr = 1 | 16 >> 2, |
Yifan Hong | ab407f0 | 2016-08-12 17:39:44 -0700 | [diff] [blame] | 105 | bitExpr = ~42 & (1 << 3 | 16 >> 2) ^ 7, |
| 106 | arithmeticExpr = 2 + 3 - 4 * -7 / (10 % 3), |
Yifan Hong | a401680 | 2016-08-18 15:09:28 -0700 | [diff] [blame] | 107 | messyExpr = 2 + (-3&4 / 7), |
Yifan Hong | ab407f0 | 2016-08-12 17:39:44 -0700 | [diff] [blame] | 108 | paranExpr = (((((1 + 1))))), |
| 109 | ternary = 1?2:3, |
| 110 | ternary2 = 1&&2?3:4, |
Yifan Hong | a401680 | 2016-08-18 15:09:28 -0700 | [diff] [blame] | 111 | complicatedTernary2 = 1 - 1 && 2 + 3 || 5 ? 7 * 8 : -3, |
Yifan Hong | ab407f0 | 2016-08-12 17:39:44 -0700 | [diff] [blame] | 112 | }; |
Yifan Hong | a401680 | 2016-08-18 15:09:28 -0700 | [diff] [blame] | 113 | |
| 114 | enum OperatorSanityCheck : int32_t { |
| 115 | // Should be all true / ones. |
| 116 | plus = (1 + 2) == 3, |
| 117 | minus = (8 - 9) == -1, |
| 118 | product = (9 * 9) == 81, |
| 119 | division = (29 / 3) == 9, |
| 120 | mod = (29 % 3) == 2, |
| 121 | bit_or = (0xC0010000 | 0xF00D) == (0xC001F00D), |
| 122 | bit_or2 = (10 | 6) == 14, |
| 123 | bit_and = (10 & 6) == 2, |
| 124 | bit_xor = (10 ^ 6) == 12, |
| 125 | lt1 = 6 < 10, |
| 126 | lt2 = (10 < 10) == 0, |
| 127 | gt1 = (6 > 10) == 0, |
| 128 | gt2 = (10 > 10) == 0, |
| 129 | gte1 = 19 >= 10, |
| 130 | gte2 = 10 >= 10, |
| 131 | lte1 = 5 <= 10, |
| 132 | lte2 = (19 <= 10) == 0, |
| 133 | ne1 = 19 != 10, |
| 134 | ne2 = (10 != 10) == 0, |
| 135 | lshift = (22 << 1) == 44, |
| 136 | rshift = (11 >> 1) == 5, |
| 137 | logor1 = (1 || 0) == 1, |
| 138 | logor2 = (1 || 1) == 1, |
| 139 | logor3 = (0 || 0) == 0, |
| 140 | logor4 = (0 || 1) == 1, |
| 141 | logand1 = (1 && 0) == 0, |
| 142 | logand2 = (1 && 1) == 1, |
| 143 | logand3 = (0 && 0) == 0, |
| 144 | logand4 = (0 && 1) == 0, |
| 145 | }; |
| 146 | |
Yifan Hong | ab407f0 | 2016-08-12 17:39:44 -0700 | [diff] [blame] | 147 | }; |