OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 // VMOptions= | 4 // VMOptions= |
5 // VMOptions=--compile_all | 5 // VMOptions=--compile_all |
6 | 6 |
7 // Exercises language constructs that require compile time constants | 7 // Exercises language constructs that require compile time constants |
8 | 8 |
9 // Initialize with different literal types | 9 // Initialize with different literal types |
10 const b = true; | 10 const b = true; |
11 const s = "apple"; | 11 const s = "apple"; |
12 const i = 1; | 12 const i = 1; |
13 const d = 3.3; | 13 const d = 3.3; |
14 const h = 0xf; | 14 const h = 0xf; |
15 const n = null; | 15 const n = null; |
16 const aList = const[1, 2, 3]; // array literal | 16 const aList = const [1, 2, 3]; // array literal |
17 const aMap = const { "1": "one", "2": "banana" }; // map literal | 17 const aMap = const {"1": "one", "2": "banana"}; // map literal |
18 | 18 |
19 const INT_LIT = 5; | 19 const INT_LIT = 5; |
20 const INT_LIT_REF = INT_LIT; | 20 const INT_LIT_REF = INT_LIT; |
21 const DOUBLE_LIT = 1.5; | 21 const DOUBLE_LIT = 1.5; |
22 const BOOL_LIT = true; | 22 const BOOL_LIT = true; |
23 const STRING_LIT = "Hello"; | 23 const STRING_LIT = "Hello"; |
24 | 24 |
25 const BOP1_0 = INT_LIT + 1; | 25 const BOP1_0 = INT_LIT + 1; |
26 const BOP1_1 = 1 + INT_LIT; | 26 const BOP1_1 = 1 + INT_LIT; |
27 const BOP1_2 = INT_LIT - 1; | 27 const BOP1_2 = INT_LIT - 1; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 const BOP7 = false || BOOL_LIT; | 68 const BOP7 = false || BOOL_LIT; |
69 const BOP8 = STRING_LIT == "World!"; | 69 const BOP8 = STRING_LIT == "World!"; |
70 const BOP9 = "Hello" != STRING_LIT; | 70 const BOP9 = "Hello" != STRING_LIT; |
71 const BOP10 = INT_LIT == INT_LIT_REF; | 71 const BOP10 = INT_LIT == INT_LIT_REF; |
72 const BOP11 = BOOL_LIT != true; | 72 const BOP11 = BOOL_LIT != true; |
73 | 73 |
74 // Multiple binary expressions | 74 // Multiple binary expressions |
75 const BOP20 = 1 * INT_LIT / 3 + INT_LIT + 9; | 75 const BOP20 = 1 * INT_LIT / 3 + INT_LIT + 9; |
76 | 76 |
77 // Parenthised expressions | 77 // Parenthised expressions |
78 const BOP30 = ( 1 > 2 ); | 78 const BOP30 = (1 > 2); |
79 const BOP31 = (1 * 2) + 3; | 79 const BOP31 = (1 * 2) + 3; |
80 const BOP32= 3 + (1 * 2); | 80 const BOP32 = 3 + (1 * 2); |
81 | 81 |
82 // Unary expressions | 82 // Unary expressions |
83 const UOP1_0 = !BOOL_LIT; | 83 const UOP1_0 = !BOOL_LIT; |
84 const UOP1_1 = BOOL_LIT || !true; | 84 const UOP1_1 = BOOL_LIT || !true; |
85 const UOP1_2 = !BOOL_LIT || true; | 85 const UOP1_2 = !BOOL_LIT || true; |
86 const UOP1_3 = !(BOOL_LIT && true); | 86 const UOP1_3 = !(BOOL_LIT && true); |
87 const UOP2_0 = ~0xf0; | 87 const UOP2_0 = ~0xf0; |
88 const UOP2_1 = ~INT_LIT; | 88 const UOP2_1 = ~INT_LIT; |
89 const UOP2_2 = ~INT_LIT & 123; | 89 const UOP2_2 = ~INT_LIT & 123; |
90 const UOP2_3 = ~(INT_LIT | 0xff); | 90 const UOP2_3 = ~(INT_LIT | 0xff); |
91 const UOP3_0 = -0xf0; | 91 const UOP3_0 = -0xf0; |
92 const UOP3_1 = -INT_LIT; | 92 const UOP3_1 = -INT_LIT; |
93 const UOP3_2 = -INT_LIT + 123; | 93 const UOP3_2 = -INT_LIT + 123; |
94 const UOP3_3 = -(INT_LIT * 0xff); | 94 const UOP3_3 = -(INT_LIT * 0xff); |
95 const UOP3_4 = -0xf0; | 95 const UOP3_4 = -0xf0; |
96 const UOP3_5 = -DOUBLE_LIT; | 96 const UOP3_5 = -DOUBLE_LIT; |
97 const UOP3_6 = -DOUBLE_LIT + 123; | 97 const UOP3_6 = -DOUBLE_LIT + 123; |
98 const UOP3_7 = -(DOUBLE_LIT * 0xff); | 98 const UOP3_7 = -(DOUBLE_LIT * 0xff); |
99 | 99 |
100 class A { | 100 class A { |
101 const A(); | 101 const A(); |
102 static const a = const A(); // Assignment from Constant constructor OK | 102 static const a = const A(); // Assignment from Constant constructor OK |
103 } | 103 } |
104 | 104 |
105 main () { | 105 main() {} |
106 } | |
OLD | NEW |