| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 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 | 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 parser_helper; | 5 library parser_helper; |
| 6 | 6 |
| 7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
| 8 | 8 |
| 9 import "package:compiler/src/elements/elements.dart"; | 9 import "package:compiler/src/elements/elements.dart"; |
| 10 import 'package:compiler/src/id_generator.dart'; |
| 10 import "package:compiler/src/tree/tree.dart"; | 11 import "package:compiler/src/tree/tree.dart"; |
| 11 import "package:compiler/src/parser/element_listener.dart"; | 12 import "package:compiler/src/parser/element_listener.dart"; |
| 12 import "package:compiler/src/parser/node_listener.dart"; | 13 import "package:compiler/src/parser/node_listener.dart"; |
| 13 import "package:compiler/src/parser/parser.dart"; | 14 import "package:compiler/src/parser/parser.dart"; |
| 14 import "package:compiler/src/parser/partial_parser.dart"; | 15 import "package:compiler/src/parser/partial_parser.dart"; |
| 15 import "package:compiler/src/scanner/string_scanner.dart"; | 16 import "package:compiler/src/scanner/string_scanner.dart"; |
| 16 import "package:compiler/src/tokens/token.dart"; | 17 import "package:compiler/src/tokens/token.dart"; |
| 17 import "package:compiler/src/tokens/token_constants.dart"; | 18 import "package:compiler/src/tokens/token_constants.dart"; |
| 18 import "package:compiler/src/io/source_file.dart"; | 19 import "package:compiler/src/io/source_file.dart"; |
| 19 import "package:compiler/src/util/util.dart"; | 20 import "package:compiler/src/util/util.dart"; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 text, | 132 text, |
| 132 (parser, tokens) => parser.parseMember(tokens), | 133 (parser, tokens) => parser.parseMember(tokens), |
| 133 reporter: reporter); | 134 reporter: reporter); |
| 134 } | 135 } |
| 135 | 136 |
| 136 class MockFile extends StringSourceFile { | 137 class MockFile extends StringSourceFile { |
| 137 MockFile(text) | 138 MockFile(text) |
| 138 : super.fromName('<string>', text); | 139 : super.fromName('<string>', text); |
| 139 } | 140 } |
| 140 | 141 |
| 142 class _IdGenerator implements IdGenerator { |
| 143 int _id = 0; |
| 144 int getNextFreeId() => _id++; |
| 145 } |
| 146 |
| 141 var sourceCounter = 0; | 147 var sourceCounter = 0; |
| 142 | 148 |
| 143 Link<Element> parseUnit(String text, Compiler compiler, | 149 Link<Element> parseUnit(String text, Compiler compiler, |
| 144 LibraryElement library, | 150 LibraryElement library, |
| 145 [void registerSource(Uri uri, String source)]) { | 151 [void registerSource(Uri uri, String source)]) { |
| 146 Token tokens = scan(text); | 152 Token tokens = scan(text); |
| 147 Uri uri = new Uri(scheme: "source", path: '${++sourceCounter}'); | 153 Uri uri = new Uri(scheme: "source", path: '${++sourceCounter}'); |
| 148 if (registerSource != null) { | 154 if (registerSource != null) { |
| 149 registerSource(uri, text); | 155 registerSource(uri, text); |
| 150 } | 156 } |
| 151 var script = new Script(uri, uri, new MockFile(text)); | 157 var script = new Script(uri, uri, new MockFile(text)); |
| 152 var unit = new CompilationUnitElementX(script, library); | 158 var unit = new CompilationUnitElementX(script, library); |
| 153 int id = 0; | |
| 154 DiagnosticReporter reporter = compiler.reporter; | 159 DiagnosticReporter reporter = compiler.reporter; |
| 155 ElementListener listener = new ElementListener( | 160 ElementListener listener = new ElementListener( |
| 156 compiler.parsing.getScannerOptionsFor(library), | 161 compiler.parsing.getScannerOptionsFor(library), |
| 157 reporter, unit, () => id++); | 162 reporter, unit, new _IdGenerator()); |
| 158 PartialParser parser = new PartialParser(listener, new MockParserOptions()); | 163 PartialParser parser = new PartialParser(listener, new MockParserOptions()); |
| 159 reporter.withCurrentElement(unit, () => parser.parseUnit(tokens)); | 164 reporter.withCurrentElement(unit, () => parser.parseUnit(tokens)); |
| 160 return unit.localMembers; | 165 return unit.localMembers; |
| 161 } | 166 } |
| 162 | 167 |
| 163 NodeList fullParseUnit(String source, {DiagnosticReporter reporter}) { | 168 NodeList fullParseUnit(String source, {DiagnosticReporter reporter}) { |
| 164 return parseBodyCode( | 169 return parseBodyCode( |
| 165 source, | 170 source, |
| 166 (parser, tokens) => parser.parseUnit(tokens), | 171 (parser, tokens) => parser.parseUnit(tokens), |
| 167 reporter: reporter); | 172 reporter: reporter); |
| 168 } | 173 } |
| OLD | NEW |