| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 import 'package:kernel/kernel.dart'; |
| 5 import 'package:kernel/class_hierarchy.dart'; |
| 6 import 'package:kernel/core_types.dart'; |
| 7 import 'package:kernel/type_checker.dart'; |
| 8 import 'dart:io'; |
| 9 |
| 10 final String usage = ''' |
| 11 Usage: typecheck FILE.dill |
| 12 |
| 13 Runs the strong mode type checker on the given program. |
| 14 '''; |
| 15 |
| 16 main(List<String> args) { |
| 17 if (args.length != 1) { |
| 18 print(usage); |
| 19 exit(1); |
| 20 } |
| 21 var program = loadProgramFromBinary(args[0]); |
| 22 var coreTypes = new CoreTypes(program); |
| 23 var hierarchy = new ClassHierarchy(program); |
| 24 new TestTypeChecker(coreTypes, hierarchy).checkProgram(program); |
| 25 } |
| 26 |
| 27 class TestTypeChecker extends TypeChecker { |
| 28 TestTypeChecker(CoreTypes coreTypes, ClassHierarchy hierarchy) |
| 29 : super(coreTypes, hierarchy); |
| 30 |
| 31 @override |
| 32 void checkAssignable(TreeNode where, DartType from, DartType to) { |
| 33 if (!environment.isSubtypeOf(from, to)) { |
| 34 fail(where, '$from is not a subtype of $to'); |
| 35 } |
| 36 } |
| 37 |
| 38 @override |
| 39 void fail(TreeNode where, String message) { |
| 40 Location location = where.location; |
| 41 String locationString = location == null ? '' : '($location)'; |
| 42 print('[error] $message $locationString'); |
| 43 } |
| 44 } |
| OLD | NEW |