222 lines
		
	
	
		
			6.3 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
			
		
		
	
	
			222 lines
		
	
	
		
			6.3 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
| /*
 | |
|  * Copyright (C) 2016 The Android Open Source Project
 | |
|  *
 | |
|  * Licensed under the Apache License, Version 2.0 (the "License");
 | |
|  * you may not use this file except in compliance with the License.
 | |
|  * You may obtain a copy of the License at
 | |
|  *
 | |
|  *      http://www.apache.org/licenses/LICENSE-2.0
 | |
|  *
 | |
|  * Unless required by applicable law or agreed to in writing, software
 | |
|  * distributed under the License is distributed on an "AS IS" BASIS,
 | |
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | |
|  * See the License for the specific language governing permissions and
 | |
|  * limitations under the License.
 | |
|  */
 | |
| 
 | |
| package android.hardware.tests.expression@1.0;
 | |
| 
 | |
| interface IExpression {
 | |
|   enum UInt64LiteralTypeGuessing : uint64_t {
 | |
|     noSuffixDec1 = 0,
 | |
|     noSuffixDec2 = 1,
 | |
|     noSuffixDec3 = -1,
 | |
|     noSuffixDec4 = ~0,
 | |
|     noSuffixDec5 = 2147483647,
 | |
|     noSuffixDec6 = -2147483648,
 | |
|     noSuffixDec7 = 2147483648,
 | |
|     noSuffixDec8 = -2147483649,
 | |
|     noSuffixDec9 = ~(-1),
 | |
|     noSuffixHex1 = 0x7fffffff,
 | |
|     noSuffixHex2 = 0x80000000,
 | |
|     noSuffixHex3 = 0xffffffff,
 | |
|     longHex1 = 0xffffffffl,
 | |
|     longHex2 = 0Xfffffffff,
 | |
|     longHex3 = 0x7fffffffffffffff,
 | |
|     longHex4 = 0x8000000000000000,
 | |
|     longHex5 = 0xFFFFFFFFFFFFFFFF,
 | |
|   };
 | |
| 
 | |
|   enum SuffixedLiteralTypeGuessing : int32_t {
 | |
|     // Should be all true / ones.
 | |
|     // dec literals are either int32_t or int64_t
 | |
|     decInt32_1 = (~(-1)) == 0,
 | |
|     decInt32_2 = -(1 << 31) == (1 << 31),
 | |
|     decInt64_1 = (~(-1l)) == 0,
 | |
|     decInt64_2 = (~4294967295) != 0,
 | |
|     decInt64_3 = (~4294967295l) != 0,
 | |
|     decInt64_4 = -(1l << 63) == (1l << 63),
 | |
|     // hex literals could be (u)int32_t or (u)int64_t
 | |
|     // 0x7fffffff is int32_t, hence can be negated
 | |
|     hexInt32_1 = -0x7fffffff < 0,
 | |
|     // 0x80000000 is uint32_t; if it were int32_t then -(int32_t)0x80000000 == (int32_t)0x80000000 > 0
 | |
|     hexUInt32_1 = -0x80000000 > 0,
 | |
|     // 0xFFFFFFFF is uint32_t, not int64_t; if it were int64_t then ~(int64_t)0xFFFFFFFF != 0
 | |
|     hexUInt32_2 = ~0xFFFFFFFF == 0,
 | |
|     // 0x7FFFFFFFFFFFFFFF is int64_t, hence can be negated
 | |
|     hexInt64_1 = -0x7FFFFFFFFFFFFFFF < 0,
 | |
|     // 0x8000000000000000 is uint64_t
 | |
|     hexUInt64_1 = -0x8000000000000000 > 0,
 | |
|   };
 | |
| 
 | |
|   enum Int64LiteralTypeGuessing : int64_t {
 | |
|     // both treated int32_t, sum = (int64_t)(int32_t)0x80000000 = (int64_t)(-2147483648)
 | |
|     noSuffixDec11 = 1 + 0x7fffffff,
 | |
|     // 0x80000000 is uint32_t, sum = (int64_t)(uint32_t)0x7fffffff = (int64_t)(2147483647)
 | |
|     noSuffixDec12 = 0x80000000 - 1,
 | |
|   };
 | |
| 
 | |
|   enum Int32BitShifting : int32_t {
 | |
|     // Shifting for more than 31 bits are undefined. Not tested.
 | |
|     int32BitShift1 = 1 << 31,
 | |
|   };
 | |
| 
 | |
|   enum UInt32BitShifting : uint32_t {
 | |
|     uint32BitShift1 = 1 << 31,
 | |
|   };
 | |
| 
 | |
|   enum Int64BitShifting : int64_t {
 | |
|     int64BitShift1 = 1l << 63,
 | |
|   };
 | |
| 
 | |
|   enum UInt64BitShifting : uint64_t {
 | |
|     uint64BitShift1 = 1l << 63,
 | |
|   };
 | |
| 
 | |
|   enum Precedence : int32_t {
 | |
|     literal = 4,
 | |
|     neg = -4,
 | |
|     literalL = -4L,
 | |
|     hex = 0xffffffff,
 | |
|     hexLong = 0xffffffffl,
 | |
|     hexLong2 = 0xfffffffff,
 | |
|     simpleArithmetic = 4 + 1,
 | |
|     simpleArithmetic2 = 2 + 3 - 4,
 | |
|     simpleArithmetic3 = 2 - 3 + 4,
 | |
|     simpleBoolExpr = 1 == 4,
 | |
|     simpleLogical = 1 && 1,
 | |
|     simpleLogical2 = 1 || 1 && 0,  // && higher than ||
 | |
|     simpleComp = 1 < 2,
 | |
|     boolExpr1 = !((3 != 4 || (2 < 3 <= 3 > 4)) >= 0),
 | |
|     boolExpr = 1 == 7 && !((3 != 4 || (2 < 3 <= 3 > 4)) >= 0),
 | |
|     simpleBitShift = 1 << 2,
 | |
|     simpleBitShift2 = 4 >> 1,
 | |
|     simpleBitShiftNeg = 4 << -1,
 | |
|     simpleArithmeticRightShift = 1 << 31 >> 31,
 | |
|     simpleBitExpr = 1 | 16 >> 2,
 | |
|     simpleBitExpr2 = 0x0f ^ 0x33 & 0x99, // & higher than ^
 | |
|     bitExpr = ~42 & (1 << 3 | 16 >> 2) ^ 7,
 | |
|     arithmeticExpr = 2 + 3 - 4 * -7 / (10 % 3),
 | |
|     messyExpr = 2 + (-3&4 / 7),
 | |
|     paranExpr = (((((1 + 1))))),
 | |
|     ternary = 1?2:3,
 | |
|     ternary2 = 1&&2?3:4,
 | |
|     complicatedTernary2 = 1 - 1 && 2 + 3 || 5 ? 7 * 8 : -3,
 | |
|   };
 | |
| 
 | |
|   enum OperatorSanityCheck : int32_t {
 | |
|     // Should be all true / ones.
 | |
|     plus = (1 + 2) == 3,
 | |
|     minus = (8 - 9) == -1,
 | |
|     product = (9 * 9) == 81,
 | |
|     division = (29 / 3) == 9,
 | |
|     mod = (29 % 3) == 2,
 | |
|     bit_or = (0xC0010000 | 0xF00D) == (0xC001F00D),
 | |
|     bit_or2 = (10 | 6) == 14,
 | |
|     bit_and = (10 & 6) == 2,
 | |
|     bit_xor = (10 ^ 6) == 12,
 | |
|     lt1 = 6 < 10,
 | |
|     lt2 = (10 < 10) == 0,
 | |
|     gt1 = (6 > 10) == 0,
 | |
|     gt2 = (10 > 10) == 0,
 | |
|     gte1 = 19 >= 10,
 | |
|     gte2 = 10 >= 10,
 | |
|     lte1 = 5 <= 10,
 | |
|     lte2 = (19 <= 10) == 0,
 | |
|     ne1 = 19 != 10,
 | |
|     ne2 = (10 != 10) == 0,
 | |
|     lshift = (22 << 1) == 44,
 | |
|     rshift = (11 >> 1) == 5,
 | |
|     logor1 = (1 || 0) == 1,
 | |
|     logor2 = (1 || 1) == 1,
 | |
|     logor3 = (0 || 0) == 0,
 | |
|     logor4 = (0 || 1) == 1,
 | |
|     logand1 = (1 && 0) == 0,
 | |
|     logand2 = (1 && 1) == 1,
 | |
|     logand3 = (0 && 0) == 0,
 | |
|     logand4 = (0 && 1) == 0,
 | |
|   };
 | |
| 
 | |
|   // Tests for enum tags
 | |
|   enum NoElements : uint32_t {};
 | |
|   enum OneElement : uint32_t {A};
 | |
|   enum TwoElement : uint32_t {A,B};
 | |
|   enum TwoCollidingElements : uint32_t {A=1,B=1};
 | |
|   enum ThreeFromInheritance : TwoElement {C};
 | |
|   enum ThreeFromDoubleInheritance : ThreeFromInheritance {};
 | |
|   enum ThreeCollidingFromInheritance : TwoCollidingElements {C};
 | |
| 
 | |
|   enum EnumTagTest : uint32_t {
 | |
|     a = NoElements#len == 0,
 | |
|     b = OneElement#len == 1,
 | |
|     c = TwoElement#len == 2,
 | |
|     d = TwoCollidingElements#len == 2,
 | |
|     e = ThreeFromInheritance#len == 3,
 | |
|     f = ThreeFromDoubleInheritance#len == 3,
 | |
|     g = ThreeCollidingFromInheritance#len == 3,
 | |
| 
 | |
|     // fine to reference current enum as well
 | |
|     h = EnumTagTest#len == 8,
 | |
|   };
 | |
| 
 | |
|   enum Grayscale : int8_t {
 | |
|     WHITE = 126,
 | |
|     GRAY, // 127
 | |
|     DARK_GRAY, // -128
 | |
|     BLACK // -127
 | |
|   };
 | |
| 
 | |
|   enum Color : Grayscale {
 | |
|     RED, // -126
 | |
|     RUBY = 0,
 | |
|     GREEN, // 1
 | |
|     BLUE = 5,
 | |
|     CYAN, // 6
 | |
|     ORANGE, // 7
 | |
|     ROSE = WHITE,
 | |
|   };
 | |
| 
 | |
|   enum Foo1 : int8_t {};
 | |
|   enum Foo2 : Foo1 {};
 | |
|   enum Foo3 : Foo2 {
 | |
|     BAR1, // 0
 | |
|     BAR2 = 10,
 | |
|   };
 | |
|   enum Foo4 : Foo3 {
 | |
|     BAR3, // 11
 | |
|     BAR4 = BAR2 + BAR3 // 21
 | |
|   };
 | |
| 
 | |
|   enum Number : uint8_t {
 | |
|     MAX = 255,
 | |
|     MAX_PLUS_1, // 0
 | |
|     MAX_PLUS_2 // 1
 | |
|   };
 | |
| 
 | |
|   enum Constants : int32_t {
 | |
|     CONST_FOO,
 | |
|     CONST_BAR = 70,
 | |
|     MAX_ARRAY_SIZE = 20,
 | |
|     MAX_ARRAY_SIZE2,
 | |
|     MAX_ARRAY_SIZE3 = MAX_ARRAY_SIZE + MAX_ARRAY_SIZE,
 | |
|     MY_INT32_MAX_MINUS_1 = 0x7FFFFFFE,
 | |
|     MY_INT32_MAX, // 0x7FFFFFFF
 | |
|     MY_INT32_MIN, // 0x80000000
 | |
|     MY_INT32_MIN_PLUS_1, // 0x80000001
 | |
|   };
 | |
| 
 | |
|   foo1(int32_t[Constants:CONST_FOO + 1] array);
 | |
|   foo2(int32_t[5 + 8] array);
 | |
|   foo3(int32_t[Constants:MAX_ARRAY_SIZE] array);
 | |
| };
 |