| 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 | 4 |
| 5 class ScannerTask extends CompilerTask { | 5 class ScannerTask extends CompilerTask { |
| 6 ScannerTask(Compiler compiler) : super(compiler); | 6 ScannerTask(Compiler compiler) : super(compiler); |
| 7 String get name() => 'Scanner'; | 7 String get name() => 'Scanner'; |
| 8 | 8 |
| 9 void scan(CompilationUnitElement compilationUnit) { | 9 void scan(CompilationUnitElement compilationUnit) { |
| 10 measure(() { | 10 measure(() { |
| 11 Link<Element> elements = scanElements(compilationUnit); | 11 Link<Element> elements = scanElements(compilationUnit); |
| 12 for (Link<Element> link = elements; !link.isEmpty(); link = link.tail) { | 12 for (Link<Element> link = elements; !link.isEmpty(); link = link.tail) { |
| 13 Element existing = compiler.universe.find(link.head.name); | 13 Element existing = compiler.universe.find(link.head.name); |
| 14 if (existing !== null) { | 14 if (existing !== null) { |
| 15 // TODO(ahe): Is this the right place to handle this? | 15 // TODO(ahe): Is this the right place to handle this? |
| 16 compiler.cancel('Duplicate definition', | 16 compiler.cancel('Duplicate definition', |
| 17 token: link.head.dynamic.beginToken); | 17 token: link.head.dynamic.beginToken); |
| 18 } | 18 } |
| 19 compiler.universe.define(link.head); | 19 compiler.universe.define(link.head); |
| 20 } | 20 } |
| 21 }); | 21 }); |
| 22 } | 22 } |
| 23 | 23 |
| 24 Link<Element> scanElements(CompilationUnitElement compilationUnit) { | 24 Link<Element> scanElements(CompilationUnitElement compilationUnit) { |
| 25 Script script = compilationUnit.script; | 25 Script script = compilationUnit.script; |
| 26 Token tokens = new StringScanner(script.text).tokenize(); | 26 Token tokens; |
| 27 try { |
| 28 tokens = new StringScanner(script.text).tokenize(); |
| 29 } catch (MalformedInputException e) { |
| 30 if (e.message is int) { |
| 31 Token token = new Token(ERROR_INFO, e.message); |
| 32 compiler.cancel('Unexpected character', token: token); |
| 33 throw "Unrecoverable error"; |
| 34 } |
| 35 } |
| 27 ElementListener listener = new ElementListener(compiler, compilationUnit); | 36 ElementListener listener = new ElementListener(compiler, compilationUnit); |
| 28 PartialParser parser = new PartialParser(listener); | 37 PartialParser parser = new PartialParser(listener); |
| 29 parser.parseUnit(tokens); | 38 parser.parseUnit(tokens); |
| 30 return listener.topLevelElements; | 39 return listener.topLevelElements; |
| 31 } | 40 } |
| 32 } | 41 } |
| OLD | NEW |