| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 | 4 |
| 5 library compiler_helper; | 5 library compiler_helper; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
| 9 | 9 |
| 10 import 'package:compiler/src/elements/elements.dart' as lego; | 10 import 'package:compiler/src/elements/elements.dart' as lego; |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 lego.LibraryElement lib = compiler.mainApp; | 190 lego.LibraryElement lib = compiler.mainApp; |
| 191 if (library != null) { | 191 if (library != null) { |
| 192 lib = compiler.libraryLoader.lookupLibrary(library); | 192 lib = compiler.libraryLoader.lookupLibrary(library); |
| 193 Expect.isNotNull(lib, 'Could not locate library $library.'); | 193 Expect.isNotNull(lib, 'Could not locate library $library.'); |
| 194 } | 194 } |
| 195 var element = lib.find(name); | 195 var element = lib.find(name); |
| 196 Expect.isNotNull(element, 'Could not locate $name.'); | 196 Expect.isNotNull(element, 'Could not locate $name.'); |
| 197 return element; | 197 return element; |
| 198 } | 198 } |
| 199 | 199 |
| 200 types.TypeMask findTypeMask(compiler, String name, | |
| 201 [String how = 'nonNullExact']) { | |
| 202 var sourceName = name; | |
| 203 var element = compiler.mainApp.find(sourceName); | |
| 204 if (element == null) { | |
| 205 element = compiler.backend.helpers.interceptorsLibrary.find(sourceName); | |
| 206 } | |
| 207 if (element == null) { | |
| 208 element = compiler.commonElements.coreLibrary.find(sourceName); | |
| 209 } | |
| 210 Expect.isNotNull(element, 'Could not locate $name'); | |
| 211 switch (how) { | |
| 212 case 'exact': | |
| 213 return new types.TypeMask.exact(element, compiler.closedWorld); | |
| 214 case 'nonNullExact': | |
| 215 return new types.TypeMask.nonNullExact(element, compiler.closedWorld); | |
| 216 case 'subclass': | |
| 217 return new types.TypeMask.subclass(element, compiler.closedWorld); | |
| 218 case 'nonNullSubclass': | |
| 219 return new types.TypeMask.nonNullSubclass(element, compiler.closedWorld); | |
| 220 case 'subtype': | |
| 221 return new types.TypeMask.subtype(element, compiler.closedWorld); | |
| 222 case 'nonNullSubtype': | |
| 223 return new types.TypeMask.nonNullSubtype(element, compiler.closedWorld); | |
| 224 } | |
| 225 Expect.fail('Unknown TypeMask constructor $how'); | |
| 226 return null; | |
| 227 } | |
| 228 | |
| 229 String anyIdentifier = "[a-zA-Z][a-zA-Z0-9]*"; | 200 String anyIdentifier = "[a-zA-Z][a-zA-Z0-9]*"; |
| 230 | 201 |
| 231 String getIntTypeCheck(String variable) { | 202 String getIntTypeCheck(String variable) { |
| 232 return "\\($variable ?!== ?\\($variable ?\\| ?0\\)|" | 203 return "\\($variable ?!== ?\\($variable ?\\| ?0\\)|" |
| 233 "\\($variable ?>>> ?0 ?!== ?$variable"; | 204 "\\($variable ?>>> ?0 ?!== ?$variable"; |
| 234 } | 205 } |
| 235 | 206 |
| 236 String getNumberTypeCheck(String variable) { | 207 String getNumberTypeCheck(String variable) { |
| 237 return """\\(typeof $variable ?!== ?"number"\\)"""; | 208 return """\\(typeof $variable ?!== ?"number"\\)"""; |
| 238 } | 209 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 regexp = regexp.replaceAll(xRe, '(?:$anyIdentifier)'); | 252 regexp = regexp.replaceAll(xRe, '(?:$anyIdentifier)'); |
| 282 final spaceRe = new RegExp('\\s+'); | 253 final spaceRe = new RegExp('\\s+'); |
| 283 regexp = regexp.replaceAll(spaceRe, '(?:\\s*)'); | 254 regexp = regexp.replaceAll(spaceRe, '(?:\\s*)'); |
| 284 if (shouldMatch) { | 255 if (shouldMatch) { |
| 285 Expect.isTrue(new RegExp(regexp).hasMatch(generated)); | 256 Expect.isTrue(new RegExp(regexp).hasMatch(generated)); |
| 286 } else { | 257 } else { |
| 287 Expect.isFalse(new RegExp(regexp).hasMatch(generated)); | 258 Expect.isFalse(new RegExp(regexp).hasMatch(generated)); |
| 288 } | 259 } |
| 289 }); | 260 }); |
| 290 } | 261 } |
| OLD | NEW |