Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: dart/frog/leg/scanner/scanner_task.dart

Issue 9663047: Repeated prefixes and parser fixes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebased and status file Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « dart/frog/leg/scanner/partial_parser.dart ('k') | dart/tests/language/language-leg.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 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(() {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 // better way to access "dart:core". 51 // better way to access "dart:core".
52 bool implicitlyImportCoreLibrary = compiler.coreLibrary !== null; 52 bool implicitlyImportCoreLibrary = compiler.coreLibrary !== null;
53 for (ScriptTag tag in imports.toLink()) { 53 for (ScriptTag tag in imports.toLink()) {
54 // Now that we have processed all the source tags, it is safe to 54 // Now that we have processed all the source tags, it is safe to
55 // start loading other libraries. 55 // start loading other libraries.
56 SourceString argument = tag.argument.value.copyWithoutQuotes(1, 1); 56 SourceString argument = tag.argument.value.copyWithoutQuotes(1, 1);
57 Uri resolved = base.resolve(argument.slowToString()); 57 Uri resolved = base.resolve(argument.slowToString());
58 if (resolved.toString() == "dart:core") { 58 if (resolved.toString() == "dart:core") {
59 implicitlyImportCoreLibrary = false; 59 implicitlyImportCoreLibrary = false;
60 } 60 }
61 importLibrary(library, loadLibrary(resolved, tag), tag.prefix); 61 importLibrary(library, loadLibrary(resolved, tag), tag);
62 } 62 }
63 if (implicitlyImportCoreLibrary) { 63 if (implicitlyImportCoreLibrary) {
64 importLibrary(library, compiler.coreLibrary, null); 64 importLibrary(library, compiler.coreLibrary, null);
65 } 65 }
66 } 66 }
67 67
68 void scanElements(CompilationUnitElement compilationUnit) { 68 void scanElements(CompilationUnitElement compilationUnit) {
69 Script script = compilationUnit.script; 69 Script script = compilationUnit.script;
70 Token tokens; 70 Token tokens;
71 try { 71 try {
(...skipping 22 matching lines...) Expand all
94 native.maybeEnableNative(compiler, element, uri); 94 native.maybeEnableNative(compiler, element, uri);
95 return element; 95 return element;
96 }); 96 });
97 if (newLibrary) { 97 if (newLibrary) {
98 compiler.withCurrentElement(library, () => scan(library)); 98 compiler.withCurrentElement(library, () => scan(library));
99 } 99 }
100 return library; 100 return library;
101 } 101 }
102 102
103 void importLibrary(LibraryElement library, LibraryElement imported, 103 void importLibrary(LibraryElement library, LibraryElement imported,
104 LiteralString prefix) { 104 ScriptTag tag) {
105 if (prefix !== null) { 105 if (tag !== null && tag.prefix !== null) {
106 library.define(new PrefixElement(prefix, imported, library), compiler); 106 SourceString prefix = tag.prefix.dartString.source;
107 Element e = library.find(prefix);
108 if (e === null) {
109 e = new PrefixElement(prefix, library);
110 library.define(e, compiler);
111 }
112 if (e.kind !== ElementKind.PREFIX) {
113 compiler.withCurrentElement(e, () {
114 compiler.reportWarning(new Identifier(e.position()),
115 'duplicated definition');
116 });
117 compiler.reportError(tag.prefix, 'duplicate defintion');
118 }
119 imported.forEachExport((Element element) {
120 Element existing = e.imported.putIfAbsent(element.name, () => element);
121 if (existing !== element) {
122 compiler.withCurrentElement(existing, () {
123 compiler.reportWarning(new Identifier(existing.position()),
124 'duplicated import');
125 });
126 compiler.withCurrentElement(element, () {
127 compiler.reportError(new Identifier(element.position()),
128 'duplicated import');
129 });
130 }
131 });
107 } else { 132 } else {
108 imported.forEachExport((Element element) { 133 imported.forEachExport((Element element) {
109 compiler.withCurrentElement(element, () { 134 compiler.withCurrentElement(element, () {
110 library.define(element, compiler); 135 library.define(element, compiler);
111 }); 136 });
112 }); 137 });
113 } 138 }
114 } 139 }
115 } 140 }
116 141
117 class DietParserTask extends CompilerTask { 142 class DietParserTask extends CompilerTask {
118 DietParserTask(Compiler compiler) : super(compiler); 143 DietParserTask(Compiler compiler) : super(compiler);
119 final String name = 'Diet Parser'; 144 final String name = 'Diet Parser';
120 145
121 dietParse(CompilationUnitElement compilationUnit, Token tokens) { 146 dietParse(CompilationUnitElement compilationUnit, Token tokens) {
122 measure(() { 147 measure(() {
123 ElementListener listener = new ElementListener(compiler, compilationUnit); 148 ElementListener listener = new ElementListener(compiler, compilationUnit);
124 PartialParser parser = new PartialParser(listener); 149 PartialParser parser = new PartialParser(listener);
125 parser.parseUnit(tokens); 150 parser.parseUnit(tokens);
126 }); 151 });
127 } 152 }
128 } 153 }
OLDNEW
« no previous file with comments | « dart/frog/leg/scanner/partial_parser.dart ('k') | dart/tests/language/language-leg.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698