| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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("patchparser"); | 5 #library("patchparser"); |
| 6 #import("dart:uri"); | 6 #import("dart:uri"); |
| 7 | 7 |
| 8 #import("tree/tree.dart", prefix: "tree"); | 8 #import("tree/tree.dart", prefix: "tree"); |
| 9 #import("leg.dart", prefix: 'leg'); // CompilerTask, Compiler. | 9 #import("leg.dart", prefix: 'leg'); // CompilerTask, Compiler. |
| 10 #import("apiimpl.dart"); | 10 #import("apiimpl.dart"); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 compiler.withCurrentElement(compilationUnit, () { | 30 compiler.withCurrentElement(compilationUnit, () { |
| 31 // This patches the elements of the patch library into [library]. | 31 // This patches the elements of the patch library into [library]. |
| 32 // Injected elements are added directly under the compilation unit. | 32 // Injected elements are added directly under the compilation unit. |
| 33 // Patche elements are stored on the patched functions or classes. | 33 // Patche elements are stored on the patched functions or classes. |
| 34 scanLibraryElements(compilationUnit, imports); | 34 scanLibraryElements(compilationUnit, imports); |
| 35 }); | 35 }); |
| 36 // After scanning declarations, we handle the import tags in the patch. | 36 // After scanning declarations, we handle the import tags in the patch. |
| 37 // TODO(lrn): These imports end up in the original library and are in | 37 // TODO(lrn): These imports end up in the original library and are in |
| 38 // scope for the original methods too. This should be fixed. | 38 // scope for the original methods too. This should be fixed. |
| 39 for (tree.ScriptTag tag in imports.toLink()) { | 39 for (tree.ScriptTag tag in imports.toLink()) { |
| 40 compiler.scanner.importLibraryFromTag(tag, compilationUnit); | 40 if (tag.isSource()) { |
| 41 library.tags = library.tags.prepend(tag); |
| 42 |
| 43 StringNode argument = tag.argument; |
| 44 Uri resolved = patchUri.resolve(argument.dartString.slowToString()); |
| 45 Script script = compiler.readScript(resolved, tag); |
| 46 CompilationUnitElement unit = |
| 47 new CompilationUnitElement(script, library); |
| 48 compiler.withCurrentElement(unit, () => compiler.scanner.scan(unit)); |
| 49 } else { |
| 50 compiler.scanner.importLibraryFromTag(tag, compilationUnit); |
| 51 } |
| 41 } | 52 } |
| 42 } | 53 } |
| 43 | 54 |
| 44 void scanLibraryElements( | 55 void scanLibraryElements( |
| 45 CompilationUnitElement compilationUnit, | 56 CompilationUnitElement compilationUnit, |
| 46 LinkBuilder<tree.ScriptTag> imports) { | 57 LinkBuilder<tree.ScriptTag> imports) { |
| 47 measure(() { | 58 measure(() { |
| 48 // TODO(lrn): Possibly recursively handle #source directives in patch. | 59 // TODO(lrn): Possibly recursively handle #source directives in patch. |
| 49 leg.Script script = compilationUnit.script; | 60 leg.Script script = compilationUnit.script; |
| 50 Token tokens = new StringScanner(script.text).tokenize(); | 61 Token tokens = new StringScanner(script.text).tokenize(); |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 } | 285 } |
| 275 } | 286 } |
| 276 | 287 |
| 277 void addMember(Element element) { | 288 void addMember(Element element) { |
| 278 if (isMemberPatch || (isClassPatch && element is ClassElement)) { | 289 if (isMemberPatch || (isClassPatch && element is ClassElement)) { |
| 279 element.addMetadata(popNode()); | 290 element.addMetadata(popNode()); |
| 280 } | 291 } |
| 281 super.addMember(element); | 292 super.addMember(element); |
| 282 } | 293 } |
| 283 } | 294 } |
| OLD | NEW |