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

Side by Side Diff: pkg/compiler/lib/src/elements/modelx.dart

Issue 707463003: Support enums in dart2js. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 elements.modelx; 5 library elements.modelx;
6 6
7 import 'elements.dart'; 7 import 'elements.dart';
8 import '../constants/expressions.dart'; 8 import '../constants/expressions.dart';
9 import '../helpers/helpers.dart'; // Included for debug helpers. 9 import '../helpers/helpers.dart'; // Included for debug helpers.
10 import '../tree/tree.dart'; 10 import '../tree/tree.dart';
(...skipping 1432 matching lines...) Expand 10 before | Expand all | Expand 10 after
1443 class FunctionSignatureX implements FunctionSignature { 1443 class FunctionSignatureX implements FunctionSignature {
1444 final Link<Element> requiredParameters; 1444 final Link<Element> requiredParameters;
1445 final Link<Element> optionalParameters; 1445 final Link<Element> optionalParameters;
1446 final int requiredParameterCount; 1446 final int requiredParameterCount;
1447 final int optionalParameterCount; 1447 final int optionalParameterCount;
1448 final bool optionalParametersAreNamed; 1448 final bool optionalParametersAreNamed;
1449 final List<Element> orderedOptionalParameters; 1449 final List<Element> orderedOptionalParameters;
1450 final FunctionType type; 1450 final FunctionType type;
1451 final bool hasOptionalParameters; 1451 final bool hasOptionalParameters;
1452 1452
1453 FunctionSignatureX(this.requiredParameters, 1453 FunctionSignatureX({this.requiredParameters: const Link<Element>(),
1454 Link<Element> optionalParameters, 1454 this.requiredParameterCount: 0,
1455 this.requiredParameterCount, 1455 Link<Element> optionalParameters: const Link<Element>(),
1456 this.optionalParameterCount, 1456 this.optionalParameterCount: 0,
1457 this.optionalParametersAreNamed, 1457 this.optionalParametersAreNamed: false,
1458 this.orderedOptionalParameters, 1458 this.orderedOptionalParameters: const <Element>[],
1459 this.type) 1459 this.type})
1460 : optionalParameters = optionalParameters, 1460 : optionalParameters = optionalParameters,
1461 hasOptionalParameters = !optionalParameters.isEmpty; 1461 hasOptionalParameters = !optionalParameters.isEmpty;
1462 1462
1463 void forEachRequiredParameter(void function(Element parameter)) { 1463 void forEachRequiredParameter(void function(Element parameter)) {
1464 for (Link<Element> link = requiredParameters; 1464 for (Link<Element> link = requiredParameters;
1465 !link.isEmpty; 1465 !link.isEmpty;
1466 link = link.tail) { 1466 link = link.tail) {
1467 function(link.head); 1467 function(link.head);
1468 } 1468 }
1469 } 1469 }
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1711 : this.prefix = prefix, 1711 : this.prefix = prefix,
1712 super("loadLibrary", 1712 super("loadLibrary",
1713 ElementKind.FUNCTION, 1713 ElementKind.FUNCTION,
1714 Modifiers.EMPTY, 1714 Modifiers.EMPTY,
1715 prefix, true); 1715 prefix, true);
1716 1716
1717 FunctionSignature computeSignature(Compiler compiler) { 1717 FunctionSignature computeSignature(Compiler compiler) {
1718 if (functionSignatureCache != null) return functionSignature; 1718 if (functionSignatureCache != null) return functionSignature;
1719 compiler.withCurrentElement(this, () { 1719 compiler.withCurrentElement(this, () {
1720 DartType inner = new FunctionType(this); 1720 DartType inner = new FunctionType(this);
1721 functionSignatureCache = new FunctionSignatureX(const Link(), 1721 functionSignatureCache = new FunctionSignatureX(type: inner);
1722 const Link(), 0, 0, false, [], inner);
1723 }); 1722 });
1724 return functionSignatureCache; 1723 return functionSignatureCache;
1725 } 1724 }
1726 1725
1727 bool get isClassMember => false; 1726 bool get isClassMember => false;
1728 1727
1729 bool isForeign(Backend backend) => true; 1728 bool isForeign(Backend backend) => true;
1730 1729
1731 bool get isSynthesized => true; 1730 bool get isSynthesized => true;
1732 1731
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1813 FunctionExpression get node => null; 1812 FunctionExpression get node => null;
1814 1813
1815 Token get position => enclosingElement.position; 1814 Token get position => enclosingElement.position;
1816 1815
1817 bool get isSynthesized => true; 1816 bool get isSynthesized => true;
1818 1817
1819 FunctionSignature computeSignature(compiler) { 1818 FunctionSignature computeSignature(compiler) {
1820 if (functionSignatureCache != null) return functionSignatureCache; 1819 if (functionSignatureCache != null) return functionSignatureCache;
1821 if (isDefaultConstructor) { 1820 if (isDefaultConstructor) {
1822 return functionSignatureCache = new FunctionSignatureX( 1821 return functionSignatureCache = new FunctionSignatureX(
1823 const Link<Element>(), const Link<Element>(), 0, 0, false, 1822 type: new FunctionType(this, enclosingClass.thisType));
1824 const <Element>[],
1825 new FunctionType(this, enclosingClass.thisType));
1826 } 1823 }
1827 if (definingConstructor.isErroneous) { 1824 if (definingConstructor.isErroneous) {
1828 return functionSignatureCache = 1825 return functionSignatureCache =
1829 compiler.objectClass.localLookup('').computeSignature(compiler); 1826 compiler.objectClass.localLookup('').computeSignature(compiler);
1830 } 1827 }
1831 // TODO(johnniwinther): Ensure that the function signature (and with it the 1828 // TODO(johnniwinther): Ensure that the function signature (and with it the
1832 // function type) substitutes type variables correctly. 1829 // function type) substitutes type variables correctly.
1833 return functionSignatureCache = 1830 return functionSignatureCache =
1834 definingConstructor.computeSignature(compiler); 1831 definingConstructor.computeSignature(compiler);
1835 } 1832 }
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1966 : supertypeLoadState = initialState, 1963 : supertypeLoadState = initialState,
1967 resolutionState = initialState, 1964 resolutionState = initialState,
1968 super(name, ElementKind.CLASS, enclosing); 1965 super(name, ElementKind.CLASS, enclosing);
1969 1966
1970 int get hashCode => id; 1967 int get hashCode => id;
1971 1968
1972 bool get hasBackendMembers => !backendMembers.isEmpty; 1969 bool get hasBackendMembers => !backendMembers.isEmpty;
1973 1970
1974 bool get isUnnamedMixinApplication => false; 1971 bool get isUnnamedMixinApplication => false;
1975 1972
1973 @override
1974 bool get isEnumClass => false;
1975
1976 InterfaceType computeType(Compiler compiler) { 1976 InterfaceType computeType(Compiler compiler) {
1977 if (thisTypeCache == null) { 1977 if (thisTypeCache == null) {
1978 computeThisAndRawType(compiler, computeTypeParameters(compiler)); 1978 computeThisAndRawType(compiler, computeTypeParameters(compiler));
1979 } 1979 }
1980 return thisTypeCache; 1980 return thisTypeCache;
1981 } 1981 }
1982 1982
1983 void computeThisAndRawType(Compiler compiler, List<DartType> typeVariables) { 1983 void computeThisAndRawType(Compiler compiler, List<DartType> typeVariables) {
1984 if (thisTypeCache == null) { 1984 if (thisTypeCache == null) {
1985 if (origin == null) { 1985 if (origin == null) {
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
2348 Link<Element> get localMembers { 2348 Link<Element> get localMembers {
2349 if (localMembersCache == null) { 2349 if (localMembersCache == null) {
2350 localMembersCache = localMembersReversed.reverse(); 2350 localMembersCache = localMembersReversed.reverse();
2351 } 2351 }
2352 return localMembersCache; 2352 return localMembersCache;
2353 } 2353 }
2354 2354
2355 ClassElementX(String name, Element enclosing, int id, int initialState) 2355 ClassElementX(String name, Element enclosing, int id, int initialState)
2356 : super(name, enclosing, id, initialState); 2356 : super(name, enclosing, id, initialState);
2357 2357
2358 ClassNode parseNode(Compiler compiler);
2359
2360 bool get isMixinApplication => false; 2358 bool get isMixinApplication => false;
2361 bool get hasLocalScopeMembers => !localScope.isEmpty; 2359 bool get hasLocalScopeMembers => !localScope.isEmpty;
2362 2360
2363 void addMember(Element element, DiagnosticListener listener) { 2361 void addMember(Element element, DiagnosticListener listener) {
2364 localMembersCache = null; 2362 localMembersCache = null;
2365 localMembersReversed = localMembersReversed.prepend(element); 2363 localMembersReversed = localMembersReversed.prepend(element);
2366 addToScope(element, listener); 2364 addToScope(element, listener);
2367 } 2365 }
2368 2366
2369 void addToScope(Element element, DiagnosticListener listener) { 2367 void addToScope(Element element, DiagnosticListener listener) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
2409 if (origin != null) { 2407 if (origin != null) {
2410 return 'patch ${super.toString()}'; 2408 return 'patch ${super.toString()}';
2411 } else if (patch != null) { 2409 } else if (patch != null) {
2412 return 'origin ${super.toString()}'; 2410 return 'origin ${super.toString()}';
2413 } else { 2411 } else {
2414 return super.toString(); 2412 return super.toString();
2415 } 2413 }
2416 } 2414 }
2417 } 2415 }
2418 2416
2417 class EnumClassElementX extends ClassElementX {
2418 final Enum node;
2419
2420 EnumClassElementX(String name, Element enclosing, int id, this.node)
2421 : super(name, enclosing, id, STATE_NOT_STARTED);
2422
2423 @override
2424 bool get hasNode => true;
2425
2426 @override
2427 Token get position => node.name.token;
2428
2429 @override
2430 bool get isEnumClass => true;
2431
2432 @override
2433 Node parseNode(Compiler compiler) => node;
2434
2435 @override
2436 accept(ElementVisitor visitor) => visitor.visitClassElement(this);
2437
2438 List<DartType> computeTypeParameters(Compiler compiler) => const <DartType>[];
2439 }
2440
2441 class EnumConstructorElementX extends ConstructorElementX {
2442 final FunctionExpression node;
2443
2444 EnumConstructorElementX(EnumClassElementX enumClass,
2445 Modifiers modifiers,
2446 this.node)
2447 : super('', // Name.
2448 ElementKind.GENERATIVE_CONSTRUCTOR,
2449 modifiers,
2450 enumClass);
2451
2452 @override
2453 bool get hasNode => true;
2454
2455 @override
2456 FunctionExpression parseNode(Compiler compiler) => node;
2457 }
2458
2459 class EnumMethodElementX extends FunctionElementX {
2460 final FunctionExpression node;
2461
2462 EnumMethodElementX(String name,
2463 EnumClassElementX enumClass,
2464 Modifiers modifiers,
2465 this.node)
2466 : super(name,
2467 ElementKind.FUNCTION,
2468 modifiers,
2469 enumClass,
2470 false);
2471
2472 @override
2473 bool get hasNode => true;
2474
2475 @override
2476 FunctionExpression parseNode(Compiler compiler) => node;
2477 }
2478
2479 class EnumFormalElementX extends InitializingFormalElementX {
2480 EnumFormalElementX(ConstructorElement constructor,
2481 VariableDefinitions variables,
2482 Identifier identifier,
2483 EnumFieldElementX fieldElement)
2484 : super(constructor, variables, identifier, null, fieldElement) {
2485 typeCache = fieldElement.type;
2486 }
2487 }
2488
2489 class EnumFieldElementX extends FieldElementX {
2490
2491 EnumFieldElementX(Identifier name,
2492 EnumClassElementX enumClass,
2493 VariableList variableList,
2494 Node definition,
2495 [Expression initializer])
2496 : super(name, enumClass, variableList) {
2497 definitionsCache = new VariableDefinitions(null,
2498 variableList.modifiers, new NodeList.singleton(definition));
2499 initializerCache = initializer;
2500 }
2501 }
2502
2419 class MixinApplicationElementX extends BaseClassElementX 2503 class MixinApplicationElementX extends BaseClassElementX
2420 implements MixinApplicationElement { 2504 implements MixinApplicationElement {
2421 final Node node; 2505 final Node node;
2422 final Modifiers modifiers; 2506 final Modifiers modifiers;
2423 2507
2424 Link<FunctionElement> constructors = new Link<FunctionElement>(); 2508 Link<FunctionElement> constructors = new Link<FunctionElement>();
2425 2509
2426 InterfaceType mixinType; 2510 InterfaceType mixinType;
2427 2511
2428 MixinApplicationElementX(String name, Element enclosing, int id, 2512 MixinApplicationElementX(String name, Element enclosing, int id,
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
2712 AstElement get definingElement; 2796 AstElement get definingElement;
2713 2797
2714 bool get hasResolvedAst => definingElement.hasTreeElements; 2798 bool get hasResolvedAst => definingElement.hasTreeElements;
2715 2799
2716 ResolvedAst get resolvedAst { 2800 ResolvedAst get resolvedAst {
2717 return new ResolvedAst(declaration, 2801 return new ResolvedAst(declaration,
2718 definingElement.node, definingElement.treeElements); 2802 definingElement.node, definingElement.treeElements);
2719 } 2803 }
2720 2804
2721 } 2805 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/elements/elements.dart ('k') | pkg/compiler/lib/src/resolution/enum_creator.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698