| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2015, the Dartino 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.md file. | |
| 4 | |
| 5 import 'dart:io'; | |
| 6 import 'dart:convert'; | |
| 7 | |
| 8 import 'parser.dart'; | |
| 9 import 'primitives.dart' as primitives; | |
| 10 import 'struct_layout.dart'; | |
| 11 | |
| 12 import 'package:path/path.dart' show join, dirname; | |
| 13 | |
| 14 Future<Map> parseImports(Unit unit, ImportResolver resolver, context) async { | |
| 15 Map units = {}; | |
| 16 await ImportParser.parse(unit, resolver, context, units); | |
| 17 return units; | |
| 18 } | |
| 19 | |
| 20 abstract class ImportResolver<Context> { | |
| 21 Context resolve(Import import, Context context); | |
| 22 Future<String> read(Context context); | |
| 23 } | |
| 24 | |
| 25 class ImportParser<Context> extends Visitor { | |
| 26 final ImportResolver resolver; | |
| 27 final Context context; | |
| 28 final Map<Context, Unit> units; | |
| 29 | |
| 30 static parse(Unit unit, ImportResolver resolver, Context context, Map units) { | |
| 31 var parser = new ImportParser(resolver, context, units); | |
| 32 return parser.visitUnit(unit); | |
| 33 } | |
| 34 | |
| 35 ImportParser(this.resolver, this.context, this.units); | |
| 36 | |
| 37 visitUnit(Unit unit) async { | |
| 38 units[context] = unit; | |
| 39 for (var import in unit.imports) { | |
| 40 await visitImport(import); | |
| 41 } | |
| 42 } | |
| 43 | |
| 44 visitImport(Import import) async { | |
| 45 var newContext = resolver.resolve(import, context); | |
| 46 if (newContext != null) { | |
| 47 String input = await resolver.read(newContext); | |
| 48 Unit unit = parseUnit(input); | |
| 49 await parse(unit, resolver, newContext, units); | |
| 50 } | |
| 51 } | |
| 52 } | |
| OLD | NEW |