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

Side by Side Diff: lib/src/compiler/code_generator.dart

Issue 2045783002: Fixes #586 - enums should now work in SDK libs (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « no previous file | no next file » | 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 import 'dart:collection' show HashMap, HashSet; 5 import 'dart:collection' show HashMap, HashSet;
6 import 'dart:math' show min, max; 6 import 'dart:math' show min, max;
7 7
8 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; 8 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator;
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/token.dart' show Token, TokenType; 10 import 'package:analyzer/dart/ast/token.dart' show Token, TokenType;
(...skipping 1035 matching lines...) Expand 10 before | Expand all | Expand 10 after
1046 1046
1047 // Create static fields for each enum value 1047 // Create static fields for each enum value
1048 for (var i = 0; i < fields.length; ++i) { 1048 for (var i = 0; i < fields.length; ++i) {
1049 result.add(js.statement('#.# = dart.const(new #(#));', 1049 result.add(js.statement('#.# = dart.const(new #(#));',
1050 [id, fields[i].name, id, js.number(i)])); 1050 [id, fields[i].name, id, js.number(i)]));
1051 } 1051 }
1052 1052
1053 // Create static values list 1053 // Create static values list
1054 var values = new JS.ArrayInitializer(new List<JS.Expression>.from( 1054 var values = new JS.ArrayInitializer(new List<JS.Expression>.from(
1055 fields.map((f) => js.call('#.#', [id, f.name])))); 1055 fields.map((f) => js.call('#.#', [id, f.name]))));
1056
1057 // dart.constList helper internally depends on _interceptors.JSArray.
1058 _declareBeforeUse(_jsArray);
1059
1056 result.add(js.statement( 1060 result.add(js.statement(
1057 '#.values = dart.constList(#, #);', [id, values, _emitType(type)])); 1061 '#.values = dart.constList(#, #);', [id, values, _emitType(type)]));
1058 1062
1059 return _statement(result); 1063 return _statement(result);
1060 } 1064 }
1061 1065
1062 /// Wraps a possibly generic class in its type arguments. 1066 /// Wraps a possibly generic class in its type arguments.
1063 JS.Statement _defineClassTypeArguments(TypeDefiningElement element, 1067 JS.Statement _defineClassTypeArguments(TypeDefiningElement element,
1064 List<TypeParameterElement> formals, JS.Statement body) { 1068 List<TypeParameterElement> formals, JS.Statement body) {
1065 assert(formals.isNotEmpty); 1069 assert(formals.isNotEmpty);
(...skipping 3904 matching lines...) Expand 10 before | Expand all | Expand 10 after
4970 } 4974 }
4971 4975
4972 bool isLibraryPrefix(Expression node) => 4976 bool isLibraryPrefix(Expression node) =>
4973 node is SimpleIdentifier && node.staticElement is PrefixElement; 4977 node is SimpleIdentifier && node.staticElement is PrefixElement;
4974 4978
4975 LibraryElement _getLibrary(AnalysisContext c, String uri) => 4979 LibraryElement _getLibrary(AnalysisContext c, String uri) =>
4976 c.computeLibraryElement(c.sourceFactory.forUri(uri)); 4980 c.computeLibraryElement(c.sourceFactory.forUri(uri));
4977 4981
4978 bool _isDartRuntime(LibraryElement l) => 4982 bool _isDartRuntime(LibraryElement l) =>
4979 l.isInSdk && l.source.uri.toString() == 'dart:_runtime'; 4983 l.isInSdk && l.source.uri.toString() == 'dart:_runtime';
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698