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

Unified Diff: sdk/lib/_internal/compiler/implementation/elements/modelx.dart

Issue 201613006: Introduces the new syntax for deferred loading (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Ambigous elements are not top-level. Created 6 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 side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/compiler/implementation/elements/modelx.dart
diff --git a/sdk/lib/_internal/compiler/implementation/elements/modelx.dart b/sdk/lib/_internal/compiler/implementation/elements/modelx.dart
index eb48b99e04a22800f2bd563b2ab8db66228b09dc..0f2dc51354825b8eeec621c5a5088661787e3030 100644
--- a/sdk/lib/_internal/compiler/implementation/elements/modelx.dart
+++ b/sdk/lib/_internal/compiler/implementation/elements/modelx.dart
@@ -76,6 +76,7 @@ abstract class ElementX implements Element {
return enclosingElement != null && enclosingElement.isClass();
}
bool isInstanceMember() => false;
+ bool isDeferredLoaderGetter() => false;
bool isFactoryConstructor() => modifiers.isFactory();
bool isGenerativeConstructor() =>
@@ -696,6 +697,12 @@ class ImportScope {
Importers importers = library.importers;
String name = element.name;
+
+ // The loadLibrary function always shadows existing bindings to that name.
+ if (element.isDeferredLoaderGetter()) {
+ importScope.remove(name);
+ // TODO(sigurdm): Print a hint.
+ }
Element existing = importScope.putIfAbsent(name, () => element);
importers.registerImport(element, import);
@@ -1025,7 +1032,11 @@ class PrefixElementX extends ElementX implements PrefixElement {
final ImportScope importScope = new ImportScope();
- bool isDeferred = false;
+ bool get isDeferred => _deferredImport != null;
+
+ // Only needed for deferred imports.
+ Import _deferredImport;
+ Import get import => _deferredImport;
floitsch 2014/03/19 21:04:51 That's not what I meant. The PrefixElement still h
Johnni Winther 2014/03/20 08:42:57 +1
sigurdm 2014/03/20 12:26:33 Of course - I must have been sleeping.
PrefixElementX(String prefix, Element enclosing, this.firstPosition)
: super(prefix, ElementKind.PREFIX, enclosing);
@@ -1042,8 +1053,8 @@ class PrefixElementX extends ElementX implements PrefixElement {
accept(ElementVisitor visitor) => visitor.visitPrefixElement(this);
- void markAsDeferred() {
- isDeferred = true;
+ void markAsDeferred(Import deferredImport) {
+ _deferredImport = deferredImport;
}
}
@@ -1655,6 +1666,42 @@ class FunctionElementX extends ElementX with AnalyzableElement
accept(ElementVisitor visitor) => visitor.visitFunctionElement(this);
}
+class DeferredLoaderGetterElementX extends FunctionElementX {
+
+ final PrefixElement prefix;
+
+ DeferredLoaderGetterElementX(PrefixElement prefix)
+ : this.prefix = prefix,
+ super("loadLibrary",
+ ElementKind.FUNCTION,
+ Modifiers.EMPTY,
+ prefix, true);
+
+ FunctionSignature computeSignature(Compiler compiler) {
+ if (functionSignature != null) return functionSignature;
+ compiler.withCurrentElement(this, () {
+ DartType inner = new FunctionType(this, compiler.types.dynamicType);
+ functionSignature = new FunctionSignatureX(const Link(),
+ const Link(), 0, 0, false, inner);
+ });
+ return functionSignature;
+ }
+
+ bool isMember() => false;
+
+ bool get isSynthesized => true;
+
+ bool isFunction() => false;
+
+ bool isDeferredLoaderGetter() => true;
+
+ bool isGetter() => true;
+
+ // By having position null, the enclosing elements location is printed in
+ // error messages.
+ Token position() => null;
+}
+
class ConstructorBodyElementX extends FunctionElementX
implements ConstructorBodyElement {
FunctionElement constructor;

Powered by Google App Engine
This is Rietveld 408576698