Chromium Code Reviews| 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 Node node = link.head.parseNode(compiler, compiler); | 15 Node node = link.head.parseNode(compiler, compiler); |
| 16 // TODO(ahe): Is this the right place to handle this? | 16 // TODO(ahe): Is this the right place to handle this? |
| 17 compiler.cancel('Duplicate definition', node: node); | 17 compiler.cancel('Duplicate definition', node: node); |
| 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 ex) { | |
| 30 Token token; | |
| 31 var message; | |
| 32 if (ex.message is int) { | |
| 33 token = new Token(EOF_INFO, ex.message); | |
| 34 message = 'unexpected character'; | |
| 35 } else { | |
| 36 token = new Token(EOF_INFO, 0); | |
| 37 message = ex.message; | |
| 38 } | |
| 39 compiler.cancel(message, token: token); | |
| 40 throw 'unrecoverable error'; | |
|
karlklose
2012/01/17 16:54:36
Compiler.cancel should terminate the compilation,
| |
| 41 } | |
| 27 ElementListener listener = new ElementListener(compiler, compilationUnit); | 42 ElementListener listener = new ElementListener(compiler, compilationUnit); |
| 28 PartialParser parser = new PartialParser(listener); | 43 PartialParser parser = new PartialParser(listener); |
| 29 parser.parseUnit(tokens); | 44 parser.parseUnit(tokens); |
| 30 return listener.topLevelElements; | 45 return listener.topLevelElements; |
| 31 } | 46 } |
| 32 } | 47 } |
| OLD | NEW |