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

Unified Diff: pkg/compiler/lib/src/resolution/members.dart

Issue 707463003: Support enums in dart2js. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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: pkg/compiler/lib/src/resolution/members.dart
diff --git a/pkg/compiler/lib/src/resolution/members.dart b/pkg/compiler/lib/src/resolution/members.dart
index 937d308a4afbc195fa6be76d78d86e5b2586eeb7..4dc0b800c7981c16703d0149a6069b8805bce2ba 100644
--- a/pkg/compiler/lib/src/resolution/members.dart
+++ b/pkg/compiler/lib/src/resolution/members.dart
@@ -4335,6 +4335,44 @@ class ClassResolverVisitor extends TypeDefinitionVisitor {
return element.computeType(compiler);
}
+ @override
+ DartType visitEnum(Enum node) {
+ if (!compiler.enableEnums) {
+ compiler.reportError(node, MessageKind.EXPERIMENTAL_ENUMS);
+ }
+
+ invariant(node, element != null);
+ invariant(element, element.resolutionState == STATE_STARTED,
+ message: () => 'cyclic resolution of class $element');
+
+ InterfaceType type = element.computeType(compiler);
+ scope = new TypeDeclarationScope(scope, element);
+
+ // Setup the supertype for the element (if there is a cycle in the
floitsch 2014/11/10 16:08:32 That comment should not be necessary. Enums only h
Johnni Winther 2014/11/11 08:23:37 Reduced to setting the supertype to Object.
+ // class hierarchy, it has already been set to Object).
+ ClassElement superElement = registry.defaultSuperclass(element);
+ // Avoid making the superclass (usually Object) extend itself.
floitsch 2014/11/10 16:08:32 ditto.
+ if (element != superElement) {
floitsch 2014/11/10 16:08:32 These tests should just be replaced with an invari
+ if (superElement == null) {
+ compiler.internalError(node,
+ "Cannot resolve default superclass for $element.");
+ } else {
+ superElement.ensureResolved(compiler);
+ }
+ element.supertype = superElement.computeType(compiler);
+ }
+
+ element.interfaces = const Link<DartType>();
+
+ calculateAllSupertypes(element);
+
+ InterfaceType enumType = element.computeType(compiler);
+
+ EnumCreator creator = new EnumCreator(compiler, element);
+ creator.createMembers();
+ return enumType;
+ }
+
/// Resolves the mixed type for [mixinNode] and checks that the the mixin type
/// is a valid, non-blacklisted interface type. The mixin type is returned.
DartType checkMixinType(TypeAnnotation mixinNode) {
@@ -4701,6 +4739,10 @@ class ClassSupertypeResolver extends CommonResolverVisitor {
visitNodeList(node.interfaces);
}
+ void visitEnum(Enum node) {
+ loadSupertype(compiler.objectClass, node);
+ }
+
void visitMixinApplication(MixinApplication node) {
node.superclass.accept(this);
visitNodeList(node.mixins);

Powered by Google App Engine
This is Rietveld 408576698