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

Side by Side Diff: compiler/java/com/google/dart/compiler/resolver/TopLevelElementBuilder.java

Issue 10919133: Support for new 'export' directive in resolver (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Tweak for parsing import/export directives Created 8 years, 3 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
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 package com.google.dart.compiler.resolver; 5 package com.google.dart.compiler.resolver;
6 6
7 import com.google.common.annotations.VisibleForTesting; 7 import com.google.common.annotations.VisibleForTesting;
8 import com.google.common.collect.Lists; 8 import com.google.common.collect.Lists;
9 import com.google.common.collect.Maps; 9 import com.google.common.collect.Maps;
10 import com.google.dart.compiler.DartCompilationError; 10 import com.google.dart.compiler.DartCompilationError;
11 import com.google.dart.compiler.DartCompilerContext; 11 import com.google.dart.compiler.DartCompilerContext;
12 import com.google.dart.compiler.DartCompilerListener; 12 import com.google.dart.compiler.DartCompilerListener;
13 import com.google.dart.compiler.ErrorCode; 13 import com.google.dart.compiler.ErrorCode;
14 import com.google.dart.compiler.ast.ASTVisitor; 14 import com.google.dart.compiler.ast.ASTVisitor;
15 import com.google.dart.compiler.ast.DartClass; 15 import com.google.dart.compiler.ast.DartClass;
16 import com.google.dart.compiler.ast.DartField; 16 import com.google.dart.compiler.ast.DartField;
17 import com.google.dart.compiler.ast.DartFieldDefinition; 17 import com.google.dart.compiler.ast.DartFieldDefinition;
18 import com.google.dart.compiler.ast.DartFunctionTypeAlias; 18 import com.google.dart.compiler.ast.DartFunctionTypeAlias;
19 import com.google.dart.compiler.ast.DartIdentifier; 19 import com.google.dart.compiler.ast.DartIdentifier;
20 import com.google.dart.compiler.ast.DartLibraryDirective; 20 import com.google.dart.compiler.ast.DartLibraryDirective;
21 import com.google.dart.compiler.ast.DartMethodDefinition; 21 import com.google.dart.compiler.ast.DartMethodDefinition;
22 import com.google.dart.compiler.ast.DartNode; 22 import com.google.dart.compiler.ast.DartNode;
23 import com.google.dart.compiler.ast.DartTypeParameter; 23 import com.google.dart.compiler.ast.DartTypeParameter;
24 import com.google.dart.compiler.ast.DartUnit; 24 import com.google.dart.compiler.ast.DartUnit;
25 import com.google.dart.compiler.ast.LibraryExport;
25 import com.google.dart.compiler.ast.LibraryImport; 26 import com.google.dart.compiler.ast.LibraryImport;
26 import com.google.dart.compiler.ast.LibraryUnit; 27 import com.google.dart.compiler.ast.LibraryUnit;
27 import com.google.dart.compiler.ast.Modifiers; 28 import com.google.dart.compiler.ast.Modifiers;
28 import com.google.dart.compiler.common.SourceInfo; 29 import com.google.dart.compiler.common.SourceInfo;
29 import com.google.dart.compiler.type.Type; 30 import com.google.dart.compiler.type.Type;
30 import com.google.dart.compiler.type.TypeVariable; 31 import com.google.dart.compiler.type.TypeVariable;
31 import com.google.dart.compiler.type.Types; 32 import com.google.dart.compiler.type.Types;
32 33
33 import java.util.Collections; 34 import java.util.Collections;
34 import java.util.List; 35 import java.util.List;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 } else { 125 } else {
125 scopeForImport = importScope; 126 scopeForImport = importScope;
126 } 127 }
127 } 128 }
128 // Prepare "lib" scope. 129 // Prepare "lib" scope.
129 fillInLibraryScope(lib, listener); 130 fillInLibraryScope(lib, listener);
130 // Fill "library" scope with element exported from "lib". 131 // Fill "library" scope with element exported from "lib".
131 for (Element element : lib.getElement().getExportedElements()) { 132 for (Element element : lib.getElement().getExportedElements()) {
132 String name = element.getName(); 133 String name = element.getName();
133 if (libraryImport.isVisible(name)) { 134 if (libraryImport.isVisible(name)) {
134 { 135 Element oldElement = scopeForImport.declareElement(name, element);
135 Element oldElement = scopeForImport.declareElement(name, element); 136 if (shouldReportDuplicateDeclaration(oldElement, element)) {
136 if (shouldReportDuplicateDeclaration(oldElement, element)) { 137 reportDuplicateTopLevelDeclarationImport(listener, library, prefix, oldElement, element);
137 reportDuplicateTopLevelDeclarationImport(listener, library, prefix , oldElement, element);
138 }
139 } 138 }
140 // May re-export. 139 }
141 if (libraryImport.isExported()) { 140 }
142 Elements.addExportedElement(library.getElement(), element); 141 }
143 } 142 // Fill "library" export scope with re-exports.
143 for (LibraryExport export : library.getExports()) {
144 LibraryUnit lib = export.getLibrary();
145 for (Element element : lib.getElement().getExportedElements()) {
146 String name = element.getName();
147 if (export.isVisible(name)) {
148 Elements.addExportedElement(library.getElement(), element);
144 } 149 }
145 } 150 }
146 } 151 }
147 // Done. 152 // Done.
148 library.getElement().getScope().markStateReady(); 153 library.getElement().getScope().markStateReady();
149 } 154 }
150 155
151 private static void reportDuplicateTopLevelDeclarationImport(DartCompilerListe ner listener, 156 private static void reportDuplicateTopLevelDeclarationImport(DartCompilerListe ner listener,
152 LibraryUnit library, String prefix, Element oldElement, Element newElement ) { 157 LibraryUnit library, String prefix, Element oldElement, Element newElement ) {
153 String name = newElement.getName(); 158 String name = newElement.getName();
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 Modifiers modifiers = node.getModifiers(); 283 Modifiers modifiers = node.getModifiers();
279 if (modifiers.isFinal()) { 284 if (modifiers.isFinal()) {
280 // final top-level fields are implicitly compile-time constants. 285 // final top-level fields are implicitly compile-time constants.
281 modifiers = modifiers.makeConstant(); 286 modifiers = modifiers.makeConstant();
282 } 287 }
283 node.setElement(Elements.fieldFromNode(node, library, node.getObsoleteMeta data(), modifiers)); 288 node.setElement(Elements.fieldFromNode(node, library, node.getObsoleteMeta data(), modifiers));
284 return null; 289 return null;
285 } 290 }
286 } 291 }
287 } 292 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698